Imported Upstream version 0.7
[pysam.git] / pysam / csamtools.c
1 /* Generated by Cython 0.16 on Thu Nov 22 15:20:54 2012 */
2
3 #define PY_SSIZE_T_CLEAN
4 #include "Python.h"
5 #ifndef Py_PYTHON_H
6     #error Python headers needed to compile C extensions, please install development version of Python.
7 #elif PY_VERSION_HEX < 0x02040000
8     #error Cython requires Python 2.4+.
9 #else
10 #include <stddef.h> /* For offsetof */
11 #ifndef offsetof
12 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
13 #endif
14
15 #if !defined(WIN32) && !defined(MS_WINDOWS)
16   #ifndef __stdcall
17     #define __stdcall
18   #endif
19   #ifndef __cdecl
20     #define __cdecl
21   #endif
22   #ifndef __fastcall
23     #define __fastcall
24   #endif
25 #endif
26
27 #ifndef DL_IMPORT
28   #define DL_IMPORT(t) t
29 #endif
30 #ifndef DL_EXPORT
31   #define DL_EXPORT(t) t
32 #endif
33
34 #ifndef PY_LONG_LONG
35   #define PY_LONG_LONG LONG_LONG
36 #endif
37
38 #ifndef Py_HUGE_VAL
39   #define Py_HUGE_VAL HUGE_VAL
40 #endif
41
42 #ifdef PYPY_VERSION
43 #define CYTHON_COMPILING_IN_PYPY 1
44 #define CYTHON_COMPILING_IN_CPYTHON 0
45 #else
46 #define CYTHON_COMPILING_IN_PYPY 0
47 #define CYTHON_COMPILING_IN_CPYTHON 1
48 #endif
49
50 #if CYTHON_COMPILING_IN_PYPY
51   #define __Pyx_PyCFunction_Call PyObject_Call
52 #else
53   #define __Pyx_PyCFunction_Call PyCFunction_Call
54 #endif
55
56 #if PY_VERSION_HEX < 0x02050000
57   typedef int Py_ssize_t;
58   #define PY_SSIZE_T_MAX INT_MAX
59   #define PY_SSIZE_T_MIN INT_MIN
60   #define PY_FORMAT_SIZE_T ""
61   #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
62   #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
63   #define PyNumber_Index(o)    PyNumber_Int(o)
64   #define PyIndex_Check(o)     PyNumber_Check(o)
65   #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
66   #define __PYX_BUILD_PY_SSIZE_T "i"
67 #else
68   #define __PYX_BUILD_PY_SSIZE_T "n"
69 #endif
70
71 #if PY_VERSION_HEX < 0x02060000
72   #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
73   #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
74   #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
75   #define PyVarObject_HEAD_INIT(type, size) \
76           PyObject_HEAD_INIT(type) size,
77   #define PyType_Modified(t)
78
79   typedef struct {
80      void *buf;
81      PyObject *obj;
82      Py_ssize_t len;
83      Py_ssize_t itemsize;
84      int readonly;
85      int ndim;
86      char *format;
87      Py_ssize_t *shape;
88      Py_ssize_t *strides;
89      Py_ssize_t *suboffsets;
90      void *internal;
91   } Py_buffer;
92
93   #define PyBUF_SIMPLE 0
94   #define PyBUF_WRITABLE 0x0001
95   #define PyBUF_FORMAT 0x0004
96   #define PyBUF_ND 0x0008
97   #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
98   #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
99   #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
100   #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
101   #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
102   #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
103   #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
104
105   typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
106   typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
107 #endif
108
109 #if PY_MAJOR_VERSION < 3
110   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
111   #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
112           PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
113 #else
114   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
115   #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
116           PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
117 #endif
118
119 #if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
120   #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
121 #endif
122
123 #if PY_MAJOR_VERSION >= 3
124   #define Py_TPFLAGS_CHECKTYPES 0
125   #define Py_TPFLAGS_HAVE_INDEX 0
126 #endif
127
128 #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
129   #define Py_TPFLAGS_HAVE_NEWBUFFER 0
130 #endif
131
132
133 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH)
134   #define CYTHON_PEP393_ENABLED 1
135   #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
136   #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
137 #else
138   #define CYTHON_PEP393_ENABLED 0
139   #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
140   #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
141 #endif
142
143 #if PY_MAJOR_VERSION >= 3
144   #define PyBaseString_Type            PyUnicode_Type
145   #define PyStringObject               PyUnicodeObject
146   #define PyString_Type                PyUnicode_Type
147   #define PyString_Check               PyUnicode_Check
148   #define PyString_CheckExact          PyUnicode_CheckExact
149 #endif
150
151 #if PY_VERSION_HEX < 0x02060000
152   #define PyBytesObject                PyStringObject
153   #define PyBytes_Type                 PyString_Type
154   #define PyBytes_Check                PyString_Check
155   #define PyBytes_CheckExact           PyString_CheckExact
156   #define PyBytes_FromString           PyString_FromString
157   #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
158   #define PyBytes_FromFormat           PyString_FromFormat
159   #define PyBytes_DecodeEscape         PyString_DecodeEscape
160   #define PyBytes_AsString             PyString_AsString
161   #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
162   #define PyBytes_Size                 PyString_Size
163   #define PyBytes_AS_STRING            PyString_AS_STRING
164   #define PyBytes_GET_SIZE             PyString_GET_SIZE
165   #define PyBytes_Repr                 PyString_Repr
166   #define PyBytes_Concat               PyString_Concat
167   #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
168 #endif
169
170 #if PY_VERSION_HEX < 0x02060000
171   #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
172   #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
173 #endif
174 #ifndef PySet_CheckExact
175   #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
176 #endif
177
178 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
179
180 #if PY_MAJOR_VERSION >= 3
181   #define PyIntObject                  PyLongObject
182   #define PyInt_Type                   PyLong_Type
183   #define PyInt_Check(op)              PyLong_Check(op)
184   #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
185   #define PyInt_FromString             PyLong_FromString
186   #define PyInt_FromUnicode            PyLong_FromUnicode
187   #define PyInt_FromLong               PyLong_FromLong
188   #define PyInt_FromSize_t             PyLong_FromSize_t
189   #define PyInt_FromSsize_t            PyLong_FromSsize_t
190   #define PyInt_AsLong                 PyLong_AsLong
191   #define PyInt_AS_LONG                PyLong_AS_LONG
192   #define PyInt_AsSsize_t              PyLong_AsSsize_t
193   #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
194   #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
195 #endif
196
197 #if PY_MAJOR_VERSION >= 3
198   #define PyBoolObject                 PyLongObject
199 #endif
200
201 #if PY_VERSION_HEX < 0x03020000
202   typedef long Py_hash_t;
203   #define __Pyx_PyInt_FromHash_t PyInt_FromLong
204   #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
205 #else
206   #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
207   #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
208 #endif
209
210 #if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
211   #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
212   #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
213   #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
214 #else
215   #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
216         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
217         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
218             (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
219   #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
220         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
221         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
222             (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
223   #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
224         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
225         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
226             (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
227 #endif
228
229 #if PY_MAJOR_VERSION >= 3
230   #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
231 #endif
232
233 #if PY_VERSION_HEX < 0x02050000
234   #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
235   #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
236   #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
237 #else
238   #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
239   #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
240   #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
241 #endif
242
243 #if PY_VERSION_HEX < 0x02050000
244   #define __Pyx_NAMESTR(n) ((char *)(n))
245   #define __Pyx_DOCSTR(n)  ((char *)(n))
246 #else
247   #define __Pyx_NAMESTR(n) (n)
248   #define __Pyx_DOCSTR(n)  (n)
249 #endif
250
251 #if PY_MAJOR_VERSION >= 3
252   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
253   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
254 #else
255   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
256   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
257 #endif
258
259 #ifndef __PYX_EXTERN_C
260   #ifdef __cplusplus
261     #define __PYX_EXTERN_C extern "C"
262   #else
263     #define __PYX_EXTERN_C extern
264   #endif
265 #endif
266
267 #if defined(WIN32) || defined(MS_WINDOWS)
268 #define _USE_MATH_DEFINES
269 #endif
270 #include <math.h>
271 #define __PYX_HAVE__csamtools
272 #define __PYX_HAVE_API__csamtools
273 #include "string.h"
274 #include "stdlib.h"
275 #include "math.h"
276 #include "stdio.h"
277 #include "ctype.h"
278 #include "unistd.h"
279 #include "razf.h"
280 #include "stdint.h"
281 #include "bam.h"
282 #include "sam.h"
283 #include "faidx.h"
284 #include "pysam_util.h"
285 #include "pythread.h"
286 #ifdef _OPENMP
287 #include <omp.h>
288 #endif /* _OPENMP */
289
290 #ifdef PYREX_WITHOUT_ASSERTIONS
291 #define CYTHON_WITHOUT_ASSERTIONS
292 #endif
293
294
295 /* inline attribute */
296 #ifndef CYTHON_INLINE
297   #if defined(__GNUC__)
298     #define CYTHON_INLINE __inline__
299   #elif defined(_MSC_VER)
300     #define CYTHON_INLINE __inline
301   #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
302     #define CYTHON_INLINE inline
303   #else
304     #define CYTHON_INLINE
305   #endif
306 #endif
307
308 /* unused attribute */
309 #ifndef CYTHON_UNUSED
310 # if defined(__GNUC__)
311 #   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
312 #     define CYTHON_UNUSED __attribute__ ((__unused__))
313 #   else
314 #     define CYTHON_UNUSED
315 #   endif
316 # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
317 #   define CYTHON_UNUSED __attribute__ ((__unused__))
318 # else
319 #   define CYTHON_UNUSED
320 # endif
321 #endif
322
323 typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
324
325
326 /* Type Conversion Predeclarations */
327
328 #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
329 #define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))
330
331 #define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
332 #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
333 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
334 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
335
336 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
337 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
338 static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
339
340 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
341 #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
342
343 #ifdef __GNUC__
344   /* Test for GCC > 2.95 */
345   #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
346     #define likely(x)   __builtin_expect(!!(x), 1)
347     #define unlikely(x) __builtin_expect(!!(x), 0)
348   #else /* __GNUC__ > 2 ... */
349     #define likely(x)   (x)
350     #define unlikely(x) (x)
351   #endif /* __GNUC__ > 2 ... */
352 #else /* __GNUC__ */
353   #define likely(x)   (x)
354   #define unlikely(x) (x)
355 #endif /* __GNUC__ */
356     
357 static PyObject *__pyx_m;
358 static PyObject *__pyx_b;
359 static PyObject *__pyx_empty_tuple;
360 static PyObject *__pyx_empty_bytes;
361 static int __pyx_lineno;
362 static int __pyx_clineno = 0;
363 static const char * __pyx_cfilenm= __FILE__;
364 static const char *__pyx_filename;
365
366
367 static const char *__pyx_f[] = {
368   "csamtools.pyx",
369   "bool.pxd",
370   "complex.pxd",
371 };
372
373 /*--- Type declarations ---*/
374 struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr;
375 struct __pyx_obj_9csamtools_IteratorRow;
376 struct __pyx_obj_9csamtools_IteratorRowAllRefs;
377 struct __pyx_obj_9csamtools_IteratorRowAll;
378 struct __pyx_obj_9csamtools_PileupProxy;
379 struct __pyx_obj_9csamtools_AlignedRead;
380 struct __pyx_obj_9csamtools_Fastafile;
381 struct __pyx_obj_9csamtools_IteratorRowSelection;
382 struct __pyx_obj_9csamtools_IteratorColumn;
383 struct __pyx_obj_9csamtools_IteratorColumnAllRefs;
384 struct __pyx_obj_9csamtools_IteratorRowRegion;
385 struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr;
386 struct __pyx_obj_9csamtools_Samfile;
387 struct __pyx_obj_9csamtools_SNPCall;
388 struct __pyx_obj_9csamtools_IndexedReads;
389 struct __pyx_obj_9csamtools_IteratorColumnRegion;
390 struct __pyx_obj_9csamtools_PileupRead;
391 struct __pyx_t_9csamtools___iterdata;
392 typedef struct __pyx_t_9csamtools___iterdata __pyx_t_9csamtools___iterdata;
393 struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData;
394 struct __pyx_t_9csamtools_MateData;
395 typedef struct __pyx_t_9csamtools_MateData __pyx_t_9csamtools_MateData;
396
397 /* "csamtools.pxd":394
398  * # Utility types
399  * 
400  * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
401  *     samfile_t * samfile
402  *     bam_iter_t iter
403  */
404 struct __pyx_t_9csamtools___iterdata {
405   samfile_t *samfile;
406   bam_iter_t iter;
407   faidx_t *fastafile;
408   int tid;
409   char *seq;
410   int seq_len;
411 };
412
413 /* "csamtools.pxd":523
414  *     cdef char * getSequence( self )
415  *     cdef setMask( self, mask )
416  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
417  *                             int tid,
418  *                             int start,
419  */
420 struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData {
421   int __pyx_n;
422   int reopen;
423 };
424
425 /* "csamtools.pyx":518
426  *      counter[0] += 1;
427  * 
428  * ctypedef struct MateData:             # <<<<<<<<<<<<<<
429  *      char * name
430  *      bam1_t * mate
431  */
432 struct __pyx_t_9csamtools_MateData {
433   char *name;
434   bam1_t *mate;
435   uint32_t flag;
436 };
437
438 /* "csamtools.pyx":140
439  * cdef char* CODE2CIGAR= "MIDNSHP=X"
440  * if IS_PYTHON3:
441  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
442  * else:
443  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
444  */
445 struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr {
446   PyObject_HEAD
447   PyObject *__pyx_v_x;
448   PyObject *__pyx_v_y;
449   PyObject *__pyx_t_0;
450   PyObject *__pyx_t_1;
451   PyObject *(*__pyx_t_2)(PyObject *);
452 };
453
454
455 /* "csamtools.pxd":464
456  *     cdef uint32_t _is_tail
457  * 
458  * cdef class IteratorRow:             # <<<<<<<<<<<<<<
459  *     pass
460  * 
461  */
462 struct __pyx_obj_9csamtools_IteratorRow {
463   PyObject_HEAD
464 };
465
466
467 /* "csamtools.pxd":487
468  *     cdef int cnext(self)
469  * 
470  * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
471  *     cdef Samfile     samfile
472  *     cdef int         tid
473  */
474 struct __pyx_obj_9csamtools_IteratorRowAllRefs {
475   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
476   struct __pyx_obj_9csamtools_Samfile *samfile;
477   int tid;
478   struct __pyx_obj_9csamtools_IteratorRowRegion *rowiter;
479 };
480
481
482 /* "csamtools.pxd":480
483  *     cdef int cnext(self)
484  * 
485  * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
486  *     cdef bam1_t * b
487  *     cdef samfile_t * fp
488  */
489 struct __pyx_obj_9csamtools_IteratorRowAll {
490   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
491   struct __pyx_vtabstruct_9csamtools_IteratorRowAll *__pyx_vtab;
492   bam1_t *b;
493   samfile_t *fp;
494   int owns_samfile;
495 };
496
497
498 /* "csamtools.pxd":449
499  *     cdef char * _getrname( self, int tid )
500  * 
501  * cdef class PileupProxy:             # <<<<<<<<<<<<<<
502  *     cdef bam_pileup1_t ** plp
503  *     cdef int tid
504  */
505 struct __pyx_obj_9csamtools_PileupProxy {
506   PyObject_HEAD
507   bam_pileup1_t **plp;
508   int tid;
509   int pos;
510   int n_pu;
511 };
512
513
514 /* "csamtools.pxd":415
515  *     cdef char * _fetch( self, char * reference, int start, int end, int * length )
516  * 
517  * cdef class AlignedRead:             # <<<<<<<<<<<<<<
518  * 
519  *     # object that this AlignedRead represents
520  */
521 struct __pyx_obj_9csamtools_AlignedRead {
522   PyObject_HEAD
523   bam1_t *_delegate;
524 };
525
526
527 /* "csamtools.pxd":408
528  * # Note: need to declare all C fields and methods here
529  * #
530  * cdef class Fastafile:             # <<<<<<<<<<<<<<
531  *     cdef char * _filename
532  *     # pointer to fastafile
533  */
534 struct __pyx_obj_9csamtools_Fastafile {
535   PyObject_HEAD
536   struct __pyx_vtabstruct_9csamtools_Fastafile *__pyx_vtab;
537   char *_filename;
538   faidx_t *fastafile;
539 };
540
541
542 /* "csamtools.pxd":492
543  *     cdef IteratorRowRegion rowiter
544  * 
545  * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
546  *     cdef bam1_t * b
547  *     cdef int current_pos
548  */
549 struct __pyx_obj_9csamtools_IteratorRowSelection {
550   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
551   struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *__pyx_vtab;
552   bam1_t *b;
553   int current_pos;
554   samfile_t *fp;
555   PyObject *positions;
556   int owns_samfile;
557 };
558
559
560 /* "csamtools.pxd":504
561  *     cdef int cnext(self)
562  * 
563  * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
564  * 
565  *     # result of the last plbuf_push
566  */
567 struct __pyx_obj_9csamtools_IteratorColumn {
568   PyObject_HEAD
569   struct __pyx_vtabstruct_9csamtools_IteratorColumn *__pyx_vtab;
570   struct __pyx_obj_9csamtools_IteratorRowRegion *iter;
571   int tid;
572   int pos;
573   int n_plp;
574   int mask;
575   const bam_pileup1_t * plp;
576   bam_plp_t pileup_iter;
577   __pyx_t_9csamtools___iterdata iterdata;
578   struct __pyx_obj_9csamtools_Samfile *samfile;
579   struct __pyx_obj_9csamtools_Fastafile *fastafile;
580   PyObject *stepper;
581   int max_depth;
582 };
583
584
585 /* "csamtools.pxd":536
586  *     cdef int truncate
587  * 
588  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
589  *     pass
590  * 
591  */
592 struct __pyx_obj_9csamtools_IteratorColumnAllRefs {
593   struct __pyx_obj_9csamtools_IteratorColumn __pyx_base;
594 };
595
596
597 /* "csamtools.pxd":467
598  *     pass
599  * 
600  * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
601  *     cdef bam_iter_t             iter # iterator state object
602  *     cdef bam1_t *               b
603  */
604 struct __pyx_obj_9csamtools_IteratorRowRegion {
605   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
606   struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *__pyx_vtab;
607   bam_iter_t iter;
608   bam1_t *b;
609   int retval;
610   struct __pyx_obj_9csamtools_Samfile *samfile;
611   samfile_t *fp;
612   int owns_samfile;
613 };
614
615
616 /* "csamtools.pyx":142
617  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
618  * else:
619  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
620  * CIGAR_REGEX = re.compile( "([MIDNSHP=X])(\d+)" )
621  * 
622  */
623 struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr {
624   PyObject_HEAD
625   PyObject *__pyx_v_x;
626   PyObject *__pyx_v_y;
627   PyObject *__pyx_t_0;
628   PyObject *__pyx_t_1;
629   PyObject *(*__pyx_t_2)(PyObject *);
630 };
631
632
633 /* "csamtools.pxd":420
634  *     cdef bam1_t * _delegate
635  * 
636  * cdef class Samfile:             # <<<<<<<<<<<<<<
637  *     cdef char * _filename
638  *     # pointer to samfile
639  */
640 struct __pyx_obj_9csamtools_Samfile {
641   PyObject_HEAD
642   struct __pyx_vtabstruct_9csamtools_Samfile *__pyx_vtab;
643   char *_filename;
644   samfile_t *samfile;
645   bam_index_t *index;
646   int isbam;
647   int isstream;
648   int isremote;
649   bam1_t *b;
650   char *mode;
651   int64_t start_offset;
652 };
653
654
655 /* "csamtools.pyx":3222
656  *     return retval, out_stderr, out_stdout
657  * 
658  * cdef class SNPCall:             # <<<<<<<<<<<<<<
659  *     '''the results of a SNP call.'''
660  *     cdef int _tid
661  */
662 struct __pyx_obj_9csamtools_SNPCall {
663   PyObject_HEAD
664   int _tid;
665   int _pos;
666   char _reference_base;
667   char _genotype;
668   int _consensus_quality;
669   int _snp_quality;
670   int _rms_mapping_quality;
671   int _coverage;
672 };
673
674
675 /* "csamtools.pxd":539
676  *     pass
677  * 
678  * cdef class IndexedReads:             # <<<<<<<<<<<<<<
679  *     cdef Samfile samfile
680  *     cdef samfile_t * fp
681  */
682 struct __pyx_obj_9csamtools_IndexedReads {
683   PyObject_HEAD
684   struct __pyx_obj_9csamtools_Samfile *samfile;
685   samfile_t *fp;
686   PyObject *index;
687   int owns_samfile;
688 };
689
690
691 /* "csamtools.pxd":531
692  *     cdef reset( self, tid, start, end )
693  * 
694  * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
695  *     cdef int start
696  *     cdef int end
697  */
698 struct __pyx_obj_9csamtools_IteratorColumnRegion {
699   struct __pyx_obj_9csamtools_IteratorColumn __pyx_base;
700   int start;
701   int end;
702   int truncate;
703 };
704
705
706 /* "csamtools.pxd":455
707  *     cdef int n_pu
708  * 
709  * cdef class PileupRead:             # <<<<<<<<<<<<<<
710  *     cdef AlignedRead _alignment
711  *     cdef int32_t  _qpos
712  */
713 struct __pyx_obj_9csamtools_PileupRead {
714   PyObject_HEAD
715   struct __pyx_obj_9csamtools_AlignedRead *_alignment;
716   int32_t _qpos;
717   int _indel;
718   int _level;
719   uint32_t _is_del;
720   uint32_t _is_head;
721   uint32_t _is_tail;
722 };
723
724
725
726 /* "csamtools.pyx":1766
727  *     return ret
728  * 
729  * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
730  *     '''abstract base class for iterators over columns.
731  * 
732  */
733
734 struct __pyx_vtabstruct_9csamtools_IteratorColumn {
735   int (*cnext)(struct __pyx_obj_9csamtools_IteratorColumn *);
736   char *(*getSequence)(struct __pyx_obj_9csamtools_IteratorColumn *);
737   PyObject *(*setMask)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *);
738   PyObject *(*setupIteratorData)(struct __pyx_obj_9csamtools_IteratorColumn *, int, int, int, struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args);
739   PyObject *(*reset)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *);
740 };
741 static struct __pyx_vtabstruct_9csamtools_IteratorColumn *__pyx_vtabptr_9csamtools_IteratorColumn;
742
743
744 /* "csamtools.pyx":1931
745  *             self.iterdata.seq = NULL
746  * 
747  * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
748  *     '''iterates over a region only.
749  *     '''
750  */
751
752 struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion {
753   struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_base;
754 };
755 static struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *__pyx_vtabptr_9csamtools_IteratorColumnRegion;
756
757
758 /* "csamtools.pyx":1461
759  * 
760  * 
761  * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
762  *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
763  * 
764  */
765
766 struct __pyx_vtabstruct_9csamtools_IteratorRowRegion {
767   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowRegion *);
768   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowRegion *);
769 };
770 static struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *__pyx_vtabptr_9csamtools_IteratorRowRegion;
771
772
773 /* "csamtools.pyx":1641
774  *                 raise StopIteration
775  * 
776  * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
777  *     """*(Samfile samfile)*
778  * 
779  */
780
781 struct __pyx_vtabstruct_9csamtools_IteratorRowSelection {
782   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowSelection *);
783   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowSelection *);
784 };
785 static struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *__pyx_vtabptr_9csamtools_IteratorRowSelection;
786
787
788 /* "csamtools.pyx":1968
789  *                                      self.n_plp )
790  * 
791  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
792  *     """iterates over all columns by chaining iterators over each reference
793  *     """
794  */
795
796 struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs {
797   struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_base;
798 };
799 static struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *__pyx_vtabptr_9csamtools_IteratorColumnAllRefs;
800
801
802 /* "csamtools.pyx":545
803  * 
804  * 
805  * cdef class Samfile:             # <<<<<<<<<<<<<<
806  *     '''*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,
807  *          add_sq_text = False, check_header = True, check_sq = True )*
808  */
809
810 struct __pyx_vtabstruct_9csamtools_Samfile {
811   bam_header_t *(*_buildHeader)(struct __pyx_obj_9csamtools_Samfile *, PyObject *);
812   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_Samfile *);
813   int (*cnext)(struct __pyx_obj_9csamtools_Samfile *);
814   int (*write)(struct __pyx_obj_9csamtools_Samfile *, struct __pyx_obj_9csamtools_AlignedRead *, int __pyx_skip_dispatch);
815   char *(*_getrname)(struct __pyx_obj_9csamtools_Samfile *, int);
816 };
817 static struct __pyx_vtabstruct_9csamtools_Samfile *__pyx_vtabptr_9csamtools_Samfile;
818
819
820 /* "csamtools.pyx":375
821  * ## Public methods
822  * ######################################################################
823  * cdef class Fastafile:             # <<<<<<<<<<<<<<
824  *     '''*(filename)*
825  * 
826  */
827
828 struct __pyx_vtabstruct_9csamtools_Fastafile {
829   char *(*_fetch)(struct __pyx_obj_9csamtools_Fastafile *, char *, int, int, int *);
830 };
831 static struct __pyx_vtabstruct_9csamtools_Fastafile *__pyx_vtabptr_9csamtools_Fastafile;
832
833
834 /* "csamtools.pyx":1540
835  *         if self.owns_samfile: samclose( self.fp )
836  * 
837  * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
838  *     """*(Samfile samfile, int reopen = True)*
839  * 
840  */
841
842 struct __pyx_vtabstruct_9csamtools_IteratorRowAll {
843   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowAll *);
844   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowAll *);
845 };
846 static struct __pyx_vtabstruct_9csamtools_IteratorRowAll *__pyx_vtabptr_9csamtools_IteratorRowAll;
847 #ifndef CYTHON_REFNANNY
848   #define CYTHON_REFNANNY 0
849 #endif
850 #if CYTHON_REFNANNY
851   typedef struct {
852     void (*INCREF)(void*, PyObject*, int);
853     void (*DECREF)(void*, PyObject*, int);
854     void (*GOTREF)(void*, PyObject*, int);
855     void (*GIVEREF)(void*, PyObject*, int);
856     void* (*SetupContext)(const char*, int, const char*);
857     void (*FinishContext)(void**);
858   } __Pyx_RefNannyAPIStruct;
859   static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
860   static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
861   #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
862 #ifdef WITH_THREAD
863   #define __Pyx_RefNannySetupContext(name, acquire_gil) \
864           if (acquire_gil) { \
865               PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
866               __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
867               PyGILState_Release(__pyx_gilstate_save); \
868           } else { \
869               __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
870           }
871 #else
872   #define __Pyx_RefNannySetupContext(name, acquire_gil) \
873           __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
874 #endif
875   #define __Pyx_RefNannyFinishContext() \
876           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
877   #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
878   #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
879   #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
880   #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
881   #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
882   #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
883   #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
884   #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
885 #else
886   #define __Pyx_RefNannyDeclarations
887   #define __Pyx_RefNannySetupContext(name, acquire_gil)
888   #define __Pyx_RefNannyFinishContext()
889   #define __Pyx_INCREF(r) Py_INCREF(r)
890   #define __Pyx_DECREF(r) Py_DECREF(r)
891   #define __Pyx_GOTREF(r)
892   #define __Pyx_GIVEREF(r)
893   #define __Pyx_XINCREF(r) Py_XINCREF(r)
894   #define __Pyx_XDECREF(r) Py_XDECREF(r)
895   #define __Pyx_XGOTREF(r)
896   #define __Pyx_XGIVEREF(r)
897 #endif /* CYTHON_REFNANNY */
898 #define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
899 #define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
900
901 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
902
903 #ifndef CYTHON_PROFILE
904   #define CYTHON_PROFILE 1
905 #endif
906 #ifndef CYTHON_PROFILE_REUSE_FRAME
907   #define CYTHON_PROFILE_REUSE_FRAME 0
908 #endif
909 #if CYTHON_PROFILE
910   #include "compile.h"
911   #include "frameobject.h"
912   #include "traceback.h"
913   #if CYTHON_PROFILE_REUSE_FRAME
914     #define CYTHON_FRAME_MODIFIER static
915     #define CYTHON_FRAME_DEL
916   #else
917     #define CYTHON_FRAME_MODIFIER
918     #define CYTHON_FRAME_DEL Py_DECREF(__pyx_frame)
919   #endif
920   #define __Pyx_TraceDeclarations                                  \
921   static PyCodeObject *__pyx_frame_code = NULL;                      \
922   CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;           \
923   int __Pyx_use_tracing = 0;
924   #define __Pyx_TraceCall(funcname, srcfile, firstlineno)                            \
925   if (unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc)) {      \
926       __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);  \
927   }
928   #define __Pyx_TraceException()                                                           \
929   if (unlikely(__Pyx_use_tracing( && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
930       PyObject *exc_info = __Pyx_GetExceptionTuple();                                      \
931       if (exc_info) {                                                                      \
932           PyThreadState_GET()->c_profilefunc(                                              \
933               PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);  \
934           Py_DECREF(exc_info);                                                             \
935       }                                                                                    \
936   }
937   #define __Pyx_TraceReturn(result)                                                  \
938   if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
939       PyThreadState_GET()->c_profilefunc(                                            \
940           PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);     \
941       CYTHON_FRAME_DEL;                                                               \
942   }
943   static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
944   static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno); /*proto*/
945 #else
946   #define __Pyx_TraceDeclarations
947   #define __Pyx_TraceCall(funcname, srcfile, firstlineno)
948   #define __Pyx_TraceException()
949   #define __Pyx_TraceReturn(result)
950 #endif /* CYTHON_PROFILE */
951
952 static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
953 static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
954
955 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
956
957 #include <string.h>
958
959 static CYTHON_INLINE PyObject* __Pyx_tp_new(PyObject* type_obj) {
960     return (PyObject*) (((PyTypeObject*)(type_obj))->tp_new(
961         (PyTypeObject*)(type_obj), __pyx_empty_tuple, NULL));
962 }
963
964 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
965
966 static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/
967
968 static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
969
970 static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
971     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
972     const char* function_name); /*proto*/
973
974 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
975     Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
976
977 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
978     const char *name, int exact); /*proto*/
979
980 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
981
982 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
983     PyObject *r;
984     if (!j) return NULL;
985     r = PyObject_GetItem(o, j);
986     Py_DECREF(j);
987     return r;
988 }
989 #define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
990                                                     __Pyx_GetItemInt_List_Fast(o, i) : \
991                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
992 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
993     if (likely(o != Py_None)) {
994         if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
995             PyObject *r = PyList_GET_ITEM(o, i);
996             Py_INCREF(r);
997             return r;
998         }
999         else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
1000             PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
1001             Py_INCREF(r);
1002             return r;
1003         }
1004     }
1005     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
1006 }
1007 #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
1008                                                     __Pyx_GetItemInt_Tuple_Fast(o, i) : \
1009                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
1010 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
1011     if (likely(o != Py_None)) {
1012         if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
1013             PyObject *r = PyTuple_GET_ITEM(o, i);
1014             Py_INCREF(r);
1015             return r;
1016         }
1017         else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
1018             PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
1019             Py_INCREF(r);
1020             return r;
1021         }
1022     }
1023     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
1024 }
1025 #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
1026                                                     __Pyx_GetItemInt_Fast(o, i) : \
1027                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
1028 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
1029     if (PyList_CheckExact(o)) {
1030         Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
1031         if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
1032             PyObject *r = PyList_GET_ITEM(o, n);
1033             Py_INCREF(r);
1034             return r;
1035         }
1036     }
1037     else if (PyTuple_CheckExact(o)) {
1038         Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
1039         if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
1040             PyObject *r = PyTuple_GET_ITEM(o, n);
1041             Py_INCREF(r);
1042             return r;
1043         }
1044     }
1045     else if (likely(i >= 0)) {
1046         PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
1047         if (likely(m && m->sq_item)) {
1048             return m->sq_item(o, i);
1049         }
1050     }
1051     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
1052 }
1053
1054 static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
1055     if (likely(PyList_CheckExact(L))) {
1056         if (PyList_Append(L, x) < 0) return NULL;
1057         Py_INCREF(Py_None);
1058         return Py_None; /* this is just to have an accurate signature */
1059     }
1060     else {
1061         PyObject *r, *m;
1062         m = __Pyx_GetAttrString(L, "append");
1063         if (!m) return NULL;
1064         r = PyObject_CallFunctionObjArgs(m, x, NULL);
1065         Py_DECREF(m);
1066         return r;
1067     }
1068 }
1069
1070 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
1071
1072 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
1073
1074 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
1075
1076 static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) {
1077     return unlikely(b < 0) ? b : !b;
1078 }
1079 static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
1080     return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
1081 }
1082
1083 static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);
1084
1085 #if PY_MAJOR_VERSION >= 3
1086 static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
1087     PyObject *value;
1088     if (unlikely(d == Py_None)) {
1089         __Pyx_RaiseNoneIndexingError();
1090         return NULL;
1091     }
1092     value = PyDict_GetItemWithError(d, key);
1093     if (unlikely(!value)) {
1094         if (!PyErr_Occurred())
1095             PyErr_SetObject(PyExc_KeyError, key);
1096         return NULL;
1097     }
1098     Py_INCREF(value);
1099     return value;
1100 }
1101 #else
1102     #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
1103 #endif
1104
1105 static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
1106     PyObject* value;
1107 #if PY_MAJOR_VERSION >= 3
1108     value = PyDict_GetItemWithError(d, key);
1109     if (unlikely(!value)) {
1110         if (unlikely(PyErr_Occurred()))
1111             return NULL;
1112         value = default_value;
1113     }
1114     Py_INCREF(value);
1115 #else
1116     if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
1117         value = PyDict_GetItem(d, key);
1118         if (unlikely(!value)) {
1119             value = default_value;
1120         }
1121         Py_INCREF(value);
1122     } else {
1123         PyObject *m;
1124         m = __Pyx_GetAttrString(d, "get");
1125         if (!m) return NULL;
1126         value = PyObject_CallFunctionObjArgs(m, key,
1127                                              (default_value == Py_None) ? NULL : default_value, NULL);
1128         Py_DECREF(m);
1129     }
1130 #endif
1131     return value;
1132 }
1133
1134 static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */
1135
1136 static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */
1137
1138 static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);
1139
1140 #define __Pyx_DelItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
1141                                                     __Pyx_DelItemInt_Fast(o, i) : \
1142                                                     __Pyx_DelItem_Generic(o, to_py_func(i)))
1143 static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
1144     int r;
1145     if (!j) return -1;
1146     r = PyObject_DelItem(o, j);
1147     Py_DECREF(j);
1148     return r;
1149 }
1150 static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i) {
1151     if (likely(i >= 0)) {
1152         PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
1153         if (likely(m && m->sq_ass_item)) {
1154             return m->sq_ass_item(o, i, (PyObject *)NULL);
1155         }
1156     }
1157     return __Pyx_DelItem_Generic(o, PyInt_FromSsize_t(i));
1158 }
1159
1160 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
1161 static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
1162
1163 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
1164
1165 static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/
1166
1167 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
1168                                    PyObject *modname); /*proto*/
1169
1170 #define __Pyx_CyFunction_USED 1
1171 #include <structmember.h>
1172 #define __Pyx_CYFUNCTION_STATICMETHOD  0x01
1173 #define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
1174 #define __Pyx_CYFUNCTION_CCLASS        0x04
1175 #define __Pyx_CyFunction_GetClosure(f) \
1176     (((__pyx_CyFunctionObject *) (f))->func_closure)
1177 #define __Pyx_CyFunction_GetClassObj(f) \
1178     (((__pyx_CyFunctionObject *) (f))->func_classobj)
1179 #define __Pyx_CyFunction_Defaults(type, f) \
1180     ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
1181 #define __Pyx_CyFunction_SetDefaultsGetter(f, g) \
1182     ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
1183 typedef struct {
1184     PyCFunctionObject func;
1185     int flags;
1186     PyObject *func_dict;
1187     PyObject *func_weakreflist;
1188     PyObject *func_name;
1189     PyObject *func_doc;
1190     PyObject *func_code;
1191     PyObject *func_closure;
1192     PyObject *func_classobj; /* No-args super() class cell */
1193     void *defaults;
1194     int defaults_pyobjects;
1195     PyObject *defaults_tuple; /* Const defaults tuple */
1196     PyObject *(*defaults_getter)(PyObject *);
1197 } __pyx_CyFunctionObject;
1198 static PyTypeObject *__pyx_CyFunctionType = 0;
1199 #define __Pyx_CyFunction_NewEx(ml, flags, self, module, code) \
1200     __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, self, module, code)
1201 static PyObject *__Pyx_CyFunction_New(PyTypeObject *,
1202                                       PyMethodDef *ml, int flags,
1203                                       PyObject *self, PyObject *module,
1204                                       PyObject* code);
1205 static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
1206                                                          size_t size,
1207                                                          int pyobjects);
1208 static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
1209                                                             PyObject *tuple);
1210 static int __Pyx_CyFunction_init(void);
1211
1212 static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
1213
1214 static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/
1215
1216 #if PY_MAJOR_VERSION >= 3
1217 #define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
1218 #else
1219 #define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
1220 #endif
1221
1222 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int8_t(int8_t);
1223
1224 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t);
1225
1226 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int16_t(int16_t);
1227
1228 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint16_t(uint16_t);
1229
1230 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t);
1231
1232 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t);
1233
1234 static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject *);
1235
1236 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t);
1237
1238 static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject *);
1239
1240 static CYTHON_INLINE uint8_t __Pyx_PyInt_from_py_uint8_t(PyObject *);
1241
1242 static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject *);
1243
1244 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t);
1245
1246 static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
1247
1248 static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
1249
1250 static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
1251
1252 static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
1253
1254 static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
1255
1256 static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
1257
1258 static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
1259
1260 static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
1261
1262 static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
1263
1264 static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
1265
1266 static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
1267
1268 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
1269
1270 static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
1271
1272 static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
1273
1274 static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
1275
1276 static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
1277
1278 static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
1279
1280 #define __Pyx_Generator_USED
1281 #include <structmember.h>
1282 typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *);
1283 typedef struct {
1284     PyObject_HEAD
1285     __pyx_generator_body_t body;
1286     PyObject *closure;
1287     int is_running;
1288     int resume_label;
1289     PyObject *exc_type;
1290     PyObject *exc_value;
1291     PyObject *exc_traceback;
1292     PyObject *gi_weakreflist;
1293     PyObject *classobj;
1294 } __pyx_GeneratorObject;
1295 static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
1296                                                   PyObject *closure);
1297 static int __pyx_Generator_init(void);
1298
1299 static void __Pyx_WriteUnraisable(const char *name, int clineno,
1300                                   int lineno, const char *filename); /*proto*/
1301
1302 static int __Pyx_check_binary_version(void);
1303
1304 static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
1305
1306 #if !defined(__Pyx_PyIdentifier_FromString)
1307 #if PY_MAJOR_VERSION < 3
1308   #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
1309 #else
1310   #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
1311 #endif
1312 #endif
1313
1314 static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);  /*proto*/
1315
1316 static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
1317
1318 typedef struct {
1319     int code_line;
1320     PyCodeObject* code_object;
1321 } __Pyx_CodeObjectCacheEntry;
1322 struct __Pyx_CodeObjectCache {
1323     int count;
1324     int max_count;
1325     __Pyx_CodeObjectCacheEntry* entries;
1326 };
1327 static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
1328 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
1329 static PyCodeObject *__pyx_find_code_object(int code_line);
1330 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
1331
1332 static void __Pyx_AddTraceback(const char *funcname, int c_line,
1333                                int py_line, const char *filename); /*proto*/
1334
1335 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
1336
1337
1338 /* Module declarations from 'cpython.version' */
1339
1340 /* Module declarations from 'cpython.ref' */
1341
1342 /* Module declarations from 'cpython.exc' */
1343
1344 /* Module declarations from 'cpython.module' */
1345
1346 /* Module declarations from 'cpython.mem' */
1347
1348 /* Module declarations from 'cpython.tuple' */
1349
1350 /* Module declarations from 'cpython.list' */
1351
1352 /* Module declarations from 'libc.stdio' */
1353
1354 /* Module declarations from 'cpython.object' */
1355
1356 /* Module declarations from 'cpython.sequence' */
1357
1358 /* Module declarations from 'cpython.mapping' */
1359
1360 /* Module declarations from 'cpython.iterator' */
1361
1362 /* Module declarations from 'cpython.type' */
1363
1364 /* Module declarations from 'cpython.number' */
1365
1366 /* Module declarations from 'cpython.int' */
1367
1368 /* Module declarations from '__builtin__' */
1369
1370 /* Module declarations from 'cpython.bool' */
1371 static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
1372
1373 /* Module declarations from 'cpython.long' */
1374
1375 /* Module declarations from 'cpython.float' */
1376
1377 /* Module declarations from '__builtin__' */
1378
1379 /* Module declarations from 'cpython.complex' */
1380 static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
1381
1382 /* Module declarations from 'cpython.string' */
1383
1384 /* Module declarations from 'cpython.unicode' */
1385
1386 /* Module declarations from 'cpython.dict' */
1387
1388 /* Module declarations from 'cpython.instance' */
1389
1390 /* Module declarations from 'cpython.function' */
1391
1392 /* Module declarations from 'cpython.method' */
1393
1394 /* Module declarations from 'cpython.weakref' */
1395
1396 /* Module declarations from 'cpython.getargs' */
1397
1398 /* Module declarations from 'cpython.pythread' */
1399
1400 /* Module declarations from 'cpython.pystate' */
1401
1402 /* Module declarations from 'cpython.cobject' */
1403
1404 /* Module declarations from 'cpython.oldbuffer' */
1405
1406 /* Module declarations from 'cpython.set' */
1407
1408 /* Module declarations from 'cpython.buffer' */
1409
1410 /* Module declarations from 'cpython.bytes' */
1411
1412 /* Module declarations from 'cpython.pycapsule' */
1413
1414 /* Module declarations from 'cpython' */
1415
1416 /* Module declarations from 'csamtools' */
1417 static PyTypeObject *__pyx_ptype_9csamtools_Fastafile = 0;
1418 static PyTypeObject *__pyx_ptype_9csamtools_AlignedRead = 0;
1419 static PyTypeObject *__pyx_ptype_9csamtools_Samfile = 0;
1420 static PyTypeObject *__pyx_ptype_9csamtools_PileupProxy = 0;
1421 static PyTypeObject *__pyx_ptype_9csamtools_PileupRead = 0;
1422 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRow = 0;
1423 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowRegion = 0;
1424 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowAll = 0;
1425 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowAllRefs = 0;
1426 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowSelection = 0;
1427 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumn = 0;
1428 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumnRegion = 0;
1429 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumnAllRefs = 0;
1430 static PyTypeObject *__pyx_ptype_9csamtools_IndexedReads = 0;
1431 static PyTypeObject *__pyx_ptype_9csamtools_SNPCall = 0;
1432 static PyTypeObject *__pyx_ptype_9csamtools___pyx_scope_struct__genexpr = 0;
1433 static PyTypeObject *__pyx_ptype_9csamtools___pyx_scope_struct_1_genexpr = 0;
1434 static PyObject *__pyx_v_9csamtools__FILENAME_ENCODING = 0;
1435 static char *__pyx_v_9csamtools_CODE2CIGAR;
1436 static char *__pyx_v_9csamtools_bam_nt16_rev_table;
1437 static int __pyx_v_9csamtools_max_pos;
1438 static PyObject *__pyx_f_9csamtools_from_string_and_size(char *, size_t); /*proto*/
1439 static PyObject *__pyx_f_9csamtools__my_encodeFilename(PyObject *); /*proto*/
1440 static PyObject *__pyx_f_9csamtools__force_bytes(PyObject *); /*proto*/
1441 static CYTHON_INLINE PyObject *__pyx_f_9csamtools__force_cmdline_bytes(PyObject *); /*proto*/
1442 static PyObject *__pyx_f_9csamtools__charptr_to_str(char *); /*proto*/
1443 static PyObject *__pyx_f_9csamtools__force_str(PyObject *); /*proto*/
1444 static PyObject *__pyx_f_9csamtools_makeAlignedRead(bam1_t *); /*proto*/
1445 static PyObject *__pyx_f_9csamtools_makePileupProxy(bam_pileup1_t **, int, int, int); /*proto*/
1446 static PyObject *__pyx_f_9csamtools_makePileupRead(bam_pileup1_t *); /*proto*/
1447 static PyObject *__pyx_f_9csamtools_convertBinaryTagToList(uint8_t *); /*proto*/
1448 static int __pyx_f_9csamtools_fetch_callback(bam1_t *, void *); /*proto*/
1449 static int __pyx_f_9csamtools_pileup_callback(uint32_t, uint32_t, int, bam_pileup1_t *, void *); /*proto*/
1450 static int __pyx_f_9csamtools_pileup_fetch_callback(bam1_t *, void *); /*proto*/
1451 static int __pyx_f_9csamtools_count_callback(bam1_t *, void *); /*proto*/
1452 static int __pyx_f_9csamtools_mate_callback(bam1_t *, void *); /*proto*/
1453 static int __pyx_f_9csamtools___advance_all(void *, bam1_t *); /*proto*/
1454 static int __pyx_f_9csamtools___advance_snpcalls(void *, bam1_t *); /*proto*/
1455 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_start(bam1_t *); /*proto*/
1456 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_end(bam1_t *); /*proto*/
1457 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_seq_range(bam1_t *, uint32_t, uint32_t); /*proto*/
1458 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_qual_range(bam1_t *, uint32_t, uint32_t); /*proto*/
1459 #define __Pyx_MODULE_NAME "csamtools"
1460 int __pyx_module_is_main_csamtools = 0;
1461
1462 /* Implementation of 'csamtools' */
1463 static PyObject *__pyx_builtin_object;
1464 static PyObject *__pyx_builtin_TypeError;
1465 static PyObject *__pyx_builtin_enumerate;
1466 static PyObject *__pyx_builtin_ord;
1467 static PyObject *__pyx_builtin_map;
1468 static PyObject *__pyx_builtin_ValueError;
1469 static PyObject *__pyx_builtin_IOError;
1470 static PyObject *__pyx_builtin_OverflowError;
1471 static PyObject *__pyx_builtin_NotImplementedError;
1472 static PyObject *__pyx_builtin_OSError;
1473 static PyObject *__pyx_builtin_AttributeError;
1474 static PyObject *__pyx_builtin_zip;
1475 static PyObject *__pyx_builtin_sorted;
1476 static PyObject *__pyx_builtin_KeyError;
1477 static PyObject *__pyx_builtin_StopIteration;
1478 static PyObject *__pyx_builtin_min;
1479 static PyObject *__pyx_builtin_max;
1480 static PyObject *__pyx_builtin_chr;
1481 static PyObject *__pyx_builtin_open;
1482 static PyObject *__pyx_builtin_UnicodeDecodeError;
1483 static PyObject *__pyx_pf_9csamtools_2genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1484 static PyObject *__pyx_pf_9csamtools_5genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
1485 static PyObject *__pyx_pf_9csamtools_12PileupColumn___str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
1486 static PyObject *__pyx_pf_9csamtools_11StderrStore___init__(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1487 static PyObject *__pyx_pf_9csamtools_11StderrStore_2readAndRelease(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1488 static PyObject *__pyx_pf_9csamtools_11StderrStore_4release(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1489 static PyObject *__pyx_pf_9csamtools_11StderrStore_6__del__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
1490 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows___init__(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1491 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_2readAndRelease(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1492 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_4release(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self); /* proto */
1493 static int __pyx_pf_9csamtools_9Fastafile___cinit__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
1494 static PyObject *__pyx_pf_9csamtools_9Fastafile_2_isOpen(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self); /* proto */
1495 static Py_ssize_t __pyx_pf_9csamtools_9Fastafile_4__len__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self); /* proto */
1496 static PyObject *__pyx_pf_9csamtools_9Fastafile_6_open(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
1497 static PyObject *__pyx_pf_9csamtools_9Fastafile_8close(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self); /* proto */
1498 static void __pyx_pf_9csamtools_9Fastafile_10__dealloc__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self); /* proto */
1499 static PyObject *__pyx_pf_9csamtools_9Fastafile_8filename___get__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self); /* proto */
1500 static PyObject *__pyx_pf_9csamtools_9Fastafile_12fetch(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */
1501 static int __pyx_pf_9csamtools_7Samfile___cinit__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
1502 static PyObject *__pyx_pf_9csamtools_7Samfile_2_isOpen(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1503 static PyObject *__pyx_pf_9csamtools_7Samfile_4_hasIndex(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1504 static PyObject *__pyx_pf_9csamtools_7Samfile_6_open(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_9csamtools_Samfile *__pyx_v_template, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_text, PyObject *__pyx_v_header, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq); /* proto */
1505 static PyObject *__pyx_pf_9csamtools_7Samfile_8gettid(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
1506 static PyObject *__pyx_pf_9csamtools_7Samfile_10getrname(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
1507 static PyObject *__pyx_pf_9csamtools_7Samfile_12_parseRegion(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region); /* proto */
1508 static PyObject *__pyx_pf_9csamtools_7Samfile_14reset(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1509 static PyObject *__pyx_pf_9csamtools_7Samfile_16seek(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, uint64_t __pyx_v_offset, int __pyx_v_where); /* proto */
1510 static PyObject *__pyx_pf_9csamtools_7Samfile_18tell(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1511 static PyObject *__pyx_pf_9csamtools_7Samfile_20fetch(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof); /* proto */
1512 static PyObject *__pyx_pf_9csamtools_7Samfile_22mate(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_read); /* proto */
1513 static PyObject *__pyx_pf_9csamtools_7Samfile_24count(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof); /* proto */
1514 static PyObject *__pyx_pf_9csamtools_7Samfile_26pileup(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_callback, PyObject *__pyx_v_kwargs); /* proto */
1515 static PyObject *__pyx_pf_9csamtools_7Samfile_28close(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1516 static void __pyx_pf_9csamtools_7Samfile_30__dealloc__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1517 static PyObject *__pyx_pf_9csamtools_7Samfile_32write(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_read); /* proto */
1518 static PyObject *__pyx_pf_9csamtools_7Samfile_34__enter__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1519 static PyObject *__pyx_pf_9csamtools_7Samfile_36__exit__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */
1520 static PyObject *__pyx_pf_9csamtools_7Samfile_8filename___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1521 static PyObject *__pyx_pf_9csamtools_7Samfile_11nreferences___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1522 static PyObject *__pyx_pf_9csamtools_7Samfile_10references___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1523 static PyObject *__pyx_pf_9csamtools_7Samfile_7lengths___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1524 static PyObject *__pyx_pf_9csamtools_7Samfile_6mapped___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1525 static PyObject *__pyx_pf_9csamtools_7Samfile_8unmapped___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1526 static PyObject *__pyx_pf_9csamtools_7Samfile_4text___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1527 static PyObject *__pyx_pf_9csamtools_7Samfile_6header___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1528 static PyObject *__pyx_pf_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */
1529 static PyObject *__pyx_pf_9csamtools_7Samfile_40__iter__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1530 static PyObject *__pyx_pf_9csamtools_7Samfile_42__next__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self); /* proto */
1531 static int __pyx_pf_9csamtools_17IteratorRowRegion___cinit__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_reopen); /* proto */
1532 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_2__iter__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self); /* proto */
1533 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_4__next__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self); /* proto */
1534 static void __pyx_pf_9csamtools_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self); /* proto */
1535 static int __pyx_pf_9csamtools_14IteratorRowAll___cinit__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_reopen); /* proto */
1536 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_2__iter__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self); /* proto */
1537 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_4__next__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self); /* proto */
1538 static void __pyx_pf_9csamtools_14IteratorRowAll_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self); /* proto */
1539 static int __pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile); /* proto */
1540 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self); /* proto */
1541 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self); /* proto */
1542 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_6__next__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self); /* proto */
1543 static int __pyx_pf_9csamtools_20IteratorRowSelection___cinit__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_reopen); /* proto */
1544 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_2__iter__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self); /* proto */
1545 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_4__next__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self); /* proto */
1546 static void __pyx_pf_9csamtools_20IteratorRowSelection_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self); /* proto */
1547 static int __pyx_pf_9csamtools_14IteratorColumn___cinit__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */
1548 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_2__iter__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self); /* proto */
1549 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self); /* proto */
1550 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_4addReference(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, struct __pyx_obj_9csamtools_Fastafile *__pyx_v_fastafile); /* proto */
1551 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_6hasReference(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self); /* proto */
1552 static void __pyx_pf_9csamtools_14IteratorColumn_8__dealloc__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self); /* proto */
1553 static int __pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(struct __pyx_obj_9csamtools_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
1554 static PyObject *__pyx_pf_9csamtools_20IteratorColumnRegion_2__next__(struct __pyx_obj_9csamtools_IteratorColumnRegion *__pyx_v_self); /* proto */
1555 static int __pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_9csamtools_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
1556 static PyObject *__pyx_pf_9csamtools_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_9csamtools_IteratorColumnAllRefs *__pyx_v_self); /* proto */
1557 static int __pyx_pf_9csamtools_11AlignedRead___init__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1558 static void __pyx_pf_9csamtools_11AlignedRead_2__dealloc__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1559 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4__str__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1560 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6compare(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_other); /* proto */
1561 static Py_hash_t __pyx_pf_9csamtools_11AlignedRead_8__hash__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1562 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qname___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1563 static int __pyx_pf_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
1564 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5cigar___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1565 static int __pyx_pf_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_values); /* proto */
1566 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11cigarstring___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1567 static int __pyx_pf_9csamtools_11AlignedRead_11cigarstring_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_cigar); /* proto */
1568 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3seq___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1569 static int __pyx_pf_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_seq); /* proto */
1570 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qual___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1571 static int __pyx_pf_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
1572 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5query___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1573 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qqual___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1574 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6qstart___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1575 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qend___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1576 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1577 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tags___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1578 static int __pyx_pf_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
1579 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4flag___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1580 static int __pyx_pf_9csamtools_11AlignedRead_4flag_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */
1581 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rname___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1582 static int __pyx_pf_9csamtools_11AlignedRead_5rname_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
1583 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3tid___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1584 static int __pyx_pf_9csamtools_11AlignedRead_3tid_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
1585 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3pos___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1586 static int __pyx_pf_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pos); /* proto */
1587 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3bin___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1588 static int __pyx_pf_9csamtools_11AlignedRead_3bin_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_bin); /* proto */
1589 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4rlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1590 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4aend___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1591 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4alen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1592 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mapq___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1593 static int __pyx_pf_9csamtools_11AlignedRead_4mapq_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
1594 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1595 static int __pyx_pf_9csamtools_11AlignedRead_4mrnm_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
1596 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rnext___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1597 static int __pyx_pf_9csamtools_11AlignedRead_5rnext_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
1598 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mpos___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1599 static int __pyx_pf_9csamtools_11AlignedRead_4mpos_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
1600 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5pnext___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1601 static int __pyx_pf_9csamtools_11AlignedRead_5pnext_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
1602 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5isize___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1603 static int __pyx_pf_9csamtools_11AlignedRead_5isize_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
1604 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1605 static int __pyx_pf_9csamtools_11AlignedRead_4tlen_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
1606 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1607 static int __pyx_pf_9csamtools_11AlignedRead_9is_paired_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1608 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1609 static int __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1610 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1611 static int __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1612 static PyObject *__pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1613 static int __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1614 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1615 static int __pyx_pf_9csamtools_11AlignedRead_10is_reverse_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1616 static PyObject *__pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1617 static int __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1618 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1619 static int __pyx_pf_9csamtools_11AlignedRead_8is_read1_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1620 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1621 static int __pyx_pf_9csamtools_11AlignedRead_8is_read2_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1622 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1623 static int __pyx_pf_9csamtools_11AlignedRead_12is_secondary_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1624 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1625 static int __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1626 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1627 static int __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
1628 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9positions___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1629 static PyObject *__pyx_pf_9csamtools_11AlignedRead_13aligned_pairs___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1630 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10overlap(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */
1631 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12opt(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
1632 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14fancy_str(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self); /* proto */
1633 static int __pyx_pf_9csamtools_11PileupProxy___init__(CYTHON_UNUSED struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1634 static PyObject *__pyx_pf_9csamtools_11PileupProxy_2__str__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1635 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3tid___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1636 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1n___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1637 static int __pyx_pf_9csamtools_11PileupProxy_1n_2__set__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
1638 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3pos___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1639 static PyObject *__pyx_pf_9csamtools_11PileupProxy_7pileups___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self); /* proto */
1640 static int __pyx_pf_9csamtools_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1641 static PyObject *__pyx_pf_9csamtools_10PileupRead_2__str__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1642 static PyObject *__pyx_pf_9csamtools_10PileupRead_9alignment___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1643 static PyObject *__pyx_pf_9csamtools_10PileupRead_4qpos___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1644 static PyObject *__pyx_pf_9csamtools_10PileupRead_5indel___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1645 static PyObject *__pyx_pf_9csamtools_10PileupRead_6is_del___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1646 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_head___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1647 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_tail___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1648 static PyObject *__pyx_pf_9csamtools_10PileupRead_5level___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self); /* proto */
1649 static PyObject *__pyx_pf_9csamtools_4Outs___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id); /* proto */
1650 static PyObject *__pyx_pf_9csamtools_4Outs_2setdevice(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
1651 static PyObject *__pyx_pf_9csamtools_4Outs_4setfile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /* proto */
1652 static PyObject *__pyx_pf_9csamtools_4Outs_6setfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_fd); /* proto */
1653 static PyObject *__pyx_pf_9csamtools_4Outs_8restore(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
1654 static PyObject *__pyx_pf_9csamtools__samtools_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout); /* proto */
1655 static PyObject *__pyx_pf_9csamtools_7SNPCall_3tid___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1656 static PyObject *__pyx_pf_9csamtools_7SNPCall_3pos___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1657 static PyObject *__pyx_pf_9csamtools_7SNPCall_14reference_base___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1658 static PyObject *__pyx_pf_9csamtools_7SNPCall_8genotype___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1659 static PyObject *__pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1660 static PyObject *__pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1661 static PyObject *__pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1662 static PyObject *__pyx_pf_9csamtools_7SNPCall_8coverage___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1663 static PyObject *__pyx_pf_9csamtools_7SNPCall___str__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self); /* proto */
1664 static int __pyx_pf_9csamtools_12IndexedReads___init__(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_reopen); /* proto */
1665 static PyObject *__pyx_pf_9csamtools_12IndexedReads_2build(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self); /* proto */
1666 static PyObject *__pyx_pf_9csamtools_12IndexedReads_4find(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
1667 static void __pyx_pf_9csamtools_12IndexedReads_6__dealloc__(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self); /* proto */
1668 static char __pyx_k_1[] = "Argument must be string or unicode.";
1669 static char __pyx_k_3[] = "Argument must be string, bytes or unicode.";
1670 static char __pyx_k_5[] = "\t";
1671 static char __pyx_k_6[] = "\n";
1672 static char __pyx_k_7[] = "calling len() on closed file";
1673 static char __pyx_k_9[] = "could not open file `%s`";
1674 static char __pyx_k_10[] = "I/O operation on closed file";
1675 static char __pyx_k_13[] = "no sequence/region supplied.";
1676 static char __pyx_k_15[] = "invalid region: start (%i) > end (%i)";
1677 static char __pyx_k_16[] = "";
1678 static char __pyx_k_17[] = "start out of range (%i)";
1679 static char __pyx_k_18[] = "end out of range (%i)";
1680 static char __pyx_k_19[] = "%s:%i-%i";
1681 static char __pyx_k_24[] = "invalid file opening mode `%s`";
1682 static char __pyx_k_26[] = "-";
1683 static char __pyx_k_27[] = "http:";
1684 static char __pyx_k_28[] = "ftp:";
1685 static char __pyx_k_29[] = "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing";
1686 static char __pyx_k_30[] = "unequal names and lengths of reference sequences";
1687 static char __pyx_k_31[] = "@SQ\tSN:%s\tLN:%s\n";
1688 static char __pyx_k_32[] = "file `%s` not found";
1689 static char __pyx_k_33[] = "could not open file (mode='%s') - is it SAM/BAM format?";
1690 static char __pyx_k_34[] = "file does not have valid header (mode='%s') - is it BAM format?";
1691 static char __pyx_k_35[] = "file does not have valid header (mode='%s') - is it SAM format?";
1692 static char __pyx_k_36[] = "file header is empty (mode='%s') - is it SAM/BAM format?";
1693 static char __pyx_k_37[] = ".bai";
1694 static char __pyx_k_38[] = "error while opening index `%s` ";
1695 static char __pyx_k_41[] = "tid %i out of range 0<=tid<%i";
1696 static char __pyx_k_43[] = "[:-]";
1697 static char __pyx_k_45[] = "invalid reference `%s`";
1698 static char __pyx_k_46[] = "invalid coordinates: start (%i) > end (%i)";
1699 static char __pyx_k_48[] = "seek only available in bam files";
1700 static char __pyx_k_50[] = "seek no available in streams";
1701 static char __pyx_k_56[] = "fetch called on bamfile without index";
1702 static char __pyx_k_58[] = "callback functionality requires a region/reference";
1703 static char __pyx_k_60[] = "no index available for fetch";
1704 static char __pyx_k_62[] = "fetching by region is not available for sam files";
1705 static char __pyx_k_64[] = "callback not implemented yet";
1706 static char __pyx_k_66[] = "fetch called for samfile without header";
1707 static char __pyx_k_69[] = "read %s: is unpaired";
1708 static char __pyx_k_70[] = "mate %s: is unmapped";
1709 static char __pyx_k_71[] = "mate not found";
1710 static char __pyx_k_76[] = "counting functionality requires a region/reference";
1711 static char __pyx_k_79[] = "count for a region is not available for sam files";
1712 static char __pyx_k_82[] = "no index available for pileup";
1713 static char __pyx_k_85[] = "pileup of samfiles not implemented yet";
1714 static char __pyx_k_92[] = "Samfile.mapped only available in bam files";
1715 static char __pyx_k_95[] = "Samfile.unmapped only available in bam files";
1716 static char __pyx_k__A[] = "A";
1717 static char __pyx_k__B[] = "B";
1718 static char __pyx_k__C[] = "C";
1719 static char __pyx_k__D[] = "D";
1720 static char __pyx_k__F[] = "F";
1721 static char __pyx_k__H[] = "H";
1722 static char __pyx_k__I[] = "I";
1723 static char __pyx_k__S[] = "S";
1724 static char __pyx_k__Z[] = "Z";
1725 static char __pyx_k__a[] = "a";
1726 static char __pyx_k__b[] = "b";
1727 static char __pyx_k__c[] = "c";
1728 static char __pyx_k__d[] = "d";
1729 static char __pyx_k__f[] = "f";
1730 static char __pyx_k__h[] = "h";
1731 static char __pyx_k__i[] = "i";
1732 static char __pyx_k__n[] = "n";
1733 static char __pyx_k__r[] = "r";
1734 static char __pyx_k__s[] = "s";
1735 static char __pyx_k__w[] = "w";
1736 static char __pyx_k_100[] = "@";
1737 static char __pyx_k_102[] = "header line without '@': '%s'";
1738 static char __pyx_k_104[] = "header line with invalid type '%s': '%s'";
1739 static char __pyx_k_105[] = ":";
1740 static char __pyx_k_107[] = "unknown field code '%s' in record '%s'";
1741 static char __pyx_k_108[] = "multiple '%s' lines are not permitted";
1742 static char __pyx_k_109[] = "@%s";
1743 static char __pyx_k_110[] = "%s:%s";
1744 static char __pyx_k_111[] = "invalid type for record %s: %s, expected %s";
1745 static char __pyx_k_113[] = "incomplete sequence information in '%s'";
1746 static char __pyx_k_116[] = "can not iterate over samfile without header";
1747 static char __pyx_k_119[] = "no index available for iteration";
1748 static char __pyx_k_125[] = "can only use this iterator on bam files";
1749 static char __pyx_k_126[] = "reference sequence for '%s' (tid=%i) not found";
1750 static char __pyx_k_127[] = "unknown stepper option `%s` in IteratorColumn";
1751 static char __pyx_k_129[] = "error during iteration";
1752 static char __pyx_k_132[] = "Invalid clipping in CIGAR string";
1753 static char __pyx_k_135[] = "%c%i";
1754 static char __pyx_k_136[] = "quality and sequence mismatch: %i != %i";
1755 static char __pyx_k_137[] = "%c";
1756 static char __pyx_k_138[] = "<";
1757 static char __pyx_k_140[] = "integer %i out of range of BAM/SAM specification";
1758 static char __pyx_k_141[] = "2sccI%i%s";
1759 static char __pyx_k_145[] = "2sc%is";
1760 static char __pyx_k_147[] = "create_string_buffer";
1761 static char __pyx_k_148[] = "tag '%s' not present";
1762 static char __pyx_k_149[] = "unknown auxilliary type '%s'";
1763 static char __pyx_k_150[] = "Contig index";
1764 static char __pyx_k_151[] = "Mapped position on contig";
1765 static char __pyx_k_152[] = "Contig index for mate pair";
1766 static char __pyx_k_153[] = "Position of mate pair";
1767 static char __pyx_k_154[] = "Insert size";
1768 static char __pyx_k_155[] = "Binary flag";
1769 static char __pyx_k_156[] = "Count of cigar entries";
1770 static char __pyx_k_157[] = "Cigar entries";
1771 static char __pyx_k_158[] = "Mapping quality";
1772 static char __pyx_k_159[] = "Bam index bin number";
1773 static char __pyx_k_160[] = "Length of query name";
1774 static char __pyx_k_161[] = "Query name";
1775 static char __pyx_k_162[] = "Length of query sequence";
1776 static char __pyx_k_163[] = "Query sequence";
1777 static char __pyx_k_164[] = "Quality scores";
1778 static char __pyx_k_165[] = "Length of auxilary data";
1779 static char __pyx_k_166[] = "Maximum data length";
1780 static char __pyx_k_167[] = "Current data length";
1781 static char __pyx_k_168[] = "%-30s %-10s= %s";
1782 static char __pyx_k_169[] = "(";
1783 static char __pyx_k_170[] = ")";
1784 static char __pyx_k_171[] = "This class cannot be instantiated from Python";
1785 static char __pyx_k_173[] = "PileupProxy accessed after iterator finished";
1786 static char __pyx_k_177[] = "No such file or directory: '%s'";
1787 static char __pyx_k_178[] = "-o";
1788 static char __pyx_k_179[] = "option -o is forbidden in samtools view";
1789 static char __pyx_k_185[] = "can only IndexReads on bam files";
1790 static char __pyx_k_186[] = "read %s not found";
1791 static char __pyx_k_187[] = "number of :term:`filename` associated with this object.";
1792 static char __pyx_k_188[] = "the query name (None if not present)";
1793 static char __pyx_k_189[] = "the :term:`cigar` alignment (None if not present). The alignment\n        is returned as a list of operations. 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    |\n        +-----+--------------+-----+\n        |S    |BAM_CSOFT_CLIP|4    |\n        +-----+--------------+-----+\n        |H    |BAM_CHARD_CLIP|5    |\n        +-----+--------------+-----+\n        |P    |BAM_CPAD      |6    |\n        +-----+--------------+-----+\n        |=    |BAM_CEQUAL    |7    |\n        +-----+--------------+-----+\n        |X    |BAM_CDIFF     |8    |\n        +-----+--------------+-----+\n\n        ";
1794 static char __pyx_k_190[] = "the :term:`cigar` alignment as a string.\n        \n        Returns the empty string if not present.\n        ";
1795 static char __pyx_k_191[] = "read sequence bases, including :term:`soft clipped` bases (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient.";
1796 static char __pyx_k_192[] = "read sequence base qualities, including :term:`soft clipped` bases (None if not present).\n\n        In Python 3, this property is of type bytes and assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient.";
1797 static char __pyx_k_193[] = "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 algorithms, which may not require alignments\n        that begin at the first residue or end at the last.  In addition,\n        extra sequencing adapters, multiplex identifiers, and low-quality bases that\n        were not considered for alignment may have been retained.";
1798 static char __pyx_k_194[] = "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.";
1799 static char __pyx_k_195[] = "start index of the aligned query portion of the sequence (0-based, inclusive)";
1800 static char __pyx_k_196[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
1801 static char __pyx_k_197[] = "Length of the aligned query sequence";
1802 static char __pyx_k_198[] = "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        ";
1803 static char __pyx_k_199[] = "properties flag";
1804 static char __pyx_k_200[] = "\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()`\n\n        ";
1805 static char __pyx_k_201[] = "\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        ";
1806 static char __pyx_k_202[] = "0-based leftmost coordinate";
1807 static char __pyx_k_203[] = "properties bin";
1808 static char __pyx_k_204[] = "length of the read (read only). Returns 0 if not given.";
1809 static char __pyx_k_205[] = "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.";
1810 static char __pyx_k_206[] = "aligned length of the read on the reference genome.  Returns None if\n        not available.";
1811 static char __pyx_k_207[] = "mapping quality";
1812 static char __pyx_k_208[] = "the :term:`reference` id of the mate\n        deprecated, use RNEXT instead.\n        ";
1813 static char __pyx_k_209[] = "the :term:`reference` id of the mate ";
1814 static char __pyx_k_210[] = "the position of the mate\n        deprecated, use PNEXT instead.";
1815 static char __pyx_k_211[] = "the position of the mate";
1816 static char __pyx_k_212[] = "the insert size\n        deprecated: use tlen instead";
1817 static char __pyx_k_213[] = "the insert size";
1818 static char __pyx_k_214[] = "true if read is paired in sequencing";
1819 static char __pyx_k_215[] = "true if read is mapped in a proper pair";
1820 static char __pyx_k_216[] = "true if read itself is unmapped";
1821 static char __pyx_k_217[] = "true if the mate is unmapped";
1822 static char __pyx_k_218[] = "true if read is mapped to reverse strand";
1823 static char __pyx_k_219[] = "true is read is mapped to reverse strand";
1824 static char __pyx_k_220[] = "true if this is read1";
1825 static char __pyx_k_221[] = "true if this is read2";
1826 static char __pyx_k_222[] = "true if not primary alignment";
1827 static char __pyx_k_223[] = "true if QC failure";
1828 static char __pyx_k_224[] = "true if optical or PCR duplicate";
1829 static char __pyx_k_225[] = "a list of reference positions that this read aligns to.";
1830 static char __pyx_k_226[] = "a list of aligned read and reference positions.\n\n       Unaligned position are marked by None.\n       ";
1831 static char __pyx_k_227[] = "number of :term:`reference` sequences in the file.";
1832 static char __pyx_k_228[] = "tuple with the names of :term:`reference` sequences.";
1833 static char __pyx_k_229[] = "tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as\n        :attr:`pysam.Samfile.references`\n        ";
1834 static char __pyx_k_230[] = "total number of mapped reads in file.\n        ";
1835 static char __pyx_k_231[] = "total number of unmapped reads in file.\n        ";
1836 static char __pyx_k_232[] = "full contents of the :term:`sam file` header as a string.";
1837 static char __pyx_k_233[] = "header information within the :term:`sam file`. The records and fields are returned as\n        a two-level dictionary.\n        ";
1838 static char __pyx_k_234[] = "the chromosome ID as is defined in the header";
1839 static char __pyx_k_235[] = "number of reads mapping to this column.";
1840 static char __pyx_k_236[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
1841 static char __pyx_k_237[] = "a :class:`pysam.AlignedRead` object of the aligned read";
1842 static char __pyx_k_238[] = "position of the read base at the pileup site, 0-based";
1843 static char __pyx_k_239[] = "indel length; 0 for no indel, positive for ins and negative for del";
1844 static char __pyx_k_240[] = "1 iff the base on the padded read is a deletion";
1845 static char __pyx_k_241[] = "current sequence length.";
1846 static char __pyx_k_242[] = "nucleotide position of SNP.";
1847 static char __pyx_k_243[] = "reference base at pos. ``N`` if no reference sequence supplied.";
1848 static char __pyx_k_244[] = "the genotype called.";
1849 static char __pyx_k_245[] = "the genotype quality (Phred-scaled).";
1850 static char __pyx_k_246[] = "the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.";
1851 static char __pyx_k_247[] = "the root mean square (rms) of the mapping quality of all reads involved in the call.";
1852 static char __pyx_k_248[] = "coverage or read depth - the number of reads involved in the call.";
1853 static char __pyx_k_249[] = "getfilesystemencoding";
1854 static char __pyx_k_250[] = "MIDNSHP=X";
1855 static char __pyx_k_251[] = "([MIDNSHP=X])(\\d+)";
1856 static char __pyx_k_253[] = "=ACMGRSVTWYHKDBN";
1857 static char __pyx_k_256[] = "/ifs/devel/pysam/pysam/csamtools.pyx";
1858 static char __pyx_k_257[] = "A pileup column. A pileup column contains\n    all the reads that map to a certain target base.\n\n    tid\n        chromosome ID as is defined in the header\n    pos\n        the target base coordinate (0-based)\n    n\n        number of reads mapping to this column\n    pileups\n        list of reads (:class:`pysam.PileupRead`) aligned to this column\n    ";
1859 static char __pyx_k_266[] = "\n    stderr is captured.\n    ";
1860 static char __pyx_k_273[] = "does nothing. stderr can't be redirected on windows";
1861 static char __pyx_k_290[] = "http://mail.python.org/pipermail/python-list/2000-June/038406.html";
1862 static char __pyx_k__AS[] = "AS";
1863 static char __pyx_k__CL[] = "CL";
1864 static char __pyx_k__CN[] = "CN";
1865 static char __pyx_k__CO[] = "CO";
1866 static char __pyx_k__DS[] = "DS";
1867 static char __pyx_k__DT[] = "DT";
1868 static char __pyx_k__FO[] = "FO";
1869 static char __pyx_k__GO[] = "GO";
1870 static char __pyx_k__HD[] = "HD";
1871 static char __pyx_k__ID[] = "ID";
1872 static char __pyx_k__KS[] = "KS";
1873 static char __pyx_k__LB[] = "LB";
1874 static char __pyx_k__LN[] = "LN";
1875 static char __pyx_k__M5[] = "M5";
1876 static char __pyx_k__PG[] = "PG";
1877 static char __pyx_k__PI[] = "PI";
1878 static char __pyx_k__PL[] = "PL";
1879 static char __pyx_k__PN[] = "PN";
1880 static char __pyx_k__PU[] = "PU";
1881 static char __pyx_k__RG[] = "RG";
1882 static char __pyx_k__SM[] = "SM";
1883 static char __pyx_k__SN[] = "SN";
1884 static char __pyx_k__SO[] = "SO";
1885 static char __pyx_k__SP[] = "SP";
1886 static char __pyx_k__SQ[] = "SQ";
1887 static char __pyx_k__UR[] = "UR";
1888 static char __pyx_k__VN[] = "VN";
1889 static char __pyx_k__fd[] = "fd";
1890 static char __pyx_k__id[] = "id";
1891 static char __pyx_k__os[] = "os";
1892 static char __pyx_k__rU[] = "rU";
1893 static char __pyx_k__rb[] = "rb";
1894 static char __pyx_k__re[] = "re";
1895 static char __pyx_k__wb[] = "wb";
1896 static char __pyx_k__wh[] = "wh";
1897 static char __pyx_k__all[] = "all";
1898 static char __pyx_k__beg[] = "beg";
1899 static char __pyx_k__bin[] = "bin";
1900 static char __pyx_k__chr[] = "chr";
1901 static char __pyx_k__dup[] = "dup";
1902 static char __pyx_k__end[] = "end";
1903 static char __pyx_k__inf[] = "inf";
1904 static char __pyx_k__map[] = "map";
1905 static char __pyx_k__max[] = "max";
1906 static char __pyx_k__min[] = "min";
1907 static char __pyx_k__ofd[] = "ofd";
1908 static char __pyx_k__ord[] = "ord";
1909 static char __pyx_k__pos[] = "pos";
1910 static char __pyx_k__raw[] = "raw";
1911 static char __pyx_k__seq[] = "seq";
1912 static char __pyx_k__sys[] = "sys";
1913 static char __pyx_k__tid[] = "tid";
1914 static char __pyx_k__wbu[] = "wbu";
1915 static char __pyx_k__zip[] = "zip";
1916 static char __pyx_k__2scB[] = "2scB";
1917 static char __pyx_k__2scH[] = "2scH";
1918 static char __pyx_k__2scI[] = "2scI";
1919 static char __pyx_k__2scb[] = "2scb";
1920 static char __pyx_k__2scc[] = "2scc";
1921 static char __pyx_k__2scf[] = "2scf";
1922 static char __pyx_k__2sch[] = "2sch";
1923 static char __pyx_k__2sci[] = "2sci";
1924 static char __pyx_k__Outs[] = "Outs";
1925 static char __pyx_k__args[] = "args";
1926 static char __pyx_k__dup2[] = "dup2";
1927 static char __pyx_k__flag[] = "flag";
1928 static char __pyx_k__join[] = "join";
1929 static char __pyx_k__mapq[] = "mapq";
1930 static char __pyx_k__mask[] = "mask";
1931 static char __pyx_k__mode[] = "mode";
1932 static char __pyx_k__mpos[] = "mpos";
1933 static char __pyx_k__mrnm[] = "mrnm";
1934 static char __pyx_k__mtid[] = "mtid";
1935 static char __pyx_k__open[] = "open";
1936 static char __pyx_k__path[] = "path";
1937 static char __pyx_k__port[] = "port";
1938 static char __pyx_k__qpos[] = "qpos";
1939 static char __pyx_k__qseq[] = "qseq";
1940 static char __pyx_k__qual[] = "qual";
1941 static char __pyx_k__read[] = "read";
1942 static char __pyx_k__rlen[] = "rlen";
1943 static char __pyx_k__seek[] = "seek";
1944 static char __pyx_k__self[] = "self";
1945 static char __pyx_k__tags[] = "tags";
1946 static char __pyx_k__text[] = "text";
1947 static char __pyx_k__view[] = "view";
1948 static char __pyx_k__warn[] = "warn";
1949 static char __pyx_k___open[] = "_open";
1950 static char __pyx_k__ascii[] = "ascii";
1951 static char __pyx_k__bqual[] = "bqual";
1952 static char __pyx_k__cargs[] = "cargs";
1953 static char __pyx_k__cigar[] = "cigar";
1954 static char __pyx_k__close[] = "close";
1955 static char __pyx_k__flush[] = "flush";
1956 static char __pyx_k__indel[] = "indel";
1957 static char __pyx_k__index[] = "index";
1958 static char __pyx_k__isize[] = "isize";
1959 static char __pyx_k__items[] = "items";
1960 static char __pyx_k__l_aux[] = "l_aux";
1961 static char __pyx_k__level[] = "level";
1962 static char __pyx_k__qname[] = "qname";
1963 static char __pyx_k__rname[] = "rname";
1964 static char __pyx_k__setfd[] = "setfd";
1965 static char __pyx_k__split[] = "split";
1966 static char __pyx_k__start[] = "start";
1967 static char __pyx_k__strip[] = "strip";
1968 static char __pyx_k__types[] = "types";
1969 static char __pyx_k__where[] = "where";
1970 static char __pyx_k__write[] = "write";
1971 static char __pyx_k__ctypes[] = "ctypes";
1972 static char __pyx_k__decode[] = "decode";
1973 static char __pyx_k__encode[] = "encode";
1974 static char __pyx_k__exists[] = "exists";
1975 static char __pyx_k__extend[] = "extend";
1976 static char __pyx_k__fields[] = "fields";
1977 static char __pyx_k__fileno[] = "fileno";
1978 static char __pyx_k__gettid[] = "gettid";
1979 static char __pyx_k__header[] = "header";
1980 static char __pyx_k__is_del[] = "is_del";
1981 static char __pyx_k__l_qseq[] = "l_qseq";
1982 static char __pyx_k__m_data[] = "m_data";
1983 static char __pyx_k__method[] = "method";
1984 static char __pyx_k__object[] = "object";
1985 static char __pyx_k__offset[] = "offset";
1986 static char __pyx_k__record[] = "record";
1987 static char __pyx_k__region[] = "region";
1988 static char __pyx_k__remove[] = "remove";
1989 static char __pyx_k__reopen[] = "reopen";
1990 static char __pyx_k__retval[] = "retval";
1991 static char __pyx_k__sorted[] = "sorted";
1992 static char __pyx_k__stderr[] = "stderr";
1993 static char __pyx_k__stdout[] = "stdout";
1994 static char __pyx_k__struct[] = "struct";
1995 static char __pyx_k__system[] = "system";
1996 static char __pyx_k__IOError[] = "IOError";
1997 static char __pyx_k__OSError[] = "OSError";
1998 static char __pyx_k__O_CREAT[] = "O_CREAT";
1999 static char __pyx_k__Samfile[] = "Samfile";
2000 static char __pyx_k__Windows[] = "Windows";
2001 static char __pyx_k____all__[] = "__all__";
2002 static char __pyx_k____del__[] = "__del__";
2003 static char __pyx_k____str__[] = "__str__";
2004 static char __pyx_k___isOpen[] = "_isOpen";
2005 static char __pyx_k__compile[] = "compile";
2006 static char __pyx_k__findall[] = "findall";
2007 static char __pyx_k__is_head[] = "is_head";
2008 static char __pyx_k__is_tail[] = "is_tail";
2009 static char __pyx_k__islower[] = "islower";
2010 static char __pyx_k__isupper[] = "isupper";
2011 static char __pyx_k__l_qname[] = "l_qname";
2012 static char __pyx_k__lengths[] = "lengths";
2013 static char __pyx_k__mkstemp[] = "mkstemp";
2014 static char __pyx_k__n_cigar[] = "n_cigar";
2015 static char __pyx_k__pileups[] = "pileups";
2016 static char __pyx_k__release[] = "release";
2017 static char __pyx_k__restore[] = "restore";
2018 static char __pyx_k__samfile[] = "samfile";
2019 static char __pyx_k__setfile[] = "setfile";
2020 static char __pyx_k__stepper[] = "stepper";
2021 static char __pyx_k__streams[] = "streams";
2022 static char __pyx_k__KeyError[] = "KeyError";
2023 static char __pyx_k__O_WRONLY[] = "O_WRONLY";
2024 static char __pyx_k____dict__[] = "__dict__";
2025 static char __pyx_k____exit__[] = "__exit__";
2026 static char __pyx_k____init__[] = "__init__";
2027 static char __pyx_k____main__[] = "__main__";
2028 static char __pyx_k____test__[] = "__test__";
2029 static char __pyx_k__calcsize[] = "calcsize";
2030 static char __pyx_k__callback[] = "callback";
2031 static char __pyx_k__check_sq[] = "check_sq";
2032 static char __pyx_k__coverage[] = "coverage";
2033 static char __pyx_k__data_len[] = "data_len";
2034 static char __pyx_k__exc_type[] = "exc_type";
2035 static char __pyx_k__filename[] = "filename";
2036 static char __pyx_k__genotype[] = "genotype";
2037 static char __pyx_k__nextiter[] = "nextiter";
2038 static char __pyx_k__platform[] = "platform";
2039 static char __pyx_k__samtools[] = "samtools";
2040 static char __pyx_k__stderr_f[] = "stderr_f";
2041 static char __pyx_k__stderr_h[] = "stderr_h";
2042 static char __pyx_k__stdout_f[] = "stdout_f";
2043 static char __pyx_k__stdout_h[] = "stdout_h";
2044 static char __pyx_k__tempfile[] = "tempfile";
2045 static char __pyx_k__template[] = "template";
2046 static char __pyx_k__truncate[] = "truncate";
2047 static char __pyx_k__warnings[] = "warnings";
2048 static char __pyx_k__Fastafile[] = "Fastafile";
2049 static char __pyx_k__TypeError[] = "TypeError";
2050 static char __pyx_k____enter__[] = "__enter__";
2051 static char __pyx_k___hasIndex[] = "_hasIndex";
2052 static char __pyx_k__alignment[] = "alignment";
2053 static char __pyx_k__csamtools[] = "csamtools";
2054 static char __pyx_k__enumerate[] = "enumerate";
2055 static char __pyx_k__exc_value[] = "exc_value";
2056 static char __pyx_k__fastafile[] = "fastafile";
2057 static char __pyx_k__itertools[] = "itertools";
2058 static char __pyx_k__max_depth[] = "max_depth";
2059 static char __pyx_k__pack_into[] = "pack_into";
2060 static char __pyx_k__positions[] = "positions";
2061 static char __pyx_k__readlines[] = "readlines";
2062 static char __pyx_k__reference[] = "reference";
2063 static char __pyx_k__setdevice[] = "setdevice";
2064 static char __pyx_k__traceback[] = "traceback";
2065 static char __pyx_k__until_eof[] = "until_eof";
2066 static char __pyx_k__CIGAR2CODE[] = "CIGAR2CODE";
2067 static char __pyx_k__IS_PYTHON3[] = "IS_PYTHON3";
2068 static char __pyx_k__PileupRead[] = "PileupRead";
2069 static char __pyx_k__ValueError[] = "ValueError";
2070 static char __pyx_k___buildLine[] = "_buildLine";
2071 static char __pyx_k__out_stderr[] = "out_stderr";
2072 static char __pyx_k__out_stdout[] = "out_stdout";
2073 static char __pyx_k__references[] = "references";
2074 static char __pyx_k__startswith[] = "startswith";
2075 static char __pyx_k__AlignedRead[] = "AlignedRead";
2076 static char __pyx_k__CIGAR_REGEX[] = "CIGAR_REGEX";
2077 static char __pyx_k__IteratorRow[] = "IteratorRow";
2078 static char __pyx_k__PileupProxy[] = "PileupProxy";
2079 static char __pyx_k__StderrStore[] = "StderrStore";
2080 static char __pyx_k__add_sq_text[] = "add_sq_text";
2081 static char __pyx_k__collections[] = "collections";
2082 static char __pyx_k__defaultdict[] = "defaultdict";
2083 static char __pyx_k__nreferences[] = "nreferences";
2084 static char __pyx_k__snp_quality[] = "snp_quality";
2085 static char __pyx_k__stdout_save[] = "stdout_save";
2086 static char __pyx_k__IndexedReads[] = "IndexedReads";
2087 static char __pyx_k__PileupColumn[] = "PileupColumn";
2088 static char __pyx_k___parseRegion[] = "_parseRegion";
2089 static char __pyx_k__catch_stdout[] = "catch_stdout";
2090 static char __pyx_k__check_header[] = "check_header";
2091 static char __pyx_k__version_info[] = "version_info";
2092 static char __pyx_k__OverflowError[] = "OverflowError";
2093 static char __pyx_k__StopIteration[] = "StopIteration";
2094 static char __pyx_k__VALID_HEADERS[] = "VALID_HEADERS";
2095 static char __pyx_k__AttributeError[] = "AttributeError";
2096 static char __pyx_k__IteratorColumn[] = "IteratorColumn";
2097 static char __pyx_k__readAndRelease[] = "readAndRelease";
2098 static char __pyx_k__reference_base[] = "reference_base";
2099 static char __pyx_k__referencenames[] = "referencenames";
2100 static char __pyx_k__mapping_quality[] = "mapping_quality";
2101 static char __pyx_k____getattribute__[] = "__getattribute__";
2102 static char __pyx_k__referencelengths[] = "referencelengths";
2103 static char __pyx_k__consensus_quality[] = "consensus_quality";
2104 static char __pyx_k__StderrStoreWindows[] = "StderrStoreWindows";
2105 static char __pyx_k__UnicodeDecodeError[] = "UnicodeDecodeError";
2106 static char __pyx_k__VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
2107 static char __pyx_k__VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
2108 static char __pyx_k___samtools_dispatch[] = "_samtools_dispatch";
2109 static char __pyx_k__getdefaultencoding[] = "getdefaultencoding";
2110 static char __pyx_k__NotImplementedError[] = "NotImplementedError";
2111 static char __pyx_k__VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
2112 static PyObject *__pyx_kp_u_1;
2113 static PyObject *__pyx_kp_s_10;
2114 static PyObject *__pyx_kp_s_100;
2115 static PyObject *__pyx_kp_s_102;
2116 static PyObject *__pyx_kp_s_104;
2117 static PyObject *__pyx_kp_s_105;
2118 static PyObject *__pyx_kp_s_107;
2119 static PyObject *__pyx_kp_s_108;
2120 static PyObject *__pyx_kp_s_109;
2121 static PyObject *__pyx_kp_s_110;
2122 static PyObject *__pyx_kp_s_111;
2123 static PyObject *__pyx_kp_s_113;
2124 static PyObject *__pyx_kp_s_116;
2125 static PyObject *__pyx_kp_s_119;
2126 static PyObject *__pyx_kp_s_125;
2127 static PyObject *__pyx_kp_s_126;
2128 static PyObject *__pyx_kp_s_127;
2129 static PyObject *__pyx_kp_s_129;
2130 static PyObject *__pyx_kp_s_13;
2131 static PyObject *__pyx_kp_s_135;
2132 static PyObject *__pyx_kp_s_136;
2133 static PyObject *__pyx_kp_s_137;
2134 static PyObject *__pyx_kp_s_138;
2135 static PyObject *__pyx_kp_s_140;
2136 static PyObject *__pyx_kp_s_141;
2137 static PyObject *__pyx_kp_s_145;
2138 static PyObject *__pyx_n_s_147;
2139 static PyObject *__pyx_kp_s_148;
2140 static PyObject *__pyx_kp_s_149;
2141 static PyObject *__pyx_kp_s_15;
2142 static PyObject *__pyx_kp_s_150;
2143 static PyObject *__pyx_kp_s_151;
2144 static PyObject *__pyx_kp_s_152;
2145 static PyObject *__pyx_kp_s_153;
2146 static PyObject *__pyx_kp_s_154;
2147 static PyObject *__pyx_kp_s_155;
2148 static PyObject *__pyx_kp_s_156;
2149 static PyObject *__pyx_kp_s_157;
2150 static PyObject *__pyx_kp_s_158;
2151 static PyObject *__pyx_kp_s_159;
2152 static PyObject *__pyx_kp_b_16;
2153 static PyObject *__pyx_kp_s_16;
2154 static PyObject *__pyx_kp_s_160;
2155 static PyObject *__pyx_kp_s_161;
2156 static PyObject *__pyx_kp_s_162;
2157 static PyObject *__pyx_kp_s_163;
2158 static PyObject *__pyx_kp_s_164;
2159 static PyObject *__pyx_kp_s_165;
2160 static PyObject *__pyx_kp_s_166;
2161 static PyObject *__pyx_kp_s_167;
2162 static PyObject *__pyx_kp_s_168;
2163 static PyObject *__pyx_kp_s_169;
2164 static PyObject *__pyx_kp_s_17;
2165 static PyObject *__pyx_kp_s_170;
2166 static PyObject *__pyx_kp_s_171;
2167 static PyObject *__pyx_kp_s_173;
2168 static PyObject *__pyx_kp_s_177;
2169 static PyObject *__pyx_kp_s_178;
2170 static PyObject *__pyx_kp_s_179;
2171 static PyObject *__pyx_kp_s_18;
2172 static PyObject *__pyx_kp_s_185;
2173 static PyObject *__pyx_kp_s_186;
2174 static PyObject *__pyx_kp_s_19;
2175 static PyObject *__pyx_kp_s_24;
2176 static PyObject *__pyx_n_s_249;
2177 static PyObject *__pyx_kp_s_251;
2178 static PyObject *__pyx_kp_s_256;
2179 static PyObject *__pyx_kp_s_257;
2180 static PyObject *__pyx_kp_s_266;
2181 static PyObject *__pyx_kp_s_273;
2182 static PyObject *__pyx_kp_s_29;
2183 static PyObject *__pyx_kp_s_290;
2184 static PyObject *__pyx_kp_u_3;
2185 static PyObject *__pyx_kp_s_30;
2186 static PyObject *__pyx_kp_s_31;
2187 static PyObject *__pyx_kp_s_32;
2188 static PyObject *__pyx_kp_s_33;
2189 static PyObject *__pyx_kp_s_34;
2190 static PyObject *__pyx_kp_s_35;
2191 static PyObject *__pyx_kp_s_36;
2192 static PyObject *__pyx_kp_b_37;
2193 static PyObject *__pyx_kp_s_38;
2194 static PyObject *__pyx_kp_s_41;
2195 static PyObject *__pyx_kp_s_43;
2196 static PyObject *__pyx_kp_s_45;
2197 static PyObject *__pyx_kp_s_46;
2198 static PyObject *__pyx_kp_s_48;
2199 static PyObject *__pyx_kp_s_5;
2200 static PyObject *__pyx_kp_s_50;
2201 static PyObject *__pyx_kp_s_56;
2202 static PyObject *__pyx_kp_s_58;
2203 static PyObject *__pyx_kp_s_6;
2204 static PyObject *__pyx_kp_s_60;
2205 static PyObject *__pyx_kp_s_62;
2206 static PyObject *__pyx_kp_s_64;
2207 static PyObject *__pyx_kp_s_66;
2208 static PyObject *__pyx_kp_s_69;
2209 static PyObject *__pyx_kp_s_7;
2210 static PyObject *__pyx_kp_s_70;
2211 static PyObject *__pyx_kp_s_71;
2212 static PyObject *__pyx_kp_s_76;
2213 static PyObject *__pyx_kp_s_79;
2214 static PyObject *__pyx_kp_s_82;
2215 static PyObject *__pyx_kp_s_85;
2216 static PyObject *__pyx_kp_s_9;
2217 static PyObject *__pyx_kp_s_92;
2218 static PyObject *__pyx_kp_s_95;
2219 static PyObject *__pyx_kp_s__2scB;
2220 static PyObject *__pyx_kp_s__2scH;
2221 static PyObject *__pyx_kp_s__2scI;
2222 static PyObject *__pyx_kp_s__2scb;
2223 static PyObject *__pyx_kp_s__2scc;
2224 static PyObject *__pyx_kp_s__2scf;
2225 static PyObject *__pyx_kp_s__2sch;
2226 static PyObject *__pyx_kp_s__2sci;
2227 static PyObject *__pyx_n_s__A;
2228 static PyObject *__pyx_n_s__AS;
2229 static PyObject *__pyx_n_s__AlignedRead;
2230 static PyObject *__pyx_n_s__AttributeError;
2231 static PyObject *__pyx_n_s__B;
2232 static PyObject *__pyx_n_s__C;
2233 static PyObject *__pyx_n_s__CIGAR2CODE;
2234 static PyObject *__pyx_n_s__CIGAR_REGEX;
2235 static PyObject *__pyx_n_s__CL;
2236 static PyObject *__pyx_n_s__CN;
2237 static PyObject *__pyx_n_s__CO;
2238 static PyObject *__pyx_n_s__D;
2239 static PyObject *__pyx_n_s__DS;
2240 static PyObject *__pyx_n_s__DT;
2241 static PyObject *__pyx_n_s__F;
2242 static PyObject *__pyx_n_s__FO;
2243 static PyObject *__pyx_n_s__Fastafile;
2244 static PyObject *__pyx_n_s__GO;
2245 static PyObject *__pyx_n_s__H;
2246 static PyObject *__pyx_n_s__HD;
2247 static PyObject *__pyx_n_s__I;
2248 static PyObject *__pyx_n_s__ID;
2249 static PyObject *__pyx_n_s__IOError;
2250 static PyObject *__pyx_n_s__IS_PYTHON3;
2251 static PyObject *__pyx_n_s__IndexedReads;
2252 static PyObject *__pyx_n_s__IteratorColumn;
2253 static PyObject *__pyx_n_s__IteratorRow;
2254 static PyObject *__pyx_n_s__KS;
2255 static PyObject *__pyx_n_s__KeyError;
2256 static PyObject *__pyx_n_s__LB;
2257 static PyObject *__pyx_n_s__LN;
2258 static PyObject *__pyx_n_s__M5;
2259 static PyObject *__pyx_n_s__NotImplementedError;
2260 static PyObject *__pyx_n_s__OSError;
2261 static PyObject *__pyx_n_s__O_CREAT;
2262 static PyObject *__pyx_n_s__O_WRONLY;
2263 static PyObject *__pyx_n_s__Outs;
2264 static PyObject *__pyx_n_s__OverflowError;
2265 static PyObject *__pyx_n_s__PG;
2266 static PyObject *__pyx_n_s__PI;
2267 static PyObject *__pyx_n_s__PL;
2268 static PyObject *__pyx_n_s__PN;
2269 static PyObject *__pyx_n_s__PU;
2270 static PyObject *__pyx_n_s__PileupColumn;
2271 static PyObject *__pyx_n_s__PileupProxy;
2272 static PyObject *__pyx_n_s__PileupRead;
2273 static PyObject *__pyx_n_s__RG;
2274 static PyObject *__pyx_n_s__S;
2275 static PyObject *__pyx_n_s__SM;
2276 static PyObject *__pyx_n_s__SN;
2277 static PyObject *__pyx_n_s__SO;
2278 static PyObject *__pyx_n_s__SP;
2279 static PyObject *__pyx_n_s__SQ;
2280 static PyObject *__pyx_n_s__Samfile;
2281 static PyObject *__pyx_n_s__StderrStore;
2282 static PyObject *__pyx_n_s__StderrStoreWindows;
2283 static PyObject *__pyx_n_s__StopIteration;
2284 static PyObject *__pyx_n_s__TypeError;
2285 static PyObject *__pyx_n_s__UR;
2286 static PyObject *__pyx_n_s__UnicodeDecodeError;
2287 static PyObject *__pyx_n_s__VALID_HEADERS;
2288 static PyObject *__pyx_n_s__VALID_HEADER_FIELDS;
2289 static PyObject *__pyx_n_s__VALID_HEADER_ORDER;
2290 static PyObject *__pyx_n_s__VALID_HEADER_TYPES;
2291 static PyObject *__pyx_n_s__VN;
2292 static PyObject *__pyx_n_s__ValueError;
2293 static PyObject *__pyx_n_s__Windows;
2294 static PyObject *__pyx_n_s__Z;
2295 static PyObject *__pyx_n_s____all__;
2296 static PyObject *__pyx_n_s____del__;
2297 static PyObject *__pyx_n_s____dict__;
2298 static PyObject *__pyx_n_s____enter__;
2299 static PyObject *__pyx_n_s____exit__;
2300 static PyObject *__pyx_n_s____getattribute__;
2301 static PyObject *__pyx_n_s____init__;
2302 static PyObject *__pyx_n_s____main__;
2303 static PyObject *__pyx_n_s____str__;
2304 static PyObject *__pyx_n_s____test__;
2305 static PyObject *__pyx_n_s___buildLine;
2306 static PyObject *__pyx_n_s___hasIndex;
2307 static PyObject *__pyx_n_s___isOpen;
2308 static PyObject *__pyx_n_s___open;
2309 static PyObject *__pyx_n_s___parseRegion;
2310 static PyObject *__pyx_n_s___samtools_dispatch;
2311 static PyObject *__pyx_n_s__a;
2312 static PyObject *__pyx_n_s__add_sq_text;
2313 static PyObject *__pyx_n_s__alignment;
2314 static PyObject *__pyx_n_s__all;
2315 static PyObject *__pyx_n_s__args;
2316 static PyObject *__pyx_n_s__ascii;
2317 static PyObject *__pyx_n_s__b;
2318 static PyObject *__pyx_n_s__beg;
2319 static PyObject *__pyx_n_s__bin;
2320 static PyObject *__pyx_n_s__bqual;
2321 static PyObject *__pyx_n_s__c;
2322 static PyObject *__pyx_n_s__calcsize;
2323 static PyObject *__pyx_n_s__callback;
2324 static PyObject *__pyx_n_s__cargs;
2325 static PyObject *__pyx_n_s__catch_stdout;
2326 static PyObject *__pyx_n_s__check_header;
2327 static PyObject *__pyx_n_s__check_sq;
2328 static PyObject *__pyx_n_s__chr;
2329 static PyObject *__pyx_n_s__cigar;
2330 static PyObject *__pyx_n_s__close;
2331 static PyObject *__pyx_n_s__collections;
2332 static PyObject *__pyx_n_s__compile;
2333 static PyObject *__pyx_n_s__consensus_quality;
2334 static PyObject *__pyx_n_s__coverage;
2335 static PyObject *__pyx_n_s__csamtools;
2336 static PyObject *__pyx_n_s__ctypes;
2337 static PyObject *__pyx_n_s__d;
2338 static PyObject *__pyx_n_s__data_len;
2339 static PyObject *__pyx_n_s__decode;
2340 static PyObject *__pyx_n_s__defaultdict;
2341 static PyObject *__pyx_n_s__dup;
2342 static PyObject *__pyx_n_s__dup2;
2343 static PyObject *__pyx_n_s__encode;
2344 static PyObject *__pyx_n_s__end;
2345 static PyObject *__pyx_n_s__enumerate;
2346 static PyObject *__pyx_n_s__exc_type;
2347 static PyObject *__pyx_n_s__exc_value;
2348 static PyObject *__pyx_n_s__exists;
2349 static PyObject *__pyx_n_s__extend;
2350 static PyObject *__pyx_n_s__f;
2351 static PyObject *__pyx_n_s__fastafile;
2352 static PyObject *__pyx_n_s__fd;
2353 static PyObject *__pyx_n_s__fields;
2354 static PyObject *__pyx_n_s__filename;
2355 static PyObject *__pyx_n_s__fileno;
2356 static PyObject *__pyx_n_s__findall;
2357 static PyObject *__pyx_n_s__flag;
2358 static PyObject *__pyx_n_s__flush;
2359 static PyObject *__pyx_n_s__genotype;
2360 static PyObject *__pyx_n_s__getdefaultencoding;
2361 static PyObject *__pyx_n_s__gettid;
2362 static PyObject *__pyx_n_s__h;
2363 static PyObject *__pyx_n_s__header;
2364 static PyObject *__pyx_n_s__i;
2365 static PyObject *__pyx_n_s__id;
2366 static PyObject *__pyx_n_s__indel;
2367 static PyObject *__pyx_n_s__index;
2368 static PyObject *__pyx_n_s__inf;
2369 static PyObject *__pyx_n_s__is_del;
2370 static PyObject *__pyx_n_s__is_head;
2371 static PyObject *__pyx_n_s__is_tail;
2372 static PyObject *__pyx_n_s__isize;
2373 static PyObject *__pyx_n_s__islower;
2374 static PyObject *__pyx_n_s__isupper;
2375 static PyObject *__pyx_n_s__items;
2376 static PyObject *__pyx_n_s__itertools;
2377 static PyObject *__pyx_n_s__join;
2378 static PyObject *__pyx_n_s__l_aux;
2379 static PyObject *__pyx_n_s__l_qname;
2380 static PyObject *__pyx_n_s__l_qseq;
2381 static PyObject *__pyx_n_s__lengths;
2382 static PyObject *__pyx_n_s__level;
2383 static PyObject *__pyx_n_s__m_data;
2384 static PyObject *__pyx_n_s__map;
2385 static PyObject *__pyx_n_s__mapping_quality;
2386 static PyObject *__pyx_n_s__mapq;
2387 static PyObject *__pyx_n_s__mask;
2388 static PyObject *__pyx_n_s__max;
2389 static PyObject *__pyx_n_s__max_depth;
2390 static PyObject *__pyx_n_s__method;
2391 static PyObject *__pyx_n_s__min;
2392 static PyObject *__pyx_n_s__mkstemp;
2393 static PyObject *__pyx_n_s__mode;
2394 static PyObject *__pyx_n_s__mpos;
2395 static PyObject *__pyx_n_s__mrnm;
2396 static PyObject *__pyx_n_s__mtid;
2397 static PyObject *__pyx_n_s__n;
2398 static PyObject *__pyx_n_s__n_cigar;
2399 static PyObject *__pyx_n_s__nextiter;
2400 static PyObject *__pyx_n_s__nreferences;
2401 static PyObject *__pyx_n_s__object;
2402 static PyObject *__pyx_n_s__ofd;
2403 static PyObject *__pyx_n_s__offset;
2404 static PyObject *__pyx_n_s__open;
2405 static PyObject *__pyx_n_s__ord;
2406 static PyObject *__pyx_n_s__os;
2407 static PyObject *__pyx_n_s__out_stderr;
2408 static PyObject *__pyx_n_s__out_stdout;
2409 static PyObject *__pyx_n_s__pack_into;
2410 static PyObject *__pyx_n_s__path;
2411 static PyObject *__pyx_n_s__pileups;
2412 static PyObject *__pyx_n_s__platform;
2413 static PyObject *__pyx_n_s__port;
2414 static PyObject *__pyx_n_s__pos;
2415 static PyObject *__pyx_n_s__positions;
2416 static PyObject *__pyx_n_s__qname;
2417 static PyObject *__pyx_n_s__qpos;
2418 static PyObject *__pyx_n_s__qseq;
2419 static PyObject *__pyx_n_s__qual;
2420 static PyObject *__pyx_n_b__r;
2421 static PyObject *__pyx_n_s__r;
2422 static PyObject *__pyx_n_s__rU;
2423 static PyObject *__pyx_n_s__raw;
2424 static PyObject *__pyx_n_b__rb;
2425 static PyObject *__pyx_n_s__rb;
2426 static PyObject *__pyx_n_s__re;
2427 static PyObject *__pyx_n_s__read;
2428 static PyObject *__pyx_n_s__readAndRelease;
2429 static PyObject *__pyx_n_s__readlines;
2430 static PyObject *__pyx_n_s__record;
2431 static PyObject *__pyx_n_s__reference;
2432 static PyObject *__pyx_n_s__reference_base;
2433 static PyObject *__pyx_n_s__referencelengths;
2434 static PyObject *__pyx_n_s__referencenames;
2435 static PyObject *__pyx_n_s__references;
2436 static PyObject *__pyx_n_s__region;
2437 static PyObject *__pyx_n_s__release;
2438 static PyObject *__pyx_n_s__remove;
2439 static PyObject *__pyx_n_s__reopen;
2440 static PyObject *__pyx_n_s__restore;
2441 static PyObject *__pyx_n_s__retval;
2442 static PyObject *__pyx_n_s__rlen;
2443 static PyObject *__pyx_n_s__rname;
2444 static PyObject *__pyx_n_s__s;
2445 static PyObject *__pyx_n_s__samfile;
2446 static PyObject *__pyx_n_s__samtools;
2447 static PyObject *__pyx_n_s__seek;
2448 static PyObject *__pyx_n_s__self;
2449 static PyObject *__pyx_n_s__seq;
2450 static PyObject *__pyx_n_s__setdevice;
2451 static PyObject *__pyx_n_s__setfd;
2452 static PyObject *__pyx_n_s__setfile;
2453 static PyObject *__pyx_n_s__snp_quality;
2454 static PyObject *__pyx_n_s__sorted;
2455 static PyObject *__pyx_n_s__split;
2456 static PyObject *__pyx_n_s__start;
2457 static PyObject *__pyx_n_s__startswith;
2458 static PyObject *__pyx_n_s__stderr;
2459 static PyObject *__pyx_n_s__stderr_f;
2460 static PyObject *__pyx_n_s__stderr_h;
2461 static PyObject *__pyx_n_s__stdout;
2462 static PyObject *__pyx_n_s__stdout_f;
2463 static PyObject *__pyx_n_s__stdout_h;
2464 static PyObject *__pyx_n_s__stdout_save;
2465 static PyObject *__pyx_n_s__stepper;
2466 static PyObject *__pyx_n_s__streams;
2467 static PyObject *__pyx_n_s__strip;
2468 static PyObject *__pyx_n_s__struct;
2469 static PyObject *__pyx_n_s__sys;
2470 static PyObject *__pyx_n_s__system;
2471 static PyObject *__pyx_n_s__tags;
2472 static PyObject *__pyx_n_s__tempfile;
2473 static PyObject *__pyx_n_s__template;
2474 static PyObject *__pyx_n_s__text;
2475 static PyObject *__pyx_n_s__tid;
2476 static PyObject *__pyx_n_s__traceback;
2477 static PyObject *__pyx_n_s__truncate;
2478 static PyObject *__pyx_n_s__types;
2479 static PyObject *__pyx_n_s__until_eof;
2480 static PyObject *__pyx_n_s__version_info;
2481 static PyObject *__pyx_n_s__view;
2482 static PyObject *__pyx_n_s__w;
2483 static PyObject *__pyx_n_s__warn;
2484 static PyObject *__pyx_n_s__warnings;
2485 static PyObject *__pyx_n_s__wb;
2486 static PyObject *__pyx_n_s__wbu;
2487 static PyObject *__pyx_n_s__wh;
2488 static PyObject *__pyx_n_s__where;
2489 static PyObject *__pyx_n_s__write;
2490 static PyObject *__pyx_n_s__zip;
2491 static PyObject *__pyx_int_0;
2492 static PyObject *__pyx_int_1;
2493 static PyObject *__pyx_int_2;
2494 static PyObject *__pyx_int_3;
2495 static PyObject *__pyx_int_4;
2496 static PyObject *__pyx_int_8;
2497 static PyObject *__pyx_int_16;
2498 static PyObject *__pyx_int_32;
2499 static PyObject *__pyx_int_64;
2500 static PyObject *__pyx_int_128;
2501 static PyObject *__pyx_int_255;
2502 static PyObject *__pyx_int_256;
2503 static PyObject *__pyx_int_512;
2504 static PyObject *__pyx_int_neg_127;
2505 static PyObject *__pyx_int_0660;
2506 static PyObject *__pyx_int_1024;
2507 static PyObject *__pyx_int_8000;
2508 static PyObject *__pyx_int_65535;
2509 static PyObject *__pyx_int_neg_32767;
2510 static PyObject *__pyx_int_536870912;
2511 static PyObject *__pyx_int_4294967295;
2512 static PyObject *__pyx_int_neg_2147483648;
2513 static PyObject *__pyx_k_21;
2514 static PyObject *__pyx_k_22;
2515 static PyObject *__pyx_k_23;
2516 static PyObject *__pyx_k_54;
2517 static PyObject *__pyx_k_73;
2518 static int __pyx_k_128;
2519 static PyObject *__pyx_k_176;
2520 static PyObject *__pyx_k_tuple_2;
2521 static PyObject *__pyx_k_tuple_4;
2522 static PyObject *__pyx_k_tuple_8;
2523 static PyObject *__pyx_k_tuple_11;
2524 static PyObject *__pyx_k_tuple_12;
2525 static PyObject *__pyx_k_tuple_14;
2526 static PyObject *__pyx_k_tuple_20;
2527 static PyObject *__pyx_k_tuple_25;
2528 static PyObject *__pyx_k_tuple_39;
2529 static PyObject *__pyx_k_tuple_40;
2530 static PyObject *__pyx_k_tuple_42;
2531 static PyObject *__pyx_k_tuple_44;
2532 static PyObject *__pyx_k_tuple_47;
2533 static PyObject *__pyx_k_tuple_49;
2534 static PyObject *__pyx_k_tuple_51;
2535 static PyObject *__pyx_k_tuple_52;
2536 static PyObject *__pyx_k_tuple_53;
2537 static PyObject *__pyx_k_tuple_55;
2538 static PyObject *__pyx_k_tuple_57;
2539 static PyObject *__pyx_k_tuple_59;
2540 static PyObject *__pyx_k_tuple_61;
2541 static PyObject *__pyx_k_tuple_63;
2542 static PyObject *__pyx_k_tuple_65;
2543 static PyObject *__pyx_k_tuple_67;
2544 static PyObject *__pyx_k_tuple_68;
2545 static PyObject *__pyx_k_tuple_72;
2546 static PyObject *__pyx_k_tuple_74;
2547 static PyObject *__pyx_k_tuple_75;
2548 static PyObject *__pyx_k_tuple_77;
2549 static PyObject *__pyx_k_tuple_78;
2550 static PyObject *__pyx_k_tuple_80;
2551 static PyObject *__pyx_k_tuple_81;
2552 static PyObject *__pyx_k_tuple_83;
2553 static PyObject *__pyx_k_tuple_84;
2554 static PyObject *__pyx_k_tuple_86;
2555 static PyObject *__pyx_k_tuple_87;
2556 static PyObject *__pyx_k_tuple_88;
2557 static PyObject *__pyx_k_tuple_89;
2558 static PyObject *__pyx_k_tuple_90;
2559 static PyObject *__pyx_k_tuple_91;
2560 static PyObject *__pyx_k_tuple_93;
2561 static PyObject *__pyx_k_tuple_94;
2562 static PyObject *__pyx_k_tuple_96;
2563 static PyObject *__pyx_k_tuple_97;
2564 static PyObject *__pyx_k_tuple_98;
2565 static PyObject *__pyx_k_tuple_99;
2566 static PyObject *__pyx_k_tuple_101;
2567 static PyObject *__pyx_k_tuple_103;
2568 static PyObject *__pyx_k_tuple_106;
2569 static PyObject *__pyx_k_tuple_112;
2570 static PyObject *__pyx_k_tuple_114;
2571 static PyObject *__pyx_k_tuple_115;
2572 static PyObject *__pyx_k_tuple_117;
2573 static PyObject *__pyx_k_tuple_118;
2574 static PyObject *__pyx_k_tuple_120;
2575 static PyObject *__pyx_k_tuple_121;
2576 static PyObject *__pyx_k_tuple_122;
2577 static PyObject *__pyx_k_tuple_123;
2578 static PyObject *__pyx_k_tuple_124;
2579 static PyObject *__pyx_k_tuple_130;
2580 static PyObject *__pyx_k_tuple_131;
2581 static PyObject *__pyx_k_tuple_133;
2582 static PyObject *__pyx_k_tuple_134;
2583 static PyObject *__pyx_k_tuple_139;
2584 static PyObject *__pyx_k_tuple_142;
2585 static PyObject *__pyx_k_tuple_143;
2586 static PyObject *__pyx_k_tuple_144;
2587 static PyObject *__pyx_k_tuple_146;
2588 static PyObject *__pyx_k_tuple_172;
2589 static PyObject *__pyx_k_tuple_174;
2590 static PyObject *__pyx_k_tuple_175;
2591 static PyObject *__pyx_k_tuple_180;
2592 static PyObject *__pyx_k_tuple_181;
2593 static PyObject *__pyx_k_tuple_182;
2594 static PyObject *__pyx_k_tuple_183;
2595 static PyObject *__pyx_k_tuple_184;
2596 static PyObject *__pyx_k_tuple_252;
2597 static PyObject *__pyx_k_tuple_254;
2598 static PyObject *__pyx_k_tuple_258;
2599 static PyObject *__pyx_k_tuple_260;
2600 static PyObject *__pyx_k_tuple_262;
2601 static PyObject *__pyx_k_tuple_264;
2602 static PyObject *__pyx_k_tuple_267;
2603 static PyObject *__pyx_k_tuple_269;
2604 static PyObject *__pyx_k_tuple_271;
2605 static PyObject *__pyx_k_tuple_274;
2606 static PyObject *__pyx_k_tuple_275;
2607 static PyObject *__pyx_k_tuple_276;
2608 static PyObject *__pyx_k_tuple_277;
2609 static PyObject *__pyx_k_tuple_278;
2610 static PyObject *__pyx_k_tuple_279;
2611 static PyObject *__pyx_k_tuple_281;
2612 static PyObject *__pyx_k_tuple_282;
2613 static PyObject *__pyx_k_tuple_284;
2614 static PyObject *__pyx_k_tuple_286;
2615 static PyObject *__pyx_k_tuple_288;
2616 static PyObject *__pyx_k_tuple_291;
2617 static PyObject *__pyx_k_codeobj_255;
2618 static PyObject *__pyx_k_codeobj_259;
2619 static PyObject *__pyx_k_codeobj_261;
2620 static PyObject *__pyx_k_codeobj_263;
2621 static PyObject *__pyx_k_codeobj_265;
2622 static PyObject *__pyx_k_codeobj_268;
2623 static PyObject *__pyx_k_codeobj_270;
2624 static PyObject *__pyx_k_codeobj_272;
2625 static PyObject *__pyx_k_codeobj_280;
2626 static PyObject *__pyx_k_codeobj_283;
2627 static PyObject *__pyx_k_codeobj_285;
2628 static PyObject *__pyx_k_codeobj_287;
2629 static PyObject *__pyx_k_codeobj_289;
2630 static PyObject *__pyx_k_codeobj_292;
2631 static PyObject *__pyx_gb_9csamtools_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
2632
2633 /* "csamtools.pyx":140
2634  * cdef char* CODE2CIGAR= "MIDNSHP=X"
2635  * if IS_PYTHON3:
2636  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
2637  * else:
2638  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
2639  */
2640
2641 static PyObject *__pyx_pf_9csamtools_2genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
2642   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *__pyx_cur_scope;
2643   PyObject *__pyx_r = NULL;
2644   __Pyx_RefNannyDeclarations
2645   int __pyx_lineno = 0;
2646   const char *__pyx_filename = NULL;
2647   int __pyx_clineno = 0;
2648   __Pyx_TraceDeclarations
2649   __Pyx_RefNannySetupContext("genexpr", 0);
2650   __pyx_cur_scope = (struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)__pyx_ptype_9csamtools___pyx_scope_struct__genexpr->tp_new(__pyx_ptype_9csamtools___pyx_scope_struct__genexpr, __pyx_empty_tuple, NULL);
2651   if (unlikely(!__pyx_cur_scope)) {
2652     __Pyx_RefNannyFinishContext();
2653     return NULL;
2654   }
2655   __Pyx_GOTREF(__pyx_cur_scope);
2656   __Pyx_TraceCall("genexpr", __pyx_f[0], 140);
2657   {
2658     __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_9csamtools_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2659     __Pyx_DECREF(__pyx_cur_scope);
2660     __Pyx_RefNannyFinishContext();
2661     return (PyObject *) gen;
2662   }
2663
2664   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2665   goto __pyx_L0;
2666   __pyx_L1_error:;
2667   __Pyx_AddTraceback("csamtools.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
2668   __pyx_r = NULL;
2669   __pyx_L0:;
2670   __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
2671   __Pyx_XGIVEREF(__pyx_r);
2672   __Pyx_TraceReturn(__pyx_r);
2673   __Pyx_RefNannyFinishContext();
2674   return __pyx_r;
2675 }
2676
2677 static PyObject *__pyx_gb_9csamtools_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
2678 {
2679   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *__pyx_cur_scope = ((struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)__pyx_generator->closure);
2680   PyObject *__pyx_r = NULL;
2681   PyObject *__pyx_t_1 = NULL;
2682   PyObject *__pyx_t_2 = NULL;
2683   PyObject *__pyx_t_3 = NULL;
2684   PyObject *(*__pyx_t_4)(PyObject *);
2685   __Pyx_RefNannyDeclarations
2686   __Pyx_RefNannySetupContext("None", 0);
2687   switch (__pyx_generator->resume_label) {
2688     case 0: goto __pyx_L3_first_run;
2689     case 1: goto __pyx_L6_resume_from_yield;
2690     default: /* CPython raises the right error here */
2691     __Pyx_RefNannyFinishContext();
2692     return NULL;
2693   }
2694   __pyx_L3_first_run:;
2695   if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2696   __Pyx_INCREF(__pyx_int_0);
2697   __pyx_t_1 = __pyx_int_0;
2698   __pyx_t_2 = PyBytes_FromString(__pyx_v_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2699   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2700   __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;}
2701   __Pyx_GOTREF(__pyx_t_3);
2702   __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
2703   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
2704   for (;;) {
2705     {
2706       __pyx_t_2 = __pyx_t_4(__pyx_t_3);
2707       if (unlikely(!__pyx_t_2)) {
2708         if (PyErr_Occurred()) {
2709           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
2710           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2711         }
2712         break;
2713       }
2714       __Pyx_GOTREF(__pyx_t_2);
2715     }
2716     __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
2717     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_y);
2718     __Pyx_GIVEREF(__pyx_t_2);
2719     __pyx_cur_scope->__pyx_v_y = __pyx_t_2;
2720     __pyx_t_2 = 0;
2721     __Pyx_INCREF(__pyx_t_1);
2722     __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
2723     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
2724     __Pyx_GIVEREF(__pyx_t_1);
2725     __pyx_cur_scope->__pyx_v_x = __pyx_t_1;
2726     __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;}
2727     __Pyx_GOTREF(__pyx_t_2);
2728     __Pyx_DECREF(__pyx_t_1);
2729     __pyx_t_1 = __pyx_t_2;
2730     __pyx_t_2 = 0;
2731     __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;}
2732     __Pyx_GOTREF(__pyx_t_2);
2733     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
2734     PyList_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
2735     __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
2736     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
2737     PyList_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_x);
2738     __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
2739     __pyx_r = ((PyObject *)__pyx_t_2);
2740     __pyx_t_2 = 0;
2741     __Pyx_XGIVEREF(__pyx_t_1);
2742     __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
2743     __Pyx_XGIVEREF(__pyx_t_3);
2744     __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
2745     __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
2746     __Pyx_XGIVEREF(__pyx_r);
2747     __Pyx_RefNannyFinishContext();
2748     /* return from generator, yielding value */
2749     __pyx_generator->resume_label = 1;
2750     return __pyx_r;
2751     __pyx_L6_resume_from_yield:;
2752     __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
2753     __pyx_cur_scope->__pyx_t_0 = 0;
2754     __Pyx_XGOTREF(__pyx_t_1);
2755     __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
2756     __pyx_cur_scope->__pyx_t_1 = 0;
2757     __Pyx_XGOTREF(__pyx_t_3);
2758     __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
2759     if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2760   }
2761   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2762   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2763   PyErr_SetNone(PyExc_StopIteration);
2764   goto __pyx_L0;
2765   __pyx_L1_error:;
2766   __Pyx_XDECREF(__pyx_t_1);
2767   __Pyx_XDECREF(__pyx_t_2);
2768   __Pyx_XDECREF(__pyx_t_3);
2769   __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
2770   __pyx_L0:;
2771   __Pyx_XDECREF(__pyx_r);
2772   __pyx_generator->resume_label = -1;
2773   __Pyx_RefNannyFinishContext();
2774   return NULL;
2775 }
2776 static PyObject *__pyx_gb_9csamtools_7generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
2777
2778 /* "csamtools.pyx":142
2779  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
2780  * else:
2781  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
2782  * CIGAR_REGEX = re.compile( "([MIDNSHP=X])(\d+)" )
2783  * 
2784  */
2785
2786 static PyObject *__pyx_pf_9csamtools_5genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
2787   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
2788   PyObject *__pyx_r = NULL;
2789   __Pyx_RefNannyDeclarations
2790   int __pyx_lineno = 0;
2791   const char *__pyx_filename = NULL;
2792   int __pyx_clineno = 0;
2793   __Pyx_TraceDeclarations
2794   __Pyx_RefNannySetupContext("genexpr", 0);
2795   __pyx_cur_scope = (struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)__pyx_ptype_9csamtools___pyx_scope_struct_1_genexpr->tp_new(__pyx_ptype_9csamtools___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
2796   if (unlikely(!__pyx_cur_scope)) {
2797     __Pyx_RefNannyFinishContext();
2798     return NULL;
2799   }
2800   __Pyx_GOTREF(__pyx_cur_scope);
2801   __Pyx_TraceCall("genexpr", __pyx_f[0], 142);
2802   {
2803     __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_9csamtools_7generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2804     __Pyx_DECREF(__pyx_cur_scope);
2805     __Pyx_RefNannyFinishContext();
2806     return (PyObject *) gen;
2807   }
2808
2809   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2810   goto __pyx_L0;
2811   __pyx_L1_error:;
2812   __Pyx_AddTraceback("csamtools.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
2813   __pyx_r = NULL;
2814   __pyx_L0:;
2815   __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
2816   __Pyx_XGIVEREF(__pyx_r);
2817   __Pyx_TraceReturn(__pyx_r);
2818   __Pyx_RefNannyFinishContext();
2819   return __pyx_r;
2820 }
2821
2822 static PyObject *__pyx_gb_9csamtools_7generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
2823 {
2824   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)__pyx_generator->closure);
2825   PyObject *__pyx_r = NULL;
2826   PyObject *__pyx_t_1 = NULL;
2827   PyObject *__pyx_t_2 = NULL;
2828   PyObject *__pyx_t_3 = NULL;
2829   PyObject *(*__pyx_t_4)(PyObject *);
2830   PyObject *__pyx_t_5 = NULL;
2831   __Pyx_RefNannyDeclarations
2832   __Pyx_RefNannySetupContext("None", 0);
2833   switch (__pyx_generator->resume_label) {
2834     case 0: goto __pyx_L3_first_run;
2835     case 1: goto __pyx_L6_resume_from_yield;
2836     default: /* CPython raises the right error here */
2837     __Pyx_RefNannyFinishContext();
2838     return NULL;
2839   }
2840   __pyx_L3_first_run:;
2841   if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2842   __Pyx_INCREF(__pyx_int_0);
2843   __pyx_t_1 = __pyx_int_0;
2844   __pyx_t_2 = PyBytes_FromString(__pyx_v_9csamtools_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2845   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2846   __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;}
2847   __Pyx_GOTREF(__pyx_t_3);
2848   __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext;
2849   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
2850   for (;;) {
2851     {
2852       __pyx_t_2 = __pyx_t_4(__pyx_t_3);
2853       if (unlikely(!__pyx_t_2)) {
2854         if (PyErr_Occurred()) {
2855           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
2856           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2857         }
2858         break;
2859       }
2860       __Pyx_GOTREF(__pyx_t_2);
2861     }
2862     __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
2863     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_y);
2864     __Pyx_GIVEREF(__pyx_t_2);
2865     __pyx_cur_scope->__pyx_v_y = __pyx_t_2;
2866     __pyx_t_2 = 0;
2867     __Pyx_INCREF(__pyx_t_1);
2868     __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
2869     __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
2870     __Pyx_GIVEREF(__pyx_t_1);
2871     __pyx_cur_scope->__pyx_v_x = __pyx_t_1;
2872     __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;}
2873     __Pyx_GOTREF(__pyx_t_2);
2874     __Pyx_DECREF(__pyx_t_1);
2875     __pyx_t_1 = __pyx_t_2;
2876     __pyx_t_2 = 0;
2877     __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;}
2878     __Pyx_GOTREF(__pyx_t_2);
2879     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
2880     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
2881     __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
2882     __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;}
2883     __Pyx_GOTREF(__pyx_t_5);
2884     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
2885     __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;}
2886     __Pyx_GOTREF(__pyx_t_2);
2887     PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
2888     __Pyx_GIVEREF(__pyx_t_5);
2889     __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
2890     PyList_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_x);
2891     __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
2892     __pyx_t_5 = 0;
2893     __pyx_r = ((PyObject *)__pyx_t_2);
2894     __pyx_t_2 = 0;
2895     __Pyx_XGIVEREF(__pyx_t_1);
2896     __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
2897     __Pyx_XGIVEREF(__pyx_t_3);
2898     __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
2899     __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
2900     __Pyx_XGIVEREF(__pyx_r);
2901     __Pyx_RefNannyFinishContext();
2902     /* return from generator, yielding value */
2903     __pyx_generator->resume_label = 1;
2904     return __pyx_r;
2905     __pyx_L6_resume_from_yield:;
2906     __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
2907     __pyx_cur_scope->__pyx_t_0 = 0;
2908     __Pyx_XGOTREF(__pyx_t_1);
2909     __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
2910     __pyx_cur_scope->__pyx_t_1 = 0;
2911     __Pyx_XGOTREF(__pyx_t_3);
2912     __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
2913     if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2914   }
2915   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2916   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2917   PyErr_SetNone(PyExc_StopIteration);
2918   goto __pyx_L0;
2919   __pyx_L1_error:;
2920   __Pyx_XDECREF(__pyx_t_1);
2921   __Pyx_XDECREF(__pyx_t_2);
2922   __Pyx_XDECREF(__pyx_t_3);
2923   __Pyx_XDECREF(__pyx_t_5);
2924   __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
2925   __pyx_L0:;
2926   __Pyx_XDECREF(__pyx_r);
2927   __pyx_generator->resume_label = -1;
2928   __Pyx_RefNannyFinishContext();
2929   return NULL;
2930 }
2931
2932 /* "csamtools.pyx":24
2933  * ########################################################################
2934  * IS_PYTHON3 = PY_MAJOR_VERSION >= 3
2935  * cdef from_string_and_size(char* s, size_t length):             # <<<<<<<<<<<<<<
2936  *     if PY_MAJOR_VERSION < 3:
2937  *         return s[:length]
2938  */
2939
2940 static PyObject *__pyx_f_9csamtools_from_string_and_size(char *__pyx_v_s, size_t __pyx_v_length) {
2941   PyObject *__pyx_r = NULL;
2942   __Pyx_RefNannyDeclarations
2943   int __pyx_t_1;
2944   PyObject *__pyx_t_2 = NULL;
2945   int __pyx_lineno = 0;
2946   const char *__pyx_filename = NULL;
2947   int __pyx_clineno = 0;
2948   __Pyx_TraceDeclarations
2949   __Pyx_RefNannySetupContext("from_string_and_size", 0);
2950   __Pyx_TraceCall("from_string_and_size", __pyx_f[0], 24);
2951
2952   /* "csamtools.pyx":25
2953  * IS_PYTHON3 = PY_MAJOR_VERSION >= 3
2954  * cdef from_string_and_size(char* s, size_t length):
2955  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
2956  *         return s[:length]
2957  *     else:
2958  */
2959   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
2960   if (__pyx_t_1) {
2961
2962     /* "csamtools.pyx":26
2963  * cdef from_string_and_size(char* s, size_t length):
2964  *     if PY_MAJOR_VERSION < 3:
2965  *         return s[:length]             # <<<<<<<<<<<<<<
2966  *     else:
2967  *         return s[:length].decode("ascii")
2968  */
2969     __Pyx_XDECREF(__pyx_r);
2970     __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;}
2971     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2972     __pyx_r = ((PyObject *)__pyx_t_2);
2973     __pyx_t_2 = 0;
2974     goto __pyx_L0;
2975     goto __pyx_L3;
2976   }
2977   /*else*/ {
2978
2979     /* "csamtools.pyx":28
2980  *         return s[:length]
2981  *     else:
2982  *         return s[:length].decode("ascii")             # <<<<<<<<<<<<<<
2983  * 
2984  * # filename encoding (copied from lxml.etree.pyx)
2985  */
2986     __Pyx_XDECREF(__pyx_r);
2987     __pyx_t_2 = ((PyObject *)PyUnicode_DecodeASCII(__pyx_v_s, __pyx_v_length, NULL)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2988     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2989     __pyx_r = ((PyObject *)__pyx_t_2);
2990     __pyx_t_2 = 0;
2991     goto __pyx_L0;
2992   }
2993   __pyx_L3:;
2994
2995   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2996   goto __pyx_L0;
2997   __pyx_L1_error:;
2998   __Pyx_XDECREF(__pyx_t_2);
2999   __Pyx_AddTraceback("csamtools.from_string_and_size", __pyx_clineno, __pyx_lineno, __pyx_filename);
3000   __pyx_r = 0;
3001   __pyx_L0:;
3002   __Pyx_XGIVEREF(__pyx_r);
3003   __Pyx_TraceReturn(__pyx_r);
3004   __Pyx_RefNannyFinishContext();
3005   return __pyx_r;
3006 }
3007
3008 /* "csamtools.pyx":41
3009  * #_C_FILENAME_ENCODING = <char*>_FILENAME_ENCODING
3010  * 
3011  * cdef bytes _my_encodeFilename(object filename):             # <<<<<<<<<<<<<<
3012  *     u"""Make sure a filename is 8-bit encoded (or None).
3013  *     """
3014  */
3015
3016 static PyObject *__pyx_f_9csamtools__my_encodeFilename(PyObject *__pyx_v_filename) {
3017   PyObject *__pyx_r = NULL;
3018   __Pyx_RefNannyDeclarations
3019   int __pyx_t_1;
3020   PyObject *__pyx_t_2 = NULL;
3021   PyObject *__pyx_t_3 = NULL;
3022   PyObject *__pyx_t_4 = NULL;
3023   int __pyx_lineno = 0;
3024   const char *__pyx_filename = NULL;
3025   int __pyx_clineno = 0;
3026   __Pyx_TraceDeclarations
3027   __Pyx_RefNannySetupContext("_my_encodeFilename", 0);
3028   __Pyx_TraceCall("_my_encodeFilename", __pyx_f[0], 41);
3029
3030   /* "csamtools.pyx":44
3031  *     u"""Make sure a filename is 8-bit encoded (or None).
3032  *     """
3033  *     if filename is None:             # <<<<<<<<<<<<<<
3034  *         return None
3035  *     elif PyBytes_Check(filename):
3036  */
3037   __pyx_t_1 = (__pyx_v_filename == Py_None);
3038   if (__pyx_t_1) {
3039
3040     /* "csamtools.pyx":45
3041  *     """
3042  *     if filename is None:
3043  *         return None             # <<<<<<<<<<<<<<
3044  *     elif PyBytes_Check(filename):
3045  *         return filename
3046  */
3047     __Pyx_XDECREF(((PyObject *)__pyx_r));
3048     __Pyx_INCREF(Py_None);
3049     __pyx_r = ((PyObject*)Py_None);
3050     goto __pyx_L0;
3051     goto __pyx_L3;
3052   }
3053
3054   /* "csamtools.pyx":46
3055  *     if filename is None:
3056  *         return None
3057  *     elif PyBytes_Check(filename):             # <<<<<<<<<<<<<<
3058  *         return filename
3059  *     elif PyUnicode_Check(filename):
3060  */
3061   __pyx_t_1 = PyBytes_Check(__pyx_v_filename);
3062   if (__pyx_t_1) {
3063
3064     /* "csamtools.pyx":47
3065  *         return None
3066  *     elif PyBytes_Check(filename):
3067  *         return filename             # <<<<<<<<<<<<<<
3068  *     elif PyUnicode_Check(filename):
3069  *         return filename.encode(_FILENAME_ENCODING)
3070  */
3071     __Pyx_XDECREF(((PyObject *)__pyx_r));
3072     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;}
3073     __Pyx_INCREF(__pyx_v_filename);
3074     __pyx_r = ((PyObject*)__pyx_v_filename);
3075     goto __pyx_L0;
3076     goto __pyx_L3;
3077   }
3078
3079   /* "csamtools.pyx":48
3080  *     elif PyBytes_Check(filename):
3081  *         return filename
3082  *     elif PyUnicode_Check(filename):             # <<<<<<<<<<<<<<
3083  *         return filename.encode(_FILENAME_ENCODING)
3084  *     else:
3085  */
3086   __pyx_t_1 = PyUnicode_Check(__pyx_v_filename);
3087   if (__pyx_t_1) {
3088
3089     /* "csamtools.pyx":49
3090  *         return filename
3091  *     elif PyUnicode_Check(filename):
3092  *         return filename.encode(_FILENAME_ENCODING)             # <<<<<<<<<<<<<<
3093  *     else:
3094  *         raise TypeError, u"Argument must be string or unicode."
3095  */
3096     __Pyx_XDECREF(((PyObject *)__pyx_r));
3097     __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;}
3098     __Pyx_GOTREF(__pyx_t_2);
3099     __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;}
3100     __Pyx_GOTREF(__pyx_t_3);
3101     __Pyx_INCREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
3102     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
3103     __Pyx_GIVEREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
3104     __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;}
3105     __Pyx_GOTREF(__pyx_t_4);
3106     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3107     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3108     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;}
3109     __pyx_r = ((PyObject*)__pyx_t_4);
3110     __pyx_t_4 = 0;
3111     goto __pyx_L0;
3112     goto __pyx_L3;
3113   }
3114   /*else*/ {
3115
3116     /* "csamtools.pyx":51
3117  *         return filename.encode(_FILENAME_ENCODING)
3118  *     else:
3119  *         raise TypeError, u"Argument must be string or unicode."             # <<<<<<<<<<<<<<
3120  * 
3121  * 
3122  */
3123     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_1), 0, 0);
3124     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3125   }
3126   __pyx_L3:;
3127
3128   __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
3129   goto __pyx_L0;
3130   __pyx_L1_error:;
3131   __Pyx_XDECREF(__pyx_t_2);
3132   __Pyx_XDECREF(__pyx_t_3);
3133   __Pyx_XDECREF(__pyx_t_4);
3134   __Pyx_AddTraceback("csamtools._my_encodeFilename", __pyx_clineno, __pyx_lineno, __pyx_filename);
3135   __pyx_r = 0;
3136   __pyx_L0:;
3137   __Pyx_XGIVEREF(__pyx_r);
3138   __Pyx_TraceReturn(__pyx_r);
3139   __Pyx_RefNannyFinishContext();
3140   return __pyx_r;
3141 }
3142
3143 /* "csamtools.pyx":54
3144  * 
3145  * 
3146  * cdef bytes _force_bytes(object s):             # <<<<<<<<<<<<<<
3147  *     u"""convert string or unicode object to bytes, assuming ascii encoding.
3148  *     """
3149  */
3150
3151 static PyObject *__pyx_f_9csamtools__force_bytes(PyObject *__pyx_v_s) {
3152   PyObject *__pyx_r = NULL;
3153   __Pyx_RefNannyDeclarations
3154   int __pyx_t_1;
3155   PyObject *__pyx_t_2 = NULL;
3156   PyObject *__pyx_t_3 = NULL;
3157   int __pyx_lineno = 0;
3158   const char *__pyx_filename = NULL;
3159   int __pyx_clineno = 0;
3160   __Pyx_TraceDeclarations
3161   __Pyx_RefNannySetupContext("_force_bytes", 0);
3162   __Pyx_TraceCall("_force_bytes", __pyx_f[0], 54);
3163
3164   /* "csamtools.pyx":57
3165  *     u"""convert string or unicode object to bytes, assuming ascii encoding.
3166  *     """
3167  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
3168  *         return s
3169  *     elif s is None:
3170  */
3171   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
3172   if (__pyx_t_1) {
3173
3174     /* "csamtools.pyx":58
3175  *     """
3176  *     if PY_MAJOR_VERSION < 3:
3177  *         return s             # <<<<<<<<<<<<<<
3178  *     elif s is None:
3179  *         return None
3180  */
3181     __Pyx_XDECREF(((PyObject *)__pyx_r));
3182     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;}
3183     __Pyx_INCREF(__pyx_v_s);
3184     __pyx_r = ((PyObject*)__pyx_v_s);
3185     goto __pyx_L0;
3186     goto __pyx_L3;
3187   }
3188
3189   /* "csamtools.pyx":59
3190  *     if PY_MAJOR_VERSION < 3:
3191  *         return s
3192  *     elif s is None:             # <<<<<<<<<<<<<<
3193  *         return None
3194  *     elif PyBytes_Check(s):
3195  */
3196   __pyx_t_1 = (__pyx_v_s == Py_None);
3197   if (__pyx_t_1) {
3198
3199     /* "csamtools.pyx":60
3200  *         return s
3201  *     elif s is None:
3202  *         return None             # <<<<<<<<<<<<<<
3203  *     elif PyBytes_Check(s):
3204  *         return s
3205  */
3206     __Pyx_XDECREF(((PyObject *)__pyx_r));
3207     __Pyx_INCREF(Py_None);
3208     __pyx_r = ((PyObject*)Py_None);
3209     goto __pyx_L0;
3210     goto __pyx_L3;
3211   }
3212
3213   /* "csamtools.pyx":61
3214  *     elif s is None:
3215  *         return None
3216  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
3217  *         return s
3218  *     elif PyUnicode_Check(s):
3219  */
3220   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
3221   if (__pyx_t_1) {
3222
3223     /* "csamtools.pyx":62
3224  *         return None
3225  *     elif PyBytes_Check(s):
3226  *         return s             # <<<<<<<<<<<<<<
3227  *     elif PyUnicode_Check(s):
3228  *         return s.encode('ascii')
3229  */
3230     __Pyx_XDECREF(((PyObject *)__pyx_r));
3231     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;}
3232     __Pyx_INCREF(__pyx_v_s);
3233     __pyx_r = ((PyObject*)__pyx_v_s);
3234     goto __pyx_L0;
3235     goto __pyx_L3;
3236   }
3237
3238   /* "csamtools.pyx":63
3239  *     elif PyBytes_Check(s):
3240  *         return s
3241  *     elif PyUnicode_Check(s):             # <<<<<<<<<<<<<<
3242  *         return s.encode('ascii')
3243  *     else:
3244  */
3245   __pyx_t_1 = PyUnicode_Check(__pyx_v_s);
3246   if (__pyx_t_1) {
3247
3248     /* "csamtools.pyx":64
3249  *         return s
3250  *     elif PyUnicode_Check(s):
3251  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
3252  *     else:
3253  *         raise TypeError, u"Argument must be string, bytes or unicode."
3254  */
3255     __Pyx_XDECREF(((PyObject *)__pyx_r));
3256     __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;}
3257     __Pyx_GOTREF(__pyx_t_2);
3258     __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;}
3259     __Pyx_GOTREF(__pyx_t_3);
3260     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3261     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;}
3262     __pyx_r = ((PyObject*)__pyx_t_3);
3263     __pyx_t_3 = 0;
3264     goto __pyx_L0;
3265     goto __pyx_L3;
3266   }
3267   /*else*/ {
3268
3269     /* "csamtools.pyx":66
3270  *         return s.encode('ascii')
3271  *     else:
3272  *         raise TypeError, u"Argument must be string, bytes or unicode."             # <<<<<<<<<<<<<<
3273  * 
3274  * cdef inline bytes _force_cmdline_bytes(object s):
3275  */
3276     __Pyx_Raise(__pyx_builtin_TypeError, ((PyObject *)__pyx_kp_u_3), 0, 0);
3277     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3278   }
3279   __pyx_L3:;
3280
3281   __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
3282   goto __pyx_L0;
3283   __pyx_L1_error:;
3284   __Pyx_XDECREF(__pyx_t_2);
3285   __Pyx_XDECREF(__pyx_t_3);
3286   __Pyx_AddTraceback("csamtools._force_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
3287   __pyx_r = 0;
3288   __pyx_L0:;
3289   __Pyx_XGIVEREF(__pyx_r);
3290   __Pyx_TraceReturn(__pyx_r);
3291   __Pyx_RefNannyFinishContext();
3292   return __pyx_r;
3293 }
3294
3295 /* "csamtools.pyx":68
3296  *         raise TypeError, u"Argument must be string, bytes or unicode."
3297  * 
3298  * cdef inline bytes _force_cmdline_bytes(object s):             # <<<<<<<<<<<<<<
3299  *     return _force_bytes(s)
3300  * 
3301  */
3302
3303 static CYTHON_INLINE PyObject *__pyx_f_9csamtools__force_cmdline_bytes(PyObject *__pyx_v_s) {
3304   PyObject *__pyx_r = NULL;
3305   __Pyx_RefNannyDeclarations
3306   PyObject *__pyx_t_1 = NULL;
3307   int __pyx_lineno = 0;
3308   const char *__pyx_filename = NULL;
3309   int __pyx_clineno = 0;
3310   __Pyx_TraceDeclarations
3311   __Pyx_RefNannySetupContext("_force_cmdline_bytes", 0);
3312   __Pyx_TraceCall("_force_cmdline_bytes", __pyx_f[0], 68);
3313
3314   /* "csamtools.pyx":69
3315  * 
3316  * cdef inline bytes _force_cmdline_bytes(object s):
3317  *     return _force_bytes(s)             # <<<<<<<<<<<<<<
3318  * 
3319  * cdef _charptr_to_str(char* s):
3320  */
3321   __Pyx_XDECREF(((PyObject *)__pyx_r));
3322   __pyx_t_1 = ((PyObject *)__pyx_f_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;}
3323   __Pyx_GOTREF(__pyx_t_1);
3324   __pyx_r = ((PyObject*)__pyx_t_1);
3325   __pyx_t_1 = 0;
3326   goto __pyx_L0;
3327
3328   __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
3329   goto __pyx_L0;
3330   __pyx_L1_error:;
3331   __Pyx_XDECREF(__pyx_t_1);
3332   __Pyx_AddTraceback("csamtools._force_cmdline_bytes", __pyx_clineno, __pyx_lineno, __pyx_filename);
3333   __pyx_r = 0;
3334   __pyx_L0:;
3335   __Pyx_XGIVEREF(__pyx_r);
3336   __Pyx_TraceReturn(__pyx_r);
3337   __Pyx_RefNannyFinishContext();
3338   return __pyx_r;
3339 }
3340
3341 /* "csamtools.pyx":71
3342  *     return _force_bytes(s)
3343  * 
3344  * cdef _charptr_to_str(char* s):             # <<<<<<<<<<<<<<
3345  *     if PY_MAJOR_VERSION < 3:
3346  *         return s
3347  */
3348
3349 static PyObject *__pyx_f_9csamtools__charptr_to_str(char *__pyx_v_s) {
3350   PyObject *__pyx_r = NULL;
3351   __Pyx_RefNannyDeclarations
3352   int __pyx_t_1;
3353   PyObject *__pyx_t_2 = NULL;
3354   int __pyx_lineno = 0;
3355   const char *__pyx_filename = NULL;
3356   int __pyx_clineno = 0;
3357   __Pyx_TraceDeclarations
3358   __Pyx_RefNannySetupContext("_charptr_to_str", 0);
3359   __Pyx_TraceCall("_charptr_to_str", __pyx_f[0], 71);
3360
3361   /* "csamtools.pyx":72
3362  * 
3363  * cdef _charptr_to_str(char* s):
3364  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
3365  *         return s
3366  *     else:
3367  */
3368   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
3369   if (__pyx_t_1) {
3370
3371     /* "csamtools.pyx":73
3372  * cdef _charptr_to_str(char* s):
3373  *     if PY_MAJOR_VERSION < 3:
3374  *         return s             # <<<<<<<<<<<<<<
3375  *     else:
3376  *         return s.decode("ascii")
3377  */
3378     __Pyx_XDECREF(__pyx_r);
3379     __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;}
3380     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
3381     __pyx_r = ((PyObject *)__pyx_t_2);
3382     __pyx_t_2 = 0;
3383     goto __pyx_L0;
3384     goto __pyx_L3;
3385   }
3386   /*else*/ {
3387
3388     /* "csamtools.pyx":75
3389  *         return s
3390  *     else:
3391  *         return s.decode("ascii")             # <<<<<<<<<<<<<<
3392  * 
3393  * cdef _force_str(object s):
3394  */
3395     __Pyx_XDECREF(__pyx_r);
3396     __pyx_t_2 = ((PyObject *)PyUnicode_DecodeASCII(__pyx_v_s, strlen(__pyx_v_s), NULL)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3397     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
3398     __pyx_r = ((PyObject *)__pyx_t_2);
3399     __pyx_t_2 = 0;
3400     goto __pyx_L0;
3401   }
3402   __pyx_L3:;
3403
3404   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3405   goto __pyx_L0;
3406   __pyx_L1_error:;
3407   __Pyx_XDECREF(__pyx_t_2);
3408   __Pyx_AddTraceback("csamtools._charptr_to_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
3409   __pyx_r = 0;
3410   __pyx_L0:;
3411   __Pyx_XGIVEREF(__pyx_r);
3412   __Pyx_TraceReturn(__pyx_r);
3413   __Pyx_RefNannyFinishContext();
3414   return __pyx_r;
3415 }
3416
3417 /* "csamtools.pyx":77
3418  *         return s.decode("ascii")
3419  * 
3420  * cdef _force_str(object s):             # <<<<<<<<<<<<<<
3421  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
3422  *     if s is None:
3423  */
3424
3425 static PyObject *__pyx_f_9csamtools__force_str(PyObject *__pyx_v_s) {
3426   PyObject *__pyx_r = NULL;
3427   __Pyx_RefNannyDeclarations
3428   int __pyx_t_1;
3429   PyObject *__pyx_t_2 = NULL;
3430   PyObject *__pyx_t_3 = NULL;
3431   int __pyx_lineno = 0;
3432   const char *__pyx_filename = NULL;
3433   int __pyx_clineno = 0;
3434   __Pyx_TraceDeclarations
3435   __Pyx_RefNannySetupContext("_force_str", 0);
3436   __Pyx_TraceCall("_force_str", __pyx_f[0], 77);
3437
3438   /* "csamtools.pyx":79
3439  * cdef _force_str(object s):
3440  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
3441  *     if s is None:             # <<<<<<<<<<<<<<
3442  *         return None
3443  *     if PY_MAJOR_VERSION < 3:
3444  */
3445   __pyx_t_1 = (__pyx_v_s == Py_None);
3446   if (__pyx_t_1) {
3447
3448     /* "csamtools.pyx":80
3449  *     """Return s converted to str type of current Python (bytes in Py2, unicode in Py3)"""
3450  *     if s is None:
3451  *         return None             # <<<<<<<<<<<<<<
3452  *     if PY_MAJOR_VERSION < 3:
3453  *         return s
3454  */
3455     __Pyx_XDECREF(__pyx_r);
3456     __Pyx_INCREF(Py_None);
3457     __pyx_r = Py_None;
3458     goto __pyx_L0;
3459     goto __pyx_L3;
3460   }
3461   __pyx_L3:;
3462
3463   /* "csamtools.pyx":81
3464  *     if s is None:
3465  *         return None
3466  *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
3467  *         return s
3468  *     elif PyBytes_Check(s):
3469  */
3470   __pyx_t_1 = (PY_MAJOR_VERSION < 3);
3471   if (__pyx_t_1) {
3472
3473     /* "csamtools.pyx":82
3474  *         return None
3475  *     if PY_MAJOR_VERSION < 3:
3476  *         return s             # <<<<<<<<<<<<<<
3477  *     elif PyBytes_Check(s):
3478  *         return s.decode('ascii')
3479  */
3480     __Pyx_XDECREF(__pyx_r);
3481     __Pyx_INCREF(__pyx_v_s);
3482     __pyx_r = __pyx_v_s;
3483     goto __pyx_L0;
3484     goto __pyx_L4;
3485   }
3486
3487   /* "csamtools.pyx":83
3488  *     if PY_MAJOR_VERSION < 3:
3489  *         return s
3490  *     elif PyBytes_Check(s):             # <<<<<<<<<<<<<<
3491  *         return s.decode('ascii')
3492  *     else:
3493  */
3494   __pyx_t_1 = PyBytes_Check(__pyx_v_s);
3495   if (__pyx_t_1) {
3496
3497     /* "csamtools.pyx":84
3498  *         return s
3499  *     elif PyBytes_Check(s):
3500  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
3501  *     else:
3502  *         # assume unicode
3503  */
3504     __Pyx_XDECREF(__pyx_r);
3505     __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;}
3506     __Pyx_GOTREF(__pyx_t_2);
3507     __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;}
3508     __Pyx_GOTREF(__pyx_t_3);
3509     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3510     __pyx_r = __pyx_t_3;
3511     __pyx_t_3 = 0;
3512     goto __pyx_L0;
3513     goto __pyx_L4;
3514   }
3515   /*else*/ {
3516
3517     /* "csamtools.pyx":87
3518  *     else:
3519  *         # assume unicode
3520  *         return s             # <<<<<<<<<<<<<<
3521  * ########################################################################
3522  * ########################################################################
3523  */
3524     __Pyx_XDECREF(__pyx_r);
3525     __Pyx_INCREF(__pyx_v_s);
3526     __pyx_r = __pyx_v_s;
3527     goto __pyx_L0;
3528   }
3529   __pyx_L4:;
3530
3531   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3532   goto __pyx_L0;
3533   __pyx_L1_error:;
3534   __Pyx_XDECREF(__pyx_t_2);
3535   __Pyx_XDECREF(__pyx_t_3);
3536   __Pyx_AddTraceback("csamtools._force_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
3537   __pyx_r = 0;
3538   __pyx_L0:;
3539   __Pyx_XGIVEREF(__pyx_r);
3540   __Pyx_TraceReturn(__pyx_r);
3541   __Pyx_RefNannyFinishContext();
3542   return __pyx_r;
3543 }
3544
3545 /* "csamtools.pyx":160
3546  * #####################################################################
3547  * cdef class AlignedRead
3548  * cdef makeAlignedRead(bam1_t * src):             # <<<<<<<<<<<<<<
3549  *     '''enter src into AlignedRead.'''
3550  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
3551  */
3552
3553 static PyObject *__pyx_f_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src) {
3554   struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_dest = 0;
3555   PyObject *__pyx_r = NULL;
3556   __Pyx_RefNannyDeclarations
3557   PyObject *__pyx_t_1 = NULL;
3558   int __pyx_lineno = 0;
3559   const char *__pyx_filename = NULL;
3560   int __pyx_clineno = 0;
3561   __Pyx_TraceDeclarations
3562   __Pyx_RefNannySetupContext("makeAlignedRead", 0);
3563   __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 160);
3564
3565   /* "csamtools.pyx":162
3566  * cdef makeAlignedRead(bam1_t * src):
3567  *     '''enter src into AlignedRead.'''
3568  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
3569  *     dest._delegate = bam_dup1(src)
3570  *     return dest
3571  */
3572   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3573   __Pyx_GOTREF(__pyx_t_1);
3574   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3575   __pyx_v_dest = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_1);
3576   __pyx_t_1 = 0;
3577
3578   /* "csamtools.pyx":163
3579  *     '''enter src into AlignedRead.'''
3580  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
3581  *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
3582  *     return dest
3583  * 
3584  */
3585   __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);
3586
3587   /* "csamtools.pyx":164
3588  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
3589  *     dest._delegate = bam_dup1(src)
3590  *     return dest             # <<<<<<<<<<<<<<
3591  * 
3592  * cdef class PileupProxy
3593  */
3594   __Pyx_XDECREF(__pyx_r);
3595   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
3596   __pyx_r = ((PyObject *)__pyx_v_dest);
3597   goto __pyx_L0;
3598
3599   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3600   goto __pyx_L0;
3601   __pyx_L1_error:;
3602   __Pyx_XDECREF(__pyx_t_1);
3603   __Pyx_AddTraceback("csamtools.makeAlignedRead", __pyx_clineno, __pyx_lineno, __pyx_filename);
3604   __pyx_r = 0;
3605   __pyx_L0:;
3606   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
3607   __Pyx_XGIVEREF(__pyx_r);
3608   __Pyx_TraceReturn(__pyx_r);
3609   __Pyx_RefNannyFinishContext();
3610   return __pyx_r;
3611 }
3612
3613 /* "csamtools.pyx":167
3614  * 
3615  * cdef class PileupProxy
3616  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):             # <<<<<<<<<<<<<<
3617  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
3618  *      dest.plp = plp
3619  */
3620
3621 static PyObject *__pyx_f_9csamtools_makePileupProxy(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n) {
3622   struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_dest = 0;
3623   PyObject *__pyx_r = NULL;
3624   __Pyx_RefNannyDeclarations
3625   PyObject *__pyx_t_1 = NULL;
3626   int __pyx_lineno = 0;
3627   const char *__pyx_filename = NULL;
3628   int __pyx_clineno = 0;
3629   __Pyx_TraceDeclarations
3630   __Pyx_RefNannySetupContext("makePileupProxy", 0);
3631   __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 167);
3632
3633   /* "csamtools.pyx":168
3634  * cdef class PileupProxy
3635  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):
3636  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)             # <<<<<<<<<<<<<<
3637  *      dest.plp = plp
3638  *      dest.tid = tid
3639  */
3640   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_PileupProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3641   __Pyx_GOTREF(__pyx_t_1);
3642   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_PileupProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3643   __pyx_v_dest = ((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_t_1);
3644   __pyx_t_1 = 0;
3645
3646   /* "csamtools.pyx":169
3647  * cdef makePileupProxy( bam_pileup1_t ** plp, int tid, int pos, int n ):
3648  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
3649  *      dest.plp = plp             # <<<<<<<<<<<<<<
3650  *      dest.tid = tid
3651  *      dest.pos = pos
3652  */
3653   __pyx_v_dest->plp = __pyx_v_plp;
3654
3655   /* "csamtools.pyx":170
3656  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
3657  *      dest.plp = plp
3658  *      dest.tid = tid             # <<<<<<<<<<<<<<
3659  *      dest.pos = pos
3660  *      dest.n = n
3661  */
3662   __pyx_v_dest->tid = __pyx_v_tid;
3663
3664   /* "csamtools.pyx":171
3665  *      dest.plp = plp
3666  *      dest.tid = tid
3667  *      dest.pos = pos             # <<<<<<<<<<<<<<
3668  *      dest.n = n
3669  *      return dest
3670  */
3671   __pyx_v_dest->pos = __pyx_v_pos;
3672
3673   /* "csamtools.pyx":172
3674  *      dest.tid = tid
3675  *      dest.pos = pos
3676  *      dest.n = n             # <<<<<<<<<<<<<<
3677  *      return dest
3678  * 
3679  */
3680   __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;}
3681   __Pyx_GOTREF(__pyx_t_1);
3682   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;}
3683   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3684
3685   /* "csamtools.pyx":173
3686  *      dest.pos = pos
3687  *      dest.n = n
3688  *      return dest             # <<<<<<<<<<<<<<
3689  * 
3690  * cdef class PileupRead
3691  */
3692   __Pyx_XDECREF(__pyx_r);
3693   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
3694   __pyx_r = ((PyObject *)__pyx_v_dest);
3695   goto __pyx_L0;
3696
3697   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3698   goto __pyx_L0;
3699   __pyx_L1_error:;
3700   __Pyx_XDECREF(__pyx_t_1);
3701   __Pyx_AddTraceback("csamtools.makePileupProxy", __pyx_clineno, __pyx_lineno, __pyx_filename);
3702   __pyx_r = 0;
3703   __pyx_L0:;
3704   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
3705   __Pyx_XGIVEREF(__pyx_r);
3706   __Pyx_TraceReturn(__pyx_r);
3707   __Pyx_RefNannyFinishContext();
3708   return __pyx_r;
3709 }
3710
3711 /* "csamtools.pyx":176
3712  * 
3713  * cdef class PileupRead
3714  * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
3715  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
3716  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
3717  */
3718
3719 static PyObject *__pyx_f_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v_src) {
3720   struct __pyx_obj_9csamtools_PileupRead *__pyx_v_dest = 0;
3721   PyObject *__pyx_r = NULL;
3722   __Pyx_RefNannyDeclarations
3723   PyObject *__pyx_t_1 = NULL;
3724   int __pyx_lineno = 0;
3725   const char *__pyx_filename = NULL;
3726   int __pyx_clineno = 0;
3727   __Pyx_TraceDeclarations
3728   __Pyx_RefNannySetupContext("makePileupRead", 0);
3729   __Pyx_TraceCall("makePileupRead", __pyx_f[0], 176);
3730
3731   /* "csamtools.pyx":178
3732  * cdef makePileupRead( bam_pileup1_t * src ):
3733  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
3734  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)             # <<<<<<<<<<<<<<
3735  *     dest._alignment = makeAlignedRead( src.b )
3736  *     dest._qpos = src.qpos
3737  */
3738   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_PileupRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3739   __Pyx_GOTREF(__pyx_t_1);
3740   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3741   __pyx_v_dest = ((struct __pyx_obj_9csamtools_PileupRead *)__pyx_t_1);
3742   __pyx_t_1 = 0;
3743
3744   /* "csamtools.pyx":179
3745  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
3746  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
3747  *     dest._alignment = makeAlignedRead( src.b )             # <<<<<<<<<<<<<<
3748  *     dest._qpos = src.qpos
3749  *     dest._indel = src.indel
3750  */
3751   __pyx_t_1 = __pyx_f_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;}
3752   __Pyx_GOTREF(__pyx_t_1);
3753   if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3754   __Pyx_GIVEREF(__pyx_t_1);
3755   __Pyx_GOTREF(__pyx_v_dest->_alignment);
3756   __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
3757   __pyx_v_dest->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_1);
3758   __pyx_t_1 = 0;
3759
3760   /* "csamtools.pyx":180
3761  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
3762  *     dest._alignment = makeAlignedRead( src.b )
3763  *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
3764  *     dest._indel = src.indel
3765  *     dest._level = src.level
3766  */
3767   __pyx_v_dest->_qpos = __pyx_v_src->qpos;
3768
3769   /* "csamtools.pyx":181
3770  *     dest._alignment = makeAlignedRead( src.b )
3771  *     dest._qpos = src.qpos
3772  *     dest._indel = src.indel             # <<<<<<<<<<<<<<
3773  *     dest._level = src.level
3774  *     dest._is_del = src.is_del
3775  */
3776   __pyx_v_dest->_indel = __pyx_v_src->indel;
3777
3778   /* "csamtools.pyx":182
3779  *     dest._qpos = src.qpos
3780  *     dest._indel = src.indel
3781  *     dest._level = src.level             # <<<<<<<<<<<<<<
3782  *     dest._is_del = src.is_del
3783  *     dest._is_head = src.is_head
3784  */
3785   __pyx_v_dest->_level = __pyx_v_src->level;
3786
3787   /* "csamtools.pyx":183
3788  *     dest._indel = src.indel
3789  *     dest._level = src.level
3790  *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
3791  *     dest._is_head = src.is_head
3792  *     dest._is_tail = src.is_tail
3793  */
3794   __pyx_v_dest->_is_del = __pyx_v_src->is_del;
3795
3796   /* "csamtools.pyx":184
3797  *     dest._level = src.level
3798  *     dest._is_del = src.is_del
3799  *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
3800  *     dest._is_tail = src.is_tail
3801  *     return dest
3802  */
3803   __pyx_v_dest->_is_head = __pyx_v_src->is_head;
3804
3805   /* "csamtools.pyx":185
3806  *     dest._is_del = src.is_del
3807  *     dest._is_head = src.is_head
3808  *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
3809  *     return dest
3810  * 
3811  */
3812   __pyx_v_dest->_is_tail = __pyx_v_src->is_tail;
3813
3814   /* "csamtools.pyx":186
3815  *     dest._is_head = src.is_head
3816  *     dest._is_tail = src.is_tail
3817  *     return dest             # <<<<<<<<<<<<<<
3818  * 
3819  * cdef convertBinaryTagToList( uint8_t * s ):
3820  */
3821   __Pyx_XDECREF(__pyx_r);
3822   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
3823   __pyx_r = ((PyObject *)__pyx_v_dest);
3824   goto __pyx_L0;
3825
3826   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3827   goto __pyx_L0;
3828   __pyx_L1_error:;
3829   __Pyx_XDECREF(__pyx_t_1);
3830   __Pyx_AddTraceback("csamtools.makePileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename);
3831   __pyx_r = 0;
3832   __pyx_L0:;
3833   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
3834   __Pyx_XGIVEREF(__pyx_r);
3835   __Pyx_TraceReturn(__pyx_r);
3836   __Pyx_RefNannyFinishContext();
3837   return __pyx_r;
3838 }
3839
3840 /* "csamtools.pyx":188
3841  *     return dest
3842  * 
3843  * cdef convertBinaryTagToList( uint8_t * s ):             # <<<<<<<<<<<<<<
3844  *     """return bytesize, number of values list of values in s."""
3845  *     cdef char auxtype
3846  */
3847
3848 static PyObject *__pyx_f_9csamtools_convertBinaryTagToList(uint8_t *__pyx_v_s) {
3849   char __pyx_v_auxtype;
3850   uint8_t __pyx_v_byte_size;
3851   int32_t __pyx_v_nvalues;
3852   PyObject *__pyx_v_values = NULL;
3853   CYTHON_UNUSED long __pyx_v_x;
3854   PyObject *__pyx_r = NULL;
3855   __Pyx_RefNannyDeclarations
3856   PyObject *__pyx_t_1 = NULL;
3857   int __pyx_t_2;
3858   int32_t __pyx_t_3;
3859   int __pyx_t_4;
3860   PyObject *__pyx_t_5 = NULL;
3861   PyObject *__pyx_t_6 = NULL;
3862   int __pyx_lineno = 0;
3863   const char *__pyx_filename = NULL;
3864   int __pyx_clineno = 0;
3865   __Pyx_TraceDeclarations
3866   __Pyx_RefNannySetupContext("convertBinaryTagToList", 0);
3867   __Pyx_TraceCall("convertBinaryTagToList", __pyx_f[0], 188);
3868
3869   /* "csamtools.pyx":195
3870  * 
3871  *     # get byte size
3872  *     auxtype = s[0]             # <<<<<<<<<<<<<<
3873  *     byte_size = bam_aux_type2size( auxtype )
3874  *     s += 1
3875  */
3876   __pyx_v_auxtype = (__pyx_v_s[0]);
3877
3878   /* "csamtools.pyx":196
3879  *     # get byte size
3880  *     auxtype = s[0]
3881  *     byte_size = bam_aux_type2size( auxtype )             # <<<<<<<<<<<<<<
3882  *     s += 1
3883  *     # get number of values in array
3884  */
3885   __pyx_v_byte_size = bam_aux_type2size(__pyx_v_auxtype);
3886
3887   /* "csamtools.pyx":197
3888  *     auxtype = s[0]
3889  *     byte_size = bam_aux_type2size( auxtype )
3890  *     s += 1             # <<<<<<<<<<<<<<
3891  *     # get number of values in array
3892  *     nvalues = (<int32_t*>s)[0]
3893  */
3894   __pyx_v_s = (__pyx_v_s + 1);
3895
3896   /* "csamtools.pyx":199
3897  *     s += 1
3898  *     # get number of values in array
3899  *     nvalues = (<int32_t*>s)[0]             # <<<<<<<<<<<<<<
3900  *     s += 4
3901  *     # get values
3902  */
3903   __pyx_v_nvalues = (((int32_t *)__pyx_v_s)[0]);
3904
3905   /* "csamtools.pyx":200
3906  *     # get number of values in array
3907  *     nvalues = (<int32_t*>s)[0]
3908  *     s += 4             # <<<<<<<<<<<<<<
3909  *     # get values
3910  *     values = []
3911  */
3912   __pyx_v_s = (__pyx_v_s + 4);
3913
3914   /* "csamtools.pyx":202
3915  *     s += 4
3916  *     # get values
3917  *     values = []             # <<<<<<<<<<<<<<
3918  *     if auxtype == 'c':
3919  *         for x from 0 <= x < nvalues:
3920  */
3921   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3922   __Pyx_GOTREF(__pyx_t_1);
3923   __pyx_v_values = __pyx_t_1;
3924   __pyx_t_1 = 0;
3925
3926   /* "csamtools.pyx":203
3927  *     # get values
3928  *     values = []
3929  *     if auxtype == 'c':             # <<<<<<<<<<<<<<
3930  *         for x from 0 <= x < nvalues:
3931  *             values.append((<int8_t*>s)[0])
3932  */
3933   __pyx_t_2 = (__pyx_v_auxtype == 'c');
3934   if (__pyx_t_2) {
3935
3936     /* "csamtools.pyx":204
3937  *     values = []
3938  *     if auxtype == 'c':
3939  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
3940  *             values.append((<int8_t*>s)[0])
3941  *             s += 1
3942  */
3943     __pyx_t_3 = __pyx_v_nvalues;
3944     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
3945
3946       /* "csamtools.pyx":205
3947  *     if auxtype == 'c':
3948  *         for x from 0 <= x < nvalues:
3949  *             values.append((<int8_t*>s)[0])             # <<<<<<<<<<<<<<
3950  *             s += 1
3951  *     elif auxtype == 'C':
3952  */
3953       __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 = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3954       __Pyx_GOTREF(__pyx_t_1);
3955       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3956       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3957
3958       /* "csamtools.pyx":206
3959  *         for x from 0 <= x < nvalues:
3960  *             values.append((<int8_t*>s)[0])
3961  *             s += 1             # <<<<<<<<<<<<<<
3962  *     elif auxtype == 'C':
3963  *         for x from 0 <= x < nvalues:
3964  */
3965       __pyx_v_s = (__pyx_v_s + 1);
3966     }
3967     goto __pyx_L3;
3968   }
3969
3970   /* "csamtools.pyx":207
3971  *             values.append((<int8_t*>s)[0])
3972  *             s += 1
3973  *     elif auxtype == 'C':             # <<<<<<<<<<<<<<
3974  *         for x from 0 <= x < nvalues:
3975  *             values.append((<uint8_t*>s)[0])
3976  */
3977   __pyx_t_2 = (__pyx_v_auxtype == 'C');
3978   if (__pyx_t_2) {
3979
3980     /* "csamtools.pyx":208
3981  *             s += 1
3982  *     elif auxtype == 'C':
3983  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
3984  *             values.append((<uint8_t*>s)[0])
3985  *             s += 1
3986  */
3987     __pyx_t_3 = __pyx_v_nvalues;
3988     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
3989
3990       /* "csamtools.pyx":209
3991  *     elif auxtype == 'C':
3992  *         for x from 0 <= x < nvalues:
3993  *             values.append((<uint8_t*>s)[0])             # <<<<<<<<<<<<<<
3994  *             s += 1
3995  *     elif auxtype == 's':
3996  */
3997       __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 = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3998       __Pyx_GOTREF(__pyx_t_1);
3999       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4000       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4001
4002       /* "csamtools.pyx":210
4003  *         for x from 0 <= x < nvalues:
4004  *             values.append((<uint8_t*>s)[0])
4005  *             s += 1             # <<<<<<<<<<<<<<
4006  *     elif auxtype == 's':
4007  *         for x from 0 <= x < nvalues:
4008  */
4009       __pyx_v_s = (__pyx_v_s + 1);
4010     }
4011     goto __pyx_L3;
4012   }
4013
4014   /* "csamtools.pyx":211
4015  *             values.append((<uint8_t*>s)[0])
4016  *             s += 1
4017  *     elif auxtype == 's':             # <<<<<<<<<<<<<<
4018  *         for x from 0 <= x < nvalues:
4019  *             values.append((<int16_t*>s)[0])
4020  */
4021   __pyx_t_2 = (__pyx_v_auxtype == 's');
4022   if (__pyx_t_2) {
4023
4024     /* "csamtools.pyx":212
4025  *             s += 1
4026  *     elif auxtype == 's':
4027  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
4028  *             values.append((<int16_t*>s)[0])
4029  *             s += 2
4030  */
4031     __pyx_t_3 = __pyx_v_nvalues;
4032     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4033
4034       /* "csamtools.pyx":213
4035  *     elif auxtype == 's':
4036  *         for x from 0 <= x < nvalues:
4037  *             values.append((<int16_t*>s)[0])             # <<<<<<<<<<<<<<
4038  *             s += 2
4039  *     elif auxtype == 'S':
4040  */
4041       __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 = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4042       __Pyx_GOTREF(__pyx_t_1);
4043       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4044       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4045
4046       /* "csamtools.pyx":214
4047  *         for x from 0 <= x < nvalues:
4048  *             values.append((<int16_t*>s)[0])
4049  *             s += 2             # <<<<<<<<<<<<<<
4050  *     elif auxtype == 'S':
4051  *         for x from 0 <= x < nvalues:
4052  */
4053       __pyx_v_s = (__pyx_v_s + 2);
4054     }
4055     goto __pyx_L3;
4056   }
4057
4058   /* "csamtools.pyx":215
4059  *             values.append((<int16_t*>s)[0])
4060  *             s += 2
4061  *     elif auxtype == 'S':             # <<<<<<<<<<<<<<
4062  *         for x from 0 <= x < nvalues:
4063  *             values.append((<uint16_t*>s)[0])
4064  */
4065   __pyx_t_2 = (__pyx_v_auxtype == 'S');
4066   if (__pyx_t_2) {
4067
4068     /* "csamtools.pyx":216
4069  *             s += 2
4070  *     elif auxtype == 'S':
4071  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
4072  *             values.append((<uint16_t*>s)[0])
4073  *             s += 2
4074  */
4075     __pyx_t_3 = __pyx_v_nvalues;
4076     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4077
4078       /* "csamtools.pyx":217
4079  *     elif auxtype == 'S':
4080  *         for x from 0 <= x < nvalues:
4081  *             values.append((<uint16_t*>s)[0])             # <<<<<<<<<<<<<<
4082  *             s += 2
4083  *     elif auxtype == 'i':
4084  */
4085       __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 = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4086       __Pyx_GOTREF(__pyx_t_1);
4087       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4088       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4089
4090       /* "csamtools.pyx":218
4091  *         for x from 0 <= x < nvalues:
4092  *             values.append((<uint16_t*>s)[0])
4093  *             s += 2             # <<<<<<<<<<<<<<
4094  *     elif auxtype == 'i':
4095  *         for x from 0 <= x < nvalues:
4096  */
4097       __pyx_v_s = (__pyx_v_s + 2);
4098     }
4099     goto __pyx_L3;
4100   }
4101
4102   /* "csamtools.pyx":219
4103  *             values.append((<uint16_t*>s)[0])
4104  *             s += 2
4105  *     elif auxtype == 'i':             # <<<<<<<<<<<<<<
4106  *         for x from 0 <= x < nvalues:
4107  *             values.append((<int32_t*>s)[0])
4108  */
4109   __pyx_t_2 = (__pyx_v_auxtype == 'i');
4110   if (__pyx_t_2) {
4111
4112     /* "csamtools.pyx":220
4113  *             s += 2
4114  *     elif auxtype == 'i':
4115  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
4116  *             values.append((<int32_t*>s)[0])
4117  *             s += 4
4118  */
4119     __pyx_t_3 = __pyx_v_nvalues;
4120     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4121
4122       /* "csamtools.pyx":221
4123  *     elif auxtype == 'i':
4124  *         for x from 0 <= x < nvalues:
4125  *             values.append((<int32_t*>s)[0])             # <<<<<<<<<<<<<<
4126  *             s += 4
4127  *     elif auxtype == 'I':
4128  */
4129       __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 = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4130       __Pyx_GOTREF(__pyx_t_1);
4131       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4132       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4133
4134       /* "csamtools.pyx":222
4135  *         for x from 0 <= x < nvalues:
4136  *             values.append((<int32_t*>s)[0])
4137  *             s += 4             # <<<<<<<<<<<<<<
4138  *     elif auxtype == 'I':
4139  *         for x from 0 <= x < nvalues:
4140  */
4141       __pyx_v_s = (__pyx_v_s + 4);
4142     }
4143     goto __pyx_L3;
4144   }
4145
4146   /* "csamtools.pyx":223
4147  *             values.append((<int32_t*>s)[0])
4148  *             s += 4
4149  *     elif auxtype == 'I':             # <<<<<<<<<<<<<<
4150  *         for x from 0 <= x < nvalues:
4151  *             values.append((<uint32_t*>s)[0])
4152  */
4153   __pyx_t_2 = (__pyx_v_auxtype == 'I');
4154   if (__pyx_t_2) {
4155
4156     /* "csamtools.pyx":224
4157  *             s += 4
4158  *     elif auxtype == 'I':
4159  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
4160  *             values.append((<uint32_t*>s)[0])
4161  *             s += 4
4162  */
4163     __pyx_t_3 = __pyx_v_nvalues;
4164     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4165
4166       /* "csamtools.pyx":225
4167  *     elif auxtype == 'I':
4168  *         for x from 0 <= x < nvalues:
4169  *             values.append((<uint32_t*>s)[0])             # <<<<<<<<<<<<<<
4170  *             s += 4
4171  *     elif auxtype == 'f':
4172  */
4173       __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 = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4174       __Pyx_GOTREF(__pyx_t_1);
4175       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4176       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4177
4178       /* "csamtools.pyx":226
4179  *         for x from 0 <= x < nvalues:
4180  *             values.append((<uint32_t*>s)[0])
4181  *             s += 4             # <<<<<<<<<<<<<<
4182  *     elif auxtype == 'f':
4183  *         for x from 0 <= x < nvalues:
4184  */
4185       __pyx_v_s = (__pyx_v_s + 4);
4186     }
4187     goto __pyx_L3;
4188   }
4189
4190   /* "csamtools.pyx":227
4191  *             values.append((<uint32_t*>s)[0])
4192  *             s += 4
4193  *     elif auxtype == 'f':             # <<<<<<<<<<<<<<
4194  *         for x from 0 <= x < nvalues:
4195  *             values.append((<float*>s)[0])
4196  */
4197   __pyx_t_2 = (__pyx_v_auxtype == 'f');
4198   if (__pyx_t_2) {
4199
4200     /* "csamtools.pyx":228
4201  *             s += 4
4202  *     elif auxtype == 'f':
4203  *         for x from 0 <= x < nvalues:             # <<<<<<<<<<<<<<
4204  *             values.append((<float*>s)[0])
4205  *             s += 4
4206  */
4207     __pyx_t_3 = __pyx_v_nvalues;
4208     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4209
4210       /* "csamtools.pyx":229
4211  *     elif auxtype == 'f':
4212  *         for x from 0 <= x < nvalues:
4213  *             values.append((<float*>s)[0])             # <<<<<<<<<<<<<<
4214  *             s += 4
4215  * 
4216  */
4217       __pyx_t_1 = PyFloat_FromDouble((((float *)__pyx_v_s)[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4218       __Pyx_GOTREF(__pyx_t_1);
4219       __pyx_t_4 = PyList_Append(__pyx_v_values, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4220       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4221
4222       /* "csamtools.pyx":230
4223  *         for x from 0 <= x < nvalues:
4224  *             values.append((<float*>s)[0])
4225  *             s += 4             # <<<<<<<<<<<<<<
4226  * 
4227  *     return byte_size, nvalues, values
4228  */
4229       __pyx_v_s = (__pyx_v_s + 4);
4230     }
4231     goto __pyx_L3;
4232   }
4233   __pyx_L3:;
4234
4235   /* "csamtools.pyx":232
4236  *             s += 4
4237  * 
4238  *     return byte_size, nvalues, values             # <<<<<<<<<<<<<<
4239  * 
4240  * #####################################################################
4241  */
4242   __Pyx_XDECREF(__pyx_r);
4243   __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 = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4244   __Pyx_GOTREF(__pyx_t_1);
4245   __pyx_t_5 = __Pyx_PyInt_to_py_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4246   __Pyx_GOTREF(__pyx_t_5);
4247   __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4248   __Pyx_GOTREF(__pyx_t_6);
4249   PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
4250   __Pyx_GIVEREF(__pyx_t_1);
4251   PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
4252   __Pyx_GIVEREF(__pyx_t_5);
4253   __Pyx_INCREF(((PyObject *)__pyx_v_values));
4254   PyTuple_SET_ITEM(__pyx_t_6, 2, ((PyObject *)__pyx_v_values));
4255   __Pyx_GIVEREF(((PyObject *)__pyx_v_values));
4256   __pyx_t_1 = 0;
4257   __pyx_t_5 = 0;
4258   __pyx_r = ((PyObject *)__pyx_t_6);
4259   __pyx_t_6 = 0;
4260   goto __pyx_L0;
4261
4262   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4263   goto __pyx_L0;
4264   __pyx_L1_error:;
4265   __Pyx_XDECREF(__pyx_t_1);
4266   __Pyx_XDECREF(__pyx_t_5);
4267   __Pyx_XDECREF(__pyx_t_6);
4268   __Pyx_AddTraceback("csamtools.convertBinaryTagToList", __pyx_clineno, __pyx_lineno, __pyx_filename);
4269   __pyx_r = 0;
4270   __pyx_L0:;
4271   __Pyx_XDECREF(__pyx_v_values);
4272   __Pyx_XGIVEREF(__pyx_r);
4273   __Pyx_TraceReturn(__pyx_r);
4274   __Pyx_RefNannyFinishContext();
4275   return __pyx_r;
4276 }
4277
4278 /* "csamtools.pyx":239
4279  * ## Generic callbacks for inserting python callbacks.
4280  * #####################################################################
4281  * cdef int fetch_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
4282  *     '''callback for bam_fetch.
4283  * 
4284  */
4285
4286 static int __pyx_f_9csamtools_fetch_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
4287   PyObject *__pyx_v_a = NULL;
4288   int __pyx_r;
4289   __Pyx_RefNannyDeclarations
4290   PyObject *__pyx_t_1 = NULL;
4291   PyObject *__pyx_t_2 = NULL;
4292   int __pyx_lineno = 0;
4293   const char *__pyx_filename = NULL;
4294   int __pyx_clineno = 0;
4295   __Pyx_TraceDeclarations
4296   __Pyx_RefNannySetupContext("fetch_callback", 0);
4297   __Pyx_TraceCall("fetch_callback", __pyx_f[0], 239);
4298
4299   /* "csamtools.pyx":244
4300  *     calls function in *f* with a new :class:`AlignedRead` object as parameter.
4301  *     '''
4302  *     a = makeAlignedRead( alignment )             # <<<<<<<<<<<<<<
4303  *     (<object>f)(a)
4304  * 
4305  */
4306   __pyx_t_1 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4307   __Pyx_GOTREF(__pyx_t_1);
4308   __pyx_v_a = __pyx_t_1;
4309   __pyx_t_1 = 0;
4310
4311   /* "csamtools.pyx":245
4312  *     '''
4313  *     a = makeAlignedRead( alignment )
4314  *     (<object>f)(a)             # <<<<<<<<<<<<<<
4315  * 
4316  * class PileupColumn(object):
4317  */
4318   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4319   __Pyx_GOTREF(__pyx_t_1);
4320   __Pyx_INCREF(__pyx_v_a);
4321   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
4322   __Pyx_GIVEREF(__pyx_v_a);
4323   __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 = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4324   __Pyx_GOTREF(__pyx_t_2);
4325   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
4326   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4327
4328   __pyx_r = 0;
4329   goto __pyx_L0;
4330   __pyx_L1_error:;
4331   __Pyx_XDECREF(__pyx_t_1);
4332   __Pyx_XDECREF(__pyx_t_2);
4333   __Pyx_WriteUnraisable("csamtools.fetch_callback", __pyx_clineno, __pyx_lineno, __pyx_filename);
4334   __pyx_r = 0;
4335   __pyx_L0:;
4336   __Pyx_XDECREF(__pyx_v_a);
4337   __Pyx_TraceReturn(Py_None);
4338   __Pyx_RefNannyFinishContext();
4339   return __pyx_r;
4340 }
4341
4342 /* Python wrapper */
4343 static PyObject *__pyx_pw_9csamtools_12PileupColumn_1__str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4344 static char __pyx_doc_9csamtools_12PileupColumn___str__[] = "PileupColumn.__str__(self)";
4345 static PyMethodDef __pyx_mdef_9csamtools_12PileupColumn_1__str__ = {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pw_9csamtools_12PileupColumn_1__str__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_12PileupColumn___str__)};
4346 static PyObject *__pyx_pw_9csamtools_12PileupColumn_1__str__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4347   PyObject *__pyx_r = 0;
4348   __Pyx_RefNannyDeclarations
4349   __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
4350   __pyx_self = __pyx_self;
4351   __pyx_r = __pyx_pf_9csamtools_12PileupColumn___str__(__pyx_self, ((PyObject *)__pyx_v_self));
4352   __Pyx_RefNannyFinishContext();
4353   return __pyx_r;
4354 }
4355
4356 /* "csamtools.pyx":260
4357  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
4358  *     '''
4359  *     def __str__(self):             # <<<<<<<<<<<<<<
4360  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
4361  *             "\n" + "\n".join( map(str, self.pileups) )
4362  */
4363
4364 static PyObject *__pyx_pf_9csamtools_12PileupColumn___str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
4365   PyObject *__pyx_r = NULL;
4366   __Pyx_RefNannyDeclarations
4367   PyObject *__pyx_t_1 = NULL;
4368   PyObject *__pyx_t_2 = NULL;
4369   PyObject *__pyx_t_3 = NULL;
4370   PyObject *__pyx_t_4 = NULL;
4371   PyObject *__pyx_t_5 = NULL;
4372   int __pyx_lineno = 0;
4373   const char *__pyx_filename = NULL;
4374   int __pyx_clineno = 0;
4375   __Pyx_TraceDeclarations
4376   __Pyx_RefNannySetupContext("__str__", 0);
4377   __Pyx_TraceCall("__str__", __pyx_f[0], 260);
4378
4379   /* "csamtools.pyx":261
4380  *     '''
4381  *     def __str__(self):
4382  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
4383  *             "\n" + "\n".join( map(str, self.pileups) )
4384  * 
4385  */
4386   __Pyx_XDECREF(__pyx_r);
4387
4388   /* "csamtools.pyx":262
4389  *     def __str__(self):
4390  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
4391  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
4392  * 
4393  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
4394  */
4395   __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 = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4396   __Pyx_GOTREF(__pyx_t_1);
4397
4398   /* "csamtools.pyx":261
4399  *     '''
4400  *     def __str__(self):
4401  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
4402  *             "\n" + "\n".join( map(str, self.pileups) )
4403  * 
4404  */
4405   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4406   __Pyx_GOTREF(__pyx_t_2);
4407   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4408   __Pyx_GOTREF(__pyx_t_3);
4409   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4410   __Pyx_GOTREF(__pyx_t_4);
4411   __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4412   __Pyx_GOTREF(__pyx_t_5);
4413   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
4414   __Pyx_GIVEREF(__pyx_t_2);
4415   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
4416   __Pyx_GIVEREF(__pyx_t_3);
4417   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
4418   __Pyx_GIVEREF(__pyx_t_4);
4419   __pyx_t_2 = 0;
4420   __pyx_t_3 = 0;
4421   __pyx_t_4 = 0;
4422   __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4423   __Pyx_GOTREF(__pyx_t_4);
4424   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
4425   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
4426   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
4427   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
4428   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
4429   __pyx_t_5 = 0;
4430   __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 = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4431   __Pyx_GOTREF(__pyx_t_5);
4432   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
4433   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4434   __Pyx_GOTREF(__pyx_t_4);
4435   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
4436   __Pyx_GIVEREF(__pyx_t_5);
4437   __pyx_t_5 = 0;
4438   __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 = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4439   __Pyx_GOTREF(__pyx_t_5);
4440   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4441   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
4442   __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 = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4443   __Pyx_GOTREF(__pyx_t_4);
4444   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
4445
4446   /* "csamtools.pyx":262
4447  *     def __str__(self):
4448  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
4449  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
4450  * 
4451  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
4452  */
4453   __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 = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4454   __Pyx_GOTREF(__pyx_t_5);
4455   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4456   __Pyx_GOTREF(__pyx_t_1);
4457   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4458   __Pyx_GOTREF(__pyx_t_3);
4459   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
4460   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
4461   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
4462   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
4463   __Pyx_GIVEREF(__pyx_t_1);
4464   __pyx_t_1 = 0;
4465   __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 = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4466   __Pyx_GOTREF(__pyx_t_1);
4467   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
4468   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4469   __Pyx_GOTREF(__pyx_t_3);
4470   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
4471   __Pyx_GIVEREF(__pyx_t_1);
4472   __pyx_t_1 = 0;
4473   __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 = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4474   __Pyx_GOTREF(__pyx_t_1);
4475   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
4476   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
4477   __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4478   __Pyx_GOTREF(__pyx_t_3);
4479   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
4480   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4481   __pyx_r = __pyx_t_3;
4482   __pyx_t_3 = 0;
4483   goto __pyx_L0;
4484
4485   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4486   goto __pyx_L0;
4487   __pyx_L1_error:;
4488   __Pyx_XDECREF(__pyx_t_1);
4489   __Pyx_XDECREF(__pyx_t_2);
4490   __Pyx_XDECREF(__pyx_t_3);
4491   __Pyx_XDECREF(__pyx_t_4);
4492   __Pyx_XDECREF(__pyx_t_5);
4493   __Pyx_AddTraceback("csamtools.PileupColumn.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
4494   __pyx_r = NULL;
4495   __pyx_L0:;
4496   __Pyx_XGIVEREF(__pyx_r);
4497   __Pyx_TraceReturn(__pyx_r);
4498   __Pyx_RefNannyFinishContext();
4499   return __pyx_r;
4500 }
4501
4502 /* "csamtools.pyx":264
4503  *             "\n" + "\n".join( map(str, self.pileups) )
4504  * 
4505  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):             # <<<<<<<<<<<<<<
4506  *     '''callback for pileup.
4507  * 
4508  */
4509
4510 static int __pyx_f_9csamtools_pileup_callback(uint32_t __pyx_v_tid, uint32_t __pyx_v_pos, int __pyx_v_n, bam_pileup1_t *__pyx_v_pl, void *__pyx_v_f) {
4511   PyObject *__pyx_v_p = NULL;
4512   PyObject *__pyx_v_pileups = NULL;
4513   int __pyx_v_x;
4514   int __pyx_r;
4515   __Pyx_RefNannyDeclarations
4516   PyObject *__pyx_t_1 = NULL;
4517   PyObject *__pyx_t_2 = NULL;
4518   int __pyx_t_3;
4519   int __pyx_t_4;
4520   int __pyx_lineno = 0;
4521   const char *__pyx_filename = NULL;
4522   int __pyx_clineno = 0;
4523   __Pyx_TraceDeclarations
4524   __Pyx_RefNannySetupContext("pileup_callback", 0);
4525   __Pyx_TraceCall("pileup_callback", __pyx_f[0], 264);
4526
4527   /* "csamtools.pyx":281
4528  *     '''
4529  * 
4530  *     p = PileupColumn()             # <<<<<<<<<<<<<<
4531  *     p.tid = tid
4532  *     p.pos = pos
4533  */
4534   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PileupColumn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4535   __Pyx_GOTREF(__pyx_t_1);
4536   __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 = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4537   __Pyx_GOTREF(__pyx_t_2);
4538   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4539   __pyx_v_p = __pyx_t_2;
4540   __pyx_t_2 = 0;
4541
4542   /* "csamtools.pyx":282
4543  * 
4544  *     p = PileupColumn()
4545  *     p.tid = tid             # <<<<<<<<<<<<<<
4546  *     p.pos = pos
4547  *     p.n = n
4548  */
4549   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4550   __Pyx_GOTREF(__pyx_t_2);
4551   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__tid, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4552   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4553
4554   /* "csamtools.pyx":283
4555  *     p = PileupColumn()
4556  *     p.tid = tid
4557  *     p.pos = pos             # <<<<<<<<<<<<<<
4558  *     p.n = n
4559  *     pileups = []
4560  */
4561   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4562   __Pyx_GOTREF(__pyx_t_2);
4563   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pos, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4564   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4565
4566   /* "csamtools.pyx":284
4567  *     p.tid = tid
4568  *     p.pos = pos
4569  *     p.n = n             # <<<<<<<<<<<<<<
4570  *     pileups = []
4571  * 
4572  */
4573   __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4574   __Pyx_GOTREF(__pyx_t_2);
4575   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__n, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4576   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4577
4578   /* "csamtools.pyx":285
4579  *     p.pos = pos
4580  *     p.n = n
4581  *     pileups = []             # <<<<<<<<<<<<<<
4582  * 
4583  *     cdef int x
4584  */
4585   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4586   __Pyx_GOTREF(__pyx_t_2);
4587   __pyx_v_pileups = __pyx_t_2;
4588   __pyx_t_2 = 0;
4589
4590   /* "csamtools.pyx":288
4591  * 
4592  *     cdef int x
4593  *     for x from 0 <= x < n:             # <<<<<<<<<<<<<<
4594  *         pileups.append( makePileupRead( &(pl[x]) ) )
4595  *     p.pileups = pileups
4596  */
4597   __pyx_t_3 = __pyx_v_n;
4598   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
4599
4600     /* "csamtools.pyx":289
4601  *     cdef int x
4602  *     for x from 0 <= x < n:
4603  *         pileups.append( makePileupRead( &(pl[x]) ) )             # <<<<<<<<<<<<<<
4604  *     p.pileups = pileups
4605  * 
4606  */
4607     __pyx_t_2 = __pyx_f_9csamtools_makePileupRead((&(__pyx_v_pl[__pyx_v_x]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4608     __Pyx_GOTREF(__pyx_t_2);
4609     __pyx_t_4 = PyList_Append(__pyx_v_pileups, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4610     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4611   }
4612
4613   /* "csamtools.pyx":290
4614  *     for x from 0 <= x < n:
4615  *         pileups.append( makePileupRead( &(pl[x]) ) )
4616  *     p.pileups = pileups             # <<<<<<<<<<<<<<
4617  * 
4618  *     (<object>f)(p)
4619  */
4620   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pileups, ((PyObject *)__pyx_v_pileups)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4621
4622   /* "csamtools.pyx":292
4623  *     p.pileups = pileups
4624  * 
4625  *     (<object>f)(p)             # <<<<<<<<<<<<<<
4626  * 
4627  * cdef int pileup_fetch_callback( bam1_t *b, void *data):
4628  */
4629   __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4630   __Pyx_GOTREF(__pyx_t_2);
4631   __Pyx_INCREF(__pyx_v_p);
4632   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_p);
4633   __Pyx_GIVEREF(__pyx_v_p);
4634   __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 = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4635   __Pyx_GOTREF(__pyx_t_1);
4636   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4637   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4638
4639   __pyx_r = 0;
4640   goto __pyx_L0;
4641   __pyx_L1_error:;
4642   __Pyx_XDECREF(__pyx_t_1);
4643   __Pyx_XDECREF(__pyx_t_2);
4644   __Pyx_WriteUnraisable("csamtools.pileup_callback", __pyx_clineno, __pyx_lineno, __pyx_filename);
4645   __pyx_r = 0;
4646   __pyx_L0:;
4647   __Pyx_XDECREF(__pyx_v_p);
4648   __Pyx_XDECREF(__pyx_v_pileups);
4649   __Pyx_TraceReturn(Py_None);
4650   __Pyx_RefNannyFinishContext();
4651   return __pyx_r;
4652 }
4653
4654 /* "csamtools.pyx":294
4655  *     (<object>f)(p)
4656  * 
4657  * cdef int pileup_fetch_callback( bam1_t *b, void *data):             # <<<<<<<<<<<<<<
4658  *     '''callback for bam_fetch.
4659  * 
4660  */
4661
4662 static int __pyx_f_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, void *__pyx_v_data) {
4663   bam_plbuf_t *__pyx_v_buf;
4664   int __pyx_r;
4665   __Pyx_RefNannyDeclarations
4666   __Pyx_TraceDeclarations
4667   __Pyx_RefNannySetupContext("pileup_fetch_callback", 0);
4668   __Pyx_TraceCall("pileup_fetch_callback", __pyx_f[0], 294);
4669
4670   /* "csamtools.pyx":300
4671  *     '''
4672  *     cdef bam_plbuf_t * buf
4673  *     buf = <bam_plbuf_t*>data             # <<<<<<<<<<<<<<
4674  *     bam_plbuf_push(b, buf)
4675  *     return 0
4676  */
4677   __pyx_v_buf = ((bam_plbuf_t *)__pyx_v_data);
4678
4679   /* "csamtools.pyx":301
4680  *     cdef bam_plbuf_t * buf
4681  *     buf = <bam_plbuf_t*>data
4682  *     bam_plbuf_push(b, buf)             # <<<<<<<<<<<<<<
4683  *     return 0
4684  * 
4685  */
4686   bam_plbuf_push(__pyx_v_b, __pyx_v_buf);
4687
4688   /* "csamtools.pyx":302
4689  *     buf = <bam_plbuf_t*>data
4690  *     bam_plbuf_push(b, buf)
4691  *     return 0             # <<<<<<<<<<<<<<
4692  * 
4693  * class StderrStore():
4694  */
4695   __pyx_r = 0;
4696   goto __pyx_L0;
4697
4698   __pyx_r = 0;
4699   __pyx_L0:;
4700   __Pyx_TraceReturn(Py_None);
4701   __Pyx_RefNannyFinishContext();
4702   return __pyx_r;
4703 }
4704
4705 /* Python wrapper */
4706 static PyObject *__pyx_pw_9csamtools_11StderrStore_1__init__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4707 static char __pyx_doc_9csamtools_11StderrStore___init__[] = "StderrStore.__init__(self)";
4708 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_1__init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pw_9csamtools_11StderrStore_1__init__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore___init__)};
4709 static PyObject *__pyx_pw_9csamtools_11StderrStore_1__init__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4710   PyObject *__pyx_r = 0;
4711   __Pyx_RefNannyDeclarations
4712   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
4713   __pyx_self = __pyx_self;
4714   __pyx_r = __pyx_pf_9csamtools_11StderrStore___init__(__pyx_self, ((PyObject *)__pyx_v_self));
4715   __Pyx_RefNannyFinishContext();
4716   return __pyx_r;
4717 }
4718
4719 /* "csamtools.pyx":308
4720  *     stderr is captured.
4721  *     '''
4722  *     def __init__(self):             # <<<<<<<<<<<<<<
4723  *         return
4724  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
4725  */
4726
4727 static PyObject *__pyx_pf_9csamtools_11StderrStore___init__(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
4728   PyObject *__pyx_r = NULL;
4729   __Pyx_RefNannyDeclarations
4730   __Pyx_TraceDeclarations
4731   __Pyx_RefNannySetupContext("__init__", 0);
4732   __Pyx_TraceCall("__init__", __pyx_f[0], 308);
4733
4734   /* "csamtools.pyx":309
4735  *     '''
4736  *     def __init__(self):
4737  *         return             # <<<<<<<<<<<<<<
4738  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
4739  *         self.stderr_save = Outs( sys.stderr.fileno() )
4740  */
4741   __Pyx_XDECREF(__pyx_r);
4742   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4743   goto __pyx_L0;
4744
4745   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4746   __pyx_L0:;
4747   __Pyx_XGIVEREF(__pyx_r);
4748   __Pyx_TraceReturn(__pyx_r);
4749   __Pyx_RefNannyFinishContext();
4750   return __pyx_r;
4751 }
4752
4753 /* Python wrapper */
4754 static PyObject *__pyx_pw_9csamtools_11StderrStore_3readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4755 static char __pyx_doc_9csamtools_11StderrStore_2readAndRelease[] = "StderrStore.readAndRelease(self)";
4756 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_3readAndRelease = {__Pyx_NAMESTR("readAndRelease"), (PyCFunction)__pyx_pw_9csamtools_11StderrStore_3readAndRelease, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_2readAndRelease)};
4757 static PyObject *__pyx_pw_9csamtools_11StderrStore_3readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4758   PyObject *__pyx_r = 0;
4759   __Pyx_RefNannyDeclarations
4760   __Pyx_RefNannySetupContext("readAndRelease (wrapper)", 0);
4761   __pyx_self = __pyx_self;
4762   __pyx_r = __pyx_pf_9csamtools_11StderrStore_2readAndRelease(__pyx_self, ((PyObject *)__pyx_v_self));
4763   __Pyx_RefNannyFinishContext();
4764   return __pyx_r;
4765 }
4766
4767 /* "csamtools.pyx":314
4768  *         self.stderr_save.setfd( self.stderr_h )
4769  * 
4770  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
4771  *         return []
4772  *         self.stderr_save.restore()
4773  */
4774
4775 static PyObject *__pyx_pf_9csamtools_11StderrStore_2readAndRelease(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
4776   PyObject *__pyx_r = NULL;
4777   __Pyx_RefNannyDeclarations
4778   PyObject *__pyx_t_1 = NULL;
4779   int __pyx_lineno = 0;
4780   const char *__pyx_filename = NULL;
4781   int __pyx_clineno = 0;
4782   __Pyx_TraceDeclarations
4783   __Pyx_RefNannySetupContext("readAndRelease", 0);
4784   __Pyx_TraceCall("readAndRelease", __pyx_f[0], 314);
4785
4786   /* "csamtools.pyx":315
4787  * 
4788  *     def readAndRelease( self ):
4789  *         return []             # <<<<<<<<<<<<<<
4790  *         self.stderr_save.restore()
4791  *         lines = []
4792  */
4793   __Pyx_XDECREF(__pyx_r);
4794   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4795   __Pyx_GOTREF(__pyx_t_1);
4796   __pyx_r = ((PyObject *)__pyx_t_1);
4797   __pyx_t_1 = 0;
4798   goto __pyx_L0;
4799
4800   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4801   goto __pyx_L0;
4802   __pyx_L1_error:;
4803   __Pyx_XDECREF(__pyx_t_1);
4804   __Pyx_AddTraceback("csamtools.StderrStore.readAndRelease", __pyx_clineno, __pyx_lineno, __pyx_filename);
4805   __pyx_r = NULL;
4806   __pyx_L0:;
4807   __Pyx_XGIVEREF(__pyx_r);
4808   __Pyx_TraceReturn(__pyx_r);
4809   __Pyx_RefNannyFinishContext();
4810   return __pyx_r;
4811 }
4812
4813 /* Python wrapper */
4814 static PyObject *__pyx_pw_9csamtools_11StderrStore_5release(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4815 static char __pyx_doc_9csamtools_11StderrStore_4release[] = "StderrStore.release(self)";
4816 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_5release = {__Pyx_NAMESTR("release"), (PyCFunction)__pyx_pw_9csamtools_11StderrStore_5release, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_4release)};
4817 static PyObject *__pyx_pw_9csamtools_11StderrStore_5release(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4818   PyObject *__pyx_r = 0;
4819   __Pyx_RefNannyDeclarations
4820   __Pyx_RefNannySetupContext("release (wrapper)", 0);
4821   __pyx_self = __pyx_self;
4822   __pyx_r = __pyx_pf_9csamtools_11StderrStore_4release(__pyx_self, ((PyObject *)__pyx_v_self));
4823   __Pyx_RefNannyFinishContext();
4824   return __pyx_r;
4825 }
4826
4827 /* "csamtools.pyx":323
4828  *         return lines
4829  * 
4830  *     def release(self):             # <<<<<<<<<<<<<<
4831  *         return
4832  *         self.stderr_save.restore()
4833  */
4834
4835 static PyObject *__pyx_pf_9csamtools_11StderrStore_4release(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
4836   PyObject *__pyx_r = NULL;
4837   __Pyx_RefNannyDeclarations
4838   __Pyx_TraceDeclarations
4839   __Pyx_RefNannySetupContext("release", 0);
4840   __Pyx_TraceCall("release", __pyx_f[0], 323);
4841
4842   /* "csamtools.pyx":324
4843  * 
4844  *     def release(self):
4845  *         return             # <<<<<<<<<<<<<<
4846  *         self.stderr_save.restore()
4847  *         if os.path.exists(self.stderr_f):
4848  */
4849   __Pyx_XDECREF(__pyx_r);
4850   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4851   goto __pyx_L0;
4852
4853   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4854   __pyx_L0:;
4855   __Pyx_XGIVEREF(__pyx_r);
4856   __Pyx_TraceReturn(__pyx_r);
4857   __Pyx_RefNannyFinishContext();
4858   return __pyx_r;
4859 }
4860
4861 /* Python wrapper */
4862 static PyObject *__pyx_pw_9csamtools_11StderrStore_7__del__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4863 static char __pyx_doc_9csamtools_11StderrStore_6__del__[] = "StderrStore.__del__(self)";
4864 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_7__del__ = {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pw_9csamtools_11StderrStore_7__del__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_6__del__)};
4865 static PyObject *__pyx_pw_9csamtools_11StderrStore_7__del__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4866   PyObject *__pyx_r = 0;
4867   __Pyx_RefNannyDeclarations
4868   __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
4869   __pyx_self = __pyx_self;
4870   __pyx_r = __pyx_pf_9csamtools_11StderrStore_6__del__(__pyx_self, ((PyObject *)__pyx_v_self));
4871   __Pyx_RefNannyFinishContext();
4872   return __pyx_r;
4873 }
4874
4875 /* "csamtools.pyx":329
4876  *             os.remove( self.stderr_f )
4877  * 
4878  *     def __del__(self):             # <<<<<<<<<<<<<<
4879  *         self.release()
4880  * 
4881  */
4882
4883 static PyObject *__pyx_pf_9csamtools_11StderrStore_6__del__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
4884   PyObject *__pyx_r = NULL;
4885   __Pyx_RefNannyDeclarations
4886   PyObject *__pyx_t_1 = NULL;
4887   PyObject *__pyx_t_2 = NULL;
4888   int __pyx_lineno = 0;
4889   const char *__pyx_filename = NULL;
4890   int __pyx_clineno = 0;
4891   __Pyx_TraceDeclarations
4892   __Pyx_RefNannySetupContext("__del__", 0);
4893   __Pyx_TraceCall("__del__", __pyx_f[0], 329);
4894
4895   /* "csamtools.pyx":330
4896  * 
4897  *     def __del__(self):
4898  *         self.release()             # <<<<<<<<<<<<<<
4899  * 
4900  * class StderrStoreWindows():
4901  */
4902   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4903   __Pyx_GOTREF(__pyx_t_1);
4904   __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 = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4905   __Pyx_GOTREF(__pyx_t_2);
4906   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4907   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4908
4909   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4910   goto __pyx_L0;
4911   __pyx_L1_error:;
4912   __Pyx_XDECREF(__pyx_t_1);
4913   __Pyx_XDECREF(__pyx_t_2);
4914   __Pyx_AddTraceback("csamtools.StderrStore.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename);
4915   __pyx_r = NULL;
4916   __pyx_L0:;
4917   __Pyx_XGIVEREF(__pyx_r);
4918   __Pyx_TraceReturn(__pyx_r);
4919   __Pyx_RefNannyFinishContext();
4920   return __pyx_r;
4921 }
4922
4923 /* Python wrapper */
4924 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_1__init__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4925 static char __pyx_doc_9csamtools_18StderrStoreWindows___init__[] = "StderrStoreWindows.__init__(self)";
4926 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows_1__init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pw_9csamtools_18StderrStoreWindows_1__init__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows___init__)};
4927 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_1__init__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4928   PyObject *__pyx_r = 0;
4929   __Pyx_RefNannyDeclarations
4930   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
4931   __pyx_self = __pyx_self;
4932   __pyx_r = __pyx_pf_9csamtools_18StderrStoreWindows___init__(__pyx_self, ((PyObject *)__pyx_v_self));
4933   __Pyx_RefNannyFinishContext();
4934   return __pyx_r;
4935 }
4936
4937 /* "csamtools.pyx":334
4938  * class StderrStoreWindows():
4939  *     '''does nothing. stderr can't be redirected on windows'''
4940  *     def __init__(self): pass             # <<<<<<<<<<<<<<
4941  *     def readAndRelease(self): return []
4942  *     def release(self): pass
4943  */
4944
4945 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows___init__(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
4946   PyObject *__pyx_r = NULL;
4947   __Pyx_RefNannyDeclarations
4948   __Pyx_TraceDeclarations
4949   __Pyx_RefNannySetupContext("__init__", 0);
4950   __Pyx_TraceCall("__init__", __pyx_f[0], 334);
4951
4952   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4953   __Pyx_XGIVEREF(__pyx_r);
4954   __Pyx_TraceReturn(__pyx_r);
4955   __Pyx_RefNannyFinishContext();
4956   return __pyx_r;
4957 }
4958
4959 /* Python wrapper */
4960 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_3readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
4961 static char __pyx_doc_9csamtools_18StderrStoreWindows_2readAndRelease[] = "StderrStoreWindows.readAndRelease(self)";
4962 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows_3readAndRelease = {__Pyx_NAMESTR("readAndRelease"), (PyCFunction)__pyx_pw_9csamtools_18StderrStoreWindows_3readAndRelease, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows_2readAndRelease)};
4963 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_3readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self) {
4964   PyObject *__pyx_r = 0;
4965   __Pyx_RefNannyDeclarations
4966   __Pyx_RefNannySetupContext("readAndRelease (wrapper)", 0);
4967   __pyx_self = __pyx_self;
4968   __pyx_r = __pyx_pf_9csamtools_18StderrStoreWindows_2readAndRelease(__pyx_self, ((PyObject *)__pyx_v_self));
4969   __Pyx_RefNannyFinishContext();
4970   return __pyx_r;
4971 }
4972
4973 /* "csamtools.pyx":335
4974  *     '''does nothing. stderr can't be redirected on windows'''
4975  *     def __init__(self): pass
4976  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
4977  *     def release(self): pass
4978  * 
4979  */
4980
4981 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_2readAndRelease(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
4982   PyObject *__pyx_r = NULL;
4983   __Pyx_RefNannyDeclarations
4984   PyObject *__pyx_t_1 = NULL;
4985   int __pyx_lineno = 0;
4986   const char *__pyx_filename = NULL;
4987   int __pyx_clineno = 0;
4988   __Pyx_TraceDeclarations
4989   __Pyx_RefNannySetupContext("readAndRelease", 0);
4990   __Pyx_TraceCall("readAndRelease", __pyx_f[0], 335);
4991   __Pyx_XDECREF(__pyx_r);
4992   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4993   __Pyx_GOTREF(__pyx_t_1);
4994   __pyx_r = ((PyObject *)__pyx_t_1);
4995   __pyx_t_1 = 0;
4996   goto __pyx_L0;
4997
4998   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4999   goto __pyx_L0;
5000   __pyx_L1_error:;
5001   __Pyx_XDECREF(__pyx_t_1);
5002   __Pyx_AddTraceback("csamtools.StderrStoreWindows.readAndRelease", __pyx_clineno, __pyx_lineno, __pyx_filename);
5003   __pyx_r = NULL;
5004   __pyx_L0:;
5005   __Pyx_XGIVEREF(__pyx_r);
5006   __Pyx_TraceReturn(__pyx_r);
5007   __Pyx_RefNannyFinishContext();
5008   return __pyx_r;
5009 }
5010
5011 /* Python wrapper */
5012 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_5release(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
5013 static char __pyx_doc_9csamtools_18StderrStoreWindows_4release[] = "StderrStoreWindows.release(self)";
5014 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows_5release = {__Pyx_NAMESTR("release"), (PyCFunction)__pyx_pw_9csamtools_18StderrStoreWindows_5release, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows_4release)};
5015 static PyObject *__pyx_pw_9csamtools_18StderrStoreWindows_5release(PyObject *__pyx_self, PyObject *__pyx_v_self) {
5016   PyObject *__pyx_r = 0;
5017   __Pyx_RefNannyDeclarations
5018   __Pyx_RefNannySetupContext("release (wrapper)", 0);
5019   __pyx_self = __pyx_self;
5020   __pyx_r = __pyx_pf_9csamtools_18StderrStoreWindows_4release(__pyx_self, ((PyObject *)__pyx_v_self));
5021   __Pyx_RefNannyFinishContext();
5022   return __pyx_r;
5023 }
5024
5025 /* "csamtools.pyx":336
5026  *     def __init__(self): pass
5027  *     def readAndRelease(self): return []
5028  *     def release(self): pass             # <<<<<<<<<<<<<<
5029  * 
5030  * if platform.system()=='Windows':
5031  */
5032
5033 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_4release(CYTHON_UNUSED PyObject *__pyx_self, CYTHON_UNUSED PyObject *__pyx_v_self) {
5034   PyObject *__pyx_r = NULL;
5035   __Pyx_RefNannyDeclarations
5036   __Pyx_TraceDeclarations
5037   __Pyx_RefNannySetupContext("release", 0);
5038   __Pyx_TraceCall("release", __pyx_f[0], 336);
5039
5040   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5041   __Pyx_XGIVEREF(__pyx_r);
5042   __Pyx_TraceReturn(__pyx_r);
5043   __Pyx_RefNannyFinishContext();
5044   return __pyx_r;
5045 }
5046
5047 /* Python wrapper */
5048 static int __pyx_pw_9csamtools_9Fastafile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
5049 static int __pyx_pw_9csamtools_9Fastafile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
5050   PyObject *__pyx_v_args = 0;
5051   PyObject *__pyx_v_kwargs = 0;
5052   int __pyx_r;
5053   __Pyx_RefNannyDeclarations
5054   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
5055   if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
5056   __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
5057   if (unlikely(!__pyx_v_kwargs)) return -1;
5058   __Pyx_GOTREF(__pyx_v_kwargs);
5059   __Pyx_INCREF(__pyx_args);
5060   __pyx_v_args = __pyx_args;
5061   __pyx_r = __pyx_pf_9csamtools_9Fastafile___cinit__(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);
5062   __Pyx_XDECREF(__pyx_v_args);
5063   __Pyx_XDECREF(__pyx_v_kwargs);
5064   __Pyx_RefNannyFinishContext();
5065   return __pyx_r;
5066 }
5067
5068 /* "csamtools.pyx":387
5069  *     '''
5070  * 
5071  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
5072  *         self.fastafile = NULL
5073  *         self._filename = NULL
5074  */
5075
5076 static int __pyx_pf_9csamtools_9Fastafile___cinit__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
5077   int __pyx_r;
5078   __Pyx_RefNannyDeclarations
5079   PyObject *__pyx_t_1 = NULL;
5080   PyObject *__pyx_t_2 = NULL;
5081   PyObject *__pyx_t_3 = NULL;
5082   PyObject *__pyx_t_4 = NULL;
5083   int __pyx_lineno = 0;
5084   const char *__pyx_filename = NULL;
5085   int __pyx_clineno = 0;
5086   __Pyx_TraceDeclarations
5087   __Pyx_RefNannySetupContext("__cinit__", 0);
5088   __Pyx_TraceCall("__cinit__", __pyx_f[0], 387);
5089
5090   /* "csamtools.pyx":388
5091  * 
5092  *     def __cinit__(self, *args, **kwargs ):
5093  *         self.fastafile = NULL             # <<<<<<<<<<<<<<
5094  *         self._filename = NULL
5095  *         self._open( *args, **kwargs )
5096  */
5097   __pyx_v_self->fastafile = NULL;
5098
5099   /* "csamtools.pyx":389
5100  *     def __cinit__(self, *args, **kwargs ):
5101  *         self.fastafile = NULL
5102  *         self._filename = NULL             # <<<<<<<<<<<<<<
5103  *         self._open( *args, **kwargs )
5104  * 
5105  */
5106   __pyx_v_self->_filename = NULL;
5107
5108   /* "csamtools.pyx":390
5109  *         self.fastafile = NULL
5110  *         self._filename = NULL
5111  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
5112  * 
5113  *     def _isOpen( self ):
5114  */
5115   __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 = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5116   __Pyx_GOTREF(__pyx_t_1);
5117   __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5118   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
5119   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
5120   __Pyx_INCREF(__pyx_t_3);
5121   __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 = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5122   __Pyx_GOTREF(__pyx_t_4);
5123   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5124   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5125   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
5126   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
5127
5128   __pyx_r = 0;
5129   goto __pyx_L0;
5130   __pyx_L1_error:;
5131   __Pyx_XDECREF(__pyx_t_1);
5132   __Pyx_XDECREF(__pyx_t_2);
5133   __Pyx_XDECREF(__pyx_t_3);
5134   __Pyx_XDECREF(__pyx_t_4);
5135   __Pyx_AddTraceback("csamtools.Fastafile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
5136   __pyx_r = -1;
5137   __pyx_L0:;
5138   __Pyx_TraceReturn(Py_None);
5139   __Pyx_RefNannyFinishContext();
5140   return __pyx_r;
5141 }
5142
5143 /* Python wrapper */
5144 static PyObject *__pyx_pw_9csamtools_9Fastafile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
5145 static char __pyx_doc_9csamtools_9Fastafile_2_isOpen[] = "Fastafile._isOpen(self)\nreturn true if samfile has been opened.";
5146 static PyObject *__pyx_pw_9csamtools_9Fastafile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
5147   PyObject *__pyx_r = 0;
5148   __Pyx_RefNannyDeclarations
5149   __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
5150   __pyx_r = __pyx_pf_9csamtools_9Fastafile_2_isOpen(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self));
5151   __Pyx_RefNannyFinishContext();
5152   return __pyx_r;
5153 }
5154
5155 /* "csamtools.pyx":392
5156  *         self._open( *args, **kwargs )
5157  * 
5158  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
5159  *         '''return true if samfile has been opened.'''
5160  *         return self.fastafile != NULL
5161  */
5162
5163 static PyObject *__pyx_pf_9csamtools_9Fastafile_2_isOpen(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self) {
5164   PyObject *__pyx_r = NULL;
5165   __Pyx_RefNannyDeclarations
5166   PyObject *__pyx_t_1 = NULL;
5167   int __pyx_lineno = 0;
5168   const char *__pyx_filename = NULL;
5169   int __pyx_clineno = 0;
5170   __Pyx_TraceDeclarations
5171   __Pyx_RefNannySetupContext("_isOpen", 0);
5172   __Pyx_TraceCall("_isOpen", __pyx_f[0], 392);
5173
5174   /* "csamtools.pyx":394
5175  *     def _isOpen( self ):
5176  *         '''return true if samfile has been opened.'''
5177  *         return self.fastafile != NULL             # <<<<<<<<<<<<<<
5178  * 
5179  *     def __len__(self):
5180  */
5181   __Pyx_XDECREF(__pyx_r);
5182   __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->fastafile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5183   __Pyx_GOTREF(__pyx_t_1);
5184   __pyx_r = __pyx_t_1;
5185   __pyx_t_1 = 0;
5186   goto __pyx_L0;
5187
5188   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5189   goto __pyx_L0;
5190   __pyx_L1_error:;
5191   __Pyx_XDECREF(__pyx_t_1);
5192   __Pyx_AddTraceback("csamtools.Fastafile._isOpen", __pyx_clineno, __pyx_lineno, __pyx_filename);
5193   __pyx_r = NULL;
5194   __pyx_L0:;
5195   __Pyx_XGIVEREF(__pyx_r);
5196   __Pyx_TraceReturn(__pyx_r);
5197   __Pyx_RefNannyFinishContext();
5198   return __pyx_r;
5199 }
5200
5201 /* Python wrapper */
5202 static Py_ssize_t __pyx_pw_9csamtools_9Fastafile_5__len__(PyObject *__pyx_v_self); /*proto*/
5203 static Py_ssize_t __pyx_pw_9csamtools_9Fastafile_5__len__(PyObject *__pyx_v_self) {
5204   Py_ssize_t __pyx_r;
5205   __Pyx_RefNannyDeclarations
5206   __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
5207   __pyx_r = __pyx_pf_9csamtools_9Fastafile_4__len__(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self));
5208   __Pyx_RefNannyFinishContext();
5209   return __pyx_r;
5210 }
5211
5212 /* "csamtools.pyx":396
5213  *         return self.fastafile != NULL
5214  * 
5215  *     def __len__(self):             # <<<<<<<<<<<<<<
5216  *         if self.fastafile == NULL:
5217  *             raise ValueError( "calling len() on closed file" )
5218  */
5219
5220 static Py_ssize_t __pyx_pf_9csamtools_9Fastafile_4__len__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self) {
5221   Py_ssize_t __pyx_r;
5222   __Pyx_RefNannyDeclarations
5223   int __pyx_t_1;
5224   PyObject *__pyx_t_2 = NULL;
5225   int __pyx_lineno = 0;
5226   const char *__pyx_filename = NULL;
5227   int __pyx_clineno = 0;
5228   __Pyx_TraceDeclarations
5229   __Pyx_RefNannySetupContext("__len__", 0);
5230   __Pyx_TraceCall("__len__", __pyx_f[0], 396);
5231
5232   /* "csamtools.pyx":397
5233  * 
5234  *     def __len__(self):
5235  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
5236  *             raise ValueError( "calling len() on closed file" )
5237  * 
5238  */
5239   __pyx_t_1 = (__pyx_v_self->fastafile == NULL);
5240   if (__pyx_t_1) {
5241
5242     /* "csamtools.pyx":398
5243  *     def __len__(self):
5244  *         if self.fastafile == NULL:
5245  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
5246  * 
5247  *         return faidx_fetch_nseq(self.fastafile)
5248  */
5249     __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 = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5250     __Pyx_GOTREF(__pyx_t_2);
5251     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
5252     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5253     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5254     goto __pyx_L3;
5255   }
5256   __pyx_L3:;
5257
5258   /* "csamtools.pyx":400
5259  *             raise ValueError( "calling len() on closed file" )
5260  * 
5261  *         return faidx_fetch_nseq(self.fastafile)             # <<<<<<<<<<<<<<
5262  * 
5263  *     def _open( self,
5264  */
5265   __pyx_r = faidx_fetch_nseq(__pyx_v_self->fastafile);
5266   goto __pyx_L0;
5267
5268   __pyx_r = 0;
5269   goto __pyx_L0;
5270   __pyx_L1_error:;
5271   __Pyx_XDECREF(__pyx_t_2);
5272   __Pyx_AddTraceback("csamtools.Fastafile.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
5273   __pyx_r = -1;
5274   __pyx_L0:;
5275   __Pyx_TraceReturn(Py_None);
5276   __Pyx_RefNannyFinishContext();
5277   return __pyx_r;
5278 }
5279
5280 /* Python wrapper */
5281 static PyObject *__pyx_pw_9csamtools_9Fastafile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /*proto*/
5282 static char __pyx_doc_9csamtools_9Fastafile_6_open[] = "Fastafile._open(self, filename)\nopen an indexed fasta file.\n\n        This method expects an indexed fasta file.\n        ";
5283 static PyObject *__pyx_pw_9csamtools_9Fastafile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
5284   PyObject *__pyx_r = 0;
5285   __Pyx_RefNannyDeclarations
5286   __Pyx_RefNannySetupContext("_open (wrapper)", 0);
5287   __pyx_r = __pyx_pf_9csamtools_9Fastafile_6_open(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self), ((PyObject *)__pyx_v_filename));
5288   __Pyx_RefNannyFinishContext();
5289   return __pyx_r;
5290 }
5291
5292 /* "csamtools.pyx":402
5293  *         return faidx_fetch_nseq(self.fastafile)
5294  * 
5295  *     def _open( self,             # <<<<<<<<<<<<<<
5296  *                filename ):
5297  *         '''open an indexed fasta file.
5298  */
5299
5300 static PyObject *__pyx_pf_9csamtools_9Fastafile_6_open(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_filename) {
5301   PyObject *__pyx_r = NULL;
5302   __Pyx_RefNannyDeclarations
5303   int __pyx_t_1;
5304   PyObject *__pyx_t_2 = NULL;
5305   PyObject *__pyx_t_3 = NULL;
5306   char *__pyx_t_4;
5307   int __pyx_lineno = 0;
5308   const char *__pyx_filename = NULL;
5309   int __pyx_clineno = 0;
5310   __Pyx_TraceDeclarations
5311   __Pyx_RefNannySetupContext("_open", 0);
5312   __Pyx_TraceCall("_open", __pyx_f[0], 402);
5313   __Pyx_INCREF(__pyx_v_filename);
5314
5315   /* "csamtools.pyx":410
5316  * 
5317  *         # close a previously opened file
5318  *         if self.fastafile != NULL: self.close()             # <<<<<<<<<<<<<<
5319  *         if self._filename != NULL: free(self._filename)
5320  *         filename = _my_encodeFilename(filename)
5321  */
5322   __pyx_t_1 = (__pyx_v_self->fastafile != NULL);
5323   if (__pyx_t_1) {
5324     __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 = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5325     __Pyx_GOTREF(__pyx_t_2);
5326     __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 = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5327     __Pyx_GOTREF(__pyx_t_3);
5328     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5329     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5330     goto __pyx_L3;
5331   }
5332   __pyx_L3:;
5333
5334   /* "csamtools.pyx":411
5335  *         # close a previously opened file
5336  *         if self.fastafile != NULL: self.close()
5337  *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
5338  *         filename = _my_encodeFilename(filename)
5339  *         self._filename = strdup(filename)
5340  */
5341   __pyx_t_1 = (__pyx_v_self->_filename != NULL);
5342   if (__pyx_t_1) {
5343     free(__pyx_v_self->_filename);
5344     goto __pyx_L4;
5345   }
5346   __pyx_L4:;
5347
5348   /* "csamtools.pyx":412
5349  *         if self.fastafile != NULL: self.close()
5350  *         if self._filename != NULL: free(self._filename)
5351  *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
5352  *         self._filename = strdup(filename)
5353  *         self.fastafile = fai_load( filename )
5354  */
5355   __pyx_t_3 = ((PyObject *)__pyx_f_9csamtools__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5356   __Pyx_GOTREF(__pyx_t_3);
5357   __Pyx_DECREF(__pyx_v_filename);
5358   __pyx_v_filename = __pyx_t_3;
5359   __pyx_t_3 = 0;
5360
5361   /* "csamtools.pyx":413
5362  *         if self._filename != NULL: free(self._filename)
5363  *         filename = _my_encodeFilename(filename)
5364  *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
5365  *         self.fastafile = fai_load( filename )
5366  * 
5367  */
5368   __pyx_t_4 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5369   __pyx_v_self->_filename = strdup(__pyx_t_4);
5370
5371   /* "csamtools.pyx":414
5372  *         filename = _my_encodeFilename(filename)
5373  *         self._filename = strdup(filename)
5374  *         self.fastafile = fai_load( filename )             # <<<<<<<<<<<<<<
5375  * 
5376  *         if self.fastafile == NULL:
5377  */
5378   __pyx_t_4 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5379   __pyx_v_self->fastafile = fai_load(__pyx_t_4);
5380
5381   /* "csamtools.pyx":416
5382  *         self.fastafile = fai_load( filename )
5383  * 
5384  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
5385  *             raise IOError("could not open file `%s`" % filename )
5386  * 
5387  */
5388   __pyx_t_1 = (__pyx_v_self->fastafile == NULL);
5389   if (__pyx_t_1) {
5390
5391     /* "csamtools.pyx":417
5392  * 
5393  *         if self.fastafile == NULL:
5394  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
5395  * 
5396  *     def close( self ):
5397  */
5398     __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 = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5399     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
5400     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5401     __Pyx_GOTREF(__pyx_t_2);
5402     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
5403     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
5404     __pyx_t_3 = 0;
5405     __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 = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5406     __Pyx_GOTREF(__pyx_t_3);
5407     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5408     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
5409     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5410     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5411     goto __pyx_L5;
5412   }
5413   __pyx_L5:;
5414
5415   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5416   goto __pyx_L0;
5417   __pyx_L1_error:;
5418   __Pyx_XDECREF(__pyx_t_2);
5419   __Pyx_XDECREF(__pyx_t_3);
5420   __Pyx_AddTraceback("csamtools.Fastafile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
5421   __pyx_r = NULL;
5422   __pyx_L0:;
5423   __Pyx_XDECREF(__pyx_v_filename);
5424   __Pyx_XGIVEREF(__pyx_r);
5425   __Pyx_TraceReturn(__pyx_r);
5426   __Pyx_RefNannyFinishContext();
5427   return __pyx_r;
5428 }
5429
5430 /* Python wrapper */
5431 static PyObject *__pyx_pw_9csamtools_9Fastafile_9close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
5432 static char __pyx_doc_9csamtools_9Fastafile_8close[] = "Fastafile.close(self)";
5433 static PyObject *__pyx_pw_9csamtools_9Fastafile_9close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
5434   PyObject *__pyx_r = 0;
5435   __Pyx_RefNannyDeclarations
5436   __Pyx_RefNannySetupContext("close (wrapper)", 0);
5437   __pyx_r = __pyx_pf_9csamtools_9Fastafile_8close(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self));
5438   __Pyx_RefNannyFinishContext();
5439   return __pyx_r;
5440 }
5441
5442 /* "csamtools.pyx":419
5443  *             raise IOError("could not open file `%s`" % filename )
5444  * 
5445  *     def close( self ):             # <<<<<<<<<<<<<<
5446  *         if self.fastafile != NULL:
5447  *             fai_destroy( self.fastafile )
5448  */
5449
5450 static PyObject *__pyx_pf_9csamtools_9Fastafile_8close(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self) {
5451   PyObject *__pyx_r = NULL;
5452   __Pyx_RefNannyDeclarations
5453   int __pyx_t_1;
5454   __Pyx_TraceDeclarations
5455   __Pyx_RefNannySetupContext("close", 0);
5456   __Pyx_TraceCall("close", __pyx_f[0], 419);
5457
5458   /* "csamtools.pyx":420
5459  * 
5460  *     def close( self ):
5461  *         if self.fastafile != NULL:             # <<<<<<<<<<<<<<
5462  *             fai_destroy( self.fastafile )
5463  *             self.fastafile = NULL
5464  */
5465   __pyx_t_1 = (__pyx_v_self->fastafile != NULL);
5466   if (__pyx_t_1) {
5467
5468     /* "csamtools.pyx":421
5469  *     def close( self ):
5470  *         if self.fastafile != NULL:
5471  *             fai_destroy( self.fastafile )             # <<<<<<<<<<<<<<
5472  *             self.fastafile = NULL
5473  * 
5474  */
5475     fai_destroy(__pyx_v_self->fastafile);
5476
5477     /* "csamtools.pyx":422
5478  *         if self.fastafile != NULL:
5479  *             fai_destroy( self.fastafile )
5480  *             self.fastafile = NULL             # <<<<<<<<<<<<<<
5481  * 
5482  *     def __dealloc__(self):
5483  */
5484     __pyx_v_self->fastafile = NULL;
5485     goto __pyx_L3;
5486   }
5487   __pyx_L3:;
5488
5489   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5490   __Pyx_XGIVEREF(__pyx_r);
5491   __Pyx_TraceReturn(__pyx_r);
5492   __Pyx_RefNannyFinishContext();
5493   return __pyx_r;
5494 }
5495
5496 /* Python wrapper */
5497 static void __pyx_pw_9csamtools_9Fastafile_11__dealloc__(PyObject *__pyx_v_self); /*proto*/
5498 static void __pyx_pw_9csamtools_9Fastafile_11__dealloc__(PyObject *__pyx_v_self) {
5499   __Pyx_RefNannyDeclarations
5500   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
5501   __pyx_pf_9csamtools_9Fastafile_10__dealloc__(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self));
5502   __Pyx_RefNannyFinishContext();
5503 }
5504
5505 /* "csamtools.pyx":424
5506  *             self.fastafile = NULL
5507  * 
5508  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
5509  *         self.close()
5510  *         if self._filename != NULL: free(self._filename)
5511  */
5512
5513 static void __pyx_pf_9csamtools_9Fastafile_10__dealloc__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self) {
5514   __Pyx_RefNannyDeclarations
5515   PyObject *__pyx_t_1 = NULL;
5516   PyObject *__pyx_t_2 = NULL;
5517   int __pyx_t_3;
5518   int __pyx_lineno = 0;
5519   const char *__pyx_filename = NULL;
5520   int __pyx_clineno = 0;
5521   __Pyx_TraceDeclarations
5522   __Pyx_RefNannySetupContext("__dealloc__", 0);
5523   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 424);
5524
5525   /* "csamtools.pyx":425
5526  * 
5527  *     def __dealloc__(self):
5528  *         self.close()             # <<<<<<<<<<<<<<
5529  *         if self._filename != NULL: free(self._filename)
5530  * 
5531  */
5532   __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 = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5533   __Pyx_GOTREF(__pyx_t_1);
5534   __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 = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5535   __Pyx_GOTREF(__pyx_t_2);
5536   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5537   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5538
5539   /* "csamtools.pyx":426
5540  *     def __dealloc__(self):
5541  *         self.close()
5542  *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
5543  * 
5544  *     property filename:
5545  */
5546   __pyx_t_3 = (__pyx_v_self->_filename != NULL);
5547   if (__pyx_t_3) {
5548     free(__pyx_v_self->_filename);
5549     goto __pyx_L3;
5550   }
5551   __pyx_L3:;
5552
5553   goto __pyx_L0;
5554   __pyx_L1_error:;
5555   __Pyx_XDECREF(__pyx_t_1);
5556   __Pyx_XDECREF(__pyx_t_2);
5557   __Pyx_AddTraceback("csamtools.Fastafile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename);
5558   __pyx_L0:;
5559   __Pyx_TraceReturn(Py_None);
5560   __Pyx_RefNannyFinishContext();
5561 }
5562
5563 /* Python wrapper */
5564 static PyObject *__pyx_pw_9csamtools_9Fastafile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
5565 static PyObject *__pyx_pw_9csamtools_9Fastafile_8filename_1__get__(PyObject *__pyx_v_self) {
5566   PyObject *__pyx_r = 0;
5567   __Pyx_RefNannyDeclarations
5568   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
5569   __pyx_r = __pyx_pf_9csamtools_9Fastafile_8filename___get__(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self));
5570   __Pyx_RefNannyFinishContext();
5571   return __pyx_r;
5572 }
5573
5574 /* "csamtools.pyx":430
5575  *     property filename:
5576  *         '''number of :term:`filename` associated with this object.'''
5577  *         def __get__(self):             # <<<<<<<<<<<<<<
5578  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
5579  *             return self._filename
5580  */
5581
5582 static PyObject *__pyx_pf_9csamtools_9Fastafile_8filename___get__(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self) {
5583   PyObject *__pyx_r = NULL;
5584   __Pyx_RefNannyDeclarations
5585   PyObject *__pyx_t_1 = NULL;
5586   PyObject *__pyx_t_2 = NULL;
5587   int __pyx_t_3;
5588   int __pyx_t_4;
5589   int __pyx_lineno = 0;
5590   const char *__pyx_filename = NULL;
5591   int __pyx_clineno = 0;
5592   __Pyx_TraceDeclarations
5593   __Pyx_RefNannySetupContext("__get__", 0);
5594   __Pyx_TraceCall("__get__", __pyx_f[0], 430);
5595
5596   /* "csamtools.pyx":431
5597  *         '''number of :term:`filename` associated with this object.'''
5598  *         def __get__(self):
5599  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
5600  *             return self._filename
5601  * 
5602  */
5603   __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 = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5604   __Pyx_GOTREF(__pyx_t_1);
5605   __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 = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5606   __Pyx_GOTREF(__pyx_t_2);
5607   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5608   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5609   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5610   __pyx_t_4 = (!__pyx_t_3);
5611   if (__pyx_t_4) {
5612     __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 = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5613     __Pyx_GOTREF(__pyx_t_2);
5614     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
5615     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5616     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5617     goto __pyx_L3;
5618   }
5619   __pyx_L3:;
5620
5621   /* "csamtools.pyx":432
5622  *         def __get__(self):
5623  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
5624  *             return self._filename             # <<<<<<<<<<<<<<
5625  * 
5626  *     def fetch( self,
5627  */
5628   __Pyx_XDECREF(__pyx_r);
5629   __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5630   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
5631   __pyx_r = ((PyObject *)__pyx_t_2);
5632   __pyx_t_2 = 0;
5633   goto __pyx_L0;
5634
5635   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5636   goto __pyx_L0;
5637   __pyx_L1_error:;
5638   __Pyx_XDECREF(__pyx_t_1);
5639   __Pyx_XDECREF(__pyx_t_2);
5640   __Pyx_AddTraceback("csamtools.Fastafile.filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
5641   __pyx_r = NULL;
5642   __pyx_L0:;
5643   __Pyx_XGIVEREF(__pyx_r);
5644   __Pyx_TraceReturn(__pyx_r);
5645   __Pyx_RefNannyFinishContext();
5646   return __pyx_r;
5647 }
5648
5649 /* Python wrapper */
5650 static PyObject *__pyx_pw_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
5651 static char __pyx_doc_9csamtools_9Fastafile_12fetch[] = "Fastafile.fetch(self, reference=None, start=None, end=None, region=None)\n*(reference = None, start = None, end = None, region = None)*\n\n        fetch :meth:`AlignedRead` objects in a :term:`region` using 0-based indexing.\n\n        The region is specified by :term:`reference`, *start* and *end*.\n\n        fetch returns an empty string if the region is out of range or addresses an unknown *reference*.\n\n        If *reference* is given and *start* is None, the sequence from the\n        first base is returned. Similarly, if *end* is None, the sequence\n        until the last base is returned.\n\n        Alternatively, a samtools :term:`region` string can be supplied.\n        ";
5652 static PyObject *__pyx_pw_9csamtools_9Fastafile_13fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
5653   PyObject *__pyx_v_reference = 0;
5654   PyObject *__pyx_v_start = 0;
5655   PyObject *__pyx_v_end = 0;
5656   PyObject *__pyx_v_region = 0;
5657   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
5658   PyObject *__pyx_r = 0;
5659   __Pyx_RefNannyDeclarations
5660   __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
5661   {
5662     PyObject* values[4] = {0,0,0,0};
5663
5664     /* "csamtools.pyx":435
5665  * 
5666  *     def fetch( self,
5667  *                reference = None,             # <<<<<<<<<<<<<<
5668  *                start = None,
5669  *                end = None,
5670  */
5671     values[0] = ((PyObject *)Py_None);
5672
5673     /* "csamtools.pyx":436
5674  *     def fetch( self,
5675  *                reference = None,
5676  *                start = None,             # <<<<<<<<<<<<<<
5677  *                end = None,
5678  *                region = None):
5679  */
5680     values[1] = ((PyObject *)Py_None);
5681
5682     /* "csamtools.pyx":437
5683  *                reference = None,
5684  *                start = None,
5685  *                end = None,             # <<<<<<<<<<<<<<
5686  *                region = None):
5687  * 
5688  */
5689     values[2] = ((PyObject *)Py_None);
5690
5691     /* "csamtools.pyx":438
5692  *                start = None,
5693  *                end = None,
5694  *                region = None):             # <<<<<<<<<<<<<<
5695  * 
5696  *         '''*(reference = None, start = None, end = None, region = None)*
5697  */
5698     values[3] = ((PyObject *)Py_None);
5699     if (unlikely(__pyx_kwds)) {
5700       Py_ssize_t kw_args;
5701       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
5702       switch (pos_args) {
5703         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
5704         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
5705         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
5706         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
5707         case  0: break;
5708         default: goto __pyx_L5_argtuple_error;
5709       }
5710       kw_args = PyDict_Size(__pyx_kwds);
5711       switch (pos_args) {
5712         case  0:
5713         if (kw_args > 0) {
5714           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
5715           if (value) { values[0] = value; kw_args--; }
5716         }
5717         case  1:
5718         if (kw_args > 0) {
5719           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
5720           if (value) { values[1] = value; kw_args--; }
5721         }
5722         case  2:
5723         if (kw_args > 0) {
5724           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
5725           if (value) { values[2] = value; kw_args--; }
5726         }
5727         case  3:
5728         if (kw_args > 0) {
5729           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
5730           if (value) { values[3] = value; kw_args--; }
5731         }
5732       }
5733       if (unlikely(kw_args > 0)) {
5734         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5735       }
5736     } else {
5737       switch (PyTuple_GET_SIZE(__pyx_args)) {
5738         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
5739         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
5740         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
5741         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
5742         case  0: break;
5743         default: goto __pyx_L5_argtuple_error;
5744       }
5745     }
5746     __pyx_v_reference = values[0];
5747     __pyx_v_start = values[1];
5748     __pyx_v_end = values[2];
5749     __pyx_v_region = values[3];
5750   }
5751   goto __pyx_L4_argument_unpacking_done;
5752   __pyx_L5_argtuple_error:;
5753   __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5754   __pyx_L3_error:;
5755   __Pyx_AddTraceback("csamtools.Fastafile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
5756   __Pyx_RefNannyFinishContext();
5757   return NULL;
5758   __pyx_L4_argument_unpacking_done:;
5759   __pyx_r = __pyx_pf_9csamtools_9Fastafile_12fetch(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region);
5760   __Pyx_RefNannyFinishContext();
5761   return __pyx_r;
5762 }
5763
5764 /* "csamtools.pyx":434
5765  *             return self._filename
5766  * 
5767  *     def fetch( self,             # <<<<<<<<<<<<<<
5768  *                reference = None,
5769  *                start = None,
5770  */
5771
5772 static PyObject *__pyx_pf_9csamtools_9Fastafile_12fetch(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region) {
5773   int __pyx_v_length;
5774   char *__pyx_v_seq;
5775   PyObject *__pyx_v_py_seq = NULL;
5776   PyObject *__pyx_r = NULL;
5777   __Pyx_RefNannyDeclarations
5778   PyObject *__pyx_t_1 = NULL;
5779   PyObject *__pyx_t_2 = NULL;
5780   int __pyx_t_3;
5781   int __pyx_t_4;
5782   char *__pyx_t_5;
5783   int __pyx_lineno = 0;
5784   const char *__pyx_filename = NULL;
5785   int __pyx_clineno = 0;
5786   __Pyx_TraceDeclarations
5787   __Pyx_RefNannySetupContext("fetch", 0);
5788   __Pyx_TraceCall("fetch", __pyx_f[0], 434);
5789   __Pyx_INCREF(__pyx_v_start);
5790   __Pyx_INCREF(__pyx_v_end);
5791   __Pyx_INCREF(__pyx_v_region);
5792
5793   /* "csamtools.pyx":455
5794  *         '''
5795  * 
5796  *         if not self._isOpen():             # <<<<<<<<<<<<<<
5797  *             raise ValueError( "I/O operation on closed file" )
5798  * 
5799  */
5800   __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 = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5801   __Pyx_GOTREF(__pyx_t_1);
5802   __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 = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5803   __Pyx_GOTREF(__pyx_t_2);
5804   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5805   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5806   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5807   __pyx_t_4 = (!__pyx_t_3);
5808   if (__pyx_t_4) {
5809
5810     /* "csamtools.pyx":456
5811  * 
5812  *         if not self._isOpen():
5813  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
5814  * 
5815  *         cdef int length
5816  */
5817     __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 = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5818     __Pyx_GOTREF(__pyx_t_2);
5819     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
5820     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5821     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5822     goto __pyx_L3;
5823   }
5824   __pyx_L3:;
5825
5826   /* "csamtools.pyx":461
5827  *         cdef char * seq
5828  * 
5829  *         if not region:             # <<<<<<<<<<<<<<
5830  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
5831  *             if start is None: start = 0
5832  */
5833   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5834   __pyx_t_3 = (!__pyx_t_4);
5835   if (__pyx_t_3) {
5836
5837     /* "csamtools.pyx":462
5838  * 
5839  *         if not region:
5840  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
5841  *             if start is None: start = 0
5842  *             if end is None: end = max_pos -1
5843  */
5844     __pyx_t_3 = (__pyx_v_reference == Py_None);
5845     if (__pyx_t_3) {
5846       __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 = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5847       __Pyx_GOTREF(__pyx_t_2);
5848       __Pyx_Raise(__pyx_t_2, 0, 0, 0);
5849       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5850       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5851       goto __pyx_L5;
5852     }
5853     __pyx_L5:;
5854
5855     /* "csamtools.pyx":463
5856  *         if not region:
5857  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
5858  *             if start is None: start = 0             # <<<<<<<<<<<<<<
5859  *             if end is None: end = max_pos -1
5860  * 
5861  */
5862     __pyx_t_3 = (__pyx_v_start == Py_None);
5863     if (__pyx_t_3) {
5864       __Pyx_INCREF(__pyx_int_0);
5865       __Pyx_DECREF(__pyx_v_start);
5866       __pyx_v_start = __pyx_int_0;
5867       goto __pyx_L6;
5868     }
5869     __pyx_L6:;
5870
5871     /* "csamtools.pyx":464
5872  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
5873  *             if start is None: start = 0
5874  *             if end is None: end = max_pos -1             # <<<<<<<<<<<<<<
5875  * 
5876  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
5877  */
5878     __pyx_t_3 = (__pyx_v_end == Py_None);
5879     if (__pyx_t_3) {
5880       __pyx_t_2 = PyInt_FromLong((__pyx_v_9csamtools_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5881       __Pyx_GOTREF(__pyx_t_2);
5882       __Pyx_DECREF(__pyx_v_end);
5883       __pyx_v_end = __pyx_t_2;
5884       __pyx_t_2 = 0;
5885       goto __pyx_L7;
5886     }
5887     __pyx_L7:;
5888
5889     /* "csamtools.pyx":466
5890  *             if end is None: end = max_pos -1
5891  * 
5892  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )             # <<<<<<<<<<<<<<
5893  *             if start == end: return b""
5894  *             # valid ranges are from 0 to 2^29-1
5895  */
5896     __pyx_t_2 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5897     __Pyx_GOTREF(__pyx_t_2);
5898     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5899     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5900     if (__pyx_t_3) {
5901       __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5902       __Pyx_GOTREF(__pyx_t_2);
5903       __Pyx_INCREF(__pyx_v_start);
5904       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
5905       __Pyx_GIVEREF(__pyx_v_start);
5906       __Pyx_INCREF(__pyx_v_end);
5907       PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
5908       __Pyx_GIVEREF(__pyx_v_end);
5909       __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 = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5910       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
5911       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5912       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5913       __Pyx_GOTREF(__pyx_t_2);
5914       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
5915       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
5916       __pyx_t_1 = 0;
5917       __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 = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5918       __Pyx_GOTREF(__pyx_t_1);
5919       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5920       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
5921       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5922       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5923       goto __pyx_L8;
5924     }
5925     __pyx_L8:;
5926
5927     /* "csamtools.pyx":467
5928  * 
5929  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
5930  *             if start == end: return b""             # <<<<<<<<<<<<<<
5931  *             # valid ranges are from 0 to 2^29-1
5932  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
5933  */
5934     __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5935     __Pyx_GOTREF(__pyx_t_1);
5936     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5937     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5938     if (__pyx_t_3) {
5939       __Pyx_XDECREF(__pyx_r);
5940       __Pyx_INCREF(((PyObject *)__pyx_kp_b_16));
5941       __pyx_r = ((PyObject *)__pyx_kp_b_16);
5942       goto __pyx_L0;
5943       goto __pyx_L9;
5944     }
5945     __pyx_L9:;
5946
5947     /* "csamtools.pyx":469
5948  *             if start == end: return b""
5949  *             # valid ranges are from 0 to 2^29-1
5950  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
5951  *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
5952  *             # note: faidx_fetch_seq has a bug such that out-of-range access
5953  */
5954     __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_start, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5955     __Pyx_GOTREF(__pyx_t_1);
5956     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
5957       __Pyx_DECREF(__pyx_t_1);
5958       __pyx_t_2 = PyInt_FromLong(__pyx_v_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5959       __Pyx_GOTREF(__pyx_t_2);
5960       __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5961       __Pyx_GOTREF(__pyx_t_1);
5962       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5963     }
5964     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5965     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5966     __pyx_t_4 = (!__pyx_t_3);
5967     if (__pyx_t_4) {
5968       __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 = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5969       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
5970       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5971       __Pyx_GOTREF(__pyx_t_2);
5972       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
5973       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
5974       __pyx_t_1 = 0;
5975       __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 = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5976       __Pyx_GOTREF(__pyx_t_1);
5977       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5978       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
5979       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5980       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5981       goto __pyx_L10;
5982     }
5983     __pyx_L10:;
5984
5985     /* "csamtools.pyx":470
5986  *             # valid ranges are from 0 to 2^29-1
5987  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
5988  *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
5989  *             # note: faidx_fetch_seq has a bug such that out-of-range access
5990  *             # always returns the last residue. Hence do not use faidx_fetch_seq,
5991  */
5992     __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_end, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5993     __Pyx_GOTREF(__pyx_t_1);
5994     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
5995       __Pyx_DECREF(__pyx_t_1);
5996       __pyx_t_2 = PyInt_FromLong(__pyx_v_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5997       __Pyx_GOTREF(__pyx_t_2);
5998       __pyx_t_1 = PyObject_RichCompare(__pyx_v_end, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5999       __Pyx_GOTREF(__pyx_t_1);
6000       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6001     }
6002     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6003     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6004     __pyx_t_3 = (!__pyx_t_4);
6005     if (__pyx_t_3) {
6006       __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 = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6007       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
6008       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6009       __Pyx_GOTREF(__pyx_t_2);
6010       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
6011       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
6012       __pyx_t_1 = 0;
6013       __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 = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6014       __Pyx_GOTREF(__pyx_t_1);
6015       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6016       __Pyx_Raise(__pyx_t_1, 0, 0, 0);
6017       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6018       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6019       goto __pyx_L11;
6020     }
6021     __pyx_L11:;
6022
6023     /* "csamtools.pyx":479
6024  *             #                       end-1,
6025  *             #                       &length)
6026  *             region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
6027  *             if PY_MAJOR_VERSION >= 3:
6028  *                 region = region.encode('ascii')
6029  */
6030     __pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6031     __Pyx_GOTREF(__pyx_t_1);
6032     __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6033     __Pyx_GOTREF(__pyx_t_2);
6034     __Pyx_INCREF(__pyx_v_reference);
6035     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
6036     __Pyx_GIVEREF(__pyx_v_reference);
6037     PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
6038     __Pyx_GIVEREF(__pyx_t_1);
6039     __Pyx_INCREF(__pyx_v_end);
6040     PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
6041     __Pyx_GIVEREF(__pyx_v_end);
6042     __pyx_t_1 = 0;
6043     __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 = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6044     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
6045     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6046     __Pyx_DECREF(__pyx_v_region);
6047     __pyx_v_region = ((PyObject *)__pyx_t_1);
6048     __pyx_t_1 = 0;
6049
6050     /* "csamtools.pyx":480
6051  *             #                       &length)
6052  *             region = "%s:%i-%i" % (reference, start+1, end)
6053  *             if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
6054  *                 region = region.encode('ascii')
6055  *             seq = fai_fetch( self.fastafile,
6056  */
6057     __pyx_t_3 = (PY_MAJOR_VERSION >= 3);
6058     if (__pyx_t_3) {
6059
6060       /* "csamtools.pyx":481
6061  *             region = "%s:%i-%i" % (reference, start+1, end)
6062  *             if PY_MAJOR_VERSION >= 3:
6063  *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
6064  *             seq = fai_fetch( self.fastafile,
6065  *                              region,
6066  */
6067       __pyx_t_1 = PyObject_GetAttr(__pyx_v_region, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6068       __Pyx_GOTREF(__pyx_t_1);
6069       __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 = 481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6070       __Pyx_GOTREF(__pyx_t_2);
6071       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6072       __Pyx_DECREF(__pyx_v_region);
6073       __pyx_v_region = __pyx_t_2;
6074       __pyx_t_2 = 0;
6075       goto __pyx_L12;
6076     }
6077     __pyx_L12:;
6078
6079     /* "csamtools.pyx":483
6080  *                 region = region.encode('ascii')
6081  *             seq = fai_fetch( self.fastafile,
6082  *                              region,             # <<<<<<<<<<<<<<
6083  *                              &length )
6084  *         else:
6085  */
6086     __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6087
6088     /* "csamtools.pyx":484
6089  *             seq = fai_fetch( self.fastafile,
6090  *                              region,
6091  *                              &length )             # <<<<<<<<<<<<<<
6092  *         else:
6093  *             # samtools adds a '\0' at the end
6094  */
6095     __pyx_v_seq = fai_fetch(__pyx_v_self->fastafile, __pyx_t_5, (&__pyx_v_length));
6096     goto __pyx_L4;
6097   }
6098   /*else*/ {
6099
6100     /* "csamtools.pyx":487
6101  *         else:
6102  *             # samtools adds a '\0' at the end
6103  *             seq = fai_fetch( self.fastafile, region, &length )             # <<<<<<<<<<<<<<
6104  * 
6105  *         # copy to python
6106  */
6107     __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6108     __pyx_v_seq = fai_fetch(__pyx_v_self->fastafile, __pyx_t_5, (&__pyx_v_length));
6109   }
6110   __pyx_L4:;
6111
6112   /* "csamtools.pyx":490
6113  * 
6114  *         # copy to python
6115  *         if seq == NULL:             # <<<<<<<<<<<<<<
6116  *             return b""
6117  *         else:
6118  */
6119   __pyx_t_3 = (__pyx_v_seq == NULL);
6120   if (__pyx_t_3) {
6121
6122     /* "csamtools.pyx":491
6123  *         # copy to python
6124  *         if seq == NULL:
6125  *             return b""             # <<<<<<<<<<<<<<
6126  *         else:
6127  *             try:
6128  */
6129     __Pyx_XDECREF(__pyx_r);
6130     __Pyx_INCREF(((PyObject *)__pyx_kp_b_16));
6131     __pyx_r = ((PyObject *)__pyx_kp_b_16);
6132     goto __pyx_L0;
6133     goto __pyx_L13;
6134   }
6135   /*else*/ {
6136
6137     /* "csamtools.pyx":493
6138  *             return b""
6139  *         else:
6140  *             try:             # <<<<<<<<<<<<<<
6141  *                 py_seq = seq[:length]
6142  *             finally:
6143  */
6144     /*try:*/ {
6145
6146       /* "csamtools.pyx":494
6147  *         else:
6148  *             try:
6149  *                 py_seq = seq[:length]             # <<<<<<<<<<<<<<
6150  *             finally:
6151  *                 free(seq)
6152  */
6153       __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 = 494; __pyx_clineno = __LINE__; goto __pyx_L15;}
6154       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6155       __pyx_v_py_seq = __pyx_t_2;
6156       __pyx_t_2 = 0;
6157     }
6158
6159     /* "csamtools.pyx":496
6160  *                 py_seq = seq[:length]
6161  *             finally:
6162  *                 free(seq)             # <<<<<<<<<<<<<<
6163  * 
6164  *         return py_seq
6165  */
6166     /*finally:*/ {
6167       int __pyx_why;
6168       PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
6169       int __pyx_exc_lineno;
6170       __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
6171       __pyx_why = 0; goto __pyx_L16;
6172       __pyx_L15: {
6173         __pyx_why = 4;
6174         __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
6175         __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
6176         __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
6177         __pyx_exc_lineno = __pyx_lineno;
6178         goto __pyx_L16;
6179       }
6180       __pyx_L16:;
6181       free(__pyx_v_seq);
6182       switch (__pyx_why) {
6183         case 4: {
6184           __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
6185           __pyx_lineno = __pyx_exc_lineno;
6186           __pyx_exc_type = 0;
6187           __pyx_exc_value = 0;
6188           __pyx_exc_tb = 0;
6189           goto __pyx_L1_error;
6190         }
6191       }
6192     }
6193   }
6194   __pyx_L13:;
6195
6196   /* "csamtools.pyx":498
6197  *                 free(seq)
6198  * 
6199  *         return py_seq             # <<<<<<<<<<<<<<
6200  * 
6201  *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):
6202  */
6203   __Pyx_XDECREF(__pyx_r);
6204   __Pyx_INCREF(((PyObject *)__pyx_v_py_seq));
6205   __pyx_r = ((PyObject *)__pyx_v_py_seq);
6206   goto __pyx_L0;
6207
6208   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6209   goto __pyx_L0;
6210   __pyx_L1_error:;
6211   __Pyx_XDECREF(__pyx_t_1);
6212   __Pyx_XDECREF(__pyx_t_2);
6213   __Pyx_AddTraceback("csamtools.Fastafile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
6214   __pyx_r = NULL;
6215   __pyx_L0:;
6216   __Pyx_XDECREF(__pyx_v_py_seq);
6217   __Pyx_XDECREF(__pyx_v_start);
6218   __Pyx_XDECREF(__pyx_v_end);
6219   __Pyx_XDECREF(__pyx_v_region);
6220   __Pyx_XGIVEREF(__pyx_r);
6221   __Pyx_TraceReturn(__pyx_r);
6222   __Pyx_RefNannyFinishContext();
6223   return __pyx_r;
6224 }
6225
6226 /* "csamtools.pyx":500
6227  *         return py_seq
6228  * 
6229  *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):             # <<<<<<<<<<<<<<
6230  *         '''fetch sequence for reference, start and end'''
6231  * 
6232  */
6233
6234 static char *__pyx_f_9csamtools_9Fastafile__fetch(struct __pyx_obj_9csamtools_Fastafile *__pyx_v_self, char *__pyx_v_reference, int __pyx_v_start, int __pyx_v_end, int *__pyx_v_length) {
6235   char *__pyx_r;
6236   __Pyx_RefNannyDeclarations
6237   __Pyx_TraceDeclarations
6238   __Pyx_RefNannySetupContext("_fetch", 0);
6239   __Pyx_TraceCall("_fetch", __pyx_f[0], 500);
6240
6241   /* "csamtools.pyx":507
6242  *                                start,
6243  *                                end-1,
6244  *                                length )             # <<<<<<<<<<<<<<
6245  * 
6246  * #------------------------------------------------------------------------
6247  */
6248   __pyx_r = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length);
6249   goto __pyx_L0;
6250
6251   __pyx_r = 0;
6252   __pyx_L0:;
6253   __Pyx_TraceReturn(Py_None);
6254   __Pyx_RefNannyFinishContext();
6255   return __pyx_r;
6256 }
6257
6258 /* "csamtools.pyx":512
6259  * #------------------------------------------------------------------------
6260  * #------------------------------------------------------------------------
6261  * cdef int count_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
6262  *      '''callback for bam_fetch - count number of reads.
6263  *      '''
6264  */
6265
6266 static int __pyx_f_9csamtools_count_callback(CYTHON_UNUSED bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
6267   int *__pyx_v_counter;
6268   int __pyx_r;
6269   __Pyx_RefNannyDeclarations
6270   long __pyx_t_1;
6271   __Pyx_TraceDeclarations
6272   __Pyx_RefNannySetupContext("count_callback", 0);
6273   __Pyx_TraceCall("count_callback", __pyx_f[0], 512);
6274
6275   /* "csamtools.pyx":515
6276  *      '''callback for bam_fetch - count number of reads.
6277  *      '''
6278  *      cdef int* counter = (<int*>f)             # <<<<<<<<<<<<<<
6279  *      counter[0] += 1;
6280  * 
6281  */
6282   __pyx_v_counter = ((int *)__pyx_v_f);
6283
6284   /* "csamtools.pyx":516
6285  *      '''
6286  *      cdef int* counter = (<int*>f)
6287  *      counter[0] += 1;             # <<<<<<<<<<<<<<
6288  * 
6289  * ctypedef struct MateData:
6290  */
6291   __pyx_t_1 = 0;
6292   (__pyx_v_counter[__pyx_t_1]) = ((__pyx_v_counter[__pyx_t_1]) + 1);
6293
6294   __pyx_r = 0;
6295   __Pyx_TraceReturn(Py_None);
6296   __Pyx_RefNannyFinishContext();
6297   return __pyx_r;
6298 }
6299
6300 /* "csamtools.pyx":526
6301  * #------------------------------------------------------------------------
6302  * #------------------------------------------------------------------------
6303  * cdef int mate_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
6304  *      '''callback for bam_fetch = filter mate
6305  *      '''
6306  */
6307
6308 static int __pyx_f_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
6309   __pyx_t_9csamtools_MateData *__pyx_v_d;
6310   int __pyx_r;
6311   __Pyx_RefNannyDeclarations
6312   int __pyx_t_1;
6313   int __pyx_t_2;
6314   int __pyx_t_3;
6315   __Pyx_TraceDeclarations
6316   __Pyx_RefNannySetupContext("mate_callback", 0);
6317   __Pyx_TraceCall("mate_callback", __pyx_f[0], 526);
6318
6319   /* "csamtools.pyx":529
6320  *      '''callback for bam_fetch = filter mate
6321  *      '''
6322  *      cdef MateData * d = (<MateData*>f)             # <<<<<<<<<<<<<<
6323  *      # printf("mate = %p, name1 = %s, name2=%s\t%i\t%i\t%i\n",
6324  *      #        d.mate, d.name, bam1_qname(alignment),
6325  */
6326   __pyx_v_d = ((__pyx_t_9csamtools_MateData *)__pyx_v_f);
6327
6328   /* "csamtools.pyx":534
6329  *      #        d.flag, alignment.core.flag, alignment.core.flag & d.flag)
6330  * 
6331  *      if d.mate == NULL:             # <<<<<<<<<<<<<<
6332  *          # could be sped up by comparing the lengths of query strings first
6333  *          # using l_qname
6334  */
6335   __pyx_t_1 = (__pyx_v_d->mate == NULL);
6336   if (__pyx_t_1) {
6337
6338     /* "csamtools.pyx":540
6339  *          # also, make sure that we get the other read by comparing
6340  *          # the flags
6341  *          if alignment.core.flag & d.flag != 0 and \             # <<<<<<<<<<<<<<
6342  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:
6343  *              d.mate = bam_dup1( alignment )
6344  */
6345     __pyx_t_1 = ((__pyx_v_alignment->core.flag & __pyx_v_d->flag) != 0);
6346     if (__pyx_t_1) {
6347
6348       /* "csamtools.pyx":541
6349  *          # the flags
6350  *          if alignment.core.flag & d.flag != 0 and \
6351  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:             # <<<<<<<<<<<<<<
6352  *              d.mate = bam_dup1( alignment )
6353  * 
6354  */
6355       __pyx_t_2 = (strcmp(bam1_qname(__pyx_v_alignment), __pyx_v_d->name) == 0);
6356       __pyx_t_3 = __pyx_t_2;
6357     } else {
6358       __pyx_t_3 = __pyx_t_1;
6359     }
6360     if (__pyx_t_3) {
6361
6362       /* "csamtools.pyx":542
6363  *          if alignment.core.flag & d.flag != 0 and \
6364  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:
6365  *              d.mate = bam_dup1( alignment )             # <<<<<<<<<<<<<<
6366  * 
6367  * 
6368  */
6369       __pyx_v_d->mate = bam_dup1(__pyx_v_alignment);
6370       goto __pyx_L4;
6371     }
6372     __pyx_L4:;
6373     goto __pyx_L3;
6374   }
6375   __pyx_L3:;
6376
6377   __pyx_r = 0;
6378   __Pyx_TraceReturn(Py_None);
6379   __Pyx_RefNannyFinishContext();
6380   return __pyx_r;
6381 }
6382
6383 /* Python wrapper */
6384 static int __pyx_pw_9csamtools_7Samfile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
6385 static int __pyx_pw_9csamtools_7Samfile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
6386   PyObject *__pyx_v_args = 0;
6387   PyObject *__pyx_v_kwargs = 0;
6388   int __pyx_r;
6389   __Pyx_RefNannyDeclarations
6390   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
6391   if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
6392   __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
6393   if (unlikely(!__pyx_v_kwargs)) return -1;
6394   __Pyx_GOTREF(__pyx_v_kwargs);
6395   __Pyx_INCREF(__pyx_args);
6396   __pyx_v_args = __pyx_args;
6397   __pyx_r = __pyx_pf_9csamtools_7Samfile___cinit__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);
6398   __Pyx_XDECREF(__pyx_v_args);
6399   __Pyx_XDECREF(__pyx_v_kwargs);
6400   __Pyx_RefNannyFinishContext();
6401   return __pyx_r;
6402 }
6403
6404 /* "csamtools.pyx":592
6405  *     '''
6406  * 
6407  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
6408  *         self.samfile = NULL
6409  *         self._filename = NULL
6410  */
6411
6412 static int __pyx_pf_9csamtools_7Samfile___cinit__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
6413   int __pyx_r;
6414   __Pyx_RefNannyDeclarations
6415   PyObject *__pyx_t_1 = NULL;
6416   PyObject *__pyx_t_2 = NULL;
6417   PyObject *__pyx_t_3 = NULL;
6418   PyObject *__pyx_t_4 = NULL;
6419   int __pyx_lineno = 0;
6420   const char *__pyx_filename = NULL;
6421   int __pyx_clineno = 0;
6422   __Pyx_TraceDeclarations
6423   __Pyx_RefNannySetupContext("__cinit__", 0);
6424   __Pyx_TraceCall("__cinit__", __pyx_f[0], 592);
6425
6426   /* "csamtools.pyx":593
6427  * 
6428  *     def __cinit__(self, *args, **kwargs ):
6429  *         self.samfile = NULL             # <<<<<<<<<<<<<<
6430  *         self._filename = NULL
6431  *         self.isbam = False
6432  */
6433   __pyx_v_self->samfile = NULL;
6434
6435   /* "csamtools.pyx":594
6436  *     def __cinit__(self, *args, **kwargs ):
6437  *         self.samfile = NULL
6438  *         self._filename = NULL             # <<<<<<<<<<<<<<
6439  *         self.isbam = False
6440  *         self.isstream = False
6441  */
6442   __pyx_v_self->_filename = NULL;
6443
6444   /* "csamtools.pyx":595
6445  *         self.samfile = NULL
6446  *         self._filename = NULL
6447  *         self.isbam = False             # <<<<<<<<<<<<<<
6448  *         self.isstream = False
6449  *         self._open( *args, **kwargs )
6450  */
6451   __pyx_v_self->isbam = 0;
6452
6453   /* "csamtools.pyx":596
6454  *         self._filename = NULL
6455  *         self.isbam = False
6456  *         self.isstream = False             # <<<<<<<<<<<<<<
6457  *         self._open( *args, **kwargs )
6458  * 
6459  */
6460   __pyx_v_self->isstream = 0;
6461
6462   /* "csamtools.pyx":597
6463  *         self.isbam = False
6464  *         self.isstream = False
6465  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
6466  * 
6467  *         # allocate memory for iterator
6468  */
6469   __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 = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6470   __Pyx_GOTREF(__pyx_t_1);
6471   __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6472   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6473   __pyx_t_3 = ((PyObject *)__pyx_v_kwargs);
6474   __Pyx_INCREF(__pyx_t_3);
6475   __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 = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6476   __Pyx_GOTREF(__pyx_t_4);
6477   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6478   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6479   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
6480   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
6481
6482   /* "csamtools.pyx":600
6483  * 
6484  *         # allocate memory for iterator
6485  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
6486  * 
6487  *     def _isOpen( self ):
6488  */
6489   __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
6490
6491   __pyx_r = 0;
6492   goto __pyx_L0;
6493   __pyx_L1_error:;
6494   __Pyx_XDECREF(__pyx_t_1);
6495   __Pyx_XDECREF(__pyx_t_2);
6496   __Pyx_XDECREF(__pyx_t_3);
6497   __Pyx_XDECREF(__pyx_t_4);
6498   __Pyx_AddTraceback("csamtools.Samfile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
6499   __pyx_r = -1;
6500   __pyx_L0:;
6501   __Pyx_TraceReturn(Py_None);
6502   __Pyx_RefNannyFinishContext();
6503   return __pyx_r;
6504 }
6505
6506 /* Python wrapper */
6507 static PyObject *__pyx_pw_9csamtools_7Samfile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
6508 static char __pyx_doc_9csamtools_7Samfile_2_isOpen[] = "Samfile._isOpen(self)\nreturn true if samfile has been opened.";
6509 static PyObject *__pyx_pw_9csamtools_7Samfile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
6510   PyObject *__pyx_r = 0;
6511   __Pyx_RefNannyDeclarations
6512   __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
6513   __pyx_r = __pyx_pf_9csamtools_7Samfile_2_isOpen(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
6514   __Pyx_RefNannyFinishContext();
6515   return __pyx_r;
6516 }
6517
6518 /* "csamtools.pyx":602
6519  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
6520  * 
6521  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
6522  *         '''return true if samfile has been opened.'''
6523  *         return self.samfile != NULL
6524  */
6525
6526 static PyObject *__pyx_pf_9csamtools_7Samfile_2_isOpen(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
6527   PyObject *__pyx_r = NULL;
6528   __Pyx_RefNannyDeclarations
6529   PyObject *__pyx_t_1 = NULL;
6530   int __pyx_lineno = 0;
6531   const char *__pyx_filename = NULL;
6532   int __pyx_clineno = 0;
6533   __Pyx_TraceDeclarations
6534   __Pyx_RefNannySetupContext("_isOpen", 0);
6535   __Pyx_TraceCall("_isOpen", __pyx_f[0], 602);
6536
6537   /* "csamtools.pyx":604
6538  *     def _isOpen( self ):
6539  *         '''return true if samfile has been opened.'''
6540  *         return self.samfile != NULL             # <<<<<<<<<<<<<<
6541  * 
6542  *     def _hasIndex( self ):
6543  */
6544   __Pyx_XDECREF(__pyx_r);
6545   __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->samfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6546   __Pyx_GOTREF(__pyx_t_1);
6547   __pyx_r = __pyx_t_1;
6548   __pyx_t_1 = 0;
6549   goto __pyx_L0;
6550
6551   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6552   goto __pyx_L0;
6553   __pyx_L1_error:;
6554   __Pyx_XDECREF(__pyx_t_1);
6555   __Pyx_AddTraceback("csamtools.Samfile._isOpen", __pyx_clineno, __pyx_lineno, __pyx_filename);
6556   __pyx_r = NULL;
6557   __pyx_L0:;
6558   __Pyx_XGIVEREF(__pyx_r);
6559   __Pyx_TraceReturn(__pyx_r);
6560   __Pyx_RefNannyFinishContext();
6561   return __pyx_r;
6562 }
6563
6564 /* Python wrapper */
6565 static PyObject *__pyx_pw_9csamtools_7Samfile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
6566 static char __pyx_doc_9csamtools_7Samfile_4_hasIndex[] = "Samfile._hasIndex(self)\nreturn true if samfile has an existing (and opened) index.";
6567 static PyObject *__pyx_pw_9csamtools_7Samfile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
6568   PyObject *__pyx_r = 0;
6569   __Pyx_RefNannyDeclarations
6570   __Pyx_RefNannySetupContext("_hasIndex (wrapper)", 0);
6571   __pyx_r = __pyx_pf_9csamtools_7Samfile_4_hasIndex(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
6572   __Pyx_RefNannyFinishContext();
6573   return __pyx_r;
6574 }
6575
6576 /* "csamtools.pyx":606
6577  *         return self.samfile != NULL
6578  * 
6579  *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
6580  *         '''return true if samfile has an existing (and opened) index.'''
6581  *         return self.index != NULL
6582  */
6583
6584 static PyObject *__pyx_pf_9csamtools_7Samfile_4_hasIndex(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
6585   PyObject *__pyx_r = NULL;
6586   __Pyx_RefNannyDeclarations
6587   PyObject *__pyx_t_1 = NULL;
6588   int __pyx_lineno = 0;
6589   const char *__pyx_filename = NULL;
6590   int __pyx_clineno = 0;
6591   __Pyx_TraceDeclarations
6592   __Pyx_RefNannySetupContext("_hasIndex", 0);
6593   __Pyx_TraceCall("_hasIndex", __pyx_f[0], 606);
6594
6595   /* "csamtools.pyx":608
6596  *     def _hasIndex( self ):
6597  *         '''return true if samfile has an existing (and opened) index.'''
6598  *         return self.index != NULL             # <<<<<<<<<<<<<<
6599  * 
6600  *     def _open( self,
6601  */
6602   __Pyx_XDECREF(__pyx_r);
6603   __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6604   __Pyx_GOTREF(__pyx_t_1);
6605   __pyx_r = __pyx_t_1;
6606   __pyx_t_1 = 0;
6607   goto __pyx_L0;
6608
6609   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6610   goto __pyx_L0;
6611   __pyx_L1_error:;
6612   __Pyx_XDECREF(__pyx_t_1);
6613   __Pyx_AddTraceback("csamtools.Samfile._hasIndex", __pyx_clineno, __pyx_lineno, __pyx_filename);
6614   __pyx_r = NULL;
6615   __pyx_L0:;
6616   __Pyx_XGIVEREF(__pyx_r);
6617   __Pyx_TraceReturn(__pyx_r);
6618   __Pyx_RefNannyFinishContext();
6619   return __pyx_r;
6620 }
6621
6622 /* Python wrapper */
6623 static PyObject *__pyx_pw_9csamtools_7Samfile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
6624 static char __pyx_doc_9csamtools_7Samfile_6_open[] = "Samfile._open(self, filename, mode=None, Samfile template=None, referencenames=None, referencelengths=None, text=None, header=None, port=None, add_sq_text=True, check_header=True, check_sq=True)\nopen a sam/bam file.\n\n        If _open is called on an existing bamfile, the current file will be\n        closed and a new file will be opened.\n        ";
6625 static PyObject *__pyx_pw_9csamtools_7Samfile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
6626   PyObject *__pyx_v_filename = 0;
6627   PyObject *__pyx_v_mode = 0;
6628   struct __pyx_obj_9csamtools_Samfile *__pyx_v_template = 0;
6629   PyObject *__pyx_v_referencenames = 0;
6630   PyObject *__pyx_v_referencelengths = 0;
6631   PyObject *__pyx_v_text = 0;
6632   PyObject *__pyx_v_header = 0;
6633   PyObject *__pyx_v_port = 0;
6634   PyObject *__pyx_v_add_sq_text = 0;
6635   PyObject *__pyx_v_check_header = 0;
6636   PyObject *__pyx_v_check_sq = 0;
6637   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};
6638   PyObject *__pyx_r = 0;
6639   __Pyx_RefNannyDeclarations
6640   __Pyx_RefNannySetupContext("_open (wrapper)", 0);
6641   {
6642     PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
6643
6644     /* "csamtools.pyx":612
6645  *     def _open( self,
6646  *                filename,
6647  *                mode = None,             # <<<<<<<<<<<<<<
6648  *                Samfile template = None,
6649  *                referencenames = None,
6650  */
6651     values[1] = ((PyObject *)Py_None);
6652
6653     /* "csamtools.pyx":613
6654  *                filename,
6655  *                mode = None,
6656  *                Samfile template = None,             # <<<<<<<<<<<<<<
6657  *                referencenames = None,
6658  *                referencelengths = None,
6659  */
6660     values[2] = (PyObject *)((struct __pyx_obj_9csamtools_Samfile *)Py_None);
6661
6662     /* "csamtools.pyx":614
6663  *                mode = None,
6664  *                Samfile template = None,
6665  *                referencenames = None,             # <<<<<<<<<<<<<<
6666  *                referencelengths = None,
6667  *                text = None,
6668  */
6669     values[3] = ((PyObject *)Py_None);
6670
6671     /* "csamtools.pyx":615
6672  *                Samfile template = None,
6673  *                referencenames = None,
6674  *                referencelengths = None,             # <<<<<<<<<<<<<<
6675  *                text = None,
6676  *                header = None,
6677  */
6678     values[4] = ((PyObject *)Py_None);
6679
6680     /* "csamtools.pyx":616
6681  *                referencenames = None,
6682  *                referencelengths = None,
6683  *                text = None,             # <<<<<<<<<<<<<<
6684  *                header = None,
6685  *                port = None,
6686  */
6687     values[5] = ((PyObject *)Py_None);
6688
6689     /* "csamtools.pyx":617
6690  *                referencelengths = None,
6691  *                text = None,
6692  *                header = None,             # <<<<<<<<<<<<<<
6693  *                port = None,
6694  *                add_sq_text = True,
6695  */
6696     values[6] = ((PyObject *)Py_None);
6697
6698     /* "csamtools.pyx":618
6699  *                text = None,
6700  *                header = None,
6701  *                port = None,             # <<<<<<<<<<<<<<
6702  *                add_sq_text = True,
6703  *                check_header = True,
6704  */
6705     values[7] = ((PyObject *)Py_None);
6706     values[8] = __pyx_k_21;
6707     values[9] = __pyx_k_22;
6708     values[10] = __pyx_k_23;
6709     if (unlikely(__pyx_kwds)) {
6710       Py_ssize_t kw_args;
6711       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
6712       switch (pos_args) {
6713         case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
6714         case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
6715         case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
6716         case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
6717         case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
6718         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
6719         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
6720         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
6721         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
6722         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
6723         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
6724         case  0: break;
6725         default: goto __pyx_L5_argtuple_error;
6726       }
6727       kw_args = PyDict_Size(__pyx_kwds);
6728       switch (pos_args) {
6729         case  0:
6730         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
6731         if (likely(values[0])) kw_args--;
6732         else goto __pyx_L5_argtuple_error;
6733         case  1:
6734         if (kw_args > 0) {
6735           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
6736           if (value) { values[1] = value; kw_args--; }
6737         }
6738         case  2:
6739         if (kw_args > 0) {
6740           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__template);
6741           if (value) { values[2] = value; kw_args--; }
6742         }
6743         case  3:
6744         if (kw_args > 0) {
6745           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencenames);
6746           if (value) { values[3] = value; kw_args--; }
6747         }
6748         case  4:
6749         if (kw_args > 0) {
6750           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencelengths);
6751           if (value) { values[4] = value; kw_args--; }
6752         }
6753         case  5:
6754         if (kw_args > 0) {
6755           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__text);
6756           if (value) { values[5] = value; kw_args--; }
6757         }
6758         case  6:
6759         if (kw_args > 0) {
6760           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__header);
6761           if (value) { values[6] = value; kw_args--; }
6762         }
6763         case  7:
6764         if (kw_args > 0) {
6765           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__port);
6766           if (value) { values[7] = value; kw_args--; }
6767         }
6768         case  8:
6769         if (kw_args > 0) {
6770           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__add_sq_text);
6771           if (value) { values[8] = value; kw_args--; }
6772         }
6773         case  9:
6774         if (kw_args > 0) {
6775           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__check_header);
6776           if (value) { values[9] = value; kw_args--; }
6777         }
6778         case 10:
6779         if (kw_args > 0) {
6780           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__check_sq);
6781           if (value) { values[10] = value; kw_args--; }
6782         }
6783       }
6784       if (unlikely(kw_args > 0)) {
6785         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
6786       }
6787     } else {
6788       switch (PyTuple_GET_SIZE(__pyx_args)) {
6789         case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
6790         case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
6791         case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
6792         case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
6793         case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
6794         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
6795         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
6796         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
6797         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
6798         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
6799         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
6800         break;
6801         default: goto __pyx_L5_argtuple_error;
6802       }
6803     }
6804     __pyx_v_filename = values[0];
6805     __pyx_v_mode = values[1];
6806     __pyx_v_template = ((struct __pyx_obj_9csamtools_Samfile *)values[2]);
6807     __pyx_v_referencenames = values[3];
6808     __pyx_v_referencelengths = values[4];
6809     __pyx_v_text = values[5];
6810     __pyx_v_header = values[6];
6811     __pyx_v_port = values[7];
6812     __pyx_v_add_sq_text = values[8];
6813     __pyx_v_check_header = values[9];
6814     __pyx_v_check_sq = values[10];
6815   }
6816   goto __pyx_L4_argument_unpacking_done;
6817   __pyx_L5_argtuple_error:;
6818   __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 11, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 610; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
6819   __pyx_L3_error:;
6820   __Pyx_AddTraceback("csamtools.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
6821   __Pyx_RefNannyFinishContext();
6822   return NULL;
6823   __pyx_L4_argument_unpacking_done:;
6824   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_9csamtools_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6825   __pyx_r = __pyx_pf_9csamtools_7Samfile_6_open(((struct __pyx_obj_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);
6826   goto __pyx_L0;
6827   __pyx_L1_error:;
6828   __pyx_r = NULL;
6829   __pyx_L0:;
6830   __Pyx_RefNannyFinishContext();
6831   return __pyx_r;
6832 }
6833
6834 /* "csamtools.pyx":610
6835  *         return self.index != NULL
6836  * 
6837  *     def _open( self,             # <<<<<<<<<<<<<<
6838  *                filename,
6839  *                mode = None,
6840  */
6841
6842 static PyObject *__pyx_pf_9csamtools_7Samfile_6_open(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_9csamtools_Samfile *__pyx_v_template, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_text, PyObject *__pyx_v_header, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq) {
6843   CYTHON_UNUSED PyObject *__pyx_v_msg = NULL;
6844   bam_header_t *__pyx_v_header_to_write;
6845   PyObject *__pyx_v_bmode = 0;
6846   char *__pyx_v_ctext;
6847   PyObject *__pyx_v_n = NULL;
6848   PyObject *__pyx_v_x = NULL;
6849   PyObject *__pyx_v_name = NULL;
6850   PyObject *__pyx_v_store = NULL;
6851   PyObject *__pyx_v_ref = NULL;
6852   PyObject *__pyx_r = NULL;
6853   __Pyx_RefNannyDeclarations
6854   int __pyx_t_1;
6855   PyObject *__pyx_t_2 = NULL;
6856   PyObject *__pyx_t_3 = NULL;
6857   PyObject *__pyx_t_4 = NULL;
6858   PyObject *__pyx_t_5 = NULL;
6859   PyObject *__pyx_t_6 = NULL;
6860   PyObject *__pyx_t_7 = NULL;
6861   PyObject *__pyx_t_8 = NULL;
6862   int __pyx_t_9;
6863   int __pyx_t_10;
6864   int __pyx_t_11;
6865   char *__pyx_t_12;
6866   Py_ssize_t __pyx_t_13;
6867   Py_ssize_t __pyx_t_14;
6868   PyObject *(*__pyx_t_15)(PyObject *);
6869   size_t __pyx_t_16;
6870   int32_t __pyx_t_17;
6871   long __pyx_t_18;
6872   uint32_t __pyx_t_19;
6873   const char* __pyx_t_20;
6874   int __pyx_t_21;
6875   int __pyx_lineno = 0;
6876   const char *__pyx_filename = NULL;
6877   int __pyx_clineno = 0;
6878   __Pyx_TraceDeclarations
6879   __Pyx_RefNannySetupContext("_open", 0);
6880   __Pyx_TraceCall("_open", __pyx_f[0], 610);
6881   __Pyx_INCREF(__pyx_v_filename);
6882   __Pyx_INCREF(__pyx_v_referencenames);
6883   __Pyx_INCREF(__pyx_v_text);
6884
6885   /* "csamtools.pyx":630
6886  * 
6887  *         # read mode autodetection
6888  *         if mode is None:             # <<<<<<<<<<<<<<
6889  *             try:
6890  *                 self._open(filename, 'rb', template=template,
6891  */
6892   __pyx_t_1 = (__pyx_v_mode == Py_None);
6893   if (__pyx_t_1) {
6894
6895     /* "csamtools.pyx":631
6896  *         # read mode autodetection
6897  *         if mode is None:
6898  *             try:             # <<<<<<<<<<<<<<
6899  *                 self._open(filename, 'rb', template=template,
6900  *                            referencenames=referencenames,
6901  */
6902     {
6903       __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
6904       __Pyx_XGOTREF(__pyx_t_2);
6905       __Pyx_XGOTREF(__pyx_t_3);
6906       __Pyx_XGOTREF(__pyx_t_4);
6907       /*try:*/ {
6908
6909         /* "csamtools.pyx":632
6910  *         if mode is None:
6911  *             try:
6912  *                 self._open(filename, 'rb', template=template,             # <<<<<<<<<<<<<<
6913  *                            referencenames=referencenames,
6914  *                            referencelengths=referencelengths,
6915  */
6916         __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 = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6917         __Pyx_GOTREF(__pyx_t_5);
6918         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6919         __Pyx_GOTREF(__pyx_t_6);
6920         __Pyx_INCREF(__pyx_v_filename);
6921         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_filename);
6922         __Pyx_GIVEREF(__pyx_v_filename);
6923         __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
6924         PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
6925         __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
6926         __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6927         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
6928         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6929
6930         /* "csamtools.pyx":633
6931  *             try:
6932  *                 self._open(filename, 'rb', template=template,
6933  *                            referencenames=referencenames,             # <<<<<<<<<<<<<<
6934  *                            referencelengths=referencelengths,
6935  *                            text=text, header=header, port=port,
6936  */
6937         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6938
6939         /* "csamtools.pyx":634
6940  *                 self._open(filename, 'rb', template=template,
6941  *                            referencenames=referencenames,
6942  *                            referencelengths=referencelengths,             # <<<<<<<<<<<<<<
6943  *                            text=text, header=header, port=port,
6944  *                            check_header=check_header,
6945  */
6946         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6947
6948         /* "csamtools.pyx":635
6949  *                            referencenames=referencenames,
6950  *                            referencelengths=referencelengths,
6951  *                            text=text, header=header, port=port,             # <<<<<<<<<<<<<<
6952  *                            check_header=check_header,
6953  *                            check_sq=check_sq)
6954  */
6955         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6956         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6957         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6958
6959         /* "csamtools.pyx":636
6960  *                            referencelengths=referencelengths,
6961  *                            text=text, header=header, port=port,
6962  *                            check_header=check_header,             # <<<<<<<<<<<<<<
6963  *                            check_sq=check_sq)
6964  *                 return
6965  */
6966         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6967
6968         /* "csamtools.pyx":637
6969  *                            text=text, header=header, port=port,
6970  *                            check_header=check_header,
6971  *                            check_sq=check_sq)             # <<<<<<<<<<<<<<
6972  *                 return
6973  *             except ValueError, msg:
6974  */
6975         if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6976         __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 = 632; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
6977         __Pyx_GOTREF(__pyx_t_8);
6978         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6979         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
6980         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
6981         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
6982
6983         /* "csamtools.pyx":638
6984  *                            check_header=check_header,
6985  *                            check_sq=check_sq)
6986  *                 return             # <<<<<<<<<<<<<<
6987  *             except ValueError, msg:
6988  *                 pass
6989  */
6990         __Pyx_XDECREF(__pyx_r);
6991         __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6992         goto __pyx_L8_try_return;
6993       }
6994       __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
6995       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
6996       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
6997       goto __pyx_L11_try_end;
6998       __pyx_L8_try_return:;
6999       __Pyx_XGIVEREF(__pyx_t_2);
7000       __Pyx_XGIVEREF(__pyx_t_3);
7001       __Pyx_XGIVEREF(__pyx_t_4);
7002       __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
7003       goto __pyx_L0;
7004       __pyx_L4_error:;
7005       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
7006       __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
7007       __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
7008       __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
7009
7010       /* "csamtools.pyx":639
7011  *                            check_sq=check_sq)
7012  *                 return
7013  *             except ValueError, msg:             # <<<<<<<<<<<<<<
7014  *                 pass
7015  * 
7016  */
7017       __pyx_t_9 = PyErr_ExceptionMatches(__pyx_builtin_ValueError);
7018       if (__pyx_t_9) {
7019         __Pyx_AddTraceback("csamtools.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
7020         if (__Pyx_GetException(&__pyx_t_8, &__pyx_t_7, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 639; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
7021         __Pyx_GOTREF(__pyx_t_8);
7022         __Pyx_GOTREF(__pyx_t_7);
7023         __Pyx_GOTREF(__pyx_t_6);
7024         __Pyx_INCREF(__pyx_t_7);
7025         __pyx_v_msg = __pyx_t_7;
7026         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7027         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7028         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7029         goto __pyx_L5_exception_handled;
7030       }
7031       __pyx_L6_except_error:;
7032       __Pyx_XGIVEREF(__pyx_t_2);
7033       __Pyx_XGIVEREF(__pyx_t_3);
7034       __Pyx_XGIVEREF(__pyx_t_4);
7035       __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
7036       goto __pyx_L1_error;
7037       __pyx_L5_exception_handled:;
7038       __Pyx_XGIVEREF(__pyx_t_2);
7039       __Pyx_XGIVEREF(__pyx_t_3);
7040       __Pyx_XGIVEREF(__pyx_t_4);
7041       __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
7042       __pyx_L11_try_end:;
7043     }
7044
7045     /* "csamtools.pyx":642
7046  *                 pass
7047  * 
7048  *             self._open(filename, 'r', template=template,             # <<<<<<<<<<<<<<
7049  *                        referencenames=referencenames,
7050  *                        referencelengths=referencelengths,
7051  */
7052     __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 = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7053     __Pyx_GOTREF(__pyx_t_6);
7054     __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7055     __Pyx_GOTREF(__pyx_t_7);
7056     __Pyx_INCREF(__pyx_v_filename);
7057     PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_filename);
7058     __Pyx_GIVEREF(__pyx_v_filename);
7059     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
7060     PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__r));
7061     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
7062     __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7063     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
7064     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7065
7066     /* "csamtools.pyx":643
7067  * 
7068  *             self._open(filename, 'r', template=template,
7069  *                        referencenames=referencenames,             # <<<<<<<<<<<<<<
7070  *                        referencelengths=referencelengths,
7071  *                        text=text, header=header, port=port,
7072  */
7073     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7074
7075     /* "csamtools.pyx":644
7076  *             self._open(filename, 'r', template=template,
7077  *                        referencenames=referencenames,
7078  *                        referencelengths=referencelengths,             # <<<<<<<<<<<<<<
7079  *                        text=text, header=header, port=port,
7080  *                        check_header=check_header,
7081  */
7082     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7083
7084     /* "csamtools.pyx":645
7085  *                        referencenames=referencenames,
7086  *                        referencelengths=referencelengths,
7087  *                        text=text, header=header, port=port,             # <<<<<<<<<<<<<<
7088  *                        check_header=check_header,
7089  *                        check_sq=check_sq)
7090  */
7091     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7092     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7093     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7094
7095     /* "csamtools.pyx":646
7096  *                        referencelengths=referencelengths,
7097  *                        text=text, header=header, port=port,
7098  *                        check_header=check_header,             # <<<<<<<<<<<<<<
7099  *                        check_sq=check_sq)
7100  *             return
7101  */
7102     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_header), __pyx_v_check_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7103
7104     /* "csamtools.pyx":647
7105  *                        text=text, header=header, port=port,
7106  *                        check_header=check_header,
7107  *                        check_sq=check_sq)             # <<<<<<<<<<<<<<
7108  *             return
7109  * 
7110  */
7111     if (PyDict_SetItem(__pyx_t_8, ((PyObject *)__pyx_n_s__check_sq), __pyx_v_check_sq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7112     __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 = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7113     __Pyx_GOTREF(__pyx_t_5);
7114     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7115     __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
7116     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
7117     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7118
7119     /* "csamtools.pyx":648
7120  *                        check_header=check_header,
7121  *                        check_sq=check_sq)
7122  *             return             # <<<<<<<<<<<<<<
7123  * 
7124  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode
7125  */
7126     __Pyx_XDECREF(__pyx_r);
7127     __pyx_r = Py_None; __Pyx_INCREF(Py_None);
7128     goto __pyx_L0;
7129     goto __pyx_L3;
7130   }
7131   __pyx_L3:;
7132
7133   /* "csamtools.pyx":650
7134  *             return
7135  * 
7136  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
7137  * 
7138  *         #assert filename != NULL
7139  */
7140   #ifndef CYTHON_WITHOUT_ASSERTIONS
7141   __Pyx_INCREF(__pyx_v_mode);
7142   __pyx_t_5 = __pyx_v_mode;
7143   __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7144   if (!((int)__pyx_t_1)) {
7145     __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7146     __pyx_t_11 = ((int)__pyx_t_10);
7147   } else {
7148     __pyx_t_11 = ((int)__pyx_t_1);
7149   }
7150   if (!__pyx_t_11) {
7151     __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__rb), Py_EQ); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7152     __pyx_t_10 = ((int)__pyx_t_1);
7153   } else {
7154     __pyx_t_10 = __pyx_t_11;
7155   }
7156   if (!__pyx_t_10) {
7157     __pyx_t_11 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__wb), Py_EQ); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7158     __pyx_t_1 = ((int)__pyx_t_11);
7159   } else {
7160     __pyx_t_1 = __pyx_t_10;
7161   }
7162   if (!__pyx_t_1) {
7163     __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__wh), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7164     __pyx_t_11 = ((int)__pyx_t_10);
7165   } else {
7166     __pyx_t_11 = __pyx_t_1;
7167   }
7168   if (!__pyx_t_11) {
7169     __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__wbu), Py_EQ); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7170     __pyx_t_10 = ((int)__pyx_t_1);
7171   } else {
7172     __pyx_t_10 = __pyx_t_11;
7173   }
7174   if (!__pyx_t_10) {
7175     __pyx_t_11 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__rU), Py_EQ); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7176     __pyx_t_1 = ((int)__pyx_t_11);
7177   } else {
7178     __pyx_t_1 = __pyx_t_10;
7179   }
7180   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7181   if (unlikely(!__pyx_t_1)) {
7182     __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), __pyx_v_mode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7183     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
7184     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_5));
7185     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
7186     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7187   }
7188   #endif
7189
7190   /* "csamtools.pyx":655
7191  * 
7192  *         # close a previously opened file
7193  *         if self.samfile != NULL: self.close()             # <<<<<<<<<<<<<<
7194  *         self.samfile = NULL
7195  * 
7196  */
7197   __pyx_t_1 = (__pyx_v_self->samfile != NULL);
7198   if (__pyx_t_1) {
7199     __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 = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7200     __Pyx_GOTREF(__pyx_t_5);
7201     __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 = 655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7202     __Pyx_GOTREF(__pyx_t_8);
7203     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7204     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7205     goto __pyx_L14;
7206   }
7207   __pyx_L14:;
7208
7209   /* "csamtools.pyx":656
7210  *         # close a previously opened file
7211  *         if self.samfile != NULL: self.close()
7212  *         self.samfile = NULL             # <<<<<<<<<<<<<<
7213  * 
7214  *         cdef bam_header_t * header_to_write
7215  */
7216   __pyx_v_self->samfile = NULL;
7217
7218   /* "csamtools.pyx":659
7219  * 
7220  *         cdef bam_header_t * header_to_write
7221  *         header_to_write = NULL             # <<<<<<<<<<<<<<
7222  * 
7223  *         if self._filename != NULL: free(self._filename )
7224  */
7225   __pyx_v_header_to_write = NULL;
7226
7227   /* "csamtools.pyx":661
7228  *         header_to_write = NULL
7229  * 
7230  *         if self._filename != NULL: free(self._filename )             # <<<<<<<<<<<<<<
7231  *         filename = _my_encodeFilename(filename)
7232  *         cdef bytes bmode = mode.encode('ascii')
7233  */
7234   __pyx_t_1 = (__pyx_v_self->_filename != NULL);
7235   if (__pyx_t_1) {
7236     free(__pyx_v_self->_filename);
7237     goto __pyx_L15;
7238   }
7239   __pyx_L15:;
7240
7241   /* "csamtools.pyx":662
7242  * 
7243  *         if self._filename != NULL: free(self._filename )
7244  *         filename = _my_encodeFilename(filename)             # <<<<<<<<<<<<<<
7245  *         cdef bytes bmode = mode.encode('ascii')
7246  *         #cdef char* cfilename
7247  */
7248   __pyx_t_8 = ((PyObject *)__pyx_f_9csamtools__my_encodeFilename(__pyx_v_filename)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7249   __Pyx_GOTREF(__pyx_t_8);
7250   __Pyx_DECREF(__pyx_v_filename);
7251   __pyx_v_filename = __pyx_t_8;
7252   __pyx_t_8 = 0;
7253
7254   /* "csamtools.pyx":663
7255  *         if self._filename != NULL: free(self._filename )
7256  *         filename = _my_encodeFilename(filename)
7257  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
7258  *         #cdef char* cfilename
7259  *         #cfilename = filename.encode(_FILENAME_ENCODING)
7260  */
7261   __pyx_t_8 = PyObject_GetAttr(__pyx_v_mode, __pyx_n_s__encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7262   __Pyx_GOTREF(__pyx_t_8);
7263   __pyx_t_5 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7264   __Pyx_GOTREF(__pyx_t_5);
7265   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7266   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 = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7267   __pyx_v_bmode = ((PyObject*)__pyx_t_5);
7268   __pyx_t_5 = 0;
7269
7270   /* "csamtools.pyx":666
7271  *         #cdef char* cfilename
7272  *         #cfilename = filename.encode(_FILENAME_ENCODING)
7273  *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
7274  *         self.isstream = strcmp( filename, "-" ) == 0
7275  * 
7276  */
7277   __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7278   __pyx_v_self->_filename = strdup(__pyx_t_12);
7279
7280   /* "csamtools.pyx":667
7281  *         #cfilename = filename.encode(_FILENAME_ENCODING)
7282  *         self._filename = strdup(filename)
7283  *         self.isstream = strcmp( filename, "-" ) == 0             # <<<<<<<<<<<<<<
7284  * 
7285  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
7286  */
7287   __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7288   __pyx_v_self->isstream = (strcmp(__pyx_t_12, __pyx_k_26) == 0);
7289
7290   /* "csamtools.pyx":669
7291  *         self.isstream = strcmp( filename, "-" ) == 0
7292  * 
7293  *         self.isbam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
7294  * 
7295  *         self.isremote = strncmp(filename,"http:",5) == 0 or \
7296  */
7297   __pyx_t_13 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7298   __pyx_t_1 = (__pyx_t_13 > 1);
7299   if (__pyx_t_1) {
7300     __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7301     __Pyx_GOTREF(__pyx_t_5);
7302     __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__b), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7303     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7304     __pyx_t_11 = __pyx_t_10;
7305   } else {
7306     __pyx_t_11 = __pyx_t_1;
7307   }
7308   __pyx_v_self->isbam = __pyx_t_11;
7309
7310   /* "csamtools.pyx":671
7311  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
7312  * 
7313  *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
7314  *             strncmp(filename,"ftp:",4) == 0
7315  * 
7316  */
7317   __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7318   __pyx_t_11 = (strncmp(__pyx_t_12, __pyx_k_27, 5) == 0);
7319   if (!__pyx_t_11) {
7320
7321     /* "csamtools.pyx":672
7322  * 
7323  *         self.isremote = strncmp(filename,"http:",5) == 0 or \
7324  *             strncmp(filename,"ftp:",4) == 0             # <<<<<<<<<<<<<<
7325  * 
7326  *         cdef char * ctext
7327  */
7328     __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7329     __pyx_t_1 = (strncmp(__pyx_t_12, __pyx_k_28, 4) == 0);
7330     __pyx_t_10 = __pyx_t_1;
7331   } else {
7332     __pyx_t_10 = __pyx_t_11;
7333   }
7334
7335   /* "csamtools.pyx":671
7336  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
7337  * 
7338  *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
7339  *             strncmp(filename,"ftp:",4) == 0
7340  * 
7341  */
7342   __pyx_v_self->isremote = __pyx_t_10;
7343
7344   /* "csamtools.pyx":675
7345  * 
7346  *         cdef char * ctext
7347  *         ctext = NULL             # <<<<<<<<<<<<<<
7348  * 
7349  *         if mode[0] == 'w':
7350  */
7351   __pyx_v_ctext = NULL;
7352
7353   /* "csamtools.pyx":677
7354  *         ctext = NULL
7355  * 
7356  *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
7357  *             # open file for writing
7358  * 
7359  */
7360   __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7361   __Pyx_GOTREF(__pyx_t_5);
7362   __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7363   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7364   if (__pyx_t_10) {
7365
7366     /* "csamtools.pyx":681
7367  * 
7368  *             # header structure (used for writing)
7369  *             if template:             # <<<<<<<<<<<<<<
7370  *                 # copy header from another file
7371  *                 header_to_write = template.samfile.header
7372  */
7373     __pyx_t_10 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7374     if (__pyx_t_10) {
7375
7376       /* "csamtools.pyx":683
7377  *             if template:
7378  *                 # copy header from another file
7379  *                 header_to_write = template.samfile.header             # <<<<<<<<<<<<<<
7380  * 
7381  *             elif header:
7382  */
7383       __pyx_v_header_to_write = __pyx_v_template->samfile->header;
7384       goto __pyx_L17;
7385     }
7386
7387     /* "csamtools.pyx":685
7388  *                 header_to_write = template.samfile.header
7389  * 
7390  *             elif header:             # <<<<<<<<<<<<<<
7391  *                 header_to_write = self._buildHeader( header )
7392  * 
7393  */
7394     __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7395     if (__pyx_t_10) {
7396
7397       /* "csamtools.pyx":686
7398  * 
7399  *             elif header:
7400  *                 header_to_write = self._buildHeader( header )             # <<<<<<<<<<<<<<
7401  * 
7402  *             else:
7403  */
7404       __pyx_v_header_to_write = ((struct __pyx_vtabstruct_9csamtools_Samfile *)__pyx_v_self->__pyx_vtab)->_buildHeader(__pyx_v_self, __pyx_v_header);
7405       goto __pyx_L17;
7406     }
7407     /*else*/ {
7408
7409       /* "csamtools.pyx":690
7410  *             else:
7411  *                 # build header from a target names and lengths
7412  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"             # <<<<<<<<<<<<<<
7413  *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"
7414  * 
7415  */
7416       #ifndef CYTHON_WITHOUT_ASSERTIONS
7417       __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7418       if (__pyx_t_10) {
7419         __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7420         __pyx_t_1 = __pyx_t_11;
7421       } else {
7422         __pyx_t_1 = __pyx_t_10;
7423       }
7424       if (unlikely(!__pyx_t_1)) {
7425         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_29));
7426         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7427       }
7428       #endif
7429
7430       /* "csamtools.pyx":691
7431  *                 # build header from a target names and lengths
7432  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"
7433  *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"             # <<<<<<<<<<<<<<
7434  * 
7435  *                 # allocate and fill header
7436  */
7437       #ifndef CYTHON_WITHOUT_ASSERTIONS
7438       __pyx_t_13 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7439       __pyx_t_14 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7440       if (unlikely(!(__pyx_t_13 == __pyx_t_14))) {
7441         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_30));
7442         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7443       }
7444       #endif
7445
7446       /* "csamtools.pyx":694
7447  * 
7448  *                 # allocate and fill header
7449  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]             # <<<<<<<<<<<<<<
7450  *                 header_to_write = bam_header_init()
7451  *                 header_to_write.n_targets = len(referencenames)
7452  */
7453       __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7454       __Pyx_GOTREF(__pyx_t_5);
7455       if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
7456         __pyx_t_8 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_8); __pyx_t_14 = 0;
7457         __pyx_t_15 = NULL;
7458       } else {
7459         __pyx_t_14 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7460         __Pyx_GOTREF(__pyx_t_8);
7461         __pyx_t_15 = Py_TYPE(__pyx_t_8)->tp_iternext;
7462       }
7463       for (;;) {
7464         if (!__pyx_t_15 && PyList_CheckExact(__pyx_t_8)) {
7465           if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_8)) break;
7466           __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++;
7467         } else if (!__pyx_t_15 && PyTuple_CheckExact(__pyx_t_8)) {
7468           if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
7469           __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_14); __Pyx_INCREF(__pyx_t_7); __pyx_t_14++;
7470         } else {
7471           __pyx_t_7 = __pyx_t_15(__pyx_t_8);
7472           if (unlikely(!__pyx_t_7)) {
7473             if (PyErr_Occurred()) {
7474               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
7475               else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7476             }
7477             break;
7478           }
7479           __Pyx_GOTREF(__pyx_t_7);
7480         }
7481         __Pyx_XDECREF(__pyx_v_ref);
7482         __pyx_v_ref = __pyx_t_7;
7483         __pyx_t_7 = 0;
7484         __pyx_t_7 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_ref)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7485         __Pyx_GOTREF(__pyx_t_7);
7486         if (unlikely(PyList_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7487         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7488       }
7489       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7490       __Pyx_INCREF(((PyObject *)__pyx_t_5));
7491       __Pyx_DECREF(__pyx_v_referencenames);
7492       __pyx_v_referencenames = ((PyObject *)__pyx_t_5);
7493       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
7494
7495       /* "csamtools.pyx":695
7496  *                 # allocate and fill header
7497  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]
7498  *                 header_to_write = bam_header_init()             # <<<<<<<<<<<<<<
7499  *                 header_to_write.n_targets = len(referencenames)
7500  *                 n = 0
7501  */
7502       __pyx_v_header_to_write = bam_header_init();
7503
7504       /* "csamtools.pyx":696
7505  *                 referencenames = [ _force_bytes(ref) for ref in referencenames ]
7506  *                 header_to_write = bam_header_init()
7507  *                 header_to_write.n_targets = len(referencenames)             # <<<<<<<<<<<<<<
7508  *                 n = 0
7509  *                 for x in referencenames: n += len(x) + 1
7510  */
7511       __pyx_t_14 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7512       __pyx_v_header_to_write->n_targets = __pyx_t_14;
7513
7514       /* "csamtools.pyx":697
7515  *                 header_to_write = bam_header_init()
7516  *                 header_to_write.n_targets = len(referencenames)
7517  *                 n = 0             # <<<<<<<<<<<<<<
7518  *                 for x in referencenames: n += len(x) + 1
7519  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
7520  */
7521       __Pyx_INCREF(__pyx_int_0);
7522       __pyx_v_n = __pyx_int_0;
7523
7524       /* "csamtools.pyx":698
7525  *                 header_to_write.n_targets = len(referencenames)
7526  *                 n = 0
7527  *                 for x in referencenames: n += len(x) + 1             # <<<<<<<<<<<<<<
7528  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
7529  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
7530  */
7531       if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
7532         __pyx_t_5 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_5); __pyx_t_14 = 0;
7533         __pyx_t_15 = NULL;
7534       } else {
7535         __pyx_t_14 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7536         __Pyx_GOTREF(__pyx_t_5);
7537         __pyx_t_15 = Py_TYPE(__pyx_t_5)->tp_iternext;
7538       }
7539       for (;;) {
7540         if (!__pyx_t_15 && PyList_CheckExact(__pyx_t_5)) {
7541           if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_5)) break;
7542           __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_8); __pyx_t_14++;
7543         } else if (!__pyx_t_15 && PyTuple_CheckExact(__pyx_t_5)) {
7544           if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
7545           __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_8); __pyx_t_14++;
7546         } else {
7547           __pyx_t_8 = __pyx_t_15(__pyx_t_5);
7548           if (unlikely(!__pyx_t_8)) {
7549             if (PyErr_Occurred()) {
7550               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
7551               else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7552             }
7553             break;
7554           }
7555           __Pyx_GOTREF(__pyx_t_8);
7556         }
7557         __Pyx_XDECREF(__pyx_v_x);
7558         __pyx_v_x = __pyx_t_8;
7559         __pyx_t_8 = 0;
7560         __pyx_t_13 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7561         __pyx_t_8 = PyInt_FromSsize_t((__pyx_t_13 + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7562         __Pyx_GOTREF(__pyx_t_8);
7563         __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7564         __Pyx_GOTREF(__pyx_t_7);
7565         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7566         __Pyx_DECREF(__pyx_v_n);
7567         __pyx_v_n = __pyx_t_7;
7568         __pyx_t_7 = 0;
7569       }
7570       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7571
7572       /* "csamtools.pyx":699
7573  *                 n = 0
7574  *                 for x in referencenames: n += len(x) + 1
7575  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
7576  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
7577  *                 for x from 0 <= x < header_to_write.n_targets:
7578  */
7579       __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 = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7580       __pyx_v_header_to_write->target_name = ((char **)calloc(__pyx_t_16, (sizeof(char *))));
7581
7582       /* "csamtools.pyx":700
7583  *                 for x in referencenames: n += len(x) + 1
7584  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
7585  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
7586  *                 for x from 0 <= x < header_to_write.n_targets:
7587  *                     header_to_write.target_len[x] = referencelengths[x]
7588  */
7589       __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 = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7590       __pyx_v_header_to_write->target_len = ((uint32_t *)calloc(__pyx_t_16, (sizeof(uint32_t))));
7591
7592       /* "csamtools.pyx":701
7593  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
7594  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
7595  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
7596  *                     header_to_write.target_len[x] = referencelengths[x]
7597  *                     name = referencenames[x]
7598  */
7599       __pyx_t_17 = __pyx_v_header_to_write->n_targets;
7600       for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18++) {
7601         __pyx_t_5 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7602         __Pyx_GOTREF(__pyx_t_5);
7603         __Pyx_XDECREF(__pyx_v_x);
7604         __pyx_v_x = __pyx_t_5;
7605         __pyx_t_5 = 0;
7606
7607         /* "csamtools.pyx":702
7608  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
7609  *                 for x from 0 <= x < header_to_write.n_targets:
7610  *                     header_to_write.target_len[x] = referencelengths[x]             # <<<<<<<<<<<<<<
7611  *                     name = referencenames[x]
7612  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
7613  */
7614         __pyx_t_5 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7615         __Pyx_GOTREF(__pyx_t_5);
7616         __pyx_t_19 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_5); if (unlikely((__pyx_t_19 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7617         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7618         __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 = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7619         (__pyx_v_header_to_write->target_len[__pyx_t_14]) = __pyx_t_19;
7620
7621         /* "csamtools.pyx":703
7622  *                 for x from 0 <= x < header_to_write.n_targets:
7623  *                     header_to_write.target_len[x] = referencelengths[x]
7624  *                     name = referencenames[x]             # <<<<<<<<<<<<<<
7625  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
7626  *                     strncpy( header_to_write.target_name[x], name, len(name) )
7627  */
7628         __pyx_t_5 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7629         __Pyx_GOTREF(__pyx_t_5);
7630         __Pyx_XDECREF(__pyx_v_name);
7631         __pyx_v_name = __pyx_t_5;
7632         __pyx_t_5 = 0;
7633
7634         /* "csamtools.pyx":704
7635  *                     header_to_write.target_len[x] = referencelengths[x]
7636  *                     name = referencenames[x]
7637  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))             # <<<<<<<<<<<<<<
7638  *                     strncpy( header_to_write.target_name[x], name, len(name) )
7639  * 
7640  */
7641         __pyx_t_14 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7642         __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 = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7643         (__pyx_v_header_to_write->target_name[__pyx_t_13]) = ((char *)calloc((__pyx_t_14 + 1), (sizeof(char))));
7644
7645         /* "csamtools.pyx":705
7646  *                     name = referencenames[x]
7647  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
7648  *                     strncpy( header_to_write.target_name[x], name, len(name) )             # <<<<<<<<<<<<<<
7649  * 
7650  *                 # Optionally, if there is no text, add a SAM compatible header to output
7651  */
7652         __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 = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7653         __pyx_t_12 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7654         __pyx_t_13 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7655         strncpy((__pyx_v_header_to_write->target_name[__pyx_t_14]), __pyx_t_12, __pyx_t_13);
7656         __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 = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7657       }
7658
7659       /* "csamtools.pyx":701
7660  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
7661  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
7662  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
7663  *                     header_to_write.target_len[x] = referencelengths[x]
7664  *                     name = referencenames[x]
7665  */
7666       __pyx_t_5 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7667       __Pyx_GOTREF(__pyx_t_5);
7668       __Pyx_XDECREF(__pyx_v_x);
7669       __pyx_v_x = __pyx_t_5;
7670       __pyx_t_5 = 0;
7671
7672       /* "csamtools.pyx":709
7673  *                 # Optionally, if there is no text, add a SAM compatible header to output
7674  *                 # file.
7675  *                 if text is None and add_sq_text:             # <<<<<<<<<<<<<<
7676  *                     text = []
7677  *                     for x from 0 <= x < header_to_write.n_targets:
7678  */
7679       __pyx_t_1 = (__pyx_v_text == Py_None);
7680       if (__pyx_t_1) {
7681         __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7682         __pyx_t_11 = __pyx_t_10;
7683       } else {
7684         __pyx_t_11 = __pyx_t_1;
7685       }
7686       if (__pyx_t_11) {
7687
7688         /* "csamtools.pyx":710
7689  *                 # file.
7690  *                 if text is None and add_sq_text:
7691  *                     text = []             # <<<<<<<<<<<<<<
7692  *                     for x from 0 <= x < header_to_write.n_targets:
7693  *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
7694  */
7695         __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7696         __Pyx_GOTREF(__pyx_t_5);
7697         __Pyx_DECREF(__pyx_v_text);
7698         __pyx_v_text = ((PyObject *)__pyx_t_5);
7699         __pyx_t_5 = 0;
7700
7701         /* "csamtools.pyx":711
7702  *                 if text is None and add_sq_text:
7703  *                     text = []
7704  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
7705  *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
7706  *                     text = ''.join(text)
7707  */
7708         __pyx_t_17 = __pyx_v_header_to_write->n_targets;
7709         for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18++) {
7710           __pyx_t_5 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7711           __Pyx_GOTREF(__pyx_t_5);
7712           __Pyx_XDECREF(__pyx_v_x);
7713           __pyx_v_x = __pyx_t_5;
7714           __pyx_t_5 = 0;
7715
7716           /* "csamtools.pyx":712
7717  *                     text = []
7718  *                     for x from 0 <= x < header_to_write.n_targets:
7719  *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )             # <<<<<<<<<<<<<<
7720  *                     text = ''.join(text)
7721  * 
7722  */
7723           __pyx_t_5 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7724           __Pyx_GOTREF(__pyx_t_5);
7725           __pyx_t_7 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7726           __Pyx_GOTREF(__pyx_t_7);
7727           __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7728           __Pyx_GOTREF(__pyx_t_8);
7729           PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
7730           __Pyx_GIVEREF(__pyx_t_5);
7731           PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
7732           __Pyx_GIVEREF(__pyx_t_7);
7733           __pyx_t_5 = 0;
7734           __pyx_t_7 = 0;
7735           __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7736           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
7737           __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
7738           __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_text, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7739           __Pyx_GOTREF(__pyx_t_8);
7740           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
7741           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7742           __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 = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7743         }
7744
7745         /* "csamtools.pyx":711
7746  *                 if text is None and add_sq_text:
7747  *                     text = []
7748  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
7749  *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
7750  *                     text = ''.join(text)
7751  */
7752         __pyx_t_8 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7753         __Pyx_GOTREF(__pyx_t_8);
7754         __Pyx_XDECREF(__pyx_v_x);
7755         __pyx_v_x = __pyx_t_8;
7756         __pyx_t_8 = 0;
7757
7758         /* "csamtools.pyx":713
7759  *                     for x from 0 <= x < header_to_write.n_targets:
7760  *                         text.append( "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] ) )
7761  *                     text = ''.join(text)             # <<<<<<<<<<<<<<
7762  * 
7763  *                 if text != None:
7764  */
7765         __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_16), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7766         __Pyx_GOTREF(__pyx_t_8);
7767         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7768         __Pyx_GOTREF(__pyx_t_7);
7769         __Pyx_INCREF(__pyx_v_text);
7770         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_text);
7771         __Pyx_GIVEREF(__pyx_v_text);
7772         __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 = 713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7773         __Pyx_GOTREF(__pyx_t_5);
7774         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
7775         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
7776         __Pyx_DECREF(__pyx_v_text);
7777         __pyx_v_text = __pyx_t_5;
7778         __pyx_t_5 = 0;
7779         goto __pyx_L24;
7780       }
7781       __pyx_L24:;
7782
7783       /* "csamtools.pyx":715
7784  *                     text = ''.join(text)
7785  * 
7786  *                 if text != None:             # <<<<<<<<<<<<<<
7787  *                     # copy without \0
7788  *                     text = _force_bytes(text)
7789  */
7790       __pyx_t_5 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7791       __Pyx_GOTREF(__pyx_t_5);
7792       __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7793       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7794       if (__pyx_t_11) {
7795
7796         /* "csamtools.pyx":717
7797  *                 if text != None:
7798  *                     # copy without \0
7799  *                     text = _force_bytes(text)             # <<<<<<<<<<<<<<
7800  *                     ctext = text
7801  *                     header_to_write.l_text = strlen(ctext)
7802  */
7803         __pyx_t_5 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_text)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7804         __Pyx_GOTREF(__pyx_t_5);
7805         __Pyx_DECREF(__pyx_v_text);
7806         __pyx_v_text = __pyx_t_5;
7807         __pyx_t_5 = 0;
7808
7809         /* "csamtools.pyx":718
7810  *                     # copy without \0
7811  *                     text = _force_bytes(text)
7812  *                     ctext = text             # <<<<<<<<<<<<<<
7813  *                     header_to_write.l_text = strlen(ctext)
7814  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
7815  */
7816         __pyx_t_12 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7817         __pyx_v_ctext = __pyx_t_12;
7818
7819         /* "csamtools.pyx":719
7820  *                     text = _force_bytes(text)
7821  *                     ctext = text
7822  *                     header_to_write.l_text = strlen(ctext)             # <<<<<<<<<<<<<<
7823  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
7824  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
7825  */
7826         __pyx_v_header_to_write->l_text = strlen(__pyx_v_ctext);
7827
7828         /* "csamtools.pyx":720
7829  *                     ctext = text
7830  *                     header_to_write.l_text = strlen(ctext)
7831  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )             # <<<<<<<<<<<<<<
7832  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
7833  * 
7834  */
7835         __pyx_v_header_to_write->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char))));
7836
7837         /* "csamtools.pyx":721
7838  *                     header_to_write.l_text = strlen(ctext)
7839  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
7840  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )             # <<<<<<<<<<<<<<
7841  * 
7842  *                 header_to_write.hash = NULL
7843  */
7844         memcpy(__pyx_v_header_to_write->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
7845         goto __pyx_L27;
7846       }
7847       __pyx_L27:;
7848
7849       /* "csamtools.pyx":723
7850  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
7851  * 
7852  *                 header_to_write.hash = NULL             # <<<<<<<<<<<<<<
7853  *                 header_to_write.rg2lib = NULL
7854  * 
7855  */
7856       __pyx_v_header_to_write->hash = NULL;
7857
7858       /* "csamtools.pyx":724
7859  * 
7860  *                 header_to_write.hash = NULL
7861  *                 header_to_write.rg2lib = NULL             # <<<<<<<<<<<<<<
7862  * 
7863  *             # open file. Header gets written to file at the same time for bam files
7864  */
7865       __pyx_v_header_to_write->rg2lib = NULL;
7866     }
7867     __pyx_L17:;
7868
7869     /* "csamtools.pyx":728
7870  *             # open file. Header gets written to file at the same time for bam files
7871  *             # and sam files (in the latter case, the mode needs to be wh)
7872  *             store = StderrStore()             # <<<<<<<<<<<<<<
7873  *             self.samfile = samopen( filename, bmode, header_to_write )
7874  *             store.release()
7875  */
7876     __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7877     __Pyx_GOTREF(__pyx_t_5);
7878     __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 = 728; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7879     __Pyx_GOTREF(__pyx_t_7);
7880     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7881     __pyx_v_store = __pyx_t_7;
7882     __pyx_t_7 = 0;
7883
7884     /* "csamtools.pyx":729
7885  *             # and sam files (in the latter case, the mode needs to be wh)
7886  *             store = StderrStore()
7887  *             self.samfile = samopen( filename, bmode, header_to_write )             # <<<<<<<<<<<<<<
7888  *             store.release()
7889  * 
7890  */
7891     __pyx_t_20 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_20 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7892     __pyx_t_12 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7893     __pyx_v_self->samfile = samopen(__pyx_t_20, __pyx_t_12, __pyx_v_header_to_write);
7894
7895     /* "csamtools.pyx":730
7896  *             store = StderrStore()
7897  *             self.samfile = samopen( filename, bmode, header_to_write )
7898  *             store.release()             # <<<<<<<<<<<<<<
7899  * 
7900  *             # bam_header_destroy takes care of cleaning up of all the members
7901  */
7902     __pyx_t_7 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7903     __Pyx_GOTREF(__pyx_t_7);
7904     __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 = 730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7905     __Pyx_GOTREF(__pyx_t_5);
7906     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7907     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7908
7909     /* "csamtools.pyx":733
7910  * 
7911  *             # bam_header_destroy takes care of cleaning up of all the members
7912  *             if not template and header_to_write != NULL:             # <<<<<<<<<<<<<<
7913  *                 bam_header_destroy( header_to_write )
7914  * 
7915  */
7916     __pyx_t_11 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7917     __pyx_t_1 = (!__pyx_t_11);
7918     if (__pyx_t_1) {
7919       __pyx_t_11 = (__pyx_v_header_to_write != NULL);
7920       __pyx_t_10 = __pyx_t_11;
7921     } else {
7922       __pyx_t_10 = __pyx_t_1;
7923     }
7924     if (__pyx_t_10) {
7925
7926       /* "csamtools.pyx":734
7927  *             # bam_header_destroy takes care of cleaning up of all the members
7928  *             if not template and header_to_write != NULL:
7929  *                 bam_header_destroy( header_to_write )             # <<<<<<<<<<<<<<
7930  * 
7931  *         elif mode[0] == "r":
7932  */
7933       bam_header_destroy(__pyx_v_header_to_write);
7934       goto __pyx_L28;
7935     }
7936     __pyx_L28:;
7937     goto __pyx_L16;
7938   }
7939
7940   /* "csamtools.pyx":736
7941  *                 bam_header_destroy( header_to_write )
7942  * 
7943  *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
7944  *             # open file for reading
7945  *             if strncmp( filename, "-", 1) != 0 and \
7946  */
7947   __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7948   __Pyx_GOTREF(__pyx_t_5);
7949   __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_5, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7950   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7951   if (__pyx_t_10) {
7952
7953     /* "csamtools.pyx":738
7954  *         elif mode[0] == "r":
7955  *             # open file for reading
7956  *             if strncmp( filename, "-", 1) != 0 and \             # <<<<<<<<<<<<<<
7957  *                     not self.isremote and \
7958  *                     not os.path.exists( filename ):
7959  */
7960     __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7961     __pyx_t_10 = (strncmp(__pyx_t_12, __pyx_k_26, 1) != 0);
7962     if (__pyx_t_10) {
7963
7964       /* "csamtools.pyx":739
7965  *             # open file for reading
7966  *             if strncmp( filename, "-", 1) != 0 and \
7967  *                     not self.isremote and \             # <<<<<<<<<<<<<<
7968  *                     not os.path.exists( filename ):
7969  *                 raise IOError( "file `%s` not found" % filename)
7970  */
7971       __pyx_t_1 = (!__pyx_v_self->isremote);
7972       if (__pyx_t_1) {
7973
7974         /* "csamtools.pyx":740
7975  *             if strncmp( filename, "-", 1) != 0 and \
7976  *                     not self.isremote and \
7977  *                     not os.path.exists( filename ):             # <<<<<<<<<<<<<<
7978  *                 raise IOError( "file `%s` not found" % filename)
7979  * 
7980  */
7981         __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7982         __Pyx_GOTREF(__pyx_t_5);
7983         __pyx_t_7 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__path); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7984         __Pyx_GOTREF(__pyx_t_7);
7985         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7986         __pyx_t_5 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__exists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7987         __Pyx_GOTREF(__pyx_t_5);
7988         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7989         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7990         __Pyx_GOTREF(__pyx_t_7);
7991         __Pyx_INCREF(__pyx_v_filename);
7992         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_filename);
7993         __Pyx_GIVEREF(__pyx_v_filename);
7994         __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 = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7995         __Pyx_GOTREF(__pyx_t_8);
7996         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7997         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
7998         __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7999         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8000         __pyx_t_21 = (!__pyx_t_11);
8001         __pyx_t_11 = __pyx_t_21;
8002       } else {
8003         __pyx_t_11 = __pyx_t_1;
8004       }
8005       __pyx_t_1 = __pyx_t_11;
8006     } else {
8007       __pyx_t_1 = __pyx_t_10;
8008     }
8009     if (__pyx_t_1) {
8010
8011       /* "csamtools.pyx":741
8012  *                     not self.isremote and \
8013  *                     not os.path.exists( filename ):
8014  *                 raise IOError( "file `%s` not found" % filename)             # <<<<<<<<<<<<<<
8015  * 
8016  *             # try to detect errors
8017  */
8018       __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8019       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8020       __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8021       __Pyx_GOTREF(__pyx_t_7);
8022       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8023       __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8024       __pyx_t_8 = 0;
8025       __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 = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8026       __Pyx_GOTREF(__pyx_t_8);
8027       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8028       __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8029       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8030       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8031       goto __pyx_L29;
8032     }
8033     __pyx_L29:;
8034
8035     /* "csamtools.pyx":744
8036  * 
8037  *             # try to detect errors
8038  *             self.samfile = samopen( filename, bmode, NULL )             # <<<<<<<<<<<<<<
8039  *             if self.samfile == NULL:
8040  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
8041  */
8042     __pyx_t_20 = PyBytes_AsString(__pyx_v_filename); if (unlikely((__pyx_t_20 == (const char*)NULL) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8043     __pyx_t_12 = PyBytes_AsString(((PyObject *)__pyx_v_bmode)); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8044     __pyx_v_self->samfile = samopen(__pyx_t_20, __pyx_t_12, NULL);
8045
8046     /* "csamtools.pyx":745
8047  *             # try to detect errors
8048  *             self.samfile = samopen( filename, bmode, NULL )
8049  *             if self.samfile == NULL:             # <<<<<<<<<<<<<<
8050  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
8051  * 
8052  */
8053     __pyx_t_1 = (__pyx_v_self->samfile == NULL);
8054     if (__pyx_t_1) {
8055
8056       /* "csamtools.pyx":746
8057  *             self.samfile = samopen( filename, bmode, NULL )
8058  *             if self.samfile == NULL:
8059  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
8060  * 
8061  *             # bam files require a valid header
8062  */
8063       __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8064       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8065       __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8066       __Pyx_GOTREF(__pyx_t_7);
8067       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8068       __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8069       __pyx_t_8 = 0;
8070       __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8071       __Pyx_GOTREF(__pyx_t_8);
8072       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8073       __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8074       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8075       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8076       goto __pyx_L30;
8077     }
8078     __pyx_L30:;
8079
8080     /* "csamtools.pyx":749
8081  * 
8082  *             # bam files require a valid header
8083  *             if self.isbam:             # <<<<<<<<<<<<<<
8084  *                 if self.samfile.header == NULL:
8085  *                     raise ValueError( "file does not have valid header (mode='%s') - is it BAM format?" % mode )
8086  */
8087     if (__pyx_v_self->isbam) {
8088
8089       /* "csamtools.pyx":750
8090  *             # bam files require a valid header
8091  *             if self.isbam:
8092  *                 if self.samfile.header == NULL:             # <<<<<<<<<<<<<<
8093  *                     raise ValueError( "file does not have valid header (mode='%s') - is it BAM format?" % mode )
8094  *             else:
8095  */
8096       __pyx_t_1 = (__pyx_v_self->samfile->header == NULL);
8097       if (__pyx_t_1) {
8098
8099         /* "csamtools.pyx":751
8100  *             if self.isbam:
8101  *                 if self.samfile.header == NULL:
8102  *                     raise ValueError( "file does not have valid header (mode='%s') - is it BAM format?" % mode )             # <<<<<<<<<<<<<<
8103  *             else:
8104  *                 # in sam files it is optional (samfile full of unmapped reads)
8105  */
8106         __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_34), __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8107         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8108         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8109         __Pyx_GOTREF(__pyx_t_7);
8110         PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8111         __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8112         __pyx_t_8 = 0;
8113         __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8114         __Pyx_GOTREF(__pyx_t_8);
8115         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8116         __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8117         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8118         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8119         goto __pyx_L32;
8120       }
8121       __pyx_L32:;
8122       goto __pyx_L31;
8123     }
8124     /*else*/ {
8125
8126       /* "csamtools.pyx":754
8127  *             else:
8128  *                 # in sam files it is optional (samfile full of unmapped reads)
8129  *                 if check_header and self.samfile.header == NULL:             # <<<<<<<<<<<<<<
8130  *                     raise ValueError( "file does not have valid header (mode='%s') - is it SAM format?" % mode )
8131  * 
8132  */
8133       __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_check_header); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8134       if (__pyx_t_1) {
8135         __pyx_t_10 = (__pyx_v_self->samfile->header == NULL);
8136         __pyx_t_11 = __pyx_t_10;
8137       } else {
8138         __pyx_t_11 = __pyx_t_1;
8139       }
8140       if (__pyx_t_11) {
8141
8142         /* "csamtools.pyx":755
8143  *                 # in sam files it is optional (samfile full of unmapped reads)
8144  *                 if check_header and self.samfile.header == NULL:
8145  *                     raise ValueError( "file does not have valid header (mode='%s') - is it SAM format?" % mode )             # <<<<<<<<<<<<<<
8146  * 
8147  *             # disabled for autodetection to work
8148  */
8149         __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_35), __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8150         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8151         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8152         __Pyx_GOTREF(__pyx_t_7);
8153         PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8154         __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8155         __pyx_t_8 = 0;
8156         __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8157         __Pyx_GOTREF(__pyx_t_8);
8158         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8159         __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8160         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8161         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8162         goto __pyx_L33;
8163       }
8164       __pyx_L33:;
8165     }
8166     __pyx_L31:;
8167
8168     /* "csamtools.pyx":759
8169  *             # disabled for autodetection to work
8170  *             # needs to be disabled so that reading from sam-files without headers works
8171  *             if check_sq and self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
8172  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)
8173  * 
8174  */
8175     __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8176     if (__pyx_t_11) {
8177       __pyx_t_1 = (__pyx_v_self->samfile->header->n_targets == 0);
8178       __pyx_t_10 = __pyx_t_1;
8179     } else {
8180       __pyx_t_10 = __pyx_t_11;
8181     }
8182     if (__pyx_t_10) {
8183
8184       /* "csamtools.pyx":760
8185  *             # needs to be disabled so that reading from sam-files without headers works
8186  *             if check_sq and self.samfile.header.n_targets == 0:
8187  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
8188  * 
8189  *         if self.samfile == NULL:
8190  */
8191       __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_36), __pyx_v_mode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8192       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8193       __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8194       __Pyx_GOTREF(__pyx_t_7);
8195       PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8196       __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8197       __pyx_t_8 = 0;
8198       __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8199       __Pyx_GOTREF(__pyx_t_8);
8200       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8201       __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8202       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8203       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8204       goto __pyx_L34;
8205     }
8206     __pyx_L34:;
8207     goto __pyx_L16;
8208   }
8209   __pyx_L16:;
8210
8211   /* "csamtools.pyx":762
8212  *                 raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)
8213  * 
8214  *         if self.samfile == NULL:             # <<<<<<<<<<<<<<
8215  *             raise IOError("could not open file `%s`" % filename )
8216  * 
8217  */
8218   __pyx_t_10 = (__pyx_v_self->samfile == NULL);
8219   if (__pyx_t_10) {
8220
8221     /* "csamtools.pyx":763
8222  * 
8223  *         if self.samfile == NULL:
8224  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
8225  * 
8226  *         # check for index and open if present
8227  */
8228     __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), __pyx_v_filename); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8229     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
8230     __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8231     __Pyx_GOTREF(__pyx_t_7);
8232     PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_8));
8233     __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
8234     __pyx_t_8 = 0;
8235     __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 = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8236     __Pyx_GOTREF(__pyx_t_8);
8237     __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8238     __Pyx_Raise(__pyx_t_8, 0, 0, 0);
8239     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8240     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8241     goto __pyx_L35;
8242   }
8243   __pyx_L35:;
8244
8245   /* "csamtools.pyx":766
8246  * 
8247  *         # check for index and open if present
8248  *         if mode[0] == "r" and self.isbam:             # <<<<<<<<<<<<<<
8249  * 
8250  *             if not self.isremote:
8251  */
8252   __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8253   __Pyx_GOTREF(__pyx_t_8);
8254   __pyx_t_10 = __Pyx_PyString_Equals(__pyx_t_8, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8255   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8256   if (__pyx_t_10) {
8257     __pyx_t_11 = __pyx_v_self->isbam;
8258   } else {
8259     __pyx_t_11 = __pyx_t_10;
8260   }
8261   if (__pyx_t_11) {
8262
8263     /* "csamtools.pyx":768
8264  *         if mode[0] == "r" and self.isbam:
8265  * 
8266  *             if not self.isremote:             # <<<<<<<<<<<<<<
8267  *                 if not os.path.exists(filename + b".bai"):
8268  *                     self.index = NULL
8269  */
8270     __pyx_t_11 = (!__pyx_v_self->isremote);
8271     if (__pyx_t_11) {
8272
8273       /* "csamtools.pyx":769
8274  * 
8275  *             if not self.isremote:
8276  *                 if not os.path.exists(filename + b".bai"):             # <<<<<<<<<<<<<<
8277  *                     self.index = NULL
8278  *                 else:
8279  */
8280       __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8281       __Pyx_GOTREF(__pyx_t_8);
8282       __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__path); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8283       __Pyx_GOTREF(__pyx_t_7);
8284       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8285       __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__exists); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8286       __Pyx_GOTREF(__pyx_t_8);
8287       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8288       __pyx_t_7 = PyNumber_Add(__pyx_v_filename, ((PyObject *)__pyx_kp_b_37)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8289       __Pyx_GOTREF(__pyx_t_7);
8290       __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8291       __Pyx_GOTREF(__pyx_t_5);
8292       PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7);
8293       __Pyx_GIVEREF(__pyx_t_7);
8294       __pyx_t_7 = 0;
8295       __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8296       __Pyx_GOTREF(__pyx_t_7);
8297       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
8298       __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
8299       __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8300       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8301       __pyx_t_10 = (!__pyx_t_11);
8302       if (__pyx_t_10) {
8303
8304         /* "csamtools.pyx":770
8305  *             if not self.isremote:
8306  *                 if not os.path.exists(filename + b".bai"):
8307  *                     self.index = NULL             # <<<<<<<<<<<<<<
8308  *                 else:
8309  *                     # returns NULL if there is no index or index could not be opened
8310  */
8311         __pyx_v_self->index = NULL;
8312         goto __pyx_L38;
8313       }
8314       /*else*/ {
8315
8316         /* "csamtools.pyx":773
8317  *                 else:
8318  *                     # returns NULL if there is no index or index could not be opened
8319  *                     self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
8320  *                     if self.index == NULL:
8321  *                         raise IOError("error while opening index `%s` " % filename )
8322  */
8323         __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8324         __pyx_v_self->index = bam_index_load(__pyx_t_12);
8325
8326         /* "csamtools.pyx":774
8327  *                     # returns NULL if there is no index or index could not be opened
8328  *                     self.index = bam_index_load(filename)
8329  *                     if self.index == NULL:             # <<<<<<<<<<<<<<
8330  *                         raise IOError("error while opening index `%s` " % filename )
8331  *             else:
8332  */
8333         __pyx_t_10 = (__pyx_v_self->index == NULL);
8334         if (__pyx_t_10) {
8335
8336           /* "csamtools.pyx":775
8337  *                     self.index = bam_index_load(filename)
8338  *                     if self.index == NULL:
8339  *                         raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
8340  *             else:
8341  *                 self.index = bam_index_load(filename)
8342  */
8343           __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_38), __pyx_v_filename); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8344           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
8345           __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8346           __Pyx_GOTREF(__pyx_t_5);
8347           PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_7));
8348           __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
8349           __pyx_t_7 = 0;
8350           __pyx_t_7 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8351           __Pyx_GOTREF(__pyx_t_7);
8352           __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
8353           __Pyx_Raise(__pyx_t_7, 0, 0, 0);
8354           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8355           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8356           goto __pyx_L39;
8357         }
8358         __pyx_L39:;
8359       }
8360       __pyx_L38:;
8361       goto __pyx_L37;
8362     }
8363     /*else*/ {
8364
8365       /* "csamtools.pyx":777
8366  *                         raise IOError("error while opening index `%s` " % filename )
8367  *             else:
8368  *                 self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
8369  *                 if self.index == NULL:
8370  *                     raise IOError("error while opening index `%s` " % filename )
8371  */
8372       __pyx_t_12 = PyBytes_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_12) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8373       __pyx_v_self->index = bam_index_load(__pyx_t_12);
8374
8375       /* "csamtools.pyx":778
8376  *             else:
8377  *                 self.index = bam_index_load(filename)
8378  *                 if self.index == NULL:             # <<<<<<<<<<<<<<
8379  *                     raise IOError("error while opening index `%s` " % filename )
8380  * 
8381  */
8382       __pyx_t_10 = (__pyx_v_self->index == NULL);
8383       if (__pyx_t_10) {
8384
8385         /* "csamtools.pyx":779
8386  *                 self.index = bam_index_load(filename)
8387  *                 if self.index == NULL:
8388  *                     raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
8389  * 
8390  *             if not self.isstream:
8391  */
8392         __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_38), __pyx_v_filename); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8393         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
8394         __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8395         __Pyx_GOTREF(__pyx_t_5);
8396         PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_7));
8397         __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
8398         __pyx_t_7 = 0;
8399         __pyx_t_7 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8400         __Pyx_GOTREF(__pyx_t_7);
8401         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
8402         __Pyx_Raise(__pyx_t_7, 0, 0, 0);
8403         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8404         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8405         goto __pyx_L40;
8406       }
8407       __pyx_L40:;
8408     }
8409     __pyx_L37:;
8410
8411     /* "csamtools.pyx":781
8412  *                     raise IOError("error while opening index `%s` " % filename )
8413  * 
8414  *             if not self.isstream:             # <<<<<<<<<<<<<<
8415  *                 self.start_offset = bam_tell( self.samfile.x.bam )
8416  * 
8417  */
8418     __pyx_t_10 = (!__pyx_v_self->isstream);
8419     if (__pyx_t_10) {
8420
8421       /* "csamtools.pyx":782
8422  * 
8423  *             if not self.isstream:
8424  *                 self.start_offset = bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
8425  * 
8426  *     def gettid( self, reference ):
8427  */
8428       __pyx_v_self->start_offset = bam_tell(__pyx_v_self->samfile->x.bam);
8429       goto __pyx_L41;
8430     }
8431     __pyx_L41:;
8432     goto __pyx_L36;
8433   }
8434   __pyx_L36:;
8435
8436   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
8437   goto __pyx_L0;
8438   __pyx_L1_error:;
8439   __Pyx_XDECREF(__pyx_t_5);
8440   __Pyx_XDECREF(__pyx_t_6);
8441   __Pyx_XDECREF(__pyx_t_7);
8442   __Pyx_XDECREF(__pyx_t_8);
8443   __Pyx_AddTraceback("csamtools.Samfile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
8444   __pyx_r = NULL;
8445   __pyx_L0:;
8446   __Pyx_XDECREF(__pyx_v_msg);
8447   __Pyx_XDECREF(__pyx_v_bmode);
8448   __Pyx_XDECREF(__pyx_v_n);
8449   __Pyx_XDECREF(__pyx_v_x);
8450   __Pyx_XDECREF(__pyx_v_name);
8451   __Pyx_XDECREF(__pyx_v_store);
8452   __Pyx_XDECREF(__pyx_v_ref);
8453   __Pyx_XDECREF(__pyx_v_filename);
8454   __Pyx_XDECREF(__pyx_v_referencenames);
8455   __Pyx_XDECREF(__pyx_v_text);
8456   __Pyx_XGIVEREF(__pyx_r);
8457   __Pyx_TraceReturn(__pyx_r);
8458   __Pyx_RefNannyFinishContext();
8459   return __pyx_r;
8460 }
8461
8462 /* Python wrapper */
8463 static PyObject *__pyx_pw_9csamtools_7Samfile_9gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
8464 static char __pyx_doc_9csamtools_7Samfile_8gettid[] = "Samfile.gettid(self, reference)\n\n        convert :term:`reference` name into numerical :term:`tid`\n\n        returns -1 if reference is not known.\n        ";
8465 static PyObject *__pyx_pw_9csamtools_7Samfile_9gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
8466   PyObject *__pyx_r = 0;
8467   __Pyx_RefNannyDeclarations
8468   __Pyx_RefNannySetupContext("gettid (wrapper)", 0);
8469   __pyx_r = __pyx_pf_9csamtools_7Samfile_8gettid(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), ((PyObject *)__pyx_v_reference));
8470   __Pyx_RefNannyFinishContext();
8471   return __pyx_r;
8472 }
8473
8474 /* "csamtools.pyx":784
8475  *                 self.start_offset = bam_tell( self.samfile.x.bam )
8476  * 
8477  *     def gettid( self, reference ):             # <<<<<<<<<<<<<<
8478  *         '''
8479  *         convert :term:`reference` name into numerical :term:`tid`
8480  */
8481
8482 static PyObject *__pyx_pf_9csamtools_7Samfile_8gettid(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference) {
8483   PyObject *__pyx_r = NULL;
8484   __Pyx_RefNannyDeclarations
8485   PyObject *__pyx_t_1 = NULL;
8486   PyObject *__pyx_t_2 = NULL;
8487   int __pyx_t_3;
8488   int __pyx_t_4;
8489   char *__pyx_t_5;
8490   int __pyx_lineno = 0;
8491   const char *__pyx_filename = NULL;
8492   int __pyx_clineno = 0;
8493   __Pyx_TraceDeclarations
8494   __Pyx_RefNannySetupContext("gettid", 0);
8495   __Pyx_TraceCall("gettid", __pyx_f[0], 784);
8496   __Pyx_INCREF(__pyx_v_reference);
8497
8498   /* "csamtools.pyx":790
8499  *         returns -1 if reference is not known.
8500  *         '''
8501  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
8502  *         reference = _force_bytes(reference)
8503  *         return pysam_reference2tid( self.samfile.header, reference )
8504  */
8505   __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 = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8506   __Pyx_GOTREF(__pyx_t_1);
8507   __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 = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8508   __Pyx_GOTREF(__pyx_t_2);
8509   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8510   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8511   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8512   __pyx_t_4 = (!__pyx_t_3);
8513   if (__pyx_t_4) {
8514     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8515     __Pyx_GOTREF(__pyx_t_2);
8516     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
8517     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8518     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8519     goto __pyx_L3;
8520   }
8521   __pyx_L3:;
8522
8523   /* "csamtools.pyx":791
8524  *         '''
8525  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8526  *         reference = _force_bytes(reference)             # <<<<<<<<<<<<<<
8527  *         return pysam_reference2tid( self.samfile.header, reference )
8528  * 
8529  */
8530   __pyx_t_2 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_reference)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8531   __Pyx_GOTREF(__pyx_t_2);
8532   __Pyx_DECREF(__pyx_v_reference);
8533   __pyx_v_reference = __pyx_t_2;
8534   __pyx_t_2 = 0;
8535
8536   /* "csamtools.pyx":792
8537  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8538  *         reference = _force_bytes(reference)
8539  *         return pysam_reference2tid( self.samfile.header, reference )             # <<<<<<<<<<<<<<
8540  * 
8541  *     def getrname( self, tid ):
8542  */
8543   __Pyx_XDECREF(__pyx_r);
8544   __pyx_t_5 = PyBytes_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8545   __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 = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8546   __Pyx_GOTREF(__pyx_t_2);
8547   __pyx_r = __pyx_t_2;
8548   __pyx_t_2 = 0;
8549   goto __pyx_L0;
8550
8551   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
8552   goto __pyx_L0;
8553   __pyx_L1_error:;
8554   __Pyx_XDECREF(__pyx_t_1);
8555   __Pyx_XDECREF(__pyx_t_2);
8556   __Pyx_AddTraceback("csamtools.Samfile.gettid", __pyx_clineno, __pyx_lineno, __pyx_filename);
8557   __pyx_r = NULL;
8558   __pyx_L0:;
8559   __Pyx_XDECREF(__pyx_v_reference);
8560   __Pyx_XGIVEREF(__pyx_r);
8561   __Pyx_TraceReturn(__pyx_r);
8562   __Pyx_RefNannyFinishContext();
8563   return __pyx_r;
8564 }
8565
8566 /* Python wrapper */
8567 static PyObject *__pyx_pw_9csamtools_7Samfile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
8568 static char __pyx_doc_9csamtools_7Samfile_10getrname[] = "Samfile.getrname(self, tid)\n\n        convert numerical :term:`tid` into :term:`reference` name.";
8569 static PyObject *__pyx_pw_9csamtools_7Samfile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
8570   PyObject *__pyx_r = 0;
8571   __Pyx_RefNannyDeclarations
8572   __Pyx_RefNannySetupContext("getrname (wrapper)", 0);
8573   __pyx_r = __pyx_pf_9csamtools_7Samfile_10getrname(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), ((PyObject *)__pyx_v_tid));
8574   __Pyx_RefNannyFinishContext();
8575   return __pyx_r;
8576 }
8577
8578 /* "csamtools.pyx":794
8579  *         return pysam_reference2tid( self.samfile.header, reference )
8580  * 
8581  *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
8582  *         '''
8583  *         convert numerical :term:`tid` into :term:`reference` name.'''
8584  */
8585
8586 static PyObject *__pyx_pf_9csamtools_7Samfile_10getrname(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_tid) {
8587   PyObject *__pyx_r = NULL;
8588   __Pyx_RefNannyDeclarations
8589   PyObject *__pyx_t_1 = NULL;
8590   PyObject *__pyx_t_2 = NULL;
8591   int __pyx_t_3;
8592   int __pyx_t_4;
8593   Py_ssize_t __pyx_t_5;
8594   int __pyx_lineno = 0;
8595   const char *__pyx_filename = NULL;
8596   int __pyx_clineno = 0;
8597   __Pyx_TraceDeclarations
8598   __Pyx_RefNannySetupContext("getrname", 0);
8599   __Pyx_TraceCall("getrname", __pyx_f[0], 794);
8600
8601   /* "csamtools.pyx":797
8602  *         '''
8603  *         convert numerical :term:`tid` into :term:`reference` name.'''
8604  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
8605  *         if not 0 <= tid < self.samfile.header.n_targets:
8606  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8607  */
8608   __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 = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8609   __Pyx_GOTREF(__pyx_t_1);
8610   __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 = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8611   __Pyx_GOTREF(__pyx_t_2);
8612   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8613   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8614   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8615   __pyx_t_4 = (!__pyx_t_3);
8616   if (__pyx_t_4) {
8617     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8618     __Pyx_GOTREF(__pyx_t_2);
8619     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
8620     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8621     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8622     goto __pyx_L3;
8623   }
8624   __pyx_L3:;
8625
8626   /* "csamtools.pyx":798
8627  *         convert numerical :term:`tid` into :term:`reference` name.'''
8628  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8629  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
8630  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8631  *         return _charptr_to_str(self.samfile.header.target_name[tid])
8632  */
8633   __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8634   __Pyx_GOTREF(__pyx_t_2);
8635   if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
8636     __Pyx_DECREF(__pyx_t_2);
8637     __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 = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8638     __Pyx_GOTREF(__pyx_t_1);
8639     __pyx_t_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_1, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8640     __Pyx_GOTREF(__pyx_t_2);
8641     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8642   }
8643   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8644   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8645   __pyx_t_3 = (!__pyx_t_4);
8646   if (__pyx_t_3) {
8647
8648     /* "csamtools.pyx":799
8649  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8650  *         if not 0 <= tid < self.samfile.header.n_targets:
8651  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
8652  *         return _charptr_to_str(self.samfile.header.target_name[tid])
8653  * 
8654  */
8655     __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 = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8656     __Pyx_GOTREF(__pyx_t_2);
8657     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8658     __Pyx_GOTREF(__pyx_t_1);
8659     __Pyx_INCREF(__pyx_v_tid);
8660     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tid);
8661     __Pyx_GIVEREF(__pyx_v_tid);
8662     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
8663     __Pyx_GIVEREF(__pyx_t_2);
8664     __pyx_t_2 = 0;
8665     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8666     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8667     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
8668     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8669     __Pyx_GOTREF(__pyx_t_1);
8670     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
8671     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
8672     __pyx_t_2 = 0;
8673     __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 = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8674     __Pyx_GOTREF(__pyx_t_2);
8675     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
8676     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
8677     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8678     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8679     goto __pyx_L4;
8680   }
8681   __pyx_L4:;
8682
8683   /* "csamtools.pyx":800
8684  *         if not 0 <= tid < self.samfile.header.n_targets:
8685  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8686  *         return _charptr_to_str(self.samfile.header.target_name[tid])             # <<<<<<<<<<<<<<
8687  * 
8688  *     cdef char * _getrname( self, int tid ): # TODO unused
8689  */
8690   __Pyx_XDECREF(__pyx_r);
8691   __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 = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8692   __pyx_t_2 = __pyx_f_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 = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8693   __Pyx_GOTREF(__pyx_t_2);
8694   __pyx_r = __pyx_t_2;
8695   __pyx_t_2 = 0;
8696   goto __pyx_L0;
8697
8698   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
8699   goto __pyx_L0;
8700   __pyx_L1_error:;
8701   __Pyx_XDECREF(__pyx_t_1);
8702   __Pyx_XDECREF(__pyx_t_2);
8703   __Pyx_AddTraceback("csamtools.Samfile.getrname", __pyx_clineno, __pyx_lineno, __pyx_filename);
8704   __pyx_r = NULL;
8705   __pyx_L0:;
8706   __Pyx_XGIVEREF(__pyx_r);
8707   __Pyx_TraceReturn(__pyx_r);
8708   __Pyx_RefNannyFinishContext();
8709   return __pyx_r;
8710 }
8711
8712 /* "csamtools.pyx":802
8713  *         return _charptr_to_str(self.samfile.header.target_name[tid])
8714  * 
8715  *     cdef char * _getrname( self, int tid ): # TODO unused             # <<<<<<<<<<<<<<
8716  *         '''
8717  *         convert numerical :term:`tid` into :term:`reference` name.'''
8718  */
8719
8720 static char *__pyx_f_9csamtools_7Samfile__getrname(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, int __pyx_v_tid) {
8721   char *__pyx_r;
8722   __Pyx_RefNannyDeclarations
8723   PyObject *__pyx_t_1 = NULL;
8724   PyObject *__pyx_t_2 = NULL;
8725   int __pyx_t_3;
8726   int __pyx_t_4;
8727   PyObject *__pyx_t_5 = NULL;
8728   int __pyx_lineno = 0;
8729   const char *__pyx_filename = NULL;
8730   int __pyx_clineno = 0;
8731   __Pyx_TraceDeclarations
8732   __Pyx_RefNannySetupContext("_getrname", 0);
8733   __Pyx_TraceCall("_getrname", __pyx_f[0], 802);
8734
8735   /* "csamtools.pyx":805
8736  *         '''
8737  *         convert numerical :term:`tid` into :term:`reference` name.'''
8738  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
8739  *         if not 0 <= tid < self.samfile.header.n_targets:
8740  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8741  */
8742   __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 = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8743   __Pyx_GOTREF(__pyx_t_1);
8744   __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 = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8745   __Pyx_GOTREF(__pyx_t_2);
8746   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8747   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8748   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8749   __pyx_t_4 = (!__pyx_t_3);
8750   if (__pyx_t_4) {
8751     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8752     __Pyx_GOTREF(__pyx_t_2);
8753     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
8754     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8755     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8756     goto __pyx_L3;
8757   }
8758   __pyx_L3:;
8759
8760   /* "csamtools.pyx":806
8761  *         convert numerical :term:`tid` into :term:`reference` name.'''
8762  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8763  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
8764  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8765  *         return self.samfile.header.target_name[tid]
8766  */
8767   __pyx_t_4 = (0 <= __pyx_v_tid);
8768   if (__pyx_t_4) {
8769     __pyx_t_4 = (__pyx_v_tid < __pyx_v_self->samfile->header->n_targets);
8770   }
8771   __pyx_t_3 = (!__pyx_t_4);
8772   if (__pyx_t_3) {
8773
8774     /* "csamtools.pyx":807
8775  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
8776  *         if not 0 <= tid < self.samfile.header.n_targets:
8777  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
8778  *         return self.samfile.header.target_name[tid]
8779  * 
8780  */
8781     __pyx_t_2 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8782     __Pyx_GOTREF(__pyx_t_2);
8783     __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 = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8784     __Pyx_GOTREF(__pyx_t_1);
8785     __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8786     __Pyx_GOTREF(__pyx_t_5);
8787     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
8788     __Pyx_GIVEREF(__pyx_t_2);
8789     PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
8790     __Pyx_GIVEREF(__pyx_t_1);
8791     __pyx_t_2 = 0;
8792     __pyx_t_1 = 0;
8793     __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_41), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8794     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
8795     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
8796     __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8797     __Pyx_GOTREF(__pyx_t_5);
8798     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
8799     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
8800     __pyx_t_1 = 0;
8801     __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 = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8802     __Pyx_GOTREF(__pyx_t_1);
8803     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
8804     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
8805     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8806     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8807     goto __pyx_L4;
8808   }
8809   __pyx_L4:;
8810
8811   /* "csamtools.pyx":808
8812  *         if not 0 <= tid < self.samfile.header.n_targets:
8813  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
8814  *         return self.samfile.header.target_name[tid]             # <<<<<<<<<<<<<<
8815  * 
8816  *     def _parseRegion( self,
8817  */
8818   __pyx_r = (__pyx_v_self->samfile->header->target_name[__pyx_v_tid]);
8819   goto __pyx_L0;
8820
8821   __pyx_r = 0;
8822   goto __pyx_L0;
8823   __pyx_L1_error:;
8824   __Pyx_XDECREF(__pyx_t_1);
8825   __Pyx_XDECREF(__pyx_t_2);
8826   __Pyx_XDECREF(__pyx_t_5);
8827   __Pyx_WriteUnraisable("csamtools.Samfile._getrname", __pyx_clineno, __pyx_lineno, __pyx_filename);
8828   __pyx_r = 0;
8829   __pyx_L0:;
8830   __Pyx_TraceReturn(Py_None);
8831   __Pyx_RefNannyFinishContext();
8832   return __pyx_r;
8833 }
8834
8835 /* Python wrapper */
8836 static PyObject *__pyx_pw_9csamtools_7Samfile_13_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
8837 static char __pyx_doc_9csamtools_7Samfile_12_parseRegion[] = "Samfile._parseRegion(self, reference=None, start=None, end=None, region=None)\n\n        parse region information.\n\n        raise ValueError for for invalid regions.\n\n        returns a tuple of flag, tid, start and end. Flag indicates\n        whether some coordinates were supplied.\n\n        Note that regions are 1-based, while start,end are python coordinates.\n        ";
8838 static PyObject *__pyx_pw_9csamtools_7Samfile_13_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
8839   PyObject *__pyx_v_reference = 0;
8840   PyObject *__pyx_v_start = 0;
8841   PyObject *__pyx_v_end = 0;
8842   PyObject *__pyx_v_region = 0;
8843   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
8844   PyObject *__pyx_r = 0;
8845   __Pyx_RefNannyDeclarations
8846   __Pyx_RefNannySetupContext("_parseRegion (wrapper)", 0);
8847   {
8848     PyObject* values[4] = {0,0,0,0};
8849
8850     /* "csamtools.pyx":811
8851  * 
8852  *     def _parseRegion( self,
8853  *                       reference = None,             # <<<<<<<<<<<<<<
8854  *                       start = None,
8855  *                       end = None,
8856  */
8857     values[0] = ((PyObject *)Py_None);
8858
8859     /* "csamtools.pyx":812
8860  *     def _parseRegion( self,
8861  *                       reference = None,
8862  *                       start = None,             # <<<<<<<<<<<<<<
8863  *                       end = None,
8864  *                       region = None ):
8865  */
8866     values[1] = ((PyObject *)Py_None);
8867
8868     /* "csamtools.pyx":813
8869  *                       reference = None,
8870  *                       start = None,
8871  *                       end = None,             # <<<<<<<<<<<<<<
8872  *                       region = None ):
8873  *         '''
8874  */
8875     values[2] = ((PyObject *)Py_None);
8876
8877     /* "csamtools.pyx":814
8878  *                       start = None,
8879  *                       end = None,
8880  *                       region = None ):             # <<<<<<<<<<<<<<
8881  *         '''
8882  *         parse region information.
8883  */
8884     values[3] = ((PyObject *)Py_None);
8885     if (unlikely(__pyx_kwds)) {
8886       Py_ssize_t kw_args;
8887       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
8888       switch (pos_args) {
8889         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
8890         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
8891         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
8892         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
8893         case  0: break;
8894         default: goto __pyx_L5_argtuple_error;
8895       }
8896       kw_args = PyDict_Size(__pyx_kwds);
8897       switch (pos_args) {
8898         case  0:
8899         if (kw_args > 0) {
8900           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
8901           if (value) { values[0] = value; kw_args--; }
8902         }
8903         case  1:
8904         if (kw_args > 0) {
8905           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
8906           if (value) { values[1] = value; kw_args--; }
8907         }
8908         case  2:
8909         if (kw_args > 0) {
8910           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
8911           if (value) { values[2] = value; kw_args--; }
8912         }
8913         case  3:
8914         if (kw_args > 0) {
8915           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
8916           if (value) { values[3] = value; kw_args--; }
8917         }
8918       }
8919       if (unlikely(kw_args > 0)) {
8920         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
8921       }
8922     } else {
8923       switch (PyTuple_GET_SIZE(__pyx_args)) {
8924         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
8925         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
8926         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
8927         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
8928         case  0: break;
8929         default: goto __pyx_L5_argtuple_error;
8930       }
8931     }
8932     __pyx_v_reference = values[0];
8933     __pyx_v_start = values[1];
8934     __pyx_v_end = values[2];
8935     __pyx_v_region = values[3];
8936   }
8937   goto __pyx_L4_argument_unpacking_done;
8938   __pyx_L5_argtuple_error:;
8939   __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
8940   __pyx_L3_error:;
8941   __Pyx_AddTraceback("csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
8942   __Pyx_RefNannyFinishContext();
8943   return NULL;
8944   __pyx_L4_argument_unpacking_done:;
8945   __pyx_r = __pyx_pf_9csamtools_7Samfile_12_parseRegion(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region);
8946   __Pyx_RefNannyFinishContext();
8947   return __pyx_r;
8948 }
8949
8950 /* "csamtools.pyx":810
8951  *         return self.samfile.header.target_name[tid]
8952  * 
8953  *     def _parseRegion( self,             # <<<<<<<<<<<<<<
8954  *                       reference = None,
8955  *                       start = None,
8956  */
8957
8958 static PyObject *__pyx_pf_9csamtools_7Samfile_12_parseRegion(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region) {
8959   int __pyx_v_rtid;
8960   PY_LONG_LONG __pyx_v_rstart;
8961   PY_LONG_LONG __pyx_v_rend;
8962   PyObject *__pyx_v_parts = NULL;
8963   PyObject *__pyx_r = NULL;
8964   __Pyx_RefNannyDeclarations
8965   PyObject *__pyx_t_1 = NULL;
8966   int __pyx_t_2;
8967   PyObject *__pyx_t_3 = NULL;
8968   PyObject *__pyx_t_4 = NULL;
8969   PyObject *__pyx_t_5 = NULL;
8970   PY_LONG_LONG __pyx_t_6;
8971   int __pyx_t_7;
8972   PyObject *__pyx_t_8 = NULL;
8973   PyObject *__pyx_t_9 = NULL;
8974   PyObject *__pyx_t_10 = NULL;
8975   PyObject *__pyx_t_11 = NULL;
8976   Py_ssize_t __pyx_t_12;
8977   int __pyx_t_13;
8978   int __pyx_lineno = 0;
8979   const char *__pyx_filename = NULL;
8980   int __pyx_clineno = 0;
8981   __Pyx_TraceDeclarations
8982   __Pyx_RefNannySetupContext("_parseRegion", 0);
8983   __Pyx_TraceCall("_parseRegion", __pyx_f[0], 810);
8984   __Pyx_INCREF(__pyx_v_reference);
8985   __Pyx_INCREF(__pyx_v_region);
8986
8987   /* "csamtools.pyx":833
8988  *         cdef long long rend
8989  * 
8990  *         rtid = -1             # <<<<<<<<<<<<<<
8991  *         rstart = 0
8992  *         rend = max_pos
8993  */
8994   __pyx_v_rtid = -1;
8995
8996   /* "csamtools.pyx":834
8997  * 
8998  *         rtid = -1
8999  *         rstart = 0             # <<<<<<<<<<<<<<
9000  *         rend = max_pos
9001  *         if start != None:
9002  */
9003   __pyx_v_rstart = 0;
9004
9005   /* "csamtools.pyx":835
9006  *         rtid = -1
9007  *         rstart = 0
9008  *         rend = max_pos             # <<<<<<<<<<<<<<
9009  *         if start != None:
9010  *             try:
9011  */
9012   __pyx_v_rend = __pyx_v_9csamtools_max_pos;
9013
9014   /* "csamtools.pyx":836
9015  *         rstart = 0
9016  *         rend = max_pos
9017  *         if start != None:             # <<<<<<<<<<<<<<
9018  *             try:
9019  *                 rstart = start
9020  */
9021   __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9022   __Pyx_GOTREF(__pyx_t_1);
9023   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9024   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9025   if (__pyx_t_2) {
9026
9027     /* "csamtools.pyx":837
9028  *         rend = max_pos
9029  *         if start != None:
9030  *             try:             # <<<<<<<<<<<<<<
9031  *                 rstart = start
9032  *             except OverflowError:
9033  */
9034     {
9035       __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
9036       __Pyx_XGOTREF(__pyx_t_3);
9037       __Pyx_XGOTREF(__pyx_t_4);
9038       __Pyx_XGOTREF(__pyx_t_5);
9039       /*try:*/ {
9040
9041         /* "csamtools.pyx":838
9042  *         if start != None:
9043  *             try:
9044  *                 rstart = start             # <<<<<<<<<<<<<<
9045  *             except OverflowError:
9046  *                 raise ValueError( 'start out of range (%i)' % start )
9047  */
9048         __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 = 838; __pyx_clineno = __LINE__; goto __pyx_L4_error;}
9049         __pyx_v_rstart = __pyx_t_6;
9050       }
9051       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
9052       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
9053       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
9054       goto __pyx_L11_try_end;
9055       __pyx_L4_error:;
9056       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
9057
9058       /* "csamtools.pyx":839
9059  *             try:
9060  *                 rstart = start
9061  *             except OverflowError:             # <<<<<<<<<<<<<<
9062  *                 raise ValueError( 'start out of range (%i)' % start )
9063  * 
9064  */
9065       __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
9066       if (__pyx_t_7) {
9067         __Pyx_AddTraceback("csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
9068         if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_8, &__pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
9069         __Pyx_GOTREF(__pyx_t_1);
9070         __Pyx_GOTREF(__pyx_t_8);
9071         __Pyx_GOTREF(__pyx_t_9);
9072
9073         /* "csamtools.pyx":840
9074  *                 rstart = start
9075  *             except OverflowError:
9076  *                 raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
9077  * 
9078  *         if end != None:
9079  */
9080         __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 = 840; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
9081         __Pyx_GOTREF(((PyObject *)__pyx_t_10));
9082         __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
9083         __Pyx_GOTREF(__pyx_t_11);
9084         PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_10));
9085         __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
9086         __pyx_t_10 = 0;
9087         __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 = 840; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
9088         __Pyx_GOTREF(__pyx_t_10);
9089         __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
9090         __Pyx_Raise(__pyx_t_10, 0, 0, 0);
9091         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
9092         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L6_except_error;}
9093         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9094         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
9095         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9096         goto __pyx_L5_exception_handled;
9097       }
9098       __pyx_L6_except_error:;
9099       __Pyx_XGIVEREF(__pyx_t_3);
9100       __Pyx_XGIVEREF(__pyx_t_4);
9101       __Pyx_XGIVEREF(__pyx_t_5);
9102       __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
9103       goto __pyx_L1_error;
9104       __pyx_L5_exception_handled:;
9105       __Pyx_XGIVEREF(__pyx_t_3);
9106       __Pyx_XGIVEREF(__pyx_t_4);
9107       __Pyx_XGIVEREF(__pyx_t_5);
9108       __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
9109       __pyx_L11_try_end:;
9110     }
9111     goto __pyx_L3;
9112   }
9113   __pyx_L3:;
9114
9115   /* "csamtools.pyx":842
9116  *                 raise ValueError( 'start out of range (%i)' % start )
9117  * 
9118  *         if end != None:             # <<<<<<<<<<<<<<
9119  *             try:
9120  *                 rend = end
9121  */
9122   __pyx_t_9 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9123   __Pyx_GOTREF(__pyx_t_9);
9124   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9125   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9126   if (__pyx_t_2) {
9127
9128     /* "csamtools.pyx":843
9129  * 
9130  *         if end != None:
9131  *             try:             # <<<<<<<<<<<<<<
9132  *                 rend = end
9133  *             except OverflowError:
9134  */
9135     {
9136       __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
9137       __Pyx_XGOTREF(__pyx_t_5);
9138       __Pyx_XGOTREF(__pyx_t_4);
9139       __Pyx_XGOTREF(__pyx_t_3);
9140       /*try:*/ {
9141
9142         /* "csamtools.pyx":844
9143  *         if end != None:
9144  *             try:
9145  *                 rend = end             # <<<<<<<<<<<<<<
9146  *             except OverflowError:
9147  *                 raise ValueError( 'end out of range (%i)' % end )
9148  */
9149         __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 = 844; __pyx_clineno = __LINE__; goto __pyx_L15_error;}
9150         __pyx_v_rend = __pyx_t_6;
9151       }
9152       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
9153       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
9154       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
9155       goto __pyx_L22_try_end;
9156       __pyx_L15_error:;
9157       __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
9158       __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
9159       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
9160       __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
9161       __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
9162
9163       /* "csamtools.pyx":845
9164  *             try:
9165  *                 rend = end
9166  *             except OverflowError:             # <<<<<<<<<<<<<<
9167  *                 raise ValueError( 'end out of range (%i)' % end )
9168  * 
9169  */
9170       __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
9171       if (__pyx_t_7) {
9172         __Pyx_AddTraceback("csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
9173         if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_8, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
9174         __Pyx_GOTREF(__pyx_t_9);
9175         __Pyx_GOTREF(__pyx_t_8);
9176         __Pyx_GOTREF(__pyx_t_1);
9177
9178         /* "csamtools.pyx":846
9179  *                 rend = end
9180  *             except OverflowError:
9181  *                 raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
9182  * 
9183  *         if region:
9184  */
9185         __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 = 846; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
9186         __Pyx_GOTREF(((PyObject *)__pyx_t_10));
9187         __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
9188         __Pyx_GOTREF(__pyx_t_11);
9189         PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_10));
9190         __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
9191         __pyx_t_10 = 0;
9192         __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 = 846; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
9193         __Pyx_GOTREF(__pyx_t_10);
9194         __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
9195         __Pyx_Raise(__pyx_t_10, 0, 0, 0);
9196         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
9197         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L17_except_error;}
9198         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9199         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
9200         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9201         goto __pyx_L16_exception_handled;
9202       }
9203       __pyx_L17_except_error:;
9204       __Pyx_XGIVEREF(__pyx_t_5);
9205       __Pyx_XGIVEREF(__pyx_t_4);
9206       __Pyx_XGIVEREF(__pyx_t_3);
9207       __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_4, __pyx_t_3);
9208       goto __pyx_L1_error;
9209       __pyx_L16_exception_handled:;
9210       __Pyx_XGIVEREF(__pyx_t_5);
9211       __Pyx_XGIVEREF(__pyx_t_4);
9212       __Pyx_XGIVEREF(__pyx_t_3);
9213       __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_4, __pyx_t_3);
9214       __pyx_L22_try_end:;
9215     }
9216     goto __pyx_L14;
9217   }
9218   __pyx_L14:;
9219
9220   /* "csamtools.pyx":848
9221  *                 raise ValueError( 'end out of range (%i)' % end )
9222  * 
9223  *         if region:             # <<<<<<<<<<<<<<
9224  *             region = _force_str(region)
9225  *             parts = re.split( "[:-]", region )
9226  */
9227   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9228   if (__pyx_t_2) {
9229
9230     /* "csamtools.pyx":849
9231  * 
9232  *         if region:
9233  *             region = _force_str(region)             # <<<<<<<<<<<<<<
9234  *             parts = re.split( "[:-]", region )
9235  *             reference = parts[0]
9236  */
9237     __pyx_t_1 = __pyx_f_9csamtools__force_str(__pyx_v_region); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9238     __Pyx_GOTREF(__pyx_t_1);
9239     __Pyx_DECREF(__pyx_v_region);
9240     __pyx_v_region = __pyx_t_1;
9241     __pyx_t_1 = 0;
9242
9243     /* "csamtools.pyx":850
9244  *         if region:
9245  *             region = _force_str(region)
9246  *             parts = re.split( "[:-]", region )             # <<<<<<<<<<<<<<
9247  *             reference = parts[0]
9248  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
9249  */
9250     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9251     __Pyx_GOTREF(__pyx_t_1);
9252     __pyx_t_8 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9253     __Pyx_GOTREF(__pyx_t_8);
9254     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9255     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9256     __Pyx_GOTREF(__pyx_t_1);
9257     __Pyx_INCREF(((PyObject *)__pyx_kp_s_43));
9258     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_43));
9259     __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43));
9260     __Pyx_INCREF(__pyx_v_region);
9261     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_region);
9262     __Pyx_GIVEREF(__pyx_v_region);
9263     __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 = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9264     __Pyx_GOTREF(__pyx_t_9);
9265     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
9266     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9267     __pyx_v_parts = __pyx_t_9;
9268     __pyx_t_9 = 0;
9269
9270     /* "csamtools.pyx":851
9271  *             region = _force_str(region)
9272  *             parts = re.split( "[:-]", region )
9273  *             reference = parts[0]             # <<<<<<<<<<<<<<
9274  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
9275  *             if len(parts) >= 3: rend = int(parts[2])
9276  */
9277     __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9278     __Pyx_GOTREF(__pyx_t_9);
9279     __Pyx_DECREF(__pyx_v_reference);
9280     __pyx_v_reference = __pyx_t_9;
9281     __pyx_t_9 = 0;
9282
9283     /* "csamtools.pyx":852
9284  *             parts = re.split( "[:-]", region )
9285  *             reference = parts[0]
9286  *             if len(parts) >= 2: rstart = int(parts[1]) - 1             # <<<<<<<<<<<<<<
9287  *             if len(parts) >= 3: rend = int(parts[2])
9288  * 
9289  */
9290     __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9291     __pyx_t_2 = (__pyx_t_12 >= 2);
9292     if (__pyx_t_2) {
9293       __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_parts, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9294       __Pyx_GOTREF(__pyx_t_9);
9295       __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9296       __Pyx_GOTREF(__pyx_t_1);
9297       PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9);
9298       __Pyx_GIVEREF(__pyx_t_9);
9299       __pyx_t_9 = 0;
9300       __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 = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9301       __Pyx_GOTREF(__pyx_t_9);
9302       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9303       __pyx_t_1 = PyNumber_Subtract(__pyx_t_9, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9304       __Pyx_GOTREF(__pyx_t_1);
9305       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9306       __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 = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9307       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9308       __pyx_v_rstart = __pyx_t_6;
9309       goto __pyx_L26;
9310     }
9311     __pyx_L26:;
9312
9313     /* "csamtools.pyx":853
9314  *             reference = parts[0]
9315  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
9316  *             if len(parts) >= 3: rend = int(parts[2])             # <<<<<<<<<<<<<<
9317  * 
9318  *         if not reference: return 0, 0, 0, 0
9319  */
9320     __pyx_t_12 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9321     __pyx_t_2 = (__pyx_t_12 >= 3);
9322     if (__pyx_t_2) {
9323       __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9324       __Pyx_GOTREF(__pyx_t_1);
9325       __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9326       __Pyx_GOTREF(__pyx_t_9);
9327       PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
9328       __Pyx_GIVEREF(__pyx_t_1);
9329       __pyx_t_1 = 0;
9330       __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 = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9331       __Pyx_GOTREF(__pyx_t_1);
9332       __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
9333       __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 = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9334       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9335       __pyx_v_rend = __pyx_t_6;
9336       goto __pyx_L27;
9337     }
9338     __pyx_L27:;
9339     goto __pyx_L25;
9340   }
9341   __pyx_L25:;
9342
9343   /* "csamtools.pyx":855
9344  *             if len(parts) >= 3: rend = int(parts[2])
9345  * 
9346  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
9347  * 
9348  *         rtid = self.gettid( reference )
9349  */
9350   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9351   __pyx_t_13 = (!__pyx_t_2);
9352   if (__pyx_t_13) {
9353     __Pyx_XDECREF(__pyx_r);
9354     __Pyx_INCREF(((PyObject *)__pyx_k_tuple_44));
9355     __pyx_r = ((PyObject *)__pyx_k_tuple_44);
9356     goto __pyx_L0;
9357     goto __pyx_L28;
9358   }
9359   __pyx_L28:;
9360
9361   /* "csamtools.pyx":857
9362  *         if not reference: return 0, 0, 0, 0
9363  * 
9364  *         rtid = self.gettid( reference )             # <<<<<<<<<<<<<<
9365  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
9366  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
9367  */
9368   __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 = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9369   __Pyx_GOTREF(__pyx_t_1);
9370   __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9371   __Pyx_GOTREF(__pyx_t_9);
9372   __Pyx_INCREF(__pyx_v_reference);
9373   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_reference);
9374   __Pyx_GIVEREF(__pyx_v_reference);
9375   __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 = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9376   __Pyx_GOTREF(__pyx_t_8);
9377   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9378   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
9379   __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 = 857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9380   __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
9381   __pyx_v_rtid = __pyx_t_7;
9382
9383   /* "csamtools.pyx":858
9384  * 
9385  *         rtid = self.gettid( reference )
9386  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )             # <<<<<<<<<<<<<<
9387  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
9388  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
9389  */
9390   __pyx_t_13 = (__pyx_v_rtid < 0);
9391   if (__pyx_t_13) {
9392     __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_45), __pyx_v_reference); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9393     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
9394     __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9395     __Pyx_GOTREF(__pyx_t_9);
9396     PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
9397     __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
9398     __pyx_t_8 = 0;
9399     __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 = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9400     __Pyx_GOTREF(__pyx_t_8);
9401     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
9402     __Pyx_Raise(__pyx_t_8, 0, 0, 0);
9403     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
9404     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9405     goto __pyx_L29;
9406   }
9407   __pyx_L29:;
9408
9409   /* "csamtools.pyx":859
9410  *         rtid = self.gettid( reference )
9411  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
9412  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )             # <<<<<<<<<<<<<<
9413  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
9414  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
9415  */
9416   __pyx_t_13 = (__pyx_v_rstart > __pyx_v_rend);
9417   if (__pyx_t_13) {
9418     __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9419     __Pyx_GOTREF(__pyx_t_8);
9420     __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9421     __Pyx_GOTREF(__pyx_t_9);
9422     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9423     __Pyx_GOTREF(__pyx_t_1);
9424     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
9425     __Pyx_GIVEREF(__pyx_t_8);
9426     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_9);
9427     __Pyx_GIVEREF(__pyx_t_9);
9428     __pyx_t_8 = 0;
9429     __pyx_t_9 = 0;
9430     __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9431     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
9432     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9433     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9434     __Pyx_GOTREF(__pyx_t_1);
9435     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9));
9436     __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
9437     __pyx_t_9 = 0;
9438     __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 = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9439     __Pyx_GOTREF(__pyx_t_9);
9440     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9441     __Pyx_Raise(__pyx_t_9, 0, 0, 0);
9442     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9443     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9444     goto __pyx_L30;
9445   }
9446   __pyx_L30:;
9447
9448   /* "csamtools.pyx":860
9449  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
9450  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
9451  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
9452  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
9453  * 
9454  */
9455   __pyx_t_13 = (0 <= __pyx_v_rstart);
9456   if (__pyx_t_13) {
9457     __pyx_t_13 = (__pyx_v_rstart < __pyx_v_9csamtools_max_pos);
9458   }
9459   __pyx_t_2 = (!__pyx_t_13);
9460   if (__pyx_t_2) {
9461     __pyx_t_9 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9462     __Pyx_GOTREF(__pyx_t_9);
9463     __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 = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9464     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
9465     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9466     __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9467     __Pyx_GOTREF(__pyx_t_9);
9468     PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_1));
9469     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
9470     __pyx_t_1 = 0;
9471     __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 = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9472     __Pyx_GOTREF(__pyx_t_1);
9473     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
9474     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
9475     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9476     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9477     goto __pyx_L31;
9478   }
9479   __pyx_L31:;
9480
9481   /* "csamtools.pyx":861
9482  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
9483  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
9484  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
9485  * 
9486  *         return 1, rtid, rstart, rend
9487  */
9488   __pyx_t_2 = (0 <= __pyx_v_rend);
9489   if (__pyx_t_2) {
9490     __pyx_t_2 = (__pyx_v_rend <= __pyx_v_9csamtools_max_pos);
9491   }
9492   __pyx_t_13 = (!__pyx_t_2);
9493   if (__pyx_t_13) {
9494     __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9495     __Pyx_GOTREF(__pyx_t_1);
9496     __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 = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9497     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
9498     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9499     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9500     __Pyx_GOTREF(__pyx_t_1);
9501     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9));
9502     __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
9503     __pyx_t_9 = 0;
9504     __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 = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9505     __Pyx_GOTREF(__pyx_t_9);
9506     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9507     __Pyx_Raise(__pyx_t_9, 0, 0, 0);
9508     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
9509     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9510     goto __pyx_L32;
9511   }
9512   __pyx_L32:;
9513
9514   /* "csamtools.pyx":863
9515  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
9516  * 
9517  *         return 1, rtid, rstart, rend             # <<<<<<<<<<<<<<
9518  * 
9519  *     def reset( self ):
9520  */
9521   __Pyx_XDECREF(__pyx_r);
9522   __pyx_t_9 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9523   __Pyx_GOTREF(__pyx_t_9);
9524   __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9525   __Pyx_GOTREF(__pyx_t_1);
9526   __pyx_t_8 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9527   __Pyx_GOTREF(__pyx_t_8);
9528   __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9529   __Pyx_GOTREF(__pyx_t_10);
9530   __Pyx_INCREF(__pyx_int_1);
9531   PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_int_1);
9532   __Pyx_GIVEREF(__pyx_int_1);
9533   PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_9);
9534   __Pyx_GIVEREF(__pyx_t_9);
9535   PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_1);
9536   __Pyx_GIVEREF(__pyx_t_1);
9537   PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_8);
9538   __Pyx_GIVEREF(__pyx_t_8);
9539   __pyx_t_9 = 0;
9540   __pyx_t_1 = 0;
9541   __pyx_t_8 = 0;
9542   __pyx_r = ((PyObject *)__pyx_t_10);
9543   __pyx_t_10 = 0;
9544   goto __pyx_L0;
9545
9546   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9547   goto __pyx_L0;
9548   __pyx_L1_error:;
9549   __Pyx_XDECREF(__pyx_t_1);
9550   __Pyx_XDECREF(__pyx_t_8);
9551   __Pyx_XDECREF(__pyx_t_9);
9552   __Pyx_XDECREF(__pyx_t_10);
9553   __Pyx_XDECREF(__pyx_t_11);
9554   __Pyx_AddTraceback("csamtools.Samfile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
9555   __pyx_r = NULL;
9556   __pyx_L0:;
9557   __Pyx_XDECREF(__pyx_v_parts);
9558   __Pyx_XDECREF(__pyx_v_reference);
9559   __Pyx_XDECREF(__pyx_v_region);
9560   __Pyx_XGIVEREF(__pyx_r);
9561   __Pyx_TraceReturn(__pyx_r);
9562   __Pyx_RefNannyFinishContext();
9563   return __pyx_r;
9564 }
9565
9566 /* Python wrapper */
9567 static PyObject *__pyx_pw_9csamtools_7Samfile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
9568 static char __pyx_doc_9csamtools_7Samfile_14reset[] = "Samfile.reset(self)\nreset file position to beginning of read section.";
9569 static PyObject *__pyx_pw_9csamtools_7Samfile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
9570   PyObject *__pyx_r = 0;
9571   __Pyx_RefNannyDeclarations
9572   __Pyx_RefNannySetupContext("reset (wrapper)", 0);
9573   __pyx_r = __pyx_pf_9csamtools_7Samfile_14reset(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
9574   __Pyx_RefNannyFinishContext();
9575   return __pyx_r;
9576 }
9577
9578 /* "csamtools.pyx":865
9579  *         return 1, rtid, rstart, rend
9580  * 
9581  *     def reset( self ):             # <<<<<<<<<<<<<<
9582  *         '''reset file position to beginning of read section.'''
9583  *         return self.seek( self.start_offset, 0 )
9584  */
9585
9586 static PyObject *__pyx_pf_9csamtools_7Samfile_14reset(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
9587   PyObject *__pyx_r = NULL;
9588   __Pyx_RefNannyDeclarations
9589   PyObject *__pyx_t_1 = NULL;
9590   PyObject *__pyx_t_2 = NULL;
9591   PyObject *__pyx_t_3 = NULL;
9592   int __pyx_lineno = 0;
9593   const char *__pyx_filename = NULL;
9594   int __pyx_clineno = 0;
9595   __Pyx_TraceDeclarations
9596   __Pyx_RefNannySetupContext("reset", 0);
9597   __Pyx_TraceCall("reset", __pyx_f[0], 865);
9598
9599   /* "csamtools.pyx":867
9600  *     def reset( self ):
9601  *         '''reset file position to beginning of read section.'''
9602  *         return self.seek( self.start_offset, 0 )             # <<<<<<<<<<<<<<
9603  * 
9604  *     def seek( self, uint64_t offset, int where = 0):
9605  */
9606   __Pyx_XDECREF(__pyx_r);
9607   __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 = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9608   __Pyx_GOTREF(__pyx_t_1);
9609   __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 = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9610   __Pyx_GOTREF(__pyx_t_2);
9611   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9612   __Pyx_GOTREF(__pyx_t_3);
9613   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
9614   __Pyx_GIVEREF(__pyx_t_2);
9615   __Pyx_INCREF(__pyx_int_0);
9616   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
9617   __Pyx_GIVEREF(__pyx_int_0);
9618   __pyx_t_2 = 0;
9619   __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 = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9620   __Pyx_GOTREF(__pyx_t_2);
9621   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9622   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
9623   __pyx_r = __pyx_t_2;
9624   __pyx_t_2 = 0;
9625   goto __pyx_L0;
9626
9627   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9628   goto __pyx_L0;
9629   __pyx_L1_error:;
9630   __Pyx_XDECREF(__pyx_t_1);
9631   __Pyx_XDECREF(__pyx_t_2);
9632   __Pyx_XDECREF(__pyx_t_3);
9633   __Pyx_AddTraceback("csamtools.Samfile.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
9634   __pyx_r = NULL;
9635   __pyx_L0:;
9636   __Pyx_XGIVEREF(__pyx_r);
9637   __Pyx_TraceReturn(__pyx_r);
9638   __Pyx_RefNannyFinishContext();
9639   return __pyx_r;
9640 }
9641
9642 /* Python wrapper */
9643 static PyObject *__pyx_pw_9csamtools_7Samfile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
9644 static char __pyx_doc_9csamtools_7Samfile_16seek[] = "Samfile.seek(self, uint64_t offset, int where=0)\n\n        move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.\n        ";
9645 static PyObject *__pyx_pw_9csamtools_7Samfile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
9646   uint64_t __pyx_v_offset;
9647   int __pyx_v_where;
9648   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__offset,&__pyx_n_s__where,0};
9649   PyObject *__pyx_r = 0;
9650   __Pyx_RefNannyDeclarations
9651   __Pyx_RefNannySetupContext("seek (wrapper)", 0);
9652   {
9653     PyObject* values[2] = {0,0};
9654     if (unlikely(__pyx_kwds)) {
9655       Py_ssize_t kw_args;
9656       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
9657       switch (pos_args) {
9658         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
9659         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
9660         case  0: break;
9661         default: goto __pyx_L5_argtuple_error;
9662       }
9663       kw_args = PyDict_Size(__pyx_kwds);
9664       switch (pos_args) {
9665         case  0:
9666         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset);
9667         if (likely(values[0])) kw_args--;
9668         else goto __pyx_L5_argtuple_error;
9669         case  1:
9670         if (kw_args > 0) {
9671           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__where);
9672           if (value) { values[1] = value; kw_args--; }
9673         }
9674       }
9675       if (unlikely(kw_args > 0)) {
9676         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9677       }
9678       if (values[1]) {
9679       } else {
9680         __pyx_v_where = ((int)0);
9681       }
9682     } else {
9683       switch (PyTuple_GET_SIZE(__pyx_args)) {
9684         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
9685         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
9686         break;
9687         default: goto __pyx_L5_argtuple_error;
9688       }
9689     }
9690     __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 = 869; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9691     if (values[1]) {
9692       __pyx_v_where = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9693     } else {
9694       __pyx_v_where = ((int)0);
9695     }
9696   }
9697   goto __pyx_L4_argument_unpacking_done;
9698   __pyx_L5_argtuple_error:;
9699   __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 869; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9700   __pyx_L3_error:;
9701   __Pyx_AddTraceback("csamtools.Samfile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
9702   __Pyx_RefNannyFinishContext();
9703   return NULL;
9704   __pyx_L4_argument_unpacking_done:;
9705   __pyx_r = __pyx_pf_9csamtools_7Samfile_16seek(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_offset, __pyx_v_where);
9706   __Pyx_RefNannyFinishContext();
9707   return __pyx_r;
9708 }
9709
9710 /* "csamtools.pyx":869
9711  *         return self.seek( self.start_offset, 0 )
9712  * 
9713  *     def seek( self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
9714  *         '''
9715  *         move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.
9716  */
9717
9718 static PyObject *__pyx_pf_9csamtools_7Samfile_16seek(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, uint64_t __pyx_v_offset, int __pyx_v_where) {
9719   PyObject *__pyx_r = NULL;
9720   __Pyx_RefNannyDeclarations
9721   PyObject *__pyx_t_1 = NULL;
9722   PyObject *__pyx_t_2 = NULL;
9723   int __pyx_t_3;
9724   int __pyx_t_4;
9725   int __pyx_lineno = 0;
9726   const char *__pyx_filename = NULL;
9727   int __pyx_clineno = 0;
9728   __Pyx_TraceDeclarations
9729   __Pyx_RefNannySetupContext("seek", 0);
9730   __Pyx_TraceCall("seek", __pyx_f[0], 869);
9731
9732   /* "csamtools.pyx":874
9733  *         '''
9734  * 
9735  *         if not self._isOpen():             # <<<<<<<<<<<<<<
9736  *             raise ValueError( "I/O operation on closed file" )
9737  *         if not self.isbam:
9738  */
9739   __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 = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9740   __Pyx_GOTREF(__pyx_t_1);
9741   __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 = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9742   __Pyx_GOTREF(__pyx_t_2);
9743   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9744   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9745   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9746   __pyx_t_4 = (!__pyx_t_3);
9747   if (__pyx_t_4) {
9748
9749     /* "csamtools.pyx":875
9750  * 
9751  *         if not self._isOpen():
9752  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
9753  *         if not self.isbam:
9754  *             raise NotImplementedError("seek only available in bam files")
9755  */
9756     __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 = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9757     __Pyx_GOTREF(__pyx_t_2);
9758     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
9759     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9760     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9761     goto __pyx_L3;
9762   }
9763   __pyx_L3:;
9764
9765   /* "csamtools.pyx":876
9766  *         if not self._isOpen():
9767  *             raise ValueError( "I/O operation on closed file" )
9768  *         if not self.isbam:             # <<<<<<<<<<<<<<
9769  *             raise NotImplementedError("seek only available in bam files")
9770  *         if self.isstream:
9771  */
9772   __pyx_t_4 = (!__pyx_v_self->isbam);
9773   if (__pyx_t_4) {
9774
9775     /* "csamtools.pyx":877
9776  *             raise ValueError( "I/O operation on closed file" )
9777  *         if not self.isbam:
9778  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
9779  *         if self.isstream:
9780  *             raise OSError("seek no available in streams")
9781  */
9782     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9783     __Pyx_GOTREF(__pyx_t_2);
9784     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
9785     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9786     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9787     goto __pyx_L4;
9788   }
9789   __pyx_L4:;
9790
9791   /* "csamtools.pyx":878
9792  *         if not self.isbam:
9793  *             raise NotImplementedError("seek only available in bam files")
9794  *         if self.isstream:             # <<<<<<<<<<<<<<
9795  *             raise OSError("seek no available in streams")
9796  * 
9797  */
9798   if (__pyx_v_self->isstream) {
9799
9800     /* "csamtools.pyx":879
9801  *             raise NotImplementedError("seek only available in bam files")
9802  *         if self.isstream:
9803  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
9804  * 
9805  *         return bam_seek( self.samfile.x.bam, offset, where )
9806  */
9807     __pyx_t_2 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9808     __Pyx_GOTREF(__pyx_t_2);
9809     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
9810     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9811     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9812     goto __pyx_L5;
9813   }
9814   __pyx_L5:;
9815
9816   /* "csamtools.pyx":881
9817  *             raise OSError("seek no available in streams")
9818  * 
9819  *         return bam_seek( self.samfile.x.bam, offset, where )             # <<<<<<<<<<<<<<
9820  * 
9821  *     def tell( self ):
9822  */
9823   __Pyx_XDECREF(__pyx_r);
9824   __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 = 881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9825   __Pyx_GOTREF(__pyx_t_2);
9826   __pyx_r = __pyx_t_2;
9827   __pyx_t_2 = 0;
9828   goto __pyx_L0;
9829
9830   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9831   goto __pyx_L0;
9832   __pyx_L1_error:;
9833   __Pyx_XDECREF(__pyx_t_1);
9834   __Pyx_XDECREF(__pyx_t_2);
9835   __Pyx_AddTraceback("csamtools.Samfile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
9836   __pyx_r = NULL;
9837   __pyx_L0:;
9838   __Pyx_XGIVEREF(__pyx_r);
9839   __Pyx_TraceReturn(__pyx_r);
9840   __Pyx_RefNannyFinishContext();
9841   return __pyx_r;
9842 }
9843
9844 /* Python wrapper */
9845 static PyObject *__pyx_pw_9csamtools_7Samfile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
9846 static char __pyx_doc_9csamtools_7Samfile_18tell[] = "Samfile.tell(self)\n\n        return current file position\n        ";
9847 static PyObject *__pyx_pw_9csamtools_7Samfile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
9848   PyObject *__pyx_r = 0;
9849   __Pyx_RefNannyDeclarations
9850   __Pyx_RefNannySetupContext("tell (wrapper)", 0);
9851   __pyx_r = __pyx_pf_9csamtools_7Samfile_18tell(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
9852   __Pyx_RefNannyFinishContext();
9853   return __pyx_r;
9854 }
9855
9856 /* "csamtools.pyx":883
9857  *         return bam_seek( self.samfile.x.bam, offset, where )
9858  * 
9859  *     def tell( self ):             # <<<<<<<<<<<<<<
9860  *         '''
9861  *         return current file position
9862  */
9863
9864 static PyObject *__pyx_pf_9csamtools_7Samfile_18tell(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
9865   PyObject *__pyx_r = NULL;
9866   __Pyx_RefNannyDeclarations
9867   PyObject *__pyx_t_1 = NULL;
9868   PyObject *__pyx_t_2 = NULL;
9869   int __pyx_t_3;
9870   int __pyx_t_4;
9871   int __pyx_lineno = 0;
9872   const char *__pyx_filename = NULL;
9873   int __pyx_clineno = 0;
9874   __Pyx_TraceDeclarations
9875   __Pyx_RefNannySetupContext("tell", 0);
9876   __Pyx_TraceCall("tell", __pyx_f[0], 883);
9877
9878   /* "csamtools.pyx":887
9879  *         return current file position
9880  *         '''
9881  *         if not self._isOpen():             # <<<<<<<<<<<<<<
9882  *             raise ValueError( "I/O operation on closed file" )
9883  *         if not self.isbam:
9884  */
9885   __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 = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9886   __Pyx_GOTREF(__pyx_t_1);
9887   __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 = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9888   __Pyx_GOTREF(__pyx_t_2);
9889   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9890   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9891   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9892   __pyx_t_4 = (!__pyx_t_3);
9893   if (__pyx_t_4) {
9894
9895     /* "csamtools.pyx":888
9896  *         '''
9897  *         if not self._isOpen():
9898  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
9899  *         if not self.isbam:
9900  *             raise NotImplementedError("seek only available in bam files")
9901  */
9902     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9903     __Pyx_GOTREF(__pyx_t_2);
9904     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
9905     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9906     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9907     goto __pyx_L3;
9908   }
9909   __pyx_L3:;
9910
9911   /* "csamtools.pyx":889
9912  *         if not self._isOpen():
9913  *             raise ValueError( "I/O operation on closed file" )
9914  *         if not self.isbam:             # <<<<<<<<<<<<<<
9915  *             raise NotImplementedError("seek only available in bam files")
9916  * 
9917  */
9918   __pyx_t_4 = (!__pyx_v_self->isbam);
9919   if (__pyx_t_4) {
9920
9921     /* "csamtools.pyx":890
9922  *             raise ValueError( "I/O operation on closed file" )
9923  *         if not self.isbam:
9924  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
9925  * 
9926  *         return bam_tell( self.samfile.x.bam )
9927  */
9928     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9929     __Pyx_GOTREF(__pyx_t_2);
9930     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
9931     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9932     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9933     goto __pyx_L4;
9934   }
9935   __pyx_L4:;
9936
9937   /* "csamtools.pyx":892
9938  *             raise NotImplementedError("seek only available in bam files")
9939  * 
9940  *         return bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
9941  * 
9942  *     def fetch( self,
9943  */
9944   __Pyx_XDECREF(__pyx_r);
9945   __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 = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9946   __Pyx_GOTREF(__pyx_t_2);
9947   __pyx_r = __pyx_t_2;
9948   __pyx_t_2 = 0;
9949   goto __pyx_L0;
9950
9951   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9952   goto __pyx_L0;
9953   __pyx_L1_error:;
9954   __Pyx_XDECREF(__pyx_t_1);
9955   __Pyx_XDECREF(__pyx_t_2);
9956   __Pyx_AddTraceback("csamtools.Samfile.tell", __pyx_clineno, __pyx_lineno, __pyx_filename);
9957   __pyx_r = NULL;
9958   __pyx_L0:;
9959   __Pyx_XGIVEREF(__pyx_r);
9960   __Pyx_TraceReturn(__pyx_r);
9961   __Pyx_RefNannyFinishContext();
9962   return __pyx_r;
9963 }
9964
9965 /* Python wrapper */
9966 static PyObject *__pyx_pw_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
9967 static char __pyx_doc_9csamtools_7Samfile_20fetch[] = "Samfile.fetch(self, reference=None, start=None, end=None, region=None, callback=None, until_eof=False)\n\n        fetch aligned reads 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\n        be supplied.\n\n        Without *reference* or *region* all mapped reads will be fetched. The reads will be returned\n        ordered by reference sequence, which will not necessarily be the order within the file.\n\n        If *until_eof* is given, all reads from the current file position will be returned\n        in order as they are within the file. Using this option will also fetch unmapped reads.\n\n        If only *reference* is set, all reads aligned to *reference* will be fetched.\n\n        The method returns an iterator of type :class:`pysam.IteratorRow` unless\n        a *callback is provided. If *callback* is given, the callback will be executed\n        for each position within the :term:`region`. Note that callbacks currently work\n        only, if *region* or *reference* is given.\n\n        Note that a :term:`SAM` file does not allow random access. If *region* or *reference* are given,\n        an exception is raised.\n        ";
9968 static PyObject *__pyx_pw_9csamtools_7Samfile_21fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
9969   PyObject *__pyx_v_reference = 0;
9970   PyObject *__pyx_v_start = 0;
9971   PyObject *__pyx_v_end = 0;
9972   PyObject *__pyx_v_region = 0;
9973   PyObject *__pyx_v_callback = 0;
9974   PyObject *__pyx_v_until_eof = 0;
9975   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};
9976   PyObject *__pyx_r = 0;
9977   __Pyx_RefNannyDeclarations
9978   __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
9979   {
9980     PyObject* values[6] = {0,0,0,0,0,0};
9981
9982     /* "csamtools.pyx":895
9983  * 
9984  *     def fetch( self,
9985  *                reference = None,             # <<<<<<<<<<<<<<
9986  *                start = None,
9987  *                end = None,
9988  */
9989     values[0] = ((PyObject *)Py_None);
9990
9991     /* "csamtools.pyx":896
9992  *     def fetch( self,
9993  *                reference = None,
9994  *                start = None,             # <<<<<<<<<<<<<<
9995  *                end = None,
9996  *                region = None,
9997  */
9998     values[1] = ((PyObject *)Py_None);
9999
10000     /* "csamtools.pyx":897
10001  *                reference = None,
10002  *                start = None,
10003  *                end = None,             # <<<<<<<<<<<<<<
10004  *                region = None,
10005  *                callback = None,
10006  */
10007     values[2] = ((PyObject *)Py_None);
10008
10009     /* "csamtools.pyx":898
10010  *                start = None,
10011  *                end = None,
10012  *                region = None,             # <<<<<<<<<<<<<<
10013  *                callback = None,
10014  *                until_eof = False ):
10015  */
10016     values[3] = ((PyObject *)Py_None);
10017
10018     /* "csamtools.pyx":899
10019  *                end = None,
10020  *                region = None,
10021  *                callback = None,             # <<<<<<<<<<<<<<
10022  *                until_eof = False ):
10023  *         '''
10024  */
10025     values[4] = ((PyObject *)Py_None);
10026     values[5] = __pyx_k_54;
10027     if (unlikely(__pyx_kwds)) {
10028       Py_ssize_t kw_args;
10029       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
10030       switch (pos_args) {
10031         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
10032         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
10033         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
10034         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
10035         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
10036         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
10037         case  0: break;
10038         default: goto __pyx_L5_argtuple_error;
10039       }
10040       kw_args = PyDict_Size(__pyx_kwds);
10041       switch (pos_args) {
10042         case  0:
10043         if (kw_args > 0) {
10044           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
10045           if (value) { values[0] = value; kw_args--; }
10046         }
10047         case  1:
10048         if (kw_args > 0) {
10049           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
10050           if (value) { values[1] = value; kw_args--; }
10051         }
10052         case  2:
10053         if (kw_args > 0) {
10054           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
10055           if (value) { values[2] = value; kw_args--; }
10056         }
10057         case  3:
10058         if (kw_args > 0) {
10059           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
10060           if (value) { values[3] = value; kw_args--; }
10061         }
10062         case  4:
10063         if (kw_args > 0) {
10064           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
10065           if (value) { values[4] = value; kw_args--; }
10066         }
10067         case  5:
10068         if (kw_args > 0) {
10069           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__until_eof);
10070           if (value) { values[5] = value; kw_args--; }
10071         }
10072       }
10073       if (unlikely(kw_args > 0)) {
10074         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10075       }
10076     } else {
10077       switch (PyTuple_GET_SIZE(__pyx_args)) {
10078         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
10079         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
10080         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
10081         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
10082         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
10083         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
10084         case  0: break;
10085         default: goto __pyx_L5_argtuple_error;
10086       }
10087     }
10088     __pyx_v_reference = values[0];
10089     __pyx_v_start = values[1];
10090     __pyx_v_end = values[2];
10091     __pyx_v_region = values[3];
10092     __pyx_v_callback = values[4];
10093     __pyx_v_until_eof = values[5];
10094   }
10095   goto __pyx_L4_argument_unpacking_done;
10096   __pyx_L5_argtuple_error:;
10097   __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 894; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10098   __pyx_L3_error:;
10099   __Pyx_AddTraceback("csamtools.Samfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
10100   __Pyx_RefNannyFinishContext();
10101   return NULL;
10102   __pyx_L4_argument_unpacking_done:;
10103   __pyx_r = __pyx_pf_9csamtools_7Samfile_20fetch(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_callback, __pyx_v_until_eof);
10104   __Pyx_RefNannyFinishContext();
10105   return __pyx_r;
10106 }
10107
10108 /* "csamtools.pyx":894
10109  *         return bam_tell( self.samfile.x.bam )
10110  * 
10111  *     def fetch( self,             # <<<<<<<<<<<<<<
10112  *                reference = None,
10113  *                start = None,
10114  */
10115
10116 static PyObject *__pyx_pf_9csamtools_7Samfile_20fetch(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof) {
10117   int __pyx_v_rtid;
10118   int __pyx_v_rstart;
10119   int __pyx_v_rend;
10120   int __pyx_v_has_coord;
10121   int __pyx_v_reopen;
10122   PyObject *__pyx_r = NULL;
10123   __Pyx_RefNannyDeclarations
10124   PyObject *__pyx_t_1 = NULL;
10125   PyObject *__pyx_t_2 = NULL;
10126   int __pyx_t_3;
10127   int __pyx_t_4;
10128   PyObject *__pyx_t_5 = NULL;
10129   PyObject *__pyx_t_6 = NULL;
10130   PyObject *__pyx_t_7 = NULL;
10131   PyObject *__pyx_t_8 = NULL;
10132   PyObject *(*__pyx_t_9)(PyObject *);
10133   int __pyx_t_10;
10134   int __pyx_t_11;
10135   int __pyx_t_12;
10136   int __pyx_t_13;
10137   int __pyx_t_14;
10138   int __pyx_t_15;
10139   int __pyx_lineno = 0;
10140   const char *__pyx_filename = NULL;
10141   int __pyx_clineno = 0;
10142   __Pyx_TraceDeclarations
10143   __Pyx_RefNannySetupContext("fetch", 0);
10144   __Pyx_TraceCall("fetch", __pyx_f[0], 894);
10145
10146   /* "csamtools.pyx":924
10147  *         cdef int rtid, rstart, rend, has_coord
10148  * 
10149  *         if not self._isOpen():             # <<<<<<<<<<<<<<
10150  *             raise ValueError( "I/O operation on closed file" )
10151  * 
10152  */
10153   __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;}
10154   __Pyx_GOTREF(__pyx_t_1);
10155   __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;}
10156   __Pyx_GOTREF(__pyx_t_2);
10157   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10158   __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;}
10159   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10160   __pyx_t_4 = (!__pyx_t_3);
10161   if (__pyx_t_4) {
10162
10163     /* "csamtools.pyx":925
10164  * 
10165  *         if not self._isOpen():
10166  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10167  * 
10168  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
10169  */
10170     __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 = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10171     __Pyx_GOTREF(__pyx_t_2);
10172     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
10173     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10174     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10175     goto __pyx_L3;
10176   }
10177   __pyx_L3:;
10178
10179   /* "csamtools.pyx":927
10180  *             raise ValueError( "I/O operation on closed file" )
10181  * 
10182  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
10183  * 
10184  *         if self.isstream: reopen = False
10185  */
10186   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10187   __Pyx_GOTREF(__pyx_t_2);
10188   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10189   __Pyx_GOTREF(__pyx_t_1);
10190   __Pyx_INCREF(__pyx_v_reference);
10191   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
10192   __Pyx_GIVEREF(__pyx_v_reference);
10193   __Pyx_INCREF(__pyx_v_start);
10194   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
10195   __Pyx_GIVEREF(__pyx_v_start);
10196   __Pyx_INCREF(__pyx_v_end);
10197   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
10198   __Pyx_GIVEREF(__pyx_v_end);
10199   __Pyx_INCREF(__pyx_v_region);
10200   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
10201   __Pyx_GIVEREF(__pyx_v_region);
10202   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10203   __Pyx_GOTREF(__pyx_t_5);
10204   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10205   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
10206   if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
10207     PyObject* sequence = __pyx_t_5;
10208     if (likely(PyTuple_CheckExact(sequence))) {
10209       if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) {
10210         if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
10211         else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
10212         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10213       }
10214       __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
10215       __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
10216       __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
10217       __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
10218     } else {
10219       if (unlikely(PyList_GET_SIZE(sequence) != 4)) {
10220         if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
10221         else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
10222         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10223       }
10224       __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
10225       __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
10226       __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
10227       __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
10228     }
10229     __Pyx_INCREF(__pyx_t_1);
10230     __Pyx_INCREF(__pyx_t_2);
10231     __Pyx_INCREF(__pyx_t_6);
10232     __Pyx_INCREF(__pyx_t_7);
10233     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
10234   } else {
10235     Py_ssize_t index = -1;
10236     __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10237     __Pyx_GOTREF(__pyx_t_8);
10238     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
10239     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
10240     index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
10241     __Pyx_GOTREF(__pyx_t_1);
10242     index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
10243     __Pyx_GOTREF(__pyx_t_2);
10244     index = 2; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
10245     __Pyx_GOTREF(__pyx_t_6);
10246     index = 3; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed;
10247     __Pyx_GOTREF(__pyx_t_7);
10248     if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10249     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
10250     goto __pyx_L5_unpacking_done;
10251     __pyx_L4_unpacking_failed:;
10252     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
10253     if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
10254     if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
10255     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10256     __pyx_L5_unpacking_done:;
10257   }
10258   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10259   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10260   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10261   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10262   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10263   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10264   __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 = 927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10265   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10266   __pyx_v_has_coord = __pyx_t_10;
10267   __pyx_v_rtid = __pyx_t_11;
10268   __pyx_v_rstart = __pyx_t_12;
10269   __pyx_v_rend = __pyx_t_13;
10270
10271   /* "csamtools.pyx":929
10272  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
10273  * 
10274  *         if self.isstream: reopen = False             # <<<<<<<<<<<<<<
10275  *         else: reopen = True
10276  * 
10277  */
10278   if (__pyx_v_self->isstream) {
10279     __pyx_v_reopen = 0;
10280     goto __pyx_L6;
10281   }
10282   /*else*/ {
10283
10284     /* "csamtools.pyx":930
10285  * 
10286  *         if self.isstream: reopen = False
10287  *         else: reopen = True             # <<<<<<<<<<<<<<
10288  * 
10289  *         if self.isbam:
10290  */
10291     __pyx_v_reopen = 1;
10292   }
10293   __pyx_L6:;
10294
10295   /* "csamtools.pyx":932
10296  *         else: reopen = True
10297  * 
10298  *         if self.isbam:             # <<<<<<<<<<<<<<
10299  *             if not until_eof and not self._hasIndex() and not self.isremote:
10300  *                 raise ValueError( "fetch called on bamfile without index" )
10301  */
10302   if (__pyx_v_self->isbam) {
10303
10304     /* "csamtools.pyx":933
10305  * 
10306  *         if self.isbam:
10307  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
10308  *                 raise ValueError( "fetch called on bamfile without index" )
10309  * 
10310  */
10311     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10312     __pyx_t_3 = (!__pyx_t_4);
10313     if (__pyx_t_3) {
10314       __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 = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10315       __Pyx_GOTREF(__pyx_t_5);
10316       __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 = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10317       __Pyx_GOTREF(__pyx_t_7);
10318       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
10319       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10320       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10321       __pyx_t_14 = (!__pyx_t_4);
10322       if (__pyx_t_14) {
10323         __pyx_t_4 = (!__pyx_v_self->isremote);
10324         __pyx_t_15 = __pyx_t_4;
10325       } else {
10326         __pyx_t_15 = __pyx_t_14;
10327       }
10328       __pyx_t_14 = __pyx_t_15;
10329     } else {
10330       __pyx_t_14 = __pyx_t_3;
10331     }
10332     if (__pyx_t_14) {
10333
10334       /* "csamtools.pyx":934
10335  *         if self.isbam:
10336  *             if not until_eof and not self._hasIndex() and not self.isremote:
10337  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
10338  * 
10339  *             if callback:
10340  */
10341       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10342       __Pyx_GOTREF(__pyx_t_7);
10343       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
10344       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10345       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10346       goto __pyx_L8;
10347     }
10348     __pyx_L8:;
10349
10350     /* "csamtools.pyx":936
10351  *                 raise ValueError( "fetch called on bamfile without index" )
10352  * 
10353  *             if callback:             # <<<<<<<<<<<<<<
10354  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
10355  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
10356  */
10357     __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10358     if (__pyx_t_14) {
10359
10360       /* "csamtools.pyx":937
10361  * 
10362  *             if callback:
10363  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
10364  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
10365  *                 return bam_fetch(self.samfile.x.bam,
10366  */
10367       __pyx_t_14 = (!__pyx_v_has_coord);
10368       if (__pyx_t_14) {
10369         __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10370         __Pyx_GOTREF(__pyx_t_7);
10371         __Pyx_Raise(__pyx_t_7, 0, 0, 0);
10372         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10373         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10374         goto __pyx_L10;
10375       }
10376       __pyx_L10:;
10377
10378       /* "csamtools.pyx":938
10379  *             if callback:
10380  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
10381  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
10382  *                 return bam_fetch(self.samfile.x.bam,
10383  *                                  self.index,
10384  */
10385       __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 = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10386       __Pyx_GOTREF(__pyx_t_7);
10387       __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 = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10388       __Pyx_GOTREF(__pyx_t_5);
10389       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10390       __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10391       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
10392       __pyx_t_3 = (!__pyx_t_14);
10393       if (__pyx_t_3) {
10394         __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10395         __Pyx_GOTREF(__pyx_t_5);
10396         __Pyx_Raise(__pyx_t_5, 0, 0, 0);
10397         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
10398         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10399         goto __pyx_L11;
10400       }
10401       __pyx_L11:;
10402
10403       /* "csamtools.pyx":939
10404  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
10405  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
10406  *                 return bam_fetch(self.samfile.x.bam,             # <<<<<<<<<<<<<<
10407  *                                  self.index,
10408  *                                  rtid,
10409  */
10410       __Pyx_XDECREF(__pyx_r);
10411
10412       /* "csamtools.pyx":945
10413  *                                  rend,
10414  *                                  <void*>callback,
10415  *                                  fetch_callback )             # <<<<<<<<<<<<<<
10416  *             else:
10417  *                 if has_coord:
10418  */
10419       __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_9csamtools_fetch_callback)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10420       __Pyx_GOTREF(__pyx_t_5);
10421       __pyx_r = __pyx_t_5;
10422       __pyx_t_5 = 0;
10423       goto __pyx_L0;
10424       goto __pyx_L9;
10425     }
10426     /*else*/ {
10427
10428       /* "csamtools.pyx":947
10429  *                                  fetch_callback )
10430  *             else:
10431  *                 if has_coord:             # <<<<<<<<<<<<<<
10432  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )
10433  *                 else:
10434  */
10435       if (__pyx_v_has_coord) {
10436
10437         /* "csamtools.pyx":948
10438  *             else:
10439  *                 if has_coord:
10440  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )             # <<<<<<<<<<<<<<
10441  *                 else:
10442  *                     if until_eof:
10443  */
10444         __Pyx_XDECREF(__pyx_r);
10445         __pyx_t_5 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10446         __Pyx_GOTREF(__pyx_t_5);
10447         __pyx_t_7 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10448         __Pyx_GOTREF(__pyx_t_7);
10449         __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10450         __Pyx_GOTREF(__pyx_t_6);
10451         __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10452         __Pyx_GOTREF(__pyx_t_2);
10453         __Pyx_INCREF(((PyObject *)__pyx_v_self));
10454         PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
10455         __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
10456         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
10457         __Pyx_GIVEREF(__pyx_t_5);
10458         PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_7);
10459         __Pyx_GIVEREF(__pyx_t_7);
10460         PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_6);
10461         __Pyx_GIVEREF(__pyx_t_6);
10462         __pyx_t_5 = 0;
10463         __pyx_t_7 = 0;
10464         __pyx_t_6 = 0;
10465         __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10466         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
10467         __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10468         __Pyx_GOTREF(__pyx_t_7);
10469         if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10470         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10471         __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10472         __Pyx_GOTREF(__pyx_t_7);
10473         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10474         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
10475         __pyx_r = __pyx_t_7;
10476         __pyx_t_7 = 0;
10477         goto __pyx_L0;
10478         goto __pyx_L12;
10479       }
10480       /*else*/ {
10481
10482         /* "csamtools.pyx":950
10483  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )
10484  *                 else:
10485  *                     if until_eof:             # <<<<<<<<<<<<<<
10486  *                         return IteratorRowAll( self, reopen=reopen )
10487  *                     else:
10488  */
10489         __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10490         if (__pyx_t_3) {
10491
10492           /* "csamtools.pyx":951
10493  *                 else:
10494  *                     if until_eof:
10495  *                         return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
10496  *                     else:
10497  *                         # AH: check - reason why no reopen for AllRefs?
10498  */
10499           __Pyx_XDECREF(__pyx_r);
10500           __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10501           __Pyx_GOTREF(__pyx_t_7);
10502           __Pyx_INCREF(((PyObject *)__pyx_v_self));
10503           PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
10504           __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
10505           __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10506           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
10507           __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10508           __Pyx_GOTREF(__pyx_t_2);
10509           if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10510           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10511           __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10512           __Pyx_GOTREF(__pyx_t_2);
10513           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
10514           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
10515           __pyx_r = __pyx_t_2;
10516           __pyx_t_2 = 0;
10517           goto __pyx_L0;
10518           goto __pyx_L13;
10519         }
10520         /*else*/ {
10521
10522           /* "csamtools.pyx":954
10523  *                     else:
10524  *                         # AH: check - reason why no reopen for AllRefs?
10525  *                         return IteratorRowAllRefs(self ) # , reopen=reopen )             # <<<<<<<<<<<<<<
10526  *         else:
10527  *             if has_coord:
10528  */
10529           __Pyx_XDECREF(__pyx_r);
10530           __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10531           __Pyx_GOTREF(__pyx_t_2);
10532           __Pyx_INCREF(((PyObject *)__pyx_v_self));
10533           PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
10534           __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
10535           __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowAllRefs)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10536           __Pyx_GOTREF(__pyx_t_6);
10537           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10538           __pyx_r = __pyx_t_6;
10539           __pyx_t_6 = 0;
10540           goto __pyx_L0;
10541         }
10542         __pyx_L13:;
10543       }
10544       __pyx_L12:;
10545     }
10546     __pyx_L9:;
10547     goto __pyx_L7;
10548   }
10549   /*else*/ {
10550
10551     /* "csamtools.pyx":956
10552  *                         return IteratorRowAllRefs(self ) # , reopen=reopen )
10553  *         else:
10554  *             if has_coord:             # <<<<<<<<<<<<<<
10555  *                 raise ValueError ("fetching by region is not available for sam files" )
10556  * 
10557  */
10558     if (__pyx_v_has_coord) {
10559
10560       /* "csamtools.pyx":957
10561  *         else:
10562  *             if has_coord:
10563  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
10564  * 
10565  *             if callback:
10566  */
10567       __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10568       __Pyx_GOTREF(__pyx_t_6);
10569       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
10570       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10571       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10572       goto __pyx_L14;
10573     }
10574     __pyx_L14:;
10575
10576     /* "csamtools.pyx":959
10577  *                 raise ValueError ("fetching by region is not available for sam files" )
10578  * 
10579  *             if callback:             # <<<<<<<<<<<<<<
10580  *                 raise NotImplementedError( "callback not implemented yet" )
10581  * 
10582  */
10583     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10584     if (__pyx_t_3) {
10585
10586       /* "csamtools.pyx":960
10587  * 
10588  *             if callback:
10589  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
10590  * 
10591  *             if self.samfile.header == NULL:
10592  */
10593       __pyx_t_6 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_65), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10594       __Pyx_GOTREF(__pyx_t_6);
10595       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
10596       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10597       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10598       goto __pyx_L15;
10599     }
10600     __pyx_L15:;
10601
10602     /* "csamtools.pyx":962
10603  *                 raise NotImplementedError( "callback not implemented yet" )
10604  * 
10605  *             if self.samfile.header == NULL:             # <<<<<<<<<<<<<<
10606  *                 raise ValueError( "fetch called for samfile without header")
10607  * 
10608  */
10609     __pyx_t_3 = (__pyx_v_self->samfile->header == NULL);
10610     if (__pyx_t_3) {
10611
10612       /* "csamtools.pyx":963
10613  * 
10614  *             if self.samfile.header == NULL:
10615  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
10616  * 
10617  *             # check if targets are defined
10618  */
10619       __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10620       __Pyx_GOTREF(__pyx_t_6);
10621       __Pyx_Raise(__pyx_t_6, 0, 0, 0);
10622       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10623       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10624       goto __pyx_L16;
10625     }
10626     __pyx_L16:;
10627
10628     /* "csamtools.pyx":967
10629  *             # check if targets are defined
10630  *             # give warning, sam_read1 segfaults
10631  *             if self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
10632  *                 warnings.warn( "fetch called for samfile without header")
10633  * 
10634  */
10635     __pyx_t_3 = (__pyx_v_self->samfile->header->n_targets == 0);
10636     if (__pyx_t_3) {
10637
10638       /* "csamtools.pyx":968
10639  *             # give warning, sam_read1 segfaults
10640  *             if self.samfile.header.n_targets == 0:
10641  *                 warnings.warn( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
10642  * 
10643  *             return IteratorRowAll( self, reopen=reopen )
10644  */
10645       __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__warnings); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10646       __Pyx_GOTREF(__pyx_t_6);
10647       __pyx_t_2 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__warn); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10648       __Pyx_GOTREF(__pyx_t_2);
10649       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10650       __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_68), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10651       __Pyx_GOTREF(__pyx_t_6);
10652       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10653       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
10654       goto __pyx_L17;
10655     }
10656     __pyx_L17:;
10657
10658     /* "csamtools.pyx":970
10659  *                 warnings.warn( "fetch called for samfile without header")
10660  * 
10661  *             return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
10662  * 
10663  *     def mate( self,
10664  */
10665     __Pyx_XDECREF(__pyx_r);
10666     __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10667     __Pyx_GOTREF(__pyx_t_6);
10668     __Pyx_INCREF(((PyObject *)__pyx_v_self));
10669     PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
10670     __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
10671     __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10672     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10673     __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10674     __Pyx_GOTREF(__pyx_t_7);
10675     if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10676     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
10677     __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowAll)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10678     __Pyx_GOTREF(__pyx_t_7);
10679     __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
10680     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10681     __pyx_r = __pyx_t_7;
10682     __pyx_t_7 = 0;
10683     goto __pyx_L0;
10684   }
10685   __pyx_L7:;
10686
10687   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10688   goto __pyx_L0;
10689   __pyx_L1_error:;
10690   __Pyx_XDECREF(__pyx_t_1);
10691   __Pyx_XDECREF(__pyx_t_2);
10692   __Pyx_XDECREF(__pyx_t_5);
10693   __Pyx_XDECREF(__pyx_t_6);
10694   __Pyx_XDECREF(__pyx_t_7);
10695   __Pyx_XDECREF(__pyx_t_8);
10696   __Pyx_AddTraceback("csamtools.Samfile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
10697   __pyx_r = NULL;
10698   __pyx_L0:;
10699   __Pyx_XGIVEREF(__pyx_r);
10700   __Pyx_TraceReturn(__pyx_r);
10701   __Pyx_RefNannyFinishContext();
10702   return __pyx_r;
10703 }
10704
10705 /* Python wrapper */
10706 static PyObject *__pyx_pw_9csamtools_7Samfile_23mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
10707 static char __pyx_doc_9csamtools_7Samfile_22mate[] = "Samfile.mate(self, AlignedRead read)\nreturn the mate of :class:`AlignedRead` *read*.\n\n        Throws a ValueError if read is unpaired or the mate\n        is unmapped.\n\n        .. note::\n            Calling this method will change the file position.\n            This might interfere with any iterators that have\n            not re-opened the file.\n\n        ";
10708 static PyObject *__pyx_pw_9csamtools_7Samfile_23mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
10709   PyObject *__pyx_r = 0;
10710   __Pyx_RefNannyDeclarations
10711   __Pyx_RefNannySetupContext("mate (wrapper)", 0);
10712   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10713   __pyx_r = __pyx_pf_9csamtools_7Samfile_22mate(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read));
10714   goto __pyx_L0;
10715   __pyx_L1_error:;
10716   __pyx_r = NULL;
10717   __pyx_L0:;
10718   __Pyx_RefNannyFinishContext();
10719   return __pyx_r;
10720 }
10721
10722 /* "csamtools.pyx":972
10723  *             return IteratorRowAll( self, reopen=reopen )
10724  * 
10725  *     def mate( self,             # <<<<<<<<<<<<<<
10726  *               AlignedRead read ):
10727  *         '''return the mate of :class:`AlignedRead` *read*.
10728  */
10729
10730 static PyObject *__pyx_pf_9csamtools_7Samfile_22mate(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_read) {
10731   uint32_t __pyx_v_flag;
10732   __pyx_t_9csamtools_MateData __pyx_v_mate_data;
10733   int __pyx_v_x;
10734   struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_dest = 0;
10735   PyObject *__pyx_r = NULL;
10736   __Pyx_RefNannyDeclarations
10737   int __pyx_t_1;
10738   PyObject *__pyx_t_2 = NULL;
10739   PyObject *__pyx_t_3 = NULL;
10740   int __pyx_lineno = 0;
10741   const char *__pyx_filename = NULL;
10742   int __pyx_clineno = 0;
10743   __Pyx_TraceDeclarations
10744   __Pyx_RefNannySetupContext("mate", 0);
10745   __Pyx_TraceCall("mate", __pyx_f[0], 972);
10746
10747   /* "csamtools.pyx":985
10748  * 
10749  *         '''
10750  *         cdef uint32_t flag = read._delegate.core.flag             # <<<<<<<<<<<<<<
10751  * 
10752  *         if flag & BAM_FPAIRED == 0:
10753  */
10754   __pyx_v_flag = __pyx_v_read->_delegate->core.flag;
10755
10756   /* "csamtools.pyx":987
10757  *         cdef uint32_t flag = read._delegate.core.flag
10758  * 
10759  *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
10760  *             raise ValueError( "read %s: is unpaired" % (read.qname))
10761  *         if flag & BAM_FMUNMAP != 0:
10762  */
10763   __pyx_t_1 = ((__pyx_v_flag & 1) == 0);
10764   if (__pyx_t_1) {
10765
10766     /* "csamtools.pyx":988
10767  * 
10768  *         if flag & BAM_FPAIRED == 0:
10769  *             raise ValueError( "read %s: is unpaired" % (read.qname))             # <<<<<<<<<<<<<<
10770  *         if flag & BAM_FMUNMAP != 0:
10771  *             raise ValueError( "mate %s: is unmapped" % (read.qname))
10772  */
10773     __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_read), __pyx_n_s__qname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10774     __Pyx_GOTREF(__pyx_t_2);
10775     __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_69), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10776     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
10777     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10778     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10779     __Pyx_GOTREF(__pyx_t_2);
10780     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
10781     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
10782     __pyx_t_3 = 0;
10783     __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10784     __Pyx_GOTREF(__pyx_t_3);
10785     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10786     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
10787     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
10788     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10789     goto __pyx_L3;
10790   }
10791   __pyx_L3:;
10792
10793   /* "csamtools.pyx":989
10794  *         if flag & BAM_FPAIRED == 0:
10795  *             raise ValueError( "read %s: is unpaired" % (read.qname))
10796  *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
10797  *             raise ValueError( "mate %s: is unmapped" % (read.qname))
10798  * 
10799  */
10800   __pyx_t_1 = ((__pyx_v_flag & 8) != 0);
10801   if (__pyx_t_1) {
10802
10803     /* "csamtools.pyx":990
10804  *             raise ValueError( "read %s: is unpaired" % (read.qname))
10805  *         if flag & BAM_FMUNMAP != 0:
10806  *             raise ValueError( "mate %s: is unmapped" % (read.qname))             # <<<<<<<<<<<<<<
10807  * 
10808  *         cdef MateData mate_data
10809  */
10810     __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 = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10811     __Pyx_GOTREF(__pyx_t_3);
10812     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_70), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10813     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10814     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
10815     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10816     __Pyx_GOTREF(__pyx_t_3);
10817     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
10818     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
10819     __pyx_t_2 = 0;
10820     __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 = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10821     __Pyx_GOTREF(__pyx_t_2);
10822     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
10823     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
10824     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10825     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10826     goto __pyx_L4;
10827   }
10828   __pyx_L4:;
10829
10830   /* "csamtools.pyx":994
10831  *         cdef MateData mate_data
10832  * 
10833  *         mate_data.name = <char *>bam1_qname(read._delegate)             # <<<<<<<<<<<<<<
10834  *         mate_data.mate = NULL
10835  *         # xor flags to get the other mate
10836  */
10837   __pyx_v_mate_data.name = ((char *)bam1_qname(__pyx_v_read->_delegate));
10838
10839   /* "csamtools.pyx":995
10840  * 
10841  *         mate_data.name = <char *>bam1_qname(read._delegate)
10842  *         mate_data.mate = NULL             # <<<<<<<<<<<<<<
10843  *         # xor flags to get the other mate
10844  *         cdef int x = BAM_FREAD1 + BAM_FREAD2
10845  */
10846   __pyx_v_mate_data.mate = NULL;
10847
10848   /* "csamtools.pyx":997
10849  *         mate_data.mate = NULL
10850  *         # xor flags to get the other mate
10851  *         cdef int x = BAM_FREAD1 + BAM_FREAD2             # <<<<<<<<<<<<<<
10852  *         mate_data.flag = ( flag ^ x) & x
10853  * 
10854  */
10855   __pyx_v_x = 192;
10856
10857   /* "csamtools.pyx":998
10858  *         # xor flags to get the other mate
10859  *         cdef int x = BAM_FREAD1 + BAM_FREAD2
10860  *         mate_data.flag = ( flag ^ x) & x             # <<<<<<<<<<<<<<
10861  * 
10862  *         bam_fetch(self.samfile.x.bam,
10863  */
10864   __pyx_v_mate_data.flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);
10865
10866   /* "csamtools.pyx":1006
10867  *                   read._delegate.core.mpos + 1,
10868  *                   <void*>&mate_data,
10869  *                   mate_callback )             # <<<<<<<<<<<<<<
10870  * 
10871  *         if mate_data.mate == NULL:
10872  */
10873   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_9csamtools_mate_callback);
10874
10875   /* "csamtools.pyx":1008
10876  *                   mate_callback )
10877  * 
10878  *         if mate_data.mate == NULL:             # <<<<<<<<<<<<<<
10879  *             raise ValueError( "mate not found" )
10880  * 
10881  */
10882   __pyx_t_1 = (__pyx_v_mate_data.mate == NULL);
10883   if (__pyx_t_1) {
10884
10885     /* "csamtools.pyx":1009
10886  * 
10887  *         if mate_data.mate == NULL:
10888  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
10889  * 
10890  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
10891  */
10892     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_72), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10893     __Pyx_GOTREF(__pyx_t_2);
10894     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
10895     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10896     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10897     goto __pyx_L5;
10898   }
10899   __pyx_L5:;
10900
10901   /* "csamtools.pyx":1011
10902  *             raise ValueError( "mate not found" )
10903  * 
10904  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
10905  *         dest._delegate = mate_data.mate
10906  *         return dest
10907  */
10908   __pyx_t_2 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10909   __Pyx_GOTREF(__pyx_t_2);
10910   if (!(likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10911   __pyx_v_dest = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_2);
10912   __pyx_t_2 = 0;
10913
10914   /* "csamtools.pyx":1012
10915  * 
10916  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
10917  *         dest._delegate = mate_data.mate             # <<<<<<<<<<<<<<
10918  *         return dest
10919  * 
10920  */
10921   __pyx_v_dest->_delegate = __pyx_v_mate_data.mate;
10922
10923   /* "csamtools.pyx":1013
10924  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
10925  *         dest._delegate = mate_data.mate
10926  *         return dest             # <<<<<<<<<<<<<<
10927  * 
10928  *     def count( self,
10929  */
10930   __Pyx_XDECREF(__pyx_r);
10931   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
10932   __pyx_r = ((PyObject *)__pyx_v_dest);
10933   goto __pyx_L0;
10934
10935   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10936   goto __pyx_L0;
10937   __pyx_L1_error:;
10938   __Pyx_XDECREF(__pyx_t_2);
10939   __Pyx_XDECREF(__pyx_t_3);
10940   __Pyx_AddTraceback("csamtools.Samfile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename);
10941   __pyx_r = NULL;
10942   __pyx_L0:;
10943   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
10944   __Pyx_XGIVEREF(__pyx_r);
10945   __Pyx_TraceReturn(__pyx_r);
10946   __Pyx_RefNannyFinishContext();
10947   return __pyx_r;
10948 }
10949
10950 /* Python wrapper */
10951 static PyObject *__pyx_pw_9csamtools_7Samfile_25count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
10952 static char __pyx_doc_9csamtools_7Samfile_24count[] = "Samfile.count(self, reference=None, start=None, end=None, region=None, until_eof=False)\n*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*\n\n        count  reads :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        Note that a :term:`TAM` file does not allow random access. If *region* or *reference* are given,\n        an exception is raised.\n        ";
10953 static PyObject *__pyx_pw_9csamtools_7Samfile_25count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
10954   PyObject *__pyx_v_reference = 0;
10955   PyObject *__pyx_v_start = 0;
10956   PyObject *__pyx_v_end = 0;
10957   PyObject *__pyx_v_region = 0;
10958   PyObject *__pyx_v_until_eof = 0;
10959   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};
10960   PyObject *__pyx_r = 0;
10961   __Pyx_RefNannyDeclarations
10962   __Pyx_RefNannySetupContext("count (wrapper)", 0);
10963   {
10964     PyObject* values[5] = {0,0,0,0,0};
10965
10966     /* "csamtools.pyx":1016
10967  * 
10968  *     def count( self,
10969  *                reference = None,             # <<<<<<<<<<<<<<
10970  *                start = None,
10971  *                end = None,
10972  */
10973     values[0] = ((PyObject *)Py_None);
10974
10975     /* "csamtools.pyx":1017
10976  *     def count( self,
10977  *                reference = None,
10978  *                start = None,             # <<<<<<<<<<<<<<
10979  *                end = None,
10980  *                region = None,
10981  */
10982     values[1] = ((PyObject *)Py_None);
10983
10984     /* "csamtools.pyx":1018
10985  *                reference = None,
10986  *                start = None,
10987  *                end = None,             # <<<<<<<<<<<<<<
10988  *                region = None,
10989  *                until_eof = False ):
10990  */
10991     values[2] = ((PyObject *)Py_None);
10992
10993     /* "csamtools.pyx":1019
10994  *                start = None,
10995  *                end = None,
10996  *                region = None,             # <<<<<<<<<<<<<<
10997  *                until_eof = False ):
10998  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
10999  */
11000     values[3] = ((PyObject *)Py_None);
11001     values[4] = __pyx_k_73;
11002     if (unlikely(__pyx_kwds)) {
11003       Py_ssize_t kw_args;
11004       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
11005       switch (pos_args) {
11006         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
11007         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
11008         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
11009         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
11010         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
11011         case  0: break;
11012         default: goto __pyx_L5_argtuple_error;
11013       }
11014       kw_args = PyDict_Size(__pyx_kwds);
11015       switch (pos_args) {
11016         case  0:
11017         if (kw_args > 0) {
11018           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
11019           if (value) { values[0] = value; kw_args--; }
11020         }
11021         case  1:
11022         if (kw_args > 0) {
11023           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
11024           if (value) { values[1] = value; kw_args--; }
11025         }
11026         case  2:
11027         if (kw_args > 0) {
11028           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
11029           if (value) { values[2] = value; kw_args--; }
11030         }
11031         case  3:
11032         if (kw_args > 0) {
11033           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
11034           if (value) { values[3] = value; kw_args--; }
11035         }
11036         case  4:
11037         if (kw_args > 0) {
11038           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__until_eof);
11039           if (value) { values[4] = value; kw_args--; }
11040         }
11041       }
11042       if (unlikely(kw_args > 0)) {
11043         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11044       }
11045     } else {
11046       switch (PyTuple_GET_SIZE(__pyx_args)) {
11047         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
11048         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
11049         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
11050         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
11051         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
11052         case  0: break;
11053         default: goto __pyx_L5_argtuple_error;
11054       }
11055     }
11056     __pyx_v_reference = values[0];
11057     __pyx_v_start = values[1];
11058     __pyx_v_end = values[2];
11059     __pyx_v_region = values[3];
11060     __pyx_v_until_eof = values[4];
11061   }
11062   goto __pyx_L4_argument_unpacking_done;
11063   __pyx_L5_argtuple_error:;
11064   __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11065   __pyx_L3_error:;
11066   __Pyx_AddTraceback("csamtools.Samfile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
11067   __Pyx_RefNannyFinishContext();
11068   return NULL;
11069   __pyx_L4_argument_unpacking_done:;
11070   __pyx_r = __pyx_pf_9csamtools_7Samfile_24count(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_until_eof);
11071   __Pyx_RefNannyFinishContext();
11072   return __pyx_r;
11073 }
11074
11075 /* "csamtools.pyx":1015
11076  *         return dest
11077  * 
11078  *     def count( self,             # <<<<<<<<<<<<<<
11079  *                reference = None,
11080  *                start = None,
11081  */
11082
11083 static PyObject *__pyx_pf_9csamtools_7Samfile_24count(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof) {
11084   int __pyx_v_rtid;
11085   int __pyx_v_rstart;
11086   int __pyx_v_rend;
11087   int __pyx_v_counter;
11088   PyObject *__pyx_r = NULL;
11089   __Pyx_RefNannyDeclarations
11090   PyObject *__pyx_t_1 = NULL;
11091   PyObject *__pyx_t_2 = NULL;
11092   int __pyx_t_3;
11093   int __pyx_t_4;
11094   PyObject *__pyx_t_5 = NULL;
11095   PyObject *__pyx_t_6 = NULL;
11096   PyObject *__pyx_t_7 = NULL;
11097   PyObject *__pyx_t_8 = NULL;
11098   PyObject *(*__pyx_t_9)(PyObject *);
11099   int __pyx_t_10;
11100   int __pyx_t_11;
11101   int __pyx_t_12;
11102   int __pyx_t_13;
11103   int __pyx_t_14;
11104   int __pyx_lineno = 0;
11105   const char *__pyx_filename = NULL;
11106   int __pyx_clineno = 0;
11107   __Pyx_TraceDeclarations
11108   __Pyx_RefNannySetupContext("count", 0);
11109   __Pyx_TraceCall("count", __pyx_f[0], 1015);
11110   __Pyx_INCREF(__pyx_v_region);
11111
11112   /* "csamtools.pyx":1033
11113  *         cdef int rend
11114  * 
11115  *         if not self._isOpen():             # <<<<<<<<<<<<<<
11116  *             raise ValueError( "I/O operation on closed file" )
11117  * 
11118  */
11119   __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 = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11120   __Pyx_GOTREF(__pyx_t_1);
11121   __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 = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11122   __Pyx_GOTREF(__pyx_t_2);
11123   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11124   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11125   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11126   __pyx_t_4 = (!__pyx_t_3);
11127   if (__pyx_t_4) {
11128
11129     /* "csamtools.pyx":1034
11130  * 
11131  *         if not self._isOpen():
11132  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
11133  * 
11134  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
11135  */
11136     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_74), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11137     __Pyx_GOTREF(__pyx_t_2);
11138     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
11139     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11140     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11141     goto __pyx_L3;
11142   }
11143   __pyx_L3:;
11144
11145   /* "csamtools.pyx":1036
11146  *             raise ValueError( "I/O operation on closed file" )
11147  * 
11148  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
11149  * 
11150  *         cdef int counter
11151  */
11152   __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 = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11153   __Pyx_GOTREF(__pyx_t_2);
11154   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11155   __Pyx_GOTREF(__pyx_t_1);
11156   __Pyx_INCREF(__pyx_v_reference);
11157   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
11158   __Pyx_GIVEREF(__pyx_v_reference);
11159   __Pyx_INCREF(__pyx_v_start);
11160   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
11161   __Pyx_GIVEREF(__pyx_v_start);
11162   __Pyx_INCREF(__pyx_v_end);
11163   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
11164   __Pyx_GIVEREF(__pyx_v_end);
11165   __Pyx_INCREF(__pyx_v_region);
11166   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
11167   __Pyx_GIVEREF(__pyx_v_region);
11168   __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 = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11169   __Pyx_GOTREF(__pyx_t_5);
11170   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11171   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
11172   if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
11173     PyObject* sequence = __pyx_t_5;
11174     if (likely(PyTuple_CheckExact(sequence))) {
11175       if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) {
11176         if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
11177         else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
11178         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11179       }
11180       __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
11181       __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
11182       __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
11183       __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
11184     } else {
11185       if (unlikely(PyList_GET_SIZE(sequence) != 4)) {
11186         if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
11187         else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
11188         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11189       }
11190       __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
11191       __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
11192       __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
11193       __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
11194     }
11195     __Pyx_INCREF(__pyx_t_1);
11196     __Pyx_INCREF(__pyx_t_2);
11197     __Pyx_INCREF(__pyx_t_6);
11198     __Pyx_INCREF(__pyx_t_7);
11199     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11200   } else {
11201     Py_ssize_t index = -1;
11202     __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11203     __Pyx_GOTREF(__pyx_t_8);
11204     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11205     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
11206     index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
11207     __Pyx_GOTREF(__pyx_t_1);
11208     index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
11209     __Pyx_GOTREF(__pyx_t_2);
11210     index = 2; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
11211     __Pyx_GOTREF(__pyx_t_6);
11212     index = 3; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed;
11213     __Pyx_GOTREF(__pyx_t_7);
11214     if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11215     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11216     goto __pyx_L5_unpacking_done;
11217     __pyx_L4_unpacking_failed:;
11218     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11219     if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
11220     if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
11221     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11222     __pyx_L5_unpacking_done:;
11223   }
11224   __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 = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11225   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11226   __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 = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11227   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11228   __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 = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11229   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11230   __Pyx_DECREF(__pyx_v_region);
11231   __pyx_v_region = __pyx_t_1;
11232   __pyx_t_1 = 0;
11233   __pyx_v_rtid = __pyx_t_10;
11234   __pyx_v_rstart = __pyx_t_11;
11235   __pyx_v_rend = __pyx_t_12;
11236
11237   /* "csamtools.pyx":1039
11238  * 
11239  *         cdef int counter
11240  *         counter = 0;             # <<<<<<<<<<<<<<
11241  * 
11242  *         if self.isbam:
11243  */
11244   __pyx_v_counter = 0;
11245
11246   /* "csamtools.pyx":1041
11247  *         counter = 0;
11248  * 
11249  *         if self.isbam:             # <<<<<<<<<<<<<<
11250  *             if not until_eof and not self._hasIndex() and not self.isremote:
11251  *                 raise ValueError( "fetch called on bamfile without index" )
11252  */
11253   if (__pyx_v_self->isbam) {
11254
11255     /* "csamtools.pyx":1042
11256  * 
11257  *         if self.isbam:
11258  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
11259  *                 raise ValueError( "fetch called on bamfile without index" )
11260  * 
11261  */
11262     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11263     __pyx_t_3 = (!__pyx_t_4);
11264     if (__pyx_t_3) {
11265       __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 = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11266       __Pyx_GOTREF(__pyx_t_5);
11267       __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 = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11268       __Pyx_GOTREF(__pyx_t_7);
11269       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11270       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11271       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11272       __pyx_t_13 = (!__pyx_t_4);
11273       if (__pyx_t_13) {
11274         __pyx_t_4 = (!__pyx_v_self->isremote);
11275         __pyx_t_14 = __pyx_t_4;
11276       } else {
11277         __pyx_t_14 = __pyx_t_13;
11278       }
11279       __pyx_t_13 = __pyx_t_14;
11280     } else {
11281       __pyx_t_13 = __pyx_t_3;
11282     }
11283     if (__pyx_t_13) {
11284
11285       /* "csamtools.pyx":1043
11286  *         if self.isbam:
11287  *             if not until_eof and not self._hasIndex() and not self.isremote:
11288  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
11289  * 
11290  *             if not region:
11291  */
11292       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11293       __Pyx_GOTREF(__pyx_t_7);
11294       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
11295       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11296       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11297       goto __pyx_L7;
11298     }
11299     __pyx_L7:;
11300
11301     /* "csamtools.pyx":1045
11302  *                 raise ValueError( "fetch called on bamfile without index" )
11303  * 
11304  *             if not region:             # <<<<<<<<<<<<<<
11305  *                 raise ValueError( "counting functionality requires a region/reference" )
11306  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
11307  */
11308     __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11309     __pyx_t_3 = (!__pyx_t_13);
11310     if (__pyx_t_3) {
11311
11312       /* "csamtools.pyx":1046
11313  * 
11314  *             if not region:
11315  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
11316  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
11317  *             bam_fetch(self.samfile.x.bam,
11318  */
11319       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_77), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11320       __Pyx_GOTREF(__pyx_t_7);
11321       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
11322       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11323       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11324       goto __pyx_L8;
11325     }
11326     __pyx_L8:;
11327
11328     /* "csamtools.pyx":1047
11329  *             if not region:
11330  *                 raise ValueError( "counting functionality requires a region/reference" )
11331  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
11332  *             bam_fetch(self.samfile.x.bam,
11333  *                              self.index,
11334  */
11335     __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 = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11336     __Pyx_GOTREF(__pyx_t_7);
11337     __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 = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11338     __Pyx_GOTREF(__pyx_t_5);
11339     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11340     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11341     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11342     __pyx_t_13 = (!__pyx_t_3);
11343     if (__pyx_t_13) {
11344       __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_78), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11345       __Pyx_GOTREF(__pyx_t_5);
11346       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
11347       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11348       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11349       goto __pyx_L9;
11350     }
11351     __pyx_L9:;
11352
11353     /* "csamtools.pyx":1054
11354  *                              rend,
11355  *                              <void*>&counter,
11356  *                              count_callback )             # <<<<<<<<<<<<<<
11357  *             return counter
11358  *         else:
11359  */
11360     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_9csamtools_count_callback);
11361
11362     /* "csamtools.pyx":1055
11363  *                              <void*>&counter,
11364  *                              count_callback )
11365  *             return counter             # <<<<<<<<<<<<<<
11366  *         else:
11367  *             raise ValueError ("count for a region is not available for sam files" )
11368  */
11369     __Pyx_XDECREF(__pyx_r);
11370     __pyx_t_5 = PyInt_FromLong(__pyx_v_counter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11371     __Pyx_GOTREF(__pyx_t_5);
11372     __pyx_r = __pyx_t_5;
11373     __pyx_t_5 = 0;
11374     goto __pyx_L0;
11375     goto __pyx_L6;
11376   }
11377   /*else*/ {
11378
11379     /* "csamtools.pyx":1057
11380  *             return counter
11381  *         else:
11382  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
11383  * 
11384  *     def pileup( self,
11385  */
11386     __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_80), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11387     __Pyx_GOTREF(__pyx_t_5);
11388     __Pyx_Raise(__pyx_t_5, 0, 0, 0);
11389     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11390     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11391   }
11392   __pyx_L6:;
11393
11394   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
11395   goto __pyx_L0;
11396   __pyx_L1_error:;
11397   __Pyx_XDECREF(__pyx_t_1);
11398   __Pyx_XDECREF(__pyx_t_2);
11399   __Pyx_XDECREF(__pyx_t_5);
11400   __Pyx_XDECREF(__pyx_t_6);
11401   __Pyx_XDECREF(__pyx_t_7);
11402   __Pyx_XDECREF(__pyx_t_8);
11403   __Pyx_AddTraceback("csamtools.Samfile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
11404   __pyx_r = NULL;
11405   __pyx_L0:;
11406   __Pyx_XDECREF(__pyx_v_region);
11407   __Pyx_XGIVEREF(__pyx_r);
11408   __Pyx_TraceReturn(__pyx_r);
11409   __Pyx_RefNannyFinishContext();
11410   return __pyx_r;
11411 }
11412
11413 /* Python wrapper */
11414 static PyObject *__pyx_pw_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
11415 static char __pyx_doc_9csamtools_7Samfile_26pileup[] = "Samfile.pileup(self, reference=None, start=None, end=None, region=None, callback=None, **kwargs)\n\n        perform a :term:`pileup` within a :term:`region`. The region is specified by\n        :term:`reference`, *start* and *end* (using 0-based indexing).\n        Alternatively, a samtools *region* string can be supplied.\n\n        Without *reference* or *region* all reads will be used for the pileup. The reads will be returned\n        ordered by :term:`reference` sequence, which will not necessarily be the order within the file.\n\n        The method returns an iterator of type :class:`pysam.IteratorColumn` unless\n        a *callback is provided. If a *callback* is given, the callback will be executed\n        for each column within the :term:`region`.\n\n        Note that :term:`SAM` formatted files do not allow random access.\n        In these files, if a *region* or *reference* are given an exception is raised.\n\n        Optional *kwargs* to the iterator:\n\n        stepper\n           The stepper controlls how the iterator advances.\n           Possible options for the stepper are\n\n           ``all``\n              use all reads for pileup.\n           ``samtools``\n              same filter and read processing as in :term:`csamtools` pileup\n\n        fastafile\n           A :class:`FastaFile` object\n\n         mask\n           Skip all reads with bits set in mask if mask=True.\n\n         max_depth\n           Maximum read depth permitted. The default limit is *8000*.\n\n         truncate\n           By default, the samtools pileup engine outputs all reads overlapping a region (see note below).\n           If truncate is True and a region is given, only output columns in the exact region\n           specificied.\n\n        .. note::\n\n            *all* reads which overlap the region are returned. The first base returned will be the\n            first base of the first read *not* necessarily the first base of the region used in the query.\n\n        ";
11416 static PyObject *__pyx_pw_9csamtools_7Samfile_27pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
11417   PyObject *__pyx_v_reference = 0;
11418   PyObject *__pyx_v_start = 0;
11419   PyObject *__pyx_v_end = 0;
11420   PyObject *__pyx_v_region = 0;
11421   PyObject *__pyx_v_callback = 0;
11422   PyObject *__pyx_v_kwargs = 0;
11423   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};
11424   PyObject *__pyx_r = 0;
11425   __Pyx_RefNannyDeclarations
11426   __Pyx_RefNannySetupContext("pileup (wrapper)", 0);
11427   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
11428   __Pyx_GOTREF(__pyx_v_kwargs);
11429   {
11430     PyObject* values[5] = {0,0,0,0,0};
11431
11432     /* "csamtools.pyx":1060
11433  * 
11434  *     def pileup( self,
11435  *                 reference = None,             # <<<<<<<<<<<<<<
11436  *                 start = None,
11437  *                 end = None,
11438  */
11439     values[0] = ((PyObject *)Py_None);
11440
11441     /* "csamtools.pyx":1061
11442  *     def pileup( self,
11443  *                 reference = None,
11444  *                 start = None,             # <<<<<<<<<<<<<<
11445  *                 end = None,
11446  *                 region = None,
11447  */
11448     values[1] = ((PyObject *)Py_None);
11449
11450     /* "csamtools.pyx":1062
11451  *                 reference = None,
11452  *                 start = None,
11453  *                 end = None,             # <<<<<<<<<<<<<<
11454  *                 region = None,
11455  *                 callback = None,
11456  */
11457     values[2] = ((PyObject *)Py_None);
11458
11459     /* "csamtools.pyx":1063
11460  *                 start = None,
11461  *                 end = None,
11462  *                 region = None,             # <<<<<<<<<<<<<<
11463  *                 callback = None,
11464  *                 **kwargs ):
11465  */
11466     values[3] = ((PyObject *)Py_None);
11467
11468     /* "csamtools.pyx":1064
11469  *                 end = None,
11470  *                 region = None,
11471  *                 callback = None,             # <<<<<<<<<<<<<<
11472  *                 **kwargs ):
11473  *         '''
11474  */
11475     values[4] = ((PyObject *)Py_None);
11476     if (unlikely(__pyx_kwds)) {
11477       Py_ssize_t kw_args;
11478       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
11479       switch (pos_args) {
11480         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
11481         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
11482         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
11483         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
11484         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
11485         case  0: break;
11486         default: goto __pyx_L5_argtuple_error;
11487       }
11488       kw_args = PyDict_Size(__pyx_kwds);
11489       switch (pos_args) {
11490         case  0:
11491         if (kw_args > 0) {
11492           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
11493           if (value) { values[0] = value; kw_args--; }
11494         }
11495         case  1:
11496         if (kw_args > 0) {
11497           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
11498           if (value) { values[1] = value; kw_args--; }
11499         }
11500         case  2:
11501         if (kw_args > 0) {
11502           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
11503           if (value) { values[2] = value; kw_args--; }
11504         }
11505         case  3:
11506         if (kw_args > 0) {
11507           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
11508           if (value) { values[3] = value; kw_args--; }
11509         }
11510         case  4:
11511         if (kw_args > 0) {
11512           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
11513           if (value) { values[4] = value; kw_args--; }
11514         }
11515       }
11516       if (unlikely(kw_args > 0)) {
11517         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11518       }
11519     } else {
11520       switch (PyTuple_GET_SIZE(__pyx_args)) {
11521         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
11522         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
11523         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
11524         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
11525         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
11526         case  0: break;
11527         default: goto __pyx_L5_argtuple_error;
11528       }
11529     }
11530     __pyx_v_reference = values[0];
11531     __pyx_v_start = values[1];
11532     __pyx_v_end = values[2];
11533     __pyx_v_region = values[3];
11534     __pyx_v_callback = values[4];
11535   }
11536   goto __pyx_L4_argument_unpacking_done;
11537   __pyx_L5_argtuple_error:;
11538   __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11539   __pyx_L3_error:;
11540   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
11541   __Pyx_AddTraceback("csamtools.Samfile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
11542   __Pyx_RefNannyFinishContext();
11543   return NULL;
11544   __pyx_L4_argument_unpacking_done:;
11545   __pyx_r = __pyx_pf_9csamtools_7Samfile_26pileup(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_callback, __pyx_v_kwargs);
11546   __Pyx_XDECREF(__pyx_v_kwargs);
11547   __Pyx_RefNannyFinishContext();
11548   return __pyx_r;
11549 }
11550
11551 /* "csamtools.pyx":1059
11552  *             raise ValueError ("count for a region is not available for sam files" )
11553  * 
11554  *     def pileup( self,             # <<<<<<<<<<<<<<
11555  *                 reference = None,
11556  *                 start = None,
11557  */
11558
11559 static PyObject *__pyx_pf_9csamtools_7Samfile_26pileup(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_callback, PyObject *__pyx_v_kwargs) {
11560   int __pyx_v_rtid;
11561   int __pyx_v_rstart;
11562   int __pyx_v_rend;
11563   int __pyx_v_has_coord;
11564   bam_plbuf_t *__pyx_v_buf;
11565   PyObject *__pyx_r = NULL;
11566   __Pyx_RefNannyDeclarations
11567   PyObject *__pyx_t_1 = NULL;
11568   PyObject *__pyx_t_2 = NULL;
11569   int __pyx_t_3;
11570   int __pyx_t_4;
11571   PyObject *__pyx_t_5 = NULL;
11572   PyObject *__pyx_t_6 = NULL;
11573   PyObject *__pyx_t_7 = NULL;
11574   PyObject *__pyx_t_8 = NULL;
11575   PyObject *(*__pyx_t_9)(PyObject *);
11576   int __pyx_t_10;
11577   int __pyx_t_11;
11578   int __pyx_t_12;
11579   int __pyx_t_13;
11580   int __pyx_lineno = 0;
11581   const char *__pyx_filename = NULL;
11582   int __pyx_clineno = 0;
11583   __Pyx_TraceDeclarations
11584   __Pyx_RefNannySetupContext("pileup", 0);
11585   __Pyx_TraceCall("pileup", __pyx_f[0], 1059);
11586
11587   /* "csamtools.pyx":1115
11588  *         cdef bam_plbuf_t *buf
11589  * 
11590  *         if not self._isOpen():             # <<<<<<<<<<<<<<
11591  *             raise ValueError( "I/O operation on closed file" )
11592  * 
11593  */
11594   __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 = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11595   __Pyx_GOTREF(__pyx_t_1);
11596   __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 = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11597   __Pyx_GOTREF(__pyx_t_2);
11598   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11599   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11600   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11601   __pyx_t_4 = (!__pyx_t_3);
11602   if (__pyx_t_4) {
11603
11604     /* "csamtools.pyx":1116
11605  * 
11606  *         if not self._isOpen():
11607  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
11608  * 
11609  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
11610  */
11611     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_81), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11612     __Pyx_GOTREF(__pyx_t_2);
11613     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
11614     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11615     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11616     goto __pyx_L3;
11617   }
11618   __pyx_L3:;
11619
11620   /* "csamtools.pyx":1118
11621  *             raise ValueError( "I/O operation on closed file" )
11622  * 
11623  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
11624  * 
11625  *         if self.isbam:
11626  */
11627   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11628   __Pyx_GOTREF(__pyx_t_2);
11629   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11630   __Pyx_GOTREF(__pyx_t_1);
11631   __Pyx_INCREF(__pyx_v_reference);
11632   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
11633   __Pyx_GIVEREF(__pyx_v_reference);
11634   __Pyx_INCREF(__pyx_v_start);
11635   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
11636   __Pyx_GIVEREF(__pyx_v_start);
11637   __Pyx_INCREF(__pyx_v_end);
11638   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
11639   __Pyx_GIVEREF(__pyx_v_end);
11640   __Pyx_INCREF(__pyx_v_region);
11641   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
11642   __Pyx_GIVEREF(__pyx_v_region);
11643   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11644   __Pyx_GOTREF(__pyx_t_5);
11645   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11646   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
11647   if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
11648     PyObject* sequence = __pyx_t_5;
11649     if (likely(PyTuple_CheckExact(sequence))) {
11650       if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) {
11651         if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
11652         else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
11653         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11654       }
11655       __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
11656       __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
11657       __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
11658       __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
11659     } else {
11660       if (unlikely(PyList_GET_SIZE(sequence) != 4)) {
11661         if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4);
11662         else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
11663         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11664       }
11665       __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
11666       __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
11667       __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
11668       __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
11669     }
11670     __Pyx_INCREF(__pyx_t_1);
11671     __Pyx_INCREF(__pyx_t_2);
11672     __Pyx_INCREF(__pyx_t_6);
11673     __Pyx_INCREF(__pyx_t_7);
11674     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11675   } else {
11676     Py_ssize_t index = -1;
11677     __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11678     __Pyx_GOTREF(__pyx_t_8);
11679     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11680     __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
11681     index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
11682     __Pyx_GOTREF(__pyx_t_1);
11683     index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
11684     __Pyx_GOTREF(__pyx_t_2);
11685     index = 2; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
11686     __Pyx_GOTREF(__pyx_t_6);
11687     index = 3; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L4_unpacking_failed;
11688     __Pyx_GOTREF(__pyx_t_7);
11689     if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11690     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11691     goto __pyx_L5_unpacking_done;
11692     __pyx_L4_unpacking_failed:;
11693     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11694     if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
11695     if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
11696     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11697     __pyx_L5_unpacking_done:;
11698   }
11699   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11700   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11701   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11702   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11703   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11704   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11705   __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 = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11706   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11707   __pyx_v_has_coord = __pyx_t_10;
11708   __pyx_v_rtid = __pyx_t_11;
11709   __pyx_v_rstart = __pyx_t_12;
11710   __pyx_v_rend = __pyx_t_13;
11711
11712   /* "csamtools.pyx":1120
11713  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
11714  * 
11715  *         if self.isbam:             # <<<<<<<<<<<<<<
11716  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
11717  * 
11718  */
11719   if (__pyx_v_self->isbam) {
11720
11721     /* "csamtools.pyx":1121
11722  * 
11723  *         if self.isbam:
11724  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
11725  * 
11726  *             if callback:
11727  */
11728     __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 = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11729     __Pyx_GOTREF(__pyx_t_5);
11730     __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 = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11731     __Pyx_GOTREF(__pyx_t_7);
11732     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
11733     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11734     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11735     __pyx_t_3 = (!__pyx_t_4);
11736     if (__pyx_t_3) {
11737       __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 = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11738       __Pyx_GOTREF(__pyx_t_7);
11739       __Pyx_Raise(__pyx_t_7, 0, 0, 0);
11740       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11741       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11742       goto __pyx_L7;
11743     }
11744     __pyx_L7:;
11745
11746     /* "csamtools.pyx":1123
11747  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
11748  * 
11749  *             if callback:             # <<<<<<<<<<<<<<
11750  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
11751  * 
11752  */
11753     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11754     if (__pyx_t_3) {
11755
11756       /* "csamtools.pyx":1124
11757  * 
11758  *             if callback:
11759  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
11760  * 
11761  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
11762  */
11763       __pyx_t_3 = (!__pyx_v_has_coord);
11764       if (__pyx_t_3) {
11765         __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_84), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11766         __Pyx_GOTREF(__pyx_t_7);
11767         __Pyx_Raise(__pyx_t_7, 0, 0, 0);
11768         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11769         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11770         goto __pyx_L9;
11771       }
11772       __pyx_L9:;
11773
11774       /* "csamtools.pyx":1126
11775  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
11776  * 
11777  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )             # <<<<<<<<<<<<<<
11778  *                 bam_fetch(self.samfile.x.bam,
11779  *                           self.index, rtid, rstart, rend,
11780  */
11781       __pyx_v_buf = bam_plbuf_init(((bam_pileup_f)__pyx_f_9csamtools_pileup_callback), ((void *)__pyx_v_callback));
11782
11783       /* "csamtools.pyx":1129
11784  *                 bam_fetch(self.samfile.x.bam,
11785  *                           self.index, rtid, rstart, rend,
11786  *                           buf, pileup_fetch_callback )             # <<<<<<<<<<<<<<
11787  * 
11788  *                 # finalize pileup
11789  */
11790       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_9csamtools_pileup_fetch_callback);
11791
11792       /* "csamtools.pyx":1132
11793  * 
11794  *                 # finalize pileup
11795  *                 bam_plbuf_push( NULL, buf)             # <<<<<<<<<<<<<<
11796  *                 bam_plbuf_destroy(buf)
11797  *             else:
11798  */
11799       bam_plbuf_push(NULL, __pyx_v_buf);
11800
11801       /* "csamtools.pyx":1133
11802  *                 # finalize pileup
11803  *                 bam_plbuf_push( NULL, buf)
11804  *                 bam_plbuf_destroy(buf)             # <<<<<<<<<<<<<<
11805  *             else:
11806  *                 if has_coord:
11807  */
11808       bam_plbuf_destroy(__pyx_v_buf);
11809       goto __pyx_L8;
11810     }
11811     /*else*/ {
11812
11813       /* "csamtools.pyx":1135
11814  *                 bam_plbuf_destroy(buf)
11815  *             else:
11816  *                 if has_coord:             # <<<<<<<<<<<<<<
11817  *                     return IteratorColumnRegion( self,
11818  *                                                  tid = rtid,
11819  */
11820       if (__pyx_v_has_coord) {
11821
11822         /* "csamtools.pyx":1136
11823  *             else:
11824  *                 if has_coord:
11825  *                     return IteratorColumnRegion( self,             # <<<<<<<<<<<<<<
11826  *                                                  tid = rtid,
11827  *                                                  start = rstart,
11828  */
11829         __Pyx_XDECREF(__pyx_r);
11830         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11831         __Pyx_GOTREF(__pyx_t_7);
11832         __Pyx_INCREF(((PyObject *)__pyx_v_self));
11833         PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
11834         __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
11835
11836         /* "csamtools.pyx":1140
11837  *                                                  start = rstart,
11838  *                                                  end = rend,
11839  *                                                  **kwargs )             # <<<<<<<<<<<<<<
11840  *                 else:
11841  *                     return IteratorColumnAllRefs(self, **kwargs )
11842  */
11843         __pyx_t_5 = PyDict_Copy(((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11844         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
11845
11846         /* "csamtools.pyx":1137
11847  *                 if has_coord:
11848  *                     return IteratorColumnRegion( self,
11849  *                                                  tid = rtid,             # <<<<<<<<<<<<<<
11850  *                                                  start = rstart,
11851  *                                                  end = rend,
11852  */
11853         __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11854         __Pyx_GOTREF(__pyx_t_6);
11855         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid)))) {
11856           __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__tid)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11857         }
11858         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11859         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11860
11861         /* "csamtools.pyx":1138
11862  *                     return IteratorColumnRegion( self,
11863  *                                                  tid = rtid,
11864  *                                                  start = rstart,             # <<<<<<<<<<<<<<
11865  *                                                  end = rend,
11866  *                                                  **kwargs )
11867  */
11868         __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11869         __Pyx_GOTREF(__pyx_t_6);
11870         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start)))) {
11871           __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__start)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11872         }
11873         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11874         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11875
11876         /* "csamtools.pyx":1139
11877  *                                                  tid = rtid,
11878  *                                                  start = rstart,
11879  *                                                  end = rend,             # <<<<<<<<<<<<<<
11880  *                                                  **kwargs )
11881  *                 else:
11882  */
11883         __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11884         __Pyx_GOTREF(__pyx_t_6);
11885         if (unlikely(PyDict_GetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end)))) {
11886           __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__end)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11887         }
11888         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11889         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11890         __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorColumnRegion)), ((PyObject *)__pyx_t_7), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11891         __Pyx_GOTREF(__pyx_t_6);
11892         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
11893         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
11894         __pyx_r = __pyx_t_6;
11895         __pyx_t_6 = 0;
11896         goto __pyx_L0;
11897         goto __pyx_L10;
11898       }
11899       /*else*/ {
11900
11901         /* "csamtools.pyx":1142
11902  *                                                  **kwargs )
11903  *                 else:
11904  *                     return IteratorColumnAllRefs(self, **kwargs )             # <<<<<<<<<<<<<<
11905  * 
11906  *         else:
11907  */
11908         __Pyx_XDECREF(__pyx_r);
11909         __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11910         __Pyx_GOTREF(__pyx_t_6);
11911         __Pyx_INCREF(((PyObject *)__pyx_v_self));
11912         PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self));
11913         __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
11914         __pyx_t_5 = ((PyObject *)__pyx_v_kwargs);
11915         __Pyx_INCREF(__pyx_t_5);
11916         __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorColumnAllRefs)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11917         __Pyx_GOTREF(__pyx_t_7);
11918         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11919         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
11920         __pyx_r = __pyx_t_7;
11921         __pyx_t_7 = 0;
11922         goto __pyx_L0;
11923       }
11924       __pyx_L10:;
11925     }
11926     __pyx_L8:;
11927     goto __pyx_L6;
11928   }
11929   /*else*/ {
11930
11931     /* "csamtools.pyx":1145
11932  * 
11933  *         else:
11934  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
11935  * 
11936  *     def close( self ):
11937  */
11938     __pyx_t_7 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_86), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11939     __Pyx_GOTREF(__pyx_t_7);
11940     __Pyx_Raise(__pyx_t_7, 0, 0, 0);
11941     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11942     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11943   }
11944   __pyx_L6:;
11945
11946   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
11947   goto __pyx_L0;
11948   __pyx_L1_error:;
11949   __Pyx_XDECREF(__pyx_t_1);
11950   __Pyx_XDECREF(__pyx_t_2);
11951   __Pyx_XDECREF(__pyx_t_5);
11952   __Pyx_XDECREF(__pyx_t_6);
11953   __Pyx_XDECREF(__pyx_t_7);
11954   __Pyx_XDECREF(__pyx_t_8);
11955   __Pyx_AddTraceback("csamtools.Samfile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
11956   __pyx_r = NULL;
11957   __pyx_L0:;
11958   __Pyx_XGIVEREF(__pyx_r);
11959   __Pyx_TraceReturn(__pyx_r);
11960   __Pyx_RefNannyFinishContext();
11961   return __pyx_r;
11962 }
11963
11964 /* Python wrapper */
11965 static PyObject *__pyx_pw_9csamtools_7Samfile_29close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
11966 static char __pyx_doc_9csamtools_7Samfile_28close[] = "Samfile.close(self)\n\n        closes the :class:`pysam.Samfile`.";
11967 static PyObject *__pyx_pw_9csamtools_7Samfile_29close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
11968   PyObject *__pyx_r = 0;
11969   __Pyx_RefNannyDeclarations
11970   __Pyx_RefNannySetupContext("close (wrapper)", 0);
11971   __pyx_r = __pyx_pf_9csamtools_7Samfile_28close(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
11972   __Pyx_RefNannyFinishContext();
11973   return __pyx_r;
11974 }
11975
11976 /* "csamtools.pyx":1147
11977  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
11978  * 
11979  *     def close( self ):             # <<<<<<<<<<<<<<
11980  *         '''
11981  *         closes the :class:`pysam.Samfile`.'''
11982  */
11983
11984 static PyObject *__pyx_pf_9csamtools_7Samfile_28close(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
11985   PyObject *__pyx_r = NULL;
11986   __Pyx_RefNannyDeclarations
11987   int __pyx_t_1;
11988   __Pyx_TraceDeclarations
11989   __Pyx_RefNannySetupContext("close", 0);
11990   __Pyx_TraceCall("close", __pyx_f[0], 1147);
11991
11992   /* "csamtools.pyx":1150
11993  *         '''
11994  *         closes the :class:`pysam.Samfile`.'''
11995  *         if self.samfile != NULL:             # <<<<<<<<<<<<<<
11996  *             samclose( self.samfile )
11997  *             bam_index_destroy(self.index);
11998  */
11999   __pyx_t_1 = (__pyx_v_self->samfile != NULL);
12000   if (__pyx_t_1) {
12001
12002     /* "csamtools.pyx":1151
12003  *         closes the :class:`pysam.Samfile`.'''
12004  *         if self.samfile != NULL:
12005  *             samclose( self.samfile )             # <<<<<<<<<<<<<<
12006  *             bam_index_destroy(self.index);
12007  *             self.samfile = NULL
12008  */
12009     samclose(__pyx_v_self->samfile);
12010
12011     /* "csamtools.pyx":1152
12012  *         if self.samfile != NULL:
12013  *             samclose( self.samfile )
12014  *             bam_index_destroy(self.index);             # <<<<<<<<<<<<<<
12015  *             self.samfile = NULL
12016  * 
12017  */
12018     bam_index_destroy(__pyx_v_self->index);
12019
12020     /* "csamtools.pyx":1153
12021  *             samclose( self.samfile )
12022  *             bam_index_destroy(self.index);
12023  *             self.samfile = NULL             # <<<<<<<<<<<<<<
12024  * 
12025  *     def __dealloc__( self ):
12026  */
12027     __pyx_v_self->samfile = NULL;
12028     goto __pyx_L3;
12029   }
12030   __pyx_L3:;
12031
12032   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12033   __Pyx_XGIVEREF(__pyx_r);
12034   __Pyx_TraceReturn(__pyx_r);
12035   __Pyx_RefNannyFinishContext();
12036   return __pyx_r;
12037 }
12038
12039 /* Python wrapper */
12040 static void __pyx_pw_9csamtools_7Samfile_31__dealloc__(PyObject *__pyx_v_self); /*proto*/
12041 static void __pyx_pw_9csamtools_7Samfile_31__dealloc__(PyObject *__pyx_v_self) {
12042   __Pyx_RefNannyDeclarations
12043   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
12044   __pyx_pf_9csamtools_7Samfile_30__dealloc__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12045   __Pyx_RefNannyFinishContext();
12046 }
12047
12048 /* "csamtools.pyx":1155
12049  *             self.samfile = NULL
12050  * 
12051  *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
12052  *         # remember: dealloc cannot call other methods
12053  *         # note: no doc string
12054  */
12055
12056 static void __pyx_pf_9csamtools_7Samfile_30__dealloc__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12057   __Pyx_RefNannyDeclarations
12058   PyObject *__pyx_t_1 = NULL;
12059   PyObject *__pyx_t_2 = NULL;
12060   int __pyx_t_3;
12061   int __pyx_lineno = 0;
12062   const char *__pyx_filename = NULL;
12063   int __pyx_clineno = 0;
12064   __Pyx_TraceDeclarations
12065   __Pyx_RefNannySetupContext("__dealloc__", 0);
12066   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1155);
12067
12068   /* "csamtools.pyx":1159
12069  *         # note: no doc string
12070  *         # note: __del__ is not called.
12071  *         self.close()             # <<<<<<<<<<<<<<
12072  *         bam_destroy1(self.b)
12073  *         if self._filename != NULL: free( self._filename )
12074  */
12075   __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 = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12076   __Pyx_GOTREF(__pyx_t_1);
12077   __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 = 1159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12078   __Pyx_GOTREF(__pyx_t_2);
12079   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12080   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12081
12082   /* "csamtools.pyx":1160
12083  *         # note: __del__ is not called.
12084  *         self.close()
12085  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
12086  *         if self._filename != NULL: free( self._filename )
12087  * 
12088  */
12089   bam_destroy1(__pyx_v_self->b);
12090
12091   /* "csamtools.pyx":1161
12092  *         self.close()
12093  *         bam_destroy1(self.b)
12094  *         if self._filename != NULL: free( self._filename )             # <<<<<<<<<<<<<<
12095  * 
12096  *     cpdef int write( self, AlignedRead read ) except -1:
12097  */
12098   __pyx_t_3 = (__pyx_v_self->_filename != NULL);
12099   if (__pyx_t_3) {
12100     free(__pyx_v_self->_filename);
12101     goto __pyx_L3;
12102   }
12103   __pyx_L3:;
12104
12105   goto __pyx_L0;
12106   __pyx_L1_error:;
12107   __Pyx_XDECREF(__pyx_t_1);
12108   __Pyx_XDECREF(__pyx_t_2);
12109   __Pyx_AddTraceback("csamtools.Samfile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12110   __pyx_L0:;
12111   __Pyx_TraceReturn(Py_None);
12112   __Pyx_RefNannyFinishContext();
12113 }
12114
12115 /* "csamtools.pyx":1163
12116  *         if self._filename != NULL: free( self._filename )
12117  * 
12118  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
12119  *         '''
12120  *         write a single :class:`pysam.AlignedRead` to disk.
12121  */
12122
12123 static PyObject *__pyx_pw_9csamtools_7Samfile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
12124 static int __pyx_f_9csamtools_7Samfile_write(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_read, int __pyx_skip_dispatch) {
12125   int __pyx_r;
12126   __Pyx_RefNannyDeclarations
12127   PyObject *__pyx_t_1 = NULL;
12128   PyObject *__pyx_t_2 = NULL;
12129   PyObject *__pyx_t_3 = NULL;
12130   int __pyx_t_4;
12131   int __pyx_t_5;
12132   int __pyx_t_6;
12133   int __pyx_lineno = 0;
12134   const char *__pyx_filename = NULL;
12135   int __pyx_clineno = 0;
12136   __Pyx_TraceDeclarations
12137   __Pyx_RefNannySetupContext("write", 0);
12138   __Pyx_TraceCall("write", __pyx_f[0], 1163);
12139   /* Check if called by wrapper */
12140   if (unlikely(__pyx_skip_dispatch)) ;
12141   /* Check if overriden in Python */
12142   else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
12143     __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 = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12144     __Pyx_GOTREF(__pyx_t_1);
12145     if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_9csamtools_7Samfile_33write)) {
12146       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12147       __Pyx_GOTREF(__pyx_t_2);
12148       __Pyx_INCREF(((PyObject *)__pyx_v_read));
12149       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_read));
12150       __Pyx_GIVEREF(((PyObject *)__pyx_v_read));
12151       __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 = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12152       __Pyx_GOTREF(__pyx_t_3);
12153       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
12154       __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 = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12155       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
12156       __pyx_r = __pyx_t_4;
12157       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12158       goto __pyx_L0;
12159     }
12160     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12161   }
12162
12163   /* "csamtools.pyx":1169
12164  *         returns the number of bytes written.
12165  *         '''
12166  *         if not self._isOpen():             # <<<<<<<<<<<<<<
12167  *             return 0
12168  * 
12169  */
12170   __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 = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12171   __Pyx_GOTREF(__pyx_t_1);
12172   __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 = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12173   __Pyx_GOTREF(__pyx_t_3);
12174   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12175   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12176   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
12177   __pyx_t_6 = (!__pyx_t_5);
12178   if (__pyx_t_6) {
12179
12180     /* "csamtools.pyx":1170
12181  *         '''
12182  *         if not self._isOpen():
12183  *             return 0             # <<<<<<<<<<<<<<
12184  * 
12185  *         return samwrite( self.samfile, read._delegate )
12186  */
12187     __pyx_r = 0;
12188     goto __pyx_L0;
12189     goto __pyx_L3;
12190   }
12191   __pyx_L3:;
12192
12193   /* "csamtools.pyx":1172
12194  *             return 0
12195  * 
12196  *         return samwrite( self.samfile, read._delegate )             # <<<<<<<<<<<<<<
12197  * 
12198  *     def __enter__(self):
12199  */
12200   __pyx_r = samwrite(__pyx_v_self->samfile, __pyx_v_read->_delegate);
12201   goto __pyx_L0;
12202
12203   __pyx_r = 0;
12204   goto __pyx_L0;
12205   __pyx_L1_error:;
12206   __Pyx_XDECREF(__pyx_t_1);
12207   __Pyx_XDECREF(__pyx_t_2);
12208   __Pyx_XDECREF(__pyx_t_3);
12209   __Pyx_WriteUnraisable("csamtools.Samfile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
12210   __pyx_r = 0;
12211   __pyx_L0:;
12212   __Pyx_TraceReturn(Py_None);
12213   __Pyx_RefNannyFinishContext();
12214   return __pyx_r;
12215 }
12216
12217 /* Python wrapper */
12218 static PyObject *__pyx_pw_9csamtools_7Samfile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
12219 static char __pyx_doc_9csamtools_7Samfile_32write[] = "Samfile.write(self, AlignedRead read) -> int\n\n        write a single :class:`pysam.AlignedRead` to disk.\n\n        returns the number of bytes written.\n        ";
12220 static PyObject *__pyx_pw_9csamtools_7Samfile_33write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
12221   PyObject *__pyx_r = 0;
12222   __Pyx_RefNannyDeclarations
12223   __Pyx_RefNannySetupContext("write (wrapper)", 0);
12224   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12225   __pyx_r = __pyx_pf_9csamtools_7Samfile_32write(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read));
12226   goto __pyx_L0;
12227   __pyx_L1_error:;
12228   __pyx_r = NULL;
12229   __pyx_L0:;
12230   __Pyx_RefNannyFinishContext();
12231   return __pyx_r;
12232 }
12233
12234 /* "csamtools.pyx":1163
12235  *         if self._filename != NULL: free( self._filename )
12236  * 
12237  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
12238  *         '''
12239  *         write a single :class:`pysam.AlignedRead` to disk.
12240  */
12241
12242 static PyObject *__pyx_pf_9csamtools_7Samfile_32write(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_read) {
12243   PyObject *__pyx_r = NULL;
12244   __Pyx_RefNannyDeclarations
12245   PyObject *__pyx_t_1 = NULL;
12246   int __pyx_lineno = 0;
12247   const char *__pyx_filename = NULL;
12248   int __pyx_clineno = 0;
12249   __Pyx_TraceDeclarations
12250   __Pyx_RefNannySetupContext("write", 0);
12251   __Pyx_TraceCall("write", __pyx_f[0], 1163);
12252   __Pyx_XDECREF(__pyx_r);
12253   __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_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 = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12254   __Pyx_GOTREF(__pyx_t_1);
12255   __pyx_r = __pyx_t_1;
12256   __pyx_t_1 = 0;
12257   goto __pyx_L0;
12258
12259   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12260   goto __pyx_L0;
12261   __pyx_L1_error:;
12262   __Pyx_XDECREF(__pyx_t_1);
12263   __Pyx_AddTraceback("csamtools.Samfile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
12264   __pyx_r = NULL;
12265   __pyx_L0:;
12266   __Pyx_XGIVEREF(__pyx_r);
12267   __Pyx_TraceReturn(__pyx_r);
12268   __Pyx_RefNannyFinishContext();
12269   return __pyx_r;
12270 }
12271
12272 /* Python wrapper */
12273 static PyObject *__pyx_pw_9csamtools_7Samfile_35__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
12274 static char __pyx_doc_9csamtools_7Samfile_34__enter__[] = "Samfile.__enter__(self)";
12275 static PyObject *__pyx_pw_9csamtools_7Samfile_35__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
12276   PyObject *__pyx_r = 0;
12277   __Pyx_RefNannyDeclarations
12278   __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
12279   __pyx_r = __pyx_pf_9csamtools_7Samfile_34__enter__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12280   __Pyx_RefNannyFinishContext();
12281   return __pyx_r;
12282 }
12283
12284 /* "csamtools.pyx":1174
12285  *         return samwrite( self.samfile, read._delegate )
12286  * 
12287  *     def __enter__(self):             # <<<<<<<<<<<<<<
12288  *         return self
12289  * 
12290  */
12291
12292 static PyObject *__pyx_pf_9csamtools_7Samfile_34__enter__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12293   PyObject *__pyx_r = NULL;
12294   __Pyx_RefNannyDeclarations
12295   __Pyx_TraceDeclarations
12296   __Pyx_RefNannySetupContext("__enter__", 0);
12297   __Pyx_TraceCall("__enter__", __pyx_f[0], 1174);
12298
12299   /* "csamtools.pyx":1175
12300  * 
12301  *     def __enter__(self):
12302  *         return self             # <<<<<<<<<<<<<<
12303  * 
12304  *     def __exit__(self, exc_type, exc_value, traceback):
12305  */
12306   __Pyx_XDECREF(__pyx_r);
12307   __Pyx_INCREF(((PyObject *)__pyx_v_self));
12308   __pyx_r = ((PyObject *)__pyx_v_self);
12309   goto __pyx_L0;
12310
12311   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12312   __pyx_L0:;
12313   __Pyx_XGIVEREF(__pyx_r);
12314   __Pyx_TraceReturn(__pyx_r);
12315   __Pyx_RefNannyFinishContext();
12316   return __pyx_r;
12317 }
12318
12319 /* Python wrapper */
12320 static PyObject *__pyx_pw_9csamtools_7Samfile_37__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
12321 static char __pyx_doc_9csamtools_7Samfile_36__exit__[] = "Samfile.__exit__(self, exc_type, exc_value, traceback)";
12322 static PyObject *__pyx_pw_9csamtools_7Samfile_37__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
12323   CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
12324   CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0;
12325   CYTHON_UNUSED PyObject *__pyx_v_traceback = 0;
12326   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__exc_type,&__pyx_n_s__exc_value,&__pyx_n_s__traceback,0};
12327   PyObject *__pyx_r = 0;
12328   __Pyx_RefNannyDeclarations
12329   __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
12330   {
12331     PyObject* values[3] = {0,0,0};
12332     if (unlikely(__pyx_kwds)) {
12333       Py_ssize_t kw_args;
12334       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
12335       switch (pos_args) {
12336         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
12337         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
12338         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
12339         case  0: break;
12340         default: goto __pyx_L5_argtuple_error;
12341       }
12342       kw_args = PyDict_Size(__pyx_kwds);
12343       switch (pos_args) {
12344         case  0:
12345         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_type);
12346         if (likely(values[0])) kw_args--;
12347         else goto __pyx_L5_argtuple_error;
12348         case  1:
12349         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_value);
12350         if (likely(values[1])) kw_args--;
12351         else {
12352           __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
12353         }
12354         case  2:
12355         values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__traceback);
12356         if (likely(values[2])) kw_args--;
12357         else {
12358           __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
12359         }
12360       }
12361       if (unlikely(kw_args > 0)) {
12362         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
12363       }
12364     } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
12365       goto __pyx_L5_argtuple_error;
12366     } else {
12367       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
12368       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
12369       values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
12370     }
12371     __pyx_v_exc_type = values[0];
12372     __pyx_v_exc_value = values[1];
12373     __pyx_v_traceback = values[2];
12374   }
12375   goto __pyx_L4_argument_unpacking_done;
12376   __pyx_L5_argtuple_error:;
12377   __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1177; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
12378   __pyx_L3_error:;
12379   __Pyx_AddTraceback("csamtools.Samfile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12380   __Pyx_RefNannyFinishContext();
12381   return NULL;
12382   __pyx_L4_argument_unpacking_done:;
12383   __pyx_r = __pyx_pf_9csamtools_7Samfile_36__exit__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback);
12384   __Pyx_RefNannyFinishContext();
12385   return __pyx_r;
12386 }
12387
12388 /* "csamtools.pyx":1177
12389  *         return self
12390  * 
12391  *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
12392  *         self.close()
12393  *         return False
12394  */
12395
12396 static PyObject *__pyx_pf_9csamtools_7Samfile_36__exit__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) {
12397   PyObject *__pyx_r = NULL;
12398   __Pyx_RefNannyDeclarations
12399   PyObject *__pyx_t_1 = NULL;
12400   PyObject *__pyx_t_2 = NULL;
12401   int __pyx_lineno = 0;
12402   const char *__pyx_filename = NULL;
12403   int __pyx_clineno = 0;
12404   __Pyx_TraceDeclarations
12405   __Pyx_RefNannySetupContext("__exit__", 0);
12406   __Pyx_TraceCall("__exit__", __pyx_f[0], 1177);
12407
12408   /* "csamtools.pyx":1178
12409  * 
12410  *     def __exit__(self, exc_type, exc_value, traceback):
12411  *         self.close()             # <<<<<<<<<<<<<<
12412  *         return False
12413  * 
12414  */
12415   __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 = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12416   __Pyx_GOTREF(__pyx_t_1);
12417   __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 = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12418   __Pyx_GOTREF(__pyx_t_2);
12419   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12420   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12421
12422   /* "csamtools.pyx":1179
12423  *     def __exit__(self, exc_type, exc_value, traceback):
12424  *         self.close()
12425  *         return False             # <<<<<<<<<<<<<<
12426  * 
12427  *     ###############################################################
12428  */
12429   __Pyx_XDECREF(__pyx_r);
12430   __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12431   __Pyx_GOTREF(__pyx_t_2);
12432   __pyx_r = __pyx_t_2;
12433   __pyx_t_2 = 0;
12434   goto __pyx_L0;
12435
12436   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12437   goto __pyx_L0;
12438   __pyx_L1_error:;
12439   __Pyx_XDECREF(__pyx_t_1);
12440   __Pyx_XDECREF(__pyx_t_2);
12441   __Pyx_AddTraceback("csamtools.Samfile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12442   __pyx_r = NULL;
12443   __pyx_L0:;
12444   __Pyx_XGIVEREF(__pyx_r);
12445   __Pyx_TraceReturn(__pyx_r);
12446   __Pyx_RefNannyFinishContext();
12447   return __pyx_r;
12448 }
12449
12450 /* Python wrapper */
12451 static PyObject *__pyx_pw_9csamtools_7Samfile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
12452 static PyObject *__pyx_pw_9csamtools_7Samfile_8filename_1__get__(PyObject *__pyx_v_self) {
12453   PyObject *__pyx_r = 0;
12454   __Pyx_RefNannyDeclarations
12455   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
12456   __pyx_r = __pyx_pf_9csamtools_7Samfile_8filename___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12457   __Pyx_RefNannyFinishContext();
12458   return __pyx_r;
12459 }
12460
12461 /* "csamtools.pyx":1188
12462  *     property filename:
12463  *         '''number of :term:`filename` associated with this object.'''
12464  *         def __get__(self):             # <<<<<<<<<<<<<<
12465  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12466  *             return self._filename
12467  */
12468
12469 static PyObject *__pyx_pf_9csamtools_7Samfile_8filename___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12470   PyObject *__pyx_r = NULL;
12471   __Pyx_RefNannyDeclarations
12472   PyObject *__pyx_t_1 = NULL;
12473   PyObject *__pyx_t_2 = NULL;
12474   int __pyx_t_3;
12475   int __pyx_t_4;
12476   int __pyx_lineno = 0;
12477   const char *__pyx_filename = NULL;
12478   int __pyx_clineno = 0;
12479   __Pyx_TraceDeclarations
12480   __Pyx_RefNannySetupContext("__get__", 0);
12481   __Pyx_TraceCall("__get__", __pyx_f[0], 1188);
12482
12483   /* "csamtools.pyx":1189
12484  *         '''number of :term:`filename` associated with this object.'''
12485  *         def __get__(self):
12486  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12487  *             return self._filename
12488  * 
12489  */
12490   __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 = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12491   __Pyx_GOTREF(__pyx_t_1);
12492   __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 = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12493   __Pyx_GOTREF(__pyx_t_2);
12494   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12495   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12496   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12497   __pyx_t_4 = (!__pyx_t_3);
12498   if (__pyx_t_4) {
12499     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_87), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12500     __Pyx_GOTREF(__pyx_t_2);
12501     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12502     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12503     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12504     goto __pyx_L3;
12505   }
12506   __pyx_L3:;
12507
12508   /* "csamtools.pyx":1190
12509  *         def __get__(self):
12510  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12511  *             return self._filename             # <<<<<<<<<<<<<<
12512  * 
12513  *     property nreferences:
12514  */
12515   __Pyx_XDECREF(__pyx_r);
12516   __pyx_t_2 = PyBytes_FromString(__pyx_v_self->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12517   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
12518   __pyx_r = ((PyObject *)__pyx_t_2);
12519   __pyx_t_2 = 0;
12520   goto __pyx_L0;
12521
12522   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12523   goto __pyx_L0;
12524   __pyx_L1_error:;
12525   __Pyx_XDECREF(__pyx_t_1);
12526   __Pyx_XDECREF(__pyx_t_2);
12527   __Pyx_AddTraceback("csamtools.Samfile.filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12528   __pyx_r = NULL;
12529   __pyx_L0:;
12530   __Pyx_XGIVEREF(__pyx_r);
12531   __Pyx_TraceReturn(__pyx_r);
12532   __Pyx_RefNannyFinishContext();
12533   return __pyx_r;
12534 }
12535
12536 /* Python wrapper */
12537 static PyObject *__pyx_pw_9csamtools_7Samfile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
12538 static PyObject *__pyx_pw_9csamtools_7Samfile_11nreferences_1__get__(PyObject *__pyx_v_self) {
12539   PyObject *__pyx_r = 0;
12540   __Pyx_RefNannyDeclarations
12541   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
12542   __pyx_r = __pyx_pf_9csamtools_7Samfile_11nreferences___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12543   __Pyx_RefNannyFinishContext();
12544   return __pyx_r;
12545 }
12546
12547 /* "csamtools.pyx":1194
12548  *     property nreferences:
12549  *         '''number of :term:`reference` sequences in the file.'''
12550  *         def __get__(self):             # <<<<<<<<<<<<<<
12551  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12552  *             return self.samfile.header.n_targets
12553  */
12554
12555 static PyObject *__pyx_pf_9csamtools_7Samfile_11nreferences___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12556   PyObject *__pyx_r = NULL;
12557   __Pyx_RefNannyDeclarations
12558   PyObject *__pyx_t_1 = NULL;
12559   PyObject *__pyx_t_2 = NULL;
12560   int __pyx_t_3;
12561   int __pyx_t_4;
12562   int __pyx_lineno = 0;
12563   const char *__pyx_filename = NULL;
12564   int __pyx_clineno = 0;
12565   __Pyx_TraceDeclarations
12566   __Pyx_RefNannySetupContext("__get__", 0);
12567   __Pyx_TraceCall("__get__", __pyx_f[0], 1194);
12568
12569   /* "csamtools.pyx":1195
12570  *         '''number of :term:`reference` sequences in the file.'''
12571  *         def __get__(self):
12572  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12573  *             return self.samfile.header.n_targets
12574  * 
12575  */
12576   __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 = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12577   __Pyx_GOTREF(__pyx_t_1);
12578   __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 = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12579   __Pyx_GOTREF(__pyx_t_2);
12580   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12581   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12582   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12583   __pyx_t_4 = (!__pyx_t_3);
12584   if (__pyx_t_4) {
12585     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12586     __Pyx_GOTREF(__pyx_t_2);
12587     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12588     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12589     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12590     goto __pyx_L3;
12591   }
12592   __pyx_L3:;
12593
12594   /* "csamtools.pyx":1196
12595  *         def __get__(self):
12596  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12597  *             return self.samfile.header.n_targets             # <<<<<<<<<<<<<<
12598  * 
12599  *     property references:
12600  */
12601   __Pyx_XDECREF(__pyx_r);
12602   __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 = 1196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12603   __Pyx_GOTREF(__pyx_t_2);
12604   __pyx_r = __pyx_t_2;
12605   __pyx_t_2 = 0;
12606   goto __pyx_L0;
12607
12608   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12609   goto __pyx_L0;
12610   __pyx_L1_error:;
12611   __Pyx_XDECREF(__pyx_t_1);
12612   __Pyx_XDECREF(__pyx_t_2);
12613   __Pyx_AddTraceback("csamtools.Samfile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12614   __pyx_r = NULL;
12615   __pyx_L0:;
12616   __Pyx_XGIVEREF(__pyx_r);
12617   __Pyx_TraceReturn(__pyx_r);
12618   __Pyx_RefNannyFinishContext();
12619   return __pyx_r;
12620 }
12621
12622 /* Python wrapper */
12623 static PyObject *__pyx_pw_9csamtools_7Samfile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
12624 static PyObject *__pyx_pw_9csamtools_7Samfile_10references_1__get__(PyObject *__pyx_v_self) {
12625   PyObject *__pyx_r = 0;
12626   __Pyx_RefNannyDeclarations
12627   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
12628   __pyx_r = __pyx_pf_9csamtools_7Samfile_10references___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12629   __Pyx_RefNannyFinishContext();
12630   return __pyx_r;
12631 }
12632
12633 /* "csamtools.pyx":1200
12634  *     property references:
12635  *         """tuple with the names of :term:`reference` sequences."""
12636  *         def __get__(self):             # <<<<<<<<<<<<<<
12637  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12638  *             t = []
12639  */
12640
12641 static PyObject *__pyx_pf_9csamtools_7Samfile_10references___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12642   PyObject *__pyx_v_t = NULL;
12643   long __pyx_v_x;
12644   PyObject *__pyx_r = NULL;
12645   __Pyx_RefNannyDeclarations
12646   PyObject *__pyx_t_1 = NULL;
12647   PyObject *__pyx_t_2 = NULL;
12648   int __pyx_t_3;
12649   int __pyx_t_4;
12650   int32_t __pyx_t_5;
12651   int __pyx_t_6;
12652   int __pyx_lineno = 0;
12653   const char *__pyx_filename = NULL;
12654   int __pyx_clineno = 0;
12655   __Pyx_TraceDeclarations
12656   __Pyx_RefNannySetupContext("__get__", 0);
12657   __Pyx_TraceCall("__get__", __pyx_f[0], 1200);
12658
12659   /* "csamtools.pyx":1201
12660  *         """tuple with the names of :term:`reference` sequences."""
12661  *         def __get__(self):
12662  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12663  *             t = []
12664  *             for x from 0 <= x < self.samfile.header.n_targets:
12665  */
12666   __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 = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12667   __Pyx_GOTREF(__pyx_t_1);
12668   __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 = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12669   __Pyx_GOTREF(__pyx_t_2);
12670   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12671   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12672   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12673   __pyx_t_4 = (!__pyx_t_3);
12674   if (__pyx_t_4) {
12675     __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 = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12676     __Pyx_GOTREF(__pyx_t_2);
12677     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12678     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12679     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12680     goto __pyx_L3;
12681   }
12682   __pyx_L3:;
12683
12684   /* "csamtools.pyx":1202
12685  *         def __get__(self):
12686  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12687  *             t = []             # <<<<<<<<<<<<<<
12688  *             for x from 0 <= x < self.samfile.header.n_targets:
12689  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )
12690  */
12691   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12692   __Pyx_GOTREF(__pyx_t_2);
12693   __pyx_v_t = __pyx_t_2;
12694   __pyx_t_2 = 0;
12695
12696   /* "csamtools.pyx":1203
12697  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12698  *             t = []
12699  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
12700  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )
12701  *             return tuple(t)
12702  */
12703   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
12704   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
12705
12706     /* "csamtools.pyx":1204
12707  *             t = []
12708  *             for x from 0 <= x < self.samfile.header.n_targets:
12709  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )             # <<<<<<<<<<<<<<
12710  *             return tuple(t)
12711  * 
12712  */
12713     __pyx_t_2 = __pyx_f_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 = 1204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12714     __Pyx_GOTREF(__pyx_t_2);
12715     __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12716     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12717   }
12718
12719   /* "csamtools.pyx":1205
12720  *             for x from 0 <= x < self.samfile.header.n_targets:
12721  *                 t.append( _charptr_to_str(self.samfile.header.target_name[x]) )
12722  *             return tuple(t)             # <<<<<<<<<<<<<<
12723  * 
12724  *     property lengths:
12725  */
12726   __Pyx_XDECREF(__pyx_r);
12727   __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12728   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
12729   __pyx_r = ((PyObject *)__pyx_t_2);
12730   __pyx_t_2 = 0;
12731   goto __pyx_L0;
12732
12733   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12734   goto __pyx_L0;
12735   __pyx_L1_error:;
12736   __Pyx_XDECREF(__pyx_t_1);
12737   __Pyx_XDECREF(__pyx_t_2);
12738   __Pyx_AddTraceback("csamtools.Samfile.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12739   __pyx_r = NULL;
12740   __pyx_L0:;
12741   __Pyx_XDECREF(__pyx_v_t);
12742   __Pyx_XGIVEREF(__pyx_r);
12743   __Pyx_TraceReturn(__pyx_r);
12744   __Pyx_RefNannyFinishContext();
12745   return __pyx_r;
12746 }
12747
12748 /* Python wrapper */
12749 static PyObject *__pyx_pw_9csamtools_7Samfile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
12750 static PyObject *__pyx_pw_9csamtools_7Samfile_7lengths_1__get__(PyObject *__pyx_v_self) {
12751   PyObject *__pyx_r = 0;
12752   __Pyx_RefNannyDeclarations
12753   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
12754   __pyx_r = __pyx_pf_9csamtools_7Samfile_7lengths___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12755   __Pyx_RefNannyFinishContext();
12756   return __pyx_r;
12757 }
12758
12759 /* "csamtools.pyx":1211
12760  *         :attr:`pysam.Samfile.references`
12761  *         """
12762  *         def __get__(self):             # <<<<<<<<<<<<<<
12763  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12764  *             t = []
12765  */
12766
12767 static PyObject *__pyx_pf_9csamtools_7Samfile_7lengths___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12768   PyObject *__pyx_v_t = NULL;
12769   long __pyx_v_x;
12770   PyObject *__pyx_r = NULL;
12771   __Pyx_RefNannyDeclarations
12772   PyObject *__pyx_t_1 = NULL;
12773   PyObject *__pyx_t_2 = NULL;
12774   int __pyx_t_3;
12775   int __pyx_t_4;
12776   int32_t __pyx_t_5;
12777   int __pyx_t_6;
12778   int __pyx_lineno = 0;
12779   const char *__pyx_filename = NULL;
12780   int __pyx_clineno = 0;
12781   __Pyx_TraceDeclarations
12782   __Pyx_RefNannySetupContext("__get__", 0);
12783   __Pyx_TraceCall("__get__", __pyx_f[0], 1211);
12784
12785   /* "csamtools.pyx":1212
12786  *         """
12787  *         def __get__(self):
12788  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12789  *             t = []
12790  *             for x from 0 <= x < self.samfile.header.n_targets:
12791  */
12792   __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 = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12793   __Pyx_GOTREF(__pyx_t_1);
12794   __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 = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12795   __Pyx_GOTREF(__pyx_t_2);
12796   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12797   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12798   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12799   __pyx_t_4 = (!__pyx_t_3);
12800   if (__pyx_t_4) {
12801     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_90), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12802     __Pyx_GOTREF(__pyx_t_2);
12803     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12804     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12805     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12806     goto __pyx_L3;
12807   }
12808   __pyx_L3:;
12809
12810   /* "csamtools.pyx":1213
12811  *         def __get__(self):
12812  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12813  *             t = []             # <<<<<<<<<<<<<<
12814  *             for x from 0 <= x < self.samfile.header.n_targets:
12815  *                 t.append( self.samfile.header.target_len[x] )
12816  */
12817   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12818   __Pyx_GOTREF(__pyx_t_2);
12819   __pyx_v_t = __pyx_t_2;
12820   __pyx_t_2 = 0;
12821
12822   /* "csamtools.pyx":1214
12823  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12824  *             t = []
12825  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
12826  *                 t.append( self.samfile.header.target_len[x] )
12827  *             return tuple(t)
12828  */
12829   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
12830   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
12831
12832     /* "csamtools.pyx":1215
12833  *             t = []
12834  *             for x from 0 <= x < self.samfile.header.n_targets:
12835  *                 t.append( self.samfile.header.target_len[x] )             # <<<<<<<<<<<<<<
12836  *             return tuple(t)
12837  * 
12838  */
12839     __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 = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12840     __Pyx_GOTREF(__pyx_t_2);
12841     __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12842     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12843   }
12844
12845   /* "csamtools.pyx":1216
12846  *             for x from 0 <= x < self.samfile.header.n_targets:
12847  *                 t.append( self.samfile.header.target_len[x] )
12848  *             return tuple(t)             # <<<<<<<<<<<<<<
12849  * 
12850  *     property mapped:
12851  */
12852   __Pyx_XDECREF(__pyx_r);
12853   __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12854   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
12855   __pyx_r = ((PyObject *)__pyx_t_2);
12856   __pyx_t_2 = 0;
12857   goto __pyx_L0;
12858
12859   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12860   goto __pyx_L0;
12861   __pyx_L1_error:;
12862   __Pyx_XDECREF(__pyx_t_1);
12863   __Pyx_XDECREF(__pyx_t_2);
12864   __Pyx_AddTraceback("csamtools.Samfile.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
12865   __pyx_r = NULL;
12866   __pyx_L0:;
12867   __Pyx_XDECREF(__pyx_v_t);
12868   __Pyx_XGIVEREF(__pyx_r);
12869   __Pyx_TraceReturn(__pyx_r);
12870   __Pyx_RefNannyFinishContext();
12871   return __pyx_r;
12872 }
12873
12874 /* Python wrapper */
12875 static PyObject *__pyx_pw_9csamtools_7Samfile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/
12876 static PyObject *__pyx_pw_9csamtools_7Samfile_6mapped_1__get__(PyObject *__pyx_v_self) {
12877   PyObject *__pyx_r = 0;
12878   __Pyx_RefNannyDeclarations
12879   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
12880   __pyx_r = __pyx_pf_9csamtools_7Samfile_6mapped___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
12881   __Pyx_RefNannyFinishContext();
12882   return __pyx_r;
12883 }
12884
12885 /* "csamtools.pyx":1221
12886  *         """total number of mapped reads in file.
12887  *         """
12888  *         def __get__(self):             # <<<<<<<<<<<<<<
12889  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12890  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
12891  */
12892
12893 static PyObject *__pyx_pf_9csamtools_7Samfile_6mapped___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12894   int __pyx_v_tid;
12895   uint32_t __pyx_v_total;
12896   PyObject *__pyx_r = NULL;
12897   __Pyx_RefNannyDeclarations
12898   PyObject *__pyx_t_1 = NULL;
12899   PyObject *__pyx_t_2 = NULL;
12900   int __pyx_t_3;
12901   int __pyx_t_4;
12902   int32_t __pyx_t_5;
12903   int __pyx_lineno = 0;
12904   const char *__pyx_filename = NULL;
12905   int __pyx_clineno = 0;
12906   __Pyx_TraceDeclarations
12907   __Pyx_RefNannySetupContext("__get__", 0);
12908   __Pyx_TraceCall("__get__", __pyx_f[0], 1221);
12909
12910   /* "csamtools.pyx":1222
12911  *         """
12912  *         def __get__(self):
12913  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12914  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
12915  * 
12916  */
12917   __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 = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12918   __Pyx_GOTREF(__pyx_t_1);
12919   __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 = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12920   __Pyx_GOTREF(__pyx_t_2);
12921   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12922   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12923   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12924   __pyx_t_4 = (!__pyx_t_3);
12925   if (__pyx_t_4) {
12926     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12927     __Pyx_GOTREF(__pyx_t_2);
12928     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12929     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12930     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12931     goto __pyx_L3;
12932   }
12933   __pyx_L3:;
12934
12935   /* "csamtools.pyx":1223
12936  *         def __get__(self):
12937  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12938  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
12939  * 
12940  *             cdef int tid
12941  */
12942   __pyx_t_4 = (!__pyx_v_self->isbam);
12943   if (__pyx_t_4) {
12944     __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_93), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12945     __Pyx_GOTREF(__pyx_t_2);
12946     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
12947     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12948     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12949     goto __pyx_L4;
12950   }
12951   __pyx_L4:;
12952
12953   /* "csamtools.pyx":1226
12954  * 
12955  *             cdef int tid
12956  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
12957  *             for tid from 0 <= tid < self.samfile.header.n_targets:
12958  *                 total += pysam_get_mapped( self.index, tid )
12959  */
12960   __pyx_v_total = 0;
12961
12962   /* "csamtools.pyx":1227
12963  *             cdef int tid
12964  *             cdef uint32_t total = 0
12965  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
12966  *                 total += pysam_get_mapped( self.index, tid )
12967  *             return total
12968  */
12969   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
12970   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
12971
12972     /* "csamtools.pyx":1228
12973  *             cdef uint32_t total = 0
12974  *             for tid from 0 <= tid < self.samfile.header.n_targets:
12975  *                 total += pysam_get_mapped( self.index, tid )             # <<<<<<<<<<<<<<
12976  *             return total
12977  * 
12978  */
12979     __pyx_v_total = (__pyx_v_total + pysam_get_mapped(__pyx_v_self->index, __pyx_v_tid));
12980   }
12981
12982   /* "csamtools.pyx":1229
12983  *             for tid from 0 <= tid < self.samfile.header.n_targets:
12984  *                 total += pysam_get_mapped( self.index, tid )
12985  *             return total             # <<<<<<<<<<<<<<
12986  * 
12987  *     property unmapped:
12988  */
12989   __Pyx_XDECREF(__pyx_r);
12990   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12991   __Pyx_GOTREF(__pyx_t_2);
12992   __pyx_r = __pyx_t_2;
12993   __pyx_t_2 = 0;
12994   goto __pyx_L0;
12995
12996   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12997   goto __pyx_L0;
12998   __pyx_L1_error:;
12999   __Pyx_XDECREF(__pyx_t_1);
13000   __Pyx_XDECREF(__pyx_t_2);
13001   __Pyx_AddTraceback("csamtools.Samfile.mapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
13002   __pyx_r = NULL;
13003   __pyx_L0:;
13004   __Pyx_XGIVEREF(__pyx_r);
13005   __Pyx_TraceReturn(__pyx_r);
13006   __Pyx_RefNannyFinishContext();
13007   return __pyx_r;
13008 }
13009
13010 /* Python wrapper */
13011 static PyObject *__pyx_pw_9csamtools_7Samfile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
13012 static PyObject *__pyx_pw_9csamtools_7Samfile_8unmapped_1__get__(PyObject *__pyx_v_self) {
13013   PyObject *__pyx_r = 0;
13014   __Pyx_RefNannyDeclarations
13015   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
13016   __pyx_r = __pyx_pf_9csamtools_7Samfile_8unmapped___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
13017   __Pyx_RefNannyFinishContext();
13018   return __pyx_r;
13019 }
13020
13021 /* "csamtools.pyx":1234
13022  *         """total number of unmapped reads in file.
13023  *         """
13024  *         def __get__(self):             # <<<<<<<<<<<<<<
13025  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13026  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
13027  */
13028
13029 static PyObject *__pyx_pf_9csamtools_7Samfile_8unmapped___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
13030   int __pyx_v_tid;
13031   uint32_t __pyx_v_total;
13032   PyObject *__pyx_r = NULL;
13033   __Pyx_RefNannyDeclarations
13034   PyObject *__pyx_t_1 = NULL;
13035   PyObject *__pyx_t_2 = NULL;
13036   int __pyx_t_3;
13037   int __pyx_t_4;
13038   int32_t __pyx_t_5;
13039   int __pyx_lineno = 0;
13040   const char *__pyx_filename = NULL;
13041   int __pyx_clineno = 0;
13042   __Pyx_TraceDeclarations
13043   __Pyx_RefNannySetupContext("__get__", 0);
13044   __Pyx_TraceCall("__get__", __pyx_f[0], 1234);
13045
13046   /* "csamtools.pyx":1235
13047  *         """
13048  *         def __get__(self):
13049  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
13050  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
13051  *             cdef int tid
13052  */
13053   __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 = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13054   __Pyx_GOTREF(__pyx_t_1);
13055   __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 = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13056   __Pyx_GOTREF(__pyx_t_2);
13057   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13058   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13059   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13060   __pyx_t_4 = (!__pyx_t_3);
13061   if (__pyx_t_4) {
13062     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13063     __Pyx_GOTREF(__pyx_t_2);
13064     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
13065     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13066     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13067     goto __pyx_L3;
13068   }
13069   __pyx_L3:;
13070
13071   /* "csamtools.pyx":1236
13072  *         def __get__(self):
13073  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13074  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
13075  *             cdef int tid
13076  *             cdef uint32_t total = 0
13077  */
13078   __pyx_t_4 = (!__pyx_v_self->isbam);
13079   if (__pyx_t_4) {
13080     __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_96), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13081     __Pyx_GOTREF(__pyx_t_2);
13082     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
13083     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13084     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13085     goto __pyx_L4;
13086   }
13087   __pyx_L4:;
13088
13089   /* "csamtools.pyx":1238
13090  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
13091  *             cdef int tid
13092  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
13093  *             for tid from 0 <= tid < self.samfile.header.n_targets:
13094  *                 total += pysam_get_unmapped( self.index, tid )
13095  */
13096   __pyx_v_total = 0;
13097
13098   /* "csamtools.pyx":1239
13099  *             cdef int tid
13100  *             cdef uint32_t total = 0
13101  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
13102  *                 total += pysam_get_unmapped( self.index, tid )
13103  *             # get unmapped reads without coordinates
13104  */
13105   __pyx_t_5 = __pyx_v_self->samfile->header->n_targets;
13106   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
13107
13108     /* "csamtools.pyx":1240
13109  *             cdef uint32_t total = 0
13110  *             for tid from 0 <= tid < self.samfile.header.n_targets:
13111  *                 total += pysam_get_unmapped( self.index, tid )             # <<<<<<<<<<<<<<
13112  *             # get unmapped reads without coordinates
13113  *             total += pysam_get_unmapped( self.index, -1 )
13114  */
13115     __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(__pyx_v_self->index, __pyx_v_tid));
13116   }
13117
13118   /* "csamtools.pyx":1242
13119  *                 total += pysam_get_unmapped( self.index, tid )
13120  *             # get unmapped reads without coordinates
13121  *             total += pysam_get_unmapped( self.index, -1 )             # <<<<<<<<<<<<<<
13122  *             return total
13123  * 
13124  */
13125   __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(__pyx_v_self->index, -1));
13126
13127   /* "csamtools.pyx":1243
13128  *             # get unmapped reads without coordinates
13129  *             total += pysam_get_unmapped( self.index, -1 )
13130  *             return total             # <<<<<<<<<<<<<<
13131  * 
13132  *     property text:
13133  */
13134   __Pyx_XDECREF(__pyx_r);
13135   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13136   __Pyx_GOTREF(__pyx_t_2);
13137   __pyx_r = __pyx_t_2;
13138   __pyx_t_2 = 0;
13139   goto __pyx_L0;
13140
13141   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13142   goto __pyx_L0;
13143   __pyx_L1_error:;
13144   __Pyx_XDECREF(__pyx_t_1);
13145   __Pyx_XDECREF(__pyx_t_2);
13146   __Pyx_AddTraceback("csamtools.Samfile.unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
13147   __pyx_r = NULL;
13148   __pyx_L0:;
13149   __Pyx_XGIVEREF(__pyx_r);
13150   __Pyx_TraceReturn(__pyx_r);
13151   __Pyx_RefNannyFinishContext();
13152   return __pyx_r;
13153 }
13154
13155 /* Python wrapper */
13156 static PyObject *__pyx_pw_9csamtools_7Samfile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
13157 static PyObject *__pyx_pw_9csamtools_7Samfile_4text_1__get__(PyObject *__pyx_v_self) {
13158   PyObject *__pyx_r = 0;
13159   __Pyx_RefNannyDeclarations
13160   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
13161   __pyx_r = __pyx_pf_9csamtools_7Samfile_4text___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
13162   __Pyx_RefNannyFinishContext();
13163   return __pyx_r;
13164 }
13165
13166 /* "csamtools.pyx":1247
13167  *     property text:
13168  *         '''full contents of the :term:`sam file` header as a string.'''
13169  *         def __get__(self):             # <<<<<<<<<<<<<<
13170  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13171  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)
13172  */
13173
13174 static PyObject *__pyx_pf_9csamtools_7Samfile_4text___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
13175   PyObject *__pyx_r = NULL;
13176   __Pyx_RefNannyDeclarations
13177   PyObject *__pyx_t_1 = NULL;
13178   PyObject *__pyx_t_2 = NULL;
13179   int __pyx_t_3;
13180   int __pyx_t_4;
13181   int __pyx_lineno = 0;
13182   const char *__pyx_filename = NULL;
13183   int __pyx_clineno = 0;
13184   __Pyx_TraceDeclarations
13185   __Pyx_RefNannySetupContext("__get__", 0);
13186   __Pyx_TraceCall("__get__", __pyx_f[0], 1247);
13187
13188   /* "csamtools.pyx":1248
13189  *         '''full contents of the :term:`sam file` header as a string.'''
13190  *         def __get__(self):
13191  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
13192  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)
13193  * 
13194  */
13195   __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;}
13196   __Pyx_GOTREF(__pyx_t_1);
13197   __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;}
13198   __Pyx_GOTREF(__pyx_t_2);
13199   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13200   __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;}
13201   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13202   __pyx_t_4 = (!__pyx_t_3);
13203   if (__pyx_t_4) {
13204     __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 = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13205     __Pyx_GOTREF(__pyx_t_2);
13206     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
13207     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13208     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13209     goto __pyx_L3;
13210   }
13211   __pyx_L3:;
13212
13213   /* "csamtools.pyx":1249
13214  *         def __get__(self):
13215  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13216  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)             # <<<<<<<<<<<<<<
13217  * 
13218  *     property header:
13219  */
13220   __Pyx_XDECREF(__pyx_r);
13221   __pyx_t_2 = __pyx_f_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 = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13222   __Pyx_GOTREF(__pyx_t_2);
13223   __pyx_r = __pyx_t_2;
13224   __pyx_t_2 = 0;
13225   goto __pyx_L0;
13226
13227   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13228   goto __pyx_L0;
13229   __pyx_L1_error:;
13230   __Pyx_XDECREF(__pyx_t_1);
13231   __Pyx_XDECREF(__pyx_t_2);
13232   __Pyx_AddTraceback("csamtools.Samfile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
13233   __pyx_r = NULL;
13234   __pyx_L0:;
13235   __Pyx_XGIVEREF(__pyx_r);
13236   __Pyx_TraceReturn(__pyx_r);
13237   __Pyx_RefNannyFinishContext();
13238   return __pyx_r;
13239 }
13240
13241 /* Python wrapper */
13242 static PyObject *__pyx_pw_9csamtools_7Samfile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/
13243 static PyObject *__pyx_pw_9csamtools_7Samfile_6header_1__get__(PyObject *__pyx_v_self) {
13244   PyObject *__pyx_r = 0;
13245   __Pyx_RefNannyDeclarations
13246   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
13247   __pyx_r = __pyx_pf_9csamtools_7Samfile_6header___get__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
13248   __Pyx_RefNannyFinishContext();
13249   return __pyx_r;
13250 }
13251
13252 /* "csamtools.pyx":1255
13253  *         a two-level dictionary.
13254  *         '''
13255  *         def __get__(self):             # <<<<<<<<<<<<<<
13256  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13257  * 
13258  */
13259
13260 static PyObject *__pyx_pf_9csamtools_7Samfile_6header___get__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
13261   PyObject *__pyx_v_result = NULL;
13262   PyObject *__pyx_v_t = NULL;
13263   PyObject *__pyx_v_line = NULL;
13264   PyObject *__pyx_v_fields = NULL;
13265   PyObject *__pyx_v_record = NULL;
13266   PyObject *__pyx_v_x = NULL;
13267   PyObject *__pyx_v_field = NULL;
13268   PyObject *__pyx_v_key = NULL;
13269   PyObject *__pyx_v_value = NULL;
13270   PyObject *__pyx_v_sq = NULL;
13271   PyObject *__pyx_v_ref = NULL;
13272   PyObject *__pyx_v_length = NULL;
13273   PyObject *__pyx_r = NULL;
13274   __Pyx_RefNannyDeclarations
13275   PyObject *__pyx_t_1 = NULL;
13276   PyObject *__pyx_t_2 = NULL;
13277   int __pyx_t_3;
13278   int __pyx_t_4;
13279   Py_ssize_t __pyx_t_5;
13280   PyObject *(*__pyx_t_6)(PyObject *);
13281   PyObject *__pyx_t_7 = NULL;
13282   PyObject *__pyx_t_8 = NULL;
13283   PyObject *__pyx_t_9 = NULL;
13284   Py_ssize_t __pyx_t_10;
13285   PyObject *(*__pyx_t_11)(PyObject *);
13286   PyObject *__pyx_t_12 = NULL;
13287   PyObject *(*__pyx_t_13)(PyObject *);
13288   int __pyx_t_14;
13289   int __pyx_lineno = 0;
13290   const char *__pyx_filename = NULL;
13291   int __pyx_clineno = 0;
13292   __Pyx_TraceDeclarations
13293   __Pyx_RefNannySetupContext("__get__", 0);
13294   __Pyx_TraceCall("__get__", __pyx_f[0], 1255);
13295
13296   /* "csamtools.pyx":1256
13297  *         '''
13298  *         def __get__(self):
13299  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
13300  * 
13301  *             result = {}
13302  */
13303   __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 = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13304   __Pyx_GOTREF(__pyx_t_1);
13305   __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 = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13306   __Pyx_GOTREF(__pyx_t_2);
13307   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13308   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13309   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13310   __pyx_t_4 = (!__pyx_t_3);
13311   if (__pyx_t_4) {
13312     __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 = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13313     __Pyx_GOTREF(__pyx_t_2);
13314     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
13315     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13316     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13317     goto __pyx_L3;
13318   }
13319   __pyx_L3:;
13320
13321   /* "csamtools.pyx":1258
13322  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
13323  * 
13324  *             result = {}             # <<<<<<<<<<<<<<
13325  * 
13326  *             if self.samfile.header.text != NULL:
13327  */
13328   __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13329   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
13330   __pyx_v_result = __pyx_t_2;
13331   __pyx_t_2 = 0;
13332
13333   /* "csamtools.pyx":1260
13334  *             result = {}
13335  * 
13336  *             if self.samfile.header.text != NULL:             # <<<<<<<<<<<<<<
13337  *                 # convert to python string (note: call self.text to create 0-terminated string)
13338  *                 t = self.text
13339  */
13340   __pyx_t_4 = (__pyx_v_self->samfile->header->text != NULL);
13341   if (__pyx_t_4) {
13342
13343     /* "csamtools.pyx":1262
13344  *             if self.samfile.header.text != NULL:
13345  *                 # convert to python string (note: call self.text to create 0-terminated string)
13346  *                 t = self.text             # <<<<<<<<<<<<<<
13347  *                 for line in t.split("\n"):
13348  *                     if not line.strip(): continue
13349  */
13350     __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 = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13351     __Pyx_GOTREF(__pyx_t_2);
13352     __pyx_v_t = __pyx_t_2;
13353     __pyx_t_2 = 0;
13354
13355     /* "csamtools.pyx":1263
13356  *                 # convert to python string (note: call self.text to create 0-terminated string)
13357  *                 t = self.text
13358  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
13359  *                     if not line.strip(): continue
13360  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
13361  */
13362     __pyx_t_2 = PyObject_GetAttr(__pyx_v_t, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13363     __Pyx_GOTREF(__pyx_t_2);
13364     __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_99), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13365     __Pyx_GOTREF(__pyx_t_1);
13366     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13367     if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
13368       __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
13369       __pyx_t_6 = NULL;
13370     } else {
13371       __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13372       __Pyx_GOTREF(__pyx_t_2);
13373       __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext;
13374     }
13375     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13376     for (;;) {
13377       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) {
13378         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
13379         __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
13380       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) {
13381         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
13382         __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
13383       } else {
13384         __pyx_t_1 = __pyx_t_6(__pyx_t_2);
13385         if (unlikely(!__pyx_t_1)) {
13386           if (PyErr_Occurred()) {
13387             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
13388             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13389           }
13390           break;
13391         }
13392         __Pyx_GOTREF(__pyx_t_1);
13393       }
13394       __Pyx_XDECREF(__pyx_v_line);
13395       __pyx_v_line = __pyx_t_1;
13396       __pyx_t_1 = 0;
13397
13398       /* "csamtools.pyx":1264
13399  *                 t = self.text
13400  *                 for line in t.split("\n"):
13401  *                     if not line.strip(): continue             # <<<<<<<<<<<<<<
13402  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
13403  *                     fields = line[1:].split("\t")
13404  */
13405       __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13406       __Pyx_GOTREF(__pyx_t_1);
13407       __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 = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13408       __Pyx_GOTREF(__pyx_t_7);
13409       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13410       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13411       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13412       __pyx_t_3 = (!__pyx_t_4);
13413       if (__pyx_t_3) {
13414         goto __pyx_L5_continue;
13415         goto __pyx_L7;
13416       }
13417       __pyx_L7:;
13418
13419       /* "csamtools.pyx":1265
13420  *                 for line in t.split("\n"):
13421  *                     if not line.strip(): continue
13422  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
13423  *                     fields = line[1:].split("\t")
13424  *                     record = fields[0]
13425  */
13426       #ifndef CYTHON_WITHOUT_ASSERTIONS
13427       __pyx_t_7 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13428       __Pyx_GOTREF(__pyx_t_7);
13429       __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_101), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13430       __Pyx_GOTREF(__pyx_t_1);
13431       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13432       __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13433       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13434       if (unlikely(!__pyx_t_3)) {
13435         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_102), __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13436         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
13437         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_1));
13438         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
13439         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13440       }
13441       #endif
13442
13443       /* "csamtools.pyx":1266
13444  *                     if not line.strip(): continue
13445  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
13446  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
13447  *                     record = fields[0]
13448  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
13449  */
13450       __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 = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13451       __Pyx_GOTREF(__pyx_t_1);
13452       __pyx_t_7 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13453       __Pyx_GOTREF(__pyx_t_7);
13454       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13455       __pyx_t_1 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_103), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13456       __Pyx_GOTREF(__pyx_t_1);
13457       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13458       __Pyx_XDECREF(__pyx_v_fields);
13459       __pyx_v_fields = __pyx_t_1;
13460       __pyx_t_1 = 0;
13461
13462       /* "csamtools.pyx":1267
13463  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
13464  *                     fields = line[1:].split("\t")
13465  *                     record = fields[0]             # <<<<<<<<<<<<<<
13466  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
13467  * 
13468  */
13469       __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13470       __Pyx_GOTREF(__pyx_t_1);
13471       __Pyx_XDECREF(__pyx_v_record);
13472       __pyx_v_record = __pyx_t_1;
13473       __pyx_t_1 = 0;
13474
13475       /* "csamtools.pyx":1268
13476  *                     fields = line[1:].split("\t")
13477  *                     record = fields[0]
13478  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
13479  * 
13480  *                     # treat comments
13481  */
13482       #ifndef CYTHON_WITHOUT_ASSERTIONS
13483       __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 = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13484       __Pyx_GOTREF(__pyx_t_1);
13485       __pyx_t_3 = ((PySequence_Contains(__pyx_t_1, __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13486       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13487       if (unlikely(!__pyx_t_3)) {
13488         __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13489         __Pyx_GOTREF(__pyx_t_1);
13490         __Pyx_INCREF(__pyx_v_record);
13491         PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_record);
13492         __Pyx_GIVEREF(__pyx_v_record);
13493         __Pyx_INCREF(__pyx_v_line);
13494         PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_line);
13495         __Pyx_GIVEREF(__pyx_v_line);
13496         __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_104), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13497         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
13498         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
13499         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_7));
13500         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
13501         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13502       }
13503       #endif
13504
13505       /* "csamtools.pyx":1271
13506  * 
13507  *                     # treat comments
13508  *                     if record == "CO":             # <<<<<<<<<<<<<<
13509  *                         if record not in result: result[record] = []
13510  *                         result[record].append( "\t".join( fields[1:] ) )
13511  */
13512       __pyx_t_3 = __Pyx_PyString_Equals(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13513       if (__pyx_t_3) {
13514
13515         /* "csamtools.pyx":1272
13516  *                     # treat comments
13517  *                     if record == "CO":
13518  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
13519  *                         result[record].append( "\t".join( fields[1:] ) )
13520  *                         continue
13521  */
13522         __pyx_t_3 = (__Pyx_NegateNonNeg(PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13523         if (__pyx_t_3) {
13524           __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13525           __Pyx_GOTREF(__pyx_t_7);
13526           if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13527           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
13528           goto __pyx_L9;
13529         }
13530         __pyx_L9:;
13531
13532         /* "csamtools.pyx":1273
13533  *                     if record == "CO":
13534  *                         if record not in result: result[record] = []
13535  *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
13536  *                         continue
13537  * 
13538  */
13539         __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13540         __Pyx_GOTREF(__pyx_t_7);
13541         __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 = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13542         __Pyx_GOTREF(__pyx_t_1);
13543         __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 = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13544         __Pyx_GOTREF(__pyx_t_8);
13545         __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13546         __Pyx_GOTREF(__pyx_t_9);
13547         PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
13548         __Pyx_GIVEREF(__pyx_t_8);
13549         __pyx_t_8 = 0;
13550         __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 = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13551         __Pyx_GOTREF(__pyx_t_8);
13552         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13553         __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
13554         __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13555         __Pyx_GOTREF(__pyx_t_9);
13556         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13557         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13558         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13559
13560         /* "csamtools.pyx":1274
13561  *                         if record not in result: result[record] = []
13562  *                         result[record].append( "\t".join( fields[1:] ) )
13563  *                         continue             # <<<<<<<<<<<<<<
13564  * 
13565  *                     # the following is clumsy as generators do not work?
13566  */
13567         goto __pyx_L5_continue;
13568         goto __pyx_L8;
13569       }
13570       __pyx_L8:;
13571
13572       /* "csamtools.pyx":1277
13573  * 
13574  *                     # the following is clumsy as generators do not work?
13575  *                     x = {}             # <<<<<<<<<<<<<<
13576  *                     for field in fields[1:]:
13577  *                         key, value = field.split(":",1)
13578  */
13579       __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13580       __Pyx_GOTREF(((PyObject *)__pyx_t_9));
13581       __Pyx_XDECREF(((PyObject *)__pyx_v_x));
13582       __pyx_v_x = __pyx_t_9;
13583       __pyx_t_9 = 0;
13584
13585       /* "csamtools.pyx":1278
13586  *                     # the following is clumsy as generators do not work?
13587  *                     x = {}
13588  *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
13589  *                         key, value = field.split(":",1)
13590  *                         # uppercase keys must be valid
13591  */
13592       __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 = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13593       __Pyx_GOTREF(__pyx_t_9);
13594       if (PyList_CheckExact(__pyx_t_9) || PyTuple_CheckExact(__pyx_t_9)) {
13595         __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_10 = 0;
13596         __pyx_t_11 = NULL;
13597       } else {
13598         __pyx_t_10 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13599         __Pyx_GOTREF(__pyx_t_8);
13600         __pyx_t_11 = Py_TYPE(__pyx_t_8)->tp_iternext;
13601       }
13602       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13603       for (;;) {
13604         if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_8)) {
13605           if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_8)) break;
13606           __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++;
13607         } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_8)) {
13608           if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
13609           __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_9); __pyx_t_10++;
13610         } else {
13611           __pyx_t_9 = __pyx_t_11(__pyx_t_8);
13612           if (unlikely(!__pyx_t_9)) {
13613             if (PyErr_Occurred()) {
13614               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
13615               else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13616             }
13617             break;
13618           }
13619           __Pyx_GOTREF(__pyx_t_9);
13620         }
13621         __Pyx_XDECREF(__pyx_v_field);
13622         __pyx_v_field = __pyx_t_9;
13623         __pyx_t_9 = 0;
13624
13625         /* "csamtools.pyx":1279
13626  *                     x = {}
13627  *                     for field in fields[1:]:
13628  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
13629  *                         # uppercase keys must be valid
13630  *                         # lowercase are permitted for user fields
13631  */
13632         __pyx_t_9 = PyObject_GetAttr(__pyx_v_field, __pyx_n_s__split); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13633         __Pyx_GOTREF(__pyx_t_9);
13634         __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_106), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13635         __Pyx_GOTREF(__pyx_t_7);
13636         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13637         if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
13638           PyObject* sequence = __pyx_t_7;
13639           if (likely(PyTuple_CheckExact(sequence))) {
13640             if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
13641               if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
13642               else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
13643               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13644             }
13645             __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
13646             __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
13647           } else {
13648             if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
13649               if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
13650               else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
13651               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13652             }
13653             __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
13654             __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
13655           }
13656           __Pyx_INCREF(__pyx_t_9);
13657           __Pyx_INCREF(__pyx_t_1);
13658           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13659         } else {
13660           Py_ssize_t index = -1;
13661           __pyx_t_12 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13662           __Pyx_GOTREF(__pyx_t_12);
13663           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13664           __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext;
13665           index = 0; __pyx_t_9 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_9)) goto __pyx_L12_unpacking_failed;
13666           __Pyx_GOTREF(__pyx_t_9);
13667           index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed;
13668           __Pyx_GOTREF(__pyx_t_1);
13669           if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13670           __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
13671           goto __pyx_L13_unpacking_done;
13672           __pyx_L12_unpacking_failed:;
13673           __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
13674           if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
13675           if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
13676           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13677           __pyx_L13_unpacking_done:;
13678         }
13679         __Pyx_XDECREF(__pyx_v_key);
13680         __pyx_v_key = __pyx_t_9;
13681         __pyx_t_9 = 0;
13682         __Pyx_XDECREF(__pyx_v_value);
13683         __pyx_v_value = __pyx_t_1;
13684         __pyx_t_1 = 0;
13685
13686         /* "csamtools.pyx":1282
13687  *                         # uppercase keys must be valid
13688  *                         # lowercase are permitted for user fields
13689  *                         if key in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
13690  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
13691  *                         elif not key.isupper():
13692  */
13693         __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 = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13694         __Pyx_GOTREF(__pyx_t_7);
13695         __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13696         __Pyx_GOTREF(__pyx_t_1);
13697         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13698         __pyx_t_3 = ((PySequence_Contains(__pyx_t_1, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13699         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13700         if (__pyx_t_3) {
13701
13702           /* "csamtools.pyx":1283
13703  *                         # lowercase are permitted for user fields
13704  *                         if key in VALID_HEADER_FIELDS[record]:
13705  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
13706  *                         elif not key.isupper():
13707  *                             x[key] = value
13708  */
13709           __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 = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13710           __Pyx_GOTREF(__pyx_t_1);
13711           __pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13712           __Pyx_GOTREF(__pyx_t_7);
13713           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13714           __pyx_t_1 = PyObject_GetItem(__pyx_t_7, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13715           __Pyx_GOTREF(__pyx_t_1);
13716           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13717           __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13718           __Pyx_GOTREF(__pyx_t_7);
13719           __Pyx_INCREF(__pyx_v_value);
13720           PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_value);
13721           __Pyx_GIVEREF(__pyx_v_value);
13722           __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 = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13723           __Pyx_GOTREF(__pyx_t_9);
13724           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13725           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
13726           if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_t_9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13727           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13728           goto __pyx_L14;
13729         }
13730
13731         /* "csamtools.pyx":1284
13732  *                         if key in VALID_HEADER_FIELDS[record]:
13733  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
13734  *                         elif not key.isupper():             # <<<<<<<<<<<<<<
13735  *                             x[key] = value
13736  *                         else:
13737  */
13738         __pyx_t_9 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13739         __Pyx_GOTREF(__pyx_t_9);
13740         __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 = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13741         __Pyx_GOTREF(__pyx_t_7);
13742         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13743         __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13744         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
13745         __pyx_t_4 = (!__pyx_t_3);
13746         if (__pyx_t_4) {
13747
13748           /* "csamtools.pyx":1285
13749  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
13750  *                         elif not key.isupper():
13751  *                             x[key] = value             # <<<<<<<<<<<<<<
13752  *                         else:
13753  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
13754  */
13755           if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13756           goto __pyx_L14;
13757         }
13758         /*else*/ {
13759
13760           /* "csamtools.pyx":1287
13761  *                             x[key] = value
13762  *                         else:
13763  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )             # <<<<<<<<<<<<<<
13764  * 
13765  *                     if VALID_HEADER_TYPES[record] == dict:
13766  */
13767           __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13768           __Pyx_GOTREF(__pyx_t_7);
13769           __Pyx_INCREF(__pyx_v_key);
13770           PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
13771           __Pyx_GIVEREF(__pyx_v_key);
13772           __Pyx_INCREF(__pyx_v_record);
13773           PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_record);
13774           __Pyx_GIVEREF(__pyx_v_record);
13775           __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_107), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13776           __Pyx_GOTREF(((PyObject *)__pyx_t_9));
13777           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
13778           __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13779           __Pyx_GOTREF(__pyx_t_7);
13780           PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_9));
13781           __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
13782           __pyx_t_9 = 0;
13783           __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 = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13784           __Pyx_GOTREF(__pyx_t_9);
13785           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
13786           __Pyx_Raise(__pyx_t_9, 0, 0, 0);
13787           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13788           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13789         }
13790         __pyx_L14:;
13791       }
13792       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13793
13794       /* "csamtools.pyx":1289
13795  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
13796  * 
13797  *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
13798  *                         if record in result:
13799  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
13800  */
13801       __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 = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13802       __Pyx_GOTREF(__pyx_t_8);
13803       __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13804       __Pyx_GOTREF(__pyx_t_9);
13805       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13806       __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13807       __Pyx_GOTREF(__pyx_t_8);
13808       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13809       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13810       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13811       if (__pyx_t_4) {
13812
13813         /* "csamtools.pyx":1290
13814  * 
13815  *                     if VALID_HEADER_TYPES[record] == dict:
13816  *                         if record in result:             # <<<<<<<<<<<<<<
13817  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
13818  *                         result[record] = x
13819  */
13820         __pyx_t_4 = ((PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13821         if (__pyx_t_4) {
13822
13823           /* "csamtools.pyx":1291
13824  *                     if VALID_HEADER_TYPES[record] == dict:
13825  *                         if record in result:
13826  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )             # <<<<<<<<<<<<<<
13827  *                         result[record] = x
13828  *                     elif VALID_HEADER_TYPES[record] == list:
13829  */
13830           __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_108), __pyx_v_record); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13831           __Pyx_GOTREF(((PyObject *)__pyx_t_8));
13832           __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13833           __Pyx_GOTREF(__pyx_t_9);
13834           PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
13835           __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
13836           __pyx_t_8 = 0;
13837           __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 = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13838           __Pyx_GOTREF(__pyx_t_8);
13839           __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
13840           __Pyx_Raise(__pyx_t_8, 0, 0, 0);
13841           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13842           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13843           goto __pyx_L16;
13844         }
13845         __pyx_L16:;
13846
13847         /* "csamtools.pyx":1292
13848  *                         if record in result:
13849  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
13850  *                         result[record] = x             # <<<<<<<<<<<<<<
13851  *                     elif VALID_HEADER_TYPES[record] == list:
13852  *                         if record not in result: result[record] = []
13853  */
13854         if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_v_x)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13855         goto __pyx_L15;
13856       }
13857
13858       /* "csamtools.pyx":1293
13859  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
13860  *                         result[record] = x
13861  *                     elif VALID_HEADER_TYPES[record] == list:             # <<<<<<<<<<<<<<
13862  *                         if record not in result: result[record] = []
13863  *                         result[record].append( x )
13864  */
13865       __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 = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13866       __Pyx_GOTREF(__pyx_t_8);
13867       __pyx_t_9 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13868       __Pyx_GOTREF(__pyx_t_9);
13869       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13870       __pyx_t_8 = PyObject_RichCompare(__pyx_t_9, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13871       __Pyx_GOTREF(__pyx_t_8);
13872       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13873       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13874       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13875       if (__pyx_t_4) {
13876
13877         /* "csamtools.pyx":1294
13878  *                         result[record] = x
13879  *                     elif VALID_HEADER_TYPES[record] == list:
13880  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
13881  *                         result[record].append( x )
13882  * 
13883  */
13884         __pyx_t_4 = (__Pyx_NegateNonNeg(PyDict_Contains(((PyObject *)__pyx_v_result), __pyx_v_record))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13885         if (__pyx_t_4) {
13886           __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13887           __Pyx_GOTREF(__pyx_t_8);
13888           if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_8)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13889           __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
13890           goto __pyx_L17;
13891         }
13892         __pyx_L17:;
13893
13894         /* "csamtools.pyx":1295
13895  *                     elif VALID_HEADER_TYPES[record] == list:
13896  *                         if record not in result: result[record] = []
13897  *                         result[record].append( x )             # <<<<<<<<<<<<<<
13898  * 
13899  *                 # if there are no SQ lines in the header, add the reference names
13900  */
13901         __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13902         __Pyx_GOTREF(__pyx_t_8);
13903         __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13904         __Pyx_GOTREF(__pyx_t_9);
13905         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
13906         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13907         goto __pyx_L15;
13908       }
13909       __pyx_L15:;
13910       __pyx_L5_continue:;
13911     }
13912     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13913
13914     /* "csamtools.pyx":1303
13915  *                 # SQ lines, the SQ information is not part of the textual header and thus
13916  *                 # are missing from the output. See issue 84.
13917  *                 if "SQ" not in result:             # <<<<<<<<<<<<<<
13918  *                     sq = []
13919  *                     for ref, length in zip( self.references, self.lengths ):
13920  */
13921     __pyx_t_4 = (__Pyx_NegateNonNeg(PyDict_Contains(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_n_s__SQ)))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13922     if (__pyx_t_4) {
13923
13924       /* "csamtools.pyx":1304
13925  *                 # are missing from the output. See issue 84.
13926  *                 if "SQ" not in result:
13927  *                     sq = []             # <<<<<<<<<<<<<<
13928  *                     for ref, length in zip( self.references, self.lengths ):
13929  *                         sq.append( {'LN': length, 'SN': ref } )
13930  */
13931       __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13932       __Pyx_GOTREF(__pyx_t_2);
13933       __pyx_v_sq = __pyx_t_2;
13934       __pyx_t_2 = 0;
13935
13936       /* "csamtools.pyx":1305
13937  *                 if "SQ" not in result:
13938  *                     sq = []
13939  *                     for ref, length in zip( self.references, self.lengths ):             # <<<<<<<<<<<<<<
13940  *                         sq.append( {'LN': length, 'SN': ref } )
13941  *                     result["SQ"] = sq
13942  */
13943       __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 = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13944       __Pyx_GOTREF(__pyx_t_2);
13945       __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 = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13946       __Pyx_GOTREF(__pyx_t_9);
13947       __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13948       __Pyx_GOTREF(__pyx_t_8);
13949       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
13950       __Pyx_GIVEREF(__pyx_t_2);
13951       PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
13952       __Pyx_GIVEREF(__pyx_t_9);
13953       __pyx_t_2 = 0;
13954       __pyx_t_9 = 0;
13955       __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 = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13956       __Pyx_GOTREF(__pyx_t_9);
13957       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
13958       if (PyList_CheckExact(__pyx_t_9) || PyTuple_CheckExact(__pyx_t_9)) {
13959         __pyx_t_8 = __pyx_t_9; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
13960         __pyx_t_6 = NULL;
13961       } else {
13962         __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13963         __Pyx_GOTREF(__pyx_t_8);
13964         __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext;
13965       }
13966       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
13967       for (;;) {
13968         if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_8)) {
13969           if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
13970           __pyx_t_9 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++;
13971         } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_8)) {
13972           if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
13973           __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_9); __pyx_t_5++;
13974         } else {
13975           __pyx_t_9 = __pyx_t_6(__pyx_t_8);
13976           if (unlikely(!__pyx_t_9)) {
13977             if (PyErr_Occurred()) {
13978               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
13979               else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13980             }
13981             break;
13982           }
13983           __Pyx_GOTREF(__pyx_t_9);
13984         }
13985         if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) {
13986           PyObject* sequence = __pyx_t_9;
13987           if (likely(PyTuple_CheckExact(sequence))) {
13988             if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
13989               if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
13990               else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
13991               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13992             }
13993             __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
13994             __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
13995           } else {
13996             if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
13997               if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
13998               else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
13999               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14000             }
14001             __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
14002             __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
14003           }
14004           __Pyx_INCREF(__pyx_t_2);
14005           __Pyx_INCREF(__pyx_t_7);
14006           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
14007         } else {
14008           Py_ssize_t index = -1;
14009           __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14010           __Pyx_GOTREF(__pyx_t_1);
14011           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
14012           __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext;
14013           index = 0; __pyx_t_2 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L21_unpacking_failed;
14014           __Pyx_GOTREF(__pyx_t_2);
14015           index = 1; __pyx_t_7 = __pyx_t_13(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L21_unpacking_failed;
14016           __Pyx_GOTREF(__pyx_t_7);
14017           if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_1), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14018           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14019           goto __pyx_L22_unpacking_done;
14020           __pyx_L21_unpacking_failed:;
14021           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14022           if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
14023           if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
14024           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14025           __pyx_L22_unpacking_done:;
14026         }
14027         __Pyx_XDECREF(__pyx_v_ref);
14028         __pyx_v_ref = __pyx_t_2;
14029         __pyx_t_2 = 0;
14030         __Pyx_XDECREF(__pyx_v_length);
14031         __pyx_v_length = __pyx_t_7;
14032         __pyx_t_7 = 0;
14033
14034         /* "csamtools.pyx":1306
14035  *                     sq = []
14036  *                     for ref, length in zip( self.references, self.lengths ):
14037  *                         sq.append( {'LN': length, 'SN': ref } )             # <<<<<<<<<<<<<<
14038  *                     result["SQ"] = sq
14039  * 
14040  */
14041         __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14042         __Pyx_GOTREF(((PyObject *)__pyx_t_9));
14043         if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__LN), __pyx_v_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14044         if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__SN), __pyx_v_ref) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14045         __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 = 1306; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14046         __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
14047       }
14048       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
14049
14050       /* "csamtools.pyx":1307
14051  *                     for ref, length in zip( self.references, self.lengths ):
14052  *                         sq.append( {'LN': length, 'SN': ref } )
14053  *                     result["SQ"] = sq             # <<<<<<<<<<<<<<
14054  * 
14055  *             return result
14056  */
14057       if (PyDict_SetItem(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_v_sq)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14058       goto __pyx_L18;
14059     }
14060     __pyx_L18:;
14061     goto __pyx_L4;
14062   }
14063   __pyx_L4:;
14064
14065   /* "csamtools.pyx":1309
14066  *                     result["SQ"] = sq
14067  * 
14068  *             return result             # <<<<<<<<<<<<<<
14069  * 
14070  *     def _buildLine( self, fields, record ):
14071  */
14072   __Pyx_XDECREF(__pyx_r);
14073   __Pyx_INCREF(((PyObject *)__pyx_v_result));
14074   __pyx_r = ((PyObject *)__pyx_v_result);
14075   goto __pyx_L0;
14076
14077   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14078   goto __pyx_L0;
14079   __pyx_L1_error:;
14080   __Pyx_XDECREF(__pyx_t_1);
14081   __Pyx_XDECREF(__pyx_t_2);
14082   __Pyx_XDECREF(__pyx_t_7);
14083   __Pyx_XDECREF(__pyx_t_8);
14084   __Pyx_XDECREF(__pyx_t_9);
14085   __Pyx_XDECREF(__pyx_t_12);
14086   __Pyx_AddTraceback("csamtools.Samfile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
14087   __pyx_r = NULL;
14088   __pyx_L0:;
14089   __Pyx_XDECREF(__pyx_v_result);
14090   __Pyx_XDECREF(__pyx_v_t);
14091   __Pyx_XDECREF(__pyx_v_line);
14092   __Pyx_XDECREF(__pyx_v_fields);
14093   __Pyx_XDECREF(__pyx_v_record);
14094   __Pyx_XDECREF(__pyx_v_x);
14095   __Pyx_XDECREF(__pyx_v_field);
14096   __Pyx_XDECREF(__pyx_v_key);
14097   __Pyx_XDECREF(__pyx_v_value);
14098   __Pyx_XDECREF(__pyx_v_sq);
14099   __Pyx_XDECREF(__pyx_v_ref);
14100   __Pyx_XDECREF(__pyx_v_length);
14101   __Pyx_XGIVEREF(__pyx_r);
14102   __Pyx_TraceReturn(__pyx_r);
14103   __Pyx_RefNannyFinishContext();
14104   return __pyx_r;
14105 }
14106
14107 /* Python wrapper */
14108 static PyObject *__pyx_pw_9csamtools_7Samfile_39_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
14109 static char __pyx_doc_9csamtools_7Samfile_38_buildLine[] = "Samfile._buildLine(self, fields, record)\nbuild a header line from *fields* dictionary for *record*";
14110 static PyObject *__pyx_pw_9csamtools_7Samfile_39_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
14111   PyObject *__pyx_v_fields = 0;
14112   PyObject *__pyx_v_record = 0;
14113   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fields,&__pyx_n_s__record,0};
14114   PyObject *__pyx_r = 0;
14115   __Pyx_RefNannyDeclarations
14116   __Pyx_RefNannySetupContext("_buildLine (wrapper)", 0);
14117   {
14118     PyObject* values[2] = {0,0};
14119     if (unlikely(__pyx_kwds)) {
14120       Py_ssize_t kw_args;
14121       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
14122       switch (pos_args) {
14123         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
14124         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
14125         case  0: break;
14126         default: goto __pyx_L5_argtuple_error;
14127       }
14128       kw_args = PyDict_Size(__pyx_kwds);
14129       switch (pos_args) {
14130         case  0:
14131         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fields);
14132         if (likely(values[0])) kw_args--;
14133         else goto __pyx_L5_argtuple_error;
14134         case  1:
14135         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__record);
14136         if (likely(values[1])) kw_args--;
14137         else {
14138           __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14139         }
14140       }
14141       if (unlikely(kw_args > 0)) {
14142         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14143       }
14144     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
14145       goto __pyx_L5_argtuple_error;
14146     } else {
14147       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
14148       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
14149     }
14150     __pyx_v_fields = values[0];
14151     __pyx_v_record = values[1];
14152   }
14153   goto __pyx_L4_argument_unpacking_done;
14154   __pyx_L5_argtuple_error:;
14155   __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14156   __pyx_L3_error:;
14157   __Pyx_AddTraceback("csamtools.Samfile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
14158   __Pyx_RefNannyFinishContext();
14159   return NULL;
14160   __pyx_L4_argument_unpacking_done:;
14161   __pyx_r = __pyx_pf_9csamtools_7Samfile_38_buildLine(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_fields, __pyx_v_record);
14162   __Pyx_RefNannyFinishContext();
14163   return __pyx_r;
14164 }
14165
14166 /* "csamtools.pyx":1311
14167  *             return result
14168  * 
14169  *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
14170  *         '''build a header line from *fields* dictionary for *record*'''
14171  * 
14172  */
14173
14174 static PyObject *__pyx_pf_9csamtools_7Samfile_38_buildLine(CYTHON_UNUSED struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record) {
14175   PyObject *__pyx_v_line = NULL;
14176   PyObject *__pyx_v_key = NULL;
14177   PyObject *__pyx_r = NULL;
14178   __Pyx_RefNannyDeclarations
14179   PyObject *__pyx_t_1 = NULL;
14180   PyObject *__pyx_t_2 = NULL;
14181   int __pyx_t_3;
14182   int __pyx_t_4;
14183   Py_ssize_t __pyx_t_5;
14184   PyObject *(*__pyx_t_6)(PyObject *);
14185   PyObject *__pyx_t_7 = NULL;
14186   int __pyx_t_8;
14187   int __pyx_lineno = 0;
14188   const char *__pyx_filename = NULL;
14189   int __pyx_clineno = 0;
14190   __Pyx_TraceDeclarations
14191   __Pyx_RefNannySetupContext("_buildLine", 0);
14192   __Pyx_TraceCall("_buildLine", __pyx_f[0], 1311);
14193
14194   /* "csamtools.pyx":1315
14195  * 
14196  *         # TODO: add checking for field and sort order
14197  *         line = ["@%s" % record ]             # <<<<<<<<<<<<<<
14198  *         # comment
14199  *         if record == "CO":
14200  */
14201   __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_109), __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14202   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
14203   __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14204   __Pyx_GOTREF(__pyx_t_2);
14205   PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
14206   __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
14207   __pyx_t_1 = 0;
14208   __pyx_v_line = __pyx_t_2;
14209   __pyx_t_2 = 0;
14210
14211   /* "csamtools.pyx":1317
14212  *         line = ["@%s" % record ]
14213  *         # comment
14214  *         if record == "CO":             # <<<<<<<<<<<<<<
14215  *             line.append( fields )
14216  *         # user tags
14217  */
14218   __pyx_t_3 = __Pyx_PyString_Equals(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14219   if (__pyx_t_3) {
14220
14221     /* "csamtools.pyx":1318
14222  *         # comment
14223  *         if record == "CO":
14224  *             line.append( fields )             # <<<<<<<<<<<<<<
14225  *         # user tags
14226  *         elif record.islower():
14227  */
14228     __pyx_t_4 = PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14229     goto __pyx_L3;
14230   }
14231
14232   /* "csamtools.pyx":1320
14233  *             line.append( fields )
14234  *         # user tags
14235  *         elif record.islower():             # <<<<<<<<<<<<<<
14236  *             for key in sorted(fields):
14237  *                 line.append( "%s:%s" % (key, str(fields[key])))
14238  */
14239   __pyx_t_2 = PyObject_GetAttr(__pyx_v_record, __pyx_n_s__islower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14240   __Pyx_GOTREF(__pyx_t_2);
14241   __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 = 1320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14242   __Pyx_GOTREF(__pyx_t_1);
14243   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14244   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14245   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14246   if (__pyx_t_3) {
14247
14248     /* "csamtools.pyx":1321
14249  *         # user tags
14250  *         elif record.islower():
14251  *             for key in sorted(fields):             # <<<<<<<<<<<<<<
14252  *                 line.append( "%s:%s" % (key, str(fields[key])))
14253  *         # defined tags
14254  */
14255     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14256     __Pyx_GOTREF(__pyx_t_1);
14257     __Pyx_INCREF(__pyx_v_fields);
14258     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
14259     __Pyx_GIVEREF(__pyx_v_fields);
14260     __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 = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14261     __Pyx_GOTREF(__pyx_t_2);
14262     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
14263     if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
14264       __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
14265       __pyx_t_6 = NULL;
14266     } else {
14267       __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14268       __Pyx_GOTREF(__pyx_t_1);
14269       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
14270     }
14271     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14272     for (;;) {
14273       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
14274         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
14275         __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14276       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
14277         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
14278         __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14279       } else {
14280         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
14281         if (unlikely(!__pyx_t_2)) {
14282           if (PyErr_Occurred()) {
14283             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14284             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14285           }
14286           break;
14287         }
14288         __Pyx_GOTREF(__pyx_t_2);
14289       }
14290       __Pyx_XDECREF(__pyx_v_key);
14291       __pyx_v_key = __pyx_t_2;
14292       __pyx_t_2 = 0;
14293
14294       /* "csamtools.pyx":1322
14295  *         elif record.islower():
14296  *             for key in sorted(fields):
14297  *                 line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
14298  *         # defined tags
14299  *         else:
14300  */
14301       __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14302       __Pyx_GOTREF(__pyx_t_2);
14303       __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14304       __Pyx_GOTREF(__pyx_t_7);
14305       PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
14306       __Pyx_GIVEREF(__pyx_t_2);
14307       __pyx_t_2 = 0;
14308       __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 = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14309       __Pyx_GOTREF(__pyx_t_2);
14310       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14311       __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14312       __Pyx_GOTREF(__pyx_t_7);
14313       __Pyx_INCREF(__pyx_v_key);
14314       PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
14315       __Pyx_GIVEREF(__pyx_v_key);
14316       PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
14317       __Pyx_GIVEREF(__pyx_t_2);
14318       __pyx_t_2 = 0;
14319       __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14320       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
14321       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14322       __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 = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14323       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14324     }
14325     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14326     goto __pyx_L3;
14327   }
14328   /*else*/ {
14329
14330     /* "csamtools.pyx":1326
14331  *         else:
14332  *             # write fields of the specification
14333  *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
14334  *                 if key in fields:
14335  *                     line.append( "%s:%s" % (key, str(fields[key])))
14336  */
14337     __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 = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14338     __Pyx_GOTREF(__pyx_t_1);
14339     __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14340     __Pyx_GOTREF(__pyx_t_2);
14341     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14342     if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
14343       __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
14344       __pyx_t_6 = NULL;
14345     } else {
14346       __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14347       __Pyx_GOTREF(__pyx_t_1);
14348       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
14349     }
14350     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14351     for (;;) {
14352       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
14353         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
14354         __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14355       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
14356         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
14357         __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14358       } else {
14359         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
14360         if (unlikely(!__pyx_t_2)) {
14361           if (PyErr_Occurred()) {
14362             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14363             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14364           }
14365           break;
14366         }
14367         __Pyx_GOTREF(__pyx_t_2);
14368       }
14369       __Pyx_XDECREF(__pyx_v_key);
14370       __pyx_v_key = __pyx_t_2;
14371       __pyx_t_2 = 0;
14372
14373       /* "csamtools.pyx":1327
14374  *             # write fields of the specification
14375  *             for key in VALID_HEADER_ORDER[record]:
14376  *                 if key in fields:             # <<<<<<<<<<<<<<
14377  *                     line.append( "%s:%s" % (key, str(fields[key])))
14378  *             # write user fields
14379  */
14380       __pyx_t_3 = ((PySequence_Contains(__pyx_v_fields, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14381       if (__pyx_t_3) {
14382
14383         /* "csamtools.pyx":1328
14384  *             for key in VALID_HEADER_ORDER[record]:
14385  *                 if key in fields:
14386  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
14387  *             # write user fields
14388  *             for key in fields:
14389  */
14390         __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14391         __Pyx_GOTREF(__pyx_t_2);
14392         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14393         __Pyx_GOTREF(__pyx_t_7);
14394         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
14395         __Pyx_GIVEREF(__pyx_t_2);
14396         __pyx_t_2 = 0;
14397         __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 = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14398         __Pyx_GOTREF(__pyx_t_2);
14399         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14400         __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14401         __Pyx_GOTREF(__pyx_t_7);
14402         __Pyx_INCREF(__pyx_v_key);
14403         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_key);
14404         __Pyx_GIVEREF(__pyx_v_key);
14405         PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_2);
14406         __Pyx_GIVEREF(__pyx_t_2);
14407         __pyx_t_2 = 0;
14408         __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14409         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
14410         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14411         __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 = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14412         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14413         goto __pyx_L8;
14414       }
14415       __pyx_L8:;
14416     }
14417     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14418
14419     /* "csamtools.pyx":1330
14420  *                     line.append( "%s:%s" % (key, str(fields[key])))
14421  *             # write user fields
14422  *             for key in fields:             # <<<<<<<<<<<<<<
14423  *                 if not key.isupper():
14424  *                     line.append( "%s:%s" % (key, str(fields[key])))
14425  */
14426     if (PyList_CheckExact(__pyx_v_fields) || PyTuple_CheckExact(__pyx_v_fields)) {
14427       __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
14428       __pyx_t_6 = NULL;
14429     } else {
14430       __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14431       __Pyx_GOTREF(__pyx_t_1);
14432       __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
14433     }
14434     for (;;) {
14435       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
14436         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
14437         __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14438       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
14439         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
14440         __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++;
14441       } else {
14442         __pyx_t_2 = __pyx_t_6(__pyx_t_1);
14443         if (unlikely(!__pyx_t_2)) {
14444           if (PyErr_Occurred()) {
14445             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14446             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14447           }
14448           break;
14449         }
14450         __Pyx_GOTREF(__pyx_t_2);
14451       }
14452       __Pyx_XDECREF(__pyx_v_key);
14453       __pyx_v_key = __pyx_t_2;
14454       __pyx_t_2 = 0;
14455
14456       /* "csamtools.pyx":1331
14457  *             # write user fields
14458  *             for key in fields:
14459  *                 if not key.isupper():             # <<<<<<<<<<<<<<
14460  *                     line.append( "%s:%s" % (key, str(fields[key])))
14461  * 
14462  */
14463       __pyx_t_2 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14464       __Pyx_GOTREF(__pyx_t_2);
14465       __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 = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14466       __Pyx_GOTREF(__pyx_t_7);
14467       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14468       __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14469       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14470       __pyx_t_8 = (!__pyx_t_3);
14471       if (__pyx_t_8) {
14472
14473         /* "csamtools.pyx":1332
14474  *             for key in fields:
14475  *                 if not key.isupper():
14476  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
14477  * 
14478  *         return "\t".join( line )
14479  */
14480         __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14481         __Pyx_GOTREF(__pyx_t_7);
14482         __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14483         __Pyx_GOTREF(__pyx_t_2);
14484         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
14485         __Pyx_GIVEREF(__pyx_t_7);
14486         __pyx_t_7 = 0;
14487         __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 = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14488         __Pyx_GOTREF(__pyx_t_7);
14489         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14490         __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14491         __Pyx_GOTREF(__pyx_t_2);
14492         __Pyx_INCREF(__pyx_v_key);
14493         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
14494         __Pyx_GIVEREF(__pyx_v_key);
14495         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
14496         __Pyx_GIVEREF(__pyx_t_7);
14497         __pyx_t_7 = 0;
14498         __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14499         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
14500         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14501         __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 = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14502         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14503         goto __pyx_L11;
14504       }
14505       __pyx_L11:;
14506     }
14507     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14508   }
14509   __pyx_L3:;
14510
14511   /* "csamtools.pyx":1334
14512  *                     line.append( "%s:%s" % (key, str(fields[key])))
14513  * 
14514  *         return "\t".join( line )             # <<<<<<<<<<<<<<
14515  * 
14516  *     cdef bam_header_t * _buildHeader( self, new_header ):
14517  */
14518   __Pyx_XDECREF(__pyx_r);
14519   __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 = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14520   __Pyx_GOTREF(__pyx_t_1);
14521   __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14522   __Pyx_GOTREF(__pyx_t_7);
14523   __Pyx_INCREF(((PyObject *)__pyx_v_line));
14524   PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_line));
14525   __Pyx_GIVEREF(((PyObject *)__pyx_v_line));
14526   __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 = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14527   __Pyx_GOTREF(__pyx_t_2);
14528   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14529   __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
14530   __pyx_r = __pyx_t_2;
14531   __pyx_t_2 = 0;
14532   goto __pyx_L0;
14533
14534   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14535   goto __pyx_L0;
14536   __pyx_L1_error:;
14537   __Pyx_XDECREF(__pyx_t_1);
14538   __Pyx_XDECREF(__pyx_t_2);
14539   __Pyx_XDECREF(__pyx_t_7);
14540   __Pyx_AddTraceback("csamtools.Samfile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
14541   __pyx_r = NULL;
14542   __pyx_L0:;
14543   __Pyx_XDECREF(__pyx_v_line);
14544   __Pyx_XDECREF(__pyx_v_key);
14545   __Pyx_XGIVEREF(__pyx_r);
14546   __Pyx_TraceReturn(__pyx_r);
14547   __Pyx_RefNannyFinishContext();
14548   return __pyx_r;
14549 }
14550
14551 /* "csamtools.pyx":1336
14552  *         return "\t".join( line )
14553  * 
14554  *     cdef bam_header_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
14555  *         '''return a new header built from a dictionary in *new_header*.
14556  * 
14557  */
14558
14559 static bam_header_t *__pyx_f_9csamtools_7Samfile__buildHeader(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_new_header) {
14560   PyObject *__pyx_v_lines = NULL;
14561   bam_header_t *__pyx_v_dest;
14562   PyObject *__pyx_v_record = NULL;
14563   PyObject *__pyx_v_ttype = NULL;
14564   PyObject *__pyx_v_data = NULL;
14565   PyObject *__pyx_v_fields = NULL;
14566   PyObject *__pyx_v_text = NULL;
14567   PyObject *__pyx_v_btext = 0;
14568   PyObject *__pyx_v_bseqname = 0;
14569   PyObject *__pyx_v_seqs = NULL;
14570   long __pyx_v_x;
14571   PyObject *__pyx_v_seqname = NULL;
14572   PyObject *__pyx_v_seqlen = NULL;
14573   bam_header_t *__pyx_r;
14574   __Pyx_RefNannyDeclarations
14575   PyObject *__pyx_t_1 = NULL;
14576   PyObject *__pyx_t_2 = NULL;
14577   Py_ssize_t __pyx_t_3;
14578   PyObject *(*__pyx_t_4)(PyObject *);
14579   int __pyx_t_5;
14580   PyObject *__pyx_t_6 = NULL;
14581   PyObject *__pyx_t_7 = NULL;
14582   int __pyx_t_8;
14583   Py_ssize_t __pyx_t_9;
14584   PyObject *(*__pyx_t_10)(PyObject *);
14585   PyObject *__pyx_t_11 = NULL;
14586   PyObject *(*__pyx_t_12)(PyObject *);
14587   char *__pyx_t_13;
14588   PyObject *__pyx_t_14 = NULL;
14589   PyObject *__pyx_t_15 = NULL;
14590   PyObject *__pyx_t_16 = NULL;
14591   int __pyx_t_17;
14592   PyObject *__pyx_t_18 = NULL;
14593   int32_t __pyx_t_19;
14594   uint32_t __pyx_t_20;
14595   int __pyx_lineno = 0;
14596   const char *__pyx_filename = NULL;
14597   int __pyx_clineno = 0;
14598   __Pyx_TraceDeclarations
14599   __Pyx_RefNannySetupContext("_buildHeader", 0);
14600   __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1336);
14601
14602   /* "csamtools.pyx":1342
14603  *         '''
14604  * 
14605  *         lines = []             # <<<<<<<<<<<<<<
14606  * 
14607  *         # check if hash exists
14608  */
14609   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14610   __Pyx_GOTREF(__pyx_t_1);
14611   __pyx_v_lines = __pyx_t_1;
14612   __pyx_t_1 = 0;
14613
14614   /* "csamtools.pyx":1349
14615  *         cdef bam_header_t * dest
14616  * 
14617  *         dest = bam_header_init()             # <<<<<<<<<<<<<<
14618  * 
14619  *         # first: defined tags
14620  */
14621   __pyx_v_dest = bam_header_init();
14622
14623   /* "csamtools.pyx":1352
14624  * 
14625  *         # first: defined tags
14626  *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
14627  *             if record in new_header:
14628  *                 ttype = VALID_HEADER_TYPES[record]
14629  */
14630   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14631   __Pyx_GOTREF(__pyx_t_1);
14632   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
14633     __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
14634     __pyx_t_4 = NULL;
14635   } else {
14636     __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14637     __Pyx_GOTREF(__pyx_t_2);
14638     __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
14639   }
14640   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14641   for (;;) {
14642     if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
14643       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
14644       __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++;
14645     } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
14646       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
14647       __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++;
14648     } else {
14649       __pyx_t_1 = __pyx_t_4(__pyx_t_2);
14650       if (unlikely(!__pyx_t_1)) {
14651         if (PyErr_Occurred()) {
14652           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14653           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14654         }
14655         break;
14656       }
14657       __Pyx_GOTREF(__pyx_t_1);
14658     }
14659     __Pyx_XDECREF(__pyx_v_record);
14660     __pyx_v_record = __pyx_t_1;
14661     __pyx_t_1 = 0;
14662
14663     /* "csamtools.pyx":1353
14664  *         # first: defined tags
14665  *         for record in VALID_HEADERS:
14666  *             if record in new_header:             # <<<<<<<<<<<<<<
14667  *                 ttype = VALID_HEADER_TYPES[record]
14668  *                 data = new_header[record]
14669  */
14670     __pyx_t_5 = ((PySequence_Contains(__pyx_v_new_header, __pyx_v_record))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14671     if (__pyx_t_5) {
14672
14673       /* "csamtools.pyx":1354
14674  *         for record in VALID_HEADERS:
14675  *             if record in new_header:
14676  *                 ttype = VALID_HEADER_TYPES[record]             # <<<<<<<<<<<<<<
14677  *                 data = new_header[record]
14678  *                 if type( data ) != type( ttype() ):
14679  */
14680       __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 = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14681       __Pyx_GOTREF(__pyx_t_1);
14682       __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14683       __Pyx_GOTREF(__pyx_t_6);
14684       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14685       __Pyx_XDECREF(__pyx_v_ttype);
14686       __pyx_v_ttype = __pyx_t_6;
14687       __pyx_t_6 = 0;
14688
14689       /* "csamtools.pyx":1355
14690  *             if record in new_header:
14691  *                 ttype = VALID_HEADER_TYPES[record]
14692  *                 data = new_header[record]             # <<<<<<<<<<<<<<
14693  *                 if type( data ) != type( ttype() ):
14694  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
14695  */
14696       __pyx_t_6 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14697       __Pyx_GOTREF(__pyx_t_6);
14698       __Pyx_XDECREF(__pyx_v_data);
14699       __pyx_v_data = __pyx_t_6;
14700       __pyx_t_6 = 0;
14701
14702       /* "csamtools.pyx":1356
14703  *                 ttype = VALID_HEADER_TYPES[record]
14704  *                 data = new_header[record]
14705  *                 if type( data ) != type( ttype() ):             # <<<<<<<<<<<<<<
14706  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
14707  *                 if type( data ) is dict:
14708  */
14709       __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 = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14710       __Pyx_GOTREF(__pyx_t_6);
14711       __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_6)), Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14712       __Pyx_GOTREF(__pyx_t_1);
14713       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14714       __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14715       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14716       if (__pyx_t_5) {
14717
14718         /* "csamtools.pyx":1357
14719  *                 data = new_header[record]
14720  *                 if type( data ) != type( ttype() ):
14721  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )             # <<<<<<<<<<<<<<
14722  *                 if type( data ) is dict:
14723  *                     lines.append( self._buildLine( data, record ) )
14724  */
14725         __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 = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14726         __Pyx_GOTREF(__pyx_t_1);
14727         __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14728         __Pyx_GOTREF(__pyx_t_6);
14729         __Pyx_INCREF(__pyx_v_record);
14730         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_record);
14731         __Pyx_GIVEREF(__pyx_v_record);
14732         __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
14733         PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)Py_TYPE(__pyx_v_data)));
14734         __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data)));
14735         __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_1)));
14736         PyTuple_SET_ITEM(__pyx_t_6, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
14737         __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
14738         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14739         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_111), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14740         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
14741         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
14742         __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14743         __Pyx_GOTREF(__pyx_t_6);
14744         PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1));
14745         __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
14746         __pyx_t_1 = 0;
14747         __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 = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14748         __Pyx_GOTREF(__pyx_t_1);
14749         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
14750         __Pyx_Raise(__pyx_t_1, 0, 0, 0);
14751         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14752         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14753         goto __pyx_L6;
14754       }
14755       __pyx_L6:;
14756
14757       /* "csamtools.pyx":1358
14758  *                 if type( data ) != type( ttype() ):
14759  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
14760  *                 if type( data ) is dict:             # <<<<<<<<<<<<<<
14761  *                     lines.append( self._buildLine( data, record ) )
14762  *                 else:
14763  */
14764       __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
14765       if (__pyx_t_5) {
14766
14767         /* "csamtools.pyx":1359
14768  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
14769  *                 if type( data ) is dict:
14770  *                     lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
14771  *                 else:
14772  *                     for fields in new_header[record]:
14773  */
14774         __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 = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14775         __Pyx_GOTREF(__pyx_t_1);
14776         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14777         __Pyx_GOTREF(__pyx_t_6);
14778         __Pyx_INCREF(__pyx_v_data);
14779         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_data);
14780         __Pyx_GIVEREF(__pyx_v_data);
14781         __Pyx_INCREF(__pyx_v_record);
14782         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_record);
14783         __Pyx_GIVEREF(__pyx_v_record);
14784         __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 = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14785         __Pyx_GOTREF(__pyx_t_7);
14786         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14787         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
14788         __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14789         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14790         goto __pyx_L7;
14791       }
14792       /*else*/ {
14793
14794         /* "csamtools.pyx":1361
14795  *                     lines.append( self._buildLine( data, record ) )
14796  *                 else:
14797  *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
14798  *                         lines.append( self._buildLine( fields, record ) )
14799  * 
14800  */
14801         __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14802         __Pyx_GOTREF(__pyx_t_7);
14803         if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
14804           __pyx_t_6 = __pyx_t_7; __Pyx_INCREF(__pyx_t_6); __pyx_t_9 = 0;
14805           __pyx_t_10 = NULL;
14806         } else {
14807           __pyx_t_9 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14808           __Pyx_GOTREF(__pyx_t_6);
14809           __pyx_t_10 = Py_TYPE(__pyx_t_6)->tp_iternext;
14810         }
14811         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14812         for (;;) {
14813           if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_6)) {
14814             if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_6)) break;
14815             __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++;
14816           } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_6)) {
14817             if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
14818             __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++;
14819           } else {
14820             __pyx_t_7 = __pyx_t_10(__pyx_t_6);
14821             if (unlikely(!__pyx_t_7)) {
14822               if (PyErr_Occurred()) {
14823                 if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14824                 else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14825               }
14826               break;
14827             }
14828             __Pyx_GOTREF(__pyx_t_7);
14829           }
14830           __Pyx_XDECREF(__pyx_v_fields);
14831           __pyx_v_fields = __pyx_t_7;
14832           __pyx_t_7 = 0;
14833
14834           /* "csamtools.pyx":1362
14835  *                 else:
14836  *                     for fields in new_header[record]:
14837  *                         lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
14838  * 
14839  *         # then: user tags (lower case), sorted alphabetically
14840  */
14841           __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 = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14842           __Pyx_GOTREF(__pyx_t_7);
14843           __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14844           __Pyx_GOTREF(__pyx_t_1);
14845           __Pyx_INCREF(__pyx_v_fields);
14846           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
14847           __Pyx_GIVEREF(__pyx_v_fields);
14848           __Pyx_INCREF(__pyx_v_record);
14849           PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
14850           __Pyx_GIVEREF(__pyx_v_record);
14851           __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 = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14852           __Pyx_GOTREF(__pyx_t_11);
14853           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14854           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
14855           __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14856           __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
14857         }
14858         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14859       }
14860       __pyx_L7:;
14861       goto __pyx_L5;
14862     }
14863     __pyx_L5:;
14864   }
14865   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14866
14867   /* "csamtools.pyx":1365
14868  * 
14869  *         # then: user tags (lower case), sorted alphabetically
14870  *         for record, data in sorted(new_header.items()):             # <<<<<<<<<<<<<<
14871  *             if record in VALID_HEADERS: continue
14872  *             if type( data ) is dict:
14873  */
14874   __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14875   __Pyx_GOTREF(__pyx_t_2);
14876   __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14877   __Pyx_GOTREF(__pyx_t_6);
14878   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14879   __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14880   __Pyx_GOTREF(__pyx_t_2);
14881   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
14882   __Pyx_GIVEREF(__pyx_t_6);
14883   __pyx_t_6 = 0;
14884   __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 = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14885   __Pyx_GOTREF(__pyx_t_6);
14886   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14887   if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
14888     __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
14889     __pyx_t_4 = NULL;
14890   } else {
14891     __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14892     __Pyx_GOTREF(__pyx_t_2);
14893     __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext;
14894   }
14895   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14896   for (;;) {
14897     if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) {
14898       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
14899       __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
14900     } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) {
14901       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
14902       __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
14903     } else {
14904       __pyx_t_6 = __pyx_t_4(__pyx_t_2);
14905       if (unlikely(!__pyx_t_6)) {
14906         if (PyErr_Occurred()) {
14907           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
14908           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14909         }
14910         break;
14911       }
14912       __Pyx_GOTREF(__pyx_t_6);
14913     }
14914     if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
14915       PyObject* sequence = __pyx_t_6;
14916       if (likely(PyTuple_CheckExact(sequence))) {
14917         if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
14918           if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
14919           else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
14920           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14921         }
14922         __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
14923         __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
14924       } else {
14925         if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
14926           if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
14927           else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
14928           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14929         }
14930         __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
14931         __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
14932       }
14933       __Pyx_INCREF(__pyx_t_11);
14934       __Pyx_INCREF(__pyx_t_1);
14935       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14936     } else {
14937       Py_ssize_t index = -1;
14938       __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14939       __Pyx_GOTREF(__pyx_t_7);
14940       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14941       __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext;
14942       index = 0; __pyx_t_11 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_11)) goto __pyx_L12_unpacking_failed;
14943       __Pyx_GOTREF(__pyx_t_11);
14944       index = 1; __pyx_t_1 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L12_unpacking_failed;
14945       __Pyx_GOTREF(__pyx_t_1);
14946       if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14947       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14948       goto __pyx_L13_unpacking_done;
14949       __pyx_L12_unpacking_failed:;
14950       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
14951       if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
14952       if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
14953       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14954       __pyx_L13_unpacking_done:;
14955     }
14956     __Pyx_XDECREF(__pyx_v_record);
14957     __pyx_v_record = __pyx_t_11;
14958     __pyx_t_11 = 0;
14959     __Pyx_XDECREF(__pyx_v_data);
14960     __pyx_v_data = __pyx_t_1;
14961     __pyx_t_1 = 0;
14962
14963     /* "csamtools.pyx":1366
14964  *         # then: user tags (lower case), sorted alphabetically
14965  *         for record, data in sorted(new_header.items()):
14966  *             if record in VALID_HEADERS: continue             # <<<<<<<<<<<<<<
14967  *             if type( data ) is dict:
14968  *                 lines.append( self._buildLine( data, record ) )
14969  */
14970     __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14971     __Pyx_GOTREF(__pyx_t_6);
14972     __pyx_t_5 = ((PySequence_Contains(__pyx_t_6, __pyx_v_record))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14973     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
14974     if (__pyx_t_5) {
14975       goto __pyx_L10_continue;
14976       goto __pyx_L14;
14977     }
14978     __pyx_L14:;
14979
14980     /* "csamtools.pyx":1367
14981  *         for record, data in sorted(new_header.items()):
14982  *             if record in VALID_HEADERS: continue
14983  *             if type( data ) is dict:             # <<<<<<<<<<<<<<
14984  *                 lines.append( self._buildLine( data, record ) )
14985  *             else:
14986  */
14987     __pyx_t_5 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
14988     if (__pyx_t_5) {
14989
14990       /* "csamtools.pyx":1368
14991  *             if record in VALID_HEADERS: continue
14992  *             if type( data ) is dict:
14993  *                 lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
14994  *             else:
14995  *                 for fields in new_header[record]:
14996  */
14997       __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 = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14998       __Pyx_GOTREF(__pyx_t_6);
14999       __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15000       __Pyx_GOTREF(__pyx_t_1);
15001       __Pyx_INCREF(__pyx_v_data);
15002       PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_data);
15003       __Pyx_GIVEREF(__pyx_v_data);
15004       __Pyx_INCREF(__pyx_v_record);
15005       PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
15006       __Pyx_GIVEREF(__pyx_v_record);
15007       __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 = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15008       __Pyx_GOTREF(__pyx_t_11);
15009       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
15010       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
15011       __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_11); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15012       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
15013       goto __pyx_L15;
15014     }
15015     /*else*/ {
15016
15017       /* "csamtools.pyx":1370
15018  *                 lines.append( self._buildLine( data, record ) )
15019  *             else:
15020  *                 for fields in new_header[record]:             # <<<<<<<<<<<<<<
15021  *                     lines.append( self._buildLine( fields, record ) )
15022  * 
15023  */
15024       __pyx_t_11 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15025       __Pyx_GOTREF(__pyx_t_11);
15026       if (PyList_CheckExact(__pyx_t_11) || PyTuple_CheckExact(__pyx_t_11)) {
15027         __pyx_t_1 = __pyx_t_11; __Pyx_INCREF(__pyx_t_1); __pyx_t_9 = 0;
15028         __pyx_t_10 = NULL;
15029       } else {
15030         __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15031         __Pyx_GOTREF(__pyx_t_1);
15032         __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
15033       }
15034       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
15035       for (;;) {
15036         if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_1)) {
15037           if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_1)) break;
15038           __pyx_t_11 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++;
15039         } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_1)) {
15040           if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
15041           __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_11); __pyx_t_9++;
15042         } else {
15043           __pyx_t_11 = __pyx_t_10(__pyx_t_1);
15044           if (unlikely(!__pyx_t_11)) {
15045             if (PyErr_Occurred()) {
15046               if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
15047               else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15048             }
15049             break;
15050           }
15051           __Pyx_GOTREF(__pyx_t_11);
15052         }
15053         __Pyx_XDECREF(__pyx_v_fields);
15054         __pyx_v_fields = __pyx_t_11;
15055         __pyx_t_11 = 0;
15056
15057         /* "csamtools.pyx":1371
15058  *             else:
15059  *                 for fields in new_header[record]:
15060  *                     lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
15061  * 
15062  *         text = "\n".join(lines) + "\n"
15063  */
15064         __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 = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15065         __Pyx_GOTREF(__pyx_t_11);
15066         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15067         __Pyx_GOTREF(__pyx_t_6);
15068         __Pyx_INCREF(__pyx_v_fields);
15069         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fields);
15070         __Pyx_GIVEREF(__pyx_v_fields);
15071         __Pyx_INCREF(__pyx_v_record);
15072         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_record);
15073         __Pyx_GIVEREF(__pyx_v_record);
15074         __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 = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15075         __Pyx_GOTREF(__pyx_t_7);
15076         __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
15077         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
15078         __pyx_t_8 = PyList_Append(__pyx_v_lines, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15079         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
15080       }
15081       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15082     }
15083     __pyx_L15:;
15084     __pyx_L10_continue:;
15085   }
15086   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15087
15088   /* "csamtools.pyx":1373
15089  *                     lines.append( self._buildLine( fields, record ) )
15090  * 
15091  *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
15092  *         if dest.text != NULL: free( dest.text )
15093  *         dest.text = <char*>calloc( len(text), sizeof(char))
15094  */
15095   __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 = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15096   __Pyx_GOTREF(__pyx_t_2);
15097   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15098   __Pyx_GOTREF(__pyx_t_1);
15099   __Pyx_INCREF(((PyObject *)__pyx_v_lines));
15100   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_lines));
15101   __Pyx_GIVEREF(((PyObject *)__pyx_v_lines));
15102   __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 = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15103   __Pyx_GOTREF(__pyx_t_7);
15104   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15105   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
15106   __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 = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15107   __Pyx_GOTREF(__pyx_t_1);
15108   __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
15109   __pyx_v_text = __pyx_t_1;
15110   __pyx_t_1 = 0;
15111
15112   /* "csamtools.pyx":1374
15113  * 
15114  *         text = "\n".join(lines) + "\n"
15115  *         if dest.text != NULL: free( dest.text )             # <<<<<<<<<<<<<<
15116  *         dest.text = <char*>calloc( len(text), sizeof(char))
15117  *         dest.l_text = len(text)
15118  */
15119   __pyx_t_5 = (__pyx_v_dest->text != NULL);
15120   if (__pyx_t_5) {
15121     free(__pyx_v_dest->text);
15122     goto __pyx_L18;
15123   }
15124   __pyx_L18:;
15125
15126   /* "csamtools.pyx":1375
15127  *         text = "\n".join(lines) + "\n"
15128  *         if dest.text != NULL: free( dest.text )
15129  *         dest.text = <char*>calloc( len(text), sizeof(char))             # <<<<<<<<<<<<<<
15130  *         dest.l_text = len(text)
15131  *         cdef bytes btext = text.encode('ascii')
15132  */
15133   __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15134   __pyx_v_dest->text = ((char *)calloc(__pyx_t_3, (sizeof(char))));
15135
15136   /* "csamtools.pyx":1376
15137  *         if dest.text != NULL: free( dest.text )
15138  *         dest.text = <char*>calloc( len(text), sizeof(char))
15139  *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
15140  *         cdef bytes btext = text.encode('ascii')
15141  *         strncpy( dest.text, btext, dest.l_text )
15142  */
15143   __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15144   __pyx_v_dest->l_text = __pyx_t_3;
15145
15146   /* "csamtools.pyx":1377
15147  *         dest.text = <char*>calloc( len(text), sizeof(char))
15148  *         dest.l_text = len(text)
15149  *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
15150  *         strncpy( dest.text, btext, dest.l_text )
15151  * 
15152  */
15153   __pyx_t_1 = PyObject_GetAttr(__pyx_v_text, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15154   __Pyx_GOTREF(__pyx_t_1);
15155   __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_112), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15156   __Pyx_GOTREF(__pyx_t_7);
15157   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15158   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 = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15159   __pyx_v_btext = ((PyObject*)__pyx_t_7);
15160   __pyx_t_7 = 0;
15161
15162   /* "csamtools.pyx":1378
15163  *         dest.l_text = len(text)
15164  *         cdef bytes btext = text.encode('ascii')
15165  *         strncpy( dest.text, btext, dest.l_text )             # <<<<<<<<<<<<<<
15166  * 
15167  *         cdef bytes bseqname
15168  */
15169   __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_btext)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15170   strncpy(__pyx_v_dest->text, __pyx_t_13, __pyx_v_dest->l_text);
15171
15172   /* "csamtools.pyx":1382
15173  *         cdef bytes bseqname
15174  *         # collect targets
15175  *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
15176  *             seqs = []
15177  *             for fields in new_header["SQ"]:
15178  */
15179   __pyx_t_5 = ((PySequence_Contains(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15180   if (__pyx_t_5) {
15181
15182     /* "csamtools.pyx":1383
15183  *         # collect targets
15184  *         if "SQ" in new_header:
15185  *             seqs = []             # <<<<<<<<<<<<<<
15186  *             for fields in new_header["SQ"]:
15187  *                 try:
15188  */
15189     __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15190     __Pyx_GOTREF(__pyx_t_7);
15191     __pyx_v_seqs = __pyx_t_7;
15192     __pyx_t_7 = 0;
15193
15194     /* "csamtools.pyx":1384
15195  *         if "SQ" in new_header:
15196  *             seqs = []
15197  *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
15198  *                 try:
15199  *                     seqs.append( (fields["SN"], fields["LN"] ) )
15200  */
15201     __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 = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15202     __Pyx_GOTREF(__pyx_t_7);
15203     if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) {
15204       __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
15205       __pyx_t_4 = NULL;
15206     } else {
15207       __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15208       __Pyx_GOTREF(__pyx_t_1);
15209       __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext;
15210     }
15211     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
15212     for (;;) {
15213       if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) {
15214         if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
15215         __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++;
15216       } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) {
15217         if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
15218         __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++;
15219       } else {
15220         __pyx_t_7 = __pyx_t_4(__pyx_t_1);
15221         if (unlikely(!__pyx_t_7)) {
15222           if (PyErr_Occurred()) {
15223             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
15224             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15225           }
15226           break;
15227         }
15228         __Pyx_GOTREF(__pyx_t_7);
15229       }
15230       __Pyx_XDECREF(__pyx_v_fields);
15231       __pyx_v_fields = __pyx_t_7;
15232       __pyx_t_7 = 0;
15233
15234       /* "csamtools.pyx":1385
15235  *             seqs = []
15236  *             for fields in new_header["SQ"]:
15237  *                 try:             # <<<<<<<<<<<<<<
15238  *                     seqs.append( (fields["SN"], fields["LN"] ) )
15239  *                 except KeyError:
15240  */
15241       {
15242         __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);
15243         __Pyx_XGOTREF(__pyx_t_14);
15244         __Pyx_XGOTREF(__pyx_t_15);
15245         __Pyx_XGOTREF(__pyx_t_16);
15246         /*try:*/ {
15247
15248           /* "csamtools.pyx":1386
15249  *             for fields in new_header["SQ"]:
15250  *                 try:
15251  *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
15252  *                 except KeyError:
15253  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
15254  */
15255           __pyx_t_7 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__SN)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
15256           __Pyx_GOTREF(__pyx_t_7);
15257           __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__LN)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
15258           __Pyx_GOTREF(__pyx_t_2);
15259           __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
15260           __Pyx_GOTREF(__pyx_t_6);
15261           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
15262           __Pyx_GIVEREF(__pyx_t_7);
15263           PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
15264           __Pyx_GIVEREF(__pyx_t_2);
15265           __pyx_t_7 = 0;
15266           __pyx_t_2 = 0;
15267           __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 = 1386; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
15268           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
15269         }
15270         __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
15271         __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
15272         __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
15273         goto __pyx_L29_try_end;
15274         __pyx_L22_error:;
15275         __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
15276         __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
15277         __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
15278         __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
15279
15280         /* "csamtools.pyx":1387
15281  *                 try:
15282  *                     seqs.append( (fields["SN"], fields["LN"] ) )
15283  *                 except KeyError:             # <<<<<<<<<<<<<<
15284  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
15285  * 
15286  */
15287         __pyx_t_17 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
15288         if (__pyx_t_17) {
15289           __Pyx_AddTraceback("csamtools.Samfile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
15290           if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_2, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15291           __Pyx_GOTREF(__pyx_t_6);
15292           __Pyx_GOTREF(__pyx_t_2);
15293           __Pyx_GOTREF(__pyx_t_7);
15294
15295           /* "csamtools.pyx":1388
15296  *                     seqs.append( (fields["SN"], fields["LN"] ) )
15297  *                 except KeyError:
15298  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
15299  * 
15300  *             dest.n_targets = len(seqs)
15301  */
15302           __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15303           __Pyx_GOTREF(__pyx_t_11);
15304           __Pyx_INCREF(__pyx_v_fields);
15305           PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_fields);
15306           __Pyx_GIVEREF(__pyx_v_fields);
15307           __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 = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15308           __Pyx_GOTREF(__pyx_t_18);
15309           __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
15310           __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_113), __pyx_t_18); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15311           __Pyx_GOTREF(((PyObject *)__pyx_t_11));
15312           __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
15313           __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15314           __Pyx_GOTREF(__pyx_t_18);
15315           PyTuple_SET_ITEM(__pyx_t_18, 0, ((PyObject *)__pyx_t_11));
15316           __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
15317           __pyx_t_11 = 0;
15318           __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 = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15319           __Pyx_GOTREF(__pyx_t_11);
15320           __Pyx_DECREF(((PyObject *)__pyx_t_18)); __pyx_t_18 = 0;
15321           __Pyx_Raise(__pyx_t_11, 0, 0, 0);
15322           __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
15323           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
15324           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
15325           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15326           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
15327           goto __pyx_L23_exception_handled;
15328         }
15329         __pyx_L24_except_error:;
15330         __Pyx_XGIVEREF(__pyx_t_14);
15331         __Pyx_XGIVEREF(__pyx_t_15);
15332         __Pyx_XGIVEREF(__pyx_t_16);
15333         __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
15334         goto __pyx_L1_error;
15335         __pyx_L23_exception_handled:;
15336         __Pyx_XGIVEREF(__pyx_t_14);
15337         __Pyx_XGIVEREF(__pyx_t_15);
15338         __Pyx_XGIVEREF(__pyx_t_16);
15339         __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16);
15340         __pyx_L29_try_end:;
15341       }
15342     }
15343     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15344
15345     /* "csamtools.pyx":1390
15346  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
15347  * 
15348  *             dest.n_targets = len(seqs)             # <<<<<<<<<<<<<<
15349  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
15350  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
15351  */
15352     __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_seqs)); 
15353     __pyx_v_dest->n_targets = __pyx_t_3;
15354
15355     /* "csamtools.pyx":1391
15356  * 
15357  *             dest.n_targets = len(seqs)
15358  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )             # <<<<<<<<<<<<<<
15359  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
15360  * 
15361  */
15362     __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *))));
15363
15364     /* "csamtools.pyx":1392
15365  *             dest.n_targets = len(seqs)
15366  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
15367  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )             # <<<<<<<<<<<<<<
15368  * 
15369  *             for x from 0 <= x < dest.n_targets:
15370  */
15371     __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t))));
15372
15373     /* "csamtools.pyx":1394
15374  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
15375  * 
15376  *             for x from 0 <= x < dest.n_targets:             # <<<<<<<<<<<<<<
15377  *                 seqname, seqlen = seqs[x]
15378  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
15379  */
15380     __pyx_t_19 = __pyx_v_dest->n_targets;
15381     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_19; __pyx_v_x++) {
15382
15383       /* "csamtools.pyx":1395
15384  * 
15385  *             for x from 0 <= x < dest.n_targets:
15386  *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
15387  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
15388  *                 bseqname = seqname.encode('ascii')
15389  */
15390       __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 = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15391       __Pyx_GOTREF(__pyx_t_1);
15392       if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
15393         PyObject* sequence = __pyx_t_1;
15394         if (likely(PyTuple_CheckExact(sequence))) {
15395           if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
15396             if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
15397             else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
15398             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15399           }
15400           __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
15401           __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
15402         } else {
15403           if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
15404             if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
15405             else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
15406             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15407           }
15408           __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
15409           __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
15410         }
15411         __Pyx_INCREF(__pyx_t_7);
15412         __Pyx_INCREF(__pyx_t_2);
15413         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15414       } else {
15415         Py_ssize_t index = -1;
15416         __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15417         __Pyx_GOTREF(__pyx_t_6);
15418         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15419         __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
15420         index = 0; __pyx_t_7 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_7)) goto __pyx_L34_unpacking_failed;
15421         __Pyx_GOTREF(__pyx_t_7);
15422         index = 1; __pyx_t_2 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L34_unpacking_failed;
15423         __Pyx_GOTREF(__pyx_t_2);
15424         if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15425         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
15426         goto __pyx_L35_unpacking_done;
15427         __pyx_L34_unpacking_failed:;
15428         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
15429         if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
15430         if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
15431         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15432         __pyx_L35_unpacking_done:;
15433       }
15434       __Pyx_XDECREF(__pyx_v_seqname);
15435       __pyx_v_seqname = __pyx_t_7;
15436       __pyx_t_7 = 0;
15437       __Pyx_XDECREF(__pyx_v_seqlen);
15438       __pyx_v_seqlen = __pyx_t_2;
15439       __pyx_t_2 = 0;
15440
15441       /* "csamtools.pyx":1396
15442  *             for x from 0 <= x < dest.n_targets:
15443  *                 seqname, seqlen = seqs[x]
15444  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )             # <<<<<<<<<<<<<<
15445  *                 bseqname = seqname.encode('ascii')
15446  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
15447  */
15448       __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15449       (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_3 + 1), (sizeof(char))));
15450
15451       /* "csamtools.pyx":1397
15452  *                 seqname, seqlen = seqs[x]
15453  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
15454  *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
15455  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
15456  *                 dest.target_len[x] = seqlen
15457  */
15458       __pyx_t_1 = PyObject_GetAttr(__pyx_v_seqname, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15459       __Pyx_GOTREF(__pyx_t_1);
15460       __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_114), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15461       __Pyx_GOTREF(__pyx_t_2);
15462       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15463       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 = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15464       __Pyx_XDECREF(((PyObject *)__pyx_v_bseqname));
15465       __pyx_v_bseqname = ((PyObject*)__pyx_t_2);
15466       __pyx_t_2 = 0;
15467
15468       /* "csamtools.pyx":1398
15469  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
15470  *                 bseqname = seqname.encode('ascii')
15471  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )             # <<<<<<<<<<<<<<
15472  *                 dest.target_len[x] = seqlen
15473  * 
15474  */
15475       __pyx_t_13 = PyBytes_AsString(((PyObject *)__pyx_v_bseqname)); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15476       __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15477       strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_13, (__pyx_t_3 + 1));
15478
15479       /* "csamtools.pyx":1399
15480  *                 bseqname = seqname.encode('ascii')
15481  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
15482  *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
15483  * 
15484  *         return dest
15485  */
15486       __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 = 1399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15487       (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_20;
15488     }
15489     goto __pyx_L19;
15490   }
15491   __pyx_L19:;
15492
15493   /* "csamtools.pyx":1401
15494  *                 dest.target_len[x] = seqlen
15495  * 
15496  *         return dest             # <<<<<<<<<<<<<<
15497  * 
15498  *     ###############################################################
15499  */
15500   __pyx_r = __pyx_v_dest;
15501   goto __pyx_L0;
15502
15503   __pyx_r = 0;
15504   goto __pyx_L0;
15505   __pyx_L1_error:;
15506   __Pyx_XDECREF(__pyx_t_1);
15507   __Pyx_XDECREF(__pyx_t_2);
15508   __Pyx_XDECREF(__pyx_t_6);
15509   __Pyx_XDECREF(__pyx_t_7);
15510   __Pyx_XDECREF(__pyx_t_11);
15511   __Pyx_XDECREF(__pyx_t_18);
15512   __Pyx_WriteUnraisable("csamtools.Samfile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
15513   __pyx_r = 0;
15514   __pyx_L0:;
15515   __Pyx_XDECREF(__pyx_v_lines);
15516   __Pyx_XDECREF(__pyx_v_record);
15517   __Pyx_XDECREF(__pyx_v_ttype);
15518   __Pyx_XDECREF(__pyx_v_data);
15519   __Pyx_XDECREF(__pyx_v_fields);
15520   __Pyx_XDECREF(__pyx_v_text);
15521   __Pyx_XDECREF(__pyx_v_btext);
15522   __Pyx_XDECREF(__pyx_v_bseqname);
15523   __Pyx_XDECREF(__pyx_v_seqs);
15524   __Pyx_XDECREF(__pyx_v_seqname);
15525   __Pyx_XDECREF(__pyx_v_seqlen);
15526   __Pyx_TraceReturn(Py_None);
15527   __Pyx_RefNannyFinishContext();
15528   return __pyx_r;
15529 }
15530
15531 /* Python wrapper */
15532 static PyObject *__pyx_pw_9csamtools_7Samfile_41__iter__(PyObject *__pyx_v_self); /*proto*/
15533 static PyObject *__pyx_pw_9csamtools_7Samfile_41__iter__(PyObject *__pyx_v_self) {
15534   PyObject *__pyx_r = 0;
15535   __Pyx_RefNannyDeclarations
15536   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
15537   __pyx_r = __pyx_pf_9csamtools_7Samfile_40__iter__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
15538   __Pyx_RefNannyFinishContext();
15539   return __pyx_r;
15540 }
15541
15542 /* "csamtools.pyx":1411
15543  *     ## Possible solutions: deprecate or open new file handle
15544  *     ###############################################################
15545  *     def __iter__(self):             # <<<<<<<<<<<<<<
15546  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
15547  *         if not self.isbam and self.samfile.header.n_targets == 0:
15548  */
15549
15550 static PyObject *__pyx_pf_9csamtools_7Samfile_40__iter__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
15551   PyObject *__pyx_r = NULL;
15552   __Pyx_RefNannyDeclarations
15553   PyObject *__pyx_t_1 = NULL;
15554   PyObject *__pyx_t_2 = NULL;
15555   int __pyx_t_3;
15556   int __pyx_t_4;
15557   int __pyx_t_5;
15558   int __pyx_lineno = 0;
15559   const char *__pyx_filename = NULL;
15560   int __pyx_clineno = 0;
15561   __Pyx_TraceDeclarations
15562   __Pyx_RefNannySetupContext("__iter__", 0);
15563   __Pyx_TraceCall("__iter__", __pyx_f[0], 1411);
15564
15565   /* "csamtools.pyx":1412
15566  *     ###############################################################
15567  *     def __iter__(self):
15568  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
15569  *         if not self.isbam and self.samfile.header.n_targets == 0:
15570  *                 raise NotImplementedError( "can not iterate over samfile without header")
15571  */
15572   __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 = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15573   __Pyx_GOTREF(__pyx_t_1);
15574   __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 = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15575   __Pyx_GOTREF(__pyx_t_2);
15576   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15577   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15578   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15579   __pyx_t_4 = (!__pyx_t_3);
15580   if (__pyx_t_4) {
15581     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_115), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15582     __Pyx_GOTREF(__pyx_t_2);
15583     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
15584     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15585     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15586     goto __pyx_L3;
15587   }
15588   __pyx_L3:;
15589
15590   /* "csamtools.pyx":1413
15591  *     def __iter__(self):
15592  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
15593  *         if not self.isbam and self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
15594  *                 raise NotImplementedError( "can not iterate over samfile without header")
15595  *         return self
15596  */
15597   __pyx_t_4 = (!__pyx_v_self->isbam);
15598   if (__pyx_t_4) {
15599     __pyx_t_3 = (__pyx_v_self->samfile->header->n_targets == 0);
15600     __pyx_t_5 = __pyx_t_3;
15601   } else {
15602     __pyx_t_5 = __pyx_t_4;
15603   }
15604   if (__pyx_t_5) {
15605
15606     /* "csamtools.pyx":1414
15607  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
15608  *         if not self.isbam and self.samfile.header.n_targets == 0:
15609  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
15610  *         return self
15611  * 
15612  */
15613     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_117), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15614     __Pyx_GOTREF(__pyx_t_2);
15615     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
15616     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15617     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15618     goto __pyx_L4;
15619   }
15620   __pyx_L4:;
15621
15622   /* "csamtools.pyx":1415
15623  *         if not self.isbam and self.samfile.header.n_targets == 0:
15624  *                 raise NotImplementedError( "can not iterate over samfile without header")
15625  *         return self             # <<<<<<<<<<<<<<
15626  * 
15627  *     cdef bam1_t * getCurrent( self ):
15628  */
15629   __Pyx_XDECREF(__pyx_r);
15630   __Pyx_INCREF(((PyObject *)__pyx_v_self));
15631   __pyx_r = ((PyObject *)__pyx_v_self);
15632   goto __pyx_L0;
15633
15634   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15635   goto __pyx_L0;
15636   __pyx_L1_error:;
15637   __Pyx_XDECREF(__pyx_t_1);
15638   __Pyx_XDECREF(__pyx_t_2);
15639   __Pyx_AddTraceback("csamtools.Samfile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
15640   __pyx_r = NULL;
15641   __pyx_L0:;
15642   __Pyx_XGIVEREF(__pyx_r);
15643   __Pyx_TraceReturn(__pyx_r);
15644   __Pyx_RefNannyFinishContext();
15645   return __pyx_r;
15646 }
15647
15648 /* "csamtools.pyx":1417
15649  *         return self
15650  * 
15651  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
15652  *         return self.b
15653  * 
15654  */
15655
15656 static bam1_t *__pyx_f_9csamtools_7Samfile_getCurrent(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
15657   bam1_t *__pyx_r;
15658   __Pyx_RefNannyDeclarations
15659   __Pyx_TraceDeclarations
15660   __Pyx_RefNannySetupContext("getCurrent", 0);
15661   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1417);
15662
15663   /* "csamtools.pyx":1418
15664  * 
15665  *     cdef bam1_t * getCurrent( self ):
15666  *         return self.b             # <<<<<<<<<<<<<<
15667  * 
15668  *     cdef int cnext(self):
15669  */
15670   __pyx_r = __pyx_v_self->b;
15671   goto __pyx_L0;
15672
15673   __pyx_r = 0;
15674   __pyx_L0:;
15675   __Pyx_TraceReturn(Py_None);
15676   __Pyx_RefNannyFinishContext();
15677   return __pyx_r;
15678 }
15679
15680 /* "csamtools.pyx":1420
15681  *         return self.b
15682  * 
15683  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
15684  *         '''
15685  *         cversion of iterator. Used by :class:`pysam.Samfile.IteratorColumn`.
15686  */
15687
15688 static int __pyx_f_9csamtools_7Samfile_cnext(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
15689   int __pyx_r;
15690   __Pyx_RefNannyDeclarations
15691   __Pyx_TraceDeclarations
15692   __Pyx_RefNannySetupContext("cnext", 0);
15693   __Pyx_TraceCall("cnext", __pyx_f[0], 1420);
15694
15695   /* "csamtools.pyx":1425
15696  *         '''
15697  *         cdef int ret
15698  *         return samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
15699  * 
15700  *     def __next__(self):
15701  */
15702   __pyx_r = samread(__pyx_v_self->samfile, __pyx_v_self->b);
15703   goto __pyx_L0;
15704
15705   __pyx_r = 0;
15706   __pyx_L0:;
15707   __Pyx_TraceReturn(Py_None);
15708   __Pyx_RefNannyFinishContext();
15709   return __pyx_r;
15710 }
15711
15712 /* Python wrapper */
15713 static PyObject *__pyx_pw_9csamtools_7Samfile_43__next__(PyObject *__pyx_v_self); /*proto*/
15714 static char __pyx_doc_9csamtools_7Samfile_42__next__[] = "\n        python version of next().\n        ";
15715 struct wrapperbase __pyx_wrapperbase_9csamtools_7Samfile_42__next__;
15716 static PyObject *__pyx_pw_9csamtools_7Samfile_43__next__(PyObject *__pyx_v_self) {
15717   PyObject *__pyx_r = 0;
15718   __Pyx_RefNannyDeclarations
15719   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
15720   __pyx_r = __pyx_pf_9csamtools_7Samfile_42__next__(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self));
15721   __Pyx_RefNannyFinishContext();
15722   return __pyx_r;
15723 }
15724
15725 /* "csamtools.pyx":1427
15726  *         return samread(self.samfile, self.b)
15727  * 
15728  *     def __next__(self):             # <<<<<<<<<<<<<<
15729  *         """
15730  *         python version of next().
15731  */
15732
15733 static PyObject *__pyx_pf_9csamtools_7Samfile_42__next__(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
15734   int __pyx_v_ret;
15735   PyObject *__pyx_r = NULL;
15736   __Pyx_RefNannyDeclarations
15737   int __pyx_t_1;
15738   PyObject *__pyx_t_2 = NULL;
15739   int __pyx_lineno = 0;
15740   const char *__pyx_filename = NULL;
15741   int __pyx_clineno = 0;
15742   __Pyx_TraceDeclarations
15743   __Pyx_RefNannySetupContext("__next__", 0);
15744   __Pyx_TraceCall("__next__", __pyx_f[0], 1427);
15745
15746   /* "csamtools.pyx":1432
15747  *         """
15748  *         cdef int ret
15749  *         ret = samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
15750  *         if (ret > 0):
15751  *             return makeAlignedRead( self.b )
15752  */
15753   __pyx_v_ret = samread(__pyx_v_self->samfile, __pyx_v_self->b);
15754
15755   /* "csamtools.pyx":1433
15756  *         cdef int ret
15757  *         ret = samread(self.samfile, self.b)
15758  *         if (ret > 0):             # <<<<<<<<<<<<<<
15759  *             return makeAlignedRead( self.b )
15760  *         else:
15761  */
15762   __pyx_t_1 = (__pyx_v_ret > 0);
15763   if (__pyx_t_1) {
15764
15765     /* "csamtools.pyx":1434
15766  *         ret = samread(self.samfile, self.b)
15767  *         if (ret > 0):
15768  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
15769  *         else:
15770  *             raise StopIteration
15771  */
15772     __Pyx_XDECREF(__pyx_r);
15773     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15774     __Pyx_GOTREF(__pyx_t_2);
15775     __pyx_r = __pyx_t_2;
15776     __pyx_t_2 = 0;
15777     goto __pyx_L0;
15778     goto __pyx_L3;
15779   }
15780   /*else*/ {
15781
15782     /* "csamtools.pyx":1436
15783  *             return makeAlignedRead( self.b )
15784  *         else:
15785  *             raise StopIteration             # <<<<<<<<<<<<<<
15786  * 
15787  * ##-------------------------------------------------------------------
15788  */
15789     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
15790     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15791   }
15792   __pyx_L3:;
15793
15794   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15795   goto __pyx_L0;
15796   __pyx_L1_error:;
15797   __Pyx_XDECREF(__pyx_t_2);
15798   __Pyx_AddTraceback("csamtools.Samfile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
15799   __pyx_r = NULL;
15800   __pyx_L0:;
15801   __Pyx_XGIVEREF(__pyx_r);
15802   __Pyx_TraceReturn(__pyx_r);
15803   __Pyx_RefNannyFinishContext();
15804   return __pyx_r;
15805 }
15806
15807 /* Python wrapper */
15808 static int __pyx_pw_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
15809 static int __pyx_pw_9csamtools_17IteratorRowRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
15810   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
15811   int __pyx_v_tid;
15812   int __pyx_v_beg;
15813   int __pyx_v_end;
15814   int __pyx_v_reopen;
15815   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__tid,&__pyx_n_s__beg,&__pyx_n_s__end,&__pyx_n_s__reopen,0};
15816   int __pyx_r;
15817   __Pyx_RefNannyDeclarations
15818   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
15819   {
15820     PyObject* values[5] = {0,0,0,0,0};
15821     if (unlikely(__pyx_kwds)) {
15822       Py_ssize_t kw_args;
15823       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
15824       switch (pos_args) {
15825         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
15826         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
15827         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
15828         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
15829         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
15830         case  0: break;
15831         default: goto __pyx_L5_argtuple_error;
15832       }
15833       kw_args = PyDict_Size(__pyx_kwds);
15834       switch (pos_args) {
15835         case  0:
15836         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
15837         if (likely(values[0])) kw_args--;
15838         else goto __pyx_L5_argtuple_error;
15839         case  1:
15840         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
15841         if (likely(values[1])) kw_args--;
15842         else {
15843           __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15844         }
15845         case  2:
15846         values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beg);
15847         if (likely(values[2])) kw_args--;
15848         else {
15849           __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15850         }
15851         case  3:
15852         values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
15853         if (likely(values[3])) kw_args--;
15854         else {
15855           __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15856         }
15857         case  4:
15858         if (kw_args > 0) {
15859           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
15860           if (value) { values[4] = value; kw_args--; }
15861         }
15862       }
15863       if (unlikely(kw_args > 0)) {
15864         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15865       }
15866       if (values[4]) {
15867       } else {
15868
15869         /* "csamtools.pyx":1481
15870  *     """
15871  * 
15872  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):             # <<<<<<<<<<<<<<
15873  * 
15874  *         if not samfile._isOpen():
15875  */
15876         __pyx_v_reopen = ((int)1);
15877       }
15878     } else {
15879       switch (PyTuple_GET_SIZE(__pyx_args)) {
15880         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
15881         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
15882         values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
15883         values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
15884         values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
15885         break;
15886         default: goto __pyx_L5_argtuple_error;
15887       }
15888     }
15889     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
15890     __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15891     __pyx_v_beg = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15892     __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15893     if (values[4]) {
15894       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15895     } else {
15896       __pyx_v_reopen = ((int)1);
15897     }
15898   }
15899   goto __pyx_L4_argument_unpacking_done;
15900   __pyx_L5_argtuple_error:;
15901   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15902   __pyx_L3_error:;
15903   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
15904   __Pyx_RefNannyFinishContext();
15905   return -1;
15906   __pyx_L4_argument_unpacking_done:;
15907   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15908   __pyx_r = __pyx_pf_9csamtools_17IteratorRowRegion___cinit__(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_end, __pyx_v_reopen);
15909   goto __pyx_L0;
15910   __pyx_L1_error:;
15911   __pyx_r = -1;
15912   __pyx_L0:;
15913   __Pyx_RefNannyFinishContext();
15914   return __pyx_r;
15915 }
15916
15917 static int __pyx_pf_9csamtools_17IteratorRowRegion___cinit__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_reopen) {
15918   PyObject *__pyx_v_mode = NULL;
15919   PyObject *__pyx_v_store = NULL;
15920   int __pyx_r;
15921   __Pyx_RefNannyDeclarations
15922   PyObject *__pyx_t_1 = NULL;
15923   PyObject *__pyx_t_2 = NULL;
15924   int __pyx_t_3;
15925   int __pyx_t_4;
15926   char *__pyx_t_5;
15927   int __pyx_lineno = 0;
15928   const char *__pyx_filename = NULL;
15929   int __pyx_clineno = 0;
15930   __Pyx_TraceDeclarations
15931   __Pyx_RefNannySetupContext("__cinit__", 0);
15932   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1481);
15933
15934   /* "csamtools.pyx":1483
15935  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):
15936  * 
15937  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
15938  *             raise ValueError( "I/O operation on closed file" )
15939  * 
15940  */
15941   __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 = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15942   __Pyx_GOTREF(__pyx_t_1);
15943   __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 = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15944   __Pyx_GOTREF(__pyx_t_2);
15945   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15946   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15947   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15948   __pyx_t_4 = (!__pyx_t_3);
15949   if (__pyx_t_4) {
15950
15951     /* "csamtools.pyx":1484
15952  * 
15953  *         if not samfile._isOpen():
15954  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
15955  * 
15956  *         if not samfile._hasIndex():
15957  */
15958     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_118), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15959     __Pyx_GOTREF(__pyx_t_2);
15960     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
15961     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15962     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15963     goto __pyx_L3;
15964   }
15965   __pyx_L3:;
15966
15967   /* "csamtools.pyx":1486
15968  *             raise ValueError( "I/O operation on closed file" )
15969  * 
15970  *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
15971  *             raise ValueError( "no index available for iteration" )
15972  * 
15973  */
15974   __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 = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15975   __Pyx_GOTREF(__pyx_t_2);
15976   __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 = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15977   __Pyx_GOTREF(__pyx_t_1);
15978   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15979   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15980   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15981   __pyx_t_3 = (!__pyx_t_4);
15982   if (__pyx_t_3) {
15983
15984     /* "csamtools.pyx":1487
15985  * 
15986  *         if not samfile._hasIndex():
15987  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
15988  * 
15989  *         # makes sure that samfile stays alive as long as the
15990  */
15991     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15992     __Pyx_GOTREF(__pyx_t_1);
15993     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
15994     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15995     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15996     goto __pyx_L4;
15997   }
15998   __pyx_L4:;
15999
16000   /* "csamtools.pyx":1491
16001  *         # makes sure that samfile stays alive as long as the
16002  *         # iterator is alive
16003  *         self.samfile = samfile             # <<<<<<<<<<<<<<
16004  * 
16005  *         if samfile.isbam: mode = b"rb"
16006  */
16007   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
16008   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
16009   __Pyx_GOTREF(__pyx_v_self->samfile);
16010   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
16011   __pyx_v_self->samfile = __pyx_v_samfile;
16012
16013   /* "csamtools.pyx":1493
16014  *         self.samfile = samfile
16015  * 
16016  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
16017  *         else: mode = b"r"
16018  * 
16019  */
16020   if (__pyx_v_samfile->isbam) {
16021     __Pyx_INCREF(((PyObject *)__pyx_n_b__rb));
16022     __pyx_v_mode = __pyx_n_b__rb;
16023     goto __pyx_L5;
16024   }
16025   /*else*/ {
16026
16027     /* "csamtools.pyx":1494
16028  * 
16029  *         if samfile.isbam: mode = b"rb"
16030  *         else: mode = b"r"             # <<<<<<<<<<<<<<
16031  * 
16032  *         # reopen the file - note that this makes the iterator
16033  */
16034     __Pyx_INCREF(((PyObject *)__pyx_n_b__r));
16035     __pyx_v_mode = __pyx_n_b__r;
16036   }
16037   __pyx_L5:;
16038
16039   /* "csamtools.pyx":1498
16040  *         # reopen the file - note that this makes the iterator
16041  *         # slow and causes pileup to slow down significantly.
16042  *         if reopen:             # <<<<<<<<<<<<<<
16043  *             store = StderrStore()
16044  *             self.fp = samopen( samfile._filename, mode, NULL )
16045  */
16046   if (__pyx_v_reopen) {
16047
16048     /* "csamtools.pyx":1499
16049  *         # slow and causes pileup to slow down significantly.
16050  *         if reopen:
16051  *             store = StderrStore()             # <<<<<<<<<<<<<<
16052  *             self.fp = samopen( samfile._filename, mode, NULL )
16053  *             store.release()
16054  */
16055     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16056     __Pyx_GOTREF(__pyx_t_1);
16057     __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 = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16058     __Pyx_GOTREF(__pyx_t_2);
16059     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16060     __pyx_v_store = __pyx_t_2;
16061     __pyx_t_2 = 0;
16062
16063     /* "csamtools.pyx":1500
16064  *         if reopen:
16065  *             store = StderrStore()
16066  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
16067  *             store.release()
16068  *             assert self.fp != NULL
16069  */
16070     __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16071     __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
16072
16073     /* "csamtools.pyx":1501
16074  *             store = StderrStore()
16075  *             self.fp = samopen( samfile._filename, mode, NULL )
16076  *             store.release()             # <<<<<<<<<<<<<<
16077  *             assert self.fp != NULL
16078  *             self.owns_samfile = True
16079  */
16080     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16081     __Pyx_GOTREF(__pyx_t_2);
16082     __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 = 1501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16083     __Pyx_GOTREF(__pyx_t_1);
16084     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16085     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16086
16087     /* "csamtools.pyx":1502
16088  *             self.fp = samopen( samfile._filename, mode, NULL )
16089  *             store.release()
16090  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
16091  *             self.owns_samfile = True
16092  *         else:
16093  */
16094     #ifndef CYTHON_WITHOUT_ASSERTIONS
16095     if (unlikely(!(__pyx_v_self->fp != NULL))) {
16096       PyErr_SetNone(PyExc_AssertionError);
16097       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16098     }
16099     #endif
16100
16101     /* "csamtools.pyx":1503
16102  *             store.release()
16103  *             assert self.fp != NULL
16104  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
16105  *         else:
16106  *             self.fp = self.samfile.samfile
16107  */
16108     __pyx_v_self->owns_samfile = 1;
16109     goto __pyx_L6;
16110   }
16111   /*else*/ {
16112
16113     /* "csamtools.pyx":1505
16114  *             self.owns_samfile = True
16115  *         else:
16116  *             self.fp = self.samfile.samfile             # <<<<<<<<<<<<<<
16117  *             self.owns_samfile = False
16118  * 
16119  */
16120     __pyx_v_self->fp = __pyx_v_self->samfile->samfile;
16121
16122     /* "csamtools.pyx":1506
16123  *         else:
16124  *             self.fp = self.samfile.samfile
16125  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
16126  * 
16127  *         self.retval = 0
16128  */
16129     __pyx_v_self->owns_samfile = 0;
16130   }
16131   __pyx_L6:;
16132
16133   /* "csamtools.pyx":1508
16134  *             self.owns_samfile = False
16135  * 
16136  *         self.retval = 0             # <<<<<<<<<<<<<<
16137  * 
16138  *         self.iter = bam_iter_query(self.samfile.index,
16139  */
16140   __pyx_v_self->retval = 0;
16141
16142   /* "csamtools.pyx":1510
16143  *         self.retval = 0
16144  * 
16145  *         self.iter = bam_iter_query(self.samfile.index,             # <<<<<<<<<<<<<<
16146  *                                    tid,
16147  *                                    beg,
16148  */
16149   __pyx_v_self->iter = bam_iter_query(__pyx_v_self->samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);
16150
16151   /* "csamtools.pyx":1514
16152  *                                    beg,
16153  *                                    end)
16154  *         self.b = bam_init1()             # <<<<<<<<<<<<<<
16155  * 
16156  *     def __iter__(self):
16157  */
16158   __pyx_v_self->b = bam_init1();
16159
16160   __pyx_r = 0;
16161   goto __pyx_L0;
16162   __pyx_L1_error:;
16163   __Pyx_XDECREF(__pyx_t_1);
16164   __Pyx_XDECREF(__pyx_t_2);
16165   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16166   __pyx_r = -1;
16167   __pyx_L0:;
16168   __Pyx_XDECREF(__pyx_v_mode);
16169   __Pyx_XDECREF(__pyx_v_store);
16170   __Pyx_TraceReturn(Py_None);
16171   __Pyx_RefNannyFinishContext();
16172   return __pyx_r;
16173 }
16174
16175 /* Python wrapper */
16176 static PyObject *__pyx_pw_9csamtools_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self); /*proto*/
16177 static PyObject *__pyx_pw_9csamtools_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self) {
16178   PyObject *__pyx_r = 0;
16179   __Pyx_RefNannyDeclarations
16180   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
16181   __pyx_r = __pyx_pf_9csamtools_17IteratorRowRegion_2__iter__(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self));
16182   __Pyx_RefNannyFinishContext();
16183   return __pyx_r;
16184 }
16185
16186 /* "csamtools.pyx":1516
16187  *         self.b = bam_init1()
16188  * 
16189  *     def __iter__(self):             # <<<<<<<<<<<<<<
16190  *         return self
16191  * 
16192  */
16193
16194 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_2__iter__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
16195   PyObject *__pyx_r = NULL;
16196   __Pyx_RefNannyDeclarations
16197   __Pyx_TraceDeclarations
16198   __Pyx_RefNannySetupContext("__iter__", 0);
16199   __Pyx_TraceCall("__iter__", __pyx_f[0], 1516);
16200
16201   /* "csamtools.pyx":1517
16202  * 
16203  *     def __iter__(self):
16204  *         return self             # <<<<<<<<<<<<<<
16205  * 
16206  *     cdef bam1_t * getCurrent( self ):
16207  */
16208   __Pyx_XDECREF(__pyx_r);
16209   __Pyx_INCREF(((PyObject *)__pyx_v_self));
16210   __pyx_r = ((PyObject *)__pyx_v_self);
16211   goto __pyx_L0;
16212
16213   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16214   __pyx_L0:;
16215   __Pyx_XGIVEREF(__pyx_r);
16216   __Pyx_TraceReturn(__pyx_r);
16217   __Pyx_RefNannyFinishContext();
16218   return __pyx_r;
16219 }
16220
16221 /* "csamtools.pyx":1519
16222  *         return self
16223  * 
16224  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
16225  *         return self.b
16226  * 
16227  */
16228
16229 static bam1_t *__pyx_f_9csamtools_17IteratorRowRegion_getCurrent(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
16230   bam1_t *__pyx_r;
16231   __Pyx_RefNannyDeclarations
16232   __Pyx_TraceDeclarations
16233   __Pyx_RefNannySetupContext("getCurrent", 0);
16234   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1519);
16235
16236   /* "csamtools.pyx":1520
16237  * 
16238  *     cdef bam1_t * getCurrent( self ):
16239  *         return self.b             # <<<<<<<<<<<<<<
16240  * 
16241  *     cdef int cnext(self):
16242  */
16243   __pyx_r = __pyx_v_self->b;
16244   goto __pyx_L0;
16245
16246   __pyx_r = 0;
16247   __pyx_L0:;
16248   __Pyx_TraceReturn(Py_None);
16249   __Pyx_RefNannyFinishContext();
16250   return __pyx_r;
16251 }
16252
16253 /* "csamtools.pyx":1522
16254  *         return self.b
16255  * 
16256  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
16257  *         '''cversion of iterator. Used by IteratorColumn'''
16258  *         self.retval = bam_iter_read( self.fp.x.bam,
16259  */
16260
16261 static int __pyx_f_9csamtools_17IteratorRowRegion_cnext(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
16262   int __pyx_r;
16263   __Pyx_RefNannyDeclarations
16264   __Pyx_TraceDeclarations
16265   __Pyx_RefNannySetupContext("cnext", 0);
16266   __Pyx_TraceCall("cnext", __pyx_f[0], 1522);
16267
16268   /* "csamtools.pyx":1524
16269  *     cdef int cnext(self):
16270  *         '''cversion of iterator. Used by IteratorColumn'''
16271  *         self.retval = bam_iter_read( self.fp.x.bam,             # <<<<<<<<<<<<<<
16272  *                                      self.iter,
16273  *                                      self.b)
16274  */
16275   __pyx_v_self->retval = bam_iter_read(__pyx_v_self->fp->x.bam, __pyx_v_self->iter, __pyx_v_self->b);
16276
16277   __pyx_r = 0;
16278   __Pyx_TraceReturn(Py_None);
16279   __Pyx_RefNannyFinishContext();
16280   return __pyx_r;
16281 }
16282
16283 /* Python wrapper */
16284 static PyObject *__pyx_pw_9csamtools_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self); /*proto*/
16285 static char __pyx_doc_9csamtools_17IteratorRowRegion_4__next__[] = "python version of next().\n        ";
16286 struct wrapperbase __pyx_wrapperbase_9csamtools_17IteratorRowRegion_4__next__;
16287 static PyObject *__pyx_pw_9csamtools_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self) {
16288   PyObject *__pyx_r = 0;
16289   __Pyx_RefNannyDeclarations
16290   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
16291   __pyx_r = __pyx_pf_9csamtools_17IteratorRowRegion_4__next__(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self));
16292   __Pyx_RefNannyFinishContext();
16293   return __pyx_r;
16294 }
16295
16296 /* "csamtools.pyx":1528
16297  *                                      self.b)
16298  * 
16299  *     def __next__(self):             # <<<<<<<<<<<<<<
16300  *         """python version of next().
16301  *         """
16302  */
16303
16304 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_4__next__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
16305   PyObject *__pyx_r = NULL;
16306   __Pyx_RefNannyDeclarations
16307   int __pyx_t_1;
16308   PyObject *__pyx_t_2 = NULL;
16309   int __pyx_lineno = 0;
16310   const char *__pyx_filename = NULL;
16311   int __pyx_clineno = 0;
16312   __Pyx_TraceDeclarations
16313   __Pyx_RefNannySetupContext("__next__", 0);
16314   __Pyx_TraceCall("__next__", __pyx_f[0], 1528);
16315
16316   /* "csamtools.pyx":1531
16317  *         """python version of next().
16318  *         """
16319  *         self.cnext()             # <<<<<<<<<<<<<<
16320  *         if self.retval < 0: raise StopIteration
16321  *         return makeAlignedRead( self.b )
16322  */
16323   ((struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);
16324
16325   /* "csamtools.pyx":1532
16326  *         """
16327  *         self.cnext()
16328  *         if self.retval < 0: raise StopIteration             # <<<<<<<<<<<<<<
16329  *         return makeAlignedRead( self.b )
16330  * 
16331  */
16332   __pyx_t_1 = (__pyx_v_self->retval < 0);
16333   if (__pyx_t_1) {
16334     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
16335     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16336     goto __pyx_L3;
16337   }
16338   __pyx_L3:;
16339
16340   /* "csamtools.pyx":1533
16341  *         self.cnext()
16342  *         if self.retval < 0: raise StopIteration
16343  *         return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
16344  * 
16345  *     def __dealloc__(self):
16346  */
16347   __Pyx_XDECREF(__pyx_r);
16348   __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16349   __Pyx_GOTREF(__pyx_t_2);
16350   __pyx_r = __pyx_t_2;
16351   __pyx_t_2 = 0;
16352   goto __pyx_L0;
16353
16354   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16355   goto __pyx_L0;
16356   __pyx_L1_error:;
16357   __Pyx_XDECREF(__pyx_t_2);
16358   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16359   __pyx_r = NULL;
16360   __pyx_L0:;
16361   __Pyx_XGIVEREF(__pyx_r);
16362   __Pyx_TraceReturn(__pyx_r);
16363   __Pyx_RefNannyFinishContext();
16364   return __pyx_r;
16365 }
16366
16367 /* Python wrapper */
16368 static void __pyx_pw_9csamtools_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
16369 static void __pyx_pw_9csamtools_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self) {
16370   __Pyx_RefNannyDeclarations
16371   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
16372   __pyx_pf_9csamtools_17IteratorRowRegion_6__dealloc__(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self));
16373   __Pyx_RefNannyFinishContext();
16374 }
16375
16376 /* "csamtools.pyx":1535
16377  *         return makeAlignedRead( self.b )
16378  * 
16379  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
16380  *         bam_destroy1(self.b)
16381  *         bam_iter_destroy( self.iter )
16382  */
16383
16384 static void __pyx_pf_9csamtools_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
16385   __Pyx_RefNannyDeclarations
16386   __Pyx_TraceDeclarations
16387   __Pyx_RefNannySetupContext("__dealloc__", 0);
16388   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1535);
16389
16390   /* "csamtools.pyx":1536
16391  * 
16392  *     def __dealloc__(self):
16393  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
16394  *         bam_iter_destroy( self.iter )
16395  *         if self.owns_samfile: samclose( self.fp )
16396  */
16397   bam_destroy1(__pyx_v_self->b);
16398
16399   /* "csamtools.pyx":1537
16400  *     def __dealloc__(self):
16401  *         bam_destroy1(self.b)
16402  *         bam_iter_destroy( self.iter )             # <<<<<<<<<<<<<<
16403  *         if self.owns_samfile: samclose( self.fp )
16404  * 
16405  */
16406   bam_iter_destroy(__pyx_v_self->iter);
16407
16408   /* "csamtools.pyx":1538
16409  *         bam_destroy1(self.b)
16410  *         bam_iter_destroy( self.iter )
16411  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
16412  * 
16413  * cdef class IteratorRowAll(IteratorRow):
16414  */
16415   if (__pyx_v_self->owns_samfile) {
16416     samclose(__pyx_v_self->fp);
16417     goto __pyx_L3;
16418   }
16419   __pyx_L3:;
16420
16421   __Pyx_TraceReturn(Py_None);
16422   __Pyx_RefNannyFinishContext();
16423 }
16424
16425 /* Python wrapper */
16426 static int __pyx_pw_9csamtools_14IteratorRowAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
16427 static int __pyx_pw_9csamtools_14IteratorRowAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
16428   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
16429   int __pyx_v_reopen;
16430   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__reopen,0};
16431   int __pyx_r;
16432   __Pyx_RefNannyDeclarations
16433   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
16434   {
16435     PyObject* values[2] = {0,0};
16436     if (unlikely(__pyx_kwds)) {
16437       Py_ssize_t kw_args;
16438       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
16439       switch (pos_args) {
16440         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
16441         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16442         case  0: break;
16443         default: goto __pyx_L5_argtuple_error;
16444       }
16445       kw_args = PyDict_Size(__pyx_kwds);
16446       switch (pos_args) {
16447         case  0:
16448         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
16449         if (likely(values[0])) kw_args--;
16450         else goto __pyx_L5_argtuple_error;
16451         case  1:
16452         if (kw_args > 0) {
16453           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
16454           if (value) { values[1] = value; kw_args--; }
16455         }
16456       }
16457       if (unlikely(kw_args > 0)) {
16458         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16459       }
16460       if (values[1]) {
16461       } else {
16462
16463         /* "csamtools.pyx":1550
16464  *     """
16465  * 
16466  *     def __cinit__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
16467  * 
16468  *         if not samfile._isOpen():
16469  */
16470         __pyx_v_reopen = ((int)1);
16471       }
16472     } else {
16473       switch (PyTuple_GET_SIZE(__pyx_args)) {
16474         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
16475         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16476         break;
16477         default: goto __pyx_L5_argtuple_error;
16478       }
16479     }
16480     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
16481     if (values[1]) {
16482       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16483     } else {
16484       __pyx_v_reopen = ((int)1);
16485     }
16486   }
16487   goto __pyx_L4_argument_unpacking_done;
16488   __pyx_L5_argtuple_error:;
16489   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16490   __pyx_L3_error:;
16491   __Pyx_AddTraceback("csamtools.IteratorRowAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16492   __Pyx_RefNannyFinishContext();
16493   return -1;
16494   __pyx_L4_argument_unpacking_done:;
16495   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16496   __pyx_r = __pyx_pf_9csamtools_14IteratorRowAll___cinit__(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);
16497   goto __pyx_L0;
16498   __pyx_L1_error:;
16499   __pyx_r = -1;
16500   __pyx_L0:;
16501   __Pyx_RefNannyFinishContext();
16502   return __pyx_r;
16503 }
16504
16505 static int __pyx_pf_9csamtools_14IteratorRowAll___cinit__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_reopen) {
16506   PyObject *__pyx_v_mode = NULL;
16507   PyObject *__pyx_v_store = NULL;
16508   int __pyx_r;
16509   __Pyx_RefNannyDeclarations
16510   PyObject *__pyx_t_1 = NULL;
16511   PyObject *__pyx_t_2 = NULL;
16512   int __pyx_t_3;
16513   int __pyx_t_4;
16514   char *__pyx_t_5;
16515   int __pyx_lineno = 0;
16516   const char *__pyx_filename = NULL;
16517   int __pyx_clineno = 0;
16518   __Pyx_TraceDeclarations
16519   __Pyx_RefNannySetupContext("__cinit__", 0);
16520   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1550);
16521
16522   /* "csamtools.pyx":1552
16523  *     def __cinit__(self, Samfile samfile, int reopen = True ):
16524  * 
16525  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
16526  *             raise ValueError( "I/O operation on closed file" )
16527  * 
16528  */
16529   __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 = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16530   __Pyx_GOTREF(__pyx_t_1);
16531   __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 = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16532   __Pyx_GOTREF(__pyx_t_2);
16533   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16534   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16535   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16536   __pyx_t_4 = (!__pyx_t_3);
16537   if (__pyx_t_4) {
16538
16539     /* "csamtools.pyx":1553
16540  * 
16541  *         if not samfile._isOpen():
16542  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
16543  * 
16544  *         if samfile.isbam: mode = b"rb"
16545  */
16546     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_121), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16547     __Pyx_GOTREF(__pyx_t_2);
16548     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
16549     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16550     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16551     goto __pyx_L3;
16552   }
16553   __pyx_L3:;
16554
16555   /* "csamtools.pyx":1555
16556  *             raise ValueError( "I/O operation on closed file" )
16557  * 
16558  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
16559  *         else: mode = b"r"
16560  * 
16561  */
16562   if (__pyx_v_samfile->isbam) {
16563     __Pyx_INCREF(((PyObject *)__pyx_n_b__rb));
16564     __pyx_v_mode = __pyx_n_b__rb;
16565     goto __pyx_L4;
16566   }
16567   /*else*/ {
16568
16569     /* "csamtools.pyx":1556
16570  * 
16571  *         if samfile.isbam: mode = b"rb"
16572  *         else: mode = b"r"             # <<<<<<<<<<<<<<
16573  * 
16574  *         # reopen the file to avoid iterator conflict
16575  */
16576     __Pyx_INCREF(((PyObject *)__pyx_n_b__r));
16577     __pyx_v_mode = __pyx_n_b__r;
16578   }
16579   __pyx_L4:;
16580
16581   /* "csamtools.pyx":1559
16582  * 
16583  *         # reopen the file to avoid iterator conflict
16584  *         if reopen:             # <<<<<<<<<<<<<<
16585  *             store = StderrStore()
16586  *             self.fp = samopen( samfile._filename, mode, NULL )
16587  */
16588   if (__pyx_v_reopen) {
16589
16590     /* "csamtools.pyx":1560
16591  *         # reopen the file to avoid iterator conflict
16592  *         if reopen:
16593  *             store = StderrStore()             # <<<<<<<<<<<<<<
16594  *             self.fp = samopen( samfile._filename, mode, NULL )
16595  *             store.release()
16596  */
16597     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16598     __Pyx_GOTREF(__pyx_t_2);
16599     __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 = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16600     __Pyx_GOTREF(__pyx_t_1);
16601     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16602     __pyx_v_store = __pyx_t_1;
16603     __pyx_t_1 = 0;
16604
16605     /* "csamtools.pyx":1561
16606  *         if reopen:
16607  *             store = StderrStore()
16608  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
16609  *             store.release()
16610  *             assert self.fp != NULL
16611  */
16612     __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16613     __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
16614
16615     /* "csamtools.pyx":1562
16616  *             store = StderrStore()
16617  *             self.fp = samopen( samfile._filename, mode, NULL )
16618  *             store.release()             # <<<<<<<<<<<<<<
16619  *             assert self.fp != NULL
16620  *             self.owns_samfile = True
16621  */
16622     __pyx_t_1 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16623     __Pyx_GOTREF(__pyx_t_1);
16624     __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 = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16625     __Pyx_GOTREF(__pyx_t_2);
16626     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16627     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16628
16629     /* "csamtools.pyx":1563
16630  *             self.fp = samopen( samfile._filename, mode, NULL )
16631  *             store.release()
16632  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
16633  *             self.owns_samfile = True
16634  *         else:
16635  */
16636     #ifndef CYTHON_WITHOUT_ASSERTIONS
16637     if (unlikely(!(__pyx_v_self->fp != NULL))) {
16638       PyErr_SetNone(PyExc_AssertionError);
16639       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16640     }
16641     #endif
16642
16643     /* "csamtools.pyx":1564
16644  *             store.release()
16645  *             assert self.fp != NULL
16646  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
16647  *         else:
16648  *             self.fp = samfile.samfile
16649  */
16650     __pyx_v_self->owns_samfile = 1;
16651     goto __pyx_L5;
16652   }
16653   /*else*/ {
16654
16655     /* "csamtools.pyx":1566
16656  *             self.owns_samfile = True
16657  *         else:
16658  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
16659  *             self.owns_samfile = False
16660  * 
16661  */
16662     __pyx_v_self->fp = __pyx_v_samfile->samfile;
16663
16664     /* "csamtools.pyx":1567
16665  *         else:
16666  *             self.fp = samfile.samfile
16667  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
16668  * 
16669  *         # allocate memory for alignment
16670  */
16671     __pyx_v_self->owns_samfile = 0;
16672   }
16673   __pyx_L5:;
16674
16675   /* "csamtools.pyx":1570
16676  * 
16677  *         # allocate memory for alignment
16678  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
16679  * 
16680  *     def __iter__(self):
16681  */
16682   __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
16683
16684   __pyx_r = 0;
16685   goto __pyx_L0;
16686   __pyx_L1_error:;
16687   __Pyx_XDECREF(__pyx_t_1);
16688   __Pyx_XDECREF(__pyx_t_2);
16689   __Pyx_AddTraceback("csamtools.IteratorRowAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16690   __pyx_r = -1;
16691   __pyx_L0:;
16692   __Pyx_XDECREF(__pyx_v_mode);
16693   __Pyx_XDECREF(__pyx_v_store);
16694   __Pyx_TraceReturn(Py_None);
16695   __Pyx_RefNannyFinishContext();
16696   return __pyx_r;
16697 }
16698
16699 /* Python wrapper */
16700 static PyObject *__pyx_pw_9csamtools_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self); /*proto*/
16701 static PyObject *__pyx_pw_9csamtools_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self) {
16702   PyObject *__pyx_r = 0;
16703   __Pyx_RefNannyDeclarations
16704   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
16705   __pyx_r = __pyx_pf_9csamtools_14IteratorRowAll_2__iter__(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self));
16706   __Pyx_RefNannyFinishContext();
16707   return __pyx_r;
16708 }
16709
16710 /* "csamtools.pyx":1572
16711  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
16712  * 
16713  *     def __iter__(self):             # <<<<<<<<<<<<<<
16714  *         return self
16715  * 
16716  */
16717
16718 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_2__iter__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
16719   PyObject *__pyx_r = NULL;
16720   __Pyx_RefNannyDeclarations
16721   __Pyx_TraceDeclarations
16722   __Pyx_RefNannySetupContext("__iter__", 0);
16723   __Pyx_TraceCall("__iter__", __pyx_f[0], 1572);
16724
16725   /* "csamtools.pyx":1573
16726  * 
16727  *     def __iter__(self):
16728  *         return self             # <<<<<<<<<<<<<<
16729  * 
16730  *     cdef bam1_t * getCurrent( self ):
16731  */
16732   __Pyx_XDECREF(__pyx_r);
16733   __Pyx_INCREF(((PyObject *)__pyx_v_self));
16734   __pyx_r = ((PyObject *)__pyx_v_self);
16735   goto __pyx_L0;
16736
16737   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16738   __pyx_L0:;
16739   __Pyx_XGIVEREF(__pyx_r);
16740   __Pyx_TraceReturn(__pyx_r);
16741   __Pyx_RefNannyFinishContext();
16742   return __pyx_r;
16743 }
16744
16745 /* "csamtools.pyx":1575
16746  *         return self
16747  * 
16748  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
16749  *         return self.b
16750  * 
16751  */
16752
16753 static bam1_t *__pyx_f_9csamtools_14IteratorRowAll_getCurrent(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
16754   bam1_t *__pyx_r;
16755   __Pyx_RefNannyDeclarations
16756   __Pyx_TraceDeclarations
16757   __Pyx_RefNannySetupContext("getCurrent", 0);
16758   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1575);
16759
16760   /* "csamtools.pyx":1576
16761  * 
16762  *     cdef bam1_t * getCurrent( self ):
16763  *         return self.b             # <<<<<<<<<<<<<<
16764  * 
16765  *     cdef int cnext(self):
16766  */
16767   __pyx_r = __pyx_v_self->b;
16768   goto __pyx_L0;
16769
16770   __pyx_r = 0;
16771   __pyx_L0:;
16772   __Pyx_TraceReturn(Py_None);
16773   __Pyx_RefNannyFinishContext();
16774   return __pyx_r;
16775 }
16776
16777 /* "csamtools.pyx":1578
16778  *         return self.b
16779  * 
16780  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
16781  *         '''cversion of iterator. Used by IteratorColumn'''
16782  *         return samread(self.fp, self.b)
16783  */
16784
16785 static int __pyx_f_9csamtools_14IteratorRowAll_cnext(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
16786   int __pyx_r;
16787   __Pyx_RefNannyDeclarations
16788   __Pyx_TraceDeclarations
16789   __Pyx_RefNannySetupContext("cnext", 0);
16790   __Pyx_TraceCall("cnext", __pyx_f[0], 1578);
16791
16792   /* "csamtools.pyx":1580
16793  *     cdef int cnext(self):
16794  *         '''cversion of iterator. Used by IteratorColumn'''
16795  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
16796  * 
16797  *     def __next__(self):
16798  */
16799   __pyx_r = samread(__pyx_v_self->fp, __pyx_v_self->b);
16800   goto __pyx_L0;
16801
16802   __pyx_r = 0;
16803   __pyx_L0:;
16804   __Pyx_TraceReturn(Py_None);
16805   __Pyx_RefNannyFinishContext();
16806   return __pyx_r;
16807 }
16808
16809 /* Python wrapper */
16810 static PyObject *__pyx_pw_9csamtools_14IteratorRowAll_5__next__(PyObject *__pyx_v_self); /*proto*/
16811 static char __pyx_doc_9csamtools_14IteratorRowAll_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
16812 struct wrapperbase __pyx_wrapperbase_9csamtools_14IteratorRowAll_4__next__;
16813 static PyObject *__pyx_pw_9csamtools_14IteratorRowAll_5__next__(PyObject *__pyx_v_self) {
16814   PyObject *__pyx_r = 0;
16815   __Pyx_RefNannyDeclarations
16816   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
16817   __pyx_r = __pyx_pf_9csamtools_14IteratorRowAll_4__next__(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self));
16818   __Pyx_RefNannyFinishContext();
16819   return __pyx_r;
16820 }
16821
16822 /* "csamtools.pyx":1582
16823  *         return samread(self.fp, self.b)
16824  * 
16825  *     def __next__(self):             # <<<<<<<<<<<<<<
16826  *         """python version of next().
16827  * 
16828  */
16829
16830 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_4__next__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
16831   int __pyx_v_ret;
16832   PyObject *__pyx_r = NULL;
16833   __Pyx_RefNannyDeclarations
16834   int __pyx_t_1;
16835   PyObject *__pyx_t_2 = NULL;
16836   int __pyx_lineno = 0;
16837   const char *__pyx_filename = NULL;
16838   int __pyx_clineno = 0;
16839   __Pyx_TraceDeclarations
16840   __Pyx_RefNannySetupContext("__next__", 0);
16841   __Pyx_TraceCall("__next__", __pyx_f[0], 1582);
16842
16843   /* "csamtools.pyx":1588
16844  *         """
16845  *         cdef int ret
16846  *         ret = samread(self.fp, self.b)             # <<<<<<<<<<<<<<
16847  *         if (ret > 0):
16848  *             return makeAlignedRead( self.b )
16849  */
16850   __pyx_v_ret = samread(__pyx_v_self->fp, __pyx_v_self->b);
16851
16852   /* "csamtools.pyx":1589
16853  *         cdef int ret
16854  *         ret = samread(self.fp, self.b)
16855  *         if (ret > 0):             # <<<<<<<<<<<<<<
16856  *             return makeAlignedRead( self.b )
16857  *         else:
16858  */
16859   __pyx_t_1 = (__pyx_v_ret > 0);
16860   if (__pyx_t_1) {
16861
16862     /* "csamtools.pyx":1590
16863  *         ret = samread(self.fp, self.b)
16864  *         if (ret > 0):
16865  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
16866  *         else:
16867  *             raise StopIteration
16868  */
16869     __Pyx_XDECREF(__pyx_r);
16870     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16871     __Pyx_GOTREF(__pyx_t_2);
16872     __pyx_r = __pyx_t_2;
16873     __pyx_t_2 = 0;
16874     goto __pyx_L0;
16875     goto __pyx_L3;
16876   }
16877   /*else*/ {
16878
16879     /* "csamtools.pyx":1592
16880  *             return makeAlignedRead( self.b )
16881  *         else:
16882  *             raise StopIteration             # <<<<<<<<<<<<<<
16883  * 
16884  *     def __dealloc__(self):
16885  */
16886     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
16887     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16888   }
16889   __pyx_L3:;
16890
16891   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16892   goto __pyx_L0;
16893   __pyx_L1_error:;
16894   __Pyx_XDECREF(__pyx_t_2);
16895   __Pyx_AddTraceback("csamtools.IteratorRowAll.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16896   __pyx_r = NULL;
16897   __pyx_L0:;
16898   __Pyx_XGIVEREF(__pyx_r);
16899   __Pyx_TraceReturn(__pyx_r);
16900   __Pyx_RefNannyFinishContext();
16901   return __pyx_r;
16902 }
16903
16904 /* Python wrapper */
16905 static void __pyx_pw_9csamtools_14IteratorRowAll_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
16906 static void __pyx_pw_9csamtools_14IteratorRowAll_7__dealloc__(PyObject *__pyx_v_self) {
16907   __Pyx_RefNannyDeclarations
16908   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
16909   __pyx_pf_9csamtools_14IteratorRowAll_6__dealloc__(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self));
16910   __Pyx_RefNannyFinishContext();
16911 }
16912
16913 /* "csamtools.pyx":1594
16914  *             raise StopIteration
16915  * 
16916  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
16917  *         bam_destroy1(self.b)
16918  *         if self.owns_samfile: samclose( self.fp )
16919  */
16920
16921 static void __pyx_pf_9csamtools_14IteratorRowAll_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
16922   __Pyx_RefNannyDeclarations
16923   __Pyx_TraceDeclarations
16924   __Pyx_RefNannySetupContext("__dealloc__", 0);
16925   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1594);
16926
16927   /* "csamtools.pyx":1595
16928  * 
16929  *     def __dealloc__(self):
16930  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
16931  *         if self.owns_samfile: samclose( self.fp )
16932  * 
16933  */
16934   bam_destroy1(__pyx_v_self->b);
16935
16936   /* "csamtools.pyx":1596
16937  *     def __dealloc__(self):
16938  *         bam_destroy1(self.b)
16939  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
16940  * 
16941  * cdef class IteratorRowAllRefs(IteratorRow):
16942  */
16943   if (__pyx_v_self->owns_samfile) {
16944     samclose(__pyx_v_self->fp);
16945     goto __pyx_L3;
16946   }
16947   __pyx_L3:;
16948
16949   __Pyx_TraceReturn(Py_None);
16950   __Pyx_RefNannyFinishContext();
16951 }
16952
16953 /* Python wrapper */
16954 static int __pyx_pw_9csamtools_18IteratorRowAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
16955 static int __pyx_pw_9csamtools_18IteratorRowAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
16956   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
16957   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
16958   int __pyx_r;
16959   __Pyx_RefNannyDeclarations
16960   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
16961   {
16962     PyObject* values[1] = {0};
16963     if (unlikely(__pyx_kwds)) {
16964       Py_ssize_t kw_args;
16965       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
16966       switch (pos_args) {
16967         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16968         case  0: break;
16969         default: goto __pyx_L5_argtuple_error;
16970       }
16971       kw_args = PyDict_Size(__pyx_kwds);
16972       switch (pos_args) {
16973         case  0:
16974         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
16975         if (likely(values[0])) kw_args--;
16976         else goto __pyx_L5_argtuple_error;
16977       }
16978       if (unlikely(kw_args > 0)) {
16979         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1602; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16980       }
16981     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
16982       goto __pyx_L5_argtuple_error;
16983     } else {
16984       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16985     }
16986     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
16987   }
16988   goto __pyx_L4_argument_unpacking_done;
16989   __pyx_L5_argtuple_error:;
16990   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1602; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16991   __pyx_L3_error:;
16992   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
16993   __Pyx_RefNannyFinishContext();
16994   return -1;
16995   __pyx_L4_argument_unpacking_done:;
16996   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16997   __pyx_r = __pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile);
16998   goto __pyx_L0;
16999   __pyx_L1_error:;
17000   __pyx_r = -1;
17001   __pyx_L0:;
17002   __Pyx_RefNannyFinishContext();
17003   return __pyx_r;
17004 }
17005
17006 /* "csamtools.pyx":1602
17007  *     """
17008  * 
17009  *     def __cinit__(self, Samfile samfile):             # <<<<<<<<<<<<<<
17010  *         assert samfile._isOpen()
17011  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
17012  */
17013
17014 static int __pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile) {
17015   int __pyx_r;
17016   __Pyx_RefNannyDeclarations
17017   PyObject *__pyx_t_1 = NULL;
17018   PyObject *__pyx_t_2 = NULL;
17019   int __pyx_t_3;
17020   int __pyx_t_4;
17021   int __pyx_lineno = 0;
17022   const char *__pyx_filename = NULL;
17023   int __pyx_clineno = 0;
17024   __Pyx_TraceDeclarations
17025   __Pyx_RefNannySetupContext("__cinit__", 0);
17026   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1602);
17027
17028   /* "csamtools.pyx":1603
17029  * 
17030  *     def __cinit__(self, Samfile samfile):
17031  *         assert samfile._isOpen()             # <<<<<<<<<<<<<<
17032  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
17033  *         self.samfile = samfile
17034  */
17035   #ifndef CYTHON_WITHOUT_ASSERTIONS
17036   __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 = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17037   __Pyx_GOTREF(__pyx_t_1);
17038   __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 = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17039   __Pyx_GOTREF(__pyx_t_2);
17040   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17041   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17042   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17043   if (unlikely(!__pyx_t_3)) {
17044     PyErr_SetNone(PyExc_AssertionError);
17045     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17046   }
17047   #endif
17048
17049   /* "csamtools.pyx":1604
17050  *     def __cinit__(self, Samfile samfile):
17051  *         assert samfile._isOpen()
17052  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
17053  *         self.samfile = samfile
17054  *         self.tid = -1
17055  */
17056   __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 = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17057   __Pyx_GOTREF(__pyx_t_2);
17058   __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 = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17059   __Pyx_GOTREF(__pyx_t_1);
17060   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17061   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17062   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17063   __pyx_t_4 = (!__pyx_t_3);
17064   if (__pyx_t_4) {
17065     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_122), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17066     __Pyx_GOTREF(__pyx_t_1);
17067     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
17068     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17069     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17070     goto __pyx_L3;
17071   }
17072   __pyx_L3:;
17073
17074   /* "csamtools.pyx":1605
17075  *         assert samfile._isOpen()
17076  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
17077  *         self.samfile = samfile             # <<<<<<<<<<<<<<
17078  *         self.tid = -1
17079  * 
17080  */
17081   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
17082   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
17083   __Pyx_GOTREF(__pyx_v_self->samfile);
17084   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
17085   __pyx_v_self->samfile = __pyx_v_samfile;
17086
17087   /* "csamtools.pyx":1606
17088  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
17089  *         self.samfile = samfile
17090  *         self.tid = -1             # <<<<<<<<<<<<<<
17091  * 
17092  *     def nextiter(self):
17093  */
17094   __pyx_v_self->tid = -1;
17095
17096   __pyx_r = 0;
17097   goto __pyx_L0;
17098   __pyx_L1_error:;
17099   __Pyx_XDECREF(__pyx_t_1);
17100   __Pyx_XDECREF(__pyx_t_2);
17101   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
17102   __pyx_r = -1;
17103   __pyx_L0:;
17104   __Pyx_TraceReturn(Py_None);
17105   __Pyx_RefNannyFinishContext();
17106   return __pyx_r;
17107 }
17108
17109 /* Python wrapper */
17110 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
17111 static char __pyx_doc_9csamtools_18IteratorRowAllRefs_2nextiter[] = "IteratorRowAllRefs.nextiter(self)";
17112 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
17113   PyObject *__pyx_r = 0;
17114   __Pyx_RefNannyDeclarations
17115   __Pyx_RefNannySetupContext("nextiter (wrapper)", 0);
17116   __pyx_r = __pyx_pf_9csamtools_18IteratorRowAllRefs_2nextiter(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self));
17117   __Pyx_RefNannyFinishContext();
17118   return __pyx_r;
17119 }
17120
17121 /* "csamtools.pyx":1608
17122  *         self.tid = -1
17123  * 
17124  *     def nextiter(self):             # <<<<<<<<<<<<<<
17125  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)
17126  * 
17127  */
17128
17129 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self) {
17130   PyObject *__pyx_r = NULL;
17131   __Pyx_RefNannyDeclarations
17132   PyObject *__pyx_t_1 = NULL;
17133   PyObject *__pyx_t_2 = NULL;
17134   int __pyx_lineno = 0;
17135   const char *__pyx_filename = NULL;
17136   int __pyx_clineno = 0;
17137   __Pyx_TraceDeclarations
17138   __Pyx_RefNannySetupContext("nextiter", 0);
17139   __Pyx_TraceCall("nextiter", __pyx_f[0], 1608);
17140
17141   /* "csamtools.pyx":1609
17142  * 
17143  *     def nextiter(self):
17144  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)             # <<<<<<<<<<<<<<
17145  * 
17146  *     def __iter__(self):
17147  */
17148   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17149   __Pyx_GOTREF(__pyx_t_1);
17150   __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17151   __Pyx_GOTREF(__pyx_t_2);
17152   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
17153   PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->samfile));
17154   __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
17155   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
17156   __Pyx_GIVEREF(__pyx_t_1);
17157   __Pyx_INCREF(__pyx_int_0);
17158   PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
17159   __Pyx_GIVEREF(__pyx_int_0);
17160   __Pyx_INCREF(__pyx_int_536870912);
17161   PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912);
17162   __Pyx_GIVEREF(__pyx_int_536870912);
17163   __pyx_t_1 = 0;
17164   __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17165   __Pyx_GOTREF(__pyx_t_1);
17166   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
17167   __Pyx_GIVEREF(__pyx_t_1);
17168   __Pyx_GOTREF(__pyx_v_self->rowiter);
17169   __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter));
17170   __pyx_v_self->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_1);
17171   __pyx_t_1 = 0;
17172
17173   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17174   goto __pyx_L0;
17175   __pyx_L1_error:;
17176   __Pyx_XDECREF(__pyx_t_1);
17177   __Pyx_XDECREF(__pyx_t_2);
17178   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.nextiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
17179   __pyx_r = NULL;
17180   __pyx_L0:;
17181   __Pyx_XGIVEREF(__pyx_r);
17182   __Pyx_TraceReturn(__pyx_r);
17183   __Pyx_RefNannyFinishContext();
17184   return __pyx_r;
17185 }
17186
17187 /* Python wrapper */
17188 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self); /*proto*/
17189 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self) {
17190   PyObject *__pyx_r = 0;
17191   __Pyx_RefNannyDeclarations
17192   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
17193   __pyx_r = __pyx_pf_9csamtools_18IteratorRowAllRefs_4__iter__(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self));
17194   __Pyx_RefNannyFinishContext();
17195   return __pyx_r;
17196 }
17197
17198 /* "csamtools.pyx":1611
17199  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)
17200  * 
17201  *     def __iter__(self):             # <<<<<<<<<<<<<<
17202  *         return self
17203  * 
17204  */
17205
17206 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self) {
17207   PyObject *__pyx_r = NULL;
17208   __Pyx_RefNannyDeclarations
17209   __Pyx_TraceDeclarations
17210   __Pyx_RefNannySetupContext("__iter__", 0);
17211   __Pyx_TraceCall("__iter__", __pyx_f[0], 1611);
17212
17213   /* "csamtools.pyx":1612
17214  * 
17215  *     def __iter__(self):
17216  *         return self             # <<<<<<<<<<<<<<
17217  * 
17218  *     def __next__(self):
17219  */
17220   __Pyx_XDECREF(__pyx_r);
17221   __Pyx_INCREF(((PyObject *)__pyx_v_self));
17222   __pyx_r = ((PyObject *)__pyx_v_self);
17223   goto __pyx_L0;
17224
17225   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17226   __pyx_L0:;
17227   __Pyx_XGIVEREF(__pyx_r);
17228   __Pyx_TraceReturn(__pyx_r);
17229   __Pyx_RefNannyFinishContext();
17230   return __pyx_r;
17231 }
17232
17233 /* Python wrapper */
17234 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self); /*proto*/
17235 static char __pyx_doc_9csamtools_18IteratorRowAllRefs_6__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
17236 struct wrapperbase __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_6__next__;
17237 static PyObject *__pyx_pw_9csamtools_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self) {
17238   PyObject *__pyx_r = 0;
17239   __Pyx_RefNannyDeclarations
17240   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
17241   __pyx_r = __pyx_pf_9csamtools_18IteratorRowAllRefs_6__next__(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self));
17242   __Pyx_RefNannyFinishContext();
17243   return __pyx_r;
17244 }
17245
17246 /* "csamtools.pyx":1614
17247  *         return self
17248  * 
17249  *     def __next__(self):             # <<<<<<<<<<<<<<
17250  *         """python version of next().
17251  * 
17252  */
17253
17254 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_6__next__(struct __pyx_obj_9csamtools_IteratorRowAllRefs *__pyx_v_self) {
17255   PyObject *__pyx_r = NULL;
17256   __Pyx_RefNannyDeclarations
17257   int __pyx_t_1;
17258   PyObject *__pyx_t_2 = NULL;
17259   int __pyx_t_3;
17260   PyObject *__pyx_t_4 = NULL;
17261   PyObject *__pyx_t_5 = NULL;
17262   int __pyx_lineno = 0;
17263   const char *__pyx_filename = NULL;
17264   int __pyx_clineno = 0;
17265   __Pyx_TraceDeclarations
17266   __Pyx_RefNannySetupContext("__next__", 0);
17267   __Pyx_TraceCall("__next__", __pyx_f[0], 1614);
17268
17269   /* "csamtools.pyx":1620
17270  *         """
17271  *         # Create an initial iterator
17272  *         if self.tid==-1:             # <<<<<<<<<<<<<<
17273  *             if not self.samfile.nreferences:
17274  *                 raise StopIteration
17275  */
17276   __pyx_t_1 = (__pyx_v_self->tid == -1);
17277   if (__pyx_t_1) {
17278
17279     /* "csamtools.pyx":1621
17280  *         # Create an initial iterator
17281  *         if self.tid==-1:
17282  *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
17283  *                 raise StopIteration
17284  *             self.tid = 0
17285  */
17286     __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 = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17287     __Pyx_GOTREF(__pyx_t_2);
17288     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17289     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17290     __pyx_t_3 = (!__pyx_t_1);
17291     if (__pyx_t_3) {
17292
17293       /* "csamtools.pyx":1622
17294  *         if self.tid==-1:
17295  *             if not self.samfile.nreferences:
17296  *                 raise StopIteration             # <<<<<<<<<<<<<<
17297  *             self.tid = 0
17298  *             self.nextiter()
17299  */
17300       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
17301       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17302       goto __pyx_L4;
17303     }
17304     __pyx_L4:;
17305
17306     /* "csamtools.pyx":1623
17307  *             if not self.samfile.nreferences:
17308  *                 raise StopIteration
17309  *             self.tid = 0             # <<<<<<<<<<<<<<
17310  *             self.nextiter()
17311  * 
17312  */
17313     __pyx_v_self->tid = 0;
17314
17315     /* "csamtools.pyx":1624
17316  *                 raise StopIteration
17317  *             self.tid = 0
17318  *             self.nextiter()             # <<<<<<<<<<<<<<
17319  * 
17320  *         while 1:
17321  */
17322     __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 = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17323     __Pyx_GOTREF(__pyx_t_2);
17324     __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 = 1624; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17325     __Pyx_GOTREF(__pyx_t_4);
17326     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17327     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
17328     goto __pyx_L3;
17329   }
17330   __pyx_L3:;
17331
17332   /* "csamtools.pyx":1626
17333  *             self.nextiter()
17334  * 
17335  *         while 1:             # <<<<<<<<<<<<<<
17336  *             self.rowiter.cnext()
17337  * 
17338  */
17339   while (1) {
17340     if (!1) break;
17341
17342     /* "csamtools.pyx":1627
17343  * 
17344  *         while 1:
17345  *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
17346  * 
17347  *             # If current iterator is not exhausted, return aligned read
17348  */
17349     ((struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter);
17350
17351     /* "csamtools.pyx":1630
17352  * 
17353  *             # If current iterator is not exhausted, return aligned read
17354  *             if self.rowiter.retval>0:             # <<<<<<<<<<<<<<
17355  *                 return makeAlignedRead(self.rowiter.b)
17356  * 
17357  */
17358     __pyx_t_3 = (__pyx_v_self->rowiter->retval > 0);
17359     if (__pyx_t_3) {
17360
17361       /* "csamtools.pyx":1631
17362  *             # If current iterator is not exhausted, return aligned read
17363  *             if self.rowiter.retval>0:
17364  *                 return makeAlignedRead(self.rowiter.b)             # <<<<<<<<<<<<<<
17365  * 
17366  *             self.tid += 1
17367  */
17368       __Pyx_XDECREF(__pyx_r);
17369       __pyx_t_4 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_self->rowiter->b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17370       __Pyx_GOTREF(__pyx_t_4);
17371       __pyx_r = __pyx_t_4;
17372       __pyx_t_4 = 0;
17373       goto __pyx_L0;
17374       goto __pyx_L7;
17375     }
17376     __pyx_L7:;
17377
17378     /* "csamtools.pyx":1633
17379  *                 return makeAlignedRead(self.rowiter.b)
17380  * 
17381  *             self.tid += 1             # <<<<<<<<<<<<<<
17382  * 
17383  *             # Otherwise, proceed to next reference or stop
17384  */
17385     __pyx_v_self->tid = (__pyx_v_self->tid + 1);
17386
17387     /* "csamtools.pyx":1636
17388  * 
17389  *             # Otherwise, proceed to next reference or stop
17390  *             if self.tid<self.samfile.nreferences:             # <<<<<<<<<<<<<<
17391  *                 self.nextiter()
17392  *             else:
17393  */
17394     __pyx_t_4 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17395     __Pyx_GOTREF(__pyx_t_4);
17396     __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 = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17397     __Pyx_GOTREF(__pyx_t_2);
17398     __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17399     __Pyx_GOTREF(__pyx_t_5);
17400     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
17401     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17402     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17403     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
17404     if (__pyx_t_3) {
17405
17406       /* "csamtools.pyx":1637
17407  *             # Otherwise, proceed to next reference or stop
17408  *             if self.tid<self.samfile.nreferences:
17409  *                 self.nextiter()             # <<<<<<<<<<<<<<
17410  *             else:
17411  *                 raise StopIteration
17412  */
17413       __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 = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17414       __Pyx_GOTREF(__pyx_t_5);
17415       __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 = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17416       __Pyx_GOTREF(__pyx_t_2);
17417       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
17418       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17419       goto __pyx_L8;
17420     }
17421     /*else*/ {
17422
17423       /* "csamtools.pyx":1639
17424  *                 self.nextiter()
17425  *             else:
17426  *                 raise StopIteration             # <<<<<<<<<<<<<<
17427  * 
17428  * cdef class IteratorRowSelection(IteratorRow):
17429  */
17430       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
17431       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17432     }
17433     __pyx_L8:;
17434   }
17435
17436   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17437   goto __pyx_L0;
17438   __pyx_L1_error:;
17439   __Pyx_XDECREF(__pyx_t_2);
17440   __Pyx_XDECREF(__pyx_t_4);
17441   __Pyx_XDECREF(__pyx_t_5);
17442   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
17443   __pyx_r = NULL;
17444   __pyx_L0:;
17445   __Pyx_XGIVEREF(__pyx_r);
17446   __Pyx_TraceReturn(__pyx_r);
17447   __Pyx_RefNannyFinishContext();
17448   return __pyx_r;
17449 }
17450
17451 /* Python wrapper */
17452 static int __pyx_pw_9csamtools_20IteratorRowSelection_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
17453 static int __pyx_pw_9csamtools_20IteratorRowSelection_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
17454   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
17455   PyObject *__pyx_v_positions = 0;
17456   int __pyx_v_reopen;
17457   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__positions,&__pyx_n_s__reopen,0};
17458   int __pyx_r;
17459   __Pyx_RefNannyDeclarations
17460   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
17461   {
17462     PyObject* values[3] = {0,0,0};
17463     if (unlikely(__pyx_kwds)) {
17464       Py_ssize_t kw_args;
17465       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
17466       switch (pos_args) {
17467         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
17468         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
17469         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
17470         case  0: break;
17471         default: goto __pyx_L5_argtuple_error;
17472       }
17473       kw_args = PyDict_Size(__pyx_kwds);
17474       switch (pos_args) {
17475         case  0:
17476         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
17477         if (likely(values[0])) kw_args--;
17478         else goto __pyx_L5_argtuple_error;
17479         case  1:
17480         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__positions);
17481         if (likely(values[1])) kw_args--;
17482         else {
17483           __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
17484         }
17485         case  2:
17486         if (kw_args > 0) {
17487           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
17488           if (value) { values[2] = value; kw_args--; }
17489         }
17490       }
17491       if (unlikely(kw_args > 0)) {
17492         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
17493       }
17494       if (values[2]) {
17495       } else {
17496
17497         /* "csamtools.pyx":1647
17498  *     """
17499  * 
17500  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):             # <<<<<<<<<<<<<<
17501  * 
17502  *         if not samfile._isOpen():
17503  */
17504         __pyx_v_reopen = ((int)1);
17505       }
17506     } else {
17507       switch (PyTuple_GET_SIZE(__pyx_args)) {
17508         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
17509         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
17510         values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
17511         break;
17512         default: goto __pyx_L5_argtuple_error;
17513       }
17514     }
17515     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
17516     __pyx_v_positions = values[1];
17517     if (values[2]) {
17518       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
17519     } else {
17520       __pyx_v_reopen = ((int)1);
17521     }
17522   }
17523   goto __pyx_L4_argument_unpacking_done;
17524   __pyx_L5_argtuple_error:;
17525   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
17526   __pyx_L3_error:;
17527   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
17528   __Pyx_RefNannyFinishContext();
17529   return -1;
17530   __pyx_L4_argument_unpacking_done:;
17531   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17532   __pyx_r = __pyx_pf_9csamtools_20IteratorRowSelection___cinit__(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_reopen);
17533   goto __pyx_L0;
17534   __pyx_L1_error:;
17535   __pyx_r = -1;
17536   __pyx_L0:;
17537   __Pyx_RefNannyFinishContext();
17538   return __pyx_r;
17539 }
17540
17541 static int __pyx_pf_9csamtools_20IteratorRowSelection___cinit__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_reopen) {
17542   PyObject *__pyx_v_mode = NULL;
17543   PyObject *__pyx_v_store = NULL;
17544   int __pyx_r;
17545   __Pyx_RefNannyDeclarations
17546   PyObject *__pyx_t_1 = NULL;
17547   PyObject *__pyx_t_2 = NULL;
17548   int __pyx_t_3;
17549   int __pyx_t_4;
17550   char *__pyx_t_5;
17551   int __pyx_lineno = 0;
17552   const char *__pyx_filename = NULL;
17553   int __pyx_clineno = 0;
17554   __Pyx_TraceDeclarations
17555   __Pyx_RefNannySetupContext("__cinit__", 0);
17556   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1647);
17557
17558   /* "csamtools.pyx":1649
17559  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):
17560  * 
17561  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
17562  *             raise ValueError( "I/O operation on closed file" )
17563  * 
17564  */
17565   __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 = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17566   __Pyx_GOTREF(__pyx_t_1);
17567   __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 = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17568   __Pyx_GOTREF(__pyx_t_2);
17569   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17570   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17571   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17572   __pyx_t_4 = (!__pyx_t_3);
17573   if (__pyx_t_4) {
17574
17575     /* "csamtools.pyx":1650
17576  * 
17577  *         if not samfile._isOpen():
17578  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
17579  * 
17580  *         if not samfile._isOpen():
17581  */
17582     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_123), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17583     __Pyx_GOTREF(__pyx_t_2);
17584     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
17585     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17586     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17587     goto __pyx_L3;
17588   }
17589   __pyx_L3:;
17590
17591   /* "csamtools.pyx":1652
17592  *             raise ValueError( "I/O operation on closed file" )
17593  * 
17594  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
17595  *             raise ValueError( "I/O operation on closed file" )
17596  * 
17597  */
17598   __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 = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17599   __Pyx_GOTREF(__pyx_t_2);
17600   __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 = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17601   __Pyx_GOTREF(__pyx_t_1);
17602   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17603   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17604   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17605   __pyx_t_3 = (!__pyx_t_4);
17606   if (__pyx_t_3) {
17607
17608     /* "csamtools.pyx":1653
17609  * 
17610  *         if not samfile._isOpen():
17611  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
17612  * 
17613  *         assert samfile.isbam, "can only use this iterator on bam files"
17614  */
17615     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_124), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17616     __Pyx_GOTREF(__pyx_t_1);
17617     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
17618     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17619     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17620     goto __pyx_L4;
17621   }
17622   __pyx_L4:;
17623
17624   /* "csamtools.pyx":1655
17625  *             raise ValueError( "I/O operation on closed file" )
17626  * 
17627  *         assert samfile.isbam, "can only use this iterator on bam files"             # <<<<<<<<<<<<<<
17628  *         mode = b"rb"
17629  * 
17630  */
17631   #ifndef CYTHON_WITHOUT_ASSERTIONS
17632   if (unlikely(!__pyx_v_samfile->isbam)) {
17633     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_125));
17634     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17635   }
17636   #endif
17637
17638   /* "csamtools.pyx":1656
17639  * 
17640  *         assert samfile.isbam, "can only use this iterator on bam files"
17641  *         mode = b"rb"             # <<<<<<<<<<<<<<
17642  * 
17643  *         # reopen the file to avoid iterator conflict
17644  */
17645   __Pyx_INCREF(((PyObject *)__pyx_n_b__rb));
17646   __pyx_v_mode = __pyx_n_b__rb;
17647
17648   /* "csamtools.pyx":1659
17649  * 
17650  *         # reopen the file to avoid iterator conflict
17651  *         if reopen:             # <<<<<<<<<<<<<<
17652  *             store = StderrStore()
17653  *             self.fp = samopen( samfile._filename, mode, NULL )
17654  */
17655   if (__pyx_v_reopen) {
17656
17657     /* "csamtools.pyx":1660
17658  *         # reopen the file to avoid iterator conflict
17659  *         if reopen:
17660  *             store = StderrStore()             # <<<<<<<<<<<<<<
17661  *             self.fp = samopen( samfile._filename, mode, NULL )
17662  *             store.release()
17663  */
17664     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17665     __Pyx_GOTREF(__pyx_t_1);
17666     __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 = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17667     __Pyx_GOTREF(__pyx_t_2);
17668     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17669     __pyx_v_store = __pyx_t_2;
17670     __pyx_t_2 = 0;
17671
17672     /* "csamtools.pyx":1661
17673  *         if reopen:
17674  *             store = StderrStore()
17675  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
17676  *             store.release()
17677  *             assert self.fp != NULL
17678  */
17679     __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17680     __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
17681
17682     /* "csamtools.pyx":1662
17683  *             store = StderrStore()
17684  *             self.fp = samopen( samfile._filename, mode, NULL )
17685  *             store.release()             # <<<<<<<<<<<<<<
17686  *             assert self.fp != NULL
17687  *             self.owns_samfile = True
17688  */
17689     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17690     __Pyx_GOTREF(__pyx_t_2);
17691     __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 = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17692     __Pyx_GOTREF(__pyx_t_1);
17693     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
17694     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17695
17696     /* "csamtools.pyx":1663
17697  *             self.fp = samopen( samfile._filename, mode, NULL )
17698  *             store.release()
17699  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
17700  *             self.owns_samfile = True
17701  *         else:
17702  */
17703     #ifndef CYTHON_WITHOUT_ASSERTIONS
17704     if (unlikely(!(__pyx_v_self->fp != NULL))) {
17705       PyErr_SetNone(PyExc_AssertionError);
17706       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17707     }
17708     #endif
17709
17710     /* "csamtools.pyx":1664
17711  *             store.release()
17712  *             assert self.fp != NULL
17713  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
17714  *         else:
17715  *             self.fp = samfile.samfile
17716  */
17717     __pyx_v_self->owns_samfile = 1;
17718     goto __pyx_L5;
17719   }
17720   /*else*/ {
17721
17722     /* "csamtools.pyx":1666
17723  *             self.owns_samfile = True
17724  *         else:
17725  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
17726  *             self.owns_samfile = False
17727  * 
17728  */
17729     __pyx_v_self->fp = __pyx_v_samfile->samfile;
17730
17731     /* "csamtools.pyx":1667
17732  *         else:
17733  *             self.fp = samfile.samfile
17734  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
17735  * 
17736  *         # allocate memory for alignment
17737  */
17738     __pyx_v_self->owns_samfile = 0;
17739   }
17740   __pyx_L5:;
17741
17742   /* "csamtools.pyx":1670
17743  * 
17744  *         # allocate memory for alignment
17745  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
17746  * 
17747  *         self.positions = positions
17748  */
17749   __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
17750
17751   /* "csamtools.pyx":1672
17752  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
17753  * 
17754  *         self.positions = positions             # <<<<<<<<<<<<<<
17755  *         self.current_pos = 0
17756  * 
17757  */
17758   __Pyx_INCREF(__pyx_v_positions);
17759   __Pyx_GIVEREF(__pyx_v_positions);
17760   __Pyx_GOTREF(__pyx_v_self->positions);
17761   __Pyx_DECREF(__pyx_v_self->positions);
17762   __pyx_v_self->positions = __pyx_v_positions;
17763
17764   /* "csamtools.pyx":1673
17765  * 
17766  *         self.positions = positions
17767  *         self.current_pos = 0             # <<<<<<<<<<<<<<
17768  * 
17769  *     def __iter__(self):
17770  */
17771   __pyx_v_self->current_pos = 0;
17772
17773   __pyx_r = 0;
17774   goto __pyx_L0;
17775   __pyx_L1_error:;
17776   __Pyx_XDECREF(__pyx_t_1);
17777   __Pyx_XDECREF(__pyx_t_2);
17778   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
17779   __pyx_r = -1;
17780   __pyx_L0:;
17781   __Pyx_XDECREF(__pyx_v_mode);
17782   __Pyx_XDECREF(__pyx_v_store);
17783   __Pyx_TraceReturn(Py_None);
17784   __Pyx_RefNannyFinishContext();
17785   return __pyx_r;
17786 }
17787
17788 /* Python wrapper */
17789 static PyObject *__pyx_pw_9csamtools_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self); /*proto*/
17790 static PyObject *__pyx_pw_9csamtools_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self) {
17791   PyObject *__pyx_r = 0;
17792   __Pyx_RefNannyDeclarations
17793   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
17794   __pyx_r = __pyx_pf_9csamtools_20IteratorRowSelection_2__iter__(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self));
17795   __Pyx_RefNannyFinishContext();
17796   return __pyx_r;
17797 }
17798
17799 /* "csamtools.pyx":1675
17800  *         self.current_pos = 0
17801  * 
17802  *     def __iter__(self):             # <<<<<<<<<<<<<<
17803  *         return self
17804  * 
17805  */
17806
17807 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_2__iter__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
17808   PyObject *__pyx_r = NULL;
17809   __Pyx_RefNannyDeclarations
17810   __Pyx_TraceDeclarations
17811   __Pyx_RefNannySetupContext("__iter__", 0);
17812   __Pyx_TraceCall("__iter__", __pyx_f[0], 1675);
17813
17814   /* "csamtools.pyx":1676
17815  * 
17816  *     def __iter__(self):
17817  *         return self             # <<<<<<<<<<<<<<
17818  * 
17819  *     cdef bam1_t * getCurrent( self ):
17820  */
17821   __Pyx_XDECREF(__pyx_r);
17822   __Pyx_INCREF(((PyObject *)__pyx_v_self));
17823   __pyx_r = ((PyObject *)__pyx_v_self);
17824   goto __pyx_L0;
17825
17826   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17827   __pyx_L0:;
17828   __Pyx_XGIVEREF(__pyx_r);
17829   __Pyx_TraceReturn(__pyx_r);
17830   __Pyx_RefNannyFinishContext();
17831   return __pyx_r;
17832 }
17833
17834 /* "csamtools.pyx":1678
17835  *         return self
17836  * 
17837  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
17838  *         return self.b
17839  * 
17840  */
17841
17842 static bam1_t *__pyx_f_9csamtools_20IteratorRowSelection_getCurrent(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
17843   bam1_t *__pyx_r;
17844   __Pyx_RefNannyDeclarations
17845   __Pyx_TraceDeclarations
17846   __Pyx_RefNannySetupContext("getCurrent", 0);
17847   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1678);
17848
17849   /* "csamtools.pyx":1679
17850  * 
17851  *     cdef bam1_t * getCurrent( self ):
17852  *         return self.b             # <<<<<<<<<<<<<<
17853  * 
17854  *     cdef int cnext(self):
17855  */
17856   __pyx_r = __pyx_v_self->b;
17857   goto __pyx_L0;
17858
17859   __pyx_r = 0;
17860   __pyx_L0:;
17861   __Pyx_TraceReturn(Py_None);
17862   __Pyx_RefNannyFinishContext();
17863   return __pyx_r;
17864 }
17865
17866 /* "csamtools.pyx":1681
17867  *         return self.b
17868  * 
17869  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
17870  *         '''cversion of iterator'''
17871  * 
17872  */
17873
17874 static int __pyx_f_9csamtools_20IteratorRowSelection_cnext(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
17875   int __pyx_r;
17876   __Pyx_RefNannyDeclarations
17877   PyObject *__pyx_t_1 = NULL;
17878   Py_ssize_t __pyx_t_2;
17879   int __pyx_t_3;
17880   uint64_t __pyx_t_4;
17881   int __pyx_lineno = 0;
17882   const char *__pyx_filename = NULL;
17883   int __pyx_clineno = 0;
17884   __Pyx_TraceDeclarations
17885   __Pyx_RefNannySetupContext("cnext", 0);
17886   __Pyx_TraceCall("cnext", __pyx_f[0], 1681);
17887
17888   /* "csamtools.pyx":1685
17889  * 
17890  *         # end iteration if out of positions
17891  *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
17892  * 
17893  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
17894  */
17895   __pyx_t_1 = __pyx_v_self->positions;
17896   __Pyx_INCREF(__pyx_t_1);
17897   __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17898   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17899   __pyx_t_3 = (__pyx_v_self->current_pos >= __pyx_t_2);
17900   if (__pyx_t_3) {
17901     __pyx_r = -1;
17902     goto __pyx_L0;
17903     goto __pyx_L3;
17904   }
17905   __pyx_L3:;
17906
17907   /* "csamtools.pyx":1687
17908  *         if self.current_pos >= len(self.positions): return -1
17909  * 
17910  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )             # <<<<<<<<<<<<<<
17911  *         self.current_pos += 1
17912  *         return samread(self.fp, self.b)
17913  */
17914   __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 = 1687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17915   __Pyx_GOTREF(__pyx_t_1);
17916   __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 = 1687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17917   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17918   bam_seek(__pyx_v_self->fp->x.bam, __pyx_t_4, 0);
17919
17920   /* "csamtools.pyx":1688
17921  * 
17922  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
17923  *         self.current_pos += 1             # <<<<<<<<<<<<<<
17924  *         return samread(self.fp, self.b)
17925  * 
17926  */
17927   __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);
17928
17929   /* "csamtools.pyx":1689
17930  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
17931  *         self.current_pos += 1
17932  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
17933  * 
17934  *     def __next__(self):
17935  */
17936   __pyx_r = samread(__pyx_v_self->fp, __pyx_v_self->b);
17937   goto __pyx_L0;
17938
17939   __pyx_r = 0;
17940   goto __pyx_L0;
17941   __pyx_L1_error:;
17942   __Pyx_XDECREF(__pyx_t_1);
17943   __Pyx_WriteUnraisable("csamtools.IteratorRowSelection.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
17944   __pyx_r = 0;
17945   __pyx_L0:;
17946   __Pyx_TraceReturn(Py_None);
17947   __Pyx_RefNannyFinishContext();
17948   return __pyx_r;
17949 }
17950
17951 /* Python wrapper */
17952 static PyObject *__pyx_pw_9csamtools_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self); /*proto*/
17953 static char __pyx_doc_9csamtools_20IteratorRowSelection_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
17954 struct wrapperbase __pyx_wrapperbase_9csamtools_20IteratorRowSelection_4__next__;
17955 static PyObject *__pyx_pw_9csamtools_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self) {
17956   PyObject *__pyx_r = 0;
17957   __Pyx_RefNannyDeclarations
17958   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
17959   __pyx_r = __pyx_pf_9csamtools_20IteratorRowSelection_4__next__(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self));
17960   __Pyx_RefNannyFinishContext();
17961   return __pyx_r;
17962 }
17963
17964 /* "csamtools.pyx":1691
17965  *         return samread(self.fp, self.b)
17966  * 
17967  *     def __next__(self):             # <<<<<<<<<<<<<<
17968  *         """python version of next().
17969  * 
17970  */
17971
17972 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_4__next__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
17973   int __pyx_v_ret;
17974   PyObject *__pyx_r = NULL;
17975   __Pyx_RefNannyDeclarations
17976   int __pyx_t_1;
17977   PyObject *__pyx_t_2 = NULL;
17978   int __pyx_lineno = 0;
17979   const char *__pyx_filename = NULL;
17980   int __pyx_clineno = 0;
17981   __Pyx_TraceDeclarations
17982   __Pyx_RefNannySetupContext("__next__", 0);
17983   __Pyx_TraceCall("__next__", __pyx_f[0], 1691);
17984
17985   /* "csamtools.pyx":1697
17986  *         """
17987  * 
17988  *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
17989  *         if (ret > 0):
17990  *             return makeAlignedRead( self.b )
17991  */
17992   __pyx_v_ret = ((struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);
17993
17994   /* "csamtools.pyx":1698
17995  * 
17996  *         cdef int ret = self.cnext()
17997  *         if (ret > 0):             # <<<<<<<<<<<<<<
17998  *             return makeAlignedRead( self.b )
17999  *         else:
18000  */
18001   __pyx_t_1 = (__pyx_v_ret > 0);
18002   if (__pyx_t_1) {
18003
18004     /* "csamtools.pyx":1699
18005  *         cdef int ret = self.cnext()
18006  *         if (ret > 0):
18007  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
18008  *         else:
18009  *             raise StopIteration
18010  */
18011     __Pyx_XDECREF(__pyx_r);
18012     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18013     __Pyx_GOTREF(__pyx_t_2);
18014     __pyx_r = __pyx_t_2;
18015     __pyx_t_2 = 0;
18016     goto __pyx_L0;
18017     goto __pyx_L3;
18018   }
18019   /*else*/ {
18020
18021     /* "csamtools.pyx":1701
18022  *             return makeAlignedRead( self.b )
18023  *         else:
18024  *             raise StopIteration             # <<<<<<<<<<<<<<
18025  * 
18026  *     def __dealloc__(self):
18027  */
18028     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
18029     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18030   }
18031   __pyx_L3:;
18032
18033   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18034   goto __pyx_L0;
18035   __pyx_L1_error:;
18036   __Pyx_XDECREF(__pyx_t_2);
18037   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
18038   __pyx_r = NULL;
18039   __pyx_L0:;
18040   __Pyx_XGIVEREF(__pyx_r);
18041   __Pyx_TraceReturn(__pyx_r);
18042   __Pyx_RefNannyFinishContext();
18043   return __pyx_r;
18044 }
18045
18046 /* Python wrapper */
18047 static void __pyx_pw_9csamtools_20IteratorRowSelection_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
18048 static void __pyx_pw_9csamtools_20IteratorRowSelection_7__dealloc__(PyObject *__pyx_v_self) {
18049   __Pyx_RefNannyDeclarations
18050   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
18051   __pyx_pf_9csamtools_20IteratorRowSelection_6__dealloc__(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self));
18052   __Pyx_RefNannyFinishContext();
18053 }
18054
18055 /* "csamtools.pyx":1703
18056  *             raise StopIteration
18057  * 
18058  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
18059  *         bam_destroy1(self.b)
18060  *         if self.owns_samfile: samclose( self.fp )
18061  */
18062
18063 static void __pyx_pf_9csamtools_20IteratorRowSelection_6__dealloc__(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
18064   __Pyx_RefNannyDeclarations
18065   __Pyx_TraceDeclarations
18066   __Pyx_RefNannySetupContext("__dealloc__", 0);
18067   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1703);
18068
18069   /* "csamtools.pyx":1704
18070  * 
18071  *     def __dealloc__(self):
18072  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
18073  *         if self.owns_samfile: samclose( self.fp )
18074  * 
18075  */
18076   bam_destroy1(__pyx_v_self->b);
18077
18078   /* "csamtools.pyx":1705
18079  *     def __dealloc__(self):
18080  *         bam_destroy1(self.b)
18081  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
18082  * 
18083  * ##-------------------------------------------------------------------
18084  */
18085   if (__pyx_v_self->owns_samfile) {
18086     samclose(__pyx_v_self->fp);
18087     goto __pyx_L3;
18088   }
18089   __pyx_L3:;
18090
18091   __Pyx_TraceReturn(Py_None);
18092   __Pyx_RefNannyFinishContext();
18093 }
18094
18095 /* "csamtools.pyx":1710
18096  * ##-------------------------------------------------------------------
18097  * ##-------------------------------------------------------------------
18098  * cdef int __advance_all( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
18099  *     '''advance without any read filtering.
18100  *     '''
18101  */
18102
18103 static int __pyx_f_9csamtools___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
18104   __pyx_t_9csamtools___iterdata *__pyx_v_d;
18105   int __pyx_r;
18106   __Pyx_RefNannyDeclarations
18107   __Pyx_TraceDeclarations
18108   __Pyx_RefNannySetupContext("__advance_all", 0);
18109   __Pyx_TraceCall("__advance_all", __pyx_f[0], 1710);
18110
18111   /* "csamtools.pyx":1714
18112  *     '''
18113  *     cdef __iterdata * d
18114  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
18115  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )
18116  * 
18117  */
18118   __pyx_v_d = ((__pyx_t_9csamtools___iterdata *)__pyx_v_data);
18119
18120   /* "csamtools.pyx":1715
18121  *     cdef __iterdata * d
18122  *     d = <__iterdata*>data
18123  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
18124  * 
18125  * cdef int __advance_snpcalls( void * data, bam1_t * b ):
18126  */
18127   __pyx_r = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
18128   goto __pyx_L0;
18129
18130   __pyx_r = 0;
18131   __pyx_L0:;
18132   __Pyx_TraceReturn(Py_None);
18133   __Pyx_RefNannyFinishContext();
18134   return __pyx_r;
18135 }
18136
18137 /* "csamtools.pyx":1717
18138  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )
18139  * 
18140  * cdef int __advance_snpcalls( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
18141  *     '''advance using same filter and read processing as in
18142  *     the samtools pileup.
18143  */
18144
18145 static int __pyx_f_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1_t *__pyx_v_b) {
18146   __pyx_t_9csamtools___iterdata *__pyx_v_d;
18147   int __pyx_v_ret;
18148   int __pyx_v_skip;
18149   int __pyx_v_q;
18150   int __pyx_v_is_cns;
18151   int __pyx_v_is_nobaq;
18152   int __pyx_v_capQ_thres;
18153   int __pyx_r;
18154   __Pyx_RefNannyDeclarations
18155   int __pyx_t_1;
18156   int __pyx_t_2;
18157   int __pyx_t_3;
18158   PyObject *__pyx_t_4 = NULL;
18159   PyObject *__pyx_t_5 = NULL;
18160   PyObject *__pyx_t_6 = NULL;
18161   long __pyx_t_7;
18162   int __pyx_lineno = 0;
18163   const char *__pyx_filename = NULL;
18164   int __pyx_clineno = 0;
18165   __Pyx_TraceDeclarations
18166   __Pyx_RefNannySetupContext("__advance_snpcalls", 0);
18167   __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1717);
18168
18169   /* "csamtools.pyx":1722
18170  *     '''
18171  *     cdef __iterdata * d
18172  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
18173  * 
18174  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
18175  */
18176   __pyx_v_d = ((__pyx_t_9csamtools___iterdata *)__pyx_v_data);
18177
18178   /* "csamtools.pyx":1724
18179  *     d = <__iterdata*>data
18180  * 
18181  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
18182  *     cdef int skip = 0
18183  *     cdef int q
18184  */
18185   __pyx_v_ret = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
18186
18187   /* "csamtools.pyx":1725
18188  * 
18189  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
18190  *     cdef int skip = 0             # <<<<<<<<<<<<<<
18191  *     cdef int q
18192  *     cdef int is_cns = 1
18193  */
18194   __pyx_v_skip = 0;
18195
18196   /* "csamtools.pyx":1727
18197  *     cdef int skip = 0
18198  *     cdef int q
18199  *     cdef int is_cns = 1             # <<<<<<<<<<<<<<
18200  *     cdef int is_nobaq = 0
18201  *     cdef int capQ_thres = 0
18202  */
18203   __pyx_v_is_cns = 1;
18204
18205   /* "csamtools.pyx":1728
18206  *     cdef int q
18207  *     cdef int is_cns = 1
18208  *     cdef int is_nobaq = 0             # <<<<<<<<<<<<<<
18209  *     cdef int capQ_thres = 0
18210  * 
18211  */
18212   __pyx_v_is_nobaq = 0;
18213
18214   /* "csamtools.pyx":1729
18215  *     cdef int is_cns = 1
18216  *     cdef int is_nobaq = 0
18217  *     cdef int capQ_thres = 0             # <<<<<<<<<<<<<<
18218  * 
18219  *     # reload sequence
18220  */
18221   __pyx_v_capQ_thres = 0;
18222
18223   /* "csamtools.pyx":1732
18224  * 
18225  *     # reload sequence
18226  *     if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
18227  *         if d.seq != NULL: free(d.seq)
18228  *         d.tid = b.core.tid
18229  */
18230   __pyx_t_1 = (__pyx_v_d->fastafile != NULL);
18231   if (__pyx_t_1) {
18232     __pyx_t_2 = (__pyx_v_b->core.tid != __pyx_v_d->tid);
18233     __pyx_t_3 = __pyx_t_2;
18234   } else {
18235     __pyx_t_3 = __pyx_t_1;
18236   }
18237   if (__pyx_t_3) {
18238
18239     /* "csamtools.pyx":1733
18240  *     # reload sequence
18241  *     if d.fastafile != NULL and b.core.tid != d.tid:
18242  *         if d.seq != NULL: free(d.seq)             # <<<<<<<<<<<<<<
18243  *         d.tid = b.core.tid
18244  *         d.seq = faidx_fetch_seq(d.fastafile,
18245  */
18246     __pyx_t_3 = (__pyx_v_d->seq != NULL);
18247     if (__pyx_t_3) {
18248       free(__pyx_v_d->seq);
18249       goto __pyx_L4;
18250     }
18251     __pyx_L4:;
18252
18253     /* "csamtools.pyx":1734
18254  *     if d.fastafile != NULL and b.core.tid != d.tid:
18255  *         if d.seq != NULL: free(d.seq)
18256  *         d.tid = b.core.tid             # <<<<<<<<<<<<<<
18257  *         d.seq = faidx_fetch_seq(d.fastafile,
18258  *                                 d.samfile.header.target_name[d.tid],
18259  */
18260     __pyx_v_d->tid = __pyx_v_b->core.tid;
18261
18262     /* "csamtools.pyx":1735
18263  *         if d.seq != NULL: free(d.seq)
18264  *         d.tid = b.core.tid
18265  *         d.seq = faidx_fetch_seq(d.fastafile,             # <<<<<<<<<<<<<<
18266  *                                 d.samfile.header.target_name[d.tid],
18267  *                                 0, max_pos,
18268  */
18269     __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_9csamtools_max_pos, (&__pyx_v_d->seq_len));
18270
18271     /* "csamtools.pyx":1739
18272  *                                 0, max_pos,
18273  *                                 &d.seq_len)
18274  *         if d.seq == NULL:             # <<<<<<<<<<<<<<
18275  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
18276  *                                   (d.samfile.header.target_name[d.tid],
18277  */
18278     __pyx_t_3 = (__pyx_v_d->seq == NULL);
18279     if (__pyx_t_3) {
18280
18281       /* "csamtools.pyx":1741
18282  *         if d.seq == NULL:
18283  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
18284  *                                   (d.samfile.header.target_name[d.tid],             # <<<<<<<<<<<<<<
18285  *                                    d.tid))
18286  * 
18287  */
18288       __pyx_t_4 = PyBytes_FromString((__pyx_v_d->samfile->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18289       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
18290
18291       /* "csamtools.pyx":1742
18292  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
18293  *                                   (d.samfile.header.target_name[d.tid],
18294  *                                    d.tid))             # <<<<<<<<<<<<<<
18295  * 
18296  * 
18297  */
18298       __pyx_t_5 = PyInt_FromLong(__pyx_v_d->tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18299       __Pyx_GOTREF(__pyx_t_5);
18300       __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18301       __Pyx_GOTREF(__pyx_t_6);
18302       PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_4));
18303       __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
18304       PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
18305       __Pyx_GIVEREF(__pyx_t_5);
18306       __pyx_t_4 = 0;
18307       __pyx_t_5 = 0;
18308       __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_126), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18309       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
18310       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
18311       __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18312       __Pyx_GOTREF(__pyx_t_6);
18313       PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
18314       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
18315       __pyx_t_5 = 0;
18316       __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 = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18317       __Pyx_GOTREF(__pyx_t_5);
18318       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
18319       __Pyx_Raise(__pyx_t_5, 0, 0, 0);
18320       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
18321       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18322       goto __pyx_L5;
18323     }
18324     __pyx_L5:;
18325     goto __pyx_L3;
18326   }
18327   __pyx_L3:;
18328
18329   /* "csamtools.pyx":1745
18330  * 
18331  * 
18332  *     while ret >= 0:             # <<<<<<<<<<<<<<
18333  * 
18334  *         skip = 0
18335  */
18336   while (1) {
18337     __pyx_t_3 = (__pyx_v_ret >= 0);
18338     if (!__pyx_t_3) break;
18339
18340     /* "csamtools.pyx":1747
18341  *     while ret >= 0:
18342  * 
18343  *         skip = 0             # <<<<<<<<<<<<<<
18344  * 
18345  *         # realign read - changes base qualities
18346  */
18347     __pyx_v_skip = 0;
18348
18349     /* "csamtools.pyx":1750
18350  * 
18351  *         # realign read - changes base qualities
18352  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )             # <<<<<<<<<<<<<<
18353  * 
18354  *         if d.seq != NULL and capQ_thres > 10:
18355  */
18356     __pyx_t_3 = (__pyx_v_d->seq != NULL);
18357     if (__pyx_t_3) {
18358       if (__pyx_v_is_cns) {
18359         __pyx_t_1 = (!__pyx_v_is_nobaq);
18360         __pyx_t_2 = __pyx_t_1;
18361       } else {
18362         __pyx_t_2 = __pyx_v_is_cns;
18363       }
18364       __pyx_t_1 = __pyx_t_2;
18365     } else {
18366       __pyx_t_1 = __pyx_t_3;
18367     }
18368     if (__pyx_t_1) {
18369       bam_prob_realn(__pyx_v_b, __pyx_v_d->seq);
18370       goto __pyx_L8;
18371     }
18372     __pyx_L8:;
18373
18374     /* "csamtools.pyx":1752
18375  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )
18376  * 
18377  *         if d.seq != NULL and capQ_thres > 10:             # <<<<<<<<<<<<<<
18378  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
18379  *             if q < 0: skip = 1
18380  */
18381     __pyx_t_1 = (__pyx_v_d->seq != NULL);
18382     if (__pyx_t_1) {
18383       __pyx_t_3 = (__pyx_v_capQ_thres > 10);
18384       __pyx_t_2 = __pyx_t_3;
18385     } else {
18386       __pyx_t_2 = __pyx_t_1;
18387     }
18388     if (__pyx_t_2) {
18389
18390       /* "csamtools.pyx":1753
18391  * 
18392  *         if d.seq != NULL and capQ_thres > 10:
18393  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)             # <<<<<<<<<<<<<<
18394  *             if q < 0: skip = 1
18395  *             elif b.core.qual > q: b.core.qual = q
18396  */
18397       __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres);
18398
18399       /* "csamtools.pyx":1754
18400  *         if d.seq != NULL and capQ_thres > 10:
18401  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
18402  *             if q < 0: skip = 1             # <<<<<<<<<<<<<<
18403  *             elif b.core.qual > q: b.core.qual = q
18404  *         if b.core.flag & BAM_FUNMAP: skip = 1
18405  */
18406       __pyx_t_2 = (__pyx_v_q < 0);
18407       if (__pyx_t_2) {
18408         __pyx_v_skip = 1;
18409         goto __pyx_L10;
18410       }
18411
18412       /* "csamtools.pyx":1755
18413  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
18414  *             if q < 0: skip = 1
18415  *             elif b.core.qual > q: b.core.qual = q             # <<<<<<<<<<<<<<
18416  *         if b.core.flag & BAM_FUNMAP: skip = 1
18417  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
18418  */
18419       __pyx_t_2 = (__pyx_v_b->core.qual > __pyx_v_q);
18420       if (__pyx_t_2) {
18421         __pyx_v_b->core.qual = __pyx_v_q;
18422         goto __pyx_L10;
18423       }
18424       __pyx_L10:;
18425       goto __pyx_L9;
18426     }
18427     __pyx_L9:;
18428
18429     /* "csamtools.pyx":1756
18430  *             if q < 0: skip = 1
18431  *             elif b.core.qual > q: b.core.qual = q
18432  *         if b.core.flag & BAM_FUNMAP: skip = 1             # <<<<<<<<<<<<<<
18433  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
18434  * 
18435  */
18436     __pyx_t_7 = (__pyx_v_b->core.flag & 4);
18437     if (__pyx_t_7) {
18438       __pyx_v_skip = 1;
18439       goto __pyx_L11;
18440     }
18441
18442     /* "csamtools.pyx":1757
18443  *             elif b.core.qual > q: b.core.qual = q
18444  *         if b.core.flag & BAM_FUNMAP: skip = 1
18445  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1             # <<<<<<<<<<<<<<
18446  * 
18447  *         if not skip: break
18448  */
18449     if ((__pyx_v_b->core.flag & 1)) {
18450       __pyx_t_2 = (!(__pyx_v_b->core.flag & 2));
18451       __pyx_t_1 = __pyx_t_2;
18452     } else {
18453       __pyx_t_1 = (__pyx_v_b->core.flag & 1);
18454     }
18455     if (__pyx_t_1) {
18456       __pyx_v_skip = 1;
18457       goto __pyx_L11;
18458     }
18459     __pyx_L11:;
18460
18461     /* "csamtools.pyx":1759
18462  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
18463  * 
18464  *         if not skip: break             # <<<<<<<<<<<<<<
18465  *         # additional filters
18466  * 
18467  */
18468     __pyx_t_1 = (!__pyx_v_skip);
18469     if (__pyx_t_1) {
18470       goto __pyx_L7_break;
18471       goto __pyx_L12;
18472     }
18473     __pyx_L12:;
18474
18475     /* "csamtools.pyx":1762
18476  *         # additional filters
18477  * 
18478  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
18479  * 
18480  *     return ret
18481  */
18482     __pyx_v_ret = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
18483   }
18484   __pyx_L7_break:;
18485
18486   /* "csamtools.pyx":1764
18487  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
18488  * 
18489  *     return ret             # <<<<<<<<<<<<<<
18490  * 
18491  * cdef class IteratorColumn:
18492  */
18493   __pyx_r = __pyx_v_ret;
18494   goto __pyx_L0;
18495
18496   __pyx_r = 0;
18497   goto __pyx_L0;
18498   __pyx_L1_error:;
18499   __Pyx_XDECREF(__pyx_t_4);
18500   __Pyx_XDECREF(__pyx_t_5);
18501   __Pyx_XDECREF(__pyx_t_6);
18502   __Pyx_WriteUnraisable("csamtools.__advance_snpcalls", __pyx_clineno, __pyx_lineno, __pyx_filename);
18503   __pyx_r = 0;
18504   __pyx_L0:;
18505   __Pyx_TraceReturn(Py_None);
18506   __Pyx_RefNannyFinishContext();
18507   return __pyx_r;
18508 }
18509
18510 /* Python wrapper */
18511 static int __pyx_pw_9csamtools_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
18512 static int __pyx_pw_9csamtools_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
18513   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
18514   PyObject *__pyx_v_kwargs = 0;
18515   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
18516   int __pyx_r;
18517   __Pyx_RefNannyDeclarations
18518   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
18519   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
18520   __Pyx_GOTREF(__pyx_v_kwargs);
18521   {
18522     PyObject* values[1] = {0};
18523     if (unlikely(__pyx_kwds)) {
18524       Py_ssize_t kw_args;
18525       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
18526       switch (pos_args) {
18527         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
18528         case  0: break;
18529         default: goto __pyx_L5_argtuple_error;
18530       }
18531       kw_args = PyDict_Size(__pyx_kwds);
18532       switch (pos_args) {
18533         case  0:
18534         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
18535         if (likely(values[0])) kw_args--;
18536         else goto __pyx_L5_argtuple_error;
18537       }
18538       if (unlikely(kw_args > 0)) {
18539         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
18540       }
18541     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
18542       goto __pyx_L5_argtuple_error;
18543     } else {
18544       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
18545     }
18546     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
18547   }
18548   goto __pyx_L4_argument_unpacking_done;
18549   __pyx_L5_argtuple_error:;
18550   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
18551   __pyx_L3_error:;
18552   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
18553   __Pyx_AddTraceback("csamtools.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
18554   __Pyx_RefNannyFinishContext();
18555   return -1;
18556   __pyx_L4_argument_unpacking_done:;
18557   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18558   __pyx_r = __pyx_pf_9csamtools_14IteratorColumn___cinit__(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);
18559   goto __pyx_L0;
18560   __pyx_L1_error:;
18561   __pyx_r = -1;
18562   __pyx_L0:;
18563   __Pyx_XDECREF(__pyx_v_kwargs);
18564   __Pyx_RefNannyFinishContext();
18565   return __pyx_r;
18566 }
18567
18568 /* "csamtools.pyx":1813
18569  *     '''
18570  * 
18571  *     def __cinit__( self, Samfile samfile, **kwargs ):             # <<<<<<<<<<<<<<
18572  *         self.samfile = samfile
18573  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
18574  */
18575
18576 static int __pyx_pf_9csamtools_14IteratorColumn___cinit__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_kwargs) {
18577   int __pyx_r;
18578   __Pyx_RefNannyDeclarations
18579   PyObject *__pyx_t_1 = NULL;
18580   PyObject *__pyx_t_2 = NULL;
18581   int __pyx_t_3;
18582   int __pyx_lineno = 0;
18583   const char *__pyx_filename = NULL;
18584   int __pyx_clineno = 0;
18585   __Pyx_TraceDeclarations
18586   __Pyx_RefNannySetupContext("__cinit__", 0);
18587   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1813);
18588
18589   /* "csamtools.pyx":1814
18590  * 
18591  *     def __cinit__( self, Samfile samfile, **kwargs ):
18592  *         self.samfile = samfile             # <<<<<<<<<<<<<<
18593  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
18594  *         self.fastafile = kwargs.get( "fastafile", None )
18595  */
18596   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
18597   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
18598   __Pyx_GOTREF(__pyx_v_self->samfile);
18599   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
18600   __pyx_v_self->samfile = __pyx_v_samfile;
18601
18602   /* "csamtools.pyx":1815
18603  *     def __cinit__( self, Samfile samfile, **kwargs ):
18604  *         self.samfile = samfile
18605  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )             # <<<<<<<<<<<<<<
18606  *         self.fastafile = kwargs.get( "fastafile", None )
18607  *         self.stepper = kwargs.get( "stepper", None )
18608  */
18609   __pyx_t_1 = PyInt_FromLong(BAM_DEF_MASK); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18610   __Pyx_GOTREF(__pyx_t_1);
18611   __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 = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18612   __Pyx_GOTREF(__pyx_t_2);
18613   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
18614   __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 = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18615   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
18616   __pyx_v_self->mask = __pyx_t_3;
18617
18618   /* "csamtools.pyx":1816
18619  *         self.samfile = samfile
18620  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
18621  *         self.fastafile = kwargs.get( "fastafile", None )             # <<<<<<<<<<<<<<
18622  *         self.stepper = kwargs.get( "stepper", None )
18623  *         self.max_depth = kwargs.get( "max_depth", 8000 )
18624  */
18625   __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 = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18626   __Pyx_GOTREF(__pyx_t_2);
18627   if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_9csamtools_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18628   __Pyx_GIVEREF(__pyx_t_2);
18629   __Pyx_GOTREF(__pyx_v_self->fastafile);
18630   __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
18631   __pyx_v_self->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_t_2);
18632   __pyx_t_2 = 0;
18633
18634   /* "csamtools.pyx":1817
18635  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
18636  *         self.fastafile = kwargs.get( "fastafile", None )
18637  *         self.stepper = kwargs.get( "stepper", None )             # <<<<<<<<<<<<<<
18638  *         self.max_depth = kwargs.get( "max_depth", 8000 )
18639  *         self.iterdata.seq = NULL
18640  */
18641   __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 = 1817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18642   __Pyx_GOTREF(__pyx_t_2);
18643   __Pyx_GIVEREF(__pyx_t_2);
18644   __Pyx_GOTREF(__pyx_v_self->stepper);
18645   __Pyx_DECREF(__pyx_v_self->stepper);
18646   __pyx_v_self->stepper = __pyx_t_2;
18647   __pyx_t_2 = 0;
18648
18649   /* "csamtools.pyx":1818
18650  *         self.fastafile = kwargs.get( "fastafile", None )
18651  *         self.stepper = kwargs.get( "stepper", None )
18652  *         self.max_depth = kwargs.get( "max_depth", 8000 )             # <<<<<<<<<<<<<<
18653  *         self.iterdata.seq = NULL
18654  *         self.tid = 0
18655  */
18656   __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 = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18657   __Pyx_GOTREF(__pyx_t_2);
18658   __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 = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18659   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
18660   __pyx_v_self->max_depth = __pyx_t_3;
18661
18662   /* "csamtools.pyx":1819
18663  *         self.stepper = kwargs.get( "stepper", None )
18664  *         self.max_depth = kwargs.get( "max_depth", 8000 )
18665  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
18666  *         self.tid = 0
18667  *         self.pos = 0
18668  */
18669   __pyx_v_self->iterdata.seq = NULL;
18670
18671   /* "csamtools.pyx":1820
18672  *         self.max_depth = kwargs.get( "max_depth", 8000 )
18673  *         self.iterdata.seq = NULL
18674  *         self.tid = 0             # <<<<<<<<<<<<<<
18675  *         self.pos = 0
18676  *         self.n_plp = 0
18677  */
18678   __pyx_v_self->tid = 0;
18679
18680   /* "csamtools.pyx":1821
18681  *         self.iterdata.seq = NULL
18682  *         self.tid = 0
18683  *         self.pos = 0             # <<<<<<<<<<<<<<
18684  *         self.n_plp = 0
18685  *         self.plp = NULL
18686  */
18687   __pyx_v_self->pos = 0;
18688
18689   /* "csamtools.pyx":1822
18690  *         self.tid = 0
18691  *         self.pos = 0
18692  *         self.n_plp = 0             # <<<<<<<<<<<<<<
18693  *         self.plp = NULL
18694  *         self.pileup_iter = <bam_plp_t>NULL
18695  */
18696   __pyx_v_self->n_plp = 0;
18697
18698   /* "csamtools.pyx":1823
18699  *         self.pos = 0
18700  *         self.n_plp = 0
18701  *         self.plp = NULL             # <<<<<<<<<<<<<<
18702  *         self.pileup_iter = <bam_plp_t>NULL
18703  * 
18704  */
18705   __pyx_v_self->plp = NULL;
18706
18707   /* "csamtools.pyx":1824
18708  *         self.n_plp = 0
18709  *         self.plp = NULL
18710  *         self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
18711  * 
18712  * 
18713  */
18714   __pyx_v_self->pileup_iter = NULL;
18715
18716   __pyx_r = 0;
18717   goto __pyx_L0;
18718   __pyx_L1_error:;
18719   __Pyx_XDECREF(__pyx_t_1);
18720   __Pyx_XDECREF(__pyx_t_2);
18721   __Pyx_AddTraceback("csamtools.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
18722   __pyx_r = -1;
18723   __pyx_L0:;
18724   __Pyx_TraceReturn(Py_None);
18725   __Pyx_RefNannyFinishContext();
18726   return __pyx_r;
18727 }
18728
18729 /* Python wrapper */
18730 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_3__iter__(PyObject *__pyx_v_self); /*proto*/
18731 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_3__iter__(PyObject *__pyx_v_self) {
18732   PyObject *__pyx_r = 0;
18733   __Pyx_RefNannyDeclarations
18734   __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
18735   __pyx_r = __pyx_pf_9csamtools_14IteratorColumn_2__iter__(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
18736   __Pyx_RefNannyFinishContext();
18737   return __pyx_r;
18738 }
18739
18740 /* "csamtools.pyx":1827
18741  * 
18742  * 
18743  *     def __iter__(self):             # <<<<<<<<<<<<<<
18744  *         return self
18745  * 
18746  */
18747
18748 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_2__iter__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
18749   PyObject *__pyx_r = NULL;
18750   __Pyx_RefNannyDeclarations
18751   __Pyx_TraceDeclarations
18752   __Pyx_RefNannySetupContext("__iter__", 0);
18753   __Pyx_TraceCall("__iter__", __pyx_f[0], 1827);
18754
18755   /* "csamtools.pyx":1828
18756  * 
18757  *     def __iter__(self):
18758  *         return self             # <<<<<<<<<<<<<<
18759  * 
18760  *     cdef int cnext(self):
18761  */
18762   __Pyx_XDECREF(__pyx_r);
18763   __Pyx_INCREF(((PyObject *)__pyx_v_self));
18764   __pyx_r = ((PyObject *)__pyx_v_self);
18765   goto __pyx_L0;
18766
18767   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18768   __pyx_L0:;
18769   __Pyx_XGIVEREF(__pyx_r);
18770   __Pyx_TraceReturn(__pyx_r);
18771   __Pyx_RefNannyFinishContext();
18772   return __pyx_r;
18773 }
18774
18775 /* "csamtools.pyx":1830
18776  *         return self
18777  * 
18778  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
18779  *         '''perform next iteration.
18780  * 
18781  */
18782
18783 static int __pyx_f_9csamtools_14IteratorColumn_cnext(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
18784   int __pyx_r;
18785   __Pyx_RefNannyDeclarations
18786   __Pyx_TraceDeclarations
18787   __Pyx_RefNannySetupContext("cnext", 0);
18788   __Pyx_TraceCall("cnext", __pyx_f[0], 1830);
18789
18790   /* "csamtools.pyx":1836
18791  *         It has been re-implemented to permit for filtering.
18792  *         '''
18793  *         self.plp = bam_plp_auto( self.pileup_iter,             # <<<<<<<<<<<<<<
18794  *                                  &self.tid,
18795  *                                  &self.pos,
18796  */
18797   __pyx_v_self->plp = bam_plp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp));
18798
18799   __pyx_r = 0;
18800   __Pyx_TraceReturn(Py_None);
18801   __Pyx_RefNannyFinishContext();
18802   return __pyx_r;
18803 }
18804
18805 /* "csamtools.pyx":1841
18806  *                                  &self.n_plp )
18807  * 
18808  *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
18809  *         '''return current reference sequence underlying the iterator.
18810  *         '''
18811  */
18812
18813 static char *__pyx_f_9csamtools_14IteratorColumn_getSequence(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
18814   char *__pyx_r;
18815   __Pyx_RefNannyDeclarations
18816   __Pyx_TraceDeclarations
18817   __Pyx_RefNannySetupContext("getSequence", 0);
18818   __Pyx_TraceCall("getSequence", __pyx_f[0], 1841);
18819
18820   /* "csamtools.pyx":1844
18821  *         '''return current reference sequence underlying the iterator.
18822  *         '''
18823  *         return self.iterdata.seq             # <<<<<<<<<<<<<<
18824  * 
18825  *     property seq_len:
18826  */
18827   __pyx_r = __pyx_v_self->iterdata.seq;
18828   goto __pyx_L0;
18829
18830   __pyx_r = 0;
18831   __pyx_L0:;
18832   __Pyx_TraceReturn(Py_None);
18833   __Pyx_RefNannyFinishContext();
18834   return __pyx_r;
18835 }
18836
18837 /* Python wrapper */
18838 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self); /*proto*/
18839 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self) {
18840   PyObject *__pyx_r = 0;
18841   __Pyx_RefNannyDeclarations
18842   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
18843   __pyx_r = __pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
18844   __Pyx_RefNannyFinishContext();
18845   return __pyx_r;
18846 }
18847
18848 /* "csamtools.pyx":1848
18849  *     property seq_len:
18850  *         '''current sequence length.'''
18851  *         def __get__(self): return self.iterdata.seq_len             # <<<<<<<<<<<<<<
18852  * 
18853  *     def addReference( self, Fastafile fastafile ):
18854  */
18855
18856 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
18857   PyObject *__pyx_r = NULL;
18858   __Pyx_RefNannyDeclarations
18859   PyObject *__pyx_t_1 = NULL;
18860   int __pyx_lineno = 0;
18861   const char *__pyx_filename = NULL;
18862   int __pyx_clineno = 0;
18863   __Pyx_TraceDeclarations
18864   __Pyx_RefNannySetupContext("__get__", 0);
18865   __Pyx_TraceCall("__get__", __pyx_f[0], 1848);
18866   __Pyx_XDECREF(__pyx_r);
18867   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18868   __Pyx_GOTREF(__pyx_t_1);
18869   __pyx_r = __pyx_t_1;
18870   __pyx_t_1 = 0;
18871   goto __pyx_L0;
18872
18873   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18874   goto __pyx_L0;
18875   __pyx_L1_error:;
18876   __Pyx_XDECREF(__pyx_t_1);
18877   __Pyx_AddTraceback("csamtools.IteratorColumn.seq_len.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
18878   __pyx_r = NULL;
18879   __pyx_L0:;
18880   __Pyx_XGIVEREF(__pyx_r);
18881   __Pyx_TraceReturn(__pyx_r);
18882   __Pyx_RefNannyFinishContext();
18883   return __pyx_r;
18884 }
18885
18886 /* Python wrapper */
18887 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
18888 static char __pyx_doc_9csamtools_14IteratorColumn_4addReference[] = "IteratorColumn.addReference(self, Fastafile fastafile)\n\n       add reference sequences in *fastafile* to iterator.";
18889 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
18890   PyObject *__pyx_r = 0;
18891   __Pyx_RefNannyDeclarations
18892   __Pyx_RefNannySetupContext("addReference (wrapper)", 0);
18893   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_9csamtools_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18894   __pyx_r = __pyx_pf_9csamtools_14IteratorColumn_4addReference(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_fastafile));
18895   goto __pyx_L0;
18896   __pyx_L1_error:;
18897   __pyx_r = NULL;
18898   __pyx_L0:;
18899   __Pyx_RefNannyFinishContext();
18900   return __pyx_r;
18901 }
18902
18903 /* "csamtools.pyx":1850
18904  *         def __get__(self): return self.iterdata.seq_len
18905  * 
18906  *     def addReference( self, Fastafile fastafile ):             # <<<<<<<<<<<<<<
18907  *        '''
18908  *        add reference sequences in *fastafile* to iterator.'''
18909  */
18910
18911 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_4addReference(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, struct __pyx_obj_9csamtools_Fastafile *__pyx_v_fastafile) {
18912   PyObject *__pyx_r = NULL;
18913   __Pyx_RefNannyDeclarations
18914   int __pyx_t_1;
18915   __Pyx_TraceDeclarations
18916   __Pyx_RefNannySetupContext("addReference", 0);
18917   __Pyx_TraceCall("addReference", __pyx_f[0], 1850);
18918
18919   /* "csamtools.pyx":1853
18920  *        '''
18921  *        add reference sequences in *fastafile* to iterator.'''
18922  *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
18923  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
18924  *        self.iterdata.tid = -1
18925  */
18926   __Pyx_INCREF(((PyObject *)__pyx_v_fastafile));
18927   __Pyx_GIVEREF(((PyObject *)__pyx_v_fastafile));
18928   __Pyx_GOTREF(__pyx_v_self->fastafile);
18929   __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
18930   __pyx_v_self->fastafile = __pyx_v_fastafile;
18931
18932   /* "csamtools.pyx":1854
18933  *        add reference sequences in *fastafile* to iterator.'''
18934  *        self.fastafile = fastafile
18935  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)             # <<<<<<<<<<<<<<
18936  *        self.iterdata.tid = -1
18937  *        self.iterdata.fastafile = self.fastafile.fastafile
18938  */
18939   __pyx_t_1 = (__pyx_v_self->iterdata.seq != NULL);
18940   if (__pyx_t_1) {
18941     free(__pyx_v_self->iterdata.seq);
18942     goto __pyx_L3;
18943   }
18944   __pyx_L3:;
18945
18946   /* "csamtools.pyx":1855
18947  *        self.fastafile = fastafile
18948  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
18949  *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
18950  *        self.iterdata.fastafile = self.fastafile.fastafile
18951  * 
18952  */
18953   __pyx_v_self->iterdata.tid = -1;
18954
18955   /* "csamtools.pyx":1856
18956  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
18957  *        self.iterdata.tid = -1
18958  *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
18959  * 
18960  *     def hasReference( self ):
18961  */
18962   __pyx_v_self->iterdata.fastafile = __pyx_v_self->fastafile->fastafile;
18963
18964   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18965   __Pyx_XGIVEREF(__pyx_r);
18966   __Pyx_TraceReturn(__pyx_r);
18967   __Pyx_RefNannyFinishContext();
18968   return __pyx_r;
18969 }
18970
18971 /* Python wrapper */
18972 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
18973 static char __pyx_doc_9csamtools_14IteratorColumn_6hasReference[] = "IteratorColumn.hasReference(self)\n\n        return true if iterator is associated with a reference";
18974 static PyObject *__pyx_pw_9csamtools_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
18975   PyObject *__pyx_r = 0;
18976   __Pyx_RefNannyDeclarations
18977   __Pyx_RefNannySetupContext("hasReference (wrapper)", 0);
18978   __pyx_r = __pyx_pf_9csamtools_14IteratorColumn_6hasReference(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
18979   __Pyx_RefNannyFinishContext();
18980   return __pyx_r;
18981 }
18982
18983 /* "csamtools.pyx":1858
18984  *        self.iterdata.fastafile = self.fastafile.fastafile
18985  * 
18986  *     def hasReference( self ):             # <<<<<<<<<<<<<<
18987  *         '''
18988  *         return true if iterator is associated with a reference'''
18989  */
18990
18991 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_6hasReference(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
18992   PyObject *__pyx_r = NULL;
18993   __Pyx_RefNannyDeclarations
18994   __Pyx_TraceDeclarations
18995   __Pyx_RefNannySetupContext("hasReference", 0);
18996   __Pyx_TraceCall("hasReference", __pyx_f[0], 1858);
18997
18998   /* "csamtools.pyx":1861
18999  *         '''
19000  *         return true if iterator is associated with a reference'''
19001  *         return self.fastafile             # <<<<<<<<<<<<<<
19002  * 
19003  *     cdef setMask( self, mask ):
19004  */
19005   __Pyx_XDECREF(__pyx_r);
19006   __Pyx_INCREF(((PyObject *)__pyx_v_self->fastafile));
19007   __pyx_r = ((PyObject *)__pyx_v_self->fastafile);
19008   goto __pyx_L0;
19009
19010   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19011   __pyx_L0:;
19012   __Pyx_XGIVEREF(__pyx_r);
19013   __Pyx_TraceReturn(__pyx_r);
19014   __Pyx_RefNannyFinishContext();
19015   return __pyx_r;
19016 }
19017
19018 /* "csamtools.pyx":1863
19019  *         return self.fastafile
19020  * 
19021  *     cdef setMask( self, mask ):             # <<<<<<<<<<<<<<
19022  *         '''set masking flag in iterator.
19023  * 
19024  */
19025
19026 static PyObject *__pyx_f_9csamtools_14IteratorColumn_setMask(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_mask) {
19027   PyObject *__pyx_r = NULL;
19028   __Pyx_RefNannyDeclarations
19029   int __pyx_t_1;
19030   int __pyx_lineno = 0;
19031   const char *__pyx_filename = NULL;
19032   int __pyx_clineno = 0;
19033   __Pyx_TraceDeclarations
19034   __Pyx_RefNannySetupContext("setMask", 0);
19035   __Pyx_TraceCall("setMask", __pyx_f[0], 1863);
19036
19037   /* "csamtools.pyx":1868
19038  *         reads with bits set in *mask* will be skipped.
19039  *         '''
19040  *         self.mask = mask             # <<<<<<<<<<<<<<
19041  *         bam_plp_set_mask( self.pileup_iter, self.mask )
19042  * 
19043  */
19044   __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 = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19045   __pyx_v_self->mask = __pyx_t_1;
19046
19047   /* "csamtools.pyx":1869
19048  *         '''
19049  *         self.mask = mask
19050  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
19051  * 
19052  *     cdef setupIteratorData( self,
19053  */
19054   bam_plp_set_mask(__pyx_v_self->pileup_iter, __pyx_v_self->mask);
19055
19056   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19057   goto __pyx_L0;
19058   __pyx_L1_error:;
19059   __Pyx_AddTraceback("csamtools.IteratorColumn.setMask", __pyx_clineno, __pyx_lineno, __pyx_filename);
19060   __pyx_r = 0;
19061   __pyx_L0:;
19062   __Pyx_XGIVEREF(__pyx_r);
19063   __Pyx_TraceReturn(__pyx_r);
19064   __Pyx_RefNannyFinishContext();
19065   return __pyx_r;
19066 }
19067
19068 /* "csamtools.pyx":1871
19069  *         bam_plp_set_mask( self.pileup_iter, self.mask )
19070  * 
19071  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
19072  *                             int tid,
19073  *                             int start,
19074  */
19075
19076 static PyObject *__pyx_f_9csamtools_14IteratorColumn_setupIteratorData(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args) {
19077   int __pyx_v_reopen = ((int)0);
19078   PyObject *__pyx_r = NULL;
19079   __Pyx_RefNannyDeclarations
19080   PyObject *__pyx_t_1 = NULL;
19081   PyObject *__pyx_t_2 = NULL;
19082   PyObject *__pyx_t_3 = NULL;
19083   PyObject *__pyx_t_4 = NULL;
19084   PyObject *__pyx_t_5 = NULL;
19085   int __pyx_t_6;
19086   int __pyx_t_7;
19087   int __pyx_t_8;
19088   int __pyx_lineno = 0;
19089   const char *__pyx_filename = NULL;
19090   int __pyx_clineno = 0;
19091   __Pyx_TraceDeclarations
19092   __Pyx_RefNannySetupContext("setupIteratorData", 0);
19093   __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 1871);
19094   if (__pyx_optional_args) {
19095     if (__pyx_optional_args->__pyx_n > 0) {
19096       __pyx_v_reopen = __pyx_optional_args->reopen;
19097     }
19098   }
19099
19100   /* "csamtools.pyx":1878
19101  *         '''setup the iterator structure'''
19102  * 
19103  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )             # <<<<<<<<<<<<<<
19104  *         self.iterdata.samfile = self.samfile.samfile
19105  *         self.iterdata.iter = self.iter.iter
19106  */
19107   __pyx_t_1 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19108   __Pyx_GOTREF(__pyx_t_1);
19109   __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19110   __Pyx_GOTREF(__pyx_t_2);
19111   __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19112   __Pyx_GOTREF(__pyx_t_3);
19113   __pyx_t_4 = PyInt_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19114   __Pyx_GOTREF(__pyx_t_4);
19115   __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19116   __Pyx_GOTREF(__pyx_t_5);
19117   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
19118   PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
19119   __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
19120   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
19121   __Pyx_GIVEREF(__pyx_t_1);
19122   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
19123   __Pyx_GIVEREF(__pyx_t_2);
19124   PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
19125   __Pyx_GIVEREF(__pyx_t_3);
19126   PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
19127   __Pyx_GIVEREF(__pyx_t_4);
19128   __pyx_t_1 = 0;
19129   __pyx_t_2 = 0;
19130   __pyx_t_3 = 0;
19131   __pyx_t_4 = 0;
19132   __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19133   __Pyx_GOTREF(__pyx_t_4);
19134   __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
19135   __Pyx_GIVEREF(__pyx_t_4);
19136   __Pyx_GOTREF(__pyx_v_self->iter);
19137   __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
19138   __pyx_v_self->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_4);
19139   __pyx_t_4 = 0;
19140
19141   /* "csamtools.pyx":1879
19142  * 
19143  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
19144  *         self.iterdata.samfile = self.samfile.samfile             # <<<<<<<<<<<<<<
19145  *         self.iterdata.iter = self.iter.iter
19146  *         self.iterdata.seq = NULL
19147  */
19148   __pyx_v_self->iterdata.samfile = __pyx_v_self->samfile->samfile;
19149
19150   /* "csamtools.pyx":1880
19151  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
19152  *         self.iterdata.samfile = self.samfile.samfile
19153  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
19154  *         self.iterdata.seq = NULL
19155  *         self.iterdata.tid = -1
19156  */
19157   __pyx_v_self->iterdata.iter = __pyx_v_self->iter->iter;
19158
19159   /* "csamtools.pyx":1881
19160  *         self.iterdata.samfile = self.samfile.samfile
19161  *         self.iterdata.iter = self.iter.iter
19162  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
19163  *         self.iterdata.tid = -1
19164  * 
19165  */
19166   __pyx_v_self->iterdata.seq = NULL;
19167
19168   /* "csamtools.pyx":1882
19169  *         self.iterdata.iter = self.iter.iter
19170  *         self.iterdata.seq = NULL
19171  *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
19172  * 
19173  *         if self.fastafile != None:
19174  */
19175   __pyx_v_self->iterdata.tid = -1;
19176
19177   /* "csamtools.pyx":1884
19178  *         self.iterdata.tid = -1
19179  * 
19180  *         if self.fastafile != None:             # <<<<<<<<<<<<<<
19181  *             self.iterdata.fastafile = self.fastafile.fastafile
19182  *         else:
19183  */
19184   __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_self->fastafile), Py_None, Py_NE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19185   __Pyx_GOTREF(__pyx_t_4);
19186   __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19187   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
19188   if (__pyx_t_6) {
19189
19190     /* "csamtools.pyx":1885
19191  * 
19192  *         if self.fastafile != None:
19193  *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
19194  *         else:
19195  *             self.iterdata.fastafile = NULL
19196  */
19197     __pyx_v_self->iterdata.fastafile = __pyx_v_self->fastafile->fastafile;
19198     goto __pyx_L3;
19199   }
19200   /*else*/ {
19201
19202     /* "csamtools.pyx":1887
19203  *             self.iterdata.fastafile = self.fastafile.fastafile
19204  *         else:
19205  *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
19206  * 
19207  *         if self.stepper == None or self.stepper == "all":
19208  */
19209     __pyx_v_self->iterdata.fastafile = NULL;
19210   }
19211   __pyx_L3:;
19212
19213   /* "csamtools.pyx":1889
19214  *             self.iterdata.fastafile = NULL
19215  * 
19216  *         if self.stepper == None or self.stepper == "all":             # <<<<<<<<<<<<<<
19217  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
19218  *         elif self.stepper == "samtools":
19219  */
19220   __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, Py_None, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19221   __Pyx_GOTREF(__pyx_t_4);
19222   __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19223   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
19224   if (!__pyx_t_6) {
19225     __pyx_t_7 = __Pyx_PyString_Equals(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__all), Py_EQ); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19226     __pyx_t_8 = __pyx_t_7;
19227   } else {
19228     __pyx_t_8 = __pyx_t_6;
19229   }
19230   if (__pyx_t_8) {
19231
19232     /* "csamtools.pyx":1890
19233  * 
19234  *         if self.stepper == None or self.stepper == "all":
19235  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )             # <<<<<<<<<<<<<<
19236  *         elif self.stepper == "samtools":
19237  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
19238  */
19239     __pyx_v_self->pileup_iter = bam_plp_init((&__pyx_f_9csamtools___advance_all), (&__pyx_v_self->iterdata));
19240     goto __pyx_L4;
19241   }
19242
19243   /* "csamtools.pyx":1891
19244  *         if self.stepper == None or self.stepper == "all":
19245  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
19246  *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
19247  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
19248  *         else:
19249  */
19250   __pyx_t_8 = __Pyx_PyString_Equals(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__samtools), Py_EQ); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19251   if (__pyx_t_8) {
19252
19253     /* "csamtools.pyx":1892
19254  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
19255  *         elif self.stepper == "samtools":
19256  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )             # <<<<<<<<<<<<<<
19257  *         else:
19258  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)
19259  */
19260     __pyx_v_self->pileup_iter = bam_plp_init((&__pyx_f_9csamtools___advance_snpcalls), (&__pyx_v_self->iterdata));
19261     goto __pyx_L4;
19262   }
19263   /*else*/ {
19264
19265     /* "csamtools.pyx":1894
19266  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
19267  *         else:
19268  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
19269  * 
19270  *         if self.max_depth:
19271  */
19272     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_127), __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19273     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
19274     __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19275     __Pyx_GOTREF(__pyx_t_5);
19276     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
19277     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
19278     __pyx_t_4 = 0;
19279     __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 = 1894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19280     __Pyx_GOTREF(__pyx_t_4);
19281     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
19282     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
19283     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
19284     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19285   }
19286   __pyx_L4:;
19287
19288   /* "csamtools.pyx":1896
19289  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)
19290  * 
19291  *         if self.max_depth:             # <<<<<<<<<<<<<<
19292  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )
19293  * 
19294  */
19295   if (__pyx_v_self->max_depth) {
19296
19297     /* "csamtools.pyx":1897
19298  * 
19299  *         if self.max_depth:
19300  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )             # <<<<<<<<<<<<<<
19301  * 
19302  *         bam_plp_set_mask( self.pileup_iter, self.mask )
19303  */
19304     bam_plp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
19305     goto __pyx_L5;
19306   }
19307   __pyx_L5:;
19308
19309   /* "csamtools.pyx":1899
19310  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )
19311  * 
19312  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
19313  * 
19314  *     cdef reset( self, tid, start, end ):
19315  */
19316   bam_plp_set_mask(__pyx_v_self->pileup_iter, __pyx_v_self->mask);
19317
19318   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19319   goto __pyx_L0;
19320   __pyx_L1_error:;
19321   __Pyx_XDECREF(__pyx_t_1);
19322   __Pyx_XDECREF(__pyx_t_2);
19323   __Pyx_XDECREF(__pyx_t_3);
19324   __Pyx_XDECREF(__pyx_t_4);
19325   __Pyx_XDECREF(__pyx_t_5);
19326   __Pyx_AddTraceback("csamtools.IteratorColumn.setupIteratorData", __pyx_clineno, __pyx_lineno, __pyx_filename);
19327   __pyx_r = 0;
19328   __pyx_L0:;
19329   __Pyx_XGIVEREF(__pyx_r);
19330   __Pyx_TraceReturn(__pyx_r);
19331   __Pyx_RefNannyFinishContext();
19332   return __pyx_r;
19333 }
19334
19335 /* "csamtools.pyx":1901
19336  *         bam_plp_set_mask( self.pileup_iter, self.mask )
19337  * 
19338  *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
19339  *         '''reset iterator position.
19340  * 
19341  */
19342
19343 static PyObject *__pyx_f_9csamtools_14IteratorColumn_reset(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
19344   PyObject *__pyx_r = NULL;
19345   __Pyx_RefNannyDeclarations
19346   PyObject *__pyx_t_1 = NULL;
19347   PyObject *__pyx_t_2 = NULL;
19348   PyObject *__pyx_t_3 = NULL;
19349   int __pyx_t_4;
19350   int __pyx_lineno = 0;
19351   const char *__pyx_filename = NULL;
19352   int __pyx_clineno = 0;
19353   __Pyx_TraceDeclarations
19354   __Pyx_RefNannySetupContext("reset", 0);
19355   __Pyx_TraceCall("reset", __pyx_f[0], 1901);
19356
19357   /* "csamtools.pyx":1907
19358  *         having to incur the full set-up costs.
19359  *         '''
19360  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )             # <<<<<<<<<<<<<<
19361  *         self.iterdata.iter = self.iter.iter
19362  * 
19363  */
19364   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19365   __Pyx_GOTREF(__pyx_t_1);
19366   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
19367   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->samfile));
19368   __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
19369   __Pyx_INCREF(__pyx_v_tid);
19370   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tid);
19371   __Pyx_GIVEREF(__pyx_v_tid);
19372   __Pyx_INCREF(__pyx_v_start);
19373   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_start);
19374   __Pyx_GIVEREF(__pyx_v_start);
19375   __Pyx_INCREF(__pyx_v_end);
19376   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end);
19377   __Pyx_GIVEREF(__pyx_v_end);
19378   __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19379   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
19380   if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19381   __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowRegion)), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19382   __Pyx_GOTREF(__pyx_t_3);
19383   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
19384   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
19385   __Pyx_GIVEREF(__pyx_t_3);
19386   __Pyx_GOTREF(__pyx_v_self->iter);
19387   __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
19388   __pyx_v_self->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_3);
19389   __pyx_t_3 = 0;
19390
19391   /* "csamtools.pyx":1908
19392  *         '''
19393  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )
19394  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
19395  * 
19396  *         # invalidate sequence if different tid
19397  */
19398   __pyx_v_self->iterdata.iter = __pyx_v_self->iter->iter;
19399
19400   /* "csamtools.pyx":1911
19401  * 
19402  *         # invalidate sequence if different tid
19403  *         if self.tid != tid:             # <<<<<<<<<<<<<<
19404  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
19405  *             self.iterdata.seq = NULL
19406  */
19407   __pyx_t_3 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19408   __Pyx_GOTREF(__pyx_t_3);
19409   __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19410   __Pyx_GOTREF(__pyx_t_2);
19411   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
19412   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19413   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
19414   if (__pyx_t_4) {
19415
19416     /* "csamtools.pyx":1912
19417  *         # invalidate sequence if different tid
19418  *         if self.tid != tid:
19419  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )             # <<<<<<<<<<<<<<
19420  *             self.iterdata.seq = NULL
19421  *             self.iterdata.tid = -1
19422  */
19423     __pyx_t_4 = (__pyx_v_self->iterdata.seq != NULL);
19424     if (__pyx_t_4) {
19425       free(__pyx_v_self->iterdata.seq);
19426       goto __pyx_L4;
19427     }
19428     __pyx_L4:;
19429
19430     /* "csamtools.pyx":1913
19431  *         if self.tid != tid:
19432  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
19433  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
19434  *             self.iterdata.tid = -1
19435  * 
19436  */
19437     __pyx_v_self->iterdata.seq = NULL;
19438
19439     /* "csamtools.pyx":1914
19440  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
19441  *             self.iterdata.seq = NULL
19442  *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
19443  * 
19444  *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
19445  */
19446     __pyx_v_self->iterdata.tid = -1;
19447     goto __pyx_L3;
19448   }
19449   __pyx_L3:;
19450
19451   /* "csamtools.pyx":1917
19452  * 
19453  *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
19454  *         bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
19455  * 
19456  *     def __dealloc__(self):
19457  */
19458   bam_plp_reset(__pyx_v_self->pileup_iter);
19459
19460   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19461   goto __pyx_L0;
19462   __pyx_L1_error:;
19463   __Pyx_XDECREF(__pyx_t_1);
19464   __Pyx_XDECREF(__pyx_t_2);
19465   __Pyx_XDECREF(__pyx_t_3);
19466   __Pyx_AddTraceback("csamtools.IteratorColumn.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
19467   __pyx_r = 0;
19468   __pyx_L0:;
19469   __Pyx_XGIVEREF(__pyx_r);
19470   __Pyx_TraceReturn(__pyx_r);
19471   __Pyx_RefNannyFinishContext();
19472   return __pyx_r;
19473 }
19474
19475 /* Python wrapper */
19476 static void __pyx_pw_9csamtools_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
19477 static void __pyx_pw_9csamtools_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self) {
19478   __Pyx_RefNannyDeclarations
19479   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
19480   __pyx_pf_9csamtools_14IteratorColumn_8__dealloc__(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
19481   __Pyx_RefNannyFinishContext();
19482 }
19483
19484 /* "csamtools.pyx":1919
19485  *         bam_plp_reset(self.pileup_iter)
19486  * 
19487  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
19488  *         # reset in order to avoid memory leak messages for iterators that have
19489  *         # not been fully consumed
19490  */
19491
19492 static void __pyx_pf_9csamtools_14IteratorColumn_8__dealloc__(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
19493   __Pyx_RefNannyDeclarations
19494   int __pyx_t_1;
19495   __Pyx_TraceDeclarations
19496   __Pyx_RefNannySetupContext("__dealloc__", 0);
19497   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1919);
19498
19499   /* "csamtools.pyx":1922
19500  *         # reset in order to avoid memory leak messages for iterators that have
19501  *         # not been fully consumed
19502  *         if self.pileup_iter != <bam_plp_t>NULL:             # <<<<<<<<<<<<<<
19503  *             bam_plp_reset(self.pileup_iter)
19504  *             bam_plp_destroy(self.pileup_iter)
19505  */
19506   __pyx_t_1 = (__pyx_v_self->pileup_iter != NULL);
19507   if (__pyx_t_1) {
19508
19509     /* "csamtools.pyx":1923
19510  *         # not been fully consumed
19511  *         if self.pileup_iter != <bam_plp_t>NULL:
19512  *             bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
19513  *             bam_plp_destroy(self.pileup_iter)
19514  *             self.pileup_iter = <bam_plp_t>NULL
19515  */
19516     bam_plp_reset(__pyx_v_self->pileup_iter);
19517
19518     /* "csamtools.pyx":1924
19519  *         if self.pileup_iter != <bam_plp_t>NULL:
19520  *             bam_plp_reset(self.pileup_iter)
19521  *             bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
19522  *             self.pileup_iter = <bam_plp_t>NULL
19523  * 
19524  */
19525     bam_plp_destroy(__pyx_v_self->pileup_iter);
19526
19527     /* "csamtools.pyx":1925
19528  *             bam_plp_reset(self.pileup_iter)
19529  *             bam_plp_destroy(self.pileup_iter)
19530  *             self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
19531  * 
19532  *         if self.iterdata.seq != NULL:
19533  */
19534     __pyx_v_self->pileup_iter = NULL;
19535     goto __pyx_L3;
19536   }
19537   __pyx_L3:;
19538
19539   /* "csamtools.pyx":1927
19540  *             self.pileup_iter = <bam_plp_t>NULL
19541  * 
19542  *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
19543  *             free(self.iterdata.seq)
19544  *             self.iterdata.seq = NULL
19545  */
19546   __pyx_t_1 = (__pyx_v_self->iterdata.seq != NULL);
19547   if (__pyx_t_1) {
19548
19549     /* "csamtools.pyx":1928
19550  * 
19551  *         if self.iterdata.seq != NULL:
19552  *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
19553  *             self.iterdata.seq = NULL
19554  * 
19555  */
19556     free(__pyx_v_self->iterdata.seq);
19557
19558     /* "csamtools.pyx":1929
19559  *         if self.iterdata.seq != NULL:
19560  *             free(self.iterdata.seq)
19561  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
19562  * 
19563  * cdef class IteratorColumnRegion(IteratorColumn):
19564  */
19565     __pyx_v_self->iterdata.seq = NULL;
19566     goto __pyx_L4;
19567   }
19568   __pyx_L4:;
19569
19570   __Pyx_TraceReturn(Py_None);
19571   __Pyx_RefNannyFinishContext();
19572 }
19573
19574 /* Python wrapper */
19575 static int __pyx_pw_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
19576 static int __pyx_pw_9csamtools_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
19577   CYTHON_UNUSED struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
19578   int __pyx_v_tid;
19579   int __pyx_v_start;
19580   int __pyx_v_end;
19581   int __pyx_v_truncate;
19582   CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
19583   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__tid,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__truncate,0};
19584   int __pyx_r;
19585   __Pyx_RefNannyDeclarations
19586   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
19587   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
19588   __Pyx_GOTREF(__pyx_v_kwargs);
19589   {
19590     PyObject* values[5] = {0,0,0,0,0};
19591     if (unlikely(__pyx_kwds)) {
19592       Py_ssize_t kw_args;
19593       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
19594       switch (pos_args) {
19595         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
19596         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
19597         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
19598         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
19599         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
19600         case  0: break;
19601         default: goto __pyx_L5_argtuple_error;
19602       }
19603       kw_args = PyDict_Size(__pyx_kwds);
19604       switch (pos_args) {
19605         case  0:
19606         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
19607         if (likely(values[0])) kw_args--;
19608         else goto __pyx_L5_argtuple_error;
19609         case  1:
19610         if (kw_args > 0) {
19611           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
19612           if (value) { values[1] = value; kw_args--; }
19613         }
19614         case  2:
19615         if (kw_args > 0) {
19616           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
19617           if (value) { values[2] = value; kw_args--; }
19618         }
19619         case  3:
19620         if (kw_args > 0) {
19621           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
19622           if (value) { values[3] = value; kw_args--; }
19623         }
19624         case  4:
19625         if (kw_args > 0) {
19626           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__truncate);
19627           if (value) { values[4] = value; kw_args--; }
19628         }
19629       }
19630       if (unlikely(kw_args > 0)) {
19631         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19632       }
19633       if (values[1]) {
19634       } else {
19635         __pyx_v_tid = ((int)0);
19636       }
19637       if (values[2]) {
19638       } else {
19639         __pyx_v_start = ((int)0);
19640       }
19641       if (values[3]) {
19642       } else {
19643         __pyx_v_end = __pyx_k_128;
19644       }
19645       if (values[4]) {
19646       } else {
19647
19648         /* "csamtools.pyx":1938
19649  *                   int start = 0,
19650  *                   int end = max_pos,
19651  *                   int truncate = False,             # <<<<<<<<<<<<<<
19652  *                   **kwargs ):
19653  * 
19654  */
19655         __pyx_v_truncate = ((int)0);
19656       }
19657     } else {
19658       switch (PyTuple_GET_SIZE(__pyx_args)) {
19659         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
19660         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
19661         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
19662         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
19663         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
19664         break;
19665         default: goto __pyx_L5_argtuple_error;
19666       }
19667     }
19668     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
19669     if (values[1]) {
19670       __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19671     } else {
19672       __pyx_v_tid = ((int)0);
19673     }
19674     if (values[2]) {
19675       __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1936; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19676     } else {
19677       __pyx_v_start = ((int)0);
19678     }
19679     if (values[3]) {
19680       __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19681     } else {
19682       __pyx_v_end = __pyx_k_128;
19683     }
19684     if (values[4]) {
19685       __pyx_v_truncate = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19686     } else {
19687       __pyx_v_truncate = ((int)0);
19688     }
19689   }
19690   goto __pyx_L4_argument_unpacking_done;
19691   __pyx_L5_argtuple_error:;
19692   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19693   __pyx_L3_error:;
19694   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
19695   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
19696   __Pyx_RefNannyFinishContext();
19697   return -1;
19698   __pyx_L4_argument_unpacking_done:;
19699   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19700   __pyx_r = __pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_truncate, __pyx_v_kwargs);
19701   goto __pyx_L0;
19702   __pyx_L1_error:;
19703   __pyx_r = -1;
19704   __pyx_L0:;
19705   __Pyx_XDECREF(__pyx_v_kwargs);
19706   __Pyx_RefNannyFinishContext();
19707   return __pyx_r;
19708 }
19709
19710 /* "csamtools.pyx":1934
19711  *     '''iterates over a region only.
19712  *     '''
19713  *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
19714  *                   int tid = 0,
19715  *                   int start = 0,
19716  */
19717
19718 static int __pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(struct __pyx_obj_9csamtools_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
19719   int __pyx_r;
19720   __Pyx_RefNannyDeclarations
19721   PyObject *__pyx_t_1 = NULL;
19722   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_2;
19723   int __pyx_lineno = 0;
19724   const char *__pyx_filename = NULL;
19725   int __pyx_clineno = 0;
19726   __Pyx_TraceDeclarations
19727   __Pyx_RefNannySetupContext("__cinit__", 0);
19728   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1934);
19729
19730   /* "csamtools.pyx":1942
19731  * 
19732  *         # initialize iterator
19733  *         self.setupIteratorData( tid, start, end, 1 )             # <<<<<<<<<<<<<<
19734  *         self.start = start
19735  *         self.end = end
19736  */
19737   __pyx_t_2.__pyx_n = 1;
19738   __pyx_t_2.reopen = 1;
19739   __pyx_t_1 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_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 = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19740   __Pyx_GOTREF(__pyx_t_1);
19741   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
19742
19743   /* "csamtools.pyx":1943
19744  *         # initialize iterator
19745  *         self.setupIteratorData( tid, start, end, 1 )
19746  *         self.start = start             # <<<<<<<<<<<<<<
19747  *         self.end = end
19748  *         self.truncate = truncate
19749  */
19750   __pyx_v_self->start = __pyx_v_start;
19751
19752   /* "csamtools.pyx":1944
19753  *         self.setupIteratorData( tid, start, end, 1 )
19754  *         self.start = start
19755  *         self.end = end             # <<<<<<<<<<<<<<
19756  *         self.truncate = truncate
19757  * 
19758  */
19759   __pyx_v_self->end = __pyx_v_end;
19760
19761   /* "csamtools.pyx":1945
19762  *         self.start = start
19763  *         self.end = end
19764  *         self.truncate = truncate             # <<<<<<<<<<<<<<
19765  * 
19766  *     def __next__(self):
19767  */
19768   __pyx_v_self->truncate = __pyx_v_truncate;
19769
19770   __pyx_r = 0;
19771   goto __pyx_L0;
19772   __pyx_L1_error:;
19773   __Pyx_XDECREF(__pyx_t_1);
19774   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
19775   __pyx_r = -1;
19776   __pyx_L0:;
19777   __Pyx_TraceReturn(Py_None);
19778   __Pyx_RefNannyFinishContext();
19779   return __pyx_r;
19780 }
19781
19782 /* Python wrapper */
19783 static PyObject *__pyx_pw_9csamtools_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self); /*proto*/
19784 static char __pyx_doc_9csamtools_20IteratorColumnRegion_2__next__[] = "python version of next().\n        ";
19785 struct wrapperbase __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_2__next__;
19786 static PyObject *__pyx_pw_9csamtools_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self) {
19787   PyObject *__pyx_r = 0;
19788   __Pyx_RefNannyDeclarations
19789   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
19790   __pyx_r = __pyx_pf_9csamtools_20IteratorColumnRegion_2__next__(((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self));
19791   __Pyx_RefNannyFinishContext();
19792   return __pyx_r;
19793 }
19794
19795 /* "csamtools.pyx":1947
19796  *         self.truncate = truncate
19797  * 
19798  *     def __next__(self):             # <<<<<<<<<<<<<<
19799  *         """python version of next().
19800  *         """
19801  */
19802
19803 static PyObject *__pyx_pf_9csamtools_20IteratorColumnRegion_2__next__(struct __pyx_obj_9csamtools_IteratorColumnRegion *__pyx_v_self) {
19804   PyObject *__pyx_r = NULL;
19805   __Pyx_RefNannyDeclarations
19806   int __pyx_t_1;
19807   PyObject *__pyx_t_2 = NULL;
19808   int __pyx_lineno = 0;
19809   const char *__pyx_filename = NULL;
19810   int __pyx_clineno = 0;
19811   __Pyx_TraceDeclarations
19812   __Pyx_RefNannySetupContext("__next__", 0);
19813   __Pyx_TraceCall("__next__", __pyx_f[0], 1947);
19814
19815   /* "csamtools.pyx":1951
19816  *         """
19817  * 
19818  *         while 1:             # <<<<<<<<<<<<<<
19819  *             self.cnext()
19820  *             if self.n_plp < 0:
19821  */
19822   while (1) {
19823     if (!1) break;
19824
19825     /* "csamtools.pyx":1952
19826  * 
19827  *         while 1:
19828  *             self.cnext()             # <<<<<<<<<<<<<<
19829  *             if self.n_plp < 0:
19830  *                 raise ValueError("error during iteration" )
19831  */
19832     ((struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
19833
19834     /* "csamtools.pyx":1953
19835  *         while 1:
19836  *             self.cnext()
19837  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
19838  *                 raise ValueError("error during iteration" )
19839  * 
19840  */
19841     __pyx_t_1 = (__pyx_v_self->__pyx_base.n_plp < 0);
19842     if (__pyx_t_1) {
19843
19844       /* "csamtools.pyx":1954
19845  *             self.cnext()
19846  *             if self.n_plp < 0:
19847  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
19848  * 
19849  *             if self.plp == NULL:
19850  */
19851       __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 = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19852       __Pyx_GOTREF(__pyx_t_2);
19853       __Pyx_Raise(__pyx_t_2, 0, 0, 0);
19854       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
19855       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19856       goto __pyx_L5;
19857     }
19858     __pyx_L5:;
19859
19860     /* "csamtools.pyx":1956
19861  *                 raise ValueError("error during iteration" )
19862  * 
19863  *             if self.plp == NULL:             # <<<<<<<<<<<<<<
19864  *                 raise StopIteration
19865  * 
19866  */
19867     __pyx_t_1 = (__pyx_v_self->__pyx_base.plp == NULL);
19868     if (__pyx_t_1) {
19869
19870       /* "csamtools.pyx":1957
19871  * 
19872  *             if self.plp == NULL:
19873  *                 raise StopIteration             # <<<<<<<<<<<<<<
19874  * 
19875  *             if self.truncate:
19876  */
19877       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
19878       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19879       goto __pyx_L6;
19880     }
19881     __pyx_L6:;
19882
19883     /* "csamtools.pyx":1959
19884  *                 raise StopIteration
19885  * 
19886  *             if self.truncate:             # <<<<<<<<<<<<<<
19887  *                 if self.start < self.pos: continue
19888  *                 if self.pos >= self.end: raise StopIteration
19889  */
19890     if (__pyx_v_self->truncate) {
19891
19892       /* "csamtools.pyx":1960
19893  * 
19894  *             if self.truncate:
19895  *                 if self.start < self.pos: continue             # <<<<<<<<<<<<<<
19896  *                 if self.pos >= self.end: raise StopIteration
19897  * 
19898  */
19899       __pyx_t_1 = (__pyx_v_self->start < __pyx_v_self->__pyx_base.pos);
19900       if (__pyx_t_1) {
19901         goto __pyx_L3_continue;
19902         goto __pyx_L8;
19903       }
19904       __pyx_L8:;
19905
19906       /* "csamtools.pyx":1961
19907  *             if self.truncate:
19908  *                 if self.start < self.pos: continue
19909  *                 if self.pos >= self.end: raise StopIteration             # <<<<<<<<<<<<<<
19910  * 
19911  *             return makePileupProxy( &self.plp,
19912  */
19913       __pyx_t_1 = (__pyx_v_self->__pyx_base.pos >= __pyx_v_self->end);
19914       if (__pyx_t_1) {
19915         __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
19916         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19917         goto __pyx_L9;
19918       }
19919       __pyx_L9:;
19920       goto __pyx_L7;
19921     }
19922     __pyx_L7:;
19923
19924     /* "csamtools.pyx":1963
19925  *                 if self.pos >= self.end: raise StopIteration
19926  * 
19927  *             return makePileupProxy( &self.plp,             # <<<<<<<<<<<<<<
19928  *                                      self.tid,
19929  *                                      self.pos,
19930  */
19931     __Pyx_XDECREF(__pyx_r);
19932
19933     /* "csamtools.pyx":1966
19934  *                                      self.tid,
19935  *                                      self.pos,
19936  *                                      self.n_plp )             # <<<<<<<<<<<<<<
19937  * 
19938  * cdef class IteratorColumnAllRefs(IteratorColumn):
19939  */
19940     __pyx_t_2 = __pyx_f_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 = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19941     __Pyx_GOTREF(__pyx_t_2);
19942     __pyx_r = __pyx_t_2;
19943     __pyx_t_2 = 0;
19944     goto __pyx_L0;
19945     __pyx_L3_continue:;
19946   }
19947
19948   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19949   goto __pyx_L0;
19950   __pyx_L1_error:;
19951   __Pyx_XDECREF(__pyx_t_2);
19952   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
19953   __pyx_r = NULL;
19954   __pyx_L0:;
19955   __Pyx_XGIVEREF(__pyx_r);
19956   __Pyx_TraceReturn(__pyx_r);
19957   __Pyx_RefNannyFinishContext();
19958   return __pyx_r;
19959 }
19960
19961 /* Python wrapper */
19962 static int __pyx_pw_9csamtools_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
19963 static int __pyx_pw_9csamtools_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
19964   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
19965   CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
19966   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
19967   int __pyx_r;
19968   __Pyx_RefNannyDeclarations
19969   __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
19970   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
19971   __Pyx_GOTREF(__pyx_v_kwargs);
19972   {
19973     PyObject* values[1] = {0};
19974     if (unlikely(__pyx_kwds)) {
19975       Py_ssize_t kw_args;
19976       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
19977       switch (pos_args) {
19978         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
19979         case  0: break;
19980         default: goto __pyx_L5_argtuple_error;
19981       }
19982       kw_args = PyDict_Size(__pyx_kwds);
19983       switch (pos_args) {
19984         case  0:
19985         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
19986         if (likely(values[0])) kw_args--;
19987         else goto __pyx_L5_argtuple_error;
19988       }
19989       if (unlikely(kw_args > 0)) {
19990         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1972; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
19991       }
19992     } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
19993       goto __pyx_L5_argtuple_error;
19994     } else {
19995       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
19996     }
19997     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
19998   }
19999   goto __pyx_L4_argument_unpacking_done;
20000   __pyx_L5_argtuple_error:;
20001   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1972; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
20002   __pyx_L3_error:;
20003   __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
20004   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
20005   __Pyx_RefNannyFinishContext();
20006   return -1;
20007   __pyx_L4_argument_unpacking_done:;
20008   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20009   __pyx_r = __pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);
20010   goto __pyx_L0;
20011   __pyx_L1_error:;
20012   __pyx_r = -1;
20013   __pyx_L0:;
20014   __Pyx_XDECREF(__pyx_v_kwargs);
20015   __Pyx_RefNannyFinishContext();
20016   return __pyx_r;
20017 }
20018
20019 /* "csamtools.pyx":1972
20020  *     """
20021  * 
20022  *     def __cinit__(self,             # <<<<<<<<<<<<<<
20023  *                   Samfile samfile,
20024  *                   **kwargs ):
20025  */
20026
20027 static int __pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_9csamtools_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
20028   int __pyx_r;
20029   __Pyx_RefNannyDeclarations
20030   PyObject *__pyx_t_1 = NULL;
20031   int __pyx_t_2;
20032   int __pyx_t_3;
20033   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_4;
20034   int __pyx_lineno = 0;
20035   const char *__pyx_filename = NULL;
20036   int __pyx_clineno = 0;
20037   __Pyx_TraceDeclarations
20038   __Pyx_RefNannySetupContext("__cinit__", 0);
20039   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1972);
20040
20041   /* "csamtools.pyx":1977
20042  * 
20043  *         # no iteration over empty files
20044  *         if not samfile.nreferences: raise StopIteration             # <<<<<<<<<<<<<<
20045  * 
20046  *         # initialize iterator
20047  */
20048   __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 = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20049   __Pyx_GOTREF(__pyx_t_1);
20050   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20051   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20052   __pyx_t_3 = (!__pyx_t_2);
20053   if (__pyx_t_3) {
20054     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
20055     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20056     goto __pyx_L3;
20057   }
20058   __pyx_L3:;
20059
20060   /* "csamtools.pyx":1980
20061  * 
20062  *         # initialize iterator
20063  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )             # <<<<<<<<<<<<<<
20064  * 
20065  *     def __next__(self):
20066  */
20067   __pyx_t_4.__pyx_n = 1;
20068   __pyx_t_4.reopen = 1;
20069   __pyx_t_1 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_9csamtools_max_pos, &__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20070   __Pyx_GOTREF(__pyx_t_1);
20071   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20072
20073   __pyx_r = 0;
20074   goto __pyx_L0;
20075   __pyx_L1_error:;
20076   __Pyx_XDECREF(__pyx_t_1);
20077   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
20078   __pyx_r = -1;
20079   __pyx_L0:;
20080   __Pyx_TraceReturn(Py_None);
20081   __Pyx_RefNannyFinishContext();
20082   return __pyx_r;
20083 }
20084
20085 /* Python wrapper */
20086 static PyObject *__pyx_pw_9csamtools_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
20087 static char __pyx_doc_9csamtools_21IteratorColumnAllRefs_2__next__[] = "python version of next().\n        ";
20088 struct wrapperbase __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_2__next__;
20089 static PyObject *__pyx_pw_9csamtools_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self) {
20090   PyObject *__pyx_r = 0;
20091   __Pyx_RefNannyDeclarations
20092   __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
20093   __pyx_r = __pyx_pf_9csamtools_21IteratorColumnAllRefs_2__next__(((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self));
20094   __Pyx_RefNannyFinishContext();
20095   return __pyx_r;
20096 }
20097
20098 /* "csamtools.pyx":1982
20099  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )
20100  * 
20101  *     def __next__(self):             # <<<<<<<<<<<<<<
20102  *         """python version of next().
20103  *         """
20104  */
20105
20106 static PyObject *__pyx_pf_9csamtools_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_9csamtools_IteratorColumnAllRefs *__pyx_v_self) {
20107   PyObject *__pyx_r = NULL;
20108   __Pyx_RefNannyDeclarations
20109   int __pyx_t_1;
20110   PyObject *__pyx_t_2 = NULL;
20111   PyObject *__pyx_t_3 = NULL;
20112   PyObject *__pyx_t_4 = NULL;
20113   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_5;
20114   int __pyx_lineno = 0;
20115   const char *__pyx_filename = NULL;
20116   int __pyx_clineno = 0;
20117   __Pyx_TraceDeclarations
20118   __Pyx_RefNannySetupContext("__next__", 0);
20119   __Pyx_TraceCall("__next__", __pyx_f[0], 1982);
20120
20121   /* "csamtools.pyx":1986
20122  *         """
20123  * 
20124  *         while 1:             # <<<<<<<<<<<<<<
20125  *             self.cnext()
20126  * 
20127  */
20128   while (1) {
20129     if (!1) break;
20130
20131     /* "csamtools.pyx":1987
20132  * 
20133  *         while 1:
20134  *             self.cnext()             # <<<<<<<<<<<<<<
20135  * 
20136  *             if self.n_plp < 0:
20137  */
20138     ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
20139
20140     /* "csamtools.pyx":1989
20141  *             self.cnext()
20142  * 
20143  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
20144  *                 raise ValueError("error during iteration" )
20145  * 
20146  */
20147     __pyx_t_1 = (__pyx_v_self->__pyx_base.n_plp < 0);
20148     if (__pyx_t_1) {
20149
20150       /* "csamtools.pyx":1990
20151  * 
20152  *             if self.n_plp < 0:
20153  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
20154  * 
20155  *             # return result, if within same reference
20156  */
20157       __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_131), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20158       __Pyx_GOTREF(__pyx_t_2);
20159       __Pyx_Raise(__pyx_t_2, 0, 0, 0);
20160       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
20161       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20162       goto __pyx_L5;
20163     }
20164     __pyx_L5:;
20165
20166     /* "csamtools.pyx":1993
20167  * 
20168  *             # return result, if within same reference
20169  *             if self.plp != NULL:             # <<<<<<<<<<<<<<
20170  *                 return makePileupProxy( &self.plp,
20171  *                                          self.tid,
20172  */
20173     __pyx_t_1 = (__pyx_v_self->__pyx_base.plp != NULL);
20174     if (__pyx_t_1) {
20175
20176       /* "csamtools.pyx":1994
20177  *             # return result, if within same reference
20178  *             if self.plp != NULL:
20179  *                 return makePileupProxy( &self.plp,             # <<<<<<<<<<<<<<
20180  *                                          self.tid,
20181  *                                          self.pos,
20182  */
20183       __Pyx_XDECREF(__pyx_r);
20184
20185       /* "csamtools.pyx":1997
20186  *                                          self.tid,
20187  *                                          self.pos,
20188  *                                          self.n_plp )             # <<<<<<<<<<<<<<
20189  * 
20190  *             # otherwise, proceed to next reference or stop
20191  */
20192       __pyx_t_2 = __pyx_f_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 = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20193       __Pyx_GOTREF(__pyx_t_2);
20194       __pyx_r = __pyx_t_2;
20195       __pyx_t_2 = 0;
20196       goto __pyx_L0;
20197       goto __pyx_L6;
20198     }
20199     __pyx_L6:;
20200
20201     /* "csamtools.pyx":2000
20202  * 
20203  *             # otherwise, proceed to next reference or stop
20204  *             self.tid += 1             # <<<<<<<<<<<<<<
20205  *             if self.tid < self.samfile.nreferences:
20206  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
20207  */
20208     __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);
20209
20210     /* "csamtools.pyx":2001
20211  *             # otherwise, proceed to next reference or stop
20212  *             self.tid += 1
20213  *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
20214  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
20215  *             else:
20216  */
20217     __pyx_t_2 = PyInt_FromLong(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20218     __Pyx_GOTREF(__pyx_t_2);
20219     __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 = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20220     __Pyx_GOTREF(__pyx_t_3);
20221     __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20222     __Pyx_GOTREF(__pyx_t_4);
20223     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
20224     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
20225     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20226     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20227     if (__pyx_t_1) {
20228
20229       /* "csamtools.pyx":2002
20230  *             self.tid += 1
20231  *             if self.tid < self.samfile.nreferences:
20232  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )             # <<<<<<<<<<<<<<
20233  *             else:
20234  *                 raise StopIteration
20235  */
20236       __pyx_t_5.__pyx_n = 1;
20237       __pyx_t_5.reopen = 0;
20238       __pyx_t_4 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_9csamtools_max_pos, &__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20239       __Pyx_GOTREF(__pyx_t_4);
20240       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20241       goto __pyx_L7;
20242     }
20243     /*else*/ {
20244
20245       /* "csamtools.pyx":2004
20246  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
20247  *             else:
20248  *                 raise StopIteration             # <<<<<<<<<<<<<<
20249  * 
20250  * ##-------------------------------------------------------------------
20251  */
20252       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
20253       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20254     }
20255     __pyx_L7:;
20256   }
20257
20258   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20259   goto __pyx_L0;
20260   __pyx_L1_error:;
20261   __Pyx_XDECREF(__pyx_t_2);
20262   __Pyx_XDECREF(__pyx_t_3);
20263   __Pyx_XDECREF(__pyx_t_4);
20264   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
20265   __pyx_r = NULL;
20266   __pyx_L0:;
20267   __Pyx_XGIVEREF(__pyx_r);
20268   __Pyx_TraceReturn(__pyx_r);
20269   __Pyx_RefNannyFinishContext();
20270   return __pyx_r;
20271 }
20272
20273 /* "csamtools.pyx":2009
20274  * ##-------------------------------------------------------------------
20275  * ##-------------------------------------------------------------------
20276  * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
20277  *     cdef uint32_t * cigar_p, op
20278  *     cdef uint32_t k
20279  */
20280
20281 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_start(bam1_t *__pyx_v_src) {
20282   uint32_t *__pyx_v_cigar_p;
20283   uint32_t __pyx_v_op;
20284   uint32_t __pyx_v_k;
20285   uint32_t __pyx_v_start_offset;
20286   int32_t __pyx_r;
20287   __Pyx_RefNannyDeclarations
20288   uint32_t __pyx_t_1;
20289   int __pyx_t_2;
20290   int __pyx_t_3;
20291   int __pyx_t_4;
20292   PyObject *__pyx_t_5 = NULL;
20293   __Pyx_TraceDeclarations
20294   __Pyx_RefNannySetupContext("query_start", 0);
20295   __Pyx_TraceCall("query_start", __pyx_f[0], 2009);
20296
20297   /* "csamtools.pyx":2012
20298  *     cdef uint32_t * cigar_p, op
20299  *     cdef uint32_t k
20300  *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
20301  * 
20302  *     if src.core.n_cigar:
20303  */
20304   __pyx_v_start_offset = 0;
20305
20306   /* "csamtools.pyx":2014
20307  *     cdef uint32_t start_offset = 0
20308  * 
20309  *     if src.core.n_cigar:             # <<<<<<<<<<<<<<
20310  *         cigar_p = bam1_cigar(src);
20311  *         for k from 0 <= k < src.core.n_cigar:
20312  */
20313   if (__pyx_v_src->core.n_cigar) {
20314
20315     /* "csamtools.pyx":2015
20316  * 
20317  *     if src.core.n_cigar:
20318  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
20319  *         for k from 0 <= k < src.core.n_cigar:
20320  *             op = cigar_p[k] & BAM_CIGAR_MASK
20321  */
20322     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
20323
20324     /* "csamtools.pyx":2016
20325  *     if src.core.n_cigar:
20326  *         cigar_p = bam1_cigar(src);
20327  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
20328  *             op = cigar_p[k] & BAM_CIGAR_MASK
20329  *             if op==BAM_CHARD_CLIP:
20330  */
20331     __pyx_t_1 = __pyx_v_src->core.n_cigar;
20332     for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_1; __pyx_v_k++) {
20333
20334       /* "csamtools.pyx":2017
20335  *         cigar_p = bam1_cigar(src);
20336  *         for k from 0 <= k < src.core.n_cigar:
20337  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
20338  *             if op==BAM_CHARD_CLIP:
20339  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
20340  */
20341       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
20342
20343       /* "csamtools.pyx":2022
20344  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20345  *                     return -1
20346  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
20347  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
20348  *             else:
20349  */
20350       switch (__pyx_v_op) {
20351
20352         /* "csamtools.pyx":2018
20353  *         for k from 0 <= k < src.core.n_cigar:
20354  *             op = cigar_p[k] & BAM_CIGAR_MASK
20355  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
20356  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
20357  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20358  */
20359         case 5:
20360
20361         /* "csamtools.pyx":2019
20362  *             op = cigar_p[k] & BAM_CIGAR_MASK
20363  *             if op==BAM_CHARD_CLIP:
20364  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
20365  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20366  *                     return -1
20367  */
20368         __pyx_t_2 = (__pyx_v_start_offset != 0);
20369         if (__pyx_t_2) {
20370           __pyx_t_3 = (__pyx_v_start_offset != __pyx_v_src->core.l_qseq);
20371           __pyx_t_4 = __pyx_t_3;
20372         } else {
20373           __pyx_t_4 = __pyx_t_2;
20374         }
20375         if (__pyx_t_4) {
20376
20377           /* "csamtools.pyx":2020
20378  *             if op==BAM_CHARD_CLIP:
20379  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
20380  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
20381  *                     return -1
20382  *             elif op==BAM_CSOFT_CLIP:
20383  */
20384           __pyx_t_5 = __pyx_builtin_ValueError;
20385           __Pyx_INCREF(__pyx_t_5);
20386           PyErr_SetString(__pyx_t_5, __pyx_k_132);
20387           __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
20388
20389           /* "csamtools.pyx":2021
20390  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
20391  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20392  *                     return -1             # <<<<<<<<<<<<<<
20393  *             elif op==BAM_CSOFT_CLIP:
20394  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
20395  */
20396           __pyx_r = -1;
20397           goto __pyx_L0;
20398           goto __pyx_L6;
20399         }
20400         __pyx_L6:;
20401         break;
20402
20403         /* "csamtools.pyx":2022
20404  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20405  *                     return -1
20406  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
20407  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
20408  *             else:
20409  */
20410         case 4:
20411
20412         /* "csamtools.pyx":2023
20413  *                     return -1
20414  *             elif op==BAM_CSOFT_CLIP:
20415  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
20416  *             else:
20417  *                 break
20418  */
20419         __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> 4));
20420         break;
20421         default:
20422
20423         /* "csamtools.pyx":2025
20424  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
20425  *             else:
20426  *                 break             # <<<<<<<<<<<<<<
20427  * 
20428  *     return start_offset
20429  */
20430         goto __pyx_L5_break;
20431         break;
20432       }
20433     }
20434     __pyx_L5_break:;
20435     goto __pyx_L3;
20436   }
20437   __pyx_L3:;
20438
20439   /* "csamtools.pyx":2027
20440  *                 break
20441  * 
20442  *     return start_offset             # <<<<<<<<<<<<<<
20443  * 
20444  * ##-------------------------------------------------------------------
20445  */
20446   __pyx_r = __pyx_v_start_offset;
20447   goto __pyx_L0;
20448
20449   __pyx_r = 0;
20450   __pyx_L0:;
20451   __Pyx_TraceReturn(Py_None);
20452   __Pyx_RefNannyFinishContext();
20453   return __pyx_r;
20454 }
20455
20456 /* "csamtools.pyx":2032
20457  * ##-------------------------------------------------------------------
20458  * ##-------------------------------------------------------------------
20459  * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
20460  *     cdef uint32_t * cigar_p, op
20461  *     cdef uint32_t k
20462  */
20463
20464 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_end(bam1_t *__pyx_v_src) {
20465   uint32_t *__pyx_v_cigar_p;
20466   uint32_t __pyx_v_op;
20467   uint32_t __pyx_v_k;
20468   uint32_t __pyx_v_end_offset;
20469   int32_t __pyx_r;
20470   __Pyx_RefNannyDeclarations
20471   int __pyx_t_1;
20472   int __pyx_t_2;
20473   int __pyx_t_3;
20474   PyObject *__pyx_t_4 = NULL;
20475   __Pyx_TraceDeclarations
20476   __Pyx_RefNannySetupContext("query_end", 0);
20477   __Pyx_TraceCall("query_end", __pyx_f[0], 2032);
20478
20479   /* "csamtools.pyx":2035
20480  *     cdef uint32_t * cigar_p, op
20481  *     cdef uint32_t k
20482  *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
20483  * 
20484  *     if src.core.n_cigar>1:
20485  */
20486   __pyx_v_end_offset = __pyx_v_src->core.l_qseq;
20487
20488   /* "csamtools.pyx":2037
20489  *     cdef uint32_t end_offset = src.core.l_qseq
20490  * 
20491  *     if src.core.n_cigar>1:             # <<<<<<<<<<<<<<
20492  *         cigar_p = bam1_cigar(src);
20493  *         for k from src.core.n_cigar > k >= 1:
20494  */
20495   __pyx_t_1 = (__pyx_v_src->core.n_cigar > 1);
20496   if (__pyx_t_1) {
20497
20498     /* "csamtools.pyx":2038
20499  * 
20500  *     if src.core.n_cigar>1:
20501  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
20502  *         for k from src.core.n_cigar > k >= 1:
20503  *             op = cigar_p[k] & BAM_CIGAR_MASK
20504  */
20505     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
20506
20507     /* "csamtools.pyx":2039
20508  *     if src.core.n_cigar>1:
20509  *         cigar_p = bam1_cigar(src);
20510  *         for k from src.core.n_cigar > k >= 1:             # <<<<<<<<<<<<<<
20511  *             op = cigar_p[k] & BAM_CIGAR_MASK
20512  *             if op==BAM_CHARD_CLIP:
20513  */
20514     for (__pyx_v_k = __pyx_v_src->core.n_cigar-1; __pyx_v_k >= 1; __pyx_v_k--) {
20515
20516       /* "csamtools.pyx":2040
20517  *         cigar_p = bam1_cigar(src);
20518  *         for k from src.core.n_cigar > k >= 1:
20519  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
20520  *             if op==BAM_CHARD_CLIP:
20521  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
20522  */
20523       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
20524
20525       /* "csamtools.pyx":2045
20526  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20527  *                     return -1
20528  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
20529  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
20530  *             else:
20531  */
20532       switch (__pyx_v_op) {
20533
20534         /* "csamtools.pyx":2041
20535  *         for k from src.core.n_cigar > k >= 1:
20536  *             op = cigar_p[k] & BAM_CIGAR_MASK
20537  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
20538  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
20539  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20540  */
20541         case 5:
20542
20543         /* "csamtools.pyx":2042
20544  *             op = cigar_p[k] & BAM_CIGAR_MASK
20545  *             if op==BAM_CHARD_CLIP:
20546  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
20547  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20548  *                     return -1
20549  */
20550         __pyx_t_1 = (__pyx_v_end_offset != 0);
20551         if (__pyx_t_1) {
20552           __pyx_t_2 = (__pyx_v_end_offset != __pyx_v_src->core.l_qseq);
20553           __pyx_t_3 = __pyx_t_2;
20554         } else {
20555           __pyx_t_3 = __pyx_t_1;
20556         }
20557         if (__pyx_t_3) {
20558
20559           /* "csamtools.pyx":2043
20560  *             if op==BAM_CHARD_CLIP:
20561  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
20562  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
20563  *                     return -1
20564  *             elif op==BAM_CSOFT_CLIP:
20565  */
20566           __pyx_t_4 = __pyx_builtin_ValueError;
20567           __Pyx_INCREF(__pyx_t_4);
20568           PyErr_SetString(__pyx_t_4, __pyx_k_132);
20569           __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20570
20571           /* "csamtools.pyx":2044
20572  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
20573  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20574  *                     return -1             # <<<<<<<<<<<<<<
20575  *             elif op==BAM_CSOFT_CLIP:
20576  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
20577  */
20578           __pyx_r = -1;
20579           goto __pyx_L0;
20580           goto __pyx_L6;
20581         }
20582         __pyx_L6:;
20583         break;
20584
20585         /* "csamtools.pyx":2045
20586  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
20587  *                     return -1
20588  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
20589  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
20590  *             else:
20591  */
20592         case 4:
20593
20594         /* "csamtools.pyx":2046
20595  *                     return -1
20596  *             elif op==BAM_CSOFT_CLIP:
20597  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
20598  *             else:
20599  *                 break
20600  */
20601         __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> 4));
20602         break;
20603         default:
20604
20605         /* "csamtools.pyx":2048
20606  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
20607  *             else:
20608  *                 break             # <<<<<<<<<<<<<<
20609  * 
20610  *     if end_offset==0:
20611  */
20612         goto __pyx_L5_break;
20613         break;
20614       }
20615     }
20616     __pyx_L5_break:;
20617     goto __pyx_L3;
20618   }
20619   __pyx_L3:;
20620
20621   /* "csamtools.pyx":2050
20622  *                 break
20623  * 
20624  *     if end_offset==0:             # <<<<<<<<<<<<<<
20625  *         end_offset = src.core.l_qseq
20626  * 
20627  */
20628   __pyx_t_3 = (__pyx_v_end_offset == 0);
20629   if (__pyx_t_3) {
20630
20631     /* "csamtools.pyx":2051
20632  * 
20633  *     if end_offset==0:
20634  *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
20635  * 
20636  *     return end_offset
20637  */
20638     __pyx_v_end_offset = __pyx_v_src->core.l_qseq;
20639     goto __pyx_L7;
20640   }
20641   __pyx_L7:;
20642
20643   /* "csamtools.pyx":2053
20644  *         end_offset = src.core.l_qseq
20645  * 
20646  *     return end_offset             # <<<<<<<<<<<<<<
20647  * 
20648  * 
20649  */
20650   __pyx_r = __pyx_v_end_offset;
20651   goto __pyx_L0;
20652
20653   __pyx_r = 0;
20654   __pyx_L0:;
20655   __Pyx_TraceReturn(Py_None);
20656   __Pyx_RefNannyFinishContext();
20657   return __pyx_r;
20658 }
20659
20660 /* "csamtools.pyx":2056
20661  * 
20662  * 
20663  * cdef inline object get_seq_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
20664  *     cdef uint8_t * p
20665  *     cdef uint32_t k
20666  */
20667
20668 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_seq_range(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
20669   uint8_t *__pyx_v_p;
20670   uint32_t __pyx_v_k;
20671   char *__pyx_v_s;
20672   PyObject *__pyx_v_seq = NULL;
20673   PyObject *__pyx_r = NULL;
20674   __Pyx_RefNannyDeclarations
20675   int __pyx_t_1;
20676   PyObject *__pyx_t_2 = NULL;
20677   char *__pyx_t_3;
20678   uint32_t __pyx_t_4;
20679   int __pyx_lineno = 0;
20680   const char *__pyx_filename = NULL;
20681   int __pyx_clineno = 0;
20682   __Pyx_TraceDeclarations
20683   __Pyx_RefNannySetupContext("get_seq_range", 0);
20684   __Pyx_TraceCall("get_seq_range", __pyx_f[0], 2056);
20685
20686   /* "csamtools.pyx":2061
20687  *     cdef char * s
20688  * 
20689  *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
20690  *         return None
20691  * 
20692  */
20693   __pyx_t_1 = (!__pyx_v_src->core.l_qseq);
20694   if (__pyx_t_1) {
20695
20696     /* "csamtools.pyx":2062
20697  * 
20698  *     if not src.core.l_qseq:
20699  *         return None             # <<<<<<<<<<<<<<
20700  * 
20701  *     seq = PyBytes_FromStringAndSize(NULL, end - start)
20702  */
20703     __Pyx_XDECREF(__pyx_r);
20704     __Pyx_INCREF(Py_None);
20705     __pyx_r = Py_None;
20706     goto __pyx_L0;
20707     goto __pyx_L3;
20708   }
20709   __pyx_L3:;
20710
20711   /* "csamtools.pyx":2064
20712  *         return None
20713  * 
20714  *     seq = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
20715  *     s   = <char*>seq
20716  *     p   = bam1_seq(src)
20717  */
20718   __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 = 2064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20719   __Pyx_GOTREF(__pyx_t_2);
20720   __pyx_v_seq = ((PyObject*)__pyx_t_2);
20721   __pyx_t_2 = 0;
20722
20723   /* "csamtools.pyx":2065
20724  * 
20725  *     seq = PyBytes_FromStringAndSize(NULL, end - start)
20726  *     s   = <char*>seq             # <<<<<<<<<<<<<<
20727  *     p   = bam1_seq(src)
20728  * 
20729  */
20730   __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_seq)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20731   __pyx_v_s = ((char *)__pyx_t_3);
20732
20733   /* "csamtools.pyx":2066
20734  *     seq = PyBytes_FromStringAndSize(NULL, end - start)
20735  *     s   = <char*>seq
20736  *     p   = bam1_seq(src)             # <<<<<<<<<<<<<<
20737  * 
20738  *     for k from start <= k < end:
20739  */
20740   __pyx_v_p = bam1_seq(__pyx_v_src);
20741
20742   /* "csamtools.pyx":2068
20743  *     p   = bam1_seq(src)
20744  * 
20745  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
20746  *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
20747  *         # note: do not use string literal as it will be a python string
20748  */
20749   __pyx_t_4 = __pyx_v_end;
20750   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
20751
20752     /* "csamtools.pyx":2071
20753  *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
20754  *         # note: do not use string literal as it will be a python string
20755  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
20756  * 
20757  *     return seq
20758  */
20759     (__pyx_v_s[(__pyx_v_k - __pyx_v_start)]) = (__pyx_v_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)]);
20760   }
20761
20762   /* "csamtools.pyx":2073
20763  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]
20764  * 
20765  *     return seq             # <<<<<<<<<<<<<<
20766  * 
20767  * 
20768  */
20769   __Pyx_XDECREF(__pyx_r);
20770   __Pyx_INCREF(((PyObject *)__pyx_v_seq));
20771   __pyx_r = ((PyObject *)__pyx_v_seq);
20772   goto __pyx_L0;
20773
20774   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20775   goto __pyx_L0;
20776   __pyx_L1_error:;
20777   __Pyx_XDECREF(__pyx_t_2);
20778   __Pyx_AddTraceback("csamtools.get_seq_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
20779   __pyx_r = 0;
20780   __pyx_L0:;
20781   __Pyx_XDECREF(__pyx_v_seq);
20782   __Pyx_XGIVEREF(__pyx_r);
20783   __Pyx_TraceReturn(__pyx_r);
20784   __Pyx_RefNannyFinishContext();
20785   return __pyx_r;
20786 }
20787
20788 /* "csamtools.pyx":2076
20789  * 
20790  * 
20791  * cdef inline object get_qual_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
20792  *     cdef uint8_t * p
20793  *     cdef uint32_t k
20794  */
20795
20796 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_qual_range(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
20797   uint8_t *__pyx_v_p;
20798   uint32_t __pyx_v_k;
20799   char *__pyx_v_q;
20800   PyObject *__pyx_v_qual = NULL;
20801   PyObject *__pyx_r = NULL;
20802   __Pyx_RefNannyDeclarations
20803   int __pyx_t_1;
20804   PyObject *__pyx_t_2 = NULL;
20805   char *__pyx_t_3;
20806   uint32_t __pyx_t_4;
20807   int __pyx_lineno = 0;
20808   const char *__pyx_filename = NULL;
20809   int __pyx_clineno = 0;
20810   __Pyx_TraceDeclarations
20811   __Pyx_RefNannySetupContext("get_qual_range", 0);
20812   __Pyx_TraceCall("get_qual_range", __pyx_f[0], 2076);
20813
20814   /* "csamtools.pyx":2081
20815  *     cdef char * q
20816  * 
20817  *     p = bam1_qual(src)             # <<<<<<<<<<<<<<
20818  *     if p[0] == 0xff:
20819  *         return None
20820  */
20821   __pyx_v_p = bam1_qual(__pyx_v_src);
20822
20823   /* "csamtools.pyx":2082
20824  * 
20825  *     p = bam1_qual(src)
20826  *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
20827  *         return None
20828  * 
20829  */
20830   __pyx_t_1 = ((__pyx_v_p[0]) == 0xff);
20831   if (__pyx_t_1) {
20832
20833     /* "csamtools.pyx":2083
20834  *     p = bam1_qual(src)
20835  *     if p[0] == 0xff:
20836  *         return None             # <<<<<<<<<<<<<<
20837  * 
20838  *     qual = PyBytes_FromStringAndSize(NULL, end - start)
20839  */
20840     __Pyx_XDECREF(__pyx_r);
20841     __Pyx_INCREF(Py_None);
20842     __pyx_r = Py_None;
20843     goto __pyx_L0;
20844     goto __pyx_L3;
20845   }
20846   __pyx_L3:;
20847
20848   /* "csamtools.pyx":2085
20849  *         return None
20850  * 
20851  *     qual = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
20852  *     q    = <char*>qual
20853  * 
20854  */
20855   __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 = 2085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20856   __Pyx_GOTREF(__pyx_t_2);
20857   __pyx_v_qual = ((PyObject*)__pyx_t_2);
20858   __pyx_t_2 = 0;
20859
20860   /* "csamtools.pyx":2086
20861  * 
20862  *     qual = PyBytes_FromStringAndSize(NULL, end - start)
20863  *     q    = <char*>qual             # <<<<<<<<<<<<<<
20864  * 
20865  *     for k from start <= k < end:
20866  */
20867   __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_qual)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20868   __pyx_v_q = ((char *)__pyx_t_3);
20869
20870   /* "csamtools.pyx":2088
20871  *     q    = <char*>qual
20872  * 
20873  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
20874  *         ## equivalent to t[i] + 33 (see bam.c)
20875  *         q[k-start] = p[k] + 33
20876  */
20877   __pyx_t_4 = __pyx_v_end;
20878   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {
20879
20880     /* "csamtools.pyx":2090
20881  *     for k from start <= k < end:
20882  *         ## equivalent to t[i] + 33 (see bam.c)
20883  *         q[k-start] = p[k] + 33             # <<<<<<<<<<<<<<
20884  * 
20885  *     return qual
20886  */
20887     (__pyx_v_q[(__pyx_v_k - __pyx_v_start)]) = ((__pyx_v_p[__pyx_v_k]) + 33);
20888   }
20889
20890   /* "csamtools.pyx":2092
20891  *         q[k-start] = p[k] + 33
20892  * 
20893  *     return qual             # <<<<<<<<<<<<<<
20894  * 
20895  * cdef class AlignedRead:
20896  */
20897   __Pyx_XDECREF(__pyx_r);
20898   __Pyx_INCREF(((PyObject *)__pyx_v_qual));
20899   __pyx_r = ((PyObject *)__pyx_v_qual);
20900   goto __pyx_L0;
20901
20902   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20903   goto __pyx_L0;
20904   __pyx_L1_error:;
20905   __Pyx_XDECREF(__pyx_t_2);
20906   __Pyx_AddTraceback("csamtools.get_qual_range", __pyx_clineno, __pyx_lineno, __pyx_filename);
20907   __pyx_r = 0;
20908   __pyx_L0:;
20909   __Pyx_XDECREF(__pyx_v_qual);
20910   __Pyx_XGIVEREF(__pyx_r);
20911   __Pyx_TraceReturn(__pyx_r);
20912   __Pyx_RefNannyFinishContext();
20913   return __pyx_r;
20914 }
20915
20916 /* Python wrapper */
20917 static int __pyx_pw_9csamtools_11AlignedRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
20918 static int __pyx_pw_9csamtools_11AlignedRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
20919   int __pyx_r;
20920   __Pyx_RefNannyDeclarations
20921   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
20922   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
20923     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
20924   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
20925   __pyx_r = __pyx_pf_9csamtools_11AlignedRead___init__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
20926   __Pyx_RefNannyFinishContext();
20927   return __pyx_r;
20928 }
20929
20930 /* "csamtools.pyx":2124
20931  * 
20932  *     # Now only called when instances are created from Python
20933  *     def __init__(self):             # <<<<<<<<<<<<<<
20934  *         # see bam_init1
20935  *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )
20936  */
20937
20938 static int __pyx_pf_9csamtools_11AlignedRead___init__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
20939   int __pyx_r;
20940   __Pyx_RefNannyDeclarations
20941   __Pyx_TraceDeclarations
20942   __Pyx_RefNannySetupContext("__init__", 0);
20943   __Pyx_TraceCall("__init__", __pyx_f[0], 2124);
20944
20945   /* "csamtools.pyx":2126
20946  *     def __init__(self):
20947  *         # see bam_init1
20948  *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
20949  *         # allocate some memory
20950  *         # If size is 0, calloc does not return a pointer that can be passed to free()
20951  */
20952   __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
20953
20954   /* "csamtools.pyx":2130
20955  *         # If size is 0, calloc does not return a pointer that can be passed to free()
20956  *         # so allocate 40 bytes for a new read
20957  *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
20958  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
20959  *         self._delegate.data_len = 0
20960  */
20961   __pyx_v_self->_delegate->m_data = 40;
20962
20963   /* "csamtools.pyx":2131
20964  *         # so allocate 40 bytes for a new read
20965  *         self._delegate.m_data = 40
20966  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )             # <<<<<<<<<<<<<<
20967  *         self._delegate.data_len = 0
20968  * 
20969  */
20970   __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1));
20971
20972   /* "csamtools.pyx":2132
20973  *         self._delegate.m_data = 40
20974  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
20975  *         self._delegate.data_len = 0             # <<<<<<<<<<<<<<
20976  * 
20977  *     def __dealloc__(self):
20978  */
20979   __pyx_v_self->_delegate->data_len = 0;
20980
20981   __pyx_r = 0;
20982   __Pyx_TraceReturn(Py_None);
20983   __Pyx_RefNannyFinishContext();
20984   return __pyx_r;
20985 }
20986
20987 /* Python wrapper */
20988 static void __pyx_pw_9csamtools_11AlignedRead_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
20989 static void __pyx_pw_9csamtools_11AlignedRead_3__dealloc__(PyObject *__pyx_v_self) {
20990   __Pyx_RefNannyDeclarations
20991   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
20992   __pyx_pf_9csamtools_11AlignedRead_2__dealloc__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
20993   __Pyx_RefNannyFinishContext();
20994 }
20995
20996 /* "csamtools.pyx":2134
20997  *         self._delegate.data_len = 0
20998  * 
20999  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
21000  *         bam_destroy1(self._delegate)
21001  * 
21002  */
21003
21004 static void __pyx_pf_9csamtools_11AlignedRead_2__dealloc__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
21005   __Pyx_RefNannyDeclarations
21006   __Pyx_TraceDeclarations
21007   __Pyx_RefNannySetupContext("__dealloc__", 0);
21008   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2134);
21009
21010   /* "csamtools.pyx":2135
21011  * 
21012  *     def __dealloc__(self):
21013  *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
21014  * 
21015  *     def __str__(self):
21016  */
21017   bam_destroy1(__pyx_v_self->_delegate);
21018
21019   __Pyx_TraceReturn(Py_None);
21020   __Pyx_RefNannyFinishContext();
21021 }
21022
21023 /* Python wrapper */
21024 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5__str__(PyObject *__pyx_v_self); /*proto*/
21025 static char __pyx_doc_9csamtools_11AlignedRead_4__str__[] = "return string representation of alignment.\n\n        The representation is an approximate :term:`sam` format.\n\n        An aligned read might not be associated with a :term:`Samfile`.\n        As a result :term:`tid` is shown instead of the reference name.\n\n        Similarly, the tags field is returned in its parsed state.\n        ";
21026 struct wrapperbase __pyx_wrapperbase_9csamtools_11AlignedRead_4__str__;
21027 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5__str__(PyObject *__pyx_v_self) {
21028   PyObject *__pyx_r = 0;
21029   __Pyx_RefNannyDeclarations
21030   __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
21031   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4__str__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
21032   __Pyx_RefNannyFinishContext();
21033   return __pyx_r;
21034 }
21035
21036 /* "csamtools.pyx":2137
21037  *         bam_destroy1(self._delegate)
21038  * 
21039  *     def __str__(self):             # <<<<<<<<<<<<<<
21040  *         """return string representation of alignment.
21041  * 
21042  */
21043
21044 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4__str__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
21045   PyObject *__pyx_v_seq = NULL;
21046   PyObject *__pyx_v_qual = NULL;
21047   PyObject *__pyx_r = NULL;
21048   __Pyx_RefNannyDeclarations
21049   PyObject *__pyx_t_1 = NULL;
21050   PyObject *__pyx_t_2 = NULL;
21051   int __pyx_t_3;
21052   PyObject *__pyx_t_4 = NULL;
21053   PyObject *__pyx_t_5 = NULL;
21054   PyObject *__pyx_t_6 = NULL;
21055   PyObject *__pyx_t_7 = NULL;
21056   PyObject *__pyx_t_8 = NULL;
21057   PyObject *__pyx_t_9 = NULL;
21058   PyObject *__pyx_t_10 = NULL;
21059   PyObject *__pyx_t_11 = NULL;
21060   PyObject *__pyx_t_12 = NULL;
21061   PyObject *__pyx_t_13 = NULL;
21062   int __pyx_lineno = 0;
21063   const char *__pyx_filename = NULL;
21064   int __pyx_clineno = 0;
21065   __Pyx_TraceDeclarations
21066   __Pyx_RefNannySetupContext("__str__", 0);
21067   __Pyx_TraceCall("__str__", __pyx_f[0], 2137);
21068
21069   /* "csamtools.pyx":2149
21070  *         # sam-parsing is done in sam.c/bam_format1_core which
21071  *         # requires a valid header.
21072  *         if sys.version_info[0] < 3:             # <<<<<<<<<<<<<<
21073  *             seq = self.seq
21074  *             qual = self.qual
21075  */
21076   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21077   __Pyx_GOTREF(__pyx_t_1);
21078   __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 = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21079   __Pyx_GOTREF(__pyx_t_2);
21080   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21081   __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21082   __Pyx_GOTREF(__pyx_t_1);
21083   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21084   __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_3, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21085   __Pyx_GOTREF(__pyx_t_2);
21086   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21087   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21088   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21089   if (__pyx_t_3) {
21090
21091     /* "csamtools.pyx":2150
21092  *         # requires a valid header.
21093  *         if sys.version_info[0] < 3:
21094  *             seq = self.seq             # <<<<<<<<<<<<<<
21095  *             qual = self.qual
21096  *         else:
21097  */
21098     __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 = 2150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21099     __Pyx_GOTREF(__pyx_t_2);
21100     __pyx_v_seq = __pyx_t_2;
21101     __pyx_t_2 = 0;
21102
21103     /* "csamtools.pyx":2151
21104  *         if sys.version_info[0] < 3:
21105  *             seq = self.seq
21106  *             qual = self.qual             # <<<<<<<<<<<<<<
21107  *         else:
21108  *             seq = self.seq.decode('ascii')
21109  */
21110     __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 = 2151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21111     __Pyx_GOTREF(__pyx_t_2);
21112     __pyx_v_qual = __pyx_t_2;
21113     __pyx_t_2 = 0;
21114     goto __pyx_L3;
21115   }
21116   /*else*/ {
21117
21118     /* "csamtools.pyx":2153
21119  *             qual = self.qual
21120  *         else:
21121  *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
21122  *             qual = self.qual.decode('ascii')
21123  *         return "\t".join(map(str, (self.qname,
21124  */
21125     __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 = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21126     __Pyx_GOTREF(__pyx_t_2);
21127     __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21128     __Pyx_GOTREF(__pyx_t_1);
21129     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21130     __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_133), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21131     __Pyx_GOTREF(__pyx_t_2);
21132     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21133     __pyx_v_seq = __pyx_t_2;
21134     __pyx_t_2 = 0;
21135
21136     /* "csamtools.pyx":2154
21137  *         else:
21138  *             seq = self.seq.decode('ascii')
21139  *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
21140  *         return "\t".join(map(str, (self.qname,
21141  *                                    self.flag,
21142  */
21143     __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 = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21144     __Pyx_GOTREF(__pyx_t_2);
21145     __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__decode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21146     __Pyx_GOTREF(__pyx_t_1);
21147     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21148     __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21149     __Pyx_GOTREF(__pyx_t_2);
21150     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21151     __pyx_v_qual = __pyx_t_2;
21152     __pyx_t_2 = 0;
21153   }
21154   __pyx_L3:;
21155
21156   /* "csamtools.pyx":2155
21157  *             seq = self.seq.decode('ascii')
21158  *             qual = self.qual.decode('ascii')
21159  *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
21160  *                                    self.flag,
21161  *                                    self.rname,
21162  */
21163   __Pyx_XDECREF(__pyx_r);
21164   __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 = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21165   __Pyx_GOTREF(__pyx_t_2);
21166   __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 = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21167   __Pyx_GOTREF(__pyx_t_1);
21168
21169   /* "csamtools.pyx":2156
21170  *             qual = self.qual.decode('ascii')
21171  *         return "\t".join(map(str, (self.qname,
21172  *                                    self.flag,             # <<<<<<<<<<<<<<
21173  *                                    self.rname,
21174  *                                    self.pos,
21175  */
21176   __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 = 2156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21177   __Pyx_GOTREF(__pyx_t_4);
21178
21179   /* "csamtools.pyx":2157
21180  *         return "\t".join(map(str, (self.qname,
21181  *                                    self.flag,
21182  *                                    self.rname,             # <<<<<<<<<<<<<<
21183  *                                    self.pos,
21184  *                                    self.mapq,
21185  */
21186   __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 = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21187   __Pyx_GOTREF(__pyx_t_5);
21188
21189   /* "csamtools.pyx":2158
21190  *                                    self.flag,
21191  *                                    self.rname,
21192  *                                    self.pos,             # <<<<<<<<<<<<<<
21193  *                                    self.mapq,
21194  *                                    self.cigar,
21195  */
21196   __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 = 2158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21197   __Pyx_GOTREF(__pyx_t_6);
21198
21199   /* "csamtools.pyx":2159
21200  *                                    self.rname,
21201  *                                    self.pos,
21202  *                                    self.mapq,             # <<<<<<<<<<<<<<
21203  *                                    self.cigar,
21204  *                                    self.mrnm,
21205  */
21206   __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 = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21207   __Pyx_GOTREF(__pyx_t_7);
21208
21209   /* "csamtools.pyx":2160
21210  *                                    self.pos,
21211  *                                    self.mapq,
21212  *                                    self.cigar,             # <<<<<<<<<<<<<<
21213  *                                    self.mrnm,
21214  *                                    self.mpos,
21215  */
21216   __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 = 2160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21217   __Pyx_GOTREF(__pyx_t_8);
21218
21219   /* "csamtools.pyx":2161
21220  *                                    self.mapq,
21221  *                                    self.cigar,
21222  *                                    self.mrnm,             # <<<<<<<<<<<<<<
21223  *                                    self.mpos,
21224  *                                    self.rlen,
21225  */
21226   __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 = 2161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21227   __Pyx_GOTREF(__pyx_t_9);
21228
21229   /* "csamtools.pyx":2162
21230  *                                    self.cigar,
21231  *                                    self.mrnm,
21232  *                                    self.mpos,             # <<<<<<<<<<<<<<
21233  *                                    self.rlen,
21234  *                                    seq,
21235  */
21236   __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 = 2162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21237   __Pyx_GOTREF(__pyx_t_10);
21238
21239   /* "csamtools.pyx":2163
21240  *                                    self.mrnm,
21241  *                                    self.mpos,
21242  *                                    self.rlen,             # <<<<<<<<<<<<<<
21243  *                                    seq,
21244  *                                    qual,
21245  */
21246   __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 = 2163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21247   __Pyx_GOTREF(__pyx_t_11);
21248
21249   /* "csamtools.pyx":2166
21250  *                                    seq,
21251  *                                    qual,
21252  *                                    self.tags )))             # <<<<<<<<<<<<<<
21253  * 
21254  *     def compare(self, AlignedRead other):
21255  */
21256   __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 = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21257   __Pyx_GOTREF(__pyx_t_12);
21258   __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21259   __Pyx_GOTREF(__pyx_t_13);
21260   PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1);
21261   __Pyx_GIVEREF(__pyx_t_1);
21262   PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4);
21263   __Pyx_GIVEREF(__pyx_t_4);
21264   PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_5);
21265   __Pyx_GIVEREF(__pyx_t_5);
21266   PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_6);
21267   __Pyx_GIVEREF(__pyx_t_6);
21268   PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_7);
21269   __Pyx_GIVEREF(__pyx_t_7);
21270   PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_8);
21271   __Pyx_GIVEREF(__pyx_t_8);
21272   PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_9);
21273   __Pyx_GIVEREF(__pyx_t_9);
21274   PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_10);
21275   __Pyx_GIVEREF(__pyx_t_10);
21276   PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_11);
21277   __Pyx_GIVEREF(__pyx_t_11);
21278   __Pyx_INCREF(__pyx_v_seq);
21279   PyTuple_SET_ITEM(__pyx_t_13, 9, __pyx_v_seq);
21280   __Pyx_GIVEREF(__pyx_v_seq);
21281   __Pyx_INCREF(__pyx_v_qual);
21282   PyTuple_SET_ITEM(__pyx_t_13, 10, __pyx_v_qual);
21283   __Pyx_GIVEREF(__pyx_v_qual);
21284   PyTuple_SET_ITEM(__pyx_t_13, 11, __pyx_t_12);
21285   __Pyx_GIVEREF(__pyx_t_12);
21286   __pyx_t_1 = 0;
21287   __pyx_t_4 = 0;
21288   __pyx_t_5 = 0;
21289   __pyx_t_6 = 0;
21290   __pyx_t_7 = 0;
21291   __pyx_t_8 = 0;
21292   __pyx_t_9 = 0;
21293   __pyx_t_10 = 0;
21294   __pyx_t_11 = 0;
21295   __pyx_t_12 = 0;
21296   __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21297   __Pyx_GOTREF(__pyx_t_12);
21298   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
21299   PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
21300   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
21301   PyTuple_SET_ITEM(__pyx_t_12, 1, ((PyObject *)__pyx_t_13));
21302   __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
21303   __pyx_t_13 = 0;
21304   __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 = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21305   __Pyx_GOTREF(__pyx_t_13);
21306   __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
21307   __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21308   __Pyx_GOTREF(__pyx_t_12);
21309   PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_13);
21310   __Pyx_GIVEREF(__pyx_t_13);
21311   __pyx_t_13 = 0;
21312   __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 = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21313   __Pyx_GOTREF(__pyx_t_13);
21314   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21315   __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0;
21316   __pyx_r = __pyx_t_13;
21317   __pyx_t_13 = 0;
21318   goto __pyx_L0;
21319
21320   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21321   goto __pyx_L0;
21322   __pyx_L1_error:;
21323   __Pyx_XDECREF(__pyx_t_1);
21324   __Pyx_XDECREF(__pyx_t_2);
21325   __Pyx_XDECREF(__pyx_t_4);
21326   __Pyx_XDECREF(__pyx_t_5);
21327   __Pyx_XDECREF(__pyx_t_6);
21328   __Pyx_XDECREF(__pyx_t_7);
21329   __Pyx_XDECREF(__pyx_t_8);
21330   __Pyx_XDECREF(__pyx_t_9);
21331   __Pyx_XDECREF(__pyx_t_10);
21332   __Pyx_XDECREF(__pyx_t_11);
21333   __Pyx_XDECREF(__pyx_t_12);
21334   __Pyx_XDECREF(__pyx_t_13);
21335   __Pyx_AddTraceback("csamtools.AlignedRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
21336   __pyx_r = NULL;
21337   __pyx_L0:;
21338   __Pyx_XDECREF(__pyx_v_seq);
21339   __Pyx_XDECREF(__pyx_v_qual);
21340   __Pyx_XGIVEREF(__pyx_r);
21341   __Pyx_TraceReturn(__pyx_r);
21342   __Pyx_RefNannyFinishContext();
21343   return __pyx_r;
21344 }
21345
21346 /* Python wrapper */
21347 static PyObject *__pyx_pw_9csamtools_11AlignedRead_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
21348 static char __pyx_doc_9csamtools_11AlignedRead_6compare[] = "AlignedRead.compare(self, AlignedRead other)\nreturn -1,0,1, if contents in this are binary <,=,> to *other*";
21349 static PyObject *__pyx_pw_9csamtools_11AlignedRead_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
21350   PyObject *__pyx_r = 0;
21351   __Pyx_RefNannyDeclarations
21352   __Pyx_RefNannySetupContext("compare (wrapper)", 0);
21353   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_9csamtools_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21354   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_6compare(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_other));
21355   goto __pyx_L0;
21356   __pyx_L1_error:;
21357   __pyx_r = NULL;
21358   __pyx_L0:;
21359   __Pyx_RefNannyFinishContext();
21360   return __pyx_r;
21361 }
21362
21363 /* "csamtools.pyx":2168
21364  *                                    self.tags )))
21365  * 
21366  *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
21367  *         '''return -1,0,1, if contents in this are binary <,=,> to *other*'''
21368  * 
21369  */
21370
21371 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6compare(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_other) {
21372   int __pyx_v_retval;
21373   bam1_t *__pyx_v_t;
21374   bam1_t *__pyx_v_o;
21375   PyObject *__pyx_r = NULL;
21376   __Pyx_RefNannyDeclarations
21377   int __pyx_t_1;
21378   PyObject *__pyx_t_2 = NULL;
21379   int __pyx_lineno = 0;
21380   const char *__pyx_filename = NULL;
21381   int __pyx_clineno = 0;
21382   __Pyx_TraceDeclarations
21383   __Pyx_RefNannySetupContext("compare", 0);
21384   __Pyx_TraceCall("compare", __pyx_f[0], 2168);
21385
21386   /* "csamtools.pyx":2174
21387  *         cdef bam1_t *t, *o
21388  * 
21389  *         t = self._delegate             # <<<<<<<<<<<<<<
21390  *         o = other._delegate
21391  * 
21392  */
21393   __pyx_v_t = __pyx_v_self->_delegate;
21394
21395   /* "csamtools.pyx":2175
21396  * 
21397  *         t = self._delegate
21398  *         o = other._delegate             # <<<<<<<<<<<<<<
21399  * 
21400  *         # uncomment for debugging purposes
21401  */
21402   __pyx_v_o = __pyx_v_other->_delegate;
21403
21404   /* "csamtools.pyx":2187
21405  * 
21406  *         # Fast-path test for object identity
21407  *         if t==o:             # <<<<<<<<<<<<<<
21408  *             return 0
21409  * 
21410  */
21411   __pyx_t_1 = (__pyx_v_t == __pyx_v_o);
21412   if (__pyx_t_1) {
21413
21414     /* "csamtools.pyx":2188
21415  *         # Fast-path test for object identity
21416  *         if t==o:
21417  *             return 0             # <<<<<<<<<<<<<<
21418  * 
21419  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
21420  */
21421     __Pyx_XDECREF(__pyx_r);
21422     __Pyx_INCREF(__pyx_int_0);
21423     __pyx_r = __pyx_int_0;
21424     goto __pyx_L0;
21425     goto __pyx_L3;
21426   }
21427   __pyx_L3:;
21428
21429   /* "csamtools.pyx":2190
21430  *             return 0
21431  * 
21432  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
21433  * 
21434  *         if retval: return retval
21435  */
21436   __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));
21437
21438   /* "csamtools.pyx":2192
21439  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
21440  * 
21441  *         if retval: return retval             # <<<<<<<<<<<<<<
21442  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)
21443  *         if retval: return retval
21444  */
21445   if (__pyx_v_retval) {
21446     __Pyx_XDECREF(__pyx_r);
21447     __pyx_t_2 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21448     __Pyx_GOTREF(__pyx_t_2);
21449     __pyx_r = __pyx_t_2;
21450     __pyx_t_2 = 0;
21451     goto __pyx_L0;
21452     goto __pyx_L4;
21453   }
21454   __pyx_L4:;
21455
21456   /* "csamtools.pyx":2193
21457  * 
21458  *         if retval: return retval
21459  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)             # <<<<<<<<<<<<<<
21460  *         if retval: return retval
21461  *         return memcmp(t.data, o.data, t.data_len)
21462  */
21463   __pyx_v_retval = ((__pyx_v_t->data_len > __pyx_v_o->data_len) - (__pyx_v_t->data_len < __pyx_v_o->data_len));
21464
21465   /* "csamtools.pyx":2194
21466  *         if retval: return retval
21467  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)
21468  *         if retval: return retval             # <<<<<<<<<<<<<<
21469  *         return memcmp(t.data, o.data, t.data_len)
21470  * 
21471  */
21472   if (__pyx_v_retval) {
21473     __Pyx_XDECREF(__pyx_r);
21474     __pyx_t_2 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21475     __Pyx_GOTREF(__pyx_t_2);
21476     __pyx_r = __pyx_t_2;
21477     __pyx_t_2 = 0;
21478     goto __pyx_L0;
21479     goto __pyx_L5;
21480   }
21481   __pyx_L5:;
21482
21483   /* "csamtools.pyx":2195
21484  *         retval = (t.data_len > o.data_len) - (t.data_len < o.data_len) # cmp(t.data_len, o.data_len)
21485  *         if retval: return retval
21486  *         return memcmp(t.data, o.data, t.data_len)             # <<<<<<<<<<<<<<
21487  * 
21488  *     # Disabled so long as __cmp__ is a special method
21489  */
21490   __Pyx_XDECREF(__pyx_r);
21491   __pyx_t_2 = PyInt_FromLong(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->data_len)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21492   __Pyx_GOTREF(__pyx_t_2);
21493   __pyx_r = __pyx_t_2;
21494   __pyx_t_2 = 0;
21495   goto __pyx_L0;
21496
21497   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21498   goto __pyx_L0;
21499   __pyx_L1_error:;
21500   __Pyx_XDECREF(__pyx_t_2);
21501   __Pyx_AddTraceback("csamtools.AlignedRead.compare", __pyx_clineno, __pyx_lineno, __pyx_filename);
21502   __pyx_r = NULL;
21503   __pyx_L0:;
21504   __Pyx_XGIVEREF(__pyx_r);
21505   __Pyx_TraceReturn(__pyx_r);
21506   __Pyx_RefNannyFinishContext();
21507   return __pyx_r;
21508 }
21509
21510 /* Python wrapper */
21511 static Py_hash_t __pyx_pw_9csamtools_11AlignedRead_9__hash__(PyObject *__pyx_v_self); /*proto*/
21512 static Py_hash_t __pyx_pw_9csamtools_11AlignedRead_9__hash__(PyObject *__pyx_v_self) {
21513   Py_hash_t __pyx_r;
21514   __Pyx_RefNannyDeclarations
21515   __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
21516   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_8__hash__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
21517   __Pyx_RefNannyFinishContext();
21518   return __pyx_r;
21519 }
21520
21521 /* "csamtools.pyx":2198
21522  * 
21523  *     # Disabled so long as __cmp__ is a special method
21524  *     def __hash__(self):             # <<<<<<<<<<<<<<
21525  *         return _Py_HashPointer(<void *>self)
21526  * 
21527  */
21528
21529 static Py_hash_t __pyx_pf_9csamtools_11AlignedRead_8__hash__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
21530   Py_hash_t __pyx_r;
21531   __Pyx_RefNannyDeclarations
21532   __Pyx_TraceDeclarations
21533   __Pyx_RefNannySetupContext("__hash__", 0);
21534   __Pyx_TraceCall("__hash__", __pyx_f[0], 2198);
21535
21536   /* "csamtools.pyx":2199
21537  *     # Disabled so long as __cmp__ is a special method
21538  *     def __hash__(self):
21539  *         return _Py_HashPointer(<void *>self)             # <<<<<<<<<<<<<<
21540  * 
21541  *     property qname:
21542  */
21543   __pyx_r = _Py_HashPointer(((void *)__pyx_v_self));
21544   goto __pyx_L0;
21545
21546   __pyx_r = 0;
21547   __pyx_L0:;
21548   if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
21549   __Pyx_TraceReturn(Py_None);
21550   __Pyx_RefNannyFinishContext();
21551   return __pyx_r;
21552 }
21553
21554 /* Python wrapper */
21555 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/
21556 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5qname_1__get__(PyObject *__pyx_v_self) {
21557   PyObject *__pyx_r = 0;
21558   __Pyx_RefNannyDeclarations
21559   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
21560   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5qname___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
21561   __Pyx_RefNannyFinishContext();
21562   return __pyx_r;
21563 }
21564
21565 /* "csamtools.pyx":2203
21566  *     property qname:
21567  *         """the query name (None if not present)"""
21568  *         def __get__(self):             # <<<<<<<<<<<<<<
21569  *             cdef bam1_t * src
21570  *             src = self._delegate
21571  */
21572
21573 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qname___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
21574   bam1_t *__pyx_v_src;
21575   PyObject *__pyx_r = NULL;
21576   __Pyx_RefNannyDeclarations
21577   int __pyx_t_1;
21578   PyObject *__pyx_t_2 = NULL;
21579   int __pyx_lineno = 0;
21580   const char *__pyx_filename = NULL;
21581   int __pyx_clineno = 0;
21582   __Pyx_TraceDeclarations
21583   __Pyx_RefNannySetupContext("__get__", 0);
21584   __Pyx_TraceCall("__get__", __pyx_f[0], 2203);
21585
21586   /* "csamtools.pyx":2205
21587  *         def __get__(self):
21588  *             cdef bam1_t * src
21589  *             src = self._delegate             # <<<<<<<<<<<<<<
21590  *             if src.core.l_qname == 0: return None
21591  *             return _charptr_to_str(<char *>bam1_qname( src ))
21592  */
21593   __pyx_v_src = __pyx_v_self->_delegate;
21594
21595   /* "csamtools.pyx":2206
21596  *             cdef bam1_t * src
21597  *             src = self._delegate
21598  *             if src.core.l_qname == 0: return None             # <<<<<<<<<<<<<<
21599  *             return _charptr_to_str(<char *>bam1_qname( src ))
21600  * 
21601  */
21602   __pyx_t_1 = (__pyx_v_src->core.l_qname == 0);
21603   if (__pyx_t_1) {
21604     __Pyx_XDECREF(__pyx_r);
21605     __Pyx_INCREF(Py_None);
21606     __pyx_r = Py_None;
21607     goto __pyx_L0;
21608     goto __pyx_L3;
21609   }
21610   __pyx_L3:;
21611
21612   /* "csamtools.pyx":2207
21613  *             src = self._delegate
21614  *             if src.core.l_qname == 0: return None
21615  *             return _charptr_to_str(<char *>bam1_qname( src ))             # <<<<<<<<<<<<<<
21616  * 
21617  *         def __set__(self, qname ):
21618  */
21619   __Pyx_XDECREF(__pyx_r);
21620   __pyx_t_2 = __pyx_f_9csamtools__charptr_to_str(((char *)bam1_qname(__pyx_v_src))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21621   __Pyx_GOTREF(__pyx_t_2);
21622   __pyx_r = __pyx_t_2;
21623   __pyx_t_2 = 0;
21624   goto __pyx_L0;
21625
21626   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21627   goto __pyx_L0;
21628   __pyx_L1_error:;
21629   __Pyx_XDECREF(__pyx_t_2);
21630   __Pyx_AddTraceback("csamtools.AlignedRead.qname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
21631   __pyx_r = NULL;
21632   __pyx_L0:;
21633   __Pyx_XGIVEREF(__pyx_r);
21634   __Pyx_TraceReturn(__pyx_r);
21635   __Pyx_RefNannyFinishContext();
21636   return __pyx_r;
21637 }
21638
21639 /* Python wrapper */
21640 static int __pyx_pw_9csamtools_11AlignedRead_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
21641 static int __pyx_pw_9csamtools_11AlignedRead_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
21642   int __pyx_r;
21643   __Pyx_RefNannyDeclarations
21644   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
21645   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5qname_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qname));
21646   __Pyx_RefNannyFinishContext();
21647   return __pyx_r;
21648 }
21649
21650 /* "csamtools.pyx":2209
21651  *             return _charptr_to_str(<char *>bam1_qname( src ))
21652  * 
21653  *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
21654  *             if qname == None or len(qname) == 0: return
21655  *             qname = _force_bytes(qname)
21656  */
21657
21658 static int __pyx_pf_9csamtools_11AlignedRead_5qname_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qname) {
21659   bam1_t *__pyx_v_src;
21660   int __pyx_v_l;
21661   char *__pyx_v_p;
21662   int __pyx_r;
21663   __Pyx_RefNannyDeclarations
21664   PyObject *__pyx_t_1 = NULL;
21665   int __pyx_t_2;
21666   Py_ssize_t __pyx_t_3;
21667   int __pyx_t_4;
21668   int __pyx_t_5;
21669   char *__pyx_t_6;
21670   int __pyx_lineno = 0;
21671   const char *__pyx_filename = NULL;
21672   int __pyx_clineno = 0;
21673   __Pyx_TraceDeclarations
21674   __Pyx_RefNannySetupContext("__set__", 0);
21675   __Pyx_TraceCall("__set__", __pyx_f[0], 2209);
21676   __Pyx_INCREF(__pyx_v_qname);
21677
21678   /* "csamtools.pyx":2210
21679  * 
21680  *         def __set__(self, qname ):
21681  *             if qname == None or len(qname) == 0: return             # <<<<<<<<<<<<<<
21682  *             qname = _force_bytes(qname)
21683  *             cdef bam1_t * src
21684  */
21685   __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21686   __Pyx_GOTREF(__pyx_t_1);
21687   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21688   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21689   if (!__pyx_t_2) {
21690     __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21691     __pyx_t_4 = (__pyx_t_3 == 0);
21692     __pyx_t_5 = __pyx_t_4;
21693   } else {
21694     __pyx_t_5 = __pyx_t_2;
21695   }
21696   if (__pyx_t_5) {
21697     __pyx_r = 0;
21698     goto __pyx_L0;
21699     goto __pyx_L3;
21700   }
21701   __pyx_L3:;
21702
21703   /* "csamtools.pyx":2211
21704  *         def __set__(self, qname ):
21705  *             if qname == None or len(qname) == 0: return
21706  *             qname = _force_bytes(qname)             # <<<<<<<<<<<<<<
21707  *             cdef bam1_t * src
21708  *             cdef int l
21709  */
21710   __pyx_t_1 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_qname)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21711   __Pyx_GOTREF(__pyx_t_1);
21712   __Pyx_DECREF(__pyx_v_qname);
21713   __pyx_v_qname = __pyx_t_1;
21714   __pyx_t_1 = 0;
21715
21716   /* "csamtools.pyx":2216
21717  *             cdef char * p
21718  * 
21719  *             src = self._delegate             # <<<<<<<<<<<<<<
21720  *             p = bam1_qname( src )
21721  * 
21722  */
21723   __pyx_v_src = __pyx_v_self->_delegate;
21724
21725   /* "csamtools.pyx":2217
21726  * 
21727  *             src = self._delegate
21728  *             p = bam1_qname( src )             # <<<<<<<<<<<<<<
21729  * 
21730  *             # the qname is \0 terminated
21731  */
21732   __pyx_v_p = bam1_qname(__pyx_v_src);
21733
21734   /* "csamtools.pyx":2220
21735  * 
21736  *             # the qname is \0 terminated
21737  *             l = len(qname) + 1             # <<<<<<<<<<<<<<
21738  *             pysam_bam_update( src,
21739  *                               src.core.l_qname,
21740  */
21741   __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21742   __pyx_v_l = (__pyx_t_3 + 1);
21743
21744   /* "csamtools.pyx":2224
21745  *                               src.core.l_qname,
21746  *                               l,
21747  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
21748  * 
21749  *             src.core.l_qname = l
21750  */
21751   pysam_bam_update(__pyx_v_src, __pyx_v_src->core.l_qname, __pyx_v_l, ((uint8_t *)__pyx_v_p));
21752
21753   /* "csamtools.pyx":2226
21754  *                               <uint8_t*>p )
21755  * 
21756  *             src.core.l_qname = l             # <<<<<<<<<<<<<<
21757  * 
21758  *             # re-acquire pointer to location in memory
21759  */
21760   __pyx_v_src->core.l_qname = __pyx_v_l;
21761
21762   /* "csamtools.pyx":2230
21763  *             # re-acquire pointer to location in memory
21764  *             # as it might have moved
21765  *             p = bam1_qname(src)             # <<<<<<<<<<<<<<
21766  * 
21767  *             strncpy( p, qname, l )
21768  */
21769   __pyx_v_p = bam1_qname(__pyx_v_src);
21770
21771   /* "csamtools.pyx":2232
21772  *             p = bam1_qname(src)
21773  * 
21774  *             strncpy( p, qname, l )             # <<<<<<<<<<<<<<
21775  * 
21776  *     property cigar:
21777  */
21778   __pyx_t_6 = PyBytes_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21779   strncpy(__pyx_v_p, __pyx_t_6, __pyx_v_l);
21780
21781   __pyx_r = 0;
21782   goto __pyx_L0;
21783   __pyx_L1_error:;
21784   __Pyx_XDECREF(__pyx_t_1);
21785   __Pyx_AddTraceback("csamtools.AlignedRead.qname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
21786   __pyx_r = -1;
21787   __pyx_L0:;
21788   __Pyx_XDECREF(__pyx_v_qname);
21789   __Pyx_TraceReturn(Py_None);
21790   __Pyx_RefNannyFinishContext();
21791   return __pyx_r;
21792 }
21793
21794 /* Python wrapper */
21795 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/
21796 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5cigar_1__get__(PyObject *__pyx_v_self) {
21797   PyObject *__pyx_r = 0;
21798   __Pyx_RefNannyDeclarations
21799   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
21800   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5cigar___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
21801   __Pyx_RefNannyFinishContext();
21802   return __pyx_r;
21803 }
21804
21805 /* "csamtools.pyx":2259
21806  * 
21807  *         """
21808  *         def __get__(self):             # <<<<<<<<<<<<<<
21809  *             cdef uint32_t * cigar_p
21810  *             cdef bam1_t * src
21811  */
21812
21813 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5cigar___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
21814   uint32_t *__pyx_v_cigar_p;
21815   bam1_t *__pyx_v_src;
21816   PyObject *__pyx_v_op = 0;
21817   PyObject *__pyx_v_l = 0;
21818   PyObject *__pyx_v_cigar = 0;
21819   int __pyx_v_k;
21820   PyObject *__pyx_r = NULL;
21821   __Pyx_RefNannyDeclarations
21822   int __pyx_t_1;
21823   PyObject *__pyx_t_2 = NULL;
21824   uint32_t __pyx_t_3;
21825   PyObject *__pyx_t_4 = NULL;
21826   int __pyx_lineno = 0;
21827   const char *__pyx_filename = NULL;
21828   int __pyx_clineno = 0;
21829   __Pyx_TraceDeclarations
21830   __Pyx_RefNannySetupContext("__get__", 0);
21831   __Pyx_TraceCall("__get__", __pyx_f[0], 2259);
21832
21833   /* "csamtools.pyx":2265
21834  *             cdef int k
21835  * 
21836  *             src = self._delegate             # <<<<<<<<<<<<<<
21837  *             if src.core.n_cigar == 0: return None
21838  * 
21839  */
21840   __pyx_v_src = __pyx_v_self->_delegate;
21841
21842   /* "csamtools.pyx":2266
21843  * 
21844  *             src = self._delegate
21845  *             if src.core.n_cigar == 0: return None             # <<<<<<<<<<<<<<
21846  * 
21847  *             cigar = []
21848  */
21849   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
21850   if (__pyx_t_1) {
21851     __Pyx_XDECREF(__pyx_r);
21852     __Pyx_INCREF(Py_None);
21853     __pyx_r = Py_None;
21854     goto __pyx_L0;
21855     goto __pyx_L3;
21856   }
21857   __pyx_L3:;
21858
21859   /* "csamtools.pyx":2268
21860  *             if src.core.n_cigar == 0: return None
21861  * 
21862  *             cigar = []             # <<<<<<<<<<<<<<
21863  *             cigar_p = bam1_cigar(src);
21864  *             for k from 0 <= k < src.core.n_cigar:
21865  */
21866   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21867   __Pyx_GOTREF(__pyx_t_2);
21868   __pyx_v_cigar = ((PyObject *)__pyx_t_2);
21869   __pyx_t_2 = 0;
21870
21871   /* "csamtools.pyx":2269
21872  * 
21873  *             cigar = []
21874  *             cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
21875  *             for k from 0 <= k < src.core.n_cigar:
21876  *                 op = cigar_p[k] & BAM_CIGAR_MASK
21877  */
21878   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
21879
21880   /* "csamtools.pyx":2270
21881  *             cigar = []
21882  *             cigar_p = bam1_cigar(src);
21883  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
21884  *                 op = cigar_p[k] & BAM_CIGAR_MASK
21885  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
21886  */
21887   __pyx_t_3 = __pyx_v_src->core.n_cigar;
21888   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
21889
21890     /* "csamtools.pyx":2271
21891  *             cigar_p = bam1_cigar(src);
21892  *             for k from 0 <= k < src.core.n_cigar:
21893  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
21894  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
21895  *                 cigar.append((op, l))
21896  */
21897     __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) & 15)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21898     __Pyx_GOTREF(__pyx_t_2);
21899     __Pyx_XDECREF(__pyx_v_op);
21900     __pyx_v_op = __pyx_t_2;
21901     __pyx_t_2 = 0;
21902
21903     /* "csamtools.pyx":2272
21904  *             for k from 0 <= k < src.core.n_cigar:
21905  *                 op = cigar_p[k] & BAM_CIGAR_MASK
21906  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
21907  *                 cigar.append((op, l))
21908  *             return cigar
21909  */
21910     __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21911     __Pyx_GOTREF(__pyx_t_2);
21912     __Pyx_XDECREF(__pyx_v_l);
21913     __pyx_v_l = __pyx_t_2;
21914     __pyx_t_2 = 0;
21915
21916     /* "csamtools.pyx":2273
21917  *                 op = cigar_p[k] & BAM_CIGAR_MASK
21918  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
21919  *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
21920  *             return cigar
21921  * 
21922  */
21923     __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21924     __Pyx_GOTREF(__pyx_t_2);
21925     __Pyx_INCREF(__pyx_v_op);
21926     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_op);
21927     __Pyx_GIVEREF(__pyx_v_op);
21928     __Pyx_INCREF(__pyx_v_l);
21929     PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_l);
21930     __Pyx_GIVEREF(__pyx_v_l);
21931     __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_cigar, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21932     __Pyx_GOTREF(__pyx_t_4);
21933     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
21934     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
21935   }
21936
21937   /* "csamtools.pyx":2274
21938  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
21939  *                 cigar.append((op, l))
21940  *             return cigar             # <<<<<<<<<<<<<<
21941  * 
21942  *         def __set__(self, values ):
21943  */
21944   __Pyx_XDECREF(__pyx_r);
21945   __Pyx_INCREF(__pyx_v_cigar);
21946   __pyx_r = __pyx_v_cigar;
21947   goto __pyx_L0;
21948
21949   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21950   goto __pyx_L0;
21951   __pyx_L1_error:;
21952   __Pyx_XDECREF(__pyx_t_2);
21953   __Pyx_XDECREF(__pyx_t_4);
21954   __Pyx_AddTraceback("csamtools.AlignedRead.cigar.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
21955   __pyx_r = NULL;
21956   __pyx_L0:;
21957   __Pyx_XDECREF(__pyx_v_op);
21958   __Pyx_XDECREF(__pyx_v_l);
21959   __Pyx_XDECREF(__pyx_v_cigar);
21960   __Pyx_XGIVEREF(__pyx_r);
21961   __Pyx_TraceReturn(__pyx_r);
21962   __Pyx_RefNannyFinishContext();
21963   return __pyx_r;
21964 }
21965
21966 /* Python wrapper */
21967 static int __pyx_pw_9csamtools_11AlignedRead_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
21968 static int __pyx_pw_9csamtools_11AlignedRead_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
21969   int __pyx_r;
21970   __Pyx_RefNannyDeclarations
21971   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
21972   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5cigar_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_values));
21973   __Pyx_RefNannyFinishContext();
21974   return __pyx_r;
21975 }
21976
21977 /* "csamtools.pyx":2276
21978  *             return cigar
21979  * 
21980  *         def __set__(self, values ):             # <<<<<<<<<<<<<<
21981  *             if values == None or len(values) == 0: return
21982  *             cdef uint32_t * p
21983  */
21984
21985 static int __pyx_pf_9csamtools_11AlignedRead_5cigar_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_values) {
21986   uint32_t *__pyx_v_p;
21987   bam1_t *__pyx_v_src;
21988   PyObject *__pyx_v_op = 0;
21989   PyObject *__pyx_v_l = 0;
21990   int __pyx_v_k;
21991   int __pyx_r;
21992   __Pyx_RefNannyDeclarations
21993   PyObject *__pyx_t_1 = NULL;
21994   int __pyx_t_2;
21995   Py_ssize_t __pyx_t_3;
21996   int __pyx_t_4;
21997   int __pyx_t_5;
21998   PyObject *(*__pyx_t_6)(PyObject *);
21999   PyObject *__pyx_t_7 = NULL;
22000   PyObject *__pyx_t_8 = NULL;
22001   PyObject *__pyx_t_9 = NULL;
22002   PyObject *__pyx_t_10 = NULL;
22003   PyObject *(*__pyx_t_11)(PyObject *);
22004   uint32_t __pyx_t_12;
22005   int __pyx_lineno = 0;
22006   const char *__pyx_filename = NULL;
22007   int __pyx_clineno = 0;
22008   __Pyx_TraceDeclarations
22009   __Pyx_RefNannySetupContext("__set__", 0);
22010   __Pyx_TraceCall("__set__", __pyx_f[0], 2276);
22011
22012   /* "csamtools.pyx":2277
22013  * 
22014  *         def __set__(self, values ):
22015  *             if values == None or len(values) == 0: return             # <<<<<<<<<<<<<<
22016  *             cdef uint32_t * p
22017  *             cdef bam1_t * src
22018  */
22019   __pyx_t_1 = PyObject_RichCompare(__pyx_v_values, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22020   __Pyx_GOTREF(__pyx_t_1);
22021   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22022   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22023   if (!__pyx_t_2) {
22024     __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22025     __pyx_t_4 = (__pyx_t_3 == 0);
22026     __pyx_t_5 = __pyx_t_4;
22027   } else {
22028     __pyx_t_5 = __pyx_t_2;
22029   }
22030   if (__pyx_t_5) {
22031     __pyx_r = 0;
22032     goto __pyx_L0;
22033     goto __pyx_L3;
22034   }
22035   __pyx_L3:;
22036
22037   /* "csamtools.pyx":2283
22038  *             cdef int k
22039  * 
22040  *             k = 0             # <<<<<<<<<<<<<<
22041  * 
22042  *             src = self._delegate
22043  */
22044   __pyx_v_k = 0;
22045
22046   /* "csamtools.pyx":2285
22047  *             k = 0
22048  * 
22049  *             src = self._delegate             # <<<<<<<<<<<<<<
22050  * 
22051  *             # get location of cigar string
22052  */
22053   __pyx_v_src = __pyx_v_self->_delegate;
22054
22055   /* "csamtools.pyx":2288
22056  * 
22057  *             # get location of cigar string
22058  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
22059  * 
22060  *             # create space for cigar data within src.data
22061  */
22062   __pyx_v_p = bam1_cigar(__pyx_v_src);
22063
22064   /* "csamtools.pyx":2293
22065  *             pysam_bam_update( src,
22066  *                               src.core.n_cigar * 4,
22067  *                               len(values) * 4,             # <<<<<<<<<<<<<<
22068  *                               <uint8_t*>p )
22069  * 
22070  */
22071   __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22072
22073   /* "csamtools.pyx":2294
22074  *                               src.core.n_cigar * 4,
22075  *                               len(values) * 4,
22076  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
22077  * 
22078  *             # length is number of cigar operations, not bytes
22079  */
22080   pysam_bam_update(__pyx_v_src, (__pyx_v_src->core.n_cigar * 4), (__pyx_t_3 * 4), ((uint8_t *)__pyx_v_p));
22081
22082   /* "csamtools.pyx":2297
22083  * 
22084  *             # length is number of cigar operations, not bytes
22085  *             src.core.n_cigar = len(values)             # <<<<<<<<<<<<<<
22086  * 
22087  *             # re-acquire pointer to location in memory
22088  */
22089   __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22090   __pyx_v_src->core.n_cigar = __pyx_t_3;
22091
22092   /* "csamtools.pyx":2301
22093  *             # re-acquire pointer to location in memory
22094  *             # as it might have moved
22095  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
22096  * 
22097  *             # insert cigar operations
22098  */
22099   __pyx_v_p = bam1_cigar(__pyx_v_src);
22100
22101   /* "csamtools.pyx":2304
22102  * 
22103  *             # insert cigar operations
22104  *             for op, l in values:             # <<<<<<<<<<<<<<
22105  *                 p[k] = l << BAM_CIGAR_SHIFT | op
22106  *                 k += 1
22107  */
22108   if (PyList_CheckExact(__pyx_v_values) || PyTuple_CheckExact(__pyx_v_values)) {
22109     __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
22110     __pyx_t_6 = NULL;
22111   } else {
22112     __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22113     __Pyx_GOTREF(__pyx_t_1);
22114     __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
22115   }
22116   for (;;) {
22117     if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) {
22118       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
22119       __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++;
22120     } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) {
22121       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
22122       __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3++;
22123     } else {
22124       __pyx_t_7 = __pyx_t_6(__pyx_t_1);
22125       if (unlikely(!__pyx_t_7)) {
22126         if (PyErr_Occurred()) {
22127           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
22128           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22129         }
22130         break;
22131       }
22132       __Pyx_GOTREF(__pyx_t_7);
22133     }
22134     if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
22135       PyObject* sequence = __pyx_t_7;
22136       if (likely(PyTuple_CheckExact(sequence))) {
22137         if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
22138           if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22139           else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
22140           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22141         }
22142         __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
22143         __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
22144       } else {
22145         if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
22146           if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22147           else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
22148           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22149         }
22150         __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
22151         __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
22152       }
22153       __Pyx_INCREF(__pyx_t_8);
22154       __Pyx_INCREF(__pyx_t_9);
22155       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
22156     } else {
22157       Py_ssize_t index = -1;
22158       __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22159       __Pyx_GOTREF(__pyx_t_10);
22160       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
22161       __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
22162       index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
22163       __Pyx_GOTREF(__pyx_t_8);
22164       index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
22165       __Pyx_GOTREF(__pyx_t_9);
22166       if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22167       __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
22168       goto __pyx_L7_unpacking_done;
22169       __pyx_L6_unpacking_failed:;
22170       __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
22171       if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
22172       if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
22173       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22174       __pyx_L7_unpacking_done:;
22175     }
22176     __Pyx_XDECREF(__pyx_v_op);
22177     __pyx_v_op = __pyx_t_8;
22178     __pyx_t_8 = 0;
22179     __Pyx_XDECREF(__pyx_v_l);
22180     __pyx_v_l = __pyx_t_9;
22181     __pyx_t_9 = 0;
22182
22183     /* "csamtools.pyx":2305
22184  *             # insert cigar operations
22185  *             for op, l in values:
22186  *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
22187  *                 k += 1
22188  * 
22189  */
22190     __pyx_t_7 = PyNumber_Lshift(__pyx_v_l, __pyx_int_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22191     __Pyx_GOTREF(__pyx_t_7);
22192     __pyx_t_9 = PyNumber_Or(__pyx_t_7, __pyx_v_op); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22193     __Pyx_GOTREF(__pyx_t_9);
22194     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
22195     __pyx_t_12 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22196     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
22197     (__pyx_v_p[__pyx_v_k]) = __pyx_t_12;
22198
22199     /* "csamtools.pyx":2306
22200  *             for op, l in values:
22201  *                 p[k] = l << BAM_CIGAR_SHIFT | op
22202  *                 k += 1             # <<<<<<<<<<<<<<
22203  * 
22204  *             ## setting the cigar string also updates the "bin" attribute
22205  */
22206     __pyx_v_k = (__pyx_v_k + 1);
22207   }
22208   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22209
22210   /* "csamtools.pyx":2309
22211  * 
22212  *             ## setting the cigar string also updates the "bin" attribute
22213  *             src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, p))             # <<<<<<<<<<<<<<
22214  * 
22215  *     property cigarstring:
22216  */
22217   __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), __pyx_v_p));
22218
22219   __pyx_r = 0;
22220   goto __pyx_L0;
22221   __pyx_L1_error:;
22222   __Pyx_XDECREF(__pyx_t_1);
22223   __Pyx_XDECREF(__pyx_t_7);
22224   __Pyx_XDECREF(__pyx_t_8);
22225   __Pyx_XDECREF(__pyx_t_9);
22226   __Pyx_XDECREF(__pyx_t_10);
22227   __Pyx_AddTraceback("csamtools.AlignedRead.cigar.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
22228   __pyx_r = -1;
22229   __pyx_L0:;
22230   __Pyx_XDECREF(__pyx_v_op);
22231   __Pyx_XDECREF(__pyx_v_l);
22232   __Pyx_TraceReturn(Py_None);
22233   __Pyx_RefNannyFinishContext();
22234   return __pyx_r;
22235 }
22236
22237 /* Python wrapper */
22238 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/
22239 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11cigarstring_1__get__(PyObject *__pyx_v_self) {
22240   PyObject *__pyx_r = 0;
22241   __Pyx_RefNannyDeclarations
22242   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
22243   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_11cigarstring___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
22244   __Pyx_RefNannyFinishContext();
22245   return __pyx_r;
22246 }
22247
22248 /* "csamtools.pyx":2316
22249  *         Returns the empty string if not present.
22250  *         '''
22251  *         def __get__(self):             # <<<<<<<<<<<<<<
22252  *             c = self.cigar
22253  *             if c == None: return ""
22254  */
22255
22256 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11cigarstring___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
22257   PyObject *__pyx_v_c = NULL;
22258   PyObject *__pyx_v_x = NULL;
22259   PyObject *__pyx_v_y = NULL;
22260   PyObject *__pyx_r = NULL;
22261   __Pyx_RefNannyDeclarations
22262   PyObject *__pyx_t_1 = NULL;
22263   int __pyx_t_2;
22264   PyObject *__pyx_t_3 = NULL;
22265   PyObject *__pyx_t_4 = NULL;
22266   Py_ssize_t __pyx_t_5;
22267   PyObject *(*__pyx_t_6)(PyObject *);
22268   PyObject *__pyx_t_7 = NULL;
22269   PyObject *__pyx_t_8 = NULL;
22270   PyObject *__pyx_t_9 = NULL;
22271   PyObject *__pyx_t_10 = NULL;
22272   PyObject *(*__pyx_t_11)(PyObject *);
22273   Py_ssize_t __pyx_t_12;
22274   int __pyx_lineno = 0;
22275   const char *__pyx_filename = NULL;
22276   int __pyx_clineno = 0;
22277   __Pyx_TraceDeclarations
22278   __Pyx_RefNannySetupContext("__get__", 0);
22279   __Pyx_TraceCall("__get__", __pyx_f[0], 2316);
22280
22281   /* "csamtools.pyx":2317
22282  *         '''
22283  *         def __get__(self):
22284  *             c = self.cigar             # <<<<<<<<<<<<<<
22285  *             if c == None: return ""
22286  *             else: return "".join([ "%c%i" % (CODE2CIGAR[x],y) for x,y in c])
22287  */
22288   __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 = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22289   __Pyx_GOTREF(__pyx_t_1);
22290   __pyx_v_c = __pyx_t_1;
22291   __pyx_t_1 = 0;
22292
22293   /* "csamtools.pyx":2318
22294  *         def __get__(self):
22295  *             c = self.cigar
22296  *             if c == None: return ""             # <<<<<<<<<<<<<<
22297  *             else: return "".join([ "%c%i" % (CODE2CIGAR[x],y) for x,y in c])
22298  * 
22299  */
22300   __pyx_t_1 = PyObject_RichCompare(__pyx_v_c, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22301   __Pyx_GOTREF(__pyx_t_1);
22302   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22303   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22304   if (__pyx_t_2) {
22305     __Pyx_XDECREF(__pyx_r);
22306     __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
22307     __pyx_r = ((PyObject *)__pyx_kp_s_16);
22308     goto __pyx_L0;
22309     goto __pyx_L3;
22310   }
22311   /*else*/ {
22312
22313     /* "csamtools.pyx":2319
22314  *             c = self.cigar
22315  *             if c == None: return ""
22316  *             else: return "".join([ "%c%i" % (CODE2CIGAR[x],y) for x,y in c])             # <<<<<<<<<<<<<<
22317  * 
22318  *         def __set__(self, cigar):
22319  */
22320     __Pyx_XDECREF(__pyx_r);
22321     __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 = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22322     __Pyx_GOTREF(__pyx_t_1);
22323     __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22324     __Pyx_GOTREF(__pyx_t_3);
22325     if (PyList_CheckExact(__pyx_v_c) || PyTuple_CheckExact(__pyx_v_c)) {
22326       __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
22327       __pyx_t_6 = NULL;
22328     } else {
22329       __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22330       __Pyx_GOTREF(__pyx_t_4);
22331       __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext;
22332     }
22333     for (;;) {
22334       if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_4)) {
22335         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
22336         __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++;
22337       } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_4)) {
22338         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
22339         __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++;
22340       } else {
22341         __pyx_t_7 = __pyx_t_6(__pyx_t_4);
22342         if (unlikely(!__pyx_t_7)) {
22343           if (PyErr_Occurred()) {
22344             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
22345             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22346           }
22347           break;
22348         }
22349         __Pyx_GOTREF(__pyx_t_7);
22350       }
22351       if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
22352         PyObject* sequence = __pyx_t_7;
22353         if (likely(PyTuple_CheckExact(sequence))) {
22354           if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
22355             if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22356             else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
22357             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22358           }
22359           __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
22360           __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
22361         } else {
22362           if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
22363             if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22364             else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
22365             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22366           }
22367           __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
22368           __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
22369         }
22370         __Pyx_INCREF(__pyx_t_8);
22371         __Pyx_INCREF(__pyx_t_9);
22372         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
22373       } else {
22374         Py_ssize_t index = -1;
22375         __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22376         __Pyx_GOTREF(__pyx_t_10);
22377         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
22378         __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
22379         index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
22380         __Pyx_GOTREF(__pyx_t_8);
22381         index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
22382         __Pyx_GOTREF(__pyx_t_9);
22383         if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22384         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
22385         goto __pyx_L7_unpacking_done;
22386         __pyx_L6_unpacking_failed:;
22387         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
22388         if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
22389         if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
22390         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22391         __pyx_L7_unpacking_done:;
22392       }
22393       __Pyx_XDECREF(__pyx_v_x);
22394       __pyx_v_x = __pyx_t_8;
22395       __pyx_t_8 = 0;
22396       __Pyx_XDECREF(__pyx_v_y);
22397       __pyx_v_y = __pyx_t_9;
22398       __pyx_t_9 = 0;
22399       __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 = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22400       __pyx_t_7 = PyInt_FromLong((__pyx_v_9csamtools_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22401       __Pyx_GOTREF(__pyx_t_7);
22402       __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22403       __Pyx_GOTREF(__pyx_t_9);
22404       PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
22405       __Pyx_GIVEREF(__pyx_t_7);
22406       __Pyx_INCREF(__pyx_v_y);
22407       PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_y);
22408       __Pyx_GIVEREF(__pyx_v_y);
22409       __pyx_t_7 = 0;
22410       __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_135), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22411       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
22412       __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
22413       if (unlikely(PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22414       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
22415     }
22416     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
22417     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22418     __Pyx_GOTREF(__pyx_t_4);
22419     __Pyx_INCREF(((PyObject *)__pyx_t_3));
22420     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
22421     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
22422     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
22423     __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 = 2319; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22424     __Pyx_GOTREF(__pyx_t_3);
22425     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22426     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
22427     __pyx_r = __pyx_t_3;
22428     __pyx_t_3 = 0;
22429     goto __pyx_L0;
22430   }
22431   __pyx_L3:;
22432
22433   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22434   goto __pyx_L0;
22435   __pyx_L1_error:;
22436   __Pyx_XDECREF(__pyx_t_1);
22437   __Pyx_XDECREF(__pyx_t_3);
22438   __Pyx_XDECREF(__pyx_t_4);
22439   __Pyx_XDECREF(__pyx_t_7);
22440   __Pyx_XDECREF(__pyx_t_8);
22441   __Pyx_XDECREF(__pyx_t_9);
22442   __Pyx_XDECREF(__pyx_t_10);
22443   __Pyx_AddTraceback("csamtools.AlignedRead.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
22444   __pyx_r = NULL;
22445   __pyx_L0:;
22446   __Pyx_XDECREF(__pyx_v_c);
22447   __Pyx_XDECREF(__pyx_v_x);
22448   __Pyx_XDECREF(__pyx_v_y);
22449   __Pyx_XGIVEREF(__pyx_r);
22450   __Pyx_TraceReturn(__pyx_r);
22451   __Pyx_RefNannyFinishContext();
22452   return __pyx_r;
22453 }
22454
22455 /* Python wrapper */
22456 static int __pyx_pw_9csamtools_11AlignedRead_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/
22457 static int __pyx_pw_9csamtools_11AlignedRead_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) {
22458   int __pyx_r;
22459   __Pyx_RefNannyDeclarations
22460   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
22461   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_11cigarstring_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_cigar));
22462   __Pyx_RefNannyFinishContext();
22463   return __pyx_r;
22464 }
22465
22466 /* "csamtools.pyx":2321
22467  *             else: return "".join([ "%c%i" % (CODE2CIGAR[x],y) for x,y in c])
22468  * 
22469  *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
22470  *             if cigar == None or len(cigar) == 0: self.cigar = []
22471  *             parts = CIGAR_REGEX.findall( cigar )
22472  */
22473
22474 static int __pyx_pf_9csamtools_11AlignedRead_11cigarstring_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_cigar) {
22475   PyObject *__pyx_v_parts = NULL;
22476   PyObject *__pyx_v_x = NULL;
22477   PyObject *__pyx_v_y = NULL;
22478   int __pyx_r;
22479   __Pyx_RefNannyDeclarations
22480   PyObject *__pyx_t_1 = NULL;
22481   int __pyx_t_2;
22482   Py_ssize_t __pyx_t_3;
22483   int __pyx_t_4;
22484   int __pyx_t_5;
22485   PyObject *__pyx_t_6 = NULL;
22486   PyObject *__pyx_t_7 = NULL;
22487   PyObject *(*__pyx_t_8)(PyObject *);
22488   PyObject *__pyx_t_9 = NULL;
22489   PyObject *__pyx_t_10 = NULL;
22490   PyObject *__pyx_t_11 = NULL;
22491   PyObject *(*__pyx_t_12)(PyObject *);
22492   int __pyx_lineno = 0;
22493   const char *__pyx_filename = NULL;
22494   int __pyx_clineno = 0;
22495   __Pyx_TraceDeclarations
22496   __Pyx_RefNannySetupContext("__set__", 0);
22497   __Pyx_TraceCall("__set__", __pyx_f[0], 2321);
22498
22499   /* "csamtools.pyx":2322
22500  * 
22501  *         def __set__(self, cigar):
22502  *             if cigar == None or len(cigar) == 0: self.cigar = []             # <<<<<<<<<<<<<<
22503  *             parts = CIGAR_REGEX.findall( cigar )
22504  *             self.cigar = [ (CIGAR2CODE[ord(x)], int(y)) for x,y in parts ]
22505  */
22506   __pyx_t_1 = PyObject_RichCompare(__pyx_v_cigar, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22507   __Pyx_GOTREF(__pyx_t_1);
22508   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22509   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22510   if (!__pyx_t_2) {
22511     __pyx_t_3 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22512     __pyx_t_4 = (__pyx_t_3 == 0);
22513     __pyx_t_5 = __pyx_t_4;
22514   } else {
22515     __pyx_t_5 = __pyx_t_2;
22516   }
22517   if (__pyx_t_5) {
22518     __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22519     __Pyx_GOTREF(__pyx_t_1);
22520     if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22521     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
22522     goto __pyx_L3;
22523   }
22524   __pyx_L3:;
22525
22526   /* "csamtools.pyx":2323
22527  *         def __set__(self, cigar):
22528  *             if cigar == None or len(cigar) == 0: self.cigar = []
22529  *             parts = CIGAR_REGEX.findall( cigar )             # <<<<<<<<<<<<<<
22530  *             self.cigar = [ (CIGAR2CODE[ord(x)], int(y)) for x,y in parts ]
22531  * 
22532  */
22533   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR_REGEX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22534   __Pyx_GOTREF(__pyx_t_1);
22535   __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__findall); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22536   __Pyx_GOTREF(__pyx_t_6);
22537   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22538   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22539   __Pyx_GOTREF(__pyx_t_1);
22540   __Pyx_INCREF(__pyx_v_cigar);
22541   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cigar);
22542   __Pyx_GIVEREF(__pyx_v_cigar);
22543   __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 = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22544   __Pyx_GOTREF(__pyx_t_7);
22545   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
22546   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
22547   __pyx_v_parts = __pyx_t_7;
22548   __pyx_t_7 = 0;
22549
22550   /* "csamtools.pyx":2324
22551  *             if cigar == None or len(cigar) == 0: self.cigar = []
22552  *             parts = CIGAR_REGEX.findall( cigar )
22553  *             self.cigar = [ (CIGAR2CODE[ord(x)], int(y)) for x,y in parts ]             # <<<<<<<<<<<<<<
22554  * 
22555  *     property seq:
22556  */
22557   __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22558   __Pyx_GOTREF(__pyx_t_7);
22559   if (PyList_CheckExact(__pyx_v_parts) || PyTuple_CheckExact(__pyx_v_parts)) {
22560     __pyx_t_1 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
22561     __pyx_t_8 = NULL;
22562   } else {
22563     __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22564     __Pyx_GOTREF(__pyx_t_1);
22565     __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext;
22566   }
22567   for (;;) {
22568     if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) {
22569       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
22570       __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
22571     } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) {
22572       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
22573       __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
22574     } else {
22575       __pyx_t_6 = __pyx_t_8(__pyx_t_1);
22576       if (unlikely(!__pyx_t_6)) {
22577         if (PyErr_Occurred()) {
22578           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
22579           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22580         }
22581         break;
22582       }
22583       __Pyx_GOTREF(__pyx_t_6);
22584     }
22585     if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
22586       PyObject* sequence = __pyx_t_6;
22587       if (likely(PyTuple_CheckExact(sequence))) {
22588         if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
22589           if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22590           else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
22591           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22592         }
22593         __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
22594         __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
22595       } else {
22596         if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
22597           if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
22598           else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
22599           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22600         }
22601         __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
22602         __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
22603       }
22604       __Pyx_INCREF(__pyx_t_9);
22605       __Pyx_INCREF(__pyx_t_10);
22606       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
22607     } else {
22608       Py_ssize_t index = -1;
22609       __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22610       __Pyx_GOTREF(__pyx_t_11);
22611       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
22612       __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
22613       index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
22614       __Pyx_GOTREF(__pyx_t_9);
22615       index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed;
22616       __Pyx_GOTREF(__pyx_t_10);
22617       if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22618       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
22619       goto __pyx_L7_unpacking_done;
22620       __pyx_L6_unpacking_failed:;
22621       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
22622       if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
22623       if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
22624       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22625       __pyx_L7_unpacking_done:;
22626     }
22627     __Pyx_XDECREF(__pyx_v_x);
22628     __pyx_v_x = __pyx_t_9;
22629     __pyx_t_9 = 0;
22630     __Pyx_XDECREF(__pyx_v_y);
22631     __pyx_v_y = __pyx_t_10;
22632     __pyx_t_10 = 0;
22633     __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__CIGAR2CODE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22634     __Pyx_GOTREF(__pyx_t_6);
22635     __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22636     __Pyx_GOTREF(__pyx_t_10);
22637     __Pyx_INCREF(__pyx_v_x);
22638     PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_x);
22639     __Pyx_GIVEREF(__pyx_v_x);
22640     __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 = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22641     __Pyx_GOTREF(__pyx_t_9);
22642     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
22643     __pyx_t_10 = PyObject_GetItem(__pyx_t_6, __pyx_t_9); if (!__pyx_t_10) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22644     __Pyx_GOTREF(__pyx_t_10);
22645     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
22646     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
22647     __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22648     __Pyx_GOTREF(__pyx_t_9);
22649     __Pyx_INCREF(__pyx_v_y);
22650     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y);
22651     __Pyx_GIVEREF(__pyx_v_y);
22652     __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 = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22653     __Pyx_GOTREF(__pyx_t_6);
22654     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
22655     __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22656     __Pyx_GOTREF(__pyx_t_9);
22657     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
22658     __Pyx_GIVEREF(__pyx_t_10);
22659     PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_6);
22660     __Pyx_GIVEREF(__pyx_t_6);
22661     __pyx_t_10 = 0;
22662     __pyx_t_6 = 0;
22663     if (unlikely(PyList_Append(__pyx_t_7, (PyObject*)__pyx_t_9))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22664     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
22665   }
22666   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22667   if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__cigar, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22668   __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
22669
22670   __pyx_r = 0;
22671   goto __pyx_L0;
22672   __pyx_L1_error:;
22673   __Pyx_XDECREF(__pyx_t_1);
22674   __Pyx_XDECREF(__pyx_t_6);
22675   __Pyx_XDECREF(__pyx_t_7);
22676   __Pyx_XDECREF(__pyx_t_9);
22677   __Pyx_XDECREF(__pyx_t_10);
22678   __Pyx_XDECREF(__pyx_t_11);
22679   __Pyx_AddTraceback("csamtools.AlignedRead.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
22680   __pyx_r = -1;
22681   __pyx_L0:;
22682   __Pyx_XDECREF(__pyx_v_parts);
22683   __Pyx_XDECREF(__pyx_v_x);
22684   __Pyx_XDECREF(__pyx_v_y);
22685   __Pyx_TraceReturn(Py_None);
22686   __Pyx_RefNannyFinishContext();
22687   return __pyx_r;
22688 }
22689
22690 /* Python wrapper */
22691 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/
22692 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3seq_1__get__(PyObject *__pyx_v_self) {
22693   PyObject *__pyx_r = 0;
22694   __Pyx_RefNannyDeclarations
22695   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
22696   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3seq___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
22697   __Pyx_RefNannyFinishContext();
22698   return __pyx_r;
22699 }
22700
22701 /* "csamtools.pyx":2330
22702  * 
22703  *         In Python 3, this property is of type bytes and assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient."""
22704  *         def __get__(self):             # <<<<<<<<<<<<<<
22705  *             cdef bam1_t * src
22706  *             cdef char * s
22707  */
22708
22709 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3seq___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
22710   bam1_t *__pyx_v_src;
22711   PyObject *__pyx_r = NULL;
22712   __Pyx_RefNannyDeclarations
22713   int __pyx_t_1;
22714   PyObject *__pyx_t_2 = NULL;
22715   int __pyx_lineno = 0;
22716   const char *__pyx_filename = NULL;
22717   int __pyx_clineno = 0;
22718   __Pyx_TraceDeclarations
22719   __Pyx_RefNannySetupContext("__get__", 0);
22720   __Pyx_TraceCall("__get__", __pyx_f[0], 2330);
22721
22722   /* "csamtools.pyx":2333
22723  *             cdef bam1_t * src
22724  *             cdef char * s
22725  *             src = self._delegate             # <<<<<<<<<<<<<<
22726  * 
22727  *             if src.core.l_qseq == 0: return None
22728  */
22729   __pyx_v_src = __pyx_v_self->_delegate;
22730
22731   /* "csamtools.pyx":2335
22732  *             src = self._delegate
22733  * 
22734  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
22735  * 
22736  *             return get_seq_range(src, 0, src.core.l_qseq)
22737  */
22738   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
22739   if (__pyx_t_1) {
22740     __Pyx_XDECREF(__pyx_r);
22741     __Pyx_INCREF(Py_None);
22742     __pyx_r = Py_None;
22743     goto __pyx_L0;
22744     goto __pyx_L3;
22745   }
22746   __pyx_L3:;
22747
22748   /* "csamtools.pyx":2337
22749  *             if src.core.l_qseq == 0: return None
22750  * 
22751  *             return get_seq_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
22752  * 
22753  *         def __set__(self,seq):
22754  */
22755   __Pyx_XDECREF(__pyx_r);
22756   __pyx_t_2 = __pyx_f_9csamtools_get_seq_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22757   __Pyx_GOTREF(__pyx_t_2);
22758   __pyx_r = __pyx_t_2;
22759   __pyx_t_2 = 0;
22760   goto __pyx_L0;
22761
22762   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22763   goto __pyx_L0;
22764   __pyx_L1_error:;
22765   __Pyx_XDECREF(__pyx_t_2);
22766   __Pyx_AddTraceback("csamtools.AlignedRead.seq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
22767   __pyx_r = NULL;
22768   __pyx_L0:;
22769   __Pyx_XGIVEREF(__pyx_r);
22770   __Pyx_TraceReturn(__pyx_r);
22771   __Pyx_RefNannyFinishContext();
22772   return __pyx_r;
22773 }
22774
22775 /* Python wrapper */
22776 static int __pyx_pw_9csamtools_11AlignedRead_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
22777 static int __pyx_pw_9csamtools_11AlignedRead_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
22778   int __pyx_r;
22779   __Pyx_RefNannyDeclarations
22780   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
22781   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3seq_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_seq));
22782   __Pyx_RefNannyFinishContext();
22783   return __pyx_r;
22784 }
22785
22786 /* "csamtools.pyx":2339
22787  *             return get_seq_range(src, 0, src.core.l_qseq)
22788  * 
22789  *         def __set__(self,seq):             # <<<<<<<<<<<<<<
22790  *             # samtools manages sequence and quality length memory together
22791  *             # if no quality information is present, the first byte says 0xff.
22792  */
22793
22794 static int __pyx_pf_9csamtools_11AlignedRead_3seq_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_seq) {
22795   bam1_t *__pyx_v_src;
22796   uint8_t *__pyx_v_p;
22797   char *__pyx_v_s;
22798   int __pyx_v_l;
22799   int __pyx_v_k;
22800   int __pyx_v_nbytes_new;
22801   int __pyx_v_nbytes_old;
22802   int __pyx_r;
22803   __Pyx_RefNannyDeclarations
22804   PyObject *__pyx_t_1 = NULL;
22805   int __pyx_t_2;
22806   Py_ssize_t __pyx_t_3;
22807   int __pyx_t_4;
22808   int __pyx_t_5;
22809   int __pyx_t_6;
22810   char *__pyx_t_7;
22811   long __pyx_t_8;
22812   int __pyx_lineno = 0;
22813   const char *__pyx_filename = NULL;
22814   int __pyx_clineno = 0;
22815   __Pyx_TraceDeclarations
22816   __Pyx_RefNannySetupContext("__set__", 0);
22817   __Pyx_TraceCall("__set__", __pyx_f[0], 2339);
22818   __Pyx_INCREF(__pyx_v_seq);
22819
22820   /* "csamtools.pyx":2343
22821  *             # if no quality information is present, the first byte says 0xff.
22822  * 
22823  *             if seq == None or len(seq) == 0: return             # <<<<<<<<<<<<<<
22824  *             seq = _force_bytes(seq)
22825  *             cdef bam1_t * src
22826  */
22827   __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22828   __Pyx_GOTREF(__pyx_t_1);
22829   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22830   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22831   if (!__pyx_t_2) {
22832     __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22833     __pyx_t_4 = (__pyx_t_3 == 0);
22834     __pyx_t_5 = __pyx_t_4;
22835   } else {
22836     __pyx_t_5 = __pyx_t_2;
22837   }
22838   if (__pyx_t_5) {
22839     __pyx_r = 0;
22840     goto __pyx_L0;
22841     goto __pyx_L3;
22842   }
22843   __pyx_L3:;
22844
22845   /* "csamtools.pyx":2344
22846  * 
22847  *             if seq == None or len(seq) == 0: return
22848  *             seq = _force_bytes(seq)             # <<<<<<<<<<<<<<
22849  *             cdef bam1_t * src
22850  *             cdef uint8_t * p
22851  */
22852   __pyx_t_1 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_seq)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22853   __Pyx_GOTREF(__pyx_t_1);
22854   __Pyx_DECREF(__pyx_v_seq);
22855   __pyx_v_seq = __pyx_t_1;
22856   __pyx_t_1 = 0;
22857
22858   /* "csamtools.pyx":2350
22859  *             cdef int l, k, nbytes_new, nbytes_old
22860  * 
22861  *             src = self._delegate             # <<<<<<<<<<<<<<
22862  * 
22863  *             l = len(seq)
22864  */
22865   __pyx_v_src = __pyx_v_self->_delegate;
22866
22867   /* "csamtools.pyx":2352
22868  *             src = self._delegate
22869  * 
22870  *             l = len(seq)             # <<<<<<<<<<<<<<
22871  * 
22872  *             # as the sequence is stored in half-bytes, the total length (sequence
22873  */
22874   __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22875   __pyx_v_l = __pyx_t_3;
22876
22877   /* "csamtools.pyx":2356
22878  *             # as the sequence is stored in half-bytes, the total length (sequence
22879  *             # plus quality scores) is (l+1)/2 + l
22880  *             nbytes_new = (l+1)/2 + l             # <<<<<<<<<<<<<<
22881  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
22882  *             # acquire pointer to location in memory
22883  */
22884   __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);
22885
22886   /* "csamtools.pyx":2357
22887  *             # plus quality scores) is (l+1)/2 + l
22888  *             nbytes_new = (l+1)/2 + l
22889  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq             # <<<<<<<<<<<<<<
22890  *             # acquire pointer to location in memory
22891  *             p = bam1_seq( src )
22892  */
22893   __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);
22894
22895   /* "csamtools.pyx":2359
22896  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
22897  *             # acquire pointer to location in memory
22898  *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
22899  *             src.core.l_qseq = l
22900  * 
22901  */
22902   __pyx_v_p = bam1_seq(__pyx_v_src);
22903
22904   /* "csamtools.pyx":2360
22905  *             # acquire pointer to location in memory
22906  *             p = bam1_seq( src )
22907  *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
22908  * 
22909  *             pysam_bam_update( src,
22910  */
22911   __pyx_v_src->core.l_qseq = __pyx_v_l;
22912
22913   /* "csamtools.pyx":2365
22914  *                               nbytes_old,
22915  *                               nbytes_new,
22916  *                               p)             # <<<<<<<<<<<<<<
22917  *             # re-acquire pointer to location in memory
22918  *             # as it might have moved
22919  */
22920   pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);
22921
22922   /* "csamtools.pyx":2368
22923  *             # re-acquire pointer to location in memory
22924  *             # as it might have moved
22925  *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
22926  *             for k from 0 <= k < nbytes_new: p[k] = 0
22927  *             # convert to C string
22928  */
22929   __pyx_v_p = bam1_seq(__pyx_v_src);
22930
22931   /* "csamtools.pyx":2369
22932  *             # as it might have moved
22933  *             p = bam1_seq( src )
22934  *             for k from 0 <= k < nbytes_new: p[k] = 0             # <<<<<<<<<<<<<<
22935  *             # convert to C string
22936  *             s = seq
22937  */
22938   __pyx_t_6 = __pyx_v_nbytes_new;
22939   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {
22940     (__pyx_v_p[__pyx_v_k]) = 0;
22941   }
22942
22943   /* "csamtools.pyx":2371
22944  *             for k from 0 <= k < nbytes_new: p[k] = 0
22945  *             # convert to C string
22946  *             s = seq             # <<<<<<<<<<<<<<
22947  *             for k from 0 <= k < l:
22948  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
22949  */
22950   __pyx_t_7 = PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22951   __pyx_v_s = __pyx_t_7;
22952
22953   /* "csamtools.pyx":2372
22954  *             # convert to C string
22955  *             s = seq
22956  *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
22957  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
22958  * 
22959  */
22960   __pyx_t_6 = __pyx_v_l;
22961   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {
22962
22963     /* "csamtools.pyx":2373
22964  *             s = seq
22965  *             for k from 0 <= k < l:
22966  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
22967  * 
22968  *             # erase qualities
22969  */
22970     __pyx_t_8 = __Pyx_div_long(__pyx_v_k, 2);
22971     (__pyx_v_p[__pyx_t_8]) = ((__pyx_v_p[__pyx_t_8]) | (pysam_translate_sequence((__pyx_v_s[__pyx_v_k])) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))));
22972   }
22973
22974   /* "csamtools.pyx":2376
22975  * 
22976  *             # erase qualities
22977  *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
22978  *             p[0] = 0xff
22979  * 
22980  */
22981   __pyx_v_p = bam1_qual(__pyx_v_src);
22982
22983   /* "csamtools.pyx":2377
22984  *             # erase qualities
22985  *             p = bam1_qual( src )
22986  *             p[0] = 0xff             # <<<<<<<<<<<<<<
22987  * 
22988  * 
22989  */
22990   (__pyx_v_p[0]) = 0xff;
22991
22992   __pyx_r = 0;
22993   goto __pyx_L0;
22994   __pyx_L1_error:;
22995   __Pyx_XDECREF(__pyx_t_1);
22996   __Pyx_AddTraceback("csamtools.AlignedRead.seq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
22997   __pyx_r = -1;
22998   __pyx_L0:;
22999   __Pyx_XDECREF(__pyx_v_seq);
23000   __Pyx_TraceReturn(Py_None);
23001   __Pyx_RefNannyFinishContext();
23002   return __pyx_r;
23003 }
23004
23005 /* Python wrapper */
23006 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/
23007 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qual_1__get__(PyObject *__pyx_v_self) {
23008   PyObject *__pyx_r = 0;
23009   __Pyx_RefNannyDeclarations
23010   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23011   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4qual___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23012   __Pyx_RefNannyFinishContext();
23013   return __pyx_r;
23014 }
23015
23016 /* "csamtools.pyx":2384
23017  * 
23018  *         In Python 3, this property is of type bytes and assigning a unicode string to it consisting of ASCII characters only will work, but is inefficient."""
23019  *         def __get__(self):             # <<<<<<<<<<<<<<
23020  * 
23021  *             cdef bam1_t * src
23022  */
23023
23024 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qual___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23025   bam1_t *__pyx_v_src;
23026   PyObject *__pyx_r = NULL;
23027   __Pyx_RefNannyDeclarations
23028   int __pyx_t_1;
23029   PyObject *__pyx_t_2 = NULL;
23030   int __pyx_lineno = 0;
23031   const char *__pyx_filename = NULL;
23032   int __pyx_clineno = 0;
23033   __Pyx_TraceDeclarations
23034   __Pyx_RefNannySetupContext("__get__", 0);
23035   __Pyx_TraceCall("__get__", __pyx_f[0], 2384);
23036
23037   /* "csamtools.pyx":2389
23038  *             cdef char * q
23039  * 
23040  *             src = self._delegate             # <<<<<<<<<<<<<<
23041  * 
23042  *             if src.core.l_qseq == 0: return None
23043  */
23044   __pyx_v_src = __pyx_v_self->_delegate;
23045
23046   /* "csamtools.pyx":2391
23047  *             src = self._delegate
23048  * 
23049  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
23050  * 
23051  *             return get_qual_range(src, 0, src.core.l_qseq)
23052  */
23053   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
23054   if (__pyx_t_1) {
23055     __Pyx_XDECREF(__pyx_r);
23056     __Pyx_INCREF(Py_None);
23057     __pyx_r = Py_None;
23058     goto __pyx_L0;
23059     goto __pyx_L3;
23060   }
23061   __pyx_L3:;
23062
23063   /* "csamtools.pyx":2393
23064  *             if src.core.l_qseq == 0: return None
23065  * 
23066  *             return get_qual_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
23067  * 
23068  *         def __set__(self,qual):
23069  */
23070   __Pyx_XDECREF(__pyx_r);
23071   __pyx_t_2 = __pyx_f_9csamtools_get_qual_range(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23072   __Pyx_GOTREF(__pyx_t_2);
23073   __pyx_r = __pyx_t_2;
23074   __pyx_t_2 = 0;
23075   goto __pyx_L0;
23076
23077   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23078   goto __pyx_L0;
23079   __pyx_L1_error:;
23080   __Pyx_XDECREF(__pyx_t_2);
23081   __Pyx_AddTraceback("csamtools.AlignedRead.qual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23082   __pyx_r = NULL;
23083   __pyx_L0:;
23084   __Pyx_XGIVEREF(__pyx_r);
23085   __Pyx_TraceReturn(__pyx_r);
23086   __Pyx_RefNannyFinishContext();
23087   return __pyx_r;
23088 }
23089
23090 /* Python wrapper */
23091 static int __pyx_pw_9csamtools_11AlignedRead_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
23092 static int __pyx_pw_9csamtools_11AlignedRead_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
23093   int __pyx_r;
23094   __Pyx_RefNannyDeclarations
23095   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
23096   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4qual_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qual));
23097   __Pyx_RefNannyFinishContext();
23098   return __pyx_r;
23099 }
23100
23101 /* "csamtools.pyx":2395
23102  *             return get_qual_range(src, 0, src.core.l_qseq)
23103  * 
23104  *         def __set__(self,qual):             # <<<<<<<<<<<<<<
23105  *             # note that space is already allocated via the sequences
23106  *             cdef bam1_t * src
23107  */
23108
23109 static int __pyx_pf_9csamtools_11AlignedRead_4qual_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual) {
23110   bam1_t *__pyx_v_src;
23111   uint8_t *__pyx_v_p;
23112   char *__pyx_v_q;
23113   int __pyx_v_k;
23114   int __pyx_v_l;
23115   int __pyx_r;
23116   __Pyx_RefNannyDeclarations
23117   PyObject *__pyx_t_1 = NULL;
23118   int __pyx_t_2;
23119   Py_ssize_t __pyx_t_3;
23120   int __pyx_t_4;
23121   int __pyx_t_5;
23122   char *__pyx_t_6;
23123   PyObject *__pyx_t_7 = NULL;
23124   PyObject *__pyx_t_8 = NULL;
23125   int __pyx_t_9;
23126   int __pyx_lineno = 0;
23127   const char *__pyx_filename = NULL;
23128   int __pyx_clineno = 0;
23129   __Pyx_TraceDeclarations
23130   __Pyx_RefNannySetupContext("__set__", 0);
23131   __Pyx_TraceCall("__set__", __pyx_f[0], 2395);
23132   __Pyx_INCREF(__pyx_v_qual);
23133
23134   /* "csamtools.pyx":2402
23135  *             cdef int k
23136  * 
23137  *             src = self._delegate             # <<<<<<<<<<<<<<
23138  *             p = bam1_qual( src )
23139  *             if qual == None or len(qual) == 0:
23140  */
23141   __pyx_v_src = __pyx_v_self->_delegate;
23142
23143   /* "csamtools.pyx":2403
23144  * 
23145  *             src = self._delegate
23146  *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
23147  *             if qual == None or len(qual) == 0:
23148  *                 # if absent - set to 0xff
23149  */
23150   __pyx_v_p = bam1_qual(__pyx_v_src);
23151
23152   /* "csamtools.pyx":2404
23153  *             src = self._delegate
23154  *             p = bam1_qual( src )
23155  *             if qual == None or len(qual) == 0:             # <<<<<<<<<<<<<<
23156  *                 # if absent - set to 0xff
23157  *                 p[0] = 0xff
23158  */
23159   __pyx_t_1 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23160   __Pyx_GOTREF(__pyx_t_1);
23161   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23162   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
23163   if (!__pyx_t_2) {
23164     __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23165     __pyx_t_4 = (__pyx_t_3 == 0);
23166     __pyx_t_5 = __pyx_t_4;
23167   } else {
23168     __pyx_t_5 = __pyx_t_2;
23169   }
23170   if (__pyx_t_5) {
23171
23172     /* "csamtools.pyx":2406
23173  *             if qual == None or len(qual) == 0:
23174  *                 # if absent - set to 0xff
23175  *                 p[0] = 0xff             # <<<<<<<<<<<<<<
23176  *                 return
23177  *             qual = _force_bytes(qual)
23178  */
23179     (__pyx_v_p[0]) = 0xff;
23180
23181     /* "csamtools.pyx":2407
23182  *                 # if absent - set to 0xff
23183  *                 p[0] = 0xff
23184  *                 return             # <<<<<<<<<<<<<<
23185  *             qual = _force_bytes(qual)
23186  *             cdef int l
23187  */
23188     __pyx_r = 0;
23189     goto __pyx_L0;
23190     goto __pyx_L3;
23191   }
23192   __pyx_L3:;
23193
23194   /* "csamtools.pyx":2408
23195  *                 p[0] = 0xff
23196  *                 return
23197  *             qual = _force_bytes(qual)             # <<<<<<<<<<<<<<
23198  *             cdef int l
23199  *             # convert to C string
23200  */
23201   __pyx_t_1 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_qual)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23202   __Pyx_GOTREF(__pyx_t_1);
23203   __Pyx_DECREF(__pyx_v_qual);
23204   __pyx_v_qual = __pyx_t_1;
23205   __pyx_t_1 = 0;
23206
23207   /* "csamtools.pyx":2411
23208  *             cdef int l
23209  *             # convert to C string
23210  *             q = qual             # <<<<<<<<<<<<<<
23211  *             l = len(qual)
23212  *             if src.core.l_qseq != l:
23213  */
23214   __pyx_t_6 = PyBytes_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23215   __pyx_v_q = __pyx_t_6;
23216
23217   /* "csamtools.pyx":2412
23218  *             # convert to C string
23219  *             q = qual
23220  *             l = len(qual)             # <<<<<<<<<<<<<<
23221  *             if src.core.l_qseq != l:
23222  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
23223  */
23224   __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23225   __pyx_v_l = __pyx_t_3;
23226
23227   /* "csamtools.pyx":2413
23228  *             q = qual
23229  *             l = len(qual)
23230  *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
23231  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
23232  *             assert src.core.l_qseq == l
23233  */
23234   __pyx_t_5 = (__pyx_v_src->core.l_qseq != __pyx_v_l);
23235   if (__pyx_t_5) {
23236
23237     /* "csamtools.pyx":2414
23238  *             l = len(qual)
23239  *             if src.core.l_qseq != l:
23240  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
23241  *             assert src.core.l_qseq == l
23242  *             for k from 0 <= k < l:
23243  */
23244     __pyx_t_1 = PyInt_FromLong(__pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23245     __Pyx_GOTREF(__pyx_t_1);
23246     __pyx_t_7 = __Pyx_PyInt_to_py_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23247     __Pyx_GOTREF(__pyx_t_7);
23248     __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23249     __Pyx_GOTREF(__pyx_t_8);
23250     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
23251     __Pyx_GIVEREF(__pyx_t_1);
23252     PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
23253     __Pyx_GIVEREF(__pyx_t_7);
23254     __pyx_t_1 = 0;
23255     __pyx_t_7 = 0;
23256     __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_136), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23257     __Pyx_GOTREF(((PyObject *)__pyx_t_7));
23258     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
23259     __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23260     __Pyx_GOTREF(__pyx_t_8);
23261     PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
23262     __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
23263     __pyx_t_7 = 0;
23264     __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23265     __Pyx_GOTREF(__pyx_t_7);
23266     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
23267     __Pyx_Raise(__pyx_t_7, 0, 0, 0);
23268     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
23269     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23270     goto __pyx_L4;
23271   }
23272   __pyx_L4:;
23273
23274   /* "csamtools.pyx":2415
23275  *             if src.core.l_qseq != l:
23276  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
23277  *             assert src.core.l_qseq == l             # <<<<<<<<<<<<<<
23278  *             for k from 0 <= k < l:
23279  *                 p[k] = <uint8_t>q[k] - 33
23280  */
23281   #ifndef CYTHON_WITHOUT_ASSERTIONS
23282   if (unlikely(!(__pyx_v_src->core.l_qseq == __pyx_v_l))) {
23283     PyErr_SetNone(PyExc_AssertionError);
23284     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23285   }
23286   #endif
23287
23288   /* "csamtools.pyx":2416
23289  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
23290  *             assert src.core.l_qseq == l
23291  *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
23292  *                 p[k] = <uint8_t>q[k] - 33
23293  * 
23294  */
23295   __pyx_t_9 = __pyx_v_l;
23296   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_9; __pyx_v_k++) {
23297
23298     /* "csamtools.pyx":2417
23299  *             assert src.core.l_qseq == l
23300  *             for k from 0 <= k < l:
23301  *                 p[k] = <uint8_t>q[k] - 33             # <<<<<<<<<<<<<<
23302  * 
23303  *     property query:
23304  */
23305     (__pyx_v_p[__pyx_v_k]) = (((uint8_t)(__pyx_v_q[__pyx_v_k])) - 33);
23306   }
23307
23308   __pyx_r = 0;
23309   goto __pyx_L0;
23310   __pyx_L1_error:;
23311   __Pyx_XDECREF(__pyx_t_1);
23312   __Pyx_XDECREF(__pyx_t_7);
23313   __Pyx_XDECREF(__pyx_t_8);
23314   __Pyx_AddTraceback("csamtools.AlignedRead.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23315   __pyx_r = -1;
23316   __pyx_L0:;
23317   __Pyx_XDECREF(__pyx_v_qual);
23318   __Pyx_TraceReturn(Py_None);
23319   __Pyx_RefNannyFinishContext();
23320   return __pyx_r;
23321 }
23322
23323 /* Python wrapper */
23324 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5query_1__get__(PyObject *__pyx_v_self); /*proto*/
23325 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5query_1__get__(PyObject *__pyx_v_self) {
23326   PyObject *__pyx_r = 0;
23327   __Pyx_RefNannyDeclarations
23328   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23329   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5query___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23330   __Pyx_RefNannyFinishContext();
23331   return __pyx_r;
23332 }
23333
23334 /* "csamtools.pyx":2431
23335  *         were not considered for alignment may have been retained."""
23336  * 
23337  *         def __get__(self):             # <<<<<<<<<<<<<<
23338  *             cdef bam1_t * src
23339  *             cdef uint32_t start, end
23340  */
23341
23342 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5query___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23343   bam1_t *__pyx_v_src;
23344   uint32_t __pyx_v_start;
23345   uint32_t __pyx_v_end;
23346   PyObject *__pyx_r = NULL;
23347   __Pyx_RefNannyDeclarations
23348   int __pyx_t_1;
23349   int32_t __pyx_t_2;
23350   PyObject *__pyx_t_3 = NULL;
23351   int __pyx_lineno = 0;
23352   const char *__pyx_filename = NULL;
23353   int __pyx_clineno = 0;
23354   __Pyx_TraceDeclarations
23355   __Pyx_RefNannySetupContext("__get__", 0);
23356   __Pyx_TraceCall("__get__", __pyx_f[0], 2431);
23357
23358   /* "csamtools.pyx":2436
23359  *             cdef char * s
23360  * 
23361  *             src = self._delegate             # <<<<<<<<<<<<<<
23362  * 
23363  *             if src.core.l_qseq == 0: return None
23364  */
23365   __pyx_v_src = __pyx_v_self->_delegate;
23366
23367   /* "csamtools.pyx":2438
23368  *             src = self._delegate
23369  * 
23370  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
23371  * 
23372  *             start = query_start(src)
23373  */
23374   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
23375   if (__pyx_t_1) {
23376     __Pyx_XDECREF(__pyx_r);
23377     __Pyx_INCREF(Py_None);
23378     __pyx_r = Py_None;
23379     goto __pyx_L0;
23380     goto __pyx_L3;
23381   }
23382   __pyx_L3:;
23383
23384   /* "csamtools.pyx":2440
23385  *             if src.core.l_qseq == 0: return None
23386  * 
23387  *             start = query_start(src)             # <<<<<<<<<<<<<<
23388  *             end   = query_end(src)
23389  * 
23390  */
23391   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23392   __pyx_v_start = __pyx_t_2;
23393
23394   /* "csamtools.pyx":2441
23395  * 
23396  *             start = query_start(src)
23397  *             end   = query_end(src)             # <<<<<<<<<<<<<<
23398  * 
23399  *             return get_seq_range(src, start, end)
23400  */
23401   __pyx_t_2 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23402   __pyx_v_end = __pyx_t_2;
23403
23404   /* "csamtools.pyx":2443
23405  *             end   = query_end(src)
23406  * 
23407  *             return get_seq_range(src, start, end)             # <<<<<<<<<<<<<<
23408  * 
23409  *     property qqual:
23410  */
23411   __Pyx_XDECREF(__pyx_r);
23412   __pyx_t_3 = __pyx_f_9csamtools_get_seq_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23413   __Pyx_GOTREF(__pyx_t_3);
23414   __pyx_r = __pyx_t_3;
23415   __pyx_t_3 = 0;
23416   goto __pyx_L0;
23417
23418   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23419   goto __pyx_L0;
23420   __pyx_L1_error:;
23421   __Pyx_XDECREF(__pyx_t_3);
23422   __Pyx_AddTraceback("csamtools.AlignedRead.query.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23423   __pyx_r = NULL;
23424   __pyx_L0:;
23425   __Pyx_XGIVEREF(__pyx_r);
23426   __Pyx_TraceReturn(__pyx_r);
23427   __Pyx_RefNannyFinishContext();
23428   return __pyx_r;
23429 }
23430
23431 /* Python wrapper */
23432 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/
23433 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5qqual_1__get__(PyObject *__pyx_v_self) {
23434   PyObject *__pyx_r = 0;
23435   __Pyx_RefNannyDeclarations
23436   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23437   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5qqual___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23438   __Pyx_RefNannyFinishContext();
23439   return __pyx_r;
23440 }
23441
23442 /* "csamtools.pyx":2449
23443  * 
23444  *         In Python 3, this property is of type bytes."""
23445  *         def __get__(self):             # <<<<<<<<<<<<<<
23446  *             cdef bam1_t * src
23447  *             cdef uint32_t start, end
23448  */
23449
23450 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qqual___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23451   bam1_t *__pyx_v_src;
23452   uint32_t __pyx_v_start;
23453   uint32_t __pyx_v_end;
23454   PyObject *__pyx_r = NULL;
23455   __Pyx_RefNannyDeclarations
23456   int __pyx_t_1;
23457   int32_t __pyx_t_2;
23458   PyObject *__pyx_t_3 = NULL;
23459   int __pyx_lineno = 0;
23460   const char *__pyx_filename = NULL;
23461   int __pyx_clineno = 0;
23462   __Pyx_TraceDeclarations
23463   __Pyx_RefNannySetupContext("__get__", 0);
23464   __Pyx_TraceCall("__get__", __pyx_f[0], 2449);
23465
23466   /* "csamtools.pyx":2453
23467  *             cdef uint32_t start, end
23468  * 
23469  *             src = self._delegate             # <<<<<<<<<<<<<<
23470  * 
23471  *             if src.core.l_qseq == 0: return None
23472  */
23473   __pyx_v_src = __pyx_v_self->_delegate;
23474
23475   /* "csamtools.pyx":2455
23476  *             src = self._delegate
23477  * 
23478  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
23479  * 
23480  *             start = query_start(src)
23481  */
23482   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
23483   if (__pyx_t_1) {
23484     __Pyx_XDECREF(__pyx_r);
23485     __Pyx_INCREF(Py_None);
23486     __pyx_r = Py_None;
23487     goto __pyx_L0;
23488     goto __pyx_L3;
23489   }
23490   __pyx_L3:;
23491
23492   /* "csamtools.pyx":2457
23493  *             if src.core.l_qseq == 0: return None
23494  * 
23495  *             start = query_start(src)             # <<<<<<<<<<<<<<
23496  *             end   = query_end(src)
23497  * 
23498  */
23499   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23500   __pyx_v_start = __pyx_t_2;
23501
23502   /* "csamtools.pyx":2458
23503  * 
23504  *             start = query_start(src)
23505  *             end   = query_end(src)             # <<<<<<<<<<<<<<
23506  * 
23507  *             return get_qual_range(src, start, end)
23508  */
23509   __pyx_t_2 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23510   __pyx_v_end = __pyx_t_2;
23511
23512   /* "csamtools.pyx":2460
23513  *             end   = query_end(src)
23514  * 
23515  *             return get_qual_range(src, start, end)             # <<<<<<<<<<<<<<
23516  * 
23517  *     property qstart:
23518  */
23519   __Pyx_XDECREF(__pyx_r);
23520   __pyx_t_3 = __pyx_f_9csamtools_get_qual_range(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23521   __Pyx_GOTREF(__pyx_t_3);
23522   __pyx_r = __pyx_t_3;
23523   __pyx_t_3 = 0;
23524   goto __pyx_L0;
23525
23526   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23527   goto __pyx_L0;
23528   __pyx_L1_error:;
23529   __Pyx_XDECREF(__pyx_t_3);
23530   __Pyx_AddTraceback("csamtools.AlignedRead.qqual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23531   __pyx_r = NULL;
23532   __pyx_L0:;
23533   __Pyx_XGIVEREF(__pyx_r);
23534   __Pyx_TraceReturn(__pyx_r);
23535   __Pyx_RefNannyFinishContext();
23536   return __pyx_r;
23537 }
23538
23539 /* Python wrapper */
23540 static PyObject *__pyx_pw_9csamtools_11AlignedRead_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/
23541 static PyObject *__pyx_pw_9csamtools_11AlignedRead_6qstart_1__get__(PyObject *__pyx_v_self) {
23542   PyObject *__pyx_r = 0;
23543   __Pyx_RefNannyDeclarations
23544   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23545   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_6qstart___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23546   __Pyx_RefNannyFinishContext();
23547   return __pyx_r;
23548 }
23549
23550 /* "csamtools.pyx":2464
23551  *     property qstart:
23552  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
23553  *         def __get__(self):             # <<<<<<<<<<<<<<
23554  *             return query_start(self._delegate)
23555  * 
23556  */
23557
23558 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6qstart___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23559   PyObject *__pyx_r = NULL;
23560   __Pyx_RefNannyDeclarations
23561   int32_t __pyx_t_1;
23562   PyObject *__pyx_t_2 = NULL;
23563   int __pyx_lineno = 0;
23564   const char *__pyx_filename = NULL;
23565   int __pyx_clineno = 0;
23566   __Pyx_TraceDeclarations
23567   __Pyx_RefNannySetupContext("__get__", 0);
23568   __Pyx_TraceCall("__get__", __pyx_f[0], 2464);
23569
23570   /* "csamtools.pyx":2465
23571  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
23572  *         def __get__(self):
23573  *             return query_start(self._delegate)             # <<<<<<<<<<<<<<
23574  * 
23575  *     property qend:
23576  */
23577   __Pyx_XDECREF(__pyx_r);
23578   __pyx_t_1 = __pyx_f_9csamtools_query_start(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23579   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23580   __Pyx_GOTREF(__pyx_t_2);
23581   __pyx_r = __pyx_t_2;
23582   __pyx_t_2 = 0;
23583   goto __pyx_L0;
23584
23585   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23586   goto __pyx_L0;
23587   __pyx_L1_error:;
23588   __Pyx_XDECREF(__pyx_t_2);
23589   __Pyx_AddTraceback("csamtools.AlignedRead.qstart.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23590   __pyx_r = NULL;
23591   __pyx_L0:;
23592   __Pyx_XGIVEREF(__pyx_r);
23593   __Pyx_TraceReturn(__pyx_r);
23594   __Pyx_RefNannyFinishContext();
23595   return __pyx_r;
23596 }
23597
23598 /* Python wrapper */
23599 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/
23600 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qend_1__get__(PyObject *__pyx_v_self) {
23601   PyObject *__pyx_r = 0;
23602   __Pyx_RefNannyDeclarations
23603   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23604   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4qend___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23605   __Pyx_RefNannyFinishContext();
23606   return __pyx_r;
23607 }
23608
23609 /* "csamtools.pyx":2469
23610  *     property qend:
23611  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
23612  *         def __get__(self):             # <<<<<<<<<<<<<<
23613  *             return query_end(self._delegate)
23614  * 
23615  */
23616
23617 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qend___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23618   PyObject *__pyx_r = NULL;
23619   __Pyx_RefNannyDeclarations
23620   int32_t __pyx_t_1;
23621   PyObject *__pyx_t_2 = NULL;
23622   int __pyx_lineno = 0;
23623   const char *__pyx_filename = NULL;
23624   int __pyx_clineno = 0;
23625   __Pyx_TraceDeclarations
23626   __Pyx_RefNannySetupContext("__get__", 0);
23627   __Pyx_TraceCall("__get__", __pyx_f[0], 2469);
23628
23629   /* "csamtools.pyx":2470
23630  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
23631  *         def __get__(self):
23632  *             return query_end(self._delegate)             # <<<<<<<<<<<<<<
23633  * 
23634  *     property qlen:
23635  */
23636   __Pyx_XDECREF(__pyx_r);
23637   __pyx_t_1 = __pyx_f_9csamtools_query_end(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23638   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23639   __Pyx_GOTREF(__pyx_t_2);
23640   __pyx_r = __pyx_t_2;
23641   __pyx_t_2 = 0;
23642   goto __pyx_L0;
23643
23644   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23645   goto __pyx_L0;
23646   __pyx_L1_error:;
23647   __Pyx_XDECREF(__pyx_t_2);
23648   __Pyx_AddTraceback("csamtools.AlignedRead.qend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23649   __pyx_r = NULL;
23650   __pyx_L0:;
23651   __Pyx_XGIVEREF(__pyx_r);
23652   __Pyx_TraceReturn(__pyx_r);
23653   __Pyx_RefNannyFinishContext();
23654   return __pyx_r;
23655 }
23656
23657 /* Python wrapper */
23658 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/
23659 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4qlen_1__get__(PyObject *__pyx_v_self) {
23660   PyObject *__pyx_r = 0;
23661   __Pyx_RefNannyDeclarations
23662   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23663   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4qlen___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23664   __Pyx_RefNannyFinishContext();
23665   return __pyx_r;
23666 }
23667
23668 /* "csamtools.pyx":2474
23669  *     property qlen:
23670  *         """Length of the aligned query sequence"""
23671  *         def __get__(self):             # <<<<<<<<<<<<<<
23672  *             cdef bam1_t * src
23673  *             src = self._delegate
23674  */
23675
23676 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23677   bam1_t *__pyx_v_src;
23678   PyObject *__pyx_r = NULL;
23679   __Pyx_RefNannyDeclarations
23680   int32_t __pyx_t_1;
23681   int32_t __pyx_t_2;
23682   PyObject *__pyx_t_3 = NULL;
23683   int __pyx_lineno = 0;
23684   const char *__pyx_filename = NULL;
23685   int __pyx_clineno = 0;
23686   __Pyx_TraceDeclarations
23687   __Pyx_RefNannySetupContext("__get__", 0);
23688   __Pyx_TraceCall("__get__", __pyx_f[0], 2474);
23689
23690   /* "csamtools.pyx":2476
23691  *         def __get__(self):
23692  *             cdef bam1_t * src
23693  *             src = self._delegate             # <<<<<<<<<<<<<<
23694  *             return query_end(src)-query_start(src)
23695  * 
23696  */
23697   __pyx_v_src = __pyx_v_self->_delegate;
23698
23699   /* "csamtools.pyx":2477
23700  *             cdef bam1_t * src
23701  *             src = self._delegate
23702  *             return query_end(src)-query_start(src)             # <<<<<<<<<<<<<<
23703  * 
23704  *     property tags:
23705  */
23706   __Pyx_XDECREF(__pyx_r);
23707   __pyx_t_1 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23708   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23709   __pyx_t_3 = PyInt_FromLong((__pyx_t_1 - __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23710   __Pyx_GOTREF(__pyx_t_3);
23711   __pyx_r = __pyx_t_3;
23712   __pyx_t_3 = 0;
23713   goto __pyx_L0;
23714
23715   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23716   goto __pyx_L0;
23717   __pyx_L1_error:;
23718   __Pyx_XDECREF(__pyx_t_3);
23719   __Pyx_AddTraceback("csamtools.AlignedRead.qlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
23720   __pyx_r = NULL;
23721   __pyx_L0:;
23722   __Pyx_XGIVEREF(__pyx_r);
23723   __Pyx_TraceReturn(__pyx_r);
23724   __Pyx_RefNannyFinishContext();
23725   return __pyx_r;
23726 }
23727
23728 /* Python wrapper */
23729 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/
23730 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4tags_1__get__(PyObject *__pyx_v_self) {
23731   PyObject *__pyx_r = 0;
23732   __Pyx_RefNannyDeclarations
23733   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
23734   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4tags___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
23735   __Pyx_RefNannyFinishContext();
23736   return __pyx_r;
23737 }
23738
23739 /* "csamtools.pyx":2494
23740  *         multiple times.
23741  *         """
23742  *         def __get__(self):             # <<<<<<<<<<<<<<
23743  *             cdef char * ctag
23744  *             cdef bam1_t * src
23745  */
23746
23747 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tags___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
23748   bam1_t *__pyx_v_src;
23749   uint8_t *__pyx_v_s;
23750   char __pyx_v_auxtag[3];
23751   char __pyx_v_auxtype;
23752   uint8_t __pyx_v_byte_size;
23753   int32_t __pyx_v_nvalues;
23754   PyObject *__pyx_v_result = NULL;
23755   PyObject *__pyx_v_value = NULL;
23756   PyObject *__pyx_r = NULL;
23757   __Pyx_RefNannyDeclarations
23758   int __pyx_t_1;
23759   PyObject *__pyx_t_2 = NULL;
23760   char __pyx_t_3;
23761   int __pyx_t_4;
23762   int __pyx_t_5;
23763   PyObject *__pyx_t_6 = NULL;
23764   Py_ssize_t __pyx_t_7;
23765   PyObject *__pyx_t_8 = NULL;
23766   PyObject *__pyx_t_9 = NULL;
23767   PyObject *__pyx_t_10 = NULL;
23768   PyObject *(*__pyx_t_11)(PyObject *);
23769   uint8_t __pyx_t_12;
23770   int32_t __pyx_t_13;
23771   int __pyx_t_14;
23772   int __pyx_lineno = 0;
23773   const char *__pyx_filename = NULL;
23774   int __pyx_clineno = 0;
23775   __Pyx_TraceDeclarations
23776   __Pyx_RefNannySetupContext("__get__", 0);
23777   __Pyx_TraceCall("__get__", __pyx_f[0], 2494);
23778
23779   /* "csamtools.pyx":2503
23780  *             cdef int32_t nvalues
23781  * 
23782  *             src = self._delegate             # <<<<<<<<<<<<<<
23783  *             if src.l_aux == 0: return []
23784  *             s = bam1_aux( src )
23785  */
23786   __pyx_v_src = __pyx_v_self->_delegate;
23787
23788   /* "csamtools.pyx":2504
23789  * 
23790  *             src = self._delegate
23791  *             if src.l_aux == 0: return []             # <<<<<<<<<<<<<<
23792  *             s = bam1_aux( src )
23793  *             result = []
23794  */
23795   __pyx_t_1 = (__pyx_v_src->l_aux == 0);
23796   if (__pyx_t_1) {
23797     __Pyx_XDECREF(__pyx_r);
23798     __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23799     __Pyx_GOTREF(__pyx_t_2);
23800     __pyx_r = ((PyObject *)__pyx_t_2);
23801     __pyx_t_2 = 0;
23802     goto __pyx_L0;
23803     goto __pyx_L3;
23804   }
23805   __pyx_L3:;
23806
23807   /* "csamtools.pyx":2505
23808  *             src = self._delegate
23809  *             if src.l_aux == 0: return []
23810  *             s = bam1_aux( src )             # <<<<<<<<<<<<<<
23811  *             result = []
23812  *             auxtag[2] = 0
23813  */
23814   __pyx_v_s = bam1_aux(__pyx_v_src);
23815
23816   /* "csamtools.pyx":2506
23817  *             if src.l_aux == 0: return []
23818  *             s = bam1_aux( src )
23819  *             result = []             # <<<<<<<<<<<<<<
23820  *             auxtag[2] = 0
23821  *             while s < (src.data + src.data_len):
23822  */
23823   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23824   __Pyx_GOTREF(__pyx_t_2);
23825   __pyx_v_result = __pyx_t_2;
23826   __pyx_t_2 = 0;
23827
23828   /* "csamtools.pyx":2507
23829  *             s = bam1_aux( src )
23830  *             result = []
23831  *             auxtag[2] = 0             # <<<<<<<<<<<<<<
23832  *             while s < (src.data + src.data_len):
23833  *                 # get tag
23834  */
23835   (__pyx_v_auxtag[2]) = 0;
23836
23837   /* "csamtools.pyx":2508
23838  *             result = []
23839  *             auxtag[2] = 0
23840  *             while s < (src.data + src.data_len):             # <<<<<<<<<<<<<<
23841  *                 # get tag
23842  *                 auxtag[0] = s[0]
23843  */
23844   while (1) {
23845     __pyx_t_1 = (__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->data_len));
23846     if (!__pyx_t_1) break;
23847
23848     /* "csamtools.pyx":2510
23849  *             while s < (src.data + src.data_len):
23850  *                 # get tag
23851  *                 auxtag[0] = s[0]             # <<<<<<<<<<<<<<
23852  *                 auxtag[1] = s[1]
23853  *                 s += 2
23854  */
23855     (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);
23856
23857     /* "csamtools.pyx":2511
23858  *                 # get tag
23859  *                 auxtag[0] = s[0]
23860  *                 auxtag[1] = s[1]             # <<<<<<<<<<<<<<
23861  *                 s += 2
23862  *                 auxtype = s[0]
23863  */
23864     (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);
23865
23866     /* "csamtools.pyx":2512
23867  *                 auxtag[0] = s[0]
23868  *                 auxtag[1] = s[1]
23869  *                 s += 2             # <<<<<<<<<<<<<<
23870  *                 auxtype = s[0]
23871  *                 if auxtype in ('c', 'C'):
23872  */
23873     __pyx_v_s = (__pyx_v_s + 2);
23874
23875     /* "csamtools.pyx":2513
23876  *                 auxtag[1] = s[1]
23877  *                 s += 2
23878  *                 auxtype = s[0]             # <<<<<<<<<<<<<<
23879  *                 if auxtype in ('c', 'C'):
23880  *                     value = <int>bam_aux2i(s)
23881  */
23882     __pyx_v_auxtype = (__pyx_v_s[0]);
23883
23884     /* "csamtools.pyx":2514
23885  *                 s += 2
23886  *                 auxtype = s[0]
23887  *                 if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
23888  *                     value = <int>bam_aux2i(s)
23889  *                     s += 1
23890  */
23891     __pyx_t_3 = __pyx_v_auxtype;
23892     __pyx_t_1 = ((int)(__pyx_t_3 == 'c'));
23893     if (!__pyx_t_1) {
23894       __pyx_t_4 = ((int)(__pyx_t_3 == 'C'));
23895       __pyx_t_5 = __pyx_t_4;
23896     } else {
23897       __pyx_t_5 = __pyx_t_1;
23898     }
23899     __pyx_t_1 = __pyx_t_5;
23900     if (__pyx_t_1) {
23901
23902       /* "csamtools.pyx":2515
23903  *                 auxtype = s[0]
23904  *                 if auxtype in ('c', 'C'):
23905  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
23906  *                     s += 1
23907  *                 elif auxtype in ('s', 'S'):
23908  */
23909       __pyx_t_2 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23910       __Pyx_GOTREF(__pyx_t_2);
23911       __Pyx_XDECREF(__pyx_v_value);
23912       __pyx_v_value = __pyx_t_2;
23913       __pyx_t_2 = 0;
23914
23915       /* "csamtools.pyx":2516
23916  *                 if auxtype in ('c', 'C'):
23917  *                     value = <int>bam_aux2i(s)
23918  *                     s += 1             # <<<<<<<<<<<<<<
23919  *                 elif auxtype in ('s', 'S'):
23920  *                     value = <int>bam_aux2i(s)
23921  */
23922       __pyx_v_s = (__pyx_v_s + 1);
23923       goto __pyx_L6;
23924     }
23925
23926     /* "csamtools.pyx":2517
23927  *                     value = <int>bam_aux2i(s)
23928  *                     s += 1
23929  *                 elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
23930  *                     value = <int>bam_aux2i(s)
23931  *                     s += 2
23932  */
23933     __pyx_t_3 = __pyx_v_auxtype;
23934     __pyx_t_1 = ((int)(__pyx_t_3 == 's'));
23935     if (!__pyx_t_1) {
23936       __pyx_t_5 = ((int)(__pyx_t_3 == 'S'));
23937       __pyx_t_4 = __pyx_t_5;
23938     } else {
23939       __pyx_t_4 = __pyx_t_1;
23940     }
23941     __pyx_t_1 = __pyx_t_4;
23942     if (__pyx_t_1) {
23943
23944       /* "csamtools.pyx":2518
23945  *                     s += 1
23946  *                 elif auxtype in ('s', 'S'):
23947  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
23948  *                     s += 2
23949  *                 elif auxtype in ('i', 'I'):
23950  */
23951       __pyx_t_2 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23952       __Pyx_GOTREF(__pyx_t_2);
23953       __Pyx_XDECREF(__pyx_v_value);
23954       __pyx_v_value = __pyx_t_2;
23955       __pyx_t_2 = 0;
23956
23957       /* "csamtools.pyx":2519
23958  *                 elif auxtype in ('s', 'S'):
23959  *                     value = <int>bam_aux2i(s)
23960  *                     s += 2             # <<<<<<<<<<<<<<
23961  *                 elif auxtype in ('i', 'I'):
23962  *                     value = <int32_t>bam_aux2i(s)
23963  */
23964       __pyx_v_s = (__pyx_v_s + 2);
23965       goto __pyx_L6;
23966     }
23967
23968     /* "csamtools.pyx":2520
23969  *                     value = <int>bam_aux2i(s)
23970  *                     s += 2
23971  *                 elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
23972  *                     value = <int32_t>bam_aux2i(s)
23973  *                     s += 4
23974  */
23975     __pyx_t_3 = __pyx_v_auxtype;
23976     __pyx_t_1 = ((int)(__pyx_t_3 == 'i'));
23977     if (!__pyx_t_1) {
23978       __pyx_t_4 = ((int)(__pyx_t_3 == 'I'));
23979       __pyx_t_5 = __pyx_t_4;
23980     } else {
23981       __pyx_t_5 = __pyx_t_1;
23982     }
23983     __pyx_t_1 = __pyx_t_5;
23984     if (__pyx_t_1) {
23985
23986       /* "csamtools.pyx":2521
23987  *                     s += 2
23988  *                 elif auxtype in ('i', 'I'):
23989  *                     value = <int32_t>bam_aux2i(s)             # <<<<<<<<<<<<<<
23990  *                     s += 4
23991  *                 elif auxtype == 'f':
23992  */
23993       __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23994       __Pyx_GOTREF(__pyx_t_2);
23995       __Pyx_XDECREF(__pyx_v_value);
23996       __pyx_v_value = __pyx_t_2;
23997       __pyx_t_2 = 0;
23998
23999       /* "csamtools.pyx":2522
24000  *                 elif auxtype in ('i', 'I'):
24001  *                     value = <int32_t>bam_aux2i(s)
24002  *                     s += 4             # <<<<<<<<<<<<<<
24003  *                 elif auxtype == 'f':
24004  *                     value = <float>bam_aux2f(s)
24005  */
24006       __pyx_v_s = (__pyx_v_s + 4);
24007       goto __pyx_L6;
24008     }
24009
24010     /* "csamtools.pyx":2523
24011  *                     value = <int32_t>bam_aux2i(s)
24012  *                     s += 4
24013  *                 elif auxtype == 'f':             # <<<<<<<<<<<<<<
24014  *                     value = <float>bam_aux2f(s)
24015  *                     s += 4
24016  */
24017     __pyx_t_1 = (__pyx_v_auxtype == 'f');
24018     if (__pyx_t_1) {
24019
24020       /* "csamtools.pyx":2524
24021  *                     s += 4
24022  *                 elif auxtype == 'f':
24023  *                     value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
24024  *                     s += 4
24025  *                 elif auxtype == 'd':
24026  */
24027       __pyx_t_2 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24028       __Pyx_GOTREF(__pyx_t_2);
24029       __Pyx_XDECREF(__pyx_v_value);
24030       __pyx_v_value = __pyx_t_2;
24031       __pyx_t_2 = 0;
24032
24033       /* "csamtools.pyx":2525
24034  *                 elif auxtype == 'f':
24035  *                     value = <float>bam_aux2f(s)
24036  *                     s += 4             # <<<<<<<<<<<<<<
24037  *                 elif auxtype == 'd':
24038  *                     value = <double>bam_aux2d(s)
24039  */
24040       __pyx_v_s = (__pyx_v_s + 4);
24041       goto __pyx_L6;
24042     }
24043
24044     /* "csamtools.pyx":2526
24045  *                     value = <float>bam_aux2f(s)
24046  *                     s += 4
24047  *                 elif auxtype == 'd':             # <<<<<<<<<<<<<<
24048  *                     value = <double>bam_aux2d(s)
24049  *                     s += 8
24050  */
24051     __pyx_t_1 = (__pyx_v_auxtype == 'd');
24052     if (__pyx_t_1) {
24053
24054       /* "csamtools.pyx":2527
24055  *                     s += 4
24056  *                 elif auxtype == 'd':
24057  *                     value = <double>bam_aux2d(s)             # <<<<<<<<<<<<<<
24058  *                     s += 8
24059  *                 elif auxtype == 'A':
24060  */
24061       __pyx_t_2 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24062       __Pyx_GOTREF(__pyx_t_2);
24063       __Pyx_XDECREF(__pyx_v_value);
24064       __pyx_v_value = __pyx_t_2;
24065       __pyx_t_2 = 0;
24066
24067       /* "csamtools.pyx":2528
24068  *                 elif auxtype == 'd':
24069  *                     value = <double>bam_aux2d(s)
24070  *                     s += 8             # <<<<<<<<<<<<<<
24071  *                 elif auxtype == 'A':
24072  *                     value = "%c" % <char>bam_aux2A(s)
24073  */
24074       __pyx_v_s = (__pyx_v_s + 8);
24075       goto __pyx_L6;
24076     }
24077
24078     /* "csamtools.pyx":2529
24079  *                     value = <double>bam_aux2d(s)
24080  *                     s += 8
24081  *                 elif auxtype == 'A':             # <<<<<<<<<<<<<<
24082  *                     value = "%c" % <char>bam_aux2A(s)
24083  *                     s += 1
24084  */
24085     __pyx_t_1 = (__pyx_v_auxtype == 'A');
24086     if (__pyx_t_1) {
24087
24088       /* "csamtools.pyx":2530
24089  *                     s += 8
24090  *                 elif auxtype == 'A':
24091  *                     value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
24092  *                     s += 1
24093  *                 elif auxtype in ('Z', 'H'):
24094  */
24095       __pyx_t_2 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24096       __Pyx_GOTREF(__pyx_t_2);
24097       __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_137), __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24098       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
24099       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
24100       __Pyx_XDECREF(__pyx_v_value);
24101       __pyx_v_value = ((PyObject *)__pyx_t_6);
24102       __pyx_t_6 = 0;
24103
24104       /* "csamtools.pyx":2531
24105  *                 elif auxtype == 'A':
24106  *                     value = "%c" % <char>bam_aux2A(s)
24107  *                     s += 1             # <<<<<<<<<<<<<<
24108  *                 elif auxtype in ('Z', 'H'):
24109  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
24110  */
24111       __pyx_v_s = (__pyx_v_s + 1);
24112       goto __pyx_L6;
24113     }
24114
24115     /* "csamtools.pyx":2532
24116  *                     value = "%c" % <char>bam_aux2A(s)
24117  *                     s += 1
24118  *                 elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
24119  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
24120  *                     # +1 for NULL terminated string
24121  */
24122     __pyx_t_3 = __pyx_v_auxtype;
24123     __pyx_t_1 = ((int)(__pyx_t_3 == 'Z'));
24124     if (!__pyx_t_1) {
24125       __pyx_t_5 = ((int)(__pyx_t_3 == 'H'));
24126       __pyx_t_4 = __pyx_t_5;
24127     } else {
24128       __pyx_t_4 = __pyx_t_1;
24129     }
24130     __pyx_t_1 = __pyx_t_4;
24131     if (__pyx_t_1) {
24132
24133       /* "csamtools.pyx":2533
24134  *                     s += 1
24135  *                 elif auxtype in ('Z', 'H'):
24136  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))             # <<<<<<<<<<<<<<
24137  *                     # +1 for NULL terminated string
24138  *                     s += len(value) + 1
24139  */
24140       __pyx_t_6 = __pyx_f_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_s))); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24141       __Pyx_GOTREF(__pyx_t_6);
24142       __Pyx_XDECREF(__pyx_v_value);
24143       __pyx_v_value = __pyx_t_6;
24144       __pyx_t_6 = 0;
24145
24146       /* "csamtools.pyx":2535
24147  *                     value = _charptr_to_str(<char*>bam_aux2Z(s))
24148  *                     # +1 for NULL terminated string
24149  *                     s += len(value) + 1             # <<<<<<<<<<<<<<
24150  *                 elif auxtype == 'B':
24151  *                     s += 1
24152  */
24153       __pyx_t_7 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24154       __pyx_v_s = (__pyx_v_s + (__pyx_t_7 + 1));
24155       goto __pyx_L6;
24156     }
24157
24158     /* "csamtools.pyx":2536
24159  *                     # +1 for NULL terminated string
24160  *                     s += len(value) + 1
24161  *                 elif auxtype == 'B':             # <<<<<<<<<<<<<<
24162  *                     s += 1
24163  *                     byte_size, nvalues, value = convertBinaryTagToList( s )
24164  */
24165     __pyx_t_1 = (__pyx_v_auxtype == 'B');
24166     if (__pyx_t_1) {
24167
24168       /* "csamtools.pyx":2537
24169  *                     s += len(value) + 1
24170  *                 elif auxtype == 'B':
24171  *                     s += 1             # <<<<<<<<<<<<<<
24172  *                     byte_size, nvalues, value = convertBinaryTagToList( s )
24173  *                     # 5 for 1 char and 1 int
24174  */
24175       __pyx_v_s = (__pyx_v_s + 1);
24176
24177       /* "csamtools.pyx":2538
24178  *                 elif auxtype == 'B':
24179  *                     s += 1
24180  *                     byte_size, nvalues, value = convertBinaryTagToList( s )             # <<<<<<<<<<<<<<
24181  *                     # 5 for 1 char and 1 int
24182  *                     s += 5 + ( nvalues * byte_size) - 1
24183  */
24184       __pyx_t_6 = __pyx_f_9csamtools_convertBinaryTagToList(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24185       __Pyx_GOTREF(__pyx_t_6);
24186       if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
24187         PyObject* sequence = __pyx_t_6;
24188         if (likely(PyTuple_CheckExact(sequence))) {
24189           if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) {
24190             if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3);
24191             else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
24192             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24193           }
24194           __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
24195           __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
24196           __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); 
24197         } else {
24198           if (unlikely(PyList_GET_SIZE(sequence) != 3)) {
24199             if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3);
24200             else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
24201             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24202           }
24203           __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
24204           __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
24205           __pyx_t_9 = PyList_GET_ITEM(sequence, 2); 
24206         }
24207         __Pyx_INCREF(__pyx_t_2);
24208         __Pyx_INCREF(__pyx_t_8);
24209         __Pyx_INCREF(__pyx_t_9);
24210         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24211       } else {
24212         Py_ssize_t index = -1;
24213         __pyx_t_10 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24214         __Pyx_GOTREF(__pyx_t_10);
24215         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24216         __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
24217         index = 0; __pyx_t_2 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L7_unpacking_failed;
24218         __Pyx_GOTREF(__pyx_t_2);
24219         index = 1; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L7_unpacking_failed;
24220         __Pyx_GOTREF(__pyx_t_8);
24221         index = 2; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed;
24222         __Pyx_GOTREF(__pyx_t_9);
24223         if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24224         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
24225         goto __pyx_L8_unpacking_done;
24226         __pyx_L7_unpacking_failed:;
24227         __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
24228         if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
24229         if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
24230         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24231         __pyx_L8_unpacking_done:;
24232       }
24233       __pyx_t_12 = __Pyx_PyInt_from_py_uint8_t(__pyx_t_2); if (unlikely((__pyx_t_12 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24234       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
24235       __pyx_t_13 = __Pyx_PyInt_from_py_int32_t(__pyx_t_8); if (unlikely((__pyx_t_13 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24236       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
24237       __pyx_v_byte_size = __pyx_t_12;
24238       __pyx_v_nvalues = __pyx_t_13;
24239       __Pyx_XDECREF(__pyx_v_value);
24240       __pyx_v_value = __pyx_t_9;
24241       __pyx_t_9 = 0;
24242
24243       /* "csamtools.pyx":2540
24244  *                     byte_size, nvalues, value = convertBinaryTagToList( s )
24245  *                     # 5 for 1 char and 1 int
24246  *                     s += 5 + ( nvalues * byte_size) - 1             # <<<<<<<<<<<<<<
24247  * 
24248  *                 s += 1
24249  */
24250       __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1));
24251       goto __pyx_L6;
24252     }
24253     __pyx_L6:;
24254
24255     /* "csamtools.pyx":2542
24256  *                     s += 5 + ( nvalues * byte_size) - 1
24257  * 
24258  *                 s += 1             # <<<<<<<<<<<<<<
24259  * 
24260  *                 result.append( (_charptr_to_str(auxtag), value) )
24261  */
24262     __pyx_v_s = (__pyx_v_s + 1);
24263
24264     /* "csamtools.pyx":2544
24265  *                 s += 1
24266  * 
24267  *                 result.append( (_charptr_to_str(auxtag), value) )             # <<<<<<<<<<<<<<
24268  * 
24269  *             return result
24270  */
24271     __pyx_t_6 = __pyx_f_9csamtools__charptr_to_str(__pyx_v_auxtag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24272     __Pyx_GOTREF(__pyx_t_6);
24273     if (unlikely(!__pyx_v_value)) { __Pyx_RaiseUnboundLocalError("value"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
24274     __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24275     __Pyx_GOTREF(__pyx_t_9);
24276     PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6);
24277     __Pyx_GIVEREF(__pyx_t_6);
24278     __Pyx_INCREF(__pyx_v_value);
24279     PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_value);
24280     __Pyx_GIVEREF(__pyx_v_value);
24281     __pyx_t_6 = 0;
24282     __pyx_t_14 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24283     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
24284   }
24285
24286   /* "csamtools.pyx":2546
24287  *                 result.append( (_charptr_to_str(auxtag), value) )
24288  * 
24289  *             return result             # <<<<<<<<<<<<<<
24290  * 
24291  *         def __set__(self, tags):
24292  */
24293   __Pyx_XDECREF(__pyx_r);
24294   __Pyx_INCREF(((PyObject *)__pyx_v_result));
24295   __pyx_r = ((PyObject *)__pyx_v_result);
24296   goto __pyx_L0;
24297
24298   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24299   goto __pyx_L0;
24300   __pyx_L1_error:;
24301   __Pyx_XDECREF(__pyx_t_2);
24302   __Pyx_XDECREF(__pyx_t_6);
24303   __Pyx_XDECREF(__pyx_t_8);
24304   __Pyx_XDECREF(__pyx_t_9);
24305   __Pyx_XDECREF(__pyx_t_10);
24306   __Pyx_AddTraceback("csamtools.AlignedRead.tags.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
24307   __pyx_r = NULL;
24308   __pyx_L0:;
24309   __Pyx_XDECREF(__pyx_v_result);
24310   __Pyx_XDECREF(__pyx_v_value);
24311   __Pyx_XGIVEREF(__pyx_r);
24312   __Pyx_TraceReturn(__pyx_r);
24313   __Pyx_RefNannyFinishContext();
24314   return __pyx_r;
24315 }
24316
24317 /* Python wrapper */
24318 static int __pyx_pw_9csamtools_11AlignedRead_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
24319 static int __pyx_pw_9csamtools_11AlignedRead_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
24320   int __pyx_r;
24321   __Pyx_RefNannyDeclarations
24322   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
24323   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4tags_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tags));
24324   __Pyx_RefNannyFinishContext();
24325   return __pyx_r;
24326 }
24327
24328 /* "csamtools.pyx":2548
24329  *             return result
24330  * 
24331  *         def __set__(self, tags):             # <<<<<<<<<<<<<<
24332  *             cdef bam1_t * src
24333  *             cdef uint8_t * s
24334  */
24335
24336 static int __pyx_pf_9csamtools_11AlignedRead_4tags_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tags) {
24337   bam1_t *__pyx_v_src;
24338   uint8_t *__pyx_v_s;
24339   char *__pyx_v_temp;
24340   PyObject *__pyx_v_fmts = NULL;
24341   PyObject *__pyx_v_args = NULL;
24342   PyObject *__pyx_v_pytag = NULL;
24343   PyObject *__pyx_v_value = NULL;
24344   PyObject *__pyx_v_t = NULL;
24345   PyObject *__pyx_v_pytype = NULL;
24346   PyObject *__pyx_v_datafmt = NULL;
24347   PyObject *__pyx_v_datatype = NULL;
24348   PyObject *__pyx_v_mi = NULL;
24349   PyObject *__pyx_v_ma = NULL;
24350   PyObject *__pyx_v_absmax = NULL;
24351   PyObject *__pyx_v_fmt = NULL;
24352   PyObject *__pyx_v_total_size = NULL;
24353   PyObject *__pyx_v_buffer = NULL;
24354   int __pyx_r;
24355   __Pyx_RefNannyDeclarations
24356   PyObject *__pyx_t_1 = NULL;
24357   PyObject *__pyx_t_2 = NULL;
24358   int __pyx_t_3;
24359   Py_ssize_t __pyx_t_4;
24360   PyObject *(*__pyx_t_5)(PyObject *);
24361   PyObject *__pyx_t_6 = NULL;
24362   PyObject *__pyx_t_7 = NULL;
24363   PyObject *__pyx_t_8 = NULL;
24364   PyObject *(*__pyx_t_9)(PyObject *);
24365   int __pyx_t_10;
24366   int __pyx_t_11;
24367   Py_ssize_t __pyx_t_12;
24368   PyObject *__pyx_t_13 = NULL;
24369   PyObject *__pyx_t_14 = NULL;
24370   int __pyx_t_15;
24371   size_t __pyx_t_16;
24372   int __pyx_t_17;
24373   char *__pyx_t_18;
24374   int __pyx_lineno = 0;
24375   const char *__pyx_filename = NULL;
24376   int __pyx_clineno = 0;
24377   __Pyx_TraceDeclarations
24378   __Pyx_RefNannySetupContext("__set__", 0);
24379   __Pyx_TraceCall("__set__", __pyx_f[0], 2548);
24380
24381   /* "csamtools.pyx":2554
24382  *             cdef char * temp
24383  * 
24384  *             src = self._delegate             # <<<<<<<<<<<<<<
24385  * 
24386  *             fmts, args = ["<"], []
24387  */
24388   __pyx_v_src = __pyx_v_self->_delegate;
24389
24390   /* "csamtools.pyx":2556
24391  *             src = self._delegate
24392  * 
24393  *             fmts, args = ["<"], []             # <<<<<<<<<<<<<<
24394  * 
24395  *             if tags != None:
24396  */
24397   __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24398   __Pyx_GOTREF(__pyx_t_1);
24399   __Pyx_INCREF(((PyObject *)__pyx_kp_s_138));
24400   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_138));
24401   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_138));
24402   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24403   __Pyx_GOTREF(__pyx_t_2);
24404   __pyx_v_fmts = __pyx_t_1;
24405   __pyx_t_1 = 0;
24406   __pyx_v_args = __pyx_t_2;
24407   __pyx_t_2 = 0;
24408
24409   /* "csamtools.pyx":2558
24410  *             fmts, args = ["<"], []
24411  * 
24412  *             if tags != None:             # <<<<<<<<<<<<<<
24413  * 
24414  *                 # map samtools code to python.struct code and byte size
24415  */
24416   __pyx_t_2 = PyObject_RichCompare(__pyx_v_tags, Py_None, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24417   __Pyx_GOTREF(__pyx_t_2);
24418   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24419   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
24420   if (__pyx_t_3) {
24421
24422     /* "csamtools.pyx":2561
24423  * 
24424  *                 # map samtools code to python.struct code and byte size
24425  *                 for pytag, value in tags:             # <<<<<<<<<<<<<<
24426  *                     if not type(pytag) is bytes:
24427  *                         pytag = pytag.encode('ascii')
24428  */
24429     if (PyList_CheckExact(__pyx_v_tags) || PyTuple_CheckExact(__pyx_v_tags)) {
24430       __pyx_t_2 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
24431       __pyx_t_5 = NULL;
24432     } else {
24433       __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24434       __Pyx_GOTREF(__pyx_t_2);
24435       __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext;
24436     }
24437     for (;;) {
24438       if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) {
24439         if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
24440         __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
24441       } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) {
24442         if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
24443         __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++;
24444       } else {
24445         __pyx_t_1 = __pyx_t_5(__pyx_t_2);
24446         if (unlikely(!__pyx_t_1)) {
24447           if (PyErr_Occurred()) {
24448             if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
24449             else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24450           }
24451           break;
24452         }
24453         __Pyx_GOTREF(__pyx_t_1);
24454       }
24455       if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
24456         PyObject* sequence = __pyx_t_1;
24457         if (likely(PyTuple_CheckExact(sequence))) {
24458           if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
24459             if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
24460             else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
24461             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24462           }
24463           __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
24464           __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
24465         } else {
24466           if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
24467             if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
24468             else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
24469             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24470           }
24471           __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
24472           __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
24473         }
24474         __Pyx_INCREF(__pyx_t_6);
24475         __Pyx_INCREF(__pyx_t_7);
24476         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24477       } else {
24478         Py_ssize_t index = -1;
24479         __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24480         __Pyx_GOTREF(__pyx_t_8);
24481         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24482         __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
24483         index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
24484         __Pyx_GOTREF(__pyx_t_6);
24485         index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
24486         __Pyx_GOTREF(__pyx_t_7);
24487         if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24488         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
24489         goto __pyx_L7_unpacking_done;
24490         __pyx_L6_unpacking_failed:;
24491         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
24492         if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
24493         if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
24494         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24495         __pyx_L7_unpacking_done:;
24496       }
24497       __Pyx_XDECREF(__pyx_v_pytag);
24498       __pyx_v_pytag = __pyx_t_6;
24499       __pyx_t_6 = 0;
24500       __Pyx_XDECREF(__pyx_v_value);
24501       __pyx_v_value = __pyx_t_7;
24502       __pyx_t_7 = 0;
24503
24504       /* "csamtools.pyx":2562
24505  *                 # map samtools code to python.struct code and byte size
24506  *                 for pytag, value in tags:
24507  *                     if not type(pytag) is bytes:             # <<<<<<<<<<<<<<
24508  *                         pytag = pytag.encode('ascii')
24509  *                     t = type(value)
24510  */
24511       __pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_pytag)) == ((PyObject *)((PyObject*)(&PyBytes_Type))));
24512       __pyx_t_10 = (!__pyx_t_3);
24513       if (__pyx_t_10) {
24514
24515         /* "csamtools.pyx":2563
24516  *                 for pytag, value in tags:
24517  *                     if not type(pytag) is bytes:
24518  *                         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
24519  *                     t = type(value)
24520  * 
24521  */
24522         __pyx_t_1 = PyObject_GetAttr(__pyx_v_pytag, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24523         __Pyx_GOTREF(__pyx_t_1);
24524         __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_139), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24525         __Pyx_GOTREF(__pyx_t_7);
24526         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24527         __Pyx_DECREF(__pyx_v_pytag);
24528         __pyx_v_pytag = __pyx_t_7;
24529         __pyx_t_7 = 0;
24530         goto __pyx_L8;
24531       }
24532       __pyx_L8:;
24533
24534       /* "csamtools.pyx":2564
24535  *                     if not type(pytag) is bytes:
24536  *                         pytag = pytag.encode('ascii')
24537  *                     t = type(value)             # <<<<<<<<<<<<<<
24538  * 
24539  *                     if t is tuple or t is list:
24540  */
24541       __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
24542       __Pyx_XDECREF(((PyObject *)__pyx_v_t));
24543       __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));
24544
24545       /* "csamtools.pyx":2566
24546  *                     t = type(value)
24547  * 
24548  *                     if t is tuple or t is list:             # <<<<<<<<<<<<<<
24549  *                         # binary tags - treat separately
24550  *                         pytype = 'B'
24551  */
24552       __pyx_t_10 = (__pyx_v_t == ((PyObject*)(&PyTuple_Type)));
24553       if (!__pyx_t_10) {
24554         __pyx_t_3 = (__pyx_v_t == ((PyObject*)(&PyList_Type)));
24555         __pyx_t_11 = __pyx_t_3;
24556       } else {
24557         __pyx_t_11 = __pyx_t_10;
24558       }
24559       if (__pyx_t_11) {
24560
24561         /* "csamtools.pyx":2568
24562  *                     if t is tuple or t is list:
24563  *                         # binary tags - treat separately
24564  *                         pytype = 'B'             # <<<<<<<<<<<<<<
24565  *                         # get data type - first value determines type
24566  *                         if type(value[0]) is float:
24567  */
24568         __Pyx_INCREF(((PyObject *)__pyx_n_s__B));
24569         __Pyx_XDECREF(__pyx_v_pytype);
24570         __pyx_v_pytype = ((PyObject *)__pyx_n_s__B);
24571
24572         /* "csamtools.pyx":2570
24573  *                         pytype = 'B'
24574  *                         # get data type - first value determines type
24575  *                         if type(value[0]) is float:             # <<<<<<<<<<<<<<
24576  *                             datafmt, datatype = "f", "f"
24577  *                         else:
24578  */
24579         __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_value, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24580         __Pyx_GOTREF(__pyx_t_7);
24581         __pyx_t_11 = (((PyObject *)Py_TYPE(__pyx_t_7)) == ((PyObject *)((PyObject*)(&PyFloat_Type))));
24582         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
24583         if (__pyx_t_11) {
24584
24585           /* "csamtools.pyx":2571
24586  *                         # get data type - first value determines type
24587  *                         if type(value[0]) is float:
24588  *                             datafmt, datatype = "f", "f"             # <<<<<<<<<<<<<<
24589  *                         else:
24590  *                             mi, ma = min(value), max(value)
24591  */
24592           __pyx_t_7 = ((PyObject *)__pyx_n_s__f);
24593           __Pyx_INCREF(__pyx_t_7);
24594           __pyx_t_1 = ((PyObject *)__pyx_n_s__f);
24595           __Pyx_INCREF(__pyx_t_1);
24596           __Pyx_XDECREF(__pyx_v_datafmt);
24597           __pyx_v_datafmt = __pyx_t_7;
24598           __pyx_t_7 = 0;
24599           __Pyx_XDECREF(__pyx_v_datatype);
24600           __pyx_v_datatype = __pyx_t_1;
24601           __pyx_t_1 = 0;
24602           goto __pyx_L10;
24603         }
24604         /*else*/ {
24605
24606           /* "csamtools.pyx":2573
24607  *                             datafmt, datatype = "f", "f"
24608  *                         else:
24609  *                             mi, ma = min(value), max(value)             # <<<<<<<<<<<<<<
24610  *                             absmax = max( abs(mi), abs(ma) )
24611  *                             # signed ints
24612  */
24613           __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24614           __Pyx_GOTREF(__pyx_t_1);
24615           __Pyx_INCREF(__pyx_v_value);
24616           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
24617           __Pyx_GIVEREF(__pyx_v_value);
24618           __pyx_t_7 = PyObject_Call(__pyx_builtin_min, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24619           __Pyx_GOTREF(__pyx_t_7);
24620           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
24621           __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24622           __Pyx_GOTREF(__pyx_t_1);
24623           __Pyx_INCREF(__pyx_v_value);
24624           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
24625           __Pyx_GIVEREF(__pyx_v_value);
24626           __pyx_t_6 = PyObject_Call(__pyx_builtin_max, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24627           __Pyx_GOTREF(__pyx_t_6);
24628           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
24629           __Pyx_XDECREF(__pyx_v_mi);
24630           __pyx_v_mi = __pyx_t_7;
24631           __pyx_t_7 = 0;
24632           __Pyx_XDECREF(__pyx_v_ma);
24633           __pyx_v_ma = __pyx_t_6;
24634           __pyx_t_6 = 0;
24635
24636           /* "csamtools.pyx":2574
24637  *                         else:
24638  *                             mi, ma = min(value), max(value)
24639  *                             absmax = max( abs(mi), abs(ma) )             # <<<<<<<<<<<<<<
24640  *                             # signed ints
24641  *                             if mi < 0:
24642  */
24643           __pyx_t_6 = PyNumber_Absolute(__pyx_v_ma); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24644           __Pyx_GOTREF(__pyx_t_6);
24645           __pyx_t_7 = PyNumber_Absolute(__pyx_v_mi); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24646           __Pyx_GOTREF(__pyx_t_7);
24647           __pyx_t_8 = PyObject_RichCompare(__pyx_t_6, __pyx_t_7, Py_GT); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24648           __Pyx_GOTREF(__pyx_t_8);
24649           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24650           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
24651           if (__pyx_t_11) {
24652             __Pyx_INCREF(__pyx_t_6);
24653             __pyx_t_1 = __pyx_t_6;
24654           } else {
24655             __Pyx_INCREF(__pyx_t_7);
24656             __pyx_t_1 = __pyx_t_7;
24657           }
24658           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
24659           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24660           __Pyx_INCREF(__pyx_t_1);
24661           __Pyx_XDECREF(__pyx_v_absmax);
24662           __pyx_v_absmax = __pyx_t_1;
24663           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24664
24665           /* "csamtools.pyx":2576
24666  *                             absmax = max( abs(mi), abs(ma) )
24667  *                             # signed ints
24668  *                             if mi < 0:             # <<<<<<<<<<<<<<
24669  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
24670  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
24671  */
24672           __pyx_t_1 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24673           __Pyx_GOTREF(__pyx_t_1);
24674           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24675           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24676           if (__pyx_t_11) {
24677
24678             /* "csamtools.pyx":2577
24679  *                             # signed ints
24680  *                             if mi < 0:
24681  *                                 if mi >= -127: datafmt, datatype = "b", 'c'             # <<<<<<<<<<<<<<
24682  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
24683  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24684  */
24685             __pyx_t_1 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_127, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24686             __Pyx_GOTREF(__pyx_t_1);
24687             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24688             __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24689             if (__pyx_t_11) {
24690               __pyx_t_1 = ((PyObject *)__pyx_n_s__b);
24691               __Pyx_INCREF(__pyx_t_1);
24692               __pyx_t_6 = ((PyObject *)__pyx_n_s__c);
24693               __Pyx_INCREF(__pyx_t_6);
24694               __Pyx_XDECREF(__pyx_v_datafmt);
24695               __pyx_v_datafmt = __pyx_t_1;
24696               __pyx_t_1 = 0;
24697               __Pyx_XDECREF(__pyx_v_datatype);
24698               __pyx_v_datatype = __pyx_t_6;
24699               __pyx_t_6 = 0;
24700               goto __pyx_L12;
24701             }
24702
24703             /* "csamtools.pyx":2578
24704  *                             if mi < 0:
24705  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
24706  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'             # <<<<<<<<<<<<<<
24707  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24708  *                                 else: datafmt, datatype = "i", 'i'
24709  */
24710             __pyx_t_6 = PyObject_RichCompare(__pyx_v_mi, __pyx_int_neg_32767, Py_GE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24711             __Pyx_GOTREF(__pyx_t_6);
24712             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24713             __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24714             if (__pyx_t_11) {
24715               __pyx_t_6 = ((PyObject *)__pyx_n_s__h);
24716               __Pyx_INCREF(__pyx_t_6);
24717               __pyx_t_1 = ((PyObject *)__pyx_n_s__s);
24718               __Pyx_INCREF(__pyx_t_1);
24719               __Pyx_XDECREF(__pyx_v_datafmt);
24720               __pyx_v_datafmt = __pyx_t_6;
24721               __pyx_t_6 = 0;
24722               __Pyx_XDECREF(__pyx_v_datatype);
24723               __pyx_v_datatype = __pyx_t_1;
24724               __pyx_t_1 = 0;
24725               goto __pyx_L12;
24726             }
24727
24728             /* "csamtools.pyx":2579
24729  *                                 if mi >= -127: datafmt, datatype = "b", 'c'
24730  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
24731  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
24732  *                                 else: datafmt, datatype = "i", 'i'
24733  * 
24734  */
24735             __pyx_t_1 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_neg_2147483648, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24736             __Pyx_GOTREF(__pyx_t_1);
24737             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24738             __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24739             if (__pyx_t_11) {
24740               __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_140), __pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24741               __Pyx_GOTREF(((PyObject *)__pyx_t_1));
24742               __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24743               __Pyx_GOTREF(__pyx_t_6);
24744               PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1));
24745               __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
24746               __pyx_t_1 = 0;
24747               __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 = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24748               __Pyx_GOTREF(__pyx_t_1);
24749               __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
24750               __Pyx_Raise(__pyx_t_1, 0, 0, 0);
24751               __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24752               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24753               goto __pyx_L12;
24754             }
24755             /*else*/ {
24756
24757               /* "csamtools.pyx":2580
24758  *                                 elif mi >= -32767: datafmt, datatype = "h", 's'
24759  *                                 elif absmax < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24760  *                                 else: datafmt, datatype = "i", 'i'             # <<<<<<<<<<<<<<
24761  * 
24762  *                             # unsigned ints
24763  */
24764               __pyx_t_1 = ((PyObject *)__pyx_n_s__i);
24765               __Pyx_INCREF(__pyx_t_1);
24766               __pyx_t_6 = ((PyObject *)__pyx_n_s__i);
24767               __Pyx_INCREF(__pyx_t_6);
24768               __Pyx_XDECREF(__pyx_v_datafmt);
24769               __pyx_v_datafmt = __pyx_t_1;
24770               __pyx_t_1 = 0;
24771               __Pyx_XDECREF(__pyx_v_datatype);
24772               __pyx_v_datatype = __pyx_t_6;
24773               __pyx_t_6 = 0;
24774             }
24775             __pyx_L12:;
24776             goto __pyx_L11;
24777           }
24778           /*else*/ {
24779
24780             /* "csamtools.pyx":2584
24781  *                             # unsigned ints
24782  *                             else:
24783  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'             # <<<<<<<<<<<<<<
24784  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
24785  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24786  */
24787             __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_255, Py_LE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24788             __Pyx_GOTREF(__pyx_t_6);
24789             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2584; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24790             __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24791             if (__pyx_t_11) {
24792               __pyx_t_6 = ((PyObject *)__pyx_n_s__B);
24793               __Pyx_INCREF(__pyx_t_6);
24794               __pyx_t_1 = ((PyObject *)__pyx_n_s__C);
24795               __Pyx_INCREF(__pyx_t_1);
24796               __Pyx_XDECREF(__pyx_v_datafmt);
24797               __pyx_v_datafmt = __pyx_t_6;
24798               __pyx_t_6 = 0;
24799               __Pyx_XDECREF(__pyx_v_datatype);
24800               __pyx_v_datatype = __pyx_t_1;
24801               __pyx_t_1 = 0;
24802               goto __pyx_L13;
24803             }
24804
24805             /* "csamtools.pyx":2585
24806  *                             else:
24807  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'
24808  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'             # <<<<<<<<<<<<<<
24809  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24810  *                                 else: datafmt, datatype = "I", 'I'
24811  */
24812             __pyx_t_1 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_65535, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24813             __Pyx_GOTREF(__pyx_t_1);
24814             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24815             __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24816             if (__pyx_t_11) {
24817               __pyx_t_1 = ((PyObject *)__pyx_n_s__H);
24818               __Pyx_INCREF(__pyx_t_1);
24819               __pyx_t_6 = ((PyObject *)__pyx_n_s__S);
24820               __Pyx_INCREF(__pyx_t_6);
24821               __Pyx_XDECREF(__pyx_v_datafmt);
24822               __pyx_v_datafmt = __pyx_t_1;
24823               __pyx_t_1 = 0;
24824               __Pyx_XDECREF(__pyx_v_datatype);
24825               __pyx_v_datatype = __pyx_t_6;
24826               __pyx_t_6 = 0;
24827               goto __pyx_L13;
24828             }
24829
24830             /* "csamtools.pyx":2586
24831  *                                 if absmax <= 255: datafmt, datatype = "B", 'C'
24832  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
24833  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
24834  *                                 else: datafmt, datatype = "I", 'I'
24835  * 
24836  */
24837             __pyx_t_6 = PyObject_RichCompare(__pyx_v_absmax, __pyx_int_4294967295, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24838             __Pyx_GOTREF(__pyx_t_6);
24839             __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24840             __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24841             if (__pyx_t_11) {
24842               __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_140), __pyx_v_value); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24843               __Pyx_GOTREF(((PyObject *)__pyx_t_6));
24844               __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24845               __Pyx_GOTREF(__pyx_t_1);
24846               PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_6));
24847               __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
24848               __pyx_t_6 = 0;
24849               __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24850               __Pyx_GOTREF(__pyx_t_6);
24851               __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
24852               __Pyx_Raise(__pyx_t_6, 0, 0, 0);
24853               __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24854               {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24855               goto __pyx_L13;
24856             }
24857             /*else*/ {
24858
24859               /* "csamtools.pyx":2587
24860  *                                 elif absmax <= 65535: datafmt, datatype = "H", 'S'
24861  *                                 elif absmax > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
24862  *                                 else: datafmt, datatype = "I", 'I'             # <<<<<<<<<<<<<<
24863  * 
24864  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
24865  */
24866               __pyx_t_6 = ((PyObject *)__pyx_n_s__I);
24867               __Pyx_INCREF(__pyx_t_6);
24868               __pyx_t_1 = ((PyObject *)__pyx_n_s__I);
24869               __Pyx_INCREF(__pyx_t_1);
24870               __Pyx_XDECREF(__pyx_v_datafmt);
24871               __pyx_v_datafmt = __pyx_t_6;
24872               __pyx_t_6 = 0;
24873               __Pyx_XDECREF(__pyx_v_datatype);
24874               __pyx_v_datatype = __pyx_t_1;
24875               __pyx_t_1 = 0;
24876             }
24877             __pyx_L13:;
24878           }
24879           __pyx_L11:;
24880         }
24881         __pyx_L10:;
24882
24883         /* "csamtools.pyx":2589
24884  *                                 else: datafmt, datatype = "I", 'I'
24885  * 
24886  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)             # <<<<<<<<<<<<<<
24887  *                         args.extend( [pytag[:2],
24888  *                                       pytype.encode('ascii'),
24889  */
24890         __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24891         __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24892         __Pyx_GOTREF(__pyx_t_1);
24893         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24894         __Pyx_GOTREF(__pyx_t_6);
24895         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
24896         __Pyx_GIVEREF(__pyx_t_1);
24897         __Pyx_INCREF(__pyx_v_datafmt);
24898         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_datafmt);
24899         __Pyx_GIVEREF(__pyx_v_datafmt);
24900         __pyx_t_1 = 0;
24901         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_141), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24902         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
24903         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
24904         __Pyx_DECREF(__pyx_v_datafmt);
24905         __pyx_v_datafmt = ((PyObject *)__pyx_t_1);
24906         __pyx_t_1 = 0;
24907
24908         /* "csamtools.pyx":2590
24909  * 
24910  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
24911  *                         args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
24912  *                                       pytype.encode('ascii'),
24913  *                                       datatype.encode('ascii'),
24914  */
24915         __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24916         __Pyx_GOTREF(__pyx_t_1);
24917
24918         /* "csamtools.pyx":2593
24919  *                                       pytype.encode('ascii'),
24920  *                                       datatype.encode('ascii'),
24921  *                                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
24922  *                         fmts.append( datafmt )
24923  *                         continue
24924  */
24925         __pyx_t_6 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24926         __Pyx_GOTREF(__pyx_t_6);
24927
24928         /* "csamtools.pyx":2591
24929  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
24930  *                         args.extend( [pytag[:2],
24931  *                                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
24932  *                                       datatype.encode('ascii'),
24933  *                                       len(value)] + list(value) )
24934  */
24935         __pyx_t_7 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24936         __Pyx_GOTREF(__pyx_t_7);
24937         __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_142), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24938         __Pyx_GOTREF(__pyx_t_8);
24939         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
24940
24941         /* "csamtools.pyx":2592
24942  *                         args.extend( [pytag[:2],
24943  *                                       pytype.encode('ascii'),
24944  *                                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
24945  *                                       len(value)] + list(value) )
24946  *                         fmts.append( datafmt )
24947  */
24948         __pyx_t_7 = PyObject_GetAttr(__pyx_v_datatype, __pyx_n_s__encode); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24949         __Pyx_GOTREF(__pyx_t_7);
24950         __pyx_t_13 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_143), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24951         __Pyx_GOTREF(__pyx_t_13);
24952         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
24953
24954         /* "csamtools.pyx":2593
24955  *                                       pytype.encode('ascii'),
24956  *                                       datatype.encode('ascii'),
24957  *                                       len(value)] + list(value) )             # <<<<<<<<<<<<<<
24958  *                         fmts.append( datafmt )
24959  *                         continue
24960  */
24961         __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24962         __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_12); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24963         __Pyx_GOTREF(__pyx_t_7);
24964         __pyx_t_14 = PyList_New(4); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24965         __Pyx_GOTREF(__pyx_t_14);
24966         PyList_SET_ITEM(__pyx_t_14, 0, __pyx_t_6);
24967         __Pyx_GIVEREF(__pyx_t_6);
24968         PyList_SET_ITEM(__pyx_t_14, 1, __pyx_t_8);
24969         __Pyx_GIVEREF(__pyx_t_8);
24970         PyList_SET_ITEM(__pyx_t_14, 2, __pyx_t_13);
24971         __Pyx_GIVEREF(__pyx_t_13);
24972         PyList_SET_ITEM(__pyx_t_14, 3, __pyx_t_7);
24973         __Pyx_GIVEREF(__pyx_t_7);
24974         __pyx_t_6 = 0;
24975         __pyx_t_8 = 0;
24976         __pyx_t_13 = 0;
24977         __pyx_t_7 = 0;
24978         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24979         __Pyx_GOTREF(__pyx_t_7);
24980         __Pyx_INCREF(__pyx_v_value);
24981         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_value);
24982         __Pyx_GIVEREF(__pyx_v_value);
24983         __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24984         __Pyx_GOTREF(__pyx_t_13);
24985         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
24986         __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_t_14), __pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24987         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
24988         __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
24989         __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
24990         __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24991         __Pyx_GOTREF(__pyx_t_13);
24992         PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_7));
24993         __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
24994         __pyx_t_7 = 0;
24995         __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24996         __Pyx_GOTREF(__pyx_t_7);
24997         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24998         __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
24999         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
25000
25001         /* "csamtools.pyx":2594
25002  *                                       datatype.encode('ascii'),
25003  *                                       len(value)] + list(value) )
25004  *                         fmts.append( datafmt )             # <<<<<<<<<<<<<<
25005  *                         continue
25006  * 
25007  */
25008         __pyx_t_15 = PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25009
25010         /* "csamtools.pyx":2595
25011  *                                       len(value)] + list(value) )
25012  *                         fmts.append( datafmt )
25013  *                         continue             # <<<<<<<<<<<<<<
25014  * 
25015  *                     if t is float:
25016  */
25017         goto __pyx_L4_continue;
25018         goto __pyx_L9;
25019       }
25020       __pyx_L9:;
25021
25022       /* "csamtools.pyx":2597
25023  *                         continue
25024  * 
25025  *                     if t is float:             # <<<<<<<<<<<<<<
25026  *                         fmt, pytype = "2scf", 'f'
25027  *                     elif t is int:
25028  */
25029       __pyx_t_11 = (__pyx_v_t == ((PyObject*)(&PyFloat_Type)));
25030       if (__pyx_t_11) {
25031
25032         /* "csamtools.pyx":2598
25033  * 
25034  *                     if t is float:
25035  *                         fmt, pytype = "2scf", 'f'             # <<<<<<<<<<<<<<
25036  *                     elif t is int:
25037  *                         # negative values
25038  */
25039         __pyx_t_7 = ((PyObject *)__pyx_kp_s__2scf);
25040         __Pyx_INCREF(__pyx_t_7);
25041         __pyx_t_13 = ((PyObject *)__pyx_n_s__f);
25042         __Pyx_INCREF(__pyx_t_13);
25043         __Pyx_XDECREF(__pyx_v_fmt);
25044         __pyx_v_fmt = __pyx_t_7;
25045         __pyx_t_7 = 0;
25046         __Pyx_XDECREF(__pyx_v_pytype);
25047         __pyx_v_pytype = __pyx_t_13;
25048         __pyx_t_13 = 0;
25049         goto __pyx_L14;
25050       }
25051
25052       /* "csamtools.pyx":2599
25053  *                     if t is float:
25054  *                         fmt, pytype = "2scf", 'f'
25055  *                     elif t is int:             # <<<<<<<<<<<<<<
25056  *                         # negative values
25057  *                         if value < 0:
25058  */
25059       __pyx_t_11 = (__pyx_v_t == ((PyObject*)(&PyInt_Type)));
25060       if (__pyx_t_11) {
25061
25062         /* "csamtools.pyx":2601
25063  *                     elif t is int:
25064  *                         # negative values
25065  *                         if value < 0:             # <<<<<<<<<<<<<<
25066  *                             if value >= -127: fmt, pytype = "2scb", 'c'
25067  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
25068  */
25069         __pyx_t_13 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25070         __Pyx_GOTREF(__pyx_t_13);
25071         __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25072         __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25073         if (__pyx_t_11) {
25074
25075           /* "csamtools.pyx":2602
25076  *                         # negative values
25077  *                         if value < 0:
25078  *                             if value >= -127: fmt, pytype = "2scb", 'c'             # <<<<<<<<<<<<<<
25079  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
25080  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25081  */
25082           __pyx_t_13 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25083           __Pyx_GOTREF(__pyx_t_13);
25084           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25085           __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25086           if (__pyx_t_11) {
25087             __pyx_t_13 = ((PyObject *)__pyx_kp_s__2scb);
25088             __Pyx_INCREF(__pyx_t_13);
25089             __pyx_t_7 = ((PyObject *)__pyx_n_s__c);
25090             __Pyx_INCREF(__pyx_t_7);
25091             __Pyx_XDECREF(__pyx_v_fmt);
25092             __pyx_v_fmt = __pyx_t_13;
25093             __pyx_t_13 = 0;
25094             __Pyx_XDECREF(__pyx_v_pytype);
25095             __pyx_v_pytype = __pyx_t_7;
25096             __pyx_t_7 = 0;
25097             goto __pyx_L16;
25098           }
25099
25100           /* "csamtools.pyx":2603
25101  *                         if value < 0:
25102  *                             if value >= -127: fmt, pytype = "2scb", 'c'
25103  *                             elif value >= -32767: fmt, pytype = "2sch", 's'             # <<<<<<<<<<<<<<
25104  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25105  *                             else: fmt, pytype = "2sci", 'i'
25106  */
25107           __pyx_t_7 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25108           __Pyx_GOTREF(__pyx_t_7);
25109           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25110           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
25111           if (__pyx_t_11) {
25112             __pyx_t_7 = ((PyObject *)__pyx_kp_s__2sch);
25113             __Pyx_INCREF(__pyx_t_7);
25114             __pyx_t_13 = ((PyObject *)__pyx_n_s__s);
25115             __Pyx_INCREF(__pyx_t_13);
25116             __Pyx_XDECREF(__pyx_v_fmt);
25117             __pyx_v_fmt = __pyx_t_7;
25118             __pyx_t_7 = 0;
25119             __Pyx_XDECREF(__pyx_v_pytype);
25120             __pyx_v_pytype = __pyx_t_13;
25121             __pyx_t_13 = 0;
25122             goto __pyx_L16;
25123           }
25124
25125           /* "csamtools.pyx":2604
25126  *                             if value >= -127: fmt, pytype = "2scb", 'c'
25127  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
25128  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
25129  *                             else: fmt, pytype = "2sci", 'i'
25130  *                         # positive values
25131  */
25132           __pyx_t_13 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25133           __Pyx_GOTREF(__pyx_t_13);
25134           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25135           __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25136           if (__pyx_t_11) {
25137             __pyx_t_13 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_140), __pyx_v_value); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25138             __Pyx_GOTREF(((PyObject *)__pyx_t_13));
25139             __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25140             __Pyx_GOTREF(__pyx_t_7);
25141             PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_13));
25142             __Pyx_GIVEREF(((PyObject *)__pyx_t_13));
25143             __pyx_t_13 = 0;
25144             __pyx_t_13 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25145             __Pyx_GOTREF(__pyx_t_13);
25146             __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
25147             __Pyx_Raise(__pyx_t_13, 0, 0, 0);
25148             __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25149             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25150             goto __pyx_L16;
25151           }
25152           /*else*/ {
25153
25154             /* "csamtools.pyx":2605
25155  *                             elif value >= -32767: fmt, pytype = "2sch", 's'
25156  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25157  *                             else: fmt, pytype = "2sci", 'i'             # <<<<<<<<<<<<<<
25158  *                         # positive values
25159  *                         else:
25160  */
25161             __pyx_t_13 = ((PyObject *)__pyx_kp_s__2sci);
25162             __Pyx_INCREF(__pyx_t_13);
25163             __pyx_t_7 = ((PyObject *)__pyx_n_s__i);
25164             __Pyx_INCREF(__pyx_t_7);
25165             __Pyx_XDECREF(__pyx_v_fmt);
25166             __pyx_v_fmt = __pyx_t_13;
25167             __pyx_t_13 = 0;
25168             __Pyx_XDECREF(__pyx_v_pytype);
25169             __pyx_v_pytype = __pyx_t_7;
25170             __pyx_t_7 = 0;
25171           }
25172           __pyx_L16:;
25173           goto __pyx_L15;
25174         }
25175         /*else*/ {
25176
25177           /* "csamtools.pyx":2608
25178  *                         # positive values
25179  *                         else:
25180  *                             if value <= 255: fmt, pytype = "2scB", 'C'             # <<<<<<<<<<<<<<
25181  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
25182  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25183  */
25184           __pyx_t_7 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25185           __Pyx_GOTREF(__pyx_t_7);
25186           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25187           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
25188           if (__pyx_t_11) {
25189             __pyx_t_7 = ((PyObject *)__pyx_kp_s__2scB);
25190             __Pyx_INCREF(__pyx_t_7);
25191             __pyx_t_13 = ((PyObject *)__pyx_n_s__C);
25192             __Pyx_INCREF(__pyx_t_13);
25193             __Pyx_XDECREF(__pyx_v_fmt);
25194             __pyx_v_fmt = __pyx_t_7;
25195             __pyx_t_7 = 0;
25196             __Pyx_XDECREF(__pyx_v_pytype);
25197             __pyx_v_pytype = __pyx_t_13;
25198             __pyx_t_13 = 0;
25199             goto __pyx_L17;
25200           }
25201
25202           /* "csamtools.pyx":2609
25203  *                         else:
25204  *                             if value <= 255: fmt, pytype = "2scB", 'C'
25205  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'             # <<<<<<<<<<<<<<
25206  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25207  *                             else: fmt, pytype = "2scI", 'I'
25208  */
25209           __pyx_t_13 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25210           __Pyx_GOTREF(__pyx_t_13);
25211           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25212           __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25213           if (__pyx_t_11) {
25214             __pyx_t_13 = ((PyObject *)__pyx_kp_s__2scH);
25215             __Pyx_INCREF(__pyx_t_13);
25216             __pyx_t_7 = ((PyObject *)__pyx_n_s__S);
25217             __Pyx_INCREF(__pyx_t_7);
25218             __Pyx_XDECREF(__pyx_v_fmt);
25219             __pyx_v_fmt = __pyx_t_13;
25220             __pyx_t_13 = 0;
25221             __Pyx_XDECREF(__pyx_v_pytype);
25222             __pyx_v_pytype = __pyx_t_7;
25223             __pyx_t_7 = 0;
25224             goto __pyx_L17;
25225           }
25226
25227           /* "csamtools.pyx":2610
25228  *                             if value <= 255: fmt, pytype = "2scB", 'C'
25229  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
25230  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
25231  *                             else: fmt, pytype = "2scI", 'I'
25232  *                     else:
25233  */
25234           __pyx_t_7 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25235           __Pyx_GOTREF(__pyx_t_7);
25236           __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25237           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
25238           if (__pyx_t_11) {
25239             __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_140), __pyx_v_value); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25240             __Pyx_GOTREF(((PyObject *)__pyx_t_7));
25241             __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25242             __Pyx_GOTREF(__pyx_t_13);
25243             PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_7));
25244             __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
25245             __pyx_t_7 = 0;
25246             __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25247             __Pyx_GOTREF(__pyx_t_7);
25248             __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
25249             __Pyx_Raise(__pyx_t_7, 0, 0, 0);
25250             __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
25251             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25252             goto __pyx_L17;
25253           }
25254           /*else*/ {
25255
25256             /* "csamtools.pyx":2611
25257  *                             elif value <= 65535: fmt, pytype = "2scH", 'S'
25258  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
25259  *                             else: fmt, pytype = "2scI", 'I'             # <<<<<<<<<<<<<<
25260  *                     else:
25261  *                         # Note: hex strings (H) are not supported yet
25262  */
25263             __pyx_t_7 = ((PyObject *)__pyx_kp_s__2scI);
25264             __Pyx_INCREF(__pyx_t_7);
25265             __pyx_t_13 = ((PyObject *)__pyx_n_s__I);
25266             __Pyx_INCREF(__pyx_t_13);
25267             __Pyx_XDECREF(__pyx_v_fmt);
25268             __pyx_v_fmt = __pyx_t_7;
25269             __pyx_t_7 = 0;
25270             __Pyx_XDECREF(__pyx_v_pytype);
25271             __pyx_v_pytype = __pyx_t_13;
25272             __pyx_t_13 = 0;
25273           }
25274           __pyx_L17:;
25275         }
25276         __pyx_L15:;
25277         goto __pyx_L14;
25278       }
25279       /*else*/ {
25280
25281         /* "csamtools.pyx":2614
25282  *                     else:
25283  *                         # Note: hex strings (H) are not supported yet
25284  *                         if t is not bytes:             # <<<<<<<<<<<<<<
25285  *                             value = value.encode('ascii')
25286  *                         if len(value) == 1:
25287  */
25288         __pyx_t_11 = (__pyx_v_t != ((PyObject*)(&PyBytes_Type)));
25289         if (__pyx_t_11) {
25290
25291           /* "csamtools.pyx":2615
25292  *                         # Note: hex strings (H) are not supported yet
25293  *                         if t is not bytes:
25294  *                             value = value.encode('ascii')             # <<<<<<<<<<<<<<
25295  *                         if len(value) == 1:
25296  *                             fmt, pytype = "2scc", 'A'
25297  */
25298           __pyx_t_13 = PyObject_GetAttr(__pyx_v_value, __pyx_n_s__encode); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25299           __Pyx_GOTREF(__pyx_t_13);
25300           __pyx_t_7 = PyObject_Call(__pyx_t_13, ((PyObject *)__pyx_k_tuple_144), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25301           __Pyx_GOTREF(__pyx_t_7);
25302           __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25303           __Pyx_DECREF(__pyx_v_value);
25304           __pyx_v_value = __pyx_t_7;
25305           __pyx_t_7 = 0;
25306           goto __pyx_L18;
25307         }
25308         __pyx_L18:;
25309
25310         /* "csamtools.pyx":2616
25311  *                         if t is not bytes:
25312  *                             value = value.encode('ascii')
25313  *                         if len(value) == 1:             # <<<<<<<<<<<<<<
25314  *                             fmt, pytype = "2scc", 'A'
25315  *                         else:
25316  */
25317         __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25318         __pyx_t_11 = (__pyx_t_12 == 1);
25319         if (__pyx_t_11) {
25320
25321           /* "csamtools.pyx":2617
25322  *                             value = value.encode('ascii')
25323  *                         if len(value) == 1:
25324  *                             fmt, pytype = "2scc", 'A'             # <<<<<<<<<<<<<<
25325  *                         else:
25326  *                             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
25327  */
25328           __pyx_t_7 = ((PyObject *)__pyx_kp_s__2scc);
25329           __Pyx_INCREF(__pyx_t_7);
25330           __pyx_t_13 = ((PyObject *)__pyx_n_s__A);
25331           __Pyx_INCREF(__pyx_t_13);
25332           __Pyx_XDECREF(__pyx_v_fmt);
25333           __pyx_v_fmt = __pyx_t_7;
25334           __pyx_t_7 = 0;
25335           __Pyx_XDECREF(__pyx_v_pytype);
25336           __pyx_v_pytype = __pyx_t_13;
25337           __pyx_t_13 = 0;
25338           goto __pyx_L19;
25339         }
25340         /*else*/ {
25341
25342           /* "csamtools.pyx":2619
25343  *                             fmt, pytype = "2scc", 'A'
25344  *                         else:
25345  *                             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
25346  * 
25347  *                     args.extend( [pytag[:2],
25348  */
25349           __pyx_t_12 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25350           __pyx_t_13 = PyInt_FromSsize_t((__pyx_t_12 + 1)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25351           __Pyx_GOTREF(__pyx_t_13);
25352           __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_145), __pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25353           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
25354           __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25355           __pyx_t_13 = ((PyObject *)__pyx_n_s__Z);
25356           __Pyx_INCREF(__pyx_t_13);
25357           __Pyx_XDECREF(__pyx_v_fmt);
25358           __pyx_v_fmt = ((PyObject *)__pyx_t_7);
25359           __pyx_t_7 = 0;
25360           __Pyx_XDECREF(__pyx_v_pytype);
25361           __pyx_v_pytype = __pyx_t_13;
25362           __pyx_t_13 = 0;
25363         }
25364         __pyx_L19:;
25365       }
25366       __pyx_L14:;
25367
25368       /* "csamtools.pyx":2621
25369  *                             fmt, pytype = "2sc%is" % (len(value)+1), 'Z'
25370  * 
25371  *                     args.extend( [pytag[:2],             # <<<<<<<<<<<<<<
25372  *                                   pytype.encode('ascii'),
25373  *                                   value ] )
25374  */
25375       __pyx_t_13 = PyObject_GetAttr(((PyObject *)__pyx_v_args), __pyx_n_s__extend); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25376       __Pyx_GOTREF(__pyx_t_13);
25377       __pyx_t_7 = __Pyx_PySequence_GetSlice(__pyx_v_pytag, 0, 2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25378       __Pyx_GOTREF(__pyx_t_7);
25379
25380       /* "csamtools.pyx":2622
25381  * 
25382  *                     args.extend( [pytag[:2],
25383  *                                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
25384  *                                   value ] )
25385  * 
25386  */
25387       __pyx_t_1 = PyObject_GetAttr(__pyx_v_pytype, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25388       __Pyx_GOTREF(__pyx_t_1);
25389       __pyx_t_14 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_146), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25390       __Pyx_GOTREF(__pyx_t_14);
25391       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25392
25393       /* "csamtools.pyx":2623
25394  *                     args.extend( [pytag[:2],
25395  *                                   pytype.encode('ascii'),
25396  *                                   value ] )             # <<<<<<<<<<<<<<
25397  * 
25398  *                     fmts.append( fmt )
25399  */
25400       __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25401       __Pyx_GOTREF(__pyx_t_1);
25402       PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
25403       __Pyx_GIVEREF(__pyx_t_7);
25404       PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_14);
25405       __Pyx_GIVEREF(__pyx_t_14);
25406       __Pyx_INCREF(__pyx_v_value);
25407       PyList_SET_ITEM(__pyx_t_1, 2, __pyx_v_value);
25408       __Pyx_GIVEREF(__pyx_v_value);
25409       __pyx_t_7 = 0;
25410       __pyx_t_14 = 0;
25411       __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25412       __Pyx_GOTREF(__pyx_t_14);
25413       PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_t_1));
25414       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
25415       __pyx_t_1 = 0;
25416       __pyx_t_1 = PyObject_Call(__pyx_t_13, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25417       __Pyx_GOTREF(__pyx_t_1);
25418       __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
25419       __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
25420       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25421
25422       /* "csamtools.pyx":2625
25423  *                                   value ] )
25424  * 
25425  *                     fmts.append( fmt )             # <<<<<<<<<<<<<<
25426  * 
25427  *                 fmt = "".join(fmts)
25428  */
25429       __pyx_t_15 = PyList_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25430       __pyx_L4_continue:;
25431     }
25432     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25433
25434     /* "csamtools.pyx":2627
25435  *                     fmts.append( fmt )
25436  * 
25437  *                 fmt = "".join(fmts)             # <<<<<<<<<<<<<<
25438  *                 total_size = struct.calcsize(fmt)
25439  *                 buffer = ctypes.create_string_buffer(total_size)
25440  */
25441     __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_16), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25442     __Pyx_GOTREF(__pyx_t_2);
25443     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25444     __Pyx_GOTREF(__pyx_t_1);
25445     __Pyx_INCREF(((PyObject *)__pyx_v_fmts));
25446     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_fmts));
25447     __Pyx_GIVEREF(((PyObject *)__pyx_v_fmts));
25448     __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25449     __Pyx_GOTREF(__pyx_t_14);
25450     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25451     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25452     __Pyx_XDECREF(__pyx_v_fmt);
25453     __pyx_v_fmt = __pyx_t_14;
25454     __pyx_t_14 = 0;
25455
25456     /* "csamtools.pyx":2628
25457  * 
25458  *                 fmt = "".join(fmts)
25459  *                 total_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
25460  *                 buffer = ctypes.create_string_buffer(total_size)
25461  *                 struct.pack_into( fmt,
25462  */
25463     __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25464     __Pyx_GOTREF(__pyx_t_14);
25465     __pyx_t_1 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__calcsize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25466     __Pyx_GOTREF(__pyx_t_1);
25467     __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
25468     __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25469     __Pyx_GOTREF(__pyx_t_14);
25470     __Pyx_INCREF(__pyx_v_fmt);
25471     PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_fmt);
25472     __Pyx_GIVEREF(__pyx_v_fmt);
25473     __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25474     __Pyx_GOTREF(__pyx_t_2);
25475     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25476     __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
25477     __pyx_v_total_size = __pyx_t_2;
25478     __pyx_t_2 = 0;
25479
25480     /* "csamtools.pyx":2629
25481  *                 fmt = "".join(fmts)
25482  *                 total_size = struct.calcsize(fmt)
25483  *                 buffer = ctypes.create_string_buffer(total_size)             # <<<<<<<<<<<<<<
25484  *                 struct.pack_into( fmt,
25485  *                                   buffer,
25486  */
25487     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__ctypes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25488     __Pyx_GOTREF(__pyx_t_2);
25489     __pyx_t_14 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s_147); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25490     __Pyx_GOTREF(__pyx_t_14);
25491     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25492     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25493     __Pyx_GOTREF(__pyx_t_2);
25494     __Pyx_INCREF(__pyx_v_total_size);
25495     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_total_size);
25496     __Pyx_GIVEREF(__pyx_v_total_size);
25497     __pyx_t_1 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25498     __Pyx_GOTREF(__pyx_t_1);
25499     __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
25500     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
25501     __pyx_v_buffer = __pyx_t_1;
25502     __pyx_t_1 = 0;
25503
25504     /* "csamtools.pyx":2630
25505  *                 total_size = struct.calcsize(fmt)
25506  *                 buffer = ctypes.create_string_buffer(total_size)
25507  *                 struct.pack_into( fmt,             # <<<<<<<<<<<<<<
25508  *                                   buffer,
25509  *                                   0,
25510  */
25511     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25512     __Pyx_GOTREF(__pyx_t_1);
25513     __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__pack_into); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25514     __Pyx_GOTREF(__pyx_t_2);
25515     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25516
25517     /* "csamtools.pyx":2631
25518  *                 buffer = ctypes.create_string_buffer(total_size)
25519  *                 struct.pack_into( fmt,
25520  *                                   buffer,             # <<<<<<<<<<<<<<
25521  *                                   0,
25522  *                                   *args )
25523  */
25524     __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25525     __Pyx_GOTREF(__pyx_t_1);
25526     __Pyx_INCREF(__pyx_v_fmt);
25527     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fmt);
25528     __Pyx_GIVEREF(__pyx_v_fmt);
25529     __Pyx_INCREF(__pyx_v_buffer);
25530     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_buffer);
25531     __Pyx_GIVEREF(__pyx_v_buffer);
25532     __Pyx_INCREF(__pyx_int_0);
25533     PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
25534     __Pyx_GIVEREF(__pyx_int_0);
25535
25536     /* "csamtools.pyx":2633
25537  *                                   buffer,
25538  *                                   0,
25539  *                                   *args )             # <<<<<<<<<<<<<<
25540  * 
25541  *             # delete the old data and allocate new space.
25542  */
25543     __pyx_t_14 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25544     __Pyx_GOTREF(((PyObject *)__pyx_t_14));
25545     __pyx_t_13 = PyNumber_Add(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25546     __Pyx_GOTREF(((PyObject *)__pyx_t_13));
25547     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25548     __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0;
25549     __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25550     __Pyx_GOTREF(__pyx_t_14);
25551     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25552     __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
25553     __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
25554     goto __pyx_L3;
25555   }
25556   __pyx_L3:;
25557
25558   /* "csamtools.pyx":2640
25559  *             pysam_bam_update( src,
25560  *                               src.l_aux,
25561  *                               total_size,             # <<<<<<<<<<<<<<
25562  *                               bam1_aux( src ) )
25563  * 
25564  */
25565   if (unlikely(!__pyx_v_total_size)) { __Pyx_RaiseUnboundLocalError("total_size"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
25566   __pyx_t_16 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_16 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25567
25568   /* "csamtools.pyx":2641
25569  *                               src.l_aux,
25570  *                               total_size,
25571  *                               bam1_aux( src ) )             # <<<<<<<<<<<<<<
25572  * 
25573  *             src.l_aux = total_size
25574  */
25575   pysam_bam_update(__pyx_v_src, __pyx_v_src->l_aux, __pyx_t_16, bam1_aux(__pyx_v_src));
25576
25577   /* "csamtools.pyx":2643
25578  *                               bam1_aux( src ) )
25579  * 
25580  *             src.l_aux = total_size             # <<<<<<<<<<<<<<
25581  * 
25582  *             # copy data only if there is any
25583  */
25584   __pyx_t_17 = __Pyx_PyInt_AsInt(__pyx_v_total_size); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25585   __pyx_v_src->l_aux = __pyx_t_17;
25586
25587   /* "csamtools.pyx":2646
25588  * 
25589  *             # copy data only if there is any
25590  *             if total_size != 0:             # <<<<<<<<<<<<<<
25591  * 
25592  *                 # get location of new data
25593  */
25594   __pyx_t_14 = PyObject_RichCompare(__pyx_v_total_size, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25595   __Pyx_GOTREF(__pyx_t_14);
25596   __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25597   __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
25598   if (__pyx_t_11) {
25599
25600     /* "csamtools.pyx":2649
25601  * 
25602  *                 # get location of new data
25603  *                 s = bam1_aux( src )             # <<<<<<<<<<<<<<
25604  * 
25605  *                 # check if there is direct path from buffer.raw to tmp
25606  */
25607     __pyx_v_s = bam1_aux(__pyx_v_src);
25608
25609     /* "csamtools.pyx":2652
25610  * 
25611  *                 # check if there is direct path from buffer.raw to tmp
25612  *                 temp = buffer.raw             # <<<<<<<<<<<<<<
25613  *                 memcpy( s, temp, total_size )
25614  * 
25615  */
25616     if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
25617     __pyx_t_14 = PyObject_GetAttr(__pyx_v_buffer, __pyx_n_s__raw); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25618     __Pyx_GOTREF(__pyx_t_14);
25619     __pyx_t_18 = PyBytes_AsString(__pyx_t_14); if (unlikely((!__pyx_t_18) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25620     __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
25621     __pyx_v_temp = __pyx_t_18;
25622
25623     /* "csamtools.pyx":2653
25624  *                 # check if there is direct path from buffer.raw to tmp
25625  *                 temp = buffer.raw
25626  *                 memcpy( s, temp, total_size )             # <<<<<<<<<<<<<<
25627  * 
25628  *     property flag:
25629  */
25630     __pyx_t_16 = __Pyx_PyInt_AsSize_t(__pyx_v_total_size); if (unlikely((__pyx_t_16 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25631     memcpy(__pyx_v_s, __pyx_v_temp, __pyx_t_16);
25632     goto __pyx_L20;
25633   }
25634   __pyx_L20:;
25635
25636   __pyx_r = 0;
25637   goto __pyx_L0;
25638   __pyx_L1_error:;
25639   __Pyx_XDECREF(__pyx_t_1);
25640   __Pyx_XDECREF(__pyx_t_2);
25641   __Pyx_XDECREF(__pyx_t_6);
25642   __Pyx_XDECREF(__pyx_t_7);
25643   __Pyx_XDECREF(__pyx_t_8);
25644   __Pyx_XDECREF(__pyx_t_13);
25645   __Pyx_XDECREF(__pyx_t_14);
25646   __Pyx_AddTraceback("csamtools.AlignedRead.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25647   __pyx_r = -1;
25648   __pyx_L0:;
25649   __Pyx_XDECREF(__pyx_v_fmts);
25650   __Pyx_XDECREF(__pyx_v_args);
25651   __Pyx_XDECREF(__pyx_v_pytag);
25652   __Pyx_XDECREF(__pyx_v_value);
25653   __Pyx_XDECREF(__pyx_v_t);
25654   __Pyx_XDECREF(__pyx_v_pytype);
25655   __Pyx_XDECREF(__pyx_v_datafmt);
25656   __Pyx_XDECREF(__pyx_v_datatype);
25657   __Pyx_XDECREF(__pyx_v_mi);
25658   __Pyx_XDECREF(__pyx_v_ma);
25659   __Pyx_XDECREF(__pyx_v_absmax);
25660   __Pyx_XDECREF(__pyx_v_fmt);
25661   __Pyx_XDECREF(__pyx_v_total_size);
25662   __Pyx_XDECREF(__pyx_v_buffer);
25663   __Pyx_TraceReturn(Py_None);
25664   __Pyx_RefNannyFinishContext();
25665   return __pyx_r;
25666 }
25667
25668 /* Python wrapper */
25669 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/
25670 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4flag_1__get__(PyObject *__pyx_v_self) {
25671   PyObject *__pyx_r = 0;
25672   __Pyx_RefNannyDeclarations
25673   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
25674   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4flag___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
25675   __Pyx_RefNannyFinishContext();
25676   return __pyx_r;
25677 }
25678
25679 /* "csamtools.pyx":2657
25680  *     property flag:
25681  *         """properties flag"""
25682  *         def __get__(self): return self._delegate.core.flag             # <<<<<<<<<<<<<<
25683  *         def __set__(self, flag): self._delegate.core.flag = flag
25684  * 
25685  */
25686
25687 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4flag___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
25688   PyObject *__pyx_r = NULL;
25689   __Pyx_RefNannyDeclarations
25690   PyObject *__pyx_t_1 = NULL;
25691   int __pyx_lineno = 0;
25692   const char *__pyx_filename = NULL;
25693   int __pyx_clineno = 0;
25694   __Pyx_TraceDeclarations
25695   __Pyx_RefNannySetupContext("__get__", 0);
25696   __Pyx_TraceCall("__get__", __pyx_f[0], 2657);
25697   __Pyx_XDECREF(__pyx_r);
25698   __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 = 2657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25699   __Pyx_GOTREF(__pyx_t_1);
25700   __pyx_r = __pyx_t_1;
25701   __pyx_t_1 = 0;
25702   goto __pyx_L0;
25703
25704   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25705   goto __pyx_L0;
25706   __pyx_L1_error:;
25707   __Pyx_XDECREF(__pyx_t_1);
25708   __Pyx_AddTraceback("csamtools.AlignedRead.flag.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25709   __pyx_r = NULL;
25710   __pyx_L0:;
25711   __Pyx_XGIVEREF(__pyx_r);
25712   __Pyx_TraceReturn(__pyx_r);
25713   __Pyx_RefNannyFinishContext();
25714   return __pyx_r;
25715 }
25716
25717 /* Python wrapper */
25718 static int __pyx_pw_9csamtools_11AlignedRead_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
25719 static int __pyx_pw_9csamtools_11AlignedRead_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
25720   int __pyx_r;
25721   __Pyx_RefNannyDeclarations
25722   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
25723   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4flag_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_flag));
25724   __Pyx_RefNannyFinishContext();
25725   return __pyx_r;
25726 }
25727
25728 /* "csamtools.pyx":2658
25729  *         """properties flag"""
25730  *         def __get__(self): return self._delegate.core.flag
25731  *         def __set__(self, flag): self._delegate.core.flag = flag             # <<<<<<<<<<<<<<
25732  * 
25733  *     property rname:
25734  */
25735
25736 static int __pyx_pf_9csamtools_11AlignedRead_4flag_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_flag) {
25737   int __pyx_r;
25738   __Pyx_RefNannyDeclarations
25739   uint32_t __pyx_t_1;
25740   int __pyx_lineno = 0;
25741   const char *__pyx_filename = NULL;
25742   int __pyx_clineno = 0;
25743   __Pyx_TraceDeclarations
25744   __Pyx_RefNannySetupContext("__set__", 0);
25745   __Pyx_TraceCall("__set__", __pyx_f[0], 2658);
25746   __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 = 2658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25747   __pyx_v_self->_delegate->core.flag = __pyx_t_1;
25748
25749   __pyx_r = 0;
25750   goto __pyx_L0;
25751   __pyx_L1_error:;
25752   __Pyx_AddTraceback("csamtools.AlignedRead.flag.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25753   __pyx_r = -1;
25754   __pyx_L0:;
25755   __Pyx_TraceReturn(Py_None);
25756   __Pyx_RefNannyFinishContext();
25757   return __pyx_r;
25758 }
25759
25760 /* Python wrapper */
25761 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/
25762 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5rname_1__get__(PyObject *__pyx_v_self) {
25763   PyObject *__pyx_r = 0;
25764   __Pyx_RefNannyDeclarations
25765   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
25766   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5rname___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
25767   __Pyx_RefNannyFinishContext();
25768   return __pyx_r;
25769 }
25770
25771 /* "csamtools.pyx":2676
25772  * 
25773  *         """
25774  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
25775  *         def __set__(self, tid): self._delegate.core.tid = tid
25776  * 
25777  */
25778
25779 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rname___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
25780   PyObject *__pyx_r = NULL;
25781   __Pyx_RefNannyDeclarations
25782   PyObject *__pyx_t_1 = NULL;
25783   int __pyx_lineno = 0;
25784   const char *__pyx_filename = NULL;
25785   int __pyx_clineno = 0;
25786   __Pyx_TraceDeclarations
25787   __Pyx_RefNannySetupContext("__get__", 0);
25788   __Pyx_TraceCall("__get__", __pyx_f[0], 2676);
25789   __Pyx_XDECREF(__pyx_r);
25790   __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 = 2676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25791   __Pyx_GOTREF(__pyx_t_1);
25792   __pyx_r = __pyx_t_1;
25793   __pyx_t_1 = 0;
25794   goto __pyx_L0;
25795
25796   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25797   goto __pyx_L0;
25798   __pyx_L1_error:;
25799   __Pyx_XDECREF(__pyx_t_1);
25800   __Pyx_AddTraceback("csamtools.AlignedRead.rname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25801   __pyx_r = NULL;
25802   __pyx_L0:;
25803   __Pyx_XGIVEREF(__pyx_r);
25804   __Pyx_TraceReturn(__pyx_r);
25805   __Pyx_RefNannyFinishContext();
25806   return __pyx_r;
25807 }
25808
25809 /* Python wrapper */
25810 static int __pyx_pw_9csamtools_11AlignedRead_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
25811 static int __pyx_pw_9csamtools_11AlignedRead_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
25812   int __pyx_r;
25813   __Pyx_RefNannyDeclarations
25814   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
25815   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5rname_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tid));
25816   __Pyx_RefNannyFinishContext();
25817   return __pyx_r;
25818 }
25819
25820 /* "csamtools.pyx":2677
25821  *         """
25822  *         def __get__(self): return self._delegate.core.tid
25823  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
25824  * 
25825  *     property tid:
25826  */
25827
25828 static int __pyx_pf_9csamtools_11AlignedRead_5rname_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid) {
25829   int __pyx_r;
25830   __Pyx_RefNannyDeclarations
25831   int32_t __pyx_t_1;
25832   int __pyx_lineno = 0;
25833   const char *__pyx_filename = NULL;
25834   int __pyx_clineno = 0;
25835   __Pyx_TraceDeclarations
25836   __Pyx_RefNannySetupContext("__set__", 0);
25837   __Pyx_TraceCall("__set__", __pyx_f[0], 2677);
25838   __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 = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25839   __pyx_v_self->_delegate->core.tid = __pyx_t_1;
25840
25841   __pyx_r = 0;
25842   goto __pyx_L0;
25843   __pyx_L1_error:;
25844   __Pyx_AddTraceback("csamtools.AlignedRead.rname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25845   __pyx_r = -1;
25846   __pyx_L0:;
25847   __Pyx_TraceReturn(Py_None);
25848   __Pyx_RefNannyFinishContext();
25849   return __pyx_r;
25850 }
25851
25852 /* Python wrapper */
25853 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
25854 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3tid_1__get__(PyObject *__pyx_v_self) {
25855   PyObject *__pyx_r = 0;
25856   __Pyx_RefNannyDeclarations
25857   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
25858   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3tid___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
25859   __Pyx_RefNannyFinishContext();
25860   return __pyx_r;
25861 }
25862
25863 /* "csamtools.pyx":2690
25864  * 
25865  *         """
25866  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
25867  *         def __set__(self, tid): self._delegate.core.tid = tid
25868  * 
25869  */
25870
25871 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3tid___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
25872   PyObject *__pyx_r = NULL;
25873   __Pyx_RefNannyDeclarations
25874   PyObject *__pyx_t_1 = NULL;
25875   int __pyx_lineno = 0;
25876   const char *__pyx_filename = NULL;
25877   int __pyx_clineno = 0;
25878   __Pyx_TraceDeclarations
25879   __Pyx_RefNannySetupContext("__get__", 0);
25880   __Pyx_TraceCall("__get__", __pyx_f[0], 2690);
25881   __Pyx_XDECREF(__pyx_r);
25882   __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 = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25883   __Pyx_GOTREF(__pyx_t_1);
25884   __pyx_r = __pyx_t_1;
25885   __pyx_t_1 = 0;
25886   goto __pyx_L0;
25887
25888   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25889   goto __pyx_L0;
25890   __pyx_L1_error:;
25891   __Pyx_XDECREF(__pyx_t_1);
25892   __Pyx_AddTraceback("csamtools.AlignedRead.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25893   __pyx_r = NULL;
25894   __pyx_L0:;
25895   __Pyx_XGIVEREF(__pyx_r);
25896   __Pyx_TraceReturn(__pyx_r);
25897   __Pyx_RefNannyFinishContext();
25898   return __pyx_r;
25899 }
25900
25901 /* Python wrapper */
25902 static int __pyx_pw_9csamtools_11AlignedRead_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
25903 static int __pyx_pw_9csamtools_11AlignedRead_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
25904   int __pyx_r;
25905   __Pyx_RefNannyDeclarations
25906   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
25907   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3tid_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tid));
25908   __Pyx_RefNannyFinishContext();
25909   return __pyx_r;
25910 }
25911
25912 /* "csamtools.pyx":2691
25913  *         """
25914  *         def __get__(self): return self._delegate.core.tid
25915  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
25916  * 
25917  *     property pos:
25918  */
25919
25920 static int __pyx_pf_9csamtools_11AlignedRead_3tid_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tid) {
25921   int __pyx_r;
25922   __Pyx_RefNannyDeclarations
25923   int32_t __pyx_t_1;
25924   int __pyx_lineno = 0;
25925   const char *__pyx_filename = NULL;
25926   int __pyx_clineno = 0;
25927   __Pyx_TraceDeclarations
25928   __Pyx_RefNannySetupContext("__set__", 0);
25929   __Pyx_TraceCall("__set__", __pyx_f[0], 2691);
25930   __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 = 2691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25931   __pyx_v_self->_delegate->core.tid = __pyx_t_1;
25932
25933   __pyx_r = 0;
25934   goto __pyx_L0;
25935   __pyx_L1_error:;
25936   __Pyx_AddTraceback("csamtools.AlignedRead.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25937   __pyx_r = -1;
25938   __pyx_L0:;
25939   __Pyx_TraceReturn(Py_None);
25940   __Pyx_RefNannyFinishContext();
25941   return __pyx_r;
25942 }
25943
25944 /* Python wrapper */
25945 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
25946 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3pos_1__get__(PyObject *__pyx_v_self) {
25947   PyObject *__pyx_r = 0;
25948   __Pyx_RefNannyDeclarations
25949   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
25950   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3pos___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
25951   __Pyx_RefNannyFinishContext();
25952   return __pyx_r;
25953 }
25954
25955 /* "csamtools.pyx":2695
25956  *     property pos:
25957  *         """0-based leftmost coordinate"""
25958  *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
25959  *         def __set__(self, pos):
25960  *             ## setting the cigar string also updates the "bin" attribute
25961  */
25962
25963 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3pos___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
25964   PyObject *__pyx_r = NULL;
25965   __Pyx_RefNannyDeclarations
25966   PyObject *__pyx_t_1 = NULL;
25967   int __pyx_lineno = 0;
25968   const char *__pyx_filename = NULL;
25969   int __pyx_clineno = 0;
25970   __Pyx_TraceDeclarations
25971   __Pyx_RefNannySetupContext("__get__", 0);
25972   __Pyx_TraceCall("__get__", __pyx_f[0], 2695);
25973   __Pyx_XDECREF(__pyx_r);
25974   __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 = 2695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25975   __Pyx_GOTREF(__pyx_t_1);
25976   __pyx_r = __pyx_t_1;
25977   __pyx_t_1 = 0;
25978   goto __pyx_L0;
25979
25980   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25981   goto __pyx_L0;
25982   __pyx_L1_error:;
25983   __Pyx_XDECREF(__pyx_t_1);
25984   __Pyx_AddTraceback("csamtools.AlignedRead.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
25985   __pyx_r = NULL;
25986   __pyx_L0:;
25987   __Pyx_XGIVEREF(__pyx_r);
25988   __Pyx_TraceReturn(__pyx_r);
25989   __Pyx_RefNannyFinishContext();
25990   return __pyx_r;
25991 }
25992
25993 /* Python wrapper */
25994 static int __pyx_pw_9csamtools_11AlignedRead_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
25995 static int __pyx_pw_9csamtools_11AlignedRead_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
25996   int __pyx_r;
25997   __Pyx_RefNannyDeclarations
25998   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
25999   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3pos_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_pos));
26000   __Pyx_RefNannyFinishContext();
26001   return __pyx_r;
26002 }
26003
26004 /* "csamtools.pyx":2696
26005  *         """0-based leftmost coordinate"""
26006  *         def __get__(self): return self._delegate.core.pos
26007  *         def __set__(self, pos):             # <<<<<<<<<<<<<<
26008  *             ## setting the cigar string also updates the "bin" attribute
26009  *             cdef bam1_t * src
26010  */
26011
26012 static int __pyx_pf_9csamtools_11AlignedRead_3pos_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_pos) {
26013   bam1_t *__pyx_v_src;
26014   int __pyx_r;
26015   __Pyx_RefNannyDeclarations
26016   int32_t __pyx_t_1;
26017   int __pyx_lineno = 0;
26018   const char *__pyx_filename = NULL;
26019   int __pyx_clineno = 0;
26020   __Pyx_TraceDeclarations
26021   __Pyx_RefNannySetupContext("__set__", 0);
26022   __Pyx_TraceCall("__set__", __pyx_f[0], 2696);
26023
26024   /* "csamtools.pyx":2699
26025  *             ## setting the cigar string also updates the "bin" attribute
26026  *             cdef bam1_t * src
26027  *             src = self._delegate             # <<<<<<<<<<<<<<
26028  *             if src.core.n_cigar:
26029  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
26030  */
26031   __pyx_v_src = __pyx_v_self->_delegate;
26032
26033   /* "csamtools.pyx":2700
26034  *             cdef bam1_t * src
26035  *             src = self._delegate
26036  *             if src.core.n_cigar:             # <<<<<<<<<<<<<<
26037  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
26038  *             else:
26039  */
26040   if (__pyx_v_src->core.n_cigar) {
26041
26042     /* "csamtools.pyx":2701
26043  *             src = self._delegate
26044  *             if src.core.n_cigar:
26045  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )             # <<<<<<<<<<<<<<
26046  *             else:
26047  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
26048  */
26049     __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)));
26050     goto __pyx_L3;
26051   }
26052   /*else*/ {
26053
26054     /* "csamtools.pyx":2703
26055  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
26056  *             else:
26057  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)             # <<<<<<<<<<<<<<
26058  *             self._delegate.core.pos = pos
26059  *     property bin:
26060  */
26061     __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1));
26062   }
26063   __pyx_L3:;
26064
26065   /* "csamtools.pyx":2704
26066  *             else:
26067  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
26068  *             self._delegate.core.pos = pos             # <<<<<<<<<<<<<<
26069  *     property bin:
26070  *         """properties bin"""
26071  */
26072   __pyx_t_1 = __Pyx_PyInt_from_py_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26073   __pyx_v_self->_delegate->core.pos = __pyx_t_1;
26074
26075   __pyx_r = 0;
26076   goto __pyx_L0;
26077   __pyx_L1_error:;
26078   __Pyx_AddTraceback("csamtools.AlignedRead.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26079   __pyx_r = -1;
26080   __pyx_L0:;
26081   __Pyx_TraceReturn(Py_None);
26082   __Pyx_RefNannyFinishContext();
26083   return __pyx_r;
26084 }
26085
26086 /* Python wrapper */
26087 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/
26088 static PyObject *__pyx_pw_9csamtools_11AlignedRead_3bin_1__get__(PyObject *__pyx_v_self) {
26089   PyObject *__pyx_r = 0;
26090   __Pyx_RefNannyDeclarations
26091   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26092   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3bin___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26093   __Pyx_RefNannyFinishContext();
26094   return __pyx_r;
26095 }
26096
26097 /* "csamtools.pyx":2707
26098  *     property bin:
26099  *         """properties bin"""
26100  *         def __get__(self): return self._delegate.core.bin             # <<<<<<<<<<<<<<
26101  *         def __set__(self, bin): self._delegate.core.bin = bin
26102  *     property rlen:
26103  */
26104
26105 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3bin___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26106   PyObject *__pyx_r = NULL;
26107   __Pyx_RefNannyDeclarations
26108   PyObject *__pyx_t_1 = NULL;
26109   int __pyx_lineno = 0;
26110   const char *__pyx_filename = NULL;
26111   int __pyx_clineno = 0;
26112   __Pyx_TraceDeclarations
26113   __Pyx_RefNannySetupContext("__get__", 0);
26114   __Pyx_TraceCall("__get__", __pyx_f[0], 2707);
26115   __Pyx_XDECREF(__pyx_r);
26116   __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 = 2707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26117   __Pyx_GOTREF(__pyx_t_1);
26118   __pyx_r = __pyx_t_1;
26119   __pyx_t_1 = 0;
26120   goto __pyx_L0;
26121
26122   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26123   goto __pyx_L0;
26124   __pyx_L1_error:;
26125   __Pyx_XDECREF(__pyx_t_1);
26126   __Pyx_AddTraceback("csamtools.AlignedRead.bin.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26127   __pyx_r = NULL;
26128   __pyx_L0:;
26129   __Pyx_XGIVEREF(__pyx_r);
26130   __Pyx_TraceReturn(__pyx_r);
26131   __Pyx_RefNannyFinishContext();
26132   return __pyx_r;
26133 }
26134
26135 /* Python wrapper */
26136 static int __pyx_pw_9csamtools_11AlignedRead_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
26137 static int __pyx_pw_9csamtools_11AlignedRead_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
26138   int __pyx_r;
26139   __Pyx_RefNannyDeclarations
26140   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26141   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_3bin_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_bin));
26142   __Pyx_RefNannyFinishContext();
26143   return __pyx_r;
26144 }
26145
26146 /* "csamtools.pyx":2708
26147  *         """properties bin"""
26148  *         def __get__(self): return self._delegate.core.bin
26149  *         def __set__(self, bin): self._delegate.core.bin = bin             # <<<<<<<<<<<<<<
26150  *     property rlen:
26151  *         '''length of the read (read only). Returns 0 if not given.'''
26152  */
26153
26154 static int __pyx_pf_9csamtools_11AlignedRead_3bin_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_bin) {
26155   int __pyx_r;
26156   __Pyx_RefNannyDeclarations
26157   uint32_t __pyx_t_1;
26158   int __pyx_lineno = 0;
26159   const char *__pyx_filename = NULL;
26160   int __pyx_clineno = 0;
26161   __Pyx_TraceDeclarations
26162   __Pyx_RefNannySetupContext("__set__", 0);
26163   __Pyx_TraceCall("__set__", __pyx_f[0], 2708);
26164   __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 = 2708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26165   __pyx_v_self->_delegate->core.bin = __pyx_t_1;
26166
26167   __pyx_r = 0;
26168   goto __pyx_L0;
26169   __pyx_L1_error:;
26170   __Pyx_AddTraceback("csamtools.AlignedRead.bin.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26171   __pyx_r = -1;
26172   __pyx_L0:;
26173   __Pyx_TraceReturn(Py_None);
26174   __Pyx_RefNannyFinishContext();
26175   return __pyx_r;
26176 }
26177
26178 /* Python wrapper */
26179 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/
26180 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4rlen_1__get__(PyObject *__pyx_v_self) {
26181   PyObject *__pyx_r = 0;
26182   __Pyx_RefNannyDeclarations
26183   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26184   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4rlen___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26185   __Pyx_RefNannyFinishContext();
26186   return __pyx_r;
26187 }
26188
26189 /* "csamtools.pyx":2711
26190  *     property rlen:
26191  *         '''length of the read (read only). Returns 0 if not given.'''
26192  *         def __get__(self): return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
26193  *     property aend:
26194  *         '''aligned reference position of the read on the reference genome.
26195  */
26196
26197 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4rlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26198   PyObject *__pyx_r = NULL;
26199   __Pyx_RefNannyDeclarations
26200   PyObject *__pyx_t_1 = NULL;
26201   int __pyx_lineno = 0;
26202   const char *__pyx_filename = NULL;
26203   int __pyx_clineno = 0;
26204   __Pyx_TraceDeclarations
26205   __Pyx_RefNannySetupContext("__get__", 0);
26206   __Pyx_TraceCall("__get__", __pyx_f[0], 2711);
26207   __Pyx_XDECREF(__pyx_r);
26208   __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 = 2711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26209   __Pyx_GOTREF(__pyx_t_1);
26210   __pyx_r = __pyx_t_1;
26211   __pyx_t_1 = 0;
26212   goto __pyx_L0;
26213
26214   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26215   goto __pyx_L0;
26216   __pyx_L1_error:;
26217   __Pyx_XDECREF(__pyx_t_1);
26218   __Pyx_AddTraceback("csamtools.AlignedRead.rlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26219   __pyx_r = NULL;
26220   __pyx_L0:;
26221   __Pyx_XGIVEREF(__pyx_r);
26222   __Pyx_TraceReturn(__pyx_r);
26223   __Pyx_RefNannyFinishContext();
26224   return __pyx_r;
26225 }
26226
26227 /* Python wrapper */
26228 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/
26229 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4aend_1__get__(PyObject *__pyx_v_self) {
26230   PyObject *__pyx_r = 0;
26231   __Pyx_RefNannyDeclarations
26232   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26233   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4aend___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26234   __Pyx_RefNannyFinishContext();
26235   return __pyx_r;
26236 }
26237
26238 /* "csamtools.pyx":2717
26239  *         aend points to one past the last aligned residue.
26240  *         Returns None if not available.'''
26241  *         def __get__(self):             # <<<<<<<<<<<<<<
26242  *             cdef bam1_t * src
26243  *             src = self._delegate
26244  */
26245
26246 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4aend___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26247   bam1_t *__pyx_v_src;
26248   PyObject *__pyx_r = NULL;
26249   __Pyx_RefNannyDeclarations
26250   PyObject *__pyx_t_1 = NULL;
26251   PyObject *__pyx_t_2 = NULL;
26252   int __pyx_t_3;
26253   int __pyx_t_4;
26254   int __pyx_t_5;
26255   int __pyx_lineno = 0;
26256   const char *__pyx_filename = NULL;
26257   int __pyx_clineno = 0;
26258   __Pyx_TraceDeclarations
26259   __Pyx_RefNannySetupContext("__get__", 0);
26260   __Pyx_TraceCall("__get__", __pyx_f[0], 2717);
26261
26262   /* "csamtools.pyx":2719
26263  *         def __get__(self):
26264  *             cdef bam1_t * src
26265  *             src = self._delegate             # <<<<<<<<<<<<<<
26266  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26267  *                 return None
26268  */
26269   __pyx_v_src = __pyx_v_self->_delegate;
26270
26271   /* "csamtools.pyx":2720
26272  *             cdef bam1_t * src
26273  *             src = self._delegate
26274  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
26275  *                 return None
26276  *             return bam_calend(&src.core, bam1_cigar(src))
26277  */
26278   __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 = 2720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26279   __Pyx_GOTREF(__pyx_t_1);
26280   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26281   __Pyx_GOTREF(__pyx_t_2);
26282   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26283   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26284   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
26285   if (!__pyx_t_3) {
26286     __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
26287     __pyx_t_5 = __pyx_t_4;
26288   } else {
26289     __pyx_t_5 = __pyx_t_3;
26290   }
26291   if (__pyx_t_5) {
26292
26293     /* "csamtools.pyx":2721
26294  *             src = self._delegate
26295  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26296  *                 return None             # <<<<<<<<<<<<<<
26297  *             return bam_calend(&src.core, bam1_cigar(src))
26298  * 
26299  */
26300     __Pyx_XDECREF(__pyx_r);
26301     __Pyx_INCREF(Py_None);
26302     __pyx_r = Py_None;
26303     goto __pyx_L0;
26304     goto __pyx_L3;
26305   }
26306   __pyx_L3:;
26307
26308   /* "csamtools.pyx":2722
26309  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26310  *                 return None
26311  *             return bam_calend(&src.core, bam1_cigar(src))             # <<<<<<<<<<<<<<
26312  * 
26313  *     property alen:
26314  */
26315   __Pyx_XDECREF(__pyx_r);
26316   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2722; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26317   __Pyx_GOTREF(__pyx_t_2);
26318   __pyx_r = __pyx_t_2;
26319   __pyx_t_2 = 0;
26320   goto __pyx_L0;
26321
26322   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26323   goto __pyx_L0;
26324   __pyx_L1_error:;
26325   __Pyx_XDECREF(__pyx_t_1);
26326   __Pyx_XDECREF(__pyx_t_2);
26327   __Pyx_AddTraceback("csamtools.AlignedRead.aend.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26328   __pyx_r = NULL;
26329   __pyx_L0:;
26330   __Pyx_XGIVEREF(__pyx_r);
26331   __Pyx_TraceReturn(__pyx_r);
26332   __Pyx_RefNannyFinishContext();
26333   return __pyx_r;
26334 }
26335
26336 /* Python wrapper */
26337 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/
26338 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4alen_1__get__(PyObject *__pyx_v_self) {
26339   PyObject *__pyx_r = 0;
26340   __Pyx_RefNannyDeclarations
26341   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26342   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4alen___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26343   __Pyx_RefNannyFinishContext();
26344   return __pyx_r;
26345 }
26346
26347 /* "csamtools.pyx":2727
26348  *         '''aligned length of the read on the reference genome.  Returns None if
26349  *         not available.'''
26350  *         def __get__(self):             # <<<<<<<<<<<<<<
26351  *             cdef bam1_t * src
26352  *             src = self._delegate
26353  */
26354
26355 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4alen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26356   bam1_t *__pyx_v_src;
26357   PyObject *__pyx_r = NULL;
26358   __Pyx_RefNannyDeclarations
26359   PyObject *__pyx_t_1 = NULL;
26360   PyObject *__pyx_t_2 = NULL;
26361   int __pyx_t_3;
26362   int __pyx_t_4;
26363   int __pyx_t_5;
26364   int __pyx_lineno = 0;
26365   const char *__pyx_filename = NULL;
26366   int __pyx_clineno = 0;
26367   __Pyx_TraceDeclarations
26368   __Pyx_RefNannySetupContext("__get__", 0);
26369   __Pyx_TraceCall("__get__", __pyx_f[0], 2727);
26370
26371   /* "csamtools.pyx":2729
26372  *         def __get__(self):
26373  *             cdef bam1_t * src
26374  *             src = self._delegate             # <<<<<<<<<<<<<<
26375  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26376  *                 return None
26377  */
26378   __pyx_v_src = __pyx_v_self->_delegate;
26379
26380   /* "csamtools.pyx":2730
26381  *             cdef bam1_t * src
26382  *             src = self._delegate
26383  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
26384  *                 return None
26385  *             return bam_calend(&src.core,
26386  */
26387   __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 = 2730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26388   __Pyx_GOTREF(__pyx_t_1);
26389   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26390   __Pyx_GOTREF(__pyx_t_2);
26391   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26392   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26393   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
26394   if (!__pyx_t_3) {
26395     __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
26396     __pyx_t_5 = __pyx_t_4;
26397   } else {
26398     __pyx_t_5 = __pyx_t_3;
26399   }
26400   if (__pyx_t_5) {
26401
26402     /* "csamtools.pyx":2731
26403  *             src = self._delegate
26404  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26405  *                 return None             # <<<<<<<<<<<<<<
26406  *             return bam_calend(&src.core,
26407  *                                bam1_cigar(src)) - \
26408  */
26409     __Pyx_XDECREF(__pyx_r);
26410     __Pyx_INCREF(Py_None);
26411     __pyx_r = Py_None;
26412     goto __pyx_L0;
26413     goto __pyx_L3;
26414   }
26415   __pyx_L3:;
26416
26417   /* "csamtools.pyx":2732
26418  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
26419  *                 return None
26420  *             return bam_calend(&src.core,             # <<<<<<<<<<<<<<
26421  *                                bam1_cigar(src)) - \
26422  *                                self._delegate.core.pos
26423  */
26424   __Pyx_XDECREF(__pyx_r);
26425
26426   /* "csamtools.pyx":2734
26427  *             return bam_calend(&src.core,
26428  *                                bam1_cigar(src)) - \
26429  *                                self._delegate.core.pos             # <<<<<<<<<<<<<<
26430  * 
26431  *     property mapq:
26432  */
26433   __pyx_t_2 = PyInt_FromLong((bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26434   __Pyx_GOTREF(__pyx_t_2);
26435   __pyx_r = __pyx_t_2;
26436   __pyx_t_2 = 0;
26437   goto __pyx_L0;
26438
26439   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26440   goto __pyx_L0;
26441   __pyx_L1_error:;
26442   __Pyx_XDECREF(__pyx_t_1);
26443   __Pyx_XDECREF(__pyx_t_2);
26444   __Pyx_AddTraceback("csamtools.AlignedRead.alen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26445   __pyx_r = NULL;
26446   __pyx_L0:;
26447   __Pyx_XGIVEREF(__pyx_r);
26448   __Pyx_TraceReturn(__pyx_r);
26449   __Pyx_RefNannyFinishContext();
26450   return __pyx_r;
26451 }
26452
26453 /* Python wrapper */
26454 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/
26455 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mapq_1__get__(PyObject *__pyx_v_self) {
26456   PyObject *__pyx_r = 0;
26457   __Pyx_RefNannyDeclarations
26458   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26459   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mapq___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26460   __Pyx_RefNannyFinishContext();
26461   return __pyx_r;
26462 }
26463
26464 /* "csamtools.pyx":2738
26465  *     property mapq:
26466  *         """mapping quality"""
26467  *         def __get__(self): return self._delegate.core.qual             # <<<<<<<<<<<<<<
26468  *         def __set__(self, qual): self._delegate.core.qual = qual
26469  * 
26470  */
26471
26472 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mapq___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26473   PyObject *__pyx_r = NULL;
26474   __Pyx_RefNannyDeclarations
26475   PyObject *__pyx_t_1 = NULL;
26476   int __pyx_lineno = 0;
26477   const char *__pyx_filename = NULL;
26478   int __pyx_clineno = 0;
26479   __Pyx_TraceDeclarations
26480   __Pyx_RefNannySetupContext("__get__", 0);
26481   __Pyx_TraceCall("__get__", __pyx_f[0], 2738);
26482   __Pyx_XDECREF(__pyx_r);
26483   __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 = 2738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26484   __Pyx_GOTREF(__pyx_t_1);
26485   __pyx_r = __pyx_t_1;
26486   __pyx_t_1 = 0;
26487   goto __pyx_L0;
26488
26489   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26490   goto __pyx_L0;
26491   __pyx_L1_error:;
26492   __Pyx_XDECREF(__pyx_t_1);
26493   __Pyx_AddTraceback("csamtools.AlignedRead.mapq.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26494   __pyx_r = NULL;
26495   __pyx_L0:;
26496   __Pyx_XGIVEREF(__pyx_r);
26497   __Pyx_TraceReturn(__pyx_r);
26498   __Pyx_RefNannyFinishContext();
26499   return __pyx_r;
26500 }
26501
26502 /* Python wrapper */
26503 static int __pyx_pw_9csamtools_11AlignedRead_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
26504 static int __pyx_pw_9csamtools_11AlignedRead_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
26505   int __pyx_r;
26506   __Pyx_RefNannyDeclarations
26507   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26508   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mapq_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_qual));
26509   __Pyx_RefNannyFinishContext();
26510   return __pyx_r;
26511 }
26512
26513 /* "csamtools.pyx":2739
26514  *         """mapping quality"""
26515  *         def __get__(self): return self._delegate.core.qual
26516  *         def __set__(self, qual): self._delegate.core.qual = qual             # <<<<<<<<<<<<<<
26517  * 
26518  *     property mrnm:
26519  */
26520
26521 static int __pyx_pf_9csamtools_11AlignedRead_4mapq_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_qual) {
26522   int __pyx_r;
26523   __Pyx_RefNannyDeclarations
26524   uint32_t __pyx_t_1;
26525   int __pyx_lineno = 0;
26526   const char *__pyx_filename = NULL;
26527   int __pyx_clineno = 0;
26528   __Pyx_TraceDeclarations
26529   __Pyx_RefNannySetupContext("__set__", 0);
26530   __Pyx_TraceCall("__set__", __pyx_f[0], 2739);
26531   __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 = 2739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26532   __pyx_v_self->_delegate->core.qual = __pyx_t_1;
26533
26534   __pyx_r = 0;
26535   goto __pyx_L0;
26536   __pyx_L1_error:;
26537   __Pyx_AddTraceback("csamtools.AlignedRead.mapq.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26538   __pyx_r = -1;
26539   __pyx_L0:;
26540   __Pyx_TraceReturn(Py_None);
26541   __Pyx_RefNannyFinishContext();
26542   return __pyx_r;
26543 }
26544
26545 /* Python wrapper */
26546 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/
26547 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mrnm_1__get__(PyObject *__pyx_v_self) {
26548   PyObject *__pyx_r = 0;
26549   __Pyx_RefNannyDeclarations
26550   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26551   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26552   __Pyx_RefNannyFinishContext();
26553   return __pyx_r;
26554 }
26555
26556 /* "csamtools.pyx":2745
26557  *         deprecated, use RNEXT instead.
26558  *         """
26559  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
26560  *         def __set__(self, mtid): self._delegate.core.mtid = mtid
26561  *     property rnext:
26562  */
26563
26564 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26565   PyObject *__pyx_r = NULL;
26566   __Pyx_RefNannyDeclarations
26567   PyObject *__pyx_t_1 = NULL;
26568   int __pyx_lineno = 0;
26569   const char *__pyx_filename = NULL;
26570   int __pyx_clineno = 0;
26571   __Pyx_TraceDeclarations
26572   __Pyx_RefNannySetupContext("__get__", 0);
26573   __Pyx_TraceCall("__get__", __pyx_f[0], 2745);
26574   __Pyx_XDECREF(__pyx_r);
26575   __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 = 2745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26576   __Pyx_GOTREF(__pyx_t_1);
26577   __pyx_r = __pyx_t_1;
26578   __pyx_t_1 = 0;
26579   goto __pyx_L0;
26580
26581   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26582   goto __pyx_L0;
26583   __pyx_L1_error:;
26584   __Pyx_XDECREF(__pyx_t_1);
26585   __Pyx_AddTraceback("csamtools.AlignedRead.mrnm.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26586   __pyx_r = NULL;
26587   __pyx_L0:;
26588   __Pyx_XGIVEREF(__pyx_r);
26589   __Pyx_TraceReturn(__pyx_r);
26590   __Pyx_RefNannyFinishContext();
26591   return __pyx_r;
26592 }
26593
26594 /* Python wrapper */
26595 static int __pyx_pw_9csamtools_11AlignedRead_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
26596 static int __pyx_pw_9csamtools_11AlignedRead_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
26597   int __pyx_r;
26598   __Pyx_RefNannyDeclarations
26599   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26600   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mrnm_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));
26601   __Pyx_RefNannyFinishContext();
26602   return __pyx_r;
26603 }
26604
26605 /* "csamtools.pyx":2746
26606  *         """
26607  *         def __get__(self): return self._delegate.core.mtid
26608  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
26609  *     property rnext:
26610  *         """the :term:`reference` id of the mate """
26611  */
26612
26613 static int __pyx_pf_9csamtools_11AlignedRead_4mrnm_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid) {
26614   int __pyx_r;
26615   __Pyx_RefNannyDeclarations
26616   int32_t __pyx_t_1;
26617   int __pyx_lineno = 0;
26618   const char *__pyx_filename = NULL;
26619   int __pyx_clineno = 0;
26620   __Pyx_TraceDeclarations
26621   __Pyx_RefNannySetupContext("__set__", 0);
26622   __Pyx_TraceCall("__set__", __pyx_f[0], 2746);
26623   __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 = 2746; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26624   __pyx_v_self->_delegate->core.mtid = __pyx_t_1;
26625
26626   __pyx_r = 0;
26627   goto __pyx_L0;
26628   __pyx_L1_error:;
26629   __Pyx_AddTraceback("csamtools.AlignedRead.mrnm.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26630   __pyx_r = -1;
26631   __pyx_L0:;
26632   __Pyx_TraceReturn(Py_None);
26633   __Pyx_RefNannyFinishContext();
26634   return __pyx_r;
26635 }
26636
26637 /* Python wrapper */
26638 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/
26639 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5rnext_1__get__(PyObject *__pyx_v_self) {
26640   PyObject *__pyx_r = 0;
26641   __Pyx_RefNannyDeclarations
26642   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26643   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5rnext___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26644   __Pyx_RefNannyFinishContext();
26645   return __pyx_r;
26646 }
26647
26648 /* "csamtools.pyx":2749
26649  *     property rnext:
26650  *         """the :term:`reference` id of the mate """
26651  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
26652  *         def __set__(self, mtid): self._delegate.core.mtid = mtid
26653  *     property mpos:
26654  */
26655
26656 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rnext___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26657   PyObject *__pyx_r = NULL;
26658   __Pyx_RefNannyDeclarations
26659   PyObject *__pyx_t_1 = NULL;
26660   int __pyx_lineno = 0;
26661   const char *__pyx_filename = NULL;
26662   int __pyx_clineno = 0;
26663   __Pyx_TraceDeclarations
26664   __Pyx_RefNannySetupContext("__get__", 0);
26665   __Pyx_TraceCall("__get__", __pyx_f[0], 2749);
26666   __Pyx_XDECREF(__pyx_r);
26667   __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 = 2749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26668   __Pyx_GOTREF(__pyx_t_1);
26669   __pyx_r = __pyx_t_1;
26670   __pyx_t_1 = 0;
26671   goto __pyx_L0;
26672
26673   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26674   goto __pyx_L0;
26675   __pyx_L1_error:;
26676   __Pyx_XDECREF(__pyx_t_1);
26677   __Pyx_AddTraceback("csamtools.AlignedRead.rnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26678   __pyx_r = NULL;
26679   __pyx_L0:;
26680   __Pyx_XGIVEREF(__pyx_r);
26681   __Pyx_TraceReturn(__pyx_r);
26682   __Pyx_RefNannyFinishContext();
26683   return __pyx_r;
26684 }
26685
26686 /* Python wrapper */
26687 static int __pyx_pw_9csamtools_11AlignedRead_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
26688 static int __pyx_pw_9csamtools_11AlignedRead_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
26689   int __pyx_r;
26690   __Pyx_RefNannyDeclarations
26691   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26692   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5rnext_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));
26693   __Pyx_RefNannyFinishContext();
26694   return __pyx_r;
26695 }
26696
26697 /* "csamtools.pyx":2750
26698  *         """the :term:`reference` id of the mate """
26699  *         def __get__(self): return self._delegate.core.mtid
26700  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
26701  *     property mpos:
26702  *         """the position of the mate
26703  */
26704
26705 static int __pyx_pf_9csamtools_11AlignedRead_5rnext_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mtid) {
26706   int __pyx_r;
26707   __Pyx_RefNannyDeclarations
26708   int32_t __pyx_t_1;
26709   int __pyx_lineno = 0;
26710   const char *__pyx_filename = NULL;
26711   int __pyx_clineno = 0;
26712   __Pyx_TraceDeclarations
26713   __Pyx_RefNannySetupContext("__set__", 0);
26714   __Pyx_TraceCall("__set__", __pyx_f[0], 2750);
26715   __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 = 2750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26716   __pyx_v_self->_delegate->core.mtid = __pyx_t_1;
26717
26718   __pyx_r = 0;
26719   goto __pyx_L0;
26720   __pyx_L1_error:;
26721   __Pyx_AddTraceback("csamtools.AlignedRead.rnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26722   __pyx_r = -1;
26723   __pyx_L0:;
26724   __Pyx_TraceReturn(Py_None);
26725   __Pyx_RefNannyFinishContext();
26726   return __pyx_r;
26727 }
26728
26729 /* Python wrapper */
26730 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/
26731 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4mpos_1__get__(PyObject *__pyx_v_self) {
26732   PyObject *__pyx_r = 0;
26733   __Pyx_RefNannyDeclarations
26734   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26735   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mpos___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26736   __Pyx_RefNannyFinishContext();
26737   return __pyx_r;
26738 }
26739
26740 /* "csamtools.pyx":2754
26741  *         """the position of the mate
26742  *         deprecated, use PNEXT instead."""
26743  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
26744  *         def __set__(self, mpos): self._delegate.core.mpos = mpos
26745  *     property pnext:
26746  */
26747
26748 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mpos___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26749   PyObject *__pyx_r = NULL;
26750   __Pyx_RefNannyDeclarations
26751   PyObject *__pyx_t_1 = NULL;
26752   int __pyx_lineno = 0;
26753   const char *__pyx_filename = NULL;
26754   int __pyx_clineno = 0;
26755   __Pyx_TraceDeclarations
26756   __Pyx_RefNannySetupContext("__get__", 0);
26757   __Pyx_TraceCall("__get__", __pyx_f[0], 2754);
26758   __Pyx_XDECREF(__pyx_r);
26759   __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 = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26760   __Pyx_GOTREF(__pyx_t_1);
26761   __pyx_r = __pyx_t_1;
26762   __pyx_t_1 = 0;
26763   goto __pyx_L0;
26764
26765   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26766   goto __pyx_L0;
26767   __pyx_L1_error:;
26768   __Pyx_XDECREF(__pyx_t_1);
26769   __Pyx_AddTraceback("csamtools.AlignedRead.mpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26770   __pyx_r = NULL;
26771   __pyx_L0:;
26772   __Pyx_XGIVEREF(__pyx_r);
26773   __Pyx_TraceReturn(__pyx_r);
26774   __Pyx_RefNannyFinishContext();
26775   return __pyx_r;
26776 }
26777
26778 /* Python wrapper */
26779 static int __pyx_pw_9csamtools_11AlignedRead_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
26780 static int __pyx_pw_9csamtools_11AlignedRead_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
26781   int __pyx_r;
26782   __Pyx_RefNannyDeclarations
26783   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26784   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4mpos_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));
26785   __Pyx_RefNannyFinishContext();
26786   return __pyx_r;
26787 }
26788
26789 /* "csamtools.pyx":2755
26790  *         deprecated, use PNEXT instead."""
26791  *         def __get__(self): return self._delegate.core.mpos
26792  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
26793  *     property pnext:
26794  *         """the position of the mate"""
26795  */
26796
26797 static int __pyx_pf_9csamtools_11AlignedRead_4mpos_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos) {
26798   int __pyx_r;
26799   __Pyx_RefNannyDeclarations
26800   int32_t __pyx_t_1;
26801   int __pyx_lineno = 0;
26802   const char *__pyx_filename = NULL;
26803   int __pyx_clineno = 0;
26804   __Pyx_TraceDeclarations
26805   __Pyx_RefNannySetupContext("__set__", 0);
26806   __Pyx_TraceCall("__set__", __pyx_f[0], 2755);
26807   __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 = 2755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26808   __pyx_v_self->_delegate->core.mpos = __pyx_t_1;
26809
26810   __pyx_r = 0;
26811   goto __pyx_L0;
26812   __pyx_L1_error:;
26813   __Pyx_AddTraceback("csamtools.AlignedRead.mpos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26814   __pyx_r = -1;
26815   __pyx_L0:;
26816   __Pyx_TraceReturn(Py_None);
26817   __Pyx_RefNannyFinishContext();
26818   return __pyx_r;
26819 }
26820
26821 /* Python wrapper */
26822 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/
26823 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5pnext_1__get__(PyObject *__pyx_v_self) {
26824   PyObject *__pyx_r = 0;
26825   __Pyx_RefNannyDeclarations
26826   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26827   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5pnext___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26828   __Pyx_RefNannyFinishContext();
26829   return __pyx_r;
26830 }
26831
26832 /* "csamtools.pyx":2758
26833  *     property pnext:
26834  *         """the position of the mate"""
26835  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
26836  *         def __set__(self, mpos): self._delegate.core.mpos = mpos
26837  *     property isize:
26838  */
26839
26840 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5pnext___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26841   PyObject *__pyx_r = NULL;
26842   __Pyx_RefNannyDeclarations
26843   PyObject *__pyx_t_1 = NULL;
26844   int __pyx_lineno = 0;
26845   const char *__pyx_filename = NULL;
26846   int __pyx_clineno = 0;
26847   __Pyx_TraceDeclarations
26848   __Pyx_RefNannySetupContext("__get__", 0);
26849   __Pyx_TraceCall("__get__", __pyx_f[0], 2758);
26850   __Pyx_XDECREF(__pyx_r);
26851   __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 = 2758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26852   __Pyx_GOTREF(__pyx_t_1);
26853   __pyx_r = __pyx_t_1;
26854   __pyx_t_1 = 0;
26855   goto __pyx_L0;
26856
26857   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26858   goto __pyx_L0;
26859   __pyx_L1_error:;
26860   __Pyx_XDECREF(__pyx_t_1);
26861   __Pyx_AddTraceback("csamtools.AlignedRead.pnext.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26862   __pyx_r = NULL;
26863   __pyx_L0:;
26864   __Pyx_XGIVEREF(__pyx_r);
26865   __Pyx_TraceReturn(__pyx_r);
26866   __Pyx_RefNannyFinishContext();
26867   return __pyx_r;
26868 }
26869
26870 /* Python wrapper */
26871 static int __pyx_pw_9csamtools_11AlignedRead_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
26872 static int __pyx_pw_9csamtools_11AlignedRead_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
26873   int __pyx_r;
26874   __Pyx_RefNannyDeclarations
26875   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26876   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5pnext_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));
26877   __Pyx_RefNannyFinishContext();
26878   return __pyx_r;
26879 }
26880
26881 /* "csamtools.pyx":2759
26882  *         """the position of the mate"""
26883  *         def __get__(self): return self._delegate.core.mpos
26884  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
26885  *     property isize:
26886  *         """the insert size
26887  */
26888
26889 static int __pyx_pf_9csamtools_11AlignedRead_5pnext_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_mpos) {
26890   int __pyx_r;
26891   __Pyx_RefNannyDeclarations
26892   int32_t __pyx_t_1;
26893   int __pyx_lineno = 0;
26894   const char *__pyx_filename = NULL;
26895   int __pyx_clineno = 0;
26896   __Pyx_TraceDeclarations
26897   __Pyx_RefNannySetupContext("__set__", 0);
26898   __Pyx_TraceCall("__set__", __pyx_f[0], 2759);
26899   __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 = 2759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26900   __pyx_v_self->_delegate->core.mpos = __pyx_t_1;
26901
26902   __pyx_r = 0;
26903   goto __pyx_L0;
26904   __pyx_L1_error:;
26905   __Pyx_AddTraceback("csamtools.AlignedRead.pnext.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26906   __pyx_r = -1;
26907   __pyx_L0:;
26908   __Pyx_TraceReturn(Py_None);
26909   __Pyx_RefNannyFinishContext();
26910   return __pyx_r;
26911 }
26912
26913 /* Python wrapper */
26914 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/
26915 static PyObject *__pyx_pw_9csamtools_11AlignedRead_5isize_1__get__(PyObject *__pyx_v_self) {
26916   PyObject *__pyx_r = 0;
26917   __Pyx_RefNannyDeclarations
26918   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
26919   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5isize___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
26920   __Pyx_RefNannyFinishContext();
26921   return __pyx_r;
26922 }
26923
26924 /* "csamtools.pyx":2763
26925  *         """the insert size
26926  *         deprecated: use tlen instead"""
26927  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
26928  *         def __set__(self, isize): self._delegate.core.isize = isize
26929  *     property tlen:
26930  */
26931
26932 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5isize___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
26933   PyObject *__pyx_r = NULL;
26934   __Pyx_RefNannyDeclarations
26935   PyObject *__pyx_t_1 = NULL;
26936   int __pyx_lineno = 0;
26937   const char *__pyx_filename = NULL;
26938   int __pyx_clineno = 0;
26939   __Pyx_TraceDeclarations
26940   __Pyx_RefNannySetupContext("__get__", 0);
26941   __Pyx_TraceCall("__get__", __pyx_f[0], 2763);
26942   __Pyx_XDECREF(__pyx_r);
26943   __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 = 2763; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26944   __Pyx_GOTREF(__pyx_t_1);
26945   __pyx_r = __pyx_t_1;
26946   __pyx_t_1 = 0;
26947   goto __pyx_L0;
26948
26949   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26950   goto __pyx_L0;
26951   __pyx_L1_error:;
26952   __Pyx_XDECREF(__pyx_t_1);
26953   __Pyx_AddTraceback("csamtools.AlignedRead.isize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26954   __pyx_r = NULL;
26955   __pyx_L0:;
26956   __Pyx_XGIVEREF(__pyx_r);
26957   __Pyx_TraceReturn(__pyx_r);
26958   __Pyx_RefNannyFinishContext();
26959   return __pyx_r;
26960 }
26961
26962 /* Python wrapper */
26963 static int __pyx_pw_9csamtools_11AlignedRead_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
26964 static int __pyx_pw_9csamtools_11AlignedRead_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
26965   int __pyx_r;
26966   __Pyx_RefNannyDeclarations
26967   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
26968   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_5isize_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_isize));
26969   __Pyx_RefNannyFinishContext();
26970   return __pyx_r;
26971 }
26972
26973 /* "csamtools.pyx":2764
26974  *         deprecated: use tlen instead"""
26975  *         def __get__(self): return self._delegate.core.isize
26976  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
26977  *     property tlen:
26978  *         """the insert size"""
26979  */
26980
26981 static int __pyx_pf_9csamtools_11AlignedRead_5isize_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize) {
26982   int __pyx_r;
26983   __Pyx_RefNannyDeclarations
26984   int32_t __pyx_t_1;
26985   int __pyx_lineno = 0;
26986   const char *__pyx_filename = NULL;
26987   int __pyx_clineno = 0;
26988   __Pyx_TraceDeclarations
26989   __Pyx_RefNannySetupContext("__set__", 0);
26990   __Pyx_TraceCall("__set__", __pyx_f[0], 2764);
26991   __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 = 2764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26992   __pyx_v_self->_delegate->core.isize = __pyx_t_1;
26993
26994   __pyx_r = 0;
26995   goto __pyx_L0;
26996   __pyx_L1_error:;
26997   __Pyx_AddTraceback("csamtools.AlignedRead.isize.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
26998   __pyx_r = -1;
26999   __pyx_L0:;
27000   __Pyx_TraceReturn(Py_None);
27001   __Pyx_RefNannyFinishContext();
27002   return __pyx_r;
27003 }
27004
27005 /* Python wrapper */
27006 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/
27007 static PyObject *__pyx_pw_9csamtools_11AlignedRead_4tlen_1__get__(PyObject *__pyx_v_self) {
27008   PyObject *__pyx_r = 0;
27009   __Pyx_RefNannyDeclarations
27010   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27011   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4tlen___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27012   __Pyx_RefNannyFinishContext();
27013   return __pyx_r;
27014 }
27015
27016 /* "csamtools.pyx":2767
27017  *     property tlen:
27018  *         """the insert size"""
27019  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
27020  *         def __set__(self, isize): self._delegate.core.isize = isize
27021  *     property is_paired:
27022  */
27023
27024 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tlen___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27025   PyObject *__pyx_r = NULL;
27026   __Pyx_RefNannyDeclarations
27027   PyObject *__pyx_t_1 = NULL;
27028   int __pyx_lineno = 0;
27029   const char *__pyx_filename = NULL;
27030   int __pyx_clineno = 0;
27031   __Pyx_TraceDeclarations
27032   __Pyx_RefNannySetupContext("__get__", 0);
27033   __Pyx_TraceCall("__get__", __pyx_f[0], 2767);
27034   __Pyx_XDECREF(__pyx_r);
27035   __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 = 2767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27036   __Pyx_GOTREF(__pyx_t_1);
27037   __pyx_r = __pyx_t_1;
27038   __pyx_t_1 = 0;
27039   goto __pyx_L0;
27040
27041   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27042   goto __pyx_L0;
27043   __pyx_L1_error:;
27044   __Pyx_XDECREF(__pyx_t_1);
27045   __Pyx_AddTraceback("csamtools.AlignedRead.tlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27046   __pyx_r = NULL;
27047   __pyx_L0:;
27048   __Pyx_XGIVEREF(__pyx_r);
27049   __Pyx_TraceReturn(__pyx_r);
27050   __Pyx_RefNannyFinishContext();
27051   return __pyx_r;
27052 }
27053
27054 /* Python wrapper */
27055 static int __pyx_pw_9csamtools_11AlignedRead_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
27056 static int __pyx_pw_9csamtools_11AlignedRead_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
27057   int __pyx_r;
27058   __Pyx_RefNannyDeclarations
27059   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27060   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_4tlen_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_isize));
27061   __Pyx_RefNannyFinishContext();
27062   return __pyx_r;
27063 }
27064
27065 /* "csamtools.pyx":2768
27066  *         """the insert size"""
27067  *         def __get__(self): return self._delegate.core.isize
27068  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
27069  *     property is_paired:
27070  *         """true if read is paired in sequencing"""
27071  */
27072
27073 static int __pyx_pf_9csamtools_11AlignedRead_4tlen_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_isize) {
27074   int __pyx_r;
27075   __Pyx_RefNannyDeclarations
27076   int32_t __pyx_t_1;
27077   int __pyx_lineno = 0;
27078   const char *__pyx_filename = NULL;
27079   int __pyx_clineno = 0;
27080   __Pyx_TraceDeclarations
27081   __Pyx_RefNannySetupContext("__set__", 0);
27082   __Pyx_TraceCall("__set__", __pyx_f[0], 2768);
27083   __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 = 2768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27084   __pyx_v_self->_delegate->core.isize = __pyx_t_1;
27085
27086   __pyx_r = 0;
27087   goto __pyx_L0;
27088   __pyx_L1_error:;
27089   __Pyx_AddTraceback("csamtools.AlignedRead.tlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27090   __pyx_r = -1;
27091   __pyx_L0:;
27092   __Pyx_TraceReturn(Py_None);
27093   __Pyx_RefNannyFinishContext();
27094   return __pyx_r;
27095 }
27096
27097 /* Python wrapper */
27098 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/
27099 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9is_paired_1__get__(PyObject *__pyx_v_self) {
27100   PyObject *__pyx_r = 0;
27101   __Pyx_RefNannyDeclarations
27102   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27103   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27104   __Pyx_RefNannyFinishContext();
27105   return __pyx_r;
27106 }
27107
27108 /* "csamtools.pyx":2771
27109  *     property is_paired:
27110  *         """true if read is paired in sequencing"""
27111  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
27112  *         def __set__(self,val):
27113  *             if val: self._delegate.core.flag |= BAM_FPAIRED
27114  */
27115
27116 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27117   PyObject *__pyx_r = NULL;
27118   __Pyx_RefNannyDeclarations
27119   PyObject *__pyx_t_1 = NULL;
27120   int __pyx_lineno = 0;
27121   const char *__pyx_filename = NULL;
27122   int __pyx_clineno = 0;
27123   __Pyx_TraceDeclarations
27124   __Pyx_RefNannySetupContext("__get__", 0);
27125   __Pyx_TraceCall("__get__", __pyx_f[0], 2771);
27126   __Pyx_XDECREF(__pyx_r);
27127   __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 = 2771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27128   __Pyx_GOTREF(__pyx_t_1);
27129   __pyx_r = __pyx_t_1;
27130   __pyx_t_1 = 0;
27131   goto __pyx_L0;
27132
27133   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27134   goto __pyx_L0;
27135   __pyx_L1_error:;
27136   __Pyx_XDECREF(__pyx_t_1);
27137   __Pyx_AddTraceback("csamtools.AlignedRead.is_paired.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27138   __pyx_r = NULL;
27139   __pyx_L0:;
27140   __Pyx_XGIVEREF(__pyx_r);
27141   __Pyx_TraceReturn(__pyx_r);
27142   __Pyx_RefNannyFinishContext();
27143   return __pyx_r;
27144 }
27145
27146 /* Python wrapper */
27147 static int __pyx_pw_9csamtools_11AlignedRead_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27148 static int __pyx_pw_9csamtools_11AlignedRead_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27149   int __pyx_r;
27150   __Pyx_RefNannyDeclarations
27151   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27152   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_9is_paired_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27153   __Pyx_RefNannyFinishContext();
27154   return __pyx_r;
27155 }
27156
27157 /* "csamtools.pyx":2772
27158  *         """true if read is paired in sequencing"""
27159  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
27160  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27161  *             if val: self._delegate.core.flag |= BAM_FPAIRED
27162  *             else: self._delegate.core.flag &= ~BAM_FPAIRED
27163  */
27164
27165 static int __pyx_pf_9csamtools_11AlignedRead_9is_paired_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27166   int __pyx_r;
27167   __Pyx_RefNannyDeclarations
27168   int __pyx_t_1;
27169   int __pyx_lineno = 0;
27170   const char *__pyx_filename = NULL;
27171   int __pyx_clineno = 0;
27172   __Pyx_TraceDeclarations
27173   __Pyx_RefNannySetupContext("__set__", 0);
27174   __Pyx_TraceCall("__set__", __pyx_f[0], 2772);
27175
27176   /* "csamtools.pyx":2773
27177  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
27178  *         def __set__(self,val):
27179  *             if val: self._delegate.core.flag |= BAM_FPAIRED             # <<<<<<<<<<<<<<
27180  *             else: self._delegate.core.flag &= ~BAM_FPAIRED
27181  *     property is_proper_pair:
27182  */
27183   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27184   if (__pyx_t_1) {
27185     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 1);
27186     goto __pyx_L3;
27187   }
27188   /*else*/ {
27189
27190     /* "csamtools.pyx":2774
27191  *         def __set__(self,val):
27192  *             if val: self._delegate.core.flag |= BAM_FPAIRED
27193  *             else: self._delegate.core.flag &= ~BAM_FPAIRED             # <<<<<<<<<<<<<<
27194  *     property is_proper_pair:
27195  *         """true if read is mapped in a proper pair"""
27196  */
27197     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~1));
27198   }
27199   __pyx_L3:;
27200
27201   __pyx_r = 0;
27202   goto __pyx_L0;
27203   __pyx_L1_error:;
27204   __Pyx_AddTraceback("csamtools.AlignedRead.is_paired.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27205   __pyx_r = -1;
27206   __pyx_L0:;
27207   __Pyx_TraceReturn(Py_None);
27208   __Pyx_RefNannyFinishContext();
27209   return __pyx_r;
27210 }
27211
27212 /* Python wrapper */
27213 static PyObject *__pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/
27214 static PyObject *__pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_1__get__(PyObject *__pyx_v_self) {
27215   PyObject *__pyx_r = 0;
27216   __Pyx_RefNannyDeclarations
27217   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27218   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27219   __Pyx_RefNannyFinishContext();
27220   return __pyx_r;
27221 }
27222
27223 /* "csamtools.pyx":2777
27224  *     property is_proper_pair:
27225  *         """true if read is mapped in a proper pair"""
27226  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
27227  *         def __set__(self,val):
27228  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
27229  */
27230
27231 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27232   PyObject *__pyx_r = NULL;
27233   __Pyx_RefNannyDeclarations
27234   PyObject *__pyx_t_1 = NULL;
27235   PyObject *__pyx_t_2 = NULL;
27236   int __pyx_lineno = 0;
27237   const char *__pyx_filename = NULL;
27238   int __pyx_clineno = 0;
27239   __Pyx_TraceDeclarations
27240   __Pyx_RefNannySetupContext("__get__", 0);
27241   __Pyx_TraceCall("__get__", __pyx_f[0], 2777);
27242   __Pyx_XDECREF(__pyx_r);
27243   __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 = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27244   __Pyx_GOTREF(__pyx_t_1);
27245   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27246   __Pyx_GOTREF(__pyx_t_2);
27247   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27248   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27249   __Pyx_GOTREF(__pyx_t_1);
27250   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27251   __pyx_r = __pyx_t_1;
27252   __pyx_t_1 = 0;
27253   goto __pyx_L0;
27254
27255   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27256   goto __pyx_L0;
27257   __pyx_L1_error:;
27258   __Pyx_XDECREF(__pyx_t_1);
27259   __Pyx_XDECREF(__pyx_t_2);
27260   __Pyx_AddTraceback("csamtools.AlignedRead.is_proper_pair.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27261   __pyx_r = NULL;
27262   __pyx_L0:;
27263   __Pyx_XGIVEREF(__pyx_r);
27264   __Pyx_TraceReturn(__pyx_r);
27265   __Pyx_RefNannyFinishContext();
27266   return __pyx_r;
27267 }
27268
27269 /* Python wrapper */
27270 static int __pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27271 static int __pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27272   int __pyx_r;
27273   __Pyx_RefNannyDeclarations
27274   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27275   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27276   __Pyx_RefNannyFinishContext();
27277   return __pyx_r;
27278 }
27279
27280 /* "csamtools.pyx":2778
27281  *         """true if read is mapped in a proper pair"""
27282  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
27283  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27284  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
27285  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
27286  */
27287
27288 static int __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27289   int __pyx_r;
27290   __Pyx_RefNannyDeclarations
27291   int __pyx_t_1;
27292   int __pyx_lineno = 0;
27293   const char *__pyx_filename = NULL;
27294   int __pyx_clineno = 0;
27295   __Pyx_TraceDeclarations
27296   __Pyx_RefNannySetupContext("__set__", 0);
27297   __Pyx_TraceCall("__set__", __pyx_f[0], 2778);
27298
27299   /* "csamtools.pyx":2779
27300  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
27301  *         def __set__(self,val):
27302  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
27303  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
27304  *     property is_unmapped:
27305  */
27306   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27307   if (__pyx_t_1) {
27308     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 2);
27309     goto __pyx_L3;
27310   }
27311   /*else*/ {
27312
27313     /* "csamtools.pyx":2780
27314  *         def __set__(self,val):
27315  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
27316  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
27317  *     property is_unmapped:
27318  *         """true if read itself is unmapped"""
27319  */
27320     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~2));
27321   }
27322   __pyx_L3:;
27323
27324   __pyx_r = 0;
27325   goto __pyx_L0;
27326   __pyx_L1_error:;
27327   __Pyx_AddTraceback("csamtools.AlignedRead.is_proper_pair.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27328   __pyx_r = -1;
27329   __pyx_L0:;
27330   __Pyx_TraceReturn(Py_None);
27331   __Pyx_RefNannyFinishContext();
27332   return __pyx_r;
27333 }
27334
27335 /* Python wrapper */
27336 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
27337 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11is_unmapped_1__get__(PyObject *__pyx_v_self) {
27338   PyObject *__pyx_r = 0;
27339   __Pyx_RefNannyDeclarations
27340   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27341   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27342   __Pyx_RefNannyFinishContext();
27343   return __pyx_r;
27344 }
27345
27346 /* "csamtools.pyx":2783
27347  *     property is_unmapped:
27348  *         """true if read itself is unmapped"""
27349  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
27350  *         def __set__(self,val):
27351  *             if val: self._delegate.core.flag |= BAM_FUNMAP
27352  */
27353
27354 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27355   PyObject *__pyx_r = NULL;
27356   __Pyx_RefNannyDeclarations
27357   PyObject *__pyx_t_1 = NULL;
27358   PyObject *__pyx_t_2 = NULL;
27359   int __pyx_lineno = 0;
27360   const char *__pyx_filename = NULL;
27361   int __pyx_clineno = 0;
27362   __Pyx_TraceDeclarations
27363   __Pyx_RefNannySetupContext("__get__", 0);
27364   __Pyx_TraceCall("__get__", __pyx_f[0], 2783);
27365   __Pyx_XDECREF(__pyx_r);
27366   __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 = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27367   __Pyx_GOTREF(__pyx_t_1);
27368   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27369   __Pyx_GOTREF(__pyx_t_2);
27370   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27371   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27372   __Pyx_GOTREF(__pyx_t_1);
27373   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27374   __pyx_r = __pyx_t_1;
27375   __pyx_t_1 = 0;
27376   goto __pyx_L0;
27377
27378   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27379   goto __pyx_L0;
27380   __pyx_L1_error:;
27381   __Pyx_XDECREF(__pyx_t_1);
27382   __Pyx_XDECREF(__pyx_t_2);
27383   __Pyx_AddTraceback("csamtools.AlignedRead.is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27384   __pyx_r = NULL;
27385   __pyx_L0:;
27386   __Pyx_XGIVEREF(__pyx_r);
27387   __Pyx_TraceReturn(__pyx_r);
27388   __Pyx_RefNannyFinishContext();
27389   return __pyx_r;
27390 }
27391
27392 /* Python wrapper */
27393 static int __pyx_pw_9csamtools_11AlignedRead_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27394 static int __pyx_pw_9csamtools_11AlignedRead_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27395   int __pyx_r;
27396   __Pyx_RefNannyDeclarations
27397   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27398   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27399   __Pyx_RefNannyFinishContext();
27400   return __pyx_r;
27401 }
27402
27403 /* "csamtools.pyx":2784
27404  *         """true if read itself is unmapped"""
27405  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
27406  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27407  *             if val: self._delegate.core.flag |= BAM_FUNMAP
27408  *             else: self._delegate.core.flag &= ~BAM_FUNMAP
27409  */
27410
27411 static int __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27412   int __pyx_r;
27413   __Pyx_RefNannyDeclarations
27414   int __pyx_t_1;
27415   int __pyx_lineno = 0;
27416   const char *__pyx_filename = NULL;
27417   int __pyx_clineno = 0;
27418   __Pyx_TraceDeclarations
27419   __Pyx_RefNannySetupContext("__set__", 0);
27420   __Pyx_TraceCall("__set__", __pyx_f[0], 2784);
27421
27422   /* "csamtools.pyx":2785
27423  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
27424  *         def __set__(self,val):
27425  *             if val: self._delegate.core.flag |= BAM_FUNMAP             # <<<<<<<<<<<<<<
27426  *             else: self._delegate.core.flag &= ~BAM_FUNMAP
27427  *     property mate_is_unmapped:
27428  */
27429   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27430   if (__pyx_t_1) {
27431     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 4);
27432     goto __pyx_L3;
27433   }
27434   /*else*/ {
27435
27436     /* "csamtools.pyx":2786
27437  *         def __set__(self,val):
27438  *             if val: self._delegate.core.flag |= BAM_FUNMAP
27439  *             else: self._delegate.core.flag &= ~BAM_FUNMAP             # <<<<<<<<<<<<<<
27440  *     property mate_is_unmapped:
27441  *         """true if the mate is unmapped"""
27442  */
27443     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~4));
27444   }
27445   __pyx_L3:;
27446
27447   __pyx_r = 0;
27448   goto __pyx_L0;
27449   __pyx_L1_error:;
27450   __Pyx_AddTraceback("csamtools.AlignedRead.is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27451   __pyx_r = -1;
27452   __pyx_L0:;
27453   __Pyx_TraceReturn(Py_None);
27454   __Pyx_RefNannyFinishContext();
27455   return __pyx_r;
27456 }
27457
27458 /* Python wrapper */
27459 static PyObject *__pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
27460 static PyObject *__pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) {
27461   PyObject *__pyx_r = 0;
27462   __Pyx_RefNannyDeclarations
27463   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27464   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27465   __Pyx_RefNannyFinishContext();
27466   return __pyx_r;
27467 }
27468
27469 /* "csamtools.pyx":2789
27470  *     property mate_is_unmapped:
27471  *         """true if the mate is unmapped"""
27472  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
27473  *         def __set__(self,val):
27474  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
27475  */
27476
27477 static PyObject *__pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27478   PyObject *__pyx_r = NULL;
27479   __Pyx_RefNannyDeclarations
27480   PyObject *__pyx_t_1 = NULL;
27481   PyObject *__pyx_t_2 = NULL;
27482   int __pyx_lineno = 0;
27483   const char *__pyx_filename = NULL;
27484   int __pyx_clineno = 0;
27485   __Pyx_TraceDeclarations
27486   __Pyx_RefNannySetupContext("__get__", 0);
27487   __Pyx_TraceCall("__get__", __pyx_f[0], 2789);
27488   __Pyx_XDECREF(__pyx_r);
27489   __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 = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27490   __Pyx_GOTREF(__pyx_t_1);
27491   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27492   __Pyx_GOTREF(__pyx_t_2);
27493   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27494   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27495   __Pyx_GOTREF(__pyx_t_1);
27496   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27497   __pyx_r = __pyx_t_1;
27498   __pyx_t_1 = 0;
27499   goto __pyx_L0;
27500
27501   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27502   goto __pyx_L0;
27503   __pyx_L1_error:;
27504   __Pyx_XDECREF(__pyx_t_1);
27505   __Pyx_XDECREF(__pyx_t_2);
27506   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27507   __pyx_r = NULL;
27508   __pyx_L0:;
27509   __Pyx_XGIVEREF(__pyx_r);
27510   __Pyx_TraceReturn(__pyx_r);
27511   __Pyx_RefNannyFinishContext();
27512   return __pyx_r;
27513 }
27514
27515 /* Python wrapper */
27516 static int __pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27517 static int __pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27518   int __pyx_r;
27519   __Pyx_RefNannyDeclarations
27520   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27521   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27522   __Pyx_RefNannyFinishContext();
27523   return __pyx_r;
27524 }
27525
27526 /* "csamtools.pyx":2790
27527  *         """true if the mate is unmapped"""
27528  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
27529  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27530  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
27531  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
27532  */
27533
27534 static int __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27535   int __pyx_r;
27536   __Pyx_RefNannyDeclarations
27537   int __pyx_t_1;
27538   int __pyx_lineno = 0;
27539   const char *__pyx_filename = NULL;
27540   int __pyx_clineno = 0;
27541   __Pyx_TraceDeclarations
27542   __Pyx_RefNannySetupContext("__set__", 0);
27543   __Pyx_TraceCall("__set__", __pyx_f[0], 2790);
27544
27545   /* "csamtools.pyx":2791
27546  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
27547  *         def __set__(self,val):
27548  *             if val: self._delegate.core.flag |= BAM_FMUNMAP             # <<<<<<<<<<<<<<
27549  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
27550  *     property is_reverse:
27551  */
27552   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27553   if (__pyx_t_1) {
27554     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 8);
27555     goto __pyx_L3;
27556   }
27557   /*else*/ {
27558
27559     /* "csamtools.pyx":2792
27560  *         def __set__(self,val):
27561  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
27562  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP             # <<<<<<<<<<<<<<
27563  *     property is_reverse:
27564  *         """true if read is mapped to reverse strand"""
27565  */
27566     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~8));
27567   }
27568   __pyx_L3:;
27569
27570   __pyx_r = 0;
27571   goto __pyx_L0;
27572   __pyx_L1_error:;
27573   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_unmapped.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27574   __pyx_r = -1;
27575   __pyx_L0:;
27576   __Pyx_TraceReturn(Py_None);
27577   __Pyx_RefNannyFinishContext();
27578   return __pyx_r;
27579 }
27580
27581 /* Python wrapper */
27582 static PyObject *__pyx_pw_9csamtools_11AlignedRead_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
27583 static PyObject *__pyx_pw_9csamtools_11AlignedRead_10is_reverse_1__get__(PyObject *__pyx_v_self) {
27584   PyObject *__pyx_r = 0;
27585   __Pyx_RefNannyDeclarations
27586   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27587   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27588   __Pyx_RefNannyFinishContext();
27589   return __pyx_r;
27590 }
27591
27592 /* "csamtools.pyx":2795
27593  *     property is_reverse:
27594  *         """true if read is mapped to reverse strand"""
27595  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
27596  *         def __set__(self,val):
27597  *             if val: self._delegate.core.flag |= BAM_FREVERSE
27598  */
27599
27600 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27601   PyObject *__pyx_r = NULL;
27602   __Pyx_RefNannyDeclarations
27603   PyObject *__pyx_t_1 = NULL;
27604   PyObject *__pyx_t_2 = NULL;
27605   int __pyx_lineno = 0;
27606   const char *__pyx_filename = NULL;
27607   int __pyx_clineno = 0;
27608   __Pyx_TraceDeclarations
27609   __Pyx_RefNannySetupContext("__get__", 0);
27610   __Pyx_TraceCall("__get__", __pyx_f[0], 2795);
27611   __Pyx_XDECREF(__pyx_r);
27612   __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 = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27613   __Pyx_GOTREF(__pyx_t_1);
27614   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27615   __Pyx_GOTREF(__pyx_t_2);
27616   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27617   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27618   __Pyx_GOTREF(__pyx_t_1);
27619   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27620   __pyx_r = __pyx_t_1;
27621   __pyx_t_1 = 0;
27622   goto __pyx_L0;
27623
27624   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27625   goto __pyx_L0;
27626   __pyx_L1_error:;
27627   __Pyx_XDECREF(__pyx_t_1);
27628   __Pyx_XDECREF(__pyx_t_2);
27629   __Pyx_AddTraceback("csamtools.AlignedRead.is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27630   __pyx_r = NULL;
27631   __pyx_L0:;
27632   __Pyx_XGIVEREF(__pyx_r);
27633   __Pyx_TraceReturn(__pyx_r);
27634   __Pyx_RefNannyFinishContext();
27635   return __pyx_r;
27636 }
27637
27638 /* Python wrapper */
27639 static int __pyx_pw_9csamtools_11AlignedRead_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27640 static int __pyx_pw_9csamtools_11AlignedRead_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27641   int __pyx_r;
27642   __Pyx_RefNannyDeclarations
27643   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27644   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_10is_reverse_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27645   __Pyx_RefNannyFinishContext();
27646   return __pyx_r;
27647 }
27648
27649 /* "csamtools.pyx":2796
27650  *         """true if read is mapped to reverse strand"""
27651  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
27652  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27653  *             if val: self._delegate.core.flag |= BAM_FREVERSE
27654  *             else: self._delegate.core.flag &= ~BAM_FREVERSE
27655  */
27656
27657 static int __pyx_pf_9csamtools_11AlignedRead_10is_reverse_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27658   int __pyx_r;
27659   __Pyx_RefNannyDeclarations
27660   int __pyx_t_1;
27661   int __pyx_lineno = 0;
27662   const char *__pyx_filename = NULL;
27663   int __pyx_clineno = 0;
27664   __Pyx_TraceDeclarations
27665   __Pyx_RefNannySetupContext("__set__", 0);
27666   __Pyx_TraceCall("__set__", __pyx_f[0], 2796);
27667
27668   /* "csamtools.pyx":2797
27669  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
27670  *         def __set__(self,val):
27671  *             if val: self._delegate.core.flag |= BAM_FREVERSE             # <<<<<<<<<<<<<<
27672  *             else: self._delegate.core.flag &= ~BAM_FREVERSE
27673  *     property mate_is_reverse:
27674  */
27675   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27676   if (__pyx_t_1) {
27677     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 16);
27678     goto __pyx_L3;
27679   }
27680   /*else*/ {
27681
27682     /* "csamtools.pyx":2798
27683  *         def __set__(self,val):
27684  *             if val: self._delegate.core.flag |= BAM_FREVERSE
27685  *             else: self._delegate.core.flag &= ~BAM_FREVERSE             # <<<<<<<<<<<<<<
27686  *     property mate_is_reverse:
27687  *         """true is read is mapped to reverse strand"""
27688  */
27689     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~16));
27690   }
27691   __pyx_L3:;
27692
27693   __pyx_r = 0;
27694   goto __pyx_L0;
27695   __pyx_L1_error:;
27696   __Pyx_AddTraceback("csamtools.AlignedRead.is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27697   __pyx_r = -1;
27698   __pyx_L0:;
27699   __Pyx_TraceReturn(Py_None);
27700   __Pyx_RefNannyFinishContext();
27701   return __pyx_r;
27702 }
27703
27704 /* Python wrapper */
27705 static PyObject *__pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
27706 static PyObject *__pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) {
27707   PyObject *__pyx_r = 0;
27708   __Pyx_RefNannyDeclarations
27709   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27710   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27711   __Pyx_RefNannyFinishContext();
27712   return __pyx_r;
27713 }
27714
27715 /* "csamtools.pyx":2801
27716  *     property mate_is_reverse:
27717  *         """true is read is mapped to reverse strand"""
27718  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
27719  *         def __set__(self,val):
27720  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
27721  */
27722
27723 static PyObject *__pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27724   PyObject *__pyx_r = NULL;
27725   __Pyx_RefNannyDeclarations
27726   PyObject *__pyx_t_1 = NULL;
27727   PyObject *__pyx_t_2 = NULL;
27728   int __pyx_lineno = 0;
27729   const char *__pyx_filename = NULL;
27730   int __pyx_clineno = 0;
27731   __Pyx_TraceDeclarations
27732   __Pyx_RefNannySetupContext("__get__", 0);
27733   __Pyx_TraceCall("__get__", __pyx_f[0], 2801);
27734   __Pyx_XDECREF(__pyx_r);
27735   __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 = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27736   __Pyx_GOTREF(__pyx_t_1);
27737   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27738   __Pyx_GOTREF(__pyx_t_2);
27739   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27740   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27741   __Pyx_GOTREF(__pyx_t_1);
27742   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27743   __pyx_r = __pyx_t_1;
27744   __pyx_t_1 = 0;
27745   goto __pyx_L0;
27746
27747   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27748   goto __pyx_L0;
27749   __pyx_L1_error:;
27750   __Pyx_XDECREF(__pyx_t_1);
27751   __Pyx_XDECREF(__pyx_t_2);
27752   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_reverse.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27753   __pyx_r = NULL;
27754   __pyx_L0:;
27755   __Pyx_XGIVEREF(__pyx_r);
27756   __Pyx_TraceReturn(__pyx_r);
27757   __Pyx_RefNannyFinishContext();
27758   return __pyx_r;
27759 }
27760
27761 /* Python wrapper */
27762 static int __pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27763 static int __pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27764   int __pyx_r;
27765   __Pyx_RefNannyDeclarations
27766   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27767   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27768   __Pyx_RefNannyFinishContext();
27769   return __pyx_r;
27770 }
27771
27772 /* "csamtools.pyx":2802
27773  *         """true is read is mapped to reverse strand"""
27774  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
27775  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27776  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
27777  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
27778  */
27779
27780 static int __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27781   int __pyx_r;
27782   __Pyx_RefNannyDeclarations
27783   int __pyx_t_1;
27784   int __pyx_lineno = 0;
27785   const char *__pyx_filename = NULL;
27786   int __pyx_clineno = 0;
27787   __Pyx_TraceDeclarations
27788   __Pyx_RefNannySetupContext("__set__", 0);
27789   __Pyx_TraceCall("__set__", __pyx_f[0], 2802);
27790
27791   /* "csamtools.pyx":2803
27792  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
27793  *         def __set__(self,val):
27794  *             if val: self._delegate.core.flag |= BAM_FMREVERSE             # <<<<<<<<<<<<<<
27795  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
27796  *     property is_read1:
27797  */
27798   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27799   if (__pyx_t_1) {
27800     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 32);
27801     goto __pyx_L3;
27802   }
27803   /*else*/ {
27804
27805     /* "csamtools.pyx":2804
27806  *         def __set__(self,val):
27807  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
27808  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE             # <<<<<<<<<<<<<<
27809  *     property is_read1:
27810  *         """true if this is read1"""
27811  */
27812     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~32));
27813   }
27814   __pyx_L3:;
27815
27816   __pyx_r = 0;
27817   goto __pyx_L0;
27818   __pyx_L1_error:;
27819   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_reverse.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27820   __pyx_r = -1;
27821   __pyx_L0:;
27822   __Pyx_TraceReturn(Py_None);
27823   __Pyx_RefNannyFinishContext();
27824   return __pyx_r;
27825 }
27826
27827 /* Python wrapper */
27828 static PyObject *__pyx_pw_9csamtools_11AlignedRead_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/
27829 static PyObject *__pyx_pw_9csamtools_11AlignedRead_8is_read1_1__get__(PyObject *__pyx_v_self) {
27830   PyObject *__pyx_r = 0;
27831   __Pyx_RefNannyDeclarations
27832   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27833   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27834   __Pyx_RefNannyFinishContext();
27835   return __pyx_r;
27836 }
27837
27838 /* "csamtools.pyx":2807
27839  *     property is_read1:
27840  *         """true if this is read1"""
27841  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
27842  *         def __set__(self,val):
27843  *             if val: self._delegate.core.flag |= BAM_FREAD1
27844  */
27845
27846 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27847   PyObject *__pyx_r = NULL;
27848   __Pyx_RefNannyDeclarations
27849   PyObject *__pyx_t_1 = NULL;
27850   PyObject *__pyx_t_2 = NULL;
27851   int __pyx_lineno = 0;
27852   const char *__pyx_filename = NULL;
27853   int __pyx_clineno = 0;
27854   __Pyx_TraceDeclarations
27855   __Pyx_RefNannySetupContext("__get__", 0);
27856   __Pyx_TraceCall("__get__", __pyx_f[0], 2807);
27857   __Pyx_XDECREF(__pyx_r);
27858   __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 = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27859   __Pyx_GOTREF(__pyx_t_1);
27860   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27861   __Pyx_GOTREF(__pyx_t_2);
27862   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27863   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27864   __Pyx_GOTREF(__pyx_t_1);
27865   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27866   __pyx_r = __pyx_t_1;
27867   __pyx_t_1 = 0;
27868   goto __pyx_L0;
27869
27870   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27871   goto __pyx_L0;
27872   __pyx_L1_error:;
27873   __Pyx_XDECREF(__pyx_t_1);
27874   __Pyx_XDECREF(__pyx_t_2);
27875   __Pyx_AddTraceback("csamtools.AlignedRead.is_read1.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27876   __pyx_r = NULL;
27877   __pyx_L0:;
27878   __Pyx_XGIVEREF(__pyx_r);
27879   __Pyx_TraceReturn(__pyx_r);
27880   __Pyx_RefNannyFinishContext();
27881   return __pyx_r;
27882 }
27883
27884 /* Python wrapper */
27885 static int __pyx_pw_9csamtools_11AlignedRead_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
27886 static int __pyx_pw_9csamtools_11AlignedRead_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
27887   int __pyx_r;
27888   __Pyx_RefNannyDeclarations
27889   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
27890   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_8is_read1_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
27891   __Pyx_RefNannyFinishContext();
27892   return __pyx_r;
27893 }
27894
27895 /* "csamtools.pyx":2808
27896  *         """true if this is read1"""
27897  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
27898  *         def __set__(self,val):             # <<<<<<<<<<<<<<
27899  *             if val: self._delegate.core.flag |= BAM_FREAD1
27900  *             else: self._delegate.core.flag &= ~BAM_FREAD1
27901  */
27902
27903 static int __pyx_pf_9csamtools_11AlignedRead_8is_read1_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
27904   int __pyx_r;
27905   __Pyx_RefNannyDeclarations
27906   int __pyx_t_1;
27907   int __pyx_lineno = 0;
27908   const char *__pyx_filename = NULL;
27909   int __pyx_clineno = 0;
27910   __Pyx_TraceDeclarations
27911   __Pyx_RefNannySetupContext("__set__", 0);
27912   __Pyx_TraceCall("__set__", __pyx_f[0], 2808);
27913
27914   /* "csamtools.pyx":2809
27915  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
27916  *         def __set__(self,val):
27917  *             if val: self._delegate.core.flag |= BAM_FREAD1             # <<<<<<<<<<<<<<
27918  *             else: self._delegate.core.flag &= ~BAM_FREAD1
27919  *     property is_read2:
27920  */
27921   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27922   if (__pyx_t_1) {
27923     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 64);
27924     goto __pyx_L3;
27925   }
27926   /*else*/ {
27927
27928     /* "csamtools.pyx":2810
27929  *         def __set__(self,val):
27930  *             if val: self._delegate.core.flag |= BAM_FREAD1
27931  *             else: self._delegate.core.flag &= ~BAM_FREAD1             # <<<<<<<<<<<<<<
27932  *     property is_read2:
27933  *         """true if this is read2"""
27934  */
27935     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~64));
27936   }
27937   __pyx_L3:;
27938
27939   __pyx_r = 0;
27940   goto __pyx_L0;
27941   __pyx_L1_error:;
27942   __Pyx_AddTraceback("csamtools.AlignedRead.is_read1.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27943   __pyx_r = -1;
27944   __pyx_L0:;
27945   __Pyx_TraceReturn(Py_None);
27946   __Pyx_RefNannyFinishContext();
27947   return __pyx_r;
27948 }
27949
27950 /* Python wrapper */
27951 static PyObject *__pyx_pw_9csamtools_11AlignedRead_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/
27952 static PyObject *__pyx_pw_9csamtools_11AlignedRead_8is_read2_1__get__(PyObject *__pyx_v_self) {
27953   PyObject *__pyx_r = 0;
27954   __Pyx_RefNannyDeclarations
27955   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
27956   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
27957   __Pyx_RefNannyFinishContext();
27958   return __pyx_r;
27959 }
27960
27961 /* "csamtools.pyx":2813
27962  *     property is_read2:
27963  *         """true if this is read2"""
27964  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
27965  *         def __set__(self,val):
27966  *             if val: self._delegate.core.flag |= BAM_FREAD2
27967  */
27968
27969 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
27970   PyObject *__pyx_r = NULL;
27971   __Pyx_RefNannyDeclarations
27972   PyObject *__pyx_t_1 = NULL;
27973   PyObject *__pyx_t_2 = NULL;
27974   int __pyx_lineno = 0;
27975   const char *__pyx_filename = NULL;
27976   int __pyx_clineno = 0;
27977   __Pyx_TraceDeclarations
27978   __Pyx_RefNannySetupContext("__get__", 0);
27979   __Pyx_TraceCall("__get__", __pyx_f[0], 2813);
27980   __Pyx_XDECREF(__pyx_r);
27981   __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 = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27982   __Pyx_GOTREF(__pyx_t_1);
27983   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27984   __Pyx_GOTREF(__pyx_t_2);
27985   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27986   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27987   __Pyx_GOTREF(__pyx_t_1);
27988   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27989   __pyx_r = __pyx_t_1;
27990   __pyx_t_1 = 0;
27991   goto __pyx_L0;
27992
27993   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27994   goto __pyx_L0;
27995   __pyx_L1_error:;
27996   __Pyx_XDECREF(__pyx_t_1);
27997   __Pyx_XDECREF(__pyx_t_2);
27998   __Pyx_AddTraceback("csamtools.AlignedRead.is_read2.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
27999   __pyx_r = NULL;
28000   __pyx_L0:;
28001   __Pyx_XGIVEREF(__pyx_r);
28002   __Pyx_TraceReturn(__pyx_r);
28003   __Pyx_RefNannyFinishContext();
28004   return __pyx_r;
28005 }
28006
28007 /* Python wrapper */
28008 static int __pyx_pw_9csamtools_11AlignedRead_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
28009 static int __pyx_pw_9csamtools_11AlignedRead_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
28010   int __pyx_r;
28011   __Pyx_RefNannyDeclarations
28012   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
28013   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_8is_read2_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
28014   __Pyx_RefNannyFinishContext();
28015   return __pyx_r;
28016 }
28017
28018 /* "csamtools.pyx":2814
28019  *         """true if this is read2"""
28020  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
28021  *         def __set__(self,val):             # <<<<<<<<<<<<<<
28022  *             if val: self._delegate.core.flag |= BAM_FREAD2
28023  *             else: self._delegate.core.flag &= ~BAM_FREAD2
28024  */
28025
28026 static int __pyx_pf_9csamtools_11AlignedRead_8is_read2_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
28027   int __pyx_r;
28028   __Pyx_RefNannyDeclarations
28029   int __pyx_t_1;
28030   int __pyx_lineno = 0;
28031   const char *__pyx_filename = NULL;
28032   int __pyx_clineno = 0;
28033   __Pyx_TraceDeclarations
28034   __Pyx_RefNannySetupContext("__set__", 0);
28035   __Pyx_TraceCall("__set__", __pyx_f[0], 2814);
28036
28037   /* "csamtools.pyx":2815
28038  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
28039  *         def __set__(self,val):
28040  *             if val: self._delegate.core.flag |= BAM_FREAD2             # <<<<<<<<<<<<<<
28041  *             else: self._delegate.core.flag &= ~BAM_FREAD2
28042  *     property is_secondary:
28043  */
28044   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28045   if (__pyx_t_1) {
28046     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 128);
28047     goto __pyx_L3;
28048   }
28049   /*else*/ {
28050
28051     /* "csamtools.pyx":2816
28052  *         def __set__(self,val):
28053  *             if val: self._delegate.core.flag |= BAM_FREAD2
28054  *             else: self._delegate.core.flag &= ~BAM_FREAD2             # <<<<<<<<<<<<<<
28055  *     property is_secondary:
28056  *         """true if not primary alignment"""
28057  */
28058     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~128));
28059   }
28060   __pyx_L3:;
28061
28062   __pyx_r = 0;
28063   goto __pyx_L0;
28064   __pyx_L1_error:;
28065   __Pyx_AddTraceback("csamtools.AlignedRead.is_read2.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28066   __pyx_r = -1;
28067   __pyx_L0:;
28068   __Pyx_TraceReturn(Py_None);
28069   __Pyx_RefNannyFinishContext();
28070   return __pyx_r;
28071 }
28072
28073 /* Python wrapper */
28074 static PyObject *__pyx_pw_9csamtools_11AlignedRead_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/
28075 static PyObject *__pyx_pw_9csamtools_11AlignedRead_12is_secondary_1__get__(PyObject *__pyx_v_self) {
28076   PyObject *__pyx_r = 0;
28077   __Pyx_RefNannyDeclarations
28078   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
28079   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
28080   __Pyx_RefNannyFinishContext();
28081   return __pyx_r;
28082 }
28083
28084 /* "csamtools.pyx":2819
28085  *     property is_secondary:
28086  *         """true if not primary alignment"""
28087  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
28088  *         def __set__(self,val):
28089  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
28090  */
28091
28092 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
28093   PyObject *__pyx_r = NULL;
28094   __Pyx_RefNannyDeclarations
28095   PyObject *__pyx_t_1 = NULL;
28096   PyObject *__pyx_t_2 = NULL;
28097   int __pyx_lineno = 0;
28098   const char *__pyx_filename = NULL;
28099   int __pyx_clineno = 0;
28100   __Pyx_TraceDeclarations
28101   __Pyx_RefNannySetupContext("__get__", 0);
28102   __Pyx_TraceCall("__get__", __pyx_f[0], 2819);
28103   __Pyx_XDECREF(__pyx_r);
28104   __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 = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28105   __Pyx_GOTREF(__pyx_t_1);
28106   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28107   __Pyx_GOTREF(__pyx_t_2);
28108   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
28109   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28110   __Pyx_GOTREF(__pyx_t_1);
28111   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28112   __pyx_r = __pyx_t_1;
28113   __pyx_t_1 = 0;
28114   goto __pyx_L0;
28115
28116   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
28117   goto __pyx_L0;
28118   __pyx_L1_error:;
28119   __Pyx_XDECREF(__pyx_t_1);
28120   __Pyx_XDECREF(__pyx_t_2);
28121   __Pyx_AddTraceback("csamtools.AlignedRead.is_secondary.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28122   __pyx_r = NULL;
28123   __pyx_L0:;
28124   __Pyx_XGIVEREF(__pyx_r);
28125   __Pyx_TraceReturn(__pyx_r);
28126   __Pyx_RefNannyFinishContext();
28127   return __pyx_r;
28128 }
28129
28130 /* Python wrapper */
28131 static int __pyx_pw_9csamtools_11AlignedRead_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
28132 static int __pyx_pw_9csamtools_11AlignedRead_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
28133   int __pyx_r;
28134   __Pyx_RefNannyDeclarations
28135   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
28136   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_12is_secondary_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
28137   __Pyx_RefNannyFinishContext();
28138   return __pyx_r;
28139 }
28140
28141 /* "csamtools.pyx":2820
28142  *         """true if not primary alignment"""
28143  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
28144  *         def __set__(self,val):             # <<<<<<<<<<<<<<
28145  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
28146  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
28147  */
28148
28149 static int __pyx_pf_9csamtools_11AlignedRead_12is_secondary_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
28150   int __pyx_r;
28151   __Pyx_RefNannyDeclarations
28152   int __pyx_t_1;
28153   int __pyx_lineno = 0;
28154   const char *__pyx_filename = NULL;
28155   int __pyx_clineno = 0;
28156   __Pyx_TraceDeclarations
28157   __Pyx_RefNannySetupContext("__set__", 0);
28158   __Pyx_TraceCall("__set__", __pyx_f[0], 2820);
28159
28160   /* "csamtools.pyx":2821
28161  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
28162  *         def __set__(self,val):
28163  *             if val: self._delegate.core.flag |= BAM_FSECONDARY             # <<<<<<<<<<<<<<
28164  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
28165  *     property is_qcfail:
28166  */
28167   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28168   if (__pyx_t_1) {
28169     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 256);
28170     goto __pyx_L3;
28171   }
28172   /*else*/ {
28173
28174     /* "csamtools.pyx":2822
28175  *         def __set__(self,val):
28176  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
28177  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY             # <<<<<<<<<<<<<<
28178  *     property is_qcfail:
28179  *         """true if QC failure"""
28180  */
28181     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~256));
28182   }
28183   __pyx_L3:;
28184
28185   __pyx_r = 0;
28186   goto __pyx_L0;
28187   __pyx_L1_error:;
28188   __Pyx_AddTraceback("csamtools.AlignedRead.is_secondary.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28189   __pyx_r = -1;
28190   __pyx_L0:;
28191   __Pyx_TraceReturn(Py_None);
28192   __Pyx_RefNannyFinishContext();
28193   return __pyx_r;
28194 }
28195
28196 /* Python wrapper */
28197 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/
28198 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9is_qcfail_1__get__(PyObject *__pyx_v_self) {
28199   PyObject *__pyx_r = 0;
28200   __Pyx_RefNannyDeclarations
28201   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
28202   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
28203   __Pyx_RefNannyFinishContext();
28204   return __pyx_r;
28205 }
28206
28207 /* "csamtools.pyx":2825
28208  *     property is_qcfail:
28209  *         """true if QC failure"""
28210  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
28211  *         def __set__(self,val):
28212  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
28213  */
28214
28215 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
28216   PyObject *__pyx_r = NULL;
28217   __Pyx_RefNannyDeclarations
28218   PyObject *__pyx_t_1 = NULL;
28219   PyObject *__pyx_t_2 = NULL;
28220   int __pyx_lineno = 0;
28221   const char *__pyx_filename = NULL;
28222   int __pyx_clineno = 0;
28223   __Pyx_TraceDeclarations
28224   __Pyx_RefNannySetupContext("__get__", 0);
28225   __Pyx_TraceCall("__get__", __pyx_f[0], 2825);
28226   __Pyx_XDECREF(__pyx_r);
28227   __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 = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28228   __Pyx_GOTREF(__pyx_t_1);
28229   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_512); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28230   __Pyx_GOTREF(__pyx_t_2);
28231   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
28232   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28233   __Pyx_GOTREF(__pyx_t_1);
28234   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28235   __pyx_r = __pyx_t_1;
28236   __pyx_t_1 = 0;
28237   goto __pyx_L0;
28238
28239   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
28240   goto __pyx_L0;
28241   __pyx_L1_error:;
28242   __Pyx_XDECREF(__pyx_t_1);
28243   __Pyx_XDECREF(__pyx_t_2);
28244   __Pyx_AddTraceback("csamtools.AlignedRead.is_qcfail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28245   __pyx_r = NULL;
28246   __pyx_L0:;
28247   __Pyx_XGIVEREF(__pyx_r);
28248   __Pyx_TraceReturn(__pyx_r);
28249   __Pyx_RefNannyFinishContext();
28250   return __pyx_r;
28251 }
28252
28253 /* Python wrapper */
28254 static int __pyx_pw_9csamtools_11AlignedRead_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
28255 static int __pyx_pw_9csamtools_11AlignedRead_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
28256   int __pyx_r;
28257   __Pyx_RefNannyDeclarations
28258   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
28259   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
28260   __Pyx_RefNannyFinishContext();
28261   return __pyx_r;
28262 }
28263
28264 /* "csamtools.pyx":2826
28265  *         """true if QC failure"""
28266  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
28267  *         def __set__(self,val):             # <<<<<<<<<<<<<<
28268  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
28269  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
28270  */
28271
28272 static int __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
28273   int __pyx_r;
28274   __Pyx_RefNannyDeclarations
28275   int __pyx_t_1;
28276   int __pyx_lineno = 0;
28277   const char *__pyx_filename = NULL;
28278   int __pyx_clineno = 0;
28279   __Pyx_TraceDeclarations
28280   __Pyx_RefNannySetupContext("__set__", 0);
28281   __Pyx_TraceCall("__set__", __pyx_f[0], 2826);
28282
28283   /* "csamtools.pyx":2827
28284  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
28285  *         def __set__(self,val):
28286  *             if val: self._delegate.core.flag |= BAM_FQCFAIL             # <<<<<<<<<<<<<<
28287  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
28288  *     property is_duplicate:
28289  */
28290   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28291   if (__pyx_t_1) {
28292     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 512);
28293     goto __pyx_L3;
28294   }
28295   /*else*/ {
28296
28297     /* "csamtools.pyx":2828
28298  *         def __set__(self,val):
28299  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
28300  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL             # <<<<<<<<<<<<<<
28301  *     property is_duplicate:
28302  *         """true if optical or PCR duplicate"""
28303  */
28304     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~512));
28305   }
28306   __pyx_L3:;
28307
28308   __pyx_r = 0;
28309   goto __pyx_L0;
28310   __pyx_L1_error:;
28311   __Pyx_AddTraceback("csamtools.AlignedRead.is_qcfail.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28312   __pyx_r = -1;
28313   __pyx_L0:;
28314   __Pyx_TraceReturn(Py_None);
28315   __Pyx_RefNannyFinishContext();
28316   return __pyx_r;
28317 }
28318
28319 /* Python wrapper */
28320 static PyObject *__pyx_pw_9csamtools_11AlignedRead_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/
28321 static PyObject *__pyx_pw_9csamtools_11AlignedRead_12is_duplicate_1__get__(PyObject *__pyx_v_self) {
28322   PyObject *__pyx_r = 0;
28323   __Pyx_RefNannyDeclarations
28324   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
28325   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
28326   __Pyx_RefNannyFinishContext();
28327   return __pyx_r;
28328 }
28329
28330 /* "csamtools.pyx":2831
28331  *     property is_duplicate:
28332  *         """true if optical or PCR duplicate"""
28333  *         def __get__(self): return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
28334  *         def __set__(self,val):
28335  *             if val: self._delegate.core.flag |= BAM_FDUP
28336  */
28337
28338 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
28339   PyObject *__pyx_r = NULL;
28340   __Pyx_RefNannyDeclarations
28341   PyObject *__pyx_t_1 = NULL;
28342   PyObject *__pyx_t_2 = NULL;
28343   int __pyx_lineno = 0;
28344   const char *__pyx_filename = NULL;
28345   int __pyx_clineno = 0;
28346   __Pyx_TraceDeclarations
28347   __Pyx_RefNannySetupContext("__get__", 0);
28348   __Pyx_TraceCall("__get__", __pyx_f[0], 2831);
28349   __Pyx_XDECREF(__pyx_r);
28350   __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 = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28351   __Pyx_GOTREF(__pyx_t_1);
28352   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_1024); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28353   __Pyx_GOTREF(__pyx_t_2);
28354   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
28355   __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28356   __Pyx_GOTREF(__pyx_t_1);
28357   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28358   __pyx_r = __pyx_t_1;
28359   __pyx_t_1 = 0;
28360   goto __pyx_L0;
28361
28362   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
28363   goto __pyx_L0;
28364   __pyx_L1_error:;
28365   __Pyx_XDECREF(__pyx_t_1);
28366   __Pyx_XDECREF(__pyx_t_2);
28367   __Pyx_AddTraceback("csamtools.AlignedRead.is_duplicate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28368   __pyx_r = NULL;
28369   __pyx_L0:;
28370   __Pyx_XGIVEREF(__pyx_r);
28371   __Pyx_TraceReturn(__pyx_r);
28372   __Pyx_RefNannyFinishContext();
28373   return __pyx_r;
28374 }
28375
28376 /* Python wrapper */
28377 static int __pyx_pw_9csamtools_11AlignedRead_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
28378 static int __pyx_pw_9csamtools_11AlignedRead_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
28379   int __pyx_r;
28380   __Pyx_RefNannyDeclarations
28381   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
28382   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_2__set__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_val));
28383   __Pyx_RefNannyFinishContext();
28384   return __pyx_r;
28385 }
28386
28387 /* "csamtools.pyx":2832
28388  *         """true if optical or PCR duplicate"""
28389  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
28390  *         def __set__(self,val):             # <<<<<<<<<<<<<<
28391  *             if val: self._delegate.core.flag |= BAM_FDUP
28392  *             else: self._delegate.core.flag &= ~BAM_FDUP
28393  */
28394
28395 static int __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_2__set__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_val) {
28396   int __pyx_r;
28397   __Pyx_RefNannyDeclarations
28398   int __pyx_t_1;
28399   int __pyx_lineno = 0;
28400   const char *__pyx_filename = NULL;
28401   int __pyx_clineno = 0;
28402   __Pyx_TraceDeclarations
28403   __Pyx_RefNannySetupContext("__set__", 0);
28404   __Pyx_TraceCall("__set__", __pyx_f[0], 2832);
28405
28406   /* "csamtools.pyx":2833
28407  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
28408  *         def __set__(self,val):
28409  *             if val: self._delegate.core.flag |= BAM_FDUP             # <<<<<<<<<<<<<<
28410  *             else: self._delegate.core.flag &= ~BAM_FDUP
28411  *     property positions:
28412  */
28413   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28414   if (__pyx_t_1) {
28415     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag | 1024);
28416     goto __pyx_L3;
28417   }
28418   /*else*/ {
28419
28420     /* "csamtools.pyx":2834
28421  *         def __set__(self,val):
28422  *             if val: self._delegate.core.flag |= BAM_FDUP
28423  *             else: self._delegate.core.flag &= ~BAM_FDUP             # <<<<<<<<<<<<<<
28424  *     property positions:
28425  *         """a list of reference positions that this read aligns to."""
28426  */
28427     __pyx_v_self->_delegate->core.flag = (__pyx_v_self->_delegate->core.flag & (~1024));
28428   }
28429   __pyx_L3:;
28430
28431   __pyx_r = 0;
28432   goto __pyx_L0;
28433   __pyx_L1_error:;
28434   __Pyx_AddTraceback("csamtools.AlignedRead.is_duplicate.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28435   __pyx_r = -1;
28436   __pyx_L0:;
28437   __Pyx_TraceReturn(Py_None);
28438   __Pyx_RefNannyFinishContext();
28439   return __pyx_r;
28440 }
28441
28442 /* Python wrapper */
28443 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/
28444 static PyObject *__pyx_pw_9csamtools_11AlignedRead_9positions_1__get__(PyObject *__pyx_v_self) {
28445   PyObject *__pyx_r = 0;
28446   __Pyx_RefNannyDeclarations
28447   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
28448   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_9positions___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
28449   __Pyx_RefNannyFinishContext();
28450   return __pyx_r;
28451 }
28452
28453 /* "csamtools.pyx":2837
28454  *     property positions:
28455  *         """a list of reference positions that this read aligns to."""
28456  *         def __get__(self):             # <<<<<<<<<<<<<<
28457  *             cdef uint32_t k, i, pos
28458  *             cdef int op
28459  */
28460
28461 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9positions___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
28462   uint32_t __pyx_v_k;
28463   uint32_t __pyx_v_i;
28464   uint32_t __pyx_v_pos;
28465   int __pyx_v_op;
28466   uint32_t *__pyx_v_cigar_p;
28467   bam1_t *__pyx_v_src;
28468   PyObject *__pyx_v_result = NULL;
28469   PyObject *__pyx_v_l = NULL;
28470   PyObject *__pyx_r = NULL;
28471   __Pyx_RefNannyDeclarations
28472   int __pyx_t_1;
28473   PyObject *__pyx_t_2 = NULL;
28474   uint32_t __pyx_t_3;
28475   PyObject *__pyx_t_4 = NULL;
28476   uint32_t __pyx_t_5;
28477   int __pyx_t_6;
28478   int __pyx_lineno = 0;
28479   const char *__pyx_filename = NULL;
28480   int __pyx_clineno = 0;
28481   __Pyx_TraceDeclarations
28482   __Pyx_RefNannySetupContext("__get__", 0);
28483   __Pyx_TraceCall("__get__", __pyx_f[0], 2837);
28484
28485   /* "csamtools.pyx":2843
28486  *             cdef bam1_t * src
28487  * 
28488  *             src = self._delegate             # <<<<<<<<<<<<<<
28489  *             if src.core.n_cigar == 0: return []
28490  * 
28491  */
28492   __pyx_v_src = __pyx_v_self->_delegate;
28493
28494   /* "csamtools.pyx":2844
28495  * 
28496  *             src = self._delegate
28497  *             if src.core.n_cigar == 0: return []             # <<<<<<<<<<<<<<
28498  * 
28499  *             result = []
28500  */
28501   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
28502   if (__pyx_t_1) {
28503     __Pyx_XDECREF(__pyx_r);
28504     __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28505     __Pyx_GOTREF(__pyx_t_2);
28506     __pyx_r = ((PyObject *)__pyx_t_2);
28507     __pyx_t_2 = 0;
28508     goto __pyx_L0;
28509     goto __pyx_L3;
28510   }
28511   __pyx_L3:;
28512
28513   /* "csamtools.pyx":2846
28514  *             if src.core.n_cigar == 0: return []
28515  * 
28516  *             result = []             # <<<<<<<<<<<<<<
28517  *             pos = src.core.pos
28518  *             cigar_p = bam1_cigar(src)
28519  */
28520   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28521   __Pyx_GOTREF(__pyx_t_2);
28522   __pyx_v_result = __pyx_t_2;
28523   __pyx_t_2 = 0;
28524
28525   /* "csamtools.pyx":2847
28526  * 
28527  *             result = []
28528  *             pos = src.core.pos             # <<<<<<<<<<<<<<
28529  *             cigar_p = bam1_cigar(src)
28530  * 
28531  */
28532   __pyx_v_pos = __pyx_v_src->core.pos;
28533
28534   /* "csamtools.pyx":2848
28535  *             result = []
28536  *             pos = src.core.pos
28537  *             cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
28538  * 
28539  *             for k from 0 <= k < src.core.n_cigar:
28540  */
28541   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
28542
28543   /* "csamtools.pyx":2850
28544  *             cigar_p = bam1_cigar(src)
28545  * 
28546  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
28547  *                 op = cigar_p[k] & BAM_CIGAR_MASK
28548  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
28549  */
28550   __pyx_t_3 = __pyx_v_src->core.n_cigar;
28551   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
28552
28553     /* "csamtools.pyx":2851
28554  * 
28555  *             for k from 0 <= k < src.core.n_cigar:
28556  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
28557  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
28558  *                 if op == BAM_CMATCH:
28559  */
28560     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
28561
28562     /* "csamtools.pyx":2852
28563  *             for k from 0 <= k < src.core.n_cigar:
28564  *                 op = cigar_p[k] & BAM_CIGAR_MASK
28565  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
28566  *                 if op == BAM_CMATCH:
28567  *                     for i from pos <= i < pos + l:
28568  */
28569     __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28570     __Pyx_GOTREF(__pyx_t_2);
28571     __Pyx_XDECREF(__pyx_v_l);
28572     __pyx_v_l = __pyx_t_2;
28573     __pyx_t_2 = 0;
28574
28575     /* "csamtools.pyx":2853
28576  *                 op = cigar_p[k] & BAM_CIGAR_MASK
28577  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
28578  *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
28579  *                     for i from pos <= i < pos + l:
28580  *                         result.append( i )
28581  */
28582     __pyx_t_1 = (__pyx_v_op == 0);
28583     if (__pyx_t_1) {
28584
28585       /* "csamtools.pyx":2854
28586  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
28587  *                 if op == BAM_CMATCH:
28588  *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
28589  *                         result.append( i )
28590  * 
28591  */
28592       __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28593       __Pyx_GOTREF(__pyx_t_2);
28594       __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28595       __Pyx_GOTREF(__pyx_t_4);
28596       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28597       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28598       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
28599       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
28600
28601         /* "csamtools.pyx":2855
28602  *                 if op == BAM_CMATCH:
28603  *                     for i from pos <= i < pos + l:
28604  *                         result.append( i )             # <<<<<<<<<<<<<<
28605  * 
28606  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
28607  */
28608         __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28609         __Pyx_GOTREF(__pyx_t_4);
28610         __pyx_t_6 = PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28611         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
28612       }
28613       goto __pyx_L6;
28614     }
28615     __pyx_L6:;
28616
28617     /* "csamtools.pyx":2857
28618  *                         result.append( i )
28619  * 
28620  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
28621  *                     pos += l
28622  * 
28623  */
28624     switch (__pyx_v_op) {
28625       case 0:
28626       case 2:
28627       case 3:
28628
28629       /* "csamtools.pyx":2858
28630  * 
28631  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
28632  *                     pos += l             # <<<<<<<<<<<<<<
28633  * 
28634  *             return result
28635  */
28636       __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28637       __Pyx_GOTREF(__pyx_t_4);
28638       __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28639       __Pyx_GOTREF(__pyx_t_2);
28640       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
28641       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28642       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28643       __pyx_v_pos = __pyx_t_5;
28644       break;
28645     }
28646   }
28647
28648   /* "csamtools.pyx":2860
28649  *                     pos += l
28650  * 
28651  *             return result             # <<<<<<<<<<<<<<
28652  * 
28653  *     property aligned_pairs:
28654  */
28655   __Pyx_XDECREF(__pyx_r);
28656   __Pyx_INCREF(((PyObject *)__pyx_v_result));
28657   __pyx_r = ((PyObject *)__pyx_v_result);
28658   goto __pyx_L0;
28659
28660   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
28661   goto __pyx_L0;
28662   __pyx_L1_error:;
28663   __Pyx_XDECREF(__pyx_t_2);
28664   __Pyx_XDECREF(__pyx_t_4);
28665   __Pyx_AddTraceback("csamtools.AlignedRead.positions.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
28666   __pyx_r = NULL;
28667   __pyx_L0:;
28668   __Pyx_XDECREF(__pyx_v_result);
28669   __Pyx_XDECREF(__pyx_v_l);
28670   __Pyx_XGIVEREF(__pyx_r);
28671   __Pyx_TraceReturn(__pyx_r);
28672   __Pyx_RefNannyFinishContext();
28673   return __pyx_r;
28674 }
28675
28676 /* Python wrapper */
28677 static PyObject *__pyx_pw_9csamtools_11AlignedRead_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/
28678 static PyObject *__pyx_pw_9csamtools_11AlignedRead_13aligned_pairs_1__get__(PyObject *__pyx_v_self) {
28679   PyObject *__pyx_r = 0;
28680   __Pyx_RefNannyDeclarations
28681   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
28682   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_13aligned_pairs___get__(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
28683   __Pyx_RefNannyFinishContext();
28684   return __pyx_r;
28685 }
28686
28687 /* "csamtools.pyx":2867
28688  *        Unaligned position are marked by None.
28689  *        """
28690  *        def __get__(self):             # <<<<<<<<<<<<<<
28691  *            cdef uint32_t k, i, pos, qpos
28692  *            cdef int op
28693  */
28694
28695 static PyObject *__pyx_pf_9csamtools_11AlignedRead_13aligned_pairs___get__(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
28696   uint32_t __pyx_v_k;
28697   uint32_t __pyx_v_i;
28698   uint32_t __pyx_v_pos;
28699   uint32_t __pyx_v_qpos;
28700   int __pyx_v_op;
28701   uint32_t *__pyx_v_cigar_p;
28702   bam1_t *__pyx_v_src;
28703   PyObject *__pyx_v_result = NULL;
28704   PyObject *__pyx_v_l = NULL;
28705   PyObject *__pyx_r = NULL;
28706   __Pyx_RefNannyDeclarations
28707   int __pyx_t_1;
28708   PyObject *__pyx_t_2 = NULL;
28709   uint32_t __pyx_t_3;
28710   PyObject *__pyx_t_4 = NULL;
28711   uint32_t __pyx_t_5;
28712   PyObject *__pyx_t_6 = NULL;
28713   int __pyx_t_7;
28714   int __pyx_lineno = 0;
28715   const char *__pyx_filename = NULL;
28716   int __pyx_clineno = 0;
28717   __Pyx_TraceDeclarations
28718   __Pyx_RefNannySetupContext("__get__", 0);
28719   __Pyx_TraceCall("__get__", __pyx_f[0], 2867);
28720
28721   /* "csamtools.pyx":2873
28722  *            cdef bam1_t * src
28723  * 
28724  *            src = self._delegate             # <<<<<<<<<<<<<<
28725  *            if src.core.n_cigar == 0: return []
28726  * 
28727  */
28728   __pyx_v_src = __pyx_v_self->_delegate;
28729
28730   /* "csamtools.pyx":2874
28731  * 
28732  *            src = self._delegate
28733  *            if src.core.n_cigar == 0: return []             # <<<<<<<<<<<<<<
28734  * 
28735  *            result = []
28736  */
28737   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
28738   if (__pyx_t_1) {
28739     __Pyx_XDECREF(__pyx_r);
28740     __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28741     __Pyx_GOTREF(__pyx_t_2);
28742     __pyx_r = ((PyObject *)__pyx_t_2);
28743     __pyx_t_2 = 0;
28744     goto __pyx_L0;
28745     goto __pyx_L3;
28746   }
28747   __pyx_L3:;
28748
28749   /* "csamtools.pyx":2876
28750  *            if src.core.n_cigar == 0: return []
28751  * 
28752  *            result = []             # <<<<<<<<<<<<<<
28753  *            pos = src.core.pos
28754  *            qpos = 0
28755  */
28756   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28757   __Pyx_GOTREF(__pyx_t_2);
28758   __pyx_v_result = __pyx_t_2;
28759   __pyx_t_2 = 0;
28760
28761   /* "csamtools.pyx":2877
28762  * 
28763  *            result = []
28764  *            pos = src.core.pos             # <<<<<<<<<<<<<<
28765  *            qpos = 0
28766  *            cigar_p = bam1_cigar(src)
28767  */
28768   __pyx_v_pos = __pyx_v_src->core.pos;
28769
28770   /* "csamtools.pyx":2878
28771  *            result = []
28772  *            pos = src.core.pos
28773  *            qpos = 0             # <<<<<<<<<<<<<<
28774  *            cigar_p = bam1_cigar(src)
28775  * 
28776  */
28777   __pyx_v_qpos = 0;
28778
28779   /* "csamtools.pyx":2879
28780  *            pos = src.core.pos
28781  *            qpos = 0
28782  *            cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
28783  * 
28784  *            for k from 0 <= k < src.core.n_cigar:
28785  */
28786   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
28787
28788   /* "csamtools.pyx":2881
28789  *            cigar_p = bam1_cigar(src)
28790  * 
28791  *            for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
28792  *                op = cigar_p[k] & BAM_CIGAR_MASK
28793  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT
28794  */
28795   __pyx_t_3 = __pyx_v_src->core.n_cigar;
28796   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
28797
28798     /* "csamtools.pyx":2882
28799  * 
28800  *            for k from 0 <= k < src.core.n_cigar:
28801  *                op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
28802  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT
28803  * 
28804  */
28805     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
28806
28807     /* "csamtools.pyx":2883
28808  *            for k from 0 <= k < src.core.n_cigar:
28809  *                op = cigar_p[k] & BAM_CIGAR_MASK
28810  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
28811  * 
28812  *                if op == BAM_CMATCH:
28813  */
28814     __pyx_t_2 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28815     __Pyx_GOTREF(__pyx_t_2);
28816     __Pyx_XDECREF(__pyx_v_l);
28817     __pyx_v_l = __pyx_t_2;
28818     __pyx_t_2 = 0;
28819
28820     /* "csamtools.pyx":2896
28821  *                        qpos += 1
28822  * 
28823  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
28824  *                    for i from pos <= i < pos + l:
28825  *                        result.append( (None, i) )
28826  */
28827     switch (__pyx_v_op) {
28828
28829       /* "csamtools.pyx":2885
28830  *                l = cigar_p[k] >> BAM_CIGAR_SHIFT
28831  * 
28832  *                if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
28833  *                    for i from pos <= i < pos + l:
28834  *                        result.append( (qpos, i) )
28835  */
28836       case 0:
28837
28838       /* "csamtools.pyx":2886
28839  * 
28840  *                if op == BAM_CMATCH:
28841  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
28842  *                        result.append( (qpos, i) )
28843  *                        qpos += 1
28844  */
28845       __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28846       __Pyx_GOTREF(__pyx_t_2);
28847       __pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28848       __Pyx_GOTREF(__pyx_t_4);
28849       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28850       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28851       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
28852       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
28853
28854         /* "csamtools.pyx":2887
28855  *                if op == BAM_CMATCH:
28856  *                    for i from pos <= i < pos + l:
28857  *                        result.append( (qpos, i) )             # <<<<<<<<<<<<<<
28858  *                        qpos += 1
28859  *                    pos += l
28860  */
28861         __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28862         __Pyx_GOTREF(__pyx_t_4);
28863         __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28864         __Pyx_GOTREF(__pyx_t_2);
28865         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28866         __Pyx_GOTREF(__pyx_t_6);
28867         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
28868         __Pyx_GIVEREF(__pyx_t_4);
28869         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2);
28870         __Pyx_GIVEREF(__pyx_t_2);
28871         __pyx_t_4 = 0;
28872         __pyx_t_2 = 0;
28873         __pyx_t_7 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28874         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
28875
28876         /* "csamtools.pyx":2888
28877  *                    for i from pos <= i < pos + l:
28878  *                        result.append( (qpos, i) )
28879  *                        qpos += 1             # <<<<<<<<<<<<<<
28880  *                    pos += l
28881  * 
28882  */
28883         __pyx_v_qpos = (__pyx_v_qpos + 1);
28884       }
28885
28886       /* "csamtools.pyx":2889
28887  *                        result.append( (qpos, i) )
28888  *                        qpos += 1
28889  *                    pos += l             # <<<<<<<<<<<<<<
28890  * 
28891  *                elif op == BAM_CINS:
28892  */
28893       __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28894       __Pyx_GOTREF(__pyx_t_6);
28895       __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28896       __Pyx_GOTREF(__pyx_t_2);
28897       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
28898       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28899       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28900       __pyx_v_pos = __pyx_t_5;
28901       break;
28902
28903       /* "csamtools.pyx":2891
28904  *                    pos += l
28905  * 
28906  *                elif op == BAM_CINS:             # <<<<<<<<<<<<<<
28907  *                    for i from pos <= i < pos + l:
28908  *                        result.append( (qpos, None) )
28909  */
28910       case 1:
28911
28912       /* "csamtools.pyx":2892
28913  * 
28914  *                elif op == BAM_CINS:
28915  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
28916  *                        result.append( (qpos, None) )
28917  *                        qpos += 1
28918  */
28919       __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28920       __Pyx_GOTREF(__pyx_t_2);
28921       __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28922       __Pyx_GOTREF(__pyx_t_6);
28923       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28924       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28925       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
28926       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
28927
28928         /* "csamtools.pyx":2893
28929  *                elif op == BAM_CINS:
28930  *                    for i from pos <= i < pos + l:
28931  *                        result.append( (qpos, None) )             # <<<<<<<<<<<<<<
28932  *                        qpos += 1
28933  * 
28934  */
28935         __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28936         __Pyx_GOTREF(__pyx_t_6);
28937         __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28938         __Pyx_GOTREF(__pyx_t_2);
28939         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
28940         __Pyx_GIVEREF(__pyx_t_6);
28941         __Pyx_INCREF(Py_None);
28942         PyTuple_SET_ITEM(__pyx_t_2, 1, Py_None);
28943         __Pyx_GIVEREF(Py_None);
28944         __pyx_t_6 = 0;
28945         __pyx_t_7 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28946         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
28947
28948         /* "csamtools.pyx":2894
28949  *                    for i from pos <= i < pos + l:
28950  *                        result.append( (qpos, None) )
28951  *                        qpos += 1             # <<<<<<<<<<<<<<
28952  * 
28953  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:
28954  */
28955         __pyx_v_qpos = (__pyx_v_qpos + 1);
28956       }
28957       break;
28958
28959       /* "csamtools.pyx":2896
28960  *                        qpos += 1
28961  * 
28962  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
28963  *                    for i from pos <= i < pos + l:
28964  *                        result.append( (None, i) )
28965  */
28966       case 2:
28967       case 3:
28968
28969       /* "csamtools.pyx":2897
28970  * 
28971  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:
28972  *                    for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
28973  *                        result.append( (None, i) )
28974  *                    pos += l
28975  */
28976       __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28977       __Pyx_GOTREF(__pyx_t_2);
28978       __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28979       __Pyx_GOTREF(__pyx_t_6);
28980       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
28981       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28982       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
28983       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
28984
28985         /* "csamtools.pyx":2898
28986  *                elif op == BAM_CDEL or op == BAM_CREF_SKIP:
28987  *                    for i from pos <= i < pos + l:
28988  *                        result.append( (None, i) )             # <<<<<<<<<<<<<<
28989  *                    pos += l
28990  * 
28991  */
28992         __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28993         __Pyx_GOTREF(__pyx_t_6);
28994         __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
28995         __Pyx_GOTREF(__pyx_t_2);
28996         __Pyx_INCREF(Py_None);
28997         PyTuple_SET_ITEM(__pyx_t_2, 0, Py_None);
28998         __Pyx_GIVEREF(Py_None);
28999         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6);
29000         __Pyx_GIVEREF(__pyx_t_6);
29001         __pyx_t_6 = 0;
29002         __pyx_t_7 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29003         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
29004       }
29005
29006       /* "csamtools.pyx":2899
29007  *                    for i from pos <= i < pos + l:
29008  *                        result.append( (None, i) )
29009  *                    pos += l             # <<<<<<<<<<<<<<
29010  * 
29011  *            return result
29012  */
29013       __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29014       __Pyx_GOTREF(__pyx_t_2);
29015       __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29016       __Pyx_GOTREF(__pyx_t_6);
29017       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
29018       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2899; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29019       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
29020       __pyx_v_pos = __pyx_t_5;
29021       break;
29022     }
29023   }
29024
29025   /* "csamtools.pyx":2901
29026  *                    pos += l
29027  * 
29028  *            return result             # <<<<<<<<<<<<<<
29029  * 
29030  * 
29031  */
29032   __Pyx_XDECREF(__pyx_r);
29033   __Pyx_INCREF(((PyObject *)__pyx_v_result));
29034   __pyx_r = ((PyObject *)__pyx_v_result);
29035   goto __pyx_L0;
29036
29037   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
29038   goto __pyx_L0;
29039   __pyx_L1_error:;
29040   __Pyx_XDECREF(__pyx_t_2);
29041   __Pyx_XDECREF(__pyx_t_4);
29042   __Pyx_XDECREF(__pyx_t_6);
29043   __Pyx_AddTraceback("csamtools.AlignedRead.aligned_pairs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
29044   __pyx_r = NULL;
29045   __pyx_L0:;
29046   __Pyx_XDECREF(__pyx_v_result);
29047   __Pyx_XDECREF(__pyx_v_l);
29048   __Pyx_XGIVEREF(__pyx_r);
29049   __Pyx_TraceReturn(__pyx_r);
29050   __Pyx_RefNannyFinishContext();
29051   return __pyx_r;
29052 }
29053
29054 /* Python wrapper */
29055 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
29056 static char __pyx_doc_9csamtools_11AlignedRead_10overlap[] = "AlignedRead.overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval *start* and *end*\n        on the reference sequence.\n        ";
29057 static PyObject *__pyx_pw_9csamtools_11AlignedRead_11overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
29058   uint32_t __pyx_v_start;
29059   uint32_t __pyx_v_end;
29060   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
29061   PyObject *__pyx_r = 0;
29062   __Pyx_RefNannyDeclarations
29063   __Pyx_RefNannySetupContext("overlap (wrapper)", 0);
29064   {
29065     PyObject* values[2] = {0,0};
29066     if (unlikely(__pyx_kwds)) {
29067       Py_ssize_t kw_args;
29068       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
29069       switch (pos_args) {
29070         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
29071         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
29072         case  0: break;
29073         default: goto __pyx_L5_argtuple_error;
29074       }
29075       kw_args = PyDict_Size(__pyx_kwds);
29076       switch (pos_args) {
29077         case  0:
29078         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
29079         if (likely(values[0])) kw_args--;
29080         else goto __pyx_L5_argtuple_error;
29081         case  1:
29082         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
29083         if (likely(values[1])) kw_args--;
29084         else {
29085           __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
29086         }
29087       }
29088       if (unlikely(kw_args > 0)) {
29089         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
29090       }
29091     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
29092       goto __pyx_L5_argtuple_error;
29093     } else {
29094       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
29095       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
29096     }
29097     __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 = 2904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
29098     __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 = 2904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
29099   }
29100   goto __pyx_L4_argument_unpacking_done;
29101   __pyx_L5_argtuple_error:;
29102   __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
29103   __pyx_L3_error:;
29104   __Pyx_AddTraceback("csamtools.AlignedRead.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
29105   __Pyx_RefNannyFinishContext();
29106   return NULL;
29107   __pyx_L4_argument_unpacking_done:;
29108   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_10overlap(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), __pyx_v_start, __pyx_v_end);
29109   __Pyx_RefNannyFinishContext();
29110   return __pyx_r;
29111 }
29112
29113 /* "csamtools.pyx":2904
29114  * 
29115  * 
29116  *     def overlap( self, uint32_t start, uint32_t end ):             # <<<<<<<<<<<<<<
29117  *         """return number of aligned bases of read overlapping the interval *start* and *end*
29118  *         on the reference sequence.
29119  */
29120
29121 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10overlap(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
29122   uint32_t __pyx_v_k;
29123   uint32_t __pyx_v_pos;
29124   uint32_t __pyx_v_overlap;
29125   int __pyx_v_op;
29126   int __pyx_v_o;
29127   uint32_t *__pyx_v_cigar_p;
29128   bam1_t *__pyx_v_src;
29129   PyObject *__pyx_v_l = NULL;
29130   PyObject *__pyx_r = NULL;
29131   __Pyx_RefNannyDeclarations
29132   int __pyx_t_1;
29133   uint32_t __pyx_t_2;
29134   PyObject *__pyx_t_3 = NULL;
29135   uint32_t __pyx_t_4;
29136   PyObject *__pyx_t_5 = NULL;
29137   PyObject *__pyx_t_6 = NULL;
29138   PyObject *__pyx_t_7 = NULL;
29139   uint32_t __pyx_t_8;
29140   uint32_t __pyx_t_9;
29141   int __pyx_t_10;
29142   int __pyx_lineno = 0;
29143   const char *__pyx_filename = NULL;
29144   int __pyx_clineno = 0;
29145   __Pyx_TraceDeclarations
29146   __Pyx_RefNannySetupContext("overlap", 0);
29147   __Pyx_TraceCall("overlap", __pyx_f[0], 2904);
29148
29149   /* "csamtools.pyx":2913
29150  *         cdef bam1_t * src
29151  * 
29152  *         overlap = 0             # <<<<<<<<<<<<<<
29153  * 
29154  *         src = self._delegate
29155  */
29156   __pyx_v_overlap = 0;
29157
29158   /* "csamtools.pyx":2915
29159  *         overlap = 0
29160  * 
29161  *         src = self._delegate             # <<<<<<<<<<<<<<
29162  *         if src.core.n_cigar == 0: return 0
29163  *         pos = src.core.pos
29164  */
29165   __pyx_v_src = __pyx_v_self->_delegate;
29166
29167   /* "csamtools.pyx":2916
29168  * 
29169  *         src = self._delegate
29170  *         if src.core.n_cigar == 0: return 0             # <<<<<<<<<<<<<<
29171  *         pos = src.core.pos
29172  *         o = 0
29173  */
29174   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
29175   if (__pyx_t_1) {
29176     __Pyx_XDECREF(__pyx_r);
29177     __Pyx_INCREF(__pyx_int_0);
29178     __pyx_r = __pyx_int_0;
29179     goto __pyx_L0;
29180     goto __pyx_L3;
29181   }
29182   __pyx_L3:;
29183
29184   /* "csamtools.pyx":2917
29185  *         src = self._delegate
29186  *         if src.core.n_cigar == 0: return 0
29187  *         pos = src.core.pos             # <<<<<<<<<<<<<<
29188  *         o = 0
29189  * 
29190  */
29191   __pyx_v_pos = __pyx_v_src->core.pos;
29192
29193   /* "csamtools.pyx":2918
29194  *         if src.core.n_cigar == 0: return 0
29195  *         pos = src.core.pos
29196  *         o = 0             # <<<<<<<<<<<<<<
29197  * 
29198  *         cigar_p = bam1_cigar(src)
29199  */
29200   __pyx_v_o = 0;
29201
29202   /* "csamtools.pyx":2920
29203  *         o = 0
29204  * 
29205  *         cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
29206  *         for k from 0 <= k < src.core.n_cigar:
29207  *             op = cigar_p[k] & BAM_CIGAR_MASK
29208  */
29209   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
29210
29211   /* "csamtools.pyx":2921
29212  * 
29213  *         cigar_p = bam1_cigar(src)
29214  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
29215  *             op = cigar_p[k] & BAM_CIGAR_MASK
29216  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
29217  */
29218   __pyx_t_2 = __pyx_v_src->core.n_cigar;
29219   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {
29220
29221     /* "csamtools.pyx":2922
29222  *         cigar_p = bam1_cigar(src)
29223  *         for k from 0 <= k < src.core.n_cigar:
29224  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
29225  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
29226  * 
29227  */
29228     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
29229
29230     /* "csamtools.pyx":2923
29231  *         for k from 0 <= k < src.core.n_cigar:
29232  *             op = cigar_p[k] & BAM_CIGAR_MASK
29233  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
29234  * 
29235  *             if op == BAM_CMATCH:
29236  */
29237     __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 = 2923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29238     __Pyx_GOTREF(__pyx_t_3);
29239     __Pyx_XDECREF(__pyx_v_l);
29240     __pyx_v_l = __pyx_t_3;
29241     __pyx_t_3 = 0;
29242
29243     /* "csamtools.pyx":2925
29244  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
29245  * 
29246  *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
29247  *                 o = min( pos + l, end) - max( pos, start )
29248  *                 if o > 0: overlap += o
29249  */
29250     __pyx_t_1 = (__pyx_v_op == 0);
29251     if (__pyx_t_1) {
29252
29253       /* "csamtools.pyx":2926
29254  * 
29255  *             if op == BAM_CMATCH:
29256  *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
29257  *                 if o > 0: overlap += o
29258  * 
29259  */
29260       __pyx_t_4 = __pyx_v_end;
29261       __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29262       __Pyx_GOTREF(__pyx_t_3);
29263       __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29264       __Pyx_GOTREF(__pyx_t_5);
29265       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
29266       __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29267       __Pyx_GOTREF(__pyx_t_6);
29268       __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_t_5, Py_LT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29269       __Pyx_GOTREF(__pyx_t_7);
29270       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
29271       __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29272       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
29273       if (__pyx_t_1) {
29274         __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29275         __Pyx_GOTREF(__pyx_t_7);
29276         __pyx_t_3 = __pyx_t_7;
29277         __pyx_t_7 = 0;
29278       } else {
29279         __Pyx_INCREF(__pyx_t_5);
29280         __pyx_t_3 = __pyx_t_5;
29281       }
29282       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
29283       __pyx_t_4 = __pyx_v_start;
29284       __pyx_t_8 = __pyx_v_pos;
29285       if ((__pyx_t_4 > __pyx_t_8)) {
29286         __pyx_t_9 = __pyx_t_4;
29287       } else {
29288         __pyx_t_9 = __pyx_t_8;
29289       }
29290       __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_9); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29291       __Pyx_GOTREF(__pyx_t_5);
29292       __pyx_t_7 = PyNumber_Subtract(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29293       __Pyx_GOTREF(__pyx_t_7);
29294       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
29295       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
29296       __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29297       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
29298       __pyx_v_o = __pyx_t_10;
29299
29300       /* "csamtools.pyx":2927
29301  *             if op == BAM_CMATCH:
29302  *                 o = min( pos + l, end) - max( pos, start )
29303  *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
29304  * 
29305  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
29306  */
29307       __pyx_t_1 = (__pyx_v_o > 0);
29308       if (__pyx_t_1) {
29309         __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o);
29310         goto __pyx_L7;
29311       }
29312       __pyx_L7:;
29313       goto __pyx_L6;
29314     }
29315     __pyx_L6:;
29316
29317     /* "csamtools.pyx":2929
29318  *                 if o > 0: overlap += o
29319  * 
29320  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
29321  *                 pos += l
29322  * 
29323  */
29324     switch (__pyx_v_op) {
29325       case 0:
29326       case 2:
29327       case 3:
29328
29329       /* "csamtools.pyx":2930
29330  * 
29331  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
29332  *                 pos += l             # <<<<<<<<<<<<<<
29333  * 
29334  *         return overlap
29335  */
29336       __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29337       __Pyx_GOTREF(__pyx_t_7);
29338       __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29339       __Pyx_GOTREF(__pyx_t_5);
29340       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
29341       __pyx_t_9 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29342       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
29343       __pyx_v_pos = __pyx_t_9;
29344       break;
29345     }
29346   }
29347
29348   /* "csamtools.pyx":2932
29349  *                 pos += l
29350  * 
29351  *         return overlap             # <<<<<<<<<<<<<<
29352  * 
29353  *     def opt(self, tag):
29354  */
29355   __Pyx_XDECREF(__pyx_r);
29356   __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29357   __Pyx_GOTREF(__pyx_t_5);
29358   __pyx_r = __pyx_t_5;
29359   __pyx_t_5 = 0;
29360   goto __pyx_L0;
29361
29362   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
29363   goto __pyx_L0;
29364   __pyx_L1_error:;
29365   __Pyx_XDECREF(__pyx_t_3);
29366   __Pyx_XDECREF(__pyx_t_5);
29367   __Pyx_XDECREF(__pyx_t_6);
29368   __Pyx_XDECREF(__pyx_t_7);
29369   __Pyx_AddTraceback("csamtools.AlignedRead.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
29370   __pyx_r = NULL;
29371   __pyx_L0:;
29372   __Pyx_XDECREF(__pyx_v_l);
29373   __Pyx_XGIVEREF(__pyx_r);
29374   __Pyx_TraceReturn(__pyx_r);
29375   __Pyx_RefNannyFinishContext();
29376   return __pyx_r;
29377 }
29378
29379 /* Python wrapper */
29380 static PyObject *__pyx_pw_9csamtools_11AlignedRead_13opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
29381 static char __pyx_doc_9csamtools_11AlignedRead_12opt[] = "AlignedRead.opt(self, tag)\nretrieves optional data given a two-letter *tag*";
29382 static PyObject *__pyx_pw_9csamtools_11AlignedRead_13opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
29383   PyObject *__pyx_r = 0;
29384   __Pyx_RefNannyDeclarations
29385   __Pyx_RefNannySetupContext("opt (wrapper)", 0);
29386   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_12opt(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self), ((PyObject *)__pyx_v_tag));
29387   __Pyx_RefNannyFinishContext();
29388   return __pyx_r;
29389 }
29390
29391 /* "csamtools.pyx":2934
29392  *         return overlap
29393  * 
29394  *     def opt(self, tag):             # <<<<<<<<<<<<<<
29395  *         """retrieves optional data given a two-letter *tag*"""
29396  *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
29397  */
29398
29399 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12opt(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self, PyObject *__pyx_v_tag) {
29400   uint8_t *__pyx_v_v;
29401   CYTHON_UNUSED int __pyx_v_nvalues;
29402   PyObject *__pyx_v_btag = NULL;
29403   PyObject *__pyx_v_auxtype = NULL;
29404   CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL;
29405   PyObject *__pyx_v_values = NULL;
29406   PyObject *__pyx_r = NULL;
29407   __Pyx_RefNannyDeclarations
29408   PyObject *__pyx_t_1 = NULL;
29409   char *__pyx_t_2;
29410   int __pyx_t_3;
29411   PyObject *__pyx_t_4 = NULL;
29412   int __pyx_t_5;
29413   int __pyx_t_6;
29414   int __pyx_t_7;
29415   int __pyx_t_8;
29416   PyObject *__pyx_t_9 = NULL;
29417   PyObject *__pyx_t_10 = NULL;
29418   PyObject *__pyx_t_11 = NULL;
29419   PyObject *(*__pyx_t_12)(PyObject *);
29420   int __pyx_t_13;
29421   int __pyx_lineno = 0;
29422   const char *__pyx_filename = NULL;
29423   int __pyx_clineno = 0;
29424   __Pyx_TraceDeclarations
29425   __Pyx_RefNannySetupContext("opt", 0);
29426   __Pyx_TraceCall("opt", __pyx_f[0], 2934);
29427
29428   /* "csamtools.pyx":2939
29429  *         cdef uint8_t * v
29430  *         cdef int nvalues
29431  *         btag = _force_bytes(tag)             # <<<<<<<<<<<<<<
29432  *         v = bam_aux_get(self._delegate, btag)
29433  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
29434  */
29435   __pyx_t_1 = ((PyObject *)__pyx_f_9csamtools__force_bytes(__pyx_v_tag)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29436   __Pyx_GOTREF(__pyx_t_1);
29437   __pyx_v_btag = ((PyObject*)__pyx_t_1);
29438   __pyx_t_1 = 0;
29439
29440   /* "csamtools.pyx":2940
29441  *         cdef int nvalues
29442  *         btag = _force_bytes(tag)
29443  *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
29444  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
29445  *         auxtype = chr(v[0])
29446  */
29447   __pyx_t_2 = PyBytes_AsString(((PyObject *)__pyx_v_btag)); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29448   __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_2);
29449
29450   /* "csamtools.pyx":2941
29451  *         btag = _force_bytes(tag)
29452  *         v = bam_aux_get(self._delegate, btag)
29453  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )             # <<<<<<<<<<<<<<
29454  *         auxtype = chr(v[0])
29455  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
29456  */
29457   __pyx_t_3 = (__pyx_v_v == NULL);
29458   if (__pyx_t_3) {
29459     __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_148), __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29460     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
29461     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29462     __Pyx_GOTREF(__pyx_t_4);
29463     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1));
29464     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
29465     __pyx_t_1 = 0;
29466     __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 = 2941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29467     __Pyx_GOTREF(__pyx_t_1);
29468     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
29469     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
29470     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
29471     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29472     goto __pyx_L3;
29473   }
29474   __pyx_L3:;
29475
29476   /* "csamtools.pyx":2942
29477  *         v = bam_aux_get(self._delegate, btag)
29478  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
29479  *         auxtype = chr(v[0])             # <<<<<<<<<<<<<<
29480  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
29481  *             return <int>bam_aux2i(v)
29482  */
29483   __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 = 2942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29484   __Pyx_GOTREF(__pyx_t_1);
29485   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29486   __Pyx_GOTREF(__pyx_t_4);
29487   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
29488   __Pyx_GIVEREF(__pyx_t_1);
29489   __pyx_t_1 = 0;
29490   __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 = 2942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29491   __Pyx_GOTREF(__pyx_t_1);
29492   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
29493   __pyx_v_auxtype = __pyx_t_1;
29494   __pyx_t_1 = 0;
29495
29496   /* "csamtools.pyx":2943
29497  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
29498  *         auxtype = chr(v[0])
29499  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
29500  *             return <int>bam_aux2i(v)
29501  *         elif auxtype == 'i' or auxtype == 'I':
29502  */
29503   __pyx_t_3 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__c), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29504   if (!__pyx_t_3) {
29505     __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__C), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29506     if (!__pyx_t_5) {
29507       __pyx_t_6 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__s), Py_EQ); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29508       if (!__pyx_t_6) {
29509         __pyx_t_7 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__S), Py_EQ); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29510         __pyx_t_8 = __pyx_t_7;
29511       } else {
29512         __pyx_t_8 = __pyx_t_6;
29513       }
29514       __pyx_t_6 = __pyx_t_8;
29515     } else {
29516       __pyx_t_6 = __pyx_t_5;
29517     }
29518     __pyx_t_5 = __pyx_t_6;
29519   } else {
29520     __pyx_t_5 = __pyx_t_3;
29521   }
29522   if (__pyx_t_5) {
29523
29524     /* "csamtools.pyx":2944
29525  *         auxtype = chr(v[0])
29526  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
29527  *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
29528  *         elif auxtype == 'i' or auxtype == 'I':
29529  *             return <int32_t>bam_aux2i(v)
29530  */
29531     __Pyx_XDECREF(__pyx_r);
29532     __pyx_t_1 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29533     __Pyx_GOTREF(__pyx_t_1);
29534     __pyx_r = __pyx_t_1;
29535     __pyx_t_1 = 0;
29536     goto __pyx_L0;
29537     goto __pyx_L4;
29538   }
29539
29540   /* "csamtools.pyx":2945
29541  *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
29542  *             return <int>bam_aux2i(v)
29543  *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
29544  *             return <int32_t>bam_aux2i(v)
29545  *         elif auxtype == 'f' or auxtype == 'F':
29546  */
29547   __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__i), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29548   if (!__pyx_t_5) {
29549     __pyx_t_3 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__I), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29550     __pyx_t_6 = __pyx_t_3;
29551   } else {
29552     __pyx_t_6 = __pyx_t_5;
29553   }
29554   if (__pyx_t_6) {
29555
29556     /* "csamtools.pyx":2946
29557  *             return <int>bam_aux2i(v)
29558  *         elif auxtype == 'i' or auxtype == 'I':
29559  *             return <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
29560  *         elif auxtype == 'f' or auxtype == 'F':
29561  *             return <float>bam_aux2f(v)
29562  */
29563     __Pyx_XDECREF(__pyx_r);
29564     __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 = 2946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29565     __Pyx_GOTREF(__pyx_t_1);
29566     __pyx_r = __pyx_t_1;
29567     __pyx_t_1 = 0;
29568     goto __pyx_L0;
29569     goto __pyx_L4;
29570   }
29571
29572   /* "csamtools.pyx":2947
29573  *         elif auxtype == 'i' or auxtype == 'I':
29574  *             return <int32_t>bam_aux2i(v)
29575  *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
29576  *             return <float>bam_aux2f(v)
29577  *         elif auxtype == 'd' or auxtype == 'D':
29578  */
29579   __pyx_t_6 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__f), Py_EQ); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29580   if (!__pyx_t_6) {
29581     __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__F), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29582     __pyx_t_3 = __pyx_t_5;
29583   } else {
29584     __pyx_t_3 = __pyx_t_6;
29585   }
29586   if (__pyx_t_3) {
29587
29588     /* "csamtools.pyx":2948
29589  *             return <int32_t>bam_aux2i(v)
29590  *         elif auxtype == 'f' or auxtype == 'F':
29591  *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
29592  *         elif auxtype == 'd' or auxtype == 'D':
29593  *             return <double>bam_aux2d(v)
29594  */
29595     __Pyx_XDECREF(__pyx_r);
29596     __pyx_t_1 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29597     __Pyx_GOTREF(__pyx_t_1);
29598     __pyx_r = __pyx_t_1;
29599     __pyx_t_1 = 0;
29600     goto __pyx_L0;
29601     goto __pyx_L4;
29602   }
29603
29604   /* "csamtools.pyx":2949
29605  *         elif auxtype == 'f' or auxtype == 'F':
29606  *             return <float>bam_aux2f(v)
29607  *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
29608  *             return <double>bam_aux2d(v)
29609  *         elif auxtype == 'A':
29610  */
29611   __pyx_t_3 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__d), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29612   if (!__pyx_t_3) {
29613     __pyx_t_6 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__D), Py_EQ); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29614     __pyx_t_5 = __pyx_t_6;
29615   } else {
29616     __pyx_t_5 = __pyx_t_3;
29617   }
29618   if (__pyx_t_5) {
29619
29620     /* "csamtools.pyx":2950
29621  *             return <float>bam_aux2f(v)
29622  *         elif auxtype == 'd' or auxtype == 'D':
29623  *             return <double>bam_aux2d(v)             # <<<<<<<<<<<<<<
29624  *         elif auxtype == 'A':
29625  *             # there might a more efficient way
29626  */
29627     __Pyx_XDECREF(__pyx_r);
29628     __pyx_t_1 = PyFloat_FromDouble(((double)bam_aux2d(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29629     __Pyx_GOTREF(__pyx_t_1);
29630     __pyx_r = __pyx_t_1;
29631     __pyx_t_1 = 0;
29632     goto __pyx_L0;
29633     goto __pyx_L4;
29634   }
29635
29636   /* "csamtools.pyx":2951
29637  *         elif auxtype == 'd' or auxtype == 'D':
29638  *             return <double>bam_aux2d(v)
29639  *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
29640  *             # there might a more efficient way
29641  *             # to convert a char into a string
29642  */
29643   __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__A), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29644   if (__pyx_t_5) {
29645
29646     /* "csamtools.pyx":2954
29647  *             # there might a more efficient way
29648  *             # to convert a char into a string
29649  *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
29650  *         elif auxtype == 'Z':
29651  *             return _charptr_to_str(<char*>bam_aux2Z(v))
29652  */
29653     __Pyx_XDECREF(__pyx_r);
29654     __pyx_t_1 = PyInt_FromLong(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29655     __Pyx_GOTREF(__pyx_t_1);
29656     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_137), __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29657     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
29658     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
29659     __pyx_r = ((PyObject *)__pyx_t_4);
29660     __pyx_t_4 = 0;
29661     goto __pyx_L0;
29662     goto __pyx_L4;
29663   }
29664
29665   /* "csamtools.pyx":2955
29666  *             # to convert a char into a string
29667  *             return '%c' % <char>bam_aux2A(v)
29668  *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
29669  *             return _charptr_to_str(<char*>bam_aux2Z(v))
29670  *         elif auxtype == 'B':
29671  */
29672   __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__Z), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29673   if (__pyx_t_5) {
29674
29675     /* "csamtools.pyx":2956
29676  *             return '%c' % <char>bam_aux2A(v)
29677  *         elif auxtype == 'Z':
29678  *             return _charptr_to_str(<char*>bam_aux2Z(v))             # <<<<<<<<<<<<<<
29679  *         elif auxtype == 'B':
29680  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
29681  */
29682     __Pyx_XDECREF(__pyx_r);
29683     __pyx_t_4 = __pyx_f_9csamtools__charptr_to_str(((char *)bam_aux2Z(__pyx_v_v))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29684     __Pyx_GOTREF(__pyx_t_4);
29685     __pyx_r = __pyx_t_4;
29686     __pyx_t_4 = 0;
29687     goto __pyx_L0;
29688     goto __pyx_L4;
29689   }
29690
29691   /* "csamtools.pyx":2957
29692  *         elif auxtype == 'Z':
29693  *             return _charptr_to_str(<char*>bam_aux2Z(v))
29694  *         elif auxtype == 'B':             # <<<<<<<<<<<<<<
29695  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
29696  *             return values
29697  */
29698   __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_auxtype, ((PyObject *)__pyx_n_s__B), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29699   if (__pyx_t_5) {
29700
29701     /* "csamtools.pyx":2958
29702  *             return _charptr_to_str(<char*>bam_aux2Z(v))
29703  *         elif auxtype == 'B':
29704  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )             # <<<<<<<<<<<<<<
29705  *             return values
29706  *         else:
29707  */
29708     __pyx_t_4 = __pyx_f_9csamtools_convertBinaryTagToList((__pyx_v_v + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29709     __Pyx_GOTREF(__pyx_t_4);
29710     if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
29711       PyObject* sequence = __pyx_t_4;
29712       if (likely(PyTuple_CheckExact(sequence))) {
29713         if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) {
29714           if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3);
29715           else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
29716           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29717         }
29718         __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
29719         __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
29720         __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); 
29721       } else {
29722         if (unlikely(PyList_GET_SIZE(sequence) != 3)) {
29723           if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3);
29724           else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
29725           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29726         }
29727         __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
29728         __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
29729         __pyx_t_10 = PyList_GET_ITEM(sequence, 2); 
29730       }
29731       __Pyx_INCREF(__pyx_t_1);
29732       __Pyx_INCREF(__pyx_t_9);
29733       __Pyx_INCREF(__pyx_t_10);
29734       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
29735     } else {
29736       Py_ssize_t index = -1;
29737       __pyx_t_11 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29738       __Pyx_GOTREF(__pyx_t_11);
29739       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
29740       __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
29741       index = 0; __pyx_t_1 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
29742       __Pyx_GOTREF(__pyx_t_1);
29743       index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L5_unpacking_failed;
29744       __Pyx_GOTREF(__pyx_t_9);
29745       index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
29746       __Pyx_GOTREF(__pyx_t_10);
29747       if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29748       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
29749       goto __pyx_L6_unpacking_done;
29750       __pyx_L5_unpacking_failed:;
29751       __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
29752       if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
29753       if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
29754       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29755       __pyx_L6_unpacking_done:;
29756     }
29757     __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 = 2958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29758     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
29759     __pyx_v_bytesize = __pyx_t_1;
29760     __pyx_t_1 = 0;
29761     __pyx_v_nvalues = __pyx_t_13;
29762     __pyx_v_values = __pyx_t_10;
29763     __pyx_t_10 = 0;
29764
29765     /* "csamtools.pyx":2959
29766  *         elif auxtype == 'B':
29767  *             bytesize, nvalues, values = convertBinaryTagToList( v + 1 )
29768  *             return values             # <<<<<<<<<<<<<<
29769  *         else:
29770  *             raise ValueError("unknown auxilliary type '%s'" % auxtype)
29771  */
29772     __Pyx_XDECREF(__pyx_r);
29773     __Pyx_INCREF(__pyx_v_values);
29774     __pyx_r = __pyx_v_values;
29775     goto __pyx_L0;
29776     goto __pyx_L4;
29777   }
29778   /*else*/ {
29779
29780     /* "csamtools.pyx":2961
29781  *             return values
29782  *         else:
29783  *             raise ValueError("unknown auxilliary type '%s'" % auxtype)             # <<<<<<<<<<<<<<
29784  * 
29785  * 
29786  */
29787     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_149), __pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29788     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
29789     __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29790     __Pyx_GOTREF(__pyx_t_10);
29791     PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4));
29792     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
29793     __pyx_t_4 = 0;
29794     __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 = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29795     __Pyx_GOTREF(__pyx_t_4);
29796     __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
29797     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
29798     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
29799     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29800   }
29801   __pyx_L4:;
29802
29803   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
29804   goto __pyx_L0;
29805   __pyx_L1_error:;
29806   __Pyx_XDECREF(__pyx_t_1);
29807   __Pyx_XDECREF(__pyx_t_4);
29808   __Pyx_XDECREF(__pyx_t_9);
29809   __Pyx_XDECREF(__pyx_t_10);
29810   __Pyx_XDECREF(__pyx_t_11);
29811   __Pyx_AddTraceback("csamtools.AlignedRead.opt", __pyx_clineno, __pyx_lineno, __pyx_filename);
29812   __pyx_r = NULL;
29813   __pyx_L0:;
29814   __Pyx_XDECREF(__pyx_v_btag);
29815   __Pyx_XDECREF(__pyx_v_auxtype);
29816   __Pyx_XDECREF(__pyx_v_bytesize);
29817   __Pyx_XDECREF(__pyx_v_values);
29818   __Pyx_XGIVEREF(__pyx_r);
29819   __Pyx_TraceReturn(__pyx_r);
29820   __Pyx_RefNannyFinishContext();
29821   return __pyx_r;
29822 }
29823
29824 /* Python wrapper */
29825 static PyObject *__pyx_pw_9csamtools_11AlignedRead_15fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
29826 static char __pyx_doc_9csamtools_11AlignedRead_14fancy_str[] = "AlignedRead.fancy_str(self)\nreturns list of fieldnames/values in pretty format for debugging\n        ";
29827 static PyObject *__pyx_pw_9csamtools_11AlignedRead_15fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
29828   PyObject *__pyx_r = 0;
29829   __Pyx_RefNannyDeclarations
29830   __Pyx_RefNannySetupContext("fancy_str (wrapper)", 0);
29831   __pyx_r = __pyx_pf_9csamtools_11AlignedRead_14fancy_str(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self));
29832   __Pyx_RefNannyFinishContext();
29833   return __pyx_r;
29834 }
29835
29836 /* "csamtools.pyx":2964
29837  * 
29838  * 
29839  *     def fancy_str (self):             # <<<<<<<<<<<<<<
29840  *         """returns list of fieldnames/values in pretty format for debugging
29841  *         """
29842  */
29843
29844 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14fancy_str(struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_self) {
29845   PyObject *__pyx_v_ret_string = NULL;
29846   PyObject *__pyx_v_field_names = NULL;
29847   PyObject *__pyx_v_fields_names_in_order = NULL;
29848   PyObject *__pyx_v_f = NULL;
29849   PyObject *__pyx_r = NULL;
29850   __Pyx_RefNannyDeclarations
29851   PyObject *__pyx_t_1 = NULL;
29852   Py_ssize_t __pyx_t_2;
29853   PyObject *__pyx_t_3 = NULL;
29854   int __pyx_t_4;
29855   int __pyx_t_5;
29856   PyObject *__pyx_t_6 = NULL;
29857   PyObject *__pyx_t_7 = NULL;
29858   PyObject *__pyx_t_8 = NULL;
29859   PyObject *__pyx_t_9 = NULL;
29860   int __pyx_t_10;
29861   PyObject *(*__pyx_t_11)(PyObject *);
29862   int __pyx_lineno = 0;
29863   const char *__pyx_filename = NULL;
29864   int __pyx_clineno = 0;
29865   __Pyx_TraceDeclarations
29866   __Pyx_RefNannySetupContext("fancy_str", 0);
29867   __Pyx_TraceCall("fancy_str", __pyx_f[0], 2964);
29868
29869   /* "csamtools.pyx":2967
29870  *         """returns list of fieldnames/values in pretty format for debugging
29871  *         """
29872  *         ret_string = []             # <<<<<<<<<<<<<<
29873  *         field_names = {
29874  *            "tid":           "Contig index",
29875  */
29876   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29877   __Pyx_GOTREF(__pyx_t_1);
29878   __pyx_v_ret_string = __pyx_t_1;
29879   __pyx_t_1 = 0;
29880
29881   /* "csamtools.pyx":2968
29882  *         """
29883  *         ret_string = []
29884  *         field_names = {             # <<<<<<<<<<<<<<
29885  *            "tid":           "Contig index",
29886  *            "pos":           "Mapped position on contig",
29887  */
29888   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29889   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
29890   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__tid), ((PyObject *)__pyx_kp_s_150)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29891   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), ((PyObject *)__pyx_kp_s_151)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29892   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mtid), ((PyObject *)__pyx_kp_s_152)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29893   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mpos), ((PyObject *)__pyx_kp_s_153)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29894   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__isize), ((PyObject *)__pyx_kp_s_154)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29895   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__flag), ((PyObject *)__pyx_kp_s_155)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29896   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__n_cigar), ((PyObject *)__pyx_kp_s_156)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29897   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__cigar), ((PyObject *)__pyx_kp_s_157)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29898   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qual), ((PyObject *)__pyx_kp_s_158)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29899   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bin), ((PyObject *)__pyx_kp_s_159)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29900   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qname), ((PyObject *)__pyx_kp_s_160)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29901   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qname), ((PyObject *)__pyx_kp_s_161)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29902   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qseq), ((PyObject *)__pyx_kp_s_162)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29903   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qseq), ((PyObject *)__pyx_kp_s_163)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29904   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bqual), ((PyObject *)__pyx_kp_s_164)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29905   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_aux), ((PyObject *)__pyx_kp_s_165)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29906   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__m_data), ((PyObject *)__pyx_kp_s_166)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29907   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__data_len), ((PyObject *)__pyx_kp_s_167)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29908   __pyx_v_field_names = __pyx_t_1;
29909   __pyx_t_1 = 0;
29910
29911   /* "csamtools.pyx":2988
29912  *            "data_len":      "Current data length",
29913  *            }
29914  *         fields_names_in_order = ["tid", "pos", "mtid", "mpos", "isize", "flag",             # <<<<<<<<<<<<<<
29915  *                                  "n_cigar", "cigar", "qual", "bin", "l_qname", "qname",
29916  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
29917  */
29918   __pyx_t_1 = PyList_New(18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
29919   __Pyx_GOTREF(__pyx_t_1);
29920   __Pyx_INCREF(((PyObject *)__pyx_n_s__tid));
29921   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__tid));
29922   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tid));
29923   __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
29924   PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__pos));
29925   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
29926   __Pyx_INCREF(((PyObject *)__pyx_n_s__mtid));
29927   PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__mtid));
29928   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mtid));
29929   __Pyx_INCREF(((PyObject *)__pyx_n_s__mpos));
29930   PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__mpos));
29931   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mpos));
29932   __Pyx_INCREF(((PyObject *)__pyx_n_s__isize));
29933   PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__isize));
29934   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isize));
29935   __Pyx_INCREF(((PyObject *)__pyx_n_s__flag));
29936   PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__flag));
29937   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__flag));
29938   __Pyx_INCREF(((PyObject *)__pyx_n_s__n_cigar));
29939   PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__n_cigar));
29940   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n_cigar));
29941   __Pyx_INCREF(((PyObject *)__pyx_n_s__cigar));
29942   PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__cigar));
29943   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cigar));
29944   __Pyx_INCREF(((PyObject *)__pyx_n_s__qual));
29945   PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__qual));
29946   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qual));
29947   __Pyx_INCREF(((PyObject *)__pyx_n_s__bin));
29948   PyList_SET_ITEM(__pyx_t_1, 9, ((PyObject *)__pyx_n_s__bin));
29949   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin));
29950   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qname));
29951   PyList_SET_ITEM(__pyx_t_1, 10, ((PyObject *)__pyx_n_s__l_qname));
29952   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qname));
29953   __Pyx_INCREF(((PyObject *)__pyx_n_s__qname));
29954   PyList_SET_ITEM(__pyx_t_1, 11, ((PyObject *)__pyx_n_s__qname));
29955   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qname));
29956   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qseq));
29957   PyList_SET_ITEM(__pyx_t_1, 12, ((PyObject *)__pyx_n_s__l_qseq));
29958   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qseq));
29959   __Pyx_INCREF(((PyObject *)__pyx_n_s__qseq));
29960   PyList_SET_ITEM(__pyx_t_1, 13, ((PyObject *)__pyx_n_s__qseq));
29961   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qseq));
29962   __Pyx_INCREF(((PyObject *)__pyx_n_s__bqual));
29963   PyList_SET_ITEM(__pyx_t_1, 14, ((PyObject *)__pyx_n_s__bqual));
29964   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bqual));
29965   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_aux));
29966   PyList_SET_ITEM(__pyx_t_1, 15, ((PyObject *)__pyx_n_s__l_aux));
29967   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_aux));
29968   __Pyx_INCREF(((PyObject *)__pyx_n_s__m_data));
29969   PyList_SET_ITEM(__pyx_t_1, 16, ((PyObject *)__pyx_n_s__m_data));
29970   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__m_data));
29971   __Pyx_INCREF(((PyObject *)__pyx_n_s__data_len));
29972   PyList_SET_ITEM(__pyx_t_1, 17, ((PyObject *)__pyx_n_s__data_len));
29973   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__data_len));
29974   __pyx_v_fields_names_in_order = __pyx_t_1;
29975   __pyx_t_1 = 0;
29976
29977   /* "csamtools.pyx":2992
29978  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
29979  * 
29980  *         for f in fields_names_in_order:             # <<<<<<<<<<<<<<
29981  *             if not f in self.__dict__:
29982  *                 continue
29983  */
29984   __pyx_t_1 = ((PyObject *)__pyx_v_fields_names_in_order); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
29985   for (;;) {
29986     if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
29987     __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
29988     __Pyx_XDECREF(__pyx_v_f);
29989     __pyx_v_f = __pyx_t_3;
29990     __pyx_t_3 = 0;
29991
29992     /* "csamtools.pyx":2993
29993  * 
29994  *         for f in fields_names_in_order:
29995  *             if not f in self.__dict__:             # <<<<<<<<<<<<<<
29996  *                 continue
29997  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
29998  */
29999     __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 = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30000     __Pyx_GOTREF(__pyx_t_3);
30001     __pyx_t_4 = ((PySequence_Contains(__pyx_t_3, __pyx_v_f))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30002     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
30003     __pyx_t_5 = (!__pyx_t_4);
30004     if (__pyx_t_5) {
30005
30006       /* "csamtools.pyx":2994
30007  *         for f in fields_names_in_order:
30008  *             if not f in self.__dict__:
30009  *                 continue             # <<<<<<<<<<<<<<
30010  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
30011  * 
30012  */
30013       goto __pyx_L3_continue;
30014       goto __pyx_L5;
30015     }
30016     __pyx_L5:;
30017
30018     /* "csamtools.pyx":2995
30019  *             if not f in self.__dict__:
30020  *                 continue
30021  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
30022  * 
30023  *         for f in self.__dict__:
30024  */
30025     __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 = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30026     __Pyx_GOTREF(__pyx_t_3);
30027     __pyx_t_6 = PyNumber_Add(((PyObject *)__pyx_kp_s_169), __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30028     __Pyx_GOTREF(__pyx_t_6);
30029     __pyx_t_7 = PyNumber_Add(__pyx_t_6, ((PyObject *)__pyx_kp_s_170)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30030     __Pyx_GOTREF(__pyx_t_7);
30031     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
30032     __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 = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30033     __Pyx_GOTREF(__pyx_t_6);
30034     __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30035     __Pyx_GOTREF(__pyx_t_8);
30036     __Pyx_INCREF(__pyx_v_f);
30037     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
30038     __Pyx_GIVEREF(__pyx_v_f);
30039     __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 = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30040     __Pyx_GOTREF(__pyx_t_9);
30041     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
30042     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30043     __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30044     __Pyx_GOTREF(__pyx_t_8);
30045     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
30046     __Pyx_GIVEREF(__pyx_t_3);
30047     PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
30048     __Pyx_GIVEREF(__pyx_t_7);
30049     PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
30050     __Pyx_GIVEREF(__pyx_t_9);
30051     __pyx_t_3 = 0;
30052     __pyx_t_7 = 0;
30053     __pyx_t_9 = 0;
30054     __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_168), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30055     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
30056     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30057     __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 = 2995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30058     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
30059     __pyx_L3_continue:;
30060   }
30061   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30062
30063   /* "csamtools.pyx":2997
30064  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
30065  * 
30066  *         for f in self.__dict__:             # <<<<<<<<<<<<<<
30067  *             if not f in field_names:
30068  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
30069  */
30070   __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 = 2997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30071   __Pyx_GOTREF(__pyx_t_1);
30072   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
30073     __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_2 = 0;
30074     __pyx_t_11 = NULL;
30075   } else {
30076     __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30077     __Pyx_GOTREF(__pyx_t_9);
30078     __pyx_t_11 = Py_TYPE(__pyx_t_9)->tp_iternext;
30079   }
30080   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30081   for (;;) {
30082     if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_9)) {
30083       if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
30084       __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
30085     } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_9)) {
30086       if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
30087       __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
30088     } else {
30089       __pyx_t_1 = __pyx_t_11(__pyx_t_9);
30090       if (unlikely(!__pyx_t_1)) {
30091         if (PyErr_Occurred()) {
30092           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
30093           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30094         }
30095         break;
30096       }
30097       __Pyx_GOTREF(__pyx_t_1);
30098     }
30099     __Pyx_XDECREF(__pyx_v_f);
30100     __pyx_v_f = __pyx_t_1;
30101     __pyx_t_1 = 0;
30102
30103     /* "csamtools.pyx":2998
30104  * 
30105  *         for f in self.__dict__:
30106  *             if not f in field_names:             # <<<<<<<<<<<<<<
30107  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
30108  *         return ret_string
30109  */
30110     __pyx_t_5 = ((PyDict_Contains(((PyObject *)__pyx_v_field_names), __pyx_v_f))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2998; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30111     __pyx_t_4 = (!__pyx_t_5);
30112     if (__pyx_t_4) {
30113
30114       /* "csamtools.pyx":2999
30115  *         for f in self.__dict__:
30116  *             if not f in field_names:
30117  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
30118  *         return ret_string
30119  * 
30120  */
30121       __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 = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30122       __Pyx_GOTREF(__pyx_t_1);
30123       __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30124       __Pyx_GOTREF(__pyx_t_8);
30125       __Pyx_INCREF(__pyx_v_f);
30126       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
30127       __Pyx_GIVEREF(__pyx_v_f);
30128       __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 = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30129       __Pyx_GOTREF(__pyx_t_7);
30130       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30131       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30132       __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30133       __Pyx_GOTREF(__pyx_t_8);
30134       __Pyx_INCREF(__pyx_v_f);
30135       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
30136       __Pyx_GIVEREF(__pyx_v_f);
30137       __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
30138       PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_kp_s_16));
30139       __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
30140       PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
30141       __Pyx_GIVEREF(__pyx_t_7);
30142       __pyx_t_7 = 0;
30143       __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_168), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30144       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
30145       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30146       __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 = 2999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30147       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
30148       goto __pyx_L8;
30149     }
30150     __pyx_L8:;
30151   }
30152   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
30153
30154   /* "csamtools.pyx":3000
30155  *             if not f in field_names:
30156  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
30157  *         return ret_string             # <<<<<<<<<<<<<<
30158  * 
30159  * cdef class PileupProxy:
30160  */
30161   __Pyx_XDECREF(__pyx_r);
30162   __Pyx_INCREF(((PyObject *)__pyx_v_ret_string));
30163   __pyx_r = ((PyObject *)__pyx_v_ret_string);
30164   goto __pyx_L0;
30165
30166   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30167   goto __pyx_L0;
30168   __pyx_L1_error:;
30169   __Pyx_XDECREF(__pyx_t_1);
30170   __Pyx_XDECREF(__pyx_t_3);
30171   __Pyx_XDECREF(__pyx_t_6);
30172   __Pyx_XDECREF(__pyx_t_7);
30173   __Pyx_XDECREF(__pyx_t_8);
30174   __Pyx_XDECREF(__pyx_t_9);
30175   __Pyx_AddTraceback("csamtools.AlignedRead.fancy_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
30176   __pyx_r = NULL;
30177   __pyx_L0:;
30178   __Pyx_XDECREF(__pyx_v_ret_string);
30179   __Pyx_XDECREF(__pyx_v_field_names);
30180   __Pyx_XDECREF(__pyx_v_fields_names_in_order);
30181   __Pyx_XDECREF(__pyx_v_f);
30182   __Pyx_XGIVEREF(__pyx_r);
30183   __Pyx_TraceReturn(__pyx_r);
30184   __Pyx_RefNannyFinishContext();
30185   return __pyx_r;
30186 }
30187
30188 /* Python wrapper */
30189 static int __pyx_pw_9csamtools_11PileupProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
30190 static int __pyx_pw_9csamtools_11PileupProxy_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
30191   int __pyx_r;
30192   __Pyx_RefNannyDeclarations
30193   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
30194   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
30195     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
30196   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
30197   __pyx_r = __pyx_pf_9csamtools_11PileupProxy___init__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30198   __Pyx_RefNannyFinishContext();
30199   return __pyx_r;
30200 }
30201
30202 /* "csamtools.pyx":3019
30203  *     will change.
30204  *     '''
30205  *     def __init__(self):             # <<<<<<<<<<<<<<
30206  *         raise TypeError("This class cannot be instantiated from Python")
30207  * 
30208  */
30209
30210 static int __pyx_pf_9csamtools_11PileupProxy___init__(CYTHON_UNUSED struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30211   int __pyx_r;
30212   __Pyx_RefNannyDeclarations
30213   PyObject *__pyx_t_1 = NULL;
30214   int __pyx_lineno = 0;
30215   const char *__pyx_filename = NULL;
30216   int __pyx_clineno = 0;
30217   __Pyx_TraceDeclarations
30218   __Pyx_RefNannySetupContext("__init__", 0);
30219   __Pyx_TraceCall("__init__", __pyx_f[0], 3019);
30220
30221   /* "csamtools.pyx":3020
30222  *     '''
30223  *     def __init__(self):
30224  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
30225  * 
30226  *     def __str__(self):
30227  */
30228   __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_172), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30229   __Pyx_GOTREF(__pyx_t_1);
30230   __Pyx_Raise(__pyx_t_1, 0, 0, 0);
30231   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30232   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30233
30234   __pyx_r = 0;
30235   goto __pyx_L0;
30236   __pyx_L1_error:;
30237   __Pyx_XDECREF(__pyx_t_1);
30238   __Pyx_AddTraceback("csamtools.PileupProxy.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30239   __pyx_r = -1;
30240   __pyx_L0:;
30241   __Pyx_TraceReturn(Py_None);
30242   __Pyx_RefNannyFinishContext();
30243   return __pyx_r;
30244 }
30245
30246 /* Python wrapper */
30247 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3__str__(PyObject *__pyx_v_self); /*proto*/
30248 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3__str__(PyObject *__pyx_v_self) {
30249   PyObject *__pyx_r = 0;
30250   __Pyx_RefNannyDeclarations
30251   __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
30252   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_2__str__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30253   __Pyx_RefNannyFinishContext();
30254   return __pyx_r;
30255 }
30256
30257 /* "csamtools.pyx":3022
30258  *         raise TypeError("This class cannot be instantiated from Python")
30259  * 
30260  *     def __str__(self):             # <<<<<<<<<<<<<<
30261  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
30262  *             "\n" +\
30263  */
30264
30265 static PyObject *__pyx_pf_9csamtools_11PileupProxy_2__str__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30266   PyObject *__pyx_r = NULL;
30267   __Pyx_RefNannyDeclarations
30268   PyObject *__pyx_t_1 = NULL;
30269   PyObject *__pyx_t_2 = NULL;
30270   PyObject *__pyx_t_3 = NULL;
30271   PyObject *__pyx_t_4 = NULL;
30272   PyObject *__pyx_t_5 = NULL;
30273   int __pyx_lineno = 0;
30274   const char *__pyx_filename = NULL;
30275   int __pyx_clineno = 0;
30276   __Pyx_TraceDeclarations
30277   __Pyx_RefNannySetupContext("__str__", 0);
30278   __Pyx_TraceCall("__str__", __pyx_f[0], 3022);
30279
30280   /* "csamtools.pyx":3023
30281  * 
30282  *     def __str__(self):
30283  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
30284  *             "\n" +\
30285  *             "\n".join( map(str, self.pileups) )
30286  */
30287   __Pyx_XDECREF(__pyx_r);
30288
30289   /* "csamtools.pyx":3024
30290  *     def __str__(self):
30291  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
30292  *             "\n" +\             # <<<<<<<<<<<<<<
30293  *             "\n".join( map(str, self.pileups) )
30294  * 
30295  */
30296   __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 = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30297   __Pyx_GOTREF(__pyx_t_1);
30298
30299   /* "csamtools.pyx":3023
30300  * 
30301  *     def __str__(self):
30302  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
30303  *             "\n" +\
30304  *             "\n".join( map(str, self.pileups) )
30305  */
30306   __pyx_t_2 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30307   __Pyx_GOTREF(__pyx_t_2);
30308   __pyx_t_3 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30309   __Pyx_GOTREF(__pyx_t_3);
30310   __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 = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30311   __Pyx_GOTREF(__pyx_t_4);
30312   __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30313   __Pyx_GOTREF(__pyx_t_5);
30314   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
30315   __Pyx_GIVEREF(__pyx_t_2);
30316   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
30317   __Pyx_GIVEREF(__pyx_t_3);
30318   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
30319   __Pyx_GIVEREF(__pyx_t_4);
30320   __pyx_t_2 = 0;
30321   __pyx_t_3 = 0;
30322   __pyx_t_4 = 0;
30323   __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30324   __Pyx_GOTREF(__pyx_t_4);
30325   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
30326   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
30327   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
30328   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
30329   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
30330   __pyx_t_5 = 0;
30331   __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 = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30332   __Pyx_GOTREF(__pyx_t_5);
30333   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
30334   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30335   __Pyx_GOTREF(__pyx_t_4);
30336   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
30337   __Pyx_GIVEREF(__pyx_t_5);
30338   __pyx_t_5 = 0;
30339   __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 = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30340   __Pyx_GOTREF(__pyx_t_5);
30341   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30342   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
30343   __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 = 3023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30344   __Pyx_GOTREF(__pyx_t_4);
30345   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
30346
30347   /* "csamtools.pyx":3025
30348  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
30349  *             "\n" +\
30350  *             "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
30351  * 
30352  *     property tid:
30353  */
30354   __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 = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30355   __Pyx_GOTREF(__pyx_t_5);
30356   __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 = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30357   __Pyx_GOTREF(__pyx_t_1);
30358   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30359   __Pyx_GOTREF(__pyx_t_3);
30360   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
30361   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
30362   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
30363   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
30364   __Pyx_GIVEREF(__pyx_t_1);
30365   __pyx_t_1 = 0;
30366   __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 = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30367   __Pyx_GOTREF(__pyx_t_1);
30368   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
30369   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30370   __Pyx_GOTREF(__pyx_t_3);
30371   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
30372   __Pyx_GIVEREF(__pyx_t_1);
30373   __pyx_t_1 = 0;
30374   __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 = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30375   __Pyx_GOTREF(__pyx_t_1);
30376   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
30377   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
30378   __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30379   __Pyx_GOTREF(__pyx_t_3);
30380   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
30381   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30382   __pyx_r = __pyx_t_3;
30383   __pyx_t_3 = 0;
30384   goto __pyx_L0;
30385
30386   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30387   goto __pyx_L0;
30388   __pyx_L1_error:;
30389   __Pyx_XDECREF(__pyx_t_1);
30390   __Pyx_XDECREF(__pyx_t_2);
30391   __Pyx_XDECREF(__pyx_t_3);
30392   __Pyx_XDECREF(__pyx_t_4);
30393   __Pyx_XDECREF(__pyx_t_5);
30394   __Pyx_AddTraceback("csamtools.PileupProxy.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30395   __pyx_r = NULL;
30396   __pyx_L0:;
30397   __Pyx_XGIVEREF(__pyx_r);
30398   __Pyx_TraceReturn(__pyx_r);
30399   __Pyx_RefNannyFinishContext();
30400   return __pyx_r;
30401 }
30402
30403 /* Python wrapper */
30404 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
30405 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3tid_1__get__(PyObject *__pyx_v_self) {
30406   PyObject *__pyx_r = 0;
30407   __Pyx_RefNannyDeclarations
30408   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30409   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_3tid___get__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30410   __Pyx_RefNannyFinishContext();
30411   return __pyx_r;
30412 }
30413
30414 /* "csamtools.pyx":3029
30415  *     property tid:
30416  *         '''the chromosome ID as is defined in the header'''
30417  *         def __get__(self): return self.tid             # <<<<<<<<<<<<<<
30418  * 
30419  *     property n:
30420  */
30421
30422 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3tid___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30423   PyObject *__pyx_r = NULL;
30424   __Pyx_RefNannyDeclarations
30425   PyObject *__pyx_t_1 = NULL;
30426   int __pyx_lineno = 0;
30427   const char *__pyx_filename = NULL;
30428   int __pyx_clineno = 0;
30429   __Pyx_TraceDeclarations
30430   __Pyx_RefNannySetupContext("__get__", 0);
30431   __Pyx_TraceCall("__get__", __pyx_f[0], 3029);
30432   __Pyx_XDECREF(__pyx_r);
30433   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30434   __Pyx_GOTREF(__pyx_t_1);
30435   __pyx_r = __pyx_t_1;
30436   __pyx_t_1 = 0;
30437   goto __pyx_L0;
30438
30439   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30440   goto __pyx_L0;
30441   __pyx_L1_error:;
30442   __Pyx_XDECREF(__pyx_t_1);
30443   __Pyx_AddTraceback("csamtools.PileupProxy.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30444   __pyx_r = NULL;
30445   __pyx_L0:;
30446   __Pyx_XGIVEREF(__pyx_r);
30447   __Pyx_TraceReturn(__pyx_r);
30448   __Pyx_RefNannyFinishContext();
30449   return __pyx_r;
30450 }
30451
30452 /* Python wrapper */
30453 static PyObject *__pyx_pw_9csamtools_11PileupProxy_1n_1__get__(PyObject *__pyx_v_self); /*proto*/
30454 static PyObject *__pyx_pw_9csamtools_11PileupProxy_1n_1__get__(PyObject *__pyx_v_self) {
30455   PyObject *__pyx_r = 0;
30456   __Pyx_RefNannyDeclarations
30457   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30458   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_1n___get__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30459   __Pyx_RefNannyFinishContext();
30460   return __pyx_r;
30461 }
30462
30463 /* "csamtools.pyx":3033
30464  *     property n:
30465  *         '''number of reads mapping to this column.'''
30466  *         def __get__(self): return self.n_pu             # <<<<<<<<<<<<<<
30467  *         def __set__(self, n): self.n_pu = n
30468  * 
30469  */
30470
30471 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1n___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30472   PyObject *__pyx_r = NULL;
30473   __Pyx_RefNannyDeclarations
30474   PyObject *__pyx_t_1 = NULL;
30475   int __pyx_lineno = 0;
30476   const char *__pyx_filename = NULL;
30477   int __pyx_clineno = 0;
30478   __Pyx_TraceDeclarations
30479   __Pyx_RefNannySetupContext("__get__", 0);
30480   __Pyx_TraceCall("__get__", __pyx_f[0], 3033);
30481   __Pyx_XDECREF(__pyx_r);
30482   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30483   __Pyx_GOTREF(__pyx_t_1);
30484   __pyx_r = __pyx_t_1;
30485   __pyx_t_1 = 0;
30486   goto __pyx_L0;
30487
30488   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30489   goto __pyx_L0;
30490   __pyx_L1_error:;
30491   __Pyx_XDECREF(__pyx_t_1);
30492   __Pyx_AddTraceback("csamtools.PileupProxy.n.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30493   __pyx_r = NULL;
30494   __pyx_L0:;
30495   __Pyx_XGIVEREF(__pyx_r);
30496   __Pyx_TraceReturn(__pyx_r);
30497   __Pyx_RefNannyFinishContext();
30498   return __pyx_r;
30499 }
30500
30501 /* Python wrapper */
30502 static int __pyx_pw_9csamtools_11PileupProxy_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
30503 static int __pyx_pw_9csamtools_11PileupProxy_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
30504   int __pyx_r;
30505   __Pyx_RefNannyDeclarations
30506   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
30507   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_1n_2__set__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self), ((PyObject *)__pyx_v_n));
30508   __Pyx_RefNannyFinishContext();
30509   return __pyx_r;
30510 }
30511
30512 /* "csamtools.pyx":3034
30513  *         '''number of reads mapping to this column.'''
30514  *         def __get__(self): return self.n_pu
30515  *         def __set__(self, n): self.n_pu = n             # <<<<<<<<<<<<<<
30516  * 
30517  *     property pos:
30518  */
30519
30520 static int __pyx_pf_9csamtools_11PileupProxy_1n_2__set__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self, PyObject *__pyx_v_n) {
30521   int __pyx_r;
30522   __Pyx_RefNannyDeclarations
30523   int __pyx_t_1;
30524   int __pyx_lineno = 0;
30525   const char *__pyx_filename = NULL;
30526   int __pyx_clineno = 0;
30527   __Pyx_TraceDeclarations
30528   __Pyx_RefNannySetupContext("__set__", 0);
30529   __Pyx_TraceCall("__set__", __pyx_f[0], 3034);
30530   __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 = 3034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30531   __pyx_v_self->n_pu = __pyx_t_1;
30532
30533   __pyx_r = 0;
30534   goto __pyx_L0;
30535   __pyx_L1_error:;
30536   __Pyx_AddTraceback("csamtools.PileupProxy.n.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30537   __pyx_r = -1;
30538   __pyx_L0:;
30539   __Pyx_TraceReturn(Py_None);
30540   __Pyx_RefNannyFinishContext();
30541   return __pyx_r;
30542 }
30543
30544 /* Python wrapper */
30545 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
30546 static PyObject *__pyx_pw_9csamtools_11PileupProxy_3pos_1__get__(PyObject *__pyx_v_self) {
30547   PyObject *__pyx_r = 0;
30548   __Pyx_RefNannyDeclarations
30549   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30550   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_3pos___get__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30551   __Pyx_RefNannyFinishContext();
30552   return __pyx_r;
30553 }
30554
30555 /* "csamtools.pyx":3037
30556  * 
30557  *     property pos:
30558  *         def __get__(self): return self.pos             # <<<<<<<<<<<<<<
30559  * 
30560  *     property pileups:
30561  */
30562
30563 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3pos___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30564   PyObject *__pyx_r = NULL;
30565   __Pyx_RefNannyDeclarations
30566   PyObject *__pyx_t_1 = NULL;
30567   int __pyx_lineno = 0;
30568   const char *__pyx_filename = NULL;
30569   int __pyx_clineno = 0;
30570   __Pyx_TraceDeclarations
30571   __Pyx_RefNannySetupContext("__get__", 0);
30572   __Pyx_TraceCall("__get__", __pyx_f[0], 3037);
30573   __Pyx_XDECREF(__pyx_r);
30574   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30575   __Pyx_GOTREF(__pyx_t_1);
30576   __pyx_r = __pyx_t_1;
30577   __pyx_t_1 = 0;
30578   goto __pyx_L0;
30579
30580   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30581   goto __pyx_L0;
30582   __pyx_L1_error:;
30583   __Pyx_XDECREF(__pyx_t_1);
30584   __Pyx_AddTraceback("csamtools.PileupProxy.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30585   __pyx_r = NULL;
30586   __pyx_L0:;
30587   __Pyx_XGIVEREF(__pyx_r);
30588   __Pyx_TraceReturn(__pyx_r);
30589   __Pyx_RefNannyFinishContext();
30590   return __pyx_r;
30591 }
30592
30593 /* Python wrapper */
30594 static PyObject *__pyx_pw_9csamtools_11PileupProxy_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/
30595 static PyObject *__pyx_pw_9csamtools_11PileupProxy_7pileups_1__get__(PyObject *__pyx_v_self) {
30596   PyObject *__pyx_r = 0;
30597   __Pyx_RefNannyDeclarations
30598   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30599   __pyx_r = __pyx_pf_9csamtools_11PileupProxy_7pileups___get__(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self));
30600   __Pyx_RefNannyFinishContext();
30601   return __pyx_r;
30602 }
30603
30604 /* "csamtools.pyx":3041
30605  *     property pileups:
30606  *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
30607  *         def __get__(self):             # <<<<<<<<<<<<<<
30608  *             cdef int x
30609  *             pileups = []
30610  */
30611
30612 static PyObject *__pyx_pf_9csamtools_11PileupProxy_7pileups___get__(struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_self) {
30613   int __pyx_v_x;
30614   PyObject *__pyx_v_pileups = NULL;
30615   PyObject *__pyx_r = NULL;
30616   __Pyx_RefNannyDeclarations
30617   PyObject *__pyx_t_1 = NULL;
30618   int __pyx_t_2;
30619   int __pyx_t_3;
30620   int __pyx_t_4;
30621   int __pyx_lineno = 0;
30622   const char *__pyx_filename = NULL;
30623   int __pyx_clineno = 0;
30624   __Pyx_TraceDeclarations
30625   __Pyx_RefNannySetupContext("__get__", 0);
30626   __Pyx_TraceCall("__get__", __pyx_f[0], 3041);
30627
30628   /* "csamtools.pyx":3043
30629  *         def __get__(self):
30630  *             cdef int x
30631  *             pileups = []             # <<<<<<<<<<<<<<
30632  * 
30633  *             if self.plp[0] == NULL:
30634  */
30635   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30636   __Pyx_GOTREF(__pyx_t_1);
30637   __pyx_v_pileups = __pyx_t_1;
30638   __pyx_t_1 = 0;
30639
30640   /* "csamtools.pyx":3045
30641  *             pileups = []
30642  * 
30643  *             if self.plp[0] == NULL:             # <<<<<<<<<<<<<<
30644  *                 raise ValueError("PileupProxy accessed after iterator finished")
30645  * 
30646  */
30647   __pyx_t_2 = ((__pyx_v_self->plp[0]) == NULL);
30648   if (__pyx_t_2) {
30649
30650     /* "csamtools.pyx":3046
30651  * 
30652  *             if self.plp[0] == NULL:
30653  *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
30654  * 
30655  *             # warning: there could be problems if self.n and self.buf are
30656  */
30657     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_174), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30658     __Pyx_GOTREF(__pyx_t_1);
30659     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
30660     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30661     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30662     goto __pyx_L3;
30663   }
30664   __pyx_L3:;
30665
30666   /* "csamtools.pyx":3050
30667  *             # warning: there could be problems if self.n and self.buf are
30668  *             # out of sync.
30669  *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
30670  *                 pileups.append( makePileupRead( &(self.plp[0][x])) )
30671  *             return pileups
30672  */
30673   __pyx_t_3 = __pyx_v_self->n_pu;
30674   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
30675
30676     /* "csamtools.pyx":3051
30677  *             # out of sync.
30678  *             for x from 0 <= x < self.n_pu:
30679  *                 pileups.append( makePileupRead( &(self.plp[0][x])) )             # <<<<<<<<<<<<<<
30680  *             return pileups
30681  * 
30682  */
30683     __pyx_t_1 = __pyx_f_9csamtools_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30684     __Pyx_GOTREF(__pyx_t_1);
30685     __pyx_t_4 = PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30686     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30687   }
30688
30689   /* "csamtools.pyx":3052
30690  *             for x from 0 <= x < self.n_pu:
30691  *                 pileups.append( makePileupRead( &(self.plp[0][x])) )
30692  *             return pileups             # <<<<<<<<<<<<<<
30693  * 
30694  * cdef class PileupRead:
30695  */
30696   __Pyx_XDECREF(__pyx_r);
30697   __Pyx_INCREF(((PyObject *)__pyx_v_pileups));
30698   __pyx_r = ((PyObject *)__pyx_v_pileups);
30699   goto __pyx_L0;
30700
30701   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30702   goto __pyx_L0;
30703   __pyx_L1_error:;
30704   __Pyx_XDECREF(__pyx_t_1);
30705   __Pyx_AddTraceback("csamtools.PileupProxy.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30706   __pyx_r = NULL;
30707   __pyx_L0:;
30708   __Pyx_XDECREF(__pyx_v_pileups);
30709   __Pyx_XGIVEREF(__pyx_r);
30710   __Pyx_TraceReturn(__pyx_r);
30711   __Pyx_RefNannyFinishContext();
30712   return __pyx_r;
30713 }
30714
30715 /* Python wrapper */
30716 static int __pyx_pw_9csamtools_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
30717 static int __pyx_pw_9csamtools_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
30718   int __pyx_r;
30719   __Pyx_RefNannyDeclarations
30720   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
30721   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
30722     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
30723   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
30724   __pyx_r = __pyx_pf_9csamtools_10PileupRead___init__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
30725   __Pyx_RefNannyFinishContext();
30726   return __pyx_r;
30727 }
30728
30729 /* "csamtools.pyx":3058
30730  *     '''
30731  * 
30732  *     def __init__(self):             # <<<<<<<<<<<<<<
30733  *         raise TypeError("This class cannot be instantiated from Python")
30734  * 
30735  */
30736
30737 static int __pyx_pf_9csamtools_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
30738   int __pyx_r;
30739   __Pyx_RefNannyDeclarations
30740   PyObject *__pyx_t_1 = NULL;
30741   int __pyx_lineno = 0;
30742   const char *__pyx_filename = NULL;
30743   int __pyx_clineno = 0;
30744   __Pyx_TraceDeclarations
30745   __Pyx_RefNannySetupContext("__init__", 0);
30746   __Pyx_TraceCall("__init__", __pyx_f[0], 3058);
30747
30748   /* "csamtools.pyx":3059
30749  * 
30750  *     def __init__(self):
30751  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
30752  * 
30753  *     def __str__(self):
30754  */
30755   __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_175), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30756   __Pyx_GOTREF(__pyx_t_1);
30757   __Pyx_Raise(__pyx_t_1, 0, 0, 0);
30758   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30759   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30760
30761   __pyx_r = 0;
30762   goto __pyx_L0;
30763   __pyx_L1_error:;
30764   __Pyx_XDECREF(__pyx_t_1);
30765   __Pyx_AddTraceback("csamtools.PileupRead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30766   __pyx_r = -1;
30767   __pyx_L0:;
30768   __Pyx_TraceReturn(Py_None);
30769   __Pyx_RefNannyFinishContext();
30770   return __pyx_r;
30771 }
30772
30773 /* Python wrapper */
30774 static PyObject *__pyx_pw_9csamtools_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/
30775 static PyObject *__pyx_pw_9csamtools_10PileupRead_3__str__(PyObject *__pyx_v_self) {
30776   PyObject *__pyx_r = 0;
30777   __Pyx_RefNannyDeclarations
30778   __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
30779   __pyx_r = __pyx_pf_9csamtools_10PileupRead_2__str__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
30780   __Pyx_RefNannyFinishContext();
30781   return __pyx_r;
30782 }
30783
30784 /* "csamtools.pyx":3061
30785  *         raise TypeError("This class cannot be instantiated from Python")
30786  * 
30787  *     def __str__(self):             # <<<<<<<<<<<<<<
30788  *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )
30789  * 
30790  */
30791
30792 static PyObject *__pyx_pf_9csamtools_10PileupRead_2__str__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
30793   PyObject *__pyx_r = NULL;
30794   __Pyx_RefNannyDeclarations
30795   PyObject *__pyx_t_1 = NULL;
30796   PyObject *__pyx_t_2 = NULL;
30797   PyObject *__pyx_t_3 = NULL;
30798   PyObject *__pyx_t_4 = NULL;
30799   PyObject *__pyx_t_5 = NULL;
30800   PyObject *__pyx_t_6 = NULL;
30801   PyObject *__pyx_t_7 = NULL;
30802   PyObject *__pyx_t_8 = NULL;
30803   PyObject *__pyx_t_9 = NULL;
30804   int __pyx_lineno = 0;
30805   const char *__pyx_filename = NULL;
30806   int __pyx_clineno = 0;
30807   __Pyx_TraceDeclarations
30808   __Pyx_RefNannySetupContext("__str__", 0);
30809   __Pyx_TraceCall("__str__", __pyx_f[0], 3061);
30810
30811   /* "csamtools.pyx":3062
30812  * 
30813  *     def __str__(self):
30814  *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )             # <<<<<<<<<<<<<<
30815  * 
30816  *     property alignment:
30817  */
30818   __Pyx_XDECREF(__pyx_r);
30819   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30820   __Pyx_GOTREF(__pyx_t_1);
30821   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30822   __Pyx_GOTREF(__pyx_t_2);
30823   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30824   __Pyx_GOTREF(__pyx_t_3);
30825   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30826   __Pyx_GOTREF(__pyx_t_4);
30827   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30828   __Pyx_GOTREF(__pyx_t_5);
30829   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30830   __Pyx_GOTREF(__pyx_t_6);
30831   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30832   __Pyx_GOTREF(__pyx_t_7);
30833   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30834   __Pyx_GOTREF(__pyx_t_8);
30835   __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30836   __Pyx_GOTREF(__pyx_t_9);
30837   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
30838   __Pyx_GIVEREF(__pyx_t_2);
30839   PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
30840   __Pyx_GIVEREF(__pyx_t_3);
30841   PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_4);
30842   __Pyx_GIVEREF(__pyx_t_4);
30843   PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_5);
30844   __Pyx_GIVEREF(__pyx_t_5);
30845   PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_6);
30846   __Pyx_GIVEREF(__pyx_t_6);
30847   PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_7);
30848   __Pyx_GIVEREF(__pyx_t_7);
30849   PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_8);
30850   __Pyx_GIVEREF(__pyx_t_8);
30851   __pyx_t_2 = 0;
30852   __pyx_t_3 = 0;
30853   __pyx_t_4 = 0;
30854   __pyx_t_5 = 0;
30855   __pyx_t_6 = 0;
30856   __pyx_t_7 = 0;
30857   __pyx_t_8 = 0;
30858   __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30859   __Pyx_GOTREF(__pyx_t_8);
30860   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
30861   PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
30862   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
30863   PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_t_9));
30864   __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
30865   __pyx_t_9 = 0;
30866   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30867   __Pyx_GOTREF(__pyx_t_9);
30868   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30869   __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30870   __Pyx_GOTREF(__pyx_t_8);
30871   PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
30872   __Pyx_GIVEREF(__pyx_t_9);
30873   __pyx_t_9 = 0;
30874   __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 = 3062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30875   __Pyx_GOTREF(__pyx_t_9);
30876   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
30877   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
30878   __pyx_r = __pyx_t_9;
30879   __pyx_t_9 = 0;
30880   goto __pyx_L0;
30881
30882   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30883   goto __pyx_L0;
30884   __pyx_L1_error:;
30885   __Pyx_XDECREF(__pyx_t_1);
30886   __Pyx_XDECREF(__pyx_t_2);
30887   __Pyx_XDECREF(__pyx_t_3);
30888   __Pyx_XDECREF(__pyx_t_4);
30889   __Pyx_XDECREF(__pyx_t_5);
30890   __Pyx_XDECREF(__pyx_t_6);
30891   __Pyx_XDECREF(__pyx_t_7);
30892   __Pyx_XDECREF(__pyx_t_8);
30893   __Pyx_XDECREF(__pyx_t_9);
30894   __Pyx_AddTraceback("csamtools.PileupRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30895   __pyx_r = NULL;
30896   __pyx_L0:;
30897   __Pyx_XGIVEREF(__pyx_r);
30898   __Pyx_TraceReturn(__pyx_r);
30899   __Pyx_RefNannyFinishContext();
30900   return __pyx_r;
30901 }
30902
30903 /* Python wrapper */
30904 static PyObject *__pyx_pw_9csamtools_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/
30905 static PyObject *__pyx_pw_9csamtools_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) {
30906   PyObject *__pyx_r = 0;
30907   __Pyx_RefNannyDeclarations
30908   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30909   __pyx_r = __pyx_pf_9csamtools_10PileupRead_9alignment___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
30910   __Pyx_RefNannyFinishContext();
30911   return __pyx_r;
30912 }
30913
30914 /* "csamtools.pyx":3066
30915  *     property alignment:
30916  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
30917  *         def __get__(self):             # <<<<<<<<<<<<<<
30918  *             return self._alignment
30919  *     property qpos:
30920  */
30921
30922 static PyObject *__pyx_pf_9csamtools_10PileupRead_9alignment___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
30923   PyObject *__pyx_r = NULL;
30924   __Pyx_RefNannyDeclarations
30925   __Pyx_TraceDeclarations
30926   __Pyx_RefNannySetupContext("__get__", 0);
30927   __Pyx_TraceCall("__get__", __pyx_f[0], 3066);
30928
30929   /* "csamtools.pyx":3067
30930  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
30931  *         def __get__(self):
30932  *             return self._alignment             # <<<<<<<<<<<<<<
30933  *     property qpos:
30934  *         """position of the read base at the pileup site, 0-based"""
30935  */
30936   __Pyx_XDECREF(__pyx_r);
30937   __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment));
30938   __pyx_r = ((PyObject *)__pyx_v_self->_alignment);
30939   goto __pyx_L0;
30940
30941   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30942   __pyx_L0:;
30943   __Pyx_XGIVEREF(__pyx_r);
30944   __Pyx_TraceReturn(__pyx_r);
30945   __Pyx_RefNannyFinishContext();
30946   return __pyx_r;
30947 }
30948
30949 /* Python wrapper */
30950 static PyObject *__pyx_pw_9csamtools_10PileupRead_4qpos_1__get__(PyObject *__pyx_v_self); /*proto*/
30951 static PyObject *__pyx_pw_9csamtools_10PileupRead_4qpos_1__get__(PyObject *__pyx_v_self) {
30952   PyObject *__pyx_r = 0;
30953   __Pyx_RefNannyDeclarations
30954   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
30955   __pyx_r = __pyx_pf_9csamtools_10PileupRead_4qpos___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
30956   __Pyx_RefNannyFinishContext();
30957   return __pyx_r;
30958 }
30959
30960 /* "csamtools.pyx":3070
30961  *     property qpos:
30962  *         """position of the read base at the pileup site, 0-based"""
30963  *         def __get__(self):             # <<<<<<<<<<<<<<
30964  *             return self._qpos
30965  *     property indel:
30966  */
30967
30968 static PyObject *__pyx_pf_9csamtools_10PileupRead_4qpos___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
30969   PyObject *__pyx_r = NULL;
30970   __Pyx_RefNannyDeclarations
30971   PyObject *__pyx_t_1 = NULL;
30972   int __pyx_lineno = 0;
30973   const char *__pyx_filename = NULL;
30974   int __pyx_clineno = 0;
30975   __Pyx_TraceDeclarations
30976   __Pyx_RefNannySetupContext("__get__", 0);
30977   __Pyx_TraceCall("__get__", __pyx_f[0], 3070);
30978
30979   /* "csamtools.pyx":3071
30980  *         """position of the read base at the pileup site, 0-based"""
30981  *         def __get__(self):
30982  *             return self._qpos             # <<<<<<<<<<<<<<
30983  *     property indel:
30984  *         """indel length; 0 for no indel, positive for ins and negative for del"""
30985  */
30986   __Pyx_XDECREF(__pyx_r);
30987   __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 = 3071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
30988   __Pyx_GOTREF(__pyx_t_1);
30989   __pyx_r = __pyx_t_1;
30990   __pyx_t_1 = 0;
30991   goto __pyx_L0;
30992
30993   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
30994   goto __pyx_L0;
30995   __pyx_L1_error:;
30996   __Pyx_XDECREF(__pyx_t_1);
30997   __Pyx_AddTraceback("csamtools.PileupRead.qpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
30998   __pyx_r = NULL;
30999   __pyx_L0:;
31000   __Pyx_XGIVEREF(__pyx_r);
31001   __Pyx_TraceReturn(__pyx_r);
31002   __Pyx_RefNannyFinishContext();
31003   return __pyx_r;
31004 }
31005
31006 /* Python wrapper */
31007 static PyObject *__pyx_pw_9csamtools_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/
31008 static PyObject *__pyx_pw_9csamtools_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) {
31009   PyObject *__pyx_r = 0;
31010   __Pyx_RefNannyDeclarations
31011   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
31012   __pyx_r = __pyx_pf_9csamtools_10PileupRead_5indel___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
31013   __Pyx_RefNannyFinishContext();
31014   return __pyx_r;
31015 }
31016
31017 /* "csamtools.pyx":3074
31018  *     property indel:
31019  *         """indel length; 0 for no indel, positive for ins and negative for del"""
31020  *         def __get__(self):             # <<<<<<<<<<<<<<
31021  *             return self._indel
31022  *     property is_del:
31023  */
31024
31025 static PyObject *__pyx_pf_9csamtools_10PileupRead_5indel___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
31026   PyObject *__pyx_r = NULL;
31027   __Pyx_RefNannyDeclarations
31028   PyObject *__pyx_t_1 = NULL;
31029   int __pyx_lineno = 0;
31030   const char *__pyx_filename = NULL;
31031   int __pyx_clineno = 0;
31032   __Pyx_TraceDeclarations
31033   __Pyx_RefNannySetupContext("__get__", 0);
31034   __Pyx_TraceCall("__get__", __pyx_f[0], 3074);
31035
31036   /* "csamtools.pyx":3075
31037  *         """indel length; 0 for no indel, positive for ins and negative for del"""
31038  *         def __get__(self):
31039  *             return self._indel             # <<<<<<<<<<<<<<
31040  *     property is_del:
31041  *         """1 iff the base on the padded read is a deletion"""
31042  */
31043   __Pyx_XDECREF(__pyx_r);
31044   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31045   __Pyx_GOTREF(__pyx_t_1);
31046   __pyx_r = __pyx_t_1;
31047   __pyx_t_1 = 0;
31048   goto __pyx_L0;
31049
31050   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31051   goto __pyx_L0;
31052   __pyx_L1_error:;
31053   __Pyx_XDECREF(__pyx_t_1);
31054   __Pyx_AddTraceback("csamtools.PileupRead.indel.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31055   __pyx_r = NULL;
31056   __pyx_L0:;
31057   __Pyx_XGIVEREF(__pyx_r);
31058   __Pyx_TraceReturn(__pyx_r);
31059   __Pyx_RefNannyFinishContext();
31060   return __pyx_r;
31061 }
31062
31063 /* Python wrapper */
31064 static PyObject *__pyx_pw_9csamtools_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/
31065 static PyObject *__pyx_pw_9csamtools_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) {
31066   PyObject *__pyx_r = 0;
31067   __Pyx_RefNannyDeclarations
31068   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
31069   __pyx_r = __pyx_pf_9csamtools_10PileupRead_6is_del___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
31070   __Pyx_RefNannyFinishContext();
31071   return __pyx_r;
31072 }
31073
31074 /* "csamtools.pyx":3078
31075  *     property is_del:
31076  *         """1 iff the base on the padded read is a deletion"""
31077  *         def __get__(self):             # <<<<<<<<<<<<<<
31078  *             return self._is_del
31079  *     property is_head:
31080  */
31081
31082 static PyObject *__pyx_pf_9csamtools_10PileupRead_6is_del___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
31083   PyObject *__pyx_r = NULL;
31084   __Pyx_RefNannyDeclarations
31085   PyObject *__pyx_t_1 = NULL;
31086   int __pyx_lineno = 0;
31087   const char *__pyx_filename = NULL;
31088   int __pyx_clineno = 0;
31089   __Pyx_TraceDeclarations
31090   __Pyx_RefNannySetupContext("__get__", 0);
31091   __Pyx_TraceCall("__get__", __pyx_f[0], 3078);
31092
31093   /* "csamtools.pyx":3079
31094  *         """1 iff the base on the padded read is a deletion"""
31095  *         def __get__(self):
31096  *             return self._is_del             # <<<<<<<<<<<<<<
31097  *     property is_head:
31098  *         def __get__(self):
31099  */
31100   __Pyx_XDECREF(__pyx_r);
31101   __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 = 3079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31102   __Pyx_GOTREF(__pyx_t_1);
31103   __pyx_r = __pyx_t_1;
31104   __pyx_t_1 = 0;
31105   goto __pyx_L0;
31106
31107   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31108   goto __pyx_L0;
31109   __pyx_L1_error:;
31110   __Pyx_XDECREF(__pyx_t_1);
31111   __Pyx_AddTraceback("csamtools.PileupRead.is_del.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31112   __pyx_r = NULL;
31113   __pyx_L0:;
31114   __Pyx_XGIVEREF(__pyx_r);
31115   __Pyx_TraceReturn(__pyx_r);
31116   __Pyx_RefNannyFinishContext();
31117   return __pyx_r;
31118 }
31119
31120 /* Python wrapper */
31121 static PyObject *__pyx_pw_9csamtools_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/
31122 static PyObject *__pyx_pw_9csamtools_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) {
31123   PyObject *__pyx_r = 0;
31124   __Pyx_RefNannyDeclarations
31125   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
31126   __pyx_r = __pyx_pf_9csamtools_10PileupRead_7is_head___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
31127   __Pyx_RefNannyFinishContext();
31128   return __pyx_r;
31129 }
31130
31131 /* "csamtools.pyx":3081
31132  *             return self._is_del
31133  *     property is_head:
31134  *         def __get__(self):             # <<<<<<<<<<<<<<
31135  *             return self._is_head
31136  *     property is_tail:
31137  */
31138
31139 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_head___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
31140   PyObject *__pyx_r = NULL;
31141   __Pyx_RefNannyDeclarations
31142   PyObject *__pyx_t_1 = NULL;
31143   int __pyx_lineno = 0;
31144   const char *__pyx_filename = NULL;
31145   int __pyx_clineno = 0;
31146   __Pyx_TraceDeclarations
31147   __Pyx_RefNannySetupContext("__get__", 0);
31148   __Pyx_TraceCall("__get__", __pyx_f[0], 3081);
31149
31150   /* "csamtools.pyx":3082
31151  *     property is_head:
31152  *         def __get__(self):
31153  *             return self._is_head             # <<<<<<<<<<<<<<
31154  *     property is_tail:
31155  *         def __get__(self):
31156  */
31157   __Pyx_XDECREF(__pyx_r);
31158   __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 = 3082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31159   __Pyx_GOTREF(__pyx_t_1);
31160   __pyx_r = __pyx_t_1;
31161   __pyx_t_1 = 0;
31162   goto __pyx_L0;
31163
31164   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31165   goto __pyx_L0;
31166   __pyx_L1_error:;
31167   __Pyx_XDECREF(__pyx_t_1);
31168   __Pyx_AddTraceback("csamtools.PileupRead.is_head.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31169   __pyx_r = NULL;
31170   __pyx_L0:;
31171   __Pyx_XGIVEREF(__pyx_r);
31172   __Pyx_TraceReturn(__pyx_r);
31173   __Pyx_RefNannyFinishContext();
31174   return __pyx_r;
31175 }
31176
31177 /* Python wrapper */
31178 static PyObject *__pyx_pw_9csamtools_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/
31179 static PyObject *__pyx_pw_9csamtools_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) {
31180   PyObject *__pyx_r = 0;
31181   __Pyx_RefNannyDeclarations
31182   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
31183   __pyx_r = __pyx_pf_9csamtools_10PileupRead_7is_tail___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
31184   __Pyx_RefNannyFinishContext();
31185   return __pyx_r;
31186 }
31187
31188 /* "csamtools.pyx":3084
31189  *             return self._is_head
31190  *     property is_tail:
31191  *         def __get__(self):             # <<<<<<<<<<<<<<
31192  *             return self._is_tail
31193  *     property level:
31194  */
31195
31196 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_tail___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
31197   PyObject *__pyx_r = NULL;
31198   __Pyx_RefNannyDeclarations
31199   PyObject *__pyx_t_1 = NULL;
31200   int __pyx_lineno = 0;
31201   const char *__pyx_filename = NULL;
31202   int __pyx_clineno = 0;
31203   __Pyx_TraceDeclarations
31204   __Pyx_RefNannySetupContext("__get__", 0);
31205   __Pyx_TraceCall("__get__", __pyx_f[0], 3084);
31206
31207   /* "csamtools.pyx":3085
31208  *     property is_tail:
31209  *         def __get__(self):
31210  *             return self._is_tail             # <<<<<<<<<<<<<<
31211  *     property level:
31212  *         def __get__(self):
31213  */
31214   __Pyx_XDECREF(__pyx_r);
31215   __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 = 3085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31216   __Pyx_GOTREF(__pyx_t_1);
31217   __pyx_r = __pyx_t_1;
31218   __pyx_t_1 = 0;
31219   goto __pyx_L0;
31220
31221   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31222   goto __pyx_L0;
31223   __pyx_L1_error:;
31224   __Pyx_XDECREF(__pyx_t_1);
31225   __Pyx_AddTraceback("csamtools.PileupRead.is_tail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31226   __pyx_r = NULL;
31227   __pyx_L0:;
31228   __Pyx_XGIVEREF(__pyx_r);
31229   __Pyx_TraceReturn(__pyx_r);
31230   __Pyx_RefNannyFinishContext();
31231   return __pyx_r;
31232 }
31233
31234 /* Python wrapper */
31235 static PyObject *__pyx_pw_9csamtools_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/
31236 static PyObject *__pyx_pw_9csamtools_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) {
31237   PyObject *__pyx_r = 0;
31238   __Pyx_RefNannyDeclarations
31239   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
31240   __pyx_r = __pyx_pf_9csamtools_10PileupRead_5level___get__(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self));
31241   __Pyx_RefNannyFinishContext();
31242   return __pyx_r;
31243 }
31244
31245 /* "csamtools.pyx":3087
31246  *             return self._is_tail
31247  *     property level:
31248  *         def __get__(self):             # <<<<<<<<<<<<<<
31249  *             return self._level
31250  * 
31251  */
31252
31253 static PyObject *__pyx_pf_9csamtools_10PileupRead_5level___get__(struct __pyx_obj_9csamtools_PileupRead *__pyx_v_self) {
31254   PyObject *__pyx_r = NULL;
31255   __Pyx_RefNannyDeclarations
31256   PyObject *__pyx_t_1 = NULL;
31257   int __pyx_lineno = 0;
31258   const char *__pyx_filename = NULL;
31259   int __pyx_clineno = 0;
31260   __Pyx_TraceDeclarations
31261   __Pyx_RefNannySetupContext("__get__", 0);
31262   __Pyx_TraceCall("__get__", __pyx_f[0], 3087);
31263
31264   /* "csamtools.pyx":3088
31265  *     property level:
31266  *         def __get__(self):
31267  *             return self._level             # <<<<<<<<<<<<<<
31268  * 
31269  * class Outs:
31270  */
31271   __Pyx_XDECREF(__pyx_r);
31272   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31273   __Pyx_GOTREF(__pyx_t_1);
31274   __pyx_r = __pyx_t_1;
31275   __pyx_t_1 = 0;
31276   goto __pyx_L0;
31277
31278   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31279   goto __pyx_L0;
31280   __pyx_L1_error:;
31281   __Pyx_XDECREF(__pyx_t_1);
31282   __Pyx_AddTraceback("csamtools.PileupRead.level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31283   __pyx_r = NULL;
31284   __pyx_L0:;
31285   __Pyx_XGIVEREF(__pyx_r);
31286   __Pyx_TraceReturn(__pyx_r);
31287   __Pyx_RefNannyFinishContext();
31288   return __pyx_r;
31289 }
31290
31291 /* Python wrapper */
31292 static PyObject *__pyx_pw_9csamtools_4Outs_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
31293 static char __pyx_doc_9csamtools_4Outs___init__[] = "Outs.__init__(self, id=1)";
31294 static PyMethodDef __pyx_mdef_9csamtools_4Outs_1__init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pw_9csamtools_4Outs_1__init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs___init__)};
31295 static PyObject *__pyx_pw_9csamtools_4Outs_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
31296   PyObject *__pyx_v_self = 0;
31297   PyObject *__pyx_v_id = 0;
31298   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__id,0};
31299   PyObject *__pyx_r = 0;
31300   __Pyx_RefNannyDeclarations
31301   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
31302   __pyx_self = __pyx_self;
31303   {
31304     PyObject* values[2] = {0,0};
31305     values[1] = ((PyObject *)((PyObject *)__pyx_int_1));
31306     if (unlikely(__pyx_kwds)) {
31307       Py_ssize_t kw_args;
31308       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
31309       switch (pos_args) {
31310         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31311         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31312         case  0: break;
31313         default: goto __pyx_L5_argtuple_error;
31314       }
31315       kw_args = PyDict_Size(__pyx_kwds);
31316       switch (pos_args) {
31317         case  0:
31318         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
31319         if (likely(values[0])) kw_args--;
31320         else goto __pyx_L5_argtuple_error;
31321         case  1:
31322         if (kw_args > 0) {
31323           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__id);
31324           if (value) { values[1] = value; kw_args--; }
31325         }
31326       }
31327       if (unlikely(kw_args > 0)) {
31328         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31329       }
31330     } else {
31331       switch (PyTuple_GET_SIZE(__pyx_args)) {
31332         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31333         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31334         break;
31335         default: goto __pyx_L5_argtuple_error;
31336       }
31337     }
31338     __pyx_v_self = values[0];
31339     __pyx_v_id = values[1];
31340   }
31341   goto __pyx_L4_argument_unpacking_done;
31342   __pyx_L5_argtuple_error:;
31343   __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31344   __pyx_L3_error:;
31345   __Pyx_AddTraceback("csamtools.Outs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31346   __Pyx_RefNannyFinishContext();
31347   return NULL;
31348   __pyx_L4_argument_unpacking_done:;
31349   __pyx_r = __pyx_pf_9csamtools_4Outs___init__(__pyx_self, __pyx_v_self, __pyx_v_id);
31350   __Pyx_RefNannyFinishContext();
31351   return __pyx_r;
31352 }
31353
31354 /* "csamtools.pyx":3092
31355  * class Outs:
31356  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
31357  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
31358  *         self.streams = []
31359  *         self.id = id
31360  */
31361
31362 static PyObject *__pyx_pf_9csamtools_4Outs___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_id) {
31363   PyObject *__pyx_r = NULL;
31364   __Pyx_RefNannyDeclarations
31365   PyObject *__pyx_t_1 = NULL;
31366   int __pyx_lineno = 0;
31367   const char *__pyx_filename = NULL;
31368   int __pyx_clineno = 0;
31369   __Pyx_TraceDeclarations
31370   __Pyx_RefNannySetupContext("__init__", 0);
31371   __Pyx_TraceCall("__init__", __pyx_f[0], 3092);
31372
31373   /* "csamtools.pyx":3093
31374  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
31375  *     def __init__(self, id = 1):
31376  *         self.streams = []             # <<<<<<<<<<<<<<
31377  *         self.id = id
31378  * 
31379  */
31380   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31381   __Pyx_GOTREF(__pyx_t_1);
31382   if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__streams, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31383   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
31384
31385   /* "csamtools.pyx":3094
31386  *     def __init__(self, id = 1):
31387  *         self.streams = []
31388  *         self.id = id             # <<<<<<<<<<<<<<
31389  * 
31390  *     def setdevice(self, filename):
31391  */
31392   if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__id, __pyx_v_id) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31393
31394   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31395   goto __pyx_L0;
31396   __pyx_L1_error:;
31397   __Pyx_XDECREF(__pyx_t_1);
31398   __Pyx_AddTraceback("csamtools.Outs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
31399   __pyx_r = NULL;
31400   __pyx_L0:;
31401   __Pyx_XGIVEREF(__pyx_r);
31402   __Pyx_TraceReturn(__pyx_r);
31403   __Pyx_RefNannyFinishContext();
31404   return __pyx_r;
31405 }
31406
31407 /* Python wrapper */
31408 static PyObject *__pyx_pw_9csamtools_4Outs_3setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
31409 static char __pyx_doc_9csamtools_4Outs_2setdevice[] = "Outs.setdevice(self, filename)\nopen an existing file, like \"/dev/null\"";
31410 static PyMethodDef __pyx_mdef_9csamtools_4Outs_3setdevice = {__Pyx_NAMESTR("setdevice"), (PyCFunction)__pyx_pw_9csamtools_4Outs_3setdevice, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_2setdevice)};
31411 static PyObject *__pyx_pw_9csamtools_4Outs_3setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
31412   PyObject *__pyx_v_self = 0;
31413   PyObject *__pyx_v_filename = 0;
31414   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
31415   PyObject *__pyx_r = 0;
31416   __Pyx_RefNannyDeclarations
31417   __Pyx_RefNannySetupContext("setdevice (wrapper)", 0);
31418   __pyx_self = __pyx_self;
31419   {
31420     PyObject* values[2] = {0,0};
31421     if (unlikely(__pyx_kwds)) {
31422       Py_ssize_t kw_args;
31423       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
31424       switch (pos_args) {
31425         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31426         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31427         case  0: break;
31428         default: goto __pyx_L5_argtuple_error;
31429       }
31430       kw_args = PyDict_Size(__pyx_kwds);
31431       switch (pos_args) {
31432         case  0:
31433         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
31434         if (likely(values[0])) kw_args--;
31435         else goto __pyx_L5_argtuple_error;
31436         case  1:
31437         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
31438         if (likely(values[1])) kw_args--;
31439         else {
31440           __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31441         }
31442       }
31443       if (unlikely(kw_args > 0)) {
31444         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setdevice") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31445       }
31446     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
31447       goto __pyx_L5_argtuple_error;
31448     } else {
31449       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31450       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31451     }
31452     __pyx_v_self = values[0];
31453     __pyx_v_filename = values[1];
31454   }
31455   goto __pyx_L4_argument_unpacking_done;
31456   __pyx_L5_argtuple_error:;
31457   __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31458   __pyx_L3_error:;
31459   __Pyx_AddTraceback("csamtools.Outs.setdevice", __pyx_clineno, __pyx_lineno, __pyx_filename);
31460   __Pyx_RefNannyFinishContext();
31461   return NULL;
31462   __pyx_L4_argument_unpacking_done:;
31463   __pyx_r = __pyx_pf_9csamtools_4Outs_2setdevice(__pyx_self, __pyx_v_self, __pyx_v_filename);
31464   __Pyx_RefNannyFinishContext();
31465   return __pyx_r;
31466 }
31467
31468 /* "csamtools.pyx":3096
31469  *         self.id = id
31470  * 
31471  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
31472  *         '''open an existing file, like "/dev/null"'''
31473  *         fd = os.open(filename, os.O_WRONLY)
31474  */
31475
31476 static PyObject *__pyx_pf_9csamtools_4Outs_2setdevice(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
31477   PyObject *__pyx_v_fd = NULL;
31478   PyObject *__pyx_r = NULL;
31479   __Pyx_RefNannyDeclarations
31480   PyObject *__pyx_t_1 = NULL;
31481   PyObject *__pyx_t_2 = NULL;
31482   PyObject *__pyx_t_3 = NULL;
31483   int __pyx_lineno = 0;
31484   const char *__pyx_filename = NULL;
31485   int __pyx_clineno = 0;
31486   __Pyx_TraceDeclarations
31487   __Pyx_RefNannySetupContext("setdevice", 0);
31488   __Pyx_TraceCall("setdevice", __pyx_f[0], 3096);
31489
31490   /* "csamtools.pyx":3098
31491  *     def setdevice(self, filename):
31492  *         '''open an existing file, like "/dev/null"'''
31493  *         fd = os.open(filename, os.O_WRONLY)             # <<<<<<<<<<<<<<
31494  *         self.setfd(fd)
31495  * 
31496  */
31497   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31498   __Pyx_GOTREF(__pyx_t_1);
31499   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31500   __Pyx_GOTREF(__pyx_t_2);
31501   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31502   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31503   __Pyx_GOTREF(__pyx_t_1);
31504   __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 = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31505   __Pyx_GOTREF(__pyx_t_3);
31506   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31507   __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31508   __Pyx_GOTREF(__pyx_t_1);
31509   __Pyx_INCREF(__pyx_v_filename);
31510   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
31511   __Pyx_GIVEREF(__pyx_v_filename);
31512   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
31513   __Pyx_GIVEREF(__pyx_t_3);
31514   __pyx_t_3 = 0;
31515   __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 = 3098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31516   __Pyx_GOTREF(__pyx_t_3);
31517   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31518   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
31519   __pyx_v_fd = __pyx_t_3;
31520   __pyx_t_3 = 0;
31521
31522   /* "csamtools.pyx":3099
31523  *         '''open an existing file, like "/dev/null"'''
31524  *         fd = os.open(filename, os.O_WRONLY)
31525  *         self.setfd(fd)             # <<<<<<<<<<<<<<
31526  * 
31527  *     def setfile(self, filename):
31528  */
31529   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31530   __Pyx_GOTREF(__pyx_t_3);
31531   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31532   __Pyx_GOTREF(__pyx_t_1);
31533   __Pyx_INCREF(__pyx_v_fd);
31534   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fd);
31535   __Pyx_GIVEREF(__pyx_v_fd);
31536   __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 = 3099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31537   __Pyx_GOTREF(__pyx_t_2);
31538   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31539   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
31540   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31541
31542   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31543   goto __pyx_L0;
31544   __pyx_L1_error:;
31545   __Pyx_XDECREF(__pyx_t_1);
31546   __Pyx_XDECREF(__pyx_t_2);
31547   __Pyx_XDECREF(__pyx_t_3);
31548   __Pyx_AddTraceback("csamtools.Outs.setdevice", __pyx_clineno, __pyx_lineno, __pyx_filename);
31549   __pyx_r = NULL;
31550   __pyx_L0:;
31551   __Pyx_XDECREF(__pyx_v_fd);
31552   __Pyx_XGIVEREF(__pyx_r);
31553   __Pyx_TraceReturn(__pyx_r);
31554   __Pyx_RefNannyFinishContext();
31555   return __pyx_r;
31556 }
31557
31558 /* Python wrapper */
31559 static PyObject *__pyx_pw_9csamtools_4Outs_5setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
31560 static char __pyx_doc_9csamtools_4Outs_4setfile[] = "Outs.setfile(self, filename)\nopen a new file.";
31561 static PyMethodDef __pyx_mdef_9csamtools_4Outs_5setfile = {__Pyx_NAMESTR("setfile"), (PyCFunction)__pyx_pw_9csamtools_4Outs_5setfile, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_4setfile)};
31562 static PyObject *__pyx_pw_9csamtools_4Outs_5setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
31563   PyObject *__pyx_v_self = 0;
31564   PyObject *__pyx_v_filename = 0;
31565   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
31566   PyObject *__pyx_r = 0;
31567   __Pyx_RefNannyDeclarations
31568   __Pyx_RefNannySetupContext("setfile (wrapper)", 0);
31569   __pyx_self = __pyx_self;
31570   {
31571     PyObject* values[2] = {0,0};
31572     if (unlikely(__pyx_kwds)) {
31573       Py_ssize_t kw_args;
31574       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
31575       switch (pos_args) {
31576         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31577         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31578         case  0: break;
31579         default: goto __pyx_L5_argtuple_error;
31580       }
31581       kw_args = PyDict_Size(__pyx_kwds);
31582       switch (pos_args) {
31583         case  0:
31584         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
31585         if (likely(values[0])) kw_args--;
31586         else goto __pyx_L5_argtuple_error;
31587         case  1:
31588         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
31589         if (likely(values[1])) kw_args--;
31590         else {
31591           __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31592         }
31593       }
31594       if (unlikely(kw_args > 0)) {
31595         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfile") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31596       }
31597     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
31598       goto __pyx_L5_argtuple_error;
31599     } else {
31600       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31601       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31602     }
31603     __pyx_v_self = values[0];
31604     __pyx_v_filename = values[1];
31605   }
31606   goto __pyx_L4_argument_unpacking_done;
31607   __pyx_L5_argtuple_error:;
31608   __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31609   __pyx_L3_error:;
31610   __Pyx_AddTraceback("csamtools.Outs.setfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
31611   __Pyx_RefNannyFinishContext();
31612   return NULL;
31613   __pyx_L4_argument_unpacking_done:;
31614   __pyx_r = __pyx_pf_9csamtools_4Outs_4setfile(__pyx_self, __pyx_v_self, __pyx_v_filename);
31615   __Pyx_RefNannyFinishContext();
31616   return __pyx_r;
31617 }
31618
31619 /* "csamtools.pyx":3101
31620  *         self.setfd(fd)
31621  * 
31622  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
31623  *         '''open a new file.'''
31624  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
31625  */
31626
31627 static PyObject *__pyx_pf_9csamtools_4Outs_4setfile(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
31628   PyObject *__pyx_v_fd = NULL;
31629   PyObject *__pyx_r = NULL;
31630   __Pyx_RefNannyDeclarations
31631   PyObject *__pyx_t_1 = NULL;
31632   PyObject *__pyx_t_2 = NULL;
31633   PyObject *__pyx_t_3 = NULL;
31634   PyObject *__pyx_t_4 = NULL;
31635   int __pyx_lineno = 0;
31636   const char *__pyx_filename = NULL;
31637   int __pyx_clineno = 0;
31638   __Pyx_TraceDeclarations
31639   __Pyx_RefNannySetupContext("setfile", 0);
31640   __Pyx_TraceCall("setfile", __pyx_f[0], 3101);
31641
31642   /* "csamtools.pyx":3103
31643  *     def setfile(self, filename):
31644  *         '''open a new file.'''
31645  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);             # <<<<<<<<<<<<<<
31646  *         self.setfd(fd)
31647  * 
31648  */
31649   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31650   __Pyx_GOTREF(__pyx_t_1);
31651   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31652   __Pyx_GOTREF(__pyx_t_2);
31653   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31654   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31655   __Pyx_GOTREF(__pyx_t_1);
31656   __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 = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31657   __Pyx_GOTREF(__pyx_t_3);
31658   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31659   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31660   __Pyx_GOTREF(__pyx_t_1);
31661   __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 = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31662   __Pyx_GOTREF(__pyx_t_4);
31663   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31664   __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31665   __Pyx_GOTREF(__pyx_t_1);
31666   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31667   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
31668   __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31669   __Pyx_GOTREF(__pyx_t_4);
31670   __Pyx_INCREF(__pyx_v_filename);
31671   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename);
31672   __Pyx_GIVEREF(__pyx_v_filename);
31673   PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
31674   __Pyx_GIVEREF(__pyx_t_1);
31675   __Pyx_INCREF(__pyx_int_0660);
31676   PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0660);
31677   __Pyx_GIVEREF(__pyx_int_0660);
31678   __pyx_t_1 = 0;
31679   __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 = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31680   __Pyx_GOTREF(__pyx_t_1);
31681   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31682   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
31683   __pyx_v_fd = __pyx_t_1;
31684   __pyx_t_1 = 0;
31685
31686   /* "csamtools.pyx":3104
31687  *         '''open a new file.'''
31688  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
31689  *         self.setfd(fd)             # <<<<<<<<<<<<<<
31690  * 
31691  *     def setfd(self, fd):
31692  */
31693   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31694   __Pyx_GOTREF(__pyx_t_1);
31695   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31696   __Pyx_GOTREF(__pyx_t_4);
31697   __Pyx_INCREF(__pyx_v_fd);
31698   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fd);
31699   __Pyx_GIVEREF(__pyx_v_fd);
31700   __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 = 3104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31701   __Pyx_GOTREF(__pyx_t_2);
31702   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31703   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
31704   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31705
31706   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31707   goto __pyx_L0;
31708   __pyx_L1_error:;
31709   __Pyx_XDECREF(__pyx_t_1);
31710   __Pyx_XDECREF(__pyx_t_2);
31711   __Pyx_XDECREF(__pyx_t_3);
31712   __Pyx_XDECREF(__pyx_t_4);
31713   __Pyx_AddTraceback("csamtools.Outs.setfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
31714   __pyx_r = NULL;
31715   __pyx_L0:;
31716   __Pyx_XDECREF(__pyx_v_fd);
31717   __Pyx_XGIVEREF(__pyx_r);
31718   __Pyx_TraceReturn(__pyx_r);
31719   __Pyx_RefNannyFinishContext();
31720   return __pyx_r;
31721 }
31722
31723 /* Python wrapper */
31724 static PyObject *__pyx_pw_9csamtools_4Outs_7setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
31725 static char __pyx_doc_9csamtools_4Outs_6setfd[] = "Outs.setfd(self, fd)";
31726 static PyMethodDef __pyx_mdef_9csamtools_4Outs_7setfd = {__Pyx_NAMESTR("setfd"), (PyCFunction)__pyx_pw_9csamtools_4Outs_7setfd, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_6setfd)};
31727 static PyObject *__pyx_pw_9csamtools_4Outs_7setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
31728   PyObject *__pyx_v_self = 0;
31729   PyObject *__pyx_v_fd = 0;
31730   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__fd,0};
31731   PyObject *__pyx_r = 0;
31732   __Pyx_RefNannyDeclarations
31733   __Pyx_RefNannySetupContext("setfd (wrapper)", 0);
31734   __pyx_self = __pyx_self;
31735   {
31736     PyObject* values[2] = {0,0};
31737     if (unlikely(__pyx_kwds)) {
31738       Py_ssize_t kw_args;
31739       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
31740       switch (pos_args) {
31741         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31742         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31743         case  0: break;
31744         default: goto __pyx_L5_argtuple_error;
31745       }
31746       kw_args = PyDict_Size(__pyx_kwds);
31747       switch (pos_args) {
31748         case  0:
31749         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
31750         if (likely(values[0])) kw_args--;
31751         else goto __pyx_L5_argtuple_error;
31752         case  1:
31753         values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fd);
31754         if (likely(values[1])) kw_args--;
31755         else {
31756           __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31757         }
31758       }
31759       if (unlikely(kw_args > 0)) {
31760         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setfd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31761       }
31762     } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
31763       goto __pyx_L5_argtuple_error;
31764     } else {
31765       values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
31766       values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
31767     }
31768     __pyx_v_self = values[0];
31769     __pyx_v_fd = values[1];
31770   }
31771   goto __pyx_L4_argument_unpacking_done;
31772   __pyx_L5_argtuple_error:;
31773   __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
31774   __pyx_L3_error:;
31775   __Pyx_AddTraceback("csamtools.Outs.setfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
31776   __Pyx_RefNannyFinishContext();
31777   return NULL;
31778   __pyx_L4_argument_unpacking_done:;
31779   __pyx_r = __pyx_pf_9csamtools_4Outs_6setfd(__pyx_self, __pyx_v_self, __pyx_v_fd);
31780   __Pyx_RefNannyFinishContext();
31781   return __pyx_r;
31782 }
31783
31784 /* "csamtools.pyx":3106
31785  *         self.setfd(fd)
31786  * 
31787  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
31788  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
31789  *         self.streams.append(ofd)
31790  */
31791
31792 static PyObject *__pyx_pf_9csamtools_4Outs_6setfd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_fd) {
31793   PyObject *__pyx_v_ofd = NULL;
31794   PyObject *__pyx_r = NULL;
31795   __Pyx_RefNannyDeclarations
31796   PyObject *__pyx_t_1 = NULL;
31797   PyObject *__pyx_t_2 = NULL;
31798   PyObject *__pyx_t_3 = NULL;
31799   int __pyx_lineno = 0;
31800   const char *__pyx_filename = NULL;
31801   int __pyx_clineno = 0;
31802   __Pyx_TraceDeclarations
31803   __Pyx_RefNannySetupContext("setfd", 0);
31804   __Pyx_TraceCall("setfd", __pyx_f[0], 3106);
31805
31806   /* "csamtools.pyx":3107
31807  * 
31808  *     def setfd(self, fd):
31809  *         ofd = os.dup(self.id)      #  Save old stream on new unit.             # <<<<<<<<<<<<<<
31810  *         self.streams.append(ofd)
31811  *         sys.stdout.flush()          #  Buffered data goes to old stream.
31812  */
31813   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31814   __Pyx_GOTREF(__pyx_t_1);
31815   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31816   __Pyx_GOTREF(__pyx_t_2);
31817   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31818   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31819   __Pyx_GOTREF(__pyx_t_1);
31820   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31821   __Pyx_GOTREF(__pyx_t_3);
31822   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
31823   __Pyx_GIVEREF(__pyx_t_1);
31824   __pyx_t_1 = 0;
31825   __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 = 3107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31826   __Pyx_GOTREF(__pyx_t_1);
31827   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31828   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
31829   __pyx_v_ofd = __pyx_t_1;
31830   __pyx_t_1 = 0;
31831
31832   /* "csamtools.pyx":3108
31833  *     def setfd(self, fd):
31834  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
31835  *         self.streams.append(ofd)             # <<<<<<<<<<<<<<
31836  *         sys.stdout.flush()          #  Buffered data goes to old stream.
31837  *         sys.stderr.flush()          #  Buffered data goes to old stream.
31838  */
31839   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31840   __Pyx_GOTREF(__pyx_t_1);
31841   __pyx_t_3 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_ofd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31842   __Pyx_GOTREF(__pyx_t_3);
31843   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31844   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31845
31846   /* "csamtools.pyx":3109
31847  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
31848  *         self.streams.append(ofd)
31849  *         sys.stdout.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
31850  *         sys.stderr.flush()          #  Buffered data goes to old stream.
31851  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
31852  */
31853   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31854   __Pyx_GOTREF(__pyx_t_3);
31855   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31856   __Pyx_GOTREF(__pyx_t_1);
31857   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31858   __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31859   __Pyx_GOTREF(__pyx_t_3);
31860   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31861   __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 = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31862   __Pyx_GOTREF(__pyx_t_1);
31863   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31864   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31865
31866   /* "csamtools.pyx":3110
31867  *         self.streams.append(ofd)
31868  *         sys.stdout.flush()          #  Buffered data goes to old stream.
31869  *         sys.stderr.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
31870  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
31871  *         os.close(fd)                #  Close other unit (look out, caller.)
31872  */
31873   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31874   __Pyx_GOTREF(__pyx_t_1);
31875   __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31876   __Pyx_GOTREF(__pyx_t_3);
31877   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31878   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31879   __Pyx_GOTREF(__pyx_t_1);
31880   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31881   __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 = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31882   __Pyx_GOTREF(__pyx_t_3);
31883   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31884   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31885
31886   /* "csamtools.pyx":3111
31887  *         sys.stdout.flush()          #  Buffered data goes to old stream.
31888  *         sys.stderr.flush()          #  Buffered data goes to old stream.
31889  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.             # <<<<<<<<<<<<<<
31890  *         os.close(fd)                #  Close other unit (look out, caller.)
31891  * 
31892  */
31893   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31894   __Pyx_GOTREF(__pyx_t_3);
31895   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__dup2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31896   __Pyx_GOTREF(__pyx_t_1);
31897   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31898   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31899   __Pyx_GOTREF(__pyx_t_3);
31900   __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31901   __Pyx_GOTREF(__pyx_t_2);
31902   __Pyx_INCREF(__pyx_v_fd);
31903   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fd);
31904   __Pyx_GIVEREF(__pyx_v_fd);
31905   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
31906   __Pyx_GIVEREF(__pyx_t_3);
31907   __pyx_t_3 = 0;
31908   __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 = 3111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31909   __Pyx_GOTREF(__pyx_t_3);
31910   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31911   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
31912   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31913
31914   /* "csamtools.pyx":3112
31915  *         sys.stderr.flush()          #  Buffered data goes to old stream.
31916  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
31917  *         os.close(fd)                #  Close other unit (look out, caller.)             # <<<<<<<<<<<<<<
31918  * 
31919  *     def restore(self):
31920  */
31921   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31922   __Pyx_GOTREF(__pyx_t_3);
31923   __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31924   __Pyx_GOTREF(__pyx_t_2);
31925   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
31926   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31927   __Pyx_GOTREF(__pyx_t_3);
31928   __Pyx_INCREF(__pyx_v_fd);
31929   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fd);
31930   __Pyx_GIVEREF(__pyx_v_fd);
31931   __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 = 3112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31932   __Pyx_GOTREF(__pyx_t_1);
31933   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
31934   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
31935   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
31936
31937   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
31938   goto __pyx_L0;
31939   __pyx_L1_error:;
31940   __Pyx_XDECREF(__pyx_t_1);
31941   __Pyx_XDECREF(__pyx_t_2);
31942   __Pyx_XDECREF(__pyx_t_3);
31943   __Pyx_AddTraceback("csamtools.Outs.setfd", __pyx_clineno, __pyx_lineno, __pyx_filename);
31944   __pyx_r = NULL;
31945   __pyx_L0:;
31946   __Pyx_XDECREF(__pyx_v_ofd);
31947   __Pyx_XGIVEREF(__pyx_r);
31948   __Pyx_TraceReturn(__pyx_r);
31949   __Pyx_RefNannyFinishContext();
31950   return __pyx_r;
31951 }
31952
31953 /* Python wrapper */
31954 static PyObject *__pyx_pw_9csamtools_4Outs_9restore(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
31955 static char __pyx_doc_9csamtools_4Outs_8restore[] = "Outs.restore(self)\nrestore previous output stream";
31956 static PyMethodDef __pyx_mdef_9csamtools_4Outs_9restore = {__Pyx_NAMESTR("restore"), (PyCFunction)__pyx_pw_9csamtools_4Outs_9restore, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_8restore)};
31957 static PyObject *__pyx_pw_9csamtools_4Outs_9restore(PyObject *__pyx_self, PyObject *__pyx_v_self) {
31958   PyObject *__pyx_r = 0;
31959   __Pyx_RefNannyDeclarations
31960   __Pyx_RefNannySetupContext("restore (wrapper)", 0);
31961   __pyx_self = __pyx_self;
31962   __pyx_r = __pyx_pf_9csamtools_4Outs_8restore(__pyx_self, ((PyObject *)__pyx_v_self));
31963   __Pyx_RefNannyFinishContext();
31964   return __pyx_r;
31965 }
31966
31967 /* "csamtools.pyx":3114
31968  *         os.close(fd)                #  Close other unit (look out, caller.)
31969  * 
31970  *     def restore(self):             # <<<<<<<<<<<<<<
31971  *         '''restore previous output stream'''
31972  *         if self.streams:
31973  */
31974
31975 static PyObject *__pyx_pf_9csamtools_4Outs_8restore(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
31976   PyObject *__pyx_r = NULL;
31977   __Pyx_RefNannyDeclarations
31978   PyObject *__pyx_t_1 = NULL;
31979   int __pyx_t_2;
31980   PyObject *__pyx_t_3 = NULL;
31981   PyObject *__pyx_t_4 = NULL;
31982   PyObject *__pyx_t_5 = NULL;
31983   int __pyx_lineno = 0;
31984   const char *__pyx_filename = NULL;
31985   int __pyx_clineno = 0;
31986   __Pyx_TraceDeclarations
31987   __Pyx_RefNannySetupContext("restore", 0);
31988   __Pyx_TraceCall("restore", __pyx_f[0], 3114);
31989
31990   /* "csamtools.pyx":3116
31991  *     def restore(self):
31992  *         '''restore previous output stream'''
31993  *         if self.streams:             # <<<<<<<<<<<<<<
31994  *             # the following was not sufficient, hence flush both stderr and stdout
31995  *             # os.fsync( self.id )
31996  */
31997   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31998   __Pyx_GOTREF(__pyx_t_1);
31999   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32000   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32001   if (__pyx_t_2) {
32002
32003     /* "csamtools.pyx":3119
32004  *             # the following was not sufficient, hence flush both stderr and stdout
32005  *             # os.fsync( self.id )
32006  *             sys.stdout.flush()             # <<<<<<<<<<<<<<
32007  *             sys.stderr.flush()
32008  *             os.dup2(self.streams[-1], self.id)
32009  */
32010     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32011     __Pyx_GOTREF(__pyx_t_1);
32012     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32013     __Pyx_GOTREF(__pyx_t_3);
32014     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32015     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32016     __Pyx_GOTREF(__pyx_t_1);
32017     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32018     __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 = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32019     __Pyx_GOTREF(__pyx_t_3);
32020     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32021     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32022
32023     /* "csamtools.pyx":3120
32024  *             # os.fsync( self.id )
32025  *             sys.stdout.flush()
32026  *             sys.stderr.flush()             # <<<<<<<<<<<<<<
32027  *             os.dup2(self.streams[-1], self.id)
32028  *             os.close(self.streams[-1])
32029  */
32030     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32031     __Pyx_GOTREF(__pyx_t_3);
32032     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32033     __Pyx_GOTREF(__pyx_t_1);
32034     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32035     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32036     __Pyx_GOTREF(__pyx_t_3);
32037     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32038     __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 = 3120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32039     __Pyx_GOTREF(__pyx_t_1);
32040     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32041     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32042
32043     /* "csamtools.pyx":3121
32044  *             sys.stdout.flush()
32045  *             sys.stderr.flush()
32046  *             os.dup2(self.streams[-1], self.id)             # <<<<<<<<<<<<<<
32047  *             os.close(self.streams[-1])
32048  *             del self.streams[-1]
32049  */
32050     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32051     __Pyx_GOTREF(__pyx_t_1);
32052     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32053     __Pyx_GOTREF(__pyx_t_3);
32054     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32055     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32056     __Pyx_GOTREF(__pyx_t_1);
32057     __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32058     __Pyx_GOTREF(__pyx_t_4);
32059     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32060     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32061     __Pyx_GOTREF(__pyx_t_1);
32062     __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32063     __Pyx_GOTREF(__pyx_t_5);
32064     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
32065     __Pyx_GIVEREF(__pyx_t_4);
32066     PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
32067     __Pyx_GIVEREF(__pyx_t_1);
32068     __pyx_t_4 = 0;
32069     __pyx_t_1 = 0;
32070     __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 = 3121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32071     __Pyx_GOTREF(__pyx_t_1);
32072     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32073     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
32074     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32075
32076     /* "csamtools.pyx":3122
32077  *             sys.stderr.flush()
32078  *             os.dup2(self.streams[-1], self.id)
32079  *             os.close(self.streams[-1])             # <<<<<<<<<<<<<<
32080  *             del self.streams[-1]
32081  * 
32082  */
32083     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32084     __Pyx_GOTREF(__pyx_t_1);
32085     __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32086     __Pyx_GOTREF(__pyx_t_5);
32087     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32088     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32089     __Pyx_GOTREF(__pyx_t_1);
32090     __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32091     __Pyx_GOTREF(__pyx_t_3);
32092     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32093     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32094     __Pyx_GOTREF(__pyx_t_1);
32095     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
32096     __Pyx_GIVEREF(__pyx_t_3);
32097     __pyx_t_3 = 0;
32098     __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 = 3122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32099     __Pyx_GOTREF(__pyx_t_3);
32100     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
32101     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
32102     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32103
32104     /* "csamtools.pyx":3123
32105  *             os.dup2(self.streams[-1], self.id)
32106  *             os.close(self.streams[-1])
32107  *             del self.streams[-1]             # <<<<<<<<<<<<<<
32108  * 
32109  * def _samtools_dispatch( method,
32110  */
32111     __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32112     __Pyx_GOTREF(__pyx_t_3);
32113     if (__Pyx_DelItemInt(__pyx_t_3, -1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32114     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32115     goto __pyx_L3;
32116   }
32117   __pyx_L3:;
32118
32119   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
32120   goto __pyx_L0;
32121   __pyx_L1_error:;
32122   __Pyx_XDECREF(__pyx_t_1);
32123   __Pyx_XDECREF(__pyx_t_3);
32124   __Pyx_XDECREF(__pyx_t_4);
32125   __Pyx_XDECREF(__pyx_t_5);
32126   __Pyx_AddTraceback("csamtools.Outs.restore", __pyx_clineno, __pyx_lineno, __pyx_filename);
32127   __pyx_r = NULL;
32128   __pyx_L0:;
32129   __Pyx_XGIVEREF(__pyx_r);
32130   __Pyx_TraceReturn(__pyx_r);
32131   __Pyx_RefNannyFinishContext();
32132   return __pyx_r;
32133 }
32134
32135 /* Python wrapper */
32136 static PyObject *__pyx_pw_9csamtools_1_samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
32137 static char __pyx_doc_9csamtools__samtools_dispatch[] = "_samtools_dispatch(method, args=(), catch_stdout=True)\ncall ``method`` in samtools providing arguments in args.\n    \n    .. note:: \n       This method redirects stdout to capture it \n       from samtools. If for some reason stdout disappears\n       the reason might be in this method.\n\n    .. note::\n       The current implementation might only work on linux.\n\n    .. note::\n       This method captures stdout and stderr using temporary files,\n       which are then read into memory in their entirety. This method\n       is slow and might cause large memory overhead.\n\n    See http://bytes.com/topic/c/answers/487231-how-capture-stdout-temporarily\n    on the topic of redirecting stderr/stdout.\n    ";
32138 static PyMethodDef __pyx_mdef_9csamtools_1_samtools_dispatch = {__Pyx_NAMESTR("_samtools_dispatch"), (PyCFunction)__pyx_pw_9csamtools_1_samtools_dispatch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools__samtools_dispatch)};
32139 static PyObject *__pyx_pw_9csamtools_1_samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
32140   PyObject *__pyx_v_method = 0;
32141   PyObject *__pyx_v_args = 0;
32142   PyObject *__pyx_v_catch_stdout = 0;
32143   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__method,&__pyx_n_s__args,&__pyx_n_s__catch_stdout,0};
32144   PyObject *__pyx_r = 0;
32145   __Pyx_RefNannyDeclarations
32146   __Pyx_RefNannySetupContext("_samtools_dispatch (wrapper)", 0);
32147   __pyx_self = __pyx_self;
32148   {
32149     PyObject* values[3] = {0,0,0};
32150
32151     /* "csamtools.pyx":3126
32152  * 
32153  * def _samtools_dispatch( method,
32154  *                         args = (),             # <<<<<<<<<<<<<<
32155  *                         catch_stdout = True ):
32156  *     '''call ``method`` in samtools providing arguments in args.
32157  */
32158     values[1] = ((PyObject *)__pyx_empty_tuple);
32159     values[2] = __pyx_k_176;
32160     if (unlikely(__pyx_kwds)) {
32161       Py_ssize_t kw_args;
32162       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
32163       switch (pos_args) {
32164         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
32165         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
32166         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
32167         case  0: break;
32168         default: goto __pyx_L5_argtuple_error;
32169       }
32170       kw_args = PyDict_Size(__pyx_kwds);
32171       switch (pos_args) {
32172         case  0:
32173         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__method);
32174         if (likely(values[0])) kw_args--;
32175         else goto __pyx_L5_argtuple_error;
32176         case  1:
32177         if (kw_args > 0) {
32178           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__args);
32179           if (value) { values[1] = value; kw_args--; }
32180         }
32181         case  2:
32182         if (kw_args > 0) {
32183           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__catch_stdout);
32184           if (value) { values[2] = value; kw_args--; }
32185         }
32186       }
32187       if (unlikely(kw_args > 0)) {
32188         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_samtools_dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
32189       }
32190     } else {
32191       switch (PyTuple_GET_SIZE(__pyx_args)) {
32192         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
32193         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
32194         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
32195         break;
32196         default: goto __pyx_L5_argtuple_error;
32197       }
32198     }
32199     __pyx_v_method = values[0];
32200     __pyx_v_args = values[1];
32201     __pyx_v_catch_stdout = values[2];
32202   }
32203   goto __pyx_L4_argument_unpacking_done;
32204   __pyx_L5_argtuple_error:;
32205   __Pyx_RaiseArgtupleInvalid("_samtools_dispatch", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
32206   __pyx_L3_error:;
32207   __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
32208   __Pyx_RefNannyFinishContext();
32209   return NULL;
32210   __pyx_L4_argument_unpacking_done:;
32211   __pyx_r = __pyx_pf_9csamtools__samtools_dispatch(__pyx_self, __pyx_v_method, __pyx_v_args, __pyx_v_catch_stdout);
32212   __Pyx_RefNannyFinishContext();
32213   return __pyx_r;
32214 }
32215
32216 /* "csamtools.pyx":3125
32217  *             del self.streams[-1]
32218  * 
32219  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
32220  *                         args = (),
32221  *                         catch_stdout = True ):
32222  */
32223
32224 static PyObject *__pyx_pf_9csamtools__samtools_dispatch(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_method, PyObject *__pyx_v_args, PyObject *__pyx_v_catch_stdout) {
32225   PyObject *__pyx_v_stderr_h = NULL;
32226   PyObject *__pyx_v_stderr_f = NULL;
32227   PyObject *__pyx_v_stdout_h = NULL;
32228   PyObject *__pyx_v_stdout_f = NULL;
32229   PyObject *__pyx_v_stdout_save = NULL;
32230   char **__pyx_v_cargs;
32231   int __pyx_v_i;
32232   int __pyx_v_n;
32233   int __pyx_v_retval;
32234   PyObject *__pyx_v_inf = NULL;
32235   PyObject *__pyx_v_out_stdout = NULL;
32236   PyObject *__pyx_v_out_stderr = NULL;
32237   PyObject *__pyx_v_a = NULL;
32238   PyObject *__pyx_r = NULL;
32239   __Pyx_RefNannyDeclarations
32240   int __pyx_t_1;
32241   PyObject *__pyx_t_2 = NULL;
32242   PyObject *__pyx_t_3 = NULL;
32243   PyObject *__pyx_t_4 = NULL;
32244   int __pyx_t_5;
32245   PyObject *__pyx_t_6 = NULL;
32246   PyObject *(*__pyx_t_7)(PyObject *);
32247   int __pyx_t_8;
32248   PyObject *__pyx_t_9 = NULL;
32249   PyObject *__pyx_t_10 = NULL;
32250   PyObject *__pyx_t_11 = NULL;
32251   Py_ssize_t __pyx_t_12;
32252   PyObject *(*__pyx_t_13)(PyObject *);
32253   char *__pyx_t_14;
32254   PyObject *__pyx_t_15 = NULL;
32255   PyObject *__pyx_t_16 = NULL;
32256   PyObject *__pyx_t_17 = NULL;
32257   PyObject *__pyx_t_18 = NULL;
32258   PyObject *__pyx_t_19 = NULL;
32259   PyObject *__pyx_t_20 = NULL;
32260   PyObject *__pyx_t_21 = NULL;
32261   PyObject *__pyx_t_22 = NULL;
32262   int __pyx_lineno = 0;
32263   const char *__pyx_filename = NULL;
32264   int __pyx_clineno = 0;
32265   __Pyx_TraceDeclarations
32266   __Pyx_RefNannySetupContext("_samtools_dispatch", 0);
32267   __Pyx_TraceCall("_samtools_dispatch", __pyx_f[0], 3125);
32268   __Pyx_INCREF(__pyx_v_method);
32269   __Pyx_INCREF(__pyx_v_args);
32270   __Pyx_INCREF(__pyx_v_catch_stdout);
32271
32272   /* "csamtools.pyx":3151
32273  * 
32274  *     # some special cases
32275  *     if method == "index":             # <<<<<<<<<<<<<<
32276  *         if not os.path.exists( args[0] ):
32277  *             raise IOError( "No such file or directory: '%s'" % args[0] )
32278  */
32279   __pyx_t_1 = __Pyx_PyString_Equals(__pyx_v_method, ((PyObject *)__pyx_n_s__index), Py_EQ); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32280   if (__pyx_t_1) {
32281
32282     /* "csamtools.pyx":3152
32283  *     # some special cases
32284  *     if method == "index":
32285  *         if not os.path.exists( args[0] ):             # <<<<<<<<<<<<<<
32286  *             raise IOError( "No such file or directory: '%s'" % args[0] )
32287  * 
32288  */
32289     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32290     __Pyx_GOTREF(__pyx_t_2);
32291     __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32292     __Pyx_GOTREF(__pyx_t_3);
32293     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32294     __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__exists); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32295     __Pyx_GOTREF(__pyx_t_2);
32296     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32297     __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32298     __Pyx_GOTREF(__pyx_t_3);
32299     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32300     __Pyx_GOTREF(__pyx_t_4);
32301     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
32302     __Pyx_GIVEREF(__pyx_t_3);
32303     __pyx_t_3 = 0;
32304     __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32305     __Pyx_GOTREF(__pyx_t_3);
32306     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32307     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
32308     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32309     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32310     __pyx_t_5 = (!__pyx_t_1);
32311     if (__pyx_t_5) {
32312
32313       /* "csamtools.pyx":3153
32314  *     if method == "index":
32315  *         if not os.path.exists( args[0] ):
32316  *             raise IOError( "No such file or directory: '%s'" % args[0] )             # <<<<<<<<<<<<<<
32317  * 
32318  *     # redirect stderr and stdout to file
32319  */
32320       __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32321       __Pyx_GOTREF(__pyx_t_3);
32322       __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_177), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32323       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
32324       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32325       __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32326       __Pyx_GOTREF(__pyx_t_3);
32327       PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
32328       __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
32329       __pyx_t_4 = 0;
32330       __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 = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32331       __Pyx_GOTREF(__pyx_t_4);
32332       __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
32333       __Pyx_Raise(__pyx_t_4, 0, 0, 0);
32334       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32335       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32336       goto __pyx_L4;
32337     }
32338     __pyx_L4:;
32339     goto __pyx_L3;
32340   }
32341   __pyx_L3:;
32342
32343   /* "csamtools.pyx":3156
32344  * 
32345  *     # redirect stderr and stdout to file
32346  *     stderr_h, stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
32347  *     pysam_set_stderr( stderr_h )
32348  * 
32349  */
32350   __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32351   __Pyx_GOTREF(__pyx_t_4);
32352   __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32353   __Pyx_GOTREF(__pyx_t_3);
32354   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32355   __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 = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32356   __Pyx_GOTREF(__pyx_t_4);
32357   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32358   if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
32359     PyObject* sequence = __pyx_t_4;
32360     if (likely(PyTuple_CheckExact(sequence))) {
32361       if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
32362         if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
32363         else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
32364         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32365       }
32366       __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
32367       __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
32368     } else {
32369       if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
32370         if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
32371         else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
32372         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32373       }
32374       __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
32375       __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
32376     }
32377     __Pyx_INCREF(__pyx_t_3);
32378     __Pyx_INCREF(__pyx_t_2);
32379     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32380   } else {
32381     Py_ssize_t index = -1;
32382     __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32383     __Pyx_GOTREF(__pyx_t_6);
32384     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32385     __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
32386     index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed;
32387     __Pyx_GOTREF(__pyx_t_3);
32388     index = 1; __pyx_t_2 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
32389     __Pyx_GOTREF(__pyx_t_2);
32390     if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32391     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
32392     goto __pyx_L6_unpacking_done;
32393     __pyx_L5_unpacking_failed:;
32394     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
32395     if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
32396     if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
32397     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32398     __pyx_L6_unpacking_done:;
32399   }
32400   __pyx_v_stderr_h = __pyx_t_3;
32401   __pyx_t_3 = 0;
32402   __pyx_v_stderr_f = __pyx_t_2;
32403   __pyx_t_2 = 0;
32404
32405   /* "csamtools.pyx":3157
32406  *     # redirect stderr and stdout to file
32407  *     stderr_h, stderr_f = tempfile.mkstemp()
32408  *     pysam_set_stderr( stderr_h )             # <<<<<<<<<<<<<<
32409  * 
32410  *     if catch_stdout:
32411  */
32412   __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 = 3157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32413   pysam_set_stderr(__pyx_t_8);
32414
32415   /* "csamtools.pyx":3159
32416  *     pysam_set_stderr( stderr_h )
32417  * 
32418  *     if catch_stdout:             # <<<<<<<<<<<<<<
32419  *         stdout_h, stdout_f = tempfile.mkstemp()
32420  *         try:
32421  */
32422   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32423   if (__pyx_t_5) {
32424
32425     /* "csamtools.pyx":3160
32426  * 
32427  *     if catch_stdout:
32428  *         stdout_h, stdout_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
32429  *         try:
32430  *             stdout_save = Outs( sys.stdout.fileno() )
32431  */
32432     __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32433     __Pyx_GOTREF(__pyx_t_4);
32434     __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32435     __Pyx_GOTREF(__pyx_t_2);
32436     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32437     __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 = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32438     __Pyx_GOTREF(__pyx_t_4);
32439     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32440     if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
32441       PyObject* sequence = __pyx_t_4;
32442       if (likely(PyTuple_CheckExact(sequence))) {
32443         if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
32444           if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
32445           else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
32446           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32447         }
32448         __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
32449         __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
32450       } else {
32451         if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
32452           if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
32453           else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
32454           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32455         }
32456         __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
32457         __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
32458       }
32459       __Pyx_INCREF(__pyx_t_2);
32460       __Pyx_INCREF(__pyx_t_3);
32461       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32462     } else {
32463       Py_ssize_t index = -1;
32464       __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32465       __Pyx_GOTREF(__pyx_t_6);
32466       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32467       __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext;
32468       index = 0; __pyx_t_2 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L8_unpacking_failed;
32469       __Pyx_GOTREF(__pyx_t_2);
32470       index = 1; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed;
32471       __Pyx_GOTREF(__pyx_t_3);
32472       if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32473       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
32474       goto __pyx_L9_unpacking_done;
32475       __pyx_L8_unpacking_failed:;
32476       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
32477       if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
32478       if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
32479       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32480       __pyx_L9_unpacking_done:;
32481     }
32482     __pyx_v_stdout_h = __pyx_t_2;
32483     __pyx_t_2 = 0;
32484     __pyx_v_stdout_f = __pyx_t_3;
32485     __pyx_t_3 = 0;
32486
32487     /* "csamtools.pyx":3161
32488  *     if catch_stdout:
32489  *         stdout_h, stdout_f = tempfile.mkstemp()
32490  *         try:             # <<<<<<<<<<<<<<
32491  *             stdout_save = Outs( sys.stdout.fileno() )
32492  *             stdout_save.setfd( stdout_h )
32493  */
32494     {
32495       __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
32496       __Pyx_XGOTREF(__pyx_t_9);
32497       __Pyx_XGOTREF(__pyx_t_10);
32498       __Pyx_XGOTREF(__pyx_t_11);
32499       /*try:*/ {
32500
32501         /* "csamtools.pyx":3162
32502  *         stdout_h, stdout_f = tempfile.mkstemp()
32503  *         try:
32504  *             stdout_save = Outs( sys.stdout.fileno() )             # <<<<<<<<<<<<<<
32505  *             stdout_save.setfd( stdout_h )
32506  *         except AttributeError:
32507  */
32508         __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32509         __Pyx_GOTREF(__pyx_t_4);
32510         __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32511         __Pyx_GOTREF(__pyx_t_3);
32512         __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32513         __Pyx_GOTREF(__pyx_t_2);
32514         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32515         __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32516         __Pyx_GOTREF(__pyx_t_3);
32517         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32518         __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32519         __Pyx_GOTREF(__pyx_t_2);
32520         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32521         __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32522         __Pyx_GOTREF(__pyx_t_3);
32523         PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
32524         __Pyx_GIVEREF(__pyx_t_2);
32525         __pyx_t_2 = 0;
32526         __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3162; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32527         __Pyx_GOTREF(__pyx_t_2);
32528         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32529         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
32530         __pyx_v_stdout_save = __pyx_t_2;
32531         __pyx_t_2 = 0;
32532
32533         /* "csamtools.pyx":3163
32534  *         try:
32535  *             stdout_save = Outs( sys.stdout.fileno() )
32536  *             stdout_save.setfd( stdout_h )             # <<<<<<<<<<<<<<
32537  *         except AttributeError:
32538  *             # stdout has already been redirected
32539  */
32540         __pyx_t_2 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3163; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32541         __Pyx_GOTREF(__pyx_t_2);
32542         __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3163; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32543         __Pyx_GOTREF(__pyx_t_3);
32544         __Pyx_INCREF(__pyx_v_stdout_h);
32545         PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_h);
32546         __Pyx_GIVEREF(__pyx_v_stdout_h);
32547         __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 = 3163; __pyx_clineno = __LINE__; goto __pyx_L10_error;}
32548         __Pyx_GOTREF(__pyx_t_4);
32549         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32550         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
32551         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32552       }
32553       __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
32554       __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
32555       __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
32556       goto __pyx_L17_try_end;
32557       __pyx_L10_error:;
32558       __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
32559       __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
32560       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
32561       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
32562
32563       /* "csamtools.pyx":3164
32564  *             stdout_save = Outs( sys.stdout.fileno() )
32565  *             stdout_save.setfd( stdout_h )
32566  *         except AttributeError:             # <<<<<<<<<<<<<<
32567  *             # stdout has already been redirected
32568  *             catch_stdout = False
32569  */
32570       __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
32571       if (__pyx_t_8) {
32572         __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
32573         if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3164; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
32574         __Pyx_GOTREF(__pyx_t_4);
32575         __Pyx_GOTREF(__pyx_t_3);
32576         __Pyx_GOTREF(__pyx_t_2);
32577
32578         /* "csamtools.pyx":3166
32579  *         except AttributeError:
32580  *             # stdout has already been redirected
32581  *             catch_stdout = False             # <<<<<<<<<<<<<<
32582  * 
32583  *         # patch for `samtools view`
32584  */
32585         __pyx_t_6 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3166; __pyx_clineno = __LINE__; goto __pyx_L12_except_error;}
32586         __Pyx_GOTREF(__pyx_t_6);
32587         __Pyx_DECREF(__pyx_v_catch_stdout);
32588         __pyx_v_catch_stdout = __pyx_t_6;
32589         __pyx_t_6 = 0;
32590         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32591         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32592         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32593         goto __pyx_L11_exception_handled;
32594       }
32595       __pyx_L12_except_error:;
32596       __Pyx_XGIVEREF(__pyx_t_9);
32597       __Pyx_XGIVEREF(__pyx_t_10);
32598       __Pyx_XGIVEREF(__pyx_t_11);
32599       __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
32600       goto __pyx_L1_error;
32601       __pyx_L11_exception_handled:;
32602       __Pyx_XGIVEREF(__pyx_t_9);
32603       __Pyx_XGIVEREF(__pyx_t_10);
32604       __Pyx_XGIVEREF(__pyx_t_11);
32605       __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
32606       __pyx_L17_try_end:;
32607     }
32608
32609     /* "csamtools.pyx":3171
32610  *         # samtools `view` closes stdout, from which I can not
32611  *         # recover. Thus redirect output to file with -o option.
32612  *         if method == "view":             # <<<<<<<<<<<<<<
32613  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
32614  *             args = ( "-o", stdout_f ) + args
32615  */
32616     __pyx_t_5 = __Pyx_PyString_Equals(__pyx_v_method, ((PyObject *)__pyx_n_s__view), Py_EQ); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32617     if (__pyx_t_5) {
32618
32619       /* "csamtools.pyx":3172
32620  *         # recover. Thus redirect output to file with -o option.
32621  *         if method == "view":
32622  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
32623  *             args = ( "-o", stdout_f ) + args
32624  * 
32625  */
32626       __pyx_t_5 = ((PySequence_Contains(__pyx_v_args, ((PyObject *)__pyx_kp_s_178)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32627       if (__pyx_t_5) {
32628         __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_180), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32629         __Pyx_GOTREF(__pyx_t_2);
32630         __Pyx_Raise(__pyx_t_2, 0, 0, 0);
32631         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32632         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32633         goto __pyx_L21;
32634       }
32635       __pyx_L21:;
32636
32637       /* "csamtools.pyx":3173
32638  *         if method == "view":
32639  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
32640  *             args = ( "-o", stdout_f ) + args             # <<<<<<<<<<<<<<
32641  * 
32642  *     # do the function call to samtools
32643  */
32644       __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32645       __Pyx_GOTREF(__pyx_t_2);
32646       __Pyx_INCREF(((PyObject *)__pyx_kp_s_178));
32647       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_178));
32648       __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_178));
32649       __Pyx_INCREF(__pyx_v_stdout_f);
32650       PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_stdout_f);
32651       __Pyx_GIVEREF(__pyx_v_stdout_f);
32652       __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_2), __pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32653       __Pyx_GOTREF(__pyx_t_3);
32654       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
32655       __Pyx_DECREF(__pyx_v_args);
32656       __pyx_v_args = __pyx_t_3;
32657       __pyx_t_3 = 0;
32658       goto __pyx_L20;
32659     }
32660     __pyx_L20:;
32661     goto __pyx_L7;
32662   }
32663   __pyx_L7:;
32664
32665   /* "csamtools.pyx":3179
32666  *     cdef int i, n, retval
32667  * 
32668  *     n = len(args)             # <<<<<<<<<<<<<<
32669  *     method = _force_cmdline_bytes(method)
32670  *     args = [ _force_cmdline_bytes(a) for a in args ]
32671  */
32672   __pyx_t_12 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32673   __pyx_v_n = __pyx_t_12;
32674
32675   /* "csamtools.pyx":3180
32676  * 
32677  *     n = len(args)
32678  *     method = _force_cmdline_bytes(method)             # <<<<<<<<<<<<<<
32679  *     args = [ _force_cmdline_bytes(a) for a in args ]
32680  * 
32681  */
32682   __pyx_t_3 = ((PyObject *)__pyx_f_9csamtools__force_cmdline_bytes(__pyx_v_method)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32683   __Pyx_GOTREF(__pyx_t_3);
32684   __Pyx_DECREF(__pyx_v_method);
32685   __pyx_v_method = __pyx_t_3;
32686   __pyx_t_3 = 0;
32687
32688   /* "csamtools.pyx":3181
32689  *     n = len(args)
32690  *     method = _force_cmdline_bytes(method)
32691  *     args = [ _force_cmdline_bytes(a) for a in args ]             # <<<<<<<<<<<<<<
32692  * 
32693  *     # allocate two more for first (dummy) argument (contains command)
32694  */
32695   __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32696   __Pyx_GOTREF(__pyx_t_3);
32697   if (PyList_CheckExact(__pyx_v_args) || PyTuple_CheckExact(__pyx_v_args)) {
32698     __pyx_t_2 = __pyx_v_args; __Pyx_INCREF(__pyx_t_2); __pyx_t_12 = 0;
32699     __pyx_t_13 = NULL;
32700   } else {
32701     __pyx_t_12 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32702     __Pyx_GOTREF(__pyx_t_2);
32703     __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext;
32704   }
32705   for (;;) {
32706     if (!__pyx_t_13 && PyList_CheckExact(__pyx_t_2)) {
32707       if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_2)) break;
32708       __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++;
32709     } else if (!__pyx_t_13 && PyTuple_CheckExact(__pyx_t_2)) {
32710       if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
32711       __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_12); __Pyx_INCREF(__pyx_t_4); __pyx_t_12++;
32712     } else {
32713       __pyx_t_4 = __pyx_t_13(__pyx_t_2);
32714       if (unlikely(!__pyx_t_4)) {
32715         if (PyErr_Occurred()) {
32716           if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
32717           else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32718         }
32719         break;
32720       }
32721       __Pyx_GOTREF(__pyx_t_4);
32722     }
32723     __Pyx_XDECREF(__pyx_v_a);
32724     __pyx_v_a = __pyx_t_4;
32725     __pyx_t_4 = 0;
32726     __pyx_t_4 = ((PyObject *)__pyx_f_9csamtools__force_cmdline_bytes(__pyx_v_a)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32727     __Pyx_GOTREF(__pyx_t_4);
32728     if (unlikely(PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32729     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32730   }
32731   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32732   __Pyx_INCREF(((PyObject *)__pyx_t_3));
32733   __Pyx_DECREF(__pyx_v_args);
32734   __pyx_v_args = ((PyObject *)__pyx_t_3);
32735   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
32736
32737   /* "csamtools.pyx":3184
32738  * 
32739  *     # allocate two more for first (dummy) argument (contains command)
32740  *     cargs = <char**>calloc( n+2, sizeof( char *) )             # <<<<<<<<<<<<<<
32741  *     cargs[0] = "samtools"
32742  *     cargs[1] = method
32743  */
32744   __pyx_v_cargs = ((char **)calloc((__pyx_v_n + 2), (sizeof(char *))));
32745
32746   /* "csamtools.pyx":3185
32747  *     # allocate two more for first (dummy) argument (contains command)
32748  *     cargs = <char**>calloc( n+2, sizeof( char *) )
32749  *     cargs[0] = "samtools"             # <<<<<<<<<<<<<<
32750  *     cargs[1] = method
32751  *     for i from 0 <= i < n: cargs[i+2] = args[i]
32752  */
32753   (__pyx_v_cargs[0]) = __pyx_k__samtools;
32754
32755   /* "csamtools.pyx":3186
32756  *     cargs = <char**>calloc( n+2, sizeof( char *) )
32757  *     cargs[0] = "samtools"
32758  *     cargs[1] = method             # <<<<<<<<<<<<<<
32759  *     for i from 0 <= i < n: cargs[i+2] = args[i]
32760  * 
32761  */
32762   __pyx_t_14 = PyBytes_AsString(__pyx_v_method); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32763   (__pyx_v_cargs[1]) = __pyx_t_14;
32764
32765   /* "csamtools.pyx":3187
32766  *     cargs[0] = "samtools"
32767  *     cargs[1] = method
32768  *     for i from 0 <= i < n: cargs[i+2] = args[i]             # <<<<<<<<<<<<<<
32769  * 
32770  *     retval = pysam_dispatch(n+2, cargs)
32771  */
32772   __pyx_t_8 = __pyx_v_n;
32773   for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {
32774     __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32775     __Pyx_GOTREF(__pyx_t_3);
32776     __pyx_t_14 = PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_14) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32777     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32778     (__pyx_v_cargs[(__pyx_v_i + 2)]) = __pyx_t_14;
32779   }
32780
32781   /* "csamtools.pyx":3189
32782  *     for i from 0 <= i < n: cargs[i+2] = args[i]
32783  * 
32784  *     retval = pysam_dispatch(n+2, cargs)             # <<<<<<<<<<<<<<
32785  *     free( cargs )
32786  * 
32787  */
32788   __pyx_v_retval = pysam_dispatch((__pyx_v_n + 2), __pyx_v_cargs);
32789
32790   /* "csamtools.pyx":3190
32791  * 
32792  *     retval = pysam_dispatch(n+2, cargs)
32793  *     free( cargs )             # <<<<<<<<<<<<<<
32794  * 
32795  *     # restore stdout/stderr. This will also flush, so
32796  */
32797   free(__pyx_v_cargs);
32798
32799   /* "csamtools.pyx":3194
32800  *     # restore stdout/stderr. This will also flush, so
32801  *     # needs to be before reading back the file contents
32802  *     if catch_stdout:             # <<<<<<<<<<<<<<
32803  *         stdout_save.restore()
32804  *         try:
32805  */
32806   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32807   if (__pyx_t_5) {
32808
32809     /* "csamtools.pyx":3195
32810  *     # needs to be before reading back the file contents
32811  *     if catch_stdout:
32812  *         stdout_save.restore()             # <<<<<<<<<<<<<<
32813  *         try:
32814  *             with open( stdout_f, "r") as inf:
32815  */
32816     if (unlikely(!__pyx_v_stdout_save)) { __Pyx_RaiseUnboundLocalError("stdout_save"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
32817     __pyx_t_3 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32818     __Pyx_GOTREF(__pyx_t_3);
32819     __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32820     __Pyx_GOTREF(__pyx_t_2);
32821     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32822     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32823
32824     /* "csamtools.pyx":3196
32825  *     if catch_stdout:
32826  *         stdout_save.restore()
32827  *         try:             # <<<<<<<<<<<<<<
32828  *             with open( stdout_f, "r") as inf:
32829  *                 out_stdout = inf.readlines()
32830  */
32831     {
32832       __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
32833       __Pyx_XGOTREF(__pyx_t_11);
32834       __Pyx_XGOTREF(__pyx_t_10);
32835       __Pyx_XGOTREF(__pyx_t_9);
32836       /*try:*/ {
32837
32838         /* "csamtools.pyx":3197
32839  *         stdout_save.restore()
32840  *         try:
32841  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
32842  *                 out_stdout = inf.readlines()
32843  *         except UnicodeDecodeError:
32844  */
32845         /*with:*/ {
32846           if (unlikely(!__pyx_v_stdout_f)) { __Pyx_RaiseUnboundLocalError("stdout_f"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;} }
32847           __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
32848           __Pyx_GOTREF(__pyx_t_2);
32849           __Pyx_INCREF(__pyx_v_stdout_f);
32850           PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stdout_f);
32851           __Pyx_GIVEREF(__pyx_v_stdout_f);
32852           __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
32853           PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__r));
32854           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
32855           __pyx_t_3 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
32856           __Pyx_GOTREF(__pyx_t_3);
32857           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
32858           __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
32859           __Pyx_GOTREF(__pyx_t_15);
32860           __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L35_error;}
32861           __Pyx_GOTREF(__pyx_t_2);
32862           __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 = 3197; __pyx_clineno = __LINE__; goto __pyx_L35_error;}
32863           __Pyx_GOTREF(__pyx_t_4);
32864           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32865           __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32866           /*try:*/ {
32867             {
32868               __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
32869               __Pyx_XGOTREF(__pyx_t_16);
32870               __Pyx_XGOTREF(__pyx_t_17);
32871               __Pyx_XGOTREF(__pyx_t_18);
32872               /*try:*/ {
32873                 __Pyx_INCREF(__pyx_t_4);
32874                 __pyx_v_inf = __pyx_t_4;
32875                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32876
32877                 /* "csamtools.pyx":3198
32878  *         try:
32879  *             with open( stdout_f, "r") as inf:
32880  *                 out_stdout = inf.readlines()             # <<<<<<<<<<<<<<
32881  *         except UnicodeDecodeError:
32882  *             with open( stdout_f, "rb") as inf:
32883  */
32884                 __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
32885                 __Pyx_GOTREF(__pyx_t_4);
32886                 __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L41_error;}
32887                 __Pyx_GOTREF(__pyx_t_3);
32888                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32889                 __pyx_v_out_stdout = __pyx_t_3;
32890                 __pyx_t_3 = 0;
32891               }
32892               __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
32893               __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
32894               __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
32895               goto __pyx_L48_try_end;
32896               __pyx_L41_error:;
32897               __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
32898               __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
32899               __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
32900               __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
32901
32902               /* "csamtools.pyx":3197
32903  *         stdout_save.restore()
32904  *         try:
32905  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
32906  *                 out_stdout = inf.readlines()
32907  *         except UnicodeDecodeError:
32908  */
32909               /*except:*/ {
32910                 __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
32911                 if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
32912                 __Pyx_GOTREF(__pyx_t_3);
32913                 __Pyx_GOTREF(__pyx_t_4);
32914                 __Pyx_GOTREF(__pyx_t_2);
32915                 __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
32916                 __Pyx_GOTREF(__pyx_t_6);
32917                 __Pyx_INCREF(__pyx_t_3);
32918                 PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
32919                 __Pyx_GIVEREF(__pyx_t_3);
32920                 __Pyx_INCREF(__pyx_t_4);
32921                 PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
32922                 __Pyx_GIVEREF(__pyx_t_4);
32923                 __Pyx_INCREF(__pyx_t_2);
32924                 PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_2);
32925                 __Pyx_GIVEREF(__pyx_t_2);
32926                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_6, NULL);
32927                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
32928                 if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
32929                 __Pyx_GOTREF(__pyx_t_19);
32930                 __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_19);
32931                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
32932                 if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
32933                 __pyx_t_1 = (!__pyx_t_5);
32934                 if (__pyx_t_1) {
32935                   __Pyx_GIVEREF(__pyx_t_3);
32936                   __Pyx_GIVEREF(__pyx_t_4);
32937                   __Pyx_GIVEREF(__pyx_t_2);
32938                   __Pyx_ErrRestore(__pyx_t_3, __pyx_t_4, __pyx_t_2);
32939                   __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_2 = 0; 
32940                   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L43_except_error;}
32941                   goto __pyx_L52;
32942                 }
32943                 __pyx_L52:;
32944                 __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
32945                 __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32946                 __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
32947                 __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32948                 goto __pyx_L42_exception_handled;
32949               }
32950               __pyx_L43_except_error:;
32951               __Pyx_XGIVEREF(__pyx_t_16);
32952               __Pyx_XGIVEREF(__pyx_t_17);
32953               __Pyx_XGIVEREF(__pyx_t_18);
32954               __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
32955               goto __pyx_L27_error;
32956               __pyx_L42_exception_handled:;
32957               __Pyx_XGIVEREF(__pyx_t_16);
32958               __Pyx_XGIVEREF(__pyx_t_17);
32959               __Pyx_XGIVEREF(__pyx_t_18);
32960               __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
32961               __pyx_L48_try_end:;
32962             }
32963           }
32964           /*finally:*/ {
32965             if (__pyx_t_15) {
32966               __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_181, NULL);
32967               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
32968               if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
32969               __Pyx_GOTREF(__pyx_t_18);
32970               __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_18);
32971               __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
32972               if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L27_error;}
32973             }
32974           }
32975           goto __pyx_L53;
32976           __pyx_L35_error:;
32977           __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
32978           goto __pyx_L27_error;
32979           __pyx_L53:;
32980         }
32981       }
32982       __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
32983       __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
32984       __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
32985       goto __pyx_L34_try_end;
32986       __pyx_L27_error:;
32987       __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
32988       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
32989       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
32990       __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
32991
32992       /* "csamtools.pyx":3199
32993  *             with open( stdout_f, "r") as inf:
32994  *                 out_stdout = inf.readlines()
32995  *         except UnicodeDecodeError:             # <<<<<<<<<<<<<<
32996  *             with open( stdout_f, "rb") as inf:
32997  *                 # read binary output
32998  */
32999       __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
33000       if (__pyx_t_8) {
33001         __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33002         if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33003         __Pyx_GOTREF(__pyx_t_2);
33004         __Pyx_GOTREF(__pyx_t_4);
33005         __Pyx_GOTREF(__pyx_t_3);
33006
33007         /* "csamtools.pyx":3200
33008  *                 out_stdout = inf.readlines()
33009  *         except UnicodeDecodeError:
33010  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
33011  *                 # read binary output
33012  *                 out_stdout = inf.read()
33013  */
33014         /*with:*/ {
33015           __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33016           __Pyx_GOTREF(__pyx_t_6);
33017           __Pyx_INCREF(__pyx_v_stdout_f);
33018           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stdout_f);
33019           __Pyx_GIVEREF(__pyx_v_stdout_f);
33020           __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
33021           PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
33022           __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
33023           __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 = 3200; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33024           __Pyx_GOTREF(__pyx_t_20);
33025           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
33026           __pyx_t_15 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33027           __Pyx_GOTREF(__pyx_t_15);
33028           __pyx_t_6 = PyObject_GetAttr(__pyx_t_20, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
33029           __Pyx_GOTREF(__pyx_t_6);
33030           __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 = 3200; __pyx_clineno = __LINE__; goto __pyx_L56_error;}
33031           __Pyx_GOTREF(__pyx_t_21);
33032           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
33033           __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33034           /*try:*/ {
33035             {
33036               __Pyx_ExceptionSave(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16);
33037               __Pyx_XGOTREF(__pyx_t_18);
33038               __Pyx_XGOTREF(__pyx_t_17);
33039               __Pyx_XGOTREF(__pyx_t_16);
33040               /*try:*/ {
33041                 __Pyx_INCREF(__pyx_t_21);
33042                 __Pyx_XDECREF(__pyx_v_inf);
33043                 __pyx_v_inf = __pyx_t_21;
33044                 __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33045
33046                 /* "csamtools.pyx":3202
33047  *             with open( stdout_f, "rb") as inf:
33048  *                 # read binary output
33049  *                 out_stdout = inf.read()             # <<<<<<<<<<<<<<
33050  *         os.remove( stdout_f )
33051  *     else:
33052  */
33053                 __pyx_t_21 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3202; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
33054                 __Pyx_GOTREF(__pyx_t_21);
33055                 __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 = 3202; __pyx_clineno = __LINE__; goto __pyx_L62_error;}
33056                 __Pyx_GOTREF(__pyx_t_20);
33057                 __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33058                 __Pyx_XDECREF(__pyx_v_out_stdout);
33059                 __pyx_v_out_stdout = __pyx_t_20;
33060                 __pyx_t_20 = 0;
33061               }
33062               __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
33063               __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
33064               __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
33065               goto __pyx_L69_try_end;
33066               __pyx_L62_error:;
33067               __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
33068               __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
33069               __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
33070
33071               /* "csamtools.pyx":3200
33072  *                 out_stdout = inf.readlines()
33073  *         except UnicodeDecodeError:
33074  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
33075  *                 # read binary output
33076  *                 out_stdout = inf.read()
33077  */
33078               /*except:*/ {
33079                 __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33080                 if (__Pyx_GetException(&__pyx_t_20, &__pyx_t_21, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
33081                 __Pyx_GOTREF(__pyx_t_20);
33082                 __Pyx_GOTREF(__pyx_t_21);
33083                 __Pyx_GOTREF(__pyx_t_6);
33084                 __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
33085                 __Pyx_GOTREF(__pyx_t_22);
33086                 __Pyx_INCREF(__pyx_t_20);
33087                 PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_20);
33088                 __Pyx_GIVEREF(__pyx_t_20);
33089                 __Pyx_INCREF(__pyx_t_21);
33090                 PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_21);
33091                 __Pyx_GIVEREF(__pyx_t_21);
33092                 __Pyx_INCREF(__pyx_t_6);
33093                 PyTuple_SET_ITEM(__pyx_t_22, 2, __pyx_t_6);
33094                 __Pyx_GIVEREF(__pyx_t_6);
33095                 __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_22, NULL);
33096                 __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33097                 if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
33098                 __Pyx_GOTREF(__pyx_t_19);
33099                 __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_19);
33100                 __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
33101                 if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
33102                 __pyx_t_5 = (!__pyx_t_1);
33103                 if (__pyx_t_5) {
33104                   __Pyx_GIVEREF(__pyx_t_20);
33105                   __Pyx_GIVEREF(__pyx_t_21);
33106                   __Pyx_GIVEREF(__pyx_t_6);
33107                   __Pyx_ErrRestore(__pyx_t_20, __pyx_t_21, __pyx_t_6);
33108                   __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_6 = 0; 
33109                   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L64_except_error;}
33110                   goto __pyx_L73;
33111                 }
33112                 __pyx_L73:;
33113                 __Pyx_DECREF(((PyObject *)__pyx_t_22)); __pyx_t_22 = 0;
33114                 __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33115                 __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33116                 __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
33117                 goto __pyx_L63_exception_handled;
33118               }
33119               __pyx_L64_except_error:;
33120               __Pyx_XGIVEREF(__pyx_t_18);
33121               __Pyx_XGIVEREF(__pyx_t_17);
33122               __Pyx_XGIVEREF(__pyx_t_16);
33123               __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
33124               goto __pyx_L29_except_error;
33125               __pyx_L63_exception_handled:;
33126               __Pyx_XGIVEREF(__pyx_t_18);
33127               __Pyx_XGIVEREF(__pyx_t_17);
33128               __Pyx_XGIVEREF(__pyx_t_16);
33129               __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
33130               __pyx_L69_try_end:;
33131             }
33132           }
33133           /*finally:*/ {
33134             if (__pyx_t_15) {
33135               __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_182, NULL);
33136               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33137               if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33138               __Pyx_GOTREF(__pyx_t_16);
33139               __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_16);
33140               __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
33141               if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L29_except_error;}
33142             }
33143           }
33144           goto __pyx_L74;
33145           __pyx_L56_error:;
33146           __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33147           goto __pyx_L29_except_error;
33148           __pyx_L74:;
33149         }
33150         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
33151         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33152         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33153         goto __pyx_L28_exception_handled;
33154       }
33155       __pyx_L29_except_error:;
33156       __Pyx_XGIVEREF(__pyx_t_11);
33157       __Pyx_XGIVEREF(__pyx_t_10);
33158       __Pyx_XGIVEREF(__pyx_t_9);
33159       __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9);
33160       goto __pyx_L1_error;
33161       __pyx_L28_exception_handled:;
33162       __Pyx_XGIVEREF(__pyx_t_11);
33163       __Pyx_XGIVEREF(__pyx_t_10);
33164       __Pyx_XGIVEREF(__pyx_t_9);
33165       __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9);
33166       __pyx_L34_try_end:;
33167     }
33168
33169     /* "csamtools.pyx":3203
33170  *                 # read binary output
33171  *                 out_stdout = inf.read()
33172  *         os.remove( stdout_f )             # <<<<<<<<<<<<<<
33173  *     else:
33174  *         out_stdout = []
33175  */
33176     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33177     __Pyx_GOTREF(__pyx_t_3);
33178     __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33179     __Pyx_GOTREF(__pyx_t_4);
33180     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33181     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33182     __Pyx_GOTREF(__pyx_t_3);
33183     __Pyx_INCREF(__pyx_v_stdout_f);
33184     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_f);
33185     __Pyx_GIVEREF(__pyx_v_stdout_f);
33186     __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33187     __Pyx_GOTREF(__pyx_t_2);
33188     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33189     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33190     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
33191     goto __pyx_L26;
33192   }
33193   /*else*/ {
33194
33195     /* "csamtools.pyx":3205
33196  *         os.remove( stdout_f )
33197  *     else:
33198  *         out_stdout = []             # <<<<<<<<<<<<<<
33199  * 
33200  *     # get error messages
33201  */
33202     __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33203     __Pyx_GOTREF(__pyx_t_2);
33204     __pyx_v_out_stdout = ((PyObject *)__pyx_t_2);
33205     __pyx_t_2 = 0;
33206   }
33207   __pyx_L26:;
33208
33209   /* "csamtools.pyx":3208
33210  * 
33211  *     # get error messages
33212  *     pysam_unset_stderr()             # <<<<<<<<<<<<<<
33213  *     try:
33214  *         with open( stderr_f, "r") as inf:
33215  */
33216   pysam_unset_stderr();
33217
33218   /* "csamtools.pyx":3209
33219  *     # get error messages
33220  *     pysam_unset_stderr()
33221  *     try:             # <<<<<<<<<<<<<<
33222  *         with open( stderr_f, "r") as inf:
33223  *             out_stderr = inf.readlines()
33224  */
33225   {
33226     __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
33227     __Pyx_XGOTREF(__pyx_t_9);
33228     __Pyx_XGOTREF(__pyx_t_10);
33229     __Pyx_XGOTREF(__pyx_t_11);
33230     /*try:*/ {
33231
33232       /* "csamtools.pyx":3210
33233  *     pysam_unset_stderr()
33234  *     try:
33235  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
33236  *             out_stderr = inf.readlines()
33237  *     except UnicodeDecodeError:
33238  */
33239       /*with:*/ {
33240         __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L75_error;}
33241         __Pyx_GOTREF(__pyx_t_2);
33242         __Pyx_INCREF(__pyx_v_stderr_f);
33243         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_stderr_f);
33244         __Pyx_GIVEREF(__pyx_v_stderr_f);
33245         __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
33246         PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__r));
33247         __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
33248         __pyx_t_3 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L75_error;}
33249         __Pyx_GOTREF(__pyx_t_3);
33250         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
33251         __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L75_error;}
33252         __Pyx_GOTREF(__pyx_t_15);
33253         __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L83_error;}
33254         __Pyx_GOTREF(__pyx_t_2);
33255         __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 = 3210; __pyx_clineno = __LINE__; goto __pyx_L83_error;}
33256         __Pyx_GOTREF(__pyx_t_4);
33257         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
33258         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33259         /*try:*/ {
33260           {
33261             __Pyx_ExceptionSave(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
33262             __Pyx_XGOTREF(__pyx_t_16);
33263             __Pyx_XGOTREF(__pyx_t_17);
33264             __Pyx_XGOTREF(__pyx_t_18);
33265             /*try:*/ {
33266               __Pyx_INCREF(__pyx_t_4);
33267               __Pyx_XDECREF(__pyx_v_inf);
33268               __pyx_v_inf = __pyx_t_4;
33269               __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33270
33271               /* "csamtools.pyx":3211
33272  *     try:
33273  *         with open( stderr_f, "r") as inf:
33274  *             out_stderr = inf.readlines()             # <<<<<<<<<<<<<<
33275  *     except UnicodeDecodeError:
33276  *         with open( stderr_f, "rb") as inf:
33277  */
33278               __pyx_t_4 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3211; __pyx_clineno = __LINE__; goto __pyx_L89_error;}
33279               __Pyx_GOTREF(__pyx_t_4);
33280               __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3211; __pyx_clineno = __LINE__; goto __pyx_L89_error;}
33281               __Pyx_GOTREF(__pyx_t_3);
33282               __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33283               __pyx_v_out_stderr = __pyx_t_3;
33284               __pyx_t_3 = 0;
33285             }
33286             __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
33287             __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
33288             __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
33289             goto __pyx_L96_try_end;
33290             __pyx_L89_error:;
33291             __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
33292             __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
33293             __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
33294             __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
33295             __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
33296             __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
33297             __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
33298
33299             /* "csamtools.pyx":3210
33300  *     pysam_unset_stderr()
33301  *     try:
33302  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
33303  *             out_stderr = inf.readlines()
33304  *     except UnicodeDecodeError:
33305  */
33306             /*except:*/ {
33307               __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33308               if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_4, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L91_except_error;}
33309               __Pyx_GOTREF(__pyx_t_3);
33310               __Pyx_GOTREF(__pyx_t_4);
33311               __Pyx_GOTREF(__pyx_t_2);
33312               __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L91_except_error;}
33313               __Pyx_GOTREF(__pyx_t_6);
33314               __Pyx_INCREF(__pyx_t_3);
33315               PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
33316               __Pyx_GIVEREF(__pyx_t_3);
33317               __Pyx_INCREF(__pyx_t_4);
33318               PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_4);
33319               __Pyx_GIVEREF(__pyx_t_4);
33320               __Pyx_INCREF(__pyx_t_2);
33321               PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_2);
33322               __Pyx_GIVEREF(__pyx_t_2);
33323               __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_6, NULL);
33324               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33325               if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L91_except_error;}
33326               __Pyx_GOTREF(__pyx_t_19);
33327               __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_19);
33328               __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
33329               if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L91_except_error;}
33330               __pyx_t_1 = (!__pyx_t_5);
33331               if (__pyx_t_1) {
33332                 __Pyx_GIVEREF(__pyx_t_3);
33333                 __Pyx_GIVEREF(__pyx_t_4);
33334                 __Pyx_GIVEREF(__pyx_t_2);
33335                 __Pyx_ErrRestore(__pyx_t_3, __pyx_t_4, __pyx_t_2);
33336                 __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_2 = 0; 
33337                 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L91_except_error;}
33338                 goto __pyx_L100;
33339               }
33340               __pyx_L100:;
33341               __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
33342               __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33343               __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33344               __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
33345               goto __pyx_L90_exception_handled;
33346             }
33347             __pyx_L91_except_error:;
33348             __Pyx_XGIVEREF(__pyx_t_16);
33349             __Pyx_XGIVEREF(__pyx_t_17);
33350             __Pyx_XGIVEREF(__pyx_t_18);
33351             __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
33352             goto __pyx_L75_error;
33353             __pyx_L90_exception_handled:;
33354             __Pyx_XGIVEREF(__pyx_t_16);
33355             __Pyx_XGIVEREF(__pyx_t_17);
33356             __Pyx_XGIVEREF(__pyx_t_18);
33357             __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
33358             __pyx_L96_try_end:;
33359           }
33360         }
33361         /*finally:*/ {
33362           if (__pyx_t_15) {
33363             __pyx_t_18 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_183, NULL);
33364             __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33365             if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L75_error;}
33366             __Pyx_GOTREF(__pyx_t_18);
33367             __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_18);
33368             __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
33369             if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L75_error;}
33370           }
33371         }
33372         goto __pyx_L101;
33373         __pyx_L83_error:;
33374         __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33375         goto __pyx_L75_error;
33376         __pyx_L101:;
33377       }
33378     }
33379     /*else:*/ {
33380
33381       /* "csamtools.pyx":3218
33382  *         os.remove( stderr_f )
33383  *     else:
33384  *         out_stderr = []             # <<<<<<<<<<<<<<
33385  * 
33386  *     return retval, out_stderr, out_stdout
33387  */
33388       __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3218; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33389       __Pyx_GOTREF(__pyx_t_2);
33390       __Pyx_XDECREF(__pyx_v_out_stderr);
33391       __pyx_v_out_stderr = ((PyObject *)__pyx_t_2);
33392       __pyx_t_2 = 0;
33393     }
33394     __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
33395     __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
33396     __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
33397     goto __pyx_L82_try_end;
33398     __pyx_L75_error:;
33399     __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
33400     __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
33401     __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
33402     __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
33403     __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
33404     __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
33405     __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
33406
33407     /* "csamtools.pyx":3212
33408  *         with open( stderr_f, "r") as inf:
33409  *             out_stderr = inf.readlines()
33410  *     except UnicodeDecodeError:             # <<<<<<<<<<<<<<
33411  *         with open( stderr_f, "rb") as inf:
33412  *             # read binary output
33413  */
33414     __pyx_t_8 = PyErr_ExceptionMatches(__pyx_builtin_UnicodeDecodeError);
33415     if (__pyx_t_8) {
33416       __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33417       if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3212; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33418       __Pyx_GOTREF(__pyx_t_2);
33419       __Pyx_GOTREF(__pyx_t_4);
33420       __Pyx_GOTREF(__pyx_t_3);
33421
33422       /* "csamtools.pyx":3213
33423  *             out_stderr = inf.readlines()
33424  *     except UnicodeDecodeError:
33425  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
33426  *             # read binary output
33427  *             out_stderr = inf.read()
33428  */
33429       /*with:*/ {
33430         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33431         __Pyx_GOTREF(__pyx_t_6);
33432         __Pyx_INCREF(__pyx_v_stderr_f);
33433         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stderr_f);
33434         __Pyx_GIVEREF(__pyx_v_stderr_f);
33435         __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
33436         PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__rb));
33437         __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
33438         __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 = 3213; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33439         __Pyx_GOTREF(__pyx_t_21);
33440         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
33441         __pyx_t_15 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____exit__); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33442         __Pyx_GOTREF(__pyx_t_15);
33443         __pyx_t_6 = PyObject_GetAttr(__pyx_t_21, __pyx_n_s____enter__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L104_error;}
33444         __Pyx_GOTREF(__pyx_t_6);
33445         __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 = 3213; __pyx_clineno = __LINE__; goto __pyx_L104_error;}
33446         __Pyx_GOTREF(__pyx_t_20);
33447         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
33448         __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33449         /*try:*/ {
33450           {
33451             __Pyx_ExceptionSave(&__pyx_t_18, &__pyx_t_17, &__pyx_t_16);
33452             __Pyx_XGOTREF(__pyx_t_18);
33453             __Pyx_XGOTREF(__pyx_t_17);
33454             __Pyx_XGOTREF(__pyx_t_16);
33455             /*try:*/ {
33456               __Pyx_INCREF(__pyx_t_20);
33457               __Pyx_XDECREF(__pyx_v_inf);
33458               __pyx_v_inf = __pyx_t_20;
33459               __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33460
33461               /* "csamtools.pyx":3215
33462  *         with open( stderr_f, "rb") as inf:
33463  *             # read binary output
33464  *             out_stderr = inf.read()             # <<<<<<<<<<<<<<
33465  *         os.remove( stderr_f )
33466  *     else:
33467  */
33468               __pyx_t_20 = PyObject_GetAttr(__pyx_v_inf, __pyx_n_s__read); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3215; __pyx_clineno = __LINE__; goto __pyx_L110_error;}
33469               __Pyx_GOTREF(__pyx_t_20);
33470               __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 = 3215; __pyx_clineno = __LINE__; goto __pyx_L110_error;}
33471               __Pyx_GOTREF(__pyx_t_21);
33472               __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33473               __Pyx_XDECREF(__pyx_v_out_stderr);
33474               __pyx_v_out_stderr = __pyx_t_21;
33475               __pyx_t_21 = 0;
33476             }
33477             __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
33478             __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
33479             __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
33480             goto __pyx_L117_try_end;
33481             __pyx_L110_error:;
33482             __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
33483             __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
33484             __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
33485             __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
33486
33487             /* "csamtools.pyx":3213
33488  *             out_stderr = inf.readlines()
33489  *     except UnicodeDecodeError:
33490  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
33491  *             # read binary output
33492  *             out_stderr = inf.read()
33493  */
33494             /*except:*/ {
33495               __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33496               if (__Pyx_GetException(&__pyx_t_21, &__pyx_t_20, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L112_except_error;}
33497               __Pyx_GOTREF(__pyx_t_21);
33498               __Pyx_GOTREF(__pyx_t_20);
33499               __Pyx_GOTREF(__pyx_t_6);
33500               __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L112_except_error;}
33501               __Pyx_GOTREF(__pyx_t_22);
33502               __Pyx_INCREF(__pyx_t_21);
33503               PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_21);
33504               __Pyx_GIVEREF(__pyx_t_21);
33505               __Pyx_INCREF(__pyx_t_20);
33506               PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_20);
33507               __Pyx_GIVEREF(__pyx_t_20);
33508               __Pyx_INCREF(__pyx_t_6);
33509               PyTuple_SET_ITEM(__pyx_t_22, 2, __pyx_t_6);
33510               __Pyx_GIVEREF(__pyx_t_6);
33511               __pyx_t_19 = PyObject_Call(__pyx_t_15, __pyx_t_22, NULL);
33512               __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33513               if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L112_except_error;}
33514               __Pyx_GOTREF(__pyx_t_19);
33515               __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_19);
33516               __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
33517               if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L112_except_error;}
33518               __pyx_t_5 = (!__pyx_t_1);
33519               if (__pyx_t_5) {
33520                 __Pyx_GIVEREF(__pyx_t_21);
33521                 __Pyx_GIVEREF(__pyx_t_20);
33522                 __Pyx_GIVEREF(__pyx_t_6);
33523                 __Pyx_ErrRestore(__pyx_t_21, __pyx_t_20, __pyx_t_6);
33524                 __pyx_t_21 = 0; __pyx_t_20 = 0; __pyx_t_6 = 0; 
33525                 {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L112_except_error;}
33526                 goto __pyx_L121;
33527               }
33528               __pyx_L121:;
33529               __Pyx_DECREF(((PyObject *)__pyx_t_22)); __pyx_t_22 = 0;
33530               __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33531               __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33532               __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
33533               goto __pyx_L111_exception_handled;
33534             }
33535             __pyx_L112_except_error:;
33536             __Pyx_XGIVEREF(__pyx_t_18);
33537             __Pyx_XGIVEREF(__pyx_t_17);
33538             __Pyx_XGIVEREF(__pyx_t_16);
33539             __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
33540             goto __pyx_L77_except_error;
33541             __pyx_L111_exception_handled:;
33542             __Pyx_XGIVEREF(__pyx_t_18);
33543             __Pyx_XGIVEREF(__pyx_t_17);
33544             __Pyx_XGIVEREF(__pyx_t_16);
33545             __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_17, __pyx_t_16);
33546             __pyx_L117_try_end:;
33547           }
33548         }
33549         /*finally:*/ {
33550           if (__pyx_t_15) {
33551             __pyx_t_16 = PyObject_Call(__pyx_t_15, __pyx_k_tuple_184, NULL);
33552             __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33553             if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33554             __Pyx_GOTREF(__pyx_t_16);
33555             __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_16);
33556             __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
33557             if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33558           }
33559         }
33560         goto __pyx_L122;
33561         __pyx_L104_error:;
33562         __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
33563         goto __pyx_L77_except_error;
33564         __pyx_L122:;
33565       }
33566
33567       /* "csamtools.pyx":3216
33568  *             # read binary output
33569  *             out_stderr = inf.read()
33570  *         os.remove( stderr_f )             # <<<<<<<<<<<<<<
33571  *     else:
33572  *         out_stderr = []
33573  */
33574       __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3216; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33575       __Pyx_GOTREF(__pyx_t_6);
33576       __pyx_t_20 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__remove); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3216; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33577       __Pyx_GOTREF(__pyx_t_20);
33578       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
33579       __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3216; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33580       __Pyx_GOTREF(__pyx_t_6);
33581       __Pyx_INCREF(__pyx_v_stderr_f);
33582       PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_stderr_f);
33583       __Pyx_GIVEREF(__pyx_v_stderr_f);
33584       __pyx_t_21 = PyObject_Call(__pyx_t_20, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3216; __pyx_clineno = __LINE__; goto __pyx_L77_except_error;}
33585       __Pyx_GOTREF(__pyx_t_21);
33586       __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
33587       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
33588       __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
33589       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
33590       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
33591       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33592       goto __pyx_L76_exception_handled;
33593     }
33594     __pyx_L77_except_error:;
33595     __Pyx_XGIVEREF(__pyx_t_9);
33596     __Pyx_XGIVEREF(__pyx_t_10);
33597     __Pyx_XGIVEREF(__pyx_t_11);
33598     __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
33599     goto __pyx_L1_error;
33600     __pyx_L76_exception_handled:;
33601     __Pyx_XGIVEREF(__pyx_t_9);
33602     __Pyx_XGIVEREF(__pyx_t_10);
33603     __Pyx_XGIVEREF(__pyx_t_11);
33604     __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
33605     __pyx_L82_try_end:;
33606   }
33607
33608   /* "csamtools.pyx":3220
33609  *         out_stderr = []
33610  * 
33611  *     return retval, out_stderr, out_stdout             # <<<<<<<<<<<<<<
33612  * 
33613  * cdef class SNPCall:
33614  */
33615   __Pyx_XDECREF(__pyx_r);
33616   __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33617   __Pyx_GOTREF(__pyx_t_3);
33618   if (unlikely(!__pyx_v_out_stderr)) { __Pyx_RaiseUnboundLocalError("out_stderr"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
33619   if (unlikely(!__pyx_v_out_stdout)) { __Pyx_RaiseUnboundLocalError("out_stdout"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
33620   __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33621   __Pyx_GOTREF(__pyx_t_4);
33622   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
33623   __Pyx_GIVEREF(__pyx_t_3);
33624   __Pyx_INCREF(__pyx_v_out_stderr);
33625   PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_out_stderr);
33626   __Pyx_GIVEREF(__pyx_v_out_stderr);
33627   __Pyx_INCREF(__pyx_v_out_stdout);
33628   PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_out_stdout);
33629   __Pyx_GIVEREF(__pyx_v_out_stdout);
33630   __pyx_t_3 = 0;
33631   __pyx_r = ((PyObject *)__pyx_t_4);
33632   __pyx_t_4 = 0;
33633   goto __pyx_L0;
33634
33635   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33636   goto __pyx_L0;
33637   __pyx_L1_error:;
33638   __Pyx_XDECREF(__pyx_t_2);
33639   __Pyx_XDECREF(__pyx_t_3);
33640   __Pyx_XDECREF(__pyx_t_4);
33641   __Pyx_XDECREF(__pyx_t_6);
33642   __Pyx_XDECREF(__pyx_t_20);
33643   __Pyx_XDECREF(__pyx_t_21);
33644   __Pyx_XDECREF(__pyx_t_22);
33645   __Pyx_AddTraceback("csamtools._samtools_dispatch", __pyx_clineno, __pyx_lineno, __pyx_filename);
33646   __pyx_r = NULL;
33647   __pyx_L0:;
33648   __Pyx_XDECREF(__pyx_v_stderr_h);
33649   __Pyx_XDECREF(__pyx_v_stderr_f);
33650   __Pyx_XDECREF(__pyx_v_stdout_h);
33651   __Pyx_XDECREF(__pyx_v_stdout_f);
33652   __Pyx_XDECREF(__pyx_v_stdout_save);
33653   __Pyx_XDECREF(__pyx_v_inf);
33654   __Pyx_XDECREF(__pyx_v_out_stdout);
33655   __Pyx_XDECREF(__pyx_v_out_stderr);
33656   __Pyx_XDECREF(__pyx_v_a);
33657   __Pyx_XDECREF(__pyx_v_method);
33658   __Pyx_XDECREF(__pyx_v_args);
33659   __Pyx_XDECREF(__pyx_v_catch_stdout);
33660   __Pyx_XGIVEREF(__pyx_r);
33661   __Pyx_TraceReturn(__pyx_r);
33662   __Pyx_RefNannyFinishContext();
33663   return __pyx_r;
33664 }
33665
33666 /* Python wrapper */
33667 static PyObject *__pyx_pw_9csamtools_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
33668 static PyObject *__pyx_pw_9csamtools_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self) {
33669   PyObject *__pyx_r = 0;
33670   __Pyx_RefNannyDeclarations
33671   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33672   __pyx_r = __pyx_pf_9csamtools_7SNPCall_3tid___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33673   __Pyx_RefNannyFinishContext();
33674   return __pyx_r;
33675 }
33676
33677 /* "csamtools.pyx":3235
33678  *     property tid:
33679  *         '''the chromosome ID as is defined in the header'''
33680  *         def __get__(self):             # <<<<<<<<<<<<<<
33681  *             return self._tid
33682  * 
33683  */
33684
33685 static PyObject *__pyx_pf_9csamtools_7SNPCall_3tid___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33686   PyObject *__pyx_r = NULL;
33687   __Pyx_RefNannyDeclarations
33688   PyObject *__pyx_t_1 = NULL;
33689   int __pyx_lineno = 0;
33690   const char *__pyx_filename = NULL;
33691   int __pyx_clineno = 0;
33692   __Pyx_TraceDeclarations
33693   __Pyx_RefNannySetupContext("__get__", 0);
33694   __Pyx_TraceCall("__get__", __pyx_f[0], 3235);
33695
33696   /* "csamtools.pyx":3236
33697  *         '''the chromosome ID as is defined in the header'''
33698  *         def __get__(self):
33699  *             return self._tid             # <<<<<<<<<<<<<<
33700  * 
33701  *     property pos:
33702  */
33703   __Pyx_XDECREF(__pyx_r);
33704   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33705   __Pyx_GOTREF(__pyx_t_1);
33706   __pyx_r = __pyx_t_1;
33707   __pyx_t_1 = 0;
33708   goto __pyx_L0;
33709
33710   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33711   goto __pyx_L0;
33712   __pyx_L1_error:;
33713   __Pyx_XDECREF(__pyx_t_1);
33714   __Pyx_AddTraceback("csamtools.SNPCall.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33715   __pyx_r = NULL;
33716   __pyx_L0:;
33717   __Pyx_XGIVEREF(__pyx_r);
33718   __Pyx_TraceReturn(__pyx_r);
33719   __Pyx_RefNannyFinishContext();
33720   return __pyx_r;
33721 }
33722
33723 /* Python wrapper */
33724 static PyObject *__pyx_pw_9csamtools_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
33725 static PyObject *__pyx_pw_9csamtools_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self) {
33726   PyObject *__pyx_r = 0;
33727   __Pyx_RefNannyDeclarations
33728   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33729   __pyx_r = __pyx_pf_9csamtools_7SNPCall_3pos___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33730   __Pyx_RefNannyFinishContext();
33731   return __pyx_r;
33732 }
33733
33734 /* "csamtools.pyx":3240
33735  *     property pos:
33736  *        '''nucleotide position of SNP.'''
33737  *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
33738  * 
33739  *     property reference_base:
33740  */
33741
33742 static PyObject *__pyx_pf_9csamtools_7SNPCall_3pos___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33743   PyObject *__pyx_r = NULL;
33744   __Pyx_RefNannyDeclarations
33745   PyObject *__pyx_t_1 = NULL;
33746   int __pyx_lineno = 0;
33747   const char *__pyx_filename = NULL;
33748   int __pyx_clineno = 0;
33749   __Pyx_TraceDeclarations
33750   __Pyx_RefNannySetupContext("__get__", 0);
33751   __Pyx_TraceCall("__get__", __pyx_f[0], 3240);
33752   __Pyx_XDECREF(__pyx_r);
33753   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33754   __Pyx_GOTREF(__pyx_t_1);
33755   __pyx_r = __pyx_t_1;
33756   __pyx_t_1 = 0;
33757   goto __pyx_L0;
33758
33759   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33760   goto __pyx_L0;
33761   __pyx_L1_error:;
33762   __Pyx_XDECREF(__pyx_t_1);
33763   __Pyx_AddTraceback("csamtools.SNPCall.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33764   __pyx_r = NULL;
33765   __pyx_L0:;
33766   __Pyx_XGIVEREF(__pyx_r);
33767   __Pyx_TraceReturn(__pyx_r);
33768   __Pyx_RefNannyFinishContext();
33769   return __pyx_r;
33770 }
33771
33772 /* Python wrapper */
33773 static PyObject *__pyx_pw_9csamtools_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self); /*proto*/
33774 static PyObject *__pyx_pw_9csamtools_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self) {
33775   PyObject *__pyx_r = 0;
33776   __Pyx_RefNannyDeclarations
33777   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33778   __pyx_r = __pyx_pf_9csamtools_7SNPCall_14reference_base___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33779   __Pyx_RefNannyFinishContext();
33780   return __pyx_r;
33781 }
33782
33783 /* "csamtools.pyx":3244
33784  *     property reference_base:
33785  *        '''reference base at pos. ``N`` if no reference sequence supplied.'''
33786  *        def __get__(self): return from_string_and_size( &self._reference_base, 1 )             # <<<<<<<<<<<<<<
33787  * 
33788  *     property genotype:
33789  */
33790
33791 static PyObject *__pyx_pf_9csamtools_7SNPCall_14reference_base___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33792   PyObject *__pyx_r = NULL;
33793   __Pyx_RefNannyDeclarations
33794   PyObject *__pyx_t_1 = NULL;
33795   int __pyx_lineno = 0;
33796   const char *__pyx_filename = NULL;
33797   int __pyx_clineno = 0;
33798   __Pyx_TraceDeclarations
33799   __Pyx_RefNannySetupContext("__get__", 0);
33800   __Pyx_TraceCall("__get__", __pyx_f[0], 3244);
33801   __Pyx_XDECREF(__pyx_r);
33802   __pyx_t_1 = __pyx_f_9csamtools_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33803   __Pyx_GOTREF(__pyx_t_1);
33804   __pyx_r = __pyx_t_1;
33805   __pyx_t_1 = 0;
33806   goto __pyx_L0;
33807
33808   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33809   goto __pyx_L0;
33810   __pyx_L1_error:;
33811   __Pyx_XDECREF(__pyx_t_1);
33812   __Pyx_AddTraceback("csamtools.SNPCall.reference_base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33813   __pyx_r = NULL;
33814   __pyx_L0:;
33815   __Pyx_XGIVEREF(__pyx_r);
33816   __Pyx_TraceReturn(__pyx_r);
33817   __Pyx_RefNannyFinishContext();
33818   return __pyx_r;
33819 }
33820
33821 /* Python wrapper */
33822 static PyObject *__pyx_pw_9csamtools_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self); /*proto*/
33823 static PyObject *__pyx_pw_9csamtools_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self) {
33824   PyObject *__pyx_r = 0;
33825   __Pyx_RefNannyDeclarations
33826   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33827   __pyx_r = __pyx_pf_9csamtools_7SNPCall_8genotype___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33828   __Pyx_RefNannyFinishContext();
33829   return __pyx_r;
33830 }
33831
33832 /* "csamtools.pyx":3248
33833  *     property genotype:
33834  *        '''the genotype called.'''
33835  *        def __get__(self): return from_string_and_size( &self._genotype, 1 )             # <<<<<<<<<<<<<<
33836  * 
33837  *     property consensus_quality:
33838  */
33839
33840 static PyObject *__pyx_pf_9csamtools_7SNPCall_8genotype___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33841   PyObject *__pyx_r = NULL;
33842   __Pyx_RefNannyDeclarations
33843   PyObject *__pyx_t_1 = NULL;
33844   int __pyx_lineno = 0;
33845   const char *__pyx_filename = NULL;
33846   int __pyx_clineno = 0;
33847   __Pyx_TraceDeclarations
33848   __Pyx_RefNannySetupContext("__get__", 0);
33849   __Pyx_TraceCall("__get__", __pyx_f[0], 3248);
33850   __Pyx_XDECREF(__pyx_r);
33851   __pyx_t_1 = __pyx_f_9csamtools_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33852   __Pyx_GOTREF(__pyx_t_1);
33853   __pyx_r = __pyx_t_1;
33854   __pyx_t_1 = 0;
33855   goto __pyx_L0;
33856
33857   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33858   goto __pyx_L0;
33859   __pyx_L1_error:;
33860   __Pyx_XDECREF(__pyx_t_1);
33861   __Pyx_AddTraceback("csamtools.SNPCall.genotype.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33862   __pyx_r = NULL;
33863   __pyx_L0:;
33864   __Pyx_XGIVEREF(__pyx_r);
33865   __Pyx_TraceReturn(__pyx_r);
33866   __Pyx_RefNannyFinishContext();
33867   return __pyx_r;
33868 }
33869
33870 /* Python wrapper */
33871 static PyObject *__pyx_pw_9csamtools_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
33872 static PyObject *__pyx_pw_9csamtools_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self) {
33873   PyObject *__pyx_r = 0;
33874   __Pyx_RefNannyDeclarations
33875   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33876   __pyx_r = __pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33877   __Pyx_RefNannyFinishContext();
33878   return __pyx_r;
33879 }
33880
33881 /* "csamtools.pyx":3252
33882  *     property consensus_quality:
33883  *        '''the genotype quality (Phred-scaled).'''
33884  *        def __get__(self): return self._consensus_quality             # <<<<<<<<<<<<<<
33885  * 
33886  *     property snp_quality:
33887  */
33888
33889 static PyObject *__pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33890   PyObject *__pyx_r = NULL;
33891   __Pyx_RefNannyDeclarations
33892   PyObject *__pyx_t_1 = NULL;
33893   int __pyx_lineno = 0;
33894   const char *__pyx_filename = NULL;
33895   int __pyx_clineno = 0;
33896   __Pyx_TraceDeclarations
33897   __Pyx_RefNannySetupContext("__get__", 0);
33898   __Pyx_TraceCall("__get__", __pyx_f[0], 3252);
33899   __Pyx_XDECREF(__pyx_r);
33900   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33901   __Pyx_GOTREF(__pyx_t_1);
33902   __pyx_r = __pyx_t_1;
33903   __pyx_t_1 = 0;
33904   goto __pyx_L0;
33905
33906   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33907   goto __pyx_L0;
33908   __pyx_L1_error:;
33909   __Pyx_XDECREF(__pyx_t_1);
33910   __Pyx_AddTraceback("csamtools.SNPCall.consensus_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33911   __pyx_r = NULL;
33912   __pyx_L0:;
33913   __Pyx_XGIVEREF(__pyx_r);
33914   __Pyx_TraceReturn(__pyx_r);
33915   __Pyx_RefNannyFinishContext();
33916   return __pyx_r;
33917 }
33918
33919 /* Python wrapper */
33920 static PyObject *__pyx_pw_9csamtools_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
33921 static PyObject *__pyx_pw_9csamtools_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self) {
33922   PyObject *__pyx_r = 0;
33923   __Pyx_RefNannyDeclarations
33924   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33925   __pyx_r = __pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33926   __Pyx_RefNannyFinishContext();
33927   return __pyx_r;
33928 }
33929
33930 /* "csamtools.pyx":3256
33931  *     property snp_quality:
33932  *        '''the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.'''
33933  *        def __get__(self): return self._snp_quality             # <<<<<<<<<<<<<<
33934  * 
33935  *     property mapping_quality:
33936  */
33937
33938 static PyObject *__pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33939   PyObject *__pyx_r = NULL;
33940   __Pyx_RefNannyDeclarations
33941   PyObject *__pyx_t_1 = NULL;
33942   int __pyx_lineno = 0;
33943   const char *__pyx_filename = NULL;
33944   int __pyx_clineno = 0;
33945   __Pyx_TraceDeclarations
33946   __Pyx_RefNannySetupContext("__get__", 0);
33947   __Pyx_TraceCall("__get__", __pyx_f[0], 3256);
33948   __Pyx_XDECREF(__pyx_r);
33949   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33950   __Pyx_GOTREF(__pyx_t_1);
33951   __pyx_r = __pyx_t_1;
33952   __pyx_t_1 = 0;
33953   goto __pyx_L0;
33954
33955   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
33956   goto __pyx_L0;
33957   __pyx_L1_error:;
33958   __Pyx_XDECREF(__pyx_t_1);
33959   __Pyx_AddTraceback("csamtools.SNPCall.snp_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
33960   __pyx_r = NULL;
33961   __pyx_L0:;
33962   __Pyx_XGIVEREF(__pyx_r);
33963   __Pyx_TraceReturn(__pyx_r);
33964   __Pyx_RefNannyFinishContext();
33965   return __pyx_r;
33966 }
33967
33968 /* Python wrapper */
33969 static PyObject *__pyx_pw_9csamtools_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
33970 static PyObject *__pyx_pw_9csamtools_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self) {
33971   PyObject *__pyx_r = 0;
33972   __Pyx_RefNannyDeclarations
33973   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
33974   __pyx_r = __pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
33975   __Pyx_RefNannyFinishContext();
33976   return __pyx_r;
33977 }
33978
33979 /* "csamtools.pyx":3260
33980  *     property mapping_quality:
33981  *        '''the root mean square (rms) of the mapping quality of all reads involved in the call.'''
33982  *        def __get__(self): return self._rms_mapping_quality             # <<<<<<<<<<<<<<
33983  * 
33984  *     property coverage:
33985  */
33986
33987 static PyObject *__pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
33988   PyObject *__pyx_r = NULL;
33989   __Pyx_RefNannyDeclarations
33990   PyObject *__pyx_t_1 = NULL;
33991   int __pyx_lineno = 0;
33992   const char *__pyx_filename = NULL;
33993   int __pyx_clineno = 0;
33994   __Pyx_TraceDeclarations
33995   __Pyx_RefNannySetupContext("__get__", 0);
33996   __Pyx_TraceCall("__get__", __pyx_f[0], 3260);
33997   __Pyx_XDECREF(__pyx_r);
33998   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33999   __Pyx_GOTREF(__pyx_t_1);
34000   __pyx_r = __pyx_t_1;
34001   __pyx_t_1 = 0;
34002   goto __pyx_L0;
34003
34004   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
34005   goto __pyx_L0;
34006   __pyx_L1_error:;
34007   __Pyx_XDECREF(__pyx_t_1);
34008   __Pyx_AddTraceback("csamtools.SNPCall.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
34009   __pyx_r = NULL;
34010   __pyx_L0:;
34011   __Pyx_XGIVEREF(__pyx_r);
34012   __Pyx_TraceReturn(__pyx_r);
34013   __Pyx_RefNannyFinishContext();
34014   return __pyx_r;
34015 }
34016
34017 /* Python wrapper */
34018 static PyObject *__pyx_pw_9csamtools_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self); /*proto*/
34019 static PyObject *__pyx_pw_9csamtools_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self) {
34020   PyObject *__pyx_r = 0;
34021   __Pyx_RefNannyDeclarations
34022   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
34023   __pyx_r = __pyx_pf_9csamtools_7SNPCall_8coverage___get__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
34024   __Pyx_RefNannyFinishContext();
34025   return __pyx_r;
34026 }
34027
34028 /* "csamtools.pyx":3264
34029  *     property coverage:
34030  *        '''coverage or read depth - the number of reads involved in the call.'''
34031  *        def __get__(self): return self._coverage             # <<<<<<<<<<<<<<
34032  * 
34033  *     def __str__(self):
34034  */
34035
34036 static PyObject *__pyx_pf_9csamtools_7SNPCall_8coverage___get__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
34037   PyObject *__pyx_r = NULL;
34038   __Pyx_RefNannyDeclarations
34039   PyObject *__pyx_t_1 = NULL;
34040   int __pyx_lineno = 0;
34041   const char *__pyx_filename = NULL;
34042   int __pyx_clineno = 0;
34043   __Pyx_TraceDeclarations
34044   __Pyx_RefNannySetupContext("__get__", 0);
34045   __Pyx_TraceCall("__get__", __pyx_f[0], 3264);
34046   __Pyx_XDECREF(__pyx_r);
34047   __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34048   __Pyx_GOTREF(__pyx_t_1);
34049   __pyx_r = __pyx_t_1;
34050   __pyx_t_1 = 0;
34051   goto __pyx_L0;
34052
34053   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
34054   goto __pyx_L0;
34055   __pyx_L1_error:;
34056   __Pyx_XDECREF(__pyx_t_1);
34057   __Pyx_AddTraceback("csamtools.SNPCall.coverage.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
34058   __pyx_r = NULL;
34059   __pyx_L0:;
34060   __Pyx_XGIVEREF(__pyx_r);
34061   __Pyx_TraceReturn(__pyx_r);
34062   __Pyx_RefNannyFinishContext();
34063   return __pyx_r;
34064 }
34065
34066 /* Python wrapper */
34067 static PyObject *__pyx_pw_9csamtools_7SNPCall_1__str__(PyObject *__pyx_v_self); /*proto*/
34068 static PyObject *__pyx_pw_9csamtools_7SNPCall_1__str__(PyObject *__pyx_v_self) {
34069   PyObject *__pyx_r = 0;
34070   __Pyx_RefNannyDeclarations
34071   __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
34072   __pyx_r = __pyx_pf_9csamtools_7SNPCall___str__(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self));
34073   __Pyx_RefNannyFinishContext();
34074   return __pyx_r;
34075 }
34076
34077 /* "csamtools.pyx":3266
34078  *        def __get__(self): return self._coverage
34079  * 
34080  *     def __str__(self):             # <<<<<<<<<<<<<<
34081  * 
34082  *         return "\t".join( map(str, (
34083  */
34084
34085 static PyObject *__pyx_pf_9csamtools_7SNPCall___str__(struct __pyx_obj_9csamtools_SNPCall *__pyx_v_self) {
34086   PyObject *__pyx_r = NULL;
34087   __Pyx_RefNannyDeclarations
34088   PyObject *__pyx_t_1 = NULL;
34089   PyObject *__pyx_t_2 = NULL;
34090   PyObject *__pyx_t_3 = NULL;
34091   PyObject *__pyx_t_4 = NULL;
34092   PyObject *__pyx_t_5 = NULL;
34093   PyObject *__pyx_t_6 = NULL;
34094   PyObject *__pyx_t_7 = NULL;
34095   PyObject *__pyx_t_8 = NULL;
34096   PyObject *__pyx_t_9 = NULL;
34097   PyObject *__pyx_t_10 = NULL;
34098   int __pyx_lineno = 0;
34099   const char *__pyx_filename = NULL;
34100   int __pyx_clineno = 0;
34101   __Pyx_TraceDeclarations
34102   __Pyx_RefNannySetupContext("__str__", 0);
34103   __Pyx_TraceCall("__str__", __pyx_f[0], 3266);
34104
34105   /* "csamtools.pyx":3268
34106  *     def __str__(self):
34107  * 
34108  *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
34109  *                     self.tid,
34110  *                     self.pos,
34111  */
34112   __Pyx_XDECREF(__pyx_r);
34113   __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 = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34114   __Pyx_GOTREF(__pyx_t_1);
34115
34116   /* "csamtools.pyx":3269
34117  * 
34118  *         return "\t".join( map(str, (
34119  *                     self.tid,             # <<<<<<<<<<<<<<
34120  *                     self.pos,
34121  *                     self.reference_base,
34122  */
34123   __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 = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34124   __Pyx_GOTREF(__pyx_t_2);
34125
34126   /* "csamtools.pyx":3270
34127  *         return "\t".join( map(str, (
34128  *                     self.tid,
34129  *                     self.pos,             # <<<<<<<<<<<<<<
34130  *                     self.reference_base,
34131  *                     self.genotype,
34132  */
34133   __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 = 3270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34134   __Pyx_GOTREF(__pyx_t_3);
34135
34136   /* "csamtools.pyx":3271
34137  *                     self.tid,
34138  *                     self.pos,
34139  *                     self.reference_base,             # <<<<<<<<<<<<<<
34140  *                     self.genotype,
34141  *                     self.consensus_quality,
34142  */
34143   __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 = 3271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34144   __Pyx_GOTREF(__pyx_t_4);
34145
34146   /* "csamtools.pyx":3272
34147  *                     self.pos,
34148  *                     self.reference_base,
34149  *                     self.genotype,             # <<<<<<<<<<<<<<
34150  *                     self.consensus_quality,
34151  *                     self.snp_quality,
34152  */
34153   __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 = 3272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34154   __Pyx_GOTREF(__pyx_t_5);
34155
34156   /* "csamtools.pyx":3273
34157  *                     self.reference_base,
34158  *                     self.genotype,
34159  *                     self.consensus_quality,             # <<<<<<<<<<<<<<
34160  *                     self.snp_quality,
34161  *                     self.mapping_quality,
34162  */
34163   __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 = 3273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34164   __Pyx_GOTREF(__pyx_t_6);
34165
34166   /* "csamtools.pyx":3274
34167  *                     self.genotype,
34168  *                     self.consensus_quality,
34169  *                     self.snp_quality,             # <<<<<<<<<<<<<<
34170  *                     self.mapping_quality,
34171  *                     self.coverage ) ) )
34172  */
34173   __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 = 3274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34174   __Pyx_GOTREF(__pyx_t_7);
34175
34176   /* "csamtools.pyx":3275
34177  *                     self.consensus_quality,
34178  *                     self.snp_quality,
34179  *                     self.mapping_quality,             # <<<<<<<<<<<<<<
34180  *                     self.coverage ) ) )
34181  * 
34182  */
34183   __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 = 3275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34184   __Pyx_GOTREF(__pyx_t_8);
34185
34186   /* "csamtools.pyx":3276
34187  *                     self.snp_quality,
34188  *                     self.mapping_quality,
34189  *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
34190  * 
34191  * 
34192  */
34193   __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 = 3276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34194   __Pyx_GOTREF(__pyx_t_9);
34195   __pyx_t_10 = PyTuple_New(8); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34196   __Pyx_GOTREF(__pyx_t_10);
34197   PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
34198   __Pyx_GIVEREF(__pyx_t_2);
34199   PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
34200   __Pyx_GIVEREF(__pyx_t_3);
34201   PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4);
34202   __Pyx_GIVEREF(__pyx_t_4);
34203   PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_5);
34204   __Pyx_GIVEREF(__pyx_t_5);
34205   PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_6);
34206   __Pyx_GIVEREF(__pyx_t_6);
34207   PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_7);
34208   __Pyx_GIVEREF(__pyx_t_7);
34209   PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_8);
34210   __Pyx_GIVEREF(__pyx_t_8);
34211   PyTuple_SET_ITEM(__pyx_t_10, 7, __pyx_t_9);
34212   __Pyx_GIVEREF(__pyx_t_9);
34213   __pyx_t_2 = 0;
34214   __pyx_t_3 = 0;
34215   __pyx_t_4 = 0;
34216   __pyx_t_5 = 0;
34217   __pyx_t_6 = 0;
34218   __pyx_t_7 = 0;
34219   __pyx_t_8 = 0;
34220   __pyx_t_9 = 0;
34221   __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34222   __Pyx_GOTREF(__pyx_t_9);
34223   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
34224   PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
34225   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
34226   PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_t_10));
34227   __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
34228   __pyx_t_10 = 0;
34229   __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 = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34230   __Pyx_GOTREF(__pyx_t_10);
34231   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
34232   __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34233   __Pyx_GOTREF(__pyx_t_9);
34234   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
34235   __Pyx_GIVEREF(__pyx_t_10);
34236   __pyx_t_10 = 0;
34237   __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 = 3268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34238   __Pyx_GOTREF(__pyx_t_10);
34239   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34240   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
34241   __pyx_r = __pyx_t_10;
34242   __pyx_t_10 = 0;
34243   goto __pyx_L0;
34244
34245   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
34246   goto __pyx_L0;
34247   __pyx_L1_error:;
34248   __Pyx_XDECREF(__pyx_t_1);
34249   __Pyx_XDECREF(__pyx_t_2);
34250   __Pyx_XDECREF(__pyx_t_3);
34251   __Pyx_XDECREF(__pyx_t_4);
34252   __Pyx_XDECREF(__pyx_t_5);
34253   __Pyx_XDECREF(__pyx_t_6);
34254   __Pyx_XDECREF(__pyx_t_7);
34255   __Pyx_XDECREF(__pyx_t_8);
34256   __Pyx_XDECREF(__pyx_t_9);
34257   __Pyx_XDECREF(__pyx_t_10);
34258   __Pyx_AddTraceback("csamtools.SNPCall.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
34259   __pyx_r = NULL;
34260   __pyx_L0:;
34261   __Pyx_XGIVEREF(__pyx_r);
34262   __Pyx_TraceReturn(__pyx_r);
34263   __Pyx_RefNannyFinishContext();
34264   return __pyx_r;
34265 }
34266
34267 /* Python wrapper */
34268 static int __pyx_pw_9csamtools_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
34269 static int __pyx_pw_9csamtools_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
34270   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
34271   int __pyx_v_reopen;
34272   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__reopen,0};
34273   int __pyx_r;
34274   __Pyx_RefNannyDeclarations
34275   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
34276   {
34277     PyObject* values[2] = {0,0};
34278     if (unlikely(__pyx_kwds)) {
34279       Py_ssize_t kw_args;
34280       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
34281       switch (pos_args) {
34282         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
34283         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
34284         case  0: break;
34285         default: goto __pyx_L5_argtuple_error;
34286       }
34287       kw_args = PyDict_Size(__pyx_kwds);
34288       switch (pos_args) {
34289         case  0:
34290         values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
34291         if (likely(values[0])) kw_args--;
34292         else goto __pyx_L5_argtuple_error;
34293         case  1:
34294         if (kw_args > 0) {
34295           PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
34296           if (value) { values[1] = value; kw_args--; }
34297         }
34298       }
34299       if (unlikely(kw_args > 0)) {
34300         if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
34301       }
34302       if (values[1]) {
34303       } else {
34304
34305         /* "csamtools.pyx":3786
34306  *     """
34307  * 
34308  *     def __init__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
34309  *         self.samfile = samfile
34310  * 
34311  */
34312         __pyx_v_reopen = ((int)1);
34313       }
34314     } else {
34315       switch (PyTuple_GET_SIZE(__pyx_args)) {
34316         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
34317         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
34318         break;
34319         default: goto __pyx_L5_argtuple_error;
34320       }
34321     }
34322     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
34323     if (values[1]) {
34324       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
34325     } else {
34326       __pyx_v_reopen = ((int)1);
34327     }
34328   }
34329   goto __pyx_L4_argument_unpacking_done;
34330   __pyx_L5_argtuple_error:;
34331   __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
34332   __pyx_L3_error:;
34333   __Pyx_AddTraceback("csamtools.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
34334   __Pyx_RefNannyFinishContext();
34335   return -1;
34336   __pyx_L4_argument_unpacking_done:;
34337   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34338   __pyx_r = __pyx_pf_9csamtools_12IndexedReads___init__(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_reopen);
34339   goto __pyx_L0;
34340   __pyx_L1_error:;
34341   __pyx_r = -1;
34342   __pyx_L0:;
34343   __Pyx_RefNannyFinishContext();
34344   return __pyx_r;
34345 }
34346
34347 static int __pyx_pf_9csamtools_12IndexedReads___init__(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self, struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile, int __pyx_v_reopen) {
34348   PyObject *__pyx_v_mode = NULL;
34349   PyObject *__pyx_v_store = NULL;
34350   int __pyx_r;
34351   __Pyx_RefNannyDeclarations
34352   PyObject *__pyx_t_1 = NULL;
34353   PyObject *__pyx_t_2 = NULL;
34354   char *__pyx_t_3;
34355   int __pyx_lineno = 0;
34356   const char *__pyx_filename = NULL;
34357   int __pyx_clineno = 0;
34358   __Pyx_TraceDeclarations
34359   __Pyx_RefNannySetupContext("__init__", 0);
34360   __Pyx_TraceCall("__init__", __pyx_f[0], 3786);
34361
34362   /* "csamtools.pyx":3787
34363  * 
34364  *     def __init__(self, Samfile samfile, int reopen = True ):
34365  *         self.samfile = samfile             # <<<<<<<<<<<<<<
34366  * 
34367  *         if samfile.isbam: mode = b"rb"
34368  */
34369   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
34370   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
34371   __Pyx_GOTREF(__pyx_v_self->samfile);
34372   __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
34373   __pyx_v_self->samfile = __pyx_v_samfile;
34374
34375   /* "csamtools.pyx":3789
34376  *         self.samfile = samfile
34377  * 
34378  *         if samfile.isbam: mode = b"rb"             # <<<<<<<<<<<<<<
34379  *         else: mode = b"r"
34380  * 
34381  */
34382   if (__pyx_v_samfile->isbam) {
34383     __Pyx_INCREF(((PyObject *)__pyx_n_b__rb));
34384     __pyx_v_mode = __pyx_n_b__rb;
34385     goto __pyx_L3;
34386   }
34387   /*else*/ {
34388
34389     /* "csamtools.pyx":3790
34390  * 
34391  *         if samfile.isbam: mode = b"rb"
34392  *         else: mode = b"r"             # <<<<<<<<<<<<<<
34393  * 
34394  *         # reopen the file - note that this makes the iterator
34395  */
34396     __Pyx_INCREF(((PyObject *)__pyx_n_b__r));
34397     __pyx_v_mode = __pyx_n_b__r;
34398   }
34399   __pyx_L3:;
34400
34401   /* "csamtools.pyx":3794
34402  *         # reopen the file - note that this makes the iterator
34403  *         # slow and causes pileup to slow down significantly.
34404  *         if reopen:             # <<<<<<<<<<<<<<
34405  *             store = StderrStore()
34406  *             self.fp = samopen( samfile._filename, mode, NULL )
34407  */
34408   if (__pyx_v_reopen) {
34409
34410     /* "csamtools.pyx":3795
34411  *         # slow and causes pileup to slow down significantly.
34412  *         if reopen:
34413  *             store = StderrStore()             # <<<<<<<<<<<<<<
34414  *             self.fp = samopen( samfile._filename, mode, NULL )
34415  *             store.release()
34416  */
34417     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34418     __Pyx_GOTREF(__pyx_t_1);
34419     __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 = 3795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34420     __Pyx_GOTREF(__pyx_t_2);
34421     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34422     __pyx_v_store = __pyx_t_2;
34423     __pyx_t_2 = 0;
34424
34425     /* "csamtools.pyx":3796
34426  *         if reopen:
34427  *             store = StderrStore()
34428  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
34429  *             store.release()
34430  *             assert self.fp != NULL
34431  */
34432     __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_mode)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34433     __pyx_v_self->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_3, NULL);
34434
34435     /* "csamtools.pyx":3797
34436  *             store = StderrStore()
34437  *             self.fp = samopen( samfile._filename, mode, NULL )
34438  *             store.release()             # <<<<<<<<<<<<<<
34439  *             assert self.fp != NULL
34440  *             self.owns_samfile = True
34441  */
34442     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34443     __Pyx_GOTREF(__pyx_t_2);
34444     __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 = 3797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34445     __Pyx_GOTREF(__pyx_t_1);
34446     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
34447     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34448
34449     /* "csamtools.pyx":3798
34450  *             self.fp = samopen( samfile._filename, mode, NULL )
34451  *             store.release()
34452  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
34453  *             self.owns_samfile = True
34454  *         else:
34455  */
34456     #ifndef CYTHON_WITHOUT_ASSERTIONS
34457     if (unlikely(!(__pyx_v_self->fp != NULL))) {
34458       PyErr_SetNone(PyExc_AssertionError);
34459       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34460     }
34461     #endif
34462
34463     /* "csamtools.pyx":3799
34464  *             store.release()
34465  *             assert self.fp != NULL
34466  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
34467  *         else:
34468  *             self.fp = samfile.samfile
34469  */
34470     __pyx_v_self->owns_samfile = 1;
34471     goto __pyx_L4;
34472   }
34473   /*else*/ {
34474
34475     /* "csamtools.pyx":3801
34476  *             self.owns_samfile = True
34477  *         else:
34478  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
34479  *             self.owns_samfile = False
34480  * 
34481  */
34482     __pyx_v_self->fp = __pyx_v_samfile->samfile;
34483
34484     /* "csamtools.pyx":3802
34485  *         else:
34486  *             self.fp = samfile.samfile
34487  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
34488  * 
34489  *         assert samfile.isbam, "can only IndexReads on bam files"
34490  */
34491     __pyx_v_self->owns_samfile = 0;
34492   }
34493   __pyx_L4:;
34494
34495   /* "csamtools.pyx":3804
34496  *             self.owns_samfile = False
34497  * 
34498  *         assert samfile.isbam, "can only IndexReads on bam files"             # <<<<<<<<<<<<<<
34499  * 
34500  *     def build( self ):
34501  */
34502   #ifndef CYTHON_WITHOUT_ASSERTIONS
34503   if (unlikely(!__pyx_v_samfile->isbam)) {
34504     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_185));
34505     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34506   }
34507   #endif
34508
34509   __pyx_r = 0;
34510   goto __pyx_L0;
34511   __pyx_L1_error:;
34512   __Pyx_XDECREF(__pyx_t_1);
34513   __Pyx_XDECREF(__pyx_t_2);
34514   __Pyx_AddTraceback("csamtools.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
34515   __pyx_r = -1;
34516   __pyx_L0:;
34517   __Pyx_XDECREF(__pyx_v_mode);
34518   __Pyx_XDECREF(__pyx_v_store);
34519   __Pyx_TraceReturn(Py_None);
34520   __Pyx_RefNannyFinishContext();
34521   return __pyx_r;
34522 }
34523
34524 /* Python wrapper */
34525 static PyObject *__pyx_pw_9csamtools_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
34526 static char __pyx_doc_9csamtools_12IndexedReads_2build[] = "IndexedReads.build(self)\nbuild index.";
34527 static PyObject *__pyx_pw_9csamtools_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
34528   PyObject *__pyx_r = 0;
34529   __Pyx_RefNannyDeclarations
34530   __Pyx_RefNannySetupContext("build (wrapper)", 0);
34531   __pyx_r = __pyx_pf_9csamtools_12IndexedReads_2build(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self));
34532   __Pyx_RefNannyFinishContext();
34533   return __pyx_r;
34534 }
34535
34536 /* "csamtools.pyx":3806
34537  *         assert samfile.isbam, "can only IndexReads on bam files"
34538  * 
34539  *     def build( self ):             # <<<<<<<<<<<<<<
34540  *         '''build index.'''
34541  * 
34542  */
34543
34544 static PyObject *__pyx_pf_9csamtools_12IndexedReads_2build(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self) {
34545   int __pyx_v_ret;
34546   bam1_t *__pyx_v_b;
34547   uint64_t __pyx_v_pos;
34548   PyObject *__pyx_v_qname = NULL;
34549   PyObject *__pyx_r = NULL;
34550   __Pyx_RefNannyDeclarations
34551   PyObject *__pyx_t_1 = NULL;
34552   PyObject *__pyx_t_2 = NULL;
34553   PyObject *__pyx_t_3 = NULL;
34554   int __pyx_t_4;
34555   int __pyx_lineno = 0;
34556   const char *__pyx_filename = NULL;
34557   int __pyx_clineno = 0;
34558   __Pyx_TraceDeclarations
34559   __Pyx_RefNannySetupContext("build", 0);
34560   __Pyx_TraceCall("build", __pyx_f[0], 3806);
34561
34562   /* "csamtools.pyx":3809
34563  *         '''build index.'''
34564  * 
34565  *         self.index = collections.defaultdict( list )             # <<<<<<<<<<<<<<
34566  * 
34567  *         # this method will start indexing from the current file position
34568  */
34569   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__collections); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34570   __Pyx_GOTREF(__pyx_t_1);
34571   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__defaultdict); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34572   __Pyx_GOTREF(__pyx_t_2);
34573   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34574   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34575   __Pyx_GOTREF(__pyx_t_1);
34576   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
34577   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyList_Type))));
34578   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
34579   __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 = 3809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34580   __Pyx_GOTREF(__pyx_t_3);
34581   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
34582   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
34583   __Pyx_GIVEREF(__pyx_t_3);
34584   __Pyx_GOTREF(__pyx_v_self->index);
34585   __Pyx_DECREF(__pyx_v_self->index);
34586   __pyx_v_self->index = __pyx_t_3;
34587   __pyx_t_3 = 0;
34588
34589   /* "csamtools.pyx":3813
34590  *         # this method will start indexing from the current file position
34591  *         # if you decide
34592  *         cdef int ret = 1             # <<<<<<<<<<<<<<
34593  *         cdef bam1_t * b = <bam1_t*> calloc(1, sizeof( bam1_t) )
34594  * 
34595  */
34596   __pyx_v_ret = 1;
34597
34598   /* "csamtools.pyx":3814
34599  *         # if you decide
34600  *         cdef int ret = 1
34601  *         cdef bam1_t * b = <bam1_t*> calloc(1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
34602  * 
34603  *         cdef uint64_t pos
34604  */
34605   __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
34606
34607   /* "csamtools.pyx":3818
34608  *         cdef uint64_t pos
34609  * 
34610  *         while ret > 0:             # <<<<<<<<<<<<<<
34611  *             pos = bam_tell( self.fp.x.bam )
34612  *             ret = samread( self.fp, b)
34613  */
34614   while (1) {
34615     __pyx_t_4 = (__pyx_v_ret > 0);
34616     if (!__pyx_t_4) break;
34617
34618     /* "csamtools.pyx":3819
34619  * 
34620  *         while ret > 0:
34621  *             pos = bam_tell( self.fp.x.bam )             # <<<<<<<<<<<<<<
34622  *             ret = samread( self.fp, b)
34623  *             if ret > 0:
34624  */
34625     __pyx_v_pos = bam_tell(__pyx_v_self->fp->x.bam);
34626
34627     /* "csamtools.pyx":3820
34628  *         while ret > 0:
34629  *             pos = bam_tell( self.fp.x.bam )
34630  *             ret = samread( self.fp, b)             # <<<<<<<<<<<<<<
34631  *             if ret > 0:
34632  *                 qname = _charptr_to_str(bam1_qname( b ))
34633  */
34634     __pyx_v_ret = samread(__pyx_v_self->fp, __pyx_v_b);
34635
34636     /* "csamtools.pyx":3821
34637  *             pos = bam_tell( self.fp.x.bam )
34638  *             ret = samread( self.fp, b)
34639  *             if ret > 0:             # <<<<<<<<<<<<<<
34640  *                 qname = _charptr_to_str(bam1_qname( b ))
34641  *                 self.index[qname].append( pos )
34642  */
34643     __pyx_t_4 = (__pyx_v_ret > 0);
34644     if (__pyx_t_4) {
34645
34646       /* "csamtools.pyx":3822
34647  *             ret = samread( self.fp, b)
34648  *             if ret > 0:
34649  *                 qname = _charptr_to_str(bam1_qname( b ))             # <<<<<<<<<<<<<<
34650  *                 self.index[qname].append( pos )
34651  * 
34652  */
34653       __pyx_t_3 = __pyx_f_9csamtools__charptr_to_str(bam1_qname(__pyx_v_b)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34654       __Pyx_GOTREF(__pyx_t_3);
34655       __Pyx_XDECREF(__pyx_v_qname);
34656       __pyx_v_qname = __pyx_t_3;
34657       __pyx_t_3 = 0;
34658
34659       /* "csamtools.pyx":3823
34660  *             if ret > 0:
34661  *                 qname = _charptr_to_str(bam1_qname( b ))
34662  *                 self.index[qname].append( pos )             # <<<<<<<<<<<<<<
34663  * 
34664  *         bam_destroy1( b )
34665  */
34666       __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34667       __Pyx_GOTREF(__pyx_t_3);
34668       __pyx_t_1 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34669       __Pyx_GOTREF(__pyx_t_1);
34670       __pyx_t_2 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34671       __Pyx_GOTREF(__pyx_t_2);
34672       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
34673       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
34674       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
34675       goto __pyx_L5;
34676     }
34677     __pyx_L5:;
34678   }
34679
34680   /* "csamtools.pyx":3825
34681  *                 self.index[qname].append( pos )
34682  * 
34683  *         bam_destroy1( b )             # <<<<<<<<<<<<<<
34684  * 
34685  *     def find( self, qname ):
34686  */
34687   bam_destroy1(__pyx_v_b);
34688
34689   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
34690   goto __pyx_L0;
34691   __pyx_L1_error:;
34692   __Pyx_XDECREF(__pyx_t_1);
34693   __Pyx_XDECREF(__pyx_t_2);
34694   __Pyx_XDECREF(__pyx_t_3);
34695   __Pyx_AddTraceback("csamtools.IndexedReads.build", __pyx_clineno, __pyx_lineno, __pyx_filename);
34696   __pyx_r = NULL;
34697   __pyx_L0:;
34698   __Pyx_XDECREF(__pyx_v_qname);
34699   __Pyx_XGIVEREF(__pyx_r);
34700   __Pyx_TraceReturn(__pyx_r);
34701   __Pyx_RefNannyFinishContext();
34702   return __pyx_r;
34703 }
34704
34705 /* Python wrapper */
34706 static PyObject *__pyx_pw_9csamtools_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
34707 static char __pyx_doc_9csamtools_12IndexedReads_4find[] = "IndexedReads.find(self, qname)";
34708 static PyObject *__pyx_pw_9csamtools_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
34709   PyObject *__pyx_r = 0;
34710   __Pyx_RefNannyDeclarations
34711   __Pyx_RefNannySetupContext("find (wrapper)", 0);
34712   __pyx_r = __pyx_pf_9csamtools_12IndexedReads_4find(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self), ((PyObject *)__pyx_v_qname));
34713   __Pyx_RefNannyFinishContext();
34714   return __pyx_r;
34715 }
34716
34717 /* "csamtools.pyx":3827
34718  *         bam_destroy1( b )
34719  * 
34720  *     def find( self, qname ):             # <<<<<<<<<<<<<<
34721  *         if qname in self.index:
34722  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
34723  */
34724
34725 static PyObject *__pyx_pf_9csamtools_12IndexedReads_4find(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self, PyObject *__pyx_v_qname) {
34726   PyObject *__pyx_r = NULL;
34727   __Pyx_RefNannyDeclarations
34728   int __pyx_t_1;
34729   PyObject *__pyx_t_2 = NULL;
34730   PyObject *__pyx_t_3 = NULL;
34731   PyObject *__pyx_t_4 = NULL;
34732   int __pyx_lineno = 0;
34733   const char *__pyx_filename = NULL;
34734   int __pyx_clineno = 0;
34735   __Pyx_TraceDeclarations
34736   __Pyx_RefNannySetupContext("find", 0);
34737   __Pyx_TraceCall("find", __pyx_f[0], 3827);
34738
34739   /* "csamtools.pyx":3828
34740  * 
34741  *     def find( self, qname ):
34742  *         if qname in self.index:             # <<<<<<<<<<<<<<
34743  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
34744  *         else:
34745  */
34746   __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->index, __pyx_v_qname))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34747   if (__pyx_t_1) {
34748
34749     /* "csamtools.pyx":3829
34750  *     def find( self, qname ):
34751  *         if qname in self.index:
34752  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )             # <<<<<<<<<<<<<<
34753  *         else:
34754  *             raise KeyError( "read %s not found" % qname )
34755  */
34756     __Pyx_XDECREF(__pyx_r);
34757     __pyx_t_2 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34758     __Pyx_GOTREF(__pyx_t_2);
34759     __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34760     __Pyx_GOTREF(__pyx_t_3);
34761     __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
34762     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->samfile));
34763     __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
34764     PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
34765     __Pyx_GIVEREF(__pyx_t_2);
34766     __pyx_t_2 = 0;
34767     __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34768     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
34769     __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34770     __Pyx_GOTREF(__pyx_t_4);
34771     if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34772     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
34773     __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorRowSelection)), ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34774     __Pyx_GOTREF(__pyx_t_4);
34775     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
34776     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
34777     __pyx_r = __pyx_t_4;
34778     __pyx_t_4 = 0;
34779     goto __pyx_L0;
34780     goto __pyx_L3;
34781   }
34782   /*else*/ {
34783
34784     /* "csamtools.pyx":3831
34785  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
34786  *         else:
34787  *             raise KeyError( "read %s not found" % qname )             # <<<<<<<<<<<<<<
34788  * 
34789  *     def __dealloc__(self):
34790  */
34791     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_186), __pyx_v_qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34792     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
34793     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34794     __Pyx_GOTREF(__pyx_t_2);
34795     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
34796     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
34797     __pyx_t_4 = 0;
34798     __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 = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34799     __Pyx_GOTREF(__pyx_t_4);
34800     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
34801     __Pyx_Raise(__pyx_t_4, 0, 0, 0);
34802     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
34803     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
34804   }
34805   __pyx_L3:;
34806
34807   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
34808   goto __pyx_L0;
34809   __pyx_L1_error:;
34810   __Pyx_XDECREF(__pyx_t_2);
34811   __Pyx_XDECREF(__pyx_t_3);
34812   __Pyx_XDECREF(__pyx_t_4);
34813   __Pyx_AddTraceback("csamtools.IndexedReads.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
34814   __pyx_r = NULL;
34815   __pyx_L0:;
34816   __Pyx_XGIVEREF(__pyx_r);
34817   __Pyx_TraceReturn(__pyx_r);
34818   __Pyx_RefNannyFinishContext();
34819   return __pyx_r;
34820 }
34821
34822 /* Python wrapper */
34823 static void __pyx_pw_9csamtools_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
34824 static void __pyx_pw_9csamtools_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self) {
34825   __Pyx_RefNannyDeclarations
34826   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
34827   __pyx_pf_9csamtools_12IndexedReads_6__dealloc__(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self));
34828   __Pyx_RefNannyFinishContext();
34829 }
34830
34831 /* "csamtools.pyx":3833
34832  *             raise KeyError( "read %s not found" % qname )
34833  * 
34834  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
34835  *         if self.owns_samfile: samclose( self.fp )
34836  * 
34837  */
34838
34839 static void __pyx_pf_9csamtools_12IndexedReads_6__dealloc__(struct __pyx_obj_9csamtools_IndexedReads *__pyx_v_self) {
34840   __Pyx_RefNannyDeclarations
34841   __Pyx_TraceDeclarations
34842   __Pyx_RefNannySetupContext("__dealloc__", 0);
34843   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3833);
34844
34845   /* "csamtools.pyx":3834
34846  * 
34847  *     def __dealloc__(self):
34848  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
34849  * 
34850  * __all__ = ["Samfile",
34851  */
34852   if (__pyx_v_self->owns_samfile) {
34853     samclose(__pyx_v_self->fp);
34854     goto __pyx_L3;
34855   }
34856   __pyx_L3:;
34857
34858   __Pyx_TraceReturn(Py_None);
34859   __Pyx_RefNannyFinishContext();
34860 }
34861 static struct __pyx_vtabstruct_9csamtools_Fastafile __pyx_vtable_9csamtools_Fastafile;
34862
34863 static PyObject *__pyx_tp_new_9csamtools_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k) {
34864   struct __pyx_obj_9csamtools_Fastafile *p;
34865   PyObject *o = (*t->tp_alloc)(t, 0);
34866   if (!o) return 0;
34867   p = ((struct __pyx_obj_9csamtools_Fastafile *)o);
34868   p->__pyx_vtab = __pyx_vtabptr_9csamtools_Fastafile;
34869   if (__pyx_pw_9csamtools_9Fastafile_1__cinit__(o, a, k) < 0) {
34870     Py_DECREF(o); o = 0;
34871   }
34872   return o;
34873 }
34874
34875 static void __pyx_tp_dealloc_9csamtools_Fastafile(PyObject *o) {
34876   {
34877     PyObject *etype, *eval, *etb;
34878     PyErr_Fetch(&etype, &eval, &etb);
34879     ++Py_REFCNT(o);
34880     __pyx_pw_9csamtools_9Fastafile_11__dealloc__(o);
34881     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
34882     --Py_REFCNT(o);
34883     PyErr_Restore(etype, eval, etb);
34884   }
34885   (*Py_TYPE(o)->tp_free)(o);
34886 }
34887
34888 static PyObject *__pyx_getprop_9csamtools_9Fastafile_filename(PyObject *o, void *x) {
34889   return __pyx_pw_9csamtools_9Fastafile_8filename_1__get__(o);
34890 }
34891
34892 static PyMethodDef __pyx_methods_9csamtools_Fastafile[] = {
34893   {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_9csamtools_9Fastafile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_2_isOpen)},
34894   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_9csamtools_9Fastafile_7_open, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_6_open)},
34895   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_9csamtools_9Fastafile_9close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_8close)},
34896   {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_9csamtools_9Fastafile_13fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_12fetch)},
34897   {0, 0, 0, 0}
34898 };
34899
34900 static struct PyGetSetDef __pyx_getsets_9csamtools_Fastafile[] = {
34901   {(char *)"filename", __pyx_getprop_9csamtools_9Fastafile_filename, 0, __Pyx_DOCSTR(__pyx_k_187), 0},
34902   {0, 0, 0, 0, 0}
34903 };
34904
34905 static PyNumberMethods __pyx_tp_as_number_Fastafile = {
34906   0, /*nb_add*/
34907   0, /*nb_subtract*/
34908   0, /*nb_multiply*/
34909   #if PY_MAJOR_VERSION < 3
34910   0, /*nb_divide*/
34911   #endif
34912   0, /*nb_remainder*/
34913   0, /*nb_divmod*/
34914   0, /*nb_power*/
34915   0, /*nb_negative*/
34916   0, /*nb_positive*/
34917   0, /*nb_absolute*/
34918   0, /*nb_nonzero*/
34919   0, /*nb_invert*/
34920   0, /*nb_lshift*/
34921   0, /*nb_rshift*/
34922   0, /*nb_and*/
34923   0, /*nb_xor*/
34924   0, /*nb_or*/
34925   #if PY_MAJOR_VERSION < 3
34926   0, /*nb_coerce*/
34927   #endif
34928   0, /*nb_int*/
34929   #if PY_MAJOR_VERSION < 3
34930   0, /*nb_long*/
34931   #else
34932   0, /*reserved*/
34933   #endif
34934   0, /*nb_float*/
34935   #if PY_MAJOR_VERSION < 3
34936   0, /*nb_oct*/
34937   #endif
34938   #if PY_MAJOR_VERSION < 3
34939   0, /*nb_hex*/
34940   #endif
34941   0, /*nb_inplace_add*/
34942   0, /*nb_inplace_subtract*/
34943   0, /*nb_inplace_multiply*/
34944   #if PY_MAJOR_VERSION < 3
34945   0, /*nb_inplace_divide*/
34946   #endif
34947   0, /*nb_inplace_remainder*/
34948   0, /*nb_inplace_power*/
34949   0, /*nb_inplace_lshift*/
34950   0, /*nb_inplace_rshift*/
34951   0, /*nb_inplace_and*/
34952   0, /*nb_inplace_xor*/
34953   0, /*nb_inplace_or*/
34954   0, /*nb_floor_divide*/
34955   0, /*nb_true_divide*/
34956   0, /*nb_inplace_floor_divide*/
34957   0, /*nb_inplace_true_divide*/
34958   #if PY_VERSION_HEX >= 0x02050000
34959   0, /*nb_index*/
34960   #endif
34961 };
34962
34963 static PySequenceMethods __pyx_tp_as_sequence_Fastafile = {
34964   __pyx_pw_9csamtools_9Fastafile_5__len__, /*sq_length*/
34965   0, /*sq_concat*/
34966   0, /*sq_repeat*/
34967   0, /*sq_item*/
34968   0, /*sq_slice*/
34969   0, /*sq_ass_item*/
34970   0, /*sq_ass_slice*/
34971   0, /*sq_contains*/
34972   0, /*sq_inplace_concat*/
34973   0, /*sq_inplace_repeat*/
34974 };
34975
34976 static PyMappingMethods __pyx_tp_as_mapping_Fastafile = {
34977   __pyx_pw_9csamtools_9Fastafile_5__len__, /*mp_length*/
34978   0, /*mp_subscript*/
34979   0, /*mp_ass_subscript*/
34980 };
34981
34982 static PyBufferProcs __pyx_tp_as_buffer_Fastafile = {
34983   #if PY_MAJOR_VERSION < 3
34984   0, /*bf_getreadbuffer*/
34985   #endif
34986   #if PY_MAJOR_VERSION < 3
34987   0, /*bf_getwritebuffer*/
34988   #endif
34989   #if PY_MAJOR_VERSION < 3
34990   0, /*bf_getsegcount*/
34991   #endif
34992   #if PY_MAJOR_VERSION < 3
34993   0, /*bf_getcharbuffer*/
34994   #endif
34995   #if PY_VERSION_HEX >= 0x02060000
34996   0, /*bf_getbuffer*/
34997   #endif
34998   #if PY_VERSION_HEX >= 0x02060000
34999   0, /*bf_releasebuffer*/
35000   #endif
35001 };
35002
35003 static PyTypeObject __pyx_type_9csamtools_Fastafile = {
35004   PyVarObject_HEAD_INIT(0, 0)
35005   __Pyx_NAMESTR("csamtools.Fastafile"), /*tp_name*/
35006   sizeof(struct __pyx_obj_9csamtools_Fastafile), /*tp_basicsize*/
35007   0, /*tp_itemsize*/
35008   __pyx_tp_dealloc_9csamtools_Fastafile, /*tp_dealloc*/
35009   0, /*tp_print*/
35010   0, /*tp_getattr*/
35011   0, /*tp_setattr*/
35012   #if PY_MAJOR_VERSION < 3
35013   0, /*tp_compare*/
35014   #else
35015   0, /*reserved*/
35016   #endif
35017   0, /*tp_repr*/
35018   &__pyx_tp_as_number_Fastafile, /*tp_as_number*/
35019   &__pyx_tp_as_sequence_Fastafile, /*tp_as_sequence*/
35020   &__pyx_tp_as_mapping_Fastafile, /*tp_as_mapping*/
35021   0, /*tp_hash*/
35022   0, /*tp_call*/
35023   0, /*tp_str*/
35024   0, /*tp_getattro*/
35025   0, /*tp_setattro*/
35026   &__pyx_tp_as_buffer_Fastafile, /*tp_as_buffer*/
35027   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
35028   __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*/
35029   0, /*tp_traverse*/
35030   0, /*tp_clear*/
35031   0, /*tp_richcompare*/
35032   0, /*tp_weaklistoffset*/
35033   0, /*tp_iter*/
35034   0, /*tp_iternext*/
35035   __pyx_methods_9csamtools_Fastafile, /*tp_methods*/
35036   0, /*tp_members*/
35037   __pyx_getsets_9csamtools_Fastafile, /*tp_getset*/
35038   0, /*tp_base*/
35039   0, /*tp_dict*/
35040   0, /*tp_descr_get*/
35041   0, /*tp_descr_set*/
35042   0, /*tp_dictoffset*/
35043   0, /*tp_init*/
35044   0, /*tp_alloc*/
35045   __pyx_tp_new_9csamtools_Fastafile, /*tp_new*/
35046   0, /*tp_free*/
35047   0, /*tp_is_gc*/
35048   0, /*tp_bases*/
35049   0, /*tp_mro*/
35050   0, /*tp_cache*/
35051   0, /*tp_subclasses*/
35052   0, /*tp_weaklist*/
35053   0, /*tp_del*/
35054   #if PY_VERSION_HEX >= 0x02060000
35055   0, /*tp_version_tag*/
35056   #endif
35057 };
35058
35059 static PyObject *__pyx_tp_new_9csamtools_AlignedRead(PyTypeObject *t, PyObject *a, PyObject *k) {
35060   PyObject *o = (*t->tp_alloc)(t, 0);
35061   if (!o) return 0;
35062   return o;
35063 }
35064
35065 static void __pyx_tp_dealloc_9csamtools_AlignedRead(PyObject *o) {
35066   {
35067     PyObject *etype, *eval, *etb;
35068     PyErr_Fetch(&etype, &eval, &etb);
35069     ++Py_REFCNT(o);
35070     __pyx_pw_9csamtools_11AlignedRead_3__dealloc__(o);
35071     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
35072     --Py_REFCNT(o);
35073     PyErr_Restore(etype, eval, etb);
35074   }
35075   (*Py_TYPE(o)->tp_free)(o);
35076 }
35077
35078 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qname(PyObject *o, void *x) {
35079   return __pyx_pw_9csamtools_11AlignedRead_5qname_1__get__(o);
35080 }
35081
35082 static int __pyx_setprop_9csamtools_11AlignedRead_qname(PyObject *o, PyObject *v, void *x) {
35083   if (v) {
35084     return __pyx_pw_9csamtools_11AlignedRead_5qname_3__set__(o, v);
35085   }
35086   else {
35087     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35088     return -1;
35089   }
35090 }
35091
35092 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_cigar(PyObject *o, void *x) {
35093   return __pyx_pw_9csamtools_11AlignedRead_5cigar_1__get__(o);
35094 }
35095
35096 static int __pyx_setprop_9csamtools_11AlignedRead_cigar(PyObject *o, PyObject *v, void *x) {
35097   if (v) {
35098     return __pyx_pw_9csamtools_11AlignedRead_5cigar_3__set__(o, v);
35099   }
35100   else {
35101     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35102     return -1;
35103   }
35104 }
35105
35106 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_cigarstring(PyObject *o, void *x) {
35107   return __pyx_pw_9csamtools_11AlignedRead_11cigarstring_1__get__(o);
35108 }
35109
35110 static int __pyx_setprop_9csamtools_11AlignedRead_cigarstring(PyObject *o, PyObject *v, void *x) {
35111   if (v) {
35112     return __pyx_pw_9csamtools_11AlignedRead_11cigarstring_3__set__(o, v);
35113   }
35114   else {
35115     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35116     return -1;
35117   }
35118 }
35119
35120 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_seq(PyObject *o, void *x) {
35121   return __pyx_pw_9csamtools_11AlignedRead_3seq_1__get__(o);
35122 }
35123
35124 static int __pyx_setprop_9csamtools_11AlignedRead_seq(PyObject *o, PyObject *v, void *x) {
35125   if (v) {
35126     return __pyx_pw_9csamtools_11AlignedRead_3seq_3__set__(o, v);
35127   }
35128   else {
35129     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35130     return -1;
35131   }
35132 }
35133
35134 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qual(PyObject *o, void *x) {
35135   return __pyx_pw_9csamtools_11AlignedRead_4qual_1__get__(o);
35136 }
35137
35138 static int __pyx_setprop_9csamtools_11AlignedRead_qual(PyObject *o, PyObject *v, void *x) {
35139   if (v) {
35140     return __pyx_pw_9csamtools_11AlignedRead_4qual_3__set__(o, v);
35141   }
35142   else {
35143     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35144     return -1;
35145   }
35146 }
35147
35148 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_query(PyObject *o, void *x) {
35149   return __pyx_pw_9csamtools_11AlignedRead_5query_1__get__(o);
35150 }
35151
35152 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qqual(PyObject *o, void *x) {
35153   return __pyx_pw_9csamtools_11AlignedRead_5qqual_1__get__(o);
35154 }
35155
35156 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qstart(PyObject *o, void *x) {
35157   return __pyx_pw_9csamtools_11AlignedRead_6qstart_1__get__(o);
35158 }
35159
35160 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qend(PyObject *o, void *x) {
35161   return __pyx_pw_9csamtools_11AlignedRead_4qend_1__get__(o);
35162 }
35163
35164 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qlen(PyObject *o, void *x) {
35165   return __pyx_pw_9csamtools_11AlignedRead_4qlen_1__get__(o);
35166 }
35167
35168 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tags(PyObject *o, void *x) {
35169   return __pyx_pw_9csamtools_11AlignedRead_4tags_1__get__(o);
35170 }
35171
35172 static int __pyx_setprop_9csamtools_11AlignedRead_tags(PyObject *o, PyObject *v, void *x) {
35173   if (v) {
35174     return __pyx_pw_9csamtools_11AlignedRead_4tags_3__set__(o, v);
35175   }
35176   else {
35177     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35178     return -1;
35179   }
35180 }
35181
35182 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_flag(PyObject *o, void *x) {
35183   return __pyx_pw_9csamtools_11AlignedRead_4flag_1__get__(o);
35184 }
35185
35186 static int __pyx_setprop_9csamtools_11AlignedRead_flag(PyObject *o, PyObject *v, void *x) {
35187   if (v) {
35188     return __pyx_pw_9csamtools_11AlignedRead_4flag_3__set__(o, v);
35189   }
35190   else {
35191     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35192     return -1;
35193   }
35194 }
35195
35196 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rname(PyObject *o, void *x) {
35197   return __pyx_pw_9csamtools_11AlignedRead_5rname_1__get__(o);
35198 }
35199
35200 static int __pyx_setprop_9csamtools_11AlignedRead_rname(PyObject *o, PyObject *v, void *x) {
35201   if (v) {
35202     return __pyx_pw_9csamtools_11AlignedRead_5rname_3__set__(o, v);
35203   }
35204   else {
35205     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35206     return -1;
35207   }
35208 }
35209
35210 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tid(PyObject *o, void *x) {
35211   return __pyx_pw_9csamtools_11AlignedRead_3tid_1__get__(o);
35212 }
35213
35214 static int __pyx_setprop_9csamtools_11AlignedRead_tid(PyObject *o, PyObject *v, void *x) {
35215   if (v) {
35216     return __pyx_pw_9csamtools_11AlignedRead_3tid_3__set__(o, v);
35217   }
35218   else {
35219     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35220     return -1;
35221   }
35222 }
35223
35224 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_pos(PyObject *o, void *x) {
35225   return __pyx_pw_9csamtools_11AlignedRead_3pos_1__get__(o);
35226 }
35227
35228 static int __pyx_setprop_9csamtools_11AlignedRead_pos(PyObject *o, PyObject *v, void *x) {
35229   if (v) {
35230     return __pyx_pw_9csamtools_11AlignedRead_3pos_3__set__(o, v);
35231   }
35232   else {
35233     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35234     return -1;
35235   }
35236 }
35237
35238 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_bin(PyObject *o, void *x) {
35239   return __pyx_pw_9csamtools_11AlignedRead_3bin_1__get__(o);
35240 }
35241
35242 static int __pyx_setprop_9csamtools_11AlignedRead_bin(PyObject *o, PyObject *v, void *x) {
35243   if (v) {
35244     return __pyx_pw_9csamtools_11AlignedRead_3bin_3__set__(o, v);
35245   }
35246   else {
35247     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35248     return -1;
35249   }
35250 }
35251
35252 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rlen(PyObject *o, void *x) {
35253   return __pyx_pw_9csamtools_11AlignedRead_4rlen_1__get__(o);
35254 }
35255
35256 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_aend(PyObject *o, void *x) {
35257   return __pyx_pw_9csamtools_11AlignedRead_4aend_1__get__(o);
35258 }
35259
35260 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_alen(PyObject *o, void *x) {
35261   return __pyx_pw_9csamtools_11AlignedRead_4alen_1__get__(o);
35262 }
35263
35264 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mapq(PyObject *o, void *x) {
35265   return __pyx_pw_9csamtools_11AlignedRead_4mapq_1__get__(o);
35266 }
35267
35268 static int __pyx_setprop_9csamtools_11AlignedRead_mapq(PyObject *o, PyObject *v, void *x) {
35269   if (v) {
35270     return __pyx_pw_9csamtools_11AlignedRead_4mapq_3__set__(o, v);
35271   }
35272   else {
35273     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35274     return -1;
35275   }
35276 }
35277
35278 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mrnm(PyObject *o, void *x) {
35279   return __pyx_pw_9csamtools_11AlignedRead_4mrnm_1__get__(o);
35280 }
35281
35282 static int __pyx_setprop_9csamtools_11AlignedRead_mrnm(PyObject *o, PyObject *v, void *x) {
35283   if (v) {
35284     return __pyx_pw_9csamtools_11AlignedRead_4mrnm_3__set__(o, v);
35285   }
35286   else {
35287     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35288     return -1;
35289   }
35290 }
35291
35292 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rnext(PyObject *o, void *x) {
35293   return __pyx_pw_9csamtools_11AlignedRead_5rnext_1__get__(o);
35294 }
35295
35296 static int __pyx_setprop_9csamtools_11AlignedRead_rnext(PyObject *o, PyObject *v, void *x) {
35297   if (v) {
35298     return __pyx_pw_9csamtools_11AlignedRead_5rnext_3__set__(o, v);
35299   }
35300   else {
35301     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35302     return -1;
35303   }
35304 }
35305
35306 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mpos(PyObject *o, void *x) {
35307   return __pyx_pw_9csamtools_11AlignedRead_4mpos_1__get__(o);
35308 }
35309
35310 static int __pyx_setprop_9csamtools_11AlignedRead_mpos(PyObject *o, PyObject *v, void *x) {
35311   if (v) {
35312     return __pyx_pw_9csamtools_11AlignedRead_4mpos_3__set__(o, v);
35313   }
35314   else {
35315     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35316     return -1;
35317   }
35318 }
35319
35320 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_pnext(PyObject *o, void *x) {
35321   return __pyx_pw_9csamtools_11AlignedRead_5pnext_1__get__(o);
35322 }
35323
35324 static int __pyx_setprop_9csamtools_11AlignedRead_pnext(PyObject *o, PyObject *v, void *x) {
35325   if (v) {
35326     return __pyx_pw_9csamtools_11AlignedRead_5pnext_3__set__(o, v);
35327   }
35328   else {
35329     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35330     return -1;
35331   }
35332 }
35333
35334 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_isize(PyObject *o, void *x) {
35335   return __pyx_pw_9csamtools_11AlignedRead_5isize_1__get__(o);
35336 }
35337
35338 static int __pyx_setprop_9csamtools_11AlignedRead_isize(PyObject *o, PyObject *v, void *x) {
35339   if (v) {
35340     return __pyx_pw_9csamtools_11AlignedRead_5isize_3__set__(o, v);
35341   }
35342   else {
35343     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35344     return -1;
35345   }
35346 }
35347
35348 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tlen(PyObject *o, void *x) {
35349   return __pyx_pw_9csamtools_11AlignedRead_4tlen_1__get__(o);
35350 }
35351
35352 static int __pyx_setprop_9csamtools_11AlignedRead_tlen(PyObject *o, PyObject *v, void *x) {
35353   if (v) {
35354     return __pyx_pw_9csamtools_11AlignedRead_4tlen_3__set__(o, v);
35355   }
35356   else {
35357     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35358     return -1;
35359   }
35360 }
35361
35362 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_paired(PyObject *o, void *x) {
35363   return __pyx_pw_9csamtools_11AlignedRead_9is_paired_1__get__(o);
35364 }
35365
35366 static int __pyx_setprop_9csamtools_11AlignedRead_is_paired(PyObject *o, PyObject *v, void *x) {
35367   if (v) {
35368     return __pyx_pw_9csamtools_11AlignedRead_9is_paired_3__set__(o, v);
35369   }
35370   else {
35371     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35372     return -1;
35373   }
35374 }
35375
35376 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, void *x) {
35377   return __pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_1__get__(o);
35378 }
35379
35380 static int __pyx_setprop_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, PyObject *v, void *x) {
35381   if (v) {
35382     return __pyx_pw_9csamtools_11AlignedRead_14is_proper_pair_3__set__(o, v);
35383   }
35384   else {
35385     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35386     return -1;
35387   }
35388 }
35389
35390 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_unmapped(PyObject *o, void *x) {
35391   return __pyx_pw_9csamtools_11AlignedRead_11is_unmapped_1__get__(o);
35392 }
35393
35394 static int __pyx_setprop_9csamtools_11AlignedRead_is_unmapped(PyObject *o, PyObject *v, void *x) {
35395   if (v) {
35396     return __pyx_pw_9csamtools_11AlignedRead_11is_unmapped_3__set__(o, v);
35397   }
35398   else {
35399     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35400     return -1;
35401   }
35402 }
35403
35404 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, void *x) {
35405   return __pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_1__get__(o);
35406 }
35407
35408 static int __pyx_setprop_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, PyObject *v, void *x) {
35409   if (v) {
35410     return __pyx_pw_9csamtools_11AlignedRead_16mate_is_unmapped_3__set__(o, v);
35411   }
35412   else {
35413     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35414     return -1;
35415   }
35416 }
35417
35418 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_reverse(PyObject *o, void *x) {
35419   return __pyx_pw_9csamtools_11AlignedRead_10is_reverse_1__get__(o);
35420 }
35421
35422 static int __pyx_setprop_9csamtools_11AlignedRead_is_reverse(PyObject *o, PyObject *v, void *x) {
35423   if (v) {
35424     return __pyx_pw_9csamtools_11AlignedRead_10is_reverse_3__set__(o, v);
35425   }
35426   else {
35427     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35428     return -1;
35429   }
35430 }
35431
35432 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, void *x) {
35433   return __pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_1__get__(o);
35434 }
35435
35436 static int __pyx_setprop_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, PyObject *v, void *x) {
35437   if (v) {
35438     return __pyx_pw_9csamtools_11AlignedRead_15mate_is_reverse_3__set__(o, v);
35439   }
35440   else {
35441     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35442     return -1;
35443   }
35444 }
35445
35446 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_read1(PyObject *o, void *x) {
35447   return __pyx_pw_9csamtools_11AlignedRead_8is_read1_1__get__(o);
35448 }
35449
35450 static int __pyx_setprop_9csamtools_11AlignedRead_is_read1(PyObject *o, PyObject *v, void *x) {
35451   if (v) {
35452     return __pyx_pw_9csamtools_11AlignedRead_8is_read1_3__set__(o, v);
35453   }
35454   else {
35455     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35456     return -1;
35457   }
35458 }
35459
35460 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_read2(PyObject *o, void *x) {
35461   return __pyx_pw_9csamtools_11AlignedRead_8is_read2_1__get__(o);
35462 }
35463
35464 static int __pyx_setprop_9csamtools_11AlignedRead_is_read2(PyObject *o, PyObject *v, void *x) {
35465   if (v) {
35466     return __pyx_pw_9csamtools_11AlignedRead_8is_read2_3__set__(o, v);
35467   }
35468   else {
35469     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35470     return -1;
35471   }
35472 }
35473
35474 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_secondary(PyObject *o, void *x) {
35475   return __pyx_pw_9csamtools_11AlignedRead_12is_secondary_1__get__(o);
35476 }
35477
35478 static int __pyx_setprop_9csamtools_11AlignedRead_is_secondary(PyObject *o, PyObject *v, void *x) {
35479   if (v) {
35480     return __pyx_pw_9csamtools_11AlignedRead_12is_secondary_3__set__(o, v);
35481   }
35482   else {
35483     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35484     return -1;
35485   }
35486 }
35487
35488 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_qcfail(PyObject *o, void *x) {
35489   return __pyx_pw_9csamtools_11AlignedRead_9is_qcfail_1__get__(o);
35490 }
35491
35492 static int __pyx_setprop_9csamtools_11AlignedRead_is_qcfail(PyObject *o, PyObject *v, void *x) {
35493   if (v) {
35494     return __pyx_pw_9csamtools_11AlignedRead_9is_qcfail_3__set__(o, v);
35495   }
35496   else {
35497     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35498     return -1;
35499   }
35500 }
35501
35502 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_duplicate(PyObject *o, void *x) {
35503   return __pyx_pw_9csamtools_11AlignedRead_12is_duplicate_1__get__(o);
35504 }
35505
35506 static int __pyx_setprop_9csamtools_11AlignedRead_is_duplicate(PyObject *o, PyObject *v, void *x) {
35507   if (v) {
35508     return __pyx_pw_9csamtools_11AlignedRead_12is_duplicate_3__set__(o, v);
35509   }
35510   else {
35511     PyErr_SetString(PyExc_NotImplementedError, "__del__");
35512     return -1;
35513   }
35514 }
35515
35516 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_positions(PyObject *o, void *x) {
35517   return __pyx_pw_9csamtools_11AlignedRead_9positions_1__get__(o);
35518 }
35519
35520 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_aligned_pairs(PyObject *o, void *x) {
35521   return __pyx_pw_9csamtools_11AlignedRead_13aligned_pairs_1__get__(o);
35522 }
35523
35524 static PyMethodDef __pyx_methods_9csamtools_AlignedRead[] = {
35525   {__Pyx_NAMESTR("compare"), (PyCFunction)__pyx_pw_9csamtools_11AlignedRead_7compare, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_6compare)},
35526   {__Pyx_NAMESTR("overlap"), (PyCFunction)__pyx_pw_9csamtools_11AlignedRead_11overlap, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_10overlap)},
35527   {__Pyx_NAMESTR("opt"), (PyCFunction)__pyx_pw_9csamtools_11AlignedRead_13opt, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_12opt)},
35528   {__Pyx_NAMESTR("fancy_str"), (PyCFunction)__pyx_pw_9csamtools_11AlignedRead_15fancy_str, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_14fancy_str)},
35529   {0, 0, 0, 0}
35530 };
35531
35532 static struct PyGetSetDef __pyx_getsets_9csamtools_AlignedRead[] = {
35533   {(char *)"qname", __pyx_getprop_9csamtools_11AlignedRead_qname, __pyx_setprop_9csamtools_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_188), 0},
35534   {(char *)"cigar", __pyx_getprop_9csamtools_11AlignedRead_cigar, __pyx_setprop_9csamtools_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_189), 0},
35535   {(char *)"cigarstring", __pyx_getprop_9csamtools_11AlignedRead_cigarstring, __pyx_setprop_9csamtools_11AlignedRead_cigarstring, __Pyx_DOCSTR(__pyx_k_190), 0},
35536   {(char *)"seq", __pyx_getprop_9csamtools_11AlignedRead_seq, __pyx_setprop_9csamtools_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_191), 0},
35537   {(char *)"qual", __pyx_getprop_9csamtools_11AlignedRead_qual, __pyx_setprop_9csamtools_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_192), 0},
35538   {(char *)"query", __pyx_getprop_9csamtools_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_193), 0},
35539   {(char *)"qqual", __pyx_getprop_9csamtools_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_194), 0},
35540   {(char *)"qstart", __pyx_getprop_9csamtools_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_195), 0},
35541   {(char *)"qend", __pyx_getprop_9csamtools_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_196), 0},
35542   {(char *)"qlen", __pyx_getprop_9csamtools_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_197), 0},
35543   {(char *)"tags", __pyx_getprop_9csamtools_11AlignedRead_tags, __pyx_setprop_9csamtools_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_198), 0},
35544   {(char *)"flag", __pyx_getprop_9csamtools_11AlignedRead_flag, __pyx_setprop_9csamtools_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_199), 0},
35545   {(char *)"rname", __pyx_getprop_9csamtools_11AlignedRead_rname, __pyx_setprop_9csamtools_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_200), 0},
35546   {(char *)"tid", __pyx_getprop_9csamtools_11AlignedRead_tid, __pyx_setprop_9csamtools_11AlignedRead_tid, __Pyx_DOCSTR(__pyx_k_201), 0},
35547   {(char *)"pos", __pyx_getprop_9csamtools_11AlignedRead_pos, __pyx_setprop_9csamtools_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_202), 0},
35548   {(char *)"bin", __pyx_getprop_9csamtools_11AlignedRead_bin, __pyx_setprop_9csamtools_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_203), 0},
35549   {(char *)"rlen", __pyx_getprop_9csamtools_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_204), 0},
35550   {(char *)"aend", __pyx_getprop_9csamtools_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_205), 0},
35551   {(char *)"alen", __pyx_getprop_9csamtools_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_206), 0},
35552   {(char *)"mapq", __pyx_getprop_9csamtools_11AlignedRead_mapq, __pyx_setprop_9csamtools_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_207), 0},
35553   {(char *)"mrnm", __pyx_getprop_9csamtools_11AlignedRead_mrnm, __pyx_setprop_9csamtools_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_208), 0},
35554   {(char *)"rnext", __pyx_getprop_9csamtools_11AlignedRead_rnext, __pyx_setprop_9csamtools_11AlignedRead_rnext, __Pyx_DOCSTR(__pyx_k_209), 0},
35555   {(char *)"mpos", __pyx_getprop_9csamtools_11AlignedRead_mpos, __pyx_setprop_9csamtools_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_210), 0},
35556   {(char *)"pnext", __pyx_getprop_9csamtools_11AlignedRead_pnext, __pyx_setprop_9csamtools_11AlignedRead_pnext, __Pyx_DOCSTR(__pyx_k_211), 0},
35557   {(char *)"isize", __pyx_getprop_9csamtools_11AlignedRead_isize, __pyx_setprop_9csamtools_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_212), 0},
35558   {(char *)"tlen", __pyx_getprop_9csamtools_11AlignedRead_tlen, __pyx_setprop_9csamtools_11AlignedRead_tlen, __Pyx_DOCSTR(__pyx_k_213), 0},
35559   {(char *)"is_paired", __pyx_getprop_9csamtools_11AlignedRead_is_paired, __pyx_setprop_9csamtools_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_214), 0},
35560   {(char *)"is_proper_pair", __pyx_getprop_9csamtools_11AlignedRead_is_proper_pair, __pyx_setprop_9csamtools_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_215), 0},
35561   {(char *)"is_unmapped", __pyx_getprop_9csamtools_11AlignedRead_is_unmapped, __pyx_setprop_9csamtools_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_216), 0},
35562   {(char *)"mate_is_unmapped", __pyx_getprop_9csamtools_11AlignedRead_mate_is_unmapped, __pyx_setprop_9csamtools_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_217), 0},
35563   {(char *)"is_reverse", __pyx_getprop_9csamtools_11AlignedRead_is_reverse, __pyx_setprop_9csamtools_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_218), 0},
35564   {(char *)"mate_is_reverse", __pyx_getprop_9csamtools_11AlignedRead_mate_is_reverse, __pyx_setprop_9csamtools_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_219), 0},
35565   {(char *)"is_read1", __pyx_getprop_9csamtools_11AlignedRead_is_read1, __pyx_setprop_9csamtools_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_220), 0},
35566   {(char *)"is_read2", __pyx_getprop_9csamtools_11AlignedRead_is_read2, __pyx_setprop_9csamtools_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_221), 0},
35567   {(char *)"is_secondary", __pyx_getprop_9csamtools_11AlignedRead_is_secondary, __pyx_setprop_9csamtools_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_222), 0},
35568   {(char *)"is_qcfail", __pyx_getprop_9csamtools_11AlignedRead_is_qcfail, __pyx_setprop_9csamtools_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_223), 0},
35569   {(char *)"is_duplicate", __pyx_getprop_9csamtools_11AlignedRead_is_duplicate, __pyx_setprop_9csamtools_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_224), 0},
35570   {(char *)"positions", __pyx_getprop_9csamtools_11AlignedRead_positions, 0, __Pyx_DOCSTR(__pyx_k_225), 0},
35571   {(char *)"aligned_pairs", __pyx_getprop_9csamtools_11AlignedRead_aligned_pairs, 0, __Pyx_DOCSTR(__pyx_k_226), 0},
35572   {0, 0, 0, 0, 0}
35573 };
35574
35575 static PyNumberMethods __pyx_tp_as_number_AlignedRead = {
35576   0, /*nb_add*/
35577   0, /*nb_subtract*/
35578   0, /*nb_multiply*/
35579   #if PY_MAJOR_VERSION < 3
35580   0, /*nb_divide*/
35581   #endif
35582   0, /*nb_remainder*/
35583   0, /*nb_divmod*/
35584   0, /*nb_power*/
35585   0, /*nb_negative*/
35586   0, /*nb_positive*/
35587   0, /*nb_absolute*/
35588   0, /*nb_nonzero*/
35589   0, /*nb_invert*/
35590   0, /*nb_lshift*/
35591   0, /*nb_rshift*/
35592   0, /*nb_and*/
35593   0, /*nb_xor*/
35594   0, /*nb_or*/
35595   #if PY_MAJOR_VERSION < 3
35596   0, /*nb_coerce*/
35597   #endif
35598   0, /*nb_int*/
35599   #if PY_MAJOR_VERSION < 3
35600   0, /*nb_long*/
35601   #else
35602   0, /*reserved*/
35603   #endif
35604   0, /*nb_float*/
35605   #if PY_MAJOR_VERSION < 3
35606   0, /*nb_oct*/
35607   #endif
35608   #if PY_MAJOR_VERSION < 3
35609   0, /*nb_hex*/
35610   #endif
35611   0, /*nb_inplace_add*/
35612   0, /*nb_inplace_subtract*/
35613   0, /*nb_inplace_multiply*/
35614   #if PY_MAJOR_VERSION < 3
35615   0, /*nb_inplace_divide*/
35616   #endif
35617   0, /*nb_inplace_remainder*/
35618   0, /*nb_inplace_power*/
35619   0, /*nb_inplace_lshift*/
35620   0, /*nb_inplace_rshift*/
35621   0, /*nb_inplace_and*/
35622   0, /*nb_inplace_xor*/
35623   0, /*nb_inplace_or*/
35624   0, /*nb_floor_divide*/
35625   0, /*nb_true_divide*/
35626   0, /*nb_inplace_floor_divide*/
35627   0, /*nb_inplace_true_divide*/
35628   #if PY_VERSION_HEX >= 0x02050000
35629   0, /*nb_index*/
35630   #endif
35631 };
35632
35633 static PySequenceMethods __pyx_tp_as_sequence_AlignedRead = {
35634   0, /*sq_length*/
35635   0, /*sq_concat*/
35636   0, /*sq_repeat*/
35637   0, /*sq_item*/
35638   0, /*sq_slice*/
35639   0, /*sq_ass_item*/
35640   0, /*sq_ass_slice*/
35641   0, /*sq_contains*/
35642   0, /*sq_inplace_concat*/
35643   0, /*sq_inplace_repeat*/
35644 };
35645
35646 static PyMappingMethods __pyx_tp_as_mapping_AlignedRead = {
35647   0, /*mp_length*/
35648   0, /*mp_subscript*/
35649   0, /*mp_ass_subscript*/
35650 };
35651
35652 static PyBufferProcs __pyx_tp_as_buffer_AlignedRead = {
35653   #if PY_MAJOR_VERSION < 3
35654   0, /*bf_getreadbuffer*/
35655   #endif
35656   #if PY_MAJOR_VERSION < 3
35657   0, /*bf_getwritebuffer*/
35658   #endif
35659   #if PY_MAJOR_VERSION < 3
35660   0, /*bf_getsegcount*/
35661   #endif
35662   #if PY_MAJOR_VERSION < 3
35663   0, /*bf_getcharbuffer*/
35664   #endif
35665   #if PY_VERSION_HEX >= 0x02060000
35666   0, /*bf_getbuffer*/
35667   #endif
35668   #if PY_VERSION_HEX >= 0x02060000
35669   0, /*bf_releasebuffer*/
35670   #endif
35671 };
35672
35673 static PyTypeObject __pyx_type_9csamtools_AlignedRead = {
35674   PyVarObject_HEAD_INIT(0, 0)
35675   __Pyx_NAMESTR("csamtools.AlignedRead"), /*tp_name*/
35676   sizeof(struct __pyx_obj_9csamtools_AlignedRead), /*tp_basicsize*/
35677   0, /*tp_itemsize*/
35678   __pyx_tp_dealloc_9csamtools_AlignedRead, /*tp_dealloc*/
35679   0, /*tp_print*/
35680   0, /*tp_getattr*/
35681   0, /*tp_setattr*/
35682   #if PY_MAJOR_VERSION < 3
35683   0, /*tp_compare*/
35684   #else
35685   0, /*reserved*/
35686   #endif
35687   0, /*tp_repr*/
35688   &__pyx_tp_as_number_AlignedRead, /*tp_as_number*/
35689   &__pyx_tp_as_sequence_AlignedRead, /*tp_as_sequence*/
35690   &__pyx_tp_as_mapping_AlignedRead, /*tp_as_mapping*/
35691   __pyx_pw_9csamtools_11AlignedRead_9__hash__, /*tp_hash*/
35692   0, /*tp_call*/
35693   __pyx_pw_9csamtools_11AlignedRead_5__str__, /*tp_str*/
35694   0, /*tp_getattro*/
35695   0, /*tp_setattro*/
35696   &__pyx_tp_as_buffer_AlignedRead, /*tp_as_buffer*/
35697   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
35698   __Pyx_DOCSTR("AlignedRead()\n\n    Class representing an aligned read. see SAM format specification for\n    the meaning of fields (http://samtools.sourceforge.net/).\n\n    This class stores a handle to the samtools C-structure representing\n    an aligned read. Member read access is forwarded to the C-structure\n    and converted into python objects. This implementation should be fast,\n    as only the data needed is converted.\n\n    For write access, the C-structure is updated in-place. This is\n    not the most efficient way to build BAM entries, as the variable\n    length data is concatenated and thus needs to resized if\n    a field is updated. Furthermore, the BAM entry might be\n    in an inconsistent state. The :meth:`~validate` method can\n    be used to check if an entry is consistent.\n\n    One issue to look out for is that the sequence should always\n    be set *before* the quality scores. Setting the sequence will\n    also erase any quality scores that were set previously.\n\n    In Python 3, the fields containing sequence and quality\n    (seq, query, qual and qqual) data are of type bytes. Other\n    string data, such as the qname field and strings in the\n    tags tuple, is represented as unicode strings. On assignment,\n    both bytes and unicode objects are allowed, but unicode strings\n    must contain only ASCII characters.\n    "), /*tp_doc*/
35699   0, /*tp_traverse*/
35700   0, /*tp_clear*/
35701   0, /*tp_richcompare*/
35702   0, /*tp_weaklistoffset*/
35703   0, /*tp_iter*/
35704   0, /*tp_iternext*/
35705   __pyx_methods_9csamtools_AlignedRead, /*tp_methods*/
35706   0, /*tp_members*/
35707   __pyx_getsets_9csamtools_AlignedRead, /*tp_getset*/
35708   0, /*tp_base*/
35709   0, /*tp_dict*/
35710   0, /*tp_descr_get*/
35711   0, /*tp_descr_set*/
35712   0, /*tp_dictoffset*/
35713   __pyx_pw_9csamtools_11AlignedRead_1__init__, /*tp_init*/
35714   0, /*tp_alloc*/
35715   __pyx_tp_new_9csamtools_AlignedRead, /*tp_new*/
35716   0, /*tp_free*/
35717   0, /*tp_is_gc*/
35718   0, /*tp_bases*/
35719   0, /*tp_mro*/
35720   0, /*tp_cache*/
35721   0, /*tp_subclasses*/
35722   0, /*tp_weaklist*/
35723   0, /*tp_del*/
35724   #if PY_VERSION_HEX >= 0x02060000
35725   0, /*tp_version_tag*/
35726   #endif
35727 };
35728 static struct __pyx_vtabstruct_9csamtools_Samfile __pyx_vtable_9csamtools_Samfile;
35729
35730 static PyObject *__pyx_tp_new_9csamtools_Samfile(PyTypeObject *t, PyObject *a, PyObject *k) {
35731   struct __pyx_obj_9csamtools_Samfile *p;
35732   PyObject *o = (*t->tp_alloc)(t, 0);
35733   if (!o) return 0;
35734   p = ((struct __pyx_obj_9csamtools_Samfile *)o);
35735   p->__pyx_vtab = __pyx_vtabptr_9csamtools_Samfile;
35736   if (__pyx_pw_9csamtools_7Samfile_1__cinit__(o, a, k) < 0) {
35737     Py_DECREF(o); o = 0;
35738   }
35739   return o;
35740 }
35741
35742 static void __pyx_tp_dealloc_9csamtools_Samfile(PyObject *o) {
35743   {
35744     PyObject *etype, *eval, *etb;
35745     PyErr_Fetch(&etype, &eval, &etb);
35746     ++Py_REFCNT(o);
35747     __pyx_pw_9csamtools_7Samfile_31__dealloc__(o);
35748     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
35749     --Py_REFCNT(o);
35750     PyErr_Restore(etype, eval, etb);
35751   }
35752   (*Py_TYPE(o)->tp_free)(o);
35753 }
35754
35755 static PyObject *__pyx_getprop_9csamtools_7Samfile_filename(PyObject *o, void *x) {
35756   return __pyx_pw_9csamtools_7Samfile_8filename_1__get__(o);
35757 }
35758
35759 static PyObject *__pyx_getprop_9csamtools_7Samfile_nreferences(PyObject *o, void *x) {
35760   return __pyx_pw_9csamtools_7Samfile_11nreferences_1__get__(o);
35761 }
35762
35763 static PyObject *__pyx_getprop_9csamtools_7Samfile_references(PyObject *o, void *x) {
35764   return __pyx_pw_9csamtools_7Samfile_10references_1__get__(o);
35765 }
35766
35767 static PyObject *__pyx_getprop_9csamtools_7Samfile_lengths(PyObject *o, void *x) {
35768   return __pyx_pw_9csamtools_7Samfile_7lengths_1__get__(o);
35769 }
35770
35771 static PyObject *__pyx_getprop_9csamtools_7Samfile_mapped(PyObject *o, void *x) {
35772   return __pyx_pw_9csamtools_7Samfile_6mapped_1__get__(o);
35773 }
35774
35775 static PyObject *__pyx_getprop_9csamtools_7Samfile_unmapped(PyObject *o, void *x) {
35776   return __pyx_pw_9csamtools_7Samfile_8unmapped_1__get__(o);
35777 }
35778
35779 static PyObject *__pyx_getprop_9csamtools_7Samfile_text(PyObject *o, void *x) {
35780   return __pyx_pw_9csamtools_7Samfile_4text_1__get__(o);
35781 }
35782
35783 static PyObject *__pyx_getprop_9csamtools_7Samfile_header(PyObject *o, void *x) {
35784   return __pyx_pw_9csamtools_7Samfile_6header_1__get__(o);
35785 }
35786
35787 static PyMethodDef __pyx_methods_9csamtools_Samfile[] = {
35788   {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_3_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_2_isOpen)},
35789   {__Pyx_NAMESTR("_hasIndex"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_5_hasIndex, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_4_hasIndex)},
35790   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_7_open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_6_open)},
35791   {__Pyx_NAMESTR("gettid"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_9gettid, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_8gettid)},
35792   {__Pyx_NAMESTR("getrname"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_11getrname, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_10getrname)},
35793   {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_13_parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_12_parseRegion)},
35794   {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_15reset, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_14reset)},
35795   {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_17seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_16seek)},
35796   {__Pyx_NAMESTR("tell"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_19tell, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_18tell)},
35797   {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_21fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_20fetch)},
35798   {__Pyx_NAMESTR("mate"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_23mate, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_22mate)},
35799   {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_25count, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_24count)},
35800   {__Pyx_NAMESTR("pileup"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_27pileup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_26pileup)},
35801   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_29close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_28close)},
35802   {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_33write, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_32write)},
35803   {__Pyx_NAMESTR("__enter__"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_35__enter__, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_34__enter__)},
35804   {__Pyx_NAMESTR("__exit__"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_37__exit__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_36__exit__)},
35805   {__Pyx_NAMESTR("_buildLine"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_39_buildLine, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_38_buildLine)},
35806   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_7Samfile_43__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_42__next__)},
35807   {0, 0, 0, 0}
35808 };
35809
35810 static struct PyGetSetDef __pyx_getsets_9csamtools_Samfile[] = {
35811   {(char *)"filename", __pyx_getprop_9csamtools_7Samfile_filename, 0, __Pyx_DOCSTR(__pyx_k_187), 0},
35812   {(char *)"nreferences", __pyx_getprop_9csamtools_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_227), 0},
35813   {(char *)"references", __pyx_getprop_9csamtools_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_228), 0},
35814   {(char *)"lengths", __pyx_getprop_9csamtools_7Samfile_lengths, 0, __Pyx_DOCSTR(__pyx_k_229), 0},
35815   {(char *)"mapped", __pyx_getprop_9csamtools_7Samfile_mapped, 0, __Pyx_DOCSTR(__pyx_k_230), 0},
35816   {(char *)"unmapped", __pyx_getprop_9csamtools_7Samfile_unmapped, 0, __Pyx_DOCSTR(__pyx_k_231), 0},
35817   {(char *)"text", __pyx_getprop_9csamtools_7Samfile_text, 0, __Pyx_DOCSTR(__pyx_k_232), 0},
35818   {(char *)"header", __pyx_getprop_9csamtools_7Samfile_header, 0, __Pyx_DOCSTR(__pyx_k_233), 0},
35819   {0, 0, 0, 0, 0}
35820 };
35821
35822 static PyNumberMethods __pyx_tp_as_number_Samfile = {
35823   0, /*nb_add*/
35824   0, /*nb_subtract*/
35825   0, /*nb_multiply*/
35826   #if PY_MAJOR_VERSION < 3
35827   0, /*nb_divide*/
35828   #endif
35829   0, /*nb_remainder*/
35830   0, /*nb_divmod*/
35831   0, /*nb_power*/
35832   0, /*nb_negative*/
35833   0, /*nb_positive*/
35834   0, /*nb_absolute*/
35835   0, /*nb_nonzero*/
35836   0, /*nb_invert*/
35837   0, /*nb_lshift*/
35838   0, /*nb_rshift*/
35839   0, /*nb_and*/
35840   0, /*nb_xor*/
35841   0, /*nb_or*/
35842   #if PY_MAJOR_VERSION < 3
35843   0, /*nb_coerce*/
35844   #endif
35845   0, /*nb_int*/
35846   #if PY_MAJOR_VERSION < 3
35847   0, /*nb_long*/
35848   #else
35849   0, /*reserved*/
35850   #endif
35851   0, /*nb_float*/
35852   #if PY_MAJOR_VERSION < 3
35853   0, /*nb_oct*/
35854   #endif
35855   #if PY_MAJOR_VERSION < 3
35856   0, /*nb_hex*/
35857   #endif
35858   0, /*nb_inplace_add*/
35859   0, /*nb_inplace_subtract*/
35860   0, /*nb_inplace_multiply*/
35861   #if PY_MAJOR_VERSION < 3
35862   0, /*nb_inplace_divide*/
35863   #endif
35864   0, /*nb_inplace_remainder*/
35865   0, /*nb_inplace_power*/
35866   0, /*nb_inplace_lshift*/
35867   0, /*nb_inplace_rshift*/
35868   0, /*nb_inplace_and*/
35869   0, /*nb_inplace_xor*/
35870   0, /*nb_inplace_or*/
35871   0, /*nb_floor_divide*/
35872   0, /*nb_true_divide*/
35873   0, /*nb_inplace_floor_divide*/
35874   0, /*nb_inplace_true_divide*/
35875   #if PY_VERSION_HEX >= 0x02050000
35876   0, /*nb_index*/
35877   #endif
35878 };
35879
35880 static PySequenceMethods __pyx_tp_as_sequence_Samfile = {
35881   0, /*sq_length*/
35882   0, /*sq_concat*/
35883   0, /*sq_repeat*/
35884   0, /*sq_item*/
35885   0, /*sq_slice*/
35886   0, /*sq_ass_item*/
35887   0, /*sq_ass_slice*/
35888   0, /*sq_contains*/
35889   0, /*sq_inplace_concat*/
35890   0, /*sq_inplace_repeat*/
35891 };
35892
35893 static PyMappingMethods __pyx_tp_as_mapping_Samfile = {
35894   0, /*mp_length*/
35895   0, /*mp_subscript*/
35896   0, /*mp_ass_subscript*/
35897 };
35898
35899 static PyBufferProcs __pyx_tp_as_buffer_Samfile = {
35900   #if PY_MAJOR_VERSION < 3
35901   0, /*bf_getreadbuffer*/
35902   #endif
35903   #if PY_MAJOR_VERSION < 3
35904   0, /*bf_getwritebuffer*/
35905   #endif
35906   #if PY_MAJOR_VERSION < 3
35907   0, /*bf_getsegcount*/
35908   #endif
35909   #if PY_MAJOR_VERSION < 3
35910   0, /*bf_getcharbuffer*/
35911   #endif
35912   #if PY_VERSION_HEX >= 0x02060000
35913   0, /*bf_getbuffer*/
35914   #endif
35915   #if PY_VERSION_HEX >= 0x02060000
35916   0, /*bf_releasebuffer*/
35917   #endif
35918 };
35919
35920 static PyTypeObject __pyx_type_9csamtools_Samfile = {
35921   PyVarObject_HEAD_INIT(0, 0)
35922   __Pyx_NAMESTR("csamtools.Samfile"), /*tp_name*/
35923   sizeof(struct __pyx_obj_9csamtools_Samfile), /*tp_basicsize*/
35924   0, /*tp_itemsize*/
35925   __pyx_tp_dealloc_9csamtools_Samfile, /*tp_dealloc*/
35926   0, /*tp_print*/
35927   0, /*tp_getattr*/
35928   0, /*tp_setattr*/
35929   #if PY_MAJOR_VERSION < 3
35930   0, /*tp_compare*/
35931   #else
35932   0, /*reserved*/
35933   #endif
35934   0, /*tp_repr*/
35935   &__pyx_tp_as_number_Samfile, /*tp_as_number*/
35936   &__pyx_tp_as_sequence_Samfile, /*tp_as_sequence*/
35937   &__pyx_tp_as_mapping_Samfile, /*tp_as_mapping*/
35938   0, /*tp_hash*/
35939   0, /*tp_call*/
35940   0, /*tp_str*/
35941   0, /*tp_getattro*/
35942   0, /*tp_setattro*/
35943   &__pyx_tp_as_buffer_Samfile, /*tp_as_buffer*/
35944   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
35945   __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 :term:`BAM` output.\n    Use ``h`` to output header information in text (:term:`TAM`)  mode.\n\n    If ``b`` is present, it must immediately follow ``r`` or ``w``.\n    Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb`` and ``wbu``. For instance, to open\n    a :term:`BAM` formatted file for reading, type::\n\n        f = pysam.Samfile('ex1.bam','rb')\n\n    If mode is not specified, we will try to auto-detect in the order 'rb', 'r', thus both the following\n    should work::\n\n        f1 = pysam.Samfile('ex1.bam' )\n        f2 = pysam.Samfile('ex1.sam' )\n\n    If an index for a BAM file exists (.bai), it will be opened automatically. Without an index random\n    access to reads via :meth:`fetch` and :meth:`pileup` is disabled.\n\n    For writing, the header of a :term:`SAM` file/:term:`BAM` file can be constituted from several\n    sources (see also the samtools format specification):\n\n        1. If *template* is given, the header is copied from a another *Samfile*\n           (*template* must be of type *Samfile*).\n\n        2. If *header* is given, the header is built from a multi-level dictionary. The first level\n           are the four types ('HD', 'SQ', ...). The second level are a list of lines, with each line\n           being a list of tag-value pairs. The header is constructed first from all the defined fields,\n           followed by user tags in alphabetical order.\n\n        3. If *text* is given, new header text is copied from raw text.\n\n        4. The names (*referencenames*) and lengths (*referencelengths*) are supplied directly as lists. \n           By default, 'SQ' and 'LN' tags will be added to the header text. This option can be\n           changed by unsetting the flag *add_sq_text*. \n\n    By default, if file a file is opened in mode 'r', it is checked for a valid header\n    (*check_header* = True) and a definition of chromosome names (*check_sq* = True). \n    \n    "), /*tp_doc*/
35946   0, /*tp_traverse*/
35947   0, /*tp_clear*/
35948   0, /*tp_richcompare*/
35949   0, /*tp_weaklistoffset*/
35950   __pyx_pw_9csamtools_7Samfile_41__iter__, /*tp_iter*/
35951   __pyx_pw_9csamtools_7Samfile_43__next__, /*tp_iternext*/
35952   __pyx_methods_9csamtools_Samfile, /*tp_methods*/
35953   0, /*tp_members*/
35954   __pyx_getsets_9csamtools_Samfile, /*tp_getset*/
35955   0, /*tp_base*/
35956   0, /*tp_dict*/
35957   0, /*tp_descr_get*/
35958   0, /*tp_descr_set*/
35959   0, /*tp_dictoffset*/
35960   0, /*tp_init*/
35961   0, /*tp_alloc*/
35962   __pyx_tp_new_9csamtools_Samfile, /*tp_new*/
35963   0, /*tp_free*/
35964   0, /*tp_is_gc*/
35965   0, /*tp_bases*/
35966   0, /*tp_mro*/
35967   0, /*tp_cache*/
35968   0, /*tp_subclasses*/
35969   0, /*tp_weaklist*/
35970   0, /*tp_del*/
35971   #if PY_VERSION_HEX >= 0x02060000
35972   0, /*tp_version_tag*/
35973   #endif
35974 };
35975
35976 static PyObject *__pyx_tp_new_9csamtools_PileupProxy(PyTypeObject *t, PyObject *a, PyObject *k) {
35977   PyObject *o = (*t->tp_alloc)(t, 0);
35978   if (!o) return 0;
35979   return o;
35980 }
35981
35982 static void __pyx_tp_dealloc_9csamtools_PileupProxy(PyObject *o) {
35983   (*Py_TYPE(o)->tp_free)(o);
35984 }
35985
35986 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_tid(PyObject *o, void *x) {
35987   return __pyx_pw_9csamtools_11PileupProxy_3tid_1__get__(o);
35988 }
35989
35990 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_n(PyObject *o, void *x) {
35991   return __pyx_pw_9csamtools_11PileupProxy_1n_1__get__(o);
35992 }
35993
35994 static int __pyx_setprop_9csamtools_11PileupProxy_n(PyObject *o, PyObject *v, void *x) {
35995   if (v) {
35996     return __pyx_pw_9csamtools_11PileupProxy_1n_3__set__(o, v);
35997   }
35998   else {
35999     PyErr_SetString(PyExc_NotImplementedError, "__del__");
36000     return -1;
36001   }
36002 }
36003
36004 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_pos(PyObject *o, void *x) {
36005   return __pyx_pw_9csamtools_11PileupProxy_3pos_1__get__(o);
36006 }
36007
36008 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_pileups(PyObject *o, void *x) {
36009   return __pyx_pw_9csamtools_11PileupProxy_7pileups_1__get__(o);
36010 }
36011
36012 static PyMethodDef __pyx_methods_9csamtools_PileupProxy[] = {
36013   {0, 0, 0, 0}
36014 };
36015
36016 static struct PyGetSetDef __pyx_getsets_9csamtools_PileupProxy[] = {
36017   {(char *)"tid", __pyx_getprop_9csamtools_11PileupProxy_tid, 0, __Pyx_DOCSTR(__pyx_k_234), 0},
36018   {(char *)"n", __pyx_getprop_9csamtools_11PileupProxy_n, __pyx_setprop_9csamtools_11PileupProxy_n, __Pyx_DOCSTR(__pyx_k_235), 0},
36019   {(char *)"pos", __pyx_getprop_9csamtools_11PileupProxy_pos, 0, 0, 0},
36020   {(char *)"pileups", __pyx_getprop_9csamtools_11PileupProxy_pileups, 0, __Pyx_DOCSTR(__pyx_k_236), 0},
36021   {0, 0, 0, 0, 0}
36022 };
36023
36024 static PyNumberMethods __pyx_tp_as_number_PileupProxy = {
36025   0, /*nb_add*/
36026   0, /*nb_subtract*/
36027   0, /*nb_multiply*/
36028   #if PY_MAJOR_VERSION < 3
36029   0, /*nb_divide*/
36030   #endif
36031   0, /*nb_remainder*/
36032   0, /*nb_divmod*/
36033   0, /*nb_power*/
36034   0, /*nb_negative*/
36035   0, /*nb_positive*/
36036   0, /*nb_absolute*/
36037   0, /*nb_nonzero*/
36038   0, /*nb_invert*/
36039   0, /*nb_lshift*/
36040   0, /*nb_rshift*/
36041   0, /*nb_and*/
36042   0, /*nb_xor*/
36043   0, /*nb_or*/
36044   #if PY_MAJOR_VERSION < 3
36045   0, /*nb_coerce*/
36046   #endif
36047   0, /*nb_int*/
36048   #if PY_MAJOR_VERSION < 3
36049   0, /*nb_long*/
36050   #else
36051   0, /*reserved*/
36052   #endif
36053   0, /*nb_float*/
36054   #if PY_MAJOR_VERSION < 3
36055   0, /*nb_oct*/
36056   #endif
36057   #if PY_MAJOR_VERSION < 3
36058   0, /*nb_hex*/
36059   #endif
36060   0, /*nb_inplace_add*/
36061   0, /*nb_inplace_subtract*/
36062   0, /*nb_inplace_multiply*/
36063   #if PY_MAJOR_VERSION < 3
36064   0, /*nb_inplace_divide*/
36065   #endif
36066   0, /*nb_inplace_remainder*/
36067   0, /*nb_inplace_power*/
36068   0, /*nb_inplace_lshift*/
36069   0, /*nb_inplace_rshift*/
36070   0, /*nb_inplace_and*/
36071   0, /*nb_inplace_xor*/
36072   0, /*nb_inplace_or*/
36073   0, /*nb_floor_divide*/
36074   0, /*nb_true_divide*/
36075   0, /*nb_inplace_floor_divide*/
36076   0, /*nb_inplace_true_divide*/
36077   #if PY_VERSION_HEX >= 0x02050000
36078   0, /*nb_index*/
36079   #endif
36080 };
36081
36082 static PySequenceMethods __pyx_tp_as_sequence_PileupProxy = {
36083   0, /*sq_length*/
36084   0, /*sq_concat*/
36085   0, /*sq_repeat*/
36086   0, /*sq_item*/
36087   0, /*sq_slice*/
36088   0, /*sq_ass_item*/
36089   0, /*sq_ass_slice*/
36090   0, /*sq_contains*/
36091   0, /*sq_inplace_concat*/
36092   0, /*sq_inplace_repeat*/
36093 };
36094
36095 static PyMappingMethods __pyx_tp_as_mapping_PileupProxy = {
36096   0, /*mp_length*/
36097   0, /*mp_subscript*/
36098   0, /*mp_ass_subscript*/
36099 };
36100
36101 static PyBufferProcs __pyx_tp_as_buffer_PileupProxy = {
36102   #if PY_MAJOR_VERSION < 3
36103   0, /*bf_getreadbuffer*/
36104   #endif
36105   #if PY_MAJOR_VERSION < 3
36106   0, /*bf_getwritebuffer*/
36107   #endif
36108   #if PY_MAJOR_VERSION < 3
36109   0, /*bf_getsegcount*/
36110   #endif
36111   #if PY_MAJOR_VERSION < 3
36112   0, /*bf_getcharbuffer*/
36113   #endif
36114   #if PY_VERSION_HEX >= 0x02060000
36115   0, /*bf_getbuffer*/
36116   #endif
36117   #if PY_VERSION_HEX >= 0x02060000
36118   0, /*bf_releasebuffer*/
36119   #endif
36120 };
36121
36122 static PyTypeObject __pyx_type_9csamtools_PileupProxy = {
36123   PyVarObject_HEAD_INIT(0, 0)
36124   __Pyx_NAMESTR("csamtools.PileupProxy"), /*tp_name*/
36125   sizeof(struct __pyx_obj_9csamtools_PileupProxy), /*tp_basicsize*/
36126   0, /*tp_itemsize*/
36127   __pyx_tp_dealloc_9csamtools_PileupProxy, /*tp_dealloc*/
36128   0, /*tp_print*/
36129   0, /*tp_getattr*/
36130   0, /*tp_setattr*/
36131   #if PY_MAJOR_VERSION < 3
36132   0, /*tp_compare*/
36133   #else
36134   0, /*reserved*/
36135   #endif
36136   0, /*tp_repr*/
36137   &__pyx_tp_as_number_PileupProxy, /*tp_as_number*/
36138   &__pyx_tp_as_sequence_PileupProxy, /*tp_as_sequence*/
36139   &__pyx_tp_as_mapping_PileupProxy, /*tp_as_mapping*/
36140   0, /*tp_hash*/
36141   0, /*tp_call*/
36142   __pyx_pw_9csamtools_11PileupProxy_3__str__, /*tp_str*/
36143   0, /*tp_getattro*/
36144   0, /*tp_setattro*/
36145   &__pyx_tp_as_buffer_PileupProxy, /*tp_as_buffer*/
36146   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
36147   __Pyx_DOCSTR("PileupProxy()\nA pileup column. A pileup column contains\n    all the reads that map to a certain target base.\n\n    tid\n        chromosome ID as is defined in the header\n    pos\n        the target base coordinate (0-based)\n    n\n        number of reads mapping to this column\n    pileups\n        list of reads (:class:`pysam.PileupRead`) aligned to this column\n\n    This class is a proxy for results returned by the samtools pileup engine.\n    If the underlying engine iterator advances, the results of this column\n    will change.\n    "), /*tp_doc*/
36148   0, /*tp_traverse*/
36149   0, /*tp_clear*/
36150   0, /*tp_richcompare*/
36151   0, /*tp_weaklistoffset*/
36152   0, /*tp_iter*/
36153   0, /*tp_iternext*/
36154   __pyx_methods_9csamtools_PileupProxy, /*tp_methods*/
36155   0, /*tp_members*/
36156   __pyx_getsets_9csamtools_PileupProxy, /*tp_getset*/
36157   0, /*tp_base*/
36158   0, /*tp_dict*/
36159   0, /*tp_descr_get*/
36160   0, /*tp_descr_set*/
36161   0, /*tp_dictoffset*/
36162   __pyx_pw_9csamtools_11PileupProxy_1__init__, /*tp_init*/
36163   0, /*tp_alloc*/
36164   __pyx_tp_new_9csamtools_PileupProxy, /*tp_new*/
36165   0, /*tp_free*/
36166   0, /*tp_is_gc*/
36167   0, /*tp_bases*/
36168   0, /*tp_mro*/
36169   0, /*tp_cache*/
36170   0, /*tp_subclasses*/
36171   0, /*tp_weaklist*/
36172   0, /*tp_del*/
36173   #if PY_VERSION_HEX >= 0x02060000
36174   0, /*tp_version_tag*/
36175   #endif
36176 };
36177
36178 static PyObject *__pyx_tp_new_9csamtools_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k) {
36179   struct __pyx_obj_9csamtools_PileupRead *p;
36180   PyObject *o = (*t->tp_alloc)(t, 0);
36181   if (!o) return 0;
36182   p = ((struct __pyx_obj_9csamtools_PileupRead *)o);
36183   p->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
36184   return o;
36185 }
36186
36187 static void __pyx_tp_dealloc_9csamtools_PileupRead(PyObject *o) {
36188   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
36189   Py_XDECREF(((PyObject *)p->_alignment));
36190   (*Py_TYPE(o)->tp_free)(o);
36191 }
36192
36193 static int __pyx_tp_traverse_9csamtools_PileupRead(PyObject *o, visitproc v, void *a) {
36194   int e;
36195   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
36196   if (p->_alignment) {
36197     e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
36198   }
36199   return 0;
36200 }
36201
36202 static int __pyx_tp_clear_9csamtools_PileupRead(PyObject *o) {
36203   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
36204   PyObject* tmp;
36205   tmp = ((PyObject*)p->_alignment);
36206   p->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
36207   Py_XDECREF(tmp);
36208   return 0;
36209 }
36210
36211 static PyObject *__pyx_getprop_9csamtools_10PileupRead_alignment(PyObject *o, void *x) {
36212   return __pyx_pw_9csamtools_10PileupRead_9alignment_1__get__(o);
36213 }
36214
36215 static PyObject *__pyx_getprop_9csamtools_10PileupRead_qpos(PyObject *o, void *x) {
36216   return __pyx_pw_9csamtools_10PileupRead_4qpos_1__get__(o);
36217 }
36218
36219 static PyObject *__pyx_getprop_9csamtools_10PileupRead_indel(PyObject *o, void *x) {
36220   return __pyx_pw_9csamtools_10PileupRead_5indel_1__get__(o);
36221 }
36222
36223 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_del(PyObject *o, void *x) {
36224   return __pyx_pw_9csamtools_10PileupRead_6is_del_1__get__(o);
36225 }
36226
36227 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_head(PyObject *o, void *x) {
36228   return __pyx_pw_9csamtools_10PileupRead_7is_head_1__get__(o);
36229 }
36230
36231 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_tail(PyObject *o, void *x) {
36232   return __pyx_pw_9csamtools_10PileupRead_7is_tail_1__get__(o);
36233 }
36234
36235 static PyObject *__pyx_getprop_9csamtools_10PileupRead_level(PyObject *o, void *x) {
36236   return __pyx_pw_9csamtools_10PileupRead_5level_1__get__(o);
36237 }
36238
36239 static PyMethodDef __pyx_methods_9csamtools_PileupRead[] = {
36240   {0, 0, 0, 0}
36241 };
36242
36243 static struct PyGetSetDef __pyx_getsets_9csamtools_PileupRead[] = {
36244   {(char *)"alignment", __pyx_getprop_9csamtools_10PileupRead_alignment, 0, __Pyx_DOCSTR(__pyx_k_237), 0},
36245   {(char *)"qpos", __pyx_getprop_9csamtools_10PileupRead_qpos, 0, __Pyx_DOCSTR(__pyx_k_238), 0},
36246   {(char *)"indel", __pyx_getprop_9csamtools_10PileupRead_indel, 0, __Pyx_DOCSTR(__pyx_k_239), 0},
36247   {(char *)"is_del", __pyx_getprop_9csamtools_10PileupRead_is_del, 0, __Pyx_DOCSTR(__pyx_k_240), 0},
36248   {(char *)"is_head", __pyx_getprop_9csamtools_10PileupRead_is_head, 0, 0, 0},
36249   {(char *)"is_tail", __pyx_getprop_9csamtools_10PileupRead_is_tail, 0, 0, 0},
36250   {(char *)"level", __pyx_getprop_9csamtools_10PileupRead_level, 0, 0, 0},
36251   {0, 0, 0, 0, 0}
36252 };
36253
36254 static PyNumberMethods __pyx_tp_as_number_PileupRead = {
36255   0, /*nb_add*/
36256   0, /*nb_subtract*/
36257   0, /*nb_multiply*/
36258   #if PY_MAJOR_VERSION < 3
36259   0, /*nb_divide*/
36260   #endif
36261   0, /*nb_remainder*/
36262   0, /*nb_divmod*/
36263   0, /*nb_power*/
36264   0, /*nb_negative*/
36265   0, /*nb_positive*/
36266   0, /*nb_absolute*/
36267   0, /*nb_nonzero*/
36268   0, /*nb_invert*/
36269   0, /*nb_lshift*/
36270   0, /*nb_rshift*/
36271   0, /*nb_and*/
36272   0, /*nb_xor*/
36273   0, /*nb_or*/
36274   #if PY_MAJOR_VERSION < 3
36275   0, /*nb_coerce*/
36276   #endif
36277   0, /*nb_int*/
36278   #if PY_MAJOR_VERSION < 3
36279   0, /*nb_long*/
36280   #else
36281   0, /*reserved*/
36282   #endif
36283   0, /*nb_float*/
36284   #if PY_MAJOR_VERSION < 3
36285   0, /*nb_oct*/
36286   #endif
36287   #if PY_MAJOR_VERSION < 3
36288   0, /*nb_hex*/
36289   #endif
36290   0, /*nb_inplace_add*/
36291   0, /*nb_inplace_subtract*/
36292   0, /*nb_inplace_multiply*/
36293   #if PY_MAJOR_VERSION < 3
36294   0, /*nb_inplace_divide*/
36295   #endif
36296   0, /*nb_inplace_remainder*/
36297   0, /*nb_inplace_power*/
36298   0, /*nb_inplace_lshift*/
36299   0, /*nb_inplace_rshift*/
36300   0, /*nb_inplace_and*/
36301   0, /*nb_inplace_xor*/
36302   0, /*nb_inplace_or*/
36303   0, /*nb_floor_divide*/
36304   0, /*nb_true_divide*/
36305   0, /*nb_inplace_floor_divide*/
36306   0, /*nb_inplace_true_divide*/
36307   #if PY_VERSION_HEX >= 0x02050000
36308   0, /*nb_index*/
36309   #endif
36310 };
36311
36312 static PySequenceMethods __pyx_tp_as_sequence_PileupRead = {
36313   0, /*sq_length*/
36314   0, /*sq_concat*/
36315   0, /*sq_repeat*/
36316   0, /*sq_item*/
36317   0, /*sq_slice*/
36318   0, /*sq_ass_item*/
36319   0, /*sq_ass_slice*/
36320   0, /*sq_contains*/
36321   0, /*sq_inplace_concat*/
36322   0, /*sq_inplace_repeat*/
36323 };
36324
36325 static PyMappingMethods __pyx_tp_as_mapping_PileupRead = {
36326   0, /*mp_length*/
36327   0, /*mp_subscript*/
36328   0, /*mp_ass_subscript*/
36329 };
36330
36331 static PyBufferProcs __pyx_tp_as_buffer_PileupRead = {
36332   #if PY_MAJOR_VERSION < 3
36333   0, /*bf_getreadbuffer*/
36334   #endif
36335   #if PY_MAJOR_VERSION < 3
36336   0, /*bf_getwritebuffer*/
36337   #endif
36338   #if PY_MAJOR_VERSION < 3
36339   0, /*bf_getsegcount*/
36340   #endif
36341   #if PY_MAJOR_VERSION < 3
36342   0, /*bf_getcharbuffer*/
36343   #endif
36344   #if PY_VERSION_HEX >= 0x02060000
36345   0, /*bf_getbuffer*/
36346   #endif
36347   #if PY_VERSION_HEX >= 0x02060000
36348   0, /*bf_releasebuffer*/
36349   #endif
36350 };
36351
36352 static PyTypeObject __pyx_type_9csamtools_PileupRead = {
36353   PyVarObject_HEAD_INIT(0, 0)
36354   __Pyx_NAMESTR("csamtools.PileupRead"), /*tp_name*/
36355   sizeof(struct __pyx_obj_9csamtools_PileupRead), /*tp_basicsize*/
36356   0, /*tp_itemsize*/
36357   __pyx_tp_dealloc_9csamtools_PileupRead, /*tp_dealloc*/
36358   0, /*tp_print*/
36359   0, /*tp_getattr*/
36360   0, /*tp_setattr*/
36361   #if PY_MAJOR_VERSION < 3
36362   0, /*tp_compare*/
36363   #else
36364   0, /*reserved*/
36365   #endif
36366   0, /*tp_repr*/
36367   &__pyx_tp_as_number_PileupRead, /*tp_as_number*/
36368   &__pyx_tp_as_sequence_PileupRead, /*tp_as_sequence*/
36369   &__pyx_tp_as_mapping_PileupRead, /*tp_as_mapping*/
36370   0, /*tp_hash*/
36371   0, /*tp_call*/
36372   __pyx_pw_9csamtools_10PileupRead_3__str__, /*tp_str*/
36373   0, /*tp_getattro*/
36374   0, /*tp_setattro*/
36375   &__pyx_tp_as_buffer_PileupRead, /*tp_as_buffer*/
36376   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
36377   __Pyx_DOCSTR("PileupRead()\nA read aligned to a column.\n    "), /*tp_doc*/
36378   __pyx_tp_traverse_9csamtools_PileupRead, /*tp_traverse*/
36379   __pyx_tp_clear_9csamtools_PileupRead, /*tp_clear*/
36380   0, /*tp_richcompare*/
36381   0, /*tp_weaklistoffset*/
36382   0, /*tp_iter*/
36383   0, /*tp_iternext*/
36384   __pyx_methods_9csamtools_PileupRead, /*tp_methods*/
36385   0, /*tp_members*/
36386   __pyx_getsets_9csamtools_PileupRead, /*tp_getset*/
36387   0, /*tp_base*/
36388   0, /*tp_dict*/
36389   0, /*tp_descr_get*/
36390   0, /*tp_descr_set*/
36391   0, /*tp_dictoffset*/
36392   __pyx_pw_9csamtools_10PileupRead_1__init__, /*tp_init*/
36393   0, /*tp_alloc*/
36394   __pyx_tp_new_9csamtools_PileupRead, /*tp_new*/
36395   0, /*tp_free*/
36396   0, /*tp_is_gc*/
36397   0, /*tp_bases*/
36398   0, /*tp_mro*/
36399   0, /*tp_cache*/
36400   0, /*tp_subclasses*/
36401   0, /*tp_weaklist*/
36402   0, /*tp_del*/
36403   #if PY_VERSION_HEX >= 0x02060000
36404   0, /*tp_version_tag*/
36405   #endif
36406 };
36407
36408 static PyObject *__pyx_tp_new_9csamtools_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k) {
36409   PyObject *o = (*t->tp_alloc)(t, 0);
36410   if (!o) return 0;
36411   return o;
36412 }
36413
36414 static void __pyx_tp_dealloc_9csamtools_IteratorRow(PyObject *o) {
36415   (*Py_TYPE(o)->tp_free)(o);
36416 }
36417
36418 static PyMethodDef __pyx_methods_9csamtools_IteratorRow[] = {
36419   {0, 0, 0, 0}
36420 };
36421
36422 static PyNumberMethods __pyx_tp_as_number_IteratorRow = {
36423   0, /*nb_add*/
36424   0, /*nb_subtract*/
36425   0, /*nb_multiply*/
36426   #if PY_MAJOR_VERSION < 3
36427   0, /*nb_divide*/
36428   #endif
36429   0, /*nb_remainder*/
36430   0, /*nb_divmod*/
36431   0, /*nb_power*/
36432   0, /*nb_negative*/
36433   0, /*nb_positive*/
36434   0, /*nb_absolute*/
36435   0, /*nb_nonzero*/
36436   0, /*nb_invert*/
36437   0, /*nb_lshift*/
36438   0, /*nb_rshift*/
36439   0, /*nb_and*/
36440   0, /*nb_xor*/
36441   0, /*nb_or*/
36442   #if PY_MAJOR_VERSION < 3
36443   0, /*nb_coerce*/
36444   #endif
36445   0, /*nb_int*/
36446   #if PY_MAJOR_VERSION < 3
36447   0, /*nb_long*/
36448   #else
36449   0, /*reserved*/
36450   #endif
36451   0, /*nb_float*/
36452   #if PY_MAJOR_VERSION < 3
36453   0, /*nb_oct*/
36454   #endif
36455   #if PY_MAJOR_VERSION < 3
36456   0, /*nb_hex*/
36457   #endif
36458   0, /*nb_inplace_add*/
36459   0, /*nb_inplace_subtract*/
36460   0, /*nb_inplace_multiply*/
36461   #if PY_MAJOR_VERSION < 3
36462   0, /*nb_inplace_divide*/
36463   #endif
36464   0, /*nb_inplace_remainder*/
36465   0, /*nb_inplace_power*/
36466   0, /*nb_inplace_lshift*/
36467   0, /*nb_inplace_rshift*/
36468   0, /*nb_inplace_and*/
36469   0, /*nb_inplace_xor*/
36470   0, /*nb_inplace_or*/
36471   0, /*nb_floor_divide*/
36472   0, /*nb_true_divide*/
36473   0, /*nb_inplace_floor_divide*/
36474   0, /*nb_inplace_true_divide*/
36475   #if PY_VERSION_HEX >= 0x02050000
36476   0, /*nb_index*/
36477   #endif
36478 };
36479
36480 static PySequenceMethods __pyx_tp_as_sequence_IteratorRow = {
36481   0, /*sq_length*/
36482   0, /*sq_concat*/
36483   0, /*sq_repeat*/
36484   0, /*sq_item*/
36485   0, /*sq_slice*/
36486   0, /*sq_ass_item*/
36487   0, /*sq_ass_slice*/
36488   0, /*sq_contains*/
36489   0, /*sq_inplace_concat*/
36490   0, /*sq_inplace_repeat*/
36491 };
36492
36493 static PyMappingMethods __pyx_tp_as_mapping_IteratorRow = {
36494   0, /*mp_length*/
36495   0, /*mp_subscript*/
36496   0, /*mp_ass_subscript*/
36497 };
36498
36499 static PyBufferProcs __pyx_tp_as_buffer_IteratorRow = {
36500   #if PY_MAJOR_VERSION < 3
36501   0, /*bf_getreadbuffer*/
36502   #endif
36503   #if PY_MAJOR_VERSION < 3
36504   0, /*bf_getwritebuffer*/
36505   #endif
36506   #if PY_MAJOR_VERSION < 3
36507   0, /*bf_getsegcount*/
36508   #endif
36509   #if PY_MAJOR_VERSION < 3
36510   0, /*bf_getcharbuffer*/
36511   #endif
36512   #if PY_VERSION_HEX >= 0x02060000
36513   0, /*bf_getbuffer*/
36514   #endif
36515   #if PY_VERSION_HEX >= 0x02060000
36516   0, /*bf_releasebuffer*/
36517   #endif
36518 };
36519
36520 static PyTypeObject __pyx_type_9csamtools_IteratorRow = {
36521   PyVarObject_HEAD_INIT(0, 0)
36522   __Pyx_NAMESTR("csamtools.IteratorRow"), /*tp_name*/
36523   sizeof(struct __pyx_obj_9csamtools_IteratorRow), /*tp_basicsize*/
36524   0, /*tp_itemsize*/
36525   __pyx_tp_dealloc_9csamtools_IteratorRow, /*tp_dealloc*/
36526   0, /*tp_print*/
36527   0, /*tp_getattr*/
36528   0, /*tp_setattr*/
36529   #if PY_MAJOR_VERSION < 3
36530   0, /*tp_compare*/
36531   #else
36532   0, /*reserved*/
36533   #endif
36534   0, /*tp_repr*/
36535   &__pyx_tp_as_number_IteratorRow, /*tp_as_number*/
36536   &__pyx_tp_as_sequence_IteratorRow, /*tp_as_sequence*/
36537   &__pyx_tp_as_mapping_IteratorRow, /*tp_as_mapping*/
36538   0, /*tp_hash*/
36539   0, /*tp_call*/
36540   0, /*tp_str*/
36541   0, /*tp_getattro*/
36542   0, /*tp_setattro*/
36543   &__pyx_tp_as_buffer_IteratorRow, /*tp_as_buffer*/
36544   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
36545   __Pyx_DOCSTR("abstract base class for iterators over mapped reads.\n\n    Various iterators implement different behaviours for wrapping around\n    contig boundaries. Examples include:\n\n    :class:`pysam.IteratorRowRegion`\n        iterate within a single contig and a defined region.\n\n    :class:`pysam.IteratorRowAll`\n        iterate until EOF. This iterator will also include unmapped reads.\n\n    :class:`pysam.IteratorRowAllRefs`\n        iterate over all reads in all reference sequences.\n\n    The method :meth:`Samfile.fetch` returns an IteratorRow.\n    "), /*tp_doc*/
36546   0, /*tp_traverse*/
36547   0, /*tp_clear*/
36548   0, /*tp_richcompare*/
36549   0, /*tp_weaklistoffset*/
36550   0, /*tp_iter*/
36551   0, /*tp_iternext*/
36552   __pyx_methods_9csamtools_IteratorRow, /*tp_methods*/
36553   0, /*tp_members*/
36554   0, /*tp_getset*/
36555   0, /*tp_base*/
36556   0, /*tp_dict*/
36557   0, /*tp_descr_get*/
36558   0, /*tp_descr_set*/
36559   0, /*tp_dictoffset*/
36560   0, /*tp_init*/
36561   0, /*tp_alloc*/
36562   __pyx_tp_new_9csamtools_IteratorRow, /*tp_new*/
36563   0, /*tp_free*/
36564   0, /*tp_is_gc*/
36565   0, /*tp_bases*/
36566   0, /*tp_mro*/
36567   0, /*tp_cache*/
36568   0, /*tp_subclasses*/
36569   0, /*tp_weaklist*/
36570   0, /*tp_del*/
36571   #if PY_VERSION_HEX >= 0x02060000
36572   0, /*tp_version_tag*/
36573   #endif
36574 };
36575 static struct __pyx_vtabstruct_9csamtools_IteratorRowRegion __pyx_vtable_9csamtools_IteratorRowRegion;
36576
36577 static PyObject *__pyx_tp_new_9csamtools_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
36578   struct __pyx_obj_9csamtools_IteratorRowRegion *p;
36579   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
36580   if (!o) return 0;
36581   p = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)o);
36582   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowRegion;
36583   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
36584   if (__pyx_pw_9csamtools_17IteratorRowRegion_1__cinit__(o, a, k) < 0) {
36585     Py_DECREF(o); o = 0;
36586   }
36587   return o;
36588 }
36589
36590 static void __pyx_tp_dealloc_9csamtools_IteratorRowRegion(PyObject *o) {
36591   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
36592   {
36593     PyObject *etype, *eval, *etb;
36594     PyErr_Fetch(&etype, &eval, &etb);
36595     ++Py_REFCNT(o);
36596     __pyx_pw_9csamtools_17IteratorRowRegion_7__dealloc__(o);
36597     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
36598     --Py_REFCNT(o);
36599     PyErr_Restore(etype, eval, etb);
36600   }
36601   Py_XDECREF(((PyObject *)p->samfile));
36602   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
36603 }
36604
36605 static int __pyx_tp_traverse_9csamtools_IteratorRowRegion(PyObject *o, visitproc v, void *a) {
36606   int e;
36607   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
36608   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
36609     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
36610   }
36611   if (p->samfile) {
36612     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
36613   }
36614   return 0;
36615 }
36616
36617 static int __pyx_tp_clear_9csamtools_IteratorRowRegion(PyObject *o) {
36618   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
36619   PyObject* tmp;
36620   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
36621     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
36622   }
36623   tmp = ((PyObject*)p->samfile);
36624   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
36625   Py_XDECREF(tmp);
36626   return 0;
36627 }
36628
36629 static PyMethodDef __pyx_methods_9csamtools_IteratorRowRegion[] = {
36630   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_17IteratorRowRegion_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_17IteratorRowRegion_4__next__)},
36631   {0, 0, 0, 0}
36632 };
36633
36634 static PyNumberMethods __pyx_tp_as_number_IteratorRowRegion = {
36635   0, /*nb_add*/
36636   0, /*nb_subtract*/
36637   0, /*nb_multiply*/
36638   #if PY_MAJOR_VERSION < 3
36639   0, /*nb_divide*/
36640   #endif
36641   0, /*nb_remainder*/
36642   0, /*nb_divmod*/
36643   0, /*nb_power*/
36644   0, /*nb_negative*/
36645   0, /*nb_positive*/
36646   0, /*nb_absolute*/
36647   0, /*nb_nonzero*/
36648   0, /*nb_invert*/
36649   0, /*nb_lshift*/
36650   0, /*nb_rshift*/
36651   0, /*nb_and*/
36652   0, /*nb_xor*/
36653   0, /*nb_or*/
36654   #if PY_MAJOR_VERSION < 3
36655   0, /*nb_coerce*/
36656   #endif
36657   0, /*nb_int*/
36658   #if PY_MAJOR_VERSION < 3
36659   0, /*nb_long*/
36660   #else
36661   0, /*reserved*/
36662   #endif
36663   0, /*nb_float*/
36664   #if PY_MAJOR_VERSION < 3
36665   0, /*nb_oct*/
36666   #endif
36667   #if PY_MAJOR_VERSION < 3
36668   0, /*nb_hex*/
36669   #endif
36670   0, /*nb_inplace_add*/
36671   0, /*nb_inplace_subtract*/
36672   0, /*nb_inplace_multiply*/
36673   #if PY_MAJOR_VERSION < 3
36674   0, /*nb_inplace_divide*/
36675   #endif
36676   0, /*nb_inplace_remainder*/
36677   0, /*nb_inplace_power*/
36678   0, /*nb_inplace_lshift*/
36679   0, /*nb_inplace_rshift*/
36680   0, /*nb_inplace_and*/
36681   0, /*nb_inplace_xor*/
36682   0, /*nb_inplace_or*/
36683   0, /*nb_floor_divide*/
36684   0, /*nb_true_divide*/
36685   0, /*nb_inplace_floor_divide*/
36686   0, /*nb_inplace_true_divide*/
36687   #if PY_VERSION_HEX >= 0x02050000
36688   0, /*nb_index*/
36689   #endif
36690 };
36691
36692 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowRegion = {
36693   0, /*sq_length*/
36694   0, /*sq_concat*/
36695   0, /*sq_repeat*/
36696   0, /*sq_item*/
36697   0, /*sq_slice*/
36698   0, /*sq_ass_item*/
36699   0, /*sq_ass_slice*/
36700   0, /*sq_contains*/
36701   0, /*sq_inplace_concat*/
36702   0, /*sq_inplace_repeat*/
36703 };
36704
36705 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowRegion = {
36706   0, /*mp_length*/
36707   0, /*mp_subscript*/
36708   0, /*mp_ass_subscript*/
36709 };
36710
36711 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowRegion = {
36712   #if PY_MAJOR_VERSION < 3
36713   0, /*bf_getreadbuffer*/
36714   #endif
36715   #if PY_MAJOR_VERSION < 3
36716   0, /*bf_getwritebuffer*/
36717   #endif
36718   #if PY_MAJOR_VERSION < 3
36719   0, /*bf_getsegcount*/
36720   #endif
36721   #if PY_MAJOR_VERSION < 3
36722   0, /*bf_getcharbuffer*/
36723   #endif
36724   #if PY_VERSION_HEX >= 0x02060000
36725   0, /*bf_getbuffer*/
36726   #endif
36727   #if PY_VERSION_HEX >= 0x02060000
36728   0, /*bf_releasebuffer*/
36729   #endif
36730 };
36731
36732 static PyTypeObject __pyx_type_9csamtools_IteratorRowRegion = {
36733   PyVarObject_HEAD_INIT(0, 0)
36734   __Pyx_NAMESTR("csamtools.IteratorRowRegion"), /*tp_name*/
36735   sizeof(struct __pyx_obj_9csamtools_IteratorRowRegion), /*tp_basicsize*/
36736   0, /*tp_itemsize*/
36737   __pyx_tp_dealloc_9csamtools_IteratorRowRegion, /*tp_dealloc*/
36738   0, /*tp_print*/
36739   0, /*tp_getattr*/
36740   0, /*tp_setattr*/
36741   #if PY_MAJOR_VERSION < 3
36742   0, /*tp_compare*/
36743   #else
36744   0, /*reserved*/
36745   #endif
36746   0, /*tp_repr*/
36747   &__pyx_tp_as_number_IteratorRowRegion, /*tp_as_number*/
36748   &__pyx_tp_as_sequence_IteratorRowRegion, /*tp_as_sequence*/
36749   &__pyx_tp_as_mapping_IteratorRowRegion, /*tp_as_mapping*/
36750   0, /*tp_hash*/
36751   0, /*tp_call*/
36752   0, /*tp_str*/
36753   0, /*tp_getattro*/
36754   0, /*tp_setattro*/
36755   &__pyx_tp_as_buffer_IteratorRowRegion, /*tp_as_buffer*/
36756   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
36757   __Pyx_DOCSTR("*(Samfile samfile, int tid, int beg, int end, int reopen = True )*\n\n    iterate over mapped reads in a region.\n\n    By default, the file is re-openend to avoid conflicts between\n    multiple iterators working on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n\n    The samtools iterators assume that the file\n    position between iterations do not change.\n    As a consequence, no two iterators can work\n    on the same file. To permit this, each iterator\n    creates its own file handle by re-opening the\n    file.\n\n    Note that the index will be shared between\n    samfile and the iterator.\n    "), /*tp_doc*/
36758   __pyx_tp_traverse_9csamtools_IteratorRowRegion, /*tp_traverse*/
36759   __pyx_tp_clear_9csamtools_IteratorRowRegion, /*tp_clear*/
36760   0, /*tp_richcompare*/
36761   0, /*tp_weaklistoffset*/
36762   __pyx_pw_9csamtools_17IteratorRowRegion_3__iter__, /*tp_iter*/
36763   __pyx_pw_9csamtools_17IteratorRowRegion_5__next__, /*tp_iternext*/
36764   __pyx_methods_9csamtools_IteratorRowRegion, /*tp_methods*/
36765   0, /*tp_members*/
36766   0, /*tp_getset*/
36767   0, /*tp_base*/
36768   0, /*tp_dict*/
36769   0, /*tp_descr_get*/
36770   0, /*tp_descr_set*/
36771   0, /*tp_dictoffset*/
36772   0, /*tp_init*/
36773   0, /*tp_alloc*/
36774   __pyx_tp_new_9csamtools_IteratorRowRegion, /*tp_new*/
36775   0, /*tp_free*/
36776   0, /*tp_is_gc*/
36777   0, /*tp_bases*/
36778   0, /*tp_mro*/
36779   0, /*tp_cache*/
36780   0, /*tp_subclasses*/
36781   0, /*tp_weaklist*/
36782   0, /*tp_del*/
36783   #if PY_VERSION_HEX >= 0x02060000
36784   0, /*tp_version_tag*/
36785   #endif
36786 };
36787 static struct __pyx_vtabstruct_9csamtools_IteratorRowAll __pyx_vtable_9csamtools_IteratorRowAll;
36788
36789 static PyObject *__pyx_tp_new_9csamtools_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
36790   struct __pyx_obj_9csamtools_IteratorRowAll *p;
36791   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
36792   if (!o) return 0;
36793   p = ((struct __pyx_obj_9csamtools_IteratorRowAll *)o);
36794   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowAll;
36795   if (__pyx_pw_9csamtools_14IteratorRowAll_1__cinit__(o, a, k) < 0) {
36796     Py_DECREF(o); o = 0;
36797   }
36798   return o;
36799 }
36800
36801 static void __pyx_tp_dealloc_9csamtools_IteratorRowAll(PyObject *o) {
36802   {
36803     PyObject *etype, *eval, *etb;
36804     PyErr_Fetch(&etype, &eval, &etb);
36805     ++Py_REFCNT(o);
36806     __pyx_pw_9csamtools_14IteratorRowAll_7__dealloc__(o);
36807     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
36808     --Py_REFCNT(o);
36809     PyErr_Restore(etype, eval, etb);
36810   }
36811   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
36812 }
36813
36814 static PyMethodDef __pyx_methods_9csamtools_IteratorRowAll[] = {
36815   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_14IteratorRowAll_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorRowAll_4__next__)},
36816   {0, 0, 0, 0}
36817 };
36818
36819 static PyNumberMethods __pyx_tp_as_number_IteratorRowAll = {
36820   0, /*nb_add*/
36821   0, /*nb_subtract*/
36822   0, /*nb_multiply*/
36823   #if PY_MAJOR_VERSION < 3
36824   0, /*nb_divide*/
36825   #endif
36826   0, /*nb_remainder*/
36827   0, /*nb_divmod*/
36828   0, /*nb_power*/
36829   0, /*nb_negative*/
36830   0, /*nb_positive*/
36831   0, /*nb_absolute*/
36832   0, /*nb_nonzero*/
36833   0, /*nb_invert*/
36834   0, /*nb_lshift*/
36835   0, /*nb_rshift*/
36836   0, /*nb_and*/
36837   0, /*nb_xor*/
36838   0, /*nb_or*/
36839   #if PY_MAJOR_VERSION < 3
36840   0, /*nb_coerce*/
36841   #endif
36842   0, /*nb_int*/
36843   #if PY_MAJOR_VERSION < 3
36844   0, /*nb_long*/
36845   #else
36846   0, /*reserved*/
36847   #endif
36848   0, /*nb_float*/
36849   #if PY_MAJOR_VERSION < 3
36850   0, /*nb_oct*/
36851   #endif
36852   #if PY_MAJOR_VERSION < 3
36853   0, /*nb_hex*/
36854   #endif
36855   0, /*nb_inplace_add*/
36856   0, /*nb_inplace_subtract*/
36857   0, /*nb_inplace_multiply*/
36858   #if PY_MAJOR_VERSION < 3
36859   0, /*nb_inplace_divide*/
36860   #endif
36861   0, /*nb_inplace_remainder*/
36862   0, /*nb_inplace_power*/
36863   0, /*nb_inplace_lshift*/
36864   0, /*nb_inplace_rshift*/
36865   0, /*nb_inplace_and*/
36866   0, /*nb_inplace_xor*/
36867   0, /*nb_inplace_or*/
36868   0, /*nb_floor_divide*/
36869   0, /*nb_true_divide*/
36870   0, /*nb_inplace_floor_divide*/
36871   0, /*nb_inplace_true_divide*/
36872   #if PY_VERSION_HEX >= 0x02050000
36873   0, /*nb_index*/
36874   #endif
36875 };
36876
36877 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowAll = {
36878   0, /*sq_length*/
36879   0, /*sq_concat*/
36880   0, /*sq_repeat*/
36881   0, /*sq_item*/
36882   0, /*sq_slice*/
36883   0, /*sq_ass_item*/
36884   0, /*sq_ass_slice*/
36885   0, /*sq_contains*/
36886   0, /*sq_inplace_concat*/
36887   0, /*sq_inplace_repeat*/
36888 };
36889
36890 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowAll = {
36891   0, /*mp_length*/
36892   0, /*mp_subscript*/
36893   0, /*mp_ass_subscript*/
36894 };
36895
36896 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowAll = {
36897   #if PY_MAJOR_VERSION < 3
36898   0, /*bf_getreadbuffer*/
36899   #endif
36900   #if PY_MAJOR_VERSION < 3
36901   0, /*bf_getwritebuffer*/
36902   #endif
36903   #if PY_MAJOR_VERSION < 3
36904   0, /*bf_getsegcount*/
36905   #endif
36906   #if PY_MAJOR_VERSION < 3
36907   0, /*bf_getcharbuffer*/
36908   #endif
36909   #if PY_VERSION_HEX >= 0x02060000
36910   0, /*bf_getbuffer*/
36911   #endif
36912   #if PY_VERSION_HEX >= 0x02060000
36913   0, /*bf_releasebuffer*/
36914   #endif
36915 };
36916
36917 static PyTypeObject __pyx_type_9csamtools_IteratorRowAll = {
36918   PyVarObject_HEAD_INIT(0, 0)
36919   __Pyx_NAMESTR("csamtools.IteratorRowAll"), /*tp_name*/
36920   sizeof(struct __pyx_obj_9csamtools_IteratorRowAll), /*tp_basicsize*/
36921   0, /*tp_itemsize*/
36922   __pyx_tp_dealloc_9csamtools_IteratorRowAll, /*tp_dealloc*/
36923   0, /*tp_print*/
36924   0, /*tp_getattr*/
36925   0, /*tp_setattr*/
36926   #if PY_MAJOR_VERSION < 3
36927   0, /*tp_compare*/
36928   #else
36929   0, /*reserved*/
36930   #endif
36931   0, /*tp_repr*/
36932   &__pyx_tp_as_number_IteratorRowAll, /*tp_as_number*/
36933   &__pyx_tp_as_sequence_IteratorRowAll, /*tp_as_sequence*/
36934   &__pyx_tp_as_mapping_IteratorRowAll, /*tp_as_mapping*/
36935   0, /*tp_hash*/
36936   0, /*tp_call*/
36937   0, /*tp_str*/
36938   0, /*tp_getattro*/
36939   0, /*tp_setattro*/
36940   &__pyx_tp_as_buffer_IteratorRowAll, /*tp_as_buffer*/
36941   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
36942   __Pyx_DOCSTR("*(Samfile samfile, int reopen = True)*\n\n    iterate over all reads in *samfile*\n\n    By default, the file is re-openend to avoid conflicts between\n    multiple iterators working on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n    "), /*tp_doc*/
36943   0, /*tp_traverse*/
36944   0, /*tp_clear*/
36945   0, /*tp_richcompare*/
36946   0, /*tp_weaklistoffset*/
36947   __pyx_pw_9csamtools_14IteratorRowAll_3__iter__, /*tp_iter*/
36948   __pyx_pw_9csamtools_14IteratorRowAll_5__next__, /*tp_iternext*/
36949   __pyx_methods_9csamtools_IteratorRowAll, /*tp_methods*/
36950   0, /*tp_members*/
36951   0, /*tp_getset*/
36952   0, /*tp_base*/
36953   0, /*tp_dict*/
36954   0, /*tp_descr_get*/
36955   0, /*tp_descr_set*/
36956   0, /*tp_dictoffset*/
36957   0, /*tp_init*/
36958   0, /*tp_alloc*/
36959   __pyx_tp_new_9csamtools_IteratorRowAll, /*tp_new*/
36960   0, /*tp_free*/
36961   0, /*tp_is_gc*/
36962   0, /*tp_bases*/
36963   0, /*tp_mro*/
36964   0, /*tp_cache*/
36965   0, /*tp_subclasses*/
36966   0, /*tp_weaklist*/
36967   0, /*tp_del*/
36968   #if PY_VERSION_HEX >= 0x02060000
36969   0, /*tp_version_tag*/
36970   #endif
36971 };
36972
36973 static PyObject *__pyx_tp_new_9csamtools_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
36974   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p;
36975   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
36976   if (!o) return 0;
36977   p = ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o);
36978   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
36979   p->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
36980   if (__pyx_pw_9csamtools_18IteratorRowAllRefs_1__cinit__(o, a, k) < 0) {
36981     Py_DECREF(o); o = 0;
36982   }
36983   return o;
36984 }
36985
36986 static void __pyx_tp_dealloc_9csamtools_IteratorRowAllRefs(PyObject *o) {
36987   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
36988   Py_XDECREF(((PyObject *)p->samfile));
36989   Py_XDECREF(((PyObject *)p->rowiter));
36990   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
36991 }
36992
36993 static int __pyx_tp_traverse_9csamtools_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
36994   int e;
36995   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
36996   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
36997     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
36998   }
36999   if (p->samfile) {
37000     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
37001   }
37002   if (p->rowiter) {
37003     e = (*v)(((PyObject*)p->rowiter), a); if (e) return e;
37004   }
37005   return 0;
37006 }
37007
37008 static int __pyx_tp_clear_9csamtools_IteratorRowAllRefs(PyObject *o) {
37009   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
37010   PyObject* tmp;
37011   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
37012     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
37013   }
37014   tmp = ((PyObject*)p->samfile);
37015   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
37016   Py_XDECREF(tmp);
37017   tmp = ((PyObject*)p->rowiter);
37018   p->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
37019   Py_XDECREF(tmp);
37020   return 0;
37021 }
37022
37023 static PyMethodDef __pyx_methods_9csamtools_IteratorRowAllRefs[] = {
37024   {__Pyx_NAMESTR("nextiter"), (PyCFunction)__pyx_pw_9csamtools_18IteratorRowAllRefs_3nextiter, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_18IteratorRowAllRefs_2nextiter)},
37025   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_18IteratorRowAllRefs_7__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_18IteratorRowAllRefs_6__next__)},
37026   {0, 0, 0, 0}
37027 };
37028
37029 static PyNumberMethods __pyx_tp_as_number_IteratorRowAllRefs = {
37030   0, /*nb_add*/
37031   0, /*nb_subtract*/
37032   0, /*nb_multiply*/
37033   #if PY_MAJOR_VERSION < 3
37034   0, /*nb_divide*/
37035   #endif
37036   0, /*nb_remainder*/
37037   0, /*nb_divmod*/
37038   0, /*nb_power*/
37039   0, /*nb_negative*/
37040   0, /*nb_positive*/
37041   0, /*nb_absolute*/
37042   0, /*nb_nonzero*/
37043   0, /*nb_invert*/
37044   0, /*nb_lshift*/
37045   0, /*nb_rshift*/
37046   0, /*nb_and*/
37047   0, /*nb_xor*/
37048   0, /*nb_or*/
37049   #if PY_MAJOR_VERSION < 3
37050   0, /*nb_coerce*/
37051   #endif
37052   0, /*nb_int*/
37053   #if PY_MAJOR_VERSION < 3
37054   0, /*nb_long*/
37055   #else
37056   0, /*reserved*/
37057   #endif
37058   0, /*nb_float*/
37059   #if PY_MAJOR_VERSION < 3
37060   0, /*nb_oct*/
37061   #endif
37062   #if PY_MAJOR_VERSION < 3
37063   0, /*nb_hex*/
37064   #endif
37065   0, /*nb_inplace_add*/
37066   0, /*nb_inplace_subtract*/
37067   0, /*nb_inplace_multiply*/
37068   #if PY_MAJOR_VERSION < 3
37069   0, /*nb_inplace_divide*/
37070   #endif
37071   0, /*nb_inplace_remainder*/
37072   0, /*nb_inplace_power*/
37073   0, /*nb_inplace_lshift*/
37074   0, /*nb_inplace_rshift*/
37075   0, /*nb_inplace_and*/
37076   0, /*nb_inplace_xor*/
37077   0, /*nb_inplace_or*/
37078   0, /*nb_floor_divide*/
37079   0, /*nb_true_divide*/
37080   0, /*nb_inplace_floor_divide*/
37081   0, /*nb_inplace_true_divide*/
37082   #if PY_VERSION_HEX >= 0x02050000
37083   0, /*nb_index*/
37084   #endif
37085 };
37086
37087 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowAllRefs = {
37088   0, /*sq_length*/
37089   0, /*sq_concat*/
37090   0, /*sq_repeat*/
37091   0, /*sq_item*/
37092   0, /*sq_slice*/
37093   0, /*sq_ass_item*/
37094   0, /*sq_ass_slice*/
37095   0, /*sq_contains*/
37096   0, /*sq_inplace_concat*/
37097   0, /*sq_inplace_repeat*/
37098 };
37099
37100 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowAllRefs = {
37101   0, /*mp_length*/
37102   0, /*mp_subscript*/
37103   0, /*mp_ass_subscript*/
37104 };
37105
37106 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowAllRefs = {
37107   #if PY_MAJOR_VERSION < 3
37108   0, /*bf_getreadbuffer*/
37109   #endif
37110   #if PY_MAJOR_VERSION < 3
37111   0, /*bf_getwritebuffer*/
37112   #endif
37113   #if PY_MAJOR_VERSION < 3
37114   0, /*bf_getsegcount*/
37115   #endif
37116   #if PY_MAJOR_VERSION < 3
37117   0, /*bf_getcharbuffer*/
37118   #endif
37119   #if PY_VERSION_HEX >= 0x02060000
37120   0, /*bf_getbuffer*/
37121   #endif
37122   #if PY_VERSION_HEX >= 0x02060000
37123   0, /*bf_releasebuffer*/
37124   #endif
37125 };
37126
37127 static PyTypeObject __pyx_type_9csamtools_IteratorRowAllRefs = {
37128   PyVarObject_HEAD_INIT(0, 0)
37129   __Pyx_NAMESTR("csamtools.IteratorRowAllRefs"), /*tp_name*/
37130   sizeof(struct __pyx_obj_9csamtools_IteratorRowAllRefs), /*tp_basicsize*/
37131   0, /*tp_itemsize*/
37132   __pyx_tp_dealloc_9csamtools_IteratorRowAllRefs, /*tp_dealloc*/
37133   0, /*tp_print*/
37134   0, /*tp_getattr*/
37135   0, /*tp_setattr*/
37136   #if PY_MAJOR_VERSION < 3
37137   0, /*tp_compare*/
37138   #else
37139   0, /*reserved*/
37140   #endif
37141   0, /*tp_repr*/
37142   &__pyx_tp_as_number_IteratorRowAllRefs, /*tp_as_number*/
37143   &__pyx_tp_as_sequence_IteratorRowAllRefs, /*tp_as_sequence*/
37144   &__pyx_tp_as_mapping_IteratorRowAllRefs, /*tp_as_mapping*/
37145   0, /*tp_hash*/
37146   0, /*tp_call*/
37147   0, /*tp_str*/
37148   0, /*tp_getattro*/
37149   0, /*tp_setattro*/
37150   &__pyx_tp_as_buffer_IteratorRowAllRefs, /*tp_as_buffer*/
37151   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
37152   __Pyx_DOCSTR("iterates over all mapped reads by chaining iterators over each reference\n    "), /*tp_doc*/
37153   __pyx_tp_traverse_9csamtools_IteratorRowAllRefs, /*tp_traverse*/
37154   __pyx_tp_clear_9csamtools_IteratorRowAllRefs, /*tp_clear*/
37155   0, /*tp_richcompare*/
37156   0, /*tp_weaklistoffset*/
37157   __pyx_pw_9csamtools_18IteratorRowAllRefs_5__iter__, /*tp_iter*/
37158   __pyx_pw_9csamtools_18IteratorRowAllRefs_7__next__, /*tp_iternext*/
37159   __pyx_methods_9csamtools_IteratorRowAllRefs, /*tp_methods*/
37160   0, /*tp_members*/
37161   0, /*tp_getset*/
37162   0, /*tp_base*/
37163   0, /*tp_dict*/
37164   0, /*tp_descr_get*/
37165   0, /*tp_descr_set*/
37166   0, /*tp_dictoffset*/
37167   0, /*tp_init*/
37168   0, /*tp_alloc*/
37169   __pyx_tp_new_9csamtools_IteratorRowAllRefs, /*tp_new*/
37170   0, /*tp_free*/
37171   0, /*tp_is_gc*/
37172   0, /*tp_bases*/
37173   0, /*tp_mro*/
37174   0, /*tp_cache*/
37175   0, /*tp_subclasses*/
37176   0, /*tp_weaklist*/
37177   0, /*tp_del*/
37178   #if PY_VERSION_HEX >= 0x02060000
37179   0, /*tp_version_tag*/
37180   #endif
37181 };
37182 static struct __pyx_vtabstruct_9csamtools_IteratorRowSelection __pyx_vtable_9csamtools_IteratorRowSelection;
37183
37184 static PyObject *__pyx_tp_new_9csamtools_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
37185   struct __pyx_obj_9csamtools_IteratorRowSelection *p;
37186   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
37187   if (!o) return 0;
37188   p = ((struct __pyx_obj_9csamtools_IteratorRowSelection *)o);
37189   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowSelection;
37190   p->positions = Py_None; Py_INCREF(Py_None);
37191   if (__pyx_pw_9csamtools_20IteratorRowSelection_1__cinit__(o, a, k) < 0) {
37192     Py_DECREF(o); o = 0;
37193   }
37194   return o;
37195 }
37196
37197 static void __pyx_tp_dealloc_9csamtools_IteratorRowSelection(PyObject *o) {
37198   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
37199   {
37200     PyObject *etype, *eval, *etb;
37201     PyErr_Fetch(&etype, &eval, &etb);
37202     ++Py_REFCNT(o);
37203     __pyx_pw_9csamtools_20IteratorRowSelection_7__dealloc__(o);
37204     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
37205     --Py_REFCNT(o);
37206     PyErr_Restore(etype, eval, etb);
37207   }
37208   Py_XDECREF(p->positions);
37209   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
37210 }
37211
37212 static int __pyx_tp_traverse_9csamtools_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
37213   int e;
37214   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
37215   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
37216     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
37217   }
37218   if (p->positions) {
37219     e = (*v)(p->positions, a); if (e) return e;
37220   }
37221   return 0;
37222 }
37223
37224 static int __pyx_tp_clear_9csamtools_IteratorRowSelection(PyObject *o) {
37225   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
37226   PyObject* tmp;
37227   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
37228     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
37229   }
37230   tmp = ((PyObject*)p->positions);
37231   p->positions = Py_None; Py_INCREF(Py_None);
37232   Py_XDECREF(tmp);
37233   return 0;
37234 }
37235
37236 static PyMethodDef __pyx_methods_9csamtools_IteratorRowSelection[] = {
37237   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_20IteratorRowSelection_5__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_20IteratorRowSelection_4__next__)},
37238   {0, 0, 0, 0}
37239 };
37240
37241 static PyNumberMethods __pyx_tp_as_number_IteratorRowSelection = {
37242   0, /*nb_add*/
37243   0, /*nb_subtract*/
37244   0, /*nb_multiply*/
37245   #if PY_MAJOR_VERSION < 3
37246   0, /*nb_divide*/
37247   #endif
37248   0, /*nb_remainder*/
37249   0, /*nb_divmod*/
37250   0, /*nb_power*/
37251   0, /*nb_negative*/
37252   0, /*nb_positive*/
37253   0, /*nb_absolute*/
37254   0, /*nb_nonzero*/
37255   0, /*nb_invert*/
37256   0, /*nb_lshift*/
37257   0, /*nb_rshift*/
37258   0, /*nb_and*/
37259   0, /*nb_xor*/
37260   0, /*nb_or*/
37261   #if PY_MAJOR_VERSION < 3
37262   0, /*nb_coerce*/
37263   #endif
37264   0, /*nb_int*/
37265   #if PY_MAJOR_VERSION < 3
37266   0, /*nb_long*/
37267   #else
37268   0, /*reserved*/
37269   #endif
37270   0, /*nb_float*/
37271   #if PY_MAJOR_VERSION < 3
37272   0, /*nb_oct*/
37273   #endif
37274   #if PY_MAJOR_VERSION < 3
37275   0, /*nb_hex*/
37276   #endif
37277   0, /*nb_inplace_add*/
37278   0, /*nb_inplace_subtract*/
37279   0, /*nb_inplace_multiply*/
37280   #if PY_MAJOR_VERSION < 3
37281   0, /*nb_inplace_divide*/
37282   #endif
37283   0, /*nb_inplace_remainder*/
37284   0, /*nb_inplace_power*/
37285   0, /*nb_inplace_lshift*/
37286   0, /*nb_inplace_rshift*/
37287   0, /*nb_inplace_and*/
37288   0, /*nb_inplace_xor*/
37289   0, /*nb_inplace_or*/
37290   0, /*nb_floor_divide*/
37291   0, /*nb_true_divide*/
37292   0, /*nb_inplace_floor_divide*/
37293   0, /*nb_inplace_true_divide*/
37294   #if PY_VERSION_HEX >= 0x02050000
37295   0, /*nb_index*/
37296   #endif
37297 };
37298
37299 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowSelection = {
37300   0, /*sq_length*/
37301   0, /*sq_concat*/
37302   0, /*sq_repeat*/
37303   0, /*sq_item*/
37304   0, /*sq_slice*/
37305   0, /*sq_ass_item*/
37306   0, /*sq_ass_slice*/
37307   0, /*sq_contains*/
37308   0, /*sq_inplace_concat*/
37309   0, /*sq_inplace_repeat*/
37310 };
37311
37312 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowSelection = {
37313   0, /*mp_length*/
37314   0, /*mp_subscript*/
37315   0, /*mp_ass_subscript*/
37316 };
37317
37318 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowSelection = {
37319   #if PY_MAJOR_VERSION < 3
37320   0, /*bf_getreadbuffer*/
37321   #endif
37322   #if PY_MAJOR_VERSION < 3
37323   0, /*bf_getwritebuffer*/
37324   #endif
37325   #if PY_MAJOR_VERSION < 3
37326   0, /*bf_getsegcount*/
37327   #endif
37328   #if PY_MAJOR_VERSION < 3
37329   0, /*bf_getcharbuffer*/
37330   #endif
37331   #if PY_VERSION_HEX >= 0x02060000
37332   0, /*bf_getbuffer*/
37333   #endif
37334   #if PY_VERSION_HEX >= 0x02060000
37335   0, /*bf_releasebuffer*/
37336   #endif
37337 };
37338
37339 static PyTypeObject __pyx_type_9csamtools_IteratorRowSelection = {
37340   PyVarObject_HEAD_INIT(0, 0)
37341   __Pyx_NAMESTR("csamtools.IteratorRowSelection"), /*tp_name*/
37342   sizeof(struct __pyx_obj_9csamtools_IteratorRowSelection), /*tp_basicsize*/
37343   0, /*tp_itemsize*/
37344   __pyx_tp_dealloc_9csamtools_IteratorRowSelection, /*tp_dealloc*/
37345   0, /*tp_print*/
37346   0, /*tp_getattr*/
37347   0, /*tp_setattr*/
37348   #if PY_MAJOR_VERSION < 3
37349   0, /*tp_compare*/
37350   #else
37351   0, /*reserved*/
37352   #endif
37353   0, /*tp_repr*/
37354   &__pyx_tp_as_number_IteratorRowSelection, /*tp_as_number*/
37355   &__pyx_tp_as_sequence_IteratorRowSelection, /*tp_as_sequence*/
37356   &__pyx_tp_as_mapping_IteratorRowSelection, /*tp_as_mapping*/
37357   0, /*tp_hash*/
37358   0, /*tp_call*/
37359   0, /*tp_str*/
37360   0, /*tp_getattro*/
37361   0, /*tp_setattro*/
37362   &__pyx_tp_as_buffer_IteratorRowSelection, /*tp_as_buffer*/
37363   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
37364   __Pyx_DOCSTR("*(Samfile samfile)*\n\n    iterate over reads in *samfile* at a given list of file positions.\n    "), /*tp_doc*/
37365   __pyx_tp_traverse_9csamtools_IteratorRowSelection, /*tp_traverse*/
37366   __pyx_tp_clear_9csamtools_IteratorRowSelection, /*tp_clear*/
37367   0, /*tp_richcompare*/
37368   0, /*tp_weaklistoffset*/
37369   __pyx_pw_9csamtools_20IteratorRowSelection_3__iter__, /*tp_iter*/
37370   __pyx_pw_9csamtools_20IteratorRowSelection_5__next__, /*tp_iternext*/
37371   __pyx_methods_9csamtools_IteratorRowSelection, /*tp_methods*/
37372   0, /*tp_members*/
37373   0, /*tp_getset*/
37374   0, /*tp_base*/
37375   0, /*tp_dict*/
37376   0, /*tp_descr_get*/
37377   0, /*tp_descr_set*/
37378   0, /*tp_dictoffset*/
37379   0, /*tp_init*/
37380   0, /*tp_alloc*/
37381   __pyx_tp_new_9csamtools_IteratorRowSelection, /*tp_new*/
37382   0, /*tp_free*/
37383   0, /*tp_is_gc*/
37384   0, /*tp_bases*/
37385   0, /*tp_mro*/
37386   0, /*tp_cache*/
37387   0, /*tp_subclasses*/
37388   0, /*tp_weaklist*/
37389   0, /*tp_del*/
37390   #if PY_VERSION_HEX >= 0x02060000
37391   0, /*tp_version_tag*/
37392   #endif
37393 };
37394 static struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_vtable_9csamtools_IteratorColumn;
37395
37396 static PyObject *__pyx_tp_new_9csamtools_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
37397   struct __pyx_obj_9csamtools_IteratorColumn *p;
37398   PyObject *o = (*t->tp_alloc)(t, 0);
37399   if (!o) return 0;
37400   p = ((struct __pyx_obj_9csamtools_IteratorColumn *)o);
37401   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorColumn;
37402   p->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
37403   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
37404   p->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
37405   p->stepper = Py_None; Py_INCREF(Py_None);
37406   if (__pyx_pw_9csamtools_14IteratorColumn_1__cinit__(o, a, k) < 0) {
37407     Py_DECREF(o); o = 0;
37408   }
37409   return o;
37410 }
37411
37412 static void __pyx_tp_dealloc_9csamtools_IteratorColumn(PyObject *o) {
37413   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
37414   {
37415     PyObject *etype, *eval, *etb;
37416     PyErr_Fetch(&etype, &eval, &etb);
37417     ++Py_REFCNT(o);
37418     __pyx_pw_9csamtools_14IteratorColumn_9__dealloc__(o);
37419     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
37420     --Py_REFCNT(o);
37421     PyErr_Restore(etype, eval, etb);
37422   }
37423   Py_XDECREF(((PyObject *)p->iter));
37424   Py_XDECREF(((PyObject *)p->samfile));
37425   Py_XDECREF(((PyObject *)p->fastafile));
37426   Py_XDECREF(p->stepper);
37427   (*Py_TYPE(o)->tp_free)(o);
37428 }
37429
37430 static int __pyx_tp_traverse_9csamtools_IteratorColumn(PyObject *o, visitproc v, void *a) {
37431   int e;
37432   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
37433   if (p->iter) {
37434     e = (*v)(((PyObject*)p->iter), a); if (e) return e;
37435   }
37436   if (p->samfile) {
37437     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
37438   }
37439   if (p->fastafile) {
37440     e = (*v)(((PyObject*)p->fastafile), a); if (e) return e;
37441   }
37442   if (p->stepper) {
37443     e = (*v)(p->stepper, a); if (e) return e;
37444   }
37445   return 0;
37446 }
37447
37448 static int __pyx_tp_clear_9csamtools_IteratorColumn(PyObject *o) {
37449   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
37450   PyObject* tmp;
37451   tmp = ((PyObject*)p->iter);
37452   p->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
37453   Py_XDECREF(tmp);
37454   tmp = ((PyObject*)p->samfile);
37455   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
37456   Py_XDECREF(tmp);
37457   tmp = ((PyObject*)p->fastafile);
37458   p->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
37459   Py_XDECREF(tmp);
37460   tmp = ((PyObject*)p->stepper);
37461   p->stepper = Py_None; Py_INCREF(Py_None);
37462   Py_XDECREF(tmp);
37463   return 0;
37464 }
37465
37466 static PyObject *__pyx_getprop_9csamtools_14IteratorColumn_seq_len(PyObject *o, void *x) {
37467   return __pyx_pw_9csamtools_14IteratorColumn_7seq_len_1__get__(o);
37468 }
37469
37470 static PyMethodDef __pyx_methods_9csamtools_IteratorColumn[] = {
37471   {__Pyx_NAMESTR("addReference"), (PyCFunction)__pyx_pw_9csamtools_14IteratorColumn_5addReference, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorColumn_4addReference)},
37472   {__Pyx_NAMESTR("hasReference"), (PyCFunction)__pyx_pw_9csamtools_14IteratorColumn_7hasReference, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorColumn_6hasReference)},
37473   {0, 0, 0, 0}
37474 };
37475
37476 static struct PyGetSetDef __pyx_getsets_9csamtools_IteratorColumn[] = {
37477   {(char *)"seq_len", __pyx_getprop_9csamtools_14IteratorColumn_seq_len, 0, __Pyx_DOCSTR(__pyx_k_241), 0},
37478   {0, 0, 0, 0, 0}
37479 };
37480
37481 static PyNumberMethods __pyx_tp_as_number_IteratorColumn = {
37482   0, /*nb_add*/
37483   0, /*nb_subtract*/
37484   0, /*nb_multiply*/
37485   #if PY_MAJOR_VERSION < 3
37486   0, /*nb_divide*/
37487   #endif
37488   0, /*nb_remainder*/
37489   0, /*nb_divmod*/
37490   0, /*nb_power*/
37491   0, /*nb_negative*/
37492   0, /*nb_positive*/
37493   0, /*nb_absolute*/
37494   0, /*nb_nonzero*/
37495   0, /*nb_invert*/
37496   0, /*nb_lshift*/
37497   0, /*nb_rshift*/
37498   0, /*nb_and*/
37499   0, /*nb_xor*/
37500   0, /*nb_or*/
37501   #if PY_MAJOR_VERSION < 3
37502   0, /*nb_coerce*/
37503   #endif
37504   0, /*nb_int*/
37505   #if PY_MAJOR_VERSION < 3
37506   0, /*nb_long*/
37507   #else
37508   0, /*reserved*/
37509   #endif
37510   0, /*nb_float*/
37511   #if PY_MAJOR_VERSION < 3
37512   0, /*nb_oct*/
37513   #endif
37514   #if PY_MAJOR_VERSION < 3
37515   0, /*nb_hex*/
37516   #endif
37517   0, /*nb_inplace_add*/
37518   0, /*nb_inplace_subtract*/
37519   0, /*nb_inplace_multiply*/
37520   #if PY_MAJOR_VERSION < 3
37521   0, /*nb_inplace_divide*/
37522   #endif
37523   0, /*nb_inplace_remainder*/
37524   0, /*nb_inplace_power*/
37525   0, /*nb_inplace_lshift*/
37526   0, /*nb_inplace_rshift*/
37527   0, /*nb_inplace_and*/
37528   0, /*nb_inplace_xor*/
37529   0, /*nb_inplace_or*/
37530   0, /*nb_floor_divide*/
37531   0, /*nb_true_divide*/
37532   0, /*nb_inplace_floor_divide*/
37533   0, /*nb_inplace_true_divide*/
37534   #if PY_VERSION_HEX >= 0x02050000
37535   0, /*nb_index*/
37536   #endif
37537 };
37538
37539 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumn = {
37540   0, /*sq_length*/
37541   0, /*sq_concat*/
37542   0, /*sq_repeat*/
37543   0, /*sq_item*/
37544   0, /*sq_slice*/
37545   0, /*sq_ass_item*/
37546   0, /*sq_ass_slice*/
37547   0, /*sq_contains*/
37548   0, /*sq_inplace_concat*/
37549   0, /*sq_inplace_repeat*/
37550 };
37551
37552 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumn = {
37553   0, /*mp_length*/
37554   0, /*mp_subscript*/
37555   0, /*mp_ass_subscript*/
37556 };
37557
37558 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumn = {
37559   #if PY_MAJOR_VERSION < 3
37560   0, /*bf_getreadbuffer*/
37561   #endif
37562   #if PY_MAJOR_VERSION < 3
37563   0, /*bf_getwritebuffer*/
37564   #endif
37565   #if PY_MAJOR_VERSION < 3
37566   0, /*bf_getsegcount*/
37567   #endif
37568   #if PY_MAJOR_VERSION < 3
37569   0, /*bf_getcharbuffer*/
37570   #endif
37571   #if PY_VERSION_HEX >= 0x02060000
37572   0, /*bf_getbuffer*/
37573   #endif
37574   #if PY_VERSION_HEX >= 0x02060000
37575   0, /*bf_releasebuffer*/
37576   #endif
37577 };
37578
37579 static PyTypeObject __pyx_type_9csamtools_IteratorColumn = {
37580   PyVarObject_HEAD_INIT(0, 0)
37581   __Pyx_NAMESTR("csamtools.IteratorColumn"), /*tp_name*/
37582   sizeof(struct __pyx_obj_9csamtools_IteratorColumn), /*tp_basicsize*/
37583   0, /*tp_itemsize*/
37584   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
37585   0, /*tp_print*/
37586   0, /*tp_getattr*/
37587   0, /*tp_setattr*/
37588   #if PY_MAJOR_VERSION < 3
37589   0, /*tp_compare*/
37590   #else
37591   0, /*reserved*/
37592   #endif
37593   0, /*tp_repr*/
37594   &__pyx_tp_as_number_IteratorColumn, /*tp_as_number*/
37595   &__pyx_tp_as_sequence_IteratorColumn, /*tp_as_sequence*/
37596   &__pyx_tp_as_mapping_IteratorColumn, /*tp_as_mapping*/
37597   0, /*tp_hash*/
37598   0, /*tp_call*/
37599   0, /*tp_str*/
37600   0, /*tp_getattro*/
37601   0, /*tp_setattro*/
37602   &__pyx_tp_as_buffer_IteratorColumn, /*tp_as_buffer*/
37603   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
37604   __Pyx_DOCSTR("abstract base class for iterators over columns.\n\n    IteratorColumn objects wrap the pileup functionality of samtools.\n\n    For reasons of efficiency, the iterator points to the current\n    pileup buffer. The pileup buffer is updated at every iteration.\n    This might cause some unexpected behavious. For example,\n    consider the conversion to a list::\n\n       f = Samfile(\"file.bam\", \"rb\")\n       result = list( f.pileup() )\n\n    Here, ``result`` will contain ``n`` objects of type :class:`PileupProxy` for ``n`` columns,\n    but each object in ``result`` will contain the same information.\n\n    The desired behaviour can be achieved by list comprehension::\n\n       result = [ x.pileups() for x in f.pileup() ]\n\n    ``result`` will be a list of ``n`` lists of objects of type :class:`PileupRead`.\n\n    If the iterator is associated with a :class:`Fastafile` using the :meth:`addReference`\n    method, then the iterator will export the current sequence via the methods :meth:`getSequence`\n    and :meth:`seq_len`.\n\n    Optional kwargs to the iterator\n\n    stepper\n       The stepper controls how the iterator advances.\n       Possible options for the stepper are\n\n       all\n           use all reads for pileup.\n       samtools\n           same filter and read processing as in :term:`csamtools` pileup\n\n       The default is to use \"all\" if no stepper is given.\n\n    fastafile\n       A :class:`FastaFile` object\n    mask\n       Skip all reads with bits set in mask.\n    max_depth\n       maximum read depth. The default is 8000.\n    "), /*tp_doc*/
37605   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
37606   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
37607   0, /*tp_richcompare*/
37608   0, /*tp_weaklistoffset*/
37609   __pyx_pw_9csamtools_14IteratorColumn_3__iter__, /*tp_iter*/
37610   0, /*tp_iternext*/
37611   __pyx_methods_9csamtools_IteratorColumn, /*tp_methods*/
37612   0, /*tp_members*/
37613   __pyx_getsets_9csamtools_IteratorColumn, /*tp_getset*/
37614   0, /*tp_base*/
37615   0, /*tp_dict*/
37616   0, /*tp_descr_get*/
37617   0, /*tp_descr_set*/
37618   0, /*tp_dictoffset*/
37619   0, /*tp_init*/
37620   0, /*tp_alloc*/
37621   __pyx_tp_new_9csamtools_IteratorColumn, /*tp_new*/
37622   0, /*tp_free*/
37623   0, /*tp_is_gc*/
37624   0, /*tp_bases*/
37625   0, /*tp_mro*/
37626   0, /*tp_cache*/
37627   0, /*tp_subclasses*/
37628   0, /*tp_weaklist*/
37629   0, /*tp_del*/
37630   #if PY_VERSION_HEX >= 0x02060000
37631   0, /*tp_version_tag*/
37632   #endif
37633 };
37634 static struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion __pyx_vtable_9csamtools_IteratorColumnRegion;
37635
37636 static PyObject *__pyx_tp_new_9csamtools_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
37637   struct __pyx_obj_9csamtools_IteratorColumnRegion *p;
37638   PyObject *o = __pyx_tp_new_9csamtools_IteratorColumn(t, a, k);
37639   if (!o) return 0;
37640   p = ((struct __pyx_obj_9csamtools_IteratorColumnRegion *)o);
37641   p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_9csamtools_IteratorColumn*)__pyx_vtabptr_9csamtools_IteratorColumnRegion;
37642   if (__pyx_pw_9csamtools_20IteratorColumnRegion_1__cinit__(o, a, k) < 0) {
37643     Py_DECREF(o); o = 0;
37644   }
37645   return o;
37646 }
37647
37648 static PyMethodDef __pyx_methods_9csamtools_IteratorColumnRegion[] = {
37649   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_20IteratorColumnRegion_3__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_20IteratorColumnRegion_2__next__)},
37650   {0, 0, 0, 0}
37651 };
37652
37653 static PyNumberMethods __pyx_tp_as_number_IteratorColumnRegion = {
37654   0, /*nb_add*/
37655   0, /*nb_subtract*/
37656   0, /*nb_multiply*/
37657   #if PY_MAJOR_VERSION < 3
37658   0, /*nb_divide*/
37659   #endif
37660   0, /*nb_remainder*/
37661   0, /*nb_divmod*/
37662   0, /*nb_power*/
37663   0, /*nb_negative*/
37664   0, /*nb_positive*/
37665   0, /*nb_absolute*/
37666   0, /*nb_nonzero*/
37667   0, /*nb_invert*/
37668   0, /*nb_lshift*/
37669   0, /*nb_rshift*/
37670   0, /*nb_and*/
37671   0, /*nb_xor*/
37672   0, /*nb_or*/
37673   #if PY_MAJOR_VERSION < 3
37674   0, /*nb_coerce*/
37675   #endif
37676   0, /*nb_int*/
37677   #if PY_MAJOR_VERSION < 3
37678   0, /*nb_long*/
37679   #else
37680   0, /*reserved*/
37681   #endif
37682   0, /*nb_float*/
37683   #if PY_MAJOR_VERSION < 3
37684   0, /*nb_oct*/
37685   #endif
37686   #if PY_MAJOR_VERSION < 3
37687   0, /*nb_hex*/
37688   #endif
37689   0, /*nb_inplace_add*/
37690   0, /*nb_inplace_subtract*/
37691   0, /*nb_inplace_multiply*/
37692   #if PY_MAJOR_VERSION < 3
37693   0, /*nb_inplace_divide*/
37694   #endif
37695   0, /*nb_inplace_remainder*/
37696   0, /*nb_inplace_power*/
37697   0, /*nb_inplace_lshift*/
37698   0, /*nb_inplace_rshift*/
37699   0, /*nb_inplace_and*/
37700   0, /*nb_inplace_xor*/
37701   0, /*nb_inplace_or*/
37702   0, /*nb_floor_divide*/
37703   0, /*nb_true_divide*/
37704   0, /*nb_inplace_floor_divide*/
37705   0, /*nb_inplace_true_divide*/
37706   #if PY_VERSION_HEX >= 0x02050000
37707   0, /*nb_index*/
37708   #endif
37709 };
37710
37711 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumnRegion = {
37712   0, /*sq_length*/
37713   0, /*sq_concat*/
37714   0, /*sq_repeat*/
37715   0, /*sq_item*/
37716   0, /*sq_slice*/
37717   0, /*sq_ass_item*/
37718   0, /*sq_ass_slice*/
37719   0, /*sq_contains*/
37720   0, /*sq_inplace_concat*/
37721   0, /*sq_inplace_repeat*/
37722 };
37723
37724 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumnRegion = {
37725   0, /*mp_length*/
37726   0, /*mp_subscript*/
37727   0, /*mp_ass_subscript*/
37728 };
37729
37730 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumnRegion = {
37731   #if PY_MAJOR_VERSION < 3
37732   0, /*bf_getreadbuffer*/
37733   #endif
37734   #if PY_MAJOR_VERSION < 3
37735   0, /*bf_getwritebuffer*/
37736   #endif
37737   #if PY_MAJOR_VERSION < 3
37738   0, /*bf_getsegcount*/
37739   #endif
37740   #if PY_MAJOR_VERSION < 3
37741   0, /*bf_getcharbuffer*/
37742   #endif
37743   #if PY_VERSION_HEX >= 0x02060000
37744   0, /*bf_getbuffer*/
37745   #endif
37746   #if PY_VERSION_HEX >= 0x02060000
37747   0, /*bf_releasebuffer*/
37748   #endif
37749 };
37750
37751 static PyTypeObject __pyx_type_9csamtools_IteratorColumnRegion = {
37752   PyVarObject_HEAD_INIT(0, 0)
37753   __Pyx_NAMESTR("csamtools.IteratorColumnRegion"), /*tp_name*/
37754   sizeof(struct __pyx_obj_9csamtools_IteratorColumnRegion), /*tp_basicsize*/
37755   0, /*tp_itemsize*/
37756   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
37757   0, /*tp_print*/
37758   0, /*tp_getattr*/
37759   0, /*tp_setattr*/
37760   #if PY_MAJOR_VERSION < 3
37761   0, /*tp_compare*/
37762   #else
37763   0, /*reserved*/
37764   #endif
37765   0, /*tp_repr*/
37766   &__pyx_tp_as_number_IteratorColumnRegion, /*tp_as_number*/
37767   &__pyx_tp_as_sequence_IteratorColumnRegion, /*tp_as_sequence*/
37768   &__pyx_tp_as_mapping_IteratorColumnRegion, /*tp_as_mapping*/
37769   0, /*tp_hash*/
37770   0, /*tp_call*/
37771   0, /*tp_str*/
37772   0, /*tp_getattro*/
37773   0, /*tp_setattro*/
37774   &__pyx_tp_as_buffer_IteratorColumnRegion, /*tp_as_buffer*/
37775   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
37776   __Pyx_DOCSTR("iterates over a region only.\n    "), /*tp_doc*/
37777   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
37778   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
37779   0, /*tp_richcompare*/
37780   0, /*tp_weaklistoffset*/
37781   0, /*tp_iter*/
37782   __pyx_pw_9csamtools_20IteratorColumnRegion_3__next__, /*tp_iternext*/
37783   __pyx_methods_9csamtools_IteratorColumnRegion, /*tp_methods*/
37784   0, /*tp_members*/
37785   0, /*tp_getset*/
37786   0, /*tp_base*/
37787   0, /*tp_dict*/
37788   0, /*tp_descr_get*/
37789   0, /*tp_descr_set*/
37790   0, /*tp_dictoffset*/
37791   0, /*tp_init*/
37792   0, /*tp_alloc*/
37793   __pyx_tp_new_9csamtools_IteratorColumnRegion, /*tp_new*/
37794   0, /*tp_free*/
37795   0, /*tp_is_gc*/
37796   0, /*tp_bases*/
37797   0, /*tp_mro*/
37798   0, /*tp_cache*/
37799   0, /*tp_subclasses*/
37800   0, /*tp_weaklist*/
37801   0, /*tp_del*/
37802   #if PY_VERSION_HEX >= 0x02060000
37803   0, /*tp_version_tag*/
37804   #endif
37805 };
37806 static struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs __pyx_vtable_9csamtools_IteratorColumnAllRefs;
37807
37808 static PyObject *__pyx_tp_new_9csamtools_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
37809   struct __pyx_obj_9csamtools_IteratorColumnAllRefs *p;
37810   PyObject *o = __pyx_tp_new_9csamtools_IteratorColumn(t, a, k);
37811   if (!o) return 0;
37812   p = ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)o);
37813   p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_9csamtools_IteratorColumn*)__pyx_vtabptr_9csamtools_IteratorColumnAllRefs;
37814   if (__pyx_pw_9csamtools_21IteratorColumnAllRefs_1__cinit__(o, a, k) < 0) {
37815     Py_DECREF(o); o = 0;
37816   }
37817   return o;
37818 }
37819
37820 static PyMethodDef __pyx_methods_9csamtools_IteratorColumnAllRefs[] = {
37821   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_9csamtools_21IteratorColumnAllRefs_3__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_21IteratorColumnAllRefs_2__next__)},
37822   {0, 0, 0, 0}
37823 };
37824
37825 static PyNumberMethods __pyx_tp_as_number_IteratorColumnAllRefs = {
37826   0, /*nb_add*/
37827   0, /*nb_subtract*/
37828   0, /*nb_multiply*/
37829   #if PY_MAJOR_VERSION < 3
37830   0, /*nb_divide*/
37831   #endif
37832   0, /*nb_remainder*/
37833   0, /*nb_divmod*/
37834   0, /*nb_power*/
37835   0, /*nb_negative*/
37836   0, /*nb_positive*/
37837   0, /*nb_absolute*/
37838   0, /*nb_nonzero*/
37839   0, /*nb_invert*/
37840   0, /*nb_lshift*/
37841   0, /*nb_rshift*/
37842   0, /*nb_and*/
37843   0, /*nb_xor*/
37844   0, /*nb_or*/
37845   #if PY_MAJOR_VERSION < 3
37846   0, /*nb_coerce*/
37847   #endif
37848   0, /*nb_int*/
37849   #if PY_MAJOR_VERSION < 3
37850   0, /*nb_long*/
37851   #else
37852   0, /*reserved*/
37853   #endif
37854   0, /*nb_float*/
37855   #if PY_MAJOR_VERSION < 3
37856   0, /*nb_oct*/
37857   #endif
37858   #if PY_MAJOR_VERSION < 3
37859   0, /*nb_hex*/
37860   #endif
37861   0, /*nb_inplace_add*/
37862   0, /*nb_inplace_subtract*/
37863   0, /*nb_inplace_multiply*/
37864   #if PY_MAJOR_VERSION < 3
37865   0, /*nb_inplace_divide*/
37866   #endif
37867   0, /*nb_inplace_remainder*/
37868   0, /*nb_inplace_power*/
37869   0, /*nb_inplace_lshift*/
37870   0, /*nb_inplace_rshift*/
37871   0, /*nb_inplace_and*/
37872   0, /*nb_inplace_xor*/
37873   0, /*nb_inplace_or*/
37874   0, /*nb_floor_divide*/
37875   0, /*nb_true_divide*/
37876   0, /*nb_inplace_floor_divide*/
37877   0, /*nb_inplace_true_divide*/
37878   #if PY_VERSION_HEX >= 0x02050000
37879   0, /*nb_index*/
37880   #endif
37881 };
37882
37883 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumnAllRefs = {
37884   0, /*sq_length*/
37885   0, /*sq_concat*/
37886   0, /*sq_repeat*/
37887   0, /*sq_item*/
37888   0, /*sq_slice*/
37889   0, /*sq_ass_item*/
37890   0, /*sq_ass_slice*/
37891   0, /*sq_contains*/
37892   0, /*sq_inplace_concat*/
37893   0, /*sq_inplace_repeat*/
37894 };
37895
37896 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumnAllRefs = {
37897   0, /*mp_length*/
37898   0, /*mp_subscript*/
37899   0, /*mp_ass_subscript*/
37900 };
37901
37902 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumnAllRefs = {
37903   #if PY_MAJOR_VERSION < 3
37904   0, /*bf_getreadbuffer*/
37905   #endif
37906   #if PY_MAJOR_VERSION < 3
37907   0, /*bf_getwritebuffer*/
37908   #endif
37909   #if PY_MAJOR_VERSION < 3
37910   0, /*bf_getsegcount*/
37911   #endif
37912   #if PY_MAJOR_VERSION < 3
37913   0, /*bf_getcharbuffer*/
37914   #endif
37915   #if PY_VERSION_HEX >= 0x02060000
37916   0, /*bf_getbuffer*/
37917   #endif
37918   #if PY_VERSION_HEX >= 0x02060000
37919   0, /*bf_releasebuffer*/
37920   #endif
37921 };
37922
37923 static PyTypeObject __pyx_type_9csamtools_IteratorColumnAllRefs = {
37924   PyVarObject_HEAD_INIT(0, 0)
37925   __Pyx_NAMESTR("csamtools.IteratorColumnAllRefs"), /*tp_name*/
37926   sizeof(struct __pyx_obj_9csamtools_IteratorColumnAllRefs), /*tp_basicsize*/
37927   0, /*tp_itemsize*/
37928   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
37929   0, /*tp_print*/
37930   0, /*tp_getattr*/
37931   0, /*tp_setattr*/
37932   #if PY_MAJOR_VERSION < 3
37933   0, /*tp_compare*/
37934   #else
37935   0, /*reserved*/
37936   #endif
37937   0, /*tp_repr*/
37938   &__pyx_tp_as_number_IteratorColumnAllRefs, /*tp_as_number*/
37939   &__pyx_tp_as_sequence_IteratorColumnAllRefs, /*tp_as_sequence*/
37940   &__pyx_tp_as_mapping_IteratorColumnAllRefs, /*tp_as_mapping*/
37941   0, /*tp_hash*/
37942   0, /*tp_call*/
37943   0, /*tp_str*/
37944   0, /*tp_getattro*/
37945   0, /*tp_setattro*/
37946   &__pyx_tp_as_buffer_IteratorColumnAllRefs, /*tp_as_buffer*/
37947   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
37948   __Pyx_DOCSTR("iterates over all columns by chaining iterators over each reference\n    "), /*tp_doc*/
37949   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
37950   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
37951   0, /*tp_richcompare*/
37952   0, /*tp_weaklistoffset*/
37953   0, /*tp_iter*/
37954   __pyx_pw_9csamtools_21IteratorColumnAllRefs_3__next__, /*tp_iternext*/
37955   __pyx_methods_9csamtools_IteratorColumnAllRefs, /*tp_methods*/
37956   0, /*tp_members*/
37957   0, /*tp_getset*/
37958   0, /*tp_base*/
37959   0, /*tp_dict*/
37960   0, /*tp_descr_get*/
37961   0, /*tp_descr_set*/
37962   0, /*tp_dictoffset*/
37963   0, /*tp_init*/
37964   0, /*tp_alloc*/
37965   __pyx_tp_new_9csamtools_IteratorColumnAllRefs, /*tp_new*/
37966   0, /*tp_free*/
37967   0, /*tp_is_gc*/
37968   0, /*tp_bases*/
37969   0, /*tp_mro*/
37970   0, /*tp_cache*/
37971   0, /*tp_subclasses*/
37972   0, /*tp_weaklist*/
37973   0, /*tp_del*/
37974   #if PY_VERSION_HEX >= 0x02060000
37975   0, /*tp_version_tag*/
37976   #endif
37977 };
37978
37979 static PyObject *__pyx_tp_new_9csamtools_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k) {
37980   struct __pyx_obj_9csamtools_IndexedReads *p;
37981   PyObject *o = (*t->tp_alloc)(t, 0);
37982   if (!o) return 0;
37983   p = ((struct __pyx_obj_9csamtools_IndexedReads *)o);
37984   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
37985   p->index = Py_None; Py_INCREF(Py_None);
37986   return o;
37987 }
37988
37989 static void __pyx_tp_dealloc_9csamtools_IndexedReads(PyObject *o) {
37990   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
37991   {
37992     PyObject *etype, *eval, *etb;
37993     PyErr_Fetch(&etype, &eval, &etb);
37994     ++Py_REFCNT(o);
37995     __pyx_pw_9csamtools_12IndexedReads_7__dealloc__(o);
37996     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
37997     --Py_REFCNT(o);
37998     PyErr_Restore(etype, eval, etb);
37999   }
38000   Py_XDECREF(((PyObject *)p->samfile));
38001   Py_XDECREF(p->index);
38002   (*Py_TYPE(o)->tp_free)(o);
38003 }
38004
38005 static int __pyx_tp_traverse_9csamtools_IndexedReads(PyObject *o, visitproc v, void *a) {
38006   int e;
38007   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
38008   if (p->samfile) {
38009     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
38010   }
38011   if (p->index) {
38012     e = (*v)(p->index, a); if (e) return e;
38013   }
38014   return 0;
38015 }
38016
38017 static int __pyx_tp_clear_9csamtools_IndexedReads(PyObject *o) {
38018   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
38019   PyObject* tmp;
38020   tmp = ((PyObject*)p->samfile);
38021   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
38022   Py_XDECREF(tmp);
38023   tmp = ((PyObject*)p->index);
38024   p->index = Py_None; Py_INCREF(Py_None);
38025   Py_XDECREF(tmp);
38026   return 0;
38027 }
38028
38029 static PyMethodDef __pyx_methods_9csamtools_IndexedReads[] = {
38030   {__Pyx_NAMESTR("build"), (PyCFunction)__pyx_pw_9csamtools_12IndexedReads_3build, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_12IndexedReads_2build)},
38031   {__Pyx_NAMESTR("find"), (PyCFunction)__pyx_pw_9csamtools_12IndexedReads_5find, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_12IndexedReads_4find)},
38032   {0, 0, 0, 0}
38033 };
38034
38035 static PyNumberMethods __pyx_tp_as_number_IndexedReads = {
38036   0, /*nb_add*/
38037   0, /*nb_subtract*/
38038   0, /*nb_multiply*/
38039   #if PY_MAJOR_VERSION < 3
38040   0, /*nb_divide*/
38041   #endif
38042   0, /*nb_remainder*/
38043   0, /*nb_divmod*/
38044   0, /*nb_power*/
38045   0, /*nb_negative*/
38046   0, /*nb_positive*/
38047   0, /*nb_absolute*/
38048   0, /*nb_nonzero*/
38049   0, /*nb_invert*/
38050   0, /*nb_lshift*/
38051   0, /*nb_rshift*/
38052   0, /*nb_and*/
38053   0, /*nb_xor*/
38054   0, /*nb_or*/
38055   #if PY_MAJOR_VERSION < 3
38056   0, /*nb_coerce*/
38057   #endif
38058   0, /*nb_int*/
38059   #if PY_MAJOR_VERSION < 3
38060   0, /*nb_long*/
38061   #else
38062   0, /*reserved*/
38063   #endif
38064   0, /*nb_float*/
38065   #if PY_MAJOR_VERSION < 3
38066   0, /*nb_oct*/
38067   #endif
38068   #if PY_MAJOR_VERSION < 3
38069   0, /*nb_hex*/
38070   #endif
38071   0, /*nb_inplace_add*/
38072   0, /*nb_inplace_subtract*/
38073   0, /*nb_inplace_multiply*/
38074   #if PY_MAJOR_VERSION < 3
38075   0, /*nb_inplace_divide*/
38076   #endif
38077   0, /*nb_inplace_remainder*/
38078   0, /*nb_inplace_power*/
38079   0, /*nb_inplace_lshift*/
38080   0, /*nb_inplace_rshift*/
38081   0, /*nb_inplace_and*/
38082   0, /*nb_inplace_xor*/
38083   0, /*nb_inplace_or*/
38084   0, /*nb_floor_divide*/
38085   0, /*nb_true_divide*/
38086   0, /*nb_inplace_floor_divide*/
38087   0, /*nb_inplace_true_divide*/
38088   #if PY_VERSION_HEX >= 0x02050000
38089   0, /*nb_index*/
38090   #endif
38091 };
38092
38093 static PySequenceMethods __pyx_tp_as_sequence_IndexedReads = {
38094   0, /*sq_length*/
38095   0, /*sq_concat*/
38096   0, /*sq_repeat*/
38097   0, /*sq_item*/
38098   0, /*sq_slice*/
38099   0, /*sq_ass_item*/
38100   0, /*sq_ass_slice*/
38101   0, /*sq_contains*/
38102   0, /*sq_inplace_concat*/
38103   0, /*sq_inplace_repeat*/
38104 };
38105
38106 static PyMappingMethods __pyx_tp_as_mapping_IndexedReads = {
38107   0, /*mp_length*/
38108   0, /*mp_subscript*/
38109   0, /*mp_ass_subscript*/
38110 };
38111
38112 static PyBufferProcs __pyx_tp_as_buffer_IndexedReads = {
38113   #if PY_MAJOR_VERSION < 3
38114   0, /*bf_getreadbuffer*/
38115   #endif
38116   #if PY_MAJOR_VERSION < 3
38117   0, /*bf_getwritebuffer*/
38118   #endif
38119   #if PY_MAJOR_VERSION < 3
38120   0, /*bf_getsegcount*/
38121   #endif
38122   #if PY_MAJOR_VERSION < 3
38123   0, /*bf_getcharbuffer*/
38124   #endif
38125   #if PY_VERSION_HEX >= 0x02060000
38126   0, /*bf_getbuffer*/
38127   #endif
38128   #if PY_VERSION_HEX >= 0x02060000
38129   0, /*bf_releasebuffer*/
38130   #endif
38131 };
38132
38133 static PyTypeObject __pyx_type_9csamtools_IndexedReads = {
38134   PyVarObject_HEAD_INIT(0, 0)
38135   __Pyx_NAMESTR("csamtools.IndexedReads"), /*tp_name*/
38136   sizeof(struct __pyx_obj_9csamtools_IndexedReads), /*tp_basicsize*/
38137   0, /*tp_itemsize*/
38138   __pyx_tp_dealloc_9csamtools_IndexedReads, /*tp_dealloc*/
38139   0, /*tp_print*/
38140   0, /*tp_getattr*/
38141   0, /*tp_setattr*/
38142   #if PY_MAJOR_VERSION < 3
38143   0, /*tp_compare*/
38144   #else
38145   0, /*reserved*/
38146   #endif
38147   0, /*tp_repr*/
38148   &__pyx_tp_as_number_IndexedReads, /*tp_as_number*/
38149   &__pyx_tp_as_sequence_IndexedReads, /*tp_as_sequence*/
38150   &__pyx_tp_as_mapping_IndexedReads, /*tp_as_mapping*/
38151   0, /*tp_hash*/
38152   0, /*tp_call*/
38153   0, /*tp_str*/
38154   0, /*tp_getattro*/
38155   0, /*tp_setattro*/
38156   &__pyx_tp_as_buffer_IndexedReads, /*tp_as_buffer*/
38157   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
38158   __Pyx_DOCSTR("IndexedReads(Samfile samfile, int reopen=True)\nindex a bamfile by read.\n\n    The index is kept in memory.\n\n    By default, the file is re-openend to avoid conflicts if\n    multiple operators work on the same file. Set *reopen* = False\n    to not re-open *samfile*.\n    "), /*tp_doc*/
38159   __pyx_tp_traverse_9csamtools_IndexedReads, /*tp_traverse*/
38160   __pyx_tp_clear_9csamtools_IndexedReads, /*tp_clear*/
38161   0, /*tp_richcompare*/
38162   0, /*tp_weaklistoffset*/
38163   0, /*tp_iter*/
38164   0, /*tp_iternext*/
38165   __pyx_methods_9csamtools_IndexedReads, /*tp_methods*/
38166   0, /*tp_members*/
38167   0, /*tp_getset*/
38168   0, /*tp_base*/
38169   0, /*tp_dict*/
38170   0, /*tp_descr_get*/
38171   0, /*tp_descr_set*/
38172   0, /*tp_dictoffset*/
38173   __pyx_pw_9csamtools_12IndexedReads_1__init__, /*tp_init*/
38174   0, /*tp_alloc*/
38175   __pyx_tp_new_9csamtools_IndexedReads, /*tp_new*/
38176   0, /*tp_free*/
38177   0, /*tp_is_gc*/
38178   0, /*tp_bases*/
38179   0, /*tp_mro*/
38180   0, /*tp_cache*/
38181   0, /*tp_subclasses*/
38182   0, /*tp_weaklist*/
38183   0, /*tp_del*/
38184   #if PY_VERSION_HEX >= 0x02060000
38185   0, /*tp_version_tag*/
38186   #endif
38187 };
38188
38189 static PyObject *__pyx_tp_new_9csamtools_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k) {
38190   PyObject *o = (*t->tp_alloc)(t, 0);
38191   if (!o) return 0;
38192   return o;
38193 }
38194
38195 static void __pyx_tp_dealloc_9csamtools_SNPCall(PyObject *o) {
38196   (*Py_TYPE(o)->tp_free)(o);
38197 }
38198
38199 static PyObject *__pyx_getprop_9csamtools_7SNPCall_tid(PyObject *o, void *x) {
38200   return __pyx_pw_9csamtools_7SNPCall_3tid_1__get__(o);
38201 }
38202
38203 static PyObject *__pyx_getprop_9csamtools_7SNPCall_pos(PyObject *o, void *x) {
38204   return __pyx_pw_9csamtools_7SNPCall_3pos_1__get__(o);
38205 }
38206
38207 static PyObject *__pyx_getprop_9csamtools_7SNPCall_reference_base(PyObject *o, void *x) {
38208   return __pyx_pw_9csamtools_7SNPCall_14reference_base_1__get__(o);
38209 }
38210
38211 static PyObject *__pyx_getprop_9csamtools_7SNPCall_genotype(PyObject *o, void *x) {
38212   return __pyx_pw_9csamtools_7SNPCall_8genotype_1__get__(o);
38213 }
38214
38215 static PyObject *__pyx_getprop_9csamtools_7SNPCall_consensus_quality(PyObject *o, void *x) {
38216   return __pyx_pw_9csamtools_7SNPCall_17consensus_quality_1__get__(o);
38217 }
38218
38219 static PyObject *__pyx_getprop_9csamtools_7SNPCall_snp_quality(PyObject *o, void *x) {
38220   return __pyx_pw_9csamtools_7SNPCall_11snp_quality_1__get__(o);
38221 }
38222
38223 static PyObject *__pyx_getprop_9csamtools_7SNPCall_mapping_quality(PyObject *o, void *x) {
38224   return __pyx_pw_9csamtools_7SNPCall_15mapping_quality_1__get__(o);
38225 }
38226
38227 static PyObject *__pyx_getprop_9csamtools_7SNPCall_coverage(PyObject *o, void *x) {
38228   return __pyx_pw_9csamtools_7SNPCall_8coverage_1__get__(o);
38229 }
38230
38231 static PyMethodDef __pyx_methods_9csamtools_SNPCall[] = {
38232   {0, 0, 0, 0}
38233 };
38234
38235 static struct PyGetSetDef __pyx_getsets_9csamtools_SNPCall[] = {
38236   {(char *)"tid", __pyx_getprop_9csamtools_7SNPCall_tid, 0, __Pyx_DOCSTR(__pyx_k_234), 0},
38237   {(char *)"pos", __pyx_getprop_9csamtools_7SNPCall_pos, 0, __Pyx_DOCSTR(__pyx_k_242), 0},
38238   {(char *)"reference_base", __pyx_getprop_9csamtools_7SNPCall_reference_base, 0, __Pyx_DOCSTR(__pyx_k_243), 0},
38239   {(char *)"genotype", __pyx_getprop_9csamtools_7SNPCall_genotype, 0, __Pyx_DOCSTR(__pyx_k_244), 0},
38240   {(char *)"consensus_quality", __pyx_getprop_9csamtools_7SNPCall_consensus_quality, 0, __Pyx_DOCSTR(__pyx_k_245), 0},
38241   {(char *)"snp_quality", __pyx_getprop_9csamtools_7SNPCall_snp_quality, 0, __Pyx_DOCSTR(__pyx_k_246), 0},
38242   {(char *)"mapping_quality", __pyx_getprop_9csamtools_7SNPCall_mapping_quality, 0, __Pyx_DOCSTR(__pyx_k_247), 0},
38243   {(char *)"coverage", __pyx_getprop_9csamtools_7SNPCall_coverage, 0, __Pyx_DOCSTR(__pyx_k_248), 0},
38244   {0, 0, 0, 0, 0}
38245 };
38246
38247 static PyNumberMethods __pyx_tp_as_number_SNPCall = {
38248   0, /*nb_add*/
38249   0, /*nb_subtract*/
38250   0, /*nb_multiply*/
38251   #if PY_MAJOR_VERSION < 3
38252   0, /*nb_divide*/
38253   #endif
38254   0, /*nb_remainder*/
38255   0, /*nb_divmod*/
38256   0, /*nb_power*/
38257   0, /*nb_negative*/
38258   0, /*nb_positive*/
38259   0, /*nb_absolute*/
38260   0, /*nb_nonzero*/
38261   0, /*nb_invert*/
38262   0, /*nb_lshift*/
38263   0, /*nb_rshift*/
38264   0, /*nb_and*/
38265   0, /*nb_xor*/
38266   0, /*nb_or*/
38267   #if PY_MAJOR_VERSION < 3
38268   0, /*nb_coerce*/
38269   #endif
38270   0, /*nb_int*/
38271   #if PY_MAJOR_VERSION < 3
38272   0, /*nb_long*/
38273   #else
38274   0, /*reserved*/
38275   #endif
38276   0, /*nb_float*/
38277   #if PY_MAJOR_VERSION < 3
38278   0, /*nb_oct*/
38279   #endif
38280   #if PY_MAJOR_VERSION < 3
38281   0, /*nb_hex*/
38282   #endif
38283   0, /*nb_inplace_add*/
38284   0, /*nb_inplace_subtract*/
38285   0, /*nb_inplace_multiply*/
38286   #if PY_MAJOR_VERSION < 3
38287   0, /*nb_inplace_divide*/
38288   #endif
38289   0, /*nb_inplace_remainder*/
38290   0, /*nb_inplace_power*/
38291   0, /*nb_inplace_lshift*/
38292   0, /*nb_inplace_rshift*/
38293   0, /*nb_inplace_and*/
38294   0, /*nb_inplace_xor*/
38295   0, /*nb_inplace_or*/
38296   0, /*nb_floor_divide*/
38297   0, /*nb_true_divide*/
38298   0, /*nb_inplace_floor_divide*/
38299   0, /*nb_inplace_true_divide*/
38300   #if PY_VERSION_HEX >= 0x02050000
38301   0, /*nb_index*/
38302   #endif
38303 };
38304
38305 static PySequenceMethods __pyx_tp_as_sequence_SNPCall = {
38306   0, /*sq_length*/
38307   0, /*sq_concat*/
38308   0, /*sq_repeat*/
38309   0, /*sq_item*/
38310   0, /*sq_slice*/
38311   0, /*sq_ass_item*/
38312   0, /*sq_ass_slice*/
38313   0, /*sq_contains*/
38314   0, /*sq_inplace_concat*/
38315   0, /*sq_inplace_repeat*/
38316 };
38317
38318 static PyMappingMethods __pyx_tp_as_mapping_SNPCall = {
38319   0, /*mp_length*/
38320   0, /*mp_subscript*/
38321   0, /*mp_ass_subscript*/
38322 };
38323
38324 static PyBufferProcs __pyx_tp_as_buffer_SNPCall = {
38325   #if PY_MAJOR_VERSION < 3
38326   0, /*bf_getreadbuffer*/
38327   #endif
38328   #if PY_MAJOR_VERSION < 3
38329   0, /*bf_getwritebuffer*/
38330   #endif
38331   #if PY_MAJOR_VERSION < 3
38332   0, /*bf_getsegcount*/
38333   #endif
38334   #if PY_MAJOR_VERSION < 3
38335   0, /*bf_getcharbuffer*/
38336   #endif
38337   #if PY_VERSION_HEX >= 0x02060000
38338   0, /*bf_getbuffer*/
38339   #endif
38340   #if PY_VERSION_HEX >= 0x02060000
38341   0, /*bf_releasebuffer*/
38342   #endif
38343 };
38344
38345 static PyTypeObject __pyx_type_9csamtools_SNPCall = {
38346   PyVarObject_HEAD_INIT(0, 0)
38347   __Pyx_NAMESTR("csamtools.SNPCall"), /*tp_name*/
38348   sizeof(struct __pyx_obj_9csamtools_SNPCall), /*tp_basicsize*/
38349   0, /*tp_itemsize*/
38350   __pyx_tp_dealloc_9csamtools_SNPCall, /*tp_dealloc*/
38351   0, /*tp_print*/
38352   0, /*tp_getattr*/
38353   0, /*tp_setattr*/
38354   #if PY_MAJOR_VERSION < 3
38355   0, /*tp_compare*/
38356   #else
38357   0, /*reserved*/
38358   #endif
38359   0, /*tp_repr*/
38360   &__pyx_tp_as_number_SNPCall, /*tp_as_number*/
38361   &__pyx_tp_as_sequence_SNPCall, /*tp_as_sequence*/
38362   &__pyx_tp_as_mapping_SNPCall, /*tp_as_mapping*/
38363   0, /*tp_hash*/
38364   0, /*tp_call*/
38365   __pyx_pw_9csamtools_7SNPCall_1__str__, /*tp_str*/
38366   0, /*tp_getattro*/
38367   0, /*tp_setattro*/
38368   &__pyx_tp_as_buffer_SNPCall, /*tp_as_buffer*/
38369   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
38370   __Pyx_DOCSTR("the results of a SNP call."), /*tp_doc*/
38371   0, /*tp_traverse*/
38372   0, /*tp_clear*/
38373   0, /*tp_richcompare*/
38374   0, /*tp_weaklistoffset*/
38375   0, /*tp_iter*/
38376   0, /*tp_iternext*/
38377   __pyx_methods_9csamtools_SNPCall, /*tp_methods*/
38378   0, /*tp_members*/
38379   __pyx_getsets_9csamtools_SNPCall, /*tp_getset*/
38380   0, /*tp_base*/
38381   0, /*tp_dict*/
38382   0, /*tp_descr_get*/
38383   0, /*tp_descr_set*/
38384   0, /*tp_dictoffset*/
38385   0, /*tp_init*/
38386   0, /*tp_alloc*/
38387   __pyx_tp_new_9csamtools_SNPCall, /*tp_new*/
38388   0, /*tp_free*/
38389   0, /*tp_is_gc*/
38390   0, /*tp_bases*/
38391   0, /*tp_mro*/
38392   0, /*tp_cache*/
38393   0, /*tp_subclasses*/
38394   0, /*tp_weaklist*/
38395   0, /*tp_del*/
38396   #if PY_VERSION_HEX >= 0x02060000
38397   0, /*tp_version_tag*/
38398   #endif
38399 };
38400
38401 static PyObject *__pyx_tp_new_9csamtools___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k) {
38402   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *p;
38403   PyObject *o = (*t->tp_alloc)(t, 0);
38404   if (!o) return 0;
38405   p = ((struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)o);
38406   p->__pyx_v_x = 0;
38407   p->__pyx_v_y = 0;
38408   p->__pyx_t_0 = 0;
38409   p->__pyx_t_1 = 0;
38410   return o;
38411 }
38412
38413 static void __pyx_tp_dealloc_9csamtools___pyx_scope_struct__genexpr(PyObject *o) {
38414   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)o;
38415   Py_XDECREF(p->__pyx_v_x);
38416   Py_XDECREF(p->__pyx_v_y);
38417   Py_XDECREF(p->__pyx_t_0);
38418   Py_XDECREF(p->__pyx_t_1);
38419   (*Py_TYPE(o)->tp_free)(o);
38420 }
38421
38422 static int __pyx_tp_traverse_9csamtools___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) {
38423   int e;
38424   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)o;
38425   if (p->__pyx_v_x) {
38426     e = (*v)(p->__pyx_v_x, a); if (e) return e;
38427   }
38428   if (p->__pyx_v_y) {
38429     e = (*v)(p->__pyx_v_y, a); if (e) return e;
38430   }
38431   if (p->__pyx_t_0) {
38432     e = (*v)(p->__pyx_t_0, a); if (e) return e;
38433   }
38434   if (p->__pyx_t_1) {
38435     e = (*v)(p->__pyx_t_1, a); if (e) return e;
38436   }
38437   return 0;
38438 }
38439
38440 static int __pyx_tp_clear_9csamtools___pyx_scope_struct__genexpr(PyObject *o) {
38441   struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr *)o;
38442   PyObject* tmp;
38443   tmp = ((PyObject*)p->__pyx_v_x);
38444   p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
38445   Py_XDECREF(tmp);
38446   tmp = ((PyObject*)p->__pyx_v_y);
38447   p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
38448   Py_XDECREF(tmp);
38449   tmp = ((PyObject*)p->__pyx_t_0);
38450   p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
38451   Py_XDECREF(tmp);
38452   tmp = ((PyObject*)p->__pyx_t_1);
38453   p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
38454   Py_XDECREF(tmp);
38455   return 0;
38456 }
38457
38458 static PyMethodDef __pyx_methods_9csamtools___pyx_scope_struct__genexpr[] = {
38459   {0, 0, 0, 0}
38460 };
38461
38462 static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__genexpr = {
38463   0, /*nb_add*/
38464   0, /*nb_subtract*/
38465   0, /*nb_multiply*/
38466   #if PY_MAJOR_VERSION < 3
38467   0, /*nb_divide*/
38468   #endif
38469   0, /*nb_remainder*/
38470   0, /*nb_divmod*/
38471   0, /*nb_power*/
38472   0, /*nb_negative*/
38473   0, /*nb_positive*/
38474   0, /*nb_absolute*/
38475   0, /*nb_nonzero*/
38476   0, /*nb_invert*/
38477   0, /*nb_lshift*/
38478   0, /*nb_rshift*/
38479   0, /*nb_and*/
38480   0, /*nb_xor*/
38481   0, /*nb_or*/
38482   #if PY_MAJOR_VERSION < 3
38483   0, /*nb_coerce*/
38484   #endif
38485   0, /*nb_int*/
38486   #if PY_MAJOR_VERSION < 3
38487   0, /*nb_long*/
38488   #else
38489   0, /*reserved*/
38490   #endif
38491   0, /*nb_float*/
38492   #if PY_MAJOR_VERSION < 3
38493   0, /*nb_oct*/
38494   #endif
38495   #if PY_MAJOR_VERSION < 3
38496   0, /*nb_hex*/
38497   #endif
38498   0, /*nb_inplace_add*/
38499   0, /*nb_inplace_subtract*/
38500   0, /*nb_inplace_multiply*/
38501   #if PY_MAJOR_VERSION < 3
38502   0, /*nb_inplace_divide*/
38503   #endif
38504   0, /*nb_inplace_remainder*/
38505   0, /*nb_inplace_power*/
38506   0, /*nb_inplace_lshift*/
38507   0, /*nb_inplace_rshift*/
38508   0, /*nb_inplace_and*/
38509   0, /*nb_inplace_xor*/
38510   0, /*nb_inplace_or*/
38511   0, /*nb_floor_divide*/
38512   0, /*nb_true_divide*/
38513   0, /*nb_inplace_floor_divide*/
38514   0, /*nb_inplace_true_divide*/
38515   #if PY_VERSION_HEX >= 0x02050000
38516   0, /*nb_index*/
38517   #endif
38518 };
38519
38520 static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__genexpr = {
38521   0, /*sq_length*/
38522   0, /*sq_concat*/
38523   0, /*sq_repeat*/
38524   0, /*sq_item*/
38525   0, /*sq_slice*/
38526   0, /*sq_ass_item*/
38527   0, /*sq_ass_slice*/
38528   0, /*sq_contains*/
38529   0, /*sq_inplace_concat*/
38530   0, /*sq_inplace_repeat*/
38531 };
38532
38533 static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__genexpr = {
38534   0, /*mp_length*/
38535   0, /*mp_subscript*/
38536   0, /*mp_ass_subscript*/
38537 };
38538
38539 static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__genexpr = {
38540   #if PY_MAJOR_VERSION < 3
38541   0, /*bf_getreadbuffer*/
38542   #endif
38543   #if PY_MAJOR_VERSION < 3
38544   0, /*bf_getwritebuffer*/
38545   #endif
38546   #if PY_MAJOR_VERSION < 3
38547   0, /*bf_getsegcount*/
38548   #endif
38549   #if PY_MAJOR_VERSION < 3
38550   0, /*bf_getcharbuffer*/
38551   #endif
38552   #if PY_VERSION_HEX >= 0x02060000
38553   0, /*bf_getbuffer*/
38554   #endif
38555   #if PY_VERSION_HEX >= 0x02060000
38556   0, /*bf_releasebuffer*/
38557   #endif
38558 };
38559
38560 static PyTypeObject __pyx_type_9csamtools___pyx_scope_struct__genexpr = {
38561   PyVarObject_HEAD_INIT(0, 0)
38562   __Pyx_NAMESTR("csamtools.__pyx_scope_struct__genexpr"), /*tp_name*/
38563   sizeof(struct __pyx_obj_9csamtools___pyx_scope_struct__genexpr), /*tp_basicsize*/
38564   0, /*tp_itemsize*/
38565   __pyx_tp_dealloc_9csamtools___pyx_scope_struct__genexpr, /*tp_dealloc*/
38566   0, /*tp_print*/
38567   0, /*tp_getattr*/
38568   0, /*tp_setattr*/
38569   #if PY_MAJOR_VERSION < 3
38570   0, /*tp_compare*/
38571   #else
38572   0, /*reserved*/
38573   #endif
38574   0, /*tp_repr*/
38575   &__pyx_tp_as_number___pyx_scope_struct__genexpr, /*tp_as_number*/
38576   &__pyx_tp_as_sequence___pyx_scope_struct__genexpr, /*tp_as_sequence*/
38577   &__pyx_tp_as_mapping___pyx_scope_struct__genexpr, /*tp_as_mapping*/
38578   0, /*tp_hash*/
38579   0, /*tp_call*/
38580   0, /*tp_str*/
38581   0, /*tp_getattro*/
38582   0, /*tp_setattro*/
38583   &__pyx_tp_as_buffer___pyx_scope_struct__genexpr, /*tp_as_buffer*/
38584   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
38585   0, /*tp_doc*/
38586   __pyx_tp_traverse_9csamtools___pyx_scope_struct__genexpr, /*tp_traverse*/
38587   __pyx_tp_clear_9csamtools___pyx_scope_struct__genexpr, /*tp_clear*/
38588   0, /*tp_richcompare*/
38589   0, /*tp_weaklistoffset*/
38590   0, /*tp_iter*/
38591   0, /*tp_iternext*/
38592   __pyx_methods_9csamtools___pyx_scope_struct__genexpr, /*tp_methods*/
38593   0, /*tp_members*/
38594   0, /*tp_getset*/
38595   0, /*tp_base*/
38596   0, /*tp_dict*/
38597   0, /*tp_descr_get*/
38598   0, /*tp_descr_set*/
38599   0, /*tp_dictoffset*/
38600   0, /*tp_init*/
38601   0, /*tp_alloc*/
38602   __pyx_tp_new_9csamtools___pyx_scope_struct__genexpr, /*tp_new*/
38603   0, /*tp_free*/
38604   0, /*tp_is_gc*/
38605   0, /*tp_bases*/
38606   0, /*tp_mro*/
38607   0, /*tp_cache*/
38608   0, /*tp_subclasses*/
38609   0, /*tp_weaklist*/
38610   0, /*tp_del*/
38611   #if PY_VERSION_HEX >= 0x02060000
38612   0, /*tp_version_tag*/
38613   #endif
38614 };
38615
38616 static PyObject *__pyx_tp_new_9csamtools___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) {
38617   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *p;
38618   PyObject *o = (*t->tp_alloc)(t, 0);
38619   if (!o) return 0;
38620   p = ((struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)o);
38621   p->__pyx_v_x = 0;
38622   p->__pyx_v_y = 0;
38623   p->__pyx_t_0 = 0;
38624   p->__pyx_t_1 = 0;
38625   return o;
38626 }
38627
38628 static void __pyx_tp_dealloc_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
38629   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)o;
38630   Py_XDECREF(p->__pyx_v_x);
38631   Py_XDECREF(p->__pyx_v_y);
38632   Py_XDECREF(p->__pyx_t_0);
38633   Py_XDECREF(p->__pyx_t_1);
38634   (*Py_TYPE(o)->tp_free)(o);
38635 }
38636
38637 static int __pyx_tp_traverse_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
38638   int e;
38639   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)o;
38640   if (p->__pyx_v_x) {
38641     e = (*v)(p->__pyx_v_x, a); if (e) return e;
38642   }
38643   if (p->__pyx_v_y) {
38644     e = (*v)(p->__pyx_v_y, a); if (e) return e;
38645   }
38646   if (p->__pyx_t_0) {
38647     e = (*v)(p->__pyx_t_0, a); if (e) return e;
38648   }
38649   if (p->__pyx_t_1) {
38650     e = (*v)(p->__pyx_t_1, a); if (e) return e;
38651   }
38652   return 0;
38653 }
38654
38655 static int __pyx_tp_clear_9csamtools___pyx_scope_struct_1_genexpr(PyObject *o) {
38656   struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr *)o;
38657   PyObject* tmp;
38658   tmp = ((PyObject*)p->__pyx_v_x);
38659   p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
38660   Py_XDECREF(tmp);
38661   tmp = ((PyObject*)p->__pyx_v_y);
38662   p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
38663   Py_XDECREF(tmp);
38664   tmp = ((PyObject*)p->__pyx_t_0);
38665   p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
38666   Py_XDECREF(tmp);
38667   tmp = ((PyObject*)p->__pyx_t_1);
38668   p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
38669   Py_XDECREF(tmp);
38670   return 0;
38671 }
38672
38673 static PyMethodDef __pyx_methods_9csamtools___pyx_scope_struct_1_genexpr[] = {
38674   {0, 0, 0, 0}
38675 };
38676
38677 static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_genexpr = {
38678   0, /*nb_add*/
38679   0, /*nb_subtract*/
38680   0, /*nb_multiply*/
38681   #if PY_MAJOR_VERSION < 3
38682   0, /*nb_divide*/
38683   #endif
38684   0, /*nb_remainder*/
38685   0, /*nb_divmod*/
38686   0, /*nb_power*/
38687   0, /*nb_negative*/
38688   0, /*nb_positive*/
38689   0, /*nb_absolute*/
38690   0, /*nb_nonzero*/
38691   0, /*nb_invert*/
38692   0, /*nb_lshift*/
38693   0, /*nb_rshift*/
38694   0, /*nb_and*/
38695   0, /*nb_xor*/
38696   0, /*nb_or*/
38697   #if PY_MAJOR_VERSION < 3
38698   0, /*nb_coerce*/
38699   #endif
38700   0, /*nb_int*/
38701   #if PY_MAJOR_VERSION < 3
38702   0, /*nb_long*/
38703   #else
38704   0, /*reserved*/
38705   #endif
38706   0, /*nb_float*/
38707   #if PY_MAJOR_VERSION < 3
38708   0, /*nb_oct*/
38709   #endif
38710   #if PY_MAJOR_VERSION < 3
38711   0, /*nb_hex*/
38712   #endif
38713   0, /*nb_inplace_add*/
38714   0, /*nb_inplace_subtract*/
38715   0, /*nb_inplace_multiply*/
38716   #if PY_MAJOR_VERSION < 3
38717   0, /*nb_inplace_divide*/
38718   #endif
38719   0, /*nb_inplace_remainder*/
38720   0, /*nb_inplace_power*/
38721   0, /*nb_inplace_lshift*/
38722   0, /*nb_inplace_rshift*/
38723   0, /*nb_inplace_and*/
38724   0, /*nb_inplace_xor*/
38725   0, /*nb_inplace_or*/
38726   0, /*nb_floor_divide*/
38727   0, /*nb_true_divide*/
38728   0, /*nb_inplace_floor_divide*/
38729   0, /*nb_inplace_true_divide*/
38730   #if PY_VERSION_HEX >= 0x02050000
38731   0, /*nb_index*/
38732   #endif
38733 };
38734
38735 static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_genexpr = {
38736   0, /*sq_length*/
38737   0, /*sq_concat*/
38738   0, /*sq_repeat*/
38739   0, /*sq_item*/
38740   0, /*sq_slice*/
38741   0, /*sq_ass_item*/
38742   0, /*sq_ass_slice*/
38743   0, /*sq_contains*/
38744   0, /*sq_inplace_concat*/
38745   0, /*sq_inplace_repeat*/
38746 };
38747
38748 static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_genexpr = {
38749   0, /*mp_length*/
38750   0, /*mp_subscript*/
38751   0, /*mp_ass_subscript*/
38752 };
38753
38754 static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_genexpr = {
38755   #if PY_MAJOR_VERSION < 3
38756   0, /*bf_getreadbuffer*/
38757   #endif
38758   #if PY_MAJOR_VERSION < 3
38759   0, /*bf_getwritebuffer*/
38760   #endif
38761   #if PY_MAJOR_VERSION < 3
38762   0, /*bf_getsegcount*/
38763   #endif
38764   #if PY_MAJOR_VERSION < 3
38765   0, /*bf_getcharbuffer*/
38766   #endif
38767   #if PY_VERSION_HEX >= 0x02060000
38768   0, /*bf_getbuffer*/
38769   #endif
38770   #if PY_VERSION_HEX >= 0x02060000
38771   0, /*bf_releasebuffer*/
38772   #endif
38773 };
38774
38775 static PyTypeObject __pyx_type_9csamtools___pyx_scope_struct_1_genexpr = {
38776   PyVarObject_HEAD_INIT(0, 0)
38777   __Pyx_NAMESTR("csamtools.__pyx_scope_struct_1_genexpr"), /*tp_name*/
38778   sizeof(struct __pyx_obj_9csamtools___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
38779   0, /*tp_itemsize*/
38780   __pyx_tp_dealloc_9csamtools___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
38781   0, /*tp_print*/
38782   0, /*tp_getattr*/
38783   0, /*tp_setattr*/
38784   #if PY_MAJOR_VERSION < 3
38785   0, /*tp_compare*/
38786   #else
38787   0, /*reserved*/
38788   #endif
38789   0, /*tp_repr*/
38790   &__pyx_tp_as_number___pyx_scope_struct_1_genexpr, /*tp_as_number*/
38791   &__pyx_tp_as_sequence___pyx_scope_struct_1_genexpr, /*tp_as_sequence*/
38792   &__pyx_tp_as_mapping___pyx_scope_struct_1_genexpr, /*tp_as_mapping*/
38793   0, /*tp_hash*/
38794   0, /*tp_call*/
38795   0, /*tp_str*/
38796   0, /*tp_getattro*/
38797   0, /*tp_setattro*/
38798   &__pyx_tp_as_buffer___pyx_scope_struct_1_genexpr, /*tp_as_buffer*/
38799   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
38800   0, /*tp_doc*/
38801   __pyx_tp_traverse_9csamtools___pyx_scope_struct_1_genexpr, /*tp_traverse*/
38802   __pyx_tp_clear_9csamtools___pyx_scope_struct_1_genexpr, /*tp_clear*/
38803   0, /*tp_richcompare*/
38804   0, /*tp_weaklistoffset*/
38805   0, /*tp_iter*/
38806   0, /*tp_iternext*/
38807   __pyx_methods_9csamtools___pyx_scope_struct_1_genexpr, /*tp_methods*/
38808   0, /*tp_members*/
38809   0, /*tp_getset*/
38810   0, /*tp_base*/
38811   0, /*tp_dict*/
38812   0, /*tp_descr_get*/
38813   0, /*tp_descr_set*/
38814   0, /*tp_dictoffset*/
38815   0, /*tp_init*/
38816   0, /*tp_alloc*/
38817   __pyx_tp_new_9csamtools___pyx_scope_struct_1_genexpr, /*tp_new*/
38818   0, /*tp_free*/
38819   0, /*tp_is_gc*/
38820   0, /*tp_bases*/
38821   0, /*tp_mro*/
38822   0, /*tp_cache*/
38823   0, /*tp_subclasses*/
38824   0, /*tp_weaklist*/
38825   0, /*tp_del*/
38826   #if PY_VERSION_HEX >= 0x02060000
38827   0, /*tp_version_tag*/
38828   #endif
38829 };
38830
38831 static PyMethodDef __pyx_methods[] = {
38832   {0, 0, 0, 0}
38833 };
38834
38835 #if PY_MAJOR_VERSION >= 3
38836 static struct PyModuleDef __pyx_moduledef = {
38837     PyModuleDef_HEAD_INIT,
38838     __Pyx_NAMESTR("csamtools"),
38839     0, /* m_doc */
38840     -1, /* m_size */
38841     __pyx_methods /* m_methods */,
38842     NULL, /* m_reload */
38843     NULL, /* m_traverse */
38844     NULL, /* m_clear */
38845     NULL /* m_free */
38846 };
38847 #endif
38848
38849 static __Pyx_StringTabEntry __pyx_string_tab[] = {
38850   {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0},
38851   {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
38852   {&__pyx_kp_s_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 0, 1, 0},
38853   {&__pyx_kp_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 0},
38854   {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0},
38855   {&__pyx_kp_s_105, __pyx_k_105, sizeof(__pyx_k_105), 0, 0, 1, 0},
38856   {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0},
38857   {&__pyx_kp_s_108, __pyx_k_108, sizeof(__pyx_k_108), 0, 0, 1, 0},
38858   {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0},
38859   {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0},
38860   {&__pyx_kp_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 0},
38861   {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0},
38862   {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0},
38863   {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0},
38864   {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0},
38865   {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0},
38866   {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0},
38867   {&__pyx_kp_s_129, __pyx_k_129, sizeof(__pyx_k_129), 0, 0, 1, 0},
38868   {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
38869   {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0},
38870   {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0},
38871   {&__pyx_kp_s_137, __pyx_k_137, sizeof(__pyx_k_137), 0, 0, 1, 0},
38872   {&__pyx_kp_s_138, __pyx_k_138, sizeof(__pyx_k_138), 0, 0, 1, 0},
38873   {&__pyx_kp_s_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 0, 1, 0},
38874   {&__pyx_kp_s_141, __pyx_k_141, sizeof(__pyx_k_141), 0, 0, 1, 0},
38875   {&__pyx_kp_s_145, __pyx_k_145, sizeof(__pyx_k_145), 0, 0, 1, 0},
38876   {&__pyx_n_s_147, __pyx_k_147, sizeof(__pyx_k_147), 0, 0, 1, 1},
38877   {&__pyx_kp_s_148, __pyx_k_148, sizeof(__pyx_k_148), 0, 0, 1, 0},
38878   {&__pyx_kp_s_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 0, 1, 0},
38879   {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
38880   {&__pyx_kp_s_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 0, 1, 0},
38881   {&__pyx_kp_s_151, __pyx_k_151, sizeof(__pyx_k_151), 0, 0, 1, 0},
38882   {&__pyx_kp_s_152, __pyx_k_152, sizeof(__pyx_k_152), 0, 0, 1, 0},
38883   {&__pyx_kp_s_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 0, 1, 0},
38884   {&__pyx_kp_s_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 0, 1, 0},
38885   {&__pyx_kp_s_155, __pyx_k_155, sizeof(__pyx_k_155), 0, 0, 1, 0},
38886   {&__pyx_kp_s_156, __pyx_k_156, sizeof(__pyx_k_156), 0, 0, 1, 0},
38887   {&__pyx_kp_s_157, __pyx_k_157, sizeof(__pyx_k_157), 0, 0, 1, 0},
38888   {&__pyx_kp_s_158, __pyx_k_158, sizeof(__pyx_k_158), 0, 0, 1, 0},
38889   {&__pyx_kp_s_159, __pyx_k_159, sizeof(__pyx_k_159), 0, 0, 1, 0},
38890   {&__pyx_kp_b_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 0, 0},
38891   {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
38892   {&__pyx_kp_s_160, __pyx_k_160, sizeof(__pyx_k_160), 0, 0, 1, 0},
38893   {&__pyx_kp_s_161, __pyx_k_161, sizeof(__pyx_k_161), 0, 0, 1, 0},
38894   {&__pyx_kp_s_162, __pyx_k_162, sizeof(__pyx_k_162), 0, 0, 1, 0},
38895   {&__pyx_kp_s_163, __pyx_k_163, sizeof(__pyx_k_163), 0, 0, 1, 0},
38896   {&__pyx_kp_s_164, __pyx_k_164, sizeof(__pyx_k_164), 0, 0, 1, 0},
38897   {&__pyx_kp_s_165, __pyx_k_165, sizeof(__pyx_k_165), 0, 0, 1, 0},
38898   {&__pyx_kp_s_166, __pyx_k_166, sizeof(__pyx_k_166), 0, 0, 1, 0},
38899   {&__pyx_kp_s_167, __pyx_k_167, sizeof(__pyx_k_167), 0, 0, 1, 0},
38900   {&__pyx_kp_s_168, __pyx_k_168, sizeof(__pyx_k_168), 0, 0, 1, 0},
38901   {&__pyx_kp_s_169, __pyx_k_169, sizeof(__pyx_k_169), 0, 0, 1, 0},
38902   {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
38903   {&__pyx_kp_s_170, __pyx_k_170, sizeof(__pyx_k_170), 0, 0, 1, 0},
38904   {&__pyx_kp_s_171, __pyx_k_171, sizeof(__pyx_k_171), 0, 0, 1, 0},
38905   {&__pyx_kp_s_173, __pyx_k_173, sizeof(__pyx_k_173), 0, 0, 1, 0},
38906   {&__pyx_kp_s_177, __pyx_k_177, sizeof(__pyx_k_177), 0, 0, 1, 0},
38907   {&__pyx_kp_s_178, __pyx_k_178, sizeof(__pyx_k_178), 0, 0, 1, 0},
38908   {&__pyx_kp_s_179, __pyx_k_179, sizeof(__pyx_k_179), 0, 0, 1, 0},
38909   {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
38910   {&__pyx_kp_s_185, __pyx_k_185, sizeof(__pyx_k_185), 0, 0, 1, 0},
38911   {&__pyx_kp_s_186, __pyx_k_186, sizeof(__pyx_k_186), 0, 0, 1, 0},
38912   {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0},
38913   {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
38914   {&__pyx_n_s_249, __pyx_k_249, sizeof(__pyx_k_249), 0, 0, 1, 1},
38915   {&__pyx_kp_s_251, __pyx_k_251, sizeof(__pyx_k_251), 0, 0, 1, 0},
38916   {&__pyx_kp_s_256, __pyx_k_256, sizeof(__pyx_k_256), 0, 0, 1, 0},
38917   {&__pyx_kp_s_257, __pyx_k_257, sizeof(__pyx_k_257), 0, 0, 1, 0},
38918   {&__pyx_kp_s_266, __pyx_k_266, sizeof(__pyx_k_266), 0, 0, 1, 0},
38919   {&__pyx_kp_s_273, __pyx_k_273, sizeof(__pyx_k_273), 0, 0, 1, 0},
38920   {&__pyx_kp_s_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0},
38921   {&__pyx_kp_s_290, __pyx_k_290, sizeof(__pyx_k_290), 0, 0, 1, 0},
38922   {&__pyx_kp_u_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 1, 0, 0},
38923   {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0},
38924   {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
38925   {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0},
38926   {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0},
38927   {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0},
38928   {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
38929   {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
38930   {&__pyx_kp_b_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 0, 0},
38931   {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
38932   {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0},
38933   {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0},
38934   {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0},
38935   {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
38936   {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
38937   {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
38938   {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
38939   {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0},
38940   {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0},
38941   {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
38942   {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0},
38943   {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0},
38944   {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0},
38945   {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0},
38946   {&__pyx_kp_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 0},
38947   {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0},
38948   {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0},
38949   {&__pyx_kp_s_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 1, 0},
38950   {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0},
38951   {&__pyx_kp_s_79, __pyx_k_79, sizeof(__pyx_k_79), 0, 0, 1, 0},
38952   {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0},
38953   {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0},
38954   {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
38955   {&__pyx_kp_s_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 0, 1, 0},
38956   {&__pyx_kp_s_95, __pyx_k_95, sizeof(__pyx_k_95), 0, 0, 1, 0},
38957   {&__pyx_kp_s__2scB, __pyx_k__2scB, sizeof(__pyx_k__2scB), 0, 0, 1, 0},
38958   {&__pyx_kp_s__2scH, __pyx_k__2scH, sizeof(__pyx_k__2scH), 0, 0, 1, 0},
38959   {&__pyx_kp_s__2scI, __pyx_k__2scI, sizeof(__pyx_k__2scI), 0, 0, 1, 0},
38960   {&__pyx_kp_s__2scb, __pyx_k__2scb, sizeof(__pyx_k__2scb), 0, 0, 1, 0},
38961   {&__pyx_kp_s__2scc, __pyx_k__2scc, sizeof(__pyx_k__2scc), 0, 0, 1, 0},
38962   {&__pyx_kp_s__2scf, __pyx_k__2scf, sizeof(__pyx_k__2scf), 0, 0, 1, 0},
38963   {&__pyx_kp_s__2sch, __pyx_k__2sch, sizeof(__pyx_k__2sch), 0, 0, 1, 0},
38964   {&__pyx_kp_s__2sci, __pyx_k__2sci, sizeof(__pyx_k__2sci), 0, 0, 1, 0},
38965   {&__pyx_n_s__A, __pyx_k__A, sizeof(__pyx_k__A), 0, 0, 1, 1},
38966   {&__pyx_n_s__AS, __pyx_k__AS, sizeof(__pyx_k__AS), 0, 0, 1, 1},
38967   {&__pyx_n_s__AlignedRead, __pyx_k__AlignedRead, sizeof(__pyx_k__AlignedRead), 0, 0, 1, 1},
38968   {&__pyx_n_s__AttributeError, __pyx_k__AttributeError, sizeof(__pyx_k__AttributeError), 0, 0, 1, 1},
38969   {&__pyx_n_s__B, __pyx_k__B, sizeof(__pyx_k__B), 0, 0, 1, 1},
38970   {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1},
38971   {&__pyx_n_s__CIGAR2CODE, __pyx_k__CIGAR2CODE, sizeof(__pyx_k__CIGAR2CODE), 0, 0, 1, 1},
38972   {&__pyx_n_s__CIGAR_REGEX, __pyx_k__CIGAR_REGEX, sizeof(__pyx_k__CIGAR_REGEX), 0, 0, 1, 1},
38973   {&__pyx_n_s__CL, __pyx_k__CL, sizeof(__pyx_k__CL), 0, 0, 1, 1},
38974   {&__pyx_n_s__CN, __pyx_k__CN, sizeof(__pyx_k__CN), 0, 0, 1, 1},
38975   {&__pyx_n_s__CO, __pyx_k__CO, sizeof(__pyx_k__CO), 0, 0, 1, 1},
38976   {&__pyx_n_s__D, __pyx_k__D, sizeof(__pyx_k__D), 0, 0, 1, 1},
38977   {&__pyx_n_s__DS, __pyx_k__DS, sizeof(__pyx_k__DS), 0, 0, 1, 1},
38978   {&__pyx_n_s__DT, __pyx_k__DT, sizeof(__pyx_k__DT), 0, 0, 1, 1},
38979   {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1},
38980   {&__pyx_n_s__FO, __pyx_k__FO, sizeof(__pyx_k__FO), 0, 0, 1, 1},
38981   {&__pyx_n_s__Fastafile, __pyx_k__Fastafile, sizeof(__pyx_k__Fastafile), 0, 0, 1, 1},
38982   {&__pyx_n_s__GO, __pyx_k__GO, sizeof(__pyx_k__GO), 0, 0, 1, 1},
38983   {&__pyx_n_s__H, __pyx_k__H, sizeof(__pyx_k__H), 0, 0, 1, 1},
38984   {&__pyx_n_s__HD, __pyx_k__HD, sizeof(__pyx_k__HD), 0, 0, 1, 1},
38985   {&__pyx_n_s__I, __pyx_k__I, sizeof(__pyx_k__I), 0, 0, 1, 1},
38986   {&__pyx_n_s__ID, __pyx_k__ID, sizeof(__pyx_k__ID), 0, 0, 1, 1},
38987   {&__pyx_n_s__IOError, __pyx_k__IOError, sizeof(__pyx_k__IOError), 0, 0, 1, 1},
38988   {&__pyx_n_s__IS_PYTHON3, __pyx_k__IS_PYTHON3, sizeof(__pyx_k__IS_PYTHON3), 0, 0, 1, 1},
38989   {&__pyx_n_s__IndexedReads, __pyx_k__IndexedReads, sizeof(__pyx_k__IndexedReads), 0, 0, 1, 1},
38990   {&__pyx_n_s__IteratorColumn, __pyx_k__IteratorColumn, sizeof(__pyx_k__IteratorColumn), 0, 0, 1, 1},
38991   {&__pyx_n_s__IteratorRow, __pyx_k__IteratorRow, sizeof(__pyx_k__IteratorRow), 0, 0, 1, 1},
38992   {&__pyx_n_s__KS, __pyx_k__KS, sizeof(__pyx_k__KS), 0, 0, 1, 1},
38993   {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
38994   {&__pyx_n_s__LB, __pyx_k__LB, sizeof(__pyx_k__LB), 0, 0, 1, 1},
38995   {&__pyx_n_s__LN, __pyx_k__LN, sizeof(__pyx_k__LN), 0, 0, 1, 1},
38996   {&__pyx_n_s__M5, __pyx_k__M5, sizeof(__pyx_k__M5), 0, 0, 1, 1},
38997   {&__pyx_n_s__NotImplementedError, __pyx_k__NotImplementedError, sizeof(__pyx_k__NotImplementedError), 0, 0, 1, 1},
38998   {&__pyx_n_s__OSError, __pyx_k__OSError, sizeof(__pyx_k__OSError), 0, 0, 1, 1},
38999   {&__pyx_n_s__O_CREAT, __pyx_k__O_CREAT, sizeof(__pyx_k__O_CREAT), 0, 0, 1, 1},
39000   {&__pyx_n_s__O_WRONLY, __pyx_k__O_WRONLY, sizeof(__pyx_k__O_WRONLY), 0, 0, 1, 1},
39001   {&__pyx_n_s__Outs, __pyx_k__Outs, sizeof(__pyx_k__Outs), 0, 0, 1, 1},
39002   {&__pyx_n_s__OverflowError, __pyx_k__OverflowError, sizeof(__pyx_k__OverflowError), 0, 0, 1, 1},
39003   {&__pyx_n_s__PG, __pyx_k__PG, sizeof(__pyx_k__PG), 0, 0, 1, 1},
39004   {&__pyx_n_s__PI, __pyx_k__PI, sizeof(__pyx_k__PI), 0, 0, 1, 1},
39005   {&__pyx_n_s__PL, __pyx_k__PL, sizeof(__pyx_k__PL), 0, 0, 1, 1},
39006   {&__pyx_n_s__PN, __pyx_k__PN, sizeof(__pyx_k__PN), 0, 0, 1, 1},
39007   {&__pyx_n_s__PU, __pyx_k__PU, sizeof(__pyx_k__PU), 0, 0, 1, 1},
39008   {&__pyx_n_s__PileupColumn, __pyx_k__PileupColumn, sizeof(__pyx_k__PileupColumn), 0, 0, 1, 1},
39009   {&__pyx_n_s__PileupProxy, __pyx_k__PileupProxy, sizeof(__pyx_k__PileupProxy), 0, 0, 1, 1},
39010   {&__pyx_n_s__PileupRead, __pyx_k__PileupRead, sizeof(__pyx_k__PileupRead), 0, 0, 1, 1},
39011   {&__pyx_n_s__RG, __pyx_k__RG, sizeof(__pyx_k__RG), 0, 0, 1, 1},
39012   {&__pyx_n_s__S, __pyx_k__S, sizeof(__pyx_k__S), 0, 0, 1, 1},
39013   {&__pyx_n_s__SM, __pyx_k__SM, sizeof(__pyx_k__SM), 0, 0, 1, 1},
39014   {&__pyx_n_s__SN, __pyx_k__SN, sizeof(__pyx_k__SN), 0, 0, 1, 1},
39015   {&__pyx_n_s__SO, __pyx_k__SO, sizeof(__pyx_k__SO), 0, 0, 1, 1},
39016   {&__pyx_n_s__SP, __pyx_k__SP, sizeof(__pyx_k__SP), 0, 0, 1, 1},
39017   {&__pyx_n_s__SQ, __pyx_k__SQ, sizeof(__pyx_k__SQ), 0, 0, 1, 1},
39018   {&__pyx_n_s__Samfile, __pyx_k__Samfile, sizeof(__pyx_k__Samfile), 0, 0, 1, 1},
39019   {&__pyx_n_s__StderrStore, __pyx_k__StderrStore, sizeof(__pyx_k__StderrStore), 0, 0, 1, 1},
39020   {&__pyx_n_s__StderrStoreWindows, __pyx_k__StderrStoreWindows, sizeof(__pyx_k__StderrStoreWindows), 0, 0, 1, 1},
39021   {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
39022   {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
39023   {&__pyx_n_s__UR, __pyx_k__UR, sizeof(__pyx_k__UR), 0, 0, 1, 1},
39024   {&__pyx_n_s__UnicodeDecodeError, __pyx_k__UnicodeDecodeError, sizeof(__pyx_k__UnicodeDecodeError), 0, 0, 1, 1},
39025   {&__pyx_n_s__VALID_HEADERS, __pyx_k__VALID_HEADERS, sizeof(__pyx_k__VALID_HEADERS), 0, 0, 1, 1},
39026   {&__pyx_n_s__VALID_HEADER_FIELDS, __pyx_k__VALID_HEADER_FIELDS, sizeof(__pyx_k__VALID_HEADER_FIELDS), 0, 0, 1, 1},
39027   {&__pyx_n_s__VALID_HEADER_ORDER, __pyx_k__VALID_HEADER_ORDER, sizeof(__pyx_k__VALID_HEADER_ORDER), 0, 0, 1, 1},
39028   {&__pyx_n_s__VALID_HEADER_TYPES, __pyx_k__VALID_HEADER_TYPES, sizeof(__pyx_k__VALID_HEADER_TYPES), 0, 0, 1, 1},
39029   {&__pyx_n_s__VN, __pyx_k__VN, sizeof(__pyx_k__VN), 0, 0, 1, 1},
39030   {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
39031   {&__pyx_n_s__Windows, __pyx_k__Windows, sizeof(__pyx_k__Windows), 0, 0, 1, 1},
39032   {&__pyx_n_s__Z, __pyx_k__Z, sizeof(__pyx_k__Z), 0, 0, 1, 1},
39033   {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
39034   {&__pyx_n_s____del__, __pyx_k____del__, sizeof(__pyx_k____del__), 0, 0, 1, 1},
39035   {&__pyx_n_s____dict__, __pyx_k____dict__, sizeof(__pyx_k____dict__), 0, 0, 1, 1},
39036   {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1},
39037   {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1},
39038   {&__pyx_n_s____getattribute__, __pyx_k____getattribute__, sizeof(__pyx_k____getattribute__), 0, 0, 1, 1},
39039   {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1},
39040   {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
39041   {&__pyx_n_s____str__, __pyx_k____str__, sizeof(__pyx_k____str__), 0, 0, 1, 1},
39042   {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
39043   {&__pyx_n_s___buildLine, __pyx_k___buildLine, sizeof(__pyx_k___buildLine), 0, 0, 1, 1},
39044   {&__pyx_n_s___hasIndex, __pyx_k___hasIndex, sizeof(__pyx_k___hasIndex), 0, 0, 1, 1},
39045   {&__pyx_n_s___isOpen, __pyx_k___isOpen, sizeof(__pyx_k___isOpen), 0, 0, 1, 1},
39046   {&__pyx_n_s___open, __pyx_k___open, sizeof(__pyx_k___open), 0, 0, 1, 1},
39047   {&__pyx_n_s___parseRegion, __pyx_k___parseRegion, sizeof(__pyx_k___parseRegion), 0, 0, 1, 1},
39048   {&__pyx_n_s___samtools_dispatch, __pyx_k___samtools_dispatch, sizeof(__pyx_k___samtools_dispatch), 0, 0, 1, 1},
39049   {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1},
39050   {&__pyx_n_s__add_sq_text, __pyx_k__add_sq_text, sizeof(__pyx_k__add_sq_text), 0, 0, 1, 1},
39051   {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1},
39052   {&__pyx_n_s__all, __pyx_k__all, sizeof(__pyx_k__all), 0, 0, 1, 1},
39053   {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
39054   {&__pyx_n_s__ascii, __pyx_k__ascii, sizeof(__pyx_k__ascii), 0, 0, 1, 1},
39055   {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1},
39056   {&__pyx_n_s__beg, __pyx_k__beg, sizeof(__pyx_k__beg), 0, 0, 1, 1},
39057   {&__pyx_n_s__bin, __pyx_k__bin, sizeof(__pyx_k__bin), 0, 0, 1, 1},
39058   {&__pyx_n_s__bqual, __pyx_k__bqual, sizeof(__pyx_k__bqual), 0, 0, 1, 1},
39059   {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1},
39060   {&__pyx_n_s__calcsize, __pyx_k__calcsize, sizeof(__pyx_k__calcsize), 0, 0, 1, 1},
39061   {&__pyx_n_s__callback, __pyx_k__callback, sizeof(__pyx_k__callback), 0, 0, 1, 1},
39062   {&__pyx_n_s__cargs, __pyx_k__cargs, sizeof(__pyx_k__cargs), 0, 0, 1, 1},
39063   {&__pyx_n_s__catch_stdout, __pyx_k__catch_stdout, sizeof(__pyx_k__catch_stdout), 0, 0, 1, 1},
39064   {&__pyx_n_s__check_header, __pyx_k__check_header, sizeof(__pyx_k__check_header), 0, 0, 1, 1},
39065   {&__pyx_n_s__check_sq, __pyx_k__check_sq, sizeof(__pyx_k__check_sq), 0, 0, 1, 1},
39066   {&__pyx_n_s__chr, __pyx_k__chr, sizeof(__pyx_k__chr), 0, 0, 1, 1},
39067   {&__pyx_n_s__cigar, __pyx_k__cigar, sizeof(__pyx_k__cigar), 0, 0, 1, 1},
39068   {&__pyx_n_s__close, __pyx_k__close, sizeof(__pyx_k__close), 0, 0, 1, 1},
39069   {&__pyx_n_s__collections, __pyx_k__collections, sizeof(__pyx_k__collections), 0, 0, 1, 1},
39070   {&__pyx_n_s__compile, __pyx_k__compile, sizeof(__pyx_k__compile), 0, 0, 1, 1},
39071   {&__pyx_n_s__consensus_quality, __pyx_k__consensus_quality, sizeof(__pyx_k__consensus_quality), 0, 0, 1, 1},
39072   {&__pyx_n_s__coverage, __pyx_k__coverage, sizeof(__pyx_k__coverage), 0, 0, 1, 1},
39073   {&__pyx_n_s__csamtools, __pyx_k__csamtools, sizeof(__pyx_k__csamtools), 0, 0, 1, 1},
39074   {&__pyx_n_s__ctypes, __pyx_k__ctypes, sizeof(__pyx_k__ctypes), 0, 0, 1, 1},
39075   {&__pyx_n_s__d, __pyx_k__d, sizeof(__pyx_k__d), 0, 0, 1, 1},
39076   {&__pyx_n_s__data_len, __pyx_k__data_len, sizeof(__pyx_k__data_len), 0, 0, 1, 1},
39077   {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1},
39078   {&__pyx_n_s__defaultdict, __pyx_k__defaultdict, sizeof(__pyx_k__defaultdict), 0, 0, 1, 1},
39079   {&__pyx_n_s__dup, __pyx_k__dup, sizeof(__pyx_k__dup), 0, 0, 1, 1},
39080   {&__pyx_n_s__dup2, __pyx_k__dup2, sizeof(__pyx_k__dup2), 0, 0, 1, 1},
39081   {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1},
39082   {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
39083   {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1},
39084   {&__pyx_n_s__exc_type, __pyx_k__exc_type, sizeof(__pyx_k__exc_type), 0, 0, 1, 1},
39085   {&__pyx_n_s__exc_value, __pyx_k__exc_value, sizeof(__pyx_k__exc_value), 0, 0, 1, 1},
39086   {&__pyx_n_s__exists, __pyx_k__exists, sizeof(__pyx_k__exists), 0, 0, 1, 1},
39087   {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1},
39088   {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1},
39089   {&__pyx_n_s__fastafile, __pyx_k__fastafile, sizeof(__pyx_k__fastafile), 0, 0, 1, 1},
39090   {&__pyx_n_s__fd, __pyx_k__fd, sizeof(__pyx_k__fd), 0, 0, 1, 1},
39091   {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1},
39092   {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1},
39093   {&__pyx_n_s__fileno, __pyx_k__fileno, sizeof(__pyx_k__fileno), 0, 0, 1, 1},
39094   {&__pyx_n_s__findall, __pyx_k__findall, sizeof(__pyx_k__findall), 0, 0, 1, 1},
39095   {&__pyx_n_s__flag, __pyx_k__flag, sizeof(__pyx_k__flag), 0, 0, 1, 1},
39096   {&__pyx_n_s__flush, __pyx_k__flush, sizeof(__pyx_k__flush), 0, 0, 1, 1},
39097   {&__pyx_n_s__genotype, __pyx_k__genotype, sizeof(__pyx_k__genotype), 0, 0, 1, 1},
39098   {&__pyx_n_s__getdefaultencoding, __pyx_k__getdefaultencoding, sizeof(__pyx_k__getdefaultencoding), 0, 0, 1, 1},
39099   {&__pyx_n_s__gettid, __pyx_k__gettid, sizeof(__pyx_k__gettid), 0, 0, 1, 1},
39100   {&__pyx_n_s__h, __pyx_k__h, sizeof(__pyx_k__h), 0, 0, 1, 1},
39101   {&__pyx_n_s__header, __pyx_k__header, sizeof(__pyx_k__header), 0, 0, 1, 1},
39102   {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
39103   {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1},
39104   {&__pyx_n_s__indel, __pyx_k__indel, sizeof(__pyx_k__indel), 0, 0, 1, 1},
39105   {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1},
39106   {&__pyx_n_s__inf, __pyx_k__inf, sizeof(__pyx_k__inf), 0, 0, 1, 1},
39107   {&__pyx_n_s__is_del, __pyx_k__is_del, sizeof(__pyx_k__is_del), 0, 0, 1, 1},
39108   {&__pyx_n_s__is_head, __pyx_k__is_head, sizeof(__pyx_k__is_head), 0, 0, 1, 1},
39109   {&__pyx_n_s__is_tail, __pyx_k__is_tail, sizeof(__pyx_k__is_tail), 0, 0, 1, 1},
39110   {&__pyx_n_s__isize, __pyx_k__isize, sizeof(__pyx_k__isize), 0, 0, 1, 1},
39111   {&__pyx_n_s__islower, __pyx_k__islower, sizeof(__pyx_k__islower), 0, 0, 1, 1},
39112   {&__pyx_n_s__isupper, __pyx_k__isupper, sizeof(__pyx_k__isupper), 0, 0, 1, 1},
39113   {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1},
39114   {&__pyx_n_s__itertools, __pyx_k__itertools, sizeof(__pyx_k__itertools), 0, 0, 1, 1},
39115   {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1},
39116   {&__pyx_n_s__l_aux, __pyx_k__l_aux, sizeof(__pyx_k__l_aux), 0, 0, 1, 1},
39117   {&__pyx_n_s__l_qname, __pyx_k__l_qname, sizeof(__pyx_k__l_qname), 0, 0, 1, 1},
39118   {&__pyx_n_s__l_qseq, __pyx_k__l_qseq, sizeof(__pyx_k__l_qseq), 0, 0, 1, 1},
39119   {&__pyx_n_s__lengths, __pyx_k__lengths, sizeof(__pyx_k__lengths), 0, 0, 1, 1},
39120   {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1},
39121   {&__pyx_n_s__m_data, __pyx_k__m_data, sizeof(__pyx_k__m_data), 0, 0, 1, 1},
39122   {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1},
39123   {&__pyx_n_s__mapping_quality, __pyx_k__mapping_quality, sizeof(__pyx_k__mapping_quality), 0, 0, 1, 1},
39124   {&__pyx_n_s__mapq, __pyx_k__mapq, sizeof(__pyx_k__mapq), 0, 0, 1, 1},
39125   {&__pyx_n_s__mask, __pyx_k__mask, sizeof(__pyx_k__mask), 0, 0, 1, 1},
39126   {&__pyx_n_s__max, __pyx_k__max, sizeof(__pyx_k__max), 0, 0, 1, 1},
39127   {&__pyx_n_s__max_depth, __pyx_k__max_depth, sizeof(__pyx_k__max_depth), 0, 0, 1, 1},
39128   {&__pyx_n_s__method, __pyx_k__method, sizeof(__pyx_k__method), 0, 0, 1, 1},
39129   {&__pyx_n_s__min, __pyx_k__min, sizeof(__pyx_k__min), 0, 0, 1, 1},
39130   {&__pyx_n_s__mkstemp, __pyx_k__mkstemp, sizeof(__pyx_k__mkstemp), 0, 0, 1, 1},
39131   {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
39132   {&__pyx_n_s__mpos, __pyx_k__mpos, sizeof(__pyx_k__mpos), 0, 0, 1, 1},
39133   {&__pyx_n_s__mrnm, __pyx_k__mrnm, sizeof(__pyx_k__mrnm), 0, 0, 1, 1},
39134   {&__pyx_n_s__mtid, __pyx_k__mtid, sizeof(__pyx_k__mtid), 0, 0, 1, 1},
39135   {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
39136   {&__pyx_n_s__n_cigar, __pyx_k__n_cigar, sizeof(__pyx_k__n_cigar), 0, 0, 1, 1},
39137   {&__pyx_n_s__nextiter, __pyx_k__nextiter, sizeof(__pyx_k__nextiter), 0, 0, 1, 1},
39138   {&__pyx_n_s__nreferences, __pyx_k__nreferences, sizeof(__pyx_k__nreferences), 0, 0, 1, 1},
39139   {&__pyx_n_s__object, __pyx_k__object, sizeof(__pyx_k__object), 0, 0, 1, 1},
39140   {&__pyx_n_s__ofd, __pyx_k__ofd, sizeof(__pyx_k__ofd), 0, 0, 1, 1},
39141   {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1},
39142   {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1},
39143   {&__pyx_n_s__ord, __pyx_k__ord, sizeof(__pyx_k__ord), 0, 0, 1, 1},
39144   {&__pyx_n_s__os, __pyx_k__os, sizeof(__pyx_k__os), 0, 0, 1, 1},
39145   {&__pyx_n_s__out_stderr, __pyx_k__out_stderr, sizeof(__pyx_k__out_stderr), 0, 0, 1, 1},
39146   {&__pyx_n_s__out_stdout, __pyx_k__out_stdout, sizeof(__pyx_k__out_stdout), 0, 0, 1, 1},
39147   {&__pyx_n_s__pack_into, __pyx_k__pack_into, sizeof(__pyx_k__pack_into), 0, 0, 1, 1},
39148   {&__pyx_n_s__path, __pyx_k__path, sizeof(__pyx_k__path), 0, 0, 1, 1},
39149   {&__pyx_n_s__pileups, __pyx_k__pileups, sizeof(__pyx_k__pileups), 0, 0, 1, 1},
39150   {&__pyx_n_s__platform, __pyx_k__platform, sizeof(__pyx_k__platform), 0, 0, 1, 1},
39151   {&__pyx_n_s__port, __pyx_k__port, sizeof(__pyx_k__port), 0, 0, 1, 1},
39152   {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
39153   {&__pyx_n_s__positions, __pyx_k__positions, sizeof(__pyx_k__positions), 0, 0, 1, 1},
39154   {&__pyx_n_s__qname, __pyx_k__qname, sizeof(__pyx_k__qname), 0, 0, 1, 1},
39155   {&__pyx_n_s__qpos, __pyx_k__qpos, sizeof(__pyx_k__qpos), 0, 0, 1, 1},
39156   {&__pyx_n_s__qseq, __pyx_k__qseq, sizeof(__pyx_k__qseq), 0, 0, 1, 1},
39157   {&__pyx_n_s__qual, __pyx_k__qual, sizeof(__pyx_k__qual), 0, 0, 1, 1},
39158   {&__pyx_n_b__r, __pyx_k__r, sizeof(__pyx_k__r), 0, 0, 0, 1},
39159   {&__pyx_n_s__r, __pyx_k__r, sizeof(__pyx_k__r), 0, 0, 1, 1},
39160   {&__pyx_n_s__rU, __pyx_k__rU, sizeof(__pyx_k__rU), 0, 0, 1, 1},
39161   {&__pyx_n_s__raw, __pyx_k__raw, sizeof(__pyx_k__raw), 0, 0, 1, 1},
39162   {&__pyx_n_b__rb, __pyx_k__rb, sizeof(__pyx_k__rb), 0, 0, 0, 1},
39163   {&__pyx_n_s__rb, __pyx_k__rb, sizeof(__pyx_k__rb), 0, 0, 1, 1},
39164   {&__pyx_n_s__re, __pyx_k__re, sizeof(__pyx_k__re), 0, 0, 1, 1},
39165   {&__pyx_n_s__read, __pyx_k__read, sizeof(__pyx_k__read), 0, 0, 1, 1},
39166   {&__pyx_n_s__readAndRelease, __pyx_k__readAndRelease, sizeof(__pyx_k__readAndRelease), 0, 0, 1, 1},
39167   {&__pyx_n_s__readlines, __pyx_k__readlines, sizeof(__pyx_k__readlines), 0, 0, 1, 1},
39168   {&__pyx_n_s__record, __pyx_k__record, sizeof(__pyx_k__record), 0, 0, 1, 1},
39169   {&__pyx_n_s__reference, __pyx_k__reference, sizeof(__pyx_k__reference), 0, 0, 1, 1},
39170   {&__pyx_n_s__reference_base, __pyx_k__reference_base, sizeof(__pyx_k__reference_base), 0, 0, 1, 1},
39171   {&__pyx_n_s__referencelengths, __pyx_k__referencelengths, sizeof(__pyx_k__referencelengths), 0, 0, 1, 1},
39172   {&__pyx_n_s__referencenames, __pyx_k__referencenames, sizeof(__pyx_k__referencenames), 0, 0, 1, 1},
39173   {&__pyx_n_s__references, __pyx_k__references, sizeof(__pyx_k__references), 0, 0, 1, 1},
39174   {&__pyx_n_s__region, __pyx_k__region, sizeof(__pyx_k__region), 0, 0, 1, 1},
39175   {&__pyx_n_s__release, __pyx_k__release, sizeof(__pyx_k__release), 0, 0, 1, 1},
39176   {&__pyx_n_s__remove, __pyx_k__remove, sizeof(__pyx_k__remove), 0, 0, 1, 1},
39177   {&__pyx_n_s__reopen, __pyx_k__reopen, sizeof(__pyx_k__reopen), 0, 0, 1, 1},
39178   {&__pyx_n_s__restore, __pyx_k__restore, sizeof(__pyx_k__restore), 0, 0, 1, 1},
39179   {&__pyx_n_s__retval, __pyx_k__retval, sizeof(__pyx_k__retval), 0, 0, 1, 1},
39180   {&__pyx_n_s__rlen, __pyx_k__rlen, sizeof(__pyx_k__rlen), 0, 0, 1, 1},
39181   {&__pyx_n_s__rname, __pyx_k__rname, sizeof(__pyx_k__rname), 0, 0, 1, 1},
39182   {&__pyx_n_s__s, __pyx_k__s, sizeof(__pyx_k__s), 0, 0, 1, 1},
39183   {&__pyx_n_s__samfile, __pyx_k__samfile, sizeof(__pyx_k__samfile), 0, 0, 1, 1},
39184   {&__pyx_n_s__samtools, __pyx_k__samtools, sizeof(__pyx_k__samtools), 0, 0, 1, 1},
39185   {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1},
39186   {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1},
39187   {&__pyx_n_s__seq, __pyx_k__seq, sizeof(__pyx_k__seq), 0, 0, 1, 1},
39188   {&__pyx_n_s__setdevice, __pyx_k__setdevice, sizeof(__pyx_k__setdevice), 0, 0, 1, 1},
39189   {&__pyx_n_s__setfd, __pyx_k__setfd, sizeof(__pyx_k__setfd), 0, 0, 1, 1},
39190   {&__pyx_n_s__setfile, __pyx_k__setfile, sizeof(__pyx_k__setfile), 0, 0, 1, 1},
39191   {&__pyx_n_s__snp_quality, __pyx_k__snp_quality, sizeof(__pyx_k__snp_quality), 0, 0, 1, 1},
39192   {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1},
39193   {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
39194   {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
39195   {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1},
39196   {&__pyx_n_s__stderr, __pyx_k__stderr, sizeof(__pyx_k__stderr), 0, 0, 1, 1},
39197   {&__pyx_n_s__stderr_f, __pyx_k__stderr_f, sizeof(__pyx_k__stderr_f), 0, 0, 1, 1},
39198   {&__pyx_n_s__stderr_h, __pyx_k__stderr_h, sizeof(__pyx_k__stderr_h), 0, 0, 1, 1},
39199   {&__pyx_n_s__stdout, __pyx_k__stdout, sizeof(__pyx_k__stdout), 0, 0, 1, 1},
39200   {&__pyx_n_s__stdout_f, __pyx_k__stdout_f, sizeof(__pyx_k__stdout_f), 0, 0, 1, 1},
39201   {&__pyx_n_s__stdout_h, __pyx_k__stdout_h, sizeof(__pyx_k__stdout_h), 0, 0, 1, 1},
39202   {&__pyx_n_s__stdout_save, __pyx_k__stdout_save, sizeof(__pyx_k__stdout_save), 0, 0, 1, 1},
39203   {&__pyx_n_s__stepper, __pyx_k__stepper, sizeof(__pyx_k__stepper), 0, 0, 1, 1},
39204   {&__pyx_n_s__streams, __pyx_k__streams, sizeof(__pyx_k__streams), 0, 0, 1, 1},
39205   {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1},
39206   {&__pyx_n_s__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1},
39207   {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
39208   {&__pyx_n_s__system, __pyx_k__system, sizeof(__pyx_k__system), 0, 0, 1, 1},
39209   {&__pyx_n_s__tags, __pyx_k__tags, sizeof(__pyx_k__tags), 0, 0, 1, 1},
39210   {&__pyx_n_s__tempfile, __pyx_k__tempfile, sizeof(__pyx_k__tempfile), 0, 0, 1, 1},
39211   {&__pyx_n_s__template, __pyx_k__template, sizeof(__pyx_k__template), 0, 0, 1, 1},
39212   {&__pyx_n_s__text, __pyx_k__text, sizeof(__pyx_k__text), 0, 0, 1, 1},
39213   {&__pyx_n_s__tid, __pyx_k__tid, sizeof(__pyx_k__tid), 0, 0, 1, 1},
39214   {&__pyx_n_s__traceback, __pyx_k__traceback, sizeof(__pyx_k__traceback), 0, 0, 1, 1},
39215   {&__pyx_n_s__truncate, __pyx_k__truncate, sizeof(__pyx_k__truncate), 0, 0, 1, 1},
39216   {&__pyx_n_s__types, __pyx_k__types, sizeof(__pyx_k__types), 0, 0, 1, 1},
39217   {&__pyx_n_s__until_eof, __pyx_k__until_eof, sizeof(__pyx_k__until_eof), 0, 0, 1, 1},
39218   {&__pyx_n_s__version_info, __pyx_k__version_info, sizeof(__pyx_k__version_info), 0, 0, 1, 1},
39219   {&__pyx_n_s__view, __pyx_k__view, sizeof(__pyx_k__view), 0, 0, 1, 1},
39220   {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1},
39221   {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1},
39222   {&__pyx_n_s__warnings, __pyx_k__warnings, sizeof(__pyx_k__warnings), 0, 0, 1, 1},
39223   {&__pyx_n_s__wb, __pyx_k__wb, sizeof(__pyx_k__wb), 0, 0, 1, 1},
39224   {&__pyx_n_s__wbu, __pyx_k__wbu, sizeof(__pyx_k__wbu), 0, 0, 1, 1},
39225   {&__pyx_n_s__wh, __pyx_k__wh, sizeof(__pyx_k__wh), 0, 0, 1, 1},
39226   {&__pyx_n_s__where, __pyx_k__where, sizeof(__pyx_k__where), 0, 0, 1, 1},
39227   {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1},
39228   {&__pyx_n_s__zip, __pyx_k__zip, sizeof(__pyx_k__zip), 0, 0, 1, 1},
39229   {0, 0, 0, 0, 0, 0, 0}
39230 };
39231 static int __Pyx_InitCachedBuiltins(void) {
39232   __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39233   __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;}
39234   __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;}
39235   __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;}
39236   __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39237   __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39238   __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39239   __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_n_s__OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39240   __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39241   __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39242   __pyx_builtin_AttributeError = __Pyx_GetName(__pyx_b, __pyx_n_s__AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39243   __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39244   __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39245   __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39246   __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39247   __pyx_builtin_min = __Pyx_GetName(__pyx_b, __pyx_n_s__min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39248   __pyx_builtin_max = __Pyx_GetName(__pyx_b, __pyx_n_s__max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39249   __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39250   __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39251   __pyx_builtin_UnicodeDecodeError = __Pyx_GetName(__pyx_b, __pyx_n_s__UnicodeDecodeError); if (!__pyx_builtin_UnicodeDecodeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39252   return 0;
39253   __pyx_L1_error:;
39254   return -1;
39255 }
39256
39257 static int __Pyx_InitCachedConstants(void) {
39258   __Pyx_RefNannyDeclarations
39259   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
39260
39261   /* "csamtools.pyx":64
39262  *         return s
39263  *     elif PyUnicode_Check(s):
39264  *         return s.encode('ascii')             # <<<<<<<<<<<<<<
39265  *     else:
39266  *         raise TypeError, u"Argument must be string, bytes or unicode."
39267  */
39268   __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39269   __Pyx_GOTREF(__pyx_k_tuple_2);
39270   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39271   PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_n_s__ascii));
39272   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39273   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
39274
39275   /* "csamtools.pyx":84
39276  *         return s
39277  *     elif PyBytes_Check(s):
39278  *         return s.decode('ascii')             # <<<<<<<<<<<<<<
39279  *     else:
39280  *         # assume unicode
39281  */
39282   __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39283   __Pyx_GOTREF(__pyx_k_tuple_4);
39284   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39285   PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__ascii));
39286   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39287   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
39288
39289   /* "csamtools.pyx":398
39290  *     def __len__(self):
39291  *         if self.fastafile == NULL:
39292  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
39293  * 
39294  *         return faidx_fetch_nseq(self.fastafile)
39295  */
39296   __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39297   __Pyx_GOTREF(__pyx_k_tuple_8);
39298   __Pyx_INCREF(((PyObject *)__pyx_kp_s_7));
39299   PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_7));
39300   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_7));
39301   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
39302
39303   /* "csamtools.pyx":431
39304  *         '''number of :term:`filename` associated with this object.'''
39305  *         def __get__(self):
39306  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39307  *             return self._filename
39308  * 
39309  */
39310   __pyx_k_tuple_11 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39311   __Pyx_GOTREF(__pyx_k_tuple_11);
39312   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39313   PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, ((PyObject *)__pyx_kp_s_10));
39314   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39315   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11));
39316
39317   /* "csamtools.pyx":456
39318  * 
39319  *         if not self._isOpen():
39320  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39321  * 
39322  *         cdef int length
39323  */
39324   __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39325   __Pyx_GOTREF(__pyx_k_tuple_12);
39326   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39327   PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_s_10));
39328   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39329   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12));
39330
39331   /* "csamtools.pyx":462
39332  * 
39333  *         if not region:
39334  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
39335  *             if start is None: start = 0
39336  *             if end is None: end = max_pos -1
39337  */
39338   __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39339   __Pyx_GOTREF(__pyx_k_tuple_14);
39340   __Pyx_INCREF(((PyObject *)__pyx_kp_s_13));
39341   PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13));
39342   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13));
39343   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14));
39344
39345   /* "csamtools.pyx":481
39346  *             region = "%s:%i-%i" % (reference, start+1, end)
39347  *             if PY_MAJOR_VERSION >= 3:
39348  *                 region = region.encode('ascii')             # <<<<<<<<<<<<<<
39349  *             seq = fai_fetch( self.fastafile,
39350  *                              region,
39351  */
39352   __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39353   __Pyx_GOTREF(__pyx_k_tuple_20);
39354   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39355   PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__ascii));
39356   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39357   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20));
39358
39359   /* "csamtools.pyx":663
39360  *         if self._filename != NULL: free(self._filename )
39361  *         filename = _my_encodeFilename(filename)
39362  *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
39363  *         #cdef char* cfilename
39364  *         #cfilename = filename.encode(_FILENAME_ENCODING)
39365  */
39366   __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39367   __Pyx_GOTREF(__pyx_k_tuple_25);
39368   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39369   PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__ascii));
39370   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39371   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25));
39372
39373   /* "csamtools.pyx":790
39374  *         returns -1 if reference is not known.
39375  *         '''
39376  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39377  *         reference = _force_bytes(reference)
39378  *         return pysam_reference2tid( self.samfile.header, reference )
39379  */
39380   __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39381   __Pyx_GOTREF(__pyx_k_tuple_39);
39382   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39383   PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_kp_s_10));
39384   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39385   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39));
39386
39387   /* "csamtools.pyx":797
39388  *         '''
39389  *         convert numerical :term:`tid` into :term:`reference` name.'''
39390  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39391  *         if not 0 <= tid < self.samfile.header.n_targets:
39392  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
39393  */
39394   __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39395   __Pyx_GOTREF(__pyx_k_tuple_40);
39396   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39397   PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_kp_s_10));
39398   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39399   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));
39400
39401   /* "csamtools.pyx":805
39402  *         '''
39403  *         convert numerical :term:`tid` into :term:`reference` name.'''
39404  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39405  *         if not 0 <= tid < self.samfile.header.n_targets:
39406  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
39407  */
39408   __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39409   __Pyx_GOTREF(__pyx_k_tuple_42);
39410   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39411   PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_10));
39412   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39413   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));
39414
39415   /* "csamtools.pyx":855
39416  *             if len(parts) >= 3: rend = int(parts[2])
39417  * 
39418  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
39419  * 
39420  *         rtid = self.gettid( reference )
39421  */
39422   __pyx_k_tuple_44 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39423   __Pyx_GOTREF(__pyx_k_tuple_44);
39424   __Pyx_INCREF(__pyx_int_0);
39425   PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, __pyx_int_0);
39426   __Pyx_GIVEREF(__pyx_int_0);
39427   __Pyx_INCREF(__pyx_int_0);
39428   PyTuple_SET_ITEM(__pyx_k_tuple_44, 1, __pyx_int_0);
39429   __Pyx_GIVEREF(__pyx_int_0);
39430   __Pyx_INCREF(__pyx_int_0);
39431   PyTuple_SET_ITEM(__pyx_k_tuple_44, 2, __pyx_int_0);
39432   __Pyx_GIVEREF(__pyx_int_0);
39433   __Pyx_INCREF(__pyx_int_0);
39434   PyTuple_SET_ITEM(__pyx_k_tuple_44, 3, __pyx_int_0);
39435   __Pyx_GIVEREF(__pyx_int_0);
39436   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44));
39437
39438   /* "csamtools.pyx":875
39439  * 
39440  *         if not self._isOpen():
39441  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39442  *         if not self.isbam:
39443  *             raise NotImplementedError("seek only available in bam files")
39444  */
39445   __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39446   __Pyx_GOTREF(__pyx_k_tuple_47);
39447   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39448   PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_kp_s_10));
39449   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39450   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
39451
39452   /* "csamtools.pyx":877
39453  *             raise ValueError( "I/O operation on closed file" )
39454  *         if not self.isbam:
39455  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
39456  *         if self.isstream:
39457  *             raise OSError("seek no available in streams")
39458  */
39459   __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39460   __Pyx_GOTREF(__pyx_k_tuple_49);
39461   __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
39462   PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_48));
39463   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
39464   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49));
39465
39466   /* "csamtools.pyx":879
39467  *             raise NotImplementedError("seek only available in bam files")
39468  *         if self.isstream:
39469  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
39470  * 
39471  *         return bam_seek( self.samfile.x.bam, offset, where )
39472  */
39473   __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39474   __Pyx_GOTREF(__pyx_k_tuple_51);
39475   __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
39476   PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_50));
39477   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
39478   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51));
39479
39480   /* "csamtools.pyx":888
39481  *         '''
39482  *         if not self._isOpen():
39483  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39484  *         if not self.isbam:
39485  *             raise NotImplementedError("seek only available in bam files")
39486  */
39487   __pyx_k_tuple_52 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39488   __Pyx_GOTREF(__pyx_k_tuple_52);
39489   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39490   PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_kp_s_10));
39491   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39492   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));
39493
39494   /* "csamtools.pyx":890
39495  *             raise ValueError( "I/O operation on closed file" )
39496  *         if not self.isbam:
39497  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
39498  * 
39499  *         return bam_tell( self.samfile.x.bam )
39500  */
39501   __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39502   __Pyx_GOTREF(__pyx_k_tuple_53);
39503   __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
39504   PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_kp_s_48));
39505   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
39506   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53));
39507
39508   /* "csamtools.pyx":925
39509  * 
39510  *         if not self._isOpen():
39511  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39512  * 
39513  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
39514  */
39515   __pyx_k_tuple_55 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39516   __Pyx_GOTREF(__pyx_k_tuple_55);
39517   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39518   PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_kp_s_10));
39519   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39520   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));
39521
39522   /* "csamtools.pyx":934
39523  *         if self.isbam:
39524  *             if not until_eof and not self._hasIndex() and not self.isremote:
39525  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
39526  * 
39527  *             if callback:
39528  */
39529   __pyx_k_tuple_57 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39530   __Pyx_GOTREF(__pyx_k_tuple_57);
39531   __Pyx_INCREF(((PyObject *)__pyx_kp_s_56));
39532   PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_kp_s_56));
39533   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_56));
39534   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57));
39535
39536   /* "csamtools.pyx":937
39537  * 
39538  *             if callback:
39539  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
39540  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
39541  *                 return bam_fetch(self.samfile.x.bam,
39542  */
39543   __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39544   __Pyx_GOTREF(__pyx_k_tuple_59);
39545   __Pyx_INCREF(((PyObject *)__pyx_kp_s_58));
39546   PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_kp_s_58));
39547   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_58));
39548   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59));
39549
39550   /* "csamtools.pyx":938
39551  *             if callback:
39552  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
39553  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
39554  *                 return bam_fetch(self.samfile.x.bam,
39555  *                                  self.index,
39556  */
39557   __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39558   __Pyx_GOTREF(__pyx_k_tuple_61);
39559   __Pyx_INCREF(((PyObject *)__pyx_kp_s_60));
39560   PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_kp_s_60));
39561   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60));
39562   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));
39563
39564   /* "csamtools.pyx":957
39565  *         else:
39566  *             if has_coord:
39567  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
39568  * 
39569  *             if callback:
39570  */
39571   __pyx_k_tuple_63 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39572   __Pyx_GOTREF(__pyx_k_tuple_63);
39573   __Pyx_INCREF(((PyObject *)__pyx_kp_s_62));
39574   PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_kp_s_62));
39575   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_62));
39576   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));
39577
39578   /* "csamtools.pyx":960
39579  * 
39580  *             if callback:
39581  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
39582  * 
39583  *             if self.samfile.header == NULL:
39584  */
39585   __pyx_k_tuple_65 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39586   __Pyx_GOTREF(__pyx_k_tuple_65);
39587   __Pyx_INCREF(((PyObject *)__pyx_kp_s_64));
39588   PyTuple_SET_ITEM(__pyx_k_tuple_65, 0, ((PyObject *)__pyx_kp_s_64));
39589   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_64));
39590   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_65));
39591
39592   /* "csamtools.pyx":963
39593  * 
39594  *             if self.samfile.header == NULL:
39595  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
39596  * 
39597  *             # check if targets are defined
39598  */
39599   __pyx_k_tuple_67 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39600   __Pyx_GOTREF(__pyx_k_tuple_67);
39601   __Pyx_INCREF(((PyObject *)__pyx_kp_s_66));
39602   PyTuple_SET_ITEM(__pyx_k_tuple_67, 0, ((PyObject *)__pyx_kp_s_66));
39603   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_66));
39604   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));
39605
39606   /* "csamtools.pyx":968
39607  *             # give warning, sam_read1 segfaults
39608  *             if self.samfile.header.n_targets == 0:
39609  *                 warnings.warn( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
39610  * 
39611  *             return IteratorRowAll( self, reopen=reopen )
39612  */
39613   __pyx_k_tuple_68 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39614   __Pyx_GOTREF(__pyx_k_tuple_68);
39615   __Pyx_INCREF(((PyObject *)__pyx_kp_s_66));
39616   PyTuple_SET_ITEM(__pyx_k_tuple_68, 0, ((PyObject *)__pyx_kp_s_66));
39617   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_66));
39618   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_68));
39619
39620   /* "csamtools.pyx":1009
39621  * 
39622  *         if mate_data.mate == NULL:
39623  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
39624  * 
39625  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
39626  */
39627   __pyx_k_tuple_72 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39628   __Pyx_GOTREF(__pyx_k_tuple_72);
39629   __Pyx_INCREF(((PyObject *)__pyx_kp_s_71));
39630   PyTuple_SET_ITEM(__pyx_k_tuple_72, 0, ((PyObject *)__pyx_kp_s_71));
39631   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_71));
39632   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_72));
39633
39634   /* "csamtools.pyx":1034
39635  * 
39636  *         if not self._isOpen():
39637  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39638  * 
39639  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
39640  */
39641   __pyx_k_tuple_74 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_74)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39642   __Pyx_GOTREF(__pyx_k_tuple_74);
39643   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39644   PyTuple_SET_ITEM(__pyx_k_tuple_74, 0, ((PyObject *)__pyx_kp_s_10));
39645   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39646   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_74));
39647
39648   /* "csamtools.pyx":1043
39649  *         if self.isbam:
39650  *             if not until_eof and not self._hasIndex() and not self.isremote:
39651  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
39652  * 
39653  *             if not region:
39654  */
39655   __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39656   __Pyx_GOTREF(__pyx_k_tuple_75);
39657   __Pyx_INCREF(((PyObject *)__pyx_kp_s_56));
39658   PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_56));
39659   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_56));
39660   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));
39661
39662   /* "csamtools.pyx":1046
39663  * 
39664  *             if not region:
39665  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
39666  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
39667  *             bam_fetch(self.samfile.x.bam,
39668  */
39669   __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39670   __Pyx_GOTREF(__pyx_k_tuple_77);
39671   __Pyx_INCREF(((PyObject *)__pyx_kp_s_76));
39672   PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, ((PyObject *)__pyx_kp_s_76));
39673   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76));
39674   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77));
39675
39676   /* "csamtools.pyx":1047
39677  *             if not region:
39678  *                 raise ValueError( "counting functionality requires a region/reference" )
39679  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
39680  *             bam_fetch(self.samfile.x.bam,
39681  *                              self.index,
39682  */
39683   __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39684   __Pyx_GOTREF(__pyx_k_tuple_78);
39685   __Pyx_INCREF(((PyObject *)__pyx_kp_s_60));
39686   PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, ((PyObject *)__pyx_kp_s_60));
39687   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60));
39688   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78));
39689
39690   /* "csamtools.pyx":1057
39691  *             return counter
39692  *         else:
39693  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
39694  * 
39695  *     def pileup( self,
39696  */
39697   __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39698   __Pyx_GOTREF(__pyx_k_tuple_80);
39699   __Pyx_INCREF(((PyObject *)__pyx_kp_s_79));
39700   PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, ((PyObject *)__pyx_kp_s_79));
39701   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_79));
39702   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80));
39703
39704   /* "csamtools.pyx":1116
39705  * 
39706  *         if not self._isOpen():
39707  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39708  * 
39709  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
39710  */
39711   __pyx_k_tuple_81 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39712   __Pyx_GOTREF(__pyx_k_tuple_81);
39713   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39714   PyTuple_SET_ITEM(__pyx_k_tuple_81, 0, ((PyObject *)__pyx_kp_s_10));
39715   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39716   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_81));
39717
39718   /* "csamtools.pyx":1121
39719  * 
39720  *         if self.isbam:
39721  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
39722  * 
39723  *             if callback:
39724  */
39725   __pyx_k_tuple_83 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39726   __Pyx_GOTREF(__pyx_k_tuple_83);
39727   __Pyx_INCREF(((PyObject *)__pyx_kp_s_82));
39728   PyTuple_SET_ITEM(__pyx_k_tuple_83, 0, ((PyObject *)__pyx_kp_s_82));
39729   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_82));
39730   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_83));
39731
39732   /* "csamtools.pyx":1124
39733  * 
39734  *             if callback:
39735  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
39736  * 
39737  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
39738  */
39739   __pyx_k_tuple_84 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39740   __Pyx_GOTREF(__pyx_k_tuple_84);
39741   __Pyx_INCREF(((PyObject *)__pyx_kp_s_58));
39742   PyTuple_SET_ITEM(__pyx_k_tuple_84, 0, ((PyObject *)__pyx_kp_s_58));
39743   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_58));
39744   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_84));
39745
39746   /* "csamtools.pyx":1145
39747  * 
39748  *         else:
39749  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
39750  * 
39751  *     def close( self ):
39752  */
39753   __pyx_k_tuple_86 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39754   __Pyx_GOTREF(__pyx_k_tuple_86);
39755   __Pyx_INCREF(((PyObject *)__pyx_kp_s_85));
39756   PyTuple_SET_ITEM(__pyx_k_tuple_86, 0, ((PyObject *)__pyx_kp_s_85));
39757   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85));
39758   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_86));
39759
39760   /* "csamtools.pyx":1189
39761  *         '''number of :term:`filename` associated with this object.'''
39762  *         def __get__(self):
39763  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39764  *             return self._filename
39765  * 
39766  */
39767   __pyx_k_tuple_87 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39768   __Pyx_GOTREF(__pyx_k_tuple_87);
39769   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39770   PyTuple_SET_ITEM(__pyx_k_tuple_87, 0, ((PyObject *)__pyx_kp_s_10));
39771   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39772   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_87));
39773
39774   /* "csamtools.pyx":1195
39775  *         '''number of :term:`reference` sequences in the file.'''
39776  *         def __get__(self):
39777  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39778  *             return self.samfile.header.n_targets
39779  * 
39780  */
39781   __pyx_k_tuple_88 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39782   __Pyx_GOTREF(__pyx_k_tuple_88);
39783   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39784   PyTuple_SET_ITEM(__pyx_k_tuple_88, 0, ((PyObject *)__pyx_kp_s_10));
39785   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39786   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_88));
39787
39788   /* "csamtools.pyx":1201
39789  *         """tuple with the names of :term:`reference` sequences."""
39790  *         def __get__(self):
39791  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39792  *             t = []
39793  *             for x from 0 <= x < self.samfile.header.n_targets:
39794  */
39795   __pyx_k_tuple_89 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39796   __Pyx_GOTREF(__pyx_k_tuple_89);
39797   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39798   PyTuple_SET_ITEM(__pyx_k_tuple_89, 0, ((PyObject *)__pyx_kp_s_10));
39799   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39800   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_89));
39801
39802   /* "csamtools.pyx":1212
39803  *         """
39804  *         def __get__(self):
39805  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39806  *             t = []
39807  *             for x from 0 <= x < self.samfile.header.n_targets:
39808  */
39809   __pyx_k_tuple_90 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39810   __Pyx_GOTREF(__pyx_k_tuple_90);
39811   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39812   PyTuple_SET_ITEM(__pyx_k_tuple_90, 0, ((PyObject *)__pyx_kp_s_10));
39813   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39814   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_90));
39815
39816   /* "csamtools.pyx":1222
39817  *         """
39818  *         def __get__(self):
39819  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39820  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
39821  * 
39822  */
39823   __pyx_k_tuple_91 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39824   __Pyx_GOTREF(__pyx_k_tuple_91);
39825   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39826   PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_kp_s_10));
39827   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39828   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91));
39829
39830   /* "csamtools.pyx":1223
39831  *         def __get__(self):
39832  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
39833  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
39834  * 
39835  *             cdef int tid
39836  */
39837   __pyx_k_tuple_93 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_93)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39838   __Pyx_GOTREF(__pyx_k_tuple_93);
39839   __Pyx_INCREF(((PyObject *)__pyx_kp_s_92));
39840   PyTuple_SET_ITEM(__pyx_k_tuple_93, 0, ((PyObject *)__pyx_kp_s_92));
39841   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92));
39842   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_93));
39843
39844   /* "csamtools.pyx":1235
39845  *         """
39846  *         def __get__(self):
39847  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39848  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
39849  *             cdef int tid
39850  */
39851   __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39852   __Pyx_GOTREF(__pyx_k_tuple_94);
39853   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39854   PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_10));
39855   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39856   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94));
39857
39858   /* "csamtools.pyx":1236
39859  *         def __get__(self):
39860  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
39861  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
39862  *             cdef int tid
39863  *             cdef uint32_t total = 0
39864  */
39865   __pyx_k_tuple_96 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39866   __Pyx_GOTREF(__pyx_k_tuple_96);
39867   __Pyx_INCREF(((PyObject *)__pyx_kp_s_95));
39868   PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, ((PyObject *)__pyx_kp_s_95));
39869   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_95));
39870   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96));
39871
39872   /* "csamtools.pyx":1248
39873  *         '''full contents of the :term:`sam file` header as a string.'''
39874  *         def __get__(self):
39875  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39876  *             return from_string_and_size(self.samfile.header.text, self.samfile.header.l_text)
39877  * 
39878  */
39879   __pyx_k_tuple_97 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39880   __Pyx_GOTREF(__pyx_k_tuple_97);
39881   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39882   PyTuple_SET_ITEM(__pyx_k_tuple_97, 0, ((PyObject *)__pyx_kp_s_10));
39883   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39884   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_97));
39885
39886   /* "csamtools.pyx":1256
39887  *         '''
39888  *         def __get__(self):
39889  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39890  * 
39891  *             result = {}
39892  */
39893   __pyx_k_tuple_98 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39894   __Pyx_GOTREF(__pyx_k_tuple_98);
39895   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39896   PyTuple_SET_ITEM(__pyx_k_tuple_98, 0, ((PyObject *)__pyx_kp_s_10));
39897   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39898   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_98));
39899
39900   /* "csamtools.pyx":1263
39901  *                 # convert to python string (note: call self.text to create 0-terminated string)
39902  *                 t = self.text
39903  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
39904  *                     if not line.strip(): continue
39905  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
39906  */
39907   __pyx_k_tuple_99 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39908   __Pyx_GOTREF(__pyx_k_tuple_99);
39909   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
39910   PyTuple_SET_ITEM(__pyx_k_tuple_99, 0, ((PyObject *)__pyx_kp_s_6));
39911   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
39912   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_99));
39913
39914   /* "csamtools.pyx":1265
39915  *                 for line in t.split("\n"):
39916  *                     if not line.strip(): continue
39917  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
39918  *                     fields = line[1:].split("\t")
39919  *                     record = fields[0]
39920  */
39921   __pyx_k_tuple_101 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_101)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39922   __Pyx_GOTREF(__pyx_k_tuple_101);
39923   __Pyx_INCREF(((PyObject *)__pyx_kp_s_100));
39924   PyTuple_SET_ITEM(__pyx_k_tuple_101, 0, ((PyObject *)__pyx_kp_s_100));
39925   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_100));
39926   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_101));
39927
39928   /* "csamtools.pyx":1266
39929  *                     if not line.strip(): continue
39930  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
39931  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
39932  *                     record = fields[0]
39933  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
39934  */
39935   __pyx_k_tuple_103 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_103)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39936   __Pyx_GOTREF(__pyx_k_tuple_103);
39937   __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
39938   PyTuple_SET_ITEM(__pyx_k_tuple_103, 0, ((PyObject *)__pyx_kp_s_5));
39939   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5));
39940   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_103));
39941
39942   /* "csamtools.pyx":1279
39943  *                     x = {}
39944  *                     for field in fields[1:]:
39945  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
39946  *                         # uppercase keys must be valid
39947  *                         # lowercase are permitted for user fields
39948  */
39949   __pyx_k_tuple_106 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39950   __Pyx_GOTREF(__pyx_k_tuple_106);
39951   __Pyx_INCREF(((PyObject *)__pyx_kp_s_105));
39952   PyTuple_SET_ITEM(__pyx_k_tuple_106, 0, ((PyObject *)__pyx_kp_s_105));
39953   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_105));
39954   __Pyx_INCREF(__pyx_int_1);
39955   PyTuple_SET_ITEM(__pyx_k_tuple_106, 1, __pyx_int_1);
39956   __Pyx_GIVEREF(__pyx_int_1);
39957   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_106));
39958
39959   /* "csamtools.pyx":1377
39960  *         dest.text = <char*>calloc( len(text), sizeof(char))
39961  *         dest.l_text = len(text)
39962  *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
39963  *         strncpy( dest.text, btext, dest.l_text )
39964  * 
39965  */
39966   __pyx_k_tuple_112 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_112)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39967   __Pyx_GOTREF(__pyx_k_tuple_112);
39968   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39969   PyTuple_SET_ITEM(__pyx_k_tuple_112, 0, ((PyObject *)__pyx_n_s__ascii));
39970   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39971   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_112));
39972
39973   /* "csamtools.pyx":1397
39974  *                 seqname, seqlen = seqs[x]
39975  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
39976  *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
39977  *                 strncpy( dest.target_name[x], bseqname, len(seqname) + 1 )
39978  *                 dest.target_len[x] = seqlen
39979  */
39980   __pyx_k_tuple_114 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_114)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39981   __Pyx_GOTREF(__pyx_k_tuple_114);
39982   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
39983   PyTuple_SET_ITEM(__pyx_k_tuple_114, 0, ((PyObject *)__pyx_n_s__ascii));
39984   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
39985   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_114));
39986
39987   /* "csamtools.pyx":1412
39988  *     ###############################################################
39989  *     def __iter__(self):
39990  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
39991  *         if not self.isbam and self.samfile.header.n_targets == 0:
39992  *                 raise NotImplementedError( "can not iterate over samfile without header")
39993  */
39994   __pyx_k_tuple_115 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_115)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
39995   __Pyx_GOTREF(__pyx_k_tuple_115);
39996   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
39997   PyTuple_SET_ITEM(__pyx_k_tuple_115, 0, ((PyObject *)__pyx_kp_s_10));
39998   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
39999   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_115));
40000
40001   /* "csamtools.pyx":1414
40002  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
40003  *         if not self.isbam and self.samfile.header.n_targets == 0:
40004  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
40005  *         return self
40006  * 
40007  */
40008   __pyx_k_tuple_117 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40009   __Pyx_GOTREF(__pyx_k_tuple_117);
40010   __Pyx_INCREF(((PyObject *)__pyx_kp_s_116));
40011   PyTuple_SET_ITEM(__pyx_k_tuple_117, 0, ((PyObject *)__pyx_kp_s_116));
40012   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_116));
40013   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_117));
40014
40015   /* "csamtools.pyx":1484
40016  * 
40017  *         if not samfile._isOpen():
40018  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
40019  * 
40020  *         if not samfile._hasIndex():
40021  */
40022   __pyx_k_tuple_118 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40023   __Pyx_GOTREF(__pyx_k_tuple_118);
40024   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
40025   PyTuple_SET_ITEM(__pyx_k_tuple_118, 0, ((PyObject *)__pyx_kp_s_10));
40026   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
40027   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));
40028
40029   /* "csamtools.pyx":1487
40030  * 
40031  *         if not samfile._hasIndex():
40032  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
40033  * 
40034  *         # makes sure that samfile stays alive as long as the
40035  */
40036   __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40037   __Pyx_GOTREF(__pyx_k_tuple_120);
40038   __Pyx_INCREF(((PyObject *)__pyx_kp_s_119));
40039   PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_119));
40040   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_119));
40041   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120));
40042
40043   /* "csamtools.pyx":1553
40044  * 
40045  *         if not samfile._isOpen():
40046  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
40047  * 
40048  *         if samfile.isbam: mode = b"rb"
40049  */
40050   __pyx_k_tuple_121 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_121)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40051   __Pyx_GOTREF(__pyx_k_tuple_121);
40052   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
40053   PyTuple_SET_ITEM(__pyx_k_tuple_121, 0, ((PyObject *)__pyx_kp_s_10));
40054   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
40055   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_121));
40056
40057   /* "csamtools.pyx":1604
40058  *     def __cinit__(self, Samfile samfile):
40059  *         assert samfile._isOpen()
40060  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
40061  *         self.samfile = samfile
40062  *         self.tid = -1
40063  */
40064   __pyx_k_tuple_122 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_122)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1604; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40065   __Pyx_GOTREF(__pyx_k_tuple_122);
40066   __Pyx_INCREF(((PyObject *)__pyx_kp_s_60));
40067   PyTuple_SET_ITEM(__pyx_k_tuple_122, 0, ((PyObject *)__pyx_kp_s_60));
40068   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60));
40069   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_122));
40070
40071   /* "csamtools.pyx":1650
40072  * 
40073  *         if not samfile._isOpen():
40074  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
40075  * 
40076  *         if not samfile._isOpen():
40077  */
40078   __pyx_k_tuple_123 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40079   __Pyx_GOTREF(__pyx_k_tuple_123);
40080   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
40081   PyTuple_SET_ITEM(__pyx_k_tuple_123, 0, ((PyObject *)__pyx_kp_s_10));
40082   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
40083   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_123));
40084
40085   /* "csamtools.pyx":1653
40086  * 
40087  *         if not samfile._isOpen():
40088  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
40089  * 
40090  *         assert samfile.isbam, "can only use this iterator on bam files"
40091  */
40092   __pyx_k_tuple_124 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40093   __Pyx_GOTREF(__pyx_k_tuple_124);
40094   __Pyx_INCREF(((PyObject *)__pyx_kp_s_10));
40095   PyTuple_SET_ITEM(__pyx_k_tuple_124, 0, ((PyObject *)__pyx_kp_s_10));
40096   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_10));
40097   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_124));
40098
40099   /* "csamtools.pyx":1954
40100  *             self.cnext()
40101  *             if self.n_plp < 0:
40102  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
40103  * 
40104  *             if self.plp == NULL:
40105  */
40106   __pyx_k_tuple_130 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_130)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40107   __Pyx_GOTREF(__pyx_k_tuple_130);
40108   __Pyx_INCREF(((PyObject *)__pyx_kp_s_129));
40109   PyTuple_SET_ITEM(__pyx_k_tuple_130, 0, ((PyObject *)__pyx_kp_s_129));
40110   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_129));
40111   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_130));
40112
40113   /* "csamtools.pyx":1990
40114  * 
40115  *             if self.n_plp < 0:
40116  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
40117  * 
40118  *             # return result, if within same reference
40119  */
40120   __pyx_k_tuple_131 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_131)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40121   __Pyx_GOTREF(__pyx_k_tuple_131);
40122   __Pyx_INCREF(((PyObject *)__pyx_kp_s_129));
40123   PyTuple_SET_ITEM(__pyx_k_tuple_131, 0, ((PyObject *)__pyx_kp_s_129));
40124   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_129));
40125   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_131));
40126
40127   /* "csamtools.pyx":2153
40128  *             qual = self.qual
40129  *         else:
40130  *             seq = self.seq.decode('ascii')             # <<<<<<<<<<<<<<
40131  *             qual = self.qual.decode('ascii')
40132  *         return "\t".join(map(str, (self.qname,
40133  */
40134   __pyx_k_tuple_133 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40135   __Pyx_GOTREF(__pyx_k_tuple_133);
40136   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40137   PyTuple_SET_ITEM(__pyx_k_tuple_133, 0, ((PyObject *)__pyx_n_s__ascii));
40138   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40139   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_133));
40140
40141   /* "csamtools.pyx":2154
40142  *         else:
40143  *             seq = self.seq.decode('ascii')
40144  *             qual = self.qual.decode('ascii')             # <<<<<<<<<<<<<<
40145  *         return "\t".join(map(str, (self.qname,
40146  *                                    self.flag,
40147  */
40148   __pyx_k_tuple_134 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40149   __Pyx_GOTREF(__pyx_k_tuple_134);
40150   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40151   PyTuple_SET_ITEM(__pyx_k_tuple_134, 0, ((PyObject *)__pyx_n_s__ascii));
40152   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40153   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
40154
40155   /* "csamtools.pyx":2563
40156  *                 for pytag, value in tags:
40157  *                     if not type(pytag) is bytes:
40158  *                         pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
40159  *                     t = type(value)
40160  * 
40161  */
40162   __pyx_k_tuple_139 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_139)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40163   __Pyx_GOTREF(__pyx_k_tuple_139);
40164   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40165   PyTuple_SET_ITEM(__pyx_k_tuple_139, 0, ((PyObject *)__pyx_n_s__ascii));
40166   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40167   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_139));
40168
40169   /* "csamtools.pyx":2591
40170  *                         datafmt = "2sccI%i%s" % (len(value), datafmt)
40171  *                         args.extend( [pytag[:2],
40172  *                                       pytype.encode('ascii'),             # <<<<<<<<<<<<<<
40173  *                                       datatype.encode('ascii'),
40174  *                                       len(value)] + list(value) )
40175  */
40176   __pyx_k_tuple_142 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40177   __Pyx_GOTREF(__pyx_k_tuple_142);
40178   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40179   PyTuple_SET_ITEM(__pyx_k_tuple_142, 0, ((PyObject *)__pyx_n_s__ascii));
40180   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40181   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142));
40182
40183   /* "csamtools.pyx":2592
40184  *                         args.extend( [pytag[:2],
40185  *                                       pytype.encode('ascii'),
40186  *                                       datatype.encode('ascii'),             # <<<<<<<<<<<<<<
40187  *                                       len(value)] + list(value) )
40188  *                         fmts.append( datafmt )
40189  */
40190   __pyx_k_tuple_143 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40191   __Pyx_GOTREF(__pyx_k_tuple_143);
40192   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40193   PyTuple_SET_ITEM(__pyx_k_tuple_143, 0, ((PyObject *)__pyx_n_s__ascii));
40194   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40195   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_143));
40196
40197   /* "csamtools.pyx":2615
40198  *                         # Note: hex strings (H) are not supported yet
40199  *                         if t is not bytes:
40200  *                             value = value.encode('ascii')             # <<<<<<<<<<<<<<
40201  *                         if len(value) == 1:
40202  *                             fmt, pytype = "2scc", 'A'
40203  */
40204   __pyx_k_tuple_144 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_144)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40205   __Pyx_GOTREF(__pyx_k_tuple_144);
40206   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40207   PyTuple_SET_ITEM(__pyx_k_tuple_144, 0, ((PyObject *)__pyx_n_s__ascii));
40208   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40209   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_144));
40210
40211   /* "csamtools.pyx":2622
40212  * 
40213  *                     args.extend( [pytag[:2],
40214  *                                   pytype.encode('ascii'),             # <<<<<<<<<<<<<<
40215  *                                   value ] )
40216  * 
40217  */
40218   __pyx_k_tuple_146 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2622; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40219   __Pyx_GOTREF(__pyx_k_tuple_146);
40220   __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
40221   PyTuple_SET_ITEM(__pyx_k_tuple_146, 0, ((PyObject *)__pyx_n_s__ascii));
40222   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
40223   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_146));
40224
40225   /* "csamtools.pyx":3020
40226  *     '''
40227  *     def __init__(self):
40228  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
40229  * 
40230  *     def __str__(self):
40231  */
40232   __pyx_k_tuple_172 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_172)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40233   __Pyx_GOTREF(__pyx_k_tuple_172);
40234   __Pyx_INCREF(((PyObject *)__pyx_kp_s_171));
40235   PyTuple_SET_ITEM(__pyx_k_tuple_172, 0, ((PyObject *)__pyx_kp_s_171));
40236   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_171));
40237   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_172));
40238
40239   /* "csamtools.pyx":3046
40240  * 
40241  *             if self.plp[0] == NULL:
40242  *                 raise ValueError("PileupProxy accessed after iterator finished")             # <<<<<<<<<<<<<<
40243  * 
40244  *             # warning: there could be problems if self.n and self.buf are
40245  */
40246   __pyx_k_tuple_174 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_174)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40247   __Pyx_GOTREF(__pyx_k_tuple_174);
40248   __Pyx_INCREF(((PyObject *)__pyx_kp_s_173));
40249   PyTuple_SET_ITEM(__pyx_k_tuple_174, 0, ((PyObject *)__pyx_kp_s_173));
40250   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_173));
40251   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_174));
40252
40253   /* "csamtools.pyx":3059
40254  * 
40255  *     def __init__(self):
40256  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
40257  * 
40258  *     def __str__(self):
40259  */
40260   __pyx_k_tuple_175 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_175)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40261   __Pyx_GOTREF(__pyx_k_tuple_175);
40262   __Pyx_INCREF(((PyObject *)__pyx_kp_s_171));
40263   PyTuple_SET_ITEM(__pyx_k_tuple_175, 0, ((PyObject *)__pyx_kp_s_171));
40264   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_171));
40265   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_175));
40266
40267   /* "csamtools.pyx":3172
40268  *         # recover. Thus redirect output to file with -o option.
40269  *         if method == "view":
40270  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
40271  *             args = ( "-o", stdout_f ) + args
40272  * 
40273  */
40274   __pyx_k_tuple_180 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_180)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40275   __Pyx_GOTREF(__pyx_k_tuple_180);
40276   __Pyx_INCREF(((PyObject *)__pyx_kp_s_179));
40277   PyTuple_SET_ITEM(__pyx_k_tuple_180, 0, ((PyObject *)__pyx_kp_s_179));
40278   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_179));
40279   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_180));
40280
40281   /* "csamtools.pyx":3197
40282  *         stdout_save.restore()
40283  *         try:
40284  *             with open( stdout_f, "r") as inf:             # <<<<<<<<<<<<<<
40285  *                 out_stdout = inf.readlines()
40286  *         except UnicodeDecodeError:
40287  */
40288   __pyx_k_tuple_181 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_181)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40289   __Pyx_GOTREF(__pyx_k_tuple_181);
40290   __Pyx_INCREF(Py_None);
40291   PyTuple_SET_ITEM(__pyx_k_tuple_181, 0, Py_None);
40292   __Pyx_GIVEREF(Py_None);
40293   __Pyx_INCREF(Py_None);
40294   PyTuple_SET_ITEM(__pyx_k_tuple_181, 1, Py_None);
40295   __Pyx_GIVEREF(Py_None);
40296   __Pyx_INCREF(Py_None);
40297   PyTuple_SET_ITEM(__pyx_k_tuple_181, 2, Py_None);
40298   __Pyx_GIVEREF(Py_None);
40299   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_181));
40300
40301   /* "csamtools.pyx":3200
40302  *                 out_stdout = inf.readlines()
40303  *         except UnicodeDecodeError:
40304  *             with open( stdout_f, "rb") as inf:             # <<<<<<<<<<<<<<
40305  *                 # read binary output
40306  *                 out_stdout = inf.read()
40307  */
40308   __pyx_k_tuple_182 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_182)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40309   __Pyx_GOTREF(__pyx_k_tuple_182);
40310   __Pyx_INCREF(Py_None);
40311   PyTuple_SET_ITEM(__pyx_k_tuple_182, 0, Py_None);
40312   __Pyx_GIVEREF(Py_None);
40313   __Pyx_INCREF(Py_None);
40314   PyTuple_SET_ITEM(__pyx_k_tuple_182, 1, Py_None);
40315   __Pyx_GIVEREF(Py_None);
40316   __Pyx_INCREF(Py_None);
40317   PyTuple_SET_ITEM(__pyx_k_tuple_182, 2, Py_None);
40318   __Pyx_GIVEREF(Py_None);
40319   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_182));
40320
40321   /* "csamtools.pyx":3210
40322  *     pysam_unset_stderr()
40323  *     try:
40324  *         with open( stderr_f, "r") as inf:             # <<<<<<<<<<<<<<
40325  *             out_stderr = inf.readlines()
40326  *     except UnicodeDecodeError:
40327  */
40328   __pyx_k_tuple_183 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_183)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40329   __Pyx_GOTREF(__pyx_k_tuple_183);
40330   __Pyx_INCREF(Py_None);
40331   PyTuple_SET_ITEM(__pyx_k_tuple_183, 0, Py_None);
40332   __Pyx_GIVEREF(Py_None);
40333   __Pyx_INCREF(Py_None);
40334   PyTuple_SET_ITEM(__pyx_k_tuple_183, 1, Py_None);
40335   __Pyx_GIVEREF(Py_None);
40336   __Pyx_INCREF(Py_None);
40337   PyTuple_SET_ITEM(__pyx_k_tuple_183, 2, Py_None);
40338   __Pyx_GIVEREF(Py_None);
40339   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_183));
40340
40341   /* "csamtools.pyx":3213
40342  *             out_stderr = inf.readlines()
40343  *     except UnicodeDecodeError:
40344  *         with open( stderr_f, "rb") as inf:             # <<<<<<<<<<<<<<
40345  *             # read binary output
40346  *             out_stderr = inf.read()
40347  */
40348   __pyx_k_tuple_184 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_184)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40349   __Pyx_GOTREF(__pyx_k_tuple_184);
40350   __Pyx_INCREF(Py_None);
40351   PyTuple_SET_ITEM(__pyx_k_tuple_184, 0, Py_None);
40352   __Pyx_GIVEREF(Py_None);
40353   __Pyx_INCREF(Py_None);
40354   PyTuple_SET_ITEM(__pyx_k_tuple_184, 1, Py_None);
40355   __Pyx_GIVEREF(Py_None);
40356   __Pyx_INCREF(Py_None);
40357   PyTuple_SET_ITEM(__pyx_k_tuple_184, 2, Py_None);
40358   __Pyx_GIVEREF(Py_None);
40359   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_184));
40360
40361   /* "csamtools.pyx":143
40362  * else:
40363  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
40364  * CIGAR_REGEX = re.compile( "([MIDNSHP=X])(\d+)" )             # <<<<<<<<<<<<<<
40365  * 
40366  * #####################################################################
40367  */
40368   __pyx_k_tuple_252 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_252)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40369   __Pyx_GOTREF(__pyx_k_tuple_252);
40370   __Pyx_INCREF(((PyObject *)__pyx_kp_s_251));
40371   PyTuple_SET_ITEM(__pyx_k_tuple_252, 0, ((PyObject *)__pyx_kp_s_251));
40372   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_251));
40373   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_252));
40374
40375   /* "csamtools.pyx":260
40376  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
40377  *     '''
40378  *     def __str__(self):             # <<<<<<<<<<<<<<
40379  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
40380  *             "\n" + "\n".join( map(str, self.pileups) )
40381  */
40382   __pyx_k_tuple_254 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_254)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40383   __Pyx_GOTREF(__pyx_k_tuple_254);
40384   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40385   PyTuple_SET_ITEM(__pyx_k_tuple_254, 0, ((PyObject *)__pyx_n_s__self));
40386   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40387   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_254));
40388   __pyx_k_codeobj_255 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_254, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s____str__, 260, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_255)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40389
40390   /* "csamtools.pyx":308
40391  *     stderr is captured.
40392  *     '''
40393  *     def __init__(self):             # <<<<<<<<<<<<<<
40394  *         return
40395  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
40396  */
40397   __pyx_k_tuple_258 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_258)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40398   __Pyx_GOTREF(__pyx_k_tuple_258);
40399   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40400   PyTuple_SET_ITEM(__pyx_k_tuple_258, 0, ((PyObject *)__pyx_n_s__self));
40401   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40402   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_258));
40403   __pyx_k_codeobj_259 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_258, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s____init__, 308, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_259)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40404
40405   /* "csamtools.pyx":314
40406  *         self.stderr_save.setfd( self.stderr_h )
40407  * 
40408  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
40409  *         return []
40410  *         self.stderr_save.restore()
40411  */
40412   __pyx_k_tuple_260 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_260)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40413   __Pyx_GOTREF(__pyx_k_tuple_260);
40414   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40415   PyTuple_SET_ITEM(__pyx_k_tuple_260, 0, ((PyObject *)__pyx_n_s__self));
40416   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40417   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_260));
40418   __pyx_k_codeobj_261 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_260, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__readAndRelease, 314, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_261)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40419
40420   /* "csamtools.pyx":323
40421  *         return lines
40422  * 
40423  *     def release(self):             # <<<<<<<<<<<<<<
40424  *         return
40425  *         self.stderr_save.restore()
40426  */
40427   __pyx_k_tuple_262 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_262)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40428   __Pyx_GOTREF(__pyx_k_tuple_262);
40429   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40430   PyTuple_SET_ITEM(__pyx_k_tuple_262, 0, ((PyObject *)__pyx_n_s__self));
40431   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40432   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_262));
40433   __pyx_k_codeobj_263 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_262, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__release, 323, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_263)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40434
40435   /* "csamtools.pyx":329
40436  *             os.remove( self.stderr_f )
40437  * 
40438  *     def __del__(self):             # <<<<<<<<<<<<<<
40439  *         self.release()
40440  * 
40441  */
40442   __pyx_k_tuple_264 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_264)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40443   __Pyx_GOTREF(__pyx_k_tuple_264);
40444   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40445   PyTuple_SET_ITEM(__pyx_k_tuple_264, 0, ((PyObject *)__pyx_n_s__self));
40446   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40447   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_264));
40448   __pyx_k_codeobj_265 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_264, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s____del__, 329, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_265)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40449
40450   /* "csamtools.pyx":334
40451  * class StderrStoreWindows():
40452  *     '''does nothing. stderr can't be redirected on windows'''
40453  *     def __init__(self): pass             # <<<<<<<<<<<<<<
40454  *     def readAndRelease(self): return []
40455  *     def release(self): pass
40456  */
40457   __pyx_k_tuple_267 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_267)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40458   __Pyx_GOTREF(__pyx_k_tuple_267);
40459   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40460   PyTuple_SET_ITEM(__pyx_k_tuple_267, 0, ((PyObject *)__pyx_n_s__self));
40461   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40462   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_267));
40463   __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_256, __pyx_n_s____init__, 334, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_268)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40464
40465   /* "csamtools.pyx":335
40466  *     '''does nothing. stderr can't be redirected on windows'''
40467  *     def __init__(self): pass
40468  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
40469  *     def release(self): pass
40470  * 
40471  */
40472   __pyx_k_tuple_269 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_269)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40473   __Pyx_GOTREF(__pyx_k_tuple_269);
40474   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40475   PyTuple_SET_ITEM(__pyx_k_tuple_269, 0, ((PyObject *)__pyx_n_s__self));
40476   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40477   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_269));
40478   __pyx_k_codeobj_270 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_269, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__readAndRelease, 335, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_270)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40479
40480   /* "csamtools.pyx":336
40481  *     def __init__(self): pass
40482  *     def readAndRelease(self): return []
40483  *     def release(self): pass             # <<<<<<<<<<<<<<
40484  * 
40485  * if platform.system()=='Windows':
40486  */
40487   __pyx_k_tuple_271 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_271)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40488   __Pyx_GOTREF(__pyx_k_tuple_271);
40489   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40490   PyTuple_SET_ITEM(__pyx_k_tuple_271, 0, ((PyObject *)__pyx_n_s__self));
40491   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40492   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_271));
40493   __pyx_k_codeobj_272 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_271, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__release, 336, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_272)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40494
40495   /* "csamtools.pyx":354
40496  * 
40497  * # order of records within sam headers
40498  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
40499  * 
40500  * # type conversions within sam header records
40501  */
40502   __pyx_k_tuple_274 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_274)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40503   __Pyx_GOTREF(__pyx_k_tuple_274);
40504   __Pyx_INCREF(((PyObject *)__pyx_n_s__HD));
40505   PyTuple_SET_ITEM(__pyx_k_tuple_274, 0, ((PyObject *)__pyx_n_s__HD));
40506   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__HD));
40507   __Pyx_INCREF(((PyObject *)__pyx_n_s__SQ));
40508   PyTuple_SET_ITEM(__pyx_k_tuple_274, 1, ((PyObject *)__pyx_n_s__SQ));
40509   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SQ));
40510   __Pyx_INCREF(((PyObject *)__pyx_n_s__RG));
40511   PyTuple_SET_ITEM(__pyx_k_tuple_274, 2, ((PyObject *)__pyx_n_s__RG));
40512   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__RG));
40513   __Pyx_INCREF(((PyObject *)__pyx_n_s__PG));
40514   PyTuple_SET_ITEM(__pyx_k_tuple_274, 3, ((PyObject *)__pyx_n_s__PG));
40515   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PG));
40516   __Pyx_INCREF(((PyObject *)__pyx_n_s__CO));
40517   PyTuple_SET_ITEM(__pyx_k_tuple_274, 4, ((PyObject *)__pyx_n_s__CO));
40518   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CO));
40519   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_274));
40520
40521   /* "csamtools.pyx":364
40522  * 
40523  * # output order of fields within records
40524  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
40525  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
40526  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
40527  */
40528   __pyx_k_tuple_275 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_275)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40529   __Pyx_GOTREF(__pyx_k_tuple_275);
40530   __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
40531   PyTuple_SET_ITEM(__pyx_k_tuple_275, 0, ((PyObject *)__pyx_n_s__VN));
40532   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
40533   __Pyx_INCREF(((PyObject *)__pyx_n_s__SO));
40534   PyTuple_SET_ITEM(__pyx_k_tuple_275, 1, ((PyObject *)__pyx_n_s__SO));
40535   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SO));
40536   __Pyx_INCREF(((PyObject *)__pyx_n_s__GO));
40537   PyTuple_SET_ITEM(__pyx_k_tuple_275, 2, ((PyObject *)__pyx_n_s__GO));
40538   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__GO));
40539   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_275));
40540
40541   /* "csamtools.pyx":365
40542  * # output order of fields within records
40543  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
40544  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
40545  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
40546  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
40547  */
40548   __pyx_k_tuple_276 = PyTuple_New(6); if (unlikely(!__pyx_k_tuple_276)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40549   __Pyx_GOTREF(__pyx_k_tuple_276);
40550   __Pyx_INCREF(((PyObject *)__pyx_n_s__SN));
40551   PyTuple_SET_ITEM(__pyx_k_tuple_276, 0, ((PyObject *)__pyx_n_s__SN));
40552   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SN));
40553   __Pyx_INCREF(((PyObject *)__pyx_n_s__LN));
40554   PyTuple_SET_ITEM(__pyx_k_tuple_276, 1, ((PyObject *)__pyx_n_s__LN));
40555   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LN));
40556   __Pyx_INCREF(((PyObject *)__pyx_n_s__AS));
40557   PyTuple_SET_ITEM(__pyx_k_tuple_276, 2, ((PyObject *)__pyx_n_s__AS));
40558   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AS));
40559   __Pyx_INCREF(((PyObject *)__pyx_n_s__M5));
40560   PyTuple_SET_ITEM(__pyx_k_tuple_276, 3, ((PyObject *)__pyx_n_s__M5));
40561   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__M5));
40562   __Pyx_INCREF(((PyObject *)__pyx_n_s__UR));
40563   PyTuple_SET_ITEM(__pyx_k_tuple_276, 4, ((PyObject *)__pyx_n_s__UR));
40564   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__UR));
40565   __Pyx_INCREF(((PyObject *)__pyx_n_s__SP));
40566   PyTuple_SET_ITEM(__pyx_k_tuple_276, 5, ((PyObject *)__pyx_n_s__SP));
40567   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SP));
40568   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_276));
40569
40570   /* "csamtools.pyx":366
40571  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
40572  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
40573  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),             # <<<<<<<<<<<<<<
40574  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
40575  * 
40576  */
40577   __pyx_k_tuple_277 = PyTuple_New(11); if (unlikely(!__pyx_k_tuple_277)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40578   __Pyx_GOTREF(__pyx_k_tuple_277);
40579   __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
40580   PyTuple_SET_ITEM(__pyx_k_tuple_277, 0, ((PyObject *)__pyx_n_s__ID));
40581   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
40582   __Pyx_INCREF(((PyObject *)__pyx_n_s__SM));
40583   PyTuple_SET_ITEM(__pyx_k_tuple_277, 1, ((PyObject *)__pyx_n_s__SM));
40584   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SM));
40585   __Pyx_INCREF(((PyObject *)__pyx_n_s__LB));
40586   PyTuple_SET_ITEM(__pyx_k_tuple_277, 2, ((PyObject *)__pyx_n_s__LB));
40587   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LB));
40588   __Pyx_INCREF(((PyObject *)__pyx_n_s__DS));
40589   PyTuple_SET_ITEM(__pyx_k_tuple_277, 3, ((PyObject *)__pyx_n_s__DS));
40590   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DS));
40591   __Pyx_INCREF(((PyObject *)__pyx_n_s__PU));
40592   PyTuple_SET_ITEM(__pyx_k_tuple_277, 4, ((PyObject *)__pyx_n_s__PU));
40593   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PU));
40594   __Pyx_INCREF(((PyObject *)__pyx_n_s__PI));
40595   PyTuple_SET_ITEM(__pyx_k_tuple_277, 5, ((PyObject *)__pyx_n_s__PI));
40596   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PI));
40597   __Pyx_INCREF(((PyObject *)__pyx_n_s__CN));
40598   PyTuple_SET_ITEM(__pyx_k_tuple_277, 6, ((PyObject *)__pyx_n_s__CN));
40599   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CN));
40600   __Pyx_INCREF(((PyObject *)__pyx_n_s__DT));
40601   PyTuple_SET_ITEM(__pyx_k_tuple_277, 7, ((PyObject *)__pyx_n_s__DT));
40602   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DT));
40603   __Pyx_INCREF(((PyObject *)__pyx_n_s__PL));
40604   PyTuple_SET_ITEM(__pyx_k_tuple_277, 8, ((PyObject *)__pyx_n_s__PL));
40605   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PL));
40606   __Pyx_INCREF(((PyObject *)__pyx_n_s__FO));
40607   PyTuple_SET_ITEM(__pyx_k_tuple_277, 9, ((PyObject *)__pyx_n_s__FO));
40608   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__FO));
40609   __Pyx_INCREF(((PyObject *)__pyx_n_s__KS));
40610   PyTuple_SET_ITEM(__pyx_k_tuple_277, 10, ((PyObject *)__pyx_n_s__KS));
40611   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__KS));
40612   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_277));
40613
40614   /* "csamtools.pyx":367
40615  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
40616  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
40617  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }             # <<<<<<<<<<<<<<
40618  * 
40619  * 
40620  */
40621   __pyx_k_tuple_278 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_278)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40622   __Pyx_GOTREF(__pyx_k_tuple_278);
40623   __Pyx_INCREF(((PyObject *)__pyx_n_s__PN));
40624   PyTuple_SET_ITEM(__pyx_k_tuple_278, 0, ((PyObject *)__pyx_n_s__PN));
40625   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PN));
40626   __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
40627   PyTuple_SET_ITEM(__pyx_k_tuple_278, 1, ((PyObject *)__pyx_n_s__ID));
40628   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
40629   __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
40630   PyTuple_SET_ITEM(__pyx_k_tuple_278, 2, ((PyObject *)__pyx_n_s__VN));
40631   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
40632   __Pyx_INCREF(((PyObject *)__pyx_n_s__CL));
40633   PyTuple_SET_ITEM(__pyx_k_tuple_278, 3, ((PyObject *)__pyx_n_s__CL));
40634   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CL));
40635   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_278));
40636
40637   /* "csamtools.pyx":3092
40638  * class Outs:
40639  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
40640  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
40641  *         self.streams = []
40642  *         self.id = id
40643  */
40644   __pyx_k_tuple_279 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_279)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40645   __Pyx_GOTREF(__pyx_k_tuple_279);
40646   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40647   PyTuple_SET_ITEM(__pyx_k_tuple_279, 0, ((PyObject *)__pyx_n_s__self));
40648   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40649   __Pyx_INCREF(((PyObject *)__pyx_n_s__id));
40650   PyTuple_SET_ITEM(__pyx_k_tuple_279, 1, ((PyObject *)__pyx_n_s__id));
40651   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__id));
40652   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_279));
40653   __pyx_k_codeobj_280 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_279, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s____init__, 3092, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_280)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40654   __pyx_k_tuple_281 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_281)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40655   __Pyx_GOTREF(__pyx_k_tuple_281);
40656   __Pyx_INCREF(((PyObject *)__pyx_int_1));
40657   PyTuple_SET_ITEM(__pyx_k_tuple_281, 0, ((PyObject *)__pyx_int_1));
40658   __Pyx_GIVEREF(((PyObject *)__pyx_int_1));
40659   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_281));
40660
40661   /* "csamtools.pyx":3096
40662  *         self.id = id
40663  * 
40664  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
40665  *         '''open an existing file, like "/dev/null"'''
40666  *         fd = os.open(filename, os.O_WRONLY)
40667  */
40668   __pyx_k_tuple_282 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_282)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40669   __Pyx_GOTREF(__pyx_k_tuple_282);
40670   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40671   PyTuple_SET_ITEM(__pyx_k_tuple_282, 0, ((PyObject *)__pyx_n_s__self));
40672   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40673   __Pyx_INCREF(((PyObject *)__pyx_n_s__filename));
40674   PyTuple_SET_ITEM(__pyx_k_tuple_282, 1, ((PyObject *)__pyx_n_s__filename));
40675   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename));
40676   __Pyx_INCREF(((PyObject *)__pyx_n_s__fd));
40677   PyTuple_SET_ITEM(__pyx_k_tuple_282, 2, ((PyObject *)__pyx_n_s__fd));
40678   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fd));
40679   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_282));
40680   __pyx_k_codeobj_283 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_282, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__setdevice, 3096, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_283)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40681
40682   /* "csamtools.pyx":3101
40683  *         self.setfd(fd)
40684  * 
40685  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
40686  *         '''open a new file.'''
40687  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
40688  */
40689   __pyx_k_tuple_284 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_284)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40690   __Pyx_GOTREF(__pyx_k_tuple_284);
40691   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40692   PyTuple_SET_ITEM(__pyx_k_tuple_284, 0, ((PyObject *)__pyx_n_s__self));
40693   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40694   __Pyx_INCREF(((PyObject *)__pyx_n_s__filename));
40695   PyTuple_SET_ITEM(__pyx_k_tuple_284, 1, ((PyObject *)__pyx_n_s__filename));
40696   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename));
40697   __Pyx_INCREF(((PyObject *)__pyx_n_s__fd));
40698   PyTuple_SET_ITEM(__pyx_k_tuple_284, 2, ((PyObject *)__pyx_n_s__fd));
40699   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fd));
40700   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_284));
40701   __pyx_k_codeobj_285 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_284, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__setfile, 3101, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_285)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40702
40703   /* "csamtools.pyx":3106
40704  *         self.setfd(fd)
40705  * 
40706  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
40707  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
40708  *         self.streams.append(ofd)
40709  */
40710   __pyx_k_tuple_286 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_286)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40711   __Pyx_GOTREF(__pyx_k_tuple_286);
40712   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40713   PyTuple_SET_ITEM(__pyx_k_tuple_286, 0, ((PyObject *)__pyx_n_s__self));
40714   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40715   __Pyx_INCREF(((PyObject *)__pyx_n_s__fd));
40716   PyTuple_SET_ITEM(__pyx_k_tuple_286, 1, ((PyObject *)__pyx_n_s__fd));
40717   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fd));
40718   __Pyx_INCREF(((PyObject *)__pyx_n_s__ofd));
40719   PyTuple_SET_ITEM(__pyx_k_tuple_286, 2, ((PyObject *)__pyx_n_s__ofd));
40720   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ofd));
40721   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_286));
40722   __pyx_k_codeobj_287 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_286, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__setfd, 3106, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_287)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40723
40724   /* "csamtools.pyx":3114
40725  *         os.close(fd)                #  Close other unit (look out, caller.)
40726  * 
40727  *     def restore(self):             # <<<<<<<<<<<<<<
40728  *         '''restore previous output stream'''
40729  *         if self.streams:
40730  */
40731   __pyx_k_tuple_288 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_288)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40732   __Pyx_GOTREF(__pyx_k_tuple_288);
40733   __Pyx_INCREF(((PyObject *)__pyx_n_s__self));
40734   PyTuple_SET_ITEM(__pyx_k_tuple_288, 0, ((PyObject *)__pyx_n_s__self));
40735   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__self));
40736   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_288));
40737   __pyx_k_codeobj_289 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_288, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s__restore, 3114, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_289)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40738
40739   /* "csamtools.pyx":3125
40740  *             del self.streams[-1]
40741  * 
40742  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
40743  *                         args = (),
40744  *                         catch_stdout = True ):
40745  */
40746   __pyx_k_tuple_291 = PyTuple_New(16); if (unlikely(!__pyx_k_tuple_291)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40747   __Pyx_GOTREF(__pyx_k_tuple_291);
40748   __Pyx_INCREF(((PyObject *)__pyx_n_s__method));
40749   PyTuple_SET_ITEM(__pyx_k_tuple_291, 0, ((PyObject *)__pyx_n_s__method));
40750   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__method));
40751   __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
40752   PyTuple_SET_ITEM(__pyx_k_tuple_291, 1, ((PyObject *)__pyx_n_s__args));
40753   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
40754   __Pyx_INCREF(((PyObject *)__pyx_n_s__catch_stdout));
40755   PyTuple_SET_ITEM(__pyx_k_tuple_291, 2, ((PyObject *)__pyx_n_s__catch_stdout));
40756   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__catch_stdout));
40757   __Pyx_INCREF(((PyObject *)__pyx_n_s__stderr_h));
40758   PyTuple_SET_ITEM(__pyx_k_tuple_291, 3, ((PyObject *)__pyx_n_s__stderr_h));
40759   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stderr_h));
40760   __Pyx_INCREF(((PyObject *)__pyx_n_s__stderr_f));
40761   PyTuple_SET_ITEM(__pyx_k_tuple_291, 4, ((PyObject *)__pyx_n_s__stderr_f));
40762   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stderr_f));
40763   __Pyx_INCREF(((PyObject *)__pyx_n_s__stdout_h));
40764   PyTuple_SET_ITEM(__pyx_k_tuple_291, 5, ((PyObject *)__pyx_n_s__stdout_h));
40765   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stdout_h));
40766   __Pyx_INCREF(((PyObject *)__pyx_n_s__stdout_f));
40767   PyTuple_SET_ITEM(__pyx_k_tuple_291, 6, ((PyObject *)__pyx_n_s__stdout_f));
40768   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stdout_f));
40769   __Pyx_INCREF(((PyObject *)__pyx_n_s__stdout_save));
40770   PyTuple_SET_ITEM(__pyx_k_tuple_291, 7, ((PyObject *)__pyx_n_s__stdout_save));
40771   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__stdout_save));
40772   __Pyx_INCREF(((PyObject *)__pyx_n_s__cargs));
40773   PyTuple_SET_ITEM(__pyx_k_tuple_291, 8, ((PyObject *)__pyx_n_s__cargs));
40774   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cargs));
40775   __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
40776   PyTuple_SET_ITEM(__pyx_k_tuple_291, 9, ((PyObject *)__pyx_n_s__i));
40777   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
40778   __Pyx_INCREF(((PyObject *)__pyx_n_s__n));
40779   PyTuple_SET_ITEM(__pyx_k_tuple_291, 10, ((PyObject *)__pyx_n_s__n));
40780   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n));
40781   __Pyx_INCREF(((PyObject *)__pyx_n_s__retval));
40782   PyTuple_SET_ITEM(__pyx_k_tuple_291, 11, ((PyObject *)__pyx_n_s__retval));
40783   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__retval));
40784   __Pyx_INCREF(((PyObject *)__pyx_n_s__inf));
40785   PyTuple_SET_ITEM(__pyx_k_tuple_291, 12, ((PyObject *)__pyx_n_s__inf));
40786   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__inf));
40787   __Pyx_INCREF(((PyObject *)__pyx_n_s__out_stdout));
40788   PyTuple_SET_ITEM(__pyx_k_tuple_291, 13, ((PyObject *)__pyx_n_s__out_stdout));
40789   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__out_stdout));
40790   __Pyx_INCREF(((PyObject *)__pyx_n_s__out_stderr));
40791   PyTuple_SET_ITEM(__pyx_k_tuple_291, 14, ((PyObject *)__pyx_n_s__out_stderr));
40792   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__out_stderr));
40793   __Pyx_INCREF(((PyObject *)__pyx_n_s__a));
40794   PyTuple_SET_ITEM(__pyx_k_tuple_291, 15, ((PyObject *)__pyx_n_s__a));
40795   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a));
40796   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_291));
40797   __pyx_k_codeobj_292 = (PyObject*)__Pyx_PyCode_New(3, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_291, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_256, __pyx_n_s___samtools_dispatch, 3125, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_292)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40798   __Pyx_RefNannyFinishContext();
40799   return 0;
40800   __pyx_L1_error:;
40801   __Pyx_RefNannyFinishContext();
40802   return -1;
40803 }
40804
40805 static int __Pyx_InitGlobals(void) {
40806   if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40807   __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40808   __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40809   __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40810   __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40811   __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40812   __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40813   __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40814   __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40815   __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;};
40816   __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40817   __pyx_int_255 = PyInt_FromLong(255); if (unlikely(!__pyx_int_255)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40818   __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40819   __pyx_int_512 = PyInt_FromLong(512); if (unlikely(!__pyx_int_512)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40820   __pyx_int_neg_127 = PyInt_FromLong(-127); if (unlikely(!__pyx_int_neg_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40821   __pyx_int_0660 = PyInt_FromLong(0660); if (unlikely(!__pyx_int_0660)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40822   __pyx_int_1024 = PyInt_FromLong(1024); if (unlikely(!__pyx_int_1024)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40823   __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40824   __pyx_int_65535 = PyInt_FromLong(65535); if (unlikely(!__pyx_int_65535)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40825   __pyx_int_neg_32767 = PyInt_FromLong(-32767); if (unlikely(!__pyx_int_neg_32767)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40826   __pyx_int_536870912 = PyInt_FromLong(536870912); if (unlikely(!__pyx_int_536870912)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40827   __pyx_int_4294967295 = PyInt_FromString((char *)"4294967295", 0, 0); if (unlikely(!__pyx_int_4294967295)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40828   __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648); if (unlikely(!__pyx_int_neg_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40829   return 0;
40830   __pyx_L1_error:;
40831   return -1;
40832 }
40833
40834 #if PY_MAJOR_VERSION < 3
40835 PyMODINIT_FUNC initcsamtools(void); /*proto*/
40836 PyMODINIT_FUNC initcsamtools(void)
40837 #else
40838 PyMODINIT_FUNC PyInit_csamtools(void); /*proto*/
40839 PyMODINIT_FUNC PyInit_csamtools(void)
40840 #endif
40841 {
40842   PyObject *__pyx_t_1 = NULL;
40843   PyObject *__pyx_t_2 = NULL;
40844   int __pyx_t_3;
40845   PyObject *__pyx_t_4 = NULL;
40846   __Pyx_RefNannyDeclarations
40847   #if CYTHON_REFNANNY
40848   __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
40849   if (!__Pyx_RefNanny) {
40850       PyErr_Clear();
40851       __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
40852       if (!__Pyx_RefNanny)
40853           Py_FatalError("failed to import 'refnanny' module");
40854   }
40855   #endif
40856   __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_csamtools(void)", 0);
40857   if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40858   __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40859   __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40860   #ifdef __Pyx_CyFunction_USED
40861   if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40862   #endif
40863   #ifdef __Pyx_FusedFunction_USED
40864   if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40865   #endif
40866   #ifdef __Pyx_Generator_USED
40867   if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40868   #endif
40869   /*--- Library function declarations ---*/
40870   /*--- Threads initialization code ---*/
40871   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
40872   #ifdef WITH_THREAD /* Python build with threading support? */
40873   PyEval_InitThreads();
40874   #endif
40875   #endif
40876   /*--- Module creation code ---*/
40877   #if PY_MAJOR_VERSION < 3
40878   __pyx_m = Py_InitModule4(__Pyx_NAMESTR("csamtools"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
40879   #else
40880   __pyx_m = PyModule_Create(&__pyx_moduledef);
40881   #endif
40882   if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40883   #if PY_MAJOR_VERSION < 3
40884   Py_INCREF(__pyx_m);
40885   #endif
40886   __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
40887   if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40888   if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40889   /*--- Initialize various global constants etc. ---*/
40890   if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40891   if (__pyx_module_is_main_csamtools) {
40892     if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
40893   }
40894   /*--- Builtin init code ---*/
40895   if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40896   /*--- Constants init code ---*/
40897   if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40898   /*--- Global init code ---*/
40899   __pyx_v_9csamtools__FILENAME_ENCODING = ((PyObject*)Py_None); Py_INCREF(Py_None);
40900   /*--- Variable export code ---*/
40901   /*--- Function export code ---*/
40902   /*--- Type init code ---*/
40903   __pyx_vtabptr_9csamtools_Fastafile = &__pyx_vtable_9csamtools_Fastafile;
40904   __pyx_vtable_9csamtools_Fastafile._fetch = (char *(*)(struct __pyx_obj_9csamtools_Fastafile *, char *, int, int, int *))__pyx_f_9csamtools_9Fastafile__fetch;
40905   if (PyType_Ready(&__pyx_type_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40906   if (__Pyx_SetVtable(__pyx_type_9csamtools_Fastafile.tp_dict, __pyx_vtabptr_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40907   if (__Pyx_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40908   __pyx_ptype_9csamtools_Fastafile = &__pyx_type_9csamtools_Fastafile;
40909   if (PyType_Ready(&__pyx_type_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40910   {
40911     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40912     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40913       __pyx_wrapperbase_9csamtools_11AlignedRead_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
40914       __pyx_wrapperbase_9csamtools_11AlignedRead_4__str__.doc = __pyx_doc_9csamtools_11AlignedRead_4__str__;
40915       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_11AlignedRead_4__str__;
40916     }
40917   }
40918   if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40919   __pyx_ptype_9csamtools_AlignedRead = &__pyx_type_9csamtools_AlignedRead;
40920   __pyx_vtabptr_9csamtools_Samfile = &__pyx_vtable_9csamtools_Samfile;
40921   __pyx_vtable_9csamtools_Samfile._buildHeader = (bam_header_t *(*)(struct __pyx_obj_9csamtools_Samfile *, PyObject *))__pyx_f_9csamtools_7Samfile__buildHeader;
40922   __pyx_vtable_9csamtools_Samfile.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_Samfile *))__pyx_f_9csamtools_7Samfile_getCurrent;
40923   __pyx_vtable_9csamtools_Samfile.cnext = (int (*)(struct __pyx_obj_9csamtools_Samfile *))__pyx_f_9csamtools_7Samfile_cnext;
40924   __pyx_vtable_9csamtools_Samfile.write = (int (*)(struct __pyx_obj_9csamtools_Samfile *, struct __pyx_obj_9csamtools_AlignedRead *, int __pyx_skip_dispatch))__pyx_f_9csamtools_7Samfile_write;
40925   __pyx_vtable_9csamtools_Samfile._getrname = (char *(*)(struct __pyx_obj_9csamtools_Samfile *, int))__pyx_f_9csamtools_7Samfile__getrname;
40926   if (PyType_Ready(&__pyx_type_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40927   {
40928     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40929     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40930       __pyx_wrapperbase_9csamtools_7Samfile_42__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
40931       __pyx_wrapperbase_9csamtools_7Samfile_42__next__.doc = __pyx_doc_9csamtools_7Samfile_42__next__;
40932       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_7Samfile_42__next__;
40933     }
40934   }
40935   if (__Pyx_SetVtable(__pyx_type_9csamtools_Samfile.tp_dict, __pyx_vtabptr_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40936   if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40937   __pyx_ptype_9csamtools_Samfile = &__pyx_type_9csamtools_Samfile;
40938   if (PyType_Ready(&__pyx_type_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40939   if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40940   __pyx_ptype_9csamtools_PileupProxy = &__pyx_type_9csamtools_PileupProxy;
40941   if (PyType_Ready(&__pyx_type_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40942   if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40943   __pyx_ptype_9csamtools_PileupRead = &__pyx_type_9csamtools_PileupRead;
40944   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40945   if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40946   __pyx_ptype_9csamtools_IteratorRow = &__pyx_type_9csamtools_IteratorRow;
40947   __pyx_vtabptr_9csamtools_IteratorRowRegion = &__pyx_vtable_9csamtools_IteratorRowRegion;
40948   __pyx_vtable_9csamtools_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowRegion *))__pyx_f_9csamtools_17IteratorRowRegion_getCurrent;
40949   __pyx_vtable_9csamtools_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowRegion *))__pyx_f_9csamtools_17IteratorRowRegion_cnext;
40950   __pyx_type_9csamtools_IteratorRowRegion.tp_base = __pyx_ptype_9csamtools_IteratorRow;
40951   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40952   {
40953     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40954     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40955       __pyx_wrapperbase_9csamtools_17IteratorRowRegion_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
40956       __pyx_wrapperbase_9csamtools_17IteratorRowRegion_4__next__.doc = __pyx_doc_9csamtools_17IteratorRowRegion_4__next__;
40957       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_17IteratorRowRegion_4__next__;
40958     }
40959   }
40960   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowRegion.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40961   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40962   __pyx_ptype_9csamtools_IteratorRowRegion = &__pyx_type_9csamtools_IteratorRowRegion;
40963   __pyx_vtabptr_9csamtools_IteratorRowAll = &__pyx_vtable_9csamtools_IteratorRowAll;
40964   __pyx_vtable_9csamtools_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowAll *))__pyx_f_9csamtools_14IteratorRowAll_getCurrent;
40965   __pyx_vtable_9csamtools_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowAll *))__pyx_f_9csamtools_14IteratorRowAll_cnext;
40966   __pyx_type_9csamtools_IteratorRowAll.tp_base = __pyx_ptype_9csamtools_IteratorRow;
40967   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40968   {
40969     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40970     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40971       __pyx_wrapperbase_9csamtools_14IteratorRowAll_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
40972       __pyx_wrapperbase_9csamtools_14IteratorRowAll_4__next__.doc = __pyx_doc_9csamtools_14IteratorRowAll_4__next__;
40973       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_14IteratorRowAll_4__next__;
40974     }
40975   }
40976   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowAll.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40977   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40978   __pyx_ptype_9csamtools_IteratorRowAll = &__pyx_type_9csamtools_IteratorRowAll;
40979   __pyx_type_9csamtools_IteratorRowAllRefs.tp_base = __pyx_ptype_9csamtools_IteratorRow;
40980   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40981   {
40982     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40983     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40984       __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_6__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
40985       __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_6__next__.doc = __pyx_doc_9csamtools_18IteratorRowAllRefs_6__next__;
40986       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_6__next__;
40987     }
40988   }
40989   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40990   __pyx_ptype_9csamtools_IteratorRowAllRefs = &__pyx_type_9csamtools_IteratorRowAllRefs;
40991   __pyx_vtabptr_9csamtools_IteratorRowSelection = &__pyx_vtable_9csamtools_IteratorRowSelection;
40992   __pyx_vtable_9csamtools_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowSelection *))__pyx_f_9csamtools_20IteratorRowSelection_getCurrent;
40993   __pyx_vtable_9csamtools_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowSelection *))__pyx_f_9csamtools_20IteratorRowSelection_cnext;
40994   __pyx_type_9csamtools_IteratorRowSelection.tp_base = __pyx_ptype_9csamtools_IteratorRow;
40995   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40996   {
40997     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
40998     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
40999       __pyx_wrapperbase_9csamtools_20IteratorRowSelection_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
41000       __pyx_wrapperbase_9csamtools_20IteratorRowSelection_4__next__.doc = __pyx_doc_9csamtools_20IteratorRowSelection_4__next__;
41001       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_20IteratorRowSelection_4__next__;
41002     }
41003   }
41004   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowSelection.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41005   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41006   __pyx_ptype_9csamtools_IteratorRowSelection = &__pyx_type_9csamtools_IteratorRowSelection;
41007   __pyx_vtabptr_9csamtools_IteratorColumn = &__pyx_vtable_9csamtools_IteratorColumn;
41008   __pyx_vtable_9csamtools_IteratorColumn.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorColumn *))__pyx_f_9csamtools_14IteratorColumn_cnext;
41009   __pyx_vtable_9csamtools_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_9csamtools_IteratorColumn *))__pyx_f_9csamtools_14IteratorColumn_getSequence;
41010   __pyx_vtable_9csamtools_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *))__pyx_f_9csamtools_14IteratorColumn_setMask;
41011   __pyx_vtable_9csamtools_IteratorColumn.setupIteratorData = (PyObject *(*)(struct __pyx_obj_9csamtools_IteratorColumn *, int, int, int, struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args))__pyx_f_9csamtools_14IteratorColumn_setupIteratorData;
41012   __pyx_vtable_9csamtools_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_9csamtools_14IteratorColumn_reset;
41013   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41014   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumn.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41015   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41016   __pyx_ptype_9csamtools_IteratorColumn = &__pyx_type_9csamtools_IteratorColumn;
41017   __pyx_vtabptr_9csamtools_IteratorColumnRegion = &__pyx_vtable_9csamtools_IteratorColumnRegion;
41018   __pyx_vtable_9csamtools_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_9csamtools_IteratorColumn;
41019   __pyx_type_9csamtools_IteratorColumnRegion.tp_base = __pyx_ptype_9csamtools_IteratorColumn;
41020   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41021   {
41022     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41023     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
41024       __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
41025       __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_2__next__.doc = __pyx_doc_9csamtools_20IteratorColumnRegion_2__next__;
41026       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_20IteratorColumnRegion_2__next__;
41027     }
41028   }
41029   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumnRegion.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41030   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41031   __pyx_ptype_9csamtools_IteratorColumnRegion = &__pyx_type_9csamtools_IteratorColumnRegion;
41032   __pyx_vtabptr_9csamtools_IteratorColumnAllRefs = &__pyx_vtable_9csamtools_IteratorColumnAllRefs;
41033   __pyx_vtable_9csamtools_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_9csamtools_IteratorColumn;
41034   __pyx_type_9csamtools_IteratorColumnAllRefs.tp_base = __pyx_ptype_9csamtools_IteratorColumn;
41035   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41036   {
41037     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41038     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
41039       __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
41040       __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_2__next__.doc = __pyx_doc_9csamtools_21IteratorColumnAllRefs_2__next__;
41041       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_2__next__;
41042     }
41043   }
41044   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41045   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41046   __pyx_ptype_9csamtools_IteratorColumnAllRefs = &__pyx_type_9csamtools_IteratorColumnAllRefs;
41047   if (PyType_Ready(&__pyx_type_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41048   if (__Pyx_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41049   __pyx_ptype_9csamtools_IndexedReads = &__pyx_type_9csamtools_IndexedReads;
41050   if (PyType_Ready(&__pyx_type_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41051   if (__Pyx_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41052   __pyx_ptype_9csamtools_SNPCall = &__pyx_type_9csamtools_SNPCall;
41053   if (PyType_Ready(&__pyx_type_9csamtools___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41054   __pyx_ptype_9csamtools___pyx_scope_struct__genexpr = &__pyx_type_9csamtools___pyx_scope_struct__genexpr;
41055   if (PyType_Ready(&__pyx_type_9csamtools___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41056   __pyx_ptype_9csamtools___pyx_scope_struct_1_genexpr = &__pyx_type_9csamtools___pyx_scope_struct_1_genexpr;
41057   /*--- Type import code ---*/
41058   __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41059   __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41060   /*--- Variable import code ---*/
41061   /*--- Function import code ---*/
41062   /*--- Execution code ---*/
41063
41064   /* "csamtools.pyx":4
41065  * # cython: profile=True
41066  * # adds doc-strings for sphinx
41067  * import tempfile             # <<<<<<<<<<<<<<
41068  * import os
41069  * import sys
41070  */
41071   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__tempfile), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41072   __Pyx_GOTREF(__pyx_t_1);
41073   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__tempfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41074   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41075
41076   /* "csamtools.pyx":5
41077  * # adds doc-strings for sphinx
41078  * import tempfile
41079  * import os             # <<<<<<<<<<<<<<
41080  * import sys
41081  * import types
41082  */
41083   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__os), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41084   __Pyx_GOTREF(__pyx_t_1);
41085   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__os, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41086   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41087
41088   /* "csamtools.pyx":6
41089  * import tempfile
41090  * import os
41091  * import sys             # <<<<<<<<<<<<<<
41092  * import types
41093  * import itertools
41094  */
41095   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41096   __Pyx_GOTREF(__pyx_t_1);
41097   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41098   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41099
41100   /* "csamtools.pyx":7
41101  * import os
41102  * import sys
41103  * import types             # <<<<<<<<<<<<<<
41104  * import itertools
41105  * import struct
41106  */
41107   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__types), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41108   __Pyx_GOTREF(__pyx_t_1);
41109   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__types, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41110   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41111
41112   /* "csamtools.pyx":8
41113  * import sys
41114  * import types
41115  * import itertools             # <<<<<<<<<<<<<<
41116  * import struct
41117  * import ctypes
41118  */
41119   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__itertools), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41120   __Pyx_GOTREF(__pyx_t_1);
41121   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__itertools, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41122   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41123
41124   /* "csamtools.pyx":9
41125  * import types
41126  * import itertools
41127  * import struct             # <<<<<<<<<<<<<<
41128  * import ctypes
41129  * import collections
41130  */
41131   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__struct), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41132   __Pyx_GOTREF(__pyx_t_1);
41133   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__struct, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41134   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41135
41136   /* "csamtools.pyx":10
41137  * import itertools
41138  * import struct
41139  * import ctypes             # <<<<<<<<<<<<<<
41140  * import collections
41141  * import re
41142  */
41143   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__ctypes), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41144   __Pyx_GOTREF(__pyx_t_1);
41145   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ctypes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41146   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41147
41148   /* "csamtools.pyx":11
41149  * import struct
41150  * import ctypes
41151  * import collections             # <<<<<<<<<<<<<<
41152  * import re
41153  * import platform
41154  */
41155   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__collections), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41156   __Pyx_GOTREF(__pyx_t_1);
41157   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__collections, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41158   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41159
41160   /* "csamtools.pyx":12
41161  * import ctypes
41162  * import collections
41163  * import re             # <<<<<<<<<<<<<<
41164  * import platform
41165  * import warnings
41166  */
41167   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__re), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41168   __Pyx_GOTREF(__pyx_t_1);
41169   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__re, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41170   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41171
41172   /* "csamtools.pyx":13
41173  * import collections
41174  * import re
41175  * import platform             # <<<<<<<<<<<<<<
41176  * import warnings
41177  * from cpython cimport PyErr_SetString, PyBytes_Check, PyUnicode_Check, PyBytes_FromStringAndSize
41178  */
41179   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__platform), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41180   __Pyx_GOTREF(__pyx_t_1);
41181   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__platform, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41182   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41183
41184   /* "csamtools.pyx":14
41185  * import re
41186  * import platform
41187  * import warnings             # <<<<<<<<<<<<<<
41188  * from cpython cimport PyErr_SetString, PyBytes_Check, PyUnicode_Check, PyBytes_FromStringAndSize
41189  * from cpython.version cimport PY_MAJOR_VERSION
41190  */
41191   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__warnings), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41192   __Pyx_GOTREF(__pyx_t_1);
41193   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__warnings, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41194   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41195
41196   /* "csamtools.pyx":23
41197  * ## Python 3 compatibility functions
41198  * ########################################################################
41199  * IS_PYTHON3 = PY_MAJOR_VERSION >= 3             # <<<<<<<<<<<<<<
41200  * cdef from_string_and_size(char* s, size_t length):
41201  *     if PY_MAJOR_VERSION < 3:
41202  */
41203   __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41204   __Pyx_GOTREF(__pyx_t_1);
41205   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__IS_PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41206   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41207
41208   /* "csamtools.pyx":32
41209  * # filename encoding (copied from lxml.etree.pyx)
41210  * cdef str _FILENAME_ENCODING
41211  * _FILENAME_ENCODING = sys.getfilesystemencoding()             # <<<<<<<<<<<<<<
41212  * if _FILENAME_ENCODING is None:
41213  *     _FILENAME_ENCODING = sys.getdefaultencoding()
41214  */
41215   __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;}
41216   __Pyx_GOTREF(__pyx_t_1);
41217   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_249); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41218   __Pyx_GOTREF(__pyx_t_2);
41219   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41220   __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;}
41221   __Pyx_GOTREF(__pyx_t_1);
41222   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
41223   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;}
41224   __Pyx_XGOTREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41225   __Pyx_DECREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41226   __Pyx_GIVEREF(__pyx_t_1);
41227   __pyx_v_9csamtools__FILENAME_ENCODING = ((PyObject*)__pyx_t_1);
41228   __pyx_t_1 = 0;
41229
41230   /* "csamtools.pyx":33
41231  * cdef str _FILENAME_ENCODING
41232  * _FILENAME_ENCODING = sys.getfilesystemencoding()
41233  * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
41234  *     _FILENAME_ENCODING = sys.getdefaultencoding()
41235  * if _FILENAME_ENCODING is None:
41236  */
41237   __pyx_t_3 = (__pyx_v_9csamtools__FILENAME_ENCODING == ((PyObject*)Py_None));
41238   if (__pyx_t_3) {
41239
41240     /* "csamtools.pyx":34
41241  * _FILENAME_ENCODING = sys.getfilesystemencoding()
41242  * if _FILENAME_ENCODING is None:
41243  *     _FILENAME_ENCODING = sys.getdefaultencoding()             # <<<<<<<<<<<<<<
41244  * if _FILENAME_ENCODING is None:
41245  *     _FILENAME_ENCODING = 'ascii'
41246  */
41247     __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;}
41248     __Pyx_GOTREF(__pyx_t_1);
41249     __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;}
41250     __Pyx_GOTREF(__pyx_t_2);
41251     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41252     __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;}
41253     __Pyx_GOTREF(__pyx_t_1);
41254     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
41255     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;}
41256     __Pyx_XGOTREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41257     __Pyx_DECREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41258     __Pyx_GIVEREF(__pyx_t_1);
41259     __pyx_v_9csamtools__FILENAME_ENCODING = ((PyObject*)__pyx_t_1);
41260     __pyx_t_1 = 0;
41261     goto __pyx_L2;
41262   }
41263   __pyx_L2:;
41264
41265   /* "csamtools.pyx":35
41266  * if _FILENAME_ENCODING is None:
41267  *     _FILENAME_ENCODING = sys.getdefaultencoding()
41268  * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
41269  *     _FILENAME_ENCODING = 'ascii'
41270  * 
41271  */
41272   __pyx_t_3 = (__pyx_v_9csamtools__FILENAME_ENCODING == ((PyObject*)Py_None));
41273   if (__pyx_t_3) {
41274
41275     /* "csamtools.pyx":36
41276  *     _FILENAME_ENCODING = sys.getdefaultencoding()
41277  * if _FILENAME_ENCODING is None:
41278  *     _FILENAME_ENCODING = 'ascii'             # <<<<<<<<<<<<<<
41279  * 
41280  * #cdef char* _C_FILENAME_ENCODING
41281  */
41282     __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii));
41283     __Pyx_XGOTREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41284     __Pyx_DECREF(((PyObject *)__pyx_v_9csamtools__FILENAME_ENCODING));
41285     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii));
41286     __pyx_v_9csamtools__FILENAME_ENCODING = __pyx_n_s__ascii;
41287     goto __pyx_L3;
41288   }
41289   __pyx_L3:;
41290
41291   /* "csamtools.pyx":138
41292  * DEF BAM_CDIFF      = 8
41293  * 
41294  * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
41295  * if IS_PYTHON3:
41296  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
41297  */
41298   __pyx_v_9csamtools_CODE2CIGAR = __pyx_k_250;
41299
41300   /* "csamtools.pyx":139
41301  * 
41302  * cdef char* CODE2CIGAR= "MIDNSHP=X"
41303  * if IS_PYTHON3:             # <<<<<<<<<<<<<<
41304  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
41305  * else:
41306  */
41307   __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;}
41308   __Pyx_GOTREF(__pyx_t_1);
41309   __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;}
41310   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41311   if (__pyx_t_3) {
41312
41313     /* "csamtools.pyx":140
41314  * cdef char* CODE2CIGAR= "MIDNSHP=X"
41315  * if IS_PYTHON3:
41316  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
41317  * else:
41318  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
41319  */
41320     __pyx_t_1 = __pyx_pf_9csamtools_2genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41321     __Pyx_GOTREF(__pyx_t_1);
41322     __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;}
41323     __Pyx_GOTREF(__pyx_t_2);
41324     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
41325     __Pyx_GIVEREF(__pyx_t_1);
41326     __pyx_t_1 = 0;
41327     __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;}
41328     __Pyx_GOTREF(__pyx_t_1);
41329     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
41330     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;}
41331     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41332     goto __pyx_L4;
41333   }
41334   /*else*/ {
41335
41336     /* "csamtools.pyx":142
41337  *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
41338  * else:
41339  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
41340  * CIGAR_REGEX = re.compile( "([MIDNSHP=X])(\d+)" )
41341  * 
41342  */
41343     __pyx_t_1 = __pyx_pf_9csamtools_5genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41344     __Pyx_GOTREF(__pyx_t_1);
41345     __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;}
41346     __Pyx_GOTREF(__pyx_t_2);
41347     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
41348     __Pyx_GIVEREF(__pyx_t_1);
41349     __pyx_t_1 = 0;
41350     __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;}
41351     __Pyx_GOTREF(__pyx_t_1);
41352     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
41353     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;}
41354     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41355   }
41356   __pyx_L4:;
41357
41358   /* "csamtools.pyx":143
41359  * else:
41360  *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
41361  * CIGAR_REGEX = re.compile( "([MIDNSHP=X])(\d+)" )             # <<<<<<<<<<<<<<
41362  * 
41363  * #####################################################################
41364  */
41365   __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;}
41366   __Pyx_GOTREF(__pyx_t_1);
41367   __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;}
41368   __Pyx_GOTREF(__pyx_t_2);
41369   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41370   __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_252), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41371   __Pyx_GOTREF(__pyx_t_1);
41372   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
41373   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;}
41374   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41375
41376   /* "csamtools.pyx":147
41377  * #####################################################################
41378  * ## set pysam stderr to /dev/null
41379  * pysam_unset_stderr()             # <<<<<<<<<<<<<<
41380  * 
41381  * #####################################################################
41382  */
41383   pysam_unset_stderr();
41384
41385   /* "csamtools.pyx":151
41386  * #####################################################################
41387  * # hard-coded constants
41388  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
41389  * cdef int max_pos = 2 << 29
41390  * 
41391  */
41392   __pyx_v_9csamtools_bam_nt16_rev_table = __pyx_k_253;
41393
41394   /* "csamtools.pyx":152
41395  * # hard-coded constants
41396  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"
41397  * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
41398  * 
41399  * #####################################################################
41400  */
41401   __pyx_v_9csamtools_max_pos = 1073741824;
41402
41403   /* "csamtools.pyx":247
41404  *     (<object>f)(a)
41405  * 
41406  * class PileupColumn(object):             # <<<<<<<<<<<<<<
41407  *     '''A pileup column. A pileup column contains
41408  *     all the reads that map to a certain target base.
41409  */
41410   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41411   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41412
41413   /* "csamtools.pyx":260
41414  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
41415  *     '''
41416  *     def __str__(self):             # <<<<<<<<<<<<<<
41417  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
41418  *             "\n" + "\n".join( map(str, self.pileups) )
41419  */
41420   __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_12PileupColumn_1__str__, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_255)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41421   __Pyx_GOTREF(__pyx_t_2);
41422   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____str__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41423   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
41424
41425   /* "csamtools.pyx":247
41426  *     (<object>f)(a)
41427  * 
41428  * class PileupColumn(object):             # <<<<<<<<<<<<<<
41429  *     '''A pileup column. A pileup column contains
41430  *     all the reads that map to a certain target base.
41431  */
41432   __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41433   __Pyx_GOTREF(__pyx_t_2);
41434   __Pyx_INCREF(__pyx_builtin_object);
41435   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object);
41436   __Pyx_GIVEREF(__pyx_builtin_object);
41437   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_257)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41438   __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__PileupColumn, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41439   __Pyx_GOTREF(__pyx_t_4);
41440   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
41441   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PileupColumn, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41442   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41443   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41444
41445   /* "csamtools.pyx":304
41446  *     return 0
41447  * 
41448  * class StderrStore():             # <<<<<<<<<<<<<<
41449  *     '''
41450  *     stderr is captured.
41451  */
41452   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41453   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41454
41455   /* "csamtools.pyx":308
41456  *     stderr is captured.
41457  *     '''
41458  *     def __init__(self):             # <<<<<<<<<<<<<<
41459  *         return
41460  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
41461  */
41462   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_11StderrStore_1__init__, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_259)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41463   __Pyx_GOTREF(__pyx_t_4);
41464   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41465   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41466
41467   /* "csamtools.pyx":314
41468  *         self.stderr_save.setfd( self.stderr_h )
41469  * 
41470  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
41471  *         return []
41472  *         self.stderr_save.restore()
41473  */
41474   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_11StderrStore_3readAndRelease, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_261)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41475   __Pyx_GOTREF(__pyx_t_4);
41476   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41477   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41478
41479   /* "csamtools.pyx":323
41480  *         return lines
41481  * 
41482  *     def release(self):             # <<<<<<<<<<<<<<
41483  *         return
41484  *         self.stderr_save.restore()
41485  */
41486   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_11StderrStore_5release, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_263)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41487   __Pyx_GOTREF(__pyx_t_4);
41488   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41489   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41490
41491   /* "csamtools.pyx":329
41492  *             os.remove( self.stderr_f )
41493  * 
41494  *     def __del__(self):             # <<<<<<<<<<<<<<
41495  *         self.release()
41496  * 
41497  */
41498   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_11StderrStore_7__del__, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_265)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41499   __Pyx_GOTREF(__pyx_t_4);
41500   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____del__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41501   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41502
41503   /* "csamtools.pyx":304
41504  *     return 0
41505  * 
41506  * class StderrStore():             # <<<<<<<<<<<<<<
41507  *     '''
41508  *     stderr is captured.
41509  */
41510   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_266)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41511   __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStore, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41512   __Pyx_GOTREF(__pyx_t_4);
41513   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41514   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41515   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41516
41517   /* "csamtools.pyx":332
41518  *         self.release()
41519  * 
41520  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
41521  *     '''does nothing. stderr can't be redirected on windows'''
41522  *     def __init__(self): pass
41523  */
41524   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41525   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41526
41527   /* "csamtools.pyx":334
41528  * class StderrStoreWindows():
41529  *     '''does nothing. stderr can't be redirected on windows'''
41530  *     def __init__(self): pass             # <<<<<<<<<<<<<<
41531  *     def readAndRelease(self): return []
41532  *     def release(self): pass
41533  */
41534   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows_1__init__, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_268)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41535   __Pyx_GOTREF(__pyx_t_4);
41536   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41537   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41538
41539   /* "csamtools.pyx":335
41540  *     '''does nothing. stderr can't be redirected on windows'''
41541  *     def __init__(self): pass
41542  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
41543  *     def release(self): pass
41544  * 
41545  */
41546   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows_3readAndRelease, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_270)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41547   __Pyx_GOTREF(__pyx_t_4);
41548   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41549   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41550
41551   /* "csamtools.pyx":336
41552  *     def __init__(self): pass
41553  *     def readAndRelease(self): return []
41554  *     def release(self): pass             # <<<<<<<<<<<<<<
41555  * 
41556  * if platform.system()=='Windows':
41557  */
41558   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows_5release, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_272)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41559   __Pyx_GOTREF(__pyx_t_4);
41560   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41561   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41562
41563   /* "csamtools.pyx":332
41564  *         self.release()
41565  * 
41566  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
41567  *     '''does nothing. stderr can't be redirected on windows'''
41568  *     def __init__(self): pass
41569  */
41570   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_273)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41571   __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStoreWindows, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41572   __Pyx_GOTREF(__pyx_t_4);
41573   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStoreWindows, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41574   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41575   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41576
41577   /* "csamtools.pyx":338
41578  *     def release(self): pass
41579  * 
41580  * if platform.system()=='Windows':             # <<<<<<<<<<<<<<
41581  *     del StderrStore
41582  *     StderrStore = StderrStoreWindows
41583  */
41584   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__platform); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41585   __Pyx_GOTREF(__pyx_t_1);
41586   __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__system); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41587   __Pyx_GOTREF(__pyx_t_4);
41588   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41589   __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 = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41590   __Pyx_GOTREF(__pyx_t_1);
41591   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41592   __pyx_t_3 = __Pyx_PyString_Equals(__pyx_t_1, ((PyObject *)__pyx_n_s__Windows), Py_EQ); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41593   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41594   if (__pyx_t_3) {
41595
41596     /* "csamtools.pyx":339
41597  * 
41598  * if platform.system()=='Windows':
41599  *     del StderrStore             # <<<<<<<<<<<<<<
41600  *     StderrStore = StderrStoreWindows
41601  * 
41602  */
41603     if (__Pyx_DelAttrString(__pyx_m, "StderrStore") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41604
41605     /* "csamtools.pyx":340
41606  * if platform.system()=='Windows':
41607  *     del StderrStore
41608  *     StderrStore = StderrStoreWindows             # <<<<<<<<<<<<<<
41609  * 
41610  * 
41611  */
41612     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStoreWindows); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41613     __Pyx_GOTREF(__pyx_t_1);
41614     if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41615     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41616     goto __pyx_L5;
41617   }
41618   __pyx_L5:;
41619
41620   /* "csamtools.pyx":347
41621  * ######################################################################
41622  * # valid types for sam headers
41623  * VALID_HEADER_TYPES = { "HD" : dict,             # <<<<<<<<<<<<<<
41624  *                        "SQ" : list,
41625  *                        "RG" : list,
41626  */
41627   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41628   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41629   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41630
41631   /* "csamtools.pyx":348
41632  * # valid types for sam headers
41633  * VALID_HEADER_TYPES = { "HD" : dict,
41634  *                        "SQ" : list,             # <<<<<<<<<<<<<<
41635  *                        "RG" : list,
41636  *                        "PG" : list,
41637  */
41638   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41639
41640   /* "csamtools.pyx":349
41641  * VALID_HEADER_TYPES = { "HD" : dict,
41642  *                        "SQ" : list,
41643  *                        "RG" : list,             # <<<<<<<<<<<<<<
41644  *                        "PG" : list,
41645  *                        "CO" : list }
41646  */
41647   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41648
41649   /* "csamtools.pyx":350
41650  *                        "SQ" : list,
41651  *                        "RG" : list,
41652  *                        "PG" : list,             # <<<<<<<<<<<<<<
41653  *                        "CO" : list }
41654  * 
41655  */
41656   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41657
41658   /* "csamtools.pyx":351
41659  *                        "RG" : list,
41660  *                        "PG" : list,
41661  *                        "CO" : list }             # <<<<<<<<<<<<<<
41662  * 
41663  * # order of records within sam headers
41664  */
41665   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CO), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41666   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41667   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41668
41669   /* "csamtools.pyx":354
41670  * 
41671  * # order of records within sam headers
41672  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
41673  * 
41674  * # type conversions within sam header records
41675  */
41676   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADERS, ((PyObject *)__pyx_k_tuple_274)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41677
41678   /* "csamtools.pyx":357
41679  * 
41680  * # type conversions within sam header records
41681  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },             # <<<<<<<<<<<<<<
41682  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
41683  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
41684  */
41685   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41686   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41687   __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41688   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
41689   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41690   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41691   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__GO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41692   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41693   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
41694
41695   /* "csamtools.pyx":358
41696  * # type conversions within sam header records
41697  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
41698  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },             # <<<<<<<<<<<<<<
41699  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
41700  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str },
41701  */
41702   __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41703   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
41704   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41705   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__LN), ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41706   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__AS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41707   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__M5), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41708   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__UR), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41709   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41710   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41711   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
41712
41713   /* "csamtools.pyx":359
41714  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
41715  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
41716  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,             # <<<<<<<<<<<<<<
41717  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str },
41718  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }
41719  */
41720   __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41721   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
41722   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41723   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SM), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41724   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__LB), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41725   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__DS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41726   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PU), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41727   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PI), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41728
41729   /* "csamtools.pyx":360
41730  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
41731  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
41732  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str },             # <<<<<<<<<<<<<<
41733  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }
41734  * 
41735  */
41736   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41737   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__DT), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41738   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41739   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__FO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41740   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__KS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41741   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41742   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
41743
41744   /* "csamtools.pyx":361
41745  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str,
41746  *                                  "CN" : str, "DT" : str, "PL" : str, "FO" : str, "KS" : str },
41747  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }             # <<<<<<<<<<<<<<
41748  * 
41749  * # output order of fields within records
41750  */
41751   __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41752   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
41753   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41754   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41755   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41756   if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41757   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41758   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
41759   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41760   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41761
41762   /* "csamtools.pyx":364
41763  * 
41764  * # output order of fields within records
41765  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
41766  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
41767  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
41768  */
41769   __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;}
41770   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41771   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_k_tuple_275)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41772
41773   /* "csamtools.pyx":365
41774  * # output order of fields within records
41775  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
41776  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
41777  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
41778  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
41779  */
41780   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_k_tuple_276)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41781
41782   /* "csamtools.pyx":366
41783  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
41784  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
41785  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),             # <<<<<<<<<<<<<<
41786  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
41787  * 
41788  */
41789   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_k_tuple_277)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41790
41791   /* "csamtools.pyx":367
41792  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
41793  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL", "FO", "KS" ),
41794  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }             # <<<<<<<<<<<<<<
41795  * 
41796  * 
41797  */
41798   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_k_tuple_278)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41799   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41800   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41801
41802   /* "csamtools.pyx":619
41803  *                header = None,
41804  *                port = None,
41805  *                add_sq_text = True,             # <<<<<<<<<<<<<<
41806  *                check_header = True,
41807  *                check_sq = True,
41808  */
41809   __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41810   __Pyx_GOTREF(__pyx_t_1);
41811   __pyx_k_21 = __pyx_t_1;
41812   __Pyx_GIVEREF(__pyx_t_1);
41813   __pyx_t_1 = 0;
41814
41815   /* "csamtools.pyx":620
41816  *                port = None,
41817  *                add_sq_text = True,
41818  *                check_header = True,             # <<<<<<<<<<<<<<
41819  *                check_sq = True,
41820  *               ):
41821  */
41822   __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41823   __Pyx_GOTREF(__pyx_t_1);
41824   __pyx_k_22 = __pyx_t_1;
41825   __Pyx_GIVEREF(__pyx_t_1);
41826   __pyx_t_1 = 0;
41827
41828   /* "csamtools.pyx":621
41829  *                add_sq_text = True,
41830  *                check_header = True,
41831  *                check_sq = True,             # <<<<<<<<<<<<<<
41832  *               ):
41833  *         '''open a sam/bam file.
41834  */
41835   __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41836   __Pyx_GOTREF(__pyx_t_1);
41837   __pyx_k_23 = __pyx_t_1;
41838   __Pyx_GIVEREF(__pyx_t_1);
41839   __pyx_t_1 = 0;
41840
41841   /* "csamtools.pyx":900
41842  *                region = None,
41843  *                callback = None,
41844  *                until_eof = False ):             # <<<<<<<<<<<<<<
41845  *         '''
41846  *         fetch aligned reads in a :term:`region` using 0-based indexing. The region is specified by
41847  */
41848   __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41849   __Pyx_GOTREF(__pyx_t_1);
41850   __pyx_k_54 = __pyx_t_1;
41851   __Pyx_GIVEREF(__pyx_t_1);
41852   __pyx_t_1 = 0;
41853
41854   /* "csamtools.pyx":1020
41855  *                end = None,
41856  *                region = None,
41857  *                until_eof = False ):             # <<<<<<<<<<<<<<
41858  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
41859  * 
41860  */
41861   __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41862   __Pyx_GOTREF(__pyx_t_1);
41863   __pyx_k_73 = __pyx_t_1;
41864   __Pyx_GIVEREF(__pyx_t_1);
41865   __pyx_t_1 = 0;
41866
41867   /* "csamtools.pyx":1937
41868  *                   int tid = 0,
41869  *                   int start = 0,
41870  *                   int end = max_pos,             # <<<<<<<<<<<<<<
41871  *                   int truncate = False,
41872  *                   **kwargs ):
41873  */
41874   __pyx_k_128 = __pyx_v_9csamtools_max_pos;
41875
41876   /* "csamtools.pyx":3090
41877  *             return self._level
41878  * 
41879  * class Outs:             # <<<<<<<<<<<<<<
41880  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
41881  *     def __init__(self, id = 1):
41882  */
41883   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41884   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
41885
41886   /* "csamtools.pyx":3092
41887  * class Outs:
41888  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
41889  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
41890  *         self.streams = []
41891  *         self.id = id
41892  */
41893   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_4Outs_1__init__, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_280)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41894   __Pyx_GOTREF(__pyx_t_4);
41895   __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, ((PyObject *)__pyx_k_tuple_281));
41896   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41897   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41898
41899   /* "csamtools.pyx":3096
41900  *         self.id = id
41901  * 
41902  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
41903  *         '''open an existing file, like "/dev/null"'''
41904  *         fd = os.open(filename, os.O_WRONLY)
41905  */
41906   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_4Outs_3setdevice, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_283)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41907   __Pyx_GOTREF(__pyx_t_4);
41908   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__setdevice, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41909   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41910
41911   /* "csamtools.pyx":3101
41912  *         self.setfd(fd)
41913  * 
41914  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
41915  *         '''open a new file.'''
41916  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
41917  */
41918   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_4Outs_5setfile, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_285)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41919   __Pyx_GOTREF(__pyx_t_4);
41920   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__setfile, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41921   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41922
41923   /* "csamtools.pyx":3106
41924  *         self.setfd(fd)
41925  * 
41926  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
41927  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
41928  *         self.streams.append(ofd)
41929  */
41930   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_4Outs_7setfd, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_287)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41931   __Pyx_GOTREF(__pyx_t_4);
41932   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__setfd, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41933   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41934
41935   /* "csamtools.pyx":3114
41936  *         os.close(fd)                #  Close other unit (look out, caller.)
41937  * 
41938  *     def restore(self):             # <<<<<<<<<<<<<<
41939  *         '''restore previous output stream'''
41940  *         if self.streams:
41941  */
41942   __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_9csamtools_4Outs_9restore, 0, NULL, __pyx_n_s__csamtools, ((PyObject *)__pyx_k_codeobj_289)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41943   __Pyx_GOTREF(__pyx_t_4);
41944   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__restore, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41945   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41946
41947   /* "csamtools.pyx":3090
41948  *             return self._level
41949  * 
41950  * class Outs:             # <<<<<<<<<<<<<<
41951  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
41952  *     def __init__(self, id = 1):
41953  */
41954   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_290)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41955   __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__Outs, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41956   __Pyx_GOTREF(__pyx_t_4);
41957   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Outs, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41958   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
41959   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
41960
41961   /* "csamtools.pyx":3127
41962  * def _samtools_dispatch( method,
41963  *                         args = (),
41964  *                         catch_stdout = True ):             # <<<<<<<<<<<<<<
41965  *     '''call ``method`` in samtools providing arguments in args.
41966  * 
41967  */
41968   __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41969   __Pyx_GOTREF(__pyx_t_1);
41970   __pyx_k_176 = __pyx_t_1;
41971   __Pyx_GIVEREF(__pyx_t_1);
41972   __pyx_t_1 = 0;
41973
41974   /* "csamtools.pyx":3125
41975  *             del self.streams[-1]
41976  * 
41977  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
41978  *                         args = (),
41979  *                         catch_stdout = True ):
41980  */
41981   __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9csamtools_1_samtools_dispatch, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41982   __Pyx_GOTREF(__pyx_t_1);
41983   if (PyObject_SetAttr(__pyx_m, __pyx_n_s___samtools_dispatch, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41984   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
41985
41986   /* "csamtools.pyx":3836
41987  *         if self.owns_samfile: samclose( self.fp )
41988  * 
41989  * __all__ = ["Samfile",             # <<<<<<<<<<<<<<
41990  *            "Fastafile",
41991  *            "IteratorRow",
41992  */
41993   __pyx_t_1 = PyList_New(9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
41994   __Pyx_GOTREF(__pyx_t_1);
41995   __Pyx_INCREF(((PyObject *)__pyx_n_s__Samfile));
41996   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__Samfile));
41997   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Samfile));
41998   __Pyx_INCREF(((PyObject *)__pyx_n_s__Fastafile));
41999   PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__Fastafile));
42000   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Fastafile));
42001   __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorRow));
42002   PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__IteratorRow));
42003   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorRow));
42004   __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorColumn));
42005   PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__IteratorColumn));
42006   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorColumn));
42007   __Pyx_INCREF(((PyObject *)__pyx_n_s__AlignedRead));
42008   PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__AlignedRead));
42009   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AlignedRead));
42010   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupColumn));
42011   PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__PileupColumn));
42012   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupColumn));
42013   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupProxy));
42014   PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__PileupProxy));
42015   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupProxy));
42016   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupRead));
42017   PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__PileupRead));
42018   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupRead));
42019   __Pyx_INCREF(((PyObject *)__pyx_n_s__IndexedReads));
42020   PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__IndexedReads));
42021   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IndexedReads));
42022   if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
42023   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
42024
42025   /* "csamtools.pyx":1
42026  * # cython: embedsignature=True             # <<<<<<<<<<<<<<
42027  * # cython: profile=True
42028  * # adds doc-strings for sphinx
42029  */
42030   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
42031   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
42032   if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
42033   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
42034   goto __pyx_L0;
42035   __pyx_L1_error:;
42036   __Pyx_XDECREF(__pyx_t_1);
42037   __Pyx_XDECREF(__pyx_t_2);
42038   __Pyx_XDECREF(__pyx_t_4);
42039   if (__pyx_m) {
42040     __Pyx_AddTraceback("init csamtools", __pyx_clineno, __pyx_lineno, __pyx_filename);
42041     Py_DECREF(__pyx_m); __pyx_m = 0;
42042   } else if (!PyErr_Occurred()) {
42043     PyErr_SetString(PyExc_ImportError, "init csamtools");
42044   }
42045   __pyx_L0:;
42046   __Pyx_RefNannyFinishContext();
42047   #if PY_MAJOR_VERSION < 3
42048   return;
42049   #else
42050   return __pyx_m;
42051   #endif
42052 }
42053
42054 /* Runtime support code */
42055 #if CYTHON_REFNANNY
42056 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
42057     PyObject *m = NULL, *p = NULL;
42058     void *r = NULL;
42059     m = PyImport_ImportModule((char *)modname);
42060     if (!m) goto end;
42061     p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
42062     if (!p) goto end;
42063     r = PyLong_AsVoidPtr(p);
42064 end:
42065     Py_XDECREF(p);
42066     Py_XDECREF(m);
42067     return (__Pyx_RefNannyAPIStruct *)r;
42068 }
42069 #endif /* CYTHON_REFNANNY */
42070
42071 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
42072     PyObject *result;
42073     result = PyObject_GetAttr(dict, name);
42074     if (!result) {
42075         if (dict != __pyx_b) {
42076             PyErr_Clear();
42077             result = PyObject_GetAttr(__pyx_b, name);
42078         }
42079         if (!result) {
42080             PyErr_SetObject(PyExc_NameError, name);
42081         }
42082     }
42083     return result;
42084 }
42085
42086 #if CYTHON_PROFILE
42087 static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
42088                                    PyFrameObject** frame,
42089                                    const char *funcname,
42090                                    const char *srcfile,
42091                                    int firstlineno) {
42092     if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
42093         if (*code == NULL) {
42094             *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
42095             if (*code == NULL) return 0;
42096         }
42097         *frame = PyFrame_New(
42098             PyThreadState_GET(),            /*PyThreadState *tstate*/
42099             *code,                          /*PyCodeObject *code*/
42100             PyModule_GetDict(__pyx_m),      /*PyObject *globals*/
42101             0                               /*PyObject *locals*/
42102         );
42103         if (*frame == NULL) return 0;
42104     }
42105     else {
42106         (*frame)->f_tstate = PyThreadState_GET();
42107     }
42108     return PyThreadState_GET()->c_profilefunc(PyThreadState_GET()->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
42109 }
42110 static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
42111     PyObject *py_srcfile = 0;
42112     PyObject *py_funcname = 0;
42113     PyCodeObject *py_code = 0;
42114     #if PY_MAJOR_VERSION < 3
42115     py_funcname = PyString_FromString(funcname);
42116     py_srcfile = PyString_FromString(srcfile);
42117     #else
42118     py_funcname = PyUnicode_FromString(funcname);
42119     py_srcfile = PyUnicode_FromString(srcfile);
42120     #endif
42121     if (!py_funcname | !py_srcfile) goto bad;
42122     py_code = PyCode_New(
42123         0,                /*int argcount,*/
42124         #if PY_MAJOR_VERSION >= 3
42125         0,                /*int kwonlyargcount,*/
42126         #endif
42127         0,                /*int nlocals,*/
42128         0,                /*int stacksize,*/
42129         0,                /*int flags,*/
42130         __pyx_empty_bytes,  /*PyObject *code,*/
42131         __pyx_empty_tuple,  /*PyObject *consts,*/
42132         __pyx_empty_tuple,  /*PyObject *names,*/
42133         __pyx_empty_tuple,  /*PyObject *varnames,*/
42134         __pyx_empty_tuple,  /*PyObject *freevars,*/
42135         __pyx_empty_tuple,  /*PyObject *cellvars,*/
42136         py_srcfile,       /*PyObject *filename,*/
42137         py_funcname,      /*PyObject *name,*/
42138         firstlineno,      /*int firstlineno,*/
42139         __pyx_empty_bytes   /*PyObject *lnotab*/
42140     );
42141 bad:
42142     Py_XDECREF(py_srcfile);
42143     Py_XDECREF(py_funcname);
42144     return py_code;
42145 }
42146 #endif /* CYTHON_PROFILE */
42147
42148 static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
42149 #if CYTHON_COMPILING_IN_CPYTHON
42150     PyObject *tmp_type, *tmp_value, *tmp_tb;
42151     PyThreadState *tstate = PyThreadState_GET();
42152     tmp_type = tstate->curexc_type;
42153     tmp_value = tstate->curexc_value;
42154     tmp_tb = tstate->curexc_traceback;
42155     tstate->curexc_type = type;
42156     tstate->curexc_value = value;
42157     tstate->curexc_traceback = tb;
42158     Py_XDECREF(tmp_type);
42159     Py_XDECREF(tmp_value);
42160     Py_XDECREF(tmp_tb);
42161 #else
42162     PyErr_Restore(type, value, tb);
42163 #endif
42164 }
42165 static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
42166 #if CYTHON_COMPILING_IN_CPYTHON
42167     PyThreadState *tstate = PyThreadState_GET();
42168     *type = tstate->curexc_type;
42169     *value = tstate->curexc_value;
42170     *tb = tstate->curexc_traceback;
42171     tstate->curexc_type = 0;
42172     tstate->curexc_value = 0;
42173     tstate->curexc_traceback = 0;
42174 #else
42175     PyErr_Fetch(type, value, tb);
42176 #endif
42177 }
42178
42179 #if PY_MAJOR_VERSION < 3
42180 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
42181                         CYTHON_UNUSED PyObject *cause) {
42182     Py_XINCREF(type);
42183     Py_XINCREF(value);
42184     Py_XINCREF(tb);
42185     if (tb == Py_None) {
42186         Py_DECREF(tb);
42187         tb = 0;
42188     }
42189     else if (tb != NULL && !PyTraceBack_Check(tb)) {
42190         PyErr_SetString(PyExc_TypeError,
42191             "raise: arg 3 must be a traceback or None");
42192         goto raise_error;
42193     }
42194     if (value == NULL) {
42195         value = Py_None;
42196         Py_INCREF(value);
42197     }
42198     #if PY_VERSION_HEX < 0x02050000
42199     if (!PyClass_Check(type))
42200     #else
42201     if (!PyType_Check(type))
42202     #endif
42203     {
42204         if (value != Py_None) {
42205             PyErr_SetString(PyExc_TypeError,
42206                 "instance exception may not have a separate value");
42207             goto raise_error;
42208         }
42209         Py_DECREF(value);
42210         value = type;
42211         #if PY_VERSION_HEX < 0x02050000
42212             if (PyInstance_Check(type)) {
42213                 type = (PyObject*) ((PyInstanceObject*)type)->in_class;
42214                 Py_INCREF(type);
42215             }
42216             else {
42217                 type = 0;
42218                 PyErr_SetString(PyExc_TypeError,
42219                     "raise: exception must be an old-style class or instance");
42220                 goto raise_error;
42221             }
42222         #else
42223             type = (PyObject*) Py_TYPE(type);
42224             Py_INCREF(type);
42225             if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
42226                 PyErr_SetString(PyExc_TypeError,
42227                     "raise: exception class must be a subclass of BaseException");
42228                 goto raise_error;
42229             }
42230         #endif
42231     }
42232     __Pyx_ErrRestore(type, value, tb);
42233     return;
42234 raise_error:
42235     Py_XDECREF(value);
42236     Py_XDECREF(type);
42237     Py_XDECREF(tb);
42238     return;
42239 }
42240 #else /* Python 3+ */
42241 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
42242     if (tb == Py_None) {
42243         tb = 0;
42244     } else if (tb && !PyTraceBack_Check(tb)) {
42245         PyErr_SetString(PyExc_TypeError,
42246             "raise: arg 3 must be a traceback or None");
42247         goto bad;
42248     }
42249     if (value == Py_None)
42250         value = 0;
42251     if (PyExceptionInstance_Check(type)) {
42252         if (value) {
42253             PyErr_SetString(PyExc_TypeError,
42254                 "instance exception may not have a separate value");
42255             goto bad;
42256         }
42257         value = type;
42258         type = (PyObject*) Py_TYPE(value);
42259     } else if (!PyExceptionClass_Check(type)) {
42260         PyErr_SetString(PyExc_TypeError,
42261             "raise: exception class must be a subclass of BaseException");
42262         goto bad;
42263     }
42264     if (cause) {
42265         PyObject *fixed_cause;
42266         if (PyExceptionClass_Check(cause)) {
42267             fixed_cause = PyObject_CallObject(cause, NULL);
42268             if (fixed_cause == NULL)
42269                 goto bad;
42270         }
42271         else if (PyExceptionInstance_Check(cause)) {
42272             fixed_cause = cause;
42273             Py_INCREF(fixed_cause);
42274         }
42275         else {
42276             PyErr_SetString(PyExc_TypeError,
42277                             "exception causes must derive from "
42278                             "BaseException");
42279             goto bad;
42280         }
42281         if (!value) {
42282             value = PyObject_CallObject(type, NULL);
42283         }
42284         PyException_SetCause(value, fixed_cause);
42285     }
42286     PyErr_SetObject(type, value);
42287     if (tb) {
42288         PyThreadState *tstate = PyThreadState_GET();
42289         PyObject* tmp_tb = tstate->curexc_traceback;
42290         if (tb != tmp_tb) {
42291             Py_INCREF(tb);
42292             tstate->curexc_traceback = tb;
42293             Py_XDECREF(tmp_tb);
42294         }
42295     }
42296 bad:
42297     return;
42298 }
42299 #endif
42300
42301 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
42302     if (unlikely(!type)) {
42303         PyErr_Format(PyExc_SystemError, "Missing type object");
42304         return 0;
42305     }
42306     if (likely(PyObject_TypeCheck(obj, type)))
42307         return 1;
42308     PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
42309                  Py_TYPE(obj)->tp_name, type->tp_name);
42310     return 0;
42311 }
42312
42313 static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
42314     PyObject *kwdict,
42315     const char* function_name,
42316     int kw_allowed)
42317 {
42318     PyObject* key = 0;
42319     Py_ssize_t pos = 0;
42320     while (PyDict_Next(kwdict, &pos, &key, 0)) {
42321         #if PY_MAJOR_VERSION < 3
42322         if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
42323         #else
42324         if (unlikely(!PyUnicode_Check(key)))
42325         #endif
42326             goto invalid_keyword_type;
42327     }
42328     if ((!kw_allowed) && unlikely(key))
42329         goto invalid_keyword;
42330     return 1;
42331 invalid_keyword_type:
42332     PyErr_Format(PyExc_TypeError,
42333         "%s() keywords must be strings", function_name);
42334     return 0;
42335 invalid_keyword:
42336     PyErr_Format(PyExc_TypeError,
42337     #if PY_MAJOR_VERSION < 3
42338         "%s() got an unexpected keyword argument '%s'",
42339         function_name, PyString_AsString(key));
42340     #else
42341         "%s() got an unexpected keyword argument '%U'",
42342         function_name, key);
42343     #endif
42344     return 0;
42345 }
42346
42347 static void __Pyx_RaiseDoubleKeywordsError(
42348     const char* func_name,
42349     PyObject* kw_name)
42350 {
42351     PyErr_Format(PyExc_TypeError,
42352         #if PY_MAJOR_VERSION >= 3
42353         "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
42354         #else
42355         "%s() got multiple values for keyword argument '%s'", func_name,
42356         PyString_AS_STRING(kw_name));
42357         #endif
42358 }
42359
42360 static int __Pyx_ParseOptionalKeywords(
42361     PyObject *kwds,
42362     PyObject **argnames[],
42363     PyObject *kwds2,
42364     PyObject *values[],
42365     Py_ssize_t num_pos_args,
42366     const char* function_name)
42367 {
42368     PyObject *key = 0, *value = 0;
42369     Py_ssize_t pos = 0;
42370     PyObject*** name;
42371     PyObject*** first_kw_arg = argnames + num_pos_args;
42372     while (PyDict_Next(kwds, &pos, &key, &value)) {
42373         name = first_kw_arg;
42374         while (*name && (**name != key)) name++;
42375         if (*name) {
42376             values[name-argnames] = value;
42377         } else {
42378             #if PY_MAJOR_VERSION < 3
42379             if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
42380             #else
42381             if (unlikely(!PyUnicode_Check(key))) {
42382             #endif
42383                 goto invalid_keyword_type;
42384             } else {
42385                 for (name = first_kw_arg; *name; name++) {
42386                     #if PY_MAJOR_VERSION >= 3
42387                     if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
42388                         PyUnicode_Compare(**name, key) == 0) break;
42389                     #else
42390                     if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
42391                         _PyString_Eq(**name, key)) break;
42392                     #endif
42393                 }
42394                 if (*name) {
42395                     values[name-argnames] = value;
42396                 } else {
42397                     for (name=argnames; name != first_kw_arg; name++) {
42398                         if (**name == key) goto arg_passed_twice;
42399                         #if PY_MAJOR_VERSION >= 3
42400                         if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
42401                             PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
42402                         #else
42403                         if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
42404                             _PyString_Eq(**name, key)) goto arg_passed_twice;
42405                         #endif
42406                     }
42407                     if (kwds2) {
42408                         if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
42409                     } else {
42410                         goto invalid_keyword;
42411                     }
42412                 }
42413             }
42414         }
42415     }
42416     return 0;
42417 arg_passed_twice:
42418     __Pyx_RaiseDoubleKeywordsError(function_name, **name);
42419     goto bad;
42420 invalid_keyword_type:
42421     PyErr_Format(PyExc_TypeError,
42422         "%s() keywords must be strings", function_name);
42423     goto bad;
42424 invalid_keyword:
42425     PyErr_Format(PyExc_TypeError,
42426     #if PY_MAJOR_VERSION < 3
42427         "%s() got an unexpected keyword argument '%s'",
42428         function_name, PyString_AsString(key));
42429     #else
42430         "%s() got an unexpected keyword argument '%U'",
42431         function_name, key);
42432     #endif
42433 bad:
42434     return -1;
42435 }
42436
42437 static void __Pyx_RaiseArgtupleInvalid(
42438     const char* func_name,
42439     int exact,
42440     Py_ssize_t num_min,
42441     Py_ssize_t num_max,
42442     Py_ssize_t num_found)
42443 {
42444     Py_ssize_t num_expected;
42445     const char *more_or_less;
42446     if (num_found < num_min) {
42447         num_expected = num_min;
42448         more_or_less = "at least";
42449     } else {
42450         num_expected = num_max;
42451         more_or_less = "at most";
42452     }
42453     if (exact) {
42454         more_or_less = "exactly";
42455     }
42456     PyErr_Format(PyExc_TypeError,
42457                  "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)",
42458                  func_name, more_or_less, num_expected,
42459                  (num_expected == 1) ? "" : "s", num_found);
42460 }
42461
42462 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
42463     const char *name, int exact)
42464 {
42465     if (!type) {
42466         PyErr_Format(PyExc_SystemError, "Missing type object");
42467         return 0;
42468     }
42469     if (none_allowed && obj == Py_None) return 1;
42470     else if (exact) {
42471         if (Py_TYPE(obj) == type) return 1;
42472     }
42473     else {
42474         if (PyObject_TypeCheck(obj, type)) return 1;
42475     }
42476     PyErr_Format(PyExc_TypeError,
42477         "Argument '%s' has incorrect type (expected %s, got %s)",
42478         name, type->tp_name, Py_TYPE(obj)->tp_name);
42479     return 0;
42480 }
42481
42482 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
42483     PyObject *local_type, *local_value, *local_tb;
42484     PyObject *tmp_type, *tmp_value, *tmp_tb;
42485     PyThreadState *tstate = PyThreadState_GET();
42486     local_type = tstate->curexc_type;
42487     local_value = tstate->curexc_value;
42488     local_tb = tstate->curexc_traceback;
42489     tstate->curexc_type = 0;
42490     tstate->curexc_value = 0;
42491     tstate->curexc_traceback = 0;
42492     PyErr_NormalizeException(&local_type, &local_value, &local_tb);
42493     if (unlikely(tstate->curexc_type))
42494         goto bad;
42495     #if PY_MAJOR_VERSION >= 3
42496     if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
42497         goto bad;
42498     #endif
42499     *type = local_type;
42500     *value = local_value;
42501     *tb = local_tb;
42502     Py_INCREF(local_type);
42503     Py_INCREF(local_value);
42504     Py_INCREF(local_tb);
42505     tmp_type = tstate->exc_type;
42506     tmp_value = tstate->exc_value;
42507     tmp_tb = tstate->exc_traceback;
42508     tstate->exc_type = local_type;
42509     tstate->exc_value = local_value;
42510     tstate->exc_traceback = local_tb;
42511     /* Make sure tstate is in a consistent state when we XDECREF
42512        these objects (XDECREF may run arbitrary code). */
42513     Py_XDECREF(tmp_type);
42514     Py_XDECREF(tmp_value);
42515     Py_XDECREF(tmp_tb);
42516     return 0;
42517 bad:
42518     *type = 0;
42519     *value = 0;
42520     *tb = 0;
42521     Py_XDECREF(local_type);
42522     Py_XDECREF(local_value);
42523     Py_XDECREF(local_tb);
42524     return -1;
42525 }
42526
42527
42528
42529 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
42530     PyErr_Format(PyExc_ValueError,
42531                  "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack",
42532                  index, (index == 1) ? "" : "s");
42533 }
42534
42535 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
42536     PyErr_Format(PyExc_ValueError,
42537                  "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected);
42538 }
42539
42540 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
42541     if (unlikely(retval)) {
42542         Py_DECREF(retval);
42543         __Pyx_RaiseTooManyValuesError(expected);
42544         return -1;
42545     } else if (PyErr_Occurred()) {
42546         if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
42547             PyErr_Clear();
42548             return 0;
42549         } else {
42550             return -1;
42551         }
42552     }
42553     return 0;
42554 }
42555
42556 static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
42557     PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
42558 }
42559
42560 static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
42561     long q = a / b;
42562     long r = a - q*b;
42563     q -= ((r != 0) & ((r ^ b) < 0));
42564     return q;
42565 }
42566
42567 static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
42568     long r = a % b;
42569     r += ((r != 0) & ((r ^ b) < 0)) * b;
42570     return r;
42571 }
42572
42573 static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
42574     PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
42575 }
42576
42577
42578
42579 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
42580     PyThreadState *tstate = PyThreadState_GET();
42581     *type = tstate->exc_type;
42582     *value = tstate->exc_value;
42583     *tb = tstate->exc_traceback;
42584     Py_XINCREF(*type);
42585     Py_XINCREF(*value);
42586     Py_XINCREF(*tb);
42587 }
42588 static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
42589     PyObject *tmp_type, *tmp_value, *tmp_tb;
42590     PyThreadState *tstate = PyThreadState_GET();
42591     tmp_type = tstate->exc_type;
42592     tmp_value = tstate->exc_value;
42593     tmp_tb = tstate->exc_traceback;
42594     tstate->exc_type = type;
42595     tstate->exc_value = value;
42596     tstate->exc_traceback = tb;
42597     Py_XDECREF(tmp_type);
42598     Py_XDECREF(tmp_value);
42599     Py_XDECREF(tmp_tb);
42600 }
42601
42602 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
42603     PyObject *py_import = 0;
42604     PyObject *empty_list = 0;
42605     PyObject *module = 0;
42606     PyObject *global_dict = 0;
42607     PyObject *empty_dict = 0;
42608     PyObject *list;
42609     py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
42610     if (!py_import)
42611         goto bad;
42612     if (from_list)
42613         list = from_list;
42614     else {
42615         empty_list = PyList_New(0);
42616         if (!empty_list)
42617             goto bad;
42618         list = empty_list;
42619     }
42620     global_dict = PyModule_GetDict(__pyx_m);
42621     if (!global_dict)
42622         goto bad;
42623     empty_dict = PyDict_New();
42624     if (!empty_dict)
42625         goto bad;
42626     #if PY_VERSION_HEX >= 0x02050000
42627     {
42628         #if PY_MAJOR_VERSION >= 3
42629         if (level == -1) {
42630             if (strchr(__Pyx_MODULE_NAME, '.')) {
42631                 /* try package relative import first */
42632                 PyObject *py_level = PyInt_FromLong(1);
42633                 if (!py_level)
42634                     goto bad;
42635                 module = PyObject_CallFunctionObjArgs(py_import,
42636                     name, global_dict, empty_dict, list, py_level, NULL);
42637                 Py_DECREF(py_level);
42638                 if (!module) {
42639                     if (!PyErr_ExceptionMatches(PyExc_ImportError))
42640                         goto bad;
42641                     PyErr_Clear();
42642                 }
42643             }
42644             level = 0; /* try absolute import on failure */
42645         }
42646         #endif
42647         if (!module) {
42648             PyObject *py_level = PyInt_FromLong(level);
42649             if (!py_level)
42650                 goto bad;
42651             module = PyObject_CallFunctionObjArgs(py_import,
42652                 name, global_dict, empty_dict, list, py_level, NULL);
42653             Py_DECREF(py_level);
42654         }
42655     }
42656     #else
42657     if (level>0) {
42658         PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
42659         goto bad;
42660     }
42661     module = PyObject_CallFunctionObjArgs(py_import,
42662         name, global_dict, empty_dict, list, NULL);
42663     #endif
42664 bad:
42665     Py_XDECREF(empty_list);
42666     Py_XDECREF(py_import);
42667     Py_XDECREF(empty_dict);
42668     return module;
42669 }
42670
42671 static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) {
42672     PyObject *metaclass;
42673     /* Default metaclass */
42674 #if PY_MAJOR_VERSION < 3
42675     if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
42676         PyObject *base = PyTuple_GET_ITEM(bases, 0);
42677         metaclass = PyObject_GetAttrString(base, (char *)"__class__");
42678         if (!metaclass) {
42679             PyErr_Clear();
42680             metaclass = (PyObject*) Py_TYPE(base);
42681         }
42682     } else {
42683         metaclass = (PyObject *) &PyClass_Type;
42684     }
42685 #else
42686     if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
42687         PyObject *base = PyTuple_GET_ITEM(bases, 0);
42688         metaclass = (PyObject*) Py_TYPE(base);
42689     } else {
42690         metaclass = (PyObject *) &PyType_Type;
42691     }
42692 #endif
42693     Py_INCREF(metaclass);
42694     return metaclass;
42695 }
42696
42697 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
42698                                    PyObject *modname) {
42699     PyObject *result;
42700     PyObject *metaclass;
42701     if (PyDict_SetItemString(dict, "__module__", modname) < 0)
42702         return NULL;
42703     /* Python2 __metaclass__ */
42704     metaclass = PyDict_GetItemString(dict, "__metaclass__");
42705     if (metaclass) {
42706         Py_INCREF(metaclass);
42707     } else {
42708         metaclass = __Pyx_FindPy2Metaclass(bases);
42709     }
42710     result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
42711     Py_DECREF(metaclass);
42712     return result;
42713 }
42714
42715 static PyObject *
42716 __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
42717 {
42718     if (op->func_doc == NULL && op->func.m_ml->ml_doc) {
42719 #if PY_MAJOR_VERSION >= 3
42720         op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
42721 #else
42722         op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
42723 #endif
42724     }
42725     if (op->func_doc == 0) {
42726         Py_INCREF(Py_None);
42727         return Py_None;
42728     }
42729     Py_INCREF(op->func_doc);
42730     return op->func_doc;
42731 }
42732 static int
42733 __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
42734 {
42735     PyObject *tmp = op->func_doc;
42736     if (value == NULL)
42737         op->func_doc = Py_None; /* Mark as deleted */
42738     else
42739         op->func_doc = value;
42740     Py_INCREF(op->func_doc);
42741     Py_XDECREF(tmp);
42742     return 0;
42743 }
42744 static PyObject *
42745 __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
42746 {
42747     if (op->func_name == NULL) {
42748 #if PY_MAJOR_VERSION >= 3
42749         op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
42750 #else
42751         op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
42752 #endif
42753     }
42754     Py_INCREF(op->func_name);
42755     return op->func_name;
42756 }
42757 static int
42758 __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
42759 {
42760     PyObject *tmp;
42761 #if PY_MAJOR_VERSION >= 3
42762     if (value == NULL || !PyUnicode_Check(value)) {
42763 #else
42764     if (value == NULL || !PyString_Check(value)) {
42765 #endif
42766         PyErr_SetString(PyExc_TypeError,
42767                         "__name__ must be set to a string object");
42768         return -1;
42769     }
42770     tmp = op->func_name;
42771     Py_INCREF(value);
42772     op->func_name = value;
42773     Py_XDECREF(tmp);
42774     return 0;
42775 }
42776 static PyObject *
42777 __Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
42778 {
42779     PyObject *self;
42780     self = m->func_closure;
42781     if (self == NULL)
42782         self = Py_None;
42783     Py_INCREF(self);
42784     return self;
42785 }
42786 static PyObject *
42787 __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
42788 {
42789     if (op->func_dict == NULL) {
42790         op->func_dict = PyDict_New();
42791         if (op->func_dict == NULL)
42792             return NULL;
42793     }
42794     Py_INCREF(op->func_dict);
42795     return op->func_dict;
42796 }
42797 static int
42798 __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
42799 {
42800     PyObject *tmp;
42801     if (value == NULL) {
42802         PyErr_SetString(PyExc_TypeError,
42803                "function's dictionary may not be deleted");
42804         return -1;
42805     }
42806     if (!PyDict_Check(value)) {
42807         PyErr_SetString(PyExc_TypeError,
42808                "setting function's dictionary to a non-dict");
42809         return -1;
42810     }
42811     tmp = op->func_dict;
42812     Py_INCREF(value);
42813     op->func_dict = value;
42814     Py_XDECREF(tmp);
42815     return 0;
42816 }
42817 static PyObject *
42818 __Pyx_CyFunction_get_globals(CYTHON_UNUSED __pyx_CyFunctionObject *op)
42819 {
42820     PyObject* dict = PyModule_GetDict(__pyx_m);
42821     Py_XINCREF(dict);
42822     return dict;
42823 }
42824 static PyObject *
42825 __Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
42826 {
42827     Py_INCREF(Py_None);
42828     return Py_None;
42829 }
42830 static PyObject *
42831 __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
42832 {
42833     PyObject* result = (op->func_code) ? op->func_code : Py_None;
42834     Py_INCREF(result);
42835     return result;
42836 }
42837 static PyObject *
42838 __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op)
42839 {
42840     if (op->defaults_tuple) {
42841         Py_INCREF(op->defaults_tuple);
42842         return op->defaults_tuple;
42843     }
42844     if (op->defaults_getter) {
42845         PyObject *res = op->defaults_getter((PyObject *) op);
42846         if (res) {
42847             Py_INCREF(res);
42848             op->defaults_tuple = res;
42849         }
42850         return res;
42851     }
42852     Py_INCREF(Py_None);
42853     return Py_None;
42854 }
42855 static PyGetSetDef __pyx_CyFunction_getsets[] = {
42856     {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
42857     {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
42858     {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
42859     {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
42860     {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
42861     {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
42862     {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
42863     {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
42864     {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
42865     {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
42866     {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
42867     {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
42868     {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
42869     {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, 0, 0, 0},
42870     {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, 0, 0, 0},
42871     {0, 0, 0, 0, 0}
42872 };
42873 #ifndef PY_WRITE_RESTRICTED /* < Py2.5 */
42874 #define PY_WRITE_RESTRICTED WRITE_RESTRICTED
42875 #endif
42876 static PyMemberDef __pyx_CyFunction_members[] = {
42877     {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
42878     {0, 0, 0,  0, 0}
42879 };
42880 static PyObject *
42881 __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
42882 {
42883 #if PY_MAJOR_VERSION >= 3
42884     return PyUnicode_FromString(m->func.m_ml->ml_name);
42885 #else
42886     return PyString_FromString(m->func.m_ml->ml_name);
42887 #endif
42888 }
42889 static PyMethodDef __pyx_CyFunction_methods[] = {
42890     {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
42891     {0, 0, 0, 0}
42892 };
42893 static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags,
42894                                       PyObject *closure, PyObject *module, PyObject* code) {
42895     __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
42896     if (op == NULL)
42897         return NULL;
42898     op->flags = flags;
42899     op->func_weakreflist = NULL;
42900     op->func.m_ml = ml;
42901     op->func.m_self = (PyObject *) op;
42902     Py_XINCREF(closure);
42903     op->func_closure = closure;
42904     Py_XINCREF(module);
42905     op->func.m_module = module;
42906     op->func_dict = NULL;
42907     op->func_name = NULL;
42908     op->func_doc = NULL;
42909     op->func_classobj = NULL;
42910     Py_XINCREF(code);
42911     op->func_code = code;
42912     op->defaults_pyobjects = 0;
42913     op->defaults = NULL;
42914     op->defaults_tuple = NULL;
42915     op->defaults_getter = NULL;
42916     PyObject_GC_Track(op);
42917     return (PyObject *) op;
42918 }
42919 static int
42920 __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
42921 {
42922     Py_CLEAR(m->func_closure);
42923     Py_CLEAR(m->func.m_module);
42924     Py_CLEAR(m->func_dict);
42925     Py_CLEAR(m->func_name);
42926     Py_CLEAR(m->func_doc);
42927     Py_CLEAR(m->func_code);
42928     Py_CLEAR(m->func_classobj);
42929     Py_CLEAR(m->defaults_tuple);
42930     if (m->defaults) {
42931         PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
42932         int i;
42933         for (i = 0; i < m->defaults_pyobjects; i++)
42934             Py_XDECREF(pydefaults[i]);
42935         PyMem_Free(m->defaults);
42936         m->defaults = NULL;
42937     }
42938     return 0;
42939 }
42940 static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
42941 {
42942     PyObject_GC_UnTrack(m);
42943     if (m->func_weakreflist != NULL)
42944         PyObject_ClearWeakRefs((PyObject *) m);
42945     __Pyx_CyFunction_clear(m);
42946     PyObject_GC_Del(m);
42947 }
42948 static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
42949 {
42950     Py_VISIT(m->func_closure);
42951     Py_VISIT(m->func.m_module);
42952     Py_VISIT(m->func_dict);
42953     Py_VISIT(m->func_name);
42954     Py_VISIT(m->func_doc);
42955     Py_VISIT(m->func_code);
42956     Py_VISIT(m->func_classobj);
42957     Py_VISIT(m->defaults_tuple);
42958     if (m->defaults) {
42959         PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
42960         int i;
42961         for (i = 0; i < m->defaults_pyobjects; i++)
42962             Py_VISIT(pydefaults[i]);
42963     }
42964     return 0;
42965 }
42966 static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
42967 {
42968     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
42969     if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
42970         Py_INCREF(func);
42971         return func;
42972     }
42973     if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
42974         if (type == NULL)
42975             type = (PyObject *)(Py_TYPE(obj));
42976         return PyMethod_New(func,
42977                             type, (PyObject *)(Py_TYPE(type)));
42978     }
42979     if (obj == Py_None)
42980         obj = NULL;
42981     return PyMethod_New(func, obj, type);
42982 }
42983 static PyObject*
42984 __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
42985 {
42986     PyObject *func_name = __Pyx_CyFunction_get_name(op);
42987 #if PY_MAJOR_VERSION >= 3
42988     return PyUnicode_FromFormat("<cyfunction %U at %p>",
42989                                 func_name, (void *)op);
42990 #else
42991     return PyString_FromFormat("<cyfunction %s at %p>",
42992                                PyString_AsString(func_name), (void *)op);
42993 #endif
42994 }
42995 static PyTypeObject __pyx_CyFunctionType_type = {
42996     PyVarObject_HEAD_INIT(0, 0)
42997     __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/
42998     sizeof(__pyx_CyFunctionObject),   /*tp_basicsize*/
42999     0,                                  /*tp_itemsize*/
43000     (destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/
43001     0,                                  /*tp_print*/
43002     0,                                  /*tp_getattr*/
43003     0,                                  /*tp_setattr*/
43004 #if PY_MAJOR_VERSION < 3
43005     0,                                  /*tp_compare*/
43006 #else
43007     0,                                  /*reserved*/
43008 #endif
43009     (reprfunc) __Pyx_CyFunction_repr,   /*tp_repr*/
43010     0,                                  /*tp_as_number*/
43011     0,                                  /*tp_as_sequence*/
43012     0,                                  /*tp_as_mapping*/
43013     0,                                  /*tp_hash*/
43014     __Pyx_PyCFunction_Call,             /*tp_call*/
43015     0,                                  /*tp_str*/
43016     0,                                  /*tp_getattro*/
43017     0,                                  /*tp_setattro*/
43018     0,                                  /*tp_as_buffer*/
43019     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/
43020     0,                                  /*tp_doc*/
43021     (traverseproc) __Pyx_CyFunction_traverse,   /*tp_traverse*/
43022     (inquiry) __Pyx_CyFunction_clear,   /*tp_clear*/
43023     0,                                  /*tp_richcompare*/
43024     offsetof(__pyx_CyFunctionObject, func_weakreflist), /* tp_weaklistoffse */
43025     0,                                  /*tp_iter*/
43026     0,                                  /*tp_iternext*/
43027     __pyx_CyFunction_methods,           /*tp_methods*/
43028     __pyx_CyFunction_members,           /*tp_members*/
43029     __pyx_CyFunction_getsets,           /*tp_getset*/
43030     0,                                  /*tp_base*/
43031     0,                                  /*tp_dict*/
43032     __Pyx_CyFunction_descr_get,         /*tp_descr_get*/
43033     0,                                  /*tp_descr_set*/
43034     offsetof(__pyx_CyFunctionObject, func_dict),/*tp_dictoffset*/
43035     0,                                  /*tp_init*/
43036     0,                                  /*tp_alloc*/
43037     0,                                  /*tp_new*/
43038     0,                                  /*tp_free*/
43039     0,                                  /*tp_is_gc*/
43040     0,                                  /*tp_bases*/
43041     0,                                  /*tp_mro*/
43042     0,                                  /*tp_cache*/
43043     0,                                  /*tp_subclasses*/
43044     0,                                  /*tp_weaklist*/
43045     0,                                  /*tp_del*/
43046 #if PY_VERSION_HEX >= 0x02060000
43047     0,                                  /*tp_version_tag*/
43048 #endif
43049 };
43050 static int __Pyx_CyFunction_init(void)
43051 {
43052     if (PyType_Ready(&__pyx_CyFunctionType_type) < 0)
43053         return -1;
43054     __pyx_CyFunctionType = &__pyx_CyFunctionType_type;
43055     return 0;
43056 }
43057 void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects)
43058 {
43059     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
43060     m->defaults = PyMem_Malloc(size);
43061     if (!m->defaults)
43062         return PyErr_NoMemory();
43063     memset(m->defaults, 0, sizeof(size));
43064     m->defaults_pyobjects = pyobjects;
43065     return m->defaults;
43066 }
43067 static void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple)
43068 {
43069     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
43070     m->defaults_tuple = tuple;
43071     Py_INCREF(tuple);
43072 }
43073
43074 static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
43075     if (s1 == s2) {
43076         return (equals == Py_EQ);
43077     } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
43078         if (PyBytes_GET_SIZE(s1) != PyBytes_GET_SIZE(s2)) {
43079             return (equals == Py_NE);
43080         } else if (PyBytes_GET_SIZE(s1) == 1) {
43081             if (equals == Py_EQ)
43082                 return (PyBytes_AS_STRING(s1)[0] == PyBytes_AS_STRING(s2)[0]);
43083             else
43084                 return (PyBytes_AS_STRING(s1)[0] != PyBytes_AS_STRING(s2)[0]);
43085         } else {
43086             int result = memcmp(PyBytes_AS_STRING(s1), PyBytes_AS_STRING(s2), (size_t)PyBytes_GET_SIZE(s1));
43087             return (equals == Py_EQ) ? (result == 0) : (result != 0);
43088         }
43089     } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
43090         return (equals == Py_NE);
43091     } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
43092         return (equals == Py_NE);
43093     } else {
43094         int result;
43095         PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
43096         if (!py_result)
43097             return -1;
43098         result = __Pyx_PyObject_IsTrue(py_result);
43099         Py_DECREF(py_result);
43100         return result;
43101     }
43102 }
43103
43104 static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
43105     if (s1 == s2) {
43106         return (equals == Py_EQ);
43107     } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) {
43108         #if CYTHON_PEP393_ENABLED
43109         if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0))
43110             return -1;
43111         if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) {
43112             return (equals == Py_NE);
43113         } else if (PyUnicode_GET_LENGTH(s1) == 1) {
43114             Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0);
43115             Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0);
43116             return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2);
43117         #else
43118         if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) {
43119             return (equals == Py_NE);
43120         } else if (PyUnicode_GET_SIZE(s1) == 1) {
43121             Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0];
43122             Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0];
43123             return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2);
43124         #endif
43125         } else {
43126             int result = PyUnicode_Compare(s1, s2);
43127             if ((result == -1) && unlikely(PyErr_Occurred()))
43128                 return -1;
43129             return (equals == Py_EQ) ? (result == 0) : (result != 0);
43130         }
43131     } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) {
43132         return (equals == Py_NE);
43133     } else if ((s2 == Py_None) & PyUnicode_CheckExact(s1)) {
43134         return (equals == Py_NE);
43135     } else {
43136         int result;
43137         PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
43138         if (!py_result)
43139             return -1;
43140         result = __Pyx_PyObject_IsTrue(py_result);
43141         Py_DECREF(py_result);
43142         return result;
43143     }
43144 }
43145
43146 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int8_t(int8_t val) {
43147     const int8_t neg_one = (int8_t)-1, const_zero = (int8_t)0;
43148     const int is_unsigned = const_zero < neg_one;
43149     if ((sizeof(int8_t) == sizeof(char))  ||
43150         (sizeof(int8_t) == sizeof(short))) {
43151         return PyInt_FromLong((long)val);
43152     } else if ((sizeof(int8_t) == sizeof(int)) ||
43153                (sizeof(int8_t) == sizeof(long))) {
43154         if (is_unsigned)
43155             return PyLong_FromUnsignedLong((unsigned long)val);
43156         else
43157             return PyInt_FromLong((long)val);
43158     } else if (sizeof(int8_t) == sizeof(PY_LONG_LONG)) {
43159         if (is_unsigned)
43160             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43161         else
43162             return PyLong_FromLongLong((PY_LONG_LONG)val);
43163     } else {
43164         int one = 1; int little = (int)*(unsigned char *)&one;
43165         unsigned char *bytes = (unsigned char *)&val;
43166         return _PyLong_FromByteArray(bytes, sizeof(int8_t),
43167                                      little, !is_unsigned);
43168     }
43169 }
43170
43171 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t val) {
43172     const uint8_t neg_one = (uint8_t)-1, const_zero = (uint8_t)0;
43173     const int is_unsigned = const_zero < neg_one;
43174     if ((sizeof(uint8_t) == sizeof(char))  ||
43175         (sizeof(uint8_t) == sizeof(short))) {
43176         return PyInt_FromLong((long)val);
43177     } else if ((sizeof(uint8_t) == sizeof(int)) ||
43178                (sizeof(uint8_t) == sizeof(long))) {
43179         if (is_unsigned)
43180             return PyLong_FromUnsignedLong((unsigned long)val);
43181         else
43182             return PyInt_FromLong((long)val);
43183     } else if (sizeof(uint8_t) == sizeof(PY_LONG_LONG)) {
43184         if (is_unsigned)
43185             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43186         else
43187             return PyLong_FromLongLong((PY_LONG_LONG)val);
43188     } else {
43189         int one = 1; int little = (int)*(unsigned char *)&one;
43190         unsigned char *bytes = (unsigned char *)&val;
43191         return _PyLong_FromByteArray(bytes, sizeof(uint8_t),
43192                                      little, !is_unsigned);
43193     }
43194 }
43195
43196 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int16_t(int16_t val) {
43197     const int16_t neg_one = (int16_t)-1, const_zero = (int16_t)0;
43198     const int is_unsigned = const_zero < neg_one;
43199     if ((sizeof(int16_t) == sizeof(char))  ||
43200         (sizeof(int16_t) == sizeof(short))) {
43201         return PyInt_FromLong((long)val);
43202     } else if ((sizeof(int16_t) == sizeof(int)) ||
43203                (sizeof(int16_t) == sizeof(long))) {
43204         if (is_unsigned)
43205             return PyLong_FromUnsignedLong((unsigned long)val);
43206         else
43207             return PyInt_FromLong((long)val);
43208     } else if (sizeof(int16_t) == sizeof(PY_LONG_LONG)) {
43209         if (is_unsigned)
43210             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43211         else
43212             return PyLong_FromLongLong((PY_LONG_LONG)val);
43213     } else {
43214         int one = 1; int little = (int)*(unsigned char *)&one;
43215         unsigned char *bytes = (unsigned char *)&val;
43216         return _PyLong_FromByteArray(bytes, sizeof(int16_t),
43217                                      little, !is_unsigned);
43218     }
43219 }
43220
43221 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint16_t(uint16_t val) {
43222     const uint16_t neg_one = (uint16_t)-1, const_zero = (uint16_t)0;
43223     const int is_unsigned = const_zero < neg_one;
43224     if ((sizeof(uint16_t) == sizeof(char))  ||
43225         (sizeof(uint16_t) == sizeof(short))) {
43226         return PyInt_FromLong((long)val);
43227     } else if ((sizeof(uint16_t) == sizeof(int)) ||
43228                (sizeof(uint16_t) == sizeof(long))) {
43229         if (is_unsigned)
43230             return PyLong_FromUnsignedLong((unsigned long)val);
43231         else
43232             return PyInt_FromLong((long)val);
43233     } else if (sizeof(uint16_t) == sizeof(PY_LONG_LONG)) {
43234         if (is_unsigned)
43235             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43236         else
43237             return PyLong_FromLongLong((PY_LONG_LONG)val);
43238     } else {
43239         int one = 1; int little = (int)*(unsigned char *)&one;
43240         unsigned char *bytes = (unsigned char *)&val;
43241         return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
43242                                      little, !is_unsigned);
43243     }
43244 }
43245
43246 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t val) {
43247     const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
43248     const int is_unsigned = const_zero < neg_one;
43249     if ((sizeof(int32_t) == sizeof(char))  ||
43250         (sizeof(int32_t) == sizeof(short))) {
43251         return PyInt_FromLong((long)val);
43252     } else if ((sizeof(int32_t) == sizeof(int)) ||
43253                (sizeof(int32_t) == sizeof(long))) {
43254         if (is_unsigned)
43255             return PyLong_FromUnsignedLong((unsigned long)val);
43256         else
43257             return PyInt_FromLong((long)val);
43258     } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
43259         if (is_unsigned)
43260             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43261         else
43262             return PyLong_FromLongLong((PY_LONG_LONG)val);
43263     } else {
43264         int one = 1; int little = (int)*(unsigned char *)&one;
43265         unsigned char *bytes = (unsigned char *)&val;
43266         return _PyLong_FromByteArray(bytes, sizeof(int32_t),
43267                                      little, !is_unsigned);
43268     }
43269 }
43270
43271 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t val) {
43272     const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
43273     const int is_unsigned = const_zero < neg_one;
43274     if ((sizeof(uint32_t) == sizeof(char))  ||
43275         (sizeof(uint32_t) == sizeof(short))) {
43276         return PyInt_FromLong((long)val);
43277     } else if ((sizeof(uint32_t) == sizeof(int)) ||
43278                (sizeof(uint32_t) == sizeof(long))) {
43279         if (is_unsigned)
43280             return PyLong_FromUnsignedLong((unsigned long)val);
43281         else
43282             return PyInt_FromLong((long)val);
43283     } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
43284         if (is_unsigned)
43285             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43286         else
43287             return PyLong_FromLongLong((PY_LONG_LONG)val);
43288     } else {
43289         int one = 1; int little = (int)*(unsigned char *)&one;
43290         unsigned char *bytes = (unsigned char *)&val;
43291         return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
43292                                      little, !is_unsigned);
43293     }
43294 }
43295
43296 static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject* x) {
43297     const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
43298     const int is_unsigned = const_zero < neg_one;
43299     if (sizeof(uint32_t) == sizeof(char)) {
43300         if (is_unsigned)
43301             return (uint32_t)__Pyx_PyInt_AsUnsignedChar(x);
43302         else
43303             return (uint32_t)__Pyx_PyInt_AsSignedChar(x);
43304     } else if (sizeof(uint32_t) == sizeof(short)) {
43305         if (is_unsigned)
43306             return (uint32_t)__Pyx_PyInt_AsUnsignedShort(x);
43307         else
43308             return (uint32_t)__Pyx_PyInt_AsSignedShort(x);
43309     } else if (sizeof(uint32_t) == sizeof(int)) {
43310         if (is_unsigned)
43311             return (uint32_t)__Pyx_PyInt_AsUnsignedInt(x);
43312         else
43313             return (uint32_t)__Pyx_PyInt_AsSignedInt(x);
43314     } else if (sizeof(uint32_t) == sizeof(long)) {
43315         if (is_unsigned)
43316             return (uint32_t)__Pyx_PyInt_AsUnsignedLong(x);
43317         else
43318             return (uint32_t)__Pyx_PyInt_AsSignedLong(x);
43319     } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
43320         if (is_unsigned)
43321             return (uint32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
43322         else
43323             return (uint32_t)__Pyx_PyInt_AsSignedLongLong(x);
43324     }  else {
43325         uint32_t val;
43326         PyObject *v = __Pyx_PyNumber_Int(x);
43327         #if PY_VERSION_HEX < 0x03000000
43328         if (likely(v) && !PyLong_Check(v)) {
43329             PyObject *tmp = v;
43330             v = PyNumber_Long(tmp);
43331             Py_DECREF(tmp);
43332         }
43333         #endif
43334         if (likely(v)) {
43335             int one = 1; int is_little = (int)*(unsigned char *)&one;
43336             unsigned char *bytes = (unsigned char *)&val;
43337             int ret = _PyLong_AsByteArray((PyLongObject *)v,
43338                                           bytes, sizeof(val),
43339                                           is_little, !is_unsigned);
43340             Py_DECREF(v);
43341             if (likely(!ret))
43342                 return val;
43343         }
43344         return (uint32_t)-1;
43345     }
43346 }
43347
43348 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t val) {
43349     const int64_t neg_one = (int64_t)-1, const_zero = (int64_t)0;
43350     const int is_unsigned = const_zero < neg_one;
43351     if ((sizeof(int64_t) == sizeof(char))  ||
43352         (sizeof(int64_t) == sizeof(short))) {
43353         return PyInt_FromLong((long)val);
43354     } else if ((sizeof(int64_t) == sizeof(int)) ||
43355                (sizeof(int64_t) == sizeof(long))) {
43356         if (is_unsigned)
43357             return PyLong_FromUnsignedLong((unsigned long)val);
43358         else
43359             return PyInt_FromLong((long)val);
43360     } else if (sizeof(int64_t) == sizeof(PY_LONG_LONG)) {
43361         if (is_unsigned)
43362             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43363         else
43364             return PyLong_FromLongLong((PY_LONG_LONG)val);
43365     } else {
43366         int one = 1; int little = (int)*(unsigned char *)&one;
43367         unsigned char *bytes = (unsigned char *)&val;
43368         return _PyLong_FromByteArray(bytes, sizeof(int64_t),
43369                                      little, !is_unsigned);
43370     }
43371 }
43372
43373 static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject* x) {
43374     const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
43375     const int is_unsigned = const_zero < neg_one;
43376     if (sizeof(uint64_t) == sizeof(char)) {
43377         if (is_unsigned)
43378             return (uint64_t)__Pyx_PyInt_AsUnsignedChar(x);
43379         else
43380             return (uint64_t)__Pyx_PyInt_AsSignedChar(x);
43381     } else if (sizeof(uint64_t) == sizeof(short)) {
43382         if (is_unsigned)
43383             return (uint64_t)__Pyx_PyInt_AsUnsignedShort(x);
43384         else
43385             return (uint64_t)__Pyx_PyInt_AsSignedShort(x);
43386     } else if (sizeof(uint64_t) == sizeof(int)) {
43387         if (is_unsigned)
43388             return (uint64_t)__Pyx_PyInt_AsUnsignedInt(x);
43389         else
43390             return (uint64_t)__Pyx_PyInt_AsSignedInt(x);
43391     } else if (sizeof(uint64_t) == sizeof(long)) {
43392         if (is_unsigned)
43393             return (uint64_t)__Pyx_PyInt_AsUnsignedLong(x);
43394         else
43395             return (uint64_t)__Pyx_PyInt_AsSignedLong(x);
43396     } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
43397         if (is_unsigned)
43398             return (uint64_t)__Pyx_PyInt_AsUnsignedLongLong(x);
43399         else
43400             return (uint64_t)__Pyx_PyInt_AsSignedLongLong(x);
43401     }  else {
43402         uint64_t val;
43403         PyObject *v = __Pyx_PyNumber_Int(x);
43404         #if PY_VERSION_HEX < 0x03000000
43405         if (likely(v) && !PyLong_Check(v)) {
43406             PyObject *tmp = v;
43407             v = PyNumber_Long(tmp);
43408             Py_DECREF(tmp);
43409         }
43410         #endif
43411         if (likely(v)) {
43412             int one = 1; int is_little = (int)*(unsigned char *)&one;
43413             unsigned char *bytes = (unsigned char *)&val;
43414             int ret = _PyLong_AsByteArray((PyLongObject *)v,
43415                                           bytes, sizeof(val),
43416                                           is_little, !is_unsigned);
43417             Py_DECREF(v);
43418             if (likely(!ret))
43419                 return val;
43420         }
43421         return (uint64_t)-1;
43422     }
43423 }
43424
43425 static CYTHON_INLINE uint8_t __Pyx_PyInt_from_py_uint8_t(PyObject* x) {
43426     const uint8_t neg_one = (uint8_t)-1, const_zero = (uint8_t)0;
43427     const int is_unsigned = const_zero < neg_one;
43428     if (sizeof(uint8_t) == sizeof(char)) {
43429         if (is_unsigned)
43430             return (uint8_t)__Pyx_PyInt_AsUnsignedChar(x);
43431         else
43432             return (uint8_t)__Pyx_PyInt_AsSignedChar(x);
43433     } else if (sizeof(uint8_t) == sizeof(short)) {
43434         if (is_unsigned)
43435             return (uint8_t)__Pyx_PyInt_AsUnsignedShort(x);
43436         else
43437             return (uint8_t)__Pyx_PyInt_AsSignedShort(x);
43438     } else if (sizeof(uint8_t) == sizeof(int)) {
43439         if (is_unsigned)
43440             return (uint8_t)__Pyx_PyInt_AsUnsignedInt(x);
43441         else
43442             return (uint8_t)__Pyx_PyInt_AsSignedInt(x);
43443     } else if (sizeof(uint8_t) == sizeof(long)) {
43444         if (is_unsigned)
43445             return (uint8_t)__Pyx_PyInt_AsUnsignedLong(x);
43446         else
43447             return (uint8_t)__Pyx_PyInt_AsSignedLong(x);
43448     } else if (sizeof(uint8_t) == sizeof(PY_LONG_LONG)) {
43449         if (is_unsigned)
43450             return (uint8_t)__Pyx_PyInt_AsUnsignedLongLong(x);
43451         else
43452             return (uint8_t)__Pyx_PyInt_AsSignedLongLong(x);
43453     }  else {
43454         uint8_t val;
43455         PyObject *v = __Pyx_PyNumber_Int(x);
43456         #if PY_VERSION_HEX < 0x03000000
43457         if (likely(v) && !PyLong_Check(v)) {
43458             PyObject *tmp = v;
43459             v = PyNumber_Long(tmp);
43460             Py_DECREF(tmp);
43461         }
43462         #endif
43463         if (likely(v)) {
43464             int one = 1; int is_little = (int)*(unsigned char *)&one;
43465             unsigned char *bytes = (unsigned char *)&val;
43466             int ret = _PyLong_AsByteArray((PyLongObject *)v,
43467                                           bytes, sizeof(val),
43468                                           is_little, !is_unsigned);
43469             Py_DECREF(v);
43470             if (likely(!ret))
43471                 return val;
43472         }
43473         return (uint8_t)-1;
43474     }
43475 }
43476
43477 static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject* x) {
43478     const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
43479     const int is_unsigned = const_zero < neg_one;
43480     if (sizeof(int32_t) == sizeof(char)) {
43481         if (is_unsigned)
43482             return (int32_t)__Pyx_PyInt_AsUnsignedChar(x);
43483         else
43484             return (int32_t)__Pyx_PyInt_AsSignedChar(x);
43485     } else if (sizeof(int32_t) == sizeof(short)) {
43486         if (is_unsigned)
43487             return (int32_t)__Pyx_PyInt_AsUnsignedShort(x);
43488         else
43489             return (int32_t)__Pyx_PyInt_AsSignedShort(x);
43490     } else if (sizeof(int32_t) == sizeof(int)) {
43491         if (is_unsigned)
43492             return (int32_t)__Pyx_PyInt_AsUnsignedInt(x);
43493         else
43494             return (int32_t)__Pyx_PyInt_AsSignedInt(x);
43495     } else if (sizeof(int32_t) == sizeof(long)) {
43496         if (is_unsigned)
43497             return (int32_t)__Pyx_PyInt_AsUnsignedLong(x);
43498         else
43499             return (int32_t)__Pyx_PyInt_AsSignedLong(x);
43500     } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
43501         if (is_unsigned)
43502             return (int32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
43503         else
43504             return (int32_t)__Pyx_PyInt_AsSignedLongLong(x);
43505     }  else {
43506         int32_t val;
43507         PyObject *v = __Pyx_PyNumber_Int(x);
43508         #if PY_VERSION_HEX < 0x03000000
43509         if (likely(v) && !PyLong_Check(v)) {
43510             PyObject *tmp = v;
43511             v = PyNumber_Long(tmp);
43512             Py_DECREF(tmp);
43513         }
43514         #endif
43515         if (likely(v)) {
43516             int one = 1; int is_little = (int)*(unsigned char *)&one;
43517             unsigned char *bytes = (unsigned char *)&val;
43518             int ret = _PyLong_AsByteArray((PyLongObject *)v,
43519                                           bytes, sizeof(val),
43520                                           is_little, !is_unsigned);
43521             Py_DECREF(v);
43522             if (likely(!ret))
43523                 return val;
43524         }
43525         return (int32_t)-1;
43526     }
43527 }
43528
43529 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t val) {
43530     const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
43531     const int is_unsigned = const_zero < neg_one;
43532     if ((sizeof(uint64_t) == sizeof(char))  ||
43533         (sizeof(uint64_t) == sizeof(short))) {
43534         return PyInt_FromLong((long)val);
43535     } else if ((sizeof(uint64_t) == sizeof(int)) ||
43536                (sizeof(uint64_t) == sizeof(long))) {
43537         if (is_unsigned)
43538             return PyLong_FromUnsignedLong((unsigned long)val);
43539         else
43540             return PyInt_FromLong((long)val);
43541     } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
43542         if (is_unsigned)
43543             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
43544         else
43545             return PyLong_FromLongLong((PY_LONG_LONG)val);
43546     } else {
43547         int one = 1; int little = (int)*(unsigned char *)&one;
43548         unsigned char *bytes = (unsigned char *)&val;
43549         return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
43550                                      little, !is_unsigned);
43551     }
43552 }
43553
43554 static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
43555     const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
43556     const int is_unsigned = neg_one > const_zero;
43557     if (sizeof(unsigned char) < sizeof(long)) {
43558         long val = __Pyx_PyInt_AsLong(x);
43559         if (unlikely(val != (long)(unsigned char)val)) {
43560             if (!unlikely(val == -1 && PyErr_Occurred())) {
43561                 PyErr_SetString(PyExc_OverflowError,
43562                     (is_unsigned && unlikely(val < 0)) ?
43563                     "can't convert negative value to unsigned char" :
43564                     "value too large to convert to unsigned char");
43565             }
43566             return (unsigned char)-1;
43567         }
43568         return (unsigned char)val;
43569     }
43570     return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
43571 }
43572
43573 static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
43574     const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
43575     const int is_unsigned = neg_one > const_zero;
43576     if (sizeof(unsigned short) < sizeof(long)) {
43577         long val = __Pyx_PyInt_AsLong(x);
43578         if (unlikely(val != (long)(unsigned short)val)) {
43579             if (!unlikely(val == -1 && PyErr_Occurred())) {
43580                 PyErr_SetString(PyExc_OverflowError,
43581                     (is_unsigned && unlikely(val < 0)) ?
43582                     "can't convert negative value to unsigned short" :
43583                     "value too large to convert to unsigned short");
43584             }
43585             return (unsigned short)-1;
43586         }
43587         return (unsigned short)val;
43588     }
43589     return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
43590 }
43591
43592 static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
43593     const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
43594     const int is_unsigned = neg_one > const_zero;
43595     if (sizeof(unsigned int) < sizeof(long)) {
43596         long val = __Pyx_PyInt_AsLong(x);
43597         if (unlikely(val != (long)(unsigned int)val)) {
43598             if (!unlikely(val == -1 && PyErr_Occurred())) {
43599                 PyErr_SetString(PyExc_OverflowError,
43600                     (is_unsigned && unlikely(val < 0)) ?
43601                     "can't convert negative value to unsigned int" :
43602                     "value too large to convert to unsigned int");
43603             }
43604             return (unsigned int)-1;
43605         }
43606         return (unsigned int)val;
43607     }
43608     return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
43609 }
43610
43611 static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
43612     const char neg_one = (char)-1, const_zero = 0;
43613     const int is_unsigned = neg_one > const_zero;
43614     if (sizeof(char) < sizeof(long)) {
43615         long val = __Pyx_PyInt_AsLong(x);
43616         if (unlikely(val != (long)(char)val)) {
43617             if (!unlikely(val == -1 && PyErr_Occurred())) {
43618                 PyErr_SetString(PyExc_OverflowError,
43619                     (is_unsigned && unlikely(val < 0)) ?
43620                     "can't convert negative value to char" :
43621                     "value too large to convert to char");
43622             }
43623             return (char)-1;
43624         }
43625         return (char)val;
43626     }
43627     return (char)__Pyx_PyInt_AsLong(x);
43628 }
43629
43630 static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
43631     const short neg_one = (short)-1, const_zero = 0;
43632     const int is_unsigned = neg_one > const_zero;
43633     if (sizeof(short) < sizeof(long)) {
43634         long val = __Pyx_PyInt_AsLong(x);
43635         if (unlikely(val != (long)(short)val)) {
43636             if (!unlikely(val == -1 && PyErr_Occurred())) {
43637                 PyErr_SetString(PyExc_OverflowError,
43638                     (is_unsigned && unlikely(val < 0)) ?
43639                     "can't convert negative value to short" :
43640                     "value too large to convert to short");
43641             }
43642             return (short)-1;
43643         }
43644         return (short)val;
43645     }
43646     return (short)__Pyx_PyInt_AsLong(x);
43647 }
43648
43649 static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
43650     const int neg_one = (int)-1, const_zero = 0;
43651     const int is_unsigned = neg_one > const_zero;
43652     if (sizeof(int) < sizeof(long)) {
43653         long val = __Pyx_PyInt_AsLong(x);
43654         if (unlikely(val != (long)(int)val)) {
43655             if (!unlikely(val == -1 && PyErr_Occurred())) {
43656                 PyErr_SetString(PyExc_OverflowError,
43657                     (is_unsigned && unlikely(val < 0)) ?
43658                     "can't convert negative value to int" :
43659                     "value too large to convert to int");
43660             }
43661             return (int)-1;
43662         }
43663         return (int)val;
43664     }
43665     return (int)__Pyx_PyInt_AsLong(x);
43666 }
43667
43668 static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
43669     const signed char neg_one = (signed char)-1, const_zero = 0;
43670     const int is_unsigned = neg_one > const_zero;
43671     if (sizeof(signed char) < sizeof(long)) {
43672         long val = __Pyx_PyInt_AsLong(x);
43673         if (unlikely(val != (long)(signed char)val)) {
43674             if (!unlikely(val == -1 && PyErr_Occurred())) {
43675                 PyErr_SetString(PyExc_OverflowError,
43676                     (is_unsigned && unlikely(val < 0)) ?
43677                     "can't convert negative value to signed char" :
43678                     "value too large to convert to signed char");
43679             }
43680             return (signed char)-1;
43681         }
43682         return (signed char)val;
43683     }
43684     return (signed char)__Pyx_PyInt_AsSignedLong(x);
43685 }
43686
43687 static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
43688     const signed short neg_one = (signed short)-1, const_zero = 0;
43689     const int is_unsigned = neg_one > const_zero;
43690     if (sizeof(signed short) < sizeof(long)) {
43691         long val = __Pyx_PyInt_AsLong(x);
43692         if (unlikely(val != (long)(signed short)val)) {
43693             if (!unlikely(val == -1 && PyErr_Occurred())) {
43694                 PyErr_SetString(PyExc_OverflowError,
43695                     (is_unsigned && unlikely(val < 0)) ?
43696                     "can't convert negative value to signed short" :
43697                     "value too large to convert to signed short");
43698             }
43699             return (signed short)-1;
43700         }
43701         return (signed short)val;
43702     }
43703     return (signed short)__Pyx_PyInt_AsSignedLong(x);
43704 }
43705
43706 static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
43707     const signed int neg_one = (signed int)-1, const_zero = 0;
43708     const int is_unsigned = neg_one > const_zero;
43709     if (sizeof(signed int) < sizeof(long)) {
43710         long val = __Pyx_PyInt_AsLong(x);
43711         if (unlikely(val != (long)(signed int)val)) {
43712             if (!unlikely(val == -1 && PyErr_Occurred())) {
43713                 PyErr_SetString(PyExc_OverflowError,
43714                     (is_unsigned && unlikely(val < 0)) ?
43715                     "can't convert negative value to signed int" :
43716                     "value too large to convert to signed int");
43717             }
43718             return (signed int)-1;
43719         }
43720         return (signed int)val;
43721     }
43722     return (signed int)__Pyx_PyInt_AsSignedLong(x);
43723 }
43724
43725 static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
43726     const int neg_one = (int)-1, const_zero = 0;
43727     const int is_unsigned = neg_one > const_zero;
43728     if (sizeof(int) < sizeof(long)) {
43729         long val = __Pyx_PyInt_AsLong(x);
43730         if (unlikely(val != (long)(int)val)) {
43731             if (!unlikely(val == -1 && PyErr_Occurred())) {
43732                 PyErr_SetString(PyExc_OverflowError,
43733                     (is_unsigned && unlikely(val < 0)) ?
43734                     "can't convert negative value to int" :
43735                     "value too large to convert to int");
43736             }
43737             return (int)-1;
43738         }
43739         return (int)val;
43740     }
43741     return (int)__Pyx_PyInt_AsLong(x);
43742 }
43743
43744 static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
43745     const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
43746     const int is_unsigned = neg_one > const_zero;
43747 #if PY_VERSION_HEX < 0x03000000
43748     if (likely(PyInt_Check(x))) {
43749         long val = PyInt_AS_LONG(x);
43750         if (is_unsigned && unlikely(val < 0)) {
43751             PyErr_SetString(PyExc_OverflowError,
43752                             "can't convert negative value to unsigned long");
43753             return (unsigned long)-1;
43754         }
43755         return (unsigned long)val;
43756     } else
43757 #endif
43758     if (likely(PyLong_Check(x))) {
43759         if (is_unsigned) {
43760             if (unlikely(Py_SIZE(x) < 0)) {
43761                 PyErr_SetString(PyExc_OverflowError,
43762                                 "can't convert negative value to unsigned long");
43763                 return (unsigned long)-1;
43764             }
43765             return (unsigned long)PyLong_AsUnsignedLong(x);
43766         } else {
43767             return (unsigned long)PyLong_AsLong(x);
43768         }
43769     } else {
43770         unsigned long val;
43771         PyObject *tmp = __Pyx_PyNumber_Int(x);
43772         if (!tmp) return (unsigned long)-1;
43773         val = __Pyx_PyInt_AsUnsignedLong(tmp);
43774         Py_DECREF(tmp);
43775         return val;
43776     }
43777 }
43778
43779 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
43780     const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
43781     const int is_unsigned = neg_one > const_zero;
43782 #if PY_VERSION_HEX < 0x03000000
43783     if (likely(PyInt_Check(x))) {
43784         long val = PyInt_AS_LONG(x);
43785         if (is_unsigned && unlikely(val < 0)) {
43786             PyErr_SetString(PyExc_OverflowError,
43787                             "can't convert negative value to unsigned PY_LONG_LONG");
43788             return (unsigned PY_LONG_LONG)-1;
43789         }
43790         return (unsigned PY_LONG_LONG)val;
43791     } else
43792 #endif
43793     if (likely(PyLong_Check(x))) {
43794         if (is_unsigned) {
43795             if (unlikely(Py_SIZE(x) < 0)) {
43796                 PyErr_SetString(PyExc_OverflowError,
43797                                 "can't convert negative value to unsigned PY_LONG_LONG");
43798                 return (unsigned PY_LONG_LONG)-1;
43799             }
43800             return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
43801         } else {
43802             return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
43803         }
43804     } else {
43805         unsigned PY_LONG_LONG val;
43806         PyObject *tmp = __Pyx_PyNumber_Int(x);
43807         if (!tmp) return (unsigned PY_LONG_LONG)-1;
43808         val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
43809         Py_DECREF(tmp);
43810         return val;
43811     }
43812 }
43813
43814 static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
43815     const long neg_one = (long)-1, const_zero = 0;
43816     const int is_unsigned = neg_one > const_zero;
43817 #if PY_VERSION_HEX < 0x03000000
43818     if (likely(PyInt_Check(x))) {
43819         long val = PyInt_AS_LONG(x);
43820         if (is_unsigned && unlikely(val < 0)) {
43821             PyErr_SetString(PyExc_OverflowError,
43822                             "can't convert negative value to long");
43823             return (long)-1;
43824         }
43825         return (long)val;
43826     } else
43827 #endif
43828     if (likely(PyLong_Check(x))) {
43829         if (is_unsigned) {
43830             if (unlikely(Py_SIZE(x) < 0)) {
43831                 PyErr_SetString(PyExc_OverflowError,
43832                                 "can't convert negative value to long");
43833                 return (long)-1;
43834             }
43835             return (long)PyLong_AsUnsignedLong(x);
43836         } else {
43837             return (long)PyLong_AsLong(x);
43838         }
43839     } else {
43840         long val;
43841         PyObject *tmp = __Pyx_PyNumber_Int(x);
43842         if (!tmp) return (long)-1;
43843         val = __Pyx_PyInt_AsLong(tmp);
43844         Py_DECREF(tmp);
43845         return val;
43846     }
43847 }
43848
43849 static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
43850     const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
43851     const int is_unsigned = neg_one > const_zero;
43852 #if PY_VERSION_HEX < 0x03000000
43853     if (likely(PyInt_Check(x))) {
43854         long val = PyInt_AS_LONG(x);
43855         if (is_unsigned && unlikely(val < 0)) {
43856             PyErr_SetString(PyExc_OverflowError,
43857                             "can't convert negative value to PY_LONG_LONG");
43858             return (PY_LONG_LONG)-1;
43859         }
43860         return (PY_LONG_LONG)val;
43861     } else
43862 #endif
43863     if (likely(PyLong_Check(x))) {
43864         if (is_unsigned) {
43865             if (unlikely(Py_SIZE(x) < 0)) {
43866                 PyErr_SetString(PyExc_OverflowError,
43867                                 "can't convert negative value to PY_LONG_LONG");
43868                 return (PY_LONG_LONG)-1;
43869             }
43870             return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
43871         } else {
43872             return (PY_LONG_LONG)PyLong_AsLongLong(x);
43873         }
43874     } else {
43875         PY_LONG_LONG val;
43876         PyObject *tmp = __Pyx_PyNumber_Int(x);
43877         if (!tmp) return (PY_LONG_LONG)-1;
43878         val = __Pyx_PyInt_AsLongLong(tmp);
43879         Py_DECREF(tmp);
43880         return val;
43881     }
43882 }
43883
43884 static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
43885     const signed long neg_one = (signed long)-1, const_zero = 0;
43886     const int is_unsigned = neg_one > const_zero;
43887 #if PY_VERSION_HEX < 0x03000000
43888     if (likely(PyInt_Check(x))) {
43889         long val = PyInt_AS_LONG(x);
43890         if (is_unsigned && unlikely(val < 0)) {
43891             PyErr_SetString(PyExc_OverflowError,
43892                             "can't convert negative value to signed long");
43893             return (signed long)-1;
43894         }
43895         return (signed long)val;
43896     } else
43897 #endif
43898     if (likely(PyLong_Check(x))) {
43899         if (is_unsigned) {
43900             if (unlikely(Py_SIZE(x) < 0)) {
43901                 PyErr_SetString(PyExc_OverflowError,
43902                                 "can't convert negative value to signed long");
43903                 return (signed long)-1;
43904             }
43905             return (signed long)PyLong_AsUnsignedLong(x);
43906         } else {
43907             return (signed long)PyLong_AsLong(x);
43908         }
43909     } else {
43910         signed long val;
43911         PyObject *tmp = __Pyx_PyNumber_Int(x);
43912         if (!tmp) return (signed long)-1;
43913         val = __Pyx_PyInt_AsSignedLong(tmp);
43914         Py_DECREF(tmp);
43915         return val;
43916     }
43917 }
43918
43919 static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
43920     const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
43921     const int is_unsigned = neg_one > const_zero;
43922 #if PY_VERSION_HEX < 0x03000000
43923     if (likely(PyInt_Check(x))) {
43924         long val = PyInt_AS_LONG(x);
43925         if (is_unsigned && unlikely(val < 0)) {
43926             PyErr_SetString(PyExc_OverflowError,
43927                             "can't convert negative value to signed PY_LONG_LONG");
43928             return (signed PY_LONG_LONG)-1;
43929         }
43930         return (signed PY_LONG_LONG)val;
43931     } else
43932 #endif
43933     if (likely(PyLong_Check(x))) {
43934         if (is_unsigned) {
43935             if (unlikely(Py_SIZE(x) < 0)) {
43936                 PyErr_SetString(PyExc_OverflowError,
43937                                 "can't convert negative value to signed PY_LONG_LONG");
43938                 return (signed PY_LONG_LONG)-1;
43939             }
43940             return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
43941         } else {
43942             return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
43943         }
43944     } else {
43945         signed PY_LONG_LONG val;
43946         PyObject *tmp = __Pyx_PyNumber_Int(x);
43947         if (!tmp) return (signed PY_LONG_LONG)-1;
43948         val = __Pyx_PyInt_AsSignedLongLong(tmp);
43949         Py_DECREF(tmp);
43950         return val;
43951     }
43952 }
43953
43954 static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
43955     PyObject *tmp_type, *tmp_value, *tmp_tb;
43956     PyThreadState *tstate = PyThreadState_GET();
43957     tmp_type = tstate->exc_type;
43958     tmp_value = tstate->exc_value;
43959     tmp_tb = tstate->exc_traceback;
43960     tstate->exc_type = *type;
43961     tstate->exc_value = *value;
43962     tstate->exc_traceback = *tb;
43963     *type = tmp_type;
43964     *value = tmp_value;
43965     *tb = tmp_tb;
43966 }
43967
43968 static PyObject *__Pyx_Generator_Next(PyObject *self);
43969 static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
43970 static PyObject *__Pyx_Generator_Close(PyObject *self);
43971 static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args);
43972 static CYTHON_INLINE
43973 void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self)
43974 {
43975     PyObject *exc_type = self->exc_type;
43976     PyObject *exc_value = self->exc_value;
43977     PyObject *exc_traceback = self->exc_traceback;
43978     self->exc_type = NULL;
43979     self->exc_value = NULL;
43980     self->exc_traceback = NULL;
43981     Py_XDECREF(exc_type);
43982     Py_XDECREF(exc_value);
43983     Py_XDECREF(exc_traceback);
43984 }
43985 static CYTHON_INLINE
43986 PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value)
43987 {
43988     PyObject *retval;
43989     if (unlikely(self->is_running)) {
43990         PyErr_SetString(PyExc_ValueError,
43991                         "generator already executing");
43992         return NULL;
43993     }
43994     if (unlikely(self->resume_label == 0)) {
43995         if (unlikely(value && value != Py_None)) {
43996             PyErr_SetString(PyExc_TypeError,
43997                             "can't send non-None value to a "
43998                             "just-started generator");
43999             return NULL;
44000         }
44001     }
44002     if (unlikely(self->resume_label == -1)) {
44003         PyErr_SetNone(PyExc_StopIteration);
44004         return NULL;
44005     }
44006     if (value)
44007         __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback);
44008     else
44009         __Pyx_Generator_ExceptionClear(self);
44010     self->is_running = 1;
44011     retval = self->body((PyObject *) self, value);
44012     self->is_running = 0;
44013     if (retval)
44014         __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback);
44015     else
44016         __Pyx_Generator_ExceptionClear(self);
44017     return retval;
44018 }
44019 static PyObject *__Pyx_Generator_Next(PyObject *self)
44020 {
44021     return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, Py_None);
44022 }
44023 static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value)
44024 {
44025     return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, value);
44026 }
44027 static PyObject *__Pyx_Generator_Close(PyObject *self)
44028 {
44029     __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self;
44030     PyObject *retval;
44031 #if PY_VERSION_HEX < 0x02050000
44032     PyErr_SetNone(PyExc_StopIteration);
44033 #else
44034     PyErr_SetNone(PyExc_GeneratorExit);
44035 #endif
44036     retval = __Pyx_Generator_SendEx(generator, NULL);
44037     if (retval) {
44038         Py_DECREF(retval);
44039         PyErr_SetString(PyExc_RuntimeError,
44040                         "generator ignored GeneratorExit");
44041         return NULL;
44042     }
44043 #if PY_VERSION_HEX < 0x02050000
44044     if (PyErr_ExceptionMatches(PyExc_StopIteration))
44045 #else
44046     if (PyErr_ExceptionMatches(PyExc_StopIteration)
44047         || PyErr_ExceptionMatches(PyExc_GeneratorExit))
44048 #endif
44049     {
44050         PyErr_Clear();          /* ignore these errors */
44051         Py_INCREF(Py_None);
44052         return Py_None;
44053     }
44054     return NULL;
44055 }
44056 static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args)
44057 {
44058     __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self;
44059     PyObject *typ;
44060     PyObject *tb = NULL;
44061     PyObject *val = NULL;
44062     if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
44063         return NULL;
44064     __Pyx_Raise(typ, val, tb, NULL);
44065     return __Pyx_Generator_SendEx(generator, NULL);
44066 }
44067 static int
44068 __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg)
44069 {
44070     __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
44071     Py_VISIT(gen->closure);
44072     Py_VISIT(gen->classobj);
44073     Py_VISIT(gen->exc_type);
44074     Py_VISIT(gen->exc_value);
44075     Py_VISIT(gen->exc_traceback);
44076     return 0;
44077 }
44078 static void
44079 __Pyx_Generator_dealloc(PyObject *self)
44080 {
44081     __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
44082     PyObject_GC_UnTrack(gen);
44083     if (gen->gi_weakreflist != NULL)
44084         PyObject_ClearWeakRefs(self);
44085     PyObject_GC_Track(self);
44086     if (gen->resume_label > 0) {
44087         Py_TYPE(gen)->tp_del(self);
44088         if (self->ob_refcnt > 0)
44089             return;                     /* resurrected.  :( */
44090     }
44091     PyObject_GC_UnTrack(self);
44092     Py_CLEAR(gen->closure);
44093     Py_CLEAR(gen->classobj);
44094     Py_CLEAR(gen->exc_type);
44095     Py_CLEAR(gen->exc_value);
44096     Py_CLEAR(gen->exc_traceback);
44097     PyObject_GC_Del(gen);
44098 }
44099 static void
44100 __Pyx_Generator_del(PyObject *self)
44101 {
44102     PyObject *res;
44103     PyObject *error_type, *error_value, *error_traceback;
44104     __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
44105     if (gen->resume_label <= 0)
44106         return ;
44107     assert(self->ob_refcnt == 0);
44108     self->ob_refcnt = 1;
44109     __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
44110     res = __Pyx_Generator_Close(self);
44111     if (res == NULL)
44112         PyErr_WriteUnraisable(self);
44113     else
44114         Py_DECREF(res);
44115     __Pyx_ErrRestore(error_type, error_value, error_traceback);
44116     /* Undo the temporary resurrection; can't use DECREF here, it would
44117      * cause a recursive call.
44118      */
44119     assert(self->ob_refcnt > 0);
44120     if (--self->ob_refcnt == 0)
44121         return; /* this is the normal path out */
44122     /* close() resurrected it!  Make it look like the original Py_DECREF
44123      * never happened.
44124      */
44125     {
44126         Py_ssize_t refcnt = self->ob_refcnt;
44127         _Py_NewReference(self);
44128         self->ob_refcnt = refcnt;
44129     }
44130     assert(PyType_IS_GC(self->ob_type) &&
44131            _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
44132     /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
44133      * we need to undo that. */
44134     _Py_DEC_REFTOTAL;
44135     /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
44136      * chain, so no more to do there.
44137      * If COUNT_ALLOCS, the original decref bumped tp_frees, and
44138      * _Py_NewReference bumped tp_allocs:  both of those need to be
44139      * undone.
44140      */
44141 #ifdef COUNT_ALLOCS
44142     --self->ob_type->tp_frees;
44143     --self->ob_type->tp_allocs;
44144 #endif
44145 }
44146 static PyMemberDef __pyx_Generator_memberlist[] = {
44147     {(char *) "gi_running",
44148      T_INT,
44149      offsetof(__pyx_GeneratorObject, is_running),
44150      READONLY,
44151      NULL},
44152     {0, 0, 0, 0, 0}
44153 };
44154 static PyMethodDef __pyx_Generator_methods[] = {
44155     {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
44156     {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
44157     {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
44158     {0, 0, 0, 0}
44159 };
44160 static PyTypeObject __pyx_GeneratorType = {
44161     PyVarObject_HEAD_INIT(0, 0)
44162     __Pyx_NAMESTR("generator"),         /*tp_name*/
44163     sizeof(__pyx_GeneratorObject),      /*tp_basicsize*/
44164     0,                                  /*tp_itemsize*/
44165     (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/
44166     0,                                  /*tp_print*/
44167     0,                                  /*tp_getattr*/
44168     0,                                  /*tp_setattr*/
44169 #if PY_MAJOR_VERSION < 3
44170     0,                                  /*tp_compare*/
44171 #else
44172     0,                                  /*reserved*/
44173 #endif
44174     0,                                   /*tp_repr*/
44175     0,                                  /*tp_as_number*/
44176     0,                                  /*tp_as_sequence*/
44177     0,                                  /*tp_as_mapping*/
44178     0,                                  /*tp_hash*/
44179     0,                                  /*tp_call*/
44180     0,                                  /*tp_str*/
44181     PyObject_GenericGetAttr,            /*tp_getattro*/
44182     0,                                  /*tp_setattro*/
44183     0,                                  /*tp_as_buffer*/
44184     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/
44185     0,                                  /*tp_doc*/
44186     (traverseproc) __Pyx_Generator_traverse,   /*tp_traverse*/
44187     0,                                  /*tp_clear*/
44188     0,                                  /*tp_richcompare*/
44189     offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */
44190     PyObject_SelfIter,                  /*tp_iter*/
44191     (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/
44192     __pyx_Generator_methods,            /*tp_methods*/
44193     __pyx_Generator_memberlist,         /*tp_members*/
44194     0,                                  /*tp_getset*/
44195     0,                                  /*tp_base*/
44196     0,                                  /*tp_dict*/
44197     0,                                  /*tp_descr_get*/
44198     0,                                  /*tp_descr_set*/
44199     0,                                  /*tp_dictoffset*/
44200     0,                                  /*tp_init*/
44201     0,                                  /*tp_alloc*/
44202     0,                                  /*tp_new*/
44203     0,                                  /*tp_free*/
44204     0,                                  /*tp_is_gc*/
44205     0,                                  /*tp_bases*/
44206     0,                                  /*tp_mro*/
44207     0,                                  /*tp_cache*/
44208     0,                                  /*tp_subclasses*/
44209     0,                                  /*tp_weaklist*/
44210     __Pyx_Generator_del,                /*tp_del*/
44211 #if PY_VERSION_HEX >= 0x02060000
44212     0,                                  /*tp_version_tag*/
44213 #endif
44214 };
44215 static
44216 __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
44217                                            PyObject *closure)
44218 {
44219     __pyx_GeneratorObject *gen =
44220         PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType);
44221     if (gen == NULL)
44222         return NULL;
44223     gen->body = body;
44224     gen->closure = closure;
44225     Py_XINCREF(closure);
44226     gen->is_running = 0;
44227     gen->resume_label = 0;
44228     gen->classobj = NULL;
44229     gen->exc_type = NULL;
44230     gen->exc_value = NULL;
44231     gen->exc_traceback = NULL;
44232     gen->gi_weakreflist = NULL;
44233     PyObject_GC_Track(gen);
44234     return gen;
44235 }
44236 static int __pyx_Generator_init(void)
44237 {
44238     return PyType_Ready(&__pyx_GeneratorType);
44239 }
44240
44241 static void __Pyx_WriteUnraisable(const char *name, int clineno,
44242                                   int lineno, const char *filename) {
44243     PyObject *old_exc, *old_val, *old_tb;
44244     PyObject *ctx;
44245     __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
44246     #if PY_MAJOR_VERSION < 3
44247     ctx = PyString_FromString(name);
44248     #else
44249     ctx = PyUnicode_FromString(name);
44250     #endif
44251     __Pyx_ErrRestore(old_exc, old_val, old_tb);
44252     if (!ctx) {
44253         PyErr_WriteUnraisable(Py_None);
44254     } else {
44255         PyErr_WriteUnraisable(ctx);
44256         Py_DECREF(ctx);
44257     }
44258 }
44259
44260 static int __Pyx_check_binary_version(void) {
44261     char ctversion[4], rtversion[4];
44262     PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
44263     PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
44264     if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
44265         char message[200];
44266         PyOS_snprintf(message, sizeof(message),
44267                       "compiletime version %s of module '%.100s' "
44268                       "does not match runtime version %s",
44269                       ctversion, __Pyx_MODULE_NAME, rtversion);
44270         #if PY_VERSION_HEX < 0x02050000
44271         return PyErr_Warn(NULL, message);
44272         #else
44273         return PyErr_WarnEx(NULL, message, 1);
44274         #endif
44275     }
44276     return 0;
44277 }
44278
44279 static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
44280 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
44281     PyObject *ob = PyCapsule_New(vtable, 0, 0);
44282 #else
44283     PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
44284 #endif
44285     if (!ob)
44286         goto bad;
44287     if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
44288         goto bad;
44289     Py_DECREF(ob);
44290     return 0;
44291 bad:
44292     Py_XDECREF(ob);
44293     return -1;
44294 }
44295
44296 #ifndef __PYX_HAVE_RT_ImportType
44297 #define __PYX_HAVE_RT_ImportType
44298 static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
44299     size_t size, int strict)
44300 {
44301     PyObject *py_module = 0;
44302     PyObject *result = 0;
44303     PyObject *py_name = 0;
44304     char warning[200];
44305     py_module = __Pyx_ImportModule(module_name);
44306     if (!py_module)
44307         goto bad;
44308     py_name = __Pyx_PyIdentifier_FromString(class_name);
44309     if (!py_name)
44310         goto bad;
44311     result = PyObject_GetAttr(py_module, py_name);
44312     Py_DECREF(py_name);
44313     py_name = 0;
44314     Py_DECREF(py_module);
44315     py_module = 0;
44316     if (!result)
44317         goto bad;
44318     if (!PyType_Check(result)) {
44319         PyErr_Format(PyExc_TypeError,
44320             "%s.%s is not a type object",
44321             module_name, class_name);
44322         goto bad;
44323     }
44324     if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
44325         PyOS_snprintf(warning, sizeof(warning),
44326             "%s.%s size changed, may indicate binary incompatibility",
44327             module_name, class_name);
44328         #if PY_VERSION_HEX < 0x02050000
44329         if (PyErr_Warn(NULL, warning) < 0) goto bad;
44330         #else
44331         if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
44332         #endif
44333     }
44334     else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
44335         PyErr_Format(PyExc_ValueError,
44336             "%s.%s has the wrong size, try recompiling",
44337             module_name, class_name);
44338         goto bad;
44339     }
44340     return (PyTypeObject *)result;
44341 bad:
44342     Py_XDECREF(py_module);
44343     Py_XDECREF(result);
44344     return NULL;
44345 }
44346 #endif
44347
44348 #ifndef __PYX_HAVE_RT_ImportModule
44349 #define __PYX_HAVE_RT_ImportModule
44350 static PyObject *__Pyx_ImportModule(const char *name) {
44351     PyObject *py_name = 0;
44352     PyObject *py_module = 0;
44353     py_name = __Pyx_PyIdentifier_FromString(name);
44354     if (!py_name)
44355         goto bad;
44356     py_module = PyImport_Import(py_name);
44357     Py_DECREF(py_name);
44358     return py_module;
44359 bad:
44360     Py_XDECREF(py_name);
44361     return 0;
44362 }
44363 #endif
44364
44365 static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
44366     int start = 0, mid = 0, end = count - 1;
44367     if (end >= 0 && code_line > entries[end].code_line) {
44368         return count;
44369     }
44370     while (start < end) {
44371         mid = (start + end) / 2;
44372         if (code_line < entries[mid].code_line) {
44373             end = mid;
44374         } else if (code_line > entries[mid].code_line) {
44375              start = mid + 1;
44376         } else {
44377             return mid;
44378         }
44379     }
44380     if (code_line <= entries[mid].code_line) {
44381         return mid;
44382     } else {
44383         return mid + 1;
44384     }
44385 }
44386 static PyCodeObject *__pyx_find_code_object(int code_line) {
44387     PyCodeObject* code_object;
44388     int pos;
44389     if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
44390         return NULL;
44391     }
44392     pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
44393     if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
44394         return NULL;
44395     }
44396     code_object = __pyx_code_cache.entries[pos].code_object;
44397     Py_INCREF(code_object);
44398     return code_object;
44399 }
44400 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
44401     int pos, i;
44402     __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
44403     if (unlikely(!code_line)) {
44404         return;
44405     }
44406     if (unlikely(!entries)) {
44407         entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
44408         if (likely(entries)) {
44409             __pyx_code_cache.entries = entries;
44410             __pyx_code_cache.max_count = 64;
44411             __pyx_code_cache.count = 1;
44412             entries[0].code_line = code_line;
44413             entries[0].code_object = code_object;
44414             Py_INCREF(code_object);
44415         }
44416         return;
44417     }
44418     pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
44419     if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
44420         PyCodeObject* tmp = entries[pos].code_object;
44421         entries[pos].code_object = code_object;
44422         Py_DECREF(tmp);
44423         return;
44424     }
44425     if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
44426         int new_max = __pyx_code_cache.max_count + 64;
44427         entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
44428             __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
44429         if (unlikely(!entries)) {
44430             return;
44431         }
44432         __pyx_code_cache.entries = entries;
44433         __pyx_code_cache.max_count = new_max;
44434     }
44435     for (i=__pyx_code_cache.count; i>pos; i--) {
44436         entries[i] = entries[i-1];
44437     }
44438     entries[pos].code_line = code_line;
44439     entries[pos].code_object = code_object;
44440     __pyx_code_cache.count++;
44441     Py_INCREF(code_object);
44442 }
44443
44444 #include "compile.h"
44445 #include "frameobject.h"
44446 #include "traceback.h"
44447 static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
44448             const char *funcname, int c_line,
44449             int py_line, const char *filename) {
44450     PyCodeObject *py_code = 0;
44451     PyObject *py_srcfile = 0;
44452     PyObject *py_funcname = 0;
44453     #if PY_MAJOR_VERSION < 3
44454     py_srcfile = PyString_FromString(filename);
44455     #else
44456     py_srcfile = PyUnicode_FromString(filename);
44457     #endif
44458     if (!py_srcfile) goto bad;
44459     if (c_line) {
44460         #if PY_MAJOR_VERSION < 3
44461         py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
44462         #else
44463         py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
44464         #endif
44465     }
44466     else {
44467         #if PY_MAJOR_VERSION < 3
44468         py_funcname = PyString_FromString(funcname);
44469         #else
44470         py_funcname = PyUnicode_FromString(funcname);
44471         #endif
44472     }
44473     if (!py_funcname) goto bad;
44474     py_code = __Pyx_PyCode_New(
44475         0,            /*int argcount,*/
44476         0,            /*int kwonlyargcount,*/
44477         0,            /*int nlocals,*/
44478         0,            /*int stacksize,*/
44479         0,            /*int flags,*/
44480         __pyx_empty_bytes, /*PyObject *code,*/
44481         __pyx_empty_tuple, /*PyObject *consts,*/
44482         __pyx_empty_tuple, /*PyObject *names,*/
44483         __pyx_empty_tuple, /*PyObject *varnames,*/
44484         __pyx_empty_tuple, /*PyObject *freevars,*/
44485         __pyx_empty_tuple, /*PyObject *cellvars,*/
44486         py_srcfile,   /*PyObject *filename,*/
44487         py_funcname,  /*PyObject *name,*/
44488         py_line,      /*int firstlineno,*/
44489         __pyx_empty_bytes  /*PyObject *lnotab*/
44490     );
44491     Py_DECREF(py_srcfile);
44492     Py_DECREF(py_funcname);
44493     return py_code;
44494 bad:
44495     Py_XDECREF(py_srcfile);
44496     Py_XDECREF(py_funcname);
44497     return NULL;
44498 }
44499 static void __Pyx_AddTraceback(const char *funcname, int c_line,
44500                                int py_line, const char *filename) {
44501     PyCodeObject *py_code = 0;
44502     PyObject *py_globals = 0;
44503     PyFrameObject *py_frame = 0;
44504     py_code = __pyx_find_code_object(c_line ? c_line : py_line);
44505     if (!py_code) {
44506         py_code = __Pyx_CreateCodeObjectForTraceback(
44507             funcname, c_line, py_line, filename);
44508         if (!py_code) goto bad;
44509         __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
44510     }
44511     py_globals = PyModule_GetDict(__pyx_m);
44512     if (!py_globals) goto bad;
44513     py_frame = PyFrame_New(
44514         PyThreadState_GET(), /*PyThreadState *tstate,*/
44515         py_code,             /*PyCodeObject *code,*/
44516         py_globals,          /*PyObject *globals,*/
44517         0                    /*PyObject *locals*/
44518     );
44519     if (!py_frame) goto bad;
44520     py_frame->f_lineno = py_line;
44521     PyTraceBack_Here(py_frame);
44522 bad:
44523     Py_XDECREF(py_code);
44524     Py_XDECREF(py_frame);
44525 }
44526
44527 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
44528     while (t->p) {
44529         #if PY_MAJOR_VERSION < 3
44530         if (t->is_unicode) {
44531             *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
44532         } else if (t->intern) {
44533             *t->p = PyString_InternFromString(t->s);
44534         } else {
44535             *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
44536         }
44537         #else  /* Python 3+ has unicode identifiers */
44538         if (t->is_unicode | t->is_str) {
44539             if (t->intern) {
44540                 *t->p = PyUnicode_InternFromString(t->s);
44541             } else if (t->encoding) {
44542                 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
44543             } else {
44544                 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
44545             }
44546         } else {
44547             *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
44548         }
44549         #endif
44550         if (!*t->p)
44551             return -1;
44552         ++t;
44553     }
44554     return 0;
44555 }
44556
44557
44558 /* Type Conversion Functions */
44559
44560 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
44561    int is_true = x == Py_True;
44562    if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
44563    else return PyObject_IsTrue(x);
44564 }
44565
44566 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
44567   PyNumberMethods *m;
44568   const char *name = NULL;
44569   PyObject *res = NULL;
44570 #if PY_VERSION_HEX < 0x03000000
44571   if (PyInt_Check(x) || PyLong_Check(x))
44572 #else
44573   if (PyLong_Check(x))
44574 #endif
44575     return Py_INCREF(x), x;
44576   m = Py_TYPE(x)->tp_as_number;
44577 #if PY_VERSION_HEX < 0x03000000
44578   if (m && m->nb_int) {
44579     name = "int";
44580     res = PyNumber_Int(x);
44581   }
44582   else if (m && m->nb_long) {
44583     name = "long";
44584     res = PyNumber_Long(x);
44585   }
44586 #else
44587   if (m && m->nb_int) {
44588     name = "int";
44589     res = PyNumber_Long(x);
44590   }
44591 #endif
44592   if (res) {
44593 #if PY_VERSION_HEX < 0x03000000
44594     if (!PyInt_Check(res) && !PyLong_Check(res)) {
44595 #else
44596     if (!PyLong_Check(res)) {
44597 #endif
44598       PyErr_Format(PyExc_TypeError,
44599                    "__%s__ returned non-%s (type %.200s)",
44600                    name, name, Py_TYPE(res)->tp_name);
44601       Py_DECREF(res);
44602       return NULL;
44603     }
44604   }
44605   else if (!PyErr_Occurred()) {
44606     PyErr_SetString(PyExc_TypeError,
44607                     "an integer is required");
44608   }
44609   return res;
44610 }
44611
44612 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
44613   Py_ssize_t ival;
44614   PyObject* x = PyNumber_Index(b);
44615   if (!x) return -1;
44616   ival = PyInt_AsSsize_t(x);
44617   Py_DECREF(x);
44618   return ival;
44619 }
44620
44621 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
44622 #if PY_VERSION_HEX < 0x02050000
44623    if (ival <= LONG_MAX)
44624        return PyInt_FromLong((long)ival);
44625    else {
44626        unsigned char *bytes = (unsigned char *) &ival;
44627        int one = 1; int little = (int)*(unsigned char*)&one;
44628        return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
44629    }
44630 #else
44631    return PyInt_FromSize_t(ival);
44632 #endif
44633 }
44634
44635 static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
44636    unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
44637    if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
44638        return (size_t)-1;
44639    } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
44640        PyErr_SetString(PyExc_OverflowError,
44641                        "value too large to convert to size_t");
44642        return (size_t)-1;
44643    }
44644    return (size_t)val;
44645 }
44646
44647
44648 #endif /* Py_PYTHON_H */