Imported Upstream version 0.6
[pysam.git] / pysam / csamtools.c
1 /* Generated by Cython 0.14.1 on Fri Nov 25 19:51:23 2011 */
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 #else
8
9 #include <stddef.h> /* For offsetof */
10 #ifndef offsetof
11 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
12 #endif
13
14 #if !defined(WIN32) && !defined(MS_WINDOWS)
15   #ifndef __stdcall
16     #define __stdcall
17   #endif
18   #ifndef __cdecl
19     #define __cdecl
20   #endif
21   #ifndef __fastcall
22     #define __fastcall
23   #endif
24 #endif
25
26 #ifndef DL_IMPORT
27   #define DL_IMPORT(t) t
28 #endif
29 #ifndef DL_EXPORT
30   #define DL_EXPORT(t) t
31 #endif
32
33 #ifndef PY_LONG_LONG
34   #define PY_LONG_LONG LONG_LONG
35 #endif
36
37 #if PY_VERSION_HEX < 0x02040000
38   #define METH_COEXIST 0
39   #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
40   #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
41 #endif
42
43 #if PY_VERSION_HEX < 0x02050000
44   typedef int Py_ssize_t;
45   #define PY_SSIZE_T_MAX INT_MAX
46   #define PY_SSIZE_T_MIN INT_MIN
47   #define PY_FORMAT_SIZE_T ""
48   #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
49   #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
50   #define PyNumber_Index(o)    PyNumber_Int(o)
51   #define PyIndex_Check(o)     PyNumber_Check(o)
52   #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
53 #endif
54
55 #if PY_VERSION_HEX < 0x02060000
56   #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
57   #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
58   #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
59   #define PyVarObject_HEAD_INIT(type, size) \
60           PyObject_HEAD_INIT(type) size,
61   #define PyType_Modified(t)
62
63   typedef struct {
64      void *buf;
65      PyObject *obj;
66      Py_ssize_t len;
67      Py_ssize_t itemsize;
68      int readonly;
69      int ndim;
70      char *format;
71      Py_ssize_t *shape;
72      Py_ssize_t *strides;
73      Py_ssize_t *suboffsets;
74      void *internal;
75   } Py_buffer;
76
77   #define PyBUF_SIMPLE 0
78   #define PyBUF_WRITABLE 0x0001
79   #define PyBUF_FORMAT 0x0004
80   #define PyBUF_ND 0x0008
81   #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
82   #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
83   #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
84   #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
85   #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
86
87 #endif
88
89 #if PY_MAJOR_VERSION < 3
90   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
91 #else
92   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
93 #endif
94
95 #if PY_MAJOR_VERSION >= 3
96   #define Py_TPFLAGS_CHECKTYPES 0
97   #define Py_TPFLAGS_HAVE_INDEX 0
98 #endif
99
100 #if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
101   #define Py_TPFLAGS_HAVE_NEWBUFFER 0
102 #endif
103
104 #if PY_MAJOR_VERSION >= 3
105   #define PyBaseString_Type            PyUnicode_Type
106   #define PyStringObject               PyUnicodeObject
107   #define PyString_Type                PyUnicode_Type
108   #define PyString_Check               PyUnicode_Check
109   #define PyString_CheckExact          PyUnicode_CheckExact
110 #endif
111
112 #if PY_VERSION_HEX < 0x02060000
113   #define PyBytesObject                PyStringObject
114   #define PyBytes_Type                 PyString_Type
115   #define PyBytes_Check                PyString_Check
116   #define PyBytes_CheckExact           PyString_CheckExact
117   #define PyBytes_FromString           PyString_FromString
118   #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
119   #define PyBytes_FromFormat           PyString_FromFormat
120   #define PyBytes_DecodeEscape         PyString_DecodeEscape
121   #define PyBytes_AsString             PyString_AsString
122   #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
123   #define PyBytes_Size                 PyString_Size
124   #define PyBytes_AS_STRING            PyString_AS_STRING
125   #define PyBytes_GET_SIZE             PyString_GET_SIZE
126   #define PyBytes_Repr                 PyString_Repr
127   #define PyBytes_Concat               PyString_Concat
128   #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
129 #endif
130
131 #if PY_VERSION_HEX < 0x02060000
132   #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
133   #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
134 #endif
135 #ifndef PySet_CheckExact
136   #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
137 #endif
138
139 #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
140
141 #if PY_MAJOR_VERSION >= 3
142   #define PyIntObject                  PyLongObject
143   #define PyInt_Type                   PyLong_Type
144   #define PyInt_Check(op)              PyLong_Check(op)
145   #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
146   #define PyInt_FromString             PyLong_FromString
147   #define PyInt_FromUnicode            PyLong_FromUnicode
148   #define PyInt_FromLong               PyLong_FromLong
149   #define PyInt_FromSize_t             PyLong_FromSize_t
150   #define PyInt_FromSsize_t            PyLong_FromSsize_t
151   #define PyInt_AsLong                 PyLong_AsLong
152   #define PyInt_AS_LONG                PyLong_AS_LONG
153   #define PyInt_AsSsize_t              PyLong_AsSsize_t
154   #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
155   #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
156 #endif
157
158 #if PY_MAJOR_VERSION >= 3
159   #define PyBoolObject                 PyLongObject
160 #endif
161
162
163 #if PY_MAJOR_VERSION >= 3
164   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
165   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
166 #else
167   #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
168   #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
169 #endif
170
171 #if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
172   #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
173   #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
174   #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
175 #else
176   #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
177         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
178         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
179             (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
180   #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
181         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
182         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
183             (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
184   #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
185         (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
186         (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
187             (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
188 #endif
189
190 #if PY_MAJOR_VERSION >= 3
191   #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
192 #endif
193
194 #if PY_VERSION_HEX < 0x02050000
195   #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
196   #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
197   #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
198 #else
199   #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
200   #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
201   #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
202 #endif
203
204 #if PY_VERSION_HEX < 0x02050000
205   #define __Pyx_NAMESTR(n) ((char *)(n))
206   #define __Pyx_DOCSTR(n)  ((char *)(n))
207 #else
208   #define __Pyx_NAMESTR(n) (n)
209   #define __Pyx_DOCSTR(n)  (n)
210 #endif
211
212 #ifdef __cplusplus
213 #define __PYX_EXTERN_C extern "C"
214 #else
215 #define __PYX_EXTERN_C extern
216 #endif
217
218 #if defined(WIN32) || defined(MS_WINDOWS)
219 #define _USE_MATH_DEFINES
220 #endif
221 #include <math.h>
222 #define __PYX_HAVE_API__csamtools
223 #include "string.h"
224 #include "stdlib.h"
225 #include "math.h"
226 #include "stdio.h"
227 #include "ctype.h"
228 #include "unistd.h"
229 #include "fileobject.h"
230 #include "razf.h"
231 #include "stdint.h"
232 #include "bam.h"
233 #include "sam.h"
234 #include "faidx.h"
235 #include "pysam_util.h"
236 #include "pythread.h"
237
238 #ifdef PYREX_WITHOUT_ASSERTIONS
239 #define CYTHON_WITHOUT_ASSERTIONS
240 #endif
241
242
243 /* inline attribute */
244 #ifndef CYTHON_INLINE
245   #if defined(__GNUC__)
246     #define CYTHON_INLINE __inline__
247   #elif defined(_MSC_VER)
248     #define CYTHON_INLINE __inline
249   #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
250     #define CYTHON_INLINE inline
251   #else
252     #define CYTHON_INLINE
253   #endif
254 #endif
255
256 /* unused attribute */
257 #ifndef CYTHON_UNUSED
258 # if defined(__GNUC__)
259 #   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
260 #     define CYTHON_UNUSED __attribute__ ((__unused__))
261 #   else
262 #     define CYTHON_UNUSED
263 #   endif
264 # elif defined(__ICC) || defined(__INTEL_COMPILER)
265 #   define CYTHON_UNUSED __attribute__ ((__unused__))
266 # else
267 #   define CYTHON_UNUSED
268 # endif
269 #endif
270
271 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*/
272
273
274 /* Type Conversion Predeclarations */
275
276 #define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
277 #define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))
278
279 #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
280 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
281 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
282
283 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
284 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
285 static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);
286
287 #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
288
289
290 #ifdef __GNUC__
291 /* Test for GCC > 2.95 */
292 #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
293 #define likely(x)   __builtin_expect(!!(x), 1)
294 #define unlikely(x) __builtin_expect(!!(x), 0)
295 #else /* __GNUC__ > 2 ... */
296 #define likely(x)   (x)
297 #define unlikely(x) (x)
298 #endif /* __GNUC__ > 2 ... */
299 #else /* __GNUC__ */
300 #define likely(x)   (x)
301 #define unlikely(x) (x)
302 #endif /* __GNUC__ */
303     
304 static PyObject *__pyx_m;
305 static PyObject *__pyx_b;
306 static PyObject *__pyx_empty_tuple;
307 static PyObject *__pyx_empty_bytes;
308 static int __pyx_lineno;
309 static int __pyx_clineno = 0;
310 static const char * __pyx_cfilenm= __FILE__;
311 static const char *__pyx_filename;
312
313
314 static const char *__pyx_f[] = {
315   "csamtools.pyx",
316   "csamtools.pxd",
317   "bool.pxd",
318   "complex.pxd",
319 };
320
321 /* Type declarations */
322
323 /* "csamtools.pyx":388
324  *      counter[0] += 1;
325  * 
326  * ctypedef struct MateData:             # <<<<<<<<<<<<<<
327  *      char * name
328  *      bam1_t * mate
329  */
330
331 typedef struct {
332   char *name;
333   bam1_t *mate;
334   uint32_t flag;
335 } __pyx_t_9csamtools_MateData;
336
337 /* "csamtools.pyx":1537
338  * ##-------------------------------------------------------------------
339  * ##-------------------------------------------------------------------
340  * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
341  *     samfile_t * samfile
342  *     bam_iter_t iter
343  */
344
345 typedef struct {
346   samfile_t *samfile;
347   bam_iter_t iter;
348   faidx_t *fastafile;
349   int tid;
350   char *seq;
351   int seq_len;
352 } __pyx_t_9csamtools___iterdata;
353
354 /* "csamtools.pyx":1717
355  *         bam_plp_set_mask( self.pileup_iter, self.mask )
356  * 
357  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
358  *                             int tid,
359  *                             int start,
360  */
361
362 struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData {
363   int __pyx_n;
364   int reopen;
365 };
366
367 /* "csamtools.pyx":91
368  *      return dest
369  * 
370  * cdef class PileupRead             # <<<<<<<<<<<<<<
371  * cdef makePileupRead( bam_pileup1_t * src ):
372  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
373  */
374
375 struct __pyx_obj_9csamtools_PileupRead {
376   PyObject_HEAD
377   struct __pyx_obj_9csamtools_AlignedRead *_alignment;
378   int32_t _qpos;
379   int _indel;
380   int _level;
381   uint32_t _is_del;
382   uint32_t _is_head;
383   uint32_t _is_tail;
384 };
385
386 /* "csamtools.pxd":423
387  *     cdef char * _getrname( self, int tid )
388  * 
389  * cdef class IteratorRow:             # <<<<<<<<<<<<<<
390  *     pass
391  * 
392  */
393
394 struct __pyx_obj_9csamtools_IteratorRow {
395   PyObject_HEAD
396 };
397
398 /* "csamtools.pyx":1415
399  *         if self.owns_samfile: samclose( self.fp )
400  * 
401  * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
402  *     """iterates over all mapped reads by chaining iterators over each reference
403  *     """
404  */
405
406 struct __pyx_obj_9csamtools_IteratorRowAllRefs {
407   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
408   struct __pyx_obj_9csamtools_Samfile *samfile;
409   int tid;
410   struct __pyx_obj_9csamtools_IteratorRowRegion *rowiter;
411 };
412
413 /* "csamtools.pxd":426
414  *     pass
415  * 
416  * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
417  *     cdef bam1_t * b
418  *     cdef samfile_t * fp
419  */
420
421 struct __pyx_obj_9csamtools_IteratorRowAll {
422   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
423   struct __pyx_vtabstruct_9csamtools_IteratorRowAll *__pyx_vtab;
424   bam1_t *b;
425   samfile_t *fp;
426   int owns_samfile;
427 };
428
429 /* "csamtools.pyx":82
430  *     return dest
431  * 
432  * cdef class PileupProxy             # <<<<<<<<<<<<<<
433  * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):
434  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
435  */
436
437 struct __pyx_obj_9csamtools_PileupProxy {
438   PyObject_HEAD
439   bam_pileup1_t *plp;
440   int tid;
441   int pos;
442   int n_pu;
443 };
444
445 /* "csamtools.pyx":1265
446  *     pass
447  * 
448  * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
449  *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
450  * 
451  */
452
453 struct __pyx_obj_9csamtools_IteratorRowRegion {
454   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
455   struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *__pyx_vtab;
456   bam_iter_t iter;
457   bam1_t *b;
458   int retval;
459   struct __pyx_obj_9csamtools_Samfile *samfile;
460   samfile_t *fp;
461   int owns_samfile;
462 };
463
464 /* "csamtools.pyx":244
465  * ## Public methods
466  * ######################################################################
467  * cdef class Fastafile:             # <<<<<<<<<<<<<<
468  *     '''*(filename)*
469  * 
470  */
471
472 struct __pyx_obj_9csamtools_Fastafile {
473   PyObject_HEAD
474   struct __pyx_vtabstruct_9csamtools_Fastafile *__pyx_vtab;
475   char *_filename;
476   faidx_t *fastafile;
477 };
478
479 /* "csamtools.pyx":1461
480  *                 raise StopIteration
481  * 
482  * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
483  *     """*(Samfile samfile)*
484  * 
485  */
486
487 struct __pyx_obj_9csamtools_IteratorRowSelection {
488   struct __pyx_obj_9csamtools_IteratorRow __pyx_base;
489   struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *__pyx_vtab;
490   bam1_t *b;
491   int current_pos;
492   samfile_t *fp;
493   PyObject *positions;
494   int owns_samfile;
495 };
496
497 /* "csamtools.pyx":1601
498  *     return ret
499  * 
500  * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
501  *     '''abstract base class for iterators over columns.
502  * 
503  */
504
505 struct __pyx_obj_9csamtools_IteratorColumn {
506   PyObject_HEAD
507   struct __pyx_vtabstruct_9csamtools_IteratorColumn *__pyx_vtab;
508   struct __pyx_obj_9csamtools_IteratorRowRegion *iter;
509   int tid;
510   int pos;
511   int n_plp;
512   int mask;
513   const bam_pileup1_t * plp;
514   bam_plp_t pileup_iter;
515   __pyx_t_9csamtools___iterdata iterdata;
516   struct __pyx_obj_9csamtools_Samfile *samfile;
517   struct __pyx_obj_9csamtools_Fastafile *fastafile;
518   PyObject *stepper;
519   int max_depth;
520 };
521
522 /* "csamtools.pyx":1806
523  *                                      self.n_plp )
524  * 
525  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
526  *     """iterates over all columns by chaining iterators over each reference
527  *     """
528  */
529
530 struct __pyx_obj_9csamtools_IteratorColumnAllRefs {
531   struct __pyx_obj_9csamtools_IteratorColumn __pyx_base;
532 };
533
534 /* "csamtools.pxd":394
535  *     cdef bam1_t * _delegate
536  * 
537  * cdef class Samfile:             # <<<<<<<<<<<<<<
538  *     cdef char * _filename
539  *     # pointer to samfile
540  */
541
542 struct __pyx_obj_9csamtools_Samfile {
543   PyObject_HEAD
544   struct __pyx_vtabstruct_9csamtools_Samfile *__pyx_vtab;
545   char *_filename;
546   samfile_t *samfile;
547   bam_index_t *index;
548   int isbam;
549   int isstream;
550   int isremote;
551   bam1_t *b;
552   char *mode;
553   int64_t start_offset;
554 };
555
556 /* "csamtools.pyx":2902
557  *     return retval, out_stderr, out_stdout
558  * 
559  * cdef class SNPCall:             # <<<<<<<<<<<<<<
560  *     '''the results of a SNP call.'''
561  *     cdef int _tid
562  */
563
564 struct __pyx_obj_9csamtools_SNPCall {
565   PyObject_HEAD
566   int _tid;
567   int _pos;
568   char _reference_base;
569   char _genotype;
570   int _consensus_quality;
571   int _snp_quality;
572   int _rms_mapping_quality;
573   int _coverage;
574 };
575
576 /* "csamtools.pyx":3456
577  * 
578  * 
579  * cdef class IndexedReads:             # <<<<<<<<<<<<<<
580  *     """index a bamfile by read.
581  * 
582  */
583
584 struct __pyx_obj_9csamtools_IndexedReads {
585   PyObject_HEAD
586   struct __pyx_obj_9csamtools_Samfile *samfile;
587   samfile_t *fp;
588   PyObject *index;
589   int owns_samfile;
590 };
591
592 /* "csamtools.pyx":1777
593  *             self.iterdata.seq = NULL
594  * 
595  * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
596  *     '''iterates over a region only.
597  *     '''
598  */
599
600 struct __pyx_obj_9csamtools_IteratorColumnRegion {
601   struct __pyx_obj_9csamtools_IteratorColumn __pyx_base;
602 };
603
604 /* "csamtools.pxd":389
605  * 
606  * # need to declare all C fields and methods here
607  * cdef class AlignedRead:             # <<<<<<<<<<<<<<
608  * 
609  *     # object that this AlignedRead represents
610  */
611
612 struct __pyx_obj_9csamtools_AlignedRead {
613   PyObject_HEAD
614   bam1_t *_delegate;
615 };
616
617
618 /* "csamtools.pyx":1601
619  *     return ret
620  * 
621  * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
622  *     '''abstract base class for iterators over columns.
623  * 
624  */
625
626 struct __pyx_vtabstruct_9csamtools_IteratorColumn {
627   int (*cnext)(struct __pyx_obj_9csamtools_IteratorColumn *);
628   char *(*getSequence)(struct __pyx_obj_9csamtools_IteratorColumn *);
629   PyObject *(*setMask)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *);
630   PyObject *(*setupIteratorData)(struct __pyx_obj_9csamtools_IteratorColumn *, int, int, int, struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args);
631   PyObject *(*reset)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *);
632 };
633 static struct __pyx_vtabstruct_9csamtools_IteratorColumn *__pyx_vtabptr_9csamtools_IteratorColumn;
634
635
636 /* "csamtools.pyx":1777
637  *             self.iterdata.seq = NULL
638  * 
639  * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
640  *     '''iterates over a region only.
641  *     '''
642  */
643
644 struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion {
645   struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_base;
646 };
647 static struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *__pyx_vtabptr_9csamtools_IteratorColumnRegion;
648
649
650 /* "csamtools.pyx":1265
651  *     pass
652  * 
653  * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
654  *     """*(Samfile samfile, int tid, int beg, int end, int reopen = True )*
655  * 
656  */
657
658 struct __pyx_vtabstruct_9csamtools_IteratorRowRegion {
659   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowRegion *);
660   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowRegion *);
661 };
662 static struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *__pyx_vtabptr_9csamtools_IteratorRowRegion;
663
664
665 /* "csamtools.pyx":1461
666  *                 raise StopIteration
667  * 
668  * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
669  *     """*(Samfile samfile)*
670  * 
671  */
672
673 struct __pyx_vtabstruct_9csamtools_IteratorRowSelection {
674   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowSelection *);
675   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowSelection *);
676 };
677 static struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *__pyx_vtabptr_9csamtools_IteratorRowSelection;
678
679
680 /* "csamtools.pyx":1806
681  *                                      self.n_plp )
682  * 
683  * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
684  *     """iterates over all columns by chaining iterators over each reference
685  *     """
686  */
687
688 struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs {
689   struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_base;
690 };
691 static struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *__pyx_vtabptr_9csamtools_IteratorColumnAllRefs;
692
693
694 /* "csamtools.pyx":415
695  * 
696  * 
697  * cdef class Samfile:             # <<<<<<<<<<<<<<
698  *     '''*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,
699  *          add_sq_text = False )*
700  */
701
702 struct __pyx_vtabstruct_9csamtools_Samfile {
703   bam_header_t *(*_buildHeader)(struct __pyx_obj_9csamtools_Samfile *, PyObject *);
704   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_Samfile *);
705   int (*cnext)(struct __pyx_obj_9csamtools_Samfile *);
706   int (*write)(struct __pyx_obj_9csamtools_Samfile *, struct __pyx_obj_9csamtools_AlignedRead *, int __pyx_skip_dispatch);
707   char *(*_getrname)(struct __pyx_obj_9csamtools_Samfile *, int);
708 };
709 static struct __pyx_vtabstruct_9csamtools_Samfile *__pyx_vtabptr_9csamtools_Samfile;
710
711
712 /* "csamtools.pyx":244
713  * ## Public methods
714  * ######################################################################
715  * cdef class Fastafile:             # <<<<<<<<<<<<<<
716  *     '''*(filename)*
717  * 
718  */
719
720 struct __pyx_vtabstruct_9csamtools_Fastafile {
721   char *(*_fetch)(struct __pyx_obj_9csamtools_Fastafile *, char *, int, int, int *);
722 };
723 static struct __pyx_vtabstruct_9csamtools_Fastafile *__pyx_vtabptr_9csamtools_Fastafile;
724
725
726 /* "csamtools.pyx":1351
727  *         if self.owns_samfile: samclose( self.fp )
728  * 
729  * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
730  *     """*(Samfile samfile, int reopen = True)*
731  * 
732  */
733
734 struct __pyx_vtabstruct_9csamtools_IteratorRowAll {
735   bam1_t *(*getCurrent)(struct __pyx_obj_9csamtools_IteratorRowAll *);
736   int (*cnext)(struct __pyx_obj_9csamtools_IteratorRowAll *);
737 };
738 static struct __pyx_vtabstruct_9csamtools_IteratorRowAll *__pyx_vtabptr_9csamtools_IteratorRowAll;
739
740 #ifndef CYTHON_REFNANNY
741   #define CYTHON_REFNANNY 0
742 #endif
743
744 #if CYTHON_REFNANNY
745   typedef struct {
746     void (*INCREF)(void*, PyObject*, int);
747     void (*DECREF)(void*, PyObject*, int);
748     void (*GOTREF)(void*, PyObject*, int);
749     void (*GIVEREF)(void*, PyObject*, int);
750     void* (*SetupContext)(const char*, int, const char*);
751     void (*FinishContext)(void**);
752   } __Pyx_RefNannyAPIStruct;
753   static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
754   static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
755     PyObject *m = NULL, *p = NULL;
756     void *r = NULL;
757     m = PyImport_ImportModule((char *)modname);
758     if (!m) goto end;
759     p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
760     if (!p) goto end;
761     r = PyLong_AsVoidPtr(p);
762   end:
763     Py_XDECREF(p);
764     Py_XDECREF(m);
765     return (__Pyx_RefNannyAPIStruct *)r;
766   }
767   #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
768   #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
769   #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
770   #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
771   #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
772   #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
773   #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
774 #else
775   #define __Pyx_RefNannySetupContext(name)
776   #define __Pyx_RefNannyFinishContext()
777   #define __Pyx_INCREF(r) Py_INCREF(r)
778   #define __Pyx_DECREF(r) Py_DECREF(r)
779   #define __Pyx_GOTREF(r)
780   #define __Pyx_GIVEREF(r)
781   #define __Pyx_XDECREF(r) Py_XDECREF(r)
782 #endif /* CYTHON_REFNANNY */
783 #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
784 #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)
785
786 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
787
788 #ifndef CYTHON_PROFILE
789   #define CYTHON_PROFILE 1
790 #endif
791
792 #ifndef CYTHON_PROFILE_REUSE_FRAME
793   #define CYTHON_PROFILE_REUSE_FRAME 0
794 #endif
795
796 #if CYTHON_PROFILE
797
798   #include "compile.h"
799   #include "frameobject.h"
800   #include "traceback.h"
801
802   #if CYTHON_PROFILE_REUSE_FRAME
803     #define CYTHON_FRAME_MODIFIER static
804     #define CYTHON_FRAME_DEL
805   #else
806     #define CYTHON_FRAME_MODIFIER
807     #define CYTHON_FRAME_DEL Py_DECREF(__pyx_frame)
808   #endif
809
810   #define __Pyx_TraceDeclarations                                  \
811   static PyCodeObject *__pyx_frame_code = NULL;                      \
812   CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;           \
813   int __Pyx_use_tracing = 0;
814
815   #define __Pyx_TraceCall(funcname, srcfile, firstlineno)                            \
816   if (unlikely(PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc)) {      \
817       __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);  \
818   }
819
820   #define __Pyx_TraceException()                                                           \
821   if (unlikely(__Pyx_use_tracing( && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
822       PyObject *exc_info = __Pyx_GetExceptionTuple();                                      \
823       if (exc_info) {                                                                      \
824           PyThreadState_GET()->c_profilefunc(                                              \
825               PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);  \
826           Py_DECREF(exc_info);                                                             \
827       }                                                                                    \
828   }
829
830   #define __Pyx_TraceReturn(result)                                                  \
831   if (unlikely(__Pyx_use_tracing) && PyThreadState_GET()->use_tracing && PyThreadState_GET()->c_profilefunc) {  \
832       PyThreadState_GET()->c_profilefunc(                                            \
833           PyThreadState_GET()->c_profileobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);     \
834       CYTHON_FRAME_DEL;                                                               \
835   }
836
837   static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
838   static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno); /*proto*/
839
840 #else
841
842   #define __Pyx_TraceDeclarations
843   #define __Pyx_TraceCall(funcname, srcfile, firstlineno)
844   #define __Pyx_TraceException()
845   #define __Pyx_TraceReturn(result)
846
847 #endif /* CYTHON_PROFILE */
848
849 static CYTHON_INLINE PyObject* __Pyx_tp_new(PyObject* type_obj) {
850     return (PyObject*) (((PyTypeObject*)(type_obj))->tp_new(
851         (PyTypeObject*)(type_obj), __pyx_empty_tuple, NULL));
852 }
853
854 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
855
856 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
857
858 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
859
860 static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
861 static int __Pyx_EndUnpack(PyObject *, Py_ssize_t expected); /*proto*/
862
863 static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
864     const char* function_name, int kw_allowed); /*proto*/
865
866 static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
867 static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
868
869 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
870
871 static void __Pyx_RaiseDoubleKeywordsError(
872     const char* func_name, PyObject* kw_name); /*proto*/
873
874 static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/
875
876 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
877     Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
878
879 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
880     const char *name, int exact); /*proto*/
881
882 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
883
884
885 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
886     PyObject *r;
887     if (!j) return NULL;
888     r = PyObject_GetItem(o, j);
889     Py_DECREF(j);
890     return r;
891 }
892
893
894 #define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
895                                                     __Pyx_GetItemInt_List_Fast(o, i) : \
896                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
897
898 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) {
899     if (likely(o != Py_None)) {
900         if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
901             PyObject *r = PyList_GET_ITEM(o, i);
902             Py_INCREF(r);
903             return r;
904         }
905         else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
906             PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
907             Py_INCREF(r);
908             return r;
909         }
910     }
911     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
912 }
913
914 #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
915                                                     __Pyx_GetItemInt_Tuple_Fast(o, i) : \
916                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
917
918 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) {
919     if (likely(o != Py_None)) {
920         if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
921             PyObject *r = PyTuple_GET_ITEM(o, i);
922             Py_INCREF(r);
923             return r;
924         }
925         else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
926             PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
927             Py_INCREF(r);
928             return r;
929         }
930     }
931     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
932 }
933
934
935 #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
936                                                     __Pyx_GetItemInt_Fast(o, i) : \
937                                                     __Pyx_GetItemInt_Generic(o, to_py_func(i)))
938
939 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) {
940     PyObject *r;
941     if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
942         r = PyList_GET_ITEM(o, i);
943         Py_INCREF(r);
944     }
945     else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
946         r = PyTuple_GET_ITEM(o, i);
947         Py_INCREF(r);
948     }
949     else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
950         r = PySequence_GetItem(o, i);
951     }
952     else {
953         r = __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
954     }
955     return r;
956 }
957
958 static CYTHON_INLINE long __Pyx_NegateNonNeg(long b) { return unlikely(b < 0) ? b : !b; }
959 static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
960     return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
961 }
962
963 static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
964     if (likely(PyList_CheckExact(L))) {
965         if (PyList_Append(L, x) < 0) return NULL;
966         Py_INCREF(Py_None);
967         return Py_None; /* this is just to have an accurate signature */
968     }
969     else {
970         PyObject *r, *m;
971         m = __Pyx_GetAttrString(L, "append");
972         if (!m) return NULL;
973         r = PyObject_CallFunctionObjArgs(m, x, NULL);
974         Py_DECREF(m);
975         return r;
976     }
977 }
978
979 static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);
980
981 #if PY_MAJOR_VERSION >= 3
982 static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
983     PyObject *value;
984     if (unlikely(d == Py_None)) {
985         __Pyx_RaiseNoneIndexingError();
986         return NULL;
987     }
988     value = PyDict_GetItemWithError(d, key);
989     if (unlikely(!value)) {
990         if (!PyErr_Occurred())
991             PyErr_SetObject(PyExc_KeyError, key);
992         return NULL;
993     }
994     Py_INCREF(value);
995     return value;
996 }
997 #else
998     #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
999 #endif
1000
1001 static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
1002     PyObject* value;
1003 #if PY_MAJOR_VERSION >= 3
1004     value = PyDict_GetItemWithError(d, key);
1005     if (unlikely(!value)) {
1006         if (unlikely(PyErr_Occurred()))
1007             return NULL;
1008         value = default_value;
1009     }
1010     Py_INCREF(value);
1011 #else
1012     if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
1013         /* these presumably have safe hash functions */
1014         value = PyDict_GetItem(d, key);
1015         if (unlikely(!value)) {
1016             value = default_value;
1017         }
1018         Py_INCREF(value);
1019     } else {
1020         PyObject *m;
1021         m = __Pyx_GetAttrString(d, "get");
1022         if (!m) return NULL;
1023         value = PyObject_CallFunctionObjArgs(m, key,
1024             (default_value == Py_None) ? NULL : default_value, NULL);
1025         Py_DECREF(m);
1026     }
1027 #endif
1028     return value;
1029 }
1030
1031 static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */
1032
1033 static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */
1034
1035 #define __Pyx_DelItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
1036                                                     __Pyx_DelItemInt_Fast(o, i) : \
1037                                                     __Pyx_DelItem_Generic(o, to_py_func(i)))
1038
1039 static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
1040     int r;
1041     if (!j) return -1;
1042     r = PyObject_DelItem(o, j);
1043     Py_DECREF(j);
1044     return r;
1045 }
1046
1047 static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i) {
1048     if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && likely(i >= 0))
1049         return PySequence_DelItem(o, i);
1050     else {
1051         PyObject *j = PyInt_FromSsize_t(i);
1052         return __Pyx_DelItem_Generic(o, j);
1053     }
1054 }
1055
1056 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
1057 static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
1058
1059 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
1060
1061 static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/
1062
1063 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
1064                                    PyObject *modname); /*proto*/
1065
1066 #define __pyx_binding_PyCFunctionType_USED 1
1067
1068 typedef struct {
1069     PyCFunctionObject func;
1070 } __pyx_binding_PyCFunctionType_object;
1071
1072 static PyTypeObject __pyx_binding_PyCFunctionType_type;
1073 static PyTypeObject *__pyx_binding_PyCFunctionType = NULL;
1074
1075 static PyObject *__pyx_binding_PyCFunctionType_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module); /* proto */
1076 #define __pyx_binding_PyCFunctionType_New(ml, self) __pyx_binding_PyCFunctionType_NewEx(ml, self, NULL)
1077
1078 static int __pyx_binding_PyCFunctionType_init(void); /* proto */
1079
1080 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t);
1081
1082 static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject *);
1083
1084 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t);
1085
1086 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t);
1087
1088 static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject *);
1089
1090 static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject *);
1091
1092 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t);
1093
1094 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t);
1095
1096 static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);
1097
1098 static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);
1099
1100 static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);
1101
1102 static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);
1103
1104 static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);
1105
1106 static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);
1107
1108 static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);
1109
1110 static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);
1111
1112 static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);
1113
1114 static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);
1115
1116 static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);
1117
1118 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);
1119
1120 static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);
1121
1122 static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);
1123
1124 static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);
1125
1126 static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);
1127
1128 static void __Pyx_WriteUnraisable(const char *name); /*proto*/
1129
1130 static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size, int strict);  /*proto*/
1131
1132 static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
1133
1134 static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
1135
1136 static void __Pyx_AddTraceback(const char *funcname); /*proto*/
1137
1138 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
1139 /* Module declarations from __builtin__ */
1140
1141 /* Module declarations from cpython.version */
1142
1143 /* Module declarations from cpython.ref */
1144
1145 /* Module declarations from cpython.exc */
1146
1147 /* Module declarations from cpython.module */
1148
1149 /* Module declarations from cpython.mem */
1150
1151 /* Module declarations from cpython.tuple */
1152
1153 /* Module declarations from cpython.list */
1154
1155 /* Module declarations from libc.stdio */
1156
1157 /* Module declarations from cpython.object */
1158
1159 /* Module declarations from cpython.sequence */
1160
1161 /* Module declarations from cpython.mapping */
1162
1163 /* Module declarations from cpython.iterator */
1164
1165 /* Module declarations from cpython.type */
1166
1167 /* Module declarations from cpython.number */
1168
1169 /* Module declarations from cpython.int */
1170
1171 /* Module declarations from __builtin__ */
1172
1173 /* Module declarations from cpython.bool */
1174
1175 static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
1176 /* Module declarations from cpython.long */
1177
1178 /* Module declarations from cpython.float */
1179
1180 /* Module declarations from __builtin__ */
1181
1182 /* Module declarations from cpython.complex */
1183
1184 static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
1185 /* Module declarations from cpython.string */
1186
1187 /* Module declarations from cpython.unicode */
1188
1189 /* Module declarations from cpython.dict */
1190
1191 /* Module declarations from cpython.instance */
1192
1193 /* Module declarations from cpython.function */
1194
1195 /* Module declarations from cpython.method */
1196
1197 /* Module declarations from cpython.weakref */
1198
1199 /* Module declarations from cpython.getargs */
1200
1201 /* Module declarations from cpython.pythread */
1202
1203 /* Module declarations from cpython.cobject */
1204
1205 /* Module declarations from cpython.oldbuffer */
1206
1207 /* Module declarations from cpython.set */
1208
1209 /* Module declarations from cpython.buffer */
1210
1211 /* Module declarations from cpython.bytes */
1212
1213 /* Module declarations from cpython.pycapsule */
1214
1215 /* Module declarations from cpython */
1216
1217 /* Module declarations from csamtools */
1218
1219 static PyTypeObject *__pyx_ptype_9csamtools_file = 0;
1220 static PyTypeObject *__pyx_ptype_9csamtools_AlignedRead = 0;
1221 static PyTypeObject *__pyx_ptype_9csamtools_Samfile = 0;
1222 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRow = 0;
1223 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowAll = 0;
1224 static PyTypeObject *__pyx_ptype_9csamtools_PileupProxy = 0;
1225 static PyTypeObject *__pyx_ptype_9csamtools_PileupRead = 0;
1226 static PyTypeObject *__pyx_ptype_9csamtools_Fastafile = 0;
1227 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowRegion = 0;
1228 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowAllRefs = 0;
1229 static PyTypeObject *__pyx_ptype_9csamtools_IteratorRowSelection = 0;
1230 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumn = 0;
1231 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumnRegion = 0;
1232 static PyTypeObject *__pyx_ptype_9csamtools_IteratorColumnAllRefs = 0;
1233 static PyTypeObject *__pyx_ptype_9csamtools_SNPCall = 0;
1234 static PyTypeObject *__pyx_ptype_9csamtools_IndexedReads = 0;
1235 static char *__pyx_v_9csamtools_bam_nt16_rev_table;
1236 static int __pyx_v_9csamtools_max_pos;
1237 static PyObject *__pyx_f_9csamtools_makeAlignedRead(bam1_t *); /*proto*/
1238 static PyObject *__pyx_f_9csamtools_makePileupProxy(bam_pileup1_t *, int, int, int); /*proto*/
1239 static PyObject *__pyx_f_9csamtools_makePileupRead(bam_pileup1_t *); /*proto*/
1240 static int __pyx_f_9csamtools_fetch_callback(bam1_t *, void *); /*proto*/
1241 static int __pyx_f_9csamtools_pileup_callback(uint32_t, uint32_t, int, bam_pileup1_t *, void *); /*proto*/
1242 static int __pyx_f_9csamtools_pileup_fetch_callback(bam1_t *, void *); /*proto*/
1243 static int __pyx_f_9csamtools_count_callback(bam1_t *, void *); /*proto*/
1244 static int __pyx_f_9csamtools_mate_callback(bam1_t *, void *); /*proto*/
1245 static int __pyx_f_9csamtools___advance_all(void *, bam1_t *); /*proto*/
1246 static int __pyx_f_9csamtools___advance_snpcalls(void *, bam1_t *); /*proto*/
1247 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_start(bam1_t *); /*proto*/
1248 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_end(bam1_t *); /*proto*/
1249 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_seq_range(bam1_t *, uint32_t, uint32_t); /*proto*/
1250 static CYTHON_INLINE PyObject *__pyx_f_9csamtools_get_qual_range(bam1_t *, uint32_t, uint32_t); /*proto*/
1251 #define __Pyx_MODULE_NAME "csamtools"
1252 static int __pyx_module_is_main_csamtools = 0;
1253
1254 /* Implementation of csamtools */
1255 static PyObject *__pyx_builtin_open;
1256 static PyObject *__pyx_builtin_object;
1257 static PyObject *__pyx_builtin_map;
1258 static PyObject *__pyx_builtin_ValueError;
1259 static PyObject *__pyx_builtin_IOError;
1260 static PyObject *__pyx_builtin_OverflowError;
1261 static PyObject *__pyx_builtin_NotImplementedError;
1262 static PyObject *__pyx_builtin_OSError;
1263 static PyObject *__pyx_builtin_AttributeError;
1264 static PyObject *__pyx_builtin_KeyError;
1265 static PyObject *__pyx_builtin_StopIteration;
1266 static PyObject *__pyx_builtin_cmp;
1267 static PyObject *__pyx_builtin_chr;
1268 static PyObject *__pyx_builtin_TypeError;
1269 static char __pyx_k_1[] = "\t";
1270 static char __pyx_k_2[] = "\n";
1271 static char __pyx_k_3[] = "calling len() on closed file";
1272 static char __pyx_k_5[] = "could not open file `%s`";
1273 static char __pyx_k_6[] = "I/O operation on closed file";
1274 static char __pyx_k_9[] = "no sequence/region supplied.";
1275 static char __pyx_k_11[] = "invalid region: start (%i) > end (%i)";
1276 static char __pyx_k_12[] = "";
1277 static char __pyx_k_13[] = "start out of range (%i)";
1278 static char __pyx_k_14[] = "end out of range (%i)";
1279 static char __pyx_k_15[] = "%s:%i-%i";
1280 static char __pyx_k_17[] = "invalid file opening mode `%s`";
1281 static char __pyx_k_18[] = "-";
1282 static char __pyx_k_19[] = "http:";
1283 static char __pyx_k_20[] = "ftp:";
1284 static char __pyx_k_21[] = "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing";
1285 static char __pyx_k_22[] = "unequal names and lengths of reference sequences";
1286 static char __pyx_k_23[] = "@SQ\tSN:%s\tLN:%s\n";
1287 static char __pyx_k_24[] = "file `%s` not found";
1288 static char __pyx_k_25[] = "could not open file (mode='%s') - is it SAM/BAM format?";
1289 static char __pyx_k_26[] = "file does not have valid header (mode='%s') - is it SAM/BAM format?";
1290 static char __pyx_k_27[] = ".bai";
1291 static char __pyx_k_28[] = "error while opening index `%s` ";
1292 static char __pyx_k_31[] = "tid %i out of range 0<=tid<%i";
1293 static char __pyx_k_33[] = "[:-]";
1294 static char __pyx_k_35[] = "invalid reference `%s`";
1295 static char __pyx_k_36[] = "invalid coordinates: start (%i) > end (%i)";
1296 static char __pyx_k_38[] = "seek only available in bam files";
1297 static char __pyx_k_40[] = "seek no available in streams";
1298 static char __pyx_k_46[] = "fetch called on bamfile without index";
1299 static char __pyx_k_48[] = "callback functionality requires a region/reference";
1300 static char __pyx_k_50[] = "no index available for fetch";
1301 static char __pyx_k_52[] = "fetching by region is not available for sam files";
1302 static char __pyx_k_54[] = "fetch called for samfile without header";
1303 static char __pyx_k_56[] = "callback not implemented yet";
1304 static char __pyx_k_58[] = "read %s: is unpaired";
1305 static char __pyx_k_59[] = "mate %s: is unmapped";
1306 static char __pyx_k_60[] = "mate not found";
1307 static char __pyx_k_65[] = "counting functionality requires a region/reference";
1308 static char __pyx_k_68[] = "count for a region is not available for sam files";
1309 static char __pyx_k_71[] = "no index available for pileup";
1310 static char __pyx_k_74[] = "pileup of samfiles not implemented yet";
1311 static char __pyx_k_81[] = "Samfile.mapped only available in bam files";
1312 static char __pyx_k_84[] = "Samfile.unmapped only available in bam files";
1313 static char __pyx_k_89[] = "@";
1314 static char __pyx_k_91[] = "header line without '@': '%s'";
1315 static char __pyx_k_93[] = "header line with invalid type '%s': '%s'";
1316 static char __pyx_k_94[] = ":";
1317 static char __pyx_k_96[] = "unknown field code '%s' in record '%s'";
1318 static char __pyx_k_97[] = "multiple '%s' lines are not permitted";
1319 static char __pyx_k_98[] = "@%s";
1320 static char __pyx_k_99[] = "%s:%s";
1321 static char __pyx_k__A[] = "A";
1322 static char __pyx_k__C[] = "C";
1323 static char __pyx_k__D[] = "D";
1324 static char __pyx_k__F[] = "F";
1325 static char __pyx_k__I[] = "I";
1326 static char __pyx_k__S[] = "S";
1327 static char __pyx_k__Z[] = "Z";
1328 static char __pyx_k__b[] = "b";
1329 static char __pyx_k__c[] = "c";
1330 static char __pyx_k__d[] = "d";
1331 static char __pyx_k__f[] = "f";
1332 static char __pyx_k__i[] = "i";
1333 static char __pyx_k__n[] = "n";
1334 static char __pyx_k__r[] = "r";
1335 static char __pyx_k__s[] = "s";
1336 static char __pyx_k__w[] = "w";
1337 static char __pyx_k__x[] = "x";
1338 static char __pyx_k_100[] = "invalid type for record %s: %s, expected %s";
1339 static char __pyx_k_101[] = "incomplete sequence information in '%s'";
1340 static char __pyx_k_103[] = "can not iterate over samfile without header";
1341 static char __pyx_k_106[] = "no index available for iteration";
1342 static char __pyx_k_112[] = "can only use this iterator on bam files";
1343 static char __pyx_k_113[] = "reference sequence for '%s' (tid=%i) not found";
1344 static char __pyx_k_114[] = "unknown stepper option `%s` in IteratorColumn";
1345 static char __pyx_k_116[] = "error during iteration";
1346 static char __pyx_k_119[] = "Invalid clipping in CIGAR string";
1347 static char __pyx_k_120[] = "quality and sequence mismatch: %i != %i";
1348 static char __pyx_k_121[] = "%c";
1349 static char __pyx_k_122[] = "create_string_buffer";
1350 static char __pyx_k_123[] = "<cccf";
1351 static char __pyx_k_124[] = "<cccb";
1352 static char __pyx_k_125[] = "<ccch";
1353 static char __pyx_k_126[] = "integer %i out of range of BAM/SAM specification";
1354 static char __pyx_k_127[] = "<ccci";
1355 static char __pyx_k_128[] = "<cccB";
1356 static char __pyx_k_129[] = "<cccH";
1357 static char __pyx_k_130[] = "<cccI";
1358 static char __pyx_k_131[] = "<cccc";
1359 static char __pyx_k_132[] = "<ccc%is";
1360 static char __pyx_k_133[] = "tags field too large";
1361 static char __pyx_k_135[] = "tag '%s' not present";
1362 static char __pyx_k_136[] = "Contig index";
1363 static char __pyx_k_137[] = "Mapped position on contig";
1364 static char __pyx_k_138[] = "Contig index for mate pair";
1365 static char __pyx_k_139[] = "Position of mate pair";
1366 static char __pyx_k_140[] = "Insert size";
1367 static char __pyx_k_141[] = "Binary flag";
1368 static char __pyx_k_142[] = "Count of cigar entries";
1369 static char __pyx_k_143[] = "Cigar entries";
1370 static char __pyx_k_144[] = "Mapping quality";
1371 static char __pyx_k_145[] = "Bam index bin number";
1372 static char __pyx_k_146[] = "Length of query name";
1373 static char __pyx_k_147[] = "Query name";
1374 static char __pyx_k_148[] = "Length of query sequence";
1375 static char __pyx_k_149[] = "Query sequence";
1376 static char __pyx_k_150[] = "Quality scores";
1377 static char __pyx_k_151[] = "Length of auxilary data";
1378 static char __pyx_k_152[] = "Maximum data length";
1379 static char __pyx_k_153[] = "Current data length";
1380 static char __pyx_k_154[] = "%-30s %-10s= %s";
1381 static char __pyx_k_155[] = "(";
1382 static char __pyx_k_156[] = ")";
1383 static char __pyx_k_157[] = "This class cannot be instantiated from Python";
1384 static char __pyx_k_162[] = "No such file or directory: '%s'";
1385 static char __pyx_k_163[] = "-o";
1386 static char __pyx_k_164[] = "option -o is forbidden in samtools view";
1387 static char __pyx_k_166[] = "_rms_mapping_quality";
1388 static char __pyx_k_167[] = "can only IndexReads on bam files";
1389 static char __pyx_k_168[] = "read %s not found";
1390 static char __pyx_k_169[] = "the query name (None if not present)";
1391 static char __pyx_k_170[] = "the :term:`cigar` alignment (None if not present).\n        ";
1392 static char __pyx_k_171[] = "read sequence bases, including :term:`soft clipped` bases (None if not present)";
1393 static char __pyx_k_172[] = "read sequence base qualities, including :term:`soft clipped` bases (None if not present)";
1394 static char __pyx_k_173[] = "aligned portion of the read and excludes any flanking bases that were :term:`soft clipped` (None if not present)\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.";
1395 static char __pyx_k_174[] = "aligned query sequence quality values (None if not present)";
1396 static char __pyx_k_175[] = "start index of the aligned query portion of the sequence (0-based, inclusive)";
1397 static char __pyx_k_176[] = "end index of the aligned query portion of the sequence (0-based, exclusive)";
1398 static char __pyx_k_177[] = "Length of the aligned query sequence";
1399 static char __pyx_k_178[] = "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        ";
1400 static char __pyx_k_179[] = "properties flag";
1401 static char __pyx_k_180[] = "\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        ";
1402 static char __pyx_k_181[] = "\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        ";
1403 static char __pyx_k_182[] = "0-based leftmost coordinate";
1404 static char __pyx_k_183[] = "properties bin";
1405 static char __pyx_k_184[] = "length of the read (read only). Returns 0 if not given.";
1406 static char __pyx_k_185[] = "aligned end position of the read on the reference genome.  Returns\n        None if not available.";
1407 static char __pyx_k_186[] = "aligned length of the read on the reference genome.  Returns None if\n        not available.";
1408 static char __pyx_k_187[] = "mapping quality";
1409 static char __pyx_k_188[] = "the :term:`reference` id of the mate \n        deprecated, use RNEXT instead.\n        ";
1410 static char __pyx_k_189[] = "the :term:`reference` id of the mate ";
1411 static char __pyx_k_190[] = "the position of the mate\n        deprecated, use PNEXT instead.";
1412 static char __pyx_k_191[] = "the position of the mate";
1413 static char __pyx_k_192[] = "the insert size\n        deprecated: use tlen instead";
1414 static char __pyx_k_193[] = "the insert size";
1415 static char __pyx_k_194[] = "true if read is paired in sequencing";
1416 static char __pyx_k_195[] = "true if read is mapped in a proper pair";
1417 static char __pyx_k_196[] = "true if read itself is unmapped";
1418 static char __pyx_k_197[] = "true if the mate is unmapped";
1419 static char __pyx_k_198[] = "true if read is mapped to reverse strand";
1420 static char __pyx_k_199[] = "true is read is mapped to reverse strand";
1421 static char __pyx_k_200[] = "true if this is read1";
1422 static char __pyx_k_201[] = "true if this is read2";
1423 static char __pyx_k_202[] = "true if not primary alignment";
1424 static char __pyx_k_203[] = "true if QC failure";
1425 static char __pyx_k_204[] = "true if optical or PCR duplicate";
1426 static char __pyx_k_205[] = "a list of reference positions that this read aligns to.";
1427 static char __pyx_k_206[] = "number of :term:`filename` associated with this object.";
1428 static char __pyx_k_207[] = "number of :term:`reference` sequences in the file.";
1429 static char __pyx_k_208[] = "tuple with the names of :term:`reference` sequences.";
1430 static char __pyx_k_209[] = "tuple of the lengths of the :term:`reference` sequences. The lengths are in the same order as \n        :attr:`pysam.Samfile.references`\n        ";
1431 static char __pyx_k_210[] = "total number of mapped reads in file.\n        ";
1432 static char __pyx_k_211[] = "total number of unmapped reads in file.\n        ";
1433 static char __pyx_k_212[] = "full contents of the :term:`sam file` header as a string.";
1434 static char __pyx_k_213[] = "header information within the :term:`sam file`. The records and fields are returned as \n        a two-level dictionary.\n        ";
1435 static char __pyx_k_214[] = "the chromosome ID as is defined in the header";
1436 static char __pyx_k_215[] = "number of reads mapping to this column.";
1437 static char __pyx_k_216[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
1438 static char __pyx_k_217[] = "a :class:`pysam.AlignedRead` object of the aligned read";
1439 static char __pyx_k_218[] = "position of the read base at the pileup site, 0-based";
1440 static char __pyx_k_219[] = "indel length; 0 for no indel, positive for ins and negative for del";
1441 static char __pyx_k_220[] = "1 iff the base on the padded read is a deletion";
1442 static char __pyx_k_221[] = "current sequence length.";
1443 static char __pyx_k_222[] = "nucleotide position of SNP.";
1444 static char __pyx_k_223[] = "reference base at pos. ``N`` if no reference sequence supplied.";
1445 static char __pyx_k_224[] = "the genotype called.";
1446 static char __pyx_k_225[] = "the genotype quality (Phred-scaled).";
1447 static char __pyx_k_226[] = "the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.";
1448 static char __pyx_k_227[] = "the root mean square (rms) of the mapping quality of all reads involved in the call.";
1449 static char __pyx_k_228[] = "coverage or read depth - the number of reads involved in the call.";
1450 static char __pyx_k_229[] = "=ACMGRSVTWYHKDBN";
1451 static char __pyx_k_230[] = "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    ";
1452 static char __pyx_k_231[] = "\n    stderr is captured. \n    ";
1453 static char __pyx_k_232[] = "does nothing. stderr can't be redirected on windows";
1454 static char __pyx_k_238[] = "http://mail.python.org/pipermail/python-list/2000-June/038406.html";
1455 static char __pyx_k__AS[] = "AS";
1456 static char __pyx_k__CL[] = "CL";
1457 static char __pyx_k__CN[] = "CN";
1458 static char __pyx_k__CO[] = "CO";
1459 static char __pyx_k__DS[] = "DS";
1460 static char __pyx_k__DT[] = "DT";
1461 static char __pyx_k__GO[] = "GO";
1462 static char __pyx_k__HD[] = "HD";
1463 static char __pyx_k__ID[] = "ID";
1464 static char __pyx_k__LB[] = "LB";
1465 static char __pyx_k__LN[] = "LN";
1466 static char __pyx_k__M5[] = "M5";
1467 static char __pyx_k__PG[] = "PG";
1468 static char __pyx_k__PI[] = "PI";
1469 static char __pyx_k__PL[] = "PL";
1470 static char __pyx_k__PN[] = "PN";
1471 static char __pyx_k__PU[] = "PU";
1472 static char __pyx_k__RG[] = "RG";
1473 static char __pyx_k__SM[] = "SM";
1474 static char __pyx_k__SN[] = "SN";
1475 static char __pyx_k__SO[] = "SO";
1476 static char __pyx_k__SP[] = "SP";
1477 static char __pyx_k__SQ[] = "SQ";
1478 static char __pyx_k__UR[] = "UR";
1479 static char __pyx_k__VN[] = "VN";
1480 static char __pyx_k__fd[] = "fd";
1481 static char __pyx_k__fp[] = "fp";
1482 static char __pyx_k__id[] = "id";
1483 static char __pyx_k__os[] = "os";
1484 static char __pyx_k__rU[] = "rU";
1485 static char __pyx_k__rb[] = "rb";
1486 static char __pyx_k__re[] = "re";
1487 static char __pyx_k__wb[] = "wb";
1488 static char __pyx_k__wh[] = "wh";
1489 static char __pyx_k__all[] = "all";
1490 static char __pyx_k__bam[] = "bam";
1491 static char __pyx_k__beg[] = "beg";
1492 static char __pyx_k__bin[] = "bin";
1493 static char __pyx_k__chr[] = "chr";
1494 static char __pyx_k__cmp[] = "cmp";
1495 static char __pyx_k__dup[] = "dup";
1496 static char __pyx_k__end[] = "end";
1497 static char __pyx_k__map[] = "map";
1498 static char __pyx_k__plp[] = "plp";
1499 static char __pyx_k__pos[] = "pos";
1500 static char __pyx_k__raw[] = "raw";
1501 static char __pyx_k__seq[] = "seq";
1502 static char __pyx_k__sys[] = "sys";
1503 static char __pyx_k__tid[] = "tid";
1504 static char __pyx_k__wbu[] = "wbu";
1505 static char __pyx_k__Outs[] = "Outs";
1506 static char __pyx_k___pos[] = "_pos";
1507 static char __pyx_k___tid[] = "_tid";
1508 static char __pyx_k__args[] = "args";
1509 static char __pyx_k__core[] = "core";
1510 static char __pyx_k__data[] = "data";
1511 static char __pyx_k__dup2[] = "dup2";
1512 static char __pyx_k__flag[] = "flag";
1513 static char __pyx_k__hash[] = "hash";
1514 static char __pyx_k__iter[] = "iter";
1515 static char __pyx_k__join[] = "join";
1516 static char __pyx_k__mapq[] = "mapq";
1517 static char __pyx_k__mask[] = "mask";
1518 static char __pyx_k__mate[] = "mate";
1519 static char __pyx_k__mode[] = "mode";
1520 static char __pyx_k__mpos[] = "mpos";
1521 static char __pyx_k__mrnm[] = "mrnm";
1522 static char __pyx_k__mtid[] = "mtid";
1523 static char __pyx_k__n_pu[] = "n_pu";
1524 static char __pyx_k__name[] = "name";
1525 static char __pyx_k__open[] = "open";
1526 static char __pyx_k__path[] = "path";
1527 static char __pyx_k__port[] = "port";
1528 static char __pyx_k__qpos[] = "qpos";
1529 static char __pyx_k__qseq[] = "qseq";
1530 static char __pyx_k__qual[] = "qual";
1531 static char __pyx_k__rlen[] = "rlen";
1532 static char __pyx_k__seek[] = "seek";
1533 static char __pyx_k__self[] = "self";
1534 static char __pyx_k__tags[] = "tags";
1535 static char __pyx_k__text[] = "text";
1536 static char __pyx_k__view[] = "view";
1537 static char __pyx_k___open[] = "_open";
1538 static char __pyx_k___qpos[] = "_qpos";
1539 static char __pyx_k__bqual[] = "bqual";
1540 static char __pyx_k__cigar[] = "cigar";
1541 static char __pyx_k__close[] = "close";
1542 static char __pyx_k__cnext[] = "cnext";
1543 static char __pyx_k__flush[] = "flush";
1544 static char __pyx_k__indel[] = "indel";
1545 static char __pyx_k__index[] = "index";
1546 static char __pyx_k__isbam[] = "isbam";
1547 static char __pyx_k__isize[] = "isize";
1548 static char __pyx_k__l_aux[] = "l_aux";
1549 static char __pyx_k__level[] = "level";
1550 static char __pyx_k__n_plp[] = "n_plp";
1551 static char __pyx_k__qname[] = "qname";
1552 static char __pyx_k__rname[] = "rname";
1553 static char __pyx_k__setfd[] = "setfd";
1554 static char __pyx_k__split[] = "split";
1555 static char __pyx_k__start[] = "start";
1556 static char __pyx_k__strip[] = "strip";
1557 static char __pyx_k__types[] = "types";
1558 static char __pyx_k__where[] = "where";
1559 static char __pyx_k__write[] = "write";
1560 static char __pyx_k___indel[] = "_indel";
1561 static char __pyx_k___level[] = "_level";
1562 static char __pyx_k__append[] = "append";
1563 static char __pyx_k__ctypes[] = "ctypes";
1564 static char __pyx_k__exists[] = "exists";
1565 static char __pyx_k__fields[] = "fields";
1566 static char __pyx_k__fileno[] = "fileno";
1567 static char __pyx_k__gettid[] = "gettid";
1568 static char __pyx_k__header[] = "header";
1569 static char __pyx_k__is_del[] = "is_del";
1570 static char __pyx_k__l_qseq[] = "l_qseq";
1571 static char __pyx_k__l_text[] = "l_text";
1572 static char __pyx_k__m_data[] = "m_data";
1573 static char __pyx_k__method[] = "method";
1574 static char __pyx_k__object[] = "object";
1575 static char __pyx_k__offset[] = "offset";
1576 static char __pyx_k__record[] = "record";
1577 static char __pyx_k__region[] = "region";
1578 static char __pyx_k__remove[] = "remove";
1579 static char __pyx_k__reopen[] = "reopen";
1580 static char __pyx_k__retval[] = "retval";
1581 static char __pyx_k__rg2lib[] = "rg2lib";
1582 static char __pyx_k__stderr[] = "stderr";
1583 static char __pyx_k__stdout[] = "stdout";
1584 static char __pyx_k__struct[] = "struct";
1585 static char __pyx_k__system[] = "system";
1586 static char __pyx_k__IOError[] = "IOError";
1587 static char __pyx_k__IntType[] = "IntType";
1588 static char __pyx_k__OSError[] = "OSError";
1589 static char __pyx_k__O_CREAT[] = "O_CREAT";
1590 static char __pyx_k__Samfile[] = "Samfile";
1591 static char __pyx_k__Windows[] = "Windows";
1592 static char __pyx_k____all__[] = "__all__";
1593 static char __pyx_k____del__[] = "__del__";
1594 static char __pyx_k____str__[] = "__str__";
1595 static char __pyx_k___isOpen[] = "_isOpen";
1596 static char __pyx_k___is_del[] = "_is_del";
1597 static char __pyx_k__devnull[] = "devnull";
1598 static char __pyx_k__is_head[] = "is_head";
1599 static char __pyx_k__is_tail[] = "is_tail";
1600 static char __pyx_k__isupper[] = "isupper";
1601 static char __pyx_k__l_qname[] = "l_qname";
1602 static char __pyx_k__mkstemp[] = "mkstemp";
1603 static char __pyx_k__n_cigar[] = "n_cigar";
1604 static char __pyx_k__pileups[] = "pileups";
1605 static char __pyx_k__release[] = "release";
1606 static char __pyx_k__restore[] = "restore";
1607 static char __pyx_k__rowiter[] = "rowiter";
1608 static char __pyx_k__samfile[] = "samfile";
1609 static char __pyx_k__seq_len[] = "seq_len";
1610 static char __pyx_k__setfile[] = "setfile";
1611 static char __pyx_k__stepper[] = "stepper";
1612 static char __pyx_k__streams[] = "streams";
1613 static char __pyx_k__DictType[] = "DictType";
1614 static char __pyx_k__KeyError[] = "KeyError";
1615 static char __pyx_k__O_WRONLY[] = "O_WRONLY";
1616 static char __pyx_k____dict__[] = "__dict__";
1617 static char __pyx_k____init__[] = "__init__";
1618 static char __pyx_k____main__[] = "__main__";
1619 static char __pyx_k____test__[] = "__test__";
1620 static char __pyx_k___is_head[] = "_is_head";
1621 static char __pyx_k___is_tail[] = "_is_tail";
1622 static char __pyx_k___logfile[] = "_logfile";
1623 static char __pyx_k__calcsize[] = "calcsize";
1624 static char __pyx_k__callback[] = "callback";
1625 static char __pyx_k__coverage[] = "coverage";
1626 static char __pyx_k__data_len[] = "data_len";
1627 static char __pyx_k__exc_type[] = "exc_type";
1628 static char __pyx_k__filename[] = "filename";
1629 static char __pyx_k__genotype[] = "genotype";
1630 static char __pyx_k__isremote[] = "isremote";
1631 static char __pyx_k__isstream[] = "isstream";
1632 static char __pyx_k__iterdata[] = "iterdata";
1633 static char __pyx_k__nextiter[] = "nextiter";
1634 static char __pyx_k__platform[] = "platform";
1635 static char __pyx_k__samtools[] = "samtools";
1636 static char __pyx_k__stderr_f[] = "stderr_f";
1637 static char __pyx_k__stderr_h[] = "stderr_h";
1638 static char __pyx_k__tempfile[] = "tempfile";
1639 static char __pyx_k__template[] = "template";
1640 static char __pyx_k__Fastafile[] = "Fastafile";
1641 static char __pyx_k__FloatType[] = "FloatType";
1642 static char __pyx_k__TypeError[] = "TypeError";
1643 static char __pyx_k___coverage[] = "_coverage";
1644 static char __pyx_k___delegate[] = "_delegate";
1645 static char __pyx_k___filename[] = "_filename";
1646 static char __pyx_k___genotype[] = "_genotype";
1647 static char __pyx_k___hasIndex[] = "_hasIndex";
1648 static char __pyx_k__alignment[] = "alignment";
1649 static char __pyx_k__csamtools[] = "csamtools";
1650 static char __pyx_k__exc_value[] = "exc_value";
1651 static char __pyx_k__fastafile[] = "fastafile";
1652 static char __pyx_k__itertools[] = "itertools";
1653 static char __pyx_k__max_depth[] = "max_depth";
1654 static char __pyx_k__n_targets[] = "n_targets";
1655 static char __pyx_k__pack_into[] = "pack_into";
1656 static char __pyx_k__positions[] = "positions";
1657 static char __pyx_k__readlines[] = "readlines";
1658 static char __pyx_k__reference[] = "reference";
1659 static char __pyx_k__setdevice[] = "setdevice";
1660 static char __pyx_k__traceback[] = "traceback";
1661 static char __pyx_k__until_eof[] = "until_eof";
1662 static char __pyx_k__PileupRead[] = "PileupRead";
1663 static char __pyx_k__ValueError[] = "ValueError";
1664 static char __pyx_k___alignment[] = "_alignment";
1665 static char __pyx_k___buildLine[] = "_buildLine";
1666 static char __pyx_k__startswith[] = "startswith";
1667 static char __pyx_k__target_len[] = "target_len";
1668 static char __pyx_k__AlignedRead[] = "AlignedRead";
1669 static char __pyx_k__IteratorRow[] = "IteratorRow";
1670 static char __pyx_k__PileupProxy[] = "PileupProxy";
1671 static char __pyx_k__StderrStore[] = "StderrStore";
1672 static char __pyx_k__add_sq_text[] = "add_sq_text";
1673 static char __pyx_k__collections[] = "collections";
1674 static char __pyx_k__current_pos[] = "current_pos";
1675 static char __pyx_k__defaultdict[] = "defaultdict";
1676 static char __pyx_k__nreferences[] = "nreferences";
1677 static char __pyx_k__pileup_iter[] = "pileup_iter";
1678 static char __pyx_k__snp_quality[] = "snp_quality";
1679 static char __pyx_k__stderr_save[] = "stderr_save";
1680 static char __pyx_k__target_name[] = "target_name";
1681 static char __pyx_k__IndexedReads[] = "IndexedReads";
1682 static char __pyx_k__PileupColumn[] = "PileupColumn";
1683 static char __pyx_k___buildHeader[] = "_buildHeader";
1684 static char __pyx_k___parseRegion[] = "_parseRegion";
1685 static char __pyx_k___snp_quality[] = "_snp_quality";
1686 static char __pyx_k__catch_stderr[] = "catch_stderr";
1687 static char __pyx_k__catch_stdout[] = "catch_stdout";
1688 static char __pyx_k__owns_samfile[] = "owns_samfile";
1689 static char __pyx_k__start_offset[] = "start_offset";
1690 static char __pyx_k__OverflowError[] = "OverflowError";
1691 static char __pyx_k__StopIteration[] = "StopIteration";
1692 static char __pyx_k__VALID_HEADERS[] = "VALID_HEADERS";
1693 static char __pyx_k__AttributeError[] = "AttributeError";
1694 static char __pyx_k__IteratorColumn[] = "IteratorColumn";
1695 static char __pyx_k__readAndRelease[] = "readAndRelease";
1696 static char __pyx_k__reference_base[] = "reference_base";
1697 static char __pyx_k__referencenames[] = "referencenames";
1698 static char __pyx_k___reference_base[] = "_reference_base";
1699 static char __pyx_k__mapping_quality[] = "mapping_quality";
1700 static char __pyx_k____getattribute__[] = "__getattribute__";
1701 static char __pyx_k__referencelengths[] = "referencelengths";
1702 static char __pyx_k__consensus_quality[] = "consensus_quality";
1703 static char __pyx_k__setupIteratorData[] = "setupIteratorData";
1704 static char __pyx_k__StderrStoreWindows[] = "StderrStoreWindows";
1705 static char __pyx_k__VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
1706 static char __pyx_k__VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
1707 static char __pyx_k___consensus_quality[] = "_consensus_quality";
1708 static char __pyx_k___samtools_dispatch[] = "_samtools_dispatch";
1709 static char __pyx_k__NotImplementedError[] = "NotImplementedError";
1710 static char __pyx_k__VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
1711 static PyObject *__pyx_kp_s_1;
1712 static PyObject *__pyx_kp_s_100;
1713 static PyObject *__pyx_kp_s_101;
1714 static PyObject *__pyx_kp_s_103;
1715 static PyObject *__pyx_kp_s_106;
1716 static PyObject *__pyx_kp_s_11;
1717 static PyObject *__pyx_kp_s_112;
1718 static PyObject *__pyx_kp_s_113;
1719 static PyObject *__pyx_kp_s_114;
1720 static PyObject *__pyx_kp_s_116;
1721 static PyObject *__pyx_kp_s_12;
1722 static PyObject *__pyx_kp_s_120;
1723 static PyObject *__pyx_kp_s_121;
1724 static PyObject *__pyx_n_s_122;
1725 static PyObject *__pyx_kp_s_123;
1726 static PyObject *__pyx_kp_s_124;
1727 static PyObject *__pyx_kp_s_125;
1728 static PyObject *__pyx_kp_s_126;
1729 static PyObject *__pyx_kp_s_127;
1730 static PyObject *__pyx_kp_s_128;
1731 static PyObject *__pyx_kp_s_129;
1732 static PyObject *__pyx_kp_s_13;
1733 static PyObject *__pyx_kp_s_130;
1734 static PyObject *__pyx_kp_s_131;
1735 static PyObject *__pyx_kp_s_132;
1736 static PyObject *__pyx_kp_s_133;
1737 static PyObject *__pyx_kp_s_135;
1738 static PyObject *__pyx_kp_s_136;
1739 static PyObject *__pyx_kp_s_137;
1740 static PyObject *__pyx_kp_s_138;
1741 static PyObject *__pyx_kp_s_139;
1742 static PyObject *__pyx_kp_s_14;
1743 static PyObject *__pyx_kp_s_140;
1744 static PyObject *__pyx_kp_s_141;
1745 static PyObject *__pyx_kp_s_142;
1746 static PyObject *__pyx_kp_s_143;
1747 static PyObject *__pyx_kp_s_144;
1748 static PyObject *__pyx_kp_s_145;
1749 static PyObject *__pyx_kp_s_146;
1750 static PyObject *__pyx_kp_s_147;
1751 static PyObject *__pyx_kp_s_148;
1752 static PyObject *__pyx_kp_s_149;
1753 static PyObject *__pyx_kp_s_15;
1754 static PyObject *__pyx_kp_s_150;
1755 static PyObject *__pyx_kp_s_151;
1756 static PyObject *__pyx_kp_s_152;
1757 static PyObject *__pyx_kp_s_153;
1758 static PyObject *__pyx_kp_s_154;
1759 static PyObject *__pyx_kp_s_155;
1760 static PyObject *__pyx_kp_s_156;
1761 static PyObject *__pyx_kp_s_157;
1762 static PyObject *__pyx_kp_s_162;
1763 static PyObject *__pyx_kp_s_163;
1764 static PyObject *__pyx_kp_s_164;
1765 static PyObject *__pyx_n_s_166;
1766 static PyObject *__pyx_kp_s_167;
1767 static PyObject *__pyx_kp_s_168;
1768 static PyObject *__pyx_kp_s_17;
1769 static PyObject *__pyx_kp_s_2;
1770 static PyObject *__pyx_kp_s_21;
1771 static PyObject *__pyx_kp_s_22;
1772 static PyObject *__pyx_kp_s_23;
1773 static PyObject *__pyx_kp_s_230;
1774 static PyObject *__pyx_kp_s_231;
1775 static PyObject *__pyx_kp_s_232;
1776 static PyObject *__pyx_kp_s_238;
1777 static PyObject *__pyx_kp_s_24;
1778 static PyObject *__pyx_kp_s_25;
1779 static PyObject *__pyx_kp_s_26;
1780 static PyObject *__pyx_kp_s_27;
1781 static PyObject *__pyx_kp_s_28;
1782 static PyObject *__pyx_kp_s_3;
1783 static PyObject *__pyx_kp_s_31;
1784 static PyObject *__pyx_kp_s_33;
1785 static PyObject *__pyx_kp_s_35;
1786 static PyObject *__pyx_kp_s_36;
1787 static PyObject *__pyx_kp_s_38;
1788 static PyObject *__pyx_kp_s_40;
1789 static PyObject *__pyx_kp_s_46;
1790 static PyObject *__pyx_kp_s_48;
1791 static PyObject *__pyx_kp_s_5;
1792 static PyObject *__pyx_kp_s_50;
1793 static PyObject *__pyx_kp_s_52;
1794 static PyObject *__pyx_kp_s_54;
1795 static PyObject *__pyx_kp_s_56;
1796 static PyObject *__pyx_kp_s_58;
1797 static PyObject *__pyx_kp_s_59;
1798 static PyObject *__pyx_kp_s_6;
1799 static PyObject *__pyx_kp_s_60;
1800 static PyObject *__pyx_kp_s_65;
1801 static PyObject *__pyx_kp_s_68;
1802 static PyObject *__pyx_kp_s_71;
1803 static PyObject *__pyx_kp_s_74;
1804 static PyObject *__pyx_kp_s_81;
1805 static PyObject *__pyx_kp_s_84;
1806 static PyObject *__pyx_kp_s_89;
1807 static PyObject *__pyx_kp_s_9;
1808 static PyObject *__pyx_kp_s_91;
1809 static PyObject *__pyx_kp_s_93;
1810 static PyObject *__pyx_kp_s_94;
1811 static PyObject *__pyx_kp_s_96;
1812 static PyObject *__pyx_kp_s_97;
1813 static PyObject *__pyx_kp_s_98;
1814 static PyObject *__pyx_kp_s_99;
1815 static PyObject *__pyx_n_s__A;
1816 static PyObject *__pyx_n_s__AS;
1817 static PyObject *__pyx_n_s__AlignedRead;
1818 static PyObject *__pyx_n_s__AttributeError;
1819 static PyObject *__pyx_n_s__C;
1820 static PyObject *__pyx_n_s__CL;
1821 static PyObject *__pyx_n_s__CN;
1822 static PyObject *__pyx_n_s__CO;
1823 static PyObject *__pyx_n_s__D;
1824 static PyObject *__pyx_n_s__DS;
1825 static PyObject *__pyx_n_s__DT;
1826 static PyObject *__pyx_n_s__DictType;
1827 static PyObject *__pyx_n_s__F;
1828 static PyObject *__pyx_n_s__Fastafile;
1829 static PyObject *__pyx_n_s__FloatType;
1830 static PyObject *__pyx_n_s__GO;
1831 static PyObject *__pyx_n_s__HD;
1832 static PyObject *__pyx_n_s__I;
1833 static PyObject *__pyx_n_s__ID;
1834 static PyObject *__pyx_n_s__IOError;
1835 static PyObject *__pyx_n_s__IndexedReads;
1836 static PyObject *__pyx_n_s__IntType;
1837 static PyObject *__pyx_n_s__IteratorColumn;
1838 static PyObject *__pyx_n_s__IteratorRow;
1839 static PyObject *__pyx_n_s__KeyError;
1840 static PyObject *__pyx_n_s__LB;
1841 static PyObject *__pyx_n_s__LN;
1842 static PyObject *__pyx_n_s__M5;
1843 static PyObject *__pyx_n_s__NotImplementedError;
1844 static PyObject *__pyx_n_s__OSError;
1845 static PyObject *__pyx_n_s__O_CREAT;
1846 static PyObject *__pyx_n_s__O_WRONLY;
1847 static PyObject *__pyx_n_s__Outs;
1848 static PyObject *__pyx_n_s__OverflowError;
1849 static PyObject *__pyx_n_s__PG;
1850 static PyObject *__pyx_n_s__PI;
1851 static PyObject *__pyx_n_s__PL;
1852 static PyObject *__pyx_n_s__PN;
1853 static PyObject *__pyx_n_s__PU;
1854 static PyObject *__pyx_n_s__PileupColumn;
1855 static PyObject *__pyx_n_s__PileupProxy;
1856 static PyObject *__pyx_n_s__PileupRead;
1857 static PyObject *__pyx_n_s__RG;
1858 static PyObject *__pyx_n_s__S;
1859 static PyObject *__pyx_n_s__SM;
1860 static PyObject *__pyx_n_s__SN;
1861 static PyObject *__pyx_n_s__SO;
1862 static PyObject *__pyx_n_s__SP;
1863 static PyObject *__pyx_n_s__SQ;
1864 static PyObject *__pyx_n_s__Samfile;
1865 static PyObject *__pyx_n_s__StderrStore;
1866 static PyObject *__pyx_n_s__StderrStoreWindows;
1867 static PyObject *__pyx_n_s__StopIteration;
1868 static PyObject *__pyx_n_s__TypeError;
1869 static PyObject *__pyx_n_s__UR;
1870 static PyObject *__pyx_n_s__VALID_HEADERS;
1871 static PyObject *__pyx_n_s__VALID_HEADER_FIELDS;
1872 static PyObject *__pyx_n_s__VALID_HEADER_ORDER;
1873 static PyObject *__pyx_n_s__VALID_HEADER_TYPES;
1874 static PyObject *__pyx_n_s__VN;
1875 static PyObject *__pyx_n_s__ValueError;
1876 static PyObject *__pyx_n_s__Windows;
1877 static PyObject *__pyx_n_s__Z;
1878 static PyObject *__pyx_n_s____all__;
1879 static PyObject *__pyx_n_s____del__;
1880 static PyObject *__pyx_n_s____dict__;
1881 static PyObject *__pyx_n_s____getattribute__;
1882 static PyObject *__pyx_n_s____init__;
1883 static PyObject *__pyx_n_s____main__;
1884 static PyObject *__pyx_n_s____str__;
1885 static PyObject *__pyx_n_s____test__;
1886 static PyObject *__pyx_n_s___alignment;
1887 static PyObject *__pyx_n_s___buildHeader;
1888 static PyObject *__pyx_n_s___buildLine;
1889 static PyObject *__pyx_n_s___consensus_quality;
1890 static PyObject *__pyx_n_s___coverage;
1891 static PyObject *__pyx_n_s___delegate;
1892 static PyObject *__pyx_n_s___filename;
1893 static PyObject *__pyx_n_s___genotype;
1894 static PyObject *__pyx_n_s___hasIndex;
1895 static PyObject *__pyx_n_s___indel;
1896 static PyObject *__pyx_n_s___isOpen;
1897 static PyObject *__pyx_n_s___is_del;
1898 static PyObject *__pyx_n_s___is_head;
1899 static PyObject *__pyx_n_s___is_tail;
1900 static PyObject *__pyx_n_s___level;
1901 static PyObject *__pyx_n_s___logfile;
1902 static PyObject *__pyx_n_s___open;
1903 static PyObject *__pyx_n_s___parseRegion;
1904 static PyObject *__pyx_n_s___pos;
1905 static PyObject *__pyx_n_s___qpos;
1906 static PyObject *__pyx_n_s___reference_base;
1907 static PyObject *__pyx_n_s___samtools_dispatch;
1908 static PyObject *__pyx_n_s___snp_quality;
1909 static PyObject *__pyx_n_s___tid;
1910 static PyObject *__pyx_n_s__add_sq_text;
1911 static PyObject *__pyx_n_s__alignment;
1912 static PyObject *__pyx_n_s__all;
1913 static PyObject *__pyx_n_s__append;
1914 static PyObject *__pyx_n_s__args;
1915 static PyObject *__pyx_n_s__b;
1916 static PyObject *__pyx_n_s__bam;
1917 static PyObject *__pyx_n_s__beg;
1918 static PyObject *__pyx_n_s__bin;
1919 static PyObject *__pyx_n_s__bqual;
1920 static PyObject *__pyx_n_s__c;
1921 static PyObject *__pyx_n_s__calcsize;
1922 static PyObject *__pyx_n_s__callback;
1923 static PyObject *__pyx_n_s__catch_stderr;
1924 static PyObject *__pyx_n_s__catch_stdout;
1925 static PyObject *__pyx_n_s__chr;
1926 static PyObject *__pyx_n_s__cigar;
1927 static PyObject *__pyx_n_s__close;
1928 static PyObject *__pyx_n_s__cmp;
1929 static PyObject *__pyx_n_s__cnext;
1930 static PyObject *__pyx_n_s__collections;
1931 static PyObject *__pyx_n_s__consensus_quality;
1932 static PyObject *__pyx_n_s__core;
1933 static PyObject *__pyx_n_s__coverage;
1934 static PyObject *__pyx_n_s__csamtools;
1935 static PyObject *__pyx_n_s__ctypes;
1936 static PyObject *__pyx_n_s__current_pos;
1937 static PyObject *__pyx_n_s__d;
1938 static PyObject *__pyx_n_s__data;
1939 static PyObject *__pyx_n_s__data_len;
1940 static PyObject *__pyx_n_s__defaultdict;
1941 static PyObject *__pyx_n_s__devnull;
1942 static PyObject *__pyx_n_s__dup;
1943 static PyObject *__pyx_n_s__dup2;
1944 static PyObject *__pyx_n_s__end;
1945 static PyObject *__pyx_n_s__exc_type;
1946 static PyObject *__pyx_n_s__exc_value;
1947 static PyObject *__pyx_n_s__exists;
1948 static PyObject *__pyx_n_s__f;
1949 static PyObject *__pyx_n_s__fastafile;
1950 static PyObject *__pyx_n_s__fd;
1951 static PyObject *__pyx_n_s__fields;
1952 static PyObject *__pyx_n_s__filename;
1953 static PyObject *__pyx_n_s__fileno;
1954 static PyObject *__pyx_n_s__flag;
1955 static PyObject *__pyx_n_s__flush;
1956 static PyObject *__pyx_n_s__fp;
1957 static PyObject *__pyx_n_s__genotype;
1958 static PyObject *__pyx_n_s__gettid;
1959 static PyObject *__pyx_n_s__hash;
1960 static PyObject *__pyx_n_s__header;
1961 static PyObject *__pyx_n_s__i;
1962 static PyObject *__pyx_n_s__id;
1963 static PyObject *__pyx_n_s__indel;
1964 static PyObject *__pyx_n_s__index;
1965 static PyObject *__pyx_n_s__is_del;
1966 static PyObject *__pyx_n_s__is_head;
1967 static PyObject *__pyx_n_s__is_tail;
1968 static PyObject *__pyx_n_s__isbam;
1969 static PyObject *__pyx_n_s__isize;
1970 static PyObject *__pyx_n_s__isremote;
1971 static PyObject *__pyx_n_s__isstream;
1972 static PyObject *__pyx_n_s__isupper;
1973 static PyObject *__pyx_n_s__iter;
1974 static PyObject *__pyx_n_s__iterdata;
1975 static PyObject *__pyx_n_s__itertools;
1976 static PyObject *__pyx_n_s__join;
1977 static PyObject *__pyx_n_s__l_aux;
1978 static PyObject *__pyx_n_s__l_qname;
1979 static PyObject *__pyx_n_s__l_qseq;
1980 static PyObject *__pyx_n_s__l_text;
1981 static PyObject *__pyx_n_s__level;
1982 static PyObject *__pyx_n_s__m_data;
1983 static PyObject *__pyx_n_s__map;
1984 static PyObject *__pyx_n_s__mapping_quality;
1985 static PyObject *__pyx_n_s__mapq;
1986 static PyObject *__pyx_n_s__mask;
1987 static PyObject *__pyx_n_s__mate;
1988 static PyObject *__pyx_n_s__max_depth;
1989 static PyObject *__pyx_n_s__method;
1990 static PyObject *__pyx_n_s__mkstemp;
1991 static PyObject *__pyx_n_s__mode;
1992 static PyObject *__pyx_n_s__mpos;
1993 static PyObject *__pyx_n_s__mrnm;
1994 static PyObject *__pyx_n_s__mtid;
1995 static PyObject *__pyx_n_s__n;
1996 static PyObject *__pyx_n_s__n_cigar;
1997 static PyObject *__pyx_n_s__n_plp;
1998 static PyObject *__pyx_n_s__n_pu;
1999 static PyObject *__pyx_n_s__n_targets;
2000 static PyObject *__pyx_n_s__name;
2001 static PyObject *__pyx_n_s__nextiter;
2002 static PyObject *__pyx_n_s__nreferences;
2003 static PyObject *__pyx_n_s__object;
2004 static PyObject *__pyx_n_s__offset;
2005 static PyObject *__pyx_n_s__open;
2006 static PyObject *__pyx_n_s__os;
2007 static PyObject *__pyx_n_s__owns_samfile;
2008 static PyObject *__pyx_n_s__pack_into;
2009 static PyObject *__pyx_n_s__path;
2010 static PyObject *__pyx_n_s__pileup_iter;
2011 static PyObject *__pyx_n_s__pileups;
2012 static PyObject *__pyx_n_s__platform;
2013 static PyObject *__pyx_n_s__plp;
2014 static PyObject *__pyx_n_s__port;
2015 static PyObject *__pyx_n_s__pos;
2016 static PyObject *__pyx_n_s__positions;
2017 static PyObject *__pyx_n_s__qname;
2018 static PyObject *__pyx_n_s__qpos;
2019 static PyObject *__pyx_n_s__qseq;
2020 static PyObject *__pyx_n_s__qual;
2021 static PyObject *__pyx_n_s__r;
2022 static PyObject *__pyx_n_s__rU;
2023 static PyObject *__pyx_n_s__raw;
2024 static PyObject *__pyx_n_s__rb;
2025 static PyObject *__pyx_n_s__re;
2026 static PyObject *__pyx_n_s__readAndRelease;
2027 static PyObject *__pyx_n_s__readlines;
2028 static PyObject *__pyx_n_s__record;
2029 static PyObject *__pyx_n_s__reference;
2030 static PyObject *__pyx_n_s__reference_base;
2031 static PyObject *__pyx_n_s__referencelengths;
2032 static PyObject *__pyx_n_s__referencenames;
2033 static PyObject *__pyx_n_s__region;
2034 static PyObject *__pyx_n_s__release;
2035 static PyObject *__pyx_n_s__remove;
2036 static PyObject *__pyx_n_s__reopen;
2037 static PyObject *__pyx_n_s__restore;
2038 static PyObject *__pyx_n_s__retval;
2039 static PyObject *__pyx_n_s__rg2lib;
2040 static PyObject *__pyx_n_s__rlen;
2041 static PyObject *__pyx_n_s__rname;
2042 static PyObject *__pyx_n_s__rowiter;
2043 static PyObject *__pyx_n_s__s;
2044 static PyObject *__pyx_n_s__samfile;
2045 static PyObject *__pyx_n_s__samtools;
2046 static PyObject *__pyx_n_s__seek;
2047 static PyObject *__pyx_n_s__self;
2048 static PyObject *__pyx_n_s__seq;
2049 static PyObject *__pyx_n_s__seq_len;
2050 static PyObject *__pyx_n_s__setdevice;
2051 static PyObject *__pyx_n_s__setfd;
2052 static PyObject *__pyx_n_s__setfile;
2053 static PyObject *__pyx_n_s__setupIteratorData;
2054 static PyObject *__pyx_n_s__snp_quality;
2055 static PyObject *__pyx_n_s__split;
2056 static PyObject *__pyx_n_s__start;
2057 static PyObject *__pyx_n_s__start_offset;
2058 static PyObject *__pyx_n_s__startswith;
2059 static PyObject *__pyx_n_s__stderr;
2060 static PyObject *__pyx_n_s__stderr_f;
2061 static PyObject *__pyx_n_s__stderr_h;
2062 static PyObject *__pyx_n_s__stderr_save;
2063 static PyObject *__pyx_n_s__stdout;
2064 static PyObject *__pyx_n_s__stepper;
2065 static PyObject *__pyx_n_s__streams;
2066 static PyObject *__pyx_n_s__strip;
2067 static PyObject *__pyx_n_s__struct;
2068 static PyObject *__pyx_n_s__sys;
2069 static PyObject *__pyx_n_s__system;
2070 static PyObject *__pyx_n_s__tags;
2071 static PyObject *__pyx_n_s__target_len;
2072 static PyObject *__pyx_n_s__target_name;
2073 static PyObject *__pyx_n_s__tempfile;
2074 static PyObject *__pyx_n_s__template;
2075 static PyObject *__pyx_n_s__text;
2076 static PyObject *__pyx_n_s__tid;
2077 static PyObject *__pyx_n_s__traceback;
2078 static PyObject *__pyx_n_s__types;
2079 static PyObject *__pyx_n_s__until_eof;
2080 static PyObject *__pyx_n_s__view;
2081 static PyObject *__pyx_n_s__w;
2082 static PyObject *__pyx_n_s__wb;
2083 static PyObject *__pyx_n_s__wbu;
2084 static PyObject *__pyx_n_s__wh;
2085 static PyObject *__pyx_n_s__where;
2086 static PyObject *__pyx_n_s__write;
2087 static PyObject *__pyx_n_s__x;
2088 static PyObject *__pyx_int_0;
2089 static PyObject *__pyx_int_1;
2090 static PyObject *__pyx_int_2;
2091 static PyObject *__pyx_int_4;
2092 static PyObject *__pyx_int_8;
2093 static PyObject *__pyx_int_16;
2094 static PyObject *__pyx_int_32;
2095 static PyObject *__pyx_int_64;
2096 static PyObject *__pyx_int_128;
2097 static PyObject *__pyx_int_255;
2098 static PyObject *__pyx_int_256;
2099 static PyObject *__pyx_int_512;
2100 static PyObject *__pyx_int_neg_127;
2101 static PyObject *__pyx_int_0660;
2102 static PyObject *__pyx_int_1024;
2103 static PyObject *__pyx_int_8000;
2104 static PyObject *__pyx_int_65535;
2105 static PyObject *__pyx_int_neg_32767;
2106 static PyObject *__pyx_int_536870912;
2107 static PyObject *__pyx_int_4294967295;
2108 static PyObject *__pyx_int_neg_2147483648;
2109 static PyObject *__pyx_k_16;
2110 static PyObject *__pyx_k_44;
2111 static PyObject *__pyx_k_62;
2112 static int __pyx_k_115;
2113 static PyObject *__pyx_k_160;
2114 static PyObject *__pyx_k_161;
2115 static PyObject *__pyx_k_tuple_4;
2116 static PyObject *__pyx_k_tuple_7;
2117 static PyObject *__pyx_k_tuple_8;
2118 static PyObject *__pyx_k_tuple_10;
2119 static PyObject *__pyx_k_tuple_29;
2120 static PyObject *__pyx_k_tuple_30;
2121 static PyObject *__pyx_k_tuple_32;
2122 static PyObject *__pyx_k_tuple_34;
2123 static PyObject *__pyx_k_tuple_37;
2124 static PyObject *__pyx_k_tuple_39;
2125 static PyObject *__pyx_k_tuple_41;
2126 static PyObject *__pyx_k_tuple_42;
2127 static PyObject *__pyx_k_tuple_43;
2128 static PyObject *__pyx_k_tuple_45;
2129 static PyObject *__pyx_k_tuple_47;
2130 static PyObject *__pyx_k_tuple_49;
2131 static PyObject *__pyx_k_tuple_51;
2132 static PyObject *__pyx_k_tuple_53;
2133 static PyObject *__pyx_k_tuple_55;
2134 static PyObject *__pyx_k_tuple_57;
2135 static PyObject *__pyx_k_tuple_61;
2136 static PyObject *__pyx_k_tuple_63;
2137 static PyObject *__pyx_k_tuple_64;
2138 static PyObject *__pyx_k_tuple_66;
2139 static PyObject *__pyx_k_tuple_67;
2140 static PyObject *__pyx_k_tuple_69;
2141 static PyObject *__pyx_k_tuple_70;
2142 static PyObject *__pyx_k_tuple_72;
2143 static PyObject *__pyx_k_tuple_73;
2144 static PyObject *__pyx_k_tuple_75;
2145 static PyObject *__pyx_k_tuple_76;
2146 static PyObject *__pyx_k_tuple_77;
2147 static PyObject *__pyx_k_tuple_78;
2148 static PyObject *__pyx_k_tuple_79;
2149 static PyObject *__pyx_k_tuple_80;
2150 static PyObject *__pyx_k_tuple_82;
2151 static PyObject *__pyx_k_tuple_83;
2152 static PyObject *__pyx_k_tuple_85;
2153 static PyObject *__pyx_k_tuple_86;
2154 static PyObject *__pyx_k_tuple_87;
2155 static PyObject *__pyx_k_tuple_88;
2156 static PyObject *__pyx_k_tuple_90;
2157 static PyObject *__pyx_k_tuple_92;
2158 static PyObject *__pyx_k_tuple_95;
2159 static PyObject *__pyx_k_tuple_102;
2160 static PyObject *__pyx_k_tuple_104;
2161 static PyObject *__pyx_k_tuple_105;
2162 static PyObject *__pyx_k_tuple_107;
2163 static PyObject *__pyx_k_tuple_108;
2164 static PyObject *__pyx_k_tuple_109;
2165 static PyObject *__pyx_k_tuple_110;
2166 static PyObject *__pyx_k_tuple_111;
2167 static PyObject *__pyx_k_tuple_117;
2168 static PyObject *__pyx_k_tuple_118;
2169 static PyObject *__pyx_k_tuple_134;
2170 static PyObject *__pyx_k_tuple_158;
2171 static PyObject *__pyx_k_tuple_159;
2172 static PyObject *__pyx_k_tuple_165;
2173 static PyObject *__pyx_k_tuple_233;
2174 static PyObject *__pyx_k_tuple_234;
2175 static PyObject *__pyx_k_tuple_235;
2176 static PyObject *__pyx_k_tuple_236;
2177 static PyObject *__pyx_k_tuple_237;
2178
2179 /* "csamtools.pyx":76
2180  * #####################################################################
2181  * cdef class AlignedRead
2182  * cdef makeAlignedRead(bam1_t * src):             # <<<<<<<<<<<<<<
2183  *     '''enter src into AlignedRead.'''
2184  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
2185  */
2186
2187 static  PyObject *__pyx_f_9csamtools_makeAlignedRead(bam1_t *__pyx_v_src) {
2188   struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_dest = 0;
2189   PyObject *__pyx_r = NULL;
2190   PyObject *__pyx_t_1 = NULL;
2191   __Pyx_TraceDeclarations
2192   __Pyx_RefNannySetupContext("makeAlignedRead");
2193   __Pyx_TraceCall("makeAlignedRead", __pyx_f[0], 76);
2194
2195   /* "csamtools.pyx":78
2196  * cdef makeAlignedRead(bam1_t * src):
2197  *     '''enter src into AlignedRead.'''
2198  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
2199  *     dest._delegate = bam_dup1(src)
2200  *     return dest
2201  */
2202   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2203   __Pyx_GOTREF(__pyx_t_1);
2204   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2205   __pyx_v_dest = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_1);
2206   __pyx_t_1 = 0;
2207
2208   /* "csamtools.pyx":79
2209  *     '''enter src into AlignedRead.'''
2210  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
2211  *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
2212  *     return dest
2213  * 
2214  */
2215   __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);
2216
2217   /* "csamtools.pyx":80
2218  *     cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
2219  *     dest._delegate = bam_dup1(src)
2220  *     return dest             # <<<<<<<<<<<<<<
2221  * 
2222  * cdef class PileupProxy
2223  */
2224   __Pyx_XDECREF(__pyx_r);
2225   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
2226   __pyx_r = ((PyObject *)__pyx_v_dest);
2227   goto __pyx_L0;
2228
2229   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2230   goto __pyx_L0;
2231   __pyx_L1_error:;
2232   __Pyx_XDECREF(__pyx_t_1);
2233   __Pyx_AddTraceback("csamtools.makeAlignedRead");
2234   __pyx_r = 0;
2235   __pyx_L0:;
2236   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
2237   __Pyx_XGIVEREF(__pyx_r);
2238   __Pyx_TraceReturn(__pyx_r);
2239   __Pyx_RefNannyFinishContext();
2240   return __pyx_r;
2241 }
2242
2243 /* "csamtools.pyx":83
2244  * 
2245  * cdef class PileupProxy
2246  * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):             # <<<<<<<<<<<<<<
2247  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
2248  *      dest.plp = plp
2249  */
2250
2251 static  PyObject *__pyx_f_9csamtools_makePileupProxy(bam_pileup1_t *__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n) {
2252   struct __pyx_obj_9csamtools_PileupProxy *__pyx_v_dest = 0;
2253   PyObject *__pyx_r = NULL;
2254   PyObject *__pyx_t_1 = NULL;
2255   __Pyx_TraceDeclarations
2256   __Pyx_RefNannySetupContext("makePileupProxy");
2257   __Pyx_TraceCall("makePileupProxy", __pyx_f[0], 83);
2258
2259   /* "csamtools.pyx":84
2260  * cdef class PileupProxy
2261  * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):
2262  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)             # <<<<<<<<<<<<<<
2263  *      dest.plp = plp
2264  *      dest.tid = tid
2265  */
2266   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_PileupProxy)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2267   __Pyx_GOTREF(__pyx_t_1);
2268   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_PileupProxy)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2269   __pyx_v_dest = ((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_t_1);
2270   __pyx_t_1 = 0;
2271
2272   /* "csamtools.pyx":85
2273  * cdef makePileupProxy( bam_pileup1_t * plp, int tid, int pos, int n ):
2274  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
2275  *      dest.plp = plp             # <<<<<<<<<<<<<<
2276  *      dest.tid = tid
2277  *      dest.pos = pos
2278  */
2279   __pyx_v_dest->plp = __pyx_v_plp;
2280
2281   /* "csamtools.pyx":86
2282  *      cdef PileupProxy dest = PileupProxy.__new__(PileupProxy)
2283  *      dest.plp = plp
2284  *      dest.tid = tid             # <<<<<<<<<<<<<<
2285  *      dest.pos = pos
2286  *      dest.n = n
2287  */
2288   __pyx_v_dest->tid = __pyx_v_tid;
2289
2290   /* "csamtools.pyx":87
2291  *      dest.plp = plp
2292  *      dest.tid = tid
2293  *      dest.pos = pos             # <<<<<<<<<<<<<<
2294  *      dest.n = n
2295  *      return dest
2296  */
2297   __pyx_v_dest->pos = __pyx_v_pos;
2298
2299   /* "csamtools.pyx":88
2300  *      dest.tid = tid
2301  *      dest.pos = pos
2302  *      dest.n = n             # <<<<<<<<<<<<<<
2303  *      return dest
2304  * 
2305  */
2306   __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2307   __Pyx_GOTREF(__pyx_t_1);
2308   if (PyObject_SetAttr(((PyObject *)__pyx_v_dest), __pyx_n_s__n, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2309   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2310
2311   /* "csamtools.pyx":89
2312  *      dest.pos = pos
2313  *      dest.n = n
2314  *      return dest             # <<<<<<<<<<<<<<
2315  * 
2316  * cdef class PileupRead
2317  */
2318   __Pyx_XDECREF(__pyx_r);
2319   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
2320   __pyx_r = ((PyObject *)__pyx_v_dest);
2321   goto __pyx_L0;
2322
2323   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2324   goto __pyx_L0;
2325   __pyx_L1_error:;
2326   __Pyx_XDECREF(__pyx_t_1);
2327   __Pyx_AddTraceback("csamtools.makePileupProxy");
2328   __pyx_r = 0;
2329   __pyx_L0:;
2330   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
2331   __Pyx_XGIVEREF(__pyx_r);
2332   __Pyx_TraceReturn(__pyx_r);
2333   __Pyx_RefNannyFinishContext();
2334   return __pyx_r;
2335 }
2336
2337 /* "csamtools.pyx":92
2338  * 
2339  * cdef class PileupRead
2340  * cdef makePileupRead( bam_pileup1_t * src ):             # <<<<<<<<<<<<<<
2341  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
2342  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
2343  */
2344
2345 static  PyObject *__pyx_f_9csamtools_makePileupRead(bam_pileup1_t *__pyx_v_src) {
2346   struct __pyx_obj_9csamtools_PileupRead *__pyx_v_dest = 0;
2347   PyObject *__pyx_r = NULL;
2348   PyObject *__pyx_t_1 = NULL;
2349   __Pyx_TraceDeclarations
2350   __Pyx_RefNannySetupContext("makePileupRead");
2351   __Pyx_TraceCall("makePileupRead", __pyx_f[0], 92);
2352
2353   /* "csamtools.pyx":94
2354  * cdef makePileupRead( bam_pileup1_t * src ):
2355  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
2356  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)             # <<<<<<<<<<<<<<
2357  *     dest._alignment = makeAlignedRead( src.b )
2358  *     dest._qpos = src.qpos
2359  */
2360   __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_PileupRead)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2361   __Pyx_GOTREF(__pyx_t_1);
2362   if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2363   __pyx_v_dest = ((struct __pyx_obj_9csamtools_PileupRead *)__pyx_t_1);
2364   __pyx_t_1 = 0;
2365
2366   /* "csamtools.pyx":95
2367  *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
2368  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
2369  *     dest._alignment = makeAlignedRead( src.b )             # <<<<<<<<<<<<<<
2370  *     dest._qpos = src.qpos
2371  *     dest._indel = src.indel
2372  */
2373   __pyx_t_1 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2374   __Pyx_GOTREF(__pyx_t_1);
2375   if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_9csamtools_AlignedRead))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2376   __Pyx_GIVEREF(__pyx_t_1);
2377   __Pyx_GOTREF(__pyx_v_dest->_alignment);
2378   __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
2379   __pyx_v_dest->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_1);
2380   __pyx_t_1 = 0;
2381
2382   /* "csamtools.pyx":96
2383  *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
2384  *     dest._alignment = makeAlignedRead( src.b )
2385  *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
2386  *     dest._indel = src.indel
2387  *     dest._level = src.level
2388  */
2389   __pyx_v_dest->_qpos = __pyx_v_src->qpos;
2390
2391   /* "csamtools.pyx":97
2392  *     dest._alignment = makeAlignedRead( src.b )
2393  *     dest._qpos = src.qpos
2394  *     dest._indel = src.indel             # <<<<<<<<<<<<<<
2395  *     dest._level = src.level
2396  *     dest._is_del = src.is_del
2397  */
2398   __pyx_v_dest->_indel = __pyx_v_src->indel;
2399
2400   /* "csamtools.pyx":98
2401  *     dest._qpos = src.qpos
2402  *     dest._indel = src.indel
2403  *     dest._level = src.level             # <<<<<<<<<<<<<<
2404  *     dest._is_del = src.is_del
2405  *     dest._is_head = src.is_head
2406  */
2407   __pyx_v_dest->_level = __pyx_v_src->level;
2408
2409   /* "csamtools.pyx":99
2410  *     dest._indel = src.indel
2411  *     dest._level = src.level
2412  *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
2413  *     dest._is_head = src.is_head
2414  *     dest._is_tail = src.is_tail
2415  */
2416   __pyx_v_dest->_is_del = __pyx_v_src->is_del;
2417
2418   /* "csamtools.pyx":100
2419  *     dest._level = src.level
2420  *     dest._is_del = src.is_del
2421  *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
2422  *     dest._is_tail = src.is_tail
2423  *     return dest
2424  */
2425   __pyx_v_dest->_is_head = __pyx_v_src->is_head;
2426
2427   /* "csamtools.pyx":101
2428  *     dest._is_del = src.is_del
2429  *     dest._is_head = src.is_head
2430  *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
2431  *     return dest
2432  * 
2433  */
2434   __pyx_v_dest->_is_tail = __pyx_v_src->is_tail;
2435
2436   /* "csamtools.pyx":102
2437  *     dest._is_head = src.is_head
2438  *     dest._is_tail = src.is_tail
2439  *     return dest             # <<<<<<<<<<<<<<
2440  * 
2441  * #####################################################################
2442  */
2443   __Pyx_XDECREF(__pyx_r);
2444   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
2445   __pyx_r = ((PyObject *)__pyx_v_dest);
2446   goto __pyx_L0;
2447
2448   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2449   goto __pyx_L0;
2450   __pyx_L1_error:;
2451   __Pyx_XDECREF(__pyx_t_1);
2452   __Pyx_AddTraceback("csamtools.makePileupRead");
2453   __pyx_r = 0;
2454   __pyx_L0:;
2455   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
2456   __Pyx_XGIVEREF(__pyx_r);
2457   __Pyx_TraceReturn(__pyx_r);
2458   __Pyx_RefNannyFinishContext();
2459   return __pyx_r;
2460 }
2461
2462 /* "csamtools.pyx":109
2463  * ## Generic callbacks for inserting python callbacks.
2464  * #####################################################################
2465  * cdef int fetch_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
2466  *     '''callback for bam_fetch.
2467  * 
2468  */
2469
2470 static  int __pyx_f_9csamtools_fetch_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
2471   PyObject *__pyx_v_a;
2472   int __pyx_r;
2473   PyObject *__pyx_t_1 = NULL;
2474   PyObject *__pyx_t_2 = NULL;
2475   __Pyx_TraceDeclarations
2476   __Pyx_RefNannySetupContext("fetch_callback");
2477   __Pyx_TraceCall("fetch_callback", __pyx_f[0], 109);
2478   __pyx_v_a = Py_None; __Pyx_INCREF(Py_None);
2479
2480   /* "csamtools.pyx":114
2481  *     calls function in *f* with a new :class:`AlignedRead` object as parameter.
2482  *     '''
2483  *     a = makeAlignedRead( alignment )             # <<<<<<<<<<<<<<
2484  *     (<object>f)(a)
2485  * 
2486  */
2487   __pyx_t_1 = __pyx_f_9csamtools_makeAlignedRead(__pyx_v_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2488   __Pyx_GOTREF(__pyx_t_1);
2489   __Pyx_DECREF(__pyx_v_a);
2490   __pyx_v_a = __pyx_t_1;
2491   __pyx_t_1 = 0;
2492
2493   /* "csamtools.pyx":115
2494  *     '''
2495  *     a = makeAlignedRead( alignment )
2496  *     (<object>f)(a)             # <<<<<<<<<<<<<<
2497  * 
2498  * class PileupColumn(object):
2499  */
2500   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2501   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
2502   __Pyx_INCREF(__pyx_v_a);
2503   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
2504   __Pyx_GIVEREF(__pyx_v_a);
2505   __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 = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2506   __Pyx_GOTREF(__pyx_t_2);
2507   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
2508   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2509
2510   __pyx_r = 0;
2511   goto __pyx_L0;
2512   __pyx_L1_error:;
2513   __Pyx_XDECREF(__pyx_t_1);
2514   __Pyx_XDECREF(__pyx_t_2);
2515   __Pyx_WriteUnraisable("csamtools.fetch_callback");
2516   __pyx_r = 0;
2517   __pyx_L0:;
2518   __Pyx_DECREF(__pyx_v_a);
2519   __Pyx_TraceReturn(Py_None);
2520   __Pyx_RefNannyFinishContext();
2521   return __pyx_r;
2522 }
2523
2524 /* "csamtools.pyx":130
2525  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
2526  *     '''
2527  *     def __str__(self):             # <<<<<<<<<<<<<<
2528  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
2529  *             "\n" + "\n".join( map(str, self.pileups) )
2530  */
2531
2532 static PyObject *__pyx_pf_9csamtools_12PileupColumn___str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
2533 static char __pyx_doc_9csamtools_12PileupColumn___str__[] = "PileupColumn.__str__(self)";
2534 static PyMethodDef __pyx_mdef_9csamtools_12PileupColumn___str__ = {__Pyx_NAMESTR("__str__"), (PyCFunction)__pyx_pf_9csamtools_12PileupColumn___str__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_12PileupColumn___str__)};
2535 static PyObject *__pyx_pf_9csamtools_12PileupColumn___str__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
2536   PyObject *__pyx_r = NULL;
2537   PyObject *__pyx_t_1 = NULL;
2538   PyObject *__pyx_t_2 = NULL;
2539   PyObject *__pyx_t_3 = NULL;
2540   PyObject *__pyx_t_4 = NULL;
2541   PyObject *__pyx_t_5 = NULL;
2542   __Pyx_TraceDeclarations
2543   __Pyx_RefNannySetupContext("__str__");
2544   __Pyx_TraceCall("__str__", __pyx_f[0], 130);
2545   __pyx_self = __pyx_self;
2546
2547   /* "csamtools.pyx":131
2548  *     '''
2549  *     def __str__(self):
2550  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
2551  *             "\n" + "\n".join( map(str, self.pileups) )
2552  * 
2553  */
2554   __Pyx_XDECREF(__pyx_r);
2555
2556   /* "csamtools.pyx":132
2557  *     def __str__(self):
2558  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
2559  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
2560  * 
2561  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
2562  */
2563   __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2564   __Pyx_GOTREF(__pyx_t_1);
2565
2566   /* "csamtools.pyx":131
2567  *     '''
2568  *     def __str__(self):
2569  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
2570  *             "\n" + "\n".join( map(str, self.pileups) )
2571  * 
2572  */
2573   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2574   __Pyx_GOTREF(__pyx_t_2);
2575   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2576   __Pyx_GOTREF(__pyx_t_3);
2577   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2578   __Pyx_GOTREF(__pyx_t_4);
2579   __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2580   __Pyx_GOTREF(((PyObject *)__pyx_t_5));
2581   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
2582   __Pyx_GIVEREF(__pyx_t_2);
2583   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
2584   __Pyx_GIVEREF(__pyx_t_3);
2585   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
2586   __Pyx_GIVEREF(__pyx_t_4);
2587   __pyx_t_2 = 0;
2588   __pyx_t_3 = 0;
2589   __pyx_t_4 = 0;
2590   __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2591   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
2592   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
2593   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
2594   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
2595   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
2596   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
2597   __pyx_t_5 = 0;
2598   __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2599   __Pyx_GOTREF(__pyx_t_5);
2600   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
2601   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2602   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
2603   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
2604   __Pyx_GIVEREF(__pyx_t_5);
2605   __pyx_t_5 = 0;
2606   __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2607   __Pyx_GOTREF(__pyx_t_5);
2608   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2609   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
2610   __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2611   __Pyx_GOTREF(__pyx_t_4);
2612   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2613
2614   /* "csamtools.pyx":132
2615  *     def __str__(self):
2616  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
2617  *             "\n" + "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
2618  * 
2619  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):
2620  */
2621   __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2622   __Pyx_GOTREF(__pyx_t_5);
2623   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2624   __Pyx_GOTREF(__pyx_t_1);
2625   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2626   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
2627   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
2628   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
2629   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
2630   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
2631   __Pyx_GIVEREF(__pyx_t_1);
2632   __pyx_t_1 = 0;
2633   __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 = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2634   __Pyx_GOTREF(__pyx_t_1);
2635   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
2636   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2637   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
2638   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
2639   __Pyx_GIVEREF(__pyx_t_1);
2640   __pyx_t_1 = 0;
2641   __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 = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2642   __Pyx_GOTREF(__pyx_t_1);
2643   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
2644   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
2645   __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2646   __Pyx_GOTREF(__pyx_t_3);
2647   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
2648   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2649   __pyx_r = __pyx_t_3;
2650   __pyx_t_3 = 0;
2651   goto __pyx_L0;
2652
2653   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2654   goto __pyx_L0;
2655   __pyx_L1_error:;
2656   __Pyx_XDECREF(__pyx_t_1);
2657   __Pyx_XDECREF(__pyx_t_2);
2658   __Pyx_XDECREF(__pyx_t_3);
2659   __Pyx_XDECREF(__pyx_t_4);
2660   __Pyx_XDECREF(__pyx_t_5);
2661   __Pyx_AddTraceback("csamtools.PileupColumn.__str__");
2662   __pyx_r = NULL;
2663   __pyx_L0:;
2664   __Pyx_XGIVEREF(__pyx_r);
2665   __Pyx_TraceReturn(__pyx_r);
2666   __Pyx_RefNannyFinishContext();
2667   return __pyx_r;
2668 }
2669
2670 /* "csamtools.pyx":134
2671  *             "\n" + "\n".join( map(str, self.pileups) )
2672  * 
2673  * cdef int pileup_callback( uint32_t tid, uint32_t pos, int n, bam_pileup1_t *pl, void *f):             # <<<<<<<<<<<<<<
2674  *     '''callback for pileup.
2675  * 
2676  */
2677
2678 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) {
2679   PyObject *__pyx_v_p;
2680   PyObject *__pyx_v_pileups;
2681   int __pyx_v_x;
2682   int __pyx_r;
2683   PyObject *__pyx_t_1 = NULL;
2684   PyObject *__pyx_t_2 = NULL;
2685   int __pyx_t_3;
2686   int __pyx_t_4;
2687   __Pyx_TraceDeclarations
2688   __Pyx_RefNannySetupContext("pileup_callback");
2689   __Pyx_TraceCall("pileup_callback", __pyx_f[0], 134);
2690   __pyx_v_p = Py_None; __Pyx_INCREF(Py_None);
2691   __pyx_v_pileups = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
2692
2693   /* "csamtools.pyx":151
2694  *     '''
2695  * 
2696  *     p = PileupColumn()             # <<<<<<<<<<<<<<
2697  *     p.tid = tid
2698  *     p.pos = pos
2699  */
2700   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__PileupColumn); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2701   __Pyx_GOTREF(__pyx_t_1);
2702   __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 = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2703   __Pyx_GOTREF(__pyx_t_2);
2704   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2705   __Pyx_DECREF(__pyx_v_p);
2706   __pyx_v_p = __pyx_t_2;
2707   __pyx_t_2 = 0;
2708
2709   /* "csamtools.pyx":152
2710  * 
2711  *     p = PileupColumn()
2712  *     p.tid = tid             # <<<<<<<<<<<<<<
2713  *     p.pos = pos
2714  *     p.n = n
2715  */
2716   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2717   __Pyx_GOTREF(__pyx_t_2);
2718   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__tid, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2719   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2720
2721   /* "csamtools.pyx":153
2722  *     p = PileupColumn()
2723  *     p.tid = tid
2724  *     p.pos = pos             # <<<<<<<<<<<<<<
2725  *     p.n = n
2726  *     pileups = []
2727  */
2728   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2729   __Pyx_GOTREF(__pyx_t_2);
2730   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pos, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2731   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2732
2733   /* "csamtools.pyx":154
2734  *     p.tid = tid
2735  *     p.pos = pos
2736  *     p.n = n             # <<<<<<<<<<<<<<
2737  *     pileups = []
2738  * 
2739  */
2740   __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2741   __Pyx_GOTREF(__pyx_t_2);
2742   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__n, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2743   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2744
2745   /* "csamtools.pyx":155
2746  *     p.pos = pos
2747  *     p.n = n
2748  *     pileups = []             # <<<<<<<<<<<<<<
2749  * 
2750  *     cdef int x
2751  */
2752   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2753   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2754   __Pyx_DECREF(((PyObject *)__pyx_v_pileups));
2755   __pyx_v_pileups = __pyx_t_2;
2756   __pyx_t_2 = 0;
2757
2758   /* "csamtools.pyx":158
2759  * 
2760  *     cdef int x
2761  *     for x from 0 <= x < n:             # <<<<<<<<<<<<<<
2762  *         pileups.append( makePileupRead( &(pl[x]) ) )
2763  *     p.pileups = pileups
2764  */
2765   __pyx_t_3 = __pyx_v_n;
2766   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_3; __pyx_v_x++) {
2767
2768     /* "csamtools.pyx":159
2769  *     cdef int x
2770  *     for x from 0 <= x < n:
2771  *         pileups.append( makePileupRead( &(pl[x]) ) )             # <<<<<<<<<<<<<<
2772  *     p.pileups = pileups
2773  * 
2774  */
2775     if (unlikely(__pyx_v_pileups == Py_None)) {
2776       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
2777     }
2778     __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 = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2779     __Pyx_GOTREF(__pyx_t_2);
2780     __pyx_t_4 = PyList_Append(__pyx_v_pileups, __pyx_t_2); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2781     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2782   }
2783
2784   /* "csamtools.pyx":160
2785  *     for x from 0 <= x < n:
2786  *         pileups.append( makePileupRead( &(pl[x]) ) )
2787  *     p.pileups = pileups             # <<<<<<<<<<<<<<
2788  * 
2789  *     (<object>f)(p)
2790  */
2791   if (PyObject_SetAttr(__pyx_v_p, __pyx_n_s__pileups, ((PyObject *)__pyx_v_pileups)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2792
2793   /* "csamtools.pyx":162
2794  *     p.pileups = pileups
2795  * 
2796  *     (<object>f)(p)             # <<<<<<<<<<<<<<
2797  * 
2798  * cdef int pileup_fetch_callback( bam1_t *b, void *data):
2799  */
2800   __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2801   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
2802   __Pyx_INCREF(__pyx_v_p);
2803   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_p);
2804   __Pyx_GIVEREF(__pyx_v_p);
2805   __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 = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2806   __Pyx_GOTREF(__pyx_t_1);
2807   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
2808   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2809
2810   __pyx_r = 0;
2811   goto __pyx_L0;
2812   __pyx_L1_error:;
2813   __Pyx_XDECREF(__pyx_t_1);
2814   __Pyx_XDECREF(__pyx_t_2);
2815   __Pyx_WriteUnraisable("csamtools.pileup_callback");
2816   __pyx_r = 0;
2817   __pyx_L0:;
2818   __Pyx_DECREF(__pyx_v_p);
2819   __Pyx_DECREF(__pyx_v_pileups);
2820   __Pyx_TraceReturn(Py_None);
2821   __Pyx_RefNannyFinishContext();
2822   return __pyx_r;
2823 }
2824
2825 /* "csamtools.pyx":164
2826  *     (<object>f)(p)
2827  * 
2828  * cdef int pileup_fetch_callback( bam1_t *b, void *data):             # <<<<<<<<<<<<<<
2829  *     '''callback for bam_fetch.
2830  * 
2831  */
2832
2833 static  int __pyx_f_9csamtools_pileup_fetch_callback(bam1_t *__pyx_v_b, void *__pyx_v_data) {
2834   bam_plbuf_t *__pyx_v_buf;
2835   int __pyx_r;
2836   __Pyx_TraceDeclarations
2837   __Pyx_RefNannySetupContext("pileup_fetch_callback");
2838   __Pyx_TraceCall("pileup_fetch_callback", __pyx_f[0], 164);
2839
2840   /* "csamtools.pyx":170
2841  *     '''
2842  *     cdef bam_plbuf_t * buf
2843  *     buf = <bam_plbuf_t*>data             # <<<<<<<<<<<<<<
2844  *     bam_plbuf_push(b, buf)
2845  *     return 0
2846  */
2847   __pyx_v_buf = ((bam_plbuf_t *)__pyx_v_data);
2848
2849   /* "csamtools.pyx":171
2850  *     cdef bam_plbuf_t * buf
2851  *     buf = <bam_plbuf_t*>data
2852  *     bam_plbuf_push(b, buf)             # <<<<<<<<<<<<<<
2853  *     return 0
2854  * 
2855  */
2856   bam_plbuf_push(__pyx_v_b, __pyx_v_buf);
2857
2858   /* "csamtools.pyx":172
2859  *     buf = <bam_plbuf_t*>data
2860  *     bam_plbuf_push(b, buf)
2861  *     return 0             # <<<<<<<<<<<<<<
2862  * 
2863  * class StderrStore():
2864  */
2865   __pyx_r = 0;
2866   goto __pyx_L0;
2867
2868   __pyx_r = 0;
2869   __pyx_L0:;
2870   __Pyx_TraceReturn(Py_None);
2871   __Pyx_RefNannyFinishContext();
2872   return __pyx_r;
2873 }
2874
2875 /* "csamtools.pyx":178
2876  *     stderr is captured.
2877  *     '''
2878  *     def __init__(self):             # <<<<<<<<<<<<<<
2879  *         return
2880  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
2881  */
2882
2883 static PyObject *__pyx_pf_9csamtools_11StderrStore___init__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
2884 static char __pyx_doc_9csamtools_11StderrStore___init__[] = "StderrStore.__init__(self)";
2885 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_9csamtools_11StderrStore___init__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore___init__)};
2886 static PyObject *__pyx_pf_9csamtools_11StderrStore___init__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
2887   PyObject *__pyx_r = NULL;
2888   PyObject *__pyx_t_1 = NULL;
2889   PyObject *__pyx_t_2 = NULL;
2890   PyObject *__pyx_t_3 = NULL;
2891   PyObject *__pyx_t_4 = NULL;
2892   __Pyx_TraceDeclarations
2893   __Pyx_RefNannySetupContext("__init__");
2894   __Pyx_TraceCall("__init__", __pyx_f[0], 178);
2895   __pyx_self = __pyx_self;
2896
2897   /* "csamtools.pyx":179
2898  *     '''
2899  *     def __init__(self):
2900  *         return             # <<<<<<<<<<<<<<
2901  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
2902  *         self.stderr_save = Outs( sys.stderr.fileno() )
2903  */
2904   __Pyx_XDECREF(__pyx_r);
2905   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
2906   goto __pyx_L0;
2907
2908   /* "csamtools.pyx":180
2909  *     def __init__(self):
2910  *         return
2911  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
2912  *         self.stderr_save = Outs( sys.stderr.fileno() )
2913  *         self.stderr_save.setfd( self.stderr_h )
2914  */
2915   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2916   __Pyx_GOTREF(__pyx_t_1);
2917   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2918   __Pyx_GOTREF(__pyx_t_2);
2919   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2920   __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 = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2921   __Pyx_GOTREF(__pyx_t_1);
2922   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2923   if (PyTuple_CheckExact(__pyx_t_1) && likely(PyTuple_GET_SIZE(__pyx_t_1) == 2)) {
2924     PyObject* tuple = __pyx_t_1;
2925     __pyx_t_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_2);
2926     __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
2927     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2928     if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_h, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2929     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2930     if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_f, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2931     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2932   } else {
2933     __pyx_t_4 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2934     __Pyx_GOTREF(__pyx_t_4);
2935     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2936     __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_4, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2937     __Pyx_GOTREF(__pyx_t_2);
2938     __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_4, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2939     __Pyx_GOTREF(__pyx_t_3);
2940     if (__Pyx_EndUnpack(__pyx_t_4, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2941     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
2942     if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_h, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2943     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2944     if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_f, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2945     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2946   }
2947
2948   /* "csamtools.pyx":181
2949  *         return
2950  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
2951  *         self.stderr_save = Outs( sys.stderr.fileno() )             # <<<<<<<<<<<<<<
2952  *         self.stderr_save.setfd( self.stderr_h )
2953  * 
2954  */
2955   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2956   __Pyx_GOTREF(__pyx_t_1);
2957   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2958   __Pyx_GOTREF(__pyx_t_3);
2959   __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2960   __Pyx_GOTREF(__pyx_t_2);
2961   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2962   __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2963   __Pyx_GOTREF(__pyx_t_3);
2964   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2965   __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 = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2966   __Pyx_GOTREF(__pyx_t_2);
2967   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
2968   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2969   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
2970   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
2971   __Pyx_GIVEREF(__pyx_t_2);
2972   __pyx_t_2 = 0;
2973   __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 = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2974   __Pyx_GOTREF(__pyx_t_2);
2975   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2976   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
2977   if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__stderr_save, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2978   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2979
2980   /* "csamtools.pyx":182
2981  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
2982  *         self.stderr_save = Outs( sys.stderr.fileno() )
2983  *         self.stderr_save.setfd( self.stderr_h )             # <<<<<<<<<<<<<<
2984  * 
2985  *     def readAndRelease( self ):
2986  */
2987   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2988   __Pyx_GOTREF(__pyx_t_2);
2989   __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2990   __Pyx_GOTREF(__pyx_t_3);
2991   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
2992   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_h); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2993   __Pyx_GOTREF(__pyx_t_2);
2994   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
2995   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
2996   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
2997   __Pyx_GIVEREF(__pyx_t_2);
2998   __pyx_t_2 = 0;
2999   __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 = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3000   __Pyx_GOTREF(__pyx_t_2);
3001   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3002   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
3003   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3004
3005   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3006   goto __pyx_L0;
3007   __pyx_L1_error:;
3008   __Pyx_XDECREF(__pyx_t_1);
3009   __Pyx_XDECREF(__pyx_t_2);
3010   __Pyx_XDECREF(__pyx_t_3);
3011   __Pyx_XDECREF(__pyx_t_4);
3012   __Pyx_AddTraceback("csamtools.StderrStore.__init__");
3013   __pyx_r = NULL;
3014   __pyx_L0:;
3015   __Pyx_XGIVEREF(__pyx_r);
3016   __Pyx_TraceReturn(__pyx_r);
3017   __Pyx_RefNannyFinishContext();
3018   return __pyx_r;
3019 }
3020
3021 /* "csamtools.pyx":184
3022  *         self.stderr_save.setfd( self.stderr_h )
3023  * 
3024  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
3025  *         return []
3026  *         self.stderr_save.restore()
3027  */
3028
3029 static PyObject *__pyx_pf_9csamtools_11StderrStore_1readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3030 static char __pyx_doc_9csamtools_11StderrStore_1readAndRelease[] = "StderrStore.readAndRelease(self)";
3031 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_1readAndRelease = {__Pyx_NAMESTR("readAndRelease"), (PyCFunction)__pyx_pf_9csamtools_11StderrStore_1readAndRelease, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_1readAndRelease)};
3032 static PyObject *__pyx_pf_9csamtools_11StderrStore_1readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3033   PyObject *__pyx_v_lines;
3034   PyObject *__pyx_r = NULL;
3035   PyObject *__pyx_t_1 = NULL;
3036   PyObject *__pyx_t_2 = NULL;
3037   PyObject *__pyx_t_3 = NULL;
3038   int __pyx_t_4;
3039   __Pyx_TraceDeclarations
3040   __Pyx_RefNannySetupContext("readAndRelease");
3041   __Pyx_TraceCall("readAndRelease", __pyx_f[0], 184);
3042   __pyx_self = __pyx_self;
3043   __pyx_v_lines = Py_None; __Pyx_INCREF(Py_None);
3044
3045   /* "csamtools.pyx":185
3046  * 
3047  *     def readAndRelease( self ):
3048  *         return []             # <<<<<<<<<<<<<<
3049  *         self.stderr_save.restore()
3050  *         lines = []
3051  */
3052   __Pyx_XDECREF(__pyx_r);
3053   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3054   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
3055   __pyx_r = ((PyObject *)__pyx_t_1);
3056   __pyx_t_1 = 0;
3057   goto __pyx_L0;
3058
3059   /* "csamtools.pyx":186
3060  *     def readAndRelease( self ):
3061  *         return []
3062  *         self.stderr_save.restore()             # <<<<<<<<<<<<<<
3063  *         lines = []
3064  *         if os.path.exists(self.stderr_f):
3065  */
3066   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3067   __Pyx_GOTREF(__pyx_t_1);
3068   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3069   __Pyx_GOTREF(__pyx_t_2);
3070   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3071   __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 = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3072   __Pyx_GOTREF(__pyx_t_1);
3073   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3074   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3075
3076   /* "csamtools.pyx":187
3077  *         return []
3078  *         self.stderr_save.restore()
3079  *         lines = []             # <<<<<<<<<<<<<<
3080  *         if os.path.exists(self.stderr_f):
3081  *             lines = open( self.stderr_f, "r" ).readlines()
3082  */
3083   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3084   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
3085   __Pyx_DECREF(__pyx_v_lines);
3086   __pyx_v_lines = ((PyObject *)__pyx_t_1);
3087   __pyx_t_1 = 0;
3088
3089   /* "csamtools.pyx":188
3090  *         self.stderr_save.restore()
3091  *         lines = []
3092  *         if os.path.exists(self.stderr_f):             # <<<<<<<<<<<<<<
3093  *             lines = open( self.stderr_f, "r" ).readlines()
3094  *             os.remove( self.stderr_f )
3095  */
3096   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3097   __Pyx_GOTREF(__pyx_t_1);
3098   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3099   __Pyx_GOTREF(__pyx_t_2);
3100   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3101   __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3102   __Pyx_GOTREF(__pyx_t_1);
3103   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3104   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3105   __Pyx_GOTREF(__pyx_t_2);
3106   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3107   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
3108   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
3109   __Pyx_GIVEREF(__pyx_t_2);
3110   __pyx_t_2 = 0;
3111   __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 = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3112   __Pyx_GOTREF(__pyx_t_2);
3113   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3114   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3115   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3116   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3117   if (__pyx_t_4) {
3118
3119     /* "csamtools.pyx":189
3120  *         lines = []
3121  *         if os.path.exists(self.stderr_f):
3122  *             lines = open( self.stderr_f, "r" ).readlines()             # <<<<<<<<<<<<<<
3123  *             os.remove( self.stderr_f )
3124  *         return lines
3125  */
3126     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3127     __Pyx_GOTREF(__pyx_t_2);
3128     __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3129     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
3130     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
3131     __Pyx_GIVEREF(__pyx_t_2);
3132     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
3133     PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__r));
3134     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
3135     __pyx_t_2 = 0;
3136     __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3137     __Pyx_GOTREF(__pyx_t_2);
3138     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3139     __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__readlines); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3140     __Pyx_GOTREF(__pyx_t_3);
3141     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3142     __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 = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3143     __Pyx_GOTREF(__pyx_t_2);
3144     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3145     __Pyx_DECREF(__pyx_v_lines);
3146     __pyx_v_lines = __pyx_t_2;
3147     __pyx_t_2 = 0;
3148
3149     /* "csamtools.pyx":190
3150  *         if os.path.exists(self.stderr_f):
3151  *             lines = open( self.stderr_f, "r" ).readlines()
3152  *             os.remove( self.stderr_f )             # <<<<<<<<<<<<<<
3153  *         return lines
3154  * 
3155  */
3156     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3157     __Pyx_GOTREF(__pyx_t_2);
3158     __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__remove); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3159     __Pyx_GOTREF(__pyx_t_3);
3160     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3161     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3162     __Pyx_GOTREF(__pyx_t_2);
3163     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3164     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
3165     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
3166     __Pyx_GIVEREF(__pyx_t_2);
3167     __pyx_t_2 = 0;
3168     __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 = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3169     __Pyx_GOTREF(__pyx_t_2);
3170     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3171     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
3172     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3173     goto __pyx_L5;
3174   }
3175   __pyx_L5:;
3176
3177   /* "csamtools.pyx":191
3178  *             lines = open( self.stderr_f, "r" ).readlines()
3179  *             os.remove( self.stderr_f )
3180  *         return lines             # <<<<<<<<<<<<<<
3181  * 
3182  *     def release(self):
3183  */
3184   __Pyx_XDECREF(__pyx_r);
3185   __Pyx_INCREF(__pyx_v_lines);
3186   __pyx_r = __pyx_v_lines;
3187   goto __pyx_L0;
3188
3189   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3190   goto __pyx_L0;
3191   __pyx_L1_error:;
3192   __Pyx_XDECREF(__pyx_t_1);
3193   __Pyx_XDECREF(__pyx_t_2);
3194   __Pyx_XDECREF(__pyx_t_3);
3195   __Pyx_AddTraceback("csamtools.StderrStore.readAndRelease");
3196   __pyx_r = NULL;
3197   __pyx_L0:;
3198   __Pyx_DECREF(__pyx_v_lines);
3199   __Pyx_XGIVEREF(__pyx_r);
3200   __Pyx_TraceReturn(__pyx_r);
3201   __Pyx_RefNannyFinishContext();
3202   return __pyx_r;
3203 }
3204
3205 /* "csamtools.pyx":193
3206  *         return lines
3207  * 
3208  *     def release(self):             # <<<<<<<<<<<<<<
3209  *         return
3210  *         self.stderr_save.restore()
3211  */
3212
3213 static PyObject *__pyx_pf_9csamtools_11StderrStore_2release(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3214 static char __pyx_doc_9csamtools_11StderrStore_2release[] = "StderrStore.release(self)";
3215 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_2release = {__Pyx_NAMESTR("release"), (PyCFunction)__pyx_pf_9csamtools_11StderrStore_2release, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_2release)};
3216 static PyObject *__pyx_pf_9csamtools_11StderrStore_2release(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3217   PyObject *__pyx_r = NULL;
3218   PyObject *__pyx_t_1 = NULL;
3219   PyObject *__pyx_t_2 = NULL;
3220   PyObject *__pyx_t_3 = NULL;
3221   int __pyx_t_4;
3222   __Pyx_TraceDeclarations
3223   __Pyx_RefNannySetupContext("release");
3224   __Pyx_TraceCall("release", __pyx_f[0], 193);
3225   __pyx_self = __pyx_self;
3226
3227   /* "csamtools.pyx":194
3228  * 
3229  *     def release(self):
3230  *         return             # <<<<<<<<<<<<<<
3231  *         self.stderr_save.restore()
3232  *         if os.path.exists(self.stderr_f):
3233  */
3234   __Pyx_XDECREF(__pyx_r);
3235   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3236   goto __pyx_L0;
3237
3238   /* "csamtools.pyx":195
3239  *     def release(self):
3240  *         return
3241  *         self.stderr_save.restore()             # <<<<<<<<<<<<<<
3242  *         if os.path.exists(self.stderr_f):
3243  *             os.remove( self.stderr_f )
3244  */
3245   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_save); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3246   __Pyx_GOTREF(__pyx_t_1);
3247   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__restore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3248   __Pyx_GOTREF(__pyx_t_2);
3249   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3250   __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 = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3251   __Pyx_GOTREF(__pyx_t_1);
3252   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3253   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3254
3255   /* "csamtools.pyx":196
3256  *         return
3257  *         self.stderr_save.restore()
3258  *         if os.path.exists(self.stderr_f):             # <<<<<<<<<<<<<<
3259  *             os.remove( self.stderr_f )
3260  * 
3261  */
3262   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3263   __Pyx_GOTREF(__pyx_t_1);
3264   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3265   __Pyx_GOTREF(__pyx_t_2);
3266   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3267   __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3268   __Pyx_GOTREF(__pyx_t_1);
3269   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3270   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3271   __Pyx_GOTREF(__pyx_t_2);
3272   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3273   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
3274   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
3275   __Pyx_GIVEREF(__pyx_t_2);
3276   __pyx_t_2 = 0;
3277   __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 = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3278   __Pyx_GOTREF(__pyx_t_2);
3279   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3280   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3281   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3282   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3283   if (__pyx_t_4) {
3284
3285     /* "csamtools.pyx":197
3286  *         self.stderr_save.restore()
3287  *         if os.path.exists(self.stderr_f):
3288  *             os.remove( self.stderr_f )             # <<<<<<<<<<<<<<
3289  * 
3290  *     def __del__(self):
3291  */
3292     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3293     __Pyx_GOTREF(__pyx_t_2);
3294     __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__remove); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3295     __Pyx_GOTREF(__pyx_t_3);
3296     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3297     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__stderr_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3298     __Pyx_GOTREF(__pyx_t_2);
3299     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3300     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
3301     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
3302     __Pyx_GIVEREF(__pyx_t_2);
3303     __pyx_t_2 = 0;
3304     __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 = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3305     __Pyx_GOTREF(__pyx_t_2);
3306     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3307     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
3308     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3309     goto __pyx_L5;
3310   }
3311   __pyx_L5:;
3312
3313   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3314   goto __pyx_L0;
3315   __pyx_L1_error:;
3316   __Pyx_XDECREF(__pyx_t_1);
3317   __Pyx_XDECREF(__pyx_t_2);
3318   __Pyx_XDECREF(__pyx_t_3);
3319   __Pyx_AddTraceback("csamtools.StderrStore.release");
3320   __pyx_r = NULL;
3321   __pyx_L0:;
3322   __Pyx_XGIVEREF(__pyx_r);
3323   __Pyx_TraceReturn(__pyx_r);
3324   __Pyx_RefNannyFinishContext();
3325   return __pyx_r;
3326 }
3327
3328 /* "csamtools.pyx":199
3329  *             os.remove( self.stderr_f )
3330  * 
3331  *     def __del__(self):             # <<<<<<<<<<<<<<
3332  *         self.release()
3333  * 
3334  */
3335
3336 static PyObject *__pyx_pf_9csamtools_11StderrStore_3__del__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3337 static char __pyx_doc_9csamtools_11StderrStore_3__del__[] = "StderrStore.__del__(self)";
3338 static PyMethodDef __pyx_mdef_9csamtools_11StderrStore_3__del__ = {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_9csamtools_11StderrStore_3__del__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11StderrStore_3__del__)};
3339 static PyObject *__pyx_pf_9csamtools_11StderrStore_3__del__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3340   PyObject *__pyx_r = NULL;
3341   PyObject *__pyx_t_1 = NULL;
3342   PyObject *__pyx_t_2 = NULL;
3343   __Pyx_TraceDeclarations
3344   __Pyx_RefNannySetupContext("__del__");
3345   __Pyx_TraceCall("__del__", __pyx_f[0], 199);
3346   __pyx_self = __pyx_self;
3347
3348   /* "csamtools.pyx":200
3349  * 
3350  *     def __del__(self):
3351  *         self.release()             # <<<<<<<<<<<<<<
3352  * 
3353  * class StderrStoreWindows():
3354  */
3355   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3356   __Pyx_GOTREF(__pyx_t_1);
3357   __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 = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3358   __Pyx_GOTREF(__pyx_t_2);
3359   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3360   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3361
3362   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3363   goto __pyx_L0;
3364   __pyx_L1_error:;
3365   __Pyx_XDECREF(__pyx_t_1);
3366   __Pyx_XDECREF(__pyx_t_2);
3367   __Pyx_AddTraceback("csamtools.StderrStore.__del__");
3368   __pyx_r = NULL;
3369   __pyx_L0:;
3370   __Pyx_XGIVEREF(__pyx_r);
3371   __Pyx_TraceReturn(__pyx_r);
3372   __Pyx_RefNannyFinishContext();
3373   return __pyx_r;
3374 }
3375
3376 /* "csamtools.pyx":204
3377  * class StderrStoreWindows():
3378  *     '''does nothing. stderr can't be redirected on windows'''
3379  *     def __init__(self): pass             # <<<<<<<<<<<<<<
3380  *     def readAndRelease(self): return []
3381  *     def release(self): pass
3382  */
3383
3384 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows___init__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3385 static char __pyx_doc_9csamtools_18StderrStoreWindows___init__[] = "StderrStoreWindows.__init__(self)";
3386 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_9csamtools_18StderrStoreWindows___init__, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows___init__)};
3387 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows___init__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3388   PyObject *__pyx_r = NULL;
3389   __Pyx_TraceDeclarations
3390   __Pyx_RefNannySetupContext("__init__");
3391   __Pyx_TraceCall("__init__", __pyx_f[0], 204);
3392   __pyx_self = __pyx_self;
3393
3394   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3395   __Pyx_XGIVEREF(__pyx_r);
3396   __Pyx_TraceReturn(__pyx_r);
3397   __Pyx_RefNannyFinishContext();
3398   return __pyx_r;
3399 }
3400
3401 /* "csamtools.pyx":205
3402  *     '''does nothing. stderr can't be redirected on windows'''
3403  *     def __init__(self): pass
3404  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
3405  *     def release(self): pass
3406  * 
3407  */
3408
3409 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_1readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3410 static char __pyx_doc_9csamtools_18StderrStoreWindows_1readAndRelease[] = "StderrStoreWindows.readAndRelease(self)";
3411 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows_1readAndRelease = {__Pyx_NAMESTR("readAndRelease"), (PyCFunction)__pyx_pf_9csamtools_18StderrStoreWindows_1readAndRelease, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows_1readAndRelease)};
3412 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_1readAndRelease(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3413   PyObject *__pyx_r = NULL;
3414   PyObject *__pyx_t_1 = NULL;
3415   __Pyx_TraceDeclarations
3416   __Pyx_RefNannySetupContext("readAndRelease");
3417   __Pyx_TraceCall("readAndRelease", __pyx_f[0], 205);
3418   __pyx_self = __pyx_self;
3419   __Pyx_XDECREF(__pyx_r);
3420   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3421   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
3422   __pyx_r = ((PyObject *)__pyx_t_1);
3423   __pyx_t_1 = 0;
3424   goto __pyx_L0;
3425
3426   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3427   goto __pyx_L0;
3428   __pyx_L1_error:;
3429   __Pyx_XDECREF(__pyx_t_1);
3430   __Pyx_AddTraceback("csamtools.StderrStoreWindows.readAndRelease");
3431   __pyx_r = NULL;
3432   __pyx_L0:;
3433   __Pyx_XGIVEREF(__pyx_r);
3434   __Pyx_TraceReturn(__pyx_r);
3435   __Pyx_RefNannyFinishContext();
3436   return __pyx_r;
3437 }
3438
3439 /* "csamtools.pyx":206
3440  *     def __init__(self): pass
3441  *     def readAndRelease(self): return []
3442  *     def release(self): pass             # <<<<<<<<<<<<<<
3443  * 
3444  * if platform.system()=='Windows':
3445  */
3446
3447 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_2release(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
3448 static char __pyx_doc_9csamtools_18StderrStoreWindows_2release[] = "StderrStoreWindows.release(self)";
3449 static PyMethodDef __pyx_mdef_9csamtools_18StderrStoreWindows_2release = {__Pyx_NAMESTR("release"), (PyCFunction)__pyx_pf_9csamtools_18StderrStoreWindows_2release, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_18StderrStoreWindows_2release)};
3450 static PyObject *__pyx_pf_9csamtools_18StderrStoreWindows_2release(PyObject *__pyx_self, PyObject *__pyx_v_self) {
3451   PyObject *__pyx_r = NULL;
3452   __Pyx_TraceDeclarations
3453   __Pyx_RefNannySetupContext("release");
3454   __Pyx_TraceCall("release", __pyx_f[0], 206);
3455   __pyx_self = __pyx_self;
3456
3457   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3458   __Pyx_XGIVEREF(__pyx_r);
3459   __Pyx_TraceReturn(__pyx_r);
3460   __Pyx_RefNannyFinishContext();
3461   return __pyx_r;
3462 }
3463
3464 /* "csamtools.pyx":260
3465  *     cdef faidx_t * fastafile
3466  * 
3467  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
3468  *         self.fastafile = NULL
3469  *         self._filename = NULL
3470  */
3471
3472 static int __pyx_pf_9csamtools_9Fastafile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3473 static int __pyx_pf_9csamtools_9Fastafile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3474   PyObject *__pyx_v_args = 0;
3475   PyObject *__pyx_v_kwargs = 0;
3476   int __pyx_r;
3477   PyObject *__pyx_t_1 = NULL;
3478   PyObject *__pyx_t_2 = NULL;
3479   PyObject *__pyx_t_3 = NULL;
3480   __Pyx_TraceDeclarations
3481   __Pyx_RefNannySetupContext("__cinit__");
3482   __Pyx_TraceCall("__cinit__", __pyx_f[0], 260);
3483   if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
3484   __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
3485   if (unlikely(!__pyx_v_kwargs)) return -1;
3486   __Pyx_GOTREF(__pyx_v_kwargs);
3487   __Pyx_INCREF(__pyx_args);
3488   __pyx_v_args = __pyx_args;
3489
3490   /* "csamtools.pyx":261
3491  * 
3492  *     def __cinit__(self, *args, **kwargs ):
3493  *         self.fastafile = NULL             # <<<<<<<<<<<<<<
3494  *         self._filename = NULL
3495  *         self._open( *args, **kwargs )
3496  */
3497   ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile = NULL;
3498
3499   /* "csamtools.pyx":262
3500  *     def __cinit__(self, *args, **kwargs ):
3501  *         self.fastafile = NULL
3502  *         self._filename = NULL             # <<<<<<<<<<<<<<
3503  *         self._open( *args, **kwargs )
3504  * 
3505  */
3506   ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename = NULL;
3507
3508   /* "csamtools.pyx":263
3509  *         self.fastafile = NULL
3510  *         self._filename = NULL
3511  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
3512  * 
3513  *     def _isOpen( self ):
3514  */
3515   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3516   __Pyx_GOTREF(__pyx_t_1);
3517   __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3518   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
3519   __pyx_t_3 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3520   __Pyx_GOTREF(__pyx_t_3);
3521   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3522   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
3523   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3524
3525   __pyx_r = 0;
3526   goto __pyx_L0;
3527   __pyx_L1_error:;
3528   __Pyx_XDECREF(__pyx_t_1);
3529   __Pyx_XDECREF(__pyx_t_2);
3530   __Pyx_XDECREF(__pyx_t_3);
3531   __Pyx_AddTraceback("csamtools.Fastafile.__cinit__");
3532   __pyx_r = -1;
3533   __pyx_L0:;
3534   __Pyx_DECREF(__pyx_v_args);
3535   __Pyx_DECREF(__pyx_v_kwargs);
3536   __Pyx_TraceReturn(Py_None);
3537   __Pyx_RefNannyFinishContext();
3538   return __pyx_r;
3539 }
3540
3541 /* "csamtools.pyx":265
3542  *         self._open( *args, **kwargs )
3543  * 
3544  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
3545  *         '''return true if samfile has been opened.'''
3546  *         return self.fastafile != NULL
3547  */
3548
3549 static PyObject *__pyx_pf_9csamtools_9Fastafile_1_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
3550 static char __pyx_doc_9csamtools_9Fastafile_1_isOpen[] = "Fastafile._isOpen(self)\nreturn true if samfile has been opened.";
3551 static PyObject *__pyx_pf_9csamtools_9Fastafile_1_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
3552   PyObject *__pyx_r = NULL;
3553   PyObject *__pyx_t_1 = NULL;
3554   __Pyx_TraceDeclarations
3555   __Pyx_RefNannySetupContext("_isOpen");
3556   __Pyx_TraceCall("_isOpen", __pyx_f[0], 265);
3557
3558   /* "csamtools.pyx":267
3559  *     def _isOpen( self ):
3560  *         '''return true if samfile has been opened.'''
3561  *         return self.fastafile != NULL             # <<<<<<<<<<<<<<
3562  * 
3563  *     def __len__(self):
3564  */
3565   __Pyx_XDECREF(__pyx_r);
3566   __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3567   __Pyx_GOTREF(__pyx_t_1);
3568   __pyx_r = __pyx_t_1;
3569   __pyx_t_1 = 0;
3570   goto __pyx_L0;
3571
3572   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3573   goto __pyx_L0;
3574   __pyx_L1_error:;
3575   __Pyx_XDECREF(__pyx_t_1);
3576   __Pyx_AddTraceback("csamtools.Fastafile._isOpen");
3577   __pyx_r = NULL;
3578   __pyx_L0:;
3579   __Pyx_XGIVEREF(__pyx_r);
3580   __Pyx_TraceReturn(__pyx_r);
3581   __Pyx_RefNannyFinishContext();
3582   return __pyx_r;
3583 }
3584
3585 /* "csamtools.pyx":269
3586  *         return self.fastafile != NULL
3587  * 
3588  *     def __len__(self):             # <<<<<<<<<<<<<<
3589  *         if self.fastafile == NULL:
3590  *             raise ValueError( "calling len() on closed file" )
3591  */
3592
3593 static Py_ssize_t __pyx_pf_9csamtools_9Fastafile_2__len__(PyObject *__pyx_v_self); /*proto*/
3594 static Py_ssize_t __pyx_pf_9csamtools_9Fastafile_2__len__(PyObject *__pyx_v_self) {
3595   Py_ssize_t __pyx_r;
3596   int __pyx_t_1;
3597   PyObject *__pyx_t_2 = NULL;
3598   __Pyx_TraceDeclarations
3599   __Pyx_RefNannySetupContext("__len__");
3600   __Pyx_TraceCall("__len__", __pyx_f[0], 269);
3601
3602   /* "csamtools.pyx":270
3603  * 
3604  *     def __len__(self):
3605  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
3606  *             raise ValueError( "calling len() on closed file" )
3607  * 
3608  */
3609   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile == NULL);
3610   if (__pyx_t_1) {
3611
3612     /* "csamtools.pyx":271
3613  *     def __len__(self):
3614  *         if self.fastafile == NULL:
3615  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
3616  * 
3617  *         return faidx_fetch_nseq(self.fastafile)
3618  */
3619     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3620     __Pyx_GOTREF(__pyx_t_2);
3621     __Pyx_Raise(__pyx_t_2, 0, 0);
3622     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3623     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3624     goto __pyx_L5;
3625   }
3626   __pyx_L5:;
3627
3628   /* "csamtools.pyx":273
3629  *             raise ValueError( "calling len() on closed file" )
3630  * 
3631  *         return faidx_fetch_nseq(self.fastafile)             # <<<<<<<<<<<<<<
3632  * 
3633  *     def _open( self,
3634  */
3635   __pyx_r = faidx_fetch_nseq(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile);
3636   goto __pyx_L0;
3637
3638   __pyx_r = 0;
3639   goto __pyx_L0;
3640   __pyx_L1_error:;
3641   __Pyx_XDECREF(__pyx_t_2);
3642   __Pyx_AddTraceback("csamtools.Fastafile.__len__");
3643   __pyx_r = -1;
3644   __pyx_L0:;
3645   __Pyx_TraceReturn(Py_None);
3646   __Pyx_RefNannyFinishContext();
3647   return __pyx_r;
3648 }
3649
3650 /* "csamtools.pyx":275
3651  *         return faidx_fetch_nseq(self.fastafile)
3652  * 
3653  *     def _open( self,             # <<<<<<<<<<<<<<
3654  *                char * filename ):
3655  *         '''open an indexed fasta file.
3656  */
3657
3658 static PyObject *__pyx_pf_9csamtools_9Fastafile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/
3659 static char __pyx_doc_9csamtools_9Fastafile_3_open[] = "Fastafile._open(self, char *filename)\nopen an indexed fasta file.\n\n        This method expects an indexed fasta file.\n        ";
3660 static PyObject *__pyx_pf_9csamtools_9Fastafile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) {
3661   char *__pyx_v_filename;
3662   PyObject *__pyx_r = NULL;
3663   int __pyx_t_1;
3664   PyObject *__pyx_t_2 = NULL;
3665   PyObject *__pyx_t_3 = NULL;
3666   __Pyx_TraceDeclarations
3667   __Pyx_RefNannySetupContext("_open");
3668   __Pyx_TraceCall("_open", __pyx_f[0], 275);
3669   assert(__pyx_arg_filename); {
3670     __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
3671   }
3672   goto __pyx_L4_argument_unpacking_done;
3673   __pyx_L3_error:;
3674   __Pyx_AddTraceback("csamtools.Fastafile._open");
3675   __Pyx_RefNannyFinishContext();
3676   return NULL;
3677   __pyx_L4_argument_unpacking_done:;
3678
3679   /* "csamtools.pyx":283
3680  * 
3681  *         # close a previously opened file
3682  *         if self.fastafile != NULL: self.close()             # <<<<<<<<<<<<<<
3683  *         if self._filename != NULL: free(self._filename)
3684  *         self._filename = strdup(filename)
3685  */
3686   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL);
3687   if (__pyx_t_1) {
3688     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3689     __Pyx_GOTREF(__pyx_t_2);
3690     __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 = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3691     __Pyx_GOTREF(__pyx_t_3);
3692     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3693     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
3694     goto __pyx_L5;
3695   }
3696   __pyx_L5:;
3697
3698   /* "csamtools.pyx":284
3699  *         # close a previously opened file
3700  *         if self.fastafile != NULL: self.close()
3701  *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
3702  *         self._filename = strdup(filename)
3703  *         self.fastafile = fai_load( filename )
3704  */
3705   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename != NULL);
3706   if (__pyx_t_1) {
3707     free(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename);
3708     goto __pyx_L6;
3709   }
3710   __pyx_L6:;
3711
3712   /* "csamtools.pyx":285
3713  *         if self.fastafile != NULL: self.close()
3714  *         if self._filename != NULL: free(self._filename)
3715  *         self._filename = strdup(filename)             # <<<<<<<<<<<<<<
3716  *         self.fastafile = fai_load( filename )
3717  * 
3718  */
3719   ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename = strdup(__pyx_v_filename);
3720
3721   /* "csamtools.pyx":286
3722  *         if self._filename != NULL: free(self._filename)
3723  *         self._filename = strdup(filename)
3724  *         self.fastafile = fai_load( filename )             # <<<<<<<<<<<<<<
3725  * 
3726  *         if self.fastafile == NULL:
3727  */
3728   ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile = fai_load(__pyx_v_filename);
3729
3730   /* "csamtools.pyx":288
3731  *         self.fastafile = fai_load( filename )
3732  * 
3733  *         if self.fastafile == NULL:             # <<<<<<<<<<<<<<
3734  *             raise IOError("could not open file `%s`" % filename )
3735  * 
3736  */
3737   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile == NULL);
3738   if (__pyx_t_1) {
3739
3740     /* "csamtools.pyx":289
3741  * 
3742  *         if self.fastafile == NULL:
3743  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
3744  * 
3745  *     def close( self ):
3746  */
3747     __pyx_t_3 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3748     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
3749     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3750     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
3751     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3752     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3753     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
3754     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
3755     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
3756     __pyx_t_2 = 0;
3757     __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3758     __Pyx_GOTREF(__pyx_t_2);
3759     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
3760     __Pyx_Raise(__pyx_t_2, 0, 0);
3761     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3762     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3763     goto __pyx_L7;
3764   }
3765   __pyx_L7:;
3766
3767   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3768   goto __pyx_L0;
3769   __pyx_L1_error:;
3770   __Pyx_XDECREF(__pyx_t_2);
3771   __Pyx_XDECREF(__pyx_t_3);
3772   __Pyx_AddTraceback("csamtools.Fastafile._open");
3773   __pyx_r = NULL;
3774   __pyx_L0:;
3775   __Pyx_XGIVEREF(__pyx_r);
3776   __Pyx_TraceReturn(__pyx_r);
3777   __Pyx_RefNannyFinishContext();
3778   return __pyx_r;
3779 }
3780
3781 /* "csamtools.pyx":291
3782  *             raise IOError("could not open file `%s`" % filename )
3783  * 
3784  *     def close( self ):             # <<<<<<<<<<<<<<
3785  *         if self.fastafile != NULL:
3786  *             fai_destroy( self.fastafile )
3787  */
3788
3789 static PyObject *__pyx_pf_9csamtools_9Fastafile_4close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
3790 static char __pyx_doc_9csamtools_9Fastafile_4close[] = "Fastafile.close(self)";
3791 static PyObject *__pyx_pf_9csamtools_9Fastafile_4close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
3792   PyObject *__pyx_r = NULL;
3793   int __pyx_t_1;
3794   __Pyx_TraceDeclarations
3795   __Pyx_RefNannySetupContext("close");
3796   __Pyx_TraceCall("close", __pyx_f[0], 291);
3797
3798   /* "csamtools.pyx":292
3799  * 
3800  *     def close( self ):
3801  *         if self.fastafile != NULL:             # <<<<<<<<<<<<<<
3802  *             fai_destroy( self.fastafile )
3803  *             self.fastafile = NULL
3804  */
3805   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile != NULL);
3806   if (__pyx_t_1) {
3807
3808     /* "csamtools.pyx":293
3809  *     def close( self ):
3810  *         if self.fastafile != NULL:
3811  *             fai_destroy( self.fastafile )             # <<<<<<<<<<<<<<
3812  *             self.fastafile = NULL
3813  * 
3814  */
3815     fai_destroy(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile);
3816
3817     /* "csamtools.pyx":294
3818  *         if self.fastafile != NULL:
3819  *             fai_destroy( self.fastafile )
3820  *             self.fastafile = NULL             # <<<<<<<<<<<<<<
3821  * 
3822  *     def __dealloc__(self):
3823  */
3824     ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile = NULL;
3825     goto __pyx_L5;
3826   }
3827   __pyx_L5:;
3828
3829   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3830   __Pyx_XGIVEREF(__pyx_r);
3831   __Pyx_TraceReturn(__pyx_r);
3832   __Pyx_RefNannyFinishContext();
3833   return __pyx_r;
3834 }
3835
3836 /* "csamtools.pyx":296
3837  *             self.fastafile = NULL
3838  * 
3839  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
3840  *         self.close()
3841  *         if self._filename != NULL: free(self._filename)
3842  */
3843
3844 static void __pyx_pf_9csamtools_9Fastafile_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
3845 static void __pyx_pf_9csamtools_9Fastafile_5__dealloc__(PyObject *__pyx_v_self) {
3846   PyObject *__pyx_t_1 = NULL;
3847   PyObject *__pyx_t_2 = NULL;
3848   int __pyx_t_3;
3849   __Pyx_TraceDeclarations
3850   __Pyx_RefNannySetupContext("__dealloc__");
3851   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 296);
3852
3853   /* "csamtools.pyx":297
3854  * 
3855  *     def __dealloc__(self):
3856  *         self.close()             # <<<<<<<<<<<<<<
3857  *         if self._filename != NULL: free(self._filename)
3858  * 
3859  */
3860   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3861   __Pyx_GOTREF(__pyx_t_1);
3862   __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 = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3863   __Pyx_GOTREF(__pyx_t_2);
3864   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3865   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3866
3867   /* "csamtools.pyx":298
3868  *     def __dealloc__(self):
3869  *         self.close()
3870  *         if self._filename != NULL: free(self._filename)             # <<<<<<<<<<<<<<
3871  * 
3872  *     property filename:
3873  */
3874   __pyx_t_3 = (((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename != NULL);
3875   if (__pyx_t_3) {
3876     free(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename);
3877     goto __pyx_L5;
3878   }
3879   __pyx_L5:;
3880
3881   goto __pyx_L0;
3882   __pyx_L1_error:;
3883   __Pyx_XDECREF(__pyx_t_1);
3884   __Pyx_XDECREF(__pyx_t_2);
3885   __Pyx_AddTraceback("csamtools.Fastafile.__dealloc__");
3886   __pyx_L0:;
3887   __Pyx_TraceReturn(Py_None);
3888   __Pyx_RefNannyFinishContext();
3889 }
3890
3891 /* "csamtools.pyx":302
3892  *     property filename:
3893  *         '''number of :term:`filename` associated with this object.'''
3894  *         def __get__(self):             # <<<<<<<<<<<<<<
3895  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
3896  *             return self._filename
3897  */
3898
3899 static PyObject *__pyx_pf_9csamtools_9Fastafile_8filename___get__(PyObject *__pyx_v_self); /*proto*/
3900 static PyObject *__pyx_pf_9csamtools_9Fastafile_8filename___get__(PyObject *__pyx_v_self) {
3901   PyObject *__pyx_r = NULL;
3902   PyObject *__pyx_t_1 = NULL;
3903   PyObject *__pyx_t_2 = NULL;
3904   int __pyx_t_3;
3905   int __pyx_t_4;
3906   __Pyx_TraceDeclarations
3907   __Pyx_RefNannySetupContext("__get__");
3908   __Pyx_TraceCall("__get__", __pyx_f[0], 302);
3909
3910   /* "csamtools.pyx":303
3911  *         '''number of :term:`filename` associated with this object.'''
3912  *         def __get__(self):
3913  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
3914  *             return self._filename
3915  * 
3916  */
3917   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3918   __Pyx_GOTREF(__pyx_t_1);
3919   __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 = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3920   __Pyx_GOTREF(__pyx_t_2);
3921   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
3922   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3923   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3924   __pyx_t_4 = (!__pyx_t_3);
3925   if (__pyx_t_4) {
3926     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3927     __Pyx_GOTREF(__pyx_t_2);
3928     __Pyx_Raise(__pyx_t_2, 0, 0);
3929     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
3930     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3931     goto __pyx_L5;
3932   }
3933   __pyx_L5:;
3934
3935   /* "csamtools.pyx":304
3936  *         def __get__(self):
3937  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
3938  *             return self._filename             # <<<<<<<<<<<<<<
3939  * 
3940  *     def fetch( self,
3941  */
3942   __Pyx_XDECREF(__pyx_r);
3943   __pyx_t_2 = PyBytes_FromString(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
3944   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
3945   __pyx_r = ((PyObject *)__pyx_t_2);
3946   __pyx_t_2 = 0;
3947   goto __pyx_L0;
3948
3949   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
3950   goto __pyx_L0;
3951   __pyx_L1_error:;
3952   __Pyx_XDECREF(__pyx_t_1);
3953   __Pyx_XDECREF(__pyx_t_2);
3954   __Pyx_AddTraceback("csamtools.Fastafile.filename.__get__");
3955   __pyx_r = NULL;
3956   __pyx_L0:;
3957   __Pyx_XGIVEREF(__pyx_r);
3958   __Pyx_TraceReturn(__pyx_r);
3959   __Pyx_RefNannyFinishContext();
3960   return __pyx_r;
3961 }
3962
3963 /* "csamtools.pyx":306
3964  *             return self._filename
3965  * 
3966  *     def fetch( self,             # <<<<<<<<<<<<<<
3967  *                reference = None,
3968  *                start = None,
3969  */
3970
3971 static PyObject *__pyx_pf_9csamtools_9Fastafile_6fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3972 static char __pyx_doc_9csamtools_9Fastafile_6fetch[] = "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        ";
3973 static PyObject *__pyx_pf_9csamtools_9Fastafile_6fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3974   PyObject *__pyx_v_reference = 0;
3975   PyObject *__pyx_v_start = 0;
3976   PyObject *__pyx_v_end = 0;
3977   PyObject *__pyx_v_region = 0;
3978   int __pyx_v_length;
3979   char *__pyx_v_seq;
3980   PyObject *__pyx_v_py_seq;
3981   PyObject *__pyx_r = NULL;
3982   PyObject *__pyx_t_1 = NULL;
3983   PyObject *__pyx_t_2 = NULL;
3984   int __pyx_t_3;
3985   int __pyx_t_4;
3986   char *__pyx_t_5;
3987   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
3988   __Pyx_TraceDeclarations
3989   __Pyx_RefNannySetupContext("fetch");
3990   __Pyx_TraceCall("fetch", __pyx_f[0], 306);
3991   if (unlikely(__pyx_kwds)) {
3992     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
3993     PyObject* values[4] = {0,0,0,0};
3994
3995     /* "csamtools.pyx":307
3996  * 
3997  *     def fetch( self,
3998  *                reference = None,             # <<<<<<<<<<<<<<
3999  *                start = None,
4000  *                end = None,
4001  */
4002     values[0] = ((PyObject *)Py_None);
4003
4004     /* "csamtools.pyx":308
4005  *     def fetch( self,
4006  *                reference = None,
4007  *                start = None,             # <<<<<<<<<<<<<<
4008  *                end = None,
4009  *                region = None):
4010  */
4011     values[1] = ((PyObject *)Py_None);
4012
4013     /* "csamtools.pyx":309
4014  *                reference = None,
4015  *                start = None,
4016  *                end = None,             # <<<<<<<<<<<<<<
4017  *                region = None):
4018  * 
4019  */
4020     values[2] = ((PyObject *)Py_None);
4021
4022     /* "csamtools.pyx":310
4023  *                start = None,
4024  *                end = None,
4025  *                region = None):             # <<<<<<<<<<<<<<
4026  * 
4027  *         '''*(reference = None, start = None, end = None, region = None)*
4028  */
4029     values[3] = ((PyObject *)Py_None);
4030     switch (PyTuple_GET_SIZE(__pyx_args)) {
4031       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
4032       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
4033       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
4034       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
4035       case  0: break;
4036       default: goto __pyx_L5_argtuple_error;
4037     }
4038     switch (PyTuple_GET_SIZE(__pyx_args)) {
4039       case  0:
4040       if (kw_args > 0) {
4041         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
4042         if (value) { values[0] = value; kw_args--; }
4043       }
4044       case  1:
4045       if (kw_args > 0) {
4046         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
4047         if (value) { values[1] = value; kw_args--; }
4048       }
4049       case  2:
4050       if (kw_args > 0) {
4051         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
4052         if (value) { values[2] = value; kw_args--; }
4053       }
4054       case  3:
4055       if (kw_args > 0) {
4056         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
4057         if (value) { values[3] = value; kw_args--; }
4058       }
4059     }
4060     if (unlikely(kw_args > 0)) {
4061       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
4062     }
4063     __pyx_v_reference = values[0];
4064     __pyx_v_start = values[1];
4065     __pyx_v_end = values[2];
4066     __pyx_v_region = values[3];
4067   } else {
4068
4069     /* "csamtools.pyx":307
4070  * 
4071  *     def fetch( self,
4072  *                reference = None,             # <<<<<<<<<<<<<<
4073  *                start = None,
4074  *                end = None,
4075  */
4076     __pyx_v_reference = ((PyObject *)Py_None);
4077
4078     /* "csamtools.pyx":308
4079  *     def fetch( self,
4080  *                reference = None,
4081  *                start = None,             # <<<<<<<<<<<<<<
4082  *                end = None,
4083  *                region = None):
4084  */
4085     __pyx_v_start = ((PyObject *)Py_None);
4086
4087     /* "csamtools.pyx":309
4088  *                reference = None,
4089  *                start = None,
4090  *                end = None,             # <<<<<<<<<<<<<<
4091  *                region = None):
4092  * 
4093  */
4094     __pyx_v_end = ((PyObject *)Py_None);
4095
4096     /* "csamtools.pyx":310
4097  *                start = None,
4098  *                end = None,
4099  *                region = None):             # <<<<<<<<<<<<<<
4100  * 
4101  *         '''*(reference = None, start = None, end = None, region = None)*
4102  */
4103     __pyx_v_region = ((PyObject *)Py_None);
4104     switch (PyTuple_GET_SIZE(__pyx_args)) {
4105       case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
4106       case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
4107       case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
4108       case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
4109       case  0: break;
4110       default: goto __pyx_L5_argtuple_error;
4111     }
4112   }
4113   goto __pyx_L4_argument_unpacking_done;
4114   __pyx_L5_argtuple_error:;
4115   __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
4116   __pyx_L3_error:;
4117   __Pyx_AddTraceback("csamtools.Fastafile.fetch");
4118   __Pyx_RefNannyFinishContext();
4119   return NULL;
4120   __pyx_L4_argument_unpacking_done:;
4121   __Pyx_INCREF(__pyx_v_start);
4122   __Pyx_INCREF(__pyx_v_end);
4123   __Pyx_INCREF(__pyx_v_region);
4124   __pyx_v_py_seq = Py_None; __Pyx_INCREF(Py_None);
4125
4126   /* "csamtools.pyx":327
4127  *         '''
4128  * 
4129  *         if not self._isOpen():             # <<<<<<<<<<<<<<
4130  *             raise ValueError( "I/O operation on closed file" )
4131  * 
4132  */
4133   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4134   __Pyx_GOTREF(__pyx_t_1);
4135   __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 = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4136   __Pyx_GOTREF(__pyx_t_2);
4137   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4138   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4139   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4140   __pyx_t_4 = (!__pyx_t_3);
4141   if (__pyx_t_4) {
4142
4143     /* "csamtools.pyx":328
4144  * 
4145  *         if not self._isOpen():
4146  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
4147  * 
4148  *         cdef int length
4149  */
4150     __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 = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4151     __Pyx_GOTREF(__pyx_t_2);
4152     __Pyx_Raise(__pyx_t_2, 0, 0);
4153     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4154     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4155     goto __pyx_L6;
4156   }
4157   __pyx_L6:;
4158
4159   /* "csamtools.pyx":333
4160  *         cdef char * seq
4161  * 
4162  *         if not region:             # <<<<<<<<<<<<<<
4163  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
4164  *             if start is None: start = 0
4165  */
4166   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4167   __pyx_t_3 = (!__pyx_t_4);
4168   if (__pyx_t_3) {
4169
4170     /* "csamtools.pyx":334
4171  * 
4172  *         if not region:
4173  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
4174  *             if start is None: start = 0
4175  *             if end is None: end = max_pos -1
4176  */
4177     __pyx_t_3 = (__pyx_v_reference == Py_None);
4178     if (__pyx_t_3) {
4179       __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4180       __Pyx_GOTREF(__pyx_t_2);
4181       __Pyx_Raise(__pyx_t_2, 0, 0);
4182       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4183       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4184       goto __pyx_L8;
4185     }
4186     __pyx_L8:;
4187
4188     /* "csamtools.pyx":335
4189  *         if not region:
4190  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
4191  *             if start is None: start = 0             # <<<<<<<<<<<<<<
4192  *             if end is None: end = max_pos -1
4193  * 
4194  */
4195     __pyx_t_3 = (__pyx_v_start == Py_None);
4196     if (__pyx_t_3) {
4197       __Pyx_INCREF(__pyx_int_0);
4198       __Pyx_DECREF(__pyx_v_start);
4199       __pyx_v_start = __pyx_int_0;
4200       goto __pyx_L9;
4201     }
4202     __pyx_L9:;
4203
4204     /* "csamtools.pyx":336
4205  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )
4206  *             if start is None: start = 0
4207  *             if end is None: end = max_pos -1             # <<<<<<<<<<<<<<
4208  * 
4209  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
4210  */
4211     __pyx_t_3 = (__pyx_v_end == Py_None);
4212     if (__pyx_t_3) {
4213       __pyx_t_2 = PyInt_FromLong((__pyx_v_9csamtools_max_pos - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4214       __Pyx_GOTREF(__pyx_t_2);
4215       __Pyx_DECREF(__pyx_v_end);
4216       __pyx_v_end = __pyx_t_2;
4217       __pyx_t_2 = 0;
4218       goto __pyx_L10;
4219     }
4220     __pyx_L10:;
4221
4222     /* "csamtools.pyx":338
4223  *             if end is None: end = max_pos -1
4224  * 
4225  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )             # <<<<<<<<<<<<<<
4226  *             if start == end: return ""
4227  *             # valid ranges are from 0 to 2^29-1
4228  */
4229     __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 = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4230     __Pyx_GOTREF(__pyx_t_2);
4231     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4232     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4233     if (__pyx_t_3) {
4234       __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4235       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4236       __Pyx_INCREF(__pyx_v_start);
4237       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
4238       __Pyx_GIVEREF(__pyx_v_start);
4239       __Pyx_INCREF(__pyx_v_end);
4240       PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
4241       __Pyx_GIVEREF(__pyx_v_end);
4242       __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4243       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
4244       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4245       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4246       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4247       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
4248       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
4249       __pyx_t_1 = 0;
4250       __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 = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4251       __Pyx_GOTREF(__pyx_t_1);
4252       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4253       __Pyx_Raise(__pyx_t_1, 0, 0);
4254       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4255       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4256       goto __pyx_L11;
4257     }
4258     __pyx_L11:;
4259
4260     /* "csamtools.pyx":339
4261  * 
4262  *             if start > end: raise ValueError( 'invalid region: start (%i) > end (%i)' % (start, end) )
4263  *             if start == end: return ""             # <<<<<<<<<<<<<<
4264  *             # valid ranges are from 0 to 2^29-1
4265  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
4266  */
4267     __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 = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4268     __Pyx_GOTREF(__pyx_t_1);
4269     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4270     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4271     if (__pyx_t_3) {
4272       __Pyx_XDECREF(__pyx_r);
4273       __Pyx_INCREF(((PyObject *)__pyx_kp_s_12));
4274       __pyx_r = ((PyObject *)__pyx_kp_s_12);
4275       goto __pyx_L0;
4276       goto __pyx_L12;
4277     }
4278     __pyx_L12:;
4279
4280     /* "csamtools.pyx":341
4281  *             if start == end: return ""
4282  *             # valid ranges are from 0 to 2^29-1
4283  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
4284  *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )
4285  *             # note: faidx_fetch_seq has a bug such that out-of-range access
4286  */
4287     __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 = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4288     __Pyx_GOTREF(__pyx_t_1);
4289     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
4290       __Pyx_DECREF(__pyx_t_1);
4291       __pyx_t_2 = PyInt_FromLong(__pyx_v_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4292       __Pyx_GOTREF(__pyx_t_2);
4293       __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 = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4294       __Pyx_GOTREF(__pyx_t_1);
4295       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4296     }
4297     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4298     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4299     __pyx_t_4 = (!__pyx_t_3);
4300     if (__pyx_t_4) {
4301       __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_v_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4302       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
4303       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4304       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4305       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
4306       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
4307       __pyx_t_1 = 0;
4308       __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 = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4309       __Pyx_GOTREF(__pyx_t_1);
4310       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4311       __Pyx_Raise(__pyx_t_1, 0, 0);
4312       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4313       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4314       goto __pyx_L13;
4315     }
4316     __pyx_L13:;
4317
4318     /* "csamtools.pyx":342
4319  *             # valid ranges are from 0 to 2^29-1
4320  *             if not 0 <= start < max_pos: raise ValueError( 'start out of range (%i)' % start )
4321  *             if not 0 <= end < max_pos: raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
4322  *             # note: faidx_fetch_seq has a bug such that out-of-range access
4323  *             # always returns the last residue. Hence do not use faidx_fetch_seq,
4324  */
4325     __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 = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4326     __Pyx_GOTREF(__pyx_t_1);
4327     if (__Pyx_PyObject_IsTrue(__pyx_t_1)) {
4328       __Pyx_DECREF(__pyx_t_1);
4329       __pyx_t_2 = PyInt_FromLong(__pyx_v_9csamtools_max_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4330       __Pyx_GOTREF(__pyx_t_2);
4331       __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 = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4332       __Pyx_GOTREF(__pyx_t_1);
4333       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
4334     }
4335     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4336     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4337     __pyx_t_3 = (!__pyx_t_4);
4338     if (__pyx_t_3) {
4339       __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_v_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4340       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
4341       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4342       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4343       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
4344       __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
4345       __pyx_t_1 = 0;
4346       __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 = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4347       __Pyx_GOTREF(__pyx_t_1);
4348       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4349       __Pyx_Raise(__pyx_t_1, 0, 0);
4350       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4351       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4352       goto __pyx_L14;
4353     }
4354     __pyx_L14:;
4355
4356     /* "csamtools.pyx":351
4357  *             #                       end-1,
4358  *             #                       &length)
4359  *             region = "%s:%i-%i" % (reference, start+1, end)             # <<<<<<<<<<<<<<
4360  *             seq = fai_fetch( self.fastafile,
4361  *                              region,
4362  */
4363     __pyx_t_1 = PyNumber_Add(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4364     __Pyx_GOTREF(__pyx_t_1);
4365     __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4366     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4367     __Pyx_INCREF(__pyx_v_reference);
4368     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_reference);
4369     __Pyx_GIVEREF(__pyx_v_reference);
4370     PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
4371     __Pyx_GIVEREF(__pyx_t_1);
4372     __Pyx_INCREF(__pyx_v_end);
4373     PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_end);
4374     __Pyx_GIVEREF(__pyx_v_end);
4375     __pyx_t_1 = 0;
4376     __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 = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4377     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
4378     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4379     __Pyx_DECREF(__pyx_v_region);
4380     __pyx_v_region = ((PyObject *)__pyx_t_1);
4381     __pyx_t_1 = 0;
4382
4383     /* "csamtools.pyx":353
4384  *             region = "%s:%i-%i" % (reference, start+1, end)
4385  *             seq = fai_fetch( self.fastafile,
4386  *                              region,             # <<<<<<<<<<<<<<
4387  *                              &length )
4388  *         else:
4389  */
4390     __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4391
4392     /* "csamtools.pyx":354
4393  *             seq = fai_fetch( self.fastafile,
4394  *                              region,
4395  *                              &length )             # <<<<<<<<<<<<<<
4396  *         else:
4397  *             # samtools adds a '\0' at the end
4398  */
4399     __pyx_v_seq = fai_fetch(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile, __pyx_t_5, (&__pyx_v_length));
4400     goto __pyx_L7;
4401   }
4402   /*else*/ {
4403
4404     /* "csamtools.pyx":357
4405  *         else:
4406  *             # samtools adds a '\0' at the end
4407  *             seq = fai_fetch( self.fastafile, region, &length )             # <<<<<<<<<<<<<<
4408  * 
4409  *         # copy to python
4410  */
4411     __pyx_t_5 = PyBytes_AsString(__pyx_v_region); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4412     __pyx_v_seq = fai_fetch(((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_self)->fastafile, __pyx_t_5, (&__pyx_v_length));
4413   }
4414   __pyx_L7:;
4415
4416   /* "csamtools.pyx":360
4417  * 
4418  *         # copy to python
4419  *         if seq == NULL:             # <<<<<<<<<<<<<<
4420  *             return ""
4421  *         else:
4422  */
4423   __pyx_t_3 = (__pyx_v_seq == NULL);
4424   if (__pyx_t_3) {
4425
4426     /* "csamtools.pyx":361
4427  *         # copy to python
4428  *         if seq == NULL:
4429  *             return ""             # <<<<<<<<<<<<<<
4430  *         else:
4431  *             try:
4432  */
4433     __Pyx_XDECREF(__pyx_r);
4434     __Pyx_INCREF(((PyObject *)__pyx_kp_s_12));
4435     __pyx_r = ((PyObject *)__pyx_kp_s_12);
4436     goto __pyx_L0;
4437     goto __pyx_L15;
4438   }
4439   /*else*/ {
4440
4441     /* "csamtools.pyx":363
4442  *             return ""
4443  *         else:
4444  *             try:             # <<<<<<<<<<<<<<
4445  *                 py_seq = PyString_FromStringAndSize(seq, length)
4446  *             finally:
4447  */
4448     /*try:*/ {
4449
4450       /* "csamtools.pyx":364
4451  *         else:
4452  *             try:
4453  *                 py_seq = PyString_FromStringAndSize(seq, length)             # <<<<<<<<<<<<<<
4454  *             finally:
4455  *                 free(seq)
4456  */
4457       __pyx_t_1 = PyString_FromStringAndSize(__pyx_v_seq, __pyx_v_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L17;}
4458       __Pyx_GOTREF(__pyx_t_1);
4459       __Pyx_DECREF(__pyx_v_py_seq);
4460       __pyx_v_py_seq = __pyx_t_1;
4461       __pyx_t_1 = 0;
4462     }
4463
4464     /* "csamtools.pyx":366
4465  *                 py_seq = PyString_FromStringAndSize(seq, length)
4466  *             finally:
4467  *                 free(seq)             # <<<<<<<<<<<<<<
4468  * 
4469  *         return py_seq
4470  */
4471     /*finally:*/ {
4472       int __pyx_why;
4473       PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
4474       int __pyx_exc_lineno;
4475       __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
4476       __pyx_why = 0; goto __pyx_L18;
4477       __pyx_L17: {
4478         __pyx_why = 4;
4479         __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
4480         __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
4481         __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
4482         __pyx_exc_lineno = __pyx_lineno;
4483         goto __pyx_L18;
4484       }
4485       __pyx_L18:;
4486       free(__pyx_v_seq);
4487       switch (__pyx_why) {
4488         case 4: {
4489           __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
4490           __pyx_lineno = __pyx_exc_lineno;
4491           __pyx_exc_type = 0;
4492           __pyx_exc_value = 0;
4493           __pyx_exc_tb = 0;
4494           goto __pyx_L1_error;
4495         }
4496       }
4497     }
4498   }
4499   __pyx_L15:;
4500
4501   /* "csamtools.pyx":368
4502  *                 free(seq)
4503  * 
4504  *         return py_seq             # <<<<<<<<<<<<<<
4505  * 
4506  *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):
4507  */
4508   __Pyx_XDECREF(__pyx_r);
4509   __Pyx_INCREF(__pyx_v_py_seq);
4510   __pyx_r = __pyx_v_py_seq;
4511   goto __pyx_L0;
4512
4513   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4514   goto __pyx_L0;
4515   __pyx_L1_error:;
4516   __Pyx_XDECREF(__pyx_t_1);
4517   __Pyx_XDECREF(__pyx_t_2);
4518   __Pyx_AddTraceback("csamtools.Fastafile.fetch");
4519   __pyx_r = NULL;
4520   __pyx_L0:;
4521   __Pyx_DECREF(__pyx_v_py_seq);
4522   __Pyx_DECREF(__pyx_v_start);
4523   __Pyx_DECREF(__pyx_v_end);
4524   __Pyx_DECREF(__pyx_v_region);
4525   __Pyx_XGIVEREF(__pyx_r);
4526   __Pyx_TraceReturn(__pyx_r);
4527   __Pyx_RefNannyFinishContext();
4528   return __pyx_r;
4529 }
4530
4531 /* "csamtools.pyx":370
4532  *         return py_seq
4533  * 
4534  *     cdef char * _fetch( self, char * reference, int start, int end, int * length ):             # <<<<<<<<<<<<<<
4535  *         '''fetch sequence for reference, start and end'''
4536  * 
4537  */
4538
4539 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) {
4540   char *__pyx_r;
4541   __Pyx_TraceDeclarations
4542   __Pyx_RefNannySetupContext("_fetch");
4543   __Pyx_TraceCall("_fetch", __pyx_f[0], 370);
4544
4545   /* "csamtools.pyx":377
4546  *                                start,
4547  *                                end-1,
4548  *                                length )             # <<<<<<<<<<<<<<
4549  * 
4550  * #------------------------------------------------------------------------
4551  */
4552   __pyx_r = faidx_fetch_seq(__pyx_v_self->fastafile, __pyx_v_reference, __pyx_v_start, (__pyx_v_end - 1), __pyx_v_length);
4553   goto __pyx_L0;
4554
4555   __pyx_r = 0;
4556   __pyx_L0:;
4557   __Pyx_TraceReturn(Py_None);
4558   __Pyx_RefNannyFinishContext();
4559   return __pyx_r;
4560 }
4561
4562 /* "csamtools.pyx":382
4563  * #------------------------------------------------------------------------
4564  * #------------------------------------------------------------------------
4565  * cdef int count_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
4566  *      '''callback for bam_fetch - count number of reads.
4567  *      '''
4568  */
4569
4570 static  int __pyx_f_9csamtools_count_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
4571   int *__pyx_v_counter;
4572   int __pyx_r;
4573   long __pyx_t_1;
4574   __Pyx_TraceDeclarations
4575   __Pyx_RefNannySetupContext("count_callback");
4576   __Pyx_TraceCall("count_callback", __pyx_f[0], 382);
4577
4578   /* "csamtools.pyx":385
4579  *      '''callback for bam_fetch - count number of reads.
4580  *      '''
4581  *      cdef int* counter = (<int*>f)             # <<<<<<<<<<<<<<
4582  *      counter[0] += 1;
4583  * 
4584  */
4585   __pyx_v_counter = ((int *)__pyx_v_f);
4586
4587   /* "csamtools.pyx":386
4588  *      '''
4589  *      cdef int* counter = (<int*>f)
4590  *      counter[0] += 1;             # <<<<<<<<<<<<<<
4591  * 
4592  * ctypedef struct MateData:
4593  */
4594   __pyx_t_1 = 0;
4595   (__pyx_v_counter[__pyx_t_1]) = ((__pyx_v_counter[__pyx_t_1]) + 1);
4596
4597   __pyx_r = 0;
4598   __Pyx_TraceReturn(Py_None);
4599   __Pyx_RefNannyFinishContext();
4600   return __pyx_r;
4601 }
4602
4603 /* "csamtools.pyx":396
4604  * #------------------------------------------------------------------------
4605  * #------------------------------------------------------------------------
4606  * cdef int mate_callback( bam1_t *alignment, void *f):             # <<<<<<<<<<<<<<
4607  *      '''callback for bam_fetch = filter mate
4608  *      '''
4609  */
4610
4611 static  int __pyx_f_9csamtools_mate_callback(bam1_t *__pyx_v_alignment, void *__pyx_v_f) {
4612   __pyx_t_9csamtools_MateData *__pyx_v_d;
4613   int __pyx_r;
4614   int __pyx_t_1;
4615   int __pyx_t_2;
4616   int __pyx_t_3;
4617   __Pyx_TraceDeclarations
4618   __Pyx_RefNannySetupContext("mate_callback");
4619   __Pyx_TraceCall("mate_callback", __pyx_f[0], 396);
4620
4621   /* "csamtools.pyx":399
4622  *      '''callback for bam_fetch = filter mate
4623  *      '''
4624  *      cdef MateData * d = (<MateData*>f)             # <<<<<<<<<<<<<<
4625  *      # printf("mate = %p, name1 = %s, name2=%s\t%i\t%i\t%i\n",
4626  *      #        d.mate, d.name, bam1_qname(alignment),
4627  */
4628   __pyx_v_d = ((__pyx_t_9csamtools_MateData *)__pyx_v_f);
4629
4630   /* "csamtools.pyx":404
4631  *      #        d.flag, alignment.core.flag, alignment.core.flag & d.flag)
4632  * 
4633  *      if d.mate == NULL:             # <<<<<<<<<<<<<<
4634  *          # could be sped up by comparing the lengths of query strings first
4635  *          # using l_qname
4636  */
4637   __pyx_t_1 = (__pyx_v_d->mate == NULL);
4638   if (__pyx_t_1) {
4639
4640     /* "csamtools.pyx":410
4641  *          # also, make sure that we get the other read by comparing
4642  *          # the flags
4643  *          if alignment.core.flag & d.flag != 0 and \             # <<<<<<<<<<<<<<
4644  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:
4645  *              d.mate = bam_dup1( alignment )
4646  */
4647     __pyx_t_1 = ((__pyx_v_alignment->core.flag & __pyx_v_d->flag) != 0);
4648     if (__pyx_t_1) {
4649
4650       /* "csamtools.pyx":411
4651  *          # the flags
4652  *          if alignment.core.flag & d.flag != 0 and \
4653  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:             # <<<<<<<<<<<<<<
4654  *              d.mate = bam_dup1( alignment )
4655  * 
4656  */
4657       __pyx_t_2 = (strcmp(bam1_qname(__pyx_v_alignment), __pyx_v_d->name) == 0);
4658       __pyx_t_3 = __pyx_t_2;
4659     } else {
4660       __pyx_t_3 = __pyx_t_1;
4661     }
4662     if (__pyx_t_3) {
4663
4664       /* "csamtools.pyx":412
4665  *          if alignment.core.flag & d.flag != 0 and \
4666  *                  strcmp( bam1_qname( alignment ), d.name ) == 0:
4667  *              d.mate = bam_dup1( alignment )             # <<<<<<<<<<<<<<
4668  * 
4669  * 
4670  */
4671       __pyx_v_d->mate = bam_dup1(__pyx_v_alignment);
4672       goto __pyx_L4;
4673     }
4674     __pyx_L4:;
4675     goto __pyx_L3;
4676   }
4677   __pyx_L3:;
4678
4679   __pyx_r = 0;
4680   __Pyx_TraceReturn(Py_None);
4681   __Pyx_RefNannyFinishContext();
4682   return __pyx_r;
4683 }
4684
4685 /* "csamtools.pyx":458
4686  *     '''
4687  * 
4688  *     def __cinit__(self, *args, **kwargs ):             # <<<<<<<<<<<<<<
4689  *         self.samfile = NULL
4690  *         self._filename = NULL
4691  */
4692
4693 static int __pyx_pf_9csamtools_7Samfile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
4694 static int __pyx_pf_9csamtools_7Samfile___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
4695   PyObject *__pyx_v_args = 0;
4696   PyObject *__pyx_v_kwargs = 0;
4697   int __pyx_r;
4698   PyObject *__pyx_t_1 = NULL;
4699   PyObject *__pyx_t_2 = NULL;
4700   PyObject *__pyx_t_3 = NULL;
4701   __Pyx_TraceDeclarations
4702   __Pyx_RefNannySetupContext("__cinit__");
4703   __Pyx_TraceCall("__cinit__", __pyx_f[0], 458);
4704   if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
4705   __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
4706   if (unlikely(!__pyx_v_kwargs)) return -1;
4707   __Pyx_GOTREF(__pyx_v_kwargs);
4708   __Pyx_INCREF(__pyx_args);
4709   __pyx_v_args = __pyx_args;
4710
4711   /* "csamtools.pyx":459
4712  * 
4713  *     def __cinit__(self, *args, **kwargs ):
4714  *         self.samfile = NULL             # <<<<<<<<<<<<<<
4715  *         self._filename = NULL
4716  *         self.isbam = False
4717  */
4718   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;
4719
4720   /* "csamtools.pyx":460
4721  *     def __cinit__(self, *args, **kwargs ):
4722  *         self.samfile = NULL
4723  *         self._filename = NULL             # <<<<<<<<<<<<<<
4724  *         self.isbam = False
4725  *         self.isstream = False
4726  */
4727   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename = NULL;
4728
4729   /* "csamtools.pyx":461
4730  *         self.samfile = NULL
4731  *         self._filename = NULL
4732  *         self.isbam = False             # <<<<<<<<<<<<<<
4733  *         self.isstream = False
4734  *         self._open( *args, **kwargs )
4735  */
4736   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam = 0;
4737
4738   /* "csamtools.pyx":462
4739  *         self._filename = NULL
4740  *         self.isbam = False
4741  *         self.isstream = False             # <<<<<<<<<<<<<<
4742  *         self._open( *args, **kwargs )
4743  * 
4744  */
4745   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isstream = 0;
4746
4747   /* "csamtools.pyx":463
4748  *         self.isbam = False
4749  *         self.isstream = False
4750  *         self._open( *args, **kwargs )             # <<<<<<<<<<<<<<
4751  * 
4752  *         # allocate memory for iterator
4753  */
4754   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4755   __Pyx_GOTREF(__pyx_t_1);
4756   __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4757   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
4758   __pyx_t_3 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4759   __Pyx_GOTREF(__pyx_t_3);
4760   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
4761   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
4762   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
4763
4764   /* "csamtools.pyx":466
4765  * 
4766  *         # allocate memory for iterator
4767  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
4768  * 
4769  *     def _isOpen( self ):
4770  */
4771   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
4772
4773   __pyx_r = 0;
4774   goto __pyx_L0;
4775   __pyx_L1_error:;
4776   __Pyx_XDECREF(__pyx_t_1);
4777   __Pyx_XDECREF(__pyx_t_2);
4778   __Pyx_XDECREF(__pyx_t_3);
4779   __Pyx_AddTraceback("csamtools.Samfile.__cinit__");
4780   __pyx_r = -1;
4781   __pyx_L0:;
4782   __Pyx_DECREF(__pyx_v_args);
4783   __Pyx_DECREF(__pyx_v_kwargs);
4784   __Pyx_TraceReturn(Py_None);
4785   __Pyx_RefNannyFinishContext();
4786   return __pyx_r;
4787 }
4788
4789 /* "csamtools.pyx":468
4790  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
4791  * 
4792  *     def _isOpen( self ):             # <<<<<<<<<<<<<<
4793  *         '''return true if samfile has been opened.'''
4794  *         return self.samfile != NULL
4795  */
4796
4797 static PyObject *__pyx_pf_9csamtools_7Samfile_1_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
4798 static char __pyx_doc_9csamtools_7Samfile_1_isOpen[] = "Samfile._isOpen(self)\nreturn true if samfile has been opened.";
4799 static PyObject *__pyx_pf_9csamtools_7Samfile_1_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
4800   PyObject *__pyx_r = NULL;
4801   PyObject *__pyx_t_1 = NULL;
4802   __Pyx_TraceDeclarations
4803   __Pyx_RefNannySetupContext("_isOpen");
4804   __Pyx_TraceCall("_isOpen", __pyx_f[0], 468);
4805
4806   /* "csamtools.pyx":470
4807  *     def _isOpen( self ):
4808  *         '''return true if samfile has been opened.'''
4809  *         return self.samfile != NULL             # <<<<<<<<<<<<<<
4810  * 
4811  *     def _hasIndex( self ):
4812  */
4813   __Pyx_XDECREF(__pyx_r);
4814   __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4815   __Pyx_GOTREF(__pyx_t_1);
4816   __pyx_r = __pyx_t_1;
4817   __pyx_t_1 = 0;
4818   goto __pyx_L0;
4819
4820   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4821   goto __pyx_L0;
4822   __pyx_L1_error:;
4823   __Pyx_XDECREF(__pyx_t_1);
4824   __Pyx_AddTraceback("csamtools.Samfile._isOpen");
4825   __pyx_r = NULL;
4826   __pyx_L0:;
4827   __Pyx_XGIVEREF(__pyx_r);
4828   __Pyx_TraceReturn(__pyx_r);
4829   __Pyx_RefNannyFinishContext();
4830   return __pyx_r;
4831 }
4832
4833 /* "csamtools.pyx":472
4834  *         return self.samfile != NULL
4835  * 
4836  *     def _hasIndex( self ):             # <<<<<<<<<<<<<<
4837  *         '''return true if samfile has an existing (and opened) index.'''
4838  *         return self.index != NULL
4839  */
4840
4841 static PyObject *__pyx_pf_9csamtools_7Samfile_2_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
4842 static char __pyx_doc_9csamtools_7Samfile_2_hasIndex[] = "Samfile._hasIndex(self)\nreturn true if samfile has an existing (and opened) index.";
4843 static PyObject *__pyx_pf_9csamtools_7Samfile_2_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
4844   PyObject *__pyx_r = NULL;
4845   PyObject *__pyx_t_1 = NULL;
4846   __Pyx_TraceDeclarations
4847   __Pyx_RefNannySetupContext("_hasIndex");
4848   __Pyx_TraceCall("_hasIndex", __pyx_f[0], 472);
4849
4850   /* "csamtools.pyx":474
4851  *     def _hasIndex( self ):
4852  *         '''return true if samfile has an existing (and opened) index.'''
4853  *         return self.index != NULL             # <<<<<<<<<<<<<<
4854  * 
4855  *     def _open( self,
4856  */
4857   __Pyx_XDECREF(__pyx_r);
4858   __pyx_t_1 = __Pyx_PyBool_FromLong((((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
4859   __Pyx_GOTREF(__pyx_t_1);
4860   __pyx_r = __pyx_t_1;
4861   __pyx_t_1 = 0;
4862   goto __pyx_L0;
4863
4864   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
4865   goto __pyx_L0;
4866   __pyx_L1_error:;
4867   __Pyx_XDECREF(__pyx_t_1);
4868   __Pyx_AddTraceback("csamtools.Samfile._hasIndex");
4869   __pyx_r = NULL;
4870   __pyx_L0:;
4871   __Pyx_XGIVEREF(__pyx_r);
4872   __Pyx_TraceReturn(__pyx_r);
4873   __Pyx_RefNannyFinishContext();
4874   return __pyx_r;
4875 }
4876
4877 /* "csamtools.pyx":476
4878  *         return self.index != NULL
4879  * 
4880  *     def _open( self,             # <<<<<<<<<<<<<<
4881  *                char * filename,
4882  *                mode = None,
4883  */
4884
4885 static PyObject *__pyx_pf_9csamtools_7Samfile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
4886 static char __pyx_doc_9csamtools_7Samfile_3_open[] = "Samfile._open(self, char *filename, mode=None, Samfile template=None, referencenames=None, referencelengths=None, text=None, header=None, port=None, add_sq_text=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        ";
4887 static PyObject *__pyx_pf_9csamtools_7Samfile_3_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
4888   char *__pyx_v_filename;
4889   PyObject *__pyx_v_mode = 0;
4890   struct __pyx_obj_9csamtools_Samfile *__pyx_v_template = 0;
4891   PyObject *__pyx_v_referencenames = 0;
4892   PyObject *__pyx_v_referencelengths = 0;
4893   PyObject *__pyx_v_text = 0;
4894   PyObject *__pyx_v_header = 0;
4895   PyObject *__pyx_v_port = 0;
4896   PyObject *__pyx_v_add_sq_text = 0;
4897   PyObject *__pyx_v_msg;
4898   bam_header_t *__pyx_v_header_to_write;
4899   char *__pyx_v_ctext;
4900   PyObject *__pyx_v_n;
4901   PyObject *__pyx_v_x;
4902   PyObject *__pyx_v_name;
4903   PyObject *__pyx_v_store;
4904   PyObject *__pyx_r = NULL;
4905   int __pyx_t_1;
4906   PyObject *__pyx_t_2 = NULL;
4907   PyObject *__pyx_t_3 = NULL;
4908   PyObject *__pyx_t_4 = NULL;
4909   PyObject *__pyx_t_5 = NULL;
4910   int __pyx_t_6;
4911   int __pyx_t_7;
4912   int __pyx_t_8;
4913   Py_ssize_t __pyx_t_9;
4914   Py_ssize_t __pyx_t_10;
4915   size_t __pyx_t_11;
4916   int32_t __pyx_t_12;
4917   long __pyx_t_13;
4918   uint32_t __pyx_t_14;
4919   char *__pyx_t_15;
4920   int __pyx_t_16;
4921   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,0};
4922   __Pyx_TraceDeclarations
4923   __Pyx_RefNannySetupContext("_open");
4924   __Pyx_TraceCall("_open", __pyx_f[0], 476);
4925   if (unlikely(__pyx_kwds)) {
4926     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
4927     PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
4928
4929     /* "csamtools.pyx":478
4930  *     def _open( self,
4931  *                char * filename,
4932  *                mode = None,             # <<<<<<<<<<<<<<
4933  *                Samfile template = None,
4934  *                referencenames = None,
4935  */
4936     values[1] = ((PyObject *)Py_None);
4937
4938     /* "csamtools.pyx":479
4939  *                char * filename,
4940  *                mode = None,
4941  *                Samfile template = None,             # <<<<<<<<<<<<<<
4942  *                referencenames = None,
4943  *                referencelengths = None,
4944  */
4945     values[2] = (PyObject *)((struct __pyx_obj_9csamtools_Samfile *)Py_None);
4946
4947     /* "csamtools.pyx":480
4948  *                mode = None,
4949  *                Samfile template = None,
4950  *                referencenames = None,             # <<<<<<<<<<<<<<
4951  *                referencelengths = None,
4952  *                text = None,
4953  */
4954     values[3] = ((PyObject *)Py_None);
4955
4956     /* "csamtools.pyx":481
4957  *                Samfile template = None,
4958  *                referencenames = None,
4959  *                referencelengths = None,             # <<<<<<<<<<<<<<
4960  *                text = None,
4961  *                header = None,
4962  */
4963     values[4] = ((PyObject *)Py_None);
4964
4965     /* "csamtools.pyx":482
4966  *                referencenames = None,
4967  *                referencelengths = None,
4968  *                text = None,             # <<<<<<<<<<<<<<
4969  *                header = None,
4970  *                port = None,
4971  */
4972     values[5] = ((PyObject *)Py_None);
4973
4974     /* "csamtools.pyx":483
4975  *                referencelengths = None,
4976  *                text = None,
4977  *                header = None,             # <<<<<<<<<<<<<<
4978  *                port = None,
4979  *                add_sq_text = True,
4980  */
4981     values[6] = ((PyObject *)Py_None);
4982
4983     /* "csamtools.pyx":484
4984  *                text = None,
4985  *                header = None,
4986  *                port = None,             # <<<<<<<<<<<<<<
4987  *                add_sq_text = True,
4988  *               ):
4989  */
4990     values[7] = ((PyObject *)Py_None);
4991     values[8] = __pyx_k_16;
4992     switch (PyTuple_GET_SIZE(__pyx_args)) {
4993       case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
4994       case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
4995       case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
4996       case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
4997       case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
4998       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
4999       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
5000       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
5001       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
5002       case  0: break;
5003       default: goto __pyx_L5_argtuple_error;
5004     }
5005     switch (PyTuple_GET_SIZE(__pyx_args)) {
5006       case  0:
5007       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
5008       if (likely(values[0])) kw_args--;
5009       else goto __pyx_L5_argtuple_error;
5010       case  1:
5011       if (kw_args > 0) {
5012         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mode);
5013         if (value) { values[1] = value; kw_args--; }
5014       }
5015       case  2:
5016       if (kw_args > 0) {
5017         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__template);
5018         if (value) { values[2] = value; kw_args--; }
5019       }
5020       case  3:
5021       if (kw_args > 0) {
5022         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencenames);
5023         if (value) { values[3] = value; kw_args--; }
5024       }
5025       case  4:
5026       if (kw_args > 0) {
5027         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__referencelengths);
5028         if (value) { values[4] = value; kw_args--; }
5029       }
5030       case  5:
5031       if (kw_args > 0) {
5032         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__text);
5033         if (value) { values[5] = value; kw_args--; }
5034       }
5035       case  6:
5036       if (kw_args > 0) {
5037         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__header);
5038         if (value) { values[6] = value; kw_args--; }
5039       }
5040       case  7:
5041       if (kw_args > 0) {
5042         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__port);
5043         if (value) { values[7] = value; kw_args--; }
5044       }
5045       case  8:
5046       if (kw_args > 0) {
5047         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__add_sq_text);
5048         if (value) { values[8] = value; kw_args--; }
5049       }
5050     }
5051     if (unlikely(kw_args > 0)) {
5052       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5053     }
5054     __pyx_v_filename = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5055     __pyx_v_mode = values[1];
5056     __pyx_v_template = ((struct __pyx_obj_9csamtools_Samfile *)values[2]);
5057     __pyx_v_referencenames = values[3];
5058     __pyx_v_referencelengths = values[4];
5059     __pyx_v_text = values[5];
5060     __pyx_v_header = values[6];
5061     __pyx_v_port = values[7];
5062     __pyx_v_add_sq_text = values[8];
5063   } else {
5064
5065     /* "csamtools.pyx":478
5066  *     def _open( self,
5067  *                char * filename,
5068  *                mode = None,             # <<<<<<<<<<<<<<
5069  *                Samfile template = None,
5070  *                referencenames = None,
5071  */
5072     __pyx_v_mode = ((PyObject *)Py_None);
5073
5074     /* "csamtools.pyx":479
5075  *                char * filename,
5076  *                mode = None,
5077  *                Samfile template = None,             # <<<<<<<<<<<<<<
5078  *                referencenames = None,
5079  *                referencelengths = None,
5080  */
5081     __pyx_v_template = ((struct __pyx_obj_9csamtools_Samfile *)Py_None);
5082
5083     /* "csamtools.pyx":480
5084  *                mode = None,
5085  *                Samfile template = None,
5086  *                referencenames = None,             # <<<<<<<<<<<<<<
5087  *                referencelengths = None,
5088  *                text = None,
5089  */
5090     __pyx_v_referencenames = ((PyObject *)Py_None);
5091
5092     /* "csamtools.pyx":481
5093  *                Samfile template = None,
5094  *                referencenames = None,
5095  *                referencelengths = None,             # <<<<<<<<<<<<<<
5096  *                text = None,
5097  *                header = None,
5098  */
5099     __pyx_v_referencelengths = ((PyObject *)Py_None);
5100
5101     /* "csamtools.pyx":482
5102  *                referencenames = None,
5103  *                referencelengths = None,
5104  *                text = None,             # <<<<<<<<<<<<<<
5105  *                header = None,
5106  *                port = None,
5107  */
5108     __pyx_v_text = ((PyObject *)Py_None);
5109
5110     /* "csamtools.pyx":483
5111  *                referencelengths = None,
5112  *                text = None,
5113  *                header = None,             # <<<<<<<<<<<<<<
5114  *                port = None,
5115  *                add_sq_text = True,
5116  */
5117     __pyx_v_header = ((PyObject *)Py_None);
5118
5119     /* "csamtools.pyx":484
5120  *                text = None,
5121  *                header = None,
5122  *                port = None,             # <<<<<<<<<<<<<<
5123  *                add_sq_text = True,
5124  *               ):
5125  */
5126     __pyx_v_port = ((PyObject *)Py_None);
5127     __pyx_v_add_sq_text = __pyx_k_16;
5128     switch (PyTuple_GET_SIZE(__pyx_args)) {
5129       case  9: __pyx_v_add_sq_text = PyTuple_GET_ITEM(__pyx_args, 8);
5130       case  8: __pyx_v_port = PyTuple_GET_ITEM(__pyx_args, 7);
5131       case  7: __pyx_v_header = PyTuple_GET_ITEM(__pyx_args, 6);
5132       case  6: __pyx_v_text = PyTuple_GET_ITEM(__pyx_args, 5);
5133       case  5: __pyx_v_referencelengths = PyTuple_GET_ITEM(__pyx_args, 4);
5134       case  4: __pyx_v_referencenames = PyTuple_GET_ITEM(__pyx_args, 3);
5135       case  3: __pyx_v_template = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 2));
5136       case  2: __pyx_v_mode = PyTuple_GET_ITEM(__pyx_args, 1);
5137       case  1: __pyx_v_filename = PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5138       break;
5139       default: goto __pyx_L5_argtuple_error;
5140     }
5141   }
5142   goto __pyx_L4_argument_unpacking_done;
5143   __pyx_L5_argtuple_error:;
5144   __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
5145   __pyx_L3_error:;
5146   __Pyx_AddTraceback("csamtools.Samfile._open");
5147   __Pyx_RefNannyFinishContext();
5148   return NULL;
5149   __pyx_L4_argument_unpacking_done:;
5150   __Pyx_INCREF(__pyx_v_text);
5151   __pyx_v_msg = Py_None; __Pyx_INCREF(Py_None);
5152   __pyx_v_n = Py_None; __Pyx_INCREF(Py_None);
5153   __pyx_v_x = Py_None; __Pyx_INCREF(Py_None);
5154   __pyx_v_name = Py_None; __Pyx_INCREF(Py_None);
5155   __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
5156   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_9csamtools_Samfile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5157
5158   /* "csamtools.pyx":494
5159  * 
5160  *         # read mode autodetection
5161  *         if mode is None:             # <<<<<<<<<<<<<<
5162  *             try:
5163  *                 self._open(filename, 'rb', template=template,
5164  */
5165   __pyx_t_1 = (__pyx_v_mode == Py_None);
5166   if (__pyx_t_1) {
5167
5168     /* "csamtools.pyx":495
5169  *         # read mode autodetection
5170  *         if mode is None:
5171  *             try:             # <<<<<<<<<<<<<<
5172  *                 self._open(filename, 'rb', template=template,
5173  *                            referencenames=referencenames,
5174  */
5175     {
5176       PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
5177       __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
5178       __Pyx_XGOTREF(__pyx_save_exc_type);
5179       __Pyx_XGOTREF(__pyx_save_exc_value);
5180       __Pyx_XGOTREF(__pyx_save_exc_tb);
5181       /*try:*/ {
5182
5183         /* "csamtools.pyx":496
5184  *         if mode is None:
5185  *             try:
5186  *                 self._open(filename, 'rb', template=template,             # <<<<<<<<<<<<<<
5187  *                            referencenames=referencenames,
5188  *                            referencelengths=referencelengths,
5189  */
5190         __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5191         __Pyx_GOTREF(__pyx_t_2);
5192         __pyx_t_3 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5193         __Pyx_GOTREF(((PyObject *)__pyx_t_3));
5194         __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5195         __Pyx_GOTREF(((PyObject *)__pyx_t_4));
5196         PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
5197         __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
5198         __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
5199         PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_n_s__rb));
5200         __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rb));
5201         __pyx_t_3 = 0;
5202         __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5203         __Pyx_GOTREF(((PyObject *)__pyx_t_3));
5204         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5205
5206         /* "csamtools.pyx":497
5207  *             try:
5208  *                 self._open(filename, 'rb', template=template,
5209  *                            referencenames=referencenames,             # <<<<<<<<<<<<<<
5210  *                            referencelengths=referencelengths,
5211  *                            text=text, header=header, port=port)
5212  */
5213         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5214
5215         /* "csamtools.pyx":498
5216  *                 self._open(filename, 'rb', template=template,
5217  *                            referencenames=referencenames,
5218  *                            referencelengths=referencelengths,             # <<<<<<<<<<<<<<
5219  *                            text=text, header=header, port=port)
5220  *                 return
5221  */
5222         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5223
5224         /* "csamtools.pyx":499
5225  *                            referencenames=referencenames,
5226  *                            referencelengths=referencelengths,
5227  *                            text=text, header=header, port=port)             # <<<<<<<<<<<<<<
5228  *                 return
5229  *             except ValueError, msg:
5230  */
5231         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5232         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5233         if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5234         __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
5235         __Pyx_GOTREF(__pyx_t_5);
5236         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5237         __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
5238         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
5239         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
5240
5241         /* "csamtools.pyx":500
5242  *                            referencelengths=referencelengths,
5243  *                            text=text, header=header, port=port)
5244  *                 return             # <<<<<<<<<<<<<<
5245  *             except ValueError, msg:
5246  *                 pass
5247  */
5248         __Pyx_XDECREF(__pyx_r);
5249         __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5250         goto __pyx_L11_try_return;
5251       }
5252       __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
5253       __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
5254       __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
5255       goto __pyx_L14_try_end;
5256       __pyx_L11_try_return:;
5257       __Pyx_XGIVEREF(__pyx_save_exc_type);
5258       __Pyx_XGIVEREF(__pyx_save_exc_value);
5259       __Pyx_XGIVEREF(__pyx_save_exc_tb);
5260       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
5261       goto __pyx_L0;
5262       __pyx_L7_error:;
5263       __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
5264       __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
5265       __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
5266       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
5267
5268       /* "csamtools.pyx":501
5269  *                            text=text, header=header, port=port)
5270  *                 return
5271  *             except ValueError, msg:             # <<<<<<<<<<<<<<
5272  *                 pass
5273  * 
5274  */
5275       __pyx_t_6 = PyErr_ExceptionMatches(__pyx_builtin_ValueError);
5276       if (__pyx_t_6) {
5277         __Pyx_AddTraceback("csamtools.Samfile._open");
5278         if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_3, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
5279         __Pyx_GOTREF(__pyx_t_5);
5280         __Pyx_GOTREF(__pyx_t_3);
5281         __Pyx_GOTREF(__pyx_t_4);
5282         __Pyx_INCREF(__pyx_t_3);
5283         __Pyx_DECREF(__pyx_v_msg);
5284         __pyx_v_msg = __pyx_t_3;
5285         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
5286         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5287         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
5288         goto __pyx_L8_exception_handled;
5289       }
5290       __pyx_L9_except_error:;
5291       __Pyx_XGIVEREF(__pyx_save_exc_type);
5292       __Pyx_XGIVEREF(__pyx_save_exc_value);
5293       __Pyx_XGIVEREF(__pyx_save_exc_tb);
5294       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
5295       goto __pyx_L1_error;
5296       __pyx_L8_exception_handled:;
5297       __Pyx_XGIVEREF(__pyx_save_exc_type);
5298       __Pyx_XGIVEREF(__pyx_save_exc_value);
5299       __Pyx_XGIVEREF(__pyx_save_exc_tb);
5300       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
5301       __pyx_L14_try_end:;
5302     }
5303
5304     /* "csamtools.pyx":504
5305  *                 pass
5306  * 
5307  *             self._open(filename, 'r', template=template,             # <<<<<<<<<<<<<<
5308  *                        referencenames=referencenames,
5309  *                        referencelengths=referencelengths,
5310  */
5311     __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___open); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5312     __Pyx_GOTREF(__pyx_t_4);
5313     __pyx_t_3 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5314     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
5315     __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5316     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
5317     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3));
5318     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
5319     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
5320     PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__r));
5321     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
5322     __pyx_t_3 = 0;
5323     __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5324     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
5325     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__template), ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5326
5327     /* "csamtools.pyx":505
5328  * 
5329  *             self._open(filename, 'r', template=template,
5330  *                        referencenames=referencenames,             # <<<<<<<<<<<<<<
5331  *                        referencelengths=referencelengths,
5332  *                        text=text, header=header, port=port)
5333  */
5334     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__referencenames), __pyx_v_referencenames) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5335
5336     /* "csamtools.pyx":506
5337  *             self._open(filename, 'r', template=template,
5338  *                        referencenames=referencenames,
5339  *                        referencelengths=referencelengths,             # <<<<<<<<<<<<<<
5340  *                        text=text, header=header, port=port)
5341  *             return
5342  */
5343     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__referencelengths), __pyx_v_referencelengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5344
5345     /* "csamtools.pyx":507
5346  *                        referencenames=referencenames,
5347  *                        referencelengths=referencelengths,
5348  *                        text=text, header=header, port=port)             # <<<<<<<<<<<<<<
5349  *             return
5350  * 
5351  */
5352     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__text), __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5353     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__header), __pyx_v_header) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5354     if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__port), __pyx_v_port) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5355     __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_4, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5356     __Pyx_GOTREF(__pyx_t_2);
5357     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
5358     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
5359     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
5360     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5361
5362     /* "csamtools.pyx":508
5363  *                        referencelengths=referencelengths,
5364  *                        text=text, header=header, port=port)
5365  *             return             # <<<<<<<<<<<<<<
5366  * 
5367  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode
5368  */
5369     __Pyx_XDECREF(__pyx_r);
5370     __pyx_r = Py_None; __Pyx_INCREF(Py_None);
5371     goto __pyx_L0;
5372     goto __pyx_L6;
5373   }
5374   __pyx_L6:;
5375
5376   /* "csamtools.pyx":510
5377  *             return
5378  * 
5379  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
5380  *         assert filename != NULL
5381  * 
5382  */
5383   #ifndef CYTHON_WITHOUT_ASSERTIONS
5384   __Pyx_INCREF(__pyx_v_mode);
5385   __pyx_t_2 = __pyx_v_mode;
5386   __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5387   __Pyx_GOTREF(__pyx_t_3);
5388   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5389   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5390   __pyx_t_7 = __pyx_t_1;
5391   if (!__pyx_t_7) {
5392     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5393     __Pyx_GOTREF(__pyx_t_3);
5394     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5395     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5396     __pyx_t_8 = __pyx_t_1;
5397     __pyx_t_1 = __pyx_t_8;
5398   } else {
5399     __pyx_t_1 = __pyx_t_7;
5400   }
5401   if (!__pyx_t_1) {
5402     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__rb), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5403     __Pyx_GOTREF(__pyx_t_3);
5404     __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5405     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5406     __pyx_t_8 = __pyx_t_7;
5407     __pyx_t_7 = __pyx_t_8;
5408   } else {
5409     __pyx_t_7 = __pyx_t_1;
5410   }
5411   if (!__pyx_t_7) {
5412     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__wb), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5413     __Pyx_GOTREF(__pyx_t_3);
5414     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5415     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5416     __pyx_t_8 = __pyx_t_1;
5417     __pyx_t_1 = __pyx_t_8;
5418   } else {
5419     __pyx_t_1 = __pyx_t_7;
5420   }
5421   if (!__pyx_t_1) {
5422     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__wh), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5423     __Pyx_GOTREF(__pyx_t_3);
5424     __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5425     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5426     __pyx_t_8 = __pyx_t_7;
5427     __pyx_t_7 = __pyx_t_8;
5428   } else {
5429     __pyx_t_7 = __pyx_t_1;
5430   }
5431   if (!__pyx_t_7) {
5432     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__wbu), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5433     __Pyx_GOTREF(__pyx_t_3);
5434     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5435     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5436     __pyx_t_8 = __pyx_t_1;
5437     __pyx_t_1 = __pyx_t_8;
5438   } else {
5439     __pyx_t_1 = __pyx_t_7;
5440   }
5441   if (!__pyx_t_1) {
5442     __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__rU), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5443     __Pyx_GOTREF(__pyx_t_3);
5444     __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5445     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5446     __pyx_t_8 = __pyx_t_7;
5447     __pyx_t_7 = __pyx_t_8;
5448   } else {
5449     __pyx_t_7 = __pyx_t_1;
5450   }
5451   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5452   if (unlikely(!__pyx_t_7)) {
5453     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), __pyx_v_mode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5454     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
5455     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_2));
5456     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5457     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5458   }
5459   #endif
5460
5461   /* "csamtools.pyx":511
5462  * 
5463  *         assert mode in ( "r","w","rb","wb", "wh", "wbu", "rU" ), "invalid file opening mode `%s`" % mode
5464  *         assert filename != NULL             # <<<<<<<<<<<<<<
5465  * 
5466  *         # close a previously opened file
5467  */
5468   #ifndef CYTHON_WITHOUT_ASSERTIONS
5469   if (unlikely(!(__pyx_v_filename != NULL))) {
5470     PyErr_SetNone(PyExc_AssertionError);
5471     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5472   }
5473   #endif
5474
5475   /* "csamtools.pyx":514
5476  * 
5477  *         # close a previously opened file
5478  *         if self.samfile != NULL: self.close()             # <<<<<<<<<<<<<<
5479  *         self.samfile = NULL
5480  * 
5481  */
5482   __pyx_t_7 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL);
5483   if (__pyx_t_7) {
5484     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5485     __Pyx_GOTREF(__pyx_t_2);
5486     __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 = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5487     __Pyx_GOTREF(__pyx_t_3);
5488     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5489     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5490     goto __pyx_L17;
5491   }
5492   __pyx_L17:;
5493
5494   /* "csamtools.pyx":515
5495  *         # close a previously opened file
5496  *         if self.samfile != NULL: self.close()
5497  *         self.samfile = NULL             # <<<<<<<<<<<<<<
5498  * 
5499  *         cdef bam_header_t * header_to_write
5500  */
5501   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;
5502
5503   /* "csamtools.pyx":518
5504  * 
5505  *         cdef bam_header_t * header_to_write
5506  *         header_to_write = NULL             # <<<<<<<<<<<<<<
5507  * 
5508  *         if self._filename != NULL: free(self._filename )
5509  */
5510   __pyx_v_header_to_write = NULL;
5511
5512   /* "csamtools.pyx":520
5513  *         header_to_write = NULL
5514  * 
5515  *         if self._filename != NULL: free(self._filename )             # <<<<<<<<<<<<<<
5516  *         self._filename = strdup( filename )
5517  *         self.isstream = strcmp( filename, "-" ) == 0
5518  */
5519   __pyx_t_7 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename != NULL);
5520   if (__pyx_t_7) {
5521     free(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename);
5522     goto __pyx_L18;
5523   }
5524   __pyx_L18:;
5525
5526   /* "csamtools.pyx":521
5527  * 
5528  *         if self._filename != NULL: free(self._filename )
5529  *         self._filename = strdup( filename )             # <<<<<<<<<<<<<<
5530  *         self.isstream = strcmp( filename, "-" ) == 0
5531  * 
5532  */
5533   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename = strdup(__pyx_v_filename);
5534
5535   /* "csamtools.pyx":522
5536  *         if self._filename != NULL: free(self._filename )
5537  *         self._filename = strdup( filename )
5538  *         self.isstream = strcmp( filename, "-" ) == 0             # <<<<<<<<<<<<<<
5539  * 
5540  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
5541  */
5542   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isstream = (strcmp(__pyx_v_filename, __pyx_k_18) == 0);
5543
5544   /* "csamtools.pyx":524
5545  *         self.isstream = strcmp( filename, "-" ) == 0
5546  * 
5547  *         self.isbam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
5548  * 
5549  *         self.isremote = strncmp(filename,"http:",5) == 0 or \
5550  */
5551   __pyx_t_9 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5552   __pyx_t_3 = __Pyx_PyBool_FromLong((__pyx_t_9 > 1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5553   __Pyx_GOTREF(__pyx_t_3);
5554   __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5555   if (__pyx_t_7) {
5556     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5557     __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5558     __Pyx_GOTREF(__pyx_t_2);
5559     __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__b), Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5560     __Pyx_GOTREF(__pyx_t_5);
5561     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5562     __pyx_t_2 = __pyx_t_5;
5563     __pyx_t_5 = 0;
5564   } else {
5565     __pyx_t_2 = __pyx_t_3;
5566     __pyx_t_3 = 0;
5567   }
5568   __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5569   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5570   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam = __pyx_t_6;
5571
5572   /* "csamtools.pyx":526
5573  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
5574  * 
5575  *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
5576  *             strncmp(filename,"ftp:",4) == 0
5577  * 
5578  */
5579   __pyx_t_7 = (strncmp(__pyx_v_filename, __pyx_k_19, 5) == 0);
5580   if (!__pyx_t_7) {
5581
5582     /* "csamtools.pyx":527
5583  * 
5584  *         self.isremote = strncmp(filename,"http:",5) == 0 or \
5585  *             strncmp(filename,"ftp:",4) == 0             # <<<<<<<<<<<<<<
5586  * 
5587  *         cdef char * ctext
5588  */
5589     __pyx_t_1 = (strncmp(__pyx_v_filename, __pyx_k_20, 4) == 0);
5590     __pyx_t_8 = __pyx_t_1;
5591   } else {
5592     __pyx_t_8 = __pyx_t_7;
5593   }
5594
5595   /* "csamtools.pyx":526
5596  *         self.isbam = len(mode) > 1 and mode[1] == 'b'
5597  * 
5598  *         self.isremote = strncmp(filename,"http:",5) == 0 or \             # <<<<<<<<<<<<<<
5599  *             strncmp(filename,"ftp:",4) == 0
5600  * 
5601  */
5602   ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isremote = __pyx_t_8;
5603
5604   /* "csamtools.pyx":530
5605  * 
5606  *         cdef char * ctext
5607  *         ctext = NULL             # <<<<<<<<<<<<<<
5608  * 
5609  *         if mode[0] == 'w':
5610  */
5611   __pyx_v_ctext = NULL;
5612
5613   /* "csamtools.pyx":532
5614  *         ctext = NULL
5615  * 
5616  *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
5617  *             # open file for writing
5618  * 
5619  */
5620   __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5621   __Pyx_GOTREF(__pyx_t_2);
5622   __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__w), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5623   __Pyx_GOTREF(__pyx_t_3);
5624   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5625   __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5626   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5627   if (__pyx_t_8) {
5628
5629     /* "csamtools.pyx":536
5630  * 
5631  *             # header structure (used for writing)
5632  *             if template:             # <<<<<<<<<<<<<<
5633  *                 # copy header from another file
5634  *                 header_to_write = template.samfile.header
5635  */
5636     __pyx_t_8 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5637     if (__pyx_t_8) {
5638
5639       /* "csamtools.pyx":538
5640  *             if template:
5641  *                 # copy header from another file
5642  *                 header_to_write = template.samfile.header             # <<<<<<<<<<<<<<
5643  * 
5644  *             elif header:
5645  */
5646       __pyx_v_header_to_write = __pyx_v_template->samfile->header;
5647       goto __pyx_L20;
5648     }
5649
5650     /* "csamtools.pyx":540
5651  *                 header_to_write = template.samfile.header
5652  * 
5653  *             elif header:             # <<<<<<<<<<<<<<
5654  *                 header_to_write = self._buildHeader( header )
5655  * 
5656  */
5657     __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5658     if (__pyx_t_8) {
5659
5660       /* "csamtools.pyx":541
5661  * 
5662  *             elif header:
5663  *                 header_to_write = self._buildHeader( header )             # <<<<<<<<<<<<<<
5664  * 
5665  *             else:
5666  */
5667       __pyx_v_header_to_write = ((struct __pyx_vtabstruct_9csamtools_Samfile *)((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->__pyx_vtab)->_buildHeader(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), __pyx_v_header);
5668       goto __pyx_L20;
5669     }
5670     /*else*/ {
5671
5672       /* "csamtools.pyx":545
5673  *             else:
5674  *                 # build header from a target names and lengths
5675  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"             # <<<<<<<<<<<<<<
5676  *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"
5677  * 
5678  */
5679       #ifndef CYTHON_WITHOUT_ASSERTIONS
5680       __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_referencenames); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5681       if (__pyx_t_8) {
5682         __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_referencelengths); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5683         __pyx_t_1 = __pyx_t_7;
5684       } else {
5685         __pyx_t_1 = __pyx_t_8;
5686       }
5687       if (unlikely(!__pyx_t_1)) {
5688         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_21));
5689         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5690       }
5691       #endif
5692
5693       /* "csamtools.pyx":546
5694  *                 # build header from a target names and lengths
5695  *                 assert referencenames and referencelengths, "either supply options `template`, `header` or  both `referencenames` and `referencelengths` for writing"
5696  *                 assert len(referencenames) == len(referencelengths), "unequal names and lengths of reference sequences"             # <<<<<<<<<<<<<<
5697  * 
5698  *                 # allocate and fill header
5699  */
5700       #ifndef CYTHON_WITHOUT_ASSERTIONS
5701       __pyx_t_9 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5702       __pyx_t_10 = PyObject_Length(__pyx_v_referencelengths); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5703       if (unlikely(!(__pyx_t_9 == __pyx_t_10))) {
5704         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_22));
5705         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5706       }
5707       #endif
5708
5709       /* "csamtools.pyx":549
5710  * 
5711  *                 # allocate and fill header
5712  *                 header_to_write = bam_header_init()             # <<<<<<<<<<<<<<
5713  *                 header_to_write.n_targets = len(referencenames)
5714  *                 n = 0
5715  */
5716       __pyx_v_header_to_write = bam_header_init();
5717
5718       /* "csamtools.pyx":550
5719  *                 # allocate and fill header
5720  *                 header_to_write = bam_header_init()
5721  *                 header_to_write.n_targets = len(referencenames)             # <<<<<<<<<<<<<<
5722  *                 n = 0
5723  *                 for x in referencenames: n += len(x) + 1
5724  */
5725       __pyx_t_10 = PyObject_Length(__pyx_v_referencenames); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5726       __pyx_v_header_to_write->n_targets = __pyx_t_10;
5727
5728       /* "csamtools.pyx":551
5729  *                 header_to_write = bam_header_init()
5730  *                 header_to_write.n_targets = len(referencenames)
5731  *                 n = 0             # <<<<<<<<<<<<<<
5732  *                 for x in referencenames: n += len(x) + 1
5733  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
5734  */
5735       __Pyx_INCREF(__pyx_int_0);
5736       __Pyx_DECREF(__pyx_v_n);
5737       __pyx_v_n = __pyx_int_0;
5738
5739       /* "csamtools.pyx":552
5740  *                 header_to_write.n_targets = len(referencenames)
5741  *                 n = 0
5742  *                 for x in referencenames: n += len(x) + 1             # <<<<<<<<<<<<<<
5743  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
5744  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
5745  */
5746       if (PyList_CheckExact(__pyx_v_referencenames) || PyTuple_CheckExact(__pyx_v_referencenames)) {
5747         __pyx_t_10 = 0; __pyx_t_3 = __pyx_v_referencenames; __Pyx_INCREF(__pyx_t_3);
5748       } else {
5749         __pyx_t_10 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_referencenames); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5750         __Pyx_GOTREF(__pyx_t_3);
5751       }
5752       for (;;) {
5753         if (likely(PyList_CheckExact(__pyx_t_3))) {
5754           if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_3)) break;
5755           __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++;
5756         } else if (likely(PyTuple_CheckExact(__pyx_t_3))) {
5757           if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
5758           __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++;
5759         } else {
5760           __pyx_t_2 = PyIter_Next(__pyx_t_3);
5761           if (!__pyx_t_2) {
5762             if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5763             break;
5764           }
5765           __Pyx_GOTREF(__pyx_t_2);
5766         }
5767         __Pyx_DECREF(__pyx_v_x);
5768         __pyx_v_x = __pyx_t_2;
5769         __pyx_t_2 = 0;
5770         __pyx_t_9 = PyObject_Length(__pyx_v_x); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5771         __pyx_t_2 = PyInt_FromSsize_t((__pyx_t_9 + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5772         __Pyx_GOTREF(__pyx_t_2);
5773         __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_n, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5774         __Pyx_GOTREF(__pyx_t_5);
5775         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5776         __Pyx_DECREF(__pyx_v_n);
5777         __pyx_v_n = __pyx_t_5;
5778         __pyx_t_5 = 0;
5779       }
5780       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5781
5782       /* "csamtools.pyx":553
5783  *                 n = 0
5784  *                 for x in referencenames: n += len(x) + 1
5785  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
5786  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
5787  *                 for x from 0 <= x < header_to_write.n_targets:
5788  */
5789       __pyx_t_11 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5790       __pyx_v_header_to_write->target_name = ((char **)calloc(__pyx_t_11, (sizeof(char *))));
5791
5792       /* "csamtools.pyx":554
5793  *                 for x in referencenames: n += len(x) + 1
5794  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
5795  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
5796  *                 for x from 0 <= x < header_to_write.n_targets:
5797  *                     header_to_write.target_len[x] = referencelengths[x]
5798  */
5799       __pyx_t_11 = __Pyx_PyInt_AsSize_t(__pyx_v_n); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5800       __pyx_v_header_to_write->target_len = ((uint32_t *)calloc(__pyx_t_11, (sizeof(uint32_t))));
5801
5802       /* "csamtools.pyx":555
5803  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
5804  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
5805  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
5806  *                     header_to_write.target_len[x] = referencelengths[x]
5807  *                     name = referencenames[x]
5808  */
5809       __pyx_t_12 = __pyx_v_header_to_write->n_targets;
5810       for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13++) {
5811         __pyx_t_3 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5812         __Pyx_GOTREF(__pyx_t_3);
5813         __Pyx_DECREF(__pyx_v_x);
5814         __pyx_v_x = __pyx_t_3;
5815         __pyx_t_3 = 0;
5816
5817         /* "csamtools.pyx":556
5818  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
5819  *                 for x from 0 <= x < header_to_write.n_targets:
5820  *                     header_to_write.target_len[x] = referencelengths[x]             # <<<<<<<<<<<<<<
5821  *                     name = referencenames[x]
5822  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
5823  */
5824         __pyx_t_3 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5825         __Pyx_GOTREF(__pyx_t_3);
5826         __pyx_t_14 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_14 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5827         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
5828         __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5829         (__pyx_v_header_to_write->target_len[__pyx_t_10]) = __pyx_t_14;
5830
5831         /* "csamtools.pyx":557
5832  *                 for x from 0 <= x < header_to_write.n_targets:
5833  *                     header_to_write.target_len[x] = referencelengths[x]
5834  *                     name = referencenames[x]             # <<<<<<<<<<<<<<
5835  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
5836  *                     strncpy( header_to_write.target_name[x], name, len(name) )
5837  */
5838         __pyx_t_3 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5839         __Pyx_GOTREF(__pyx_t_3);
5840         __Pyx_DECREF(__pyx_v_name);
5841         __pyx_v_name = __pyx_t_3;
5842         __pyx_t_3 = 0;
5843
5844         /* "csamtools.pyx":558
5845  *                     header_to_write.target_len[x] = referencelengths[x]
5846  *                     name = referencenames[x]
5847  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))             # <<<<<<<<<<<<<<
5848  *                     strncpy( header_to_write.target_name[x], name, len(name) )
5849  * 
5850  */
5851         __pyx_t_10 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5852         __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5853         (__pyx_v_header_to_write->target_name[__pyx_t_9]) = ((char *)calloc((__pyx_t_10 + 1), (sizeof(char))));
5854
5855         /* "csamtools.pyx":559
5856  *                     name = referencenames[x]
5857  *                     header_to_write.target_name[x] = <char*>calloc(len(name)+1, sizeof(char))
5858  *                     strncpy( header_to_write.target_name[x], name, len(name) )             # <<<<<<<<<<<<<<
5859  * 
5860  *                 # Optionally, if there is no text, add a SAM compatible header to output
5861  */
5862         __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5863         __pyx_t_15 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5864         __pyx_t_9 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5865         strncpy((__pyx_v_header_to_write->target_name[__pyx_t_10]), __pyx_t_15, __pyx_t_9);
5866         __pyx_t_13 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5867       }
5868
5869       /* "csamtools.pyx":555
5870  *                 header_to_write.target_name = <char**>calloc(n, sizeof(char*))
5871  *                 header_to_write.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
5872  *                 for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
5873  *                     header_to_write.target_len[x] = referencelengths[x]
5874  *                     name = referencenames[x]
5875  */
5876       __pyx_t_3 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5877       __Pyx_GOTREF(__pyx_t_3);
5878       __Pyx_DECREF(__pyx_v_x);
5879       __pyx_v_x = __pyx_t_3;
5880       __pyx_t_3 = 0;
5881
5882       /* "csamtools.pyx":563
5883  *                 # Optionally, if there is no text, add a SAM compatible header to output
5884  *                 # file.
5885  *                 if text is None and add_sq_text:             # <<<<<<<<<<<<<<
5886  *                     text = ''
5887  *                     for x from 0 <= x < header_to_write.n_targets:
5888  */
5889       __pyx_t_1 = (__pyx_v_text == Py_None);
5890       if (__pyx_t_1) {
5891         __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5892         __pyx_t_7 = __pyx_t_8;
5893       } else {
5894         __pyx_t_7 = __pyx_t_1;
5895       }
5896       if (__pyx_t_7) {
5897
5898         /* "csamtools.pyx":564
5899  *                 # file.
5900  *                 if text is None and add_sq_text:
5901  *                     text = ''             # <<<<<<<<<<<<<<
5902  *                     for x from 0 <= x < header_to_write.n_targets:
5903  *                         text += "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] )
5904  */
5905         __Pyx_INCREF(((PyObject *)__pyx_kp_s_12));
5906         __Pyx_DECREF(__pyx_v_text);
5907         __pyx_v_text = ((PyObject *)__pyx_kp_s_12);
5908
5909         /* "csamtools.pyx":565
5910  *                 if text is None and add_sq_text:
5911  *                     text = ''
5912  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
5913  *                         text += "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] )
5914  * 
5915  */
5916         __pyx_t_12 = __pyx_v_header_to_write->n_targets;
5917         for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13++) {
5918           __pyx_t_3 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5919           __Pyx_GOTREF(__pyx_t_3);
5920           __Pyx_DECREF(__pyx_v_x);
5921           __pyx_v_x = __pyx_t_3;
5922           __pyx_t_3 = 0;
5923
5924           /* "csamtools.pyx":566
5925  *                     text = ''
5926  *                     for x from 0 <= x < header_to_write.n_targets:
5927  *                         text += "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] )             # <<<<<<<<<<<<<<
5928  * 
5929  *                 if text != None:
5930  */
5931           __pyx_t_3 = PyObject_GetItem(__pyx_v_referencenames, __pyx_v_x); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5932           __Pyx_GOTREF(__pyx_t_3);
5933           __pyx_t_5 = PyObject_GetItem(__pyx_v_referencelengths, __pyx_v_x); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5934           __Pyx_GOTREF(__pyx_t_5);
5935           __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5936           __Pyx_GOTREF(((PyObject *)__pyx_t_2));
5937           PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
5938           __Pyx_GIVEREF(__pyx_t_3);
5939           PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
5940           __Pyx_GIVEREF(__pyx_t_5);
5941           __pyx_t_3 = 0;
5942           __pyx_t_5 = 0;
5943           __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5944           __Pyx_GOTREF(((PyObject *)__pyx_t_5));
5945           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
5946           __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_text, ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5947           __Pyx_GOTREF(__pyx_t_2);
5948           __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
5949           __Pyx_DECREF(__pyx_v_text);
5950           __pyx_v_text = __pyx_t_2;
5951           __pyx_t_2 = 0;
5952           __pyx_t_13 = __Pyx_PyInt_AsLong(__pyx_v_x); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5953         }
5954
5955         /* "csamtools.pyx":565
5956  *                 if text is None and add_sq_text:
5957  *                     text = ''
5958  *                     for x from 0 <= x < header_to_write.n_targets:             # <<<<<<<<<<<<<<
5959  *                         text += "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] )
5960  * 
5961  */
5962         __pyx_t_2 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5963         __Pyx_GOTREF(__pyx_t_2);
5964         __Pyx_DECREF(__pyx_v_x);
5965         __pyx_v_x = __pyx_t_2;
5966         __pyx_t_2 = 0;
5967         goto __pyx_L25;
5968       }
5969       __pyx_L25:;
5970
5971       /* "csamtools.pyx":568
5972  *                         text += "@SQ\tSN:%s\tLN:%s\n" % (referencenames[x], referencelengths[x] )
5973  * 
5974  *                 if text != None:             # <<<<<<<<<<<<<<
5975  *                     # copy without \0
5976  *                     ctext = text
5977  */
5978       __pyx_t_2 = PyObject_RichCompare(__pyx_v_text, Py_None, Py_NE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5979       __Pyx_GOTREF(__pyx_t_2);
5980       __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5981       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
5982       if (__pyx_t_7) {
5983
5984         /* "csamtools.pyx":570
5985  *                 if text != None:
5986  *                     # copy without \0
5987  *                     ctext = text             # <<<<<<<<<<<<<<
5988  *                     header_to_write.l_text = strlen(ctext)
5989  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
5990  */
5991         __pyx_t_15 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
5992         __pyx_v_ctext = __pyx_t_15;
5993
5994         /* "csamtools.pyx":571
5995  *                     # copy without \0
5996  *                     ctext = text
5997  *                     header_to_write.l_text = strlen(ctext)             # <<<<<<<<<<<<<<
5998  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
5999  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
6000  */
6001         __pyx_v_header_to_write->l_text = strlen(__pyx_v_ctext);
6002
6003         /* "csamtools.pyx":572
6004  *                     ctext = text
6005  *                     header_to_write.l_text = strlen(ctext)
6006  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )             # <<<<<<<<<<<<<<
6007  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
6008  * 
6009  */
6010         __pyx_v_header_to_write->text = ((char *)calloc(strlen(__pyx_v_ctext), (sizeof(char))));
6011
6012         /* "csamtools.pyx":573
6013  *                     header_to_write.l_text = strlen(ctext)
6014  *                     header_to_write.text = <char*>calloc( strlen(ctext), sizeof(char) )
6015  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )             # <<<<<<<<<<<<<<
6016  * 
6017  *                 header_to_write.hash = NULL
6018  */
6019         memcpy(__pyx_v_header_to_write->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
6020         goto __pyx_L28;
6021       }
6022       __pyx_L28:;
6023
6024       /* "csamtools.pyx":575
6025  *                     memcpy( header_to_write.text, ctext, strlen(ctext) )
6026  * 
6027  *                 header_to_write.hash = NULL             # <<<<<<<<<<<<<<
6028  *                 header_to_write.rg2lib = NULL
6029  * 
6030  */
6031       __pyx_v_header_to_write->hash = NULL;
6032
6033       /* "csamtools.pyx":576
6034  * 
6035  *                 header_to_write.hash = NULL
6036  *                 header_to_write.rg2lib = NULL             # <<<<<<<<<<<<<<
6037  * 
6038  *             # open file. Header gets written to file at the same time for bam files
6039  */
6040       __pyx_v_header_to_write->rg2lib = NULL;
6041     }
6042     __pyx_L20:;
6043
6044     /* "csamtools.pyx":580
6045  *             # open file. Header gets written to file at the same time for bam files
6046  *             # and sam files (in the latter case, the mode needs to be wh)
6047  *             store = StderrStore()             # <<<<<<<<<<<<<<
6048  *             self.samfile = samopen( filename, mode, header_to_write )
6049  *             store.release()
6050  */
6051     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6052     __Pyx_GOTREF(__pyx_t_2);
6053     __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6054     __Pyx_GOTREF(__pyx_t_5);
6055     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6056     __Pyx_DECREF(__pyx_v_store);
6057     __pyx_v_store = __pyx_t_5;
6058     __pyx_t_5 = 0;
6059
6060     /* "csamtools.pyx":581
6061  *             # and sam files (in the latter case, the mode needs to be wh)
6062  *             store = StderrStore()
6063  *             self.samfile = samopen( filename, mode, header_to_write )             # <<<<<<<<<<<<<<
6064  *             store.release()
6065  * 
6066  */
6067     __pyx_t_15 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6068     ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile = samopen(__pyx_v_filename, __pyx_t_15, __pyx_v_header_to_write);
6069
6070     /* "csamtools.pyx":582
6071  *             store = StderrStore()
6072  *             self.samfile = samopen( filename, mode, header_to_write )
6073  *             store.release()             # <<<<<<<<<<<<<<
6074  * 
6075  *             # bam_header_destroy takes care of cleaning up of all the members
6076  */
6077     __pyx_t_5 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6078     __Pyx_GOTREF(__pyx_t_5);
6079     __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 = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6080     __Pyx_GOTREF(__pyx_t_2);
6081     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6082     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6083
6084     /* "csamtools.pyx":585
6085  * 
6086  *             # bam_header_destroy takes care of cleaning up of all the members
6087  *             if not template and header_to_write != NULL:             # <<<<<<<<<<<<<<
6088  *                 bam_header_destroy( header_to_write )
6089  * 
6090  */
6091     __pyx_t_7 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6092     __pyx_t_1 = (!__pyx_t_7);
6093     if (__pyx_t_1) {
6094       __pyx_t_7 = (__pyx_v_header_to_write != NULL);
6095       __pyx_t_8 = __pyx_t_7;
6096     } else {
6097       __pyx_t_8 = __pyx_t_1;
6098     }
6099     if (__pyx_t_8) {
6100
6101       /* "csamtools.pyx":586
6102  *             # bam_header_destroy takes care of cleaning up of all the members
6103  *             if not template and header_to_write != NULL:
6104  *                 bam_header_destroy( header_to_write )             # <<<<<<<<<<<<<<
6105  * 
6106  *         elif mode[0] == "r":
6107  */
6108       bam_header_destroy(__pyx_v_header_to_write);
6109       goto __pyx_L29;
6110     }
6111     __pyx_L29:;
6112     goto __pyx_L19;
6113   }
6114
6115   /* "csamtools.pyx":588
6116  *                 bam_header_destroy( header_to_write )
6117  * 
6118  *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
6119  *             # open file for reading
6120  *             if strncmp( filename, "-", 1) != 0 and \
6121  */
6122   __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6123   __Pyx_GOTREF(__pyx_t_2);
6124   __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6125   __Pyx_GOTREF(__pyx_t_5);
6126   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6127   __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6128   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6129   if (__pyx_t_8) {
6130
6131     /* "csamtools.pyx":590
6132  *         elif mode[0] == "r":
6133  *             # open file for reading
6134  *             if strncmp( filename, "-", 1) != 0 and \             # <<<<<<<<<<<<<<
6135  *                     not self.isremote and \
6136  *                     not os.path.exists( filename ):
6137  */
6138     __pyx_t_8 = (strncmp(__pyx_v_filename, __pyx_k_18, 1) != 0);
6139     if (__pyx_t_8) {
6140
6141       /* "csamtools.pyx":591
6142  *             # open file for reading
6143  *             if strncmp( filename, "-", 1) != 0 and \
6144  *                     not self.isremote and \             # <<<<<<<<<<<<<<
6145  *                     not os.path.exists( filename ):
6146  *                 raise IOError( "file `%s` not found" % filename)
6147  */
6148       __pyx_t_1 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isremote);
6149       if (__pyx_t_1) {
6150
6151         /* "csamtools.pyx":592
6152  *             if strncmp( filename, "-", 1) != 0 and \
6153  *                     not self.isremote and \
6154  *                     not os.path.exists( filename ):             # <<<<<<<<<<<<<<
6155  *                 raise IOError( "file `%s` not found" % filename)
6156  * 
6157  */
6158         __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6159         __Pyx_GOTREF(__pyx_t_5);
6160         __pyx_t_2 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6161         __Pyx_GOTREF(__pyx_t_2);
6162         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6163         __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6164         __Pyx_GOTREF(__pyx_t_5);
6165         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6166         __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6167         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6168         __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6169         __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6170         PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
6171         __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
6172         __pyx_t_2 = 0;
6173         __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6174         __Pyx_GOTREF(__pyx_t_2);
6175         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6176         __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
6177         __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6178         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6179         __pyx_t_16 = (!__pyx_t_7);
6180         __pyx_t_7 = __pyx_t_16;
6181       } else {
6182         __pyx_t_7 = __pyx_t_1;
6183       }
6184       __pyx_t_1 = __pyx_t_7;
6185     } else {
6186       __pyx_t_1 = __pyx_t_8;
6187     }
6188     if (__pyx_t_1) {
6189
6190       /* "csamtools.pyx":593
6191  *                     not self.isremote and \
6192  *                     not os.path.exists( filename ):
6193  *                 raise IOError( "file `%s` not found" % filename)             # <<<<<<<<<<<<<<
6194  * 
6195  *             # try to detect errors
6196  */
6197       __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6198       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6199       __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_24), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6200       __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6201       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6202       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6203       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6204       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
6205       __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
6206       __pyx_t_3 = 0;
6207       __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 = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6208       __Pyx_GOTREF(__pyx_t_3);
6209       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6210       __Pyx_Raise(__pyx_t_3, 0, 0);
6211       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6212       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6213       goto __pyx_L30;
6214     }
6215     __pyx_L30:;
6216
6217     /* "csamtools.pyx":596
6218  * 
6219  *             # try to detect errors
6220  *             self.samfile = samopen( filename, mode, NULL )             # <<<<<<<<<<<<<<
6221  *             if self.samfile == NULL:
6222  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
6223  */
6224     __pyx_t_15 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6225     ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile = samopen(__pyx_v_filename, __pyx_t_15, NULL);
6226
6227     /* "csamtools.pyx":597
6228  *             # try to detect errors
6229  *             self.samfile = samopen( filename, mode, NULL )
6230  *             if self.samfile == NULL:             # <<<<<<<<<<<<<<
6231  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
6232  * 
6233  */
6234     __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile == NULL);
6235     if (__pyx_t_1) {
6236
6237       /* "csamtools.pyx":598
6238  *             self.samfile = samopen( filename, mode, NULL )
6239  *             if self.samfile == NULL:
6240  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
6241  * 
6242  *             if self.samfile.header == NULL:
6243  */
6244       __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), __pyx_v_mode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6245       __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6246       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6247       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6248       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
6249       __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
6250       __pyx_t_3 = 0;
6251       __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 = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6252       __Pyx_GOTREF(__pyx_t_3);
6253       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6254       __Pyx_Raise(__pyx_t_3, 0, 0);
6255       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6256       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6257       goto __pyx_L31;
6258     }
6259     __pyx_L31:;
6260
6261     /* "csamtools.pyx":600
6262  *                 raise ValueError( "could not open file (mode='%s') - is it SAM/BAM format?" % mode)
6263  * 
6264  *             if self.samfile.header == NULL:             # <<<<<<<<<<<<<<
6265  *                 raise ValueError( "file does not have valid header (mode='%s') - is it SAM/BAM format?" % mode )
6266  * 
6267  */
6268     __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header == NULL);
6269     if (__pyx_t_1) {
6270
6271       /* "csamtools.pyx":601
6272  * 
6273  *             if self.samfile.header == NULL:
6274  *                 raise ValueError( "file does not have valid header (mode='%s') - is it SAM/BAM format?" % mode )             # <<<<<<<<<<<<<<
6275  * 
6276  *             #disabled for autodetection to work
6277  */
6278       __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), __pyx_v_mode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6279       __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6280       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6281       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6282       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
6283       __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
6284       __pyx_t_3 = 0;
6285       __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 = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6286       __Pyx_GOTREF(__pyx_t_3);
6287       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6288       __Pyx_Raise(__pyx_t_3, 0, 0);
6289       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6290       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6291       goto __pyx_L32;
6292     }
6293     __pyx_L32:;
6294     goto __pyx_L19;
6295   }
6296   __pyx_L19:;
6297
6298   /* "csamtools.pyx":608
6299  *             #    raise ValueError( "file header is empty (mode='%s') - is it SAM/BAM format?" % mode)
6300  * 
6301  *         if self.samfile == NULL:             # <<<<<<<<<<<<<<
6302  *             raise IOError("could not open file `%s`" % filename )
6303  * 
6304  */
6305   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile == NULL);
6306   if (__pyx_t_1) {
6307
6308     /* "csamtools.pyx":609
6309  * 
6310  *         if self.samfile == NULL:
6311  *             raise IOError("could not open file `%s`" % filename )             # <<<<<<<<<<<<<<
6312  * 
6313  *         # check for index and open if present
6314  */
6315     __pyx_t_3 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6316     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6317     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_5), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6318     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6319     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
6320     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6321     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
6322     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
6323     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
6324     __pyx_t_2 = 0;
6325     __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6326     __Pyx_GOTREF(__pyx_t_2);
6327     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
6328     __Pyx_Raise(__pyx_t_2, 0, 0);
6329     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6330     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 609; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6331     goto __pyx_L33;
6332   }
6333   __pyx_L33:;
6334
6335   /* "csamtools.pyx":612
6336  * 
6337  *         # check for index and open if present
6338  *         if mode[0] == "r" and self.isbam:             # <<<<<<<<<<<<<<
6339  * 
6340  *             if not self.isremote:
6341  */
6342   __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_mode, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6343   __Pyx_GOTREF(__pyx_t_2);
6344   __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, ((PyObject *)__pyx_n_s__r), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6345   __Pyx_GOTREF(__pyx_t_3);
6346   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6347   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6348   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6349   if (__pyx_t_1) {
6350     __pyx_t_8 = ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam;
6351   } else {
6352     __pyx_t_8 = __pyx_t_1;
6353   }
6354   if (__pyx_t_8) {
6355
6356     /* "csamtools.pyx":614
6357  *         if mode[0] == "r" and self.isbam:
6358  * 
6359  *             if not self.isremote:             # <<<<<<<<<<<<<<
6360  *                 if not os.path.exists(filename +".bai"):
6361  *                     self.index = NULL
6362  */
6363     __pyx_t_8 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isremote);
6364     if (__pyx_t_8) {
6365
6366       /* "csamtools.pyx":615
6367  * 
6368  *             if not self.isremote:
6369  *                 if not os.path.exists(filename +".bai"):             # <<<<<<<<<<<<<<
6370  *                     self.index = NULL
6371  *                 else:
6372  */
6373       __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6374       __Pyx_GOTREF(__pyx_t_3);
6375       __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6376       __Pyx_GOTREF(__pyx_t_2);
6377       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6378       __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__exists); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6379       __Pyx_GOTREF(__pyx_t_3);
6380       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6381       __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6382       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6383       __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_kp_s_27)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6384       __Pyx_GOTREF(__pyx_t_5);
6385       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6386       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6387       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6388       PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
6389       __Pyx_GIVEREF(__pyx_t_5);
6390       __pyx_t_5 = 0;
6391       __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6392       __Pyx_GOTREF(__pyx_t_5);
6393       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
6394       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6395       __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 615; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6396       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6397       __pyx_t_1 = (!__pyx_t_8);
6398       if (__pyx_t_1) {
6399
6400         /* "csamtools.pyx":616
6401  *             if not self.isremote:
6402  *                 if not os.path.exists(filename +".bai"):
6403  *                     self.index = NULL             # <<<<<<<<<<<<<<
6404  *                 else:
6405  *                     # returns NULL if there is no index or index could not be opened
6406  */
6407         ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index = NULL;
6408         goto __pyx_L36;
6409       }
6410       /*else*/ {
6411
6412         /* "csamtools.pyx":619
6413  *                 else:
6414  *                     # returns NULL if there is no index or index could not be opened
6415  *                     self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
6416  *                     if self.index == NULL:
6417  *                         raise IOError("error while opening index `%s` " % filename )
6418  */
6419         ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index = bam_index_load(__pyx_v_filename);
6420
6421         /* "csamtools.pyx":620
6422  *                     # returns NULL if there is no index or index could not be opened
6423  *                     self.index = bam_index_load(filename)
6424  *                     if self.index == NULL:             # <<<<<<<<<<<<<<
6425  *                         raise IOError("error while opening index `%s` " % filename )
6426  *             else:
6427  */
6428         __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index == NULL);
6429         if (__pyx_t_1) {
6430
6431           /* "csamtools.pyx":621
6432  *                     self.index = bam_index_load(filename)
6433  *                     if self.index == NULL:
6434  *                         raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
6435  *             else:
6436  *                 self.index = bam_index_load(filename)
6437  */
6438           __pyx_t_5 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6439           __Pyx_GOTREF(((PyObject *)__pyx_t_5));
6440           __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_28), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6441           __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6442           __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
6443           __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6444           __Pyx_GOTREF(((PyObject *)__pyx_t_5));
6445           PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2));
6446           __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
6447           __pyx_t_2 = 0;
6448           __pyx_t_2 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6449           __Pyx_GOTREF(__pyx_t_2);
6450           __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
6451           __Pyx_Raise(__pyx_t_2, 0, 0);
6452           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6453           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6454           goto __pyx_L37;
6455         }
6456         __pyx_L37:;
6457       }
6458       __pyx_L36:;
6459       goto __pyx_L35;
6460     }
6461     /*else*/ {
6462
6463       /* "csamtools.pyx":623
6464  *                         raise IOError("error while opening index `%s` " % filename )
6465  *             else:
6466  *                 self.index = bam_index_load(filename)             # <<<<<<<<<<<<<<
6467  *                 if self.index == NULL:
6468  *                     raise IOError("error while opening index `%s` " % filename )
6469  */
6470       ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index = bam_index_load(__pyx_v_filename);
6471
6472       /* "csamtools.pyx":624
6473  *             else:
6474  *                 self.index = bam_index_load(filename)
6475  *                 if self.index == NULL:             # <<<<<<<<<<<<<<
6476  *                     raise IOError("error while opening index `%s` " % filename )
6477  * 
6478  */
6479       __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index == NULL);
6480       if (__pyx_t_1) {
6481
6482         /* "csamtools.pyx":625
6483  *                 self.index = bam_index_load(filename)
6484  *                 if self.index == NULL:
6485  *                     raise IOError("error while opening index `%s` " % filename )             # <<<<<<<<<<<<<<
6486  * 
6487  *             if not self.isstream:
6488  */
6489         __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6490         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6491         __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_28), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6492         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
6493         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6494         __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6495         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6496         PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_5));
6497         __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
6498         __pyx_t_5 = 0;
6499         __pyx_t_5 = PyObject_Call(__pyx_builtin_IOError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6500         __Pyx_GOTREF(__pyx_t_5);
6501         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
6502         __Pyx_Raise(__pyx_t_5, 0, 0);
6503         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
6504         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6505         goto __pyx_L38;
6506       }
6507       __pyx_L38:;
6508     }
6509     __pyx_L35:;
6510
6511     /* "csamtools.pyx":627
6512  *                     raise IOError("error while opening index `%s` " % filename )
6513  * 
6514  *             if not self.isstream:             # <<<<<<<<<<<<<<
6515  *                 self.start_offset = bam_tell( self.samfile.x.bam )
6516  * 
6517  */
6518     __pyx_t_1 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isstream);
6519     if (__pyx_t_1) {
6520
6521       /* "csamtools.pyx":628
6522  * 
6523  *             if not self.isstream:
6524  *                 self.start_offset = bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
6525  * 
6526  *     def gettid( self, reference ):
6527  */
6528       ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->start_offset = bam_tell(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam);
6529       goto __pyx_L39;
6530     }
6531     __pyx_L39:;
6532     goto __pyx_L34;
6533   }
6534   __pyx_L34:;
6535
6536   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6537   goto __pyx_L0;
6538   __pyx_L1_error:;
6539   __Pyx_XDECREF(__pyx_t_2);
6540   __Pyx_XDECREF(__pyx_t_3);
6541   __Pyx_XDECREF(__pyx_t_4);
6542   __Pyx_XDECREF(__pyx_t_5);
6543   __Pyx_AddTraceback("csamtools.Samfile._open");
6544   __pyx_r = NULL;
6545   __pyx_L0:;
6546   __Pyx_DECREF(__pyx_v_msg);
6547   __Pyx_DECREF(__pyx_v_n);
6548   __Pyx_DECREF(__pyx_v_x);
6549   __Pyx_DECREF(__pyx_v_name);
6550   __Pyx_DECREF(__pyx_v_store);
6551   __Pyx_DECREF(__pyx_v_text);
6552   __Pyx_XGIVEREF(__pyx_r);
6553   __Pyx_TraceReturn(__pyx_r);
6554   __Pyx_RefNannyFinishContext();
6555   return __pyx_r;
6556 }
6557
6558 /* "csamtools.pyx":630
6559  *                 self.start_offset = bam_tell( self.samfile.x.bam )
6560  * 
6561  *     def gettid( self, reference ):             # <<<<<<<<<<<<<<
6562  *         '''
6563  *         convert :term:`reference` name into numerical :term:`tid`
6564  */
6565
6566 static PyObject *__pyx_pf_9csamtools_7Samfile_4gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference); /*proto*/
6567 static char __pyx_doc_9csamtools_7Samfile_4gettid[] = "Samfile.gettid(self, reference)\n\n        convert :term:`reference` name into numerical :term:`tid`\n\n        returns -1 if reference is not known.\n        ";
6568 static PyObject *__pyx_pf_9csamtools_7Samfile_4gettid(PyObject *__pyx_v_self, PyObject *__pyx_v_reference) {
6569   PyObject *__pyx_r = NULL;
6570   PyObject *__pyx_t_1 = NULL;
6571   PyObject *__pyx_t_2 = NULL;
6572   int __pyx_t_3;
6573   int __pyx_t_4;
6574   char *__pyx_t_5;
6575   __Pyx_TraceDeclarations
6576   __Pyx_RefNannySetupContext("gettid");
6577   __Pyx_TraceCall("gettid", __pyx_f[0], 630);
6578
6579   /* "csamtools.pyx":636
6580  *         returns -1 if reference is not known.
6581  *         '''
6582  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
6583  *         return pysam_reference2tid( self.samfile.header, reference )
6584  * 
6585  */
6586   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6587   __Pyx_GOTREF(__pyx_t_1);
6588   __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 = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6589   __Pyx_GOTREF(__pyx_t_2);
6590   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6591   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6592   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6593   __pyx_t_4 = (!__pyx_t_3);
6594   if (__pyx_t_4) {
6595     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6596     __Pyx_GOTREF(__pyx_t_2);
6597     __Pyx_Raise(__pyx_t_2, 0, 0);
6598     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6599     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6600     goto __pyx_L5;
6601   }
6602   __pyx_L5:;
6603
6604   /* "csamtools.pyx":637
6605  *         '''
6606  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
6607  *         return pysam_reference2tid( self.samfile.header, reference )             # <<<<<<<<<<<<<<
6608  * 
6609  *     def getrname( self, tid ):
6610  */
6611   __Pyx_XDECREF(__pyx_r);
6612   __pyx_t_5 = PyBytes_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6613   __pyx_t_2 = PyInt_FromLong(pysam_reference2tid(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header, __pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6614   __Pyx_GOTREF(__pyx_t_2);
6615   __pyx_r = __pyx_t_2;
6616   __pyx_t_2 = 0;
6617   goto __pyx_L0;
6618
6619   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6620   goto __pyx_L0;
6621   __pyx_L1_error:;
6622   __Pyx_XDECREF(__pyx_t_1);
6623   __Pyx_XDECREF(__pyx_t_2);
6624   __Pyx_AddTraceback("csamtools.Samfile.gettid");
6625   __pyx_r = NULL;
6626   __pyx_L0:;
6627   __Pyx_XGIVEREF(__pyx_r);
6628   __Pyx_TraceReturn(__pyx_r);
6629   __Pyx_RefNannyFinishContext();
6630   return __pyx_r;
6631 }
6632
6633 /* "csamtools.pyx":639
6634  *         return pysam_reference2tid( self.samfile.header, reference )
6635  * 
6636  *     def getrname( self, tid ):             # <<<<<<<<<<<<<<
6637  *         '''
6638  *         convert numerical :term:`tid` into :term:`reference` name.'''
6639  */
6640
6641 static PyObject *__pyx_pf_9csamtools_7Samfile_5getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
6642 static char __pyx_doc_9csamtools_7Samfile_5getrname[] = "Samfile.getrname(self, tid)\n\n        convert numerical :term:`tid` into :term:`reference` name.";
6643 static PyObject *__pyx_pf_9csamtools_7Samfile_5getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
6644   PyObject *__pyx_r = NULL;
6645   PyObject *__pyx_t_1 = NULL;
6646   PyObject *__pyx_t_2 = NULL;
6647   int __pyx_t_3;
6648   int __pyx_t_4;
6649   Py_ssize_t __pyx_t_5;
6650   __Pyx_TraceDeclarations
6651   __Pyx_RefNannySetupContext("getrname");
6652   __Pyx_TraceCall("getrname", __pyx_f[0], 639);
6653
6654   /* "csamtools.pyx":642
6655  *         '''
6656  *         convert numerical :term:`tid` into :term:`reference` name.'''
6657  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
6658  *         if not 0 <= tid < self.samfile.header.n_targets:
6659  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6660  */
6661   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6662   __Pyx_GOTREF(__pyx_t_1);
6663   __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 = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6664   __Pyx_GOTREF(__pyx_t_2);
6665   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6666   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6667   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6668   __pyx_t_4 = (!__pyx_t_3);
6669   if (__pyx_t_4) {
6670     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6671     __Pyx_GOTREF(__pyx_t_2);
6672     __Pyx_Raise(__pyx_t_2, 0, 0);
6673     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6674     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6675     goto __pyx_L5;
6676   }
6677   __pyx_L5:;
6678
6679   /* "csamtools.pyx":643
6680  *         convert numerical :term:`tid` into :term:`reference` name.'''
6681  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
6682  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
6683  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6684  *         return self.samfile.header.target_name[tid]
6685  */
6686   __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 = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6687   __Pyx_GOTREF(__pyx_t_2);
6688   if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
6689     __Pyx_DECREF(__pyx_t_2);
6690     __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6691     __Pyx_GOTREF(__pyx_t_1);
6692     __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 = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6693     __Pyx_GOTREF(__pyx_t_2);
6694     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6695   }
6696   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6697   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6698   __pyx_t_3 = (!__pyx_t_4);
6699   if (__pyx_t_3) {
6700
6701     /* "csamtools.pyx":644
6702  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
6703  *         if not 0 <= tid < self.samfile.header.n_targets:
6704  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
6705  *         return self.samfile.header.target_name[tid]
6706  * 
6707  */
6708     __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6709     __Pyx_GOTREF(__pyx_t_2);
6710     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6711     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
6712     __Pyx_INCREF(__pyx_v_tid);
6713     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tid);
6714     __Pyx_GIVEREF(__pyx_v_tid);
6715     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
6716     __Pyx_GIVEREF(__pyx_t_2);
6717     __pyx_t_2 = 0;
6718     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6719     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6720     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
6721     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6722     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
6723     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2));
6724     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
6725     __pyx_t_2 = 0;
6726     __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 = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6727     __Pyx_GOTREF(__pyx_t_2);
6728     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
6729     __Pyx_Raise(__pyx_t_2, 0, 0);
6730     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6731     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6732     goto __pyx_L6;
6733   }
6734   __pyx_L6:;
6735
6736   /* "csamtools.pyx":645
6737  *         if not 0 <= tid < self.samfile.header.n_targets:
6738  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6739  *         return self.samfile.header.target_name[tid]             # <<<<<<<<<<<<<<
6740  * 
6741  *     cdef char * _getrname( self, int tid ):
6742  */
6743   __Pyx_XDECREF(__pyx_r);
6744   __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 = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6745   __pyx_t_2 = PyBytes_FromString((((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_name[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6746   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
6747   __pyx_r = ((PyObject *)__pyx_t_2);
6748   __pyx_t_2 = 0;
6749   goto __pyx_L0;
6750
6751   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
6752   goto __pyx_L0;
6753   __pyx_L1_error:;
6754   __Pyx_XDECREF(__pyx_t_1);
6755   __Pyx_XDECREF(__pyx_t_2);
6756   __Pyx_AddTraceback("csamtools.Samfile.getrname");
6757   __pyx_r = NULL;
6758   __pyx_L0:;
6759   __Pyx_XGIVEREF(__pyx_r);
6760   __Pyx_TraceReturn(__pyx_r);
6761   __Pyx_RefNannyFinishContext();
6762   return __pyx_r;
6763 }
6764
6765 /* "csamtools.pyx":647
6766  *         return self.samfile.header.target_name[tid]
6767  * 
6768  *     cdef char * _getrname( self, int tid ):             # <<<<<<<<<<<<<<
6769  *         '''
6770  *         convert numerical :term:`tid` into :term:`reference` name.'''
6771  */
6772
6773 static  char *__pyx_f_9csamtools_7Samfile__getrname(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, int __pyx_v_tid) {
6774   char *__pyx_r;
6775   PyObject *__pyx_t_1 = NULL;
6776   PyObject *__pyx_t_2 = NULL;
6777   int __pyx_t_3;
6778   int __pyx_t_4;
6779   PyObject *__pyx_t_5 = NULL;
6780   __Pyx_TraceDeclarations
6781   __Pyx_RefNannySetupContext("_getrname");
6782   __Pyx_TraceCall("_getrname", __pyx_f[0], 647);
6783
6784   /* "csamtools.pyx":650
6785  *         '''
6786  *         convert numerical :term:`tid` into :term:`reference` name.'''
6787  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
6788  *         if not 0 <= tid < self.samfile.header.n_targets:
6789  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6790  */
6791   __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 = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6792   __Pyx_GOTREF(__pyx_t_1);
6793   __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 = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6794   __Pyx_GOTREF(__pyx_t_2);
6795   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6796   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6797   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6798   __pyx_t_4 = (!__pyx_t_3);
6799   if (__pyx_t_4) {
6800     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6801     __Pyx_GOTREF(__pyx_t_2);
6802     __Pyx_Raise(__pyx_t_2, 0, 0);
6803     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
6804     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6805     goto __pyx_L3;
6806   }
6807   __pyx_L3:;
6808
6809   /* "csamtools.pyx":651
6810  *         convert numerical :term:`tid` into :term:`reference` name.'''
6811  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
6812  *         if not 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
6813  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6814  *         return self.samfile.header.target_name[tid]
6815  */
6816   __pyx_t_4 = (0 <= __pyx_v_tid);
6817   if (__pyx_t_4) {
6818     __pyx_t_4 = (__pyx_v_tid < __pyx_v_self->samfile->header->n_targets);
6819   }
6820   __pyx_t_3 = (!__pyx_t_4);
6821   if (__pyx_t_3) {
6822
6823     /* "csamtools.pyx":652
6824  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
6825  *         if not 0 <= tid < self.samfile.header.n_targets:
6826  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )             # <<<<<<<<<<<<<<
6827  *         return self.samfile.header.target_name[tid]
6828  * 
6829  */
6830     __pyx_t_2 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6831     __Pyx_GOTREF(__pyx_t_2);
6832     __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 = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6833     __Pyx_GOTREF(__pyx_t_1);
6834     __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6835     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
6836     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
6837     __Pyx_GIVEREF(__pyx_t_2);
6838     PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
6839     __Pyx_GIVEREF(__pyx_t_1);
6840     __pyx_t_2 = 0;
6841     __pyx_t_1 = 0;
6842     __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_31), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6843     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
6844     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
6845     __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6846     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
6847     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
6848     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
6849     __pyx_t_1 = 0;
6850     __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 = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6851     __Pyx_GOTREF(__pyx_t_1);
6852     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
6853     __Pyx_Raise(__pyx_t_1, 0, 0);
6854     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6855     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
6856     goto __pyx_L4;
6857   }
6858   __pyx_L4:;
6859
6860   /* "csamtools.pyx":653
6861  *         if not 0 <= tid < self.samfile.header.n_targets:
6862  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
6863  *         return self.samfile.header.target_name[tid]             # <<<<<<<<<<<<<<
6864  * 
6865  *     def _parseRegion( self,
6866  */
6867   __pyx_r = (__pyx_v_self->samfile->header->target_name[__pyx_v_tid]);
6868   goto __pyx_L0;
6869
6870   __pyx_r = 0;
6871   goto __pyx_L0;
6872   __pyx_L1_error:;
6873   __Pyx_XDECREF(__pyx_t_1);
6874   __Pyx_XDECREF(__pyx_t_2);
6875   __Pyx_XDECREF(__pyx_t_5);
6876   __Pyx_WriteUnraisable("csamtools.Samfile._getrname");
6877   __pyx_r = 0;
6878   __pyx_L0:;
6879   __Pyx_TraceReturn(Py_None);
6880   __Pyx_RefNannyFinishContext();
6881   return __pyx_r;
6882 }
6883
6884 /* "csamtools.pyx":655
6885  *         return self.samfile.header.target_name[tid]
6886  * 
6887  *     def _parseRegion( self,             # <<<<<<<<<<<<<<
6888  *                       reference = None,
6889  *                       start = None,
6890  */
6891
6892 static PyObject *__pyx_pf_9csamtools_7Samfile_6_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
6893 static char __pyx_doc_9csamtools_7Samfile_6_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        ";
6894 static PyObject *__pyx_pf_9csamtools_7Samfile_6_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
6895   PyObject *__pyx_v_reference = 0;
6896   PyObject *__pyx_v_start = 0;
6897   PyObject *__pyx_v_end = 0;
6898   PyObject *__pyx_v_region = 0;
6899   int __pyx_v_rtid;
6900   PY_LONG_LONG __pyx_v_rstart;
6901   PY_LONG_LONG __pyx_v_rend;
6902   PyObject *__pyx_v_parts;
6903   PyObject *__pyx_r = NULL;
6904   PyObject *__pyx_t_1 = NULL;
6905   int __pyx_t_2;
6906   PY_LONG_LONG __pyx_t_3;
6907   int __pyx_t_4;
6908   PyObject *__pyx_t_5 = NULL;
6909   PyObject *__pyx_t_6 = NULL;
6910   PyObject *__pyx_t_7 = NULL;
6911   PyObject *__pyx_t_8 = NULL;
6912   Py_ssize_t __pyx_t_9;
6913   int __pyx_t_10;
6914   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__reference,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__region,0};
6915   __Pyx_TraceDeclarations
6916   __Pyx_RefNannySetupContext("_parseRegion");
6917   __Pyx_TraceCall("_parseRegion", __pyx_f[0], 655);
6918   if (unlikely(__pyx_kwds)) {
6919     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
6920     PyObject* values[4] = {0,0,0,0};
6921
6922     /* "csamtools.pyx":656
6923  * 
6924  *     def _parseRegion( self,
6925  *                       reference = None,             # <<<<<<<<<<<<<<
6926  *                       start = None,
6927  *                       end = None,
6928  */
6929     values[0] = ((PyObject *)Py_None);
6930
6931     /* "csamtools.pyx":657
6932  *     def _parseRegion( self,
6933  *                       reference = None,
6934  *                       start = None,             # <<<<<<<<<<<<<<
6935  *                       end = None,
6936  *                       region = None ):
6937  */
6938     values[1] = ((PyObject *)Py_None);
6939
6940     /* "csamtools.pyx":658
6941  *                       reference = None,
6942  *                       start = None,
6943  *                       end = None,             # <<<<<<<<<<<<<<
6944  *                       region = None ):
6945  *         '''
6946  */
6947     values[2] = ((PyObject *)Py_None);
6948
6949     /* "csamtools.pyx":659
6950  *                       start = None,
6951  *                       end = None,
6952  *                       region = None ):             # <<<<<<<<<<<<<<
6953  *         '''
6954  *         parse region information.
6955  */
6956     values[3] = ((PyObject *)Py_None);
6957     switch (PyTuple_GET_SIZE(__pyx_args)) {
6958       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
6959       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
6960       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
6961       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
6962       case  0: break;
6963       default: goto __pyx_L5_argtuple_error;
6964     }
6965     switch (PyTuple_GET_SIZE(__pyx_args)) {
6966       case  0:
6967       if (kw_args > 0) {
6968         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
6969         if (value) { values[0] = value; kw_args--; }
6970       }
6971       case  1:
6972       if (kw_args > 0) {
6973         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
6974         if (value) { values[1] = value; kw_args--; }
6975       }
6976       case  2:
6977       if (kw_args > 0) {
6978         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
6979         if (value) { values[2] = value; kw_args--; }
6980       }
6981       case  3:
6982       if (kw_args > 0) {
6983         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
6984         if (value) { values[3] = value; kw_args--; }
6985       }
6986     }
6987     if (unlikely(kw_args > 0)) {
6988       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
6989     }
6990     __pyx_v_reference = values[0];
6991     __pyx_v_start = values[1];
6992     __pyx_v_end = values[2];
6993     __pyx_v_region = values[3];
6994   } else {
6995
6996     /* "csamtools.pyx":656
6997  * 
6998  *     def _parseRegion( self,
6999  *                       reference = None,             # <<<<<<<<<<<<<<
7000  *                       start = None,
7001  *                       end = None,
7002  */
7003     __pyx_v_reference = ((PyObject *)Py_None);
7004
7005     /* "csamtools.pyx":657
7006  *     def _parseRegion( self,
7007  *                       reference = None,
7008  *                       start = None,             # <<<<<<<<<<<<<<
7009  *                       end = None,
7010  *                       region = None ):
7011  */
7012     __pyx_v_start = ((PyObject *)Py_None);
7013
7014     /* "csamtools.pyx":658
7015  *                       reference = None,
7016  *                       start = None,
7017  *                       end = None,             # <<<<<<<<<<<<<<
7018  *                       region = None ):
7019  *         '''
7020  */
7021     __pyx_v_end = ((PyObject *)Py_None);
7022
7023     /* "csamtools.pyx":659
7024  *                       start = None,
7025  *                       end = None,
7026  *                       region = None ):             # <<<<<<<<<<<<<<
7027  *         '''
7028  *         parse region information.
7029  */
7030     __pyx_v_region = ((PyObject *)Py_None);
7031     switch (PyTuple_GET_SIZE(__pyx_args)) {
7032       case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
7033       case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
7034       case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
7035       case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
7036       case  0: break;
7037       default: goto __pyx_L5_argtuple_error;
7038     }
7039   }
7040   goto __pyx_L4_argument_unpacking_done;
7041   __pyx_L5_argtuple_error:;
7042   __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 655; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7043   __pyx_L3_error:;
7044   __Pyx_AddTraceback("csamtools.Samfile._parseRegion");
7045   __Pyx_RefNannyFinishContext();
7046   return NULL;
7047   __pyx_L4_argument_unpacking_done:;
7048   __Pyx_INCREF(__pyx_v_reference);
7049   __pyx_v_parts = Py_None; __Pyx_INCREF(Py_None);
7050
7051   /* "csamtools.pyx":678
7052  *         cdef long long rend
7053  * 
7054  *         rtid = -1             # <<<<<<<<<<<<<<
7055  *         rstart = 0
7056  *         rend = max_pos
7057  */
7058   __pyx_v_rtid = -1;
7059
7060   /* "csamtools.pyx":679
7061  * 
7062  *         rtid = -1
7063  *         rstart = 0             # <<<<<<<<<<<<<<
7064  *         rend = max_pos
7065  *         if start != None:
7066  */
7067   __pyx_v_rstart = 0;
7068
7069   /* "csamtools.pyx":680
7070  *         rtid = -1
7071  *         rstart = 0
7072  *         rend = max_pos             # <<<<<<<<<<<<<<
7073  *         if start != None:
7074  *             try:
7075  */
7076   __pyx_v_rend = __pyx_v_9csamtools_max_pos;
7077
7078   /* "csamtools.pyx":681
7079  *         rstart = 0
7080  *         rend = max_pos
7081  *         if start != None:             # <<<<<<<<<<<<<<
7082  *             try:
7083  *                 rstart = start
7084  */
7085   __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7086   __Pyx_GOTREF(__pyx_t_1);
7087   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7088   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7089   if (__pyx_t_2) {
7090
7091     /* "csamtools.pyx":682
7092  *         rend = max_pos
7093  *         if start != None:
7094  *             try:             # <<<<<<<<<<<<<<
7095  *                 rstart = start
7096  *             except OverflowError:
7097  */
7098     {
7099       PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
7100       __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
7101       __Pyx_XGOTREF(__pyx_save_exc_type);
7102       __Pyx_XGOTREF(__pyx_save_exc_value);
7103       __Pyx_XGOTREF(__pyx_save_exc_tb);
7104       /*try:*/ {
7105
7106         /* "csamtools.pyx":683
7107  *         if start != None:
7108  *             try:
7109  *                 rstart = start             # <<<<<<<<<<<<<<
7110  *             except OverflowError:
7111  *                 raise ValueError( 'start out of range (%i)' % start )
7112  */
7113         __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_start); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
7114         __pyx_v_rstart = __pyx_t_3;
7115       }
7116       __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
7117       __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
7118       __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
7119       goto __pyx_L14_try_end;
7120       __pyx_L7_error:;
7121       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
7122
7123       /* "csamtools.pyx":684
7124  *             try:
7125  *                 rstart = start
7126  *             except OverflowError:             # <<<<<<<<<<<<<<
7127  *                 raise ValueError( 'start out of range (%i)' % start )
7128  * 
7129  */
7130       __pyx_t_4 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
7131       if (__pyx_t_4) {
7132         __Pyx_AddTraceback("csamtools.Samfile._parseRegion");
7133         if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_5, &__pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
7134         __Pyx_GOTREF(__pyx_t_1);
7135         __Pyx_GOTREF(__pyx_t_5);
7136         __Pyx_GOTREF(__pyx_t_6);
7137
7138         /* "csamtools.pyx":685
7139  *                 rstart = start
7140  *             except OverflowError:
7141  *                 raise ValueError( 'start out of range (%i)' % start )             # <<<<<<<<<<<<<<
7142  * 
7143  *         if end != None:
7144  */
7145         __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_v_start); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
7146         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
7147         __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
7148         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
7149         PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
7150         __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
7151         __pyx_t_7 = 0;
7152         __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 = 685; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
7153         __Pyx_GOTREF(__pyx_t_7);
7154         __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
7155         __Pyx_Raise(__pyx_t_7, 0, 0);
7156         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7157         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
7158         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7159         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7160         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7161         goto __pyx_L8_exception_handled;
7162       }
7163       __pyx_L9_except_error:;
7164       __Pyx_XGIVEREF(__pyx_save_exc_type);
7165       __Pyx_XGIVEREF(__pyx_save_exc_value);
7166       __Pyx_XGIVEREF(__pyx_save_exc_tb);
7167       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
7168       goto __pyx_L1_error;
7169       __pyx_L8_exception_handled:;
7170       __Pyx_XGIVEREF(__pyx_save_exc_type);
7171       __Pyx_XGIVEREF(__pyx_save_exc_value);
7172       __Pyx_XGIVEREF(__pyx_save_exc_tb);
7173       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
7174       __pyx_L14_try_end:;
7175     }
7176     goto __pyx_L6;
7177   }
7178   __pyx_L6:;
7179
7180   /* "csamtools.pyx":687
7181  *                 raise ValueError( 'start out of range (%i)' % start )
7182  * 
7183  *         if end != None:             # <<<<<<<<<<<<<<
7184  *             try:
7185  *                 rend = end
7186  */
7187   __pyx_t_6 = PyObject_RichCompare(__pyx_v_end, Py_None, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7188   __Pyx_GOTREF(__pyx_t_6);
7189   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7190   __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7191   if (__pyx_t_2) {
7192
7193     /* "csamtools.pyx":688
7194  * 
7195  *         if end != None:
7196  *             try:             # <<<<<<<<<<<<<<
7197  *                 rend = end
7198  *             except OverflowError:
7199  */
7200     {
7201       PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
7202       __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
7203       __Pyx_XGOTREF(__pyx_save_exc_type);
7204       __Pyx_XGOTREF(__pyx_save_exc_value);
7205       __Pyx_XGOTREF(__pyx_save_exc_tb);
7206       /*try:*/ {
7207
7208         /* "csamtools.pyx":689
7209  *         if end != None:
7210  *             try:
7211  *                 rend = end             # <<<<<<<<<<<<<<
7212  *             except OverflowError:
7213  *                 raise ValueError( 'end out of range (%i)' % end )
7214  */
7215         __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_end); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L18_error;}
7216         __pyx_v_rend = __pyx_t_3;
7217       }
7218       __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
7219       __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
7220       __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
7221       goto __pyx_L25_try_end;
7222       __pyx_L18_error:;
7223       __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
7224       __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
7225       __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
7226       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
7227       __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
7228
7229       /* "csamtools.pyx":690
7230  *             try:
7231  *                 rend = end
7232  *             except OverflowError:             # <<<<<<<<<<<<<<
7233  *                 raise ValueError( 'end out of range (%i)' % end )
7234  * 
7235  */
7236       __pyx_t_4 = PyErr_ExceptionMatches(__pyx_builtin_OverflowError);
7237       if (__pyx_t_4) {
7238         __Pyx_AddTraceback("csamtools.Samfile._parseRegion");
7239         if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L20_except_error;}
7240         __Pyx_GOTREF(__pyx_t_6);
7241         __Pyx_GOTREF(__pyx_t_5);
7242         __Pyx_GOTREF(__pyx_t_1);
7243
7244         /* "csamtools.pyx":691
7245  *                 rend = end
7246  *             except OverflowError:
7247  *                 raise ValueError( 'end out of range (%i)' % end )             # <<<<<<<<<<<<<<
7248  * 
7249  *         if region:
7250  */
7251         __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_v_end); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L20_except_error;}
7252         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
7253         __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L20_except_error;}
7254         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
7255         PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
7256         __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
7257         __pyx_t_7 = 0;
7258         __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 = 691; __pyx_clineno = __LINE__; goto __pyx_L20_except_error;}
7259         __Pyx_GOTREF(__pyx_t_7);
7260         __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
7261         __Pyx_Raise(__pyx_t_7, 0, 0);
7262         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
7263         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L20_except_error;}
7264         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7265         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7266         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7267         goto __pyx_L19_exception_handled;
7268       }
7269       __pyx_L20_except_error:;
7270       __Pyx_XGIVEREF(__pyx_save_exc_type);
7271       __Pyx_XGIVEREF(__pyx_save_exc_value);
7272       __Pyx_XGIVEREF(__pyx_save_exc_tb);
7273       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
7274       goto __pyx_L1_error;
7275       __pyx_L19_exception_handled:;
7276       __Pyx_XGIVEREF(__pyx_save_exc_type);
7277       __Pyx_XGIVEREF(__pyx_save_exc_value);
7278       __Pyx_XGIVEREF(__pyx_save_exc_tb);
7279       __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
7280       __pyx_L25_try_end:;
7281     }
7282     goto __pyx_L17;
7283   }
7284   __pyx_L17:;
7285
7286   /* "csamtools.pyx":693
7287  *                 raise ValueError( 'end out of range (%i)' % end )
7288  * 
7289  *         if region:             # <<<<<<<<<<<<<<
7290  *             parts = re.split( "[:-]", region )
7291  *             reference = parts[0]
7292  */
7293   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7294   if (__pyx_t_2) {
7295
7296     /* "csamtools.pyx":694
7297  * 
7298  *         if region:
7299  *             parts = re.split( "[:-]", region )             # <<<<<<<<<<<<<<
7300  *             reference = parts[0]
7301  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
7302  */
7303     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7304     __Pyx_GOTREF(__pyx_t_1);
7305     __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7306     __Pyx_GOTREF(__pyx_t_5);
7307     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7308     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7309     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7310     __Pyx_INCREF(((PyObject *)__pyx_kp_s_33));
7311     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_33));
7312     __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_33));
7313     __Pyx_INCREF(__pyx_v_region);
7314     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_region);
7315     __Pyx_GIVEREF(__pyx_v_region);
7316     __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7317     __Pyx_GOTREF(__pyx_t_6);
7318     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7319     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
7320     __Pyx_DECREF(__pyx_v_parts);
7321     __pyx_v_parts = __pyx_t_6;
7322     __pyx_t_6 = 0;
7323
7324     /* "csamtools.pyx":695
7325  *         if region:
7326  *             parts = re.split( "[:-]", region )
7327  *             reference = parts[0]             # <<<<<<<<<<<<<<
7328  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
7329  *             if len(parts) >= 3: rend = int(parts[2])
7330  */
7331     __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_parts, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7332     __Pyx_GOTREF(__pyx_t_6);
7333     __Pyx_DECREF(__pyx_v_reference);
7334     __pyx_v_reference = __pyx_t_6;
7335     __pyx_t_6 = 0;
7336
7337     /* "csamtools.pyx":696
7338  *             parts = re.split( "[:-]", region )
7339  *             reference = parts[0]
7340  *             if len(parts) >= 2: rstart = int(parts[1]) - 1             # <<<<<<<<<<<<<<
7341  *             if len(parts) >= 3: rend = int(parts[2])
7342  * 
7343  */
7344     __pyx_t_9 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7345     __pyx_t_2 = (__pyx_t_9 >= 2);
7346     if (__pyx_t_2) {
7347       __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_parts, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7348       __Pyx_GOTREF(__pyx_t_6);
7349       __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7350       __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7351       PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
7352       __Pyx_GIVEREF(__pyx_t_6);
7353       __pyx_t_6 = 0;
7354       __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7355       __Pyx_GOTREF(__pyx_t_6);
7356       __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
7357       __pyx_t_1 = PyNumber_Subtract(__pyx_t_6, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7358       __Pyx_GOTREF(__pyx_t_1);
7359       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7360       __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7361       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7362       __pyx_v_rstart = __pyx_t_3;
7363       goto __pyx_L29;
7364     }
7365     __pyx_L29:;
7366
7367     /* "csamtools.pyx":697
7368  *             reference = parts[0]
7369  *             if len(parts) >= 2: rstart = int(parts[1]) - 1
7370  *             if len(parts) >= 3: rend = int(parts[2])             # <<<<<<<<<<<<<<
7371  * 
7372  *         if not reference: return 0, 0, 0, 0
7373  */
7374     __pyx_t_9 = PyObject_Length(__pyx_v_parts); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7375     __pyx_t_2 = (__pyx_t_9 >= 3);
7376     if (__pyx_t_2) {
7377       __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_parts, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7378       __Pyx_GOTREF(__pyx_t_1);
7379       __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7380       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7381       PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
7382       __Pyx_GIVEREF(__pyx_t_1);
7383       __pyx_t_1 = 0;
7384       __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7385       __Pyx_GOTREF(__pyx_t_1);
7386       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
7387       __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_t_1); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7388       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7389       __pyx_v_rend = __pyx_t_3;
7390       goto __pyx_L30;
7391     }
7392     __pyx_L30:;
7393     goto __pyx_L28;
7394   }
7395   __pyx_L28:;
7396
7397   /* "csamtools.pyx":699
7398  *             if len(parts) >= 3: rend = int(parts[2])
7399  * 
7400  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
7401  * 
7402  *         rtid = self.gettid( reference )
7403  */
7404   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7405   __pyx_t_10 = (!__pyx_t_2);
7406   if (__pyx_t_10) {
7407     __Pyx_XDECREF(__pyx_r);
7408     __Pyx_INCREF(((PyObject *)__pyx_k_tuple_34));
7409     __pyx_r = ((PyObject *)__pyx_k_tuple_34);
7410     goto __pyx_L0;
7411     goto __pyx_L31;
7412   }
7413   __pyx_L31:;
7414
7415   /* "csamtools.pyx":701
7416  *         if not reference: return 0, 0, 0, 0
7417  * 
7418  *         rtid = self.gettid( reference )             # <<<<<<<<<<<<<<
7419  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
7420  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
7421  */
7422   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__gettid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7423   __Pyx_GOTREF(__pyx_t_1);
7424   __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7425   __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7426   __Pyx_INCREF(__pyx_v_reference);
7427   PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_reference);
7428   __Pyx_GIVEREF(__pyx_v_reference);
7429   __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7430   __Pyx_GOTREF(__pyx_t_5);
7431   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7432   __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
7433   __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7434   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7435   __pyx_v_rtid = __pyx_t_4;
7436
7437   /* "csamtools.pyx":702
7438  * 
7439  *         rtid = self.gettid( reference )
7440  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )             # <<<<<<<<<<<<<<
7441  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
7442  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
7443  */
7444   __pyx_t_10 = (__pyx_v_rtid < 0);
7445   if (__pyx_t_10) {
7446     __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_35), __pyx_v_reference); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7447     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
7448     __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7449     __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7450     PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
7451     __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
7452     __pyx_t_5 = 0;
7453     __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 = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7454     __Pyx_GOTREF(__pyx_t_5);
7455     __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
7456     __Pyx_Raise(__pyx_t_5, 0, 0);
7457     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
7458     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7459     goto __pyx_L32;
7460   }
7461   __pyx_L32:;
7462
7463   /* "csamtools.pyx":703
7464  *         rtid = self.gettid( reference )
7465  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
7466  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )             # <<<<<<<<<<<<<<
7467  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
7468  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
7469  */
7470   __pyx_t_10 = (__pyx_v_rstart > __pyx_v_rend);
7471   if (__pyx_t_10) {
7472     __pyx_t_5 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7473     __Pyx_GOTREF(__pyx_t_5);
7474     __pyx_t_6 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7475     __Pyx_GOTREF(__pyx_t_6);
7476     __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7477     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7478     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
7479     __Pyx_GIVEREF(__pyx_t_5);
7480     PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
7481     __Pyx_GIVEREF(__pyx_t_6);
7482     __pyx_t_5 = 0;
7483     __pyx_t_6 = 0;
7484     __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_36), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7485     __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7486     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
7487     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7488     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7489     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_6));
7490     __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
7491     __pyx_t_6 = 0;
7492     __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 = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7493     __Pyx_GOTREF(__pyx_t_6);
7494     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
7495     __Pyx_Raise(__pyx_t_6, 0, 0);
7496     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7497     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 703; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7498     goto __pyx_L33;
7499   }
7500   __pyx_L33:;
7501
7502   /* "csamtools.pyx":704
7503  *         if rtid < 0: raise ValueError( "invalid reference `%s`" % reference )
7504  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
7505  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )             # <<<<<<<<<<<<<<
7506  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
7507  * 
7508  */
7509   __pyx_t_10 = (0 <= __pyx_v_rstart);
7510   if (__pyx_t_10) {
7511     __pyx_t_10 = (__pyx_v_rstart < __pyx_v_9csamtools_max_pos);
7512   }
7513   __pyx_t_2 = (!__pyx_t_10);
7514   if (__pyx_t_2) {
7515     __pyx_t_6 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7516     __Pyx_GOTREF(__pyx_t_6);
7517     __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7518     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7519     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7520     __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7521     __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7522     PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1));
7523     __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
7524     __pyx_t_1 = 0;
7525     __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 = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7526     __Pyx_GOTREF(__pyx_t_1);
7527     __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
7528     __Pyx_Raise(__pyx_t_1, 0, 0);
7529     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7530     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7531     goto __pyx_L34;
7532   }
7533   __pyx_L34:;
7534
7535   /* "csamtools.pyx":705
7536  *         if rstart > rend: raise ValueError( 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend) )
7537  *         if not 0 <= rstart < max_pos: raise ValueError( 'start out of range (%i)' % rstart )
7538  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )             # <<<<<<<<<<<<<<
7539  * 
7540  *         return 1, rtid, rstart, rend
7541  */
7542   __pyx_t_2 = (0 <= __pyx_v_rend);
7543   if (__pyx_t_2) {
7544     __pyx_t_2 = (__pyx_v_rend <= __pyx_v_9csamtools_max_pos);
7545   }
7546   __pyx_t_10 = (!__pyx_t_2);
7547   if (__pyx_t_10) {
7548     __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7549     __Pyx_GOTREF(__pyx_t_1);
7550     __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_14), __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7551     __Pyx_GOTREF(((PyObject *)__pyx_t_6));
7552     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7553     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7554     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
7555     PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_6));
7556     __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
7557     __pyx_t_6 = 0;
7558     __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 = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7559     __Pyx_GOTREF(__pyx_t_6);
7560     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
7561     __Pyx_Raise(__pyx_t_6, 0, 0);
7562     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
7563     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7564     goto __pyx_L35;
7565   }
7566   __pyx_L35:;
7567
7568   /* "csamtools.pyx":707
7569  *         if not 0 <= rend <= max_pos: raise ValueError( 'end out of range (%i)' % rend )
7570  * 
7571  *         return 1, rtid, rstart, rend             # <<<<<<<<<<<<<<
7572  * 
7573  *     def reset( self ):
7574  */
7575   __Pyx_XDECREF(__pyx_r);
7576   __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7577   __Pyx_GOTREF(__pyx_t_6);
7578   __pyx_t_1 = PyLong_FromLongLong(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7579   __Pyx_GOTREF(__pyx_t_1);
7580   __pyx_t_5 = PyLong_FromLongLong(__pyx_v_rend); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7581   __Pyx_GOTREF(__pyx_t_5);
7582   __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 707; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7583   __Pyx_GOTREF(((PyObject *)__pyx_t_7));
7584   __Pyx_INCREF(__pyx_int_1);
7585   PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_int_1);
7586   __Pyx_GIVEREF(__pyx_int_1);
7587   PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
7588   __Pyx_GIVEREF(__pyx_t_6);
7589   PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_1);
7590   __Pyx_GIVEREF(__pyx_t_1);
7591   PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_5);
7592   __Pyx_GIVEREF(__pyx_t_5);
7593   __pyx_t_6 = 0;
7594   __pyx_t_1 = 0;
7595   __pyx_t_5 = 0;
7596   __pyx_r = ((PyObject *)__pyx_t_7);
7597   __pyx_t_7 = 0;
7598   goto __pyx_L0;
7599
7600   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
7601   goto __pyx_L0;
7602   __pyx_L1_error:;
7603   __Pyx_XDECREF(__pyx_t_1);
7604   __Pyx_XDECREF(__pyx_t_5);
7605   __Pyx_XDECREF(__pyx_t_6);
7606   __Pyx_XDECREF(__pyx_t_7);
7607   __Pyx_XDECREF(__pyx_t_8);
7608   __Pyx_AddTraceback("csamtools.Samfile._parseRegion");
7609   __pyx_r = NULL;
7610   __pyx_L0:;
7611   __Pyx_DECREF(__pyx_v_parts);
7612   __Pyx_DECREF(__pyx_v_reference);
7613   __Pyx_XGIVEREF(__pyx_r);
7614   __Pyx_TraceReturn(__pyx_r);
7615   __Pyx_RefNannyFinishContext();
7616   return __pyx_r;
7617 }
7618
7619 /* "csamtools.pyx":709
7620  *         return 1, rtid, rstart, rend
7621  * 
7622  *     def reset( self ):             # <<<<<<<<<<<<<<
7623  *         '''reset file position to beginning of read section.'''
7624  *         return self.seek( self.start_offset, 0 )
7625  */
7626
7627 static PyObject *__pyx_pf_9csamtools_7Samfile_7reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
7628 static char __pyx_doc_9csamtools_7Samfile_7reset[] = "Samfile.reset(self)\nreset file position to beginning of read section.";
7629 static PyObject *__pyx_pf_9csamtools_7Samfile_7reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
7630   PyObject *__pyx_r = NULL;
7631   PyObject *__pyx_t_1 = NULL;
7632   PyObject *__pyx_t_2 = NULL;
7633   PyObject *__pyx_t_3 = NULL;
7634   __Pyx_TraceDeclarations
7635   __Pyx_RefNannySetupContext("reset");
7636   __Pyx_TraceCall("reset", __pyx_f[0], 709);
7637
7638   /* "csamtools.pyx":711
7639  *     def reset( self ):
7640  *         '''reset file position to beginning of read section.'''
7641  *         return self.seek( self.start_offset, 0 )             # <<<<<<<<<<<<<<
7642  * 
7643  *     def seek( self, uint64_t offset, int where = 0):
7644  */
7645   __Pyx_XDECREF(__pyx_r);
7646   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__seek); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7647   __Pyx_GOTREF(__pyx_t_1);
7648   __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->start_offset); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7649   __Pyx_GOTREF(__pyx_t_2);
7650   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7651   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
7652   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
7653   __Pyx_GIVEREF(__pyx_t_2);
7654   __Pyx_INCREF(__pyx_int_0);
7655   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
7656   __Pyx_GIVEREF(__pyx_int_0);
7657   __pyx_t_2 = 0;
7658   __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 = 711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7659   __Pyx_GOTREF(__pyx_t_2);
7660   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7661   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
7662   __pyx_r = __pyx_t_2;
7663   __pyx_t_2 = 0;
7664   goto __pyx_L0;
7665
7666   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
7667   goto __pyx_L0;
7668   __pyx_L1_error:;
7669   __Pyx_XDECREF(__pyx_t_1);
7670   __Pyx_XDECREF(__pyx_t_2);
7671   __Pyx_XDECREF(__pyx_t_3);
7672   __Pyx_AddTraceback("csamtools.Samfile.reset");
7673   __pyx_r = NULL;
7674   __pyx_L0:;
7675   __Pyx_XGIVEREF(__pyx_r);
7676   __Pyx_TraceReturn(__pyx_r);
7677   __Pyx_RefNannyFinishContext();
7678   return __pyx_r;
7679 }
7680
7681 /* "csamtools.pyx":713
7682  *         return self.seek( self.start_offset, 0 )
7683  * 
7684  *     def seek( self, uint64_t offset, int where = 0):             # <<<<<<<<<<<<<<
7685  *         '''
7686  *         move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.
7687  */
7688
7689 static PyObject *__pyx_pf_9csamtools_7Samfile_8seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
7690 static char __pyx_doc_9csamtools_7Samfile_8seek[] = "Samfile.seek(self, uint64_t offset, int where=0)\n\n        move file pointer to position *offset*, see :meth:`pysam.Samfile.tell`.\n        ";
7691 static PyObject *__pyx_pf_9csamtools_7Samfile_8seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
7692   uint64_t __pyx_v_offset;
7693   int __pyx_v_where;
7694   PyObject *__pyx_r = NULL;
7695   PyObject *__pyx_t_1 = NULL;
7696   PyObject *__pyx_t_2 = NULL;
7697   int __pyx_t_3;
7698   int __pyx_t_4;
7699   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__offset,&__pyx_n_s__where,0};
7700   __Pyx_TraceDeclarations
7701   __Pyx_RefNannySetupContext("seek");
7702   __Pyx_TraceCall("seek", __pyx_f[0], 713);
7703   if (unlikely(__pyx_kwds)) {
7704     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
7705     PyObject* values[2] = {0,0};
7706     switch (PyTuple_GET_SIZE(__pyx_args)) {
7707       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
7708       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
7709       case  0: break;
7710       default: goto __pyx_L5_argtuple_error;
7711     }
7712     switch (PyTuple_GET_SIZE(__pyx_args)) {
7713       case  0:
7714       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset);
7715       if (likely(values[0])) kw_args--;
7716       else goto __pyx_L5_argtuple_error;
7717       case  1:
7718       if (kw_args > 0) {
7719         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__where);
7720         if (value) { values[1] = value; kw_args--; }
7721       }
7722     }
7723     if (unlikely(kw_args > 0)) {
7724       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7725     }
7726     __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 = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7727     if (values[1]) {
7728       __pyx_v_where = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7729     } else {
7730       __pyx_v_where = ((int)0);
7731     }
7732   } else {
7733     __pyx_v_where = ((int)0);
7734     switch (PyTuple_GET_SIZE(__pyx_args)) {
7735       case  2: __pyx_v_where = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7736       case  1: __pyx_v_offset = __Pyx_PyInt_from_py_uint64_t(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7737       break;
7738       default: goto __pyx_L5_argtuple_error;
7739     }
7740   }
7741   goto __pyx_L4_argument_unpacking_done;
7742   __pyx_L5_argtuple_error:;
7743   __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 713; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
7744   __pyx_L3_error:;
7745   __Pyx_AddTraceback("csamtools.Samfile.seek");
7746   __Pyx_RefNannyFinishContext();
7747   return NULL;
7748   __pyx_L4_argument_unpacking_done:;
7749
7750   /* "csamtools.pyx":718
7751  *         '''
7752  * 
7753  *         if not self._isOpen():             # <<<<<<<<<<<<<<
7754  *             raise ValueError( "I/O operation on closed file" )
7755  *         if not self.isbam:
7756  */
7757   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7758   __Pyx_GOTREF(__pyx_t_1);
7759   __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 = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7760   __Pyx_GOTREF(__pyx_t_2);
7761   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7762   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7763   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7764   __pyx_t_4 = (!__pyx_t_3);
7765   if (__pyx_t_4) {
7766
7767     /* "csamtools.pyx":719
7768  * 
7769  *         if not self._isOpen():
7770  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
7771  *         if not self.isbam:
7772  *             raise NotImplementedError("seek only available in bam files")
7773  */
7774     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_37), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7775     __Pyx_GOTREF(__pyx_t_2);
7776     __Pyx_Raise(__pyx_t_2, 0, 0);
7777     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7778     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7779     goto __pyx_L6;
7780   }
7781   __pyx_L6:;
7782
7783   /* "csamtools.pyx":720
7784  *         if not self._isOpen():
7785  *             raise ValueError( "I/O operation on closed file" )
7786  *         if not self.isbam:             # <<<<<<<<<<<<<<
7787  *             raise NotImplementedError("seek only available in bam files")
7788  *         if self.isstream:
7789  */
7790   __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam);
7791   if (__pyx_t_4) {
7792
7793     /* "csamtools.pyx":721
7794  *             raise ValueError( "I/O operation on closed file" )
7795  *         if not self.isbam:
7796  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
7797  *         if self.isstream:
7798  *             raise OSError("seek no available in streams")
7799  */
7800     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7801     __Pyx_GOTREF(__pyx_t_2);
7802     __Pyx_Raise(__pyx_t_2, 0, 0);
7803     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7804     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7805     goto __pyx_L7;
7806   }
7807   __pyx_L7:;
7808
7809   /* "csamtools.pyx":722
7810  *         if not self.isbam:
7811  *             raise NotImplementedError("seek only available in bam files")
7812  *         if self.isstream:             # <<<<<<<<<<<<<<
7813  *             raise OSError("seek no available in streams")
7814  * 
7815  */
7816   if (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isstream) {
7817
7818     /* "csamtools.pyx":723
7819  *             raise NotImplementedError("seek only available in bam files")
7820  *         if self.isstream:
7821  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
7822  * 
7823  *         return bam_seek( self.samfile.x.bam, offset, where )
7824  */
7825     __pyx_t_2 = PyObject_Call(__pyx_builtin_OSError, ((PyObject *)__pyx_k_tuple_41), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7826     __Pyx_GOTREF(__pyx_t_2);
7827     __Pyx_Raise(__pyx_t_2, 0, 0);
7828     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7829     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7830     goto __pyx_L8;
7831   }
7832   __pyx_L8:;
7833
7834   /* "csamtools.pyx":725
7835  *             raise OSError("seek no available in streams")
7836  * 
7837  *         return bam_seek( self.samfile.x.bam, offset, where )             # <<<<<<<<<<<<<<
7838  * 
7839  *     def tell( self ):
7840  */
7841   __Pyx_XDECREF(__pyx_r);
7842   __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_seek(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, __pyx_v_offset, __pyx_v_where)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7843   __Pyx_GOTREF(__pyx_t_2);
7844   __pyx_r = __pyx_t_2;
7845   __pyx_t_2 = 0;
7846   goto __pyx_L0;
7847
7848   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
7849   goto __pyx_L0;
7850   __pyx_L1_error:;
7851   __Pyx_XDECREF(__pyx_t_1);
7852   __Pyx_XDECREF(__pyx_t_2);
7853   __Pyx_AddTraceback("csamtools.Samfile.seek");
7854   __pyx_r = NULL;
7855   __pyx_L0:;
7856   __Pyx_XGIVEREF(__pyx_r);
7857   __Pyx_TraceReturn(__pyx_r);
7858   __Pyx_RefNannyFinishContext();
7859   return __pyx_r;
7860 }
7861
7862 /* "csamtools.pyx":727
7863  *         return bam_seek( self.samfile.x.bam, offset, where )
7864  * 
7865  *     def tell( self ):             # <<<<<<<<<<<<<<
7866  *         '''
7867  *         return current file position
7868  */
7869
7870 static PyObject *__pyx_pf_9csamtools_7Samfile_9tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
7871 static char __pyx_doc_9csamtools_7Samfile_9tell[] = "Samfile.tell(self)\n\n        return current file position\n        ";
7872 static PyObject *__pyx_pf_9csamtools_7Samfile_9tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
7873   PyObject *__pyx_r = NULL;
7874   PyObject *__pyx_t_1 = NULL;
7875   PyObject *__pyx_t_2 = NULL;
7876   int __pyx_t_3;
7877   int __pyx_t_4;
7878   __Pyx_TraceDeclarations
7879   __Pyx_RefNannySetupContext("tell");
7880   __Pyx_TraceCall("tell", __pyx_f[0], 727);
7881
7882   /* "csamtools.pyx":731
7883  *         return current file position
7884  *         '''
7885  *         if not self._isOpen():             # <<<<<<<<<<<<<<
7886  *             raise ValueError( "I/O operation on closed file" )
7887  *         if not self.isbam:
7888  */
7889   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7890   __Pyx_GOTREF(__pyx_t_1);
7891   __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 = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7892   __Pyx_GOTREF(__pyx_t_2);
7893   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
7894   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7895   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7896   __pyx_t_4 = (!__pyx_t_3);
7897   if (__pyx_t_4) {
7898
7899     /* "csamtools.pyx":732
7900  *         '''
7901  *         if not self._isOpen():
7902  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
7903  *         if not self.isbam:
7904  *             raise NotImplementedError("seek only available in bam files")
7905  */
7906     __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 = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7907     __Pyx_GOTREF(__pyx_t_2);
7908     __Pyx_Raise(__pyx_t_2, 0, 0);
7909     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7910     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7911     goto __pyx_L5;
7912   }
7913   __pyx_L5:;
7914
7915   /* "csamtools.pyx":733
7916  *         if not self._isOpen():
7917  *             raise ValueError( "I/O operation on closed file" )
7918  *         if not self.isbam:             # <<<<<<<<<<<<<<
7919  *             raise NotImplementedError("seek only available in bam files")
7920  * 
7921  */
7922   __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam);
7923   if (__pyx_t_4) {
7924
7925     /* "csamtools.pyx":734
7926  *             raise ValueError( "I/O operation on closed file" )
7927  *         if not self.isbam:
7928  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
7929  * 
7930  *         return bam_tell( self.samfile.x.bam )
7931  */
7932     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_43), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7933     __Pyx_GOTREF(__pyx_t_2);
7934     __Pyx_Raise(__pyx_t_2, 0, 0);
7935     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
7936     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7937     goto __pyx_L6;
7938   }
7939   __pyx_L6:;
7940
7941   /* "csamtools.pyx":736
7942  *             raise NotImplementedError("seek only available in bam files")
7943  * 
7944  *         return bam_tell( self.samfile.x.bam )             # <<<<<<<<<<<<<<
7945  * 
7946  *     def fetch( self,
7947  */
7948   __Pyx_XDECREF(__pyx_r);
7949   __pyx_t_2 = __Pyx_PyInt_to_py_int64_t(bam_tell(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
7950   __Pyx_GOTREF(__pyx_t_2);
7951   __pyx_r = __pyx_t_2;
7952   __pyx_t_2 = 0;
7953   goto __pyx_L0;
7954
7955   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
7956   goto __pyx_L0;
7957   __pyx_L1_error:;
7958   __Pyx_XDECREF(__pyx_t_1);
7959   __Pyx_XDECREF(__pyx_t_2);
7960   __Pyx_AddTraceback("csamtools.Samfile.tell");
7961   __pyx_r = NULL;
7962   __pyx_L0:;
7963   __Pyx_XGIVEREF(__pyx_r);
7964   __Pyx_TraceReturn(__pyx_r);
7965   __Pyx_RefNannyFinishContext();
7966   return __pyx_r;
7967 }
7968
7969 /* "csamtools.pyx":738
7970  *         return bam_tell( self.samfile.x.bam )
7971  * 
7972  *     def fetch( self,             # <<<<<<<<<<<<<<
7973  *                reference = None,
7974  *                start = None,
7975  */
7976
7977 static PyObject *__pyx_pf_9csamtools_7Samfile_10fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
7978 static char __pyx_doc_9csamtools_7Samfile_10fetch[] = "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        ";
7979 static PyObject *__pyx_pf_9csamtools_7Samfile_10fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
7980   PyObject *__pyx_v_reference = 0;
7981   PyObject *__pyx_v_start = 0;
7982   PyObject *__pyx_v_end = 0;
7983   PyObject *__pyx_v_region = 0;
7984   PyObject *__pyx_v_callback = 0;
7985   PyObject *__pyx_v_until_eof = 0;
7986   int __pyx_v_rtid;
7987   int __pyx_v_rstart;
7988   int __pyx_v_rend;
7989   int __pyx_v_has_coord;
7990   int __pyx_v_reopen;
7991   PyObject *__pyx_r = NULL;
7992   PyObject *__pyx_t_1 = NULL;
7993   PyObject *__pyx_t_2 = NULL;
7994   int __pyx_t_3;
7995   int __pyx_t_4;
7996   PyObject *__pyx_t_5 = NULL;
7997   PyObject *__pyx_t_6 = NULL;
7998   PyObject *__pyx_t_7 = NULL;
7999   int __pyx_t_8;
8000   int __pyx_t_9;
8001   int __pyx_t_10;
8002   int __pyx_t_11;
8003   PyObject *__pyx_t_12 = NULL;
8004   int __pyx_t_13;
8005   int __pyx_t_14;
8006   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};
8007   __Pyx_TraceDeclarations
8008   __Pyx_RefNannySetupContext("fetch");
8009   __Pyx_TraceCall("fetch", __pyx_f[0], 738);
8010   if (unlikely(__pyx_kwds)) {
8011     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
8012     PyObject* values[6] = {0,0,0,0,0,0};
8013
8014     /* "csamtools.pyx":739
8015  * 
8016  *     def fetch( self,
8017  *                reference = None,             # <<<<<<<<<<<<<<
8018  *                start = None,
8019  *                end = None,
8020  */
8021     values[0] = ((PyObject *)Py_None);
8022
8023     /* "csamtools.pyx":740
8024  *     def fetch( self,
8025  *                reference = None,
8026  *                start = None,             # <<<<<<<<<<<<<<
8027  *                end = None,
8028  *                region = None,
8029  */
8030     values[1] = ((PyObject *)Py_None);
8031
8032     /* "csamtools.pyx":741
8033  *                reference = None,
8034  *                start = None,
8035  *                end = None,             # <<<<<<<<<<<<<<
8036  *                region = None,
8037  *                callback = None,
8038  */
8039     values[2] = ((PyObject *)Py_None);
8040
8041     /* "csamtools.pyx":742
8042  *                start = None,
8043  *                end = None,
8044  *                region = None,             # <<<<<<<<<<<<<<
8045  *                callback = None,
8046  *                until_eof = False ):
8047  */
8048     values[3] = ((PyObject *)Py_None);
8049
8050     /* "csamtools.pyx":743
8051  *                end = None,
8052  *                region = None,
8053  *                callback = None,             # <<<<<<<<<<<<<<
8054  *                until_eof = False ):
8055  *         '''
8056  */
8057     values[4] = ((PyObject *)Py_None);
8058     values[5] = __pyx_k_44;
8059     switch (PyTuple_GET_SIZE(__pyx_args)) {
8060       case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
8061       case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
8062       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
8063       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
8064       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
8065       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
8066       case  0: break;
8067       default: goto __pyx_L5_argtuple_error;
8068     }
8069     switch (PyTuple_GET_SIZE(__pyx_args)) {
8070       case  0:
8071       if (kw_args > 0) {
8072         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
8073         if (value) { values[0] = value; kw_args--; }
8074       }
8075       case  1:
8076       if (kw_args > 0) {
8077         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
8078         if (value) { values[1] = value; kw_args--; }
8079       }
8080       case  2:
8081       if (kw_args > 0) {
8082         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
8083         if (value) { values[2] = value; kw_args--; }
8084       }
8085       case  3:
8086       if (kw_args > 0) {
8087         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
8088         if (value) { values[3] = value; kw_args--; }
8089       }
8090       case  4:
8091       if (kw_args > 0) {
8092         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
8093         if (value) { values[4] = value; kw_args--; }
8094       }
8095       case  5:
8096       if (kw_args > 0) {
8097         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__until_eof);
8098         if (value) { values[5] = value; kw_args--; }
8099       }
8100     }
8101     if (unlikely(kw_args > 0)) {
8102       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
8103     }
8104     __pyx_v_reference = values[0];
8105     __pyx_v_start = values[1];
8106     __pyx_v_end = values[2];
8107     __pyx_v_region = values[3];
8108     __pyx_v_callback = values[4];
8109     __pyx_v_until_eof = values[5];
8110   } else {
8111
8112     /* "csamtools.pyx":739
8113  * 
8114  *     def fetch( self,
8115  *                reference = None,             # <<<<<<<<<<<<<<
8116  *                start = None,
8117  *                end = None,
8118  */
8119     __pyx_v_reference = ((PyObject *)Py_None);
8120
8121     /* "csamtools.pyx":740
8122  *     def fetch( self,
8123  *                reference = None,
8124  *                start = None,             # <<<<<<<<<<<<<<
8125  *                end = None,
8126  *                region = None,
8127  */
8128     __pyx_v_start = ((PyObject *)Py_None);
8129
8130     /* "csamtools.pyx":741
8131  *                reference = None,
8132  *                start = None,
8133  *                end = None,             # <<<<<<<<<<<<<<
8134  *                region = None,
8135  *                callback = None,
8136  */
8137     __pyx_v_end = ((PyObject *)Py_None);
8138
8139     /* "csamtools.pyx":742
8140  *                start = None,
8141  *                end = None,
8142  *                region = None,             # <<<<<<<<<<<<<<
8143  *                callback = None,
8144  *                until_eof = False ):
8145  */
8146     __pyx_v_region = ((PyObject *)Py_None);
8147
8148     /* "csamtools.pyx":743
8149  *                end = None,
8150  *                region = None,
8151  *                callback = None,             # <<<<<<<<<<<<<<
8152  *                until_eof = False ):
8153  *         '''
8154  */
8155     __pyx_v_callback = ((PyObject *)Py_None);
8156     __pyx_v_until_eof = __pyx_k_44;
8157     switch (PyTuple_GET_SIZE(__pyx_args)) {
8158       case  6: __pyx_v_until_eof = PyTuple_GET_ITEM(__pyx_args, 5);
8159       case  5: __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 4);
8160       case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
8161       case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
8162       case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
8163       case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
8164       case  0: break;
8165       default: goto __pyx_L5_argtuple_error;
8166     }
8167   }
8168   goto __pyx_L4_argument_unpacking_done;
8169   __pyx_L5_argtuple_error:;
8170   __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
8171   __pyx_L3_error:;
8172   __Pyx_AddTraceback("csamtools.Samfile.fetch");
8173   __Pyx_RefNannyFinishContext();
8174   return NULL;
8175   __pyx_L4_argument_unpacking_done:;
8176
8177   /* "csamtools.pyx":768
8178  *         cdef int rtid, rstart, rend, has_coord
8179  * 
8180  *         if not self._isOpen():             # <<<<<<<<<<<<<<
8181  *             raise ValueError( "I/O operation on closed file" )
8182  * 
8183  */
8184   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8185   __Pyx_GOTREF(__pyx_t_1);
8186   __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 = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8187   __Pyx_GOTREF(__pyx_t_2);
8188   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8189   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8190   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8191   __pyx_t_4 = (!__pyx_t_3);
8192   if (__pyx_t_4) {
8193
8194     /* "csamtools.pyx":769
8195  * 
8196  *         if not self._isOpen():
8197  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
8198  * 
8199  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
8200  */
8201     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8202     __Pyx_GOTREF(__pyx_t_2);
8203     __Pyx_Raise(__pyx_t_2, 0, 0);
8204     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8205     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8206     goto __pyx_L6;
8207   }
8208   __pyx_L6:;
8209
8210   /* "csamtools.pyx":771
8211  *             raise ValueError( "I/O operation on closed file" )
8212  * 
8213  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
8214  * 
8215  *         if self.isstream: reopen = False
8216  */
8217   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8218   __Pyx_GOTREF(__pyx_t_2);
8219   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8220   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
8221   __Pyx_INCREF(__pyx_v_reference);
8222   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
8223   __Pyx_GIVEREF(__pyx_v_reference);
8224   __Pyx_INCREF(__pyx_v_start);
8225   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
8226   __Pyx_GIVEREF(__pyx_v_start);
8227   __Pyx_INCREF(__pyx_v_end);
8228   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
8229   __Pyx_GIVEREF(__pyx_v_end);
8230   __Pyx_INCREF(__pyx_v_region);
8231   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
8232   __Pyx_GIVEREF(__pyx_v_region);
8233   __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 = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8234   __Pyx_GOTREF(__pyx_t_5);
8235   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8236   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
8237   if (PyTuple_CheckExact(__pyx_t_5) && likely(PyTuple_GET_SIZE(__pyx_t_5) == 4)) {
8238     PyObject* tuple = __pyx_t_5;
8239     __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
8240     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8241     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8242     __pyx_t_2 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_2);
8243     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8244     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8245     __pyx_t_6 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_6);
8246     __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8247     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
8248     __pyx_t_7 = PyTuple_GET_ITEM(tuple, 3); __Pyx_INCREF(__pyx_t_7);
8249     __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8250     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8251     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
8252     __pyx_v_has_coord = __pyx_t_8;
8253     __pyx_v_rtid = __pyx_t_9;
8254     __pyx_v_rstart = __pyx_t_10;
8255     __pyx_v_rend = __pyx_t_11;
8256   } else {
8257     __pyx_t_12 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8258     __Pyx_GOTREF(__pyx_t_12);
8259     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
8260     __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_12, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8261     __Pyx_GOTREF(__pyx_t_1);
8262     __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8263     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
8264     __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_12, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8265     __Pyx_GOTREF(__pyx_t_2);
8266     __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 = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8267     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8268     __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_12, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8269     __Pyx_GOTREF(__pyx_t_6);
8270     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8271     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
8272     __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_12, 3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8273     __Pyx_GOTREF(__pyx_t_7);
8274     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8275     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8276     if (__Pyx_EndUnpack(__pyx_t_12, 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8277     __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
8278     __pyx_v_has_coord = __pyx_t_11;
8279     __pyx_v_rtid = __pyx_t_10;
8280     __pyx_v_rstart = __pyx_t_9;
8281     __pyx_v_rend = __pyx_t_8;
8282   }
8283
8284   /* "csamtools.pyx":773
8285  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
8286  * 
8287  *         if self.isstream: reopen = False             # <<<<<<<<<<<<<<
8288  *         else: reopen = True
8289  * 
8290  */
8291   if (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isstream) {
8292     __pyx_v_reopen = 0;
8293     goto __pyx_L7;
8294   }
8295   /*else*/ {
8296
8297     /* "csamtools.pyx":774
8298  * 
8299  *         if self.isstream: reopen = False
8300  *         else: reopen = True             # <<<<<<<<<<<<<<
8301  * 
8302  *         if self.isbam:
8303  */
8304     __pyx_v_reopen = 1;
8305   }
8306   __pyx_L7:;
8307
8308   /* "csamtools.pyx":776
8309  *         else: reopen = True
8310  * 
8311  *         if self.isbam:             # <<<<<<<<<<<<<<
8312  *             if not until_eof and not self._hasIndex() and not self.isremote:
8313  *                 raise ValueError( "fetch called on bamfile without index" )
8314  */
8315   if (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam) {
8316
8317     /* "csamtools.pyx":777
8318  * 
8319  *         if self.isbam:
8320  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
8321  *                 raise ValueError( "fetch called on bamfile without index" )
8322  * 
8323  */
8324     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8325     __pyx_t_3 = (!__pyx_t_4);
8326     if (__pyx_t_3) {
8327       __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8328       __Pyx_GOTREF(__pyx_t_5);
8329       __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 = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8330       __Pyx_GOTREF(__pyx_t_7);
8331       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
8332       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8333       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8334       __pyx_t_13 = (!__pyx_t_4);
8335       if (__pyx_t_13) {
8336         __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isremote);
8337         __pyx_t_14 = __pyx_t_4;
8338       } else {
8339         __pyx_t_14 = __pyx_t_13;
8340       }
8341       __pyx_t_13 = __pyx_t_14;
8342     } else {
8343       __pyx_t_13 = __pyx_t_3;
8344     }
8345     if (__pyx_t_13) {
8346
8347       /* "csamtools.pyx":778
8348  *         if self.isbam:
8349  *             if not until_eof and not self._hasIndex() and not self.isremote:
8350  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
8351  * 
8352  *             if callback:
8353  */
8354       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8355       __Pyx_GOTREF(__pyx_t_7);
8356       __Pyx_Raise(__pyx_t_7, 0, 0);
8357       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8358       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8359       goto __pyx_L9;
8360     }
8361     __pyx_L9:;
8362
8363     /* "csamtools.pyx":780
8364  *                 raise ValueError( "fetch called on bamfile without index" )
8365  * 
8366  *             if callback:             # <<<<<<<<<<<<<<
8367  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
8368  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
8369  */
8370     __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8371     if (__pyx_t_13) {
8372
8373       /* "csamtools.pyx":781
8374  * 
8375  *             if callback:
8376  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
8377  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
8378  *                 return bam_fetch(self.samfile.x.bam,
8379  */
8380       __pyx_t_13 = (!__pyx_v_has_coord);
8381       if (__pyx_t_13) {
8382         __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8383         __Pyx_GOTREF(__pyx_t_7);
8384         __Pyx_Raise(__pyx_t_7, 0, 0);
8385         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8386         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8387         goto __pyx_L11;
8388       }
8389       __pyx_L11:;
8390
8391       /* "csamtools.pyx":782
8392  *             if callback:
8393  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
8394  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
8395  *                 return bam_fetch(self.samfile.x.bam,
8396  *                                  self.index,
8397  */
8398       __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8399       __Pyx_GOTREF(__pyx_t_7);
8400       __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 = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8401       __Pyx_GOTREF(__pyx_t_5);
8402       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8403       __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8404       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
8405       __pyx_t_3 = (!__pyx_t_13);
8406       if (__pyx_t_3) {
8407         __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8408         __Pyx_GOTREF(__pyx_t_5);
8409         __Pyx_Raise(__pyx_t_5, 0, 0);
8410         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
8411         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8412         goto __pyx_L12;
8413       }
8414       __pyx_L12:;
8415
8416       /* "csamtools.pyx":783
8417  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
8418  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
8419  *                 return bam_fetch(self.samfile.x.bam,             # <<<<<<<<<<<<<<
8420  *                                  self.index,
8421  *                                  rtid,
8422  */
8423       __Pyx_XDECREF(__pyx_r);
8424
8425       /* "csamtools.pyx":789
8426  *                                  rend,
8427  *                                  <void*>callback,
8428  *                                  fetch_callback )             # <<<<<<<<<<<<<<
8429  *             else:
8430  *                 if has_coord:
8431  */
8432       __pyx_t_5 = PyInt_FromLong(bam_fetch(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_9csamtools_Samfile *)__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 = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8433       __Pyx_GOTREF(__pyx_t_5);
8434       __pyx_r = __pyx_t_5;
8435       __pyx_t_5 = 0;
8436       goto __pyx_L0;
8437       goto __pyx_L10;
8438     }
8439     /*else*/ {
8440
8441       /* "csamtools.pyx":791
8442  *                                  fetch_callback )
8443  *             else:
8444  *                 if has_coord:             # <<<<<<<<<<<<<<
8445  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )
8446  *                 else:
8447  */
8448       if (__pyx_v_has_coord) {
8449
8450         /* "csamtools.pyx":792
8451  *             else:
8452  *                 if has_coord:
8453  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )             # <<<<<<<<<<<<<<
8454  *                 else:
8455  *                     if until_eof:
8456  */
8457         __Pyx_XDECREF(__pyx_r);
8458         __pyx_t_5 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8459         __Pyx_GOTREF(__pyx_t_5);
8460         __pyx_t_7 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8461         __Pyx_GOTREF(__pyx_t_7);
8462         __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8463         __Pyx_GOTREF(__pyx_t_6);
8464         __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8465         __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8466         __Pyx_INCREF(__pyx_v_self);
8467         PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self);
8468         __Pyx_GIVEREF(__pyx_v_self);
8469         PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
8470         __Pyx_GIVEREF(__pyx_t_5);
8471         PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_7);
8472         __Pyx_GIVEREF(__pyx_t_7);
8473         PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_6);
8474         __Pyx_GIVEREF(__pyx_t_6);
8475         __pyx_t_5 = 0;
8476         __pyx_t_7 = 0;
8477         __pyx_t_6 = 0;
8478         __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8479         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
8480         __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8481         __Pyx_GOTREF(__pyx_t_7);
8482         if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8483         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8484         __pyx_t_7 = PyEval_CallObjectWithKeywords(((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 = 792; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8485         __Pyx_GOTREF(__pyx_t_7);
8486         __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
8487         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
8488         __pyx_r = __pyx_t_7;
8489         __pyx_t_7 = 0;
8490         goto __pyx_L0;
8491         goto __pyx_L13;
8492       }
8493       /*else*/ {
8494
8495         /* "csamtools.pyx":794
8496  *                     return IteratorRowRegion( self, rtid, rstart, rend, reopen=reopen )
8497  *                 else:
8498  *                     if until_eof:             # <<<<<<<<<<<<<<
8499  *                         return IteratorRowAll( self, reopen=reopen )
8500  *                     else:
8501  */
8502         __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8503         if (__pyx_t_3) {
8504
8505           /* "csamtools.pyx":795
8506  *                 else:
8507  *                     if until_eof:
8508  *                         return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
8509  *                     else:
8510  *                         # AH: check - reason why no reopen for AllRefs?
8511  */
8512           __Pyx_XDECREF(__pyx_r);
8513           __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8514           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
8515           __Pyx_INCREF(__pyx_v_self);
8516           PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self);
8517           __Pyx_GIVEREF(__pyx_v_self);
8518           __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8519           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
8520           __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8521           __Pyx_GOTREF(__pyx_t_2);
8522           if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__reopen), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8523           __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8524           __pyx_t_2 = PyEval_CallObjectWithKeywords(((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 = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8525           __Pyx_GOTREF(__pyx_t_2);
8526           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
8527           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
8528           __pyx_r = __pyx_t_2;
8529           __pyx_t_2 = 0;
8530           goto __pyx_L0;
8531           goto __pyx_L14;
8532         }
8533         /*else*/ {
8534
8535           /* "csamtools.pyx":798
8536  *                     else:
8537  *                         # AH: check - reason why no reopen for AllRefs?
8538  *                         return IteratorRowAllRefs(self ) # , reopen=reopen )             # <<<<<<<<<<<<<<
8539  *         else:
8540  *             # check if header is present - otherwise sam_read1 aborts
8541  */
8542           __Pyx_XDECREF(__pyx_r);
8543           __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8544           __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8545           __Pyx_INCREF(__pyx_v_self);
8546           PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self);
8547           __Pyx_GIVEREF(__pyx_v_self);
8548           __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 = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8549           __Pyx_GOTREF(__pyx_t_6);
8550           __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
8551           __pyx_r = __pyx_t_6;
8552           __pyx_t_6 = 0;
8553           goto __pyx_L0;
8554         }
8555         __pyx_L14:;
8556       }
8557       __pyx_L13:;
8558     }
8559     __pyx_L10:;
8560     goto __pyx_L8;
8561   }
8562   /*else*/ {
8563
8564     /* "csamtools.pyx":802
8565  *             # check if header is present - otherwise sam_read1 aborts
8566  *             # this happens if a bamfile is opened with mode 'r'
8567  *             if has_coord:             # <<<<<<<<<<<<<<
8568  *                 raise ValueError ("fetching by region is not available for sam files" )
8569  * 
8570  */
8571     if (__pyx_v_has_coord) {
8572
8573       /* "csamtools.pyx":803
8574  *             # this happens if a bamfile is opened with mode 'r'
8575  *             if has_coord:
8576  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
8577  * 
8578  *             if self.samfile.header.n_targets == 0:
8579  */
8580       __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8581       __Pyx_GOTREF(__pyx_t_6);
8582       __Pyx_Raise(__pyx_t_6, 0, 0);
8583       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
8584       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8585       goto __pyx_L15;
8586     }
8587     __pyx_L15:;
8588
8589     /* "csamtools.pyx":805
8590  *                 raise ValueError ("fetching by region is not available for sam files" )
8591  * 
8592  *             if self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
8593  *                 raise ValueError( "fetch called for samfile without header")
8594  * 
8595  */
8596     __pyx_t_3 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets == 0);
8597     if (__pyx_t_3) {
8598
8599       /* "csamtools.pyx":806
8600  * 
8601  *             if self.samfile.header.n_targets == 0:
8602  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
8603  * 
8604  *             if callback:
8605  */
8606       __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8607       __Pyx_GOTREF(__pyx_t_6);
8608       __Pyx_Raise(__pyx_t_6, 0, 0);
8609       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
8610       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8611       goto __pyx_L16;
8612     }
8613     __pyx_L16:;
8614
8615     /* "csamtools.pyx":808
8616  *                 raise ValueError( "fetch called for samfile without header")
8617  * 
8618  *             if callback:             # <<<<<<<<<<<<<<
8619  *                 raise NotImplementedError( "callback not implemented yet" )
8620  *             else:
8621  */
8622     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_callback); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8623     if (__pyx_t_3) {
8624
8625       /* "csamtools.pyx":809
8626  * 
8627  *             if callback:
8628  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
8629  *             else:
8630  *                 return IteratorRowAll( self, reopen=reopen )
8631  */
8632       __pyx_t_6 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8633       __Pyx_GOTREF(__pyx_t_6);
8634       __Pyx_Raise(__pyx_t_6, 0, 0);
8635       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
8636       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8637       goto __pyx_L17;
8638     }
8639     /*else*/ {
8640
8641       /* "csamtools.pyx":811
8642  *                 raise NotImplementedError( "callback not implemented yet" )
8643  *             else:
8644  *                 return IteratorRowAll( self, reopen=reopen )             # <<<<<<<<<<<<<<
8645  * 
8646  *     def mate( self,
8647  */
8648       __Pyx_XDECREF(__pyx_r);
8649       __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8650       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
8651       __Pyx_INCREF(__pyx_v_self);
8652       PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self);
8653       __Pyx_GIVEREF(__pyx_v_self);
8654       __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8655       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8656       __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8657       __Pyx_GOTREF(__pyx_t_7);
8658       if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8659       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
8660       __pyx_t_7 = PyEval_CallObjectWithKeywords(((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 = 811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8661       __Pyx_GOTREF(__pyx_t_7);
8662       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
8663       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
8664       __pyx_r = __pyx_t_7;
8665       __pyx_t_7 = 0;
8666       goto __pyx_L0;
8667     }
8668     __pyx_L17:;
8669   }
8670   __pyx_L8:;
8671
8672   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
8673   goto __pyx_L0;
8674   __pyx_L1_error:;
8675   __Pyx_XDECREF(__pyx_t_1);
8676   __Pyx_XDECREF(__pyx_t_2);
8677   __Pyx_XDECREF(__pyx_t_5);
8678   __Pyx_XDECREF(__pyx_t_6);
8679   __Pyx_XDECREF(__pyx_t_7);
8680   __Pyx_XDECREF(__pyx_t_12);
8681   __Pyx_AddTraceback("csamtools.Samfile.fetch");
8682   __pyx_r = NULL;
8683   __pyx_L0:;
8684   __Pyx_XGIVEREF(__pyx_r);
8685   __Pyx_TraceReturn(__pyx_r);
8686   __Pyx_RefNannyFinishContext();
8687   return __pyx_r;
8688 }
8689
8690 /* "csamtools.pyx":813
8691  *                 return IteratorRowAll( self, reopen=reopen )
8692  * 
8693  *     def mate( self,             # <<<<<<<<<<<<<<
8694  *               AlignedRead read ):
8695  *         '''return the mate of :class:`AlignedRead` *read*.
8696  */
8697
8698 static PyObject *__pyx_pf_9csamtools_7Samfile_11mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
8699 static char __pyx_doc_9csamtools_7Samfile_11mate[] = "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        ";
8700 static PyObject *__pyx_pf_9csamtools_7Samfile_11mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
8701   uint32_t __pyx_v_flag;
8702   __pyx_t_9csamtools_MateData __pyx_v_mate_data;
8703   int __pyx_v_x;
8704   struct __pyx_obj_9csamtools_AlignedRead *__pyx_v_dest = 0;
8705   PyObject *__pyx_r = NULL;
8706   int __pyx_t_1;
8707   PyObject *__pyx_t_2 = NULL;
8708   PyObject *__pyx_t_3 = NULL;
8709   __Pyx_TraceDeclarations
8710   __Pyx_RefNannySetupContext("mate");
8711   __Pyx_TraceCall("mate", __pyx_f[0], 813);
8712   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8713
8714   /* "csamtools.pyx":826
8715  * 
8716  *         '''
8717  *         cdef uint32_t flag = read._delegate.core.flag             # <<<<<<<<<<<<<<
8718  * 
8719  *         if flag & BAM_FPAIRED == 0:
8720  */
8721   __pyx_v_flag = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read)->_delegate->core.flag;
8722
8723   /* "csamtools.pyx":828
8724  *         cdef uint32_t flag = read._delegate.core.flag
8725  * 
8726  *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
8727  *             raise ValueError( "read %s: is unpaired" % (read.qname))
8728  *         if flag & BAM_FMUNMAP != 0:
8729  */
8730   __pyx_t_1 = ((__pyx_v_flag & 1) == 0);
8731   if (__pyx_t_1) {
8732
8733     /* "csamtools.pyx":829
8734  * 
8735  *         if flag & BAM_FPAIRED == 0:
8736  *             raise ValueError( "read %s: is unpaired" % (read.qname))             # <<<<<<<<<<<<<<
8737  *         if flag & BAM_FMUNMAP != 0:
8738  *             raise ValueError( "mate %s: is unmapped" % (read.qname))
8739  */
8740     __pyx_t_2 = PyObject_GetAttr(__pyx_v_read, __pyx_n_s__qname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8741     __Pyx_GOTREF(__pyx_t_2);
8742     __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_58), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8743     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
8744     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8745     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8746     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8747     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3));
8748     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
8749     __pyx_t_3 = 0;
8750     __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 = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8751     __Pyx_GOTREF(__pyx_t_3);
8752     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
8753     __Pyx_Raise(__pyx_t_3, 0, 0);
8754     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
8755     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8756     goto __pyx_L5;
8757   }
8758   __pyx_L5:;
8759
8760   /* "csamtools.pyx":830
8761  *         if flag & BAM_FPAIRED == 0:
8762  *             raise ValueError( "read %s: is unpaired" % (read.qname))
8763  *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
8764  *             raise ValueError( "mate %s: is unmapped" % (read.qname))
8765  * 
8766  */
8767   __pyx_t_1 = ((__pyx_v_flag & 8) != 0);
8768   if (__pyx_t_1) {
8769
8770     /* "csamtools.pyx":831
8771  *             raise ValueError( "read %s: is unpaired" % (read.qname))
8772  *         if flag & BAM_FMUNMAP != 0:
8773  *             raise ValueError( "mate %s: is unmapped" % (read.qname))             # <<<<<<<<<<<<<<
8774  * 
8775  *         cdef MateData mate_data
8776  */
8777     __pyx_t_3 = PyObject_GetAttr(__pyx_v_read, __pyx_n_s__qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8778     __Pyx_GOTREF(__pyx_t_3);
8779     __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_59), __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8780     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
8781     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
8782     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8783     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
8784     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2));
8785     __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
8786     __pyx_t_2 = 0;
8787     __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 = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8788     __Pyx_GOTREF(__pyx_t_2);
8789     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
8790     __Pyx_Raise(__pyx_t_2, 0, 0);
8791     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8792     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8793     goto __pyx_L6;
8794   }
8795   __pyx_L6:;
8796
8797   /* "csamtools.pyx":835
8798  *         cdef MateData mate_data
8799  * 
8800  *         mate_data.name = <char *>bam1_qname(read._delegate)             # <<<<<<<<<<<<<<
8801  *         mate_data.mate = NULL
8802  *         # xor flags to get the other mate
8803  */
8804   __pyx_v_mate_data.name = bam1_qname(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read)->_delegate);
8805
8806   /* "csamtools.pyx":836
8807  * 
8808  *         mate_data.name = <char *>bam1_qname(read._delegate)
8809  *         mate_data.mate = NULL             # <<<<<<<<<<<<<<
8810  *         # xor flags to get the other mate
8811  *         cdef int x = BAM_FREAD1 + BAM_FREAD2
8812  */
8813   __pyx_v_mate_data.mate = NULL;
8814
8815   /* "csamtools.pyx":838
8816  *         mate_data.mate = NULL
8817  *         # xor flags to get the other mate
8818  *         cdef int x = BAM_FREAD1 + BAM_FREAD2             # <<<<<<<<<<<<<<
8819  *         mate_data.flag = ( flag ^ x) & x
8820  * 
8821  */
8822   __pyx_v_x = 192;
8823
8824   /* "csamtools.pyx":839
8825  *         # xor flags to get the other mate
8826  *         cdef int x = BAM_FREAD1 + BAM_FREAD2
8827  *         mate_data.flag = ( flag ^ x) & x             # <<<<<<<<<<<<<<
8828  * 
8829  *         bam_fetch(self.samfile.x.bam,
8830  */
8831   __pyx_v_mate_data.flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);
8832
8833   /* "csamtools.pyx":847
8834  *                   read._delegate.core.mpos + 1,
8835  *                   <void*>&mate_data,
8836  *                   mate_callback )             # <<<<<<<<<<<<<<
8837  * 
8838  *         if mate_data.mate == NULL:
8839  */
8840   bam_fetch(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read)->_delegate->core.mtid, ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read)->_delegate->core.mpos, (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read)->_delegate->core.mpos + 1), ((void *)(&__pyx_v_mate_data)), __pyx_f_9csamtools_mate_callback);
8841
8842   /* "csamtools.pyx":849
8843  *                   mate_callback )
8844  * 
8845  *         if mate_data.mate == NULL:             # <<<<<<<<<<<<<<
8846  *             raise ValueError( "mate not found" )
8847  * 
8848  */
8849   __pyx_t_1 = (__pyx_v_mate_data.mate == NULL);
8850   if (__pyx_t_1) {
8851
8852     /* "csamtools.pyx":850
8853  * 
8854  *         if mate_data.mate == NULL:
8855  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
8856  * 
8857  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
8858  */
8859     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8860     __Pyx_GOTREF(__pyx_t_2);
8861     __Pyx_Raise(__pyx_t_2, 0, 0);
8862     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
8863     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8864     goto __pyx_L7;
8865   }
8866   __pyx_L7:;
8867
8868   /* "csamtools.pyx":852
8869  *             raise ValueError( "mate not found" )
8870  * 
8871  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)             # <<<<<<<<<<<<<<
8872  *         dest._delegate = mate_data.mate
8873  *         return dest
8874  */
8875   __pyx_t_2 = __Pyx_tp_new(((PyObject*)__pyx_ptype_9csamtools_AlignedRead)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8876   __Pyx_GOTREF(__pyx_t_2);
8877   if (!(likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_9csamtools_AlignedRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
8878   __pyx_v_dest = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_t_2);
8879   __pyx_t_2 = 0;
8880
8881   /* "csamtools.pyx":853
8882  * 
8883  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
8884  *         dest._delegate = mate_data.mate             # <<<<<<<<<<<<<<
8885  *         return dest
8886  * 
8887  */
8888   __pyx_v_dest->_delegate = __pyx_v_mate_data.mate;
8889
8890   /* "csamtools.pyx":854
8891  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
8892  *         dest._delegate = mate_data.mate
8893  *         return dest             # <<<<<<<<<<<<<<
8894  * 
8895  *     def count( self,
8896  */
8897   __Pyx_XDECREF(__pyx_r);
8898   __Pyx_INCREF(((PyObject *)__pyx_v_dest));
8899   __pyx_r = ((PyObject *)__pyx_v_dest);
8900   goto __pyx_L0;
8901
8902   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
8903   goto __pyx_L0;
8904   __pyx_L1_error:;
8905   __Pyx_XDECREF(__pyx_t_2);
8906   __Pyx_XDECREF(__pyx_t_3);
8907   __Pyx_AddTraceback("csamtools.Samfile.mate");
8908   __pyx_r = NULL;
8909   __pyx_L0:;
8910   __Pyx_XDECREF((PyObject *)__pyx_v_dest);
8911   __Pyx_XGIVEREF(__pyx_r);
8912   __Pyx_TraceReturn(__pyx_r);
8913   __Pyx_RefNannyFinishContext();
8914   return __pyx_r;
8915 }
8916
8917 /* "csamtools.pyx":856
8918  *         return dest
8919  * 
8920  *     def count( self,             # <<<<<<<<<<<<<<
8921  *                reference = None,
8922  *                start = None,
8923  */
8924
8925 static PyObject *__pyx_pf_9csamtools_7Samfile_12count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
8926 static char __pyx_doc_9csamtools_7Samfile_12count[] = "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        ";
8927 static PyObject *__pyx_pf_9csamtools_7Samfile_12count(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
8928   PyObject *__pyx_v_reference = 0;
8929   PyObject *__pyx_v_start = 0;
8930   PyObject *__pyx_v_end = 0;
8931   PyObject *__pyx_v_region = 0;
8932   PyObject *__pyx_v_until_eof = 0;
8933   int __pyx_v_rtid;
8934   int __pyx_v_rstart;
8935   int __pyx_v_rend;
8936   int __pyx_v_counter;
8937   PyObject *__pyx_r = NULL;
8938   PyObject *__pyx_t_1 = NULL;
8939   PyObject *__pyx_t_2 = NULL;
8940   int __pyx_t_3;
8941   int __pyx_t_4;
8942   PyObject *__pyx_t_5 = NULL;
8943   PyObject *__pyx_t_6 = NULL;
8944   PyObject *__pyx_t_7 = NULL;
8945   int __pyx_t_8;
8946   int __pyx_t_9;
8947   int __pyx_t_10;
8948   PyObject *__pyx_t_11 = NULL;
8949   int __pyx_t_12;
8950   int __pyx_t_13;
8951   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};
8952   __Pyx_TraceDeclarations
8953   __Pyx_RefNannySetupContext("count");
8954   __Pyx_TraceCall("count", __pyx_f[0], 856);
8955   if (unlikely(__pyx_kwds)) {
8956     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
8957     PyObject* values[5] = {0,0,0,0,0};
8958
8959     /* "csamtools.pyx":857
8960  * 
8961  *     def count( self,
8962  *                reference = None,             # <<<<<<<<<<<<<<
8963  *                start = None,
8964  *                end = None,
8965  */
8966     values[0] = ((PyObject *)Py_None);
8967
8968     /* "csamtools.pyx":858
8969  *     def count( self,
8970  *                reference = None,
8971  *                start = None,             # <<<<<<<<<<<<<<
8972  *                end = None,
8973  *                region = None,
8974  */
8975     values[1] = ((PyObject *)Py_None);
8976
8977     /* "csamtools.pyx":859
8978  *                reference = None,
8979  *                start = None,
8980  *                end = None,             # <<<<<<<<<<<<<<
8981  *                region = None,
8982  *                until_eof = False ):
8983  */
8984     values[2] = ((PyObject *)Py_None);
8985
8986     /* "csamtools.pyx":860
8987  *                start = None,
8988  *                end = None,
8989  *                region = None,             # <<<<<<<<<<<<<<
8990  *                until_eof = False ):
8991  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
8992  */
8993     values[3] = ((PyObject *)Py_None);
8994     values[4] = __pyx_k_62;
8995     switch (PyTuple_GET_SIZE(__pyx_args)) {
8996       case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
8997       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
8998       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
8999       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
9000       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
9001       case  0: break;
9002       default: goto __pyx_L5_argtuple_error;
9003     }
9004     switch (PyTuple_GET_SIZE(__pyx_args)) {
9005       case  0:
9006       if (kw_args > 0) {
9007         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
9008         if (value) { values[0] = value; kw_args--; }
9009       }
9010       case  1:
9011       if (kw_args > 0) {
9012         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
9013         if (value) { values[1] = value; kw_args--; }
9014       }
9015       case  2:
9016       if (kw_args > 0) {
9017         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
9018         if (value) { values[2] = value; kw_args--; }
9019       }
9020       case  3:
9021       if (kw_args > 0) {
9022         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
9023         if (value) { values[3] = value; kw_args--; }
9024       }
9025       case  4:
9026       if (kw_args > 0) {
9027         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__until_eof);
9028         if (value) { values[4] = value; kw_args--; }
9029       }
9030     }
9031     if (unlikely(kw_args > 0)) {
9032       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9033     }
9034     __pyx_v_reference = values[0];
9035     __pyx_v_start = values[1];
9036     __pyx_v_end = values[2];
9037     __pyx_v_region = values[3];
9038     __pyx_v_until_eof = values[4];
9039   } else {
9040
9041     /* "csamtools.pyx":857
9042  * 
9043  *     def count( self,
9044  *                reference = None,             # <<<<<<<<<<<<<<
9045  *                start = None,
9046  *                end = None,
9047  */
9048     __pyx_v_reference = ((PyObject *)Py_None);
9049
9050     /* "csamtools.pyx":858
9051  *     def count( self,
9052  *                reference = None,
9053  *                start = None,             # <<<<<<<<<<<<<<
9054  *                end = None,
9055  *                region = None,
9056  */
9057     __pyx_v_start = ((PyObject *)Py_None);
9058
9059     /* "csamtools.pyx":859
9060  *                reference = None,
9061  *                start = None,
9062  *                end = None,             # <<<<<<<<<<<<<<
9063  *                region = None,
9064  *                until_eof = False ):
9065  */
9066     __pyx_v_end = ((PyObject *)Py_None);
9067
9068     /* "csamtools.pyx":860
9069  *                start = None,
9070  *                end = None,
9071  *                region = None,             # <<<<<<<<<<<<<<
9072  *                until_eof = False ):
9073  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
9074  */
9075     __pyx_v_region = ((PyObject *)Py_None);
9076     __pyx_v_until_eof = __pyx_k_62;
9077     switch (PyTuple_GET_SIZE(__pyx_args)) {
9078       case  5: __pyx_v_until_eof = PyTuple_GET_ITEM(__pyx_args, 4);
9079       case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
9080       case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
9081       case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
9082       case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
9083       case  0: break;
9084       default: goto __pyx_L5_argtuple_error;
9085     }
9086   }
9087   goto __pyx_L4_argument_unpacking_done;
9088   __pyx_L5_argtuple_error:;
9089   __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9090   __pyx_L3_error:;
9091   __Pyx_AddTraceback("csamtools.Samfile.count");
9092   __Pyx_RefNannyFinishContext();
9093   return NULL;
9094   __pyx_L4_argument_unpacking_done:;
9095   __Pyx_INCREF(__pyx_v_region);
9096
9097   /* "csamtools.pyx":874
9098  *         cdef int rend
9099  * 
9100  *         if not self._isOpen():             # <<<<<<<<<<<<<<
9101  *             raise ValueError( "I/O operation on closed file" )
9102  * 
9103  */
9104   __pyx_t_1 = PyObject_GetAttr(__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;}
9105   __Pyx_GOTREF(__pyx_t_1);
9106   __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;}
9107   __Pyx_GOTREF(__pyx_t_2);
9108   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9109   __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;}
9110   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9111   __pyx_t_4 = (!__pyx_t_3);
9112   if (__pyx_t_4) {
9113
9114     /* "csamtools.pyx":875
9115  * 
9116  *         if not self._isOpen():
9117  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
9118  * 
9119  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
9120  */
9121     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9122     __Pyx_GOTREF(__pyx_t_2);
9123     __Pyx_Raise(__pyx_t_2, 0, 0);
9124     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9125     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9126     goto __pyx_L6;
9127   }
9128   __pyx_L6:;
9129
9130   /* "csamtools.pyx":877
9131  *             raise ValueError( "I/O operation on closed file" )
9132  * 
9133  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
9134  * 
9135  *         cdef int counter
9136  */
9137   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9138   __Pyx_GOTREF(__pyx_t_2);
9139   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9140   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
9141   __Pyx_INCREF(__pyx_v_reference);
9142   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
9143   __Pyx_GIVEREF(__pyx_v_reference);
9144   __Pyx_INCREF(__pyx_v_start);
9145   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
9146   __Pyx_GIVEREF(__pyx_v_start);
9147   __Pyx_INCREF(__pyx_v_end);
9148   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
9149   __Pyx_GIVEREF(__pyx_v_end);
9150   __Pyx_INCREF(__pyx_v_region);
9151   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
9152   __Pyx_GIVEREF(__pyx_v_region);
9153   __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 = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9154   __Pyx_GOTREF(__pyx_t_5);
9155   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9156   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9157   if (PyTuple_CheckExact(__pyx_t_5) && likely(PyTuple_GET_SIZE(__pyx_t_5) == 4)) {
9158     PyObject* tuple = __pyx_t_5;
9159     __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
9160     __pyx_t_2 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_2);
9161     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9162     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9163     __pyx_t_6 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_6);
9164     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9165     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9166     __pyx_t_7 = PyTuple_GET_ITEM(tuple, 3); __Pyx_INCREF(__pyx_t_7);
9167     __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 = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9168     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9169     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9170     __Pyx_DECREF(__pyx_v_region);
9171     __pyx_v_region = __pyx_t_1;
9172     __pyx_t_1 = 0;
9173     __pyx_v_rtid = __pyx_t_8;
9174     __pyx_v_rstart = __pyx_t_9;
9175     __pyx_v_rend = __pyx_t_10;
9176   } else {
9177     __pyx_t_11 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9178     __Pyx_GOTREF(__pyx_t_11);
9179     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9180     __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_11, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9181     __Pyx_GOTREF(__pyx_t_1);
9182     __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_11, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9183     __Pyx_GOTREF(__pyx_t_2);
9184     __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 = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9185     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9186     __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_11, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9187     __Pyx_GOTREF(__pyx_t_6);
9188     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9189     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9190     __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_11, 3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9191     __Pyx_GOTREF(__pyx_t_7);
9192     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9193     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9194     if (__Pyx_EndUnpack(__pyx_t_11, 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9195     __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
9196     __Pyx_DECREF(__pyx_v_region);
9197     __pyx_v_region = __pyx_t_1;
9198     __pyx_t_1 = 0;
9199     __pyx_v_rtid = __pyx_t_10;
9200     __pyx_v_rstart = __pyx_t_9;
9201     __pyx_v_rend = __pyx_t_8;
9202   }
9203
9204   /* "csamtools.pyx":880
9205  * 
9206  *         cdef int counter
9207  *         counter = 0;             # <<<<<<<<<<<<<<
9208  * 
9209  *         if self.isbam:
9210  */
9211   __pyx_v_counter = 0;
9212
9213   /* "csamtools.pyx":882
9214  *         counter = 0;
9215  * 
9216  *         if self.isbam:             # <<<<<<<<<<<<<<
9217  *             if not until_eof and not self._hasIndex() and not self.isremote:
9218  *                 raise ValueError( "fetch called on bamfile without index" )
9219  */
9220   if (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam) {
9221
9222     /* "csamtools.pyx":883
9223  * 
9224  *         if self.isbam:
9225  *             if not until_eof and not self._hasIndex() and not self.isremote:             # <<<<<<<<<<<<<<
9226  *                 raise ValueError( "fetch called on bamfile without index" )
9227  * 
9228  */
9229     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9230     __pyx_t_3 = (!__pyx_t_4);
9231     if (__pyx_t_3) {
9232       __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9233       __Pyx_GOTREF(__pyx_t_5);
9234       __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 = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9235       __Pyx_GOTREF(__pyx_t_7);
9236       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9237       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9238       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9239       __pyx_t_12 = (!__pyx_t_4);
9240       if (__pyx_t_12) {
9241         __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isremote);
9242         __pyx_t_13 = __pyx_t_4;
9243       } else {
9244         __pyx_t_13 = __pyx_t_12;
9245       }
9246       __pyx_t_12 = __pyx_t_13;
9247     } else {
9248       __pyx_t_12 = __pyx_t_3;
9249     }
9250     if (__pyx_t_12) {
9251
9252       /* "csamtools.pyx":884
9253  *         if self.isbam:
9254  *             if not until_eof and not self._hasIndex() and not self.isremote:
9255  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
9256  * 
9257  *             if not region:
9258  */
9259       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_64), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9260       __Pyx_GOTREF(__pyx_t_7);
9261       __Pyx_Raise(__pyx_t_7, 0, 0);
9262       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9263       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9264       goto __pyx_L8;
9265     }
9266     __pyx_L8:;
9267
9268     /* "csamtools.pyx":886
9269  *                 raise ValueError( "fetch called on bamfile without index" )
9270  * 
9271  *             if not region:             # <<<<<<<<<<<<<<
9272  *                 raise ValueError( "counting functionality requires a region/reference" )
9273  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
9274  */
9275     __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_region); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9276     __pyx_t_3 = (!__pyx_t_12);
9277     if (__pyx_t_3) {
9278
9279       /* "csamtools.pyx":887
9280  * 
9281  *             if not region:
9282  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
9283  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
9284  *             bam_fetch(self.samfile.x.bam,
9285  */
9286       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_66), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9287       __Pyx_GOTREF(__pyx_t_7);
9288       __Pyx_Raise(__pyx_t_7, 0, 0);
9289       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9290       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9291       goto __pyx_L9;
9292     }
9293     __pyx_L9:;
9294
9295     /* "csamtools.pyx":888
9296  *             if not region:
9297  *                 raise ValueError( "counting functionality requires a region/reference" )
9298  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
9299  *             bam_fetch(self.samfile.x.bam,
9300  *                              self.index,
9301  */
9302     __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9303     __Pyx_GOTREF(__pyx_t_7);
9304     __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 = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9305     __Pyx_GOTREF(__pyx_t_5);
9306     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9307     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9308     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9309     __pyx_t_12 = (!__pyx_t_3);
9310     if (__pyx_t_12) {
9311       __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_67), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9312       __Pyx_GOTREF(__pyx_t_5);
9313       __Pyx_Raise(__pyx_t_5, 0, 0);
9314       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9315       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9316       goto __pyx_L10;
9317     }
9318     __pyx_L10:;
9319
9320     /* "csamtools.pyx":895
9321  *                              rend,
9322  *                              <void*>&counter,
9323  *                              count_callback )             # <<<<<<<<<<<<<<
9324  *             return counter
9325  *         else:
9326  */
9327     bam_fetch(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, ((void *)(&__pyx_v_counter)), __pyx_f_9csamtools_count_callback);
9328
9329     /* "csamtools.pyx":896
9330  *                              <void*>&counter,
9331  *                              count_callback )
9332  *             return counter             # <<<<<<<<<<<<<<
9333  *         else:
9334  *             raise ValueError ("count for a region is not available for sam files" )
9335  */
9336     __Pyx_XDECREF(__pyx_r);
9337     __pyx_t_5 = PyInt_FromLong(__pyx_v_counter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9338     __Pyx_GOTREF(__pyx_t_5);
9339     __pyx_r = __pyx_t_5;
9340     __pyx_t_5 = 0;
9341     goto __pyx_L0;
9342     goto __pyx_L7;
9343   }
9344   /*else*/ {
9345
9346     /* "csamtools.pyx":898
9347  *             return counter
9348  *         else:
9349  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
9350  * 
9351  *     def pileup( self,
9352  */
9353     __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_69), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9354     __Pyx_GOTREF(__pyx_t_5);
9355     __Pyx_Raise(__pyx_t_5, 0, 0);
9356     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9357     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9358   }
9359   __pyx_L7:;
9360
9361   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9362   goto __pyx_L0;
9363   __pyx_L1_error:;
9364   __Pyx_XDECREF(__pyx_t_1);
9365   __Pyx_XDECREF(__pyx_t_2);
9366   __Pyx_XDECREF(__pyx_t_5);
9367   __Pyx_XDECREF(__pyx_t_6);
9368   __Pyx_XDECREF(__pyx_t_7);
9369   __Pyx_XDECREF(__pyx_t_11);
9370   __Pyx_AddTraceback("csamtools.Samfile.count");
9371   __pyx_r = NULL;
9372   __pyx_L0:;
9373   __Pyx_DECREF(__pyx_v_region);
9374   __Pyx_XGIVEREF(__pyx_r);
9375   __Pyx_TraceReturn(__pyx_r);
9376   __Pyx_RefNannyFinishContext();
9377   return __pyx_r;
9378 }
9379
9380 /* "csamtools.pyx":900
9381  *             raise ValueError ("count for a region is not available for sam files" )
9382  * 
9383  *     def pileup( self,             # <<<<<<<<<<<<<<
9384  *                 reference = None,
9385  *                 start = None,
9386  */
9387
9388 static PyObject *__pyx_pf_9csamtools_7Samfile_13pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
9389 static char __pyx_doc_9csamtools_7Samfile_13pileup[] = "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.\n\n         max_depth\n           Maximum read depth permitted. The default limit is *8000*.\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        ";
9390 static PyObject *__pyx_pf_9csamtools_7Samfile_13pileup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
9391   PyObject *__pyx_v_reference = 0;
9392   PyObject *__pyx_v_start = 0;
9393   PyObject *__pyx_v_end = 0;
9394   PyObject *__pyx_v_region = 0;
9395   PyObject *__pyx_v_callback = 0;
9396   PyObject *__pyx_v_kwargs = 0;
9397   int __pyx_v_rtid;
9398   int __pyx_v_rstart;
9399   int __pyx_v_rend;
9400   int __pyx_v_has_coord;
9401   bam_plbuf_t *__pyx_v_buf;
9402   PyObject *__pyx_r = NULL;
9403   PyObject *__pyx_t_1 = NULL;
9404   PyObject *__pyx_t_2 = NULL;
9405   int __pyx_t_3;
9406   int __pyx_t_4;
9407   PyObject *__pyx_t_5 = NULL;
9408   PyObject *__pyx_t_6 = NULL;
9409   PyObject *__pyx_t_7 = NULL;
9410   int __pyx_t_8;
9411   int __pyx_t_9;
9412   int __pyx_t_10;
9413   int __pyx_t_11;
9414   PyObject *__pyx_t_12 = NULL;
9415   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};
9416   __Pyx_TraceDeclarations
9417   __Pyx_RefNannySetupContext("pileup");
9418   __Pyx_TraceCall("pileup", __pyx_f[0], 900);
9419   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
9420   __Pyx_GOTREF(__pyx_v_kwargs);
9421   if (unlikely(__pyx_kwds)) {
9422     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
9423     PyObject* values[5] = {0,0,0,0,0};
9424
9425     /* "csamtools.pyx":901
9426  * 
9427  *     def pileup( self,
9428  *                 reference = None,             # <<<<<<<<<<<<<<
9429  *                 start = None,
9430  *                 end = None,
9431  */
9432     values[0] = ((PyObject *)Py_None);
9433
9434     /* "csamtools.pyx":902
9435  *     def pileup( self,
9436  *                 reference = None,
9437  *                 start = None,             # <<<<<<<<<<<<<<
9438  *                 end = None,
9439  *                 region = None,
9440  */
9441     values[1] = ((PyObject *)Py_None);
9442
9443     /* "csamtools.pyx":903
9444  *                 reference = None,
9445  *                 start = None,
9446  *                 end = None,             # <<<<<<<<<<<<<<
9447  *                 region = None,
9448  *                 callback = None,
9449  */
9450     values[2] = ((PyObject *)Py_None);
9451
9452     /* "csamtools.pyx":904
9453  *                 start = None,
9454  *                 end = None,
9455  *                 region = None,             # <<<<<<<<<<<<<<
9456  *                 callback = None,
9457  *                 **kwargs ):
9458  */
9459     values[3] = ((PyObject *)Py_None);
9460
9461     /* "csamtools.pyx":905
9462  *                 end = None,
9463  *                 region = None,
9464  *                 callback = None,             # <<<<<<<<<<<<<<
9465  *                 **kwargs ):
9466  *         '''
9467  */
9468     values[4] = ((PyObject *)Py_None);
9469     switch (PyTuple_GET_SIZE(__pyx_args)) {
9470       case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
9471       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
9472       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
9473       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
9474       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
9475       case  0: break;
9476       default: goto __pyx_L5_argtuple_error;
9477     }
9478     switch (PyTuple_GET_SIZE(__pyx_args)) {
9479       case  0:
9480       if (kw_args > 0) {
9481         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reference);
9482         if (value) { values[0] = value; kw_args--; }
9483       }
9484       case  1:
9485       if (kw_args > 0) {
9486         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
9487         if (value) { values[1] = value; kw_args--; }
9488       }
9489       case  2:
9490       if (kw_args > 0) {
9491         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
9492         if (value) { values[2] = value; kw_args--; }
9493       }
9494       case  3:
9495       if (kw_args > 0) {
9496         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__region);
9497         if (value) { values[3] = value; kw_args--; }
9498       }
9499       case  4:
9500       if (kw_args > 0) {
9501         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
9502         if (value) { values[4] = value; kw_args--; }
9503       }
9504     }
9505     if (unlikely(kw_args > 0)) {
9506       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, PyTuple_GET_SIZE(__pyx_args), "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9507     }
9508     __pyx_v_reference = values[0];
9509     __pyx_v_start = values[1];
9510     __pyx_v_end = values[2];
9511     __pyx_v_region = values[3];
9512     __pyx_v_callback = values[4];
9513   } else {
9514
9515     /* "csamtools.pyx":901
9516  * 
9517  *     def pileup( self,
9518  *                 reference = None,             # <<<<<<<<<<<<<<
9519  *                 start = None,
9520  *                 end = None,
9521  */
9522     __pyx_v_reference = ((PyObject *)Py_None);
9523
9524     /* "csamtools.pyx":902
9525  *     def pileup( self,
9526  *                 reference = None,
9527  *                 start = None,             # <<<<<<<<<<<<<<
9528  *                 end = None,
9529  *                 region = None,
9530  */
9531     __pyx_v_start = ((PyObject *)Py_None);
9532
9533     /* "csamtools.pyx":903
9534  *                 reference = None,
9535  *                 start = None,
9536  *                 end = None,             # <<<<<<<<<<<<<<
9537  *                 region = None,
9538  *                 callback = None,
9539  */
9540     __pyx_v_end = ((PyObject *)Py_None);
9541
9542     /* "csamtools.pyx":904
9543  *                 start = None,
9544  *                 end = None,
9545  *                 region = None,             # <<<<<<<<<<<<<<
9546  *                 callback = None,
9547  *                 **kwargs ):
9548  */
9549     __pyx_v_region = ((PyObject *)Py_None);
9550
9551     /* "csamtools.pyx":905
9552  *                 end = None,
9553  *                 region = None,
9554  *                 callback = None,             # <<<<<<<<<<<<<<
9555  *                 **kwargs ):
9556  *         '''
9557  */
9558     __pyx_v_callback = ((PyObject *)Py_None);
9559     switch (PyTuple_GET_SIZE(__pyx_args)) {
9560       case  5: __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 4);
9561       case  4: __pyx_v_region = PyTuple_GET_ITEM(__pyx_args, 3);
9562       case  3: __pyx_v_end = PyTuple_GET_ITEM(__pyx_args, 2);
9563       case  2: __pyx_v_start = PyTuple_GET_ITEM(__pyx_args, 1);
9564       case  1: __pyx_v_reference = PyTuple_GET_ITEM(__pyx_args, 0);
9565       case  0: break;
9566       default: goto __pyx_L5_argtuple_error;
9567     }
9568   }
9569   goto __pyx_L4_argument_unpacking_done;
9570   __pyx_L5_argtuple_error:;
9571   __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
9572   __pyx_L3_error:;
9573   __Pyx_DECREF(__pyx_v_kwargs);
9574   __Pyx_AddTraceback("csamtools.Samfile.pileup");
9575   __Pyx_RefNannyFinishContext();
9576   return NULL;
9577   __pyx_L4_argument_unpacking_done:;
9578
9579   /* "csamtools.pyx":951
9580  *         cdef bam_plbuf_t *buf
9581  * 
9582  *         if not self._isOpen():             # <<<<<<<<<<<<<<
9583  *             raise ValueError( "I/O operation on closed file" )
9584  * 
9585  */
9586   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9587   __Pyx_GOTREF(__pyx_t_1);
9588   __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 = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9589   __Pyx_GOTREF(__pyx_t_2);
9590   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9591   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9592   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9593   __pyx_t_4 = (!__pyx_t_3);
9594   if (__pyx_t_4) {
9595
9596     /* "csamtools.pyx":952
9597  * 
9598  *         if not self._isOpen():
9599  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
9600  * 
9601  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
9602  */
9603     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_70), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9604     __Pyx_GOTREF(__pyx_t_2);
9605     __Pyx_Raise(__pyx_t_2, 0, 0);
9606     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9607     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9608     goto __pyx_L6;
9609   }
9610   __pyx_L6:;
9611
9612   /* "csamtools.pyx":954
9613  *             raise ValueError( "I/O operation on closed file" )
9614  * 
9615  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )             # <<<<<<<<<<<<<<
9616  * 
9617  *         if self.isbam:
9618  */
9619   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___parseRegion); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9620   __Pyx_GOTREF(__pyx_t_2);
9621   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9622   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
9623   __Pyx_INCREF(__pyx_v_reference);
9624   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_reference);
9625   __Pyx_GIVEREF(__pyx_v_reference);
9626   __Pyx_INCREF(__pyx_v_start);
9627   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_start);
9628   __Pyx_GIVEREF(__pyx_v_start);
9629   __Pyx_INCREF(__pyx_v_end);
9630   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_end);
9631   __Pyx_GIVEREF(__pyx_v_end);
9632   __Pyx_INCREF(__pyx_v_region);
9633   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_region);
9634   __Pyx_GIVEREF(__pyx_v_region);
9635   __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 = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9636   __Pyx_GOTREF(__pyx_t_5);
9637   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9638   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
9639   if (PyTuple_CheckExact(__pyx_t_5) && likely(PyTuple_GET_SIZE(__pyx_t_5) == 4)) {
9640     PyObject* tuple = __pyx_t_5;
9641     __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
9642     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9643     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9644     __pyx_t_2 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_2);
9645     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9646     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9647     __pyx_t_6 = PyTuple_GET_ITEM(tuple, 2); __Pyx_INCREF(__pyx_t_6);
9648     __pyx_t_10 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9649     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9650     __pyx_t_7 = PyTuple_GET_ITEM(tuple, 3); __Pyx_INCREF(__pyx_t_7);
9651     __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9652     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9653     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9654     __pyx_v_has_coord = __pyx_t_8;
9655     __pyx_v_rtid = __pyx_t_9;
9656     __pyx_v_rstart = __pyx_t_10;
9657     __pyx_v_rend = __pyx_t_11;
9658   } else {
9659     __pyx_t_12 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9660     __Pyx_GOTREF(__pyx_t_12);
9661     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9662     __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_12, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9663     __Pyx_GOTREF(__pyx_t_1);
9664     __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9665     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
9666     __pyx_t_2 = __Pyx_UnpackItem(__pyx_t_12, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9667     __Pyx_GOTREF(__pyx_t_2);
9668     __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 = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9669     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
9670     __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_12, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9671     __Pyx_GOTREF(__pyx_t_6);
9672     __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9673     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9674     __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_12, 3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9675     __Pyx_GOTREF(__pyx_t_7);
9676     __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9677     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9678     if (__Pyx_EndUnpack(__pyx_t_12, 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9679     __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
9680     __pyx_v_has_coord = __pyx_t_11;
9681     __pyx_v_rtid = __pyx_t_10;
9682     __pyx_v_rstart = __pyx_t_9;
9683     __pyx_v_rend = __pyx_t_8;
9684   }
9685
9686   /* "csamtools.pyx":956
9687  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
9688  * 
9689  *         if self.isbam:             # <<<<<<<<<<<<<<
9690  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
9691  * 
9692  */
9693   if (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam) {
9694
9695     /* "csamtools.pyx":957
9696  * 
9697  *         if self.isbam:
9698  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
9699  * 
9700  *             if callback:
9701  */
9702     __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___hasIndex); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9703     __Pyx_GOTREF(__pyx_t_5);
9704     __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 = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9705     __Pyx_GOTREF(__pyx_t_7);
9706     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9707     __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9708     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9709     __pyx_t_3 = (!__pyx_t_4);
9710     if (__pyx_t_3) {
9711       __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_72), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9712       __Pyx_GOTREF(__pyx_t_7);
9713       __Pyx_Raise(__pyx_t_7, 0, 0);
9714       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9715       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9716       goto __pyx_L8;
9717     }
9718     __pyx_L8:;
9719
9720     /* "csamtools.pyx":959
9721  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )
9722  * 
9723  *             if callback:             # <<<<<<<<<<<<<<
9724  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
9725  * 
9726  */
9727     __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;}
9728     if (__pyx_t_3) {
9729
9730       /* "csamtools.pyx":960
9731  * 
9732  *             if callback:
9733  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
9734  * 
9735  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
9736  */
9737       __pyx_t_3 = (!__pyx_v_has_coord);
9738       if (__pyx_t_3) {
9739         __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9740         __Pyx_GOTREF(__pyx_t_7);
9741         __Pyx_Raise(__pyx_t_7, 0, 0);
9742         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
9743         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9744         goto __pyx_L10;
9745       }
9746       __pyx_L10:;
9747
9748       /* "csamtools.pyx":962
9749  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
9750  * 
9751  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )             # <<<<<<<<<<<<<<
9752  *                 bam_fetch(self.samfile.x.bam,
9753  *                           self.index, rtid, rstart, rend,
9754  */
9755       __pyx_v_buf = bam_plbuf_init(((bam_pileup_f)__pyx_f_9csamtools_pileup_callback), ((void *)__pyx_v_callback));
9756
9757       /* "csamtools.pyx":965
9758  *                 bam_fetch(self.samfile.x.bam,
9759  *                           self.index, rtid, rstart, rend,
9760  *                           buf, pileup_fetch_callback )             # <<<<<<<<<<<<<<
9761  * 
9762  *                 # finalize pileup
9763  */
9764       bam_fetch(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->x.bam, ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_rtid, __pyx_v_rstart, __pyx_v_rend, __pyx_v_buf, __pyx_f_9csamtools_pileup_fetch_callback);
9765
9766       /* "csamtools.pyx":968
9767  * 
9768  *                 # finalize pileup
9769  *                 bam_plbuf_push( NULL, buf)             # <<<<<<<<<<<<<<
9770  *                 bam_plbuf_destroy(buf)
9771  *             else:
9772  */
9773       bam_plbuf_push(NULL, __pyx_v_buf);
9774
9775       /* "csamtools.pyx":969
9776  *                 # finalize pileup
9777  *                 bam_plbuf_push( NULL, buf)
9778  *                 bam_plbuf_destroy(buf)             # <<<<<<<<<<<<<<
9779  *             else:
9780  *                 if has_coord:
9781  */
9782       bam_plbuf_destroy(__pyx_v_buf);
9783       goto __pyx_L9;
9784     }
9785     /*else*/ {
9786
9787       /* "csamtools.pyx":971
9788  *                 bam_plbuf_destroy(buf)
9789  *             else:
9790  *                 if has_coord:             # <<<<<<<<<<<<<<
9791  *                     return IteratorColumnRegion( self,
9792  *                                                  tid = rtid,
9793  */
9794       if (__pyx_v_has_coord) {
9795
9796         /* "csamtools.pyx":972
9797  *             else:
9798  *                 if has_coord:
9799  *                     return IteratorColumnRegion( self,             # <<<<<<<<<<<<<<
9800  *                                                  tid = rtid,
9801  *                                                  start = rstart,
9802  */
9803         __Pyx_XDECREF(__pyx_r);
9804         __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9805         __Pyx_GOTREF(((PyObject *)__pyx_t_7));
9806         __Pyx_INCREF(__pyx_v_self);
9807         PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self);
9808         __Pyx_GIVEREF(__pyx_v_self);
9809         __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9810         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
9811
9812         /* "csamtools.pyx":973
9813  *                 if has_coord:
9814  *                     return IteratorColumnRegion( self,
9815  *                                                  tid = rtid,             # <<<<<<<<<<<<<<
9816  *                                                  start = rstart,
9817  *                                                  end = rend,
9818  */
9819         __pyx_t_6 = PyInt_FromLong(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9820         __Pyx_GOTREF(__pyx_t_6);
9821         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__tid), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9822         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9823
9824         /* "csamtools.pyx":974
9825  *                     return IteratorColumnRegion( self,
9826  *                                                  tid = rtid,
9827  *                                                  start = rstart,             # <<<<<<<<<<<<<<
9828  *                                                  end = rend,
9829  *                                                  **kwargs )
9830  */
9831         __pyx_t_6 = PyInt_FromLong(__pyx_v_rstart); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9832         __Pyx_GOTREF(__pyx_t_6);
9833         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9834         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9835
9836         /* "csamtools.pyx":975
9837  *                                                  tid = rtid,
9838  *                                                  start = rstart,
9839  *                                                  end = rend,             # <<<<<<<<<<<<<<
9840  *                                                  **kwargs )
9841  *                 else:
9842  */
9843         __pyx_t_6 = PyInt_FromLong(__pyx_v_rend); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9844         __Pyx_GOTREF(__pyx_t_6);
9845         if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9846         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
9847
9848         /* "csamtools.pyx":976
9849  *                                                  start = rstart,
9850  *                                                  end = rend,
9851  *                                                  **kwargs )             # <<<<<<<<<<<<<<
9852  *                 else:
9853  *                     return IteratorColumnAllRefs(self, **kwargs )
9854  */
9855         if (PyDict_Update(((PyObject *)__pyx_t_5), ((PyObject *)__pyx_v_kwargs)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9856         __pyx_t_6 = PyEval_CallObjectWithKeywords(((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 = 972; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9857         __Pyx_GOTREF(__pyx_t_6);
9858         __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
9859         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
9860         __pyx_r = __pyx_t_6;
9861         __pyx_t_6 = 0;
9862         goto __pyx_L0;
9863         goto __pyx_L11;
9864       }
9865       /*else*/ {
9866
9867         /* "csamtools.pyx":978
9868  *                                                  **kwargs )
9869  *                 else:
9870  *                     return IteratorColumnAllRefs(self, **kwargs )             # <<<<<<<<<<<<<<
9871  * 
9872  *         else:
9873  */
9874         __Pyx_XDECREF(__pyx_r);
9875         __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9876         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
9877         __Pyx_INCREF(__pyx_v_self);
9878         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self);
9879         __Pyx_GIVEREF(__pyx_v_self);
9880         __pyx_t_5 = PyEval_CallObjectWithKeywords(((PyObject *)((PyObject*)__pyx_ptype_9csamtools_IteratorColumnAllRefs)), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9881         __Pyx_GOTREF(__pyx_t_5);
9882         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
9883         __pyx_r = __pyx_t_5;
9884         __pyx_t_5 = 0;
9885         goto __pyx_L0;
9886       }
9887       __pyx_L11:;
9888     }
9889     __pyx_L9:;
9890     goto __pyx_L7;
9891   }
9892   /*else*/ {
9893
9894     /* "csamtools.pyx":981
9895  * 
9896  *         else:
9897  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
9898  * 
9899  *     def close( self ):
9900  */
9901     __pyx_t_5 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9902     __Pyx_GOTREF(__pyx_t_5);
9903     __Pyx_Raise(__pyx_t_5, 0, 0);
9904     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
9905     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
9906   }
9907   __pyx_L7:;
9908
9909   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9910   goto __pyx_L0;
9911   __pyx_L1_error:;
9912   __Pyx_XDECREF(__pyx_t_1);
9913   __Pyx_XDECREF(__pyx_t_2);
9914   __Pyx_XDECREF(__pyx_t_5);
9915   __Pyx_XDECREF(__pyx_t_6);
9916   __Pyx_XDECREF(__pyx_t_7);
9917   __Pyx_XDECREF(__pyx_t_12);
9918   __Pyx_AddTraceback("csamtools.Samfile.pileup");
9919   __pyx_r = NULL;
9920   __pyx_L0:;
9921   __Pyx_DECREF(__pyx_v_kwargs);
9922   __Pyx_XGIVEREF(__pyx_r);
9923   __Pyx_TraceReturn(__pyx_r);
9924   __Pyx_RefNannyFinishContext();
9925   return __pyx_r;
9926 }
9927
9928 /* "csamtools.pyx":983
9929  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )
9930  * 
9931  *     def close( self ):             # <<<<<<<<<<<<<<
9932  *         '''
9933  *         closes the :class:`pysam.Samfile`.'''
9934  */
9935
9936 static PyObject *__pyx_pf_9csamtools_7Samfile_14close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
9937 static char __pyx_doc_9csamtools_7Samfile_14close[] = "Samfile.close(self)\n\n        closes the :class:`pysam.Samfile`.";
9938 static PyObject *__pyx_pf_9csamtools_7Samfile_14close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
9939   PyObject *__pyx_r = NULL;
9940   int __pyx_t_1;
9941   __Pyx_TraceDeclarations
9942   __Pyx_RefNannySetupContext("close");
9943   __Pyx_TraceCall("close", __pyx_f[0], 983);
9944
9945   /* "csamtools.pyx":986
9946  *         '''
9947  *         closes the :class:`pysam.Samfile`.'''
9948  *         if self.samfile != NULL:             # <<<<<<<<<<<<<<
9949  *             samclose( self.samfile )
9950  *             bam_index_destroy(self.index);
9951  */
9952   __pyx_t_1 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile != NULL);
9953   if (__pyx_t_1) {
9954
9955     /* "csamtools.pyx":987
9956  *         closes the :class:`pysam.Samfile`.'''
9957  *         if self.samfile != NULL:
9958  *             samclose( self.samfile )             # <<<<<<<<<<<<<<
9959  *             bam_index_destroy(self.index);
9960  *             self.samfile = NULL
9961  */
9962     samclose(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile);
9963
9964     /* "csamtools.pyx":988
9965  *         if self.samfile != NULL:
9966  *             samclose( self.samfile )
9967  *             bam_index_destroy(self.index);             # <<<<<<<<<<<<<<
9968  *             self.samfile = NULL
9969  * 
9970  */
9971     bam_index_destroy(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index);
9972
9973     /* "csamtools.pyx":989
9974  *             samclose( self.samfile )
9975  *             bam_index_destroy(self.index);
9976  *             self.samfile = NULL             # <<<<<<<<<<<<<<
9977  * 
9978  *     def __dealloc__( self ):
9979  */
9980     ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile = NULL;
9981     goto __pyx_L5;
9982   }
9983   __pyx_L5:;
9984
9985   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
9986   __Pyx_XGIVEREF(__pyx_r);
9987   __Pyx_TraceReturn(__pyx_r);
9988   __Pyx_RefNannyFinishContext();
9989   return __pyx_r;
9990 }
9991
9992 /* "csamtools.pyx":991
9993  *             self.samfile = NULL
9994  * 
9995  *     def __dealloc__( self ):             # <<<<<<<<<<<<<<
9996  *         # remember: dealloc cannot call other methods
9997  *         # note: no doc string
9998  */
9999
10000 static void __pyx_pf_9csamtools_7Samfile_15__dealloc__(PyObject *__pyx_v_self); /*proto*/
10001 static void __pyx_pf_9csamtools_7Samfile_15__dealloc__(PyObject *__pyx_v_self) {
10002   PyObject *__pyx_t_1 = NULL;
10003   PyObject *__pyx_t_2 = NULL;
10004   int __pyx_t_3;
10005   __Pyx_TraceDeclarations
10006   __Pyx_RefNannySetupContext("__dealloc__");
10007   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 991);
10008
10009   /* "csamtools.pyx":995
10010  *         # note: no doc string
10011  *         # note: __del__ is not called.
10012  *         self.close()             # <<<<<<<<<<<<<<
10013  *         bam_destroy1(self.b)
10014  *         if self._filename != NULL: free( self._filename )
10015  */
10016   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10017   __Pyx_GOTREF(__pyx_t_1);
10018   __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 = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10019   __Pyx_GOTREF(__pyx_t_2);
10020   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10021   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10022
10023   /* "csamtools.pyx":996
10024  *         # note: __del__ is not called.
10025  *         self.close()
10026  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
10027  *         if self._filename != NULL: free( self._filename )
10028  * 
10029  */
10030   bam_destroy1(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->b);
10031
10032   /* "csamtools.pyx":997
10033  *         self.close()
10034  *         bam_destroy1(self.b)
10035  *         if self._filename != NULL: free( self._filename )             # <<<<<<<<<<<<<<
10036  * 
10037  *     cpdef int write( self, AlignedRead read ) except -1:
10038  */
10039   __pyx_t_3 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename != NULL);
10040   if (__pyx_t_3) {
10041     free(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename);
10042     goto __pyx_L5;
10043   }
10044   __pyx_L5:;
10045
10046   goto __pyx_L0;
10047   __pyx_L1_error:;
10048   __Pyx_XDECREF(__pyx_t_1);
10049   __Pyx_XDECREF(__pyx_t_2);
10050   __Pyx_AddTraceback("csamtools.Samfile.__dealloc__");
10051   __pyx_L0:;
10052   __Pyx_TraceReturn(Py_None);
10053   __Pyx_RefNannyFinishContext();
10054 }
10055
10056 /* "csamtools.pyx":999
10057  *         if self._filename != NULL: free( self._filename )
10058  * 
10059  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
10060  *         '''
10061  *         write a single :class:`pysam.AlignedRead` to disk.
10062  */
10063
10064 static PyObject *__pyx_pf_9csamtools_7Samfile_16write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
10065 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) {
10066   int __pyx_r;
10067   PyObject *__pyx_t_1 = NULL;
10068   PyObject *__pyx_t_2 = NULL;
10069   PyObject *__pyx_t_3 = NULL;
10070   int __pyx_t_4;
10071   int __pyx_t_5;
10072   int __pyx_t_6;
10073   __Pyx_TraceDeclarations
10074   __Pyx_RefNannySetupContext("write");
10075   __Pyx_TraceCall("write", __pyx_f[0], 999);
10076   /* Check if called by wrapper */
10077   if (unlikely(__pyx_skip_dispatch)) ;
10078   /* Check if overriden in Python */
10079   else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
10080     __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 = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10081     __Pyx_GOTREF(__pyx_t_1);
10082     if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (void *)&__pyx_pf_9csamtools_7Samfile_16write)) {
10083       __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10084       __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10085       __Pyx_INCREF(((PyObject *)__pyx_v_read));
10086       PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_read));
10087       __Pyx_GIVEREF(((PyObject *)__pyx_v_read));
10088       __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 = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10089       __Pyx_GOTREF(__pyx_t_3);
10090       __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10091       __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 = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10092       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
10093       __pyx_r = __pyx_t_4;
10094       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10095       goto __pyx_L0;
10096     }
10097     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10098   }
10099
10100   /* "csamtools.pyx":1005
10101  *         returns the number of bytes written.
10102  *         '''
10103  *         if not self._isOpen():             # <<<<<<<<<<<<<<
10104  *             return 0
10105  * 
10106  */
10107   __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 = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10108   __Pyx_GOTREF(__pyx_t_1);
10109   __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 = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10110   __Pyx_GOTREF(__pyx_t_3);
10111   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10112   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10113   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
10114   __pyx_t_6 = (!__pyx_t_5);
10115   if (__pyx_t_6) {
10116
10117     /* "csamtools.pyx":1006
10118  *         '''
10119  *         if not self._isOpen():
10120  *             return 0             # <<<<<<<<<<<<<<
10121  * 
10122  *         return samwrite( self.samfile, read._delegate )
10123  */
10124     __pyx_r = 0;
10125     goto __pyx_L0;
10126     goto __pyx_L3;
10127   }
10128   __pyx_L3:;
10129
10130   /* "csamtools.pyx":1008
10131  *             return 0
10132  * 
10133  *         return samwrite( self.samfile, read._delegate )             # <<<<<<<<<<<<<<
10134  * 
10135  *     def __enter__(self):
10136  */
10137   __pyx_r = samwrite(__pyx_v_self->samfile, __pyx_v_read->_delegate);
10138   goto __pyx_L0;
10139
10140   __pyx_r = 0;
10141   goto __pyx_L0;
10142   __pyx_L1_error:;
10143   __Pyx_XDECREF(__pyx_t_1);
10144   __Pyx_XDECREF(__pyx_t_2);
10145   __Pyx_XDECREF(__pyx_t_3);
10146   __Pyx_WriteUnraisable("csamtools.Samfile.write");
10147   __pyx_r = 0;
10148   __pyx_L0:;
10149   __Pyx_TraceReturn(Py_None);
10150   __Pyx_RefNannyFinishContext();
10151   return __pyx_r;
10152 }
10153
10154 /* "csamtools.pyx":999
10155  *         if self._filename != NULL: free( self._filename )
10156  * 
10157  *     cpdef int write( self, AlignedRead read ) except -1:             # <<<<<<<<<<<<<<
10158  *         '''
10159  *         write a single :class:`pysam.AlignedRead` to disk.
10160  */
10161
10162 static PyObject *__pyx_pf_9csamtools_7Samfile_16write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
10163 static char __pyx_doc_9csamtools_7Samfile_16write[] = "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        ";
10164 static PyObject *__pyx_pf_9csamtools_7Samfile_16write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
10165   PyObject *__pyx_r = NULL;
10166   PyObject *__pyx_t_1 = NULL;
10167   __Pyx_TraceDeclarations
10168   __Pyx_RefNannySetupContext("write");
10169   __Pyx_TraceCall("write", __pyx_f[0], 999);
10170   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_9csamtools_AlignedRead, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10171   __Pyx_XDECREF(__pyx_r);
10172   __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_9csamtools_Samfile *)((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->__pyx_vtab)->write(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self), ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_read), 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 999; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10173   __Pyx_GOTREF(__pyx_t_1);
10174   __pyx_r = __pyx_t_1;
10175   __pyx_t_1 = 0;
10176   goto __pyx_L0;
10177
10178   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10179   goto __pyx_L0;
10180   __pyx_L1_error:;
10181   __Pyx_XDECREF(__pyx_t_1);
10182   __Pyx_AddTraceback("csamtools.Samfile.write");
10183   __pyx_r = NULL;
10184   __pyx_L0:;
10185   __Pyx_XGIVEREF(__pyx_r);
10186   __Pyx_TraceReturn(__pyx_r);
10187   __Pyx_RefNannyFinishContext();
10188   return __pyx_r;
10189 }
10190
10191 /* "csamtools.pyx":1010
10192  *         return samwrite( self.samfile, read._delegate )
10193  * 
10194  *     def __enter__(self):             # <<<<<<<<<<<<<<
10195  *         return self
10196  * 
10197  */
10198
10199 static PyObject *__pyx_pf_9csamtools_7Samfile_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
10200 static char __pyx_doc_9csamtools_7Samfile_17__enter__[] = "Samfile.__enter__(self)";
10201 static PyObject *__pyx_pf_9csamtools_7Samfile_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
10202   PyObject *__pyx_r = NULL;
10203   __Pyx_TraceDeclarations
10204   __Pyx_RefNannySetupContext("__enter__");
10205   __Pyx_TraceCall("__enter__", __pyx_f[0], 1010);
10206
10207   /* "csamtools.pyx":1011
10208  * 
10209  *     def __enter__(self):
10210  *         return self             # <<<<<<<<<<<<<<
10211  * 
10212  *     def __exit__(self, exc_type, exc_value, traceback):
10213  */
10214   __Pyx_XDECREF(__pyx_r);
10215   __Pyx_INCREF(__pyx_v_self);
10216   __pyx_r = __pyx_v_self;
10217   goto __pyx_L0;
10218
10219   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10220   __pyx_L0:;
10221   __Pyx_XGIVEREF(__pyx_r);
10222   __Pyx_TraceReturn(__pyx_r);
10223   __Pyx_RefNannyFinishContext();
10224   return __pyx_r;
10225 }
10226
10227 /* "csamtools.pyx":1013
10228  *         return self
10229  * 
10230  *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
10231  *         self.close()
10232  *         return False
10233  */
10234
10235 static PyObject *__pyx_pf_9csamtools_7Samfile_18__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
10236 static char __pyx_doc_9csamtools_7Samfile_18__exit__[] = "Samfile.__exit__(self, exc_type, exc_value, traceback)";
10237 static PyObject *__pyx_pf_9csamtools_7Samfile_18__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
10238   PyObject *__pyx_v_exc_type = 0;
10239   PyObject *__pyx_v_exc_value = 0;
10240   PyObject *__pyx_v_traceback = 0;
10241   PyObject *__pyx_r = NULL;
10242   PyObject *__pyx_t_1 = NULL;
10243   PyObject *__pyx_t_2 = NULL;
10244   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__exc_type,&__pyx_n_s__exc_value,&__pyx_n_s__traceback,0};
10245   __Pyx_TraceDeclarations
10246   __Pyx_RefNannySetupContext("__exit__");
10247   __Pyx_TraceCall("__exit__", __pyx_f[0], 1013);
10248   if (unlikely(__pyx_kwds)) {
10249     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
10250     PyObject* values[3] = {0,0,0};
10251     switch (PyTuple_GET_SIZE(__pyx_args)) {
10252       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
10253       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
10254       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
10255       case  0: break;
10256       default: goto __pyx_L5_argtuple_error;
10257     }
10258     switch (PyTuple_GET_SIZE(__pyx_args)) {
10259       case  0:
10260       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_type);
10261       if (likely(values[0])) kw_args--;
10262       else goto __pyx_L5_argtuple_error;
10263       case  1:
10264       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_value);
10265       if (likely(values[1])) kw_args--;
10266       else {
10267         __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10268       }
10269       case  2:
10270       values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__traceback);
10271       if (likely(values[2])) kw_args--;
10272       else {
10273         __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10274       }
10275     }
10276     if (unlikely(kw_args > 0)) {
10277       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10278     }
10279     __pyx_v_exc_type = values[0];
10280     __pyx_v_exc_value = values[1];
10281     __pyx_v_traceback = values[2];
10282   } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
10283     goto __pyx_L5_argtuple_error;
10284   } else {
10285     __pyx_v_exc_type = PyTuple_GET_ITEM(__pyx_args, 0);
10286     __pyx_v_exc_value = PyTuple_GET_ITEM(__pyx_args, 1);
10287     __pyx_v_traceback = PyTuple_GET_ITEM(__pyx_args, 2);
10288   }
10289   goto __pyx_L4_argument_unpacking_done;
10290   __pyx_L5_argtuple_error:;
10291   __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
10292   __pyx_L3_error:;
10293   __Pyx_AddTraceback("csamtools.Samfile.__exit__");
10294   __Pyx_RefNannyFinishContext();
10295   return NULL;
10296   __pyx_L4_argument_unpacking_done:;
10297
10298   /* "csamtools.pyx":1014
10299  * 
10300  *     def __exit__(self, exc_type, exc_value, traceback):
10301  *         self.close()             # <<<<<<<<<<<<<<
10302  *         return False
10303  * 
10304  */
10305   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__close); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10306   __Pyx_GOTREF(__pyx_t_1);
10307   __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10308   __Pyx_GOTREF(__pyx_t_2);
10309   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10310   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10311
10312   /* "csamtools.pyx":1015
10313  *     def __exit__(self, exc_type, exc_value, traceback):
10314  *         self.close()
10315  *         return False             # <<<<<<<<<<<<<<
10316  * 
10317  *     ###############################################################
10318  */
10319   __Pyx_XDECREF(__pyx_r);
10320   __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10321   __Pyx_GOTREF(__pyx_t_2);
10322   __pyx_r = __pyx_t_2;
10323   __pyx_t_2 = 0;
10324   goto __pyx_L0;
10325
10326   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10327   goto __pyx_L0;
10328   __pyx_L1_error:;
10329   __Pyx_XDECREF(__pyx_t_1);
10330   __Pyx_XDECREF(__pyx_t_2);
10331   __Pyx_AddTraceback("csamtools.Samfile.__exit__");
10332   __pyx_r = NULL;
10333   __pyx_L0:;
10334   __Pyx_XGIVEREF(__pyx_r);
10335   __Pyx_TraceReturn(__pyx_r);
10336   __Pyx_RefNannyFinishContext();
10337   return __pyx_r;
10338 }
10339
10340 /* "csamtools.pyx":1024
10341  *     property filename:
10342  *         '''number of :term:`filename` associated with this object.'''
10343  *         def __get__(self):             # <<<<<<<<<<<<<<
10344  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10345  *             return self._filename
10346  */
10347
10348 static PyObject *__pyx_pf_9csamtools_7Samfile_8filename___get__(PyObject *__pyx_v_self); /*proto*/
10349 static PyObject *__pyx_pf_9csamtools_7Samfile_8filename___get__(PyObject *__pyx_v_self) {
10350   PyObject *__pyx_r = NULL;
10351   PyObject *__pyx_t_1 = NULL;
10352   PyObject *__pyx_t_2 = NULL;
10353   int __pyx_t_3;
10354   int __pyx_t_4;
10355   __Pyx_TraceDeclarations
10356   __Pyx_RefNannySetupContext("__get__");
10357   __Pyx_TraceCall("__get__", __pyx_f[0], 1024);
10358
10359   /* "csamtools.pyx":1025
10360  *         '''number of :term:`filename` associated with this object.'''
10361  *         def __get__(self):
10362  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10363  *             return self._filename
10364  * 
10365  */
10366   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10367   __Pyx_GOTREF(__pyx_t_1);
10368   __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 = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10369   __Pyx_GOTREF(__pyx_t_2);
10370   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10371   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10372   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10373   __pyx_t_4 = (!__pyx_t_3);
10374   if (__pyx_t_4) {
10375     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_76), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10376     __Pyx_GOTREF(__pyx_t_2);
10377     __Pyx_Raise(__pyx_t_2, 0, 0);
10378     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10379     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10380     goto __pyx_L5;
10381   }
10382   __pyx_L5:;
10383
10384   /* "csamtools.pyx":1026
10385  *         def __get__(self):
10386  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10387  *             return self._filename             # <<<<<<<<<<<<<<
10388  * 
10389  *     property nreferences:
10390  */
10391   __Pyx_XDECREF(__pyx_r);
10392   __pyx_t_2 = PyBytes_FromString(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10393   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10394   __pyx_r = ((PyObject *)__pyx_t_2);
10395   __pyx_t_2 = 0;
10396   goto __pyx_L0;
10397
10398   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10399   goto __pyx_L0;
10400   __pyx_L1_error:;
10401   __Pyx_XDECREF(__pyx_t_1);
10402   __Pyx_XDECREF(__pyx_t_2);
10403   __Pyx_AddTraceback("csamtools.Samfile.filename.__get__");
10404   __pyx_r = NULL;
10405   __pyx_L0:;
10406   __Pyx_XGIVEREF(__pyx_r);
10407   __Pyx_TraceReturn(__pyx_r);
10408   __Pyx_RefNannyFinishContext();
10409   return __pyx_r;
10410 }
10411
10412 /* "csamtools.pyx":1030
10413  *     property nreferences:
10414  *         '''number of :term:`reference` sequences in the file.'''
10415  *         def __get__(self):             # <<<<<<<<<<<<<<
10416  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10417  *             return self.samfile.header.n_targets
10418  */
10419
10420 static PyObject *__pyx_pf_9csamtools_7Samfile_11nreferences___get__(PyObject *__pyx_v_self); /*proto*/
10421 static PyObject *__pyx_pf_9csamtools_7Samfile_11nreferences___get__(PyObject *__pyx_v_self) {
10422   PyObject *__pyx_r = NULL;
10423   PyObject *__pyx_t_1 = NULL;
10424   PyObject *__pyx_t_2 = NULL;
10425   int __pyx_t_3;
10426   int __pyx_t_4;
10427   __Pyx_TraceDeclarations
10428   __Pyx_RefNannySetupContext("__get__");
10429   __Pyx_TraceCall("__get__", __pyx_f[0], 1030);
10430
10431   /* "csamtools.pyx":1031
10432  *         '''number of :term:`reference` sequences in the file.'''
10433  *         def __get__(self):
10434  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10435  *             return self.samfile.header.n_targets
10436  * 
10437  */
10438   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10439   __Pyx_GOTREF(__pyx_t_1);
10440   __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 = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10441   __Pyx_GOTREF(__pyx_t_2);
10442   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10443   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10444   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10445   __pyx_t_4 = (!__pyx_t_3);
10446   if (__pyx_t_4) {
10447     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_77), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10448     __Pyx_GOTREF(__pyx_t_2);
10449     __Pyx_Raise(__pyx_t_2, 0, 0);
10450     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10451     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10452     goto __pyx_L5;
10453   }
10454   __pyx_L5:;
10455
10456   /* "csamtools.pyx":1032
10457  *         def __get__(self):
10458  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10459  *             return self.samfile.header.n_targets             # <<<<<<<<<<<<<<
10460  * 
10461  *     property references:
10462  */
10463   __Pyx_XDECREF(__pyx_r);
10464   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10465   __Pyx_GOTREF(__pyx_t_2);
10466   __pyx_r = __pyx_t_2;
10467   __pyx_t_2 = 0;
10468   goto __pyx_L0;
10469
10470   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10471   goto __pyx_L0;
10472   __pyx_L1_error:;
10473   __Pyx_XDECREF(__pyx_t_1);
10474   __Pyx_XDECREF(__pyx_t_2);
10475   __Pyx_AddTraceback("csamtools.Samfile.nreferences.__get__");
10476   __pyx_r = NULL;
10477   __pyx_L0:;
10478   __Pyx_XGIVEREF(__pyx_r);
10479   __Pyx_TraceReturn(__pyx_r);
10480   __Pyx_RefNannyFinishContext();
10481   return __pyx_r;
10482 }
10483
10484 /* "csamtools.pyx":1036
10485  *     property references:
10486  *         """tuple with the names of :term:`reference` sequences."""
10487  *         def __get__(self):             # <<<<<<<<<<<<<<
10488  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10489  *             t = []
10490  */
10491
10492 static PyObject *__pyx_pf_9csamtools_7Samfile_10references___get__(PyObject *__pyx_v_self); /*proto*/
10493 static PyObject *__pyx_pf_9csamtools_7Samfile_10references___get__(PyObject *__pyx_v_self) {
10494   PyObject *__pyx_v_t;
10495   long __pyx_v_x;
10496   PyObject *__pyx_r = NULL;
10497   PyObject *__pyx_t_1 = NULL;
10498   PyObject *__pyx_t_2 = NULL;
10499   int __pyx_t_3;
10500   int __pyx_t_4;
10501   int32_t __pyx_t_5;
10502   int __pyx_t_6;
10503   __Pyx_TraceDeclarations
10504   __Pyx_RefNannySetupContext("__get__");
10505   __Pyx_TraceCall("__get__", __pyx_f[0], 1036);
10506   __pyx_v_t = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
10507
10508   /* "csamtools.pyx":1037
10509  *         """tuple with the names of :term:`reference` sequences."""
10510  *         def __get__(self):
10511  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10512  *             t = []
10513  *             for x from 0 <= x < self.samfile.header.n_targets:
10514  */
10515   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10516   __Pyx_GOTREF(__pyx_t_1);
10517   __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 = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10518   __Pyx_GOTREF(__pyx_t_2);
10519   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10520   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10521   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10522   __pyx_t_4 = (!__pyx_t_3);
10523   if (__pyx_t_4) {
10524     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_78), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10525     __Pyx_GOTREF(__pyx_t_2);
10526     __Pyx_Raise(__pyx_t_2, 0, 0);
10527     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10528     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10529     goto __pyx_L5;
10530   }
10531   __pyx_L5:;
10532
10533   /* "csamtools.pyx":1038
10534  *         def __get__(self):
10535  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10536  *             t = []             # <<<<<<<<<<<<<<
10537  *             for x from 0 <= x < self.samfile.header.n_targets:
10538  *                 t.append( self.samfile.header.target_name[x] )
10539  */
10540   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10541   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10542   __Pyx_DECREF(((PyObject *)__pyx_v_t));
10543   __pyx_v_t = __pyx_t_2;
10544   __pyx_t_2 = 0;
10545
10546   /* "csamtools.pyx":1039
10547  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10548  *             t = []
10549  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
10550  *                 t.append( self.samfile.header.target_name[x] )
10551  *             return tuple(t)
10552  */
10553   __pyx_t_5 = ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
10554   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
10555
10556     /* "csamtools.pyx":1040
10557  *             t = []
10558  *             for x from 0 <= x < self.samfile.header.n_targets:
10559  *                 t.append( self.samfile.header.target_name[x] )             # <<<<<<<<<<<<<<
10560  *             return tuple(t)
10561  * 
10562  */
10563     if (unlikely(__pyx_v_t == Py_None)) {
10564       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
10565     }
10566     __pyx_t_2 = PyBytes_FromString((((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10567     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10568     __pyx_t_6 = PyList_Append(__pyx_v_t, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10569     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
10570   }
10571
10572   /* "csamtools.pyx":1041
10573  *             for x from 0 <= x < self.samfile.header.n_targets:
10574  *                 t.append( self.samfile.header.target_name[x] )
10575  *             return tuple(t)             # <<<<<<<<<<<<<<
10576  * 
10577  *     property lengths:
10578  */
10579   __Pyx_XDECREF(__pyx_r);
10580   if (unlikely(__pyx_v_t == Py_None)) {
10581     PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
10582   }
10583   __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10584   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10585   __pyx_r = ((PyObject *)__pyx_t_2);
10586   __pyx_t_2 = 0;
10587   goto __pyx_L0;
10588
10589   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10590   goto __pyx_L0;
10591   __pyx_L1_error:;
10592   __Pyx_XDECREF(__pyx_t_1);
10593   __Pyx_XDECREF(__pyx_t_2);
10594   __Pyx_AddTraceback("csamtools.Samfile.references.__get__");
10595   __pyx_r = NULL;
10596   __pyx_L0:;
10597   __Pyx_DECREF(__pyx_v_t);
10598   __Pyx_XGIVEREF(__pyx_r);
10599   __Pyx_TraceReturn(__pyx_r);
10600   __Pyx_RefNannyFinishContext();
10601   return __pyx_r;
10602 }
10603
10604 /* "csamtools.pyx":1047
10605  *         :attr:`pysam.Samfile.references`
10606  *         """
10607  *         def __get__(self):             # <<<<<<<<<<<<<<
10608  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10609  *             t = []
10610  */
10611
10612 static PyObject *__pyx_pf_9csamtools_7Samfile_7lengths___get__(PyObject *__pyx_v_self); /*proto*/
10613 static PyObject *__pyx_pf_9csamtools_7Samfile_7lengths___get__(PyObject *__pyx_v_self) {
10614   PyObject *__pyx_v_t;
10615   long __pyx_v_x;
10616   PyObject *__pyx_r = NULL;
10617   PyObject *__pyx_t_1 = NULL;
10618   PyObject *__pyx_t_2 = NULL;
10619   int __pyx_t_3;
10620   int __pyx_t_4;
10621   int32_t __pyx_t_5;
10622   int __pyx_t_6;
10623   __Pyx_TraceDeclarations
10624   __Pyx_RefNannySetupContext("__get__");
10625   __Pyx_TraceCall("__get__", __pyx_f[0], 1047);
10626   __pyx_v_t = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
10627
10628   /* "csamtools.pyx":1048
10629  *         """
10630  *         def __get__(self):
10631  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10632  *             t = []
10633  *             for x from 0 <= x < self.samfile.header.n_targets:
10634  */
10635   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10636   __Pyx_GOTREF(__pyx_t_1);
10637   __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 = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10638   __Pyx_GOTREF(__pyx_t_2);
10639   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10640   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10641   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10642   __pyx_t_4 = (!__pyx_t_3);
10643   if (__pyx_t_4) {
10644     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_79), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10645     __Pyx_GOTREF(__pyx_t_2);
10646     __Pyx_Raise(__pyx_t_2, 0, 0);
10647     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10648     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10649     goto __pyx_L5;
10650   }
10651   __pyx_L5:;
10652
10653   /* "csamtools.pyx":1049
10654  *         def __get__(self):
10655  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10656  *             t = []             # <<<<<<<<<<<<<<
10657  *             for x from 0 <= x < self.samfile.header.n_targets:
10658  *                 t.append( self.samfile.header.target_len[x] )
10659  */
10660   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10661   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10662   __Pyx_DECREF(((PyObject *)__pyx_v_t));
10663   __pyx_v_t = __pyx_t_2;
10664   __pyx_t_2 = 0;
10665
10666   /* "csamtools.pyx":1050
10667  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10668  *             t = []
10669  *             for x from 0 <= x < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
10670  *                 t.append( self.samfile.header.target_len[x] )
10671  *             return tuple(t)
10672  */
10673   __pyx_t_5 = ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
10674   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_5; __pyx_v_x++) {
10675
10676     /* "csamtools.pyx":1051
10677  *             t = []
10678  *             for x from 0 <= x < self.samfile.header.n_targets:
10679  *                 t.append( self.samfile.header.target_len[x] )             # <<<<<<<<<<<<<<
10680  *             return tuple(t)
10681  * 
10682  */
10683     if (unlikely(__pyx_v_t == Py_None)) {
10684       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
10685     }
10686     __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t((((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10687     __Pyx_GOTREF(__pyx_t_2);
10688     __pyx_t_6 = PyList_Append(__pyx_v_t, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10689     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10690   }
10691
10692   /* "csamtools.pyx":1052
10693  *             for x from 0 <= x < self.samfile.header.n_targets:
10694  *                 t.append( self.samfile.header.target_len[x] )
10695  *             return tuple(t)             # <<<<<<<<<<<<<<
10696  * 
10697  *     property mapped:
10698  */
10699   __Pyx_XDECREF(__pyx_r);
10700   if (unlikely(__pyx_v_t == Py_None)) {
10701     PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
10702   }
10703   __pyx_t_2 = ((PyObject *)PyList_AsTuple(__pyx_v_t)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10704   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
10705   __pyx_r = ((PyObject *)__pyx_t_2);
10706   __pyx_t_2 = 0;
10707   goto __pyx_L0;
10708
10709   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10710   goto __pyx_L0;
10711   __pyx_L1_error:;
10712   __Pyx_XDECREF(__pyx_t_1);
10713   __Pyx_XDECREF(__pyx_t_2);
10714   __Pyx_AddTraceback("csamtools.Samfile.lengths.__get__");
10715   __pyx_r = NULL;
10716   __pyx_L0:;
10717   __Pyx_DECREF(__pyx_v_t);
10718   __Pyx_XGIVEREF(__pyx_r);
10719   __Pyx_TraceReturn(__pyx_r);
10720   __Pyx_RefNannyFinishContext();
10721   return __pyx_r;
10722 }
10723
10724 /* "csamtools.pyx":1057
10725  *         """total number of mapped reads in file.
10726  *         """
10727  *         def __get__(self):             # <<<<<<<<<<<<<<
10728  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10729  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
10730  */
10731
10732 static PyObject *__pyx_pf_9csamtools_7Samfile_6mapped___get__(PyObject *__pyx_v_self); /*proto*/
10733 static PyObject *__pyx_pf_9csamtools_7Samfile_6mapped___get__(PyObject *__pyx_v_self) {
10734   int __pyx_v_tid;
10735   uint32_t __pyx_v_total;
10736   PyObject *__pyx_r = NULL;
10737   PyObject *__pyx_t_1 = NULL;
10738   PyObject *__pyx_t_2 = NULL;
10739   int __pyx_t_3;
10740   int __pyx_t_4;
10741   int32_t __pyx_t_5;
10742   __Pyx_TraceDeclarations
10743   __Pyx_RefNannySetupContext("__get__");
10744   __Pyx_TraceCall("__get__", __pyx_f[0], 1057);
10745
10746   /* "csamtools.pyx":1058
10747  *         """
10748  *         def __get__(self):
10749  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10750  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
10751  * 
10752  */
10753   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10754   __Pyx_GOTREF(__pyx_t_1);
10755   __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 = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10756   __Pyx_GOTREF(__pyx_t_2);
10757   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10758   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10759   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10760   __pyx_t_4 = (!__pyx_t_3);
10761   if (__pyx_t_4) {
10762     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_80), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10763     __Pyx_GOTREF(__pyx_t_2);
10764     __Pyx_Raise(__pyx_t_2, 0, 0);
10765     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10766     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10767     goto __pyx_L5;
10768   }
10769   __pyx_L5:;
10770
10771   /* "csamtools.pyx":1059
10772  *         def __get__(self):
10773  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10774  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
10775  * 
10776  *             cdef int tid
10777  */
10778   __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam);
10779   if (__pyx_t_4) {
10780     __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_82), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10781     __Pyx_GOTREF(__pyx_t_2);
10782     __Pyx_Raise(__pyx_t_2, 0, 0);
10783     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10784     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10785     goto __pyx_L6;
10786   }
10787   __pyx_L6:;
10788
10789   /* "csamtools.pyx":1062
10790  * 
10791  *             cdef int tid
10792  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
10793  *             for tid from 0 <= tid < self.samfile.header.n_targets:
10794  *                 total += pysam_get_mapped( self.index, tid )
10795  */
10796   __pyx_v_total = 0;
10797
10798   /* "csamtools.pyx":1063
10799  *             cdef int tid
10800  *             cdef uint32_t total = 0
10801  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
10802  *                 total += pysam_get_mapped( self.index, tid )
10803  *             return total
10804  */
10805   __pyx_t_5 = ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
10806   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
10807
10808     /* "csamtools.pyx":1064
10809  *             cdef uint32_t total = 0
10810  *             for tid from 0 <= tid < self.samfile.header.n_targets:
10811  *                 total += pysam_get_mapped( self.index, tid )             # <<<<<<<<<<<<<<
10812  *             return total
10813  * 
10814  */
10815     __pyx_v_total = (__pyx_v_total + pysam_get_mapped(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_tid));
10816   }
10817
10818   /* "csamtools.pyx":1065
10819  *             for tid from 0 <= tid < self.samfile.header.n_targets:
10820  *                 total += pysam_get_mapped( self.index, tid )
10821  *             return total             # <<<<<<<<<<<<<<
10822  * 
10823  *     property unmapped:
10824  */
10825   __Pyx_XDECREF(__pyx_r);
10826   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10827   __Pyx_GOTREF(__pyx_t_2);
10828   __pyx_r = __pyx_t_2;
10829   __pyx_t_2 = 0;
10830   goto __pyx_L0;
10831
10832   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10833   goto __pyx_L0;
10834   __pyx_L1_error:;
10835   __Pyx_XDECREF(__pyx_t_1);
10836   __Pyx_XDECREF(__pyx_t_2);
10837   __Pyx_AddTraceback("csamtools.Samfile.mapped.__get__");
10838   __pyx_r = NULL;
10839   __pyx_L0:;
10840   __Pyx_XGIVEREF(__pyx_r);
10841   __Pyx_TraceReturn(__pyx_r);
10842   __Pyx_RefNannyFinishContext();
10843   return __pyx_r;
10844 }
10845
10846 /* "csamtools.pyx":1070
10847  *         """total number of unmapped reads in file.
10848  *         """
10849  *         def __get__(self):             # <<<<<<<<<<<<<<
10850  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10851  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
10852  */
10853
10854 static PyObject *__pyx_pf_9csamtools_7Samfile_8unmapped___get__(PyObject *__pyx_v_self); /*proto*/
10855 static PyObject *__pyx_pf_9csamtools_7Samfile_8unmapped___get__(PyObject *__pyx_v_self) {
10856   int __pyx_v_tid;
10857   uint32_t __pyx_v_total;
10858   PyObject *__pyx_r = NULL;
10859   PyObject *__pyx_t_1 = NULL;
10860   PyObject *__pyx_t_2 = NULL;
10861   int __pyx_t_3;
10862   int __pyx_t_4;
10863   int32_t __pyx_t_5;
10864   __Pyx_TraceDeclarations
10865   __Pyx_RefNannySetupContext("__get__");
10866   __Pyx_TraceCall("__get__", __pyx_f[0], 1070);
10867
10868   /* "csamtools.pyx":1071
10869  *         """
10870  *         def __get__(self):
10871  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
10872  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
10873  *             cdef int tid
10874  */
10875   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10876   __Pyx_GOTREF(__pyx_t_1);
10877   __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 = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10878   __Pyx_GOTREF(__pyx_t_2);
10879   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
10880   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10881   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10882   __pyx_t_4 = (!__pyx_t_3);
10883   if (__pyx_t_4) {
10884     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_83), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10885     __Pyx_GOTREF(__pyx_t_2);
10886     __Pyx_Raise(__pyx_t_2, 0, 0);
10887     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10888     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10889     goto __pyx_L5;
10890   }
10891   __pyx_L5:;
10892
10893   /* "csamtools.pyx":1072
10894  *         def __get__(self):
10895  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10896  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
10897  *             cdef int tid
10898  *             cdef uint32_t total = 0
10899  */
10900   __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam);
10901   if (__pyx_t_4) {
10902     __pyx_t_2 = PyObject_Call(__pyx_builtin_AttributeError, ((PyObject *)__pyx_k_tuple_85), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10903     __Pyx_GOTREF(__pyx_t_2);
10904     __Pyx_Raise(__pyx_t_2, 0, 0);
10905     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
10906     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10907     goto __pyx_L6;
10908   }
10909   __pyx_L6:;
10910
10911   /* "csamtools.pyx":1074
10912  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
10913  *             cdef int tid
10914  *             cdef uint32_t total = 0             # <<<<<<<<<<<<<<
10915  *             for tid from 0 <= tid < self.samfile.header.n_targets:
10916  *                 total += pysam_get_unmapped( self.index, tid )
10917  */
10918   __pyx_v_total = 0;
10919
10920   /* "csamtools.pyx":1075
10921  *             cdef int tid
10922  *             cdef uint32_t total = 0
10923  *             for tid from 0 <= tid < self.samfile.header.n_targets:             # <<<<<<<<<<<<<<
10924  *                 total += pysam_get_unmapped( self.index, tid )
10925  *             # get unmapped reads without coordinates
10926  */
10927   __pyx_t_5 = ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets;
10928   for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {
10929
10930     /* "csamtools.pyx":1076
10931  *             cdef uint32_t total = 0
10932  *             for tid from 0 <= tid < self.samfile.header.n_targets:
10933  *                 total += pysam_get_unmapped( self.index, tid )             # <<<<<<<<<<<<<<
10934  *             # get unmapped reads without coordinates
10935  *             total += pysam_get_unmapped( self.index, -1 )
10936  */
10937     __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, __pyx_v_tid));
10938   }
10939
10940   /* "csamtools.pyx":1078
10941  *                 total += pysam_get_unmapped( self.index, tid )
10942  *             # get unmapped reads without coordinates
10943  *             total += pysam_get_unmapped( self.index, -1 )             # <<<<<<<<<<<<<<
10944  *             return total
10945  * 
10946  */
10947   __pyx_v_total = (__pyx_v_total + pysam_get_unmapped(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->index, -1));
10948
10949   /* "csamtools.pyx":1079
10950  *             # get unmapped reads without coordinates
10951  *             total += pysam_get_unmapped( self.index, -1 )
10952  *             return total             # <<<<<<<<<<<<<<
10953  * 
10954  *     property text:
10955  */
10956   __Pyx_XDECREF(__pyx_r);
10957   __pyx_t_2 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_total); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
10958   __Pyx_GOTREF(__pyx_t_2);
10959   __pyx_r = __pyx_t_2;
10960   __pyx_t_2 = 0;
10961   goto __pyx_L0;
10962
10963   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
10964   goto __pyx_L0;
10965   __pyx_L1_error:;
10966   __Pyx_XDECREF(__pyx_t_1);
10967   __Pyx_XDECREF(__pyx_t_2);
10968   __Pyx_AddTraceback("csamtools.Samfile.unmapped.__get__");
10969   __pyx_r = NULL;
10970   __pyx_L0:;
10971   __Pyx_XGIVEREF(__pyx_r);
10972   __Pyx_TraceReturn(__pyx_r);
10973   __Pyx_RefNannyFinishContext();
10974   return __pyx_r;
10975 }
10976
10977 /* "csamtools.pyx":1083
10978  *     property text:
10979  *         '''full contents of the :term:`sam file` header as a string.'''
10980  *         def __get__(self):             # <<<<<<<<<<<<<<
10981  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
10982  *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)
10983  */
10984
10985 static PyObject *__pyx_pf_9csamtools_7Samfile_4text___get__(PyObject *__pyx_v_self); /*proto*/
10986 static PyObject *__pyx_pf_9csamtools_7Samfile_4text___get__(PyObject *__pyx_v_self) {
10987   PyObject *__pyx_r = NULL;
10988   PyObject *__pyx_t_1 = NULL;
10989   PyObject *__pyx_t_2 = NULL;
10990   int __pyx_t_3;
10991   int __pyx_t_4;
10992   __Pyx_TraceDeclarations
10993   __Pyx_RefNannySetupContext("__get__");
10994   __Pyx_TraceCall("__get__", __pyx_f[0], 1083);
10995
10996   /* "csamtools.pyx":1084
10997  *         '''full contents of the :term:`sam file` header as a string.'''
10998  *         def __get__(self):
10999  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
11000  *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)
11001  * 
11002  */
11003   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11004   __Pyx_GOTREF(__pyx_t_1);
11005   __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 = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11006   __Pyx_GOTREF(__pyx_t_2);
11007   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11008   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11009   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11010   __pyx_t_4 = (!__pyx_t_3);
11011   if (__pyx_t_4) {
11012     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_86), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11013     __Pyx_GOTREF(__pyx_t_2);
11014     __Pyx_Raise(__pyx_t_2, 0, 0);
11015     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11016     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11017     goto __pyx_L5;
11018   }
11019   __pyx_L5:;
11020
11021   /* "csamtools.pyx":1085
11022  *         def __get__(self):
11023  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
11024  *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)             # <<<<<<<<<<<<<<
11025  * 
11026  *     property header:
11027  */
11028   __Pyx_XDECREF(__pyx_r);
11029   __pyx_t_2 = PyString_FromStringAndSize(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->text, ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->l_text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11030   __Pyx_GOTREF(__pyx_t_2);
11031   __pyx_r = __pyx_t_2;
11032   __pyx_t_2 = 0;
11033   goto __pyx_L0;
11034
11035   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
11036   goto __pyx_L0;
11037   __pyx_L1_error:;
11038   __Pyx_XDECREF(__pyx_t_1);
11039   __Pyx_XDECREF(__pyx_t_2);
11040   __Pyx_AddTraceback("csamtools.Samfile.text.__get__");
11041   __pyx_r = NULL;
11042   __pyx_L0:;
11043   __Pyx_XGIVEREF(__pyx_r);
11044   __Pyx_TraceReturn(__pyx_r);
11045   __Pyx_RefNannyFinishContext();
11046   return __pyx_r;
11047 }
11048
11049 /* "csamtools.pyx":1091
11050  *         a two-level dictionary.
11051  *         '''
11052  *         def __get__(self):             # <<<<<<<<<<<<<<
11053  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
11054  * 
11055  */
11056
11057 static PyObject *__pyx_pf_9csamtools_7Samfile_6header___get__(PyObject *__pyx_v_self); /*proto*/
11058 static PyObject *__pyx_pf_9csamtools_7Samfile_6header___get__(PyObject *__pyx_v_self) {
11059   PyObject *__pyx_v_result;
11060   PyObject *__pyx_v_t;
11061   PyObject *__pyx_v_line;
11062   PyObject *__pyx_v_fields;
11063   PyObject *__pyx_v_record;
11064   PyObject *__pyx_v_x;
11065   PyObject *__pyx_v_field;
11066   PyObject *__pyx_v_key;
11067   PyObject *__pyx_v_value;
11068   PyObject *__pyx_r = NULL;
11069   PyObject *__pyx_t_1 = NULL;
11070   PyObject *__pyx_t_2 = NULL;
11071   int __pyx_t_3;
11072   int __pyx_t_4;
11073   Py_ssize_t __pyx_t_5;
11074   PyObject *__pyx_t_6 = NULL;
11075   PyObject *__pyx_t_7 = NULL;
11076   PyObject *__pyx_t_8 = NULL;
11077   Py_ssize_t __pyx_t_9;
11078   PyObject *__pyx_t_10 = NULL;
11079   __Pyx_TraceDeclarations
11080   __Pyx_RefNannySetupContext("__get__");
11081   __Pyx_TraceCall("__get__", __pyx_f[0], 1091);
11082   __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
11083   __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);
11084   __pyx_v_line = Py_None; __Pyx_INCREF(Py_None);
11085   __pyx_v_fields = Py_None; __Pyx_INCREF(Py_None);
11086   __pyx_v_record = Py_None; __Pyx_INCREF(Py_None);
11087   __pyx_v_x = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
11088   __pyx_v_field = Py_None; __Pyx_INCREF(Py_None);
11089   __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
11090   __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
11091
11092   /* "csamtools.pyx":1092
11093  *         '''
11094  *         def __get__(self):
11095  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
11096  * 
11097  *             result = {}
11098  */
11099   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11100   __Pyx_GOTREF(__pyx_t_1);
11101   __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 = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11102   __Pyx_GOTREF(__pyx_t_2);
11103   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11104   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11105   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11106   __pyx_t_4 = (!__pyx_t_3);
11107   if (__pyx_t_4) {
11108     __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 = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11109     __Pyx_GOTREF(__pyx_t_2);
11110     __Pyx_Raise(__pyx_t_2, 0, 0);
11111     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11112     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11113     goto __pyx_L5;
11114   }
11115   __pyx_L5:;
11116
11117   /* "csamtools.pyx":1094
11118  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
11119  * 
11120  *             result = {}             # <<<<<<<<<<<<<<
11121  * 
11122  *             if self.samfile.header.text != NULL:
11123  */
11124   __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1094; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11125   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
11126   __Pyx_DECREF(((PyObject *)__pyx_v_result));
11127   __pyx_v_result = __pyx_t_2;
11128   __pyx_t_2 = 0;
11129
11130   /* "csamtools.pyx":1096
11131  *             result = {}
11132  * 
11133  *             if self.samfile.header.text != NULL:             # <<<<<<<<<<<<<<
11134  *                 # convert to python string (note: call self.text to create 0-terminated string)
11135  *                 t = self.text
11136  */
11137   __pyx_t_4 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->text != NULL);
11138   if (__pyx_t_4) {
11139
11140     /* "csamtools.pyx":1098
11141  *             if self.samfile.header.text != NULL:
11142  *                 # convert to python string (note: call self.text to create 0-terminated string)
11143  *                 t = self.text             # <<<<<<<<<<<<<<
11144  *                 for line in t.split("\n"):
11145  *                     if not line.strip(): continue
11146  */
11147     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__text); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11148     __Pyx_GOTREF(__pyx_t_2);
11149     __Pyx_DECREF(__pyx_v_t);
11150     __pyx_v_t = __pyx_t_2;
11151     __pyx_t_2 = 0;
11152
11153     /* "csamtools.pyx":1099
11154  *                 # convert to python string (note: call self.text to create 0-terminated string)
11155  *                 t = self.text
11156  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
11157  *                     if not line.strip(): continue
11158  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
11159  */
11160     __pyx_t_2 = PyObject_GetAttr(__pyx_v_t, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11161     __Pyx_GOTREF(__pyx_t_2);
11162     __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_88), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11163     __Pyx_GOTREF(__pyx_t_1);
11164     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11165     if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
11166       __pyx_t_5 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
11167     } else {
11168       __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11169       __Pyx_GOTREF(__pyx_t_2);
11170     }
11171     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11172     for (;;) {
11173       if (likely(PyList_CheckExact(__pyx_t_2))) {
11174         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
11175         __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11176       } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
11177         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
11178         __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11179       } else {
11180         __pyx_t_1 = PyIter_Next(__pyx_t_2);
11181         if (!__pyx_t_1) {
11182           if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11183           break;
11184         }
11185         __Pyx_GOTREF(__pyx_t_1);
11186       }
11187       __Pyx_DECREF(__pyx_v_line);
11188       __pyx_v_line = __pyx_t_1;
11189       __pyx_t_1 = 0;
11190
11191       /* "csamtools.pyx":1100
11192  *                 t = self.text
11193  *                 for line in t.split("\n"):
11194  *                     if not line.strip(): continue             # <<<<<<<<<<<<<<
11195  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
11196  *                     fields = line[1:].split("\t")
11197  */
11198       __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11199       __Pyx_GOTREF(__pyx_t_1);
11200       __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11201       __Pyx_GOTREF(__pyx_t_6);
11202       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11203       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11204       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11205       __pyx_t_3 = (!__pyx_t_4);
11206       if (__pyx_t_3) {
11207         goto __pyx_L7_continue;
11208         goto __pyx_L9;
11209       }
11210       __pyx_L9:;
11211
11212       /* "csamtools.pyx":1101
11213  *                 for line in t.split("\n"):
11214  *                     if not line.strip(): continue
11215  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
11216  *                     fields = line[1:].split("\t")
11217  *                     record = fields[0]
11218  */
11219       #ifndef CYTHON_WITHOUT_ASSERTIONS
11220       __pyx_t_6 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__startswith); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11221       __Pyx_GOTREF(__pyx_t_6);
11222       __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_90), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11223       __Pyx_GOTREF(__pyx_t_1);
11224       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11225       __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11226       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11227       if (unlikely(!__pyx_t_3)) {
11228         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_91), __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11229         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
11230         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_1));
11231         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
11232         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11233       }
11234       #endif
11235
11236       /* "csamtools.pyx":1102
11237  *                     if not line.strip(): continue
11238  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
11239  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
11240  *                     record = fields[0]
11241  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
11242  */
11243       __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 = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11244       __Pyx_GOTREF(__pyx_t_1);
11245       __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__split); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11246       __Pyx_GOTREF(__pyx_t_6);
11247       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11248       __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_92), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11249       __Pyx_GOTREF(__pyx_t_1);
11250       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11251       __Pyx_DECREF(__pyx_v_fields);
11252       __pyx_v_fields = __pyx_t_1;
11253       __pyx_t_1 = 0;
11254
11255       /* "csamtools.pyx":1103
11256  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
11257  *                     fields = line[1:].split("\t")
11258  *                     record = fields[0]             # <<<<<<<<<<<<<<
11259  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
11260  * 
11261  */
11262       __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11263       __Pyx_GOTREF(__pyx_t_1);
11264       __Pyx_DECREF(__pyx_v_record);
11265       __pyx_v_record = __pyx_t_1;
11266       __pyx_t_1 = 0;
11267
11268       /* "csamtools.pyx":1104
11269  *                     fields = line[1:].split("\t")
11270  *                     record = fields[0]
11271  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
11272  * 
11273  *                     # treat comments
11274  */
11275       #ifndef CYTHON_WITHOUT_ASSERTIONS
11276       __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 = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11277       __Pyx_GOTREF(__pyx_t_1);
11278       __pyx_t_3 = ((PySequence_Contains(__pyx_t_1, __pyx_v_record))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11279       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11280       if (unlikely(!__pyx_t_3)) {
11281         __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11282         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
11283         __Pyx_INCREF(__pyx_v_record);
11284         PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_record);
11285         __Pyx_GIVEREF(__pyx_v_record);
11286         __Pyx_INCREF(__pyx_v_line);
11287         PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_line);
11288         __Pyx_GIVEREF(__pyx_v_line);
11289         __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_93), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11290         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11291         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
11292         PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_t_6));
11293         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11294         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11295       }
11296       #endif
11297
11298       /* "csamtools.pyx":1107
11299  * 
11300  *                     # treat comments
11301  *                     if record == "CO":             # <<<<<<<<<<<<<<
11302  *                         if record not in result: result[record] = []
11303  *                         result[record].append( "\t".join( fields[1:] ) )
11304  */
11305       __pyx_t_6 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11306       __Pyx_GOTREF(__pyx_t_6);
11307       __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11308       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11309       if (__pyx_t_3) {
11310
11311         /* "csamtools.pyx":1108
11312  *                     # treat comments
11313  *                     if record == "CO":
11314  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
11315  *                         result[record].append( "\t".join( fields[1:] ) )
11316  *                         continue
11317  */
11318         if (unlikely(__pyx_v_result == Py_None)) {
11319           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11320         }
11321         __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 = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11322         if (__pyx_t_3) {
11323           __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11324           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11325           if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_6)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11326           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11327           goto __pyx_L11;
11328         }
11329         __pyx_L11:;
11330
11331         /* "csamtools.pyx":1109
11332  *                     if record == "CO":
11333  *                         if record not in result: result[record] = []
11334  *                         result[record].append( "\t".join( fields[1:] ) )             # <<<<<<<<<<<<<<
11335  *                         continue
11336  * 
11337  */
11338         __pyx_t_6 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11339         __Pyx_GOTREF(__pyx_t_6);
11340         __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11341         __Pyx_GOTREF(__pyx_t_1);
11342         __pyx_t_7 = __Pyx_PySequence_GetSlice(__pyx_v_fields, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11343         __Pyx_GOTREF(__pyx_t_7);
11344         __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11345         __Pyx_GOTREF(((PyObject *)__pyx_t_8));
11346         PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
11347         __Pyx_GIVEREF(__pyx_t_7);
11348         __pyx_t_7 = 0;
11349         __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 = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11350         __Pyx_GOTREF(__pyx_t_7);
11351         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11352         __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
11353         __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11354         __Pyx_GOTREF(__pyx_t_8);
11355         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11356         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11357         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11358
11359         /* "csamtools.pyx":1110
11360  *                         if record not in result: result[record] = []
11361  *                         result[record].append( "\t".join( fields[1:] ) )
11362  *                         continue             # <<<<<<<<<<<<<<
11363  * 
11364  *                     # the following is clumsy as generators do not work?
11365  */
11366         goto __pyx_L7_continue;
11367         goto __pyx_L10;
11368       }
11369       __pyx_L10:;
11370
11371       /* "csamtools.pyx":1113
11372  * 
11373  *                     # the following is clumsy as generators do not work?
11374  *                     x = {}             # <<<<<<<<<<<<<<
11375  *                     for field in fields[1:]:
11376  *                         key, value = field.split(":",1)
11377  */
11378       __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11379       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
11380       __Pyx_DECREF(((PyObject *)__pyx_v_x));
11381       __pyx_v_x = __pyx_t_8;
11382       __pyx_t_8 = 0;
11383
11384       /* "csamtools.pyx":1114
11385  *                     # the following is clumsy as generators do not work?
11386  *                     x = {}
11387  *                     for field in fields[1:]:             # <<<<<<<<<<<<<<
11388  *                         key, value = field.split(":",1)
11389  *                         # uppercase keys must be valid
11390  */
11391       __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 = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11392       __Pyx_GOTREF(__pyx_t_8);
11393       if (PyList_CheckExact(__pyx_t_8) || PyTuple_CheckExact(__pyx_t_8)) {
11394         __pyx_t_9 = 0; __pyx_t_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7);
11395       } else {
11396         __pyx_t_9 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11397         __Pyx_GOTREF(__pyx_t_7);
11398       }
11399       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11400       for (;;) {
11401         if (likely(PyList_CheckExact(__pyx_t_7))) {
11402           if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_7)) break;
11403           __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++;
11404         } else if (likely(PyTuple_CheckExact(__pyx_t_7))) {
11405           if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
11406           __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++;
11407         } else {
11408           __pyx_t_8 = PyIter_Next(__pyx_t_7);
11409           if (!__pyx_t_8) {
11410             if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11411             break;
11412           }
11413           __Pyx_GOTREF(__pyx_t_8);
11414         }
11415         __Pyx_DECREF(__pyx_v_field);
11416         __pyx_v_field = __pyx_t_8;
11417         __pyx_t_8 = 0;
11418
11419         /* "csamtools.pyx":1115
11420  *                     x = {}
11421  *                     for field in fields[1:]:
11422  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
11423  *                         # uppercase keys must be valid
11424  *                         # lowercase are permitted for user fields
11425  */
11426         __pyx_t_8 = PyObject_GetAttr(__pyx_v_field, __pyx_n_s__split); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11427         __Pyx_GOTREF(__pyx_t_8);
11428         __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11429         __Pyx_GOTREF(__pyx_t_6);
11430         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11431         if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) {
11432           PyObject* tuple = __pyx_t_6;
11433           __pyx_t_8 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_8);
11434           __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
11435           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11436           __Pyx_DECREF(__pyx_v_key);
11437           __pyx_v_key = __pyx_t_8;
11438           __pyx_t_8 = 0;
11439           __Pyx_DECREF(__pyx_v_value);
11440           __pyx_v_value = __pyx_t_1;
11441           __pyx_t_1 = 0;
11442         } else {
11443           __pyx_t_10 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11444           __Pyx_GOTREF(__pyx_t_10);
11445           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11446           __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_10, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11447           __Pyx_GOTREF(__pyx_t_8);
11448           __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_10, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11449           __Pyx_GOTREF(__pyx_t_1);
11450           if (__Pyx_EndUnpack(__pyx_t_10, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11451           __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
11452           __Pyx_DECREF(__pyx_v_key);
11453           __pyx_v_key = __pyx_t_8;
11454           __pyx_t_8 = 0;
11455           __Pyx_DECREF(__pyx_v_value);
11456           __pyx_v_value = __pyx_t_1;
11457           __pyx_t_1 = 0;
11458         }
11459
11460         /* "csamtools.pyx":1118
11461  *                         # uppercase keys must be valid
11462  *                         # lowercase are permitted for user fields
11463  *                         if key in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
11464  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
11465  *                         elif not key.isupper():
11466  */
11467         __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11468         __Pyx_GOTREF(__pyx_t_6);
11469         __pyx_t_1 = PyObject_GetItem(__pyx_t_6, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11470         __Pyx_GOTREF(__pyx_t_1);
11471         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11472         __pyx_t_3 = ((PySequence_Contains(__pyx_t_1, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11473         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11474         if (__pyx_t_3) {
11475
11476           /* "csamtools.pyx":1119
11477  *                         # lowercase are permitted for user fields
11478  *                         if key in VALID_HEADER_FIELDS[record]:
11479  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
11480  *                         elif not key.isupper():
11481  *                             x[key] = value
11482  */
11483           __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 = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11484           __Pyx_GOTREF(__pyx_t_1);
11485           __pyx_t_6 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11486           __Pyx_GOTREF(__pyx_t_6);
11487           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11488           __pyx_t_1 = PyObject_GetItem(__pyx_t_6, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11489           __Pyx_GOTREF(__pyx_t_1);
11490           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11491           __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11492           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11493           __Pyx_INCREF(__pyx_v_value);
11494           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_value);
11495           __Pyx_GIVEREF(__pyx_v_value);
11496           __pyx_t_8 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11497           __Pyx_GOTREF(__pyx_t_8);
11498           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11499           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11500           if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11501           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11502           goto __pyx_L14;
11503         }
11504
11505         /* "csamtools.pyx":1120
11506  *                         if key in VALID_HEADER_FIELDS[record]:
11507  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
11508  *                         elif not key.isupper():             # <<<<<<<<<<<<<<
11509  *                             x[key] = value
11510  *                         else:
11511  */
11512         __pyx_t_8 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11513         __Pyx_GOTREF(__pyx_t_8);
11514         __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11515         __Pyx_GOTREF(__pyx_t_6);
11516         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11517         __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11518         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11519         __pyx_t_4 = (!__pyx_t_3);
11520         if (__pyx_t_4) {
11521
11522           /* "csamtools.pyx":1121
11523  *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
11524  *                         elif not key.isupper():
11525  *                             x[key] = value             # <<<<<<<<<<<<<<
11526  *                         else:
11527  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
11528  */
11529           if (PyDict_SetItem(((PyObject *)__pyx_v_x), __pyx_v_key, __pyx_v_value) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11530           goto __pyx_L14;
11531         }
11532         /*else*/ {
11533
11534           /* "csamtools.pyx":1123
11535  *                             x[key] = value
11536  *                         else:
11537  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )             # <<<<<<<<<<<<<<
11538  * 
11539  *                     if VALID_HEADER_TYPES[record] == dict:
11540  */
11541           __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11542           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11543           __Pyx_INCREF(__pyx_v_key);
11544           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
11545           __Pyx_GIVEREF(__pyx_v_key);
11546           __Pyx_INCREF(__pyx_v_record);
11547           PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_record);
11548           __Pyx_GIVEREF(__pyx_v_record);
11549           __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_96), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11550           __Pyx_GOTREF(((PyObject *)__pyx_t_8));
11551           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11552           __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11553           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11554           PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_8));
11555           __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
11556           __pyx_t_8 = 0;
11557           __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11558           __Pyx_GOTREF(__pyx_t_8);
11559           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11560           __Pyx_Raise(__pyx_t_8, 0, 0);
11561           __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11562           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11563         }
11564         __pyx_L14:;
11565       }
11566       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11567
11568       /* "csamtools.pyx":1125
11569  *                             raise ValueError( "unknown field code '%s' in record '%s'" % (key, record) )
11570  * 
11571  *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
11572  *                         if record in result:
11573  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
11574  */
11575       __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11576       __Pyx_GOTREF(__pyx_t_7);
11577       __pyx_t_8 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11578       __Pyx_GOTREF(__pyx_t_8);
11579       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11580       __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11581       __Pyx_GOTREF(__pyx_t_7);
11582       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11583       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11584       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11585       if (__pyx_t_4) {
11586
11587         /* "csamtools.pyx":1126
11588  * 
11589  *                     if VALID_HEADER_TYPES[record] == dict:
11590  *                         if record in result:             # <<<<<<<<<<<<<<
11591  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
11592  *                         result[record] = x
11593  */
11594         if (unlikely(__pyx_v_result == Py_None)) {
11595           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11596         }
11597         __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 = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11598         if (__pyx_t_4) {
11599
11600           /* "csamtools.pyx":1127
11601  *                     if VALID_HEADER_TYPES[record] == dict:
11602  *                         if record in result:
11603  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )             # <<<<<<<<<<<<<<
11604  *                         result[record] = x
11605  *                     elif VALID_HEADER_TYPES[record] == list:
11606  */
11607           __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_97), __pyx_v_record); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11608           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
11609           __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11610           __Pyx_GOTREF(((PyObject *)__pyx_t_8));
11611           PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
11612           __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
11613           __pyx_t_7 = 0;
11614           __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 = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11615           __Pyx_GOTREF(__pyx_t_7);
11616           __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
11617           __Pyx_Raise(__pyx_t_7, 0, 0);
11618           __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11619           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11620           goto __pyx_L16;
11621         }
11622         __pyx_L16:;
11623
11624         /* "csamtools.pyx":1128
11625  *                         if record in result:
11626  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
11627  *                         result[record] = x             # <<<<<<<<<<<<<<
11628  *                     elif VALID_HEADER_TYPES[record] == list:
11629  *                         if record not in result: result[record] = []
11630  */
11631         if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_v_x)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11632         goto __pyx_L15;
11633       }
11634
11635       /* "csamtools.pyx":1129
11636  *                             raise ValueError( "multiple '%s' lines are not permitted" % record )
11637  *                         result[record] = x
11638  *                     elif VALID_HEADER_TYPES[record] == list:             # <<<<<<<<<<<<<<
11639  *                         if record not in result: result[record] = []
11640  *                         result[record].append( x )
11641  */
11642       __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11643       __Pyx_GOTREF(__pyx_t_7);
11644       __pyx_t_8 = PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11645       __Pyx_GOTREF(__pyx_t_8);
11646       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11647       __pyx_t_7 = PyObject_RichCompare(__pyx_t_8, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11648       __Pyx_GOTREF(__pyx_t_7);
11649       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11650       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11651       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11652       if (__pyx_t_4) {
11653
11654         /* "csamtools.pyx":1130
11655  *                         result[record] = x
11656  *                     elif VALID_HEADER_TYPES[record] == list:
11657  *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
11658  *                         result[record].append( x )
11659  * 
11660  */
11661         if (unlikely(__pyx_v_result == Py_None)) {
11662           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11663         }
11664         __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 = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11665         if (__pyx_t_4) {
11666           __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11667           __Pyx_GOTREF(((PyObject *)__pyx_t_7));
11668           if (PyDict_SetItem(((PyObject *)__pyx_v_result), __pyx_v_record, ((PyObject *)__pyx_t_7)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11669           __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
11670           goto __pyx_L17;
11671         }
11672         __pyx_L17:;
11673
11674         /* "csamtools.pyx":1131
11675  *                     elif VALID_HEADER_TYPES[record] == list:
11676  *                         if record not in result: result[record] = []
11677  *                         result[record].append( x )             # <<<<<<<<<<<<<<
11678  * 
11679  *             return result
11680  */
11681         __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_result), __pyx_v_record); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11682         __Pyx_GOTREF(__pyx_t_7);
11683         __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_7, ((PyObject *)__pyx_v_x)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11684         __Pyx_GOTREF(__pyx_t_8);
11685         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
11686         __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
11687         goto __pyx_L15;
11688       }
11689       __pyx_L15:;
11690       __pyx_L7_continue:;
11691     }
11692     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11693     goto __pyx_L6;
11694   }
11695   __pyx_L6:;
11696
11697   /* "csamtools.pyx":1133
11698  *                         result[record].append( x )
11699  * 
11700  *             return result             # <<<<<<<<<<<<<<
11701  * 
11702  *     def _buildLine( self, fields, record ):
11703  */
11704   __Pyx_XDECREF(__pyx_r);
11705   __Pyx_INCREF(((PyObject *)__pyx_v_result));
11706   __pyx_r = ((PyObject *)__pyx_v_result);
11707   goto __pyx_L0;
11708
11709   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
11710   goto __pyx_L0;
11711   __pyx_L1_error:;
11712   __Pyx_XDECREF(__pyx_t_1);
11713   __Pyx_XDECREF(__pyx_t_2);
11714   __Pyx_XDECREF(__pyx_t_6);
11715   __Pyx_XDECREF(__pyx_t_7);
11716   __Pyx_XDECREF(__pyx_t_8);
11717   __Pyx_XDECREF(__pyx_t_10);
11718   __Pyx_AddTraceback("csamtools.Samfile.header.__get__");
11719   __pyx_r = NULL;
11720   __pyx_L0:;
11721   __Pyx_DECREF(__pyx_v_result);
11722   __Pyx_DECREF(__pyx_v_t);
11723   __Pyx_DECREF(__pyx_v_line);
11724   __Pyx_DECREF(__pyx_v_fields);
11725   __Pyx_DECREF(__pyx_v_record);
11726   __Pyx_DECREF(__pyx_v_x);
11727   __Pyx_DECREF(__pyx_v_field);
11728   __Pyx_DECREF(__pyx_v_key);
11729   __Pyx_DECREF(__pyx_v_value);
11730   __Pyx_XGIVEREF(__pyx_r);
11731   __Pyx_TraceReturn(__pyx_r);
11732   __Pyx_RefNannyFinishContext();
11733   return __pyx_r;
11734 }
11735
11736 /* "csamtools.pyx":1135
11737  *             return result
11738  * 
11739  *     def _buildLine( self, fields, record ):             # <<<<<<<<<<<<<<
11740  *         '''build a header line from *fields* dictionary for *record*'''
11741  * 
11742  */
11743
11744 static PyObject *__pyx_pf_9csamtools_7Samfile_19_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
11745 static char __pyx_doc_9csamtools_7Samfile_19_buildLine[] = "Samfile._buildLine(self, fields, record)\nbuild a header line from *fields* dictionary for *record*";
11746 static PyObject *__pyx_pf_9csamtools_7Samfile_19_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
11747   PyObject *__pyx_v_fields = 0;
11748   PyObject *__pyx_v_record = 0;
11749   PyObject *__pyx_v_line;
11750   PyObject *__pyx_v_key;
11751   PyObject *__pyx_r = NULL;
11752   PyObject *__pyx_t_1 = NULL;
11753   PyObject *__pyx_t_2 = NULL;
11754   int __pyx_t_3;
11755   int __pyx_t_4;
11756   Py_ssize_t __pyx_t_5;
11757   PyObject *__pyx_t_6 = NULL;
11758   int __pyx_t_7;
11759   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fields,&__pyx_n_s__record,0};
11760   __Pyx_TraceDeclarations
11761   __Pyx_RefNannySetupContext("_buildLine");
11762   __Pyx_TraceCall("_buildLine", __pyx_f[0], 1135);
11763   if (unlikely(__pyx_kwds)) {
11764     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
11765     PyObject* values[2] = {0,0};
11766     switch (PyTuple_GET_SIZE(__pyx_args)) {
11767       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
11768       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
11769       case  0: break;
11770       default: goto __pyx_L5_argtuple_error;
11771     }
11772     switch (PyTuple_GET_SIZE(__pyx_args)) {
11773       case  0:
11774       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fields);
11775       if (likely(values[0])) kw_args--;
11776       else goto __pyx_L5_argtuple_error;
11777       case  1:
11778       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__record);
11779       if (likely(values[1])) kw_args--;
11780       else {
11781         __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11782       }
11783     }
11784     if (unlikely(kw_args > 0)) {
11785       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11786     }
11787     __pyx_v_fields = values[0];
11788     __pyx_v_record = values[1];
11789   } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
11790     goto __pyx_L5_argtuple_error;
11791   } else {
11792     __pyx_v_fields = PyTuple_GET_ITEM(__pyx_args, 0);
11793     __pyx_v_record = PyTuple_GET_ITEM(__pyx_args, 1);
11794   }
11795   goto __pyx_L4_argument_unpacking_done;
11796   __pyx_L5_argtuple_error:;
11797   __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
11798   __pyx_L3_error:;
11799   __Pyx_AddTraceback("csamtools.Samfile._buildLine");
11800   __Pyx_RefNannyFinishContext();
11801   return NULL;
11802   __pyx_L4_argument_unpacking_done:;
11803   __pyx_v_line = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
11804   __pyx_v_key = Py_None; __Pyx_INCREF(Py_None);
11805
11806   /* "csamtools.pyx":1139
11807  * 
11808  *         # TODO: add checking for field and sort order
11809  *         line = ["@%s" % record ]             # <<<<<<<<<<<<<<
11810  *         if record == "CO":
11811  *             line.append( fields )
11812  */
11813   __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_98), __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11814   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
11815   __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11816   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
11817   PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1));
11818   __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
11819   __pyx_t_1 = 0;
11820   __Pyx_DECREF(((PyObject *)__pyx_v_line));
11821   __pyx_v_line = __pyx_t_2;
11822   __pyx_t_2 = 0;
11823
11824   /* "csamtools.pyx":1140
11825  *         # TODO: add checking for field and sort order
11826  *         line = ["@%s" % record ]
11827  *         if record == "CO":             # <<<<<<<<<<<<<<
11828  *             line.append( fields )
11829  *         else:
11830  */
11831   __pyx_t_2 = PyObject_RichCompare(__pyx_v_record, ((PyObject *)__pyx_n_s__CO), Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11832   __Pyx_GOTREF(__pyx_t_2);
11833   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11834   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11835   if (__pyx_t_3) {
11836
11837     /* "csamtools.pyx":1141
11838  *         line = ["@%s" % record ]
11839  *         if record == "CO":
11840  *             line.append( fields )             # <<<<<<<<<<<<<<
11841  *         else:
11842  *             # write fields of the specification
11843  */
11844     if (unlikely(__pyx_v_line == Py_None)) {
11845       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11846     }
11847     __pyx_t_4 = PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11848     goto __pyx_L6;
11849   }
11850   /*else*/ {
11851
11852     /* "csamtools.pyx":1144
11853  *         else:
11854  *             # write fields of the specification
11855  *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
11856  *                 if key in fields:
11857  *                     line.append( "%s:%s" % (key, str(fields[key])))
11858  */
11859     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11860     __Pyx_GOTREF(__pyx_t_2);
11861     __pyx_t_1 = PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11862     __Pyx_GOTREF(__pyx_t_1);
11863     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11864     if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
11865       __pyx_t_5 = 0; __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
11866     } else {
11867       __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11868       __Pyx_GOTREF(__pyx_t_2);
11869     }
11870     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11871     for (;;) {
11872       if (likely(PyList_CheckExact(__pyx_t_2))) {
11873         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
11874         __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11875       } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
11876         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
11877         __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11878       } else {
11879         __pyx_t_1 = PyIter_Next(__pyx_t_2);
11880         if (!__pyx_t_1) {
11881           if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11882           break;
11883         }
11884         __Pyx_GOTREF(__pyx_t_1);
11885       }
11886       __Pyx_DECREF(__pyx_v_key);
11887       __pyx_v_key = __pyx_t_1;
11888       __pyx_t_1 = 0;
11889
11890       /* "csamtools.pyx":1145
11891  *             # write fields of the specification
11892  *             for key in VALID_HEADER_ORDER[record]:
11893  *                 if key in fields:             # <<<<<<<<<<<<<<
11894  *                     line.append( "%s:%s" % (key, str(fields[key])))
11895  *             # write user fields
11896  */
11897       __pyx_t_3 = ((PySequence_Contains(__pyx_v_fields, __pyx_v_key))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11898       if (__pyx_t_3) {
11899
11900         /* "csamtools.pyx":1146
11901  *             for key in VALID_HEADER_ORDER[record]:
11902  *                 if key in fields:
11903  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
11904  *             # write user fields
11905  *             for key in fields:
11906  */
11907         if (unlikely(__pyx_v_line == Py_None)) {
11908           PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11909         }
11910         __pyx_t_1 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11911         __Pyx_GOTREF(__pyx_t_1);
11912         __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11913         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11914         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
11915         __Pyx_GIVEREF(__pyx_t_1);
11916         __pyx_t_1 = 0;
11917         __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11918         __Pyx_GOTREF(__pyx_t_1);
11919         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11920         __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11921         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
11922         __Pyx_INCREF(__pyx_v_key);
11923         PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_key);
11924         __Pyx_GIVEREF(__pyx_v_key);
11925         PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1);
11926         __Pyx_GIVEREF(__pyx_t_1);
11927         __pyx_t_1 = 0;
11928         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_99), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11929         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
11930         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
11931         __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11932         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
11933         goto __pyx_L9;
11934       }
11935       __pyx_L9:;
11936     }
11937     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
11938
11939     /* "csamtools.pyx":1148
11940  *                     line.append( "%s:%s" % (key, str(fields[key])))
11941  *             # write user fields
11942  *             for key in fields:             # <<<<<<<<<<<<<<
11943  *                 if not key.isupper():
11944  *                     line.append( "%s:%s" % (key, str(fields[key])))
11945  */
11946     if (PyList_CheckExact(__pyx_v_fields) || PyTuple_CheckExact(__pyx_v_fields)) {
11947       __pyx_t_5 = 0; __pyx_t_2 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_2);
11948     } else {
11949       __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11950       __Pyx_GOTREF(__pyx_t_2);
11951     }
11952     for (;;) {
11953       if (likely(PyList_CheckExact(__pyx_t_2))) {
11954         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
11955         __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11956       } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
11957         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
11958         __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
11959       } else {
11960         __pyx_t_1 = PyIter_Next(__pyx_t_2);
11961         if (!__pyx_t_1) {
11962           if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11963           break;
11964         }
11965         __Pyx_GOTREF(__pyx_t_1);
11966       }
11967       __Pyx_DECREF(__pyx_v_key);
11968       __pyx_v_key = __pyx_t_1;
11969       __pyx_t_1 = 0;
11970
11971       /* "csamtools.pyx":1149
11972  *             # write user fields
11973  *             for key in fields:
11974  *                 if not key.isupper():             # <<<<<<<<<<<<<<
11975  *                     line.append( "%s:%s" % (key, str(fields[key])))
11976  * 
11977  */
11978       __pyx_t_1 = PyObject_GetAttr(__pyx_v_key, __pyx_n_s__isupper); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11979       __Pyx_GOTREF(__pyx_t_1);
11980       __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11981       __Pyx_GOTREF(__pyx_t_6);
11982       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
11983       __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11984       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
11985       __pyx_t_7 = (!__pyx_t_3);
11986       if (__pyx_t_7) {
11987
11988         /* "csamtools.pyx":1150
11989  *             for key in fields:
11990  *                 if not key.isupper():
11991  *                     line.append( "%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
11992  * 
11993  *         return "\t".join( line )
11994  */
11995         if (unlikely(__pyx_v_line == Py_None)) {
11996           PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
11997         }
11998         __pyx_t_6 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
11999         __Pyx_GOTREF(__pyx_t_6);
12000         __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12001         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12002         PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6);
12003         __Pyx_GIVEREF(__pyx_t_6);
12004         __pyx_t_6 = 0;
12005         __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12006         __Pyx_GOTREF(__pyx_t_6);
12007         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
12008         __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12009         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12010         __Pyx_INCREF(__pyx_v_key);
12011         PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key);
12012         __Pyx_GIVEREF(__pyx_v_key);
12013         PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
12014         __Pyx_GIVEREF(__pyx_t_6);
12015         __pyx_t_6 = 0;
12016         __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_99), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12017         __Pyx_GOTREF(((PyObject *)__pyx_t_6));
12018         __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
12019         __pyx_t_4 = PyList_Append(__pyx_v_line, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12020         __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
12021         goto __pyx_L12;
12022       }
12023       __pyx_L12:;
12024     }
12025     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12026   }
12027   __pyx_L6:;
12028
12029   /* "csamtools.pyx":1152
12030  *                     line.append( "%s:%s" % (key, str(fields[key])))
12031  * 
12032  *         return "\t".join( line )             # <<<<<<<<<<<<<<
12033  * 
12034  *     cdef bam_header_t * _buildHeader( self, new_header ):
12035  */
12036   __Pyx_XDECREF(__pyx_r);
12037   __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12038   __Pyx_GOTREF(__pyx_t_2);
12039   __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12040   __Pyx_GOTREF(((PyObject *)__pyx_t_6));
12041   __Pyx_INCREF(((PyObject *)__pyx_v_line));
12042   PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_line));
12043   __Pyx_GIVEREF(((PyObject *)__pyx_v_line));
12044   __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12045   __Pyx_GOTREF(__pyx_t_1);
12046   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12047   __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
12048   __pyx_r = __pyx_t_1;
12049   __pyx_t_1 = 0;
12050   goto __pyx_L0;
12051
12052   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12053   goto __pyx_L0;
12054   __pyx_L1_error:;
12055   __Pyx_XDECREF(__pyx_t_1);
12056   __Pyx_XDECREF(__pyx_t_2);
12057   __Pyx_XDECREF(__pyx_t_6);
12058   __Pyx_AddTraceback("csamtools.Samfile._buildLine");
12059   __pyx_r = NULL;
12060   __pyx_L0:;
12061   __Pyx_DECREF(__pyx_v_line);
12062   __Pyx_DECREF(__pyx_v_key);
12063   __Pyx_XGIVEREF(__pyx_r);
12064   __Pyx_TraceReturn(__pyx_r);
12065   __Pyx_RefNannyFinishContext();
12066   return __pyx_r;
12067 }
12068
12069 /* "csamtools.pyx":1154
12070  *         return "\t".join( line )
12071  * 
12072  *     cdef bam_header_t * _buildHeader( self, new_header ):             # <<<<<<<<<<<<<<
12073  *         '''return a new header built from a dictionary in *new_header*.
12074  * 
12075  */
12076
12077 static  bam_header_t *__pyx_f_9csamtools_7Samfile__buildHeader(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self, PyObject *__pyx_v_new_header) {
12078   PyObject *__pyx_v_lines;
12079   bam_header_t *__pyx_v_dest;
12080   PyObject *__pyx_v_record;
12081   PyObject *__pyx_v_ttype;
12082   PyObject *__pyx_v_data;
12083   PyObject *__pyx_v_fields;
12084   PyObject *__pyx_v_text;
12085   PyObject *__pyx_v_seqs;
12086   long __pyx_v_x;
12087   PyObject *__pyx_v_seqname;
12088   PyObject *__pyx_v_seqlen;
12089   bam_header_t *__pyx_r;
12090   PyObject *__pyx_t_1 = NULL;
12091   Py_ssize_t __pyx_t_2;
12092   PyObject *__pyx_t_3 = NULL;
12093   int __pyx_t_4;
12094   PyObject *__pyx_t_5 = NULL;
12095   PyObject *__pyx_t_6 = NULL;
12096   int __pyx_t_7;
12097   Py_ssize_t __pyx_t_8;
12098   PyObject *__pyx_t_9 = NULL;
12099   char *__pyx_t_10;
12100   PyObject *__pyx_t_11 = NULL;
12101   int32_t __pyx_t_12;
12102   uint32_t __pyx_t_13;
12103   __Pyx_TraceDeclarations
12104   __Pyx_RefNannySetupContext("_buildHeader");
12105   __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1154);
12106   __pyx_v_lines = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
12107   __pyx_v_record = Py_None; __Pyx_INCREF(Py_None);
12108   __pyx_v_ttype = Py_None; __Pyx_INCREF(Py_None);
12109   __pyx_v_data = Py_None; __Pyx_INCREF(Py_None);
12110   __pyx_v_fields = Py_None; __Pyx_INCREF(Py_None);
12111   __pyx_v_text = Py_None; __Pyx_INCREF(Py_None);
12112   __pyx_v_seqs = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
12113   __pyx_v_seqname = Py_None; __Pyx_INCREF(Py_None);
12114   __pyx_v_seqlen = Py_None; __Pyx_INCREF(Py_None);
12115
12116   /* "csamtools.pyx":1160
12117  *         '''
12118  * 
12119  *         lines = []             # <<<<<<<<<<<<<<
12120  * 
12121  *         # check if hash exists
12122  */
12123   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12124   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12125   __Pyx_DECREF(((PyObject *)__pyx_v_lines));
12126   __pyx_v_lines = __pyx_t_1;
12127   __pyx_t_1 = 0;
12128
12129   /* "csamtools.pyx":1167
12130  *         cdef bam_header_t * dest
12131  * 
12132  *         dest = bam_header_init()             # <<<<<<<<<<<<<<
12133  * 
12134  *         for record in VALID_HEADERS:
12135  */
12136   __pyx_v_dest = bam_header_init();
12137
12138   /* "csamtools.pyx":1169
12139  *         dest = bam_header_init()
12140  * 
12141  *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
12142  *             if record in new_header:
12143  *                 ttype = VALID_HEADER_TYPES[record]
12144  */
12145   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12146   __Pyx_GOTREF(__pyx_t_1);
12147   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
12148     __pyx_t_2 = 0; __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3);
12149   } else {
12150     __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12151     __Pyx_GOTREF(__pyx_t_3);
12152   }
12153   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12154   for (;;) {
12155     if (likely(PyList_CheckExact(__pyx_t_3))) {
12156       if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break;
12157       __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
12158     } else if (likely(PyTuple_CheckExact(__pyx_t_3))) {
12159       if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
12160       __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
12161     } else {
12162       __pyx_t_1 = PyIter_Next(__pyx_t_3);
12163       if (!__pyx_t_1) {
12164         if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12165         break;
12166       }
12167       __Pyx_GOTREF(__pyx_t_1);
12168     }
12169     __Pyx_DECREF(__pyx_v_record);
12170     __pyx_v_record = __pyx_t_1;
12171     __pyx_t_1 = 0;
12172
12173     /* "csamtools.pyx":1170
12174  * 
12175  *         for record in VALID_HEADERS:
12176  *             if record in new_header:             # <<<<<<<<<<<<<<
12177  *                 ttype = VALID_HEADER_TYPES[record]
12178  *                 data = new_header[record]
12179  */
12180     __pyx_t_4 = ((PySequence_Contains(__pyx_v_new_header, __pyx_v_record))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12181     if (__pyx_t_4) {
12182
12183       /* "csamtools.pyx":1171
12184  *         for record in VALID_HEADERS:
12185  *             if record in new_header:
12186  *                 ttype = VALID_HEADER_TYPES[record]             # <<<<<<<<<<<<<<
12187  *                 data = new_header[record]
12188  *                 if type( data ) != type( ttype() ):
12189  */
12190       __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 = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12191       __Pyx_GOTREF(__pyx_t_1);
12192       __pyx_t_5 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12193       __Pyx_GOTREF(__pyx_t_5);
12194       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12195       __Pyx_DECREF(__pyx_v_ttype);
12196       __pyx_v_ttype = __pyx_t_5;
12197       __pyx_t_5 = 0;
12198
12199       /* "csamtools.pyx":1172
12200  *             if record in new_header:
12201  *                 ttype = VALID_HEADER_TYPES[record]
12202  *                 data = new_header[record]             # <<<<<<<<<<<<<<
12203  *                 if type( data ) != type( ttype() ):
12204  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
12205  */
12206       __pyx_t_5 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12207       __Pyx_GOTREF(__pyx_t_5);
12208       __Pyx_DECREF(__pyx_v_data);
12209       __pyx_v_data = __pyx_t_5;
12210       __pyx_t_5 = 0;
12211
12212       /* "csamtools.pyx":1173
12213  *                 ttype = VALID_HEADER_TYPES[record]
12214  *                 data = new_header[record]
12215  *                 if type( data ) != type( ttype() ):             # <<<<<<<<<<<<<<
12216  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
12217  *                 if type( data ) == types.DictType:
12218  */
12219       __pyx_t_5 = PyObject_Call(__pyx_v_ttype, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12220       __Pyx_GOTREF(__pyx_t_5);
12221       __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_5)), Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12222       __Pyx_GOTREF(__pyx_t_1);
12223       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
12224       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12225       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12226       if (__pyx_t_4) {
12227
12228         /* "csamtools.pyx":1174
12229  *                 data = new_header[record]
12230  *                 if type( data ) != type( ttype() ):
12231  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )             # <<<<<<<<<<<<<<
12232  *                 if type( data ) == types.DictType:
12233  *                     lines.append( self._buildLine( data, record ) )
12234  */
12235         __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 = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12236         __Pyx_GOTREF(__pyx_t_1);
12237         __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12238         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
12239         __Pyx_INCREF(__pyx_v_record);
12240         PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_record);
12241         __Pyx_GIVEREF(__pyx_v_record);
12242         __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
12243         PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)Py_TYPE(__pyx_v_data)));
12244         __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data)));
12245         __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_1)));
12246         PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
12247         __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
12248         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12249         __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_100), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12250         __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12251         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
12252         __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12253         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
12254         PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1));
12255         __Pyx_GIVEREF(((PyObject *)__pyx_t_1));
12256         __pyx_t_1 = 0;
12257         __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 = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12258         __Pyx_GOTREF(__pyx_t_1);
12259         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
12260         __Pyx_Raise(__pyx_t_1, 0, 0);
12261         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12262         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12263         goto __pyx_L6;
12264       }
12265       __pyx_L6:;
12266
12267       /* "csamtools.pyx":1175
12268  *                 if type( data ) != type( ttype() ):
12269  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
12270  *                 if type( data ) == types.DictType:             # <<<<<<<<<<<<<<
12271  *                     lines.append( self._buildLine( data, record ) )
12272  *                 else:
12273  */
12274       __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12275       __Pyx_GOTREF(__pyx_t_1);
12276       __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__DictType); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12277       __Pyx_GOTREF(__pyx_t_5);
12278       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12279       __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_5, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12280       __Pyx_GOTREF(__pyx_t_1);
12281       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
12282       __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12283       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12284       if (__pyx_t_4) {
12285
12286         /* "csamtools.pyx":1176
12287  *                     raise ValueError( "invalid type for record %s: %s, expected %s" % (record, type(data), type(ttype()) ) )
12288  *                 if type( data ) == types.DictType:
12289  *                     lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
12290  *                 else:
12291  *                     for fields in new_header[record]:
12292  */
12293         if (unlikely(__pyx_v_lines == Py_None)) {
12294           PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
12295         }
12296         __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 = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12297         __Pyx_GOTREF(__pyx_t_1);
12298         __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12299         __Pyx_GOTREF(((PyObject *)__pyx_t_5));
12300         __Pyx_INCREF(__pyx_v_data);
12301         PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_data);
12302         __Pyx_GIVEREF(__pyx_v_data);
12303         __Pyx_INCREF(__pyx_v_record);
12304         PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_record);
12305         __Pyx_GIVEREF(__pyx_v_record);
12306         __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12307         __Pyx_GOTREF(__pyx_t_6);
12308         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12309         __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
12310         __pyx_t_7 = PyList_Append(__pyx_v_lines, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12311         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
12312         goto __pyx_L7;
12313       }
12314       /*else*/ {
12315
12316         /* "csamtools.pyx":1178
12317  *                     lines.append( self._buildLine( data, record ) )
12318  *                 else:
12319  *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
12320  *                         lines.append( self._buildLine( fields, record ) )
12321  * 
12322  */
12323         __pyx_t_6 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12324         __Pyx_GOTREF(__pyx_t_6);
12325         if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
12326           __pyx_t_8 = 0; __pyx_t_5 = __pyx_t_6; __Pyx_INCREF(__pyx_t_5);
12327         } else {
12328           __pyx_t_8 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12329           __Pyx_GOTREF(__pyx_t_5);
12330         }
12331         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
12332         for (;;) {
12333           if (likely(PyList_CheckExact(__pyx_t_5))) {
12334             if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_5)) break;
12335             __pyx_t_6 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++;
12336           } else if (likely(PyTuple_CheckExact(__pyx_t_5))) {
12337             if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
12338             __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++;
12339           } else {
12340             __pyx_t_6 = PyIter_Next(__pyx_t_5);
12341             if (!__pyx_t_6) {
12342               if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12343               break;
12344             }
12345             __Pyx_GOTREF(__pyx_t_6);
12346           }
12347           __Pyx_DECREF(__pyx_v_fields);
12348           __pyx_v_fields = __pyx_t_6;
12349           __pyx_t_6 = 0;
12350
12351           /* "csamtools.pyx":1179
12352  *                 else:
12353  *                     for fields in new_header[record]:
12354  *                         lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
12355  * 
12356  *         text = "\n".join(lines) + "\n"
12357  */
12358           if (unlikely(__pyx_v_lines == Py_None)) {
12359             PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
12360           }
12361           __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 = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12362           __Pyx_GOTREF(__pyx_t_6);
12363           __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12364           __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12365           __Pyx_INCREF(__pyx_v_fields);
12366           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fields);
12367           __Pyx_GIVEREF(__pyx_v_fields);
12368           __Pyx_INCREF(__pyx_v_record);
12369           PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_record);
12370           __Pyx_GIVEREF(__pyx_v_record);
12371           __pyx_t_9 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12372           __Pyx_GOTREF(__pyx_t_9);
12373           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
12374           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
12375           __pyx_t_7 = PyList_Append(__pyx_v_lines, __pyx_t_9); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12376           __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
12377         }
12378         __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
12379       }
12380       __pyx_L7:;
12381       goto __pyx_L5;
12382     }
12383     __pyx_L5:;
12384   }
12385   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
12386
12387   /* "csamtools.pyx":1181
12388  *                         lines.append( self._buildLine( fields, record ) )
12389  * 
12390  *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
12391  *         if dest.text != NULL: free( dest.text )
12392  *         dest.text = <char*>calloc( len(text), sizeof(char))
12393  */
12394   __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12395   __Pyx_GOTREF(__pyx_t_3);
12396   __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12397   __Pyx_GOTREF(((PyObject *)__pyx_t_5));
12398   __Pyx_INCREF(((PyObject *)__pyx_v_lines));
12399   PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_lines));
12400   __Pyx_GIVEREF(((PyObject *)__pyx_v_lines));
12401   __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12402   __Pyx_GOTREF(__pyx_t_9);
12403   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
12404   __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
12405   __pyx_t_5 = PyNumber_Add(__pyx_t_9, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12406   __Pyx_GOTREF(__pyx_t_5);
12407   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
12408   __Pyx_DECREF(__pyx_v_text);
12409   __pyx_v_text = __pyx_t_5;
12410   __pyx_t_5 = 0;
12411
12412   /* "csamtools.pyx":1182
12413  * 
12414  *         text = "\n".join(lines) + "\n"
12415  *         if dest.text != NULL: free( dest.text )             # <<<<<<<<<<<<<<
12416  *         dest.text = <char*>calloc( len(text), sizeof(char))
12417  *         dest.l_text = len(text)
12418  */
12419   __pyx_t_4 = (__pyx_v_dest->text != NULL);
12420   if (__pyx_t_4) {
12421     free(__pyx_v_dest->text);
12422     goto __pyx_L10;
12423   }
12424   __pyx_L10:;
12425
12426   /* "csamtools.pyx":1183
12427  *         text = "\n".join(lines) + "\n"
12428  *         if dest.text != NULL: free( dest.text )
12429  *         dest.text = <char*>calloc( len(text), sizeof(char))             # <<<<<<<<<<<<<<
12430  *         dest.l_text = len(text)
12431  *         strncpy( dest.text, text, dest.l_text )
12432  */
12433   __pyx_t_2 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12434   __pyx_v_dest->text = ((char *)calloc(__pyx_t_2, (sizeof(char))));
12435
12436   /* "csamtools.pyx":1184
12437  *         if dest.text != NULL: free( dest.text )
12438  *         dest.text = <char*>calloc( len(text), sizeof(char))
12439  *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
12440  *         strncpy( dest.text, text, dest.l_text )
12441  * 
12442  */
12443   __pyx_t_2 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12444   __pyx_v_dest->l_text = __pyx_t_2;
12445
12446   /* "csamtools.pyx":1185
12447  *         dest.text = <char*>calloc( len(text), sizeof(char))
12448  *         dest.l_text = len(text)
12449  *         strncpy( dest.text, text, dest.l_text )             # <<<<<<<<<<<<<<
12450  * 
12451  *         # collect targets
12452  */
12453   __pyx_t_10 = PyBytes_AsString(__pyx_v_text); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12454   strncpy(__pyx_v_dest->text, __pyx_t_10, __pyx_v_dest->l_text);
12455
12456   /* "csamtools.pyx":1188
12457  * 
12458  *         # collect targets
12459  *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
12460  *             seqs = []
12461  *             for fields in new_header["SQ"]:
12462  */
12463   __pyx_t_4 = ((PySequence_Contains(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12464   if (__pyx_t_4) {
12465
12466     /* "csamtools.pyx":1189
12467  *         # collect targets
12468  *         if "SQ" in new_header:
12469  *             seqs = []             # <<<<<<<<<<<<<<
12470  *             for fields in new_header["SQ"]:
12471  *                 try:
12472  */
12473     __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12474     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
12475     __Pyx_DECREF(((PyObject *)__pyx_v_seqs));
12476     __pyx_v_seqs = __pyx_t_5;
12477     __pyx_t_5 = 0;
12478
12479     /* "csamtools.pyx":1190
12480  *         if "SQ" in new_header:
12481  *             seqs = []
12482  *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
12483  *                 try:
12484  *                     seqs.append( (fields["SN"], fields["LN"] ) )
12485  */
12486     __pyx_t_5 = PyObject_GetItem(__pyx_v_new_header, ((PyObject *)__pyx_n_s__SQ)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12487     __Pyx_GOTREF(__pyx_t_5);
12488     if (PyList_CheckExact(__pyx_t_5) || PyTuple_CheckExact(__pyx_t_5)) {
12489       __pyx_t_2 = 0; __pyx_t_9 = __pyx_t_5; __Pyx_INCREF(__pyx_t_9);
12490     } else {
12491       __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12492       __Pyx_GOTREF(__pyx_t_9);
12493     }
12494     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
12495     for (;;) {
12496       if (likely(PyList_CheckExact(__pyx_t_9))) {
12497         if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
12498         __pyx_t_5 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++;
12499       } else if (likely(PyTuple_CheckExact(__pyx_t_9))) {
12500         if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
12501         __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++;
12502       } else {
12503         __pyx_t_5 = PyIter_Next(__pyx_t_9);
12504         if (!__pyx_t_5) {
12505           if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12506           break;
12507         }
12508         __Pyx_GOTREF(__pyx_t_5);
12509       }
12510       __Pyx_DECREF(__pyx_v_fields);
12511       __pyx_v_fields = __pyx_t_5;
12512       __pyx_t_5 = 0;
12513
12514       /* "csamtools.pyx":1191
12515  *             seqs = []
12516  *             for fields in new_header["SQ"]:
12517  *                 try:             # <<<<<<<<<<<<<<
12518  *                     seqs.append( (fields["SN"], fields["LN"] ) )
12519  *                 except KeyError:
12520  */
12521       {
12522         PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
12523         __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
12524         __Pyx_XGOTREF(__pyx_save_exc_type);
12525         __Pyx_XGOTREF(__pyx_save_exc_value);
12526         __Pyx_XGOTREF(__pyx_save_exc_tb);
12527         /*try:*/ {
12528
12529           /* "csamtools.pyx":1192
12530  *             for fields in new_header["SQ"]:
12531  *                 try:
12532  *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
12533  *                 except KeyError:
12534  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
12535  */
12536           if (unlikely(__pyx_v_seqs == Py_None)) {
12537             PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L14_error;} 
12538           }
12539           __pyx_t_5 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__SN)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
12540           __Pyx_GOTREF(__pyx_t_5);
12541           __pyx_t_3 = PyObject_GetItem(__pyx_v_fields, ((PyObject *)__pyx_n_s__LN)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
12542           __Pyx_GOTREF(__pyx_t_3);
12543           __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
12544           __Pyx_GOTREF(((PyObject *)__pyx_t_1));
12545           PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
12546           __Pyx_GIVEREF(__pyx_t_5);
12547           PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
12548           __Pyx_GIVEREF(__pyx_t_3);
12549           __pyx_t_5 = 0;
12550           __pyx_t_3 = 0;
12551           __pyx_t_7 = PyList_Append(__pyx_v_seqs, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L14_error;}
12552           __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
12553         }
12554         __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
12555         __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
12556         __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
12557         goto __pyx_L21_try_end;
12558         __pyx_L14_error:;
12559         __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
12560         __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
12561         __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
12562         __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
12563
12564         /* "csamtools.pyx":1193
12565  *                 try:
12566  *                     seqs.append( (fields["SN"], fields["LN"] ) )
12567  *                 except KeyError:             # <<<<<<<<<<<<<<
12568  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
12569  * 
12570  */
12571         __pyx_t_7 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
12572         if (__pyx_t_7) {
12573           __Pyx_AddTraceback("csamtools.Samfile._buildHeader");
12574           if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12575           __Pyx_GOTREF(__pyx_t_1);
12576           __Pyx_GOTREF(__pyx_t_3);
12577           __Pyx_GOTREF(__pyx_t_5);
12578
12579           /* "csamtools.pyx":1194
12580  *                     seqs.append( (fields["SN"], fields["LN"] ) )
12581  *                 except KeyError:
12582  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
12583  * 
12584  *             dest.n_targets = len(seqs)
12585  */
12586           __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12587           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
12588           __Pyx_INCREF(__pyx_v_fields);
12589           PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fields);
12590           __Pyx_GIVEREF(__pyx_v_fields);
12591           __pyx_t_11 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12592           __Pyx_GOTREF(__pyx_t_11);
12593           __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
12594           __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_101), __pyx_t_11); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12595           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
12596           __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
12597           __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12598           __Pyx_GOTREF(((PyObject *)__pyx_t_11));
12599           PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_6));
12600           __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
12601           __pyx_t_6 = 0;
12602           __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12603           __Pyx_GOTREF(__pyx_t_6);
12604           __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
12605           __Pyx_Raise(__pyx_t_6, 0, 0);
12606           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
12607           {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L16_except_error;}
12608           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12609           __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
12610           __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
12611           goto __pyx_L15_exception_handled;
12612         }
12613         __pyx_L16_except_error:;
12614         __Pyx_XGIVEREF(__pyx_save_exc_type);
12615         __Pyx_XGIVEREF(__pyx_save_exc_value);
12616         __Pyx_XGIVEREF(__pyx_save_exc_tb);
12617         __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
12618         goto __pyx_L1_error;
12619         __pyx_L15_exception_handled:;
12620         __Pyx_XGIVEREF(__pyx_save_exc_type);
12621         __Pyx_XGIVEREF(__pyx_save_exc_value);
12622         __Pyx_XGIVEREF(__pyx_save_exc_tb);
12623         __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
12624         __pyx_L21_try_end:;
12625       }
12626     }
12627     __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
12628
12629     /* "csamtools.pyx":1196
12630  *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
12631  * 
12632  *             dest.n_targets = len(seqs)             # <<<<<<<<<<<<<<
12633  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
12634  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
12635  */
12636     if (unlikely(__pyx_v_seqs == Py_None)) {
12637       PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
12638     }
12639     __pyx_t_2 = PyList_GET_SIZE(((PyObject *)__pyx_v_seqs)); 
12640     __pyx_v_dest->n_targets = __pyx_t_2;
12641
12642     /* "csamtools.pyx":1197
12643  * 
12644  *             dest.n_targets = len(seqs)
12645  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )             # <<<<<<<<<<<<<<
12646  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
12647  * 
12648  */
12649     __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *))));
12650
12651     /* "csamtools.pyx":1198
12652  *             dest.n_targets = len(seqs)
12653  *             dest.target_name = <char**>calloc( dest.n_targets, sizeof(char*) )
12654  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )             # <<<<<<<<<<<<<<
12655  * 
12656  *             for x from 0 <= x < dest.n_targets:
12657  */
12658     __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t))));
12659
12660     /* "csamtools.pyx":1200
12661  *             dest.target_len = <uint32_t*>calloc( dest.n_targets, sizeof(uint32_t) )
12662  * 
12663  *             for x from 0 <= x < dest.n_targets:             # <<<<<<<<<<<<<<
12664  *                 seqname, seqlen = seqs[x]
12665  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
12666  */
12667     __pyx_t_12 = __pyx_v_dest->n_targets;
12668     for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_12; __pyx_v_x++) {
12669
12670       /* "csamtools.pyx":1201
12671  * 
12672  *             for x from 0 <= x < dest.n_targets:
12673  *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
12674  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
12675  *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
12676  */
12677       __pyx_t_9 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_seqs), __pyx_v_x, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12678       __Pyx_GOTREF(__pyx_t_9);
12679       if (PyTuple_CheckExact(__pyx_t_9) && likely(PyTuple_GET_SIZE(__pyx_t_9) == 2)) {
12680         PyObject* tuple = __pyx_t_9;
12681         __pyx_t_5 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_5);
12682         __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
12683         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
12684         __Pyx_DECREF(__pyx_v_seqname);
12685         __pyx_v_seqname = __pyx_t_5;
12686         __pyx_t_5 = 0;
12687         __Pyx_DECREF(__pyx_v_seqlen);
12688         __pyx_v_seqlen = __pyx_t_3;
12689         __pyx_t_3 = 0;
12690       } else {
12691         __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12692         __Pyx_GOTREF(__pyx_t_1);
12693         __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
12694         __pyx_t_5 = __Pyx_UnpackItem(__pyx_t_1, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12695         __Pyx_GOTREF(__pyx_t_5);
12696         __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_1, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12697         __Pyx_GOTREF(__pyx_t_3);
12698         if (__Pyx_EndUnpack(__pyx_t_1, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12699         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12700         __Pyx_DECREF(__pyx_v_seqname);
12701         __pyx_v_seqname = __pyx_t_5;
12702         __pyx_t_5 = 0;
12703         __Pyx_DECREF(__pyx_v_seqlen);
12704         __pyx_v_seqlen = __pyx_t_3;
12705         __pyx_t_3 = 0;
12706       }
12707
12708       /* "csamtools.pyx":1202
12709  *             for x from 0 <= x < dest.n_targets:
12710  *                 seqname, seqlen = seqs[x]
12711  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )             # <<<<<<<<<<<<<<
12712  *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
12713  *                 dest.target_len[x] = seqlen
12714  */
12715       __pyx_t_2 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12716       (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_2 + 1), (sizeof(char))));
12717
12718       /* "csamtools.pyx":1203
12719  *                 seqname, seqlen = seqs[x]
12720  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
12721  *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )             # <<<<<<<<<<<<<<
12722  *                 dest.target_len[x] = seqlen
12723  * 
12724  */
12725       __pyx_t_10 = PyBytes_AsString(__pyx_v_seqname); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12726       __pyx_t_2 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12727       strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_10, (__pyx_t_2 + 1));
12728
12729       /* "csamtools.pyx":1204
12730  *                 dest.target_name[x] = <char*>calloc( len( seqname ) + 1, sizeof(char) )
12731  *                 strncpy( dest.target_name[x], seqname, len(seqname) + 1 )
12732  *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
12733  * 
12734  *         return dest
12735  */
12736       __pyx_t_13 = __Pyx_PyInt_from_py_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_13 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12737       (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_13;
12738     }
12739     goto __pyx_L11;
12740   }
12741   __pyx_L11:;
12742
12743   /* "csamtools.pyx":1206
12744  *                 dest.target_len[x] = seqlen
12745  * 
12746  *         return dest             # <<<<<<<<<<<<<<
12747  * 
12748  *     ###############################################################
12749  */
12750   __pyx_r = __pyx_v_dest;
12751   goto __pyx_L0;
12752
12753   __pyx_r = 0;
12754   goto __pyx_L0;
12755   __pyx_L1_error:;
12756   __Pyx_XDECREF(__pyx_t_1);
12757   __Pyx_XDECREF(__pyx_t_3);
12758   __Pyx_XDECREF(__pyx_t_5);
12759   __Pyx_XDECREF(__pyx_t_6);
12760   __Pyx_XDECREF(__pyx_t_9);
12761   __Pyx_XDECREF(__pyx_t_11);
12762   __Pyx_WriteUnraisable("csamtools.Samfile._buildHeader");
12763   __pyx_r = 0;
12764   __pyx_L0:;
12765   __Pyx_DECREF(__pyx_v_lines);
12766   __Pyx_DECREF(__pyx_v_record);
12767   __Pyx_DECREF(__pyx_v_ttype);
12768   __Pyx_DECREF(__pyx_v_data);
12769   __Pyx_DECREF(__pyx_v_fields);
12770   __Pyx_DECREF(__pyx_v_text);
12771   __Pyx_DECREF(__pyx_v_seqs);
12772   __Pyx_DECREF(__pyx_v_seqname);
12773   __Pyx_DECREF(__pyx_v_seqlen);
12774   __Pyx_TraceReturn(Py_None);
12775   __Pyx_RefNannyFinishContext();
12776   return __pyx_r;
12777 }
12778
12779 /* "csamtools.pyx":1216
12780  *     ## Possible solutions: deprecate or open new file handle
12781  *     ###############################################################
12782  *     def __iter__(self):             # <<<<<<<<<<<<<<
12783  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12784  *         if not self.isbam and self.samfile.header.n_targets == 0:
12785  */
12786
12787 static PyObject *__pyx_pf_9csamtools_7Samfile_20__iter__(PyObject *__pyx_v_self); /*proto*/
12788 static PyObject *__pyx_pf_9csamtools_7Samfile_20__iter__(PyObject *__pyx_v_self) {
12789   PyObject *__pyx_r = NULL;
12790   PyObject *__pyx_t_1 = NULL;
12791   PyObject *__pyx_t_2 = NULL;
12792   int __pyx_t_3;
12793   int __pyx_t_4;
12794   int __pyx_t_5;
12795   __Pyx_TraceDeclarations
12796   __Pyx_RefNannySetupContext("__iter__");
12797   __Pyx_TraceCall("__iter__", __pyx_f[0], 1216);
12798
12799   /* "csamtools.pyx":1217
12800  *     ###############################################################
12801  *     def __iter__(self):
12802  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
12803  *         if not self.isbam and self.samfile.header.n_targets == 0:
12804  *                 raise NotImplementedError( "can not iterate over samfile without header")
12805  */
12806   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___isOpen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12807   __Pyx_GOTREF(__pyx_t_1);
12808   __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 = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12809   __Pyx_GOTREF(__pyx_t_2);
12810   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
12811   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12812   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12813   __pyx_t_4 = (!__pyx_t_3);
12814   if (__pyx_t_4) {
12815     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_102), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12816     __Pyx_GOTREF(__pyx_t_2);
12817     __Pyx_Raise(__pyx_t_2, 0, 0);
12818     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12819     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12820     goto __pyx_L5;
12821   }
12822   __pyx_L5:;
12823
12824   /* "csamtools.pyx":1218
12825  *     def __iter__(self):
12826  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12827  *         if not self.isbam and self.samfile.header.n_targets == 0:             # <<<<<<<<<<<<<<
12828  *                 raise NotImplementedError( "can not iterate over samfile without header")
12829  *         return self
12830  */
12831   __pyx_t_4 = (!((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->isbam);
12832   if (__pyx_t_4) {
12833     __pyx_t_3 = (((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile->header->n_targets == 0);
12834     __pyx_t_5 = __pyx_t_3;
12835   } else {
12836     __pyx_t_5 = __pyx_t_4;
12837   }
12838   if (__pyx_t_5) {
12839
12840     /* "csamtools.pyx":1219
12841  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
12842  *         if not self.isbam and self.samfile.header.n_targets == 0:
12843  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
12844  *         return self
12845  * 
12846  */
12847     __pyx_t_2 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_104), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12848     __Pyx_GOTREF(__pyx_t_2);
12849     __Pyx_Raise(__pyx_t_2, 0, 0);
12850     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
12851     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12852     goto __pyx_L6;
12853   }
12854   __pyx_L6:;
12855
12856   /* "csamtools.pyx":1220
12857  *         if not self.isbam and self.samfile.header.n_targets == 0:
12858  *                 raise NotImplementedError( "can not iterate over samfile without header")
12859  *         return self             # <<<<<<<<<<<<<<
12860  * 
12861  *     cdef bam1_t * getCurrent( self ):
12862  */
12863   __Pyx_XDECREF(__pyx_r);
12864   __Pyx_INCREF(__pyx_v_self);
12865   __pyx_r = __pyx_v_self;
12866   goto __pyx_L0;
12867
12868   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
12869   goto __pyx_L0;
12870   __pyx_L1_error:;
12871   __Pyx_XDECREF(__pyx_t_1);
12872   __Pyx_XDECREF(__pyx_t_2);
12873   __Pyx_AddTraceback("csamtools.Samfile.__iter__");
12874   __pyx_r = NULL;
12875   __pyx_L0:;
12876   __Pyx_XGIVEREF(__pyx_r);
12877   __Pyx_TraceReturn(__pyx_r);
12878   __Pyx_RefNannyFinishContext();
12879   return __pyx_r;
12880 }
12881
12882 /* "csamtools.pyx":1222
12883  *         return self
12884  * 
12885  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
12886  *         return self.b
12887  * 
12888  */
12889
12890 static  bam1_t *__pyx_f_9csamtools_7Samfile_getCurrent(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12891   bam1_t *__pyx_r;
12892   __Pyx_TraceDeclarations
12893   __Pyx_RefNannySetupContext("getCurrent");
12894   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1222);
12895
12896   /* "csamtools.pyx":1223
12897  * 
12898  *     cdef bam1_t * getCurrent( self ):
12899  *         return self.b             # <<<<<<<<<<<<<<
12900  * 
12901  *     cdef int cnext(self):
12902  */
12903   __pyx_r = __pyx_v_self->b;
12904   goto __pyx_L0;
12905
12906   __pyx_r = 0;
12907   __pyx_L0:;
12908   __Pyx_TraceReturn(Py_None);
12909   __Pyx_RefNannyFinishContext();
12910   return __pyx_r;
12911 }
12912
12913 /* "csamtools.pyx":1225
12914  *         return self.b
12915  * 
12916  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
12917  *         '''
12918  *         cversion of iterator. Used by :class:`pysam.Samfile.IteratorColumn`.
12919  */
12920
12921 static  int __pyx_f_9csamtools_7Samfile_cnext(struct __pyx_obj_9csamtools_Samfile *__pyx_v_self) {
12922   int __pyx_r;
12923   __Pyx_TraceDeclarations
12924   __Pyx_RefNannySetupContext("cnext");
12925   __Pyx_TraceCall("cnext", __pyx_f[0], 1225);
12926
12927   /* "csamtools.pyx":1230
12928  *         '''
12929  *         cdef int ret
12930  *         return samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
12931  * 
12932  *     def __next__(self):
12933  */
12934   __pyx_r = samread(__pyx_v_self->samfile, __pyx_v_self->b);
12935   goto __pyx_L0;
12936
12937   __pyx_r = 0;
12938   __pyx_L0:;
12939   __Pyx_TraceReturn(Py_None);
12940   __Pyx_RefNannyFinishContext();
12941   return __pyx_r;
12942 }
12943
12944 /* "csamtools.pyx":1232
12945  *         return samread(self.samfile, self.b)
12946  * 
12947  *     def __next__(self):             # <<<<<<<<<<<<<<
12948  *         """
12949  *         python version of next().
12950  */
12951
12952 static PyObject *__pyx_pf_9csamtools_7Samfile_21__next__(PyObject *__pyx_v_self); /*proto*/
12953 static char __pyx_doc_9csamtools_7Samfile_21__next__[] = "\n        python version of next().\n        ";
12954 struct wrapperbase __pyx_wrapperbase_9csamtools_7Samfile_21__next__;
12955 static PyObject *__pyx_pf_9csamtools_7Samfile_21__next__(PyObject *__pyx_v_self) {
12956   int __pyx_v_ret;
12957   PyObject *__pyx_r = NULL;
12958   int __pyx_t_1;
12959   PyObject *__pyx_t_2 = NULL;
12960   __Pyx_TraceDeclarations
12961   __Pyx_RefNannySetupContext("__next__");
12962   __Pyx_TraceCall("__next__", __pyx_f[0], 1232);
12963
12964   /* "csamtools.pyx":1237
12965  *         """
12966  *         cdef int ret
12967  *         ret = samread(self.samfile, self.b)             # <<<<<<<<<<<<<<
12968  *         if (ret > 0):
12969  *             return makeAlignedRead( self.b )
12970  */
12971   __pyx_v_ret = samread(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->samfile, ((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->b);
12972
12973   /* "csamtools.pyx":1238
12974  *         cdef int ret
12975  *         ret = samread(self.samfile, self.b)
12976  *         if (ret > 0):             # <<<<<<<<<<<<<<
12977  *             return makeAlignedRead( self.b )
12978  *         else:
12979  */
12980   __pyx_t_1 = (__pyx_v_ret > 0);
12981   if (__pyx_t_1) {
12982
12983     /* "csamtools.pyx":1239
12984  *         ret = samread(self.samfile, self.b)
12985  *         if (ret > 0):
12986  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
12987  *         else:
12988  *             raise StopIteration
12989  */
12990     __Pyx_XDECREF(__pyx_r);
12991     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(((struct __pyx_obj_9csamtools_Samfile *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
12992     __Pyx_GOTREF(__pyx_t_2);
12993     __pyx_r = __pyx_t_2;
12994     __pyx_t_2 = 0;
12995     goto __pyx_L0;
12996     goto __pyx_L5;
12997   }
12998   /*else*/ {
12999
13000     /* "csamtools.pyx":1241
13001  *             return makeAlignedRead( self.b )
13002  *         else:
13003  *             raise StopIteration             # <<<<<<<<<<<<<<
13004  * 
13005  * ##-------------------------------------------------------------------
13006  */
13007     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
13008     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13009   }
13010   __pyx_L5:;
13011
13012   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13013   goto __pyx_L0;
13014   __pyx_L1_error:;
13015   __Pyx_XDECREF(__pyx_t_2);
13016   __Pyx_AddTraceback("csamtools.Samfile.__next__");
13017   __pyx_r = NULL;
13018   __pyx_L0:;
13019   __Pyx_XGIVEREF(__pyx_r);
13020   __Pyx_TraceReturn(__pyx_r);
13021   __Pyx_RefNannyFinishContext();
13022   return __pyx_r;
13023 }
13024
13025 /* "csamtools.pyx":1293
13026  *     cdef int owns_samfile
13027  * 
13028  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):             # <<<<<<<<<<<<<<
13029  * 
13030  *         if not samfile._isOpen():
13031  */
13032
13033 static int __pyx_pf_9csamtools_17IteratorRowRegion___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
13034 static int __pyx_pf_9csamtools_17IteratorRowRegion___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
13035   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
13036   int __pyx_v_tid;
13037   int __pyx_v_beg;
13038   int __pyx_v_end;
13039   int __pyx_v_reopen;
13040   PyObject *__pyx_v_mode;
13041   PyObject *__pyx_v_store;
13042   int __pyx_r;
13043   PyObject *__pyx_t_1 = NULL;
13044   PyObject *__pyx_t_2 = NULL;
13045   int __pyx_t_3;
13046   int __pyx_t_4;
13047   char *__pyx_t_5;
13048   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};
13049   __Pyx_TraceDeclarations
13050   __Pyx_RefNannySetupContext("__cinit__");
13051   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1293);
13052   if (unlikely(__pyx_kwds)) {
13053     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
13054     PyObject* values[5] = {0,0,0,0,0};
13055     switch (PyTuple_GET_SIZE(__pyx_args)) {
13056       case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
13057       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
13058       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
13059       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
13060       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
13061       case  0: break;
13062       default: goto __pyx_L5_argtuple_error;
13063     }
13064     switch (PyTuple_GET_SIZE(__pyx_args)) {
13065       case  0:
13066       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
13067       if (likely(values[0])) kw_args--;
13068       else goto __pyx_L5_argtuple_error;
13069       case  1:
13070       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
13071       if (likely(values[1])) kw_args--;
13072       else {
13073         __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13074       }
13075       case  2:
13076       values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beg);
13077       if (likely(values[2])) kw_args--;
13078       else {
13079         __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13080       }
13081       case  3:
13082       values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
13083       if (likely(values[3])) kw_args--;
13084       else {
13085         __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13086       }
13087       case  4:
13088       if (kw_args > 0) {
13089         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
13090         if (value) { values[4] = value; kw_args--; }
13091       }
13092     }
13093     if (unlikely(kw_args > 0)) {
13094       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13095     }
13096     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
13097     __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13098     __pyx_v_beg = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13099     __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13100     if (values[4]) {
13101       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[4]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13102     } else {
13103       __pyx_v_reopen = ((int)1);
13104     }
13105   } else {
13106     __pyx_v_reopen = ((int)1);
13107     switch (PyTuple_GET_SIZE(__pyx_args)) {
13108       case  5:
13109       __pyx_v_reopen = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 4)); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13110       case  4:
13111       __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13112       __pyx_v_beg = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13113       __pyx_v_tid = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13114       __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
13115       break;
13116       default: goto __pyx_L5_argtuple_error;
13117     }
13118   }
13119   goto __pyx_L4_argument_unpacking_done;
13120   __pyx_L5_argtuple_error:;
13121   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13122   __pyx_L3_error:;
13123   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__cinit__");
13124   __Pyx_RefNannyFinishContext();
13125   return -1;
13126   __pyx_L4_argument_unpacking_done:;
13127   __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
13128   __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
13129   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13130
13131   /* "csamtools.pyx":1295
13132  *     def __cinit__(self, Samfile samfile, int tid, int beg, int end, int reopen = True ):
13133  * 
13134  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
13135  *             raise ValueError( "I/O operation on closed file" )
13136  * 
13137  */
13138   __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13139   __Pyx_GOTREF(__pyx_t_1);
13140   __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 = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13141   __Pyx_GOTREF(__pyx_t_2);
13142   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13143   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13144   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13145   __pyx_t_4 = (!__pyx_t_3);
13146   if (__pyx_t_4) {
13147
13148     /* "csamtools.pyx":1296
13149  * 
13150  *         if not samfile._isOpen():
13151  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
13152  * 
13153  *         if not samfile._hasIndex():
13154  */
13155     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13156     __Pyx_GOTREF(__pyx_t_2);
13157     __Pyx_Raise(__pyx_t_2, 0, 0);
13158     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13159     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13160     goto __pyx_L6;
13161   }
13162   __pyx_L6:;
13163
13164   /* "csamtools.pyx":1298
13165  *             raise ValueError( "I/O operation on closed file" )
13166  * 
13167  *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
13168  *             raise ValueError( "no index available for iteration" )
13169  * 
13170  */
13171   __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 = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13172   __Pyx_GOTREF(__pyx_t_2);
13173   __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 = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13174   __Pyx_GOTREF(__pyx_t_1);
13175   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13176   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13177   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13178   __pyx_t_3 = (!__pyx_t_4);
13179   if (__pyx_t_3) {
13180
13181     /* "csamtools.pyx":1299
13182  * 
13183  *         if not samfile._hasIndex():
13184  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
13185  * 
13186  *         # makes sure that samfile stays alive as long as the
13187  */
13188     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_107), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13189     __Pyx_GOTREF(__pyx_t_1);
13190     __Pyx_Raise(__pyx_t_1, 0, 0);
13191     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13192     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13193     goto __pyx_L7;
13194   }
13195   __pyx_L7:;
13196
13197   /* "csamtools.pyx":1303
13198  *         # makes sure that samfile stays alive as long as the
13199  *         # iterator is alive
13200  *         self.samfile = samfile             # <<<<<<<<<<<<<<
13201  * 
13202  *         if samfile.isbam: mode = "rb"
13203  */
13204   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
13205   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
13206   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->samfile);
13207   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->samfile));
13208   ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->samfile = __pyx_v_samfile;
13209
13210   /* "csamtools.pyx":1305
13211  *         self.samfile = samfile
13212  * 
13213  *         if samfile.isbam: mode = "rb"             # <<<<<<<<<<<<<<
13214  *         else: mode = "r"
13215  * 
13216  */
13217   if (__pyx_v_samfile->isbam) {
13218     __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
13219     __Pyx_DECREF(__pyx_v_mode);
13220     __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
13221     goto __pyx_L8;
13222   }
13223   /*else*/ {
13224
13225     /* "csamtools.pyx":1306
13226  * 
13227  *         if samfile.isbam: mode = "rb"
13228  *         else: mode = "r"             # <<<<<<<<<<<<<<
13229  * 
13230  *         # reopen the file - note that this makes the iterator
13231  */
13232     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
13233     __Pyx_DECREF(__pyx_v_mode);
13234     __pyx_v_mode = ((PyObject *)__pyx_n_s__r);
13235   }
13236   __pyx_L8:;
13237
13238   /* "csamtools.pyx":1310
13239  *         # reopen the file - note that this makes the iterator
13240  *         # slow and causes pileup to slow down significantly.
13241  *         if reopen:             # <<<<<<<<<<<<<<
13242  *             store = StderrStore()
13243  *             self.fp = samopen( samfile._filename, mode, NULL )
13244  */
13245   if (__pyx_v_reopen) {
13246
13247     /* "csamtools.pyx":1311
13248  *         # slow and causes pileup to slow down significantly.
13249  *         if reopen:
13250  *             store = StderrStore()             # <<<<<<<<<<<<<<
13251  *             self.fp = samopen( samfile._filename, mode, NULL )
13252  *             store.release()
13253  */
13254     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13255     __Pyx_GOTREF(__pyx_t_1);
13256     __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 = 1311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13257     __Pyx_GOTREF(__pyx_t_2);
13258     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13259     __Pyx_DECREF(__pyx_v_store);
13260     __pyx_v_store = __pyx_t_2;
13261     __pyx_t_2 = 0;
13262
13263     /* "csamtools.pyx":1312
13264  *         if reopen:
13265  *             store = StderrStore()
13266  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
13267  *             store.release()
13268  *             assert self.fp != NULL
13269  */
13270     __pyx_t_5 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13271     ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
13272
13273     /* "csamtools.pyx":1313
13274  *             store = StderrStore()
13275  *             self.fp = samopen( samfile._filename, mode, NULL )
13276  *             store.release()             # <<<<<<<<<<<<<<
13277  *             assert self.fp != NULL
13278  *             self.owns_samfile = True
13279  */
13280     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13281     __Pyx_GOTREF(__pyx_t_2);
13282     __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 = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13283     __Pyx_GOTREF(__pyx_t_1);
13284     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13285     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13286
13287     /* "csamtools.pyx":1314
13288  *             self.fp = samopen( samfile._filename, mode, NULL )
13289  *             store.release()
13290  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
13291  *             self.owns_samfile = True
13292  *         else:
13293  */
13294     #ifndef CYTHON_WITHOUT_ASSERTIONS
13295     if (unlikely(!(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->fp != NULL))) {
13296       PyErr_SetNone(PyExc_AssertionError);
13297       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13298     }
13299     #endif
13300
13301     /* "csamtools.pyx":1315
13302  *             store.release()
13303  *             assert self.fp != NULL
13304  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
13305  *         else:
13306  *             self.fp = self.samfile.samfile
13307  */
13308     ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->owns_samfile = 1;
13309     goto __pyx_L9;
13310   }
13311   /*else*/ {
13312
13313     /* "csamtools.pyx":1317
13314  *             self.owns_samfile = True
13315  *         else:
13316  *             self.fp = self.samfile.samfile             # <<<<<<<<<<<<<<
13317  *             self.owns_samfile = False
13318  * 
13319  */
13320     ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->fp = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->samfile->samfile;
13321
13322     /* "csamtools.pyx":1318
13323  *         else:
13324  *             self.fp = self.samfile.samfile
13325  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
13326  * 
13327  *         self.retval = 0
13328  */
13329     ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->owns_samfile = 0;
13330   }
13331   __pyx_L9:;
13332
13333   /* "csamtools.pyx":1320
13334  *             self.owns_samfile = False
13335  * 
13336  *         self.retval = 0             # <<<<<<<<<<<<<<
13337  * 
13338  *         self.iter = bam_iter_query(self.samfile.index,
13339  */
13340   ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->retval = 0;
13341
13342   /* "csamtools.pyx":1322
13343  *         self.retval = 0
13344  * 
13345  *         self.iter = bam_iter_query(self.samfile.index,             # <<<<<<<<<<<<<<
13346  *                                    tid,
13347  *                                    beg,
13348  */
13349   ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->iter = bam_iter_query(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);
13350
13351   /* "csamtools.pyx":1326
13352  *                                    beg,
13353  *                                    end)
13354  *         self.b = bam_init1()             # <<<<<<<<<<<<<<
13355  * 
13356  *     def __iter__(self):
13357  */
13358   ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->b = bam_init1();
13359
13360   __pyx_r = 0;
13361   goto __pyx_L0;
13362   __pyx_L1_error:;
13363   __Pyx_XDECREF(__pyx_t_1);
13364   __Pyx_XDECREF(__pyx_t_2);
13365   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__cinit__");
13366   __pyx_r = -1;
13367   __pyx_L0:;
13368   __Pyx_DECREF(__pyx_v_mode);
13369   __Pyx_DECREF(__pyx_v_store);
13370   __Pyx_TraceReturn(Py_None);
13371   __Pyx_RefNannyFinishContext();
13372   return __pyx_r;
13373 }
13374
13375 /* "csamtools.pyx":1328
13376  *         self.b = bam_init1()
13377  * 
13378  *     def __iter__(self):             # <<<<<<<<<<<<<<
13379  *         return self
13380  * 
13381  */
13382
13383 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_1__iter__(PyObject *__pyx_v_self); /*proto*/
13384 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_1__iter__(PyObject *__pyx_v_self) {
13385   PyObject *__pyx_r = NULL;
13386   __Pyx_TraceDeclarations
13387   __Pyx_RefNannySetupContext("__iter__");
13388   __Pyx_TraceCall("__iter__", __pyx_f[0], 1328);
13389
13390   /* "csamtools.pyx":1329
13391  * 
13392  *     def __iter__(self):
13393  *         return self             # <<<<<<<<<<<<<<
13394  * 
13395  *     cdef bam1_t * getCurrent( self ):
13396  */
13397   __Pyx_XDECREF(__pyx_r);
13398   __Pyx_INCREF(__pyx_v_self);
13399   __pyx_r = __pyx_v_self;
13400   goto __pyx_L0;
13401
13402   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13403   __pyx_L0:;
13404   __Pyx_XGIVEREF(__pyx_r);
13405   __Pyx_TraceReturn(__pyx_r);
13406   __Pyx_RefNannyFinishContext();
13407   return __pyx_r;
13408 }
13409
13410 /* "csamtools.pyx":1331
13411  *         return self
13412  * 
13413  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
13414  *         return self.b
13415  * 
13416  */
13417
13418 static  bam1_t *__pyx_f_9csamtools_17IteratorRowRegion_getCurrent(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
13419   bam1_t *__pyx_r;
13420   __Pyx_TraceDeclarations
13421   __Pyx_RefNannySetupContext("getCurrent");
13422   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1331);
13423
13424   /* "csamtools.pyx":1332
13425  * 
13426  *     cdef bam1_t * getCurrent( self ):
13427  *         return self.b             # <<<<<<<<<<<<<<
13428  * 
13429  *     cdef int cnext(self):
13430  */
13431   __pyx_r = __pyx_v_self->b;
13432   goto __pyx_L0;
13433
13434   __pyx_r = 0;
13435   __pyx_L0:;
13436   __Pyx_TraceReturn(Py_None);
13437   __Pyx_RefNannyFinishContext();
13438   return __pyx_r;
13439 }
13440
13441 /* "csamtools.pyx":1334
13442  *         return self.b
13443  * 
13444  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
13445  *         '''cversion of iterator. Used by IteratorColumn'''
13446  *         self.retval = bam_iter_read( self.fp.x.bam,
13447  */
13448
13449 static  int __pyx_f_9csamtools_17IteratorRowRegion_cnext(struct __pyx_obj_9csamtools_IteratorRowRegion *__pyx_v_self) {
13450   int __pyx_r;
13451   __Pyx_TraceDeclarations
13452   __Pyx_RefNannySetupContext("cnext");
13453   __Pyx_TraceCall("cnext", __pyx_f[0], 1334);
13454
13455   /* "csamtools.pyx":1336
13456  *     cdef int cnext(self):
13457  *         '''cversion of iterator. Used by IteratorColumn'''
13458  *         self.retval = bam_iter_read( self.fp.x.bam,             # <<<<<<<<<<<<<<
13459  *                                      self.iter,
13460  *                                      self.b)
13461  */
13462   __pyx_v_self->retval = bam_iter_read(__pyx_v_self->fp->x.bam, __pyx_v_self->iter, __pyx_v_self->b);
13463
13464   __pyx_r = 0;
13465   __Pyx_TraceReturn(Py_None);
13466   __Pyx_RefNannyFinishContext();
13467   return __pyx_r;
13468 }
13469
13470 /* "csamtools.pyx":1340
13471  *                                      self.b)
13472  * 
13473  *     def __next__(self):             # <<<<<<<<<<<<<<
13474  *         """python version of next().
13475  *         """
13476  */
13477
13478 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_2__next__(PyObject *__pyx_v_self); /*proto*/
13479 static char __pyx_doc_9csamtools_17IteratorRowRegion_2__next__[] = "python version of next().\n        ";
13480 struct wrapperbase __pyx_wrapperbase_9csamtools_17IteratorRowRegion_2__next__;
13481 static PyObject *__pyx_pf_9csamtools_17IteratorRowRegion_2__next__(PyObject *__pyx_v_self) {
13482   PyObject *__pyx_r = NULL;
13483   int __pyx_t_1;
13484   PyObject *__pyx_t_2 = NULL;
13485   __Pyx_TraceDeclarations
13486   __Pyx_RefNannySetupContext("__next__");
13487   __Pyx_TraceCall("__next__", __pyx_f[0], 1340);
13488
13489   /* "csamtools.pyx":1343
13490  *         """python version of next().
13491  *         """
13492  *         self.cnext()             # <<<<<<<<<<<<<<
13493  *         if self.retval < 0: raise StopIteration
13494  *         return makeAlignedRead( self.b )
13495  */
13496   ((struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *)((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->__pyx_vtab)->cnext(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self));
13497
13498   /* "csamtools.pyx":1344
13499  *         """
13500  *         self.cnext()
13501  *         if self.retval < 0: raise StopIteration             # <<<<<<<<<<<<<<
13502  *         return makeAlignedRead( self.b )
13503  * 
13504  */
13505   __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->retval < 0);
13506   if (__pyx_t_1) {
13507     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
13508     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13509     goto __pyx_L5;
13510   }
13511   __pyx_L5:;
13512
13513   /* "csamtools.pyx":1345
13514  *         self.cnext()
13515  *         if self.retval < 0: raise StopIteration
13516  *         return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
13517  * 
13518  *     def __dealloc__(self):
13519  */
13520   __Pyx_XDECREF(__pyx_r);
13521   __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13522   __Pyx_GOTREF(__pyx_t_2);
13523   __pyx_r = __pyx_t_2;
13524   __pyx_t_2 = 0;
13525   goto __pyx_L0;
13526
13527   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13528   goto __pyx_L0;
13529   __pyx_L1_error:;
13530   __Pyx_XDECREF(__pyx_t_2);
13531   __Pyx_AddTraceback("csamtools.IteratorRowRegion.__next__");
13532   __pyx_r = NULL;
13533   __pyx_L0:;
13534   __Pyx_XGIVEREF(__pyx_r);
13535   __Pyx_TraceReturn(__pyx_r);
13536   __Pyx_RefNannyFinishContext();
13537   return __pyx_r;
13538 }
13539
13540 /* "csamtools.pyx":1347
13541  *         return makeAlignedRead( self.b )
13542  * 
13543  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
13544  *         bam_destroy1(self.b)
13545  *         if self.owns_samfile: samclose( self.fp )
13546  */
13547
13548 static void __pyx_pf_9csamtools_17IteratorRowRegion_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
13549 static void __pyx_pf_9csamtools_17IteratorRowRegion_3__dealloc__(PyObject *__pyx_v_self) {
13550   __Pyx_TraceDeclarations
13551   __Pyx_RefNannySetupContext("__dealloc__");
13552   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1347);
13553
13554   /* "csamtools.pyx":1348
13555  * 
13556  *     def __dealloc__(self):
13557  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
13558  *         if self.owns_samfile: samclose( self.fp )
13559  * 
13560  */
13561   bam_destroy1(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->b);
13562
13563   /* "csamtools.pyx":1349
13564  *     def __dealloc__(self):
13565  *         bam_destroy1(self.b)
13566  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
13567  * 
13568  * cdef class IteratorRowAll(IteratorRow):
13569  */
13570   if (((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->owns_samfile) {
13571     samclose(((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_v_self)->fp);
13572     goto __pyx_L5;
13573   }
13574   __pyx_L5:;
13575
13576   __Pyx_TraceReturn(Py_None);
13577   __Pyx_RefNannyFinishContext();
13578 }
13579
13580 /* "csamtools.pyx":1366
13581  *     # cdef int owns_samfile
13582  * 
13583  *     def __cinit__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
13584  * 
13585  *         if not samfile._isOpen():
13586  */
13587
13588 static int __pyx_pf_9csamtools_14IteratorRowAll___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
13589 static int __pyx_pf_9csamtools_14IteratorRowAll___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
13590   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
13591   int __pyx_v_reopen;
13592   PyObject *__pyx_v_mode;
13593   PyObject *__pyx_v_store;
13594   int __pyx_r;
13595   PyObject *__pyx_t_1 = NULL;
13596   PyObject *__pyx_t_2 = NULL;
13597   int __pyx_t_3;
13598   int __pyx_t_4;
13599   char *__pyx_t_5;
13600   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__reopen,0};
13601   __Pyx_TraceDeclarations
13602   __Pyx_RefNannySetupContext("__cinit__");
13603   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1366);
13604   if (unlikely(__pyx_kwds)) {
13605     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
13606     PyObject* values[2] = {0,0};
13607     switch (PyTuple_GET_SIZE(__pyx_args)) {
13608       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
13609       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
13610       case  0: break;
13611       default: goto __pyx_L5_argtuple_error;
13612     }
13613     switch (PyTuple_GET_SIZE(__pyx_args)) {
13614       case  0:
13615       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
13616       if (likely(values[0])) kw_args--;
13617       else goto __pyx_L5_argtuple_error;
13618       case  1:
13619       if (kw_args > 0) {
13620         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
13621         if (value) { values[1] = value; kw_args--; }
13622       }
13623     }
13624     if (unlikely(kw_args > 0)) {
13625       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13626     }
13627     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
13628     if (values[1]) {
13629       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13630     } else {
13631       __pyx_v_reopen = ((int)1);
13632     }
13633   } else {
13634     __pyx_v_reopen = ((int)1);
13635     switch (PyTuple_GET_SIZE(__pyx_args)) {
13636       case  2: __pyx_v_reopen = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13637       case  1: __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
13638       break;
13639       default: goto __pyx_L5_argtuple_error;
13640     }
13641   }
13642   goto __pyx_L4_argument_unpacking_done;
13643   __pyx_L5_argtuple_error:;
13644   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
13645   __pyx_L3_error:;
13646   __Pyx_AddTraceback("csamtools.IteratorRowAll.__cinit__");
13647   __Pyx_RefNannyFinishContext();
13648   return -1;
13649   __pyx_L4_argument_unpacking_done:;
13650   __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
13651   __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
13652   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13653
13654   /* "csamtools.pyx":1368
13655  *     def __cinit__(self, Samfile samfile, int reopen = True ):
13656  * 
13657  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
13658  *             raise ValueError( "I/O operation on closed file" )
13659  * 
13660  */
13661   __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 = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13662   __Pyx_GOTREF(__pyx_t_1);
13663   __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13664   __Pyx_GOTREF(__pyx_t_2);
13665   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13666   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13667   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13668   __pyx_t_4 = (!__pyx_t_3);
13669   if (__pyx_t_4) {
13670
13671     /* "csamtools.pyx":1369
13672  * 
13673  *         if not samfile._isOpen():
13674  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
13675  * 
13676  *         if samfile.isbam: mode = "rb"
13677  */
13678     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_108), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13679     __Pyx_GOTREF(__pyx_t_2);
13680     __Pyx_Raise(__pyx_t_2, 0, 0);
13681     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13682     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13683     goto __pyx_L6;
13684   }
13685   __pyx_L6:;
13686
13687   /* "csamtools.pyx":1371
13688  *             raise ValueError( "I/O operation on closed file" )
13689  * 
13690  *         if samfile.isbam: mode = "rb"             # <<<<<<<<<<<<<<
13691  *         else: mode = "r"
13692  * 
13693  */
13694   if (__pyx_v_samfile->isbam) {
13695     __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
13696     __Pyx_DECREF(__pyx_v_mode);
13697     __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
13698     goto __pyx_L7;
13699   }
13700   /*else*/ {
13701
13702     /* "csamtools.pyx":1372
13703  * 
13704  *         if samfile.isbam: mode = "rb"
13705  *         else: mode = "r"             # <<<<<<<<<<<<<<
13706  * 
13707  *         # reopen the file to avoid iterator conflict
13708  */
13709     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
13710     __Pyx_DECREF(__pyx_v_mode);
13711     __pyx_v_mode = ((PyObject *)__pyx_n_s__r);
13712   }
13713   __pyx_L7:;
13714
13715   /* "csamtools.pyx":1375
13716  * 
13717  *         # reopen the file to avoid iterator conflict
13718  *         if reopen:             # <<<<<<<<<<<<<<
13719  *             store = StderrStore()
13720  *             self.fp = samopen( samfile._filename, mode, NULL )
13721  */
13722   if (__pyx_v_reopen) {
13723
13724     /* "csamtools.pyx":1376
13725  *         # reopen the file to avoid iterator conflict
13726  *         if reopen:
13727  *             store = StderrStore()             # <<<<<<<<<<<<<<
13728  *             self.fp = samopen( samfile._filename, mode, NULL )
13729  *             store.release()
13730  */
13731     __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13732     __Pyx_GOTREF(__pyx_t_2);
13733     __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 = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13734     __Pyx_GOTREF(__pyx_t_1);
13735     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13736     __Pyx_DECREF(__pyx_v_store);
13737     __pyx_v_store = __pyx_t_1;
13738     __pyx_t_1 = 0;
13739
13740     /* "csamtools.pyx":1377
13741  *         if reopen:
13742  *             store = StderrStore()
13743  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
13744  *             store.release()
13745  *             assert self.fp != NULL
13746  */
13747     __pyx_t_5 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13748     ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
13749
13750     /* "csamtools.pyx":1378
13751  *             store = StderrStore()
13752  *             self.fp = samopen( samfile._filename, mode, NULL )
13753  *             store.release()             # <<<<<<<<<<<<<<
13754  *             assert self.fp != NULL
13755  *             self.owns_samfile = True
13756  */
13757     __pyx_t_1 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13758     __Pyx_GOTREF(__pyx_t_1);
13759     __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13760     __Pyx_GOTREF(__pyx_t_2);
13761     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
13762     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
13763
13764     /* "csamtools.pyx":1379
13765  *             self.fp = samopen( samfile._filename, mode, NULL )
13766  *             store.release()
13767  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
13768  *             self.owns_samfile = True
13769  *         else:
13770  */
13771     #ifndef CYTHON_WITHOUT_ASSERTIONS
13772     if (unlikely(!(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->fp != NULL))) {
13773       PyErr_SetNone(PyExc_AssertionError);
13774       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13775     }
13776     #endif
13777
13778     /* "csamtools.pyx":1380
13779  *             store.release()
13780  *             assert self.fp != NULL
13781  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
13782  *         else:
13783  *             self.fp = samfile.samfile
13784  */
13785     ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->owns_samfile = 1;
13786     goto __pyx_L8;
13787   }
13788   /*else*/ {
13789
13790     /* "csamtools.pyx":1382
13791  *             self.owns_samfile = True
13792  *         else:
13793  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
13794  *             self.owns_samfile = False
13795  * 
13796  */
13797     ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->fp = __pyx_v_samfile->samfile;
13798
13799     /* "csamtools.pyx":1383
13800  *         else:
13801  *             self.fp = samfile.samfile
13802  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
13803  * 
13804  *         # allocate memory for alignment
13805  */
13806     ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->owns_samfile = 0;
13807   }
13808   __pyx_L8:;
13809
13810   /* "csamtools.pyx":1386
13811  * 
13812  *         # allocate memory for alignment
13813  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
13814  * 
13815  *     def __iter__(self):
13816  */
13817   ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
13818
13819   __pyx_r = 0;
13820   goto __pyx_L0;
13821   __pyx_L1_error:;
13822   __Pyx_XDECREF(__pyx_t_1);
13823   __Pyx_XDECREF(__pyx_t_2);
13824   __Pyx_AddTraceback("csamtools.IteratorRowAll.__cinit__");
13825   __pyx_r = -1;
13826   __pyx_L0:;
13827   __Pyx_DECREF(__pyx_v_mode);
13828   __Pyx_DECREF(__pyx_v_store);
13829   __Pyx_TraceReturn(Py_None);
13830   __Pyx_RefNannyFinishContext();
13831   return __pyx_r;
13832 }
13833
13834 /* "csamtools.pyx":1388
13835  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
13836  * 
13837  *     def __iter__(self):             # <<<<<<<<<<<<<<
13838  *         return self
13839  * 
13840  */
13841
13842 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_1__iter__(PyObject *__pyx_v_self); /*proto*/
13843 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_1__iter__(PyObject *__pyx_v_self) {
13844   PyObject *__pyx_r = NULL;
13845   __Pyx_TraceDeclarations
13846   __Pyx_RefNannySetupContext("__iter__");
13847   __Pyx_TraceCall("__iter__", __pyx_f[0], 1388);
13848
13849   /* "csamtools.pyx":1389
13850  * 
13851  *     def __iter__(self):
13852  *         return self             # <<<<<<<<<<<<<<
13853  * 
13854  *     cdef bam1_t * getCurrent( self ):
13855  */
13856   __Pyx_XDECREF(__pyx_r);
13857   __Pyx_INCREF(__pyx_v_self);
13858   __pyx_r = __pyx_v_self;
13859   goto __pyx_L0;
13860
13861   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
13862   __pyx_L0:;
13863   __Pyx_XGIVEREF(__pyx_r);
13864   __Pyx_TraceReturn(__pyx_r);
13865   __Pyx_RefNannyFinishContext();
13866   return __pyx_r;
13867 }
13868
13869 /* "csamtools.pyx":1391
13870  *         return self
13871  * 
13872  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
13873  *         return self.b
13874  * 
13875  */
13876
13877 static  bam1_t *__pyx_f_9csamtools_14IteratorRowAll_getCurrent(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
13878   bam1_t *__pyx_r;
13879   __Pyx_TraceDeclarations
13880   __Pyx_RefNannySetupContext("getCurrent");
13881   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1391);
13882
13883   /* "csamtools.pyx":1392
13884  * 
13885  *     cdef bam1_t * getCurrent( self ):
13886  *         return self.b             # <<<<<<<<<<<<<<
13887  * 
13888  *     cdef int cnext(self):
13889  */
13890   __pyx_r = __pyx_v_self->b;
13891   goto __pyx_L0;
13892
13893   __pyx_r = 0;
13894   __pyx_L0:;
13895   __Pyx_TraceReturn(Py_None);
13896   __Pyx_RefNannyFinishContext();
13897   return __pyx_r;
13898 }
13899
13900 /* "csamtools.pyx":1394
13901  *         return self.b
13902  * 
13903  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
13904  *         '''cversion of iterator. Used by IteratorColumn'''
13905  *         cdef int ret
13906  */
13907
13908 static  int __pyx_f_9csamtools_14IteratorRowAll_cnext(struct __pyx_obj_9csamtools_IteratorRowAll *__pyx_v_self) {
13909   int __pyx_r;
13910   __Pyx_TraceDeclarations
13911   __Pyx_RefNannySetupContext("cnext");
13912   __Pyx_TraceCall("cnext", __pyx_f[0], 1394);
13913
13914   /* "csamtools.pyx":1397
13915  *         '''cversion of iterator. Used by IteratorColumn'''
13916  *         cdef int ret
13917  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
13918  * 
13919  *     def __next__(self):
13920  */
13921   __pyx_r = samread(__pyx_v_self->fp, __pyx_v_self->b);
13922   goto __pyx_L0;
13923
13924   __pyx_r = 0;
13925   __pyx_L0:;
13926   __Pyx_TraceReturn(Py_None);
13927   __Pyx_RefNannyFinishContext();
13928   return __pyx_r;
13929 }
13930
13931 /* "csamtools.pyx":1399
13932  *         return samread(self.fp, self.b)
13933  * 
13934  *     def __next__(self):             # <<<<<<<<<<<<<<
13935  *         """python version of next().
13936  * 
13937  */
13938
13939 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_2__next__(PyObject *__pyx_v_self); /*proto*/
13940 static char __pyx_doc_9csamtools_14IteratorRowAll_2__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
13941 struct wrapperbase __pyx_wrapperbase_9csamtools_14IteratorRowAll_2__next__;
13942 static PyObject *__pyx_pf_9csamtools_14IteratorRowAll_2__next__(PyObject *__pyx_v_self) {
13943   int __pyx_v_ret;
13944   PyObject *__pyx_r = NULL;
13945   int __pyx_t_1;
13946   PyObject *__pyx_t_2 = NULL;
13947   __Pyx_TraceDeclarations
13948   __Pyx_RefNannySetupContext("__next__");
13949   __Pyx_TraceCall("__next__", __pyx_f[0], 1399);
13950
13951   /* "csamtools.pyx":1405
13952  *         """
13953  *         cdef int ret
13954  *         ret = samread(self.fp, self.b)             # <<<<<<<<<<<<<<
13955  *         if (ret > 0):
13956  *             return makeAlignedRead( self.b )
13957  */
13958   __pyx_v_ret = samread(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->fp, ((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->b);
13959
13960   /* "csamtools.pyx":1406
13961  *         cdef int ret
13962  *         ret = samread(self.fp, self.b)
13963  *         if (ret > 0):             # <<<<<<<<<<<<<<
13964  *             return makeAlignedRead( self.b )
13965  *         else:
13966  */
13967   __pyx_t_1 = (__pyx_v_ret > 0);
13968   if (__pyx_t_1) {
13969
13970     /* "csamtools.pyx":1407
13971  *         ret = samread(self.fp, self.b)
13972  *         if (ret > 0):
13973  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
13974  *         else:
13975  *             raise StopIteration
13976  */
13977     __Pyx_XDECREF(__pyx_r);
13978     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13979     __Pyx_GOTREF(__pyx_t_2);
13980     __pyx_r = __pyx_t_2;
13981     __pyx_t_2 = 0;
13982     goto __pyx_L0;
13983     goto __pyx_L5;
13984   }
13985   /*else*/ {
13986
13987     /* "csamtools.pyx":1409
13988  *             return makeAlignedRead( self.b )
13989  *         else:
13990  *             raise StopIteration             # <<<<<<<<<<<<<<
13991  * 
13992  *     def __dealloc__(self):
13993  */
13994     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
13995     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
13996   }
13997   __pyx_L5:;
13998
13999   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14000   goto __pyx_L0;
14001   __pyx_L1_error:;
14002   __Pyx_XDECREF(__pyx_t_2);
14003   __Pyx_AddTraceback("csamtools.IteratorRowAll.__next__");
14004   __pyx_r = NULL;
14005   __pyx_L0:;
14006   __Pyx_XGIVEREF(__pyx_r);
14007   __Pyx_TraceReturn(__pyx_r);
14008   __Pyx_RefNannyFinishContext();
14009   return __pyx_r;
14010 }
14011
14012 /* "csamtools.pyx":1411
14013  *             raise StopIteration
14014  * 
14015  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
14016  *         bam_destroy1(self.b)
14017  *         if self.owns_samfile: samclose( self.fp )
14018  */
14019
14020 static void __pyx_pf_9csamtools_14IteratorRowAll_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
14021 static void __pyx_pf_9csamtools_14IteratorRowAll_3__dealloc__(PyObject *__pyx_v_self) {
14022   __Pyx_TraceDeclarations
14023   __Pyx_RefNannySetupContext("__dealloc__");
14024   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1411);
14025
14026   /* "csamtools.pyx":1412
14027  * 
14028  *     def __dealloc__(self):
14029  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
14030  *         if self.owns_samfile: samclose( self.fp )
14031  * 
14032  */
14033   bam_destroy1(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->b);
14034
14035   /* "csamtools.pyx":1413
14036  *     def __dealloc__(self):
14037  *         bam_destroy1(self.b)
14038  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
14039  * 
14040  * cdef class IteratorRowAllRefs(IteratorRow):
14041  */
14042   if (((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->owns_samfile) {
14043     samclose(((struct __pyx_obj_9csamtools_IteratorRowAll *)__pyx_v_self)->fp);
14044     goto __pyx_L5;
14045   }
14046   __pyx_L5:;
14047
14048   __Pyx_TraceReturn(Py_None);
14049   __Pyx_RefNannyFinishContext();
14050 }
14051
14052 /* "csamtools.pyx":1422
14053  *     cdef IteratorRowRegion rowiter
14054  * 
14055  *     def __cinit__(self, Samfile samfile):             # <<<<<<<<<<<<<<
14056  *         assert samfile._isOpen()
14057  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
14058  */
14059
14060 static int __pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
14061 static int __pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
14062   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
14063   int __pyx_r;
14064   PyObject *__pyx_t_1 = NULL;
14065   PyObject *__pyx_t_2 = NULL;
14066   int __pyx_t_3;
14067   int __pyx_t_4;
14068   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
14069   __Pyx_TraceDeclarations
14070   __Pyx_RefNannySetupContext("__cinit__");
14071   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1422);
14072   if (unlikely(__pyx_kwds)) {
14073     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
14074     PyObject* values[1] = {0};
14075     switch (PyTuple_GET_SIZE(__pyx_args)) {
14076       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
14077       case  0: break;
14078       default: goto __pyx_L5_argtuple_error;
14079     }
14080     switch (PyTuple_GET_SIZE(__pyx_args)) {
14081       case  0:
14082       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
14083       if (likely(values[0])) kw_args--;
14084       else goto __pyx_L5_argtuple_error;
14085     }
14086     if (unlikely(kw_args > 0)) {
14087       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14088     }
14089     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
14090   } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
14091     goto __pyx_L5_argtuple_error;
14092   } else {
14093     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
14094   }
14095   goto __pyx_L4_argument_unpacking_done;
14096   __pyx_L5_argtuple_error:;
14097   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14098   __pyx_L3_error:;
14099   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__cinit__");
14100   __Pyx_RefNannyFinishContext();
14101   return -1;
14102   __pyx_L4_argument_unpacking_done:;
14103   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14104
14105   /* "csamtools.pyx":1423
14106  * 
14107  *     def __cinit__(self, Samfile samfile):
14108  *         assert samfile._isOpen()             # <<<<<<<<<<<<<<
14109  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
14110  *         self.samfile = samfile
14111  */
14112   #ifndef CYTHON_WITHOUT_ASSERTIONS
14113   __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 = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14114   __Pyx_GOTREF(__pyx_t_1);
14115   __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 = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14116   __Pyx_GOTREF(__pyx_t_2);
14117   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14118   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14119   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14120   if (unlikely(!__pyx_t_3)) {
14121     PyErr_SetNone(PyExc_AssertionError);
14122     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14123   }
14124   #endif
14125
14126   /* "csamtools.pyx":1424
14127  *     def __cinit__(self, Samfile samfile):
14128  *         assert samfile._isOpen()
14129  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
14130  *         self.samfile = samfile
14131  *         self.tid = -1
14132  */
14133   __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 = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14134   __Pyx_GOTREF(__pyx_t_2);
14135   __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 = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14136   __Pyx_GOTREF(__pyx_t_1);
14137   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14138   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14139   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14140   __pyx_t_4 = (!__pyx_t_3);
14141   if (__pyx_t_4) {
14142     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_109), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14143     __Pyx_GOTREF(__pyx_t_1);
14144     __Pyx_Raise(__pyx_t_1, 0, 0);
14145     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14146     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14147     goto __pyx_L6;
14148   }
14149   __pyx_L6:;
14150
14151   /* "csamtools.pyx":1425
14152  *         assert samfile._isOpen()
14153  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
14154  *         self.samfile = samfile             # <<<<<<<<<<<<<<
14155  *         self.tid = -1
14156  * 
14157  */
14158   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
14159   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
14160   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile);
14161   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile));
14162   ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile = __pyx_v_samfile;
14163
14164   /* "csamtools.pyx":1426
14165  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")
14166  *         self.samfile = samfile
14167  *         self.tid = -1             # <<<<<<<<<<<<<<
14168  * 
14169  *     def nextiter(self):
14170  */
14171   ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid = -1;
14172
14173   __pyx_r = 0;
14174   goto __pyx_L0;
14175   __pyx_L1_error:;
14176   __Pyx_XDECREF(__pyx_t_1);
14177   __Pyx_XDECREF(__pyx_t_2);
14178   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__cinit__");
14179   __pyx_r = -1;
14180   __pyx_L0:;
14181   __Pyx_TraceReturn(Py_None);
14182   __Pyx_RefNannyFinishContext();
14183   return __pyx_r;
14184 }
14185
14186 /* "csamtools.pyx":1428
14187  *         self.tid = -1
14188  * 
14189  *     def nextiter(self):             # <<<<<<<<<<<<<<
14190  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)
14191  * 
14192  */
14193
14194 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_1nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
14195 static char __pyx_doc_9csamtools_18IteratorRowAllRefs_1nextiter[] = "IteratorRowAllRefs.nextiter(self)";
14196 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_1nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
14197   PyObject *__pyx_r = NULL;
14198   PyObject *__pyx_t_1 = NULL;
14199   PyObject *__pyx_t_2 = NULL;
14200   __Pyx_TraceDeclarations
14201   __Pyx_RefNannySetupContext("nextiter");
14202   __Pyx_TraceCall("nextiter", __pyx_f[0], 1428);
14203
14204   /* "csamtools.pyx":1429
14205  * 
14206  *     def nextiter(self):
14207  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)             # <<<<<<<<<<<<<<
14208  * 
14209  *     def __iter__(self):
14210  */
14211   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14212   __Pyx_GOTREF(__pyx_t_1);
14213   __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14214   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
14215   __Pyx_INCREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile));
14216   PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile));
14217   __Pyx_GIVEREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile));
14218   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
14219   __Pyx_GIVEREF(__pyx_t_1);
14220   __Pyx_INCREF(__pyx_int_0);
14221   PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
14222   __Pyx_GIVEREF(__pyx_int_0);
14223   __Pyx_INCREF(__pyx_int_536870912);
14224   PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912);
14225   __Pyx_GIVEREF(__pyx_int_536870912);
14226   __pyx_t_1 = 0;
14227   __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 = 1429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14228   __Pyx_GOTREF(__pyx_t_1);
14229   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
14230   __Pyx_GIVEREF(__pyx_t_1);
14231   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter);
14232   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter));
14233   ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_1);
14234   __pyx_t_1 = 0;
14235
14236   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14237   goto __pyx_L0;
14238   __pyx_L1_error:;
14239   __Pyx_XDECREF(__pyx_t_1);
14240   __Pyx_XDECREF(__pyx_t_2);
14241   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.nextiter");
14242   __pyx_r = NULL;
14243   __pyx_L0:;
14244   __Pyx_XGIVEREF(__pyx_r);
14245   __Pyx_TraceReturn(__pyx_r);
14246   __Pyx_RefNannyFinishContext();
14247   return __pyx_r;
14248 }
14249
14250 /* "csamtools.pyx":1431
14251  *         self.rowiter = IteratorRowRegion(self.samfile, self.tid, 0, 1<<29)
14252  * 
14253  *     def __iter__(self):             # <<<<<<<<<<<<<<
14254  *         return self
14255  * 
14256  */
14257
14258 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_2__iter__(PyObject *__pyx_v_self); /*proto*/
14259 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_2__iter__(PyObject *__pyx_v_self) {
14260   PyObject *__pyx_r = NULL;
14261   __Pyx_TraceDeclarations
14262   __Pyx_RefNannySetupContext("__iter__");
14263   __Pyx_TraceCall("__iter__", __pyx_f[0], 1431);
14264
14265   /* "csamtools.pyx":1432
14266  * 
14267  *     def __iter__(self):
14268  *         return self             # <<<<<<<<<<<<<<
14269  * 
14270  *     def __next__(self):
14271  */
14272   __Pyx_XDECREF(__pyx_r);
14273   __Pyx_INCREF(__pyx_v_self);
14274   __pyx_r = __pyx_v_self;
14275   goto __pyx_L0;
14276
14277   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14278   __pyx_L0:;
14279   __Pyx_XGIVEREF(__pyx_r);
14280   __Pyx_TraceReturn(__pyx_r);
14281   __Pyx_RefNannyFinishContext();
14282   return __pyx_r;
14283 }
14284
14285 /* "csamtools.pyx":1434
14286  *         return self
14287  * 
14288  *     def __next__(self):             # <<<<<<<<<<<<<<
14289  *         """python version of next().
14290  * 
14291  */
14292
14293 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
14294 static char __pyx_doc_9csamtools_18IteratorRowAllRefs_3__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
14295 struct wrapperbase __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_3__next__;
14296 static PyObject *__pyx_pf_9csamtools_18IteratorRowAllRefs_3__next__(PyObject *__pyx_v_self) {
14297   PyObject *__pyx_r = NULL;
14298   int __pyx_t_1;
14299   PyObject *__pyx_t_2 = NULL;
14300   int __pyx_t_3;
14301   PyObject *__pyx_t_4 = NULL;
14302   PyObject *__pyx_t_5 = NULL;
14303   __Pyx_TraceDeclarations
14304   __Pyx_RefNannySetupContext("__next__");
14305   __Pyx_TraceCall("__next__", __pyx_f[0], 1434);
14306
14307   /* "csamtools.pyx":1440
14308  *         """
14309  *         # Create an initial iterator
14310  *         if self.tid==-1:             # <<<<<<<<<<<<<<
14311  *             if not self.samfile.nreferences:
14312  *                 raise StopIteration
14313  */
14314   __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid == -1);
14315   if (__pyx_t_1) {
14316
14317     /* "csamtools.pyx":1441
14318  *         # Create an initial iterator
14319  *         if self.tid==-1:
14320  *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
14321  *                 raise StopIteration
14322  *             self.tid = 0
14323  */
14324     __pyx_t_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14325     __Pyx_GOTREF(__pyx_t_2);
14326     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1441; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14327     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14328     __pyx_t_3 = (!__pyx_t_1);
14329     if (__pyx_t_3) {
14330
14331       /* "csamtools.pyx":1442
14332  *         if self.tid==-1:
14333  *             if not self.samfile.nreferences:
14334  *                 raise StopIteration             # <<<<<<<<<<<<<<
14335  *             self.tid = 0
14336  *             self.nextiter()
14337  */
14338       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
14339       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14340       goto __pyx_L6;
14341     }
14342     __pyx_L6:;
14343
14344     /* "csamtools.pyx":1443
14345  *             if not self.samfile.nreferences:
14346  *                 raise StopIteration
14347  *             self.tid = 0             # <<<<<<<<<<<<<<
14348  *             self.nextiter()
14349  * 
14350  */
14351     ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid = 0;
14352
14353     /* "csamtools.pyx":1444
14354  *                 raise StopIteration
14355  *             self.tid = 0
14356  *             self.nextiter()             # <<<<<<<<<<<<<<
14357  * 
14358  *         while 1:
14359  */
14360     __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__nextiter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14361     __Pyx_GOTREF(__pyx_t_2);
14362     __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 = 1444; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14363     __Pyx_GOTREF(__pyx_t_4);
14364     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14365     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
14366     goto __pyx_L5;
14367   }
14368   __pyx_L5:;
14369
14370   /* "csamtools.pyx":1446
14371  *             self.nextiter()
14372  * 
14373  *         while 1:             # <<<<<<<<<<<<<<
14374  *             self.rowiter.cnext()
14375  * 
14376  */
14377   while (1) {
14378     if (!1) break;
14379
14380     /* "csamtools.pyx":1447
14381  * 
14382  *         while 1:
14383  *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
14384  * 
14385  *             # If current iterator is not exhausted, return aligned read
14386  */
14387     ((struct __pyx_vtabstruct_9csamtools_IteratorRowRegion *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter->__pyx_vtab)->cnext(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter);
14388
14389     /* "csamtools.pyx":1450
14390  * 
14391  *             # If current iterator is not exhausted, return aligned read
14392  *             if self.rowiter.retval>0:             # <<<<<<<<<<<<<<
14393  *                 return makeAlignedRead(self.rowiter.b)
14394  * 
14395  */
14396     __pyx_t_3 = (((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter->retval > 0);
14397     if (__pyx_t_3) {
14398
14399       /* "csamtools.pyx":1451
14400  *             # If current iterator is not exhausted, return aligned read
14401  *             if self.rowiter.retval>0:
14402  *                 return makeAlignedRead(self.rowiter.b)             # <<<<<<<<<<<<<<
14403  * 
14404  *             self.tid += 1
14405  */
14406       __Pyx_XDECREF(__pyx_r);
14407       __pyx_t_4 = __pyx_f_9csamtools_makeAlignedRead(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->rowiter->b); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14408       __Pyx_GOTREF(__pyx_t_4);
14409       __pyx_r = __pyx_t_4;
14410       __pyx_t_4 = 0;
14411       goto __pyx_L0;
14412       goto __pyx_L9;
14413     }
14414     __pyx_L9:;
14415
14416     /* "csamtools.pyx":1453
14417  *                 return makeAlignedRead(self.rowiter.b)
14418  * 
14419  *             self.tid += 1             # <<<<<<<<<<<<<<
14420  * 
14421  *             # Otherwise, proceed to next reference or stop
14422  */
14423     ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid = (((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid + 1);
14424
14425     /* "csamtools.pyx":1456
14426  * 
14427  *             # Otherwise, proceed to next reference or stop
14428  *             if self.tid<self.samfile.nreferences:             # <<<<<<<<<<<<<<
14429  *                 self.nextiter()
14430  *             else:
14431  */
14432     __pyx_t_4 = PyInt_FromLong(((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14433     __Pyx_GOTREF(__pyx_t_4);
14434     __pyx_t_2 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)__pyx_v_self)->samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14435     __Pyx_GOTREF(__pyx_t_2);
14436     __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 = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14437     __Pyx_GOTREF(__pyx_t_5);
14438     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
14439     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14440     __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14441     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
14442     if (__pyx_t_3) {
14443
14444       /* "csamtools.pyx":1457
14445  *             # Otherwise, proceed to next reference or stop
14446  *             if self.tid<self.samfile.nreferences:
14447  *                 self.nextiter()             # <<<<<<<<<<<<<<
14448  *             else:
14449  *                 raise StopIteration
14450  */
14451       __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__nextiter); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14452       __Pyx_GOTREF(__pyx_t_5);
14453       __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 = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14454       __Pyx_GOTREF(__pyx_t_2);
14455       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
14456       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14457       goto __pyx_L10;
14458     }
14459     /*else*/ {
14460
14461       /* "csamtools.pyx":1459
14462  *                 self.nextiter()
14463  *             else:
14464  *                 raise StopIteration             # <<<<<<<<<<<<<<
14465  * 
14466  * cdef class IteratorRowSelection(IteratorRow):
14467  */
14468       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
14469       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14470     }
14471     __pyx_L10:;
14472   }
14473
14474   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14475   goto __pyx_L0;
14476   __pyx_L1_error:;
14477   __Pyx_XDECREF(__pyx_t_2);
14478   __Pyx_XDECREF(__pyx_t_4);
14479   __Pyx_XDECREF(__pyx_t_5);
14480   __Pyx_AddTraceback("csamtools.IteratorRowAllRefs.__next__");
14481   __pyx_r = NULL;
14482   __pyx_L0:;
14483   __Pyx_XGIVEREF(__pyx_r);
14484   __Pyx_TraceReturn(__pyx_r);
14485   __Pyx_RefNannyFinishContext();
14486   return __pyx_r;
14487 }
14488
14489 /* "csamtools.pyx":1474
14490  *     cdef int owns_samfile
14491  * 
14492  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):             # <<<<<<<<<<<<<<
14493  * 
14494  *         if not samfile._isOpen():
14495  */
14496
14497 static int __pyx_pf_9csamtools_20IteratorRowSelection___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
14498 static int __pyx_pf_9csamtools_20IteratorRowSelection___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
14499   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
14500   PyObject *__pyx_v_positions = 0;
14501   int __pyx_v_reopen;
14502   PyObject *__pyx_v_mode;
14503   PyObject *__pyx_v_store;
14504   int __pyx_r;
14505   PyObject *__pyx_t_1 = NULL;
14506   PyObject *__pyx_t_2 = NULL;
14507   int __pyx_t_3;
14508   int __pyx_t_4;
14509   char *__pyx_t_5;
14510   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__positions,&__pyx_n_s__reopen,0};
14511   __Pyx_TraceDeclarations
14512   __Pyx_RefNannySetupContext("__cinit__");
14513   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1474);
14514   if (unlikely(__pyx_kwds)) {
14515     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
14516     PyObject* values[3] = {0,0,0};
14517     switch (PyTuple_GET_SIZE(__pyx_args)) {
14518       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
14519       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
14520       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
14521       case  0: break;
14522       default: goto __pyx_L5_argtuple_error;
14523     }
14524     switch (PyTuple_GET_SIZE(__pyx_args)) {
14525       case  0:
14526       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
14527       if (likely(values[0])) kw_args--;
14528       else goto __pyx_L5_argtuple_error;
14529       case  1:
14530       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__positions);
14531       if (likely(values[1])) kw_args--;
14532       else {
14533         __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14534       }
14535       case  2:
14536       if (kw_args > 0) {
14537         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
14538         if (value) { values[2] = value; kw_args--; }
14539       }
14540     }
14541     if (unlikely(kw_args > 0)) {
14542       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14543     }
14544     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
14545     __pyx_v_positions = values[1];
14546     if (values[2]) {
14547       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14548     } else {
14549       __pyx_v_reopen = ((int)1);
14550     }
14551   } else {
14552     __pyx_v_reopen = ((int)1);
14553     switch (PyTuple_GET_SIZE(__pyx_args)) {
14554       case  3:
14555       __pyx_v_reopen = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14556       case  2:
14557       __pyx_v_positions = PyTuple_GET_ITEM(__pyx_args, 1);
14558       __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
14559       break;
14560       default: goto __pyx_L5_argtuple_error;
14561     }
14562   }
14563   goto __pyx_L4_argument_unpacking_done;
14564   __pyx_L5_argtuple_error:;
14565   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
14566   __pyx_L3_error:;
14567   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__cinit__");
14568   __Pyx_RefNannyFinishContext();
14569   return -1;
14570   __pyx_L4_argument_unpacking_done:;
14571   __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
14572   __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
14573   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14574
14575   /* "csamtools.pyx":1476
14576  *     def __cinit__(self, Samfile samfile, positions, int reopen = True ):
14577  * 
14578  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
14579  *             raise ValueError( "I/O operation on closed file" )
14580  * 
14581  */
14582   __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 = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14583   __Pyx_GOTREF(__pyx_t_1);
14584   __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 = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14585   __Pyx_GOTREF(__pyx_t_2);
14586   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14587   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14588   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14589   __pyx_t_4 = (!__pyx_t_3);
14590   if (__pyx_t_4) {
14591
14592     /* "csamtools.pyx":1477
14593  * 
14594  *         if not samfile._isOpen():
14595  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
14596  * 
14597  *         if not samfile._isOpen():
14598  */
14599     __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_110), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14600     __Pyx_GOTREF(__pyx_t_2);
14601     __Pyx_Raise(__pyx_t_2, 0, 0);
14602     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14603     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14604     goto __pyx_L6;
14605   }
14606   __pyx_L6:;
14607
14608   /* "csamtools.pyx":1479
14609  *             raise ValueError( "I/O operation on closed file" )
14610  * 
14611  *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
14612  *             raise ValueError( "I/O operation on closed file" )
14613  * 
14614  */
14615   __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 = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14616   __Pyx_GOTREF(__pyx_t_2);
14617   __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 = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14618   __Pyx_GOTREF(__pyx_t_1);
14619   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14620   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14621   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14622   __pyx_t_3 = (!__pyx_t_4);
14623   if (__pyx_t_3) {
14624
14625     /* "csamtools.pyx":1480
14626  * 
14627  *         if not samfile._isOpen():
14628  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
14629  * 
14630  *         assert samfile.isbam, "can only use this iterator on bam files"
14631  */
14632     __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_111), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14633     __Pyx_GOTREF(__pyx_t_1);
14634     __Pyx_Raise(__pyx_t_1, 0, 0);
14635     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14636     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14637     goto __pyx_L7;
14638   }
14639   __pyx_L7:;
14640
14641   /* "csamtools.pyx":1482
14642  *             raise ValueError( "I/O operation on closed file" )
14643  * 
14644  *         assert samfile.isbam, "can only use this iterator on bam files"             # <<<<<<<<<<<<<<
14645  *         mode = "rb"
14646  * 
14647  */
14648   #ifndef CYTHON_WITHOUT_ASSERTIONS
14649   if (unlikely(!__pyx_v_samfile->isbam)) {
14650     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_112));
14651     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14652   }
14653   #endif
14654
14655   /* "csamtools.pyx":1483
14656  * 
14657  *         assert samfile.isbam, "can only use this iterator on bam files"
14658  *         mode = "rb"             # <<<<<<<<<<<<<<
14659  * 
14660  *         # reopen the file to avoid iterator conflict
14661  */
14662   __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
14663   __Pyx_DECREF(__pyx_v_mode);
14664   __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
14665
14666   /* "csamtools.pyx":1486
14667  * 
14668  *         # reopen the file to avoid iterator conflict
14669  *         if reopen:             # <<<<<<<<<<<<<<
14670  *             store = StderrStore()
14671  *             self.fp = samopen( samfile._filename, mode, NULL )
14672  */
14673   if (__pyx_v_reopen) {
14674
14675     /* "csamtools.pyx":1487
14676  *         # reopen the file to avoid iterator conflict
14677  *         if reopen:
14678  *             store = StderrStore()             # <<<<<<<<<<<<<<
14679  *             self.fp = samopen( samfile._filename, mode, NULL )
14680  *             store.release()
14681  */
14682     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14683     __Pyx_GOTREF(__pyx_t_1);
14684     __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 = 1487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14685     __Pyx_GOTREF(__pyx_t_2);
14686     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14687     __Pyx_DECREF(__pyx_v_store);
14688     __pyx_v_store = __pyx_t_2;
14689     __pyx_t_2 = 0;
14690
14691     /* "csamtools.pyx":1488
14692  *         if reopen:
14693  *             store = StderrStore()
14694  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
14695  *             store.release()
14696  *             assert self.fp != NULL
14697  */
14698     __pyx_t_5 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14699     ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_5, NULL);
14700
14701     /* "csamtools.pyx":1489
14702  *             store = StderrStore()
14703  *             self.fp = samopen( samfile._filename, mode, NULL )
14704  *             store.release()             # <<<<<<<<<<<<<<
14705  *             assert self.fp != NULL
14706  *             self.owns_samfile = True
14707  */
14708     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14709     __Pyx_GOTREF(__pyx_t_2);
14710     __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 = 1489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14711     __Pyx_GOTREF(__pyx_t_1);
14712     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
14713     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14714
14715     /* "csamtools.pyx":1490
14716  *             self.fp = samopen( samfile._filename, mode, NULL )
14717  *             store.release()
14718  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
14719  *             self.owns_samfile = True
14720  *         else:
14721  */
14722     #ifndef CYTHON_WITHOUT_ASSERTIONS
14723     if (unlikely(!(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->fp != NULL))) {
14724       PyErr_SetNone(PyExc_AssertionError);
14725       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14726     }
14727     #endif
14728
14729     /* "csamtools.pyx":1491
14730  *             store.release()
14731  *             assert self.fp != NULL
14732  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
14733  *         else:
14734  *             self.fp = samfile.samfile
14735  */
14736     ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->owns_samfile = 1;
14737     goto __pyx_L8;
14738   }
14739   /*else*/ {
14740
14741     /* "csamtools.pyx":1493
14742  *             self.owns_samfile = True
14743  *         else:
14744  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
14745  *             self.owns_samfile = False
14746  * 
14747  */
14748     ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->fp = __pyx_v_samfile->samfile;
14749
14750     /* "csamtools.pyx":1494
14751  *         else:
14752  *             self.fp = samfile.samfile
14753  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
14754  * 
14755  *         # allocate memory for alignment
14756  */
14757     ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->owns_samfile = 0;
14758   }
14759   __pyx_L8:;
14760
14761   /* "csamtools.pyx":1497
14762  * 
14763  *         # allocate memory for alignment
14764  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
14765  * 
14766  *         self.positions = positions
14767  */
14768   ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
14769
14770   /* "csamtools.pyx":1499
14771  *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
14772  * 
14773  *         self.positions = positions             # <<<<<<<<<<<<<<
14774  *         self.current_pos = 0
14775  * 
14776  */
14777   __Pyx_INCREF(__pyx_v_positions);
14778   __Pyx_GIVEREF(__pyx_v_positions);
14779   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->positions);
14780   __Pyx_DECREF(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->positions);
14781   ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->positions = __pyx_v_positions;
14782
14783   /* "csamtools.pyx":1500
14784  * 
14785  *         self.positions = positions
14786  *         self.current_pos = 0             # <<<<<<<<<<<<<<
14787  * 
14788  *     def __iter__(self):
14789  */
14790   ((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->current_pos = 0;
14791
14792   __pyx_r = 0;
14793   goto __pyx_L0;
14794   __pyx_L1_error:;
14795   __Pyx_XDECREF(__pyx_t_1);
14796   __Pyx_XDECREF(__pyx_t_2);
14797   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__cinit__");
14798   __pyx_r = -1;
14799   __pyx_L0:;
14800   __Pyx_DECREF(__pyx_v_mode);
14801   __Pyx_DECREF(__pyx_v_store);
14802   __Pyx_TraceReturn(Py_None);
14803   __Pyx_RefNannyFinishContext();
14804   return __pyx_r;
14805 }
14806
14807 /* "csamtools.pyx":1502
14808  *         self.current_pos = 0
14809  * 
14810  *     def __iter__(self):             # <<<<<<<<<<<<<<
14811  *         return self
14812  * 
14813  */
14814
14815 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_1__iter__(PyObject *__pyx_v_self); /*proto*/
14816 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_1__iter__(PyObject *__pyx_v_self) {
14817   PyObject *__pyx_r = NULL;
14818   __Pyx_TraceDeclarations
14819   __Pyx_RefNannySetupContext("__iter__");
14820   __Pyx_TraceCall("__iter__", __pyx_f[0], 1502);
14821
14822   /* "csamtools.pyx":1503
14823  * 
14824  *     def __iter__(self):
14825  *         return self             # <<<<<<<<<<<<<<
14826  * 
14827  *     cdef bam1_t * getCurrent( self ):
14828  */
14829   __Pyx_XDECREF(__pyx_r);
14830   __Pyx_INCREF(__pyx_v_self);
14831   __pyx_r = __pyx_v_self;
14832   goto __pyx_L0;
14833
14834   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
14835   __pyx_L0:;
14836   __Pyx_XGIVEREF(__pyx_r);
14837   __Pyx_TraceReturn(__pyx_r);
14838   __Pyx_RefNannyFinishContext();
14839   return __pyx_r;
14840 }
14841
14842 /* "csamtools.pyx":1505
14843  *         return self
14844  * 
14845  *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
14846  *         return self.b
14847  * 
14848  */
14849
14850 static  bam1_t *__pyx_f_9csamtools_20IteratorRowSelection_getCurrent(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
14851   bam1_t *__pyx_r;
14852   __Pyx_TraceDeclarations
14853   __Pyx_RefNannySetupContext("getCurrent");
14854   __Pyx_TraceCall("getCurrent", __pyx_f[0], 1505);
14855
14856   /* "csamtools.pyx":1506
14857  * 
14858  *     cdef bam1_t * getCurrent( self ):
14859  *         return self.b             # <<<<<<<<<<<<<<
14860  * 
14861  *     cdef int cnext(self):
14862  */
14863   __pyx_r = __pyx_v_self->b;
14864   goto __pyx_L0;
14865
14866   __pyx_r = 0;
14867   __pyx_L0:;
14868   __Pyx_TraceReturn(Py_None);
14869   __Pyx_RefNannyFinishContext();
14870   return __pyx_r;
14871 }
14872
14873 /* "csamtools.pyx":1508
14874  *         return self.b
14875  * 
14876  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
14877  *         '''cversion of iterator'''
14878  * 
14879  */
14880
14881 static  int __pyx_f_9csamtools_20IteratorRowSelection_cnext(struct __pyx_obj_9csamtools_IteratorRowSelection *__pyx_v_self) {
14882   int __pyx_r;
14883   PyObject *__pyx_t_1 = NULL;
14884   Py_ssize_t __pyx_t_2;
14885   int __pyx_t_3;
14886   uint64_t __pyx_t_4;
14887   __Pyx_TraceDeclarations
14888   __Pyx_RefNannySetupContext("cnext");
14889   __Pyx_TraceCall("cnext", __pyx_f[0], 1508);
14890
14891   /* "csamtools.pyx":1512
14892  * 
14893  *         # end iteration if out of positions
14894  *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
14895  * 
14896  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
14897  */
14898   __pyx_t_1 = __pyx_v_self->positions;
14899   __Pyx_INCREF(__pyx_t_1);
14900   __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14901   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14902   __pyx_t_3 = (__pyx_v_self->current_pos >= __pyx_t_2);
14903   if (__pyx_t_3) {
14904     __pyx_r = -1;
14905     goto __pyx_L0;
14906     goto __pyx_L3;
14907   }
14908   __pyx_L3:;
14909
14910   /* "csamtools.pyx":1514
14911  *         if self.current_pos >= len(self.positions): return -1
14912  * 
14913  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )             # <<<<<<<<<<<<<<
14914  *         self.current_pos += 1
14915  *         return samread(self.fp, self.b)
14916  */
14917   __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 = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14918   __Pyx_GOTREF(__pyx_t_1);
14919   __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 = 1514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
14920   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14921   bam_seek(__pyx_v_self->fp->x.bam, __pyx_t_4, 0);
14922
14923   /* "csamtools.pyx":1515
14924  * 
14925  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
14926  *         self.current_pos += 1             # <<<<<<<<<<<<<<
14927  *         return samread(self.fp, self.b)
14928  * 
14929  */
14930   __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);
14931
14932   /* "csamtools.pyx":1516
14933  *         bam_seek( self.fp.x.bam, self.positions[self.current_pos], 0 )
14934  *         self.current_pos += 1
14935  *         return samread(self.fp, self.b)             # <<<<<<<<<<<<<<
14936  * 
14937  *     def __next__(self):
14938  */
14939   __pyx_r = samread(__pyx_v_self->fp, __pyx_v_self->b);
14940   goto __pyx_L0;
14941
14942   __pyx_r = 0;
14943   goto __pyx_L0;
14944   __pyx_L1_error:;
14945   __Pyx_XDECREF(__pyx_t_1);
14946   __Pyx_WriteUnraisable("csamtools.IteratorRowSelection.cnext");
14947   __pyx_r = 0;
14948   __pyx_L0:;
14949   __Pyx_TraceReturn(Py_None);
14950   __Pyx_RefNannyFinishContext();
14951   return __pyx_r;
14952 }
14953
14954 /* "csamtools.pyx":1518
14955  *         return samread(self.fp, self.b)
14956  * 
14957  *     def __next__(self):             # <<<<<<<<<<<<<<
14958  *         """python version of next().
14959  * 
14960  */
14961
14962 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_2__next__(PyObject *__pyx_v_self); /*proto*/
14963 static char __pyx_doc_9csamtools_20IteratorRowSelection_2__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
14964 struct wrapperbase __pyx_wrapperbase_9csamtools_20IteratorRowSelection_2__next__;
14965 static PyObject *__pyx_pf_9csamtools_20IteratorRowSelection_2__next__(PyObject *__pyx_v_self) {
14966   int __pyx_v_ret;
14967   PyObject *__pyx_r = NULL;
14968   int __pyx_t_1;
14969   PyObject *__pyx_t_2 = NULL;
14970   __Pyx_TraceDeclarations
14971   __Pyx_RefNannySetupContext("__next__");
14972   __Pyx_TraceCall("__next__", __pyx_f[0], 1518);
14973
14974   /* "csamtools.pyx":1524
14975  *         """
14976  * 
14977  *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
14978  *         if (ret > 0):
14979  *             return makeAlignedRead( self.b )
14980  */
14981   __pyx_v_ret = ((struct __pyx_vtabstruct_9csamtools_IteratorRowSelection *)((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->__pyx_vtab)->cnext(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self));
14982
14983   /* "csamtools.pyx":1525
14984  * 
14985  *         cdef int ret = self.cnext()
14986  *         if (ret > 0):             # <<<<<<<<<<<<<<
14987  *             return makeAlignedRead( self.b )
14988  *         else:
14989  */
14990   __pyx_t_1 = (__pyx_v_ret > 0);
14991   if (__pyx_t_1) {
14992
14993     /* "csamtools.pyx":1526
14994  *         cdef int ret = self.cnext()
14995  *         if (ret > 0):
14996  *             return makeAlignedRead( self.b )             # <<<<<<<<<<<<<<
14997  *         else:
14998  *             raise StopIteration
14999  */
15000     __Pyx_XDECREF(__pyx_r);
15001     __pyx_t_2 = __pyx_f_9csamtools_makeAlignedRead(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15002     __Pyx_GOTREF(__pyx_t_2);
15003     __pyx_r = __pyx_t_2;
15004     __pyx_t_2 = 0;
15005     goto __pyx_L0;
15006     goto __pyx_L5;
15007   }
15008   /*else*/ {
15009
15010     /* "csamtools.pyx":1528
15011  *             return makeAlignedRead( self.b )
15012  *         else:
15013  *             raise StopIteration             # <<<<<<<<<<<<<<
15014  * 
15015  *     def __dealloc__(self):
15016  */
15017     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
15018     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15019   }
15020   __pyx_L5:;
15021
15022   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15023   goto __pyx_L0;
15024   __pyx_L1_error:;
15025   __Pyx_XDECREF(__pyx_t_2);
15026   __Pyx_AddTraceback("csamtools.IteratorRowSelection.__next__");
15027   __pyx_r = NULL;
15028   __pyx_L0:;
15029   __Pyx_XGIVEREF(__pyx_r);
15030   __Pyx_TraceReturn(__pyx_r);
15031   __Pyx_RefNannyFinishContext();
15032   return __pyx_r;
15033 }
15034
15035 /* "csamtools.pyx":1530
15036  *             raise StopIteration
15037  * 
15038  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
15039  *         bam_destroy1(self.b)
15040  *         if self.owns_samfile: samclose( self.fp )
15041  */
15042
15043 static void __pyx_pf_9csamtools_20IteratorRowSelection_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
15044 static void __pyx_pf_9csamtools_20IteratorRowSelection_3__dealloc__(PyObject *__pyx_v_self) {
15045   __Pyx_TraceDeclarations
15046   __Pyx_RefNannySetupContext("__dealloc__");
15047   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1530);
15048
15049   /* "csamtools.pyx":1531
15050  * 
15051  *     def __dealloc__(self):
15052  *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
15053  *         if self.owns_samfile: samclose( self.fp )
15054  * 
15055  */
15056   bam_destroy1(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->b);
15057
15058   /* "csamtools.pyx":1532
15059  *     def __dealloc__(self):
15060  *         bam_destroy1(self.b)
15061  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
15062  * 
15063  * ##-------------------------------------------------------------------
15064  */
15065   if (((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->owns_samfile) {
15066     samclose(((struct __pyx_obj_9csamtools_IteratorRowSelection *)__pyx_v_self)->fp);
15067     goto __pyx_L5;
15068   }
15069   __pyx_L5:;
15070
15071   __Pyx_TraceReturn(Py_None);
15072   __Pyx_RefNannyFinishContext();
15073 }
15074
15075 /* "csamtools.pyx":1545
15076  *     int seq_len
15077  * 
15078  * cdef int __advance_all( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
15079  *     '''advance without any read filtering.
15080  *     '''
15081  */
15082
15083 static  int __pyx_f_9csamtools___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
15084   __pyx_t_9csamtools___iterdata *__pyx_v_d;
15085   int __pyx_r;
15086   __Pyx_TraceDeclarations
15087   __Pyx_RefNannySetupContext("__advance_all");
15088   __Pyx_TraceCall("__advance_all", __pyx_f[0], 1545);
15089
15090   /* "csamtools.pyx":1549
15091  *     '''
15092  *     cdef __iterdata * d
15093  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
15094  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )
15095  * 
15096  */
15097   __pyx_v_d = ((__pyx_t_9csamtools___iterdata *)__pyx_v_data);
15098
15099   /* "csamtools.pyx":1550
15100  *     cdef __iterdata * d
15101  *     d = <__iterdata*>data
15102  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
15103  * 
15104  * cdef int __advance_snpcalls( void * data, bam1_t * b ):
15105  */
15106   __pyx_r = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
15107   goto __pyx_L0;
15108
15109   __pyx_r = 0;
15110   __pyx_L0:;
15111   __Pyx_TraceReturn(Py_None);
15112   __Pyx_RefNannyFinishContext();
15113   return __pyx_r;
15114 }
15115
15116 /* "csamtools.pyx":1552
15117  *     return bam_iter_read( d.samfile.x.bam, d.iter, b )
15118  * 
15119  * cdef int __advance_snpcalls( void * data, bam1_t * b ):             # <<<<<<<<<<<<<<
15120  *     '''advance using same filter and read processing as in
15121  *     the samtools pileup.
15122  */
15123
15124 static  int __pyx_f_9csamtools___advance_snpcalls(void *__pyx_v_data, bam1_t *__pyx_v_b) {
15125   __pyx_t_9csamtools___iterdata *__pyx_v_d;
15126   int __pyx_v_ret;
15127   int __pyx_v_skip;
15128   int __pyx_v_q;
15129   int __pyx_v_is_cns;
15130   int __pyx_v_is_nobaq;
15131   int __pyx_v_capQ_thres;
15132   int __pyx_r;
15133   int __pyx_t_1;
15134   int __pyx_t_2;
15135   int __pyx_t_3;
15136   PyObject *__pyx_t_4 = NULL;
15137   PyObject *__pyx_t_5 = NULL;
15138   PyObject *__pyx_t_6 = NULL;
15139   long __pyx_t_7;
15140   __Pyx_TraceDeclarations
15141   __Pyx_RefNannySetupContext("__advance_snpcalls");
15142   __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1552);
15143
15144   /* "csamtools.pyx":1557
15145  *     '''
15146  *     cdef __iterdata * d
15147  *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
15148  * 
15149  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
15150  */
15151   __pyx_v_d = ((__pyx_t_9csamtools___iterdata *)__pyx_v_data);
15152
15153   /* "csamtools.pyx":1559
15154  *     d = <__iterdata*>data
15155  * 
15156  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
15157  *     cdef int skip = 0
15158  *     cdef int q
15159  */
15160   __pyx_v_ret = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
15161
15162   /* "csamtools.pyx":1560
15163  * 
15164  *     cdef int ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
15165  *     cdef int skip = 0             # <<<<<<<<<<<<<<
15166  *     cdef int q
15167  *     cdef int is_cns = 1
15168  */
15169   __pyx_v_skip = 0;
15170
15171   /* "csamtools.pyx":1562
15172  *     cdef int skip = 0
15173  *     cdef int q
15174  *     cdef int is_cns = 1             # <<<<<<<<<<<<<<
15175  *     cdef int is_nobaq = 0
15176  *     cdef int capQ_thres = 0
15177  */
15178   __pyx_v_is_cns = 1;
15179
15180   /* "csamtools.pyx":1563
15181  *     cdef int q
15182  *     cdef int is_cns = 1
15183  *     cdef int is_nobaq = 0             # <<<<<<<<<<<<<<
15184  *     cdef int capQ_thres = 0
15185  * 
15186  */
15187   __pyx_v_is_nobaq = 0;
15188
15189   /* "csamtools.pyx":1564
15190  *     cdef int is_cns = 1
15191  *     cdef int is_nobaq = 0
15192  *     cdef int capQ_thres = 0             # <<<<<<<<<<<<<<
15193  * 
15194  *     # reload sequence
15195  */
15196   __pyx_v_capQ_thres = 0;
15197
15198   /* "csamtools.pyx":1567
15199  * 
15200  *     # reload sequence
15201  *     if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
15202  *         if d.seq != NULL: free(d.seq)
15203  *         d.tid = b.core.tid
15204  */
15205   __pyx_t_1 = (__pyx_v_d->fastafile != NULL);
15206   if (__pyx_t_1) {
15207     __pyx_t_2 = (__pyx_v_b->core.tid != __pyx_v_d->tid);
15208     __pyx_t_3 = __pyx_t_2;
15209   } else {
15210     __pyx_t_3 = __pyx_t_1;
15211   }
15212   if (__pyx_t_3) {
15213
15214     /* "csamtools.pyx":1568
15215  *     # reload sequence
15216  *     if d.fastafile != NULL and b.core.tid != d.tid:
15217  *         if d.seq != NULL: free(d.seq)             # <<<<<<<<<<<<<<
15218  *         d.tid = b.core.tid
15219  *         d.seq = faidx_fetch_seq(d.fastafile,
15220  */
15221     __pyx_t_3 = (__pyx_v_d->seq != NULL);
15222     if (__pyx_t_3) {
15223       free(__pyx_v_d->seq);
15224       goto __pyx_L4;
15225     }
15226     __pyx_L4:;
15227
15228     /* "csamtools.pyx":1569
15229  *     if d.fastafile != NULL and b.core.tid != d.tid:
15230  *         if d.seq != NULL: free(d.seq)
15231  *         d.tid = b.core.tid             # <<<<<<<<<<<<<<
15232  *         d.seq = faidx_fetch_seq(d.fastafile,
15233  *                                 d.samfile.header.target_name[d.tid],
15234  */
15235     __pyx_v_d->tid = __pyx_v_b->core.tid;
15236
15237     /* "csamtools.pyx":1570
15238  *         if d.seq != NULL: free(d.seq)
15239  *         d.tid = b.core.tid
15240  *         d.seq = faidx_fetch_seq(d.fastafile,             # <<<<<<<<<<<<<<
15241  *                                 d.samfile.header.target_name[d.tid],
15242  *                                 0, max_pos,
15243  */
15244     __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));
15245
15246     /* "csamtools.pyx":1574
15247  *                                 0, max_pos,
15248  *                                 &d.seq_len)
15249  *         if d.seq == NULL:             # <<<<<<<<<<<<<<
15250  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
15251  *                                   (d.samfile.header.target_name[d.tid],
15252  */
15253     __pyx_t_3 = (__pyx_v_d->seq == NULL);
15254     if (__pyx_t_3) {
15255
15256       /* "csamtools.pyx":1576
15257  *         if d.seq == NULL:
15258  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
15259  *                                   (d.samfile.header.target_name[d.tid],             # <<<<<<<<<<<<<<
15260  *                                    d.tid))
15261  * 
15262  */
15263       __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 = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15264       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
15265
15266       /* "csamtools.pyx":1577
15267  *             raise ValueError( "reference sequence for '%s' (tid=%i) not found" % \
15268  *                                   (d.samfile.header.target_name[d.tid],
15269  *                                    d.tid))             # <<<<<<<<<<<<<<
15270  * 
15271  * 
15272  */
15273       __pyx_t_5 = PyInt_FromLong(__pyx_v_d->tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15274       __Pyx_GOTREF(__pyx_t_5);
15275       __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15276       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
15277       PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_4));
15278       __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
15279       PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
15280       __Pyx_GIVEREF(__pyx_t_5);
15281       __pyx_t_4 = 0;
15282       __pyx_t_5 = 0;
15283       __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_113), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15284       __Pyx_GOTREF(((PyObject *)__pyx_t_5));
15285       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
15286       __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15287       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
15288       PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5));
15289       __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
15290       __pyx_t_5 = 0;
15291       __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 = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15292       __Pyx_GOTREF(__pyx_t_5);
15293       __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
15294       __Pyx_Raise(__pyx_t_5, 0, 0);
15295       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
15296       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15297       goto __pyx_L5;
15298     }
15299     __pyx_L5:;
15300     goto __pyx_L3;
15301   }
15302   __pyx_L3:;
15303
15304   /* "csamtools.pyx":1580
15305  * 
15306  * 
15307  *     while ret >= 0:             # <<<<<<<<<<<<<<
15308  * 
15309  *         skip = 0
15310  */
15311   while (1) {
15312     __pyx_t_3 = (__pyx_v_ret >= 0);
15313     if (!__pyx_t_3) break;
15314
15315     /* "csamtools.pyx":1582
15316  *     while ret >= 0:
15317  * 
15318  *         skip = 0             # <<<<<<<<<<<<<<
15319  * 
15320  *         # realign read - changes base qualities
15321  */
15322     __pyx_v_skip = 0;
15323
15324     /* "csamtools.pyx":1585
15325  * 
15326  *         # realign read - changes base qualities
15327  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )             # <<<<<<<<<<<<<<
15328  * 
15329  *         if d.seq != NULL and capQ_thres > 10:
15330  */
15331     __pyx_t_3 = (__pyx_v_d->seq != NULL);
15332     if (__pyx_t_3) {
15333       if (__pyx_v_is_cns) {
15334         __pyx_t_1 = (!__pyx_v_is_nobaq);
15335         __pyx_t_2 = __pyx_t_1;
15336       } else {
15337         __pyx_t_2 = __pyx_v_is_cns;
15338       }
15339       __pyx_t_1 = __pyx_t_2;
15340     } else {
15341       __pyx_t_1 = __pyx_t_3;
15342     }
15343     if (__pyx_t_1) {
15344       bam_prob_realn(__pyx_v_b, __pyx_v_d->seq);
15345       goto __pyx_L8;
15346     }
15347     __pyx_L8:;
15348
15349     /* "csamtools.pyx":1587
15350  *         if d.seq != NULL and is_cns and not is_nobaq: bam_prob_realn( b, d.seq )
15351  * 
15352  *         if d.seq != NULL and capQ_thres > 10:             # <<<<<<<<<<<<<<
15353  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
15354  *             if q < 0: skip = 1
15355  */
15356     __pyx_t_1 = (__pyx_v_d->seq != NULL);
15357     if (__pyx_t_1) {
15358       __pyx_t_3 = (__pyx_v_capQ_thres > 10);
15359       __pyx_t_2 = __pyx_t_3;
15360     } else {
15361       __pyx_t_2 = __pyx_t_1;
15362     }
15363     if (__pyx_t_2) {
15364
15365       /* "csamtools.pyx":1588
15366  * 
15367  *         if d.seq != NULL and capQ_thres > 10:
15368  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)             # <<<<<<<<<<<<<<
15369  *             if q < 0: skip = 1
15370  *             elif b.core.qual > q: b.core.qual = q
15371  */
15372       __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres);
15373
15374       /* "csamtools.pyx":1589
15375  *         if d.seq != NULL and capQ_thres > 10:
15376  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
15377  *             if q < 0: skip = 1             # <<<<<<<<<<<<<<
15378  *             elif b.core.qual > q: b.core.qual = q
15379  *         if b.core.flag & BAM_FUNMAP: skip = 1
15380  */
15381       __pyx_t_2 = (__pyx_v_q < 0);
15382       if (__pyx_t_2) {
15383         __pyx_v_skip = 1;
15384         goto __pyx_L10;
15385       }
15386
15387       /* "csamtools.pyx":1590
15388  *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
15389  *             if q < 0: skip = 1
15390  *             elif b.core.qual > q: b.core.qual = q             # <<<<<<<<<<<<<<
15391  *         if b.core.flag & BAM_FUNMAP: skip = 1
15392  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
15393  */
15394       __pyx_t_2 = (__pyx_v_b->core.qual > __pyx_v_q);
15395       if (__pyx_t_2) {
15396         __pyx_v_b->core.qual = __pyx_v_q;
15397         goto __pyx_L10;
15398       }
15399       __pyx_L10:;
15400       goto __pyx_L9;
15401     }
15402     __pyx_L9:;
15403
15404     /* "csamtools.pyx":1591
15405  *             if q < 0: skip = 1
15406  *             elif b.core.qual > q: b.core.qual = q
15407  *         if b.core.flag & BAM_FUNMAP: skip = 1             # <<<<<<<<<<<<<<
15408  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
15409  * 
15410  */
15411     __pyx_t_7 = (__pyx_v_b->core.flag & 4);
15412     if (__pyx_t_7) {
15413       __pyx_v_skip = 1;
15414       goto __pyx_L11;
15415     }
15416
15417     /* "csamtools.pyx":1592
15418  *             elif b.core.qual > q: b.core.qual = q
15419  *         if b.core.flag & BAM_FUNMAP: skip = 1
15420  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1             # <<<<<<<<<<<<<<
15421  * 
15422  *         if not skip: break
15423  */
15424     if ((__pyx_v_b->core.flag & 1)) {
15425       __pyx_t_2 = (!(__pyx_v_b->core.flag & 2));
15426       __pyx_t_1 = __pyx_t_2;
15427     } else {
15428       __pyx_t_1 = (__pyx_v_b->core.flag & 1);
15429     }
15430     if (__pyx_t_1) {
15431       __pyx_v_skip = 1;
15432       goto __pyx_L11;
15433     }
15434     __pyx_L11:;
15435
15436     /* "csamtools.pyx":1594
15437  *         elif b.core.flag & 1 and not b.core.flag & 2: skip = 1
15438  * 
15439  *         if not skip: break             # <<<<<<<<<<<<<<
15440  *         # additional filters
15441  * 
15442  */
15443     __pyx_t_1 = (!__pyx_v_skip);
15444     if (__pyx_t_1) {
15445       goto __pyx_L7_break;
15446       goto __pyx_L12;
15447     }
15448     __pyx_L12:;
15449
15450     /* "csamtools.pyx":1597
15451  *         # additional filters
15452  * 
15453  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )             # <<<<<<<<<<<<<<
15454  * 
15455  *     return ret
15456  */
15457     __pyx_v_ret = bam_iter_read(__pyx_v_d->samfile->x.bam, __pyx_v_d->iter, __pyx_v_b);
15458   }
15459   __pyx_L7_break:;
15460
15461   /* "csamtools.pyx":1599
15462  *         ret = bam_iter_read( d.samfile.x.bam, d.iter, b )
15463  * 
15464  *     return ret             # <<<<<<<<<<<<<<
15465  * 
15466  * cdef class IteratorColumn:
15467  */
15468   __pyx_r = __pyx_v_ret;
15469   goto __pyx_L0;
15470
15471   __pyx_r = 0;
15472   goto __pyx_L0;
15473   __pyx_L1_error:;
15474   __Pyx_XDECREF(__pyx_t_4);
15475   __Pyx_XDECREF(__pyx_t_5);
15476   __Pyx_XDECREF(__pyx_t_6);
15477   __Pyx_WriteUnraisable("csamtools.__advance_snpcalls");
15478   __pyx_r = 0;
15479   __pyx_L0:;
15480   __Pyx_TraceReturn(Py_None);
15481   __Pyx_RefNannyFinishContext();
15482   return __pyx_r;
15483 }
15484
15485 /* "csamtools.pyx":1659
15486  *     cdef int max_depth
15487  * 
15488  *     def __cinit__( self, Samfile samfile, **kwargs ):             # <<<<<<<<<<<<<<
15489  *         self.samfile = samfile
15490  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
15491  */
15492
15493 static int __pyx_pf_9csamtools_14IteratorColumn___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
15494 static int __pyx_pf_9csamtools_14IteratorColumn___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
15495   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
15496   PyObject *__pyx_v_kwargs = 0;
15497   int __pyx_r;
15498   PyObject *__pyx_t_1 = NULL;
15499   PyObject *__pyx_t_2 = NULL;
15500   int __pyx_t_3;
15501   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
15502   __Pyx_TraceDeclarations
15503   __Pyx_RefNannySetupContext("__cinit__");
15504   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1659);
15505   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
15506   __Pyx_GOTREF(__pyx_v_kwargs);
15507   if (unlikely(__pyx_kwds)) {
15508     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
15509     PyObject* values[1] = {0};
15510     switch (PyTuple_GET_SIZE(__pyx_args)) {
15511       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
15512       case  0: break;
15513       default: goto __pyx_L5_argtuple_error;
15514     }
15515     switch (PyTuple_GET_SIZE(__pyx_args)) {
15516       case  0:
15517       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
15518       if (likely(values[0])) kw_args--;
15519       else goto __pyx_L5_argtuple_error;
15520     }
15521     if (unlikely(kw_args > 0)) {
15522       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15523     }
15524     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
15525   } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
15526     goto __pyx_L5_argtuple_error;
15527   } else {
15528     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
15529   }
15530   goto __pyx_L4_argument_unpacking_done;
15531   __pyx_L5_argtuple_error:;
15532   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
15533   __pyx_L3_error:;
15534   __Pyx_DECREF(__pyx_v_kwargs);
15535   __Pyx_AddTraceback("csamtools.IteratorColumn.__cinit__");
15536   __Pyx_RefNannyFinishContext();
15537   return -1;
15538   __pyx_L4_argument_unpacking_done:;
15539   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15540
15541   /* "csamtools.pyx":1660
15542  * 
15543  *     def __cinit__( self, Samfile samfile, **kwargs ):
15544  *         self.samfile = samfile             # <<<<<<<<<<<<<<
15545  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
15546  *         self.fastafile = kwargs.get( "fastafile", None )
15547  */
15548   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
15549   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
15550   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->samfile);
15551   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->samfile));
15552   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->samfile = __pyx_v_samfile;
15553
15554   /* "csamtools.pyx":1661
15555  *     def __cinit__( self, Samfile samfile, **kwargs ):
15556  *         self.samfile = samfile
15557  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )             # <<<<<<<<<<<<<<
15558  *         self.fastafile = kwargs.get( "fastafile", None )
15559  *         self.stepper = kwargs.get( "stepper", None )
15560  */
15561   if (unlikely(__pyx_v_kwargs == Py_None)) {
15562     PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'get'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1661; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
15563   }
15564   __pyx_t_1 = PyInt_FromLong(BAM_DEF_MASK); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15565   __Pyx_GOTREF(__pyx_t_1);
15566   __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 = 1661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15567   __Pyx_GOTREF(__pyx_t_2);
15568   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
15569   __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 = 1661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15570   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15571   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->mask = __pyx_t_3;
15572
15573   /* "csamtools.pyx":1662
15574  *         self.samfile = samfile
15575  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
15576  *         self.fastafile = kwargs.get( "fastafile", None )             # <<<<<<<<<<<<<<
15577  *         self.stepper = kwargs.get( "stepper", None )
15578  *         self.max_depth = kwargs.get( "max_depth", 8000 )
15579  */
15580   if (unlikely(__pyx_v_kwargs == Py_None)) {
15581     PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'get'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
15582   }
15583   __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 = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15584   __Pyx_GOTREF(__pyx_t_2);
15585   if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_9csamtools_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15586   __Pyx_GIVEREF(__pyx_t_2);
15587   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile);
15588   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile));
15589   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_t_2);
15590   __pyx_t_2 = 0;
15591
15592   /* "csamtools.pyx":1663
15593  *         self.mask = kwargs.get("mask", BAM_DEF_MASK )
15594  *         self.fastafile = kwargs.get( "fastafile", None )
15595  *         self.stepper = kwargs.get( "stepper", None )             # <<<<<<<<<<<<<<
15596  *         self.max_depth = kwargs.get( "max_depth", 8000 )
15597  *         self.iterdata.seq = NULL
15598  */
15599   if (unlikely(__pyx_v_kwargs == Py_None)) {
15600     PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'get'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
15601   }
15602   __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 = 1663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15603   __Pyx_GOTREF(__pyx_t_2);
15604   __Pyx_GIVEREF(__pyx_t_2);
15605   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->stepper);
15606   __Pyx_DECREF(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->stepper);
15607   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->stepper = __pyx_t_2;
15608   __pyx_t_2 = 0;
15609
15610   /* "csamtools.pyx":1664
15611  *         self.fastafile = kwargs.get( "fastafile", None )
15612  *         self.stepper = kwargs.get( "stepper", None )
15613  *         self.max_depth = kwargs.get( "max_depth", 8000 )             # <<<<<<<<<<<<<<
15614  *         self.iterdata.seq = NULL
15615  *         self.tid = 0
15616  */
15617   if (unlikely(__pyx_v_kwargs == Py_None)) {
15618     PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'get'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1664; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
15619   }
15620   __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 = 1664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15621   __Pyx_GOTREF(__pyx_t_2);
15622   __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 = 1664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15623   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
15624   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->max_depth = __pyx_t_3;
15625
15626   /* "csamtools.pyx":1665
15627  *         self.stepper = kwargs.get( "stepper", None )
15628  *         self.max_depth = kwargs.get( "max_depth", 8000 )
15629  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
15630  *         self.tid = 0
15631  *         self.pos = 0
15632  */
15633   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq = NULL;
15634
15635   /* "csamtools.pyx":1666
15636  *         self.max_depth = kwargs.get( "max_depth", 8000 )
15637  *         self.iterdata.seq = NULL
15638  *         self.tid = 0             # <<<<<<<<<<<<<<
15639  *         self.pos = 0
15640  *         self.n_plp = 0
15641  */
15642   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->tid = 0;
15643
15644   /* "csamtools.pyx":1667
15645  *         self.iterdata.seq = NULL
15646  *         self.tid = 0
15647  *         self.pos = 0             # <<<<<<<<<<<<<<
15648  *         self.n_plp = 0
15649  *         self.plp = NULL
15650  */
15651   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pos = 0;
15652
15653   /* "csamtools.pyx":1668
15654  *         self.tid = 0
15655  *         self.pos = 0
15656  *         self.n_plp = 0             # <<<<<<<<<<<<<<
15657  *         self.plp = NULL
15658  *         self.pileup_iter = <bam_plp_t>NULL
15659  */
15660   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->n_plp = 0;
15661
15662   /* "csamtools.pyx":1669
15663  *         self.pos = 0
15664  *         self.n_plp = 0
15665  *         self.plp = NULL             # <<<<<<<<<<<<<<
15666  *         self.pileup_iter = <bam_plp_t>NULL
15667  * 
15668  */
15669   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->plp = NULL;
15670
15671   /* "csamtools.pyx":1670
15672  *         self.n_plp = 0
15673  *         self.plp = NULL
15674  *         self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
15675  * 
15676  * 
15677  */
15678   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter = ((bam_plp_t)NULL);
15679
15680   __pyx_r = 0;
15681   goto __pyx_L0;
15682   __pyx_L1_error:;
15683   __Pyx_XDECREF(__pyx_t_1);
15684   __Pyx_XDECREF(__pyx_t_2);
15685   __Pyx_AddTraceback("csamtools.IteratorColumn.__cinit__");
15686   __pyx_r = -1;
15687   __pyx_L0:;
15688   __Pyx_DECREF(__pyx_v_kwargs);
15689   __Pyx_TraceReturn(Py_None);
15690   __Pyx_RefNannyFinishContext();
15691   return __pyx_r;
15692 }
15693
15694 /* "csamtools.pyx":1673
15695  * 
15696  * 
15697  *     def __iter__(self):             # <<<<<<<<<<<<<<
15698  *         return self
15699  * 
15700  */
15701
15702 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_1__iter__(PyObject *__pyx_v_self); /*proto*/
15703 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_1__iter__(PyObject *__pyx_v_self) {
15704   PyObject *__pyx_r = NULL;
15705   __Pyx_TraceDeclarations
15706   __Pyx_RefNannySetupContext("__iter__");
15707   __Pyx_TraceCall("__iter__", __pyx_f[0], 1673);
15708
15709   /* "csamtools.pyx":1674
15710  * 
15711  *     def __iter__(self):
15712  *         return self             # <<<<<<<<<<<<<<
15713  * 
15714  *     cdef int cnext(self):
15715  */
15716   __Pyx_XDECREF(__pyx_r);
15717   __Pyx_INCREF(__pyx_v_self);
15718   __pyx_r = __pyx_v_self;
15719   goto __pyx_L0;
15720
15721   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15722   __pyx_L0:;
15723   __Pyx_XGIVEREF(__pyx_r);
15724   __Pyx_TraceReturn(__pyx_r);
15725   __Pyx_RefNannyFinishContext();
15726   return __pyx_r;
15727 }
15728
15729 /* "csamtools.pyx":1676
15730  *         return self
15731  * 
15732  *     cdef int cnext(self):             # <<<<<<<<<<<<<<
15733  *         '''perform next iteration.
15734  * 
15735  */
15736
15737 static  int __pyx_f_9csamtools_14IteratorColumn_cnext(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
15738   int __pyx_r;
15739   __Pyx_TraceDeclarations
15740   __Pyx_RefNannySetupContext("cnext");
15741   __Pyx_TraceCall("cnext", __pyx_f[0], 1676);
15742
15743   /* "csamtools.pyx":1682
15744  *         It has been re-implemented to permit for filtering.
15745  *         '''
15746  *         self.plp = bam_plp_auto( self.pileup_iter,             # <<<<<<<<<<<<<<
15747  *                                  &self.tid,
15748  *                                  &self.pos,
15749  */
15750   __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));
15751
15752   __pyx_r = 0;
15753   __Pyx_TraceReturn(Py_None);
15754   __Pyx_RefNannyFinishContext();
15755   return __pyx_r;
15756 }
15757
15758 /* "csamtools.pyx":1687
15759  *                                  &self.n_plp )
15760  * 
15761  *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
15762  *         '''return current reference sequence underlying the iterator.
15763  *         '''
15764  */
15765
15766 static  char *__pyx_f_9csamtools_14IteratorColumn_getSequence(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self) {
15767   char *__pyx_r;
15768   __Pyx_TraceDeclarations
15769   __Pyx_RefNannySetupContext("getSequence");
15770   __Pyx_TraceCall("getSequence", __pyx_f[0], 1687);
15771
15772   /* "csamtools.pyx":1690
15773  *         '''return current reference sequence underlying the iterator.
15774  *         '''
15775  *         return self.iterdata.seq             # <<<<<<<<<<<<<<
15776  * 
15777  *     property seq_len:
15778  */
15779   __pyx_r = __pyx_v_self->iterdata.seq;
15780   goto __pyx_L0;
15781
15782   __pyx_r = 0;
15783   __pyx_L0:;
15784   __Pyx_TraceReturn(Py_None);
15785   __Pyx_RefNannyFinishContext();
15786   return __pyx_r;
15787 }
15788
15789 /* "csamtools.pyx":1694
15790  *     property seq_len:
15791  *         '''current sequence length.'''
15792  *         def __get__(self): return self.iterdata.seq_len             # <<<<<<<<<<<<<<
15793  * 
15794  *     def addReference( self, Fastafile fastafile ):
15795  */
15796
15797 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(PyObject *__pyx_v_self); /*proto*/
15798 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(PyObject *__pyx_v_self) {
15799   PyObject *__pyx_r = NULL;
15800   PyObject *__pyx_t_1 = NULL;
15801   __Pyx_TraceDeclarations
15802   __Pyx_RefNannySetupContext("__get__");
15803   __Pyx_TraceCall("__get__", __pyx_f[0], 1694);
15804   __Pyx_XDECREF(__pyx_r);
15805   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15806   __Pyx_GOTREF(__pyx_t_1);
15807   __pyx_r = __pyx_t_1;
15808   __pyx_t_1 = 0;
15809   goto __pyx_L0;
15810
15811   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15812   goto __pyx_L0;
15813   __pyx_L1_error:;
15814   __Pyx_XDECREF(__pyx_t_1);
15815   __Pyx_AddTraceback("csamtools.IteratorColumn.seq_len.__get__");
15816   __pyx_r = NULL;
15817   __pyx_L0:;
15818   __Pyx_XGIVEREF(__pyx_r);
15819   __Pyx_TraceReturn(__pyx_r);
15820   __Pyx_RefNannyFinishContext();
15821   return __pyx_r;
15822 }
15823
15824 /* "csamtools.pyx":1696
15825  *         def __get__(self): return self.iterdata.seq_len
15826  * 
15827  *     def addReference( self, Fastafile fastafile ):             # <<<<<<<<<<<<<<
15828  *        '''
15829  *        add reference sequences in *fastafile* to iterator.'''
15830  */
15831
15832 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_2addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
15833 static char __pyx_doc_9csamtools_14IteratorColumn_2addReference[] = "IteratorColumn.addReference(self, Fastafile fastafile)\n\n       add reference sequences in *fastafile* to iterator.";
15834 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_2addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
15835   PyObject *__pyx_r = NULL;
15836   int __pyx_t_1;
15837   __Pyx_TraceDeclarations
15838   __Pyx_RefNannySetupContext("addReference");
15839   __Pyx_TraceCall("addReference", __pyx_f[0], 1696);
15840   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_9csamtools_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15841
15842   /* "csamtools.pyx":1699
15843  *        '''
15844  *        add reference sequences in *fastafile* to iterator.'''
15845  *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
15846  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
15847  *        self.iterdata.tid = -1
15848  */
15849   __Pyx_INCREF(__pyx_v_fastafile);
15850   __Pyx_GIVEREF(__pyx_v_fastafile);
15851   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile);
15852   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile));
15853   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)__pyx_v_fastafile);
15854
15855   /* "csamtools.pyx":1700
15856  *        add reference sequences in *fastafile* to iterator.'''
15857  *        self.fastafile = fastafile
15858  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)             # <<<<<<<<<<<<<<
15859  *        self.iterdata.tid = -1
15860  *        self.iterdata.fastafile = self.fastafile.fastafile
15861  */
15862   __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq != NULL);
15863   if (__pyx_t_1) {
15864     free(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq);
15865     goto __pyx_L5;
15866   }
15867   __pyx_L5:;
15868
15869   /* "csamtools.pyx":1701
15870  *        self.fastafile = fastafile
15871  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
15872  *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
15873  *        self.iterdata.fastafile = self.fastafile.fastafile
15874  * 
15875  */
15876   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.tid = -1;
15877
15878   /* "csamtools.pyx":1702
15879  *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
15880  *        self.iterdata.tid = -1
15881  *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
15882  * 
15883  *     def hasReference( self ):
15884  */
15885   ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.fastafile = ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile->fastafile;
15886
15887   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15888   goto __pyx_L0;
15889   __pyx_L1_error:;
15890   __Pyx_AddTraceback("csamtools.IteratorColumn.addReference");
15891   __pyx_r = NULL;
15892   __pyx_L0:;
15893   __Pyx_XGIVEREF(__pyx_r);
15894   __Pyx_TraceReturn(__pyx_r);
15895   __Pyx_RefNannyFinishContext();
15896   return __pyx_r;
15897 }
15898
15899 /* "csamtools.pyx":1704
15900  *        self.iterdata.fastafile = self.fastafile.fastafile
15901  * 
15902  *     def hasReference( self ):             # <<<<<<<<<<<<<<
15903  *         '''
15904  *         return true if iterator is associated with a reference'''
15905  */
15906
15907 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_3hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
15908 static char __pyx_doc_9csamtools_14IteratorColumn_3hasReference[] = "IteratorColumn.hasReference(self)\n\n        return true if iterator is associated with a reference";
15909 static PyObject *__pyx_pf_9csamtools_14IteratorColumn_3hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
15910   PyObject *__pyx_r = NULL;
15911   __Pyx_TraceDeclarations
15912   __Pyx_RefNannySetupContext("hasReference");
15913   __Pyx_TraceCall("hasReference", __pyx_f[0], 1704);
15914
15915   /* "csamtools.pyx":1707
15916  *         '''
15917  *         return true if iterator is associated with a reference'''
15918  *         return self.fastafile             # <<<<<<<<<<<<<<
15919  * 
15920  *     cdef setMask( self, mask ):
15921  */
15922   __Pyx_XDECREF(__pyx_r);
15923   __Pyx_INCREF(((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile));
15924   __pyx_r = ((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->fastafile);
15925   goto __pyx_L0;
15926
15927   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15928   __pyx_L0:;
15929   __Pyx_XGIVEREF(__pyx_r);
15930   __Pyx_TraceReturn(__pyx_r);
15931   __Pyx_RefNannyFinishContext();
15932   return __pyx_r;
15933 }
15934
15935 /* "csamtools.pyx":1709
15936  *         return self.fastafile
15937  * 
15938  *     cdef setMask( self, mask ):             # <<<<<<<<<<<<<<
15939  *         '''set masking flag in iterator.
15940  * 
15941  */
15942
15943 static  PyObject *__pyx_f_9csamtools_14IteratorColumn_setMask(struct __pyx_obj_9csamtools_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_mask) {
15944   PyObject *__pyx_r = NULL;
15945   int __pyx_t_1;
15946   __Pyx_TraceDeclarations
15947   __Pyx_RefNannySetupContext("setMask");
15948   __Pyx_TraceCall("setMask", __pyx_f[0], 1709);
15949
15950   /* "csamtools.pyx":1714
15951  *         reads with bits set in *mask* will be skipped.
15952  *         '''
15953  *         self.mask = mask             # <<<<<<<<<<<<<<
15954  *         bam_plp_set_mask( self.pileup_iter, self.mask )
15955  * 
15956  */
15957   __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 = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
15958   __pyx_v_self->mask = __pyx_t_1;
15959
15960   /* "csamtools.pyx":1715
15961  *         '''
15962  *         self.mask = mask
15963  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
15964  * 
15965  *     cdef setupIteratorData( self,
15966  */
15967   bam_plp_set_mask(__pyx_v_self->pileup_iter, __pyx_v_self->mask);
15968
15969   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
15970   goto __pyx_L0;
15971   __pyx_L1_error:;
15972   __Pyx_AddTraceback("csamtools.IteratorColumn.setMask");
15973   __pyx_r = 0;
15974   __pyx_L0:;
15975   __Pyx_XGIVEREF(__pyx_r);
15976   __Pyx_TraceReturn(__pyx_r);
15977   __Pyx_RefNannyFinishContext();
15978   return __pyx_r;
15979 }
15980
15981 /* "csamtools.pyx":1717
15982  *         bam_plp_set_mask( self.pileup_iter, self.mask )
15983  * 
15984  *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
15985  *                             int tid,
15986  *                             int start,
15987  */
15988
15989 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) {
15990   int __pyx_v_reopen = ((int)0);
15991   PyObject *__pyx_r = NULL;
15992   PyObject *__pyx_t_1 = NULL;
15993   PyObject *__pyx_t_2 = NULL;
15994   PyObject *__pyx_t_3 = NULL;
15995   PyObject *__pyx_t_4 = NULL;
15996   PyObject *__pyx_t_5 = NULL;
15997   int __pyx_t_6;
15998   int __pyx_t_7;
15999   int __pyx_t_8;
16000   __Pyx_TraceDeclarations
16001   __Pyx_RefNannySetupContext("setupIteratorData");
16002   __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 1717);
16003   if (__pyx_optional_args) {
16004     if (__pyx_optional_args->__pyx_n > 0) {
16005       __pyx_v_reopen = __pyx_optional_args->reopen;
16006     }
16007   }
16008
16009   /* "csamtools.pyx":1724
16010  *         '''setup the iterator structure'''
16011  * 
16012  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )             # <<<<<<<<<<<<<<
16013  *         self.iterdata.samfile = self.samfile.samfile
16014  *         self.iterdata.iter = self.iter.iter
16015  */
16016   __pyx_t_1 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16017   __Pyx_GOTREF(__pyx_t_1);
16018   __pyx_t_2 = PyInt_FromLong(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16019   __Pyx_GOTREF(__pyx_t_2);
16020   __pyx_t_3 = PyInt_FromLong(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16021   __Pyx_GOTREF(__pyx_t_3);
16022   __pyx_t_4 = PyInt_FromLong(__pyx_v_reopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16023   __Pyx_GOTREF(__pyx_t_4);
16024   __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16025   __Pyx_GOTREF(((PyObject *)__pyx_t_5));
16026   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
16027   PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
16028   __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
16029   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
16030   __Pyx_GIVEREF(__pyx_t_1);
16031   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
16032   __Pyx_GIVEREF(__pyx_t_2);
16033   PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
16034   __Pyx_GIVEREF(__pyx_t_3);
16035   PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
16036   __Pyx_GIVEREF(__pyx_t_4);
16037   __pyx_t_1 = 0;
16038   __pyx_t_2 = 0;
16039   __pyx_t_3 = 0;
16040   __pyx_t_4 = 0;
16041   __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 = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16042   __Pyx_GOTREF(__pyx_t_4);
16043   __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
16044   __Pyx_GIVEREF(__pyx_t_4);
16045   __Pyx_GOTREF(__pyx_v_self->iter);
16046   __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
16047   __pyx_v_self->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_4);
16048   __pyx_t_4 = 0;
16049
16050   /* "csamtools.pyx":1725
16051  * 
16052  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
16053  *         self.iterdata.samfile = self.samfile.samfile             # <<<<<<<<<<<<<<
16054  *         self.iterdata.iter = self.iter.iter
16055  *         self.iterdata.seq = NULL
16056  */
16057   __pyx_v_self->iterdata.samfile = __pyx_v_self->samfile->samfile;
16058
16059   /* "csamtools.pyx":1726
16060  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen )
16061  *         self.iterdata.samfile = self.samfile.samfile
16062  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
16063  *         self.iterdata.seq = NULL
16064  *         self.iterdata.tid = -1
16065  */
16066   __pyx_v_self->iterdata.iter = __pyx_v_self->iter->iter;
16067
16068   /* "csamtools.pyx":1727
16069  *         self.iterdata.samfile = self.samfile.samfile
16070  *         self.iterdata.iter = self.iter.iter
16071  *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
16072  *         self.iterdata.tid = -1
16073  * 
16074  */
16075   __pyx_v_self->iterdata.seq = NULL;
16076
16077   /* "csamtools.pyx":1728
16078  *         self.iterdata.iter = self.iter.iter
16079  *         self.iterdata.seq = NULL
16080  *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
16081  * 
16082  *         if self.fastafile != None:
16083  */
16084   __pyx_v_self->iterdata.tid = -1;
16085
16086   /* "csamtools.pyx":1730
16087  *         self.iterdata.tid = -1
16088  * 
16089  *         if self.fastafile != None:             # <<<<<<<<<<<<<<
16090  *             self.iterdata.fastafile = self.fastafile.fastafile
16091  *         else:
16092  */
16093   __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 = 1730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16094   __Pyx_GOTREF(__pyx_t_4);
16095   __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16096   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16097   if (__pyx_t_6) {
16098
16099     /* "csamtools.pyx":1731
16100  * 
16101  *         if self.fastafile != None:
16102  *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
16103  *         else:
16104  *             self.iterdata.fastafile = NULL
16105  */
16106     __pyx_v_self->iterdata.fastafile = __pyx_v_self->fastafile->fastafile;
16107     goto __pyx_L3;
16108   }
16109   /*else*/ {
16110
16111     /* "csamtools.pyx":1733
16112  *             self.iterdata.fastafile = self.fastafile.fastafile
16113  *         else:
16114  *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
16115  * 
16116  *         if self.stepper == None or self.stepper == "all":
16117  */
16118     __pyx_v_self->iterdata.fastafile = NULL;
16119   }
16120   __pyx_L3:;
16121
16122   /* "csamtools.pyx":1735
16123  *             self.iterdata.fastafile = NULL
16124  * 
16125  *         if self.stepper == None or self.stepper == "all":             # <<<<<<<<<<<<<<
16126  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
16127  *         elif self.stepper == "samtools":
16128  */
16129   __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 = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16130   __Pyx_GOTREF(__pyx_t_4);
16131   __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16132   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16133   if (!__pyx_t_6) {
16134     __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__all), Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16135     __Pyx_GOTREF(__pyx_t_4);
16136     __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16137     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16138     __pyx_t_8 = __pyx_t_7;
16139   } else {
16140     __pyx_t_8 = __pyx_t_6;
16141   }
16142   if (__pyx_t_8) {
16143
16144     /* "csamtools.pyx":1736
16145  * 
16146  *         if self.stepper == None or self.stepper == "all":
16147  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )             # <<<<<<<<<<<<<<
16148  *         elif self.stepper == "samtools":
16149  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
16150  */
16151     __pyx_v_self->pileup_iter = bam_plp_init((&__pyx_f_9csamtools___advance_all), (&__pyx_v_self->iterdata));
16152     goto __pyx_L4;
16153   }
16154
16155   /* "csamtools.pyx":1737
16156  *         if self.stepper == None or self.stepper == "all":
16157  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
16158  *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
16159  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
16160  *         else:
16161  */
16162   __pyx_t_4 = PyObject_RichCompare(__pyx_v_self->stepper, ((PyObject *)__pyx_n_s__samtools), Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16163   __Pyx_GOTREF(__pyx_t_4);
16164   __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16165   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16166   if (__pyx_t_8) {
16167
16168     /* "csamtools.pyx":1738
16169  *             self.pileup_iter = bam_plp_init( &__advance_all, &self.iterdata )
16170  *         elif self.stepper == "samtools":
16171  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )             # <<<<<<<<<<<<<<
16172  *         else:
16173  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)
16174  */
16175     __pyx_v_self->pileup_iter = bam_plp_init((&__pyx_f_9csamtools___advance_snpcalls), (&__pyx_v_self->iterdata));
16176     goto __pyx_L4;
16177   }
16178   /*else*/ {
16179
16180     /* "csamtools.pyx":1740
16181  *             self.pileup_iter = bam_plp_init( &__advance_snpcalls, &self.iterdata )
16182  *         else:
16183  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
16184  * 
16185  *         if self.max_depth:
16186  */
16187     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_114), __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16188     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
16189     __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16190     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
16191     PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4));
16192     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
16193     __pyx_t_4 = 0;
16194     __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 = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16195     __Pyx_GOTREF(__pyx_t_4);
16196     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
16197     __Pyx_Raise(__pyx_t_4, 0, 0);
16198     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16199     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16200   }
16201   __pyx_L4:;
16202
16203   /* "csamtools.pyx":1742
16204  *             raise ValueError( "unknown stepper option `%s` in IteratorColumn" % self.stepper)
16205  * 
16206  *         if self.max_depth:             # <<<<<<<<<<<<<<
16207  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )
16208  * 
16209  */
16210   if (__pyx_v_self->max_depth) {
16211
16212     /* "csamtools.pyx":1743
16213  * 
16214  *         if self.max_depth:
16215  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )             # <<<<<<<<<<<<<<
16216  * 
16217  *         bam_plp_set_mask( self.pileup_iter, self.mask )
16218  */
16219     bam_plp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
16220     goto __pyx_L5;
16221   }
16222   __pyx_L5:;
16223
16224   /* "csamtools.pyx":1745
16225  *             bam_plp_set_maxcnt( self.pileup_iter, self.max_depth )
16226  * 
16227  *         bam_plp_set_mask( self.pileup_iter, self.mask )             # <<<<<<<<<<<<<<
16228  * 
16229  *     cdef reset( self, tid, start, end ):
16230  */
16231   bam_plp_set_mask(__pyx_v_self->pileup_iter, __pyx_v_self->mask);
16232
16233   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16234   goto __pyx_L0;
16235   __pyx_L1_error:;
16236   __Pyx_XDECREF(__pyx_t_1);
16237   __Pyx_XDECREF(__pyx_t_2);
16238   __Pyx_XDECREF(__pyx_t_3);
16239   __Pyx_XDECREF(__pyx_t_4);
16240   __Pyx_XDECREF(__pyx_t_5);
16241   __Pyx_AddTraceback("csamtools.IteratorColumn.setupIteratorData");
16242   __pyx_r = 0;
16243   __pyx_L0:;
16244   __Pyx_XGIVEREF(__pyx_r);
16245   __Pyx_TraceReturn(__pyx_r);
16246   __Pyx_RefNannyFinishContext();
16247   return __pyx_r;
16248 }
16249
16250 /* "csamtools.pyx":1747
16251  *         bam_plp_set_mask( self.pileup_iter, self.mask )
16252  * 
16253  *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
16254  *         '''reset iterator position.
16255  * 
16256  */
16257
16258 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) {
16259   PyObject *__pyx_r = NULL;
16260   PyObject *__pyx_t_1 = NULL;
16261   PyObject *__pyx_t_2 = NULL;
16262   PyObject *__pyx_t_3 = NULL;
16263   int __pyx_t_4;
16264   __Pyx_TraceDeclarations
16265   __Pyx_RefNannySetupContext("reset");
16266   __Pyx_TraceCall("reset", __pyx_f[0], 1747);
16267
16268   /* "csamtools.pyx":1753
16269  *         having to incur the full set-up costs.
16270  *         '''
16271  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )             # <<<<<<<<<<<<<<
16272  *         self.iterdata.iter = self.iter.iter
16273  * 
16274  */
16275   __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16276   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
16277   __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
16278   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->samfile));
16279   __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
16280   __Pyx_INCREF(__pyx_v_tid);
16281   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tid);
16282   __Pyx_GIVEREF(__pyx_v_tid);
16283   __Pyx_INCREF(__pyx_v_start);
16284   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_start);
16285   __Pyx_GIVEREF(__pyx_v_start);
16286   __Pyx_INCREF(__pyx_v_end);
16287   PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end);
16288   __Pyx_GIVEREF(__pyx_v_end);
16289   __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16290   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
16291   if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16292   __pyx_t_3 = PyEval_CallObjectWithKeywords(((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 = 1753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16293   __Pyx_GOTREF(__pyx_t_3);
16294   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
16295   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
16296   __Pyx_GIVEREF(__pyx_t_3);
16297   __Pyx_GOTREF(__pyx_v_self->iter);
16298   __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
16299   __pyx_v_self->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)__pyx_t_3);
16300   __pyx_t_3 = 0;
16301
16302   /* "csamtools.pyx":1754
16303  *         '''
16304  *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, reopen = 0 )
16305  *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
16306  * 
16307  *         # invalidate sequence if different tid
16308  */
16309   __pyx_v_self->iterdata.iter = __pyx_v_self->iter->iter;
16310
16311   /* "csamtools.pyx":1757
16312  * 
16313  *         # invalidate sequence if different tid
16314  *         if self.tid != tid:             # <<<<<<<<<<<<<<
16315  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
16316  *             self.iterdata.seq = NULL
16317  */
16318   __pyx_t_3 = PyInt_FromLong(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16319   __Pyx_GOTREF(__pyx_t_3);
16320   __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 = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16321   __Pyx_GOTREF(__pyx_t_2);
16322   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
16323   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16324   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16325   if (__pyx_t_4) {
16326
16327     /* "csamtools.pyx":1758
16328  *         # invalidate sequence if different tid
16329  *         if self.tid != tid:
16330  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )             # <<<<<<<<<<<<<<
16331  *             self.iterdata.seq = NULL
16332  *             self.iterdata.tid = -1
16333  */
16334     __pyx_t_4 = (__pyx_v_self->iterdata.seq != NULL);
16335     if (__pyx_t_4) {
16336       free(__pyx_v_self->iterdata.seq);
16337       goto __pyx_L4;
16338     }
16339     __pyx_L4:;
16340
16341     /* "csamtools.pyx":1759
16342  *         if self.tid != tid:
16343  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
16344  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
16345  *             self.iterdata.tid = -1
16346  * 
16347  */
16348     __pyx_v_self->iterdata.seq = NULL;
16349
16350     /* "csamtools.pyx":1760
16351  *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
16352  *             self.iterdata.seq = NULL
16353  *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
16354  * 
16355  *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
16356  */
16357     __pyx_v_self->iterdata.tid = -1;
16358     goto __pyx_L3;
16359   }
16360   __pyx_L3:;
16361
16362   /* "csamtools.pyx":1763
16363  * 
16364  *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
16365  *         bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
16366  * 
16367  *     def __dealloc__(self):
16368  */
16369   bam_plp_reset(__pyx_v_self->pileup_iter);
16370
16371   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16372   goto __pyx_L0;
16373   __pyx_L1_error:;
16374   __Pyx_XDECREF(__pyx_t_1);
16375   __Pyx_XDECREF(__pyx_t_2);
16376   __Pyx_XDECREF(__pyx_t_3);
16377   __Pyx_AddTraceback("csamtools.IteratorColumn.reset");
16378   __pyx_r = 0;
16379   __pyx_L0:;
16380   __Pyx_XGIVEREF(__pyx_r);
16381   __Pyx_TraceReturn(__pyx_r);
16382   __Pyx_RefNannyFinishContext();
16383   return __pyx_r;
16384 }
16385
16386 /* "csamtools.pyx":1765
16387  *         bam_plp_reset(self.pileup_iter)
16388  * 
16389  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
16390  *         # reset in order to avoid memory leak messages for iterators that have
16391  *         # not been fully consumed
16392  */
16393
16394 static void __pyx_pf_9csamtools_14IteratorColumn_4__dealloc__(PyObject *__pyx_v_self); /*proto*/
16395 static void __pyx_pf_9csamtools_14IteratorColumn_4__dealloc__(PyObject *__pyx_v_self) {
16396   int __pyx_t_1;
16397   __Pyx_TraceDeclarations
16398   __Pyx_RefNannySetupContext("__dealloc__");
16399   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1765);
16400
16401   /* "csamtools.pyx":1768
16402  *         # reset in order to avoid memory leak messages for iterators that have
16403  *         # not been fully consumed
16404  *         if self.pileup_iter != <bam_plp_t>NULL:             # <<<<<<<<<<<<<<
16405  *             bam_plp_reset(self.pileup_iter)
16406  *             bam_plp_destroy(self.pileup_iter)
16407  */
16408   __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter != ((bam_plp_t)NULL));
16409   if (__pyx_t_1) {
16410
16411     /* "csamtools.pyx":1769
16412  *         # not been fully consumed
16413  *         if self.pileup_iter != <bam_plp_t>NULL:
16414  *             bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
16415  *             bam_plp_destroy(self.pileup_iter)
16416  *             self.pileup_iter = <bam_plp_t>NULL
16417  */
16418     bam_plp_reset(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter);
16419
16420     /* "csamtools.pyx":1770
16421  *         if self.pileup_iter != <bam_plp_t>NULL:
16422  *             bam_plp_reset(self.pileup_iter)
16423  *             bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
16424  *             self.pileup_iter = <bam_plp_t>NULL
16425  * 
16426  */
16427     bam_plp_destroy(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter);
16428
16429     /* "csamtools.pyx":1771
16430  *             bam_plp_reset(self.pileup_iter)
16431  *             bam_plp_destroy(self.pileup_iter)
16432  *             self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
16433  * 
16434  *         if self.iterdata.seq != NULL:
16435  */
16436     ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->pileup_iter = ((bam_plp_t)NULL);
16437     goto __pyx_L5;
16438   }
16439   __pyx_L5:;
16440
16441   /* "csamtools.pyx":1773
16442  *             self.pileup_iter = <bam_plp_t>NULL
16443  * 
16444  *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
16445  *             free(self.iterdata.seq)
16446  *             self.iterdata.seq = NULL
16447  */
16448   __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq != NULL);
16449   if (__pyx_t_1) {
16450
16451     /* "csamtools.pyx":1774
16452  * 
16453  *         if self.iterdata.seq != NULL:
16454  *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
16455  *             self.iterdata.seq = NULL
16456  * 
16457  */
16458     free(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq);
16459
16460     /* "csamtools.pyx":1775
16461  *         if self.iterdata.seq != NULL:
16462  *             free(self.iterdata.seq)
16463  *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
16464  * 
16465  * cdef class IteratorColumnRegion(IteratorColumn):
16466  */
16467     ((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self)->iterdata.seq = NULL;
16468     goto __pyx_L6;
16469   }
16470   __pyx_L6:;
16471
16472   __Pyx_TraceReturn(Py_None);
16473   __Pyx_RefNannyFinishContext();
16474 }
16475
16476 /* "csamtools.pyx":1780
16477  *     '''iterates over a region only.
16478  *     '''
16479  *     def __cinit__(self, Samfile samfile,             # <<<<<<<<<<<<<<
16480  *                   int tid = 0,
16481  *                   int start = 0,
16482  */
16483
16484 static int __pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
16485 static int __pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
16486   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
16487   int __pyx_v_tid;
16488   int __pyx_v_start;
16489   int __pyx_v_end;
16490   PyObject *__pyx_v_kwargs = 0;
16491   int __pyx_r;
16492   PyObject *__pyx_t_1 = NULL;
16493   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_2;
16494   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__tid,&__pyx_n_s__start,&__pyx_n_s__end,0};
16495   __Pyx_TraceDeclarations
16496   __Pyx_RefNannySetupContext("__cinit__");
16497   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1780);
16498   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
16499   __Pyx_GOTREF(__pyx_v_kwargs);
16500   if (unlikely(__pyx_kwds)) {
16501     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
16502     PyObject* values[4] = {0,0,0,0};
16503     switch (PyTuple_GET_SIZE(__pyx_args)) {
16504       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
16505       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
16506       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
16507       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16508       case  0: break;
16509       default: goto __pyx_L5_argtuple_error;
16510     }
16511     switch (PyTuple_GET_SIZE(__pyx_args)) {
16512       case  0:
16513       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
16514       if (likely(values[0])) kw_args--;
16515       else goto __pyx_L5_argtuple_error;
16516       case  1:
16517       if (kw_args > 0) {
16518         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tid);
16519         if (value) { values[1] = value; kw_args--; }
16520       }
16521       case  2:
16522       if (kw_args > 0) {
16523         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
16524         if (value) { values[2] = value; kw_args--; }
16525       }
16526       case  3:
16527       if (kw_args > 0) {
16528         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
16529         if (value) { values[3] = value; kw_args--; }
16530       }
16531     }
16532     if (unlikely(kw_args > 0)) {
16533       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16534     }
16535     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
16536     if (values[1]) {
16537       __pyx_v_tid = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16538     } else {
16539       __pyx_v_tid = ((int)0);
16540     }
16541     if (values[2]) {
16542       __pyx_v_start = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16543     } else {
16544       __pyx_v_start = ((int)0);
16545     }
16546     if (values[3]) {
16547       __pyx_v_end = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16548     } else {
16549       __pyx_v_end = __pyx_k_115;
16550     }
16551   } else {
16552     __pyx_v_tid = ((int)0);
16553     __pyx_v_start = ((int)0);
16554     __pyx_v_end = __pyx_k_115;
16555     switch (PyTuple_GET_SIZE(__pyx_args)) {
16556       case  4: __pyx_v_end = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16557       case  3: __pyx_v_start = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1782; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16558       case  2: __pyx_v_tid = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16559       case  1: __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
16560       break;
16561       default: goto __pyx_L5_argtuple_error;
16562     }
16563   }
16564   goto __pyx_L4_argument_unpacking_done;
16565   __pyx_L5_argtuple_error:;
16566   __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16567   __pyx_L3_error:;
16568   __Pyx_DECREF(__pyx_v_kwargs);
16569   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__cinit__");
16570   __Pyx_RefNannyFinishContext();
16571   return -1;
16572   __pyx_L4_argument_unpacking_done:;
16573   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16574
16575   /* "csamtools.pyx":1787
16576  * 
16577  *         # initialize iterator
16578  *         self.setupIteratorData( tid, start, end, 1 )             # <<<<<<<<<<<<<<
16579  * 
16580  *     def __next__(self):
16581  */
16582   __pyx_t_2.__pyx_n = 1;
16583   __pyx_t_2.reopen = 1;
16584   __pyx_t_1 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *)((struct __pyx_obj_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 = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16585   __Pyx_GOTREF(__pyx_t_1);
16586   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16587
16588   __pyx_r = 0;
16589   goto __pyx_L0;
16590   __pyx_L1_error:;
16591   __Pyx_XDECREF(__pyx_t_1);
16592   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__cinit__");
16593   __pyx_r = -1;
16594   __pyx_L0:;
16595   __Pyx_DECREF(__pyx_v_kwargs);
16596   __Pyx_TraceReturn(Py_None);
16597   __Pyx_RefNannyFinishContext();
16598   return __pyx_r;
16599 }
16600
16601 /* "csamtools.pyx":1789
16602  *         self.setupIteratorData( tid, start, end, 1 )
16603  * 
16604  *     def __next__(self):             # <<<<<<<<<<<<<<
16605  *         """python version of next().
16606  *         """
16607  */
16608
16609 static PyObject *__pyx_pf_9csamtools_20IteratorColumnRegion_1__next__(PyObject *__pyx_v_self); /*proto*/
16610 static char __pyx_doc_9csamtools_20IteratorColumnRegion_1__next__[] = "python version of next().\n        ";
16611 struct wrapperbase __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_1__next__;
16612 static PyObject *__pyx_pf_9csamtools_20IteratorColumnRegion_1__next__(PyObject *__pyx_v_self) {
16613   PyObject *__pyx_r = NULL;
16614   int __pyx_t_1;
16615   PyObject *__pyx_t_2 = NULL;
16616   __Pyx_TraceDeclarations
16617   __Pyx_RefNannySetupContext("__next__");
16618   __Pyx_TraceCall("__next__", __pyx_f[0], 1789);
16619
16620   /* "csamtools.pyx":1793
16621  *         """
16622  * 
16623  *         while 1:             # <<<<<<<<<<<<<<
16624  *             self.cnext()
16625  *             if self.n_plp < 0:
16626  */
16627   while (1) {
16628     if (!1) break;
16629
16630     /* "csamtools.pyx":1794
16631  * 
16632  *         while 1:
16633  *             self.cnext()             # <<<<<<<<<<<<<<
16634  *             if self.n_plp < 0:
16635  *                 raise ValueError("error during iteration" )
16636  */
16637     ((struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion *)((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
16638
16639     /* "csamtools.pyx":1795
16640  *         while 1:
16641  *             self.cnext()
16642  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
16643  *                 raise ValueError("error during iteration" )
16644  * 
16645  */
16646     __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.n_plp < 0);
16647     if (__pyx_t_1) {
16648
16649       /* "csamtools.pyx":1796
16650  *             self.cnext()
16651  *             if self.n_plp < 0:
16652  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
16653  * 
16654  *             if self.plp == NULL:
16655  */
16656       __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_117), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16657       __Pyx_GOTREF(__pyx_t_2);
16658       __Pyx_Raise(__pyx_t_2, 0, 0);
16659       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16660       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16661       goto __pyx_L7;
16662     }
16663     __pyx_L7:;
16664
16665     /* "csamtools.pyx":1798
16666  *                 raise ValueError("error during iteration" )
16667  * 
16668  *             if self.plp == NULL:             # <<<<<<<<<<<<<<
16669  *                 raise StopIteration
16670  * 
16671  */
16672     __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.plp == NULL);
16673     if (__pyx_t_1) {
16674
16675       /* "csamtools.pyx":1799
16676  * 
16677  *             if self.plp == NULL:
16678  *                 raise StopIteration             # <<<<<<<<<<<<<<
16679  * 
16680  *             return makePileupProxy( <bam_pileup1_t*>self.plp,
16681  */
16682       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
16683       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16684       goto __pyx_L8;
16685     }
16686     __pyx_L8:;
16687
16688     /* "csamtools.pyx":1801
16689  *                 raise StopIteration
16690  * 
16691  *             return makePileupProxy( <bam_pileup1_t*>self.plp,             # <<<<<<<<<<<<<<
16692  *                                      self.tid,
16693  *                                      self.pos,
16694  */
16695     __Pyx_XDECREF(__pyx_r);
16696
16697     /* "csamtools.pyx":1804
16698  *                                      self.tid,
16699  *                                      self.pos,
16700  *                                      self.n_plp )             # <<<<<<<<<<<<<<
16701  * 
16702  * cdef class IteratorColumnAllRefs(IteratorColumn):
16703  */
16704     __pyx_t_2 = __pyx_f_9csamtools_makePileupProxy(((bam_pileup1_t *)((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.plp), ((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.tid, ((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.pos, ((struct __pyx_obj_9csamtools_IteratorColumnRegion *)__pyx_v_self)->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16705     __Pyx_GOTREF(__pyx_t_2);
16706     __pyx_r = __pyx_t_2;
16707     __pyx_t_2 = 0;
16708     goto __pyx_L0;
16709   }
16710
16711   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16712   goto __pyx_L0;
16713   __pyx_L1_error:;
16714   __Pyx_XDECREF(__pyx_t_2);
16715   __Pyx_AddTraceback("csamtools.IteratorColumnRegion.__next__");
16716   __pyx_r = NULL;
16717   __pyx_L0:;
16718   __Pyx_XGIVEREF(__pyx_r);
16719   __Pyx_TraceReturn(__pyx_r);
16720   __Pyx_RefNannyFinishContext();
16721   return __pyx_r;
16722 }
16723
16724 /* "csamtools.pyx":1810
16725  *     """
16726  * 
16727  *     def __cinit__(self,             # <<<<<<<<<<<<<<
16728  *                   Samfile samfile,
16729  *                   **kwargs ):
16730  */
16731
16732 static int __pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
16733 static int __pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
16734   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
16735   PyObject *__pyx_v_kwargs = 0;
16736   int __pyx_r;
16737   PyObject *__pyx_t_1 = NULL;
16738   int __pyx_t_2;
16739   int __pyx_t_3;
16740   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_4;
16741   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,0};
16742   __Pyx_TraceDeclarations
16743   __Pyx_RefNannySetupContext("__cinit__");
16744   __Pyx_TraceCall("__cinit__", __pyx_f[0], 1810);
16745   __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
16746   __Pyx_GOTREF(__pyx_v_kwargs);
16747   if (unlikely(__pyx_kwds)) {
16748     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
16749     PyObject* values[1] = {0};
16750     switch (PyTuple_GET_SIZE(__pyx_args)) {
16751       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
16752       case  0: break;
16753       default: goto __pyx_L5_argtuple_error;
16754     }
16755     switch (PyTuple_GET_SIZE(__pyx_args)) {
16756       case  0:
16757       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
16758       if (likely(values[0])) kw_args--;
16759       else goto __pyx_L5_argtuple_error;
16760     }
16761     if (unlikely(kw_args > 0)) {
16762       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, PyTuple_GET_SIZE(__pyx_args), "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16763     }
16764     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
16765   } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
16766     goto __pyx_L5_argtuple_error;
16767   } else {
16768     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
16769   }
16770   goto __pyx_L4_argument_unpacking_done;
16771   __pyx_L5_argtuple_error:;
16772   __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
16773   __pyx_L3_error:;
16774   __Pyx_DECREF(__pyx_v_kwargs);
16775   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__cinit__");
16776   __Pyx_RefNannyFinishContext();
16777   return -1;
16778   __pyx_L4_argument_unpacking_done:;
16779   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16780
16781   /* "csamtools.pyx":1815
16782  * 
16783  *         # no iteration over empty files
16784  *         if not samfile.nreferences: raise StopIteration             # <<<<<<<<<<<<<<
16785  * 
16786  *         # initialize iterator
16787  */
16788   __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 = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16789   __Pyx_GOTREF(__pyx_t_1);
16790   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16791   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16792   __pyx_t_3 = (!__pyx_t_2);
16793   if (__pyx_t_3) {
16794     __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
16795     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16796     goto __pyx_L6;
16797   }
16798   __pyx_L6:;
16799
16800   /* "csamtools.pyx":1818
16801  * 
16802  *         # initialize iterator
16803  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )             # <<<<<<<<<<<<<<
16804  * 
16805  *     def __next__(self):
16806  */
16807   __pyx_t_4.__pyx_n = 1;
16808   __pyx_t_4.reopen = 1;
16809   __pyx_t_1 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__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 = 1818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16810   __Pyx_GOTREF(__pyx_t_1);
16811   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
16812
16813   __pyx_r = 0;
16814   goto __pyx_L0;
16815   __pyx_L1_error:;
16816   __Pyx_XDECREF(__pyx_t_1);
16817   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__cinit__");
16818   __pyx_r = -1;
16819   __pyx_L0:;
16820   __Pyx_DECREF(__pyx_v_kwargs);
16821   __Pyx_TraceReturn(Py_None);
16822   __Pyx_RefNannyFinishContext();
16823   return __pyx_r;
16824 }
16825
16826 /* "csamtools.pyx":1820
16827  *         self.setupIteratorData( self.tid, 0, max_pos, 1 )
16828  * 
16829  *     def __next__(self):             # <<<<<<<<<<<<<<
16830  *         """python version of next().
16831  *         """
16832  */
16833
16834 static PyObject *__pyx_pf_9csamtools_21IteratorColumnAllRefs_1__next__(PyObject *__pyx_v_self); /*proto*/
16835 static char __pyx_doc_9csamtools_21IteratorColumnAllRefs_1__next__[] = "python version of next().\n        ";
16836 struct wrapperbase __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_1__next__;
16837 static PyObject *__pyx_pf_9csamtools_21IteratorColumnAllRefs_1__next__(PyObject *__pyx_v_self) {
16838   PyObject *__pyx_r = NULL;
16839   int __pyx_t_1;
16840   PyObject *__pyx_t_2 = NULL;
16841   PyObject *__pyx_t_3 = NULL;
16842   PyObject *__pyx_t_4 = NULL;
16843   struct __pyx_opt_args_9csamtools_14IteratorColumn_setupIteratorData __pyx_t_5;
16844   __Pyx_TraceDeclarations
16845   __Pyx_RefNannySetupContext("__next__");
16846   __Pyx_TraceCall("__next__", __pyx_f[0], 1820);
16847
16848   /* "csamtools.pyx":1824
16849  *         """
16850  * 
16851  *         while 1:             # <<<<<<<<<<<<<<
16852  *             self.cnext()
16853  * 
16854  */
16855   while (1) {
16856     if (!1) break;
16857
16858     /* "csamtools.pyx":1825
16859  * 
16860  *         while 1:
16861  *             self.cnext()             # <<<<<<<<<<<<<<
16862  * 
16863  *             if self.n_plp < 0:
16864  */
16865     ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self));
16866
16867     /* "csamtools.pyx":1827
16868  *             self.cnext()
16869  * 
16870  *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
16871  *                 raise ValueError("error during iteration" )
16872  * 
16873  */
16874     __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.n_plp < 0);
16875     if (__pyx_t_1) {
16876
16877       /* "csamtools.pyx":1828
16878  * 
16879  *             if self.n_plp < 0:
16880  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
16881  * 
16882  *             # return result, if within same reference
16883  */
16884       __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 = 1828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16885       __Pyx_GOTREF(__pyx_t_2);
16886       __Pyx_Raise(__pyx_t_2, 0, 0);
16887       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16888       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16889       goto __pyx_L7;
16890     }
16891     __pyx_L7:;
16892
16893     /* "csamtools.pyx":1831
16894  * 
16895  *             # return result, if within same reference
16896  *             if self.plp != NULL:             # <<<<<<<<<<<<<<
16897  *                 return makePileupProxy( <bam_pileup1_t*>self.plp,
16898  *                                          self.tid,
16899  */
16900     __pyx_t_1 = (((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.plp != NULL);
16901     if (__pyx_t_1) {
16902
16903       /* "csamtools.pyx":1832
16904  *             # return result, if within same reference
16905  *             if self.plp != NULL:
16906  *                 return makePileupProxy( <bam_pileup1_t*>self.plp,             # <<<<<<<<<<<<<<
16907  *                                          self.tid,
16908  *                                          self.pos,
16909  */
16910       __Pyx_XDECREF(__pyx_r);
16911
16912       /* "csamtools.pyx":1835
16913  *                                          self.tid,
16914  *                                          self.pos,
16915  *                                          self.n_plp )             # <<<<<<<<<<<<<<
16916  * 
16917  *             # otherwise, proceed to next reference or stop
16918  */
16919       __pyx_t_2 = __pyx_f_9csamtools_makePileupProxy(((bam_pileup1_t *)((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.plp), ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.tid, ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.pos, ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.n_plp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16920       __Pyx_GOTREF(__pyx_t_2);
16921       __pyx_r = __pyx_t_2;
16922       __pyx_t_2 = 0;
16923       goto __pyx_L0;
16924       goto __pyx_L8;
16925     }
16926     __pyx_L8:;
16927
16928     /* "csamtools.pyx":1838
16929  * 
16930  *             # otherwise, proceed to next reference or stop
16931  *             self.tid += 1             # <<<<<<<<<<<<<<
16932  *             if self.tid < self.samfile.nreferences:
16933  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
16934  */
16935     ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.tid = (((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.tid + 1);
16936
16937     /* "csamtools.pyx":1839
16938  *             # otherwise, proceed to next reference or stop
16939  *             self.tid += 1
16940  *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
16941  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
16942  *             else:
16943  */
16944     __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16945     __Pyx_GOTREF(__pyx_t_2);
16946     __pyx_t_3 = PyObject_GetAttr(((PyObject *)((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.samfile), __pyx_n_s__nreferences); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16947     __Pyx_GOTREF(__pyx_t_3);
16948     __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 = 1839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16949     __Pyx_GOTREF(__pyx_t_4);
16950     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
16951     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
16952     __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16953     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16954     if (__pyx_t_1) {
16955
16956       /* "csamtools.pyx":1840
16957  *             self.tid += 1
16958  *             if self.tid < self.samfile.nreferences:
16959  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )             # <<<<<<<<<<<<<<
16960  *             else:
16961  *                 raise StopIteration
16962  */
16963       __pyx_t_5.__pyx_n = 1;
16964       __pyx_t_5.reopen = 0;
16965       __pyx_t_4 = ((struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs *)((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__pyx_v_self)->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_9csamtools_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)__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 = 1840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16966       __Pyx_GOTREF(__pyx_t_4);
16967       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
16968       goto __pyx_L9;
16969     }
16970     /*else*/ {
16971
16972       /* "csamtools.pyx":1842
16973  *                 self.setupIteratorData( self.tid, 0, max_pos, 0 )
16974  *             else:
16975  *                 raise StopIteration             # <<<<<<<<<<<<<<
16976  * 
16977  * ##-------------------------------------------------------------------
16978  */
16979       __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0);
16980       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
16981     }
16982     __pyx_L9:;
16983   }
16984
16985   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
16986   goto __pyx_L0;
16987   __pyx_L1_error:;
16988   __Pyx_XDECREF(__pyx_t_2);
16989   __Pyx_XDECREF(__pyx_t_3);
16990   __Pyx_XDECREF(__pyx_t_4);
16991   __Pyx_AddTraceback("csamtools.IteratorColumnAllRefs.__next__");
16992   __pyx_r = NULL;
16993   __pyx_L0:;
16994   __Pyx_XGIVEREF(__pyx_r);
16995   __Pyx_TraceReturn(__pyx_r);
16996   __Pyx_RefNannyFinishContext();
16997   return __pyx_r;
16998 }
16999
17000 /* "csamtools.pyx":1847
17001  * ##-------------------------------------------------------------------
17002  * ##-------------------------------------------------------------------
17003  * cdef inline int32_t query_start(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
17004  *     cdef uint32_t * cigar_p, op
17005  *     cdef uint32_t k
17006  */
17007
17008 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_start(bam1_t *__pyx_v_src) {
17009   uint32_t *__pyx_v_cigar_p;
17010   uint32_t __pyx_v_op;
17011   uint32_t __pyx_v_k;
17012   uint32_t __pyx_v_start_offset;
17013   int32_t __pyx_r;
17014   uint32_t __pyx_t_1;
17015   int __pyx_t_2;
17016   int __pyx_t_3;
17017   int __pyx_t_4;
17018   __Pyx_TraceDeclarations
17019   __Pyx_RefNannySetupContext("query_start");
17020   __Pyx_TraceCall("query_start", __pyx_f[0], 1847);
17021
17022   /* "csamtools.pyx":1850
17023  *     cdef uint32_t * cigar_p, op
17024  *     cdef uint32_t k
17025  *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
17026  * 
17027  *     if src.core.n_cigar:
17028  */
17029   __pyx_v_start_offset = 0;
17030
17031   /* "csamtools.pyx":1852
17032  *     cdef uint32_t start_offset = 0
17033  * 
17034  *     if src.core.n_cigar:             # <<<<<<<<<<<<<<
17035  *         cigar_p = bam1_cigar(src);
17036  *         for k from 0 <= k < src.core.n_cigar:
17037  */
17038   if (__pyx_v_src->core.n_cigar) {
17039
17040     /* "csamtools.pyx":1853
17041  * 
17042  *     if src.core.n_cigar:
17043  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
17044  *         for k from 0 <= k < src.core.n_cigar:
17045  *             op = cigar_p[k] & BAM_CIGAR_MASK
17046  */
17047     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
17048
17049     /* "csamtools.pyx":1854
17050  *     if src.core.n_cigar:
17051  *         cigar_p = bam1_cigar(src);
17052  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
17053  *             op = cigar_p[k] & BAM_CIGAR_MASK
17054  *             if op==BAM_CHARD_CLIP:
17055  */
17056     __pyx_t_1 = __pyx_v_src->core.n_cigar;
17057     for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_1; __pyx_v_k++) {
17058
17059       /* "csamtools.pyx":1855
17060  *         cigar_p = bam1_cigar(src);
17061  *         for k from 0 <= k < src.core.n_cigar:
17062  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
17063  *             if op==BAM_CHARD_CLIP:
17064  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
17065  */
17066       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
17067
17068       /* "csamtools.pyx":1860
17069  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17070  *                     return -1
17071  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
17072  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
17073  *             else:
17074  */
17075       switch (__pyx_v_op) {
17076
17077         /* "csamtools.pyx":1856
17078  *         for k from 0 <= k < src.core.n_cigar:
17079  *             op = cigar_p[k] & BAM_CIGAR_MASK
17080  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
17081  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
17082  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17083  */
17084         case 5:
17085
17086         /* "csamtools.pyx":1857
17087  *             op = cigar_p[k] & BAM_CIGAR_MASK
17088  *             if op==BAM_CHARD_CLIP:
17089  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
17090  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17091  *                     return -1
17092  */
17093         __pyx_t_2 = (__pyx_v_start_offset != 0);
17094         if (__pyx_t_2) {
17095           __pyx_t_3 = (__pyx_v_start_offset != __pyx_v_src->core.l_qseq);
17096           __pyx_t_4 = __pyx_t_3;
17097         } else {
17098           __pyx_t_4 = __pyx_t_2;
17099         }
17100         if (__pyx_t_4) {
17101
17102           /* "csamtools.pyx":1858
17103  *             if op==BAM_CHARD_CLIP:
17104  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
17105  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
17106  *                     return -1
17107  *             elif op==BAM_CSOFT_CLIP:
17108  */
17109           PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_119);
17110
17111           /* "csamtools.pyx":1859
17112  *                 if start_offset!=0 and start_offset!=src.core.l_qseq:
17113  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17114  *                     return -1             # <<<<<<<<<<<<<<
17115  *             elif op==BAM_CSOFT_CLIP:
17116  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
17117  */
17118           __pyx_r = -1;
17119           goto __pyx_L0;
17120           goto __pyx_L6;
17121         }
17122         __pyx_L6:;
17123         break;
17124
17125         /* "csamtools.pyx":1860
17126  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17127  *                     return -1
17128  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
17129  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
17130  *             else:
17131  */
17132         case 4:
17133
17134         /* "csamtools.pyx":1861
17135  *                     return -1
17136  *             elif op==BAM_CSOFT_CLIP:
17137  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
17138  *             else:
17139  *                 break
17140  */
17141         __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> 4));
17142         break;
17143         default:
17144
17145         /* "csamtools.pyx":1863
17146  *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
17147  *             else:
17148  *                 break             # <<<<<<<<<<<<<<
17149  * 
17150  *     return start_offset
17151  */
17152         goto __pyx_L5_break;
17153         break;
17154       }
17155     }
17156     __pyx_L5_break:;
17157     goto __pyx_L3;
17158   }
17159   __pyx_L3:;
17160
17161   /* "csamtools.pyx":1865
17162  *                 break
17163  * 
17164  *     return start_offset             # <<<<<<<<<<<<<<
17165  * 
17166  * ##-------------------------------------------------------------------
17167  */
17168   __pyx_r = __pyx_v_start_offset;
17169   goto __pyx_L0;
17170
17171   __pyx_r = 0;
17172   __pyx_L0:;
17173   __Pyx_TraceReturn(Py_None);
17174   __Pyx_RefNannyFinishContext();
17175   return __pyx_r;
17176 }
17177
17178 /* "csamtools.pyx":1870
17179  * ##-------------------------------------------------------------------
17180  * ##-------------------------------------------------------------------
17181  * cdef inline int32_t query_end(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
17182  *     cdef uint32_t * cigar_p, op
17183  *     cdef uint32_t k
17184  */
17185
17186 static CYTHON_INLINE int32_t __pyx_f_9csamtools_query_end(bam1_t *__pyx_v_src) {
17187   uint32_t *__pyx_v_cigar_p;
17188   uint32_t __pyx_v_op;
17189   uint32_t __pyx_v_k;
17190   uint32_t __pyx_v_end_offset;
17191   int32_t __pyx_r;
17192   int __pyx_t_1;
17193   int __pyx_t_2;
17194   int __pyx_t_3;
17195   __Pyx_TraceDeclarations
17196   __Pyx_RefNannySetupContext("query_end");
17197   __Pyx_TraceCall("query_end", __pyx_f[0], 1870);
17198
17199   /* "csamtools.pyx":1873
17200  *     cdef uint32_t * cigar_p, op
17201  *     cdef uint32_t k
17202  *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
17203  * 
17204  *     if src.core.n_cigar>1:
17205  */
17206   __pyx_v_end_offset = __pyx_v_src->core.l_qseq;
17207
17208   /* "csamtools.pyx":1875
17209  *     cdef uint32_t end_offset = src.core.l_qseq
17210  * 
17211  *     if src.core.n_cigar>1:             # <<<<<<<<<<<<<<
17212  *         cigar_p = bam1_cigar(src);
17213  *         for k from src.core.n_cigar > k >= 1:
17214  */
17215   __pyx_t_1 = (__pyx_v_src->core.n_cigar > 1);
17216   if (__pyx_t_1) {
17217
17218     /* "csamtools.pyx":1876
17219  * 
17220  *     if src.core.n_cigar>1:
17221  *         cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
17222  *         for k from src.core.n_cigar > k >= 1:
17223  *             op = cigar_p[k] & BAM_CIGAR_MASK
17224  */
17225     __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
17226
17227     /* "csamtools.pyx":1877
17228  *     if src.core.n_cigar>1:
17229  *         cigar_p = bam1_cigar(src);
17230  *         for k from src.core.n_cigar > k >= 1:             # <<<<<<<<<<<<<<
17231  *             op = cigar_p[k] & BAM_CIGAR_MASK
17232  *             if op==BAM_CHARD_CLIP:
17233  */
17234     for (__pyx_v_k = __pyx_v_src->core.n_cigar-1; __pyx_v_k >= 1; __pyx_v_k--) {
17235
17236       /* "csamtools.pyx":1878
17237  *         cigar_p = bam1_cigar(src);
17238  *         for k from src.core.n_cigar > k >= 1:
17239  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
17240  *             if op==BAM_CHARD_CLIP:
17241  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
17242  */
17243       __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
17244
17245       /* "csamtools.pyx":1883
17246  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17247  *                     return -1
17248  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
17249  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
17250  *             else:
17251  */
17252       switch (__pyx_v_op) {
17253
17254         /* "csamtools.pyx":1879
17255  *         for k from src.core.n_cigar > k >= 1:
17256  *             op = cigar_p[k] & BAM_CIGAR_MASK
17257  *             if op==BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
17258  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
17259  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17260  */
17261         case 5:
17262
17263         /* "csamtools.pyx":1880
17264  *             op = cigar_p[k] & BAM_CIGAR_MASK
17265  *             if op==BAM_CHARD_CLIP:
17266  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:             # <<<<<<<<<<<<<<
17267  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17268  *                     return -1
17269  */
17270         __pyx_t_1 = (__pyx_v_end_offset != 0);
17271         if (__pyx_t_1) {
17272           __pyx_t_2 = (__pyx_v_end_offset != __pyx_v_src->core.l_qseq);
17273           __pyx_t_3 = __pyx_t_2;
17274         } else {
17275           __pyx_t_3 = __pyx_t_1;
17276         }
17277         if (__pyx_t_3) {
17278
17279           /* "csamtools.pyx":1881
17280  *             if op==BAM_CHARD_CLIP:
17281  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
17282  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
17283  *                     return -1
17284  *             elif op==BAM_CSOFT_CLIP:
17285  */
17286           PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_119);
17287
17288           /* "csamtools.pyx":1882
17289  *                 if end_offset!=0 and end_offset!=src.core.l_qseq:
17290  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17291  *                     return -1             # <<<<<<<<<<<<<<
17292  *             elif op==BAM_CSOFT_CLIP:
17293  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
17294  */
17295           __pyx_r = -1;
17296           goto __pyx_L0;
17297           goto __pyx_L6;
17298         }
17299         __pyx_L6:;
17300         break;
17301
17302         /* "csamtools.pyx":1883
17303  *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
17304  *                     return -1
17305  *             elif op==BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
17306  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
17307  *             else:
17308  */
17309         case 4:
17310
17311         /* "csamtools.pyx":1884
17312  *                     return -1
17313  *             elif op==BAM_CSOFT_CLIP:
17314  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
17315  *             else:
17316  *                 break
17317  */
17318         __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> 4));
17319         break;
17320         default:
17321
17322         /* "csamtools.pyx":1886
17323  *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
17324  *             else:
17325  *                 break             # <<<<<<<<<<<<<<
17326  * 
17327  *     if end_offset==0:
17328  */
17329         goto __pyx_L5_break;
17330         break;
17331       }
17332     }
17333     __pyx_L5_break:;
17334     goto __pyx_L3;
17335   }
17336   __pyx_L3:;
17337
17338   /* "csamtools.pyx":1888
17339  *                 break
17340  * 
17341  *     if end_offset==0:             # <<<<<<<<<<<<<<
17342  *         end_offset = src.core.l_qseq
17343  * 
17344  */
17345   __pyx_t_3 = (__pyx_v_end_offset == 0);
17346   if (__pyx_t_3) {
17347
17348     /* "csamtools.pyx":1889
17349  * 
17350  *     if end_offset==0:
17351  *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
17352  * 
17353  *     return end_offset
17354  */
17355     __pyx_v_end_offset = __pyx_v_src->core.l_qseq;
17356     goto __pyx_L7;
17357   }
17358   __pyx_L7:;
17359
17360   /* "csamtools.pyx":1891
17361  *         end_offset = src.core.l_qseq
17362  * 
17363  *     return end_offset             # <<<<<<<<<<<<<<
17364  * 
17365  * 
17366  */
17367   __pyx_r = __pyx_v_end_offset;
17368   goto __pyx_L0;
17369
17370   __pyx_r = 0;
17371   __pyx_L0:;
17372   __Pyx_TraceReturn(Py_None);
17373   __Pyx_RefNannyFinishContext();
17374   return __pyx_r;
17375 }
17376
17377 /* "csamtools.pyx":1894
17378  * 
17379  * 
17380  * cdef inline object get_seq_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
17381  *     cdef uint8_t * p
17382  *     cdef uint32_t k
17383  */
17384
17385 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) {
17386   uint8_t *__pyx_v_p;
17387   uint32_t __pyx_v_k;
17388   char *__pyx_v_s;
17389   PyObject *__pyx_v_seq;
17390   PyObject *__pyx_r = NULL;
17391   int __pyx_t_1;
17392   PyObject *__pyx_t_2 = NULL;
17393   uint32_t __pyx_t_3;
17394   __Pyx_TraceDeclarations
17395   __Pyx_RefNannySetupContext("get_seq_range");
17396   __Pyx_TraceCall("get_seq_range", __pyx_f[0], 1894);
17397   __pyx_v_seq = Py_None; __Pyx_INCREF(Py_None);
17398
17399   /* "csamtools.pyx":1899
17400  *     cdef char * s
17401  * 
17402  *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
17403  *         return None
17404  * 
17405  */
17406   __pyx_t_1 = (!__pyx_v_src->core.l_qseq);
17407   if (__pyx_t_1) {
17408
17409     /* "csamtools.pyx":1900
17410  * 
17411  *     if not src.core.l_qseq:
17412  *         return None             # <<<<<<<<<<<<<<
17413  * 
17414  *     seq = PyString_FromStringAndSize(NULL, end-start)
17415  */
17416     __Pyx_XDECREF(__pyx_r);
17417     __Pyx_INCREF(Py_None);
17418     __pyx_r = Py_None;
17419     goto __pyx_L0;
17420     goto __pyx_L3;
17421   }
17422   __pyx_L3:;
17423
17424   /* "csamtools.pyx":1902
17425  *         return None
17426  * 
17427  *     seq = PyString_FromStringAndSize(NULL, end-start)             # <<<<<<<<<<<<<<
17428  *     s   = PyString_AS_STRING(seq)
17429  *     p   = bam1_seq(src)
17430  */
17431   __pyx_t_2 = PyString_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17432   __Pyx_GOTREF(__pyx_t_2);
17433   __Pyx_DECREF(__pyx_v_seq);
17434   __pyx_v_seq = __pyx_t_2;
17435   __pyx_t_2 = 0;
17436
17437   /* "csamtools.pyx":1903
17438  * 
17439  *     seq = PyString_FromStringAndSize(NULL, end-start)
17440  *     s   = PyString_AS_STRING(seq)             # <<<<<<<<<<<<<<
17441  *     p   = bam1_seq(src)
17442  * 
17443  */
17444   __pyx_v_s = PyString_AS_STRING(__pyx_v_seq);
17445
17446   /* "csamtools.pyx":1904
17447  *     seq = PyString_FromStringAndSize(NULL, end-start)
17448  *     s   = PyString_AS_STRING(seq)
17449  *     p   = bam1_seq(src)             # <<<<<<<<<<<<<<
17450  * 
17451  *     for k from start <= k < end:
17452  */
17453   __pyx_v_p = bam1_seq(__pyx_v_src);
17454
17455   /* "csamtools.pyx":1906
17456  *     p   = bam1_seq(src)
17457  * 
17458  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
17459  *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
17460  *         # note: do not use string literal as it will be a python string
17461  */
17462   __pyx_t_3 = __pyx_v_end;
17463   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
17464
17465     /* "csamtools.pyx":1909
17466  *         # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
17467  *         # note: do not use string literal as it will be a python string
17468  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
17469  * 
17470  *     return seq
17471  */
17472     (__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)]);
17473   }
17474
17475   /* "csamtools.pyx":1911
17476  *         s[k-start] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]
17477  * 
17478  *     return seq             # <<<<<<<<<<<<<<
17479  * 
17480  * 
17481  */
17482   __Pyx_XDECREF(__pyx_r);
17483   __Pyx_INCREF(__pyx_v_seq);
17484   __pyx_r = __pyx_v_seq;
17485   goto __pyx_L0;
17486
17487   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17488   goto __pyx_L0;
17489   __pyx_L1_error:;
17490   __Pyx_XDECREF(__pyx_t_2);
17491   __Pyx_AddTraceback("csamtools.get_seq_range");
17492   __pyx_r = 0;
17493   __pyx_L0:;
17494   __Pyx_DECREF(__pyx_v_seq);
17495   __Pyx_XGIVEREF(__pyx_r);
17496   __Pyx_TraceReturn(__pyx_r);
17497   __Pyx_RefNannyFinishContext();
17498   return __pyx_r;
17499 }
17500
17501 /* "csamtools.pyx":1914
17502  * 
17503  * 
17504  * cdef inline object get_qual_range(bam1_t *src, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
17505  *     cdef uint8_t * p
17506  *     cdef uint32_t k
17507  */
17508
17509 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) {
17510   uint8_t *__pyx_v_p;
17511   uint32_t __pyx_v_k;
17512   char *__pyx_v_q;
17513   PyObject *__pyx_v_qual;
17514   PyObject *__pyx_r = NULL;
17515   int __pyx_t_1;
17516   PyObject *__pyx_t_2 = NULL;
17517   uint32_t __pyx_t_3;
17518   __Pyx_TraceDeclarations
17519   __Pyx_RefNannySetupContext("get_qual_range");
17520   __Pyx_TraceCall("get_qual_range", __pyx_f[0], 1914);
17521   __pyx_v_qual = Py_None; __Pyx_INCREF(Py_None);
17522
17523   /* "csamtools.pyx":1919
17524  *     cdef char * q
17525  * 
17526  *     p = bam1_qual(src)             # <<<<<<<<<<<<<<
17527  *     if p[0] == 0xff:
17528  *         return None
17529  */
17530   __pyx_v_p = bam1_qual(__pyx_v_src);
17531
17532   /* "csamtools.pyx":1920
17533  * 
17534  *     p = bam1_qual(src)
17535  *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
17536  *         return None
17537  * 
17538  */
17539   __pyx_t_1 = ((__pyx_v_p[0]) == 0xff);
17540   if (__pyx_t_1) {
17541
17542     /* "csamtools.pyx":1921
17543  *     p = bam1_qual(src)
17544  *     if p[0] == 0xff:
17545  *         return None             # <<<<<<<<<<<<<<
17546  * 
17547  *     qual = PyString_FromStringAndSize(NULL, end-start)
17548  */
17549     __Pyx_XDECREF(__pyx_r);
17550     __Pyx_INCREF(Py_None);
17551     __pyx_r = Py_None;
17552     goto __pyx_L0;
17553     goto __pyx_L3;
17554   }
17555   __pyx_L3:;
17556
17557   /* "csamtools.pyx":1923
17558  *         return None
17559  * 
17560  *     qual = PyString_FromStringAndSize(NULL, end-start)             # <<<<<<<<<<<<<<
17561  *     q    = PyString_AS_STRING(qual)
17562  * 
17563  */
17564   __pyx_t_2 = PyString_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17565   __Pyx_GOTREF(__pyx_t_2);
17566   __Pyx_DECREF(__pyx_v_qual);
17567   __pyx_v_qual = __pyx_t_2;
17568   __pyx_t_2 = 0;
17569
17570   /* "csamtools.pyx":1924
17571  * 
17572  *     qual = PyString_FromStringAndSize(NULL, end-start)
17573  *     q    = PyString_AS_STRING(qual)             # <<<<<<<<<<<<<<
17574  * 
17575  *     for k from start <= k < end:
17576  */
17577   __pyx_v_q = PyString_AS_STRING(__pyx_v_qual);
17578
17579   /* "csamtools.pyx":1926
17580  *     q    = PyString_AS_STRING(qual)
17581  * 
17582  *     for k from start <= k < end:             # <<<<<<<<<<<<<<
17583  *         ## equivalent to t[i] + 33 (see bam.c)
17584  *         q[k-start] = p[k] + 33
17585  */
17586   __pyx_t_3 = __pyx_v_end;
17587   for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
17588
17589     /* "csamtools.pyx":1928
17590  *     for k from start <= k < end:
17591  *         ## equivalent to t[i] + 33 (see bam.c)
17592  *         q[k-start] = p[k] + 33             # <<<<<<<<<<<<<<
17593  * 
17594  *     return qual
17595  */
17596     (__pyx_v_q[(__pyx_v_k - __pyx_v_start)]) = ((__pyx_v_p[__pyx_v_k]) + 33);
17597   }
17598
17599   /* "csamtools.pyx":1930
17600  *         q[k-start] = p[k] + 33
17601  * 
17602  *     return qual             # <<<<<<<<<<<<<<
17603  * 
17604  * cdef class AlignedRead:
17605  */
17606   __Pyx_XDECREF(__pyx_r);
17607   __Pyx_INCREF(__pyx_v_qual);
17608   __pyx_r = __pyx_v_qual;
17609   goto __pyx_L0;
17610
17611   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17612   goto __pyx_L0;
17613   __pyx_L1_error:;
17614   __Pyx_XDECREF(__pyx_t_2);
17615   __Pyx_AddTraceback("csamtools.get_qual_range");
17616   __pyx_r = 0;
17617   __pyx_L0:;
17618   __Pyx_DECREF(__pyx_v_qual);
17619   __Pyx_XGIVEREF(__pyx_r);
17620   __Pyx_TraceReturn(__pyx_r);
17621   __Pyx_RefNannyFinishContext();
17622   return __pyx_r;
17623 }
17624
17625 /* "csamtools.pyx":1955
17626  * 
17627  *     # Now only called when instances are created from Python
17628  *     def __init__(self):             # <<<<<<<<<<<<<<
17629  *         # see bam_init1
17630  *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )
17631  */
17632
17633 static int __pyx_pf_9csamtools_11AlignedRead___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
17634 static int __pyx_pf_9csamtools_11AlignedRead___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
17635   int __pyx_r;
17636   __Pyx_TraceDeclarations
17637   __Pyx_RefNannySetupContext("__init__");
17638   __Pyx_TraceCall("__init__", __pyx_f[0], 1955);
17639   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
17640     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
17641   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
17642
17643   /* "csamtools.pyx":1957
17644  *     def __init__(self):
17645  *         # see bam_init1
17646  *         self._delegate = <bam1_t*>calloc( 1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
17647  *         # allocate some memory
17648  *         # If size is 0, calloc does not return a pointer that can be passed to free()
17649  */
17650   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
17651
17652   /* "csamtools.pyx":1961
17653  *         # If size is 0, calloc does not return a pointer that can be passed to free()
17654  *         # so allocate 40 bytes for a new read
17655  *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
17656  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
17657  *         self._delegate.data_len = 0
17658  */
17659   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->m_data = 40;
17660
17661   /* "csamtools.pyx":1962
17662  *         # so allocate 40 bytes for a new read
17663  *         self._delegate.m_data = 40
17664  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )             # <<<<<<<<<<<<<<
17665  *         self._delegate.data_len = 0
17666  * 
17667  */
17668   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->data = ((uint8_t *)calloc(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->m_data, 1));
17669
17670   /* "csamtools.pyx":1963
17671  *         self._delegate.m_data = 40
17672  *         self._delegate.data = <uint8_t *>calloc( self._delegate.m_data, 1 )
17673  *         self._delegate.data_len = 0             # <<<<<<<<<<<<<<
17674  * 
17675  *     def __dealloc__(self):
17676  */
17677   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->data_len = 0;
17678
17679   __pyx_r = 0;
17680   __Pyx_TraceReturn(Py_None);
17681   __Pyx_RefNannyFinishContext();
17682   return __pyx_r;
17683 }
17684
17685 /* "csamtools.pyx":1965
17686  *         self._delegate.data_len = 0
17687  * 
17688  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
17689  *         bam_destroy1(self._delegate)
17690  * 
17691  */
17692
17693 static void __pyx_pf_9csamtools_11AlignedRead_1__dealloc__(PyObject *__pyx_v_self); /*proto*/
17694 static void __pyx_pf_9csamtools_11AlignedRead_1__dealloc__(PyObject *__pyx_v_self) {
17695   __Pyx_TraceDeclarations
17696   __Pyx_RefNannySetupContext("__dealloc__");
17697   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1965);
17698
17699   /* "csamtools.pyx":1966
17700  * 
17701  *     def __dealloc__(self):
17702  *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
17703  * 
17704  *     def __str__(self):
17705  */
17706   bam_destroy1(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate);
17707
17708   __Pyx_TraceReturn(Py_None);
17709   __Pyx_RefNannyFinishContext();
17710 }
17711
17712 /* "csamtools.pyx":1968
17713  *         bam_destroy1(self._delegate)
17714  * 
17715  *     def __str__(self):             # <<<<<<<<<<<<<<
17716  *         """return string representation of alignment.
17717  * 
17718  */
17719
17720 static PyObject *__pyx_pf_9csamtools_11AlignedRead_2__str__(PyObject *__pyx_v_self); /*proto*/
17721 static char __pyx_doc_9csamtools_11AlignedRead_2__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        ";
17722 struct wrapperbase __pyx_wrapperbase_9csamtools_11AlignedRead_2__str__;
17723 static PyObject *__pyx_pf_9csamtools_11AlignedRead_2__str__(PyObject *__pyx_v_self) {
17724   PyObject *__pyx_r = NULL;
17725   PyObject *__pyx_t_1 = NULL;
17726   PyObject *__pyx_t_2 = NULL;
17727   PyObject *__pyx_t_3 = NULL;
17728   PyObject *__pyx_t_4 = NULL;
17729   PyObject *__pyx_t_5 = NULL;
17730   PyObject *__pyx_t_6 = NULL;
17731   PyObject *__pyx_t_7 = NULL;
17732   PyObject *__pyx_t_8 = NULL;
17733   PyObject *__pyx_t_9 = NULL;
17734   PyObject *__pyx_t_10 = NULL;
17735   PyObject *__pyx_t_11 = NULL;
17736   PyObject *__pyx_t_12 = NULL;
17737   PyObject *__pyx_t_13 = NULL;
17738   PyObject *__pyx_t_14 = NULL;
17739   __Pyx_TraceDeclarations
17740   __Pyx_RefNannySetupContext("__str__");
17741   __Pyx_TraceCall("__str__", __pyx_f[0], 1968);
17742
17743   /* "csamtools.pyx":1980
17744  *         # sam-parsing is done in sam.c/bam_format1_core which
17745  *         # requires a valid header.
17746  *         return "\t".join(map(str, (self.qname,             # <<<<<<<<<<<<<<
17747  *                                    self.flag,
17748  *                                    self.rname,
17749  */
17750   __Pyx_XDECREF(__pyx_r);
17751   __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17752   __Pyx_GOTREF(__pyx_t_1);
17753   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17754   __Pyx_GOTREF(__pyx_t_2);
17755
17756   /* "csamtools.pyx":1981
17757  *         # requires a valid header.
17758  *         return "\t".join(map(str, (self.qname,
17759  *                                    self.flag,             # <<<<<<<<<<<<<<
17760  *                                    self.rname,
17761  *                                    self.pos,
17762  */
17763   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17764   __Pyx_GOTREF(__pyx_t_3);
17765
17766   /* "csamtools.pyx":1982
17767  *         return "\t".join(map(str, (self.qname,
17768  *                                    self.flag,
17769  *                                    self.rname,             # <<<<<<<<<<<<<<
17770  *                                    self.pos,
17771  *                                    self.mapq,
17772  */
17773   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__rname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1982; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17774   __Pyx_GOTREF(__pyx_t_4);
17775
17776   /* "csamtools.pyx":1983
17777  *                                    self.flag,
17778  *                                    self.rname,
17779  *                                    self.pos,             # <<<<<<<<<<<<<<
17780  *                                    self.mapq,
17781  *                                    self.cigar,
17782  */
17783   __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17784   __Pyx_GOTREF(__pyx_t_5);
17785
17786   /* "csamtools.pyx":1984
17787  *                                    self.rname,
17788  *                                    self.pos,
17789  *                                    self.mapq,             # <<<<<<<<<<<<<<
17790  *                                    self.cigar,
17791  *                                    self.mrnm,
17792  */
17793   __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__mapq); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17794   __Pyx_GOTREF(__pyx_t_6);
17795
17796   /* "csamtools.pyx":1985
17797  *                                    self.pos,
17798  *                                    self.mapq,
17799  *                                    self.cigar,             # <<<<<<<<<<<<<<
17800  *                                    self.mrnm,
17801  *                                    self.mpos,
17802  */
17803   __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__cigar); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17804   __Pyx_GOTREF(__pyx_t_7);
17805
17806   /* "csamtools.pyx":1986
17807  *                                    self.mapq,
17808  *                                    self.cigar,
17809  *                                    self.mrnm,             # <<<<<<<<<<<<<<
17810  *                                    self.mpos,
17811  *                                    self.rlen,
17812  */
17813   __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__mrnm); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17814   __Pyx_GOTREF(__pyx_t_8);
17815
17816   /* "csamtools.pyx":1987
17817  *                                    self.cigar,
17818  *                                    self.mrnm,
17819  *                                    self.mpos,             # <<<<<<<<<<<<<<
17820  *                                    self.rlen,
17821  *                                    self.seq,
17822  */
17823   __pyx_t_9 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__mpos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17824   __Pyx_GOTREF(__pyx_t_9);
17825
17826   /* "csamtools.pyx":1988
17827  *                                    self.mrnm,
17828  *                                    self.mpos,
17829  *                                    self.rlen,             # <<<<<<<<<<<<<<
17830  *                                    self.seq,
17831  *                                    self.qual,
17832  */
17833   __pyx_t_10 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__rlen); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17834   __Pyx_GOTREF(__pyx_t_10);
17835
17836   /* "csamtools.pyx":1989
17837  *                                    self.mpos,
17838  *                                    self.rlen,
17839  *                                    self.seq,             # <<<<<<<<<<<<<<
17840  *                                    self.qual,
17841  *                                    self.tags )))
17842  */
17843   __pyx_t_11 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__seq); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17844   __Pyx_GOTREF(__pyx_t_11);
17845
17846   /* "csamtools.pyx":1990
17847  *                                    self.rlen,
17848  *                                    self.seq,
17849  *                                    self.qual,             # <<<<<<<<<<<<<<
17850  *                                    self.tags )))
17851  * 
17852  */
17853   __pyx_t_12 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qual); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17854   __Pyx_GOTREF(__pyx_t_12);
17855
17856   /* "csamtools.pyx":1991
17857  *                                    self.seq,
17858  *                                    self.qual,
17859  *                                    self.tags )))             # <<<<<<<<<<<<<<
17860  * 
17861  *     def compare(self, AlignedRead other):
17862  */
17863   __pyx_t_13 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tags); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1991; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17864   __Pyx_GOTREF(__pyx_t_13);
17865   __pyx_t_14 = PyTuple_New(12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17866   __Pyx_GOTREF(((PyObject *)__pyx_t_14));
17867   PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_2);
17868   __Pyx_GIVEREF(__pyx_t_2);
17869   PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_3);
17870   __Pyx_GIVEREF(__pyx_t_3);
17871   PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_4);
17872   __Pyx_GIVEREF(__pyx_t_4);
17873   PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_5);
17874   __Pyx_GIVEREF(__pyx_t_5);
17875   PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_t_6);
17876   __Pyx_GIVEREF(__pyx_t_6);
17877   PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_7);
17878   __Pyx_GIVEREF(__pyx_t_7);
17879   PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_t_8);
17880   __Pyx_GIVEREF(__pyx_t_8);
17881   PyTuple_SET_ITEM(__pyx_t_14, 7, __pyx_t_9);
17882   __Pyx_GIVEREF(__pyx_t_9);
17883   PyTuple_SET_ITEM(__pyx_t_14, 8, __pyx_t_10);
17884   __Pyx_GIVEREF(__pyx_t_10);
17885   PyTuple_SET_ITEM(__pyx_t_14, 9, __pyx_t_11);
17886   __Pyx_GIVEREF(__pyx_t_11);
17887   PyTuple_SET_ITEM(__pyx_t_14, 10, __pyx_t_12);
17888   __Pyx_GIVEREF(__pyx_t_12);
17889   PyTuple_SET_ITEM(__pyx_t_14, 11, __pyx_t_13);
17890   __Pyx_GIVEREF(__pyx_t_13);
17891   __pyx_t_2 = 0;
17892   __pyx_t_3 = 0;
17893   __pyx_t_4 = 0;
17894   __pyx_t_5 = 0;
17895   __pyx_t_6 = 0;
17896   __pyx_t_7 = 0;
17897   __pyx_t_8 = 0;
17898   __pyx_t_9 = 0;
17899   __pyx_t_10 = 0;
17900   __pyx_t_11 = 0;
17901   __pyx_t_12 = 0;
17902   __pyx_t_13 = 0;
17903   __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17904   __Pyx_GOTREF(((PyObject *)__pyx_t_13));
17905   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
17906   PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
17907   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
17908   PyTuple_SET_ITEM(__pyx_t_13, 1, ((PyObject *)__pyx_t_14));
17909   __Pyx_GIVEREF(((PyObject *)__pyx_t_14));
17910   __pyx_t_14 = 0;
17911   __pyx_t_14 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17912   __Pyx_GOTREF(__pyx_t_14);
17913   __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
17914   __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17915   __Pyx_GOTREF(((PyObject *)__pyx_t_13));
17916   PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14);
17917   __Pyx_GIVEREF(__pyx_t_14);
17918   __pyx_t_14 = 0;
17919   __pyx_t_14 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17920   __Pyx_GOTREF(__pyx_t_14);
17921   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
17922   __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0;
17923   __pyx_r = __pyx_t_14;
17924   __pyx_t_14 = 0;
17925   goto __pyx_L0;
17926
17927   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
17928   goto __pyx_L0;
17929   __pyx_L1_error:;
17930   __Pyx_XDECREF(__pyx_t_1);
17931   __Pyx_XDECREF(__pyx_t_2);
17932   __Pyx_XDECREF(__pyx_t_3);
17933   __Pyx_XDECREF(__pyx_t_4);
17934   __Pyx_XDECREF(__pyx_t_5);
17935   __Pyx_XDECREF(__pyx_t_6);
17936   __Pyx_XDECREF(__pyx_t_7);
17937   __Pyx_XDECREF(__pyx_t_8);
17938   __Pyx_XDECREF(__pyx_t_9);
17939   __Pyx_XDECREF(__pyx_t_10);
17940   __Pyx_XDECREF(__pyx_t_11);
17941   __Pyx_XDECREF(__pyx_t_12);
17942   __Pyx_XDECREF(__pyx_t_13);
17943   __Pyx_XDECREF(__pyx_t_14);
17944   __Pyx_AddTraceback("csamtools.AlignedRead.__str__");
17945   __pyx_r = NULL;
17946   __pyx_L0:;
17947   __Pyx_XGIVEREF(__pyx_r);
17948   __Pyx_TraceReturn(__pyx_r);
17949   __Pyx_RefNannyFinishContext();
17950   return __pyx_r;
17951 }
17952
17953 /* "csamtools.pyx":1993
17954  *                                    self.tags )))
17955  * 
17956  *     def compare(self, AlignedRead other):             # <<<<<<<<<<<<<<
17957  *         '''return -1,0,1, if contents in this are binary <,=,> to *other*'''
17958  * 
17959  */
17960
17961 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
17962 static char __pyx_doc_9csamtools_11AlignedRead_3compare[] = "AlignedRead.compare(self, AlignedRead other)\nreturn -1,0,1, if contents in this are binary <,=,> to *other*";
17963 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
17964   int __pyx_v_retval;
17965   bam1_t *__pyx_v_t;
17966   bam1_t *__pyx_v_o;
17967   PyObject *__pyx_r = NULL;
17968   int __pyx_t_1;
17969   PyObject *__pyx_t_2 = NULL;
17970   PyObject *__pyx_t_3 = NULL;
17971   PyObject *__pyx_t_4 = NULL;
17972   int __pyx_t_5;
17973   __Pyx_TraceDeclarations
17974   __Pyx_RefNannySetupContext("compare");
17975   __Pyx_TraceCall("compare", __pyx_f[0], 1993);
17976   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_9csamtools_AlignedRead, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
17977
17978   /* "csamtools.pyx":1999
17979  *         cdef bam1_t *t, *o
17980  * 
17981  *         t = self._delegate             # <<<<<<<<<<<<<<
17982  *         o = other._delegate
17983  * 
17984  */
17985   __pyx_v_t = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
17986
17987   /* "csamtools.pyx":2000
17988  * 
17989  *         t = self._delegate
17990  *         o = other._delegate             # <<<<<<<<<<<<<<
17991  * 
17992  *         # uncomment for debugging purposes
17993  */
17994   __pyx_v_o = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_other)->_delegate;
17995
17996   /* "csamtools.pyx":2012
17997  * 
17998  *         # Fast-path test for object identity
17999  *         if t==o:             # <<<<<<<<<<<<<<
18000  *             return 0
18001  * 
18002  */
18003   __pyx_t_1 = (__pyx_v_t == __pyx_v_o);
18004   if (__pyx_t_1) {
18005
18006     /* "csamtools.pyx":2013
18007  *         # Fast-path test for object identity
18008  *         if t==o:
18009  *             return 0             # <<<<<<<<<<<<<<
18010  * 
18011  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
18012  */
18013     __Pyx_XDECREF(__pyx_r);
18014     __Pyx_INCREF(__pyx_int_0);
18015     __pyx_r = __pyx_int_0;
18016     goto __pyx_L0;
18017     goto __pyx_L5;
18018   }
18019   __pyx_L5:;
18020
18021   /* "csamtools.pyx":2015
18022  *             return 0
18023  * 
18024  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
18025  * 
18026  *         if retval: return retval
18027  */
18028   __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));
18029
18030   /* "csamtools.pyx":2017
18031  *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
18032  * 
18033  *         if retval: return retval             # <<<<<<<<<<<<<<
18034  *         retval = cmp(t.data_len, o.data_len)
18035  *         if retval: return retval
18036  */
18037   if (__pyx_v_retval) {
18038     __Pyx_XDECREF(__pyx_r);
18039     __pyx_t_2 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2017; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18040     __Pyx_GOTREF(__pyx_t_2);
18041     __pyx_r = __pyx_t_2;
18042     __pyx_t_2 = 0;
18043     goto __pyx_L0;
18044     goto __pyx_L6;
18045   }
18046   __pyx_L6:;
18047
18048   /* "csamtools.pyx":2018
18049  * 
18050  *         if retval: return retval
18051  *         retval = cmp(t.data_len, o.data_len)             # <<<<<<<<<<<<<<
18052  *         if retval: return retval
18053  *         return memcmp(t.data, o.data, t.data_len)
18054  */
18055   __pyx_t_2 = PyInt_FromLong(__pyx_v_t->data_len); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18056   __Pyx_GOTREF(__pyx_t_2);
18057   __pyx_t_3 = PyInt_FromLong(__pyx_v_o->data_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18058   __Pyx_GOTREF(__pyx_t_3);
18059   __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18060   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
18061   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
18062   __Pyx_GIVEREF(__pyx_t_2);
18063   PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
18064   __Pyx_GIVEREF(__pyx_t_3);
18065   __pyx_t_2 = 0;
18066   __pyx_t_3 = 0;
18067   __pyx_t_3 = PyObject_Call(__pyx_builtin_cmp, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18068   __Pyx_GOTREF(__pyx_t_3);
18069   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
18070   __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18071   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
18072   __pyx_v_retval = __pyx_t_5;
18073
18074   /* "csamtools.pyx":2019
18075  *         if retval: return retval
18076  *         retval = cmp(t.data_len, o.data_len)
18077  *         if retval: return retval             # <<<<<<<<<<<<<<
18078  *         return memcmp(t.data, o.data, t.data_len)
18079  * 
18080  */
18081   if (__pyx_v_retval) {
18082     __Pyx_XDECREF(__pyx_r);
18083     __pyx_t_3 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2019; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18084     __Pyx_GOTREF(__pyx_t_3);
18085     __pyx_r = __pyx_t_3;
18086     __pyx_t_3 = 0;
18087     goto __pyx_L0;
18088     goto __pyx_L7;
18089   }
18090   __pyx_L7:;
18091
18092   /* "csamtools.pyx":2020
18093  *         retval = cmp(t.data_len, o.data_len)
18094  *         if retval: return retval
18095  *         return memcmp(t.data, o.data, t.data_len)             # <<<<<<<<<<<<<<
18096  * 
18097  *     # Disabled so long as __cmp__ is a special method
18098  */
18099   __Pyx_XDECREF(__pyx_r);
18100   __pyx_t_3 = PyInt_FromLong(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->data_len)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18101   __Pyx_GOTREF(__pyx_t_3);
18102   __pyx_r = __pyx_t_3;
18103   __pyx_t_3 = 0;
18104   goto __pyx_L0;
18105
18106   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18107   goto __pyx_L0;
18108   __pyx_L1_error:;
18109   __Pyx_XDECREF(__pyx_t_2);
18110   __Pyx_XDECREF(__pyx_t_3);
18111   __Pyx_XDECREF(__pyx_t_4);
18112   __Pyx_AddTraceback("csamtools.AlignedRead.compare");
18113   __pyx_r = NULL;
18114   __pyx_L0:;
18115   __Pyx_XGIVEREF(__pyx_r);
18116   __Pyx_TraceReturn(__pyx_r);
18117   __Pyx_RefNannyFinishContext();
18118   return __pyx_r;
18119 }
18120
18121 /* "csamtools.pyx":2023
18122  * 
18123  *     # Disabled so long as __cmp__ is a special method
18124  *     def __hash__(self):             # <<<<<<<<<<<<<<
18125  *         return _Py_HashPointer(<void *>self)
18126  * 
18127  */
18128
18129 static long __pyx_pf_9csamtools_11AlignedRead_4__hash__(PyObject *__pyx_v_self); /*proto*/
18130 static long __pyx_pf_9csamtools_11AlignedRead_4__hash__(PyObject *__pyx_v_self) {
18131   long __pyx_r;
18132   __Pyx_TraceDeclarations
18133   __Pyx_RefNannySetupContext("__hash__");
18134   __Pyx_TraceCall("__hash__", __pyx_f[0], 2023);
18135
18136   /* "csamtools.pyx":2024
18137  *     # Disabled so long as __cmp__ is a special method
18138  *     def __hash__(self):
18139  *         return _Py_HashPointer(<void *>self)             # <<<<<<<<<<<<<<
18140  * 
18141  *     property qname:
18142  */
18143   __pyx_r = _Py_HashPointer(((void *)__pyx_v_self));
18144   goto __pyx_L0;
18145
18146   __pyx_r = 0;
18147   __pyx_L0:;
18148   if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
18149   __Pyx_TraceReturn(Py_None);
18150   __Pyx_RefNannyFinishContext();
18151   return __pyx_r;
18152 }
18153
18154 /* "csamtools.pyx":2028
18155  *     property qname:
18156  *         """the query name (None if not present)"""
18157  *         def __get__(self):             # <<<<<<<<<<<<<<
18158  *             cdef bam1_t * src
18159  *             src = self._delegate
18160  */
18161
18162 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qname___get__(PyObject *__pyx_v_self); /*proto*/
18163 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qname___get__(PyObject *__pyx_v_self) {
18164   bam1_t *__pyx_v_src;
18165   PyObject *__pyx_r = NULL;
18166   int __pyx_t_1;
18167   PyObject *__pyx_t_2 = NULL;
18168   __Pyx_TraceDeclarations
18169   __Pyx_RefNannySetupContext("__get__");
18170   __Pyx_TraceCall("__get__", __pyx_f[0], 2028);
18171
18172   /* "csamtools.pyx":2030
18173  *         def __get__(self):
18174  *             cdef bam1_t * src
18175  *             src = self._delegate             # <<<<<<<<<<<<<<
18176  *             if src.core.l_qname == 0: return None
18177  *             return <char *>bam1_qname( src )
18178  */
18179   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18180
18181   /* "csamtools.pyx":2031
18182  *             cdef bam1_t * src
18183  *             src = self._delegate
18184  *             if src.core.l_qname == 0: return None             # <<<<<<<<<<<<<<
18185  *             return <char *>bam1_qname( src )
18186  * 
18187  */
18188   __pyx_t_1 = (__pyx_v_src->core.l_qname == 0);
18189   if (__pyx_t_1) {
18190     __Pyx_XDECREF(__pyx_r);
18191     __Pyx_INCREF(Py_None);
18192     __pyx_r = Py_None;
18193     goto __pyx_L0;
18194     goto __pyx_L5;
18195   }
18196   __pyx_L5:;
18197
18198   /* "csamtools.pyx":2032
18199  *             src = self._delegate
18200  *             if src.core.l_qname == 0: return None
18201  *             return <char *>bam1_qname( src )             # <<<<<<<<<<<<<<
18202  * 
18203  *         def __set__(self, qname ):
18204  */
18205   __Pyx_XDECREF(__pyx_r);
18206   __pyx_t_2 = PyBytes_FromString(bam1_qname(__pyx_v_src)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18207   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
18208   __pyx_r = ((PyObject *)__pyx_t_2);
18209   __pyx_t_2 = 0;
18210   goto __pyx_L0;
18211
18212   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18213   goto __pyx_L0;
18214   __pyx_L1_error:;
18215   __Pyx_XDECREF(__pyx_t_2);
18216   __Pyx_AddTraceback("csamtools.AlignedRead.qname.__get__");
18217   __pyx_r = NULL;
18218   __pyx_L0:;
18219   __Pyx_XGIVEREF(__pyx_r);
18220   __Pyx_TraceReturn(__pyx_r);
18221   __Pyx_RefNannyFinishContext();
18222   return __pyx_r;
18223 }
18224
18225 /* "csamtools.pyx":2034
18226  *             return <char *>bam1_qname( src )
18227  * 
18228  *         def __set__(self, qname ):             # <<<<<<<<<<<<<<
18229  *             if qname == None or len(qname) == 0: return
18230  *             cdef bam1_t * src
18231  */
18232
18233 static int __pyx_pf_9csamtools_11AlignedRead_5qname_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
18234 static int __pyx_pf_9csamtools_11AlignedRead_5qname_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
18235   bam1_t *__pyx_v_src;
18236   int __pyx_v_l;
18237   char *__pyx_v_p;
18238   int __pyx_r;
18239   PyObject *__pyx_t_1 = NULL;
18240   int __pyx_t_2;
18241   Py_ssize_t __pyx_t_3;
18242   int __pyx_t_4;
18243   int __pyx_t_5;
18244   char *__pyx_t_6;
18245   __Pyx_TraceDeclarations
18246   __Pyx_RefNannySetupContext("__set__");
18247   __Pyx_TraceCall("__set__", __pyx_f[0], 2034);
18248
18249   /* "csamtools.pyx":2035
18250  * 
18251  *         def __set__(self, qname ):
18252  *             if qname == None or len(qname) == 0: return             # <<<<<<<<<<<<<<
18253  *             cdef bam1_t * src
18254  *             cdef int l
18255  */
18256   __pyx_t_1 = PyObject_RichCompare(__pyx_v_qname, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18257   __Pyx_GOTREF(__pyx_t_1);
18258   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18259   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
18260   if (!__pyx_t_2) {
18261     __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18262     __pyx_t_4 = (__pyx_t_3 == 0);
18263     __pyx_t_5 = __pyx_t_4;
18264   } else {
18265     __pyx_t_5 = __pyx_t_2;
18266   }
18267   if (__pyx_t_5) {
18268     __pyx_r = 0;
18269     goto __pyx_L0;
18270     goto __pyx_L5;
18271   }
18272   __pyx_L5:;
18273
18274   /* "csamtools.pyx":2040
18275  *             cdef char * p
18276  * 
18277  *             src = self._delegate             # <<<<<<<<<<<<<<
18278  *             p = bam1_qname( src )
18279  * 
18280  */
18281   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18282
18283   /* "csamtools.pyx":2041
18284  * 
18285  *             src = self._delegate
18286  *             p = bam1_qname( src )             # <<<<<<<<<<<<<<
18287  * 
18288  *             # the qname is \0 terminated
18289  */
18290   __pyx_v_p = bam1_qname(__pyx_v_src);
18291
18292   /* "csamtools.pyx":2044
18293  * 
18294  *             # the qname is \0 terminated
18295  *             l = len(qname) + 1             # <<<<<<<<<<<<<<
18296  *             pysam_bam_update( src,
18297  *                               src.core.l_qname,
18298  */
18299   __pyx_t_3 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18300   __pyx_v_l = (__pyx_t_3 + 1);
18301
18302   /* "csamtools.pyx":2048
18303  *                               src.core.l_qname,
18304  *                               l,
18305  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
18306  * 
18307  *             src.core.l_qname = l
18308  */
18309   pysam_bam_update(__pyx_v_src, __pyx_v_src->core.l_qname, __pyx_v_l, ((uint8_t *)__pyx_v_p));
18310
18311   /* "csamtools.pyx":2050
18312  *                               <uint8_t*>p )
18313  * 
18314  *             src.core.l_qname = l             # <<<<<<<<<<<<<<
18315  * 
18316  *             # re-acquire pointer to location in memory
18317  */
18318   __pyx_v_src->core.l_qname = __pyx_v_l;
18319
18320   /* "csamtools.pyx":2054
18321  *             # re-acquire pointer to location in memory
18322  *             # as it might have moved
18323  *             p = bam1_qname(src)             # <<<<<<<<<<<<<<
18324  * 
18325  *             strncpy( p, qname, l )
18326  */
18327   __pyx_v_p = bam1_qname(__pyx_v_src);
18328
18329   /* "csamtools.pyx":2056
18330  *             p = bam1_qname(src)
18331  * 
18332  *             strncpy( p, qname, l )             # <<<<<<<<<<<<<<
18333  * 
18334  *     property cigar:
18335  */
18336   __pyx_t_6 = PyBytes_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18337   strncpy(__pyx_v_p, __pyx_t_6, __pyx_v_l);
18338
18339   __pyx_r = 0;
18340   goto __pyx_L0;
18341   __pyx_L1_error:;
18342   __Pyx_XDECREF(__pyx_t_1);
18343   __Pyx_AddTraceback("csamtools.AlignedRead.qname.__set__");
18344   __pyx_r = -1;
18345   __pyx_L0:;
18346   __Pyx_TraceReturn(Py_None);
18347   __Pyx_RefNannyFinishContext();
18348   return __pyx_r;
18349 }
18350
18351 /* "csamtools.pyx":2061
18352  *         """the :term:`cigar` alignment (None if not present).
18353  *         """
18354  *         def __get__(self):             # <<<<<<<<<<<<<<
18355  *             cdef uint32_t * cigar_p
18356  *             cdef bam1_t * src
18357  */
18358
18359 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5cigar___get__(PyObject *__pyx_v_self); /*proto*/
18360 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5cigar___get__(PyObject *__pyx_v_self) {
18361   uint32_t *__pyx_v_cigar_p;
18362   bam1_t *__pyx_v_src;
18363   PyObject *__pyx_v_op;
18364   PyObject *__pyx_v_l;
18365   PyObject *__pyx_v_cigar;
18366   int __pyx_v_k;
18367   PyObject *__pyx_r = NULL;
18368   int __pyx_t_1;
18369   PyObject *__pyx_t_2 = NULL;
18370   uint32_t __pyx_t_3;
18371   PyObject *__pyx_t_4 = NULL;
18372   __Pyx_TraceDeclarations
18373   __Pyx_RefNannySetupContext("__get__");
18374   __Pyx_TraceCall("__get__", __pyx_f[0], 2061);
18375   __pyx_v_op = Py_None; __Pyx_INCREF(Py_None);
18376   __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
18377   __pyx_v_cigar = Py_None; __Pyx_INCREF(Py_None);
18378
18379   /* "csamtools.pyx":2067
18380  *             cdef int k
18381  * 
18382  *             src = self._delegate             # <<<<<<<<<<<<<<
18383  *             if src.core.n_cigar == 0: return None
18384  * 
18385  */
18386   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18387
18388   /* "csamtools.pyx":2068
18389  * 
18390  *             src = self._delegate
18391  *             if src.core.n_cigar == 0: return None             # <<<<<<<<<<<<<<
18392  * 
18393  *             cigar = []
18394  */
18395   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
18396   if (__pyx_t_1) {
18397     __Pyx_XDECREF(__pyx_r);
18398     __Pyx_INCREF(Py_None);
18399     __pyx_r = Py_None;
18400     goto __pyx_L0;
18401     goto __pyx_L5;
18402   }
18403   __pyx_L5:;
18404
18405   /* "csamtools.pyx":2070
18406  *             if src.core.n_cigar == 0: return None
18407  * 
18408  *             cigar = []             # <<<<<<<<<<<<<<
18409  *             cigar_p = bam1_cigar(src);
18410  *             for k from 0 <= k < src.core.n_cigar:
18411  */
18412   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2070; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18413   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
18414   __Pyx_DECREF(__pyx_v_cigar);
18415   __pyx_v_cigar = ((PyObject *)__pyx_t_2);
18416   __pyx_t_2 = 0;
18417
18418   /* "csamtools.pyx":2071
18419  * 
18420  *             cigar = []
18421  *             cigar_p = bam1_cigar(src);             # <<<<<<<<<<<<<<
18422  *             for k from 0 <= k < src.core.n_cigar:
18423  *                 op = cigar_p[k] & BAM_CIGAR_MASK
18424  */
18425   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
18426
18427   /* "csamtools.pyx":2072
18428  *             cigar = []
18429  *             cigar_p = bam1_cigar(src);
18430  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
18431  *                 op = cigar_p[k] & BAM_CIGAR_MASK
18432  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
18433  */
18434   __pyx_t_3 = __pyx_v_src->core.n_cigar;
18435   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
18436
18437     /* "csamtools.pyx":2073
18438  *             cigar_p = bam1_cigar(src);
18439  *             for k from 0 <= k < src.core.n_cigar:
18440  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
18441  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
18442  *                 cigar.append((op, l))
18443  */
18444     __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 = 2073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18445     __Pyx_GOTREF(__pyx_t_2);
18446     __Pyx_DECREF(__pyx_v_op);
18447     __pyx_v_op = __pyx_t_2;
18448     __pyx_t_2 = 0;
18449
18450     /* "csamtools.pyx":2074
18451  *             for k from 0 <= k < src.core.n_cigar:
18452  *                 op = cigar_p[k] & BAM_CIGAR_MASK
18453  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
18454  *                 cigar.append((op, l))
18455  *             return cigar
18456  */
18457     __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 = 2074; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18458     __Pyx_GOTREF(__pyx_t_2);
18459     __Pyx_DECREF(__pyx_v_l);
18460     __pyx_v_l = __pyx_t_2;
18461     __pyx_t_2 = 0;
18462
18463     /* "csamtools.pyx":2075
18464  *                 op = cigar_p[k] & BAM_CIGAR_MASK
18465  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
18466  *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
18467  *             return cigar
18468  * 
18469  */
18470     __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18471     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
18472     __Pyx_INCREF(__pyx_v_op);
18473     PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_op);
18474     __Pyx_GIVEREF(__pyx_v_op);
18475     __Pyx_INCREF(__pyx_v_l);
18476     PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_l);
18477     __Pyx_GIVEREF(__pyx_v_l);
18478     __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 = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18479     __Pyx_GOTREF(__pyx_t_4);
18480     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
18481     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
18482   }
18483
18484   /* "csamtools.pyx":2076
18485  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
18486  *                 cigar.append((op, l))
18487  *             return cigar             # <<<<<<<<<<<<<<
18488  * 
18489  *         def __set__(self, values ):
18490  */
18491   __Pyx_XDECREF(__pyx_r);
18492   __Pyx_INCREF(__pyx_v_cigar);
18493   __pyx_r = __pyx_v_cigar;
18494   goto __pyx_L0;
18495
18496   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18497   goto __pyx_L0;
18498   __pyx_L1_error:;
18499   __Pyx_XDECREF(__pyx_t_2);
18500   __Pyx_XDECREF(__pyx_t_4);
18501   __Pyx_AddTraceback("csamtools.AlignedRead.cigar.__get__");
18502   __pyx_r = NULL;
18503   __pyx_L0:;
18504   __Pyx_DECREF(__pyx_v_op);
18505   __Pyx_DECREF(__pyx_v_l);
18506   __Pyx_DECREF(__pyx_v_cigar);
18507   __Pyx_XGIVEREF(__pyx_r);
18508   __Pyx_TraceReturn(__pyx_r);
18509   __Pyx_RefNannyFinishContext();
18510   return __pyx_r;
18511 }
18512
18513 /* "csamtools.pyx":2078
18514  *             return cigar
18515  * 
18516  *         def __set__(self, values ):             # <<<<<<<<<<<<<<
18517  *             if values == None or len(values) == 0: return
18518  *             cdef uint32_t * p
18519  */
18520
18521 static int __pyx_pf_9csamtools_11AlignedRead_5cigar_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
18522 static int __pyx_pf_9csamtools_11AlignedRead_5cigar_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
18523   uint32_t *__pyx_v_p;
18524   bam1_t *__pyx_v_src;
18525   PyObject *__pyx_v_op;
18526   PyObject *__pyx_v_l;
18527   int __pyx_v_k;
18528   int __pyx_r;
18529   PyObject *__pyx_t_1 = NULL;
18530   int __pyx_t_2;
18531   Py_ssize_t __pyx_t_3;
18532   int __pyx_t_4;
18533   int __pyx_t_5;
18534   PyObject *__pyx_t_6 = NULL;
18535   PyObject *__pyx_t_7 = NULL;
18536   PyObject *__pyx_t_8 = NULL;
18537   PyObject *__pyx_t_9 = NULL;
18538   uint32_t __pyx_t_10;
18539   __Pyx_TraceDeclarations
18540   __Pyx_RefNannySetupContext("__set__");
18541   __Pyx_TraceCall("__set__", __pyx_f[0], 2078);
18542   __pyx_v_op = Py_None; __Pyx_INCREF(Py_None);
18543   __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
18544
18545   /* "csamtools.pyx":2079
18546  * 
18547  *         def __set__(self, values ):
18548  *             if values == None or len(values) == 0: return             # <<<<<<<<<<<<<<
18549  *             cdef uint32_t * p
18550  *             cdef bam1_t * src
18551  */
18552   __pyx_t_1 = PyObject_RichCompare(__pyx_v_values, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18553   __Pyx_GOTREF(__pyx_t_1);
18554   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18555   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
18556   if (!__pyx_t_2) {
18557     __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18558     __pyx_t_4 = (__pyx_t_3 == 0);
18559     __pyx_t_5 = __pyx_t_4;
18560   } else {
18561     __pyx_t_5 = __pyx_t_2;
18562   }
18563   if (__pyx_t_5) {
18564     __pyx_r = 0;
18565     goto __pyx_L0;
18566     goto __pyx_L5;
18567   }
18568   __pyx_L5:;
18569
18570   /* "csamtools.pyx":2085
18571  *             cdef int k
18572  * 
18573  *             k = 0             # <<<<<<<<<<<<<<
18574  * 
18575  *             src = self._delegate
18576  */
18577   __pyx_v_k = 0;
18578
18579   /* "csamtools.pyx":2087
18580  *             k = 0
18581  * 
18582  *             src = self._delegate             # <<<<<<<<<<<<<<
18583  * 
18584  *             # get location of cigar string
18585  */
18586   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18587
18588   /* "csamtools.pyx":2090
18589  * 
18590  *             # get location of cigar string
18591  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
18592  * 
18593  *             # create space for cigar data within src.data
18594  */
18595   __pyx_v_p = bam1_cigar(__pyx_v_src);
18596
18597   /* "csamtools.pyx":2095
18598  *             pysam_bam_update( src,
18599  *                               src.core.n_cigar * 4,
18600  *                               len(values) * 4,             # <<<<<<<<<<<<<<
18601  *                               <uint8_t*>p )
18602  * 
18603  */
18604   __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18605
18606   /* "csamtools.pyx":2096
18607  *                               src.core.n_cigar * 4,
18608  *                               len(values) * 4,
18609  *                               <uint8_t*>p )             # <<<<<<<<<<<<<<
18610  * 
18611  *             # length is number of cigar operations, not bytes
18612  */
18613   pysam_bam_update(__pyx_v_src, (__pyx_v_src->core.n_cigar * 4), (__pyx_t_3 * 4), ((uint8_t *)__pyx_v_p));
18614
18615   /* "csamtools.pyx":2099
18616  * 
18617  *             # length is number of cigar operations, not bytes
18618  *             src.core.n_cigar = len(values)             # <<<<<<<<<<<<<<
18619  * 
18620  *             # re-acquire pointer to location in memory
18621  */
18622   __pyx_t_3 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18623   __pyx_v_src->core.n_cigar = __pyx_t_3;
18624
18625   /* "csamtools.pyx":2103
18626  *             # re-acquire pointer to location in memory
18627  *             # as it might have moved
18628  *             p = bam1_cigar(src)             # <<<<<<<<<<<<<<
18629  * 
18630  *             # insert cigar operations
18631  */
18632   __pyx_v_p = bam1_cigar(__pyx_v_src);
18633
18634   /* "csamtools.pyx":2106
18635  * 
18636  *             # insert cigar operations
18637  *             for op, l in values:             # <<<<<<<<<<<<<<
18638  *                 p[k] = l << BAM_CIGAR_SHIFT | op
18639  *                 k += 1
18640  */
18641   if (PyList_CheckExact(__pyx_v_values) || PyTuple_CheckExact(__pyx_v_values)) {
18642     __pyx_t_3 = 0; __pyx_t_1 = __pyx_v_values; __Pyx_INCREF(__pyx_t_1);
18643   } else {
18644     __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18645     __Pyx_GOTREF(__pyx_t_1);
18646   }
18647   for (;;) {
18648     if (likely(PyList_CheckExact(__pyx_t_1))) {
18649       if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
18650       __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
18651     } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
18652       if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
18653       __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++;
18654     } else {
18655       __pyx_t_6 = PyIter_Next(__pyx_t_1);
18656       if (!__pyx_t_6) {
18657         if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18658         break;
18659       }
18660       __Pyx_GOTREF(__pyx_t_6);
18661     }
18662     if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) {
18663       PyObject* tuple = __pyx_t_6;
18664       __pyx_t_7 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_7);
18665       __pyx_t_8 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_8);
18666       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
18667       __Pyx_DECREF(__pyx_v_op);
18668       __pyx_v_op = __pyx_t_7;
18669       __pyx_t_7 = 0;
18670       __Pyx_DECREF(__pyx_v_l);
18671       __pyx_v_l = __pyx_t_8;
18672       __pyx_t_8 = 0;
18673     } else {
18674       __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18675       __Pyx_GOTREF(__pyx_t_9);
18676       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
18677       __pyx_t_7 = __Pyx_UnpackItem(__pyx_t_9, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18678       __Pyx_GOTREF(__pyx_t_7);
18679       __pyx_t_8 = __Pyx_UnpackItem(__pyx_t_9, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18680       __Pyx_GOTREF(__pyx_t_8);
18681       if (__Pyx_EndUnpack(__pyx_t_9, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18682       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
18683       __Pyx_DECREF(__pyx_v_op);
18684       __pyx_v_op = __pyx_t_7;
18685       __pyx_t_7 = 0;
18686       __Pyx_DECREF(__pyx_v_l);
18687       __pyx_v_l = __pyx_t_8;
18688       __pyx_t_8 = 0;
18689     }
18690
18691     /* "csamtools.pyx":2107
18692  *             # insert cigar operations
18693  *             for op, l in values:
18694  *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
18695  *                 k += 1
18696  * 
18697  */
18698     __pyx_t_6 = PyNumber_Lshift(__pyx_v_l, __pyx_int_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18699     __Pyx_GOTREF(__pyx_t_6);
18700     __pyx_t_8 = PyNumber_Or(__pyx_t_6, __pyx_v_op); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18701     __Pyx_GOTREF(__pyx_t_8);
18702     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
18703     __pyx_t_10 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_8); if (unlikely((__pyx_t_10 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18704     __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
18705     (__pyx_v_p[__pyx_v_k]) = __pyx_t_10;
18706
18707     /* "csamtools.pyx":2108
18708  *             for op, l in values:
18709  *                 p[k] = l << BAM_CIGAR_SHIFT | op
18710  *                 k += 1             # <<<<<<<<<<<<<<
18711  * 
18712  *             ## setting the cigar string also updates the "bin" attribute
18713  */
18714     __pyx_v_k = (__pyx_v_k + 1);
18715   }
18716   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
18717
18718   /* "csamtools.pyx":2111
18719  * 
18720  *             ## setting the cigar string also updates the "bin" attribute
18721  *             src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, p))             # <<<<<<<<<<<<<<
18722  * 
18723  *     property seq:
18724  */
18725   __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), __pyx_v_p));
18726
18727   __pyx_r = 0;
18728   goto __pyx_L0;
18729   __pyx_L1_error:;
18730   __Pyx_XDECREF(__pyx_t_1);
18731   __Pyx_XDECREF(__pyx_t_6);
18732   __Pyx_XDECREF(__pyx_t_7);
18733   __Pyx_XDECREF(__pyx_t_8);
18734   __Pyx_XDECREF(__pyx_t_9);
18735   __Pyx_AddTraceback("csamtools.AlignedRead.cigar.__set__");
18736   __pyx_r = -1;
18737   __pyx_L0:;
18738   __Pyx_DECREF(__pyx_v_op);
18739   __Pyx_DECREF(__pyx_v_l);
18740   __Pyx_TraceReturn(Py_None);
18741   __Pyx_RefNannyFinishContext();
18742   return __pyx_r;
18743 }
18744
18745 /* "csamtools.pyx":2115
18746  *     property seq:
18747  *         """read sequence bases, including :term:`soft clipped` bases (None if not present)"""
18748  *         def __get__(self):             # <<<<<<<<<<<<<<
18749  *             cdef bam1_t * src
18750  *             cdef char * s
18751  */
18752
18753 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3seq___get__(PyObject *__pyx_v_self); /*proto*/
18754 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3seq___get__(PyObject *__pyx_v_self) {
18755   bam1_t *__pyx_v_src;
18756   PyObject *__pyx_r = NULL;
18757   int __pyx_t_1;
18758   PyObject *__pyx_t_2 = NULL;
18759   __Pyx_TraceDeclarations
18760   __Pyx_RefNannySetupContext("__get__");
18761   __Pyx_TraceCall("__get__", __pyx_f[0], 2115);
18762
18763   /* "csamtools.pyx":2118
18764  *             cdef bam1_t * src
18765  *             cdef char * s
18766  *             src = self._delegate             # <<<<<<<<<<<<<<
18767  * 
18768  *             if src.core.l_qseq == 0: return None
18769  */
18770   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18771
18772   /* "csamtools.pyx":2120
18773  *             src = self._delegate
18774  * 
18775  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
18776  * 
18777  *             return get_seq_range(src, 0, src.core.l_qseq)
18778  */
18779   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
18780   if (__pyx_t_1) {
18781     __Pyx_XDECREF(__pyx_r);
18782     __Pyx_INCREF(Py_None);
18783     __pyx_r = Py_None;
18784     goto __pyx_L0;
18785     goto __pyx_L5;
18786   }
18787   __pyx_L5:;
18788
18789   /* "csamtools.pyx":2122
18790  *             if src.core.l_qseq == 0: return None
18791  * 
18792  *             return get_seq_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
18793  * 
18794  *         def __set__(self,seq):
18795  */
18796   __Pyx_XDECREF(__pyx_r);
18797   __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 = 2122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18798   __Pyx_GOTREF(__pyx_t_2);
18799   __pyx_r = __pyx_t_2;
18800   __pyx_t_2 = 0;
18801   goto __pyx_L0;
18802
18803   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
18804   goto __pyx_L0;
18805   __pyx_L1_error:;
18806   __Pyx_XDECREF(__pyx_t_2);
18807   __Pyx_AddTraceback("csamtools.AlignedRead.seq.__get__");
18808   __pyx_r = NULL;
18809   __pyx_L0:;
18810   __Pyx_XGIVEREF(__pyx_r);
18811   __Pyx_TraceReturn(__pyx_r);
18812   __Pyx_RefNannyFinishContext();
18813   return __pyx_r;
18814 }
18815
18816 /* "csamtools.pyx":2124
18817  *             return get_seq_range(src, 0, src.core.l_qseq)
18818  * 
18819  *         def __set__(self,seq):             # <<<<<<<<<<<<<<
18820  *             # samtools manages sequence and quality length memory together
18821  *             # if no quality information is present, the first byte says 0xff.
18822  */
18823
18824 static int __pyx_pf_9csamtools_11AlignedRead_3seq_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
18825 static int __pyx_pf_9csamtools_11AlignedRead_3seq_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
18826   bam1_t *__pyx_v_src;
18827   uint8_t *__pyx_v_p;
18828   char *__pyx_v_s;
18829   int __pyx_v_l;
18830   int __pyx_v_k;
18831   int __pyx_v_nbytes_new;
18832   int __pyx_v_nbytes_old;
18833   int __pyx_r;
18834   PyObject *__pyx_t_1 = NULL;
18835   int __pyx_t_2;
18836   Py_ssize_t __pyx_t_3;
18837   int __pyx_t_4;
18838   int __pyx_t_5;
18839   int __pyx_t_6;
18840   char *__pyx_t_7;
18841   long __pyx_t_8;
18842   __Pyx_TraceDeclarations
18843   __Pyx_RefNannySetupContext("__set__");
18844   __Pyx_TraceCall("__set__", __pyx_f[0], 2124);
18845
18846   /* "csamtools.pyx":2128
18847  *             # if no quality information is present, the first byte says 0xff.
18848  * 
18849  *             if seq == None or len(seq) == 0: return             # <<<<<<<<<<<<<<
18850  *             cdef bam1_t * src
18851  *             cdef uint8_t * p
18852  */
18853   __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18854   __Pyx_GOTREF(__pyx_t_1);
18855   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18856   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
18857   if (!__pyx_t_2) {
18858     __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18859     __pyx_t_4 = (__pyx_t_3 == 0);
18860     __pyx_t_5 = __pyx_t_4;
18861   } else {
18862     __pyx_t_5 = __pyx_t_2;
18863   }
18864   if (__pyx_t_5) {
18865     __pyx_r = 0;
18866     goto __pyx_L0;
18867     goto __pyx_L5;
18868   }
18869   __pyx_L5:;
18870
18871   /* "csamtools.pyx":2134
18872  *             cdef int l, k, nbytes_new, nbytes_old
18873  * 
18874  *             src = self._delegate             # <<<<<<<<<<<<<<
18875  * 
18876  *             l = len(seq)
18877  */
18878   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
18879
18880   /* "csamtools.pyx":2136
18881  *             src = self._delegate
18882  * 
18883  *             l = len(seq)             # <<<<<<<<<<<<<<
18884  * 
18885  *             # as the sequence is stored in half-bytes, the total length (sequence
18886  */
18887   __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18888   __pyx_v_l = __pyx_t_3;
18889
18890   /* "csamtools.pyx":2140
18891  *             # as the sequence is stored in half-bytes, the total length (sequence
18892  *             # plus quality scores) is (l+1)/2 + l
18893  *             nbytes_new = (l+1)/2 + l             # <<<<<<<<<<<<<<
18894  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
18895  *             # acquire pointer to location in memory
18896  */
18897   __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);
18898
18899   /* "csamtools.pyx":2141
18900  *             # plus quality scores) is (l+1)/2 + l
18901  *             nbytes_new = (l+1)/2 + l
18902  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq             # <<<<<<<<<<<<<<
18903  *             # acquire pointer to location in memory
18904  *             p = bam1_seq( src )
18905  */
18906   __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);
18907
18908   /* "csamtools.pyx":2143
18909  *             nbytes_old = (src.core.l_qseq+1)/2 + src.core.l_qseq
18910  *             # acquire pointer to location in memory
18911  *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
18912  *             src.core.l_qseq = l
18913  * 
18914  */
18915   __pyx_v_p = bam1_seq(__pyx_v_src);
18916
18917   /* "csamtools.pyx":2144
18918  *             # acquire pointer to location in memory
18919  *             p = bam1_seq( src )
18920  *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
18921  * 
18922  *             pysam_bam_update( src,
18923  */
18924   __pyx_v_src->core.l_qseq = __pyx_v_l;
18925
18926   /* "csamtools.pyx":2149
18927  *                               nbytes_old,
18928  *                               nbytes_new,
18929  *                               p)             # <<<<<<<<<<<<<<
18930  *             # re-acquire pointer to location in memory
18931  *             # as it might have moved
18932  */
18933   pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);
18934
18935   /* "csamtools.pyx":2152
18936  *             # re-acquire pointer to location in memory
18937  *             # as it might have moved
18938  *             p = bam1_seq( src )             # <<<<<<<<<<<<<<
18939  *             for k from 0 <= k < nbytes_new: p[k] = 0
18940  *             # convert to C string
18941  */
18942   __pyx_v_p = bam1_seq(__pyx_v_src);
18943
18944   /* "csamtools.pyx":2153
18945  *             # as it might have moved
18946  *             p = bam1_seq( src )
18947  *             for k from 0 <= k < nbytes_new: p[k] = 0             # <<<<<<<<<<<<<<
18948  *             # convert to C string
18949  *             s = seq
18950  */
18951   __pyx_t_6 = __pyx_v_nbytes_new;
18952   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {
18953     (__pyx_v_p[__pyx_v_k]) = 0;
18954   }
18955
18956   /* "csamtools.pyx":2155
18957  *             for k from 0 <= k < nbytes_new: p[k] = 0
18958  *             # convert to C string
18959  *             s = seq             # <<<<<<<<<<<<<<
18960  *             for k from 0 <= k < l:
18961  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
18962  */
18963   __pyx_t_7 = PyBytes_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
18964   __pyx_v_s = __pyx_t_7;
18965
18966   /* "csamtools.pyx":2156
18967  *             # convert to C string
18968  *             s = seq
18969  *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
18970  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)
18971  * 
18972  */
18973   __pyx_t_6 = __pyx_v_l;
18974   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {
18975
18976     /* "csamtools.pyx":2157
18977  *             s = seq
18978  *             for k from 0 <= k < l:
18979  *                 p[k/2] |= pysam_translate_sequence(s[k]) << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
18980  * 
18981  *             # erase qualities
18982  */
18983     __pyx_t_8 = __Pyx_div_long(__pyx_v_k, 2);
18984     (__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)))));
18985   }
18986
18987   /* "csamtools.pyx":2160
18988  * 
18989  *             # erase qualities
18990  *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
18991  *             p[0] = 0xff
18992  * 
18993  */
18994   __pyx_v_p = bam1_qual(__pyx_v_src);
18995
18996   /* "csamtools.pyx":2161
18997  *             # erase qualities
18998  *             p = bam1_qual( src )
18999  *             p[0] = 0xff             # <<<<<<<<<<<<<<
19000  * 
19001  * 
19002  */
19003   (__pyx_v_p[0]) = 0xff;
19004
19005   __pyx_r = 0;
19006   goto __pyx_L0;
19007   __pyx_L1_error:;
19008   __Pyx_XDECREF(__pyx_t_1);
19009   __Pyx_AddTraceback("csamtools.AlignedRead.seq.__set__");
19010   __pyx_r = -1;
19011   __pyx_L0:;
19012   __Pyx_TraceReturn(Py_None);
19013   __Pyx_RefNannyFinishContext();
19014   return __pyx_r;
19015 }
19016
19017 /* "csamtools.pyx":2166
19018  *     property qual:
19019  *         """read sequence base qualities, including :term:`soft clipped` bases (None if not present)"""
19020  *         def __get__(self):             # <<<<<<<<<<<<<<
19021  * 
19022  *             cdef bam1_t * src
19023  */
19024
19025 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qual___get__(PyObject *__pyx_v_self); /*proto*/
19026 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qual___get__(PyObject *__pyx_v_self) {
19027   bam1_t *__pyx_v_src;
19028   PyObject *__pyx_r = NULL;
19029   int __pyx_t_1;
19030   PyObject *__pyx_t_2 = NULL;
19031   __Pyx_TraceDeclarations
19032   __Pyx_RefNannySetupContext("__get__");
19033   __Pyx_TraceCall("__get__", __pyx_f[0], 2166);
19034
19035   /* "csamtools.pyx":2171
19036  *             cdef char * q
19037  * 
19038  *             src = self._delegate             # <<<<<<<<<<<<<<
19039  * 
19040  *             if src.core.l_qseq == 0: return None
19041  */
19042   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19043
19044   /* "csamtools.pyx":2173
19045  *             src = self._delegate
19046  * 
19047  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
19048  * 
19049  *             return get_qual_range(src, 0, src.core.l_qseq)
19050  */
19051   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
19052   if (__pyx_t_1) {
19053     __Pyx_XDECREF(__pyx_r);
19054     __Pyx_INCREF(Py_None);
19055     __pyx_r = Py_None;
19056     goto __pyx_L0;
19057     goto __pyx_L5;
19058   }
19059   __pyx_L5:;
19060
19061   /* "csamtools.pyx":2175
19062  *             if src.core.l_qseq == 0: return None
19063  * 
19064  *             return get_qual_range(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
19065  * 
19066  *         def __set__(self,qual):
19067  */
19068   __Pyx_XDECREF(__pyx_r);
19069   __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 = 2175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19070   __Pyx_GOTREF(__pyx_t_2);
19071   __pyx_r = __pyx_t_2;
19072   __pyx_t_2 = 0;
19073   goto __pyx_L0;
19074
19075   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19076   goto __pyx_L0;
19077   __pyx_L1_error:;
19078   __Pyx_XDECREF(__pyx_t_2);
19079   __Pyx_AddTraceback("csamtools.AlignedRead.qual.__get__");
19080   __pyx_r = NULL;
19081   __pyx_L0:;
19082   __Pyx_XGIVEREF(__pyx_r);
19083   __Pyx_TraceReturn(__pyx_r);
19084   __Pyx_RefNannyFinishContext();
19085   return __pyx_r;
19086 }
19087
19088 /* "csamtools.pyx":2177
19089  *             return get_qual_range(src, 0, src.core.l_qseq)
19090  * 
19091  *         def __set__(self,qual):             # <<<<<<<<<<<<<<
19092  *             # note that space is already allocated via the sequences
19093  *             cdef bam1_t * src
19094  */
19095
19096 static int __pyx_pf_9csamtools_11AlignedRead_4qual_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
19097 static int __pyx_pf_9csamtools_11AlignedRead_4qual_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
19098   bam1_t *__pyx_v_src;
19099   uint8_t *__pyx_v_p;
19100   char *__pyx_v_q;
19101   int __pyx_v_k;
19102   int __pyx_v_l;
19103   int __pyx_r;
19104   PyObject *__pyx_t_1 = NULL;
19105   int __pyx_t_2;
19106   Py_ssize_t __pyx_t_3;
19107   int __pyx_t_4;
19108   int __pyx_t_5;
19109   char *__pyx_t_6;
19110   PyObject *__pyx_t_7 = NULL;
19111   PyObject *__pyx_t_8 = NULL;
19112   int __pyx_t_9;
19113   __Pyx_TraceDeclarations
19114   __Pyx_RefNannySetupContext("__set__");
19115   __Pyx_TraceCall("__set__", __pyx_f[0], 2177);
19116
19117   /* "csamtools.pyx":2184
19118  *             cdef int k
19119  * 
19120  *             src = self._delegate             # <<<<<<<<<<<<<<
19121  *             p = bam1_qual( src )
19122  *             if qual == None or len(qual) == 0:
19123  */
19124   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19125
19126   /* "csamtools.pyx":2185
19127  * 
19128  *             src = self._delegate
19129  *             p = bam1_qual( src )             # <<<<<<<<<<<<<<
19130  *             if qual == None or len(qual) == 0:
19131  *                 # if absent - set to 0xff
19132  */
19133   __pyx_v_p = bam1_qual(__pyx_v_src);
19134
19135   /* "csamtools.pyx":2186
19136  *             src = self._delegate
19137  *             p = bam1_qual( src )
19138  *             if qual == None or len(qual) == 0:             # <<<<<<<<<<<<<<
19139  *                 # if absent - set to 0xff
19140  *                 p[0] = 0xff
19141  */
19142   __pyx_t_1 = PyObject_RichCompare(__pyx_v_qual, Py_None, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19143   __Pyx_GOTREF(__pyx_t_1);
19144   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19145   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
19146   if (!__pyx_t_2) {
19147     __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19148     __pyx_t_4 = (__pyx_t_3 == 0);
19149     __pyx_t_5 = __pyx_t_4;
19150   } else {
19151     __pyx_t_5 = __pyx_t_2;
19152   }
19153   if (__pyx_t_5) {
19154
19155     /* "csamtools.pyx":2188
19156  *             if qual == None or len(qual) == 0:
19157  *                 # if absent - set to 0xff
19158  *                 p[0] = 0xff             # <<<<<<<<<<<<<<
19159  *                 return
19160  *             cdef int l
19161  */
19162     (__pyx_v_p[0]) = 0xff;
19163
19164     /* "csamtools.pyx":2189
19165  *                 # if absent - set to 0xff
19166  *                 p[0] = 0xff
19167  *                 return             # <<<<<<<<<<<<<<
19168  *             cdef int l
19169  *             # convert to C string
19170  */
19171     __pyx_r = 0;
19172     goto __pyx_L0;
19173     goto __pyx_L5;
19174   }
19175   __pyx_L5:;
19176
19177   /* "csamtools.pyx":2192
19178  *             cdef int l
19179  *             # convert to C string
19180  *             q = qual             # <<<<<<<<<<<<<<
19181  *             l = len(qual)
19182  *             if src.core.l_qseq != l:
19183  */
19184   __pyx_t_6 = PyBytes_AsString(__pyx_v_qual); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19185   __pyx_v_q = __pyx_t_6;
19186
19187   /* "csamtools.pyx":2193
19188  *             # convert to C string
19189  *             q = qual
19190  *             l = len(qual)             # <<<<<<<<<<<<<<
19191  *             if src.core.l_qseq != l:
19192  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
19193  */
19194   __pyx_t_3 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19195   __pyx_v_l = __pyx_t_3;
19196
19197   /* "csamtools.pyx":2194
19198  *             q = qual
19199  *             l = len(qual)
19200  *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
19201  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
19202  *             assert src.core.l_qseq == l
19203  */
19204   __pyx_t_5 = (__pyx_v_src->core.l_qseq != __pyx_v_l);
19205   if (__pyx_t_5) {
19206
19207     /* "csamtools.pyx":2195
19208  *             l = len(qual)
19209  *             if src.core.l_qseq != l:
19210  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
19211  *             assert src.core.l_qseq == l
19212  *             for k from 0 <= k < l:
19213  */
19214     __pyx_t_1 = PyInt_FromLong(__pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19215     __Pyx_GOTREF(__pyx_t_1);
19216     __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 = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19217     __Pyx_GOTREF(__pyx_t_7);
19218     __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19219     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
19220     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
19221     __Pyx_GIVEREF(__pyx_t_1);
19222     PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
19223     __Pyx_GIVEREF(__pyx_t_7);
19224     __pyx_t_1 = 0;
19225     __pyx_t_7 = 0;
19226     __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_120), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19227     __Pyx_GOTREF(((PyObject *)__pyx_t_7));
19228     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
19229     __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19230     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
19231     PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_t_7));
19232     __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
19233     __pyx_t_7 = 0;
19234     __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 = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19235     __Pyx_GOTREF(__pyx_t_7);
19236     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
19237     __Pyx_Raise(__pyx_t_7, 0, 0);
19238     __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
19239     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19240     goto __pyx_L6;
19241   }
19242   __pyx_L6:;
19243
19244   /* "csamtools.pyx":2196
19245  *             if src.core.l_qseq != l:
19246  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
19247  *             assert src.core.l_qseq == l             # <<<<<<<<<<<<<<
19248  *             for k from 0 <= k < l:
19249  *                 p[k] = <uint8_t>q[k] - 33
19250  */
19251   #ifndef CYTHON_WITHOUT_ASSERTIONS
19252   if (unlikely(!(__pyx_v_src->core.l_qseq == __pyx_v_l))) {
19253     PyErr_SetNone(PyExc_AssertionError);
19254     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19255   }
19256   #endif
19257
19258   /* "csamtools.pyx":2197
19259  *                 raise ValueError("quality and sequence mismatch: %i != %i" % (l, src.core.l_qseq))
19260  *             assert src.core.l_qseq == l
19261  *             for k from 0 <= k < l:             # <<<<<<<<<<<<<<
19262  *                 p[k] = <uint8_t>q[k] - 33
19263  * 
19264  */
19265   __pyx_t_9 = __pyx_v_l;
19266   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_9; __pyx_v_k++) {
19267
19268     /* "csamtools.pyx":2198
19269  *             assert src.core.l_qseq == l
19270  *             for k from 0 <= k < l:
19271  *                 p[k] = <uint8_t>q[k] - 33             # <<<<<<<<<<<<<<
19272  * 
19273  *     property query:
19274  */
19275     (__pyx_v_p[__pyx_v_k]) = (((uint8_t)(__pyx_v_q[__pyx_v_k])) - 33);
19276   }
19277
19278   __pyx_r = 0;
19279   goto __pyx_L0;
19280   __pyx_L1_error:;
19281   __Pyx_XDECREF(__pyx_t_1);
19282   __Pyx_XDECREF(__pyx_t_7);
19283   __Pyx_XDECREF(__pyx_t_8);
19284   __Pyx_AddTraceback("csamtools.AlignedRead.qual.__set__");
19285   __pyx_r = -1;
19286   __pyx_L0:;
19287   __Pyx_TraceReturn(Py_None);
19288   __Pyx_RefNannyFinishContext();
19289   return __pyx_r;
19290 }
19291
19292 /* "csamtools.pyx":2210
19293  *         were not considered for alignment may have been retained."""
19294  * 
19295  *         def __get__(self):             # <<<<<<<<<<<<<<
19296  *             cdef bam1_t * src
19297  *             cdef uint32_t start, end
19298  */
19299
19300 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5query___get__(PyObject *__pyx_v_self); /*proto*/
19301 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5query___get__(PyObject *__pyx_v_self) {
19302   bam1_t *__pyx_v_src;
19303   uint32_t __pyx_v_start;
19304   uint32_t __pyx_v_end;
19305   PyObject *__pyx_r = NULL;
19306   int __pyx_t_1;
19307   int32_t __pyx_t_2;
19308   PyObject *__pyx_t_3 = NULL;
19309   __Pyx_TraceDeclarations
19310   __Pyx_RefNannySetupContext("__get__");
19311   __Pyx_TraceCall("__get__", __pyx_f[0], 2210);
19312
19313   /* "csamtools.pyx":2215
19314  *             cdef char * s
19315  * 
19316  *             src = self._delegate             # <<<<<<<<<<<<<<
19317  * 
19318  *             if src.core.l_qseq == 0: return None
19319  */
19320   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19321
19322   /* "csamtools.pyx":2217
19323  *             src = self._delegate
19324  * 
19325  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
19326  * 
19327  *             start = query_start(src)
19328  */
19329   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
19330   if (__pyx_t_1) {
19331     __Pyx_XDECREF(__pyx_r);
19332     __Pyx_INCREF(Py_None);
19333     __pyx_r = Py_None;
19334     goto __pyx_L0;
19335     goto __pyx_L5;
19336   }
19337   __pyx_L5:;
19338
19339   /* "csamtools.pyx":2219
19340  *             if src.core.l_qseq == 0: return None
19341  * 
19342  *             start = query_start(src)             # <<<<<<<<<<<<<<
19343  *             end   = query_end(src)
19344  * 
19345  */
19346   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19347   __pyx_v_start = __pyx_t_2;
19348
19349   /* "csamtools.pyx":2220
19350  * 
19351  *             start = query_start(src)
19352  *             end   = query_end(src)             # <<<<<<<<<<<<<<
19353  * 
19354  *             return get_seq_range(src, start, end)
19355  */
19356   __pyx_t_2 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19357   __pyx_v_end = __pyx_t_2;
19358
19359   /* "csamtools.pyx":2222
19360  *             end   = query_end(src)
19361  * 
19362  *             return get_seq_range(src, start, end)             # <<<<<<<<<<<<<<
19363  * 
19364  *     property qqual:
19365  */
19366   __Pyx_XDECREF(__pyx_r);
19367   __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 = 2222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19368   __Pyx_GOTREF(__pyx_t_3);
19369   __pyx_r = __pyx_t_3;
19370   __pyx_t_3 = 0;
19371   goto __pyx_L0;
19372
19373   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19374   goto __pyx_L0;
19375   __pyx_L1_error:;
19376   __Pyx_XDECREF(__pyx_t_3);
19377   __Pyx_AddTraceback("csamtools.AlignedRead.query.__get__");
19378   __pyx_r = NULL;
19379   __pyx_L0:;
19380   __Pyx_XGIVEREF(__pyx_r);
19381   __Pyx_TraceReturn(__pyx_r);
19382   __Pyx_RefNannyFinishContext();
19383   return __pyx_r;
19384 }
19385
19386 /* "csamtools.pyx":2226
19387  *     property qqual:
19388  *         """aligned query sequence quality values (None if not present)"""
19389  *         def __get__(self):             # <<<<<<<<<<<<<<
19390  *             cdef bam1_t * src
19391  *             cdef uint32_t start, end
19392  */
19393
19394 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qqual___get__(PyObject *__pyx_v_self); /*proto*/
19395 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5qqual___get__(PyObject *__pyx_v_self) {
19396   bam1_t *__pyx_v_src;
19397   uint32_t __pyx_v_start;
19398   uint32_t __pyx_v_end;
19399   PyObject *__pyx_r = NULL;
19400   int __pyx_t_1;
19401   int32_t __pyx_t_2;
19402   PyObject *__pyx_t_3 = NULL;
19403   __Pyx_TraceDeclarations
19404   __Pyx_RefNannySetupContext("__get__");
19405   __Pyx_TraceCall("__get__", __pyx_f[0], 2226);
19406
19407   /* "csamtools.pyx":2231
19408  *             cdef char * q
19409  * 
19410  *             src = self._delegate             # <<<<<<<<<<<<<<
19411  * 
19412  *             if src.core.l_qseq == 0: return None
19413  */
19414   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19415
19416   /* "csamtools.pyx":2233
19417  *             src = self._delegate
19418  * 
19419  *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
19420  * 
19421  *             start = query_start(src)
19422  */
19423   __pyx_t_1 = (__pyx_v_src->core.l_qseq == 0);
19424   if (__pyx_t_1) {
19425     __Pyx_XDECREF(__pyx_r);
19426     __Pyx_INCREF(Py_None);
19427     __pyx_r = Py_None;
19428     goto __pyx_L0;
19429     goto __pyx_L5;
19430   }
19431   __pyx_L5:;
19432
19433   /* "csamtools.pyx":2235
19434  *             if src.core.l_qseq == 0: return None
19435  * 
19436  *             start = query_start(src)             # <<<<<<<<<<<<<<
19437  *             end   = query_end(src)
19438  * 
19439  */
19440   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19441   __pyx_v_start = __pyx_t_2;
19442
19443   /* "csamtools.pyx":2236
19444  * 
19445  *             start = query_start(src)
19446  *             end   = query_end(src)             # <<<<<<<<<<<<<<
19447  * 
19448  *             return get_qual_range(src, start, end)
19449  */
19450   __pyx_t_2 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19451   __pyx_v_end = __pyx_t_2;
19452
19453   /* "csamtools.pyx":2238
19454  *             end   = query_end(src)
19455  * 
19456  *             return get_qual_range(src, start, end)             # <<<<<<<<<<<<<<
19457  * 
19458  *     property qstart:
19459  */
19460   __Pyx_XDECREF(__pyx_r);
19461   __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 = 2238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19462   __Pyx_GOTREF(__pyx_t_3);
19463   __pyx_r = __pyx_t_3;
19464   __pyx_t_3 = 0;
19465   goto __pyx_L0;
19466
19467   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19468   goto __pyx_L0;
19469   __pyx_L1_error:;
19470   __Pyx_XDECREF(__pyx_t_3);
19471   __Pyx_AddTraceback("csamtools.AlignedRead.qqual.__get__");
19472   __pyx_r = NULL;
19473   __pyx_L0:;
19474   __Pyx_XGIVEREF(__pyx_r);
19475   __Pyx_TraceReturn(__pyx_r);
19476   __Pyx_RefNannyFinishContext();
19477   return __pyx_r;
19478 }
19479
19480 /* "csamtools.pyx":2242
19481  *     property qstart:
19482  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
19483  *         def __get__(self):             # <<<<<<<<<<<<<<
19484  *             return query_start(self._delegate)
19485  * 
19486  */
19487
19488 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6qstart___get__(PyObject *__pyx_v_self); /*proto*/
19489 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6qstart___get__(PyObject *__pyx_v_self) {
19490   PyObject *__pyx_r = NULL;
19491   int32_t __pyx_t_1;
19492   PyObject *__pyx_t_2 = NULL;
19493   __Pyx_TraceDeclarations
19494   __Pyx_RefNannySetupContext("__get__");
19495   __Pyx_TraceCall("__get__", __pyx_f[0], 2242);
19496
19497   /* "csamtools.pyx":2243
19498  *         """start index of the aligned query portion of the sequence (0-based, inclusive)"""
19499  *         def __get__(self):
19500  *             return query_start(self._delegate)             # <<<<<<<<<<<<<<
19501  * 
19502  *     property qend:
19503  */
19504   __Pyx_XDECREF(__pyx_r);
19505   __pyx_t_1 = __pyx_f_9csamtools_query_start(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19506   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19507   __Pyx_GOTREF(__pyx_t_2);
19508   __pyx_r = __pyx_t_2;
19509   __pyx_t_2 = 0;
19510   goto __pyx_L0;
19511
19512   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19513   goto __pyx_L0;
19514   __pyx_L1_error:;
19515   __Pyx_XDECREF(__pyx_t_2);
19516   __Pyx_AddTraceback("csamtools.AlignedRead.qstart.__get__");
19517   __pyx_r = NULL;
19518   __pyx_L0:;
19519   __Pyx_XGIVEREF(__pyx_r);
19520   __Pyx_TraceReturn(__pyx_r);
19521   __Pyx_RefNannyFinishContext();
19522   return __pyx_r;
19523 }
19524
19525 /* "csamtools.pyx":2247
19526  *     property qend:
19527  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
19528  *         def __get__(self):             # <<<<<<<<<<<<<<
19529  *             return query_end(self._delegate)
19530  * 
19531  */
19532
19533 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qend___get__(PyObject *__pyx_v_self); /*proto*/
19534 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qend___get__(PyObject *__pyx_v_self) {
19535   PyObject *__pyx_r = NULL;
19536   int32_t __pyx_t_1;
19537   PyObject *__pyx_t_2 = NULL;
19538   __Pyx_TraceDeclarations
19539   __Pyx_RefNannySetupContext("__get__");
19540   __Pyx_TraceCall("__get__", __pyx_f[0], 2247);
19541
19542   /* "csamtools.pyx":2248
19543  *         """end index of the aligned query portion of the sequence (0-based, exclusive)"""
19544  *         def __get__(self):
19545  *             return query_end(self._delegate)             # <<<<<<<<<<<<<<
19546  * 
19547  *     property qlen:
19548  */
19549   __Pyx_XDECREF(__pyx_r);
19550   __pyx_t_1 = __pyx_f_9csamtools_query_end(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19551   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19552   __Pyx_GOTREF(__pyx_t_2);
19553   __pyx_r = __pyx_t_2;
19554   __pyx_t_2 = 0;
19555   goto __pyx_L0;
19556
19557   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19558   goto __pyx_L0;
19559   __pyx_L1_error:;
19560   __Pyx_XDECREF(__pyx_t_2);
19561   __Pyx_AddTraceback("csamtools.AlignedRead.qend.__get__");
19562   __pyx_r = NULL;
19563   __pyx_L0:;
19564   __Pyx_XGIVEREF(__pyx_r);
19565   __Pyx_TraceReturn(__pyx_r);
19566   __Pyx_RefNannyFinishContext();
19567   return __pyx_r;
19568 }
19569
19570 /* "csamtools.pyx":2252
19571  *     property qlen:
19572  *         """Length of the aligned query sequence"""
19573  *         def __get__(self):             # <<<<<<<<<<<<<<
19574  *             cdef bam1_t * src
19575  *             src = self._delegate
19576  */
19577
19578 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qlen___get__(PyObject *__pyx_v_self); /*proto*/
19579 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4qlen___get__(PyObject *__pyx_v_self) {
19580   bam1_t *__pyx_v_src;
19581   PyObject *__pyx_r = NULL;
19582   int32_t __pyx_t_1;
19583   int32_t __pyx_t_2;
19584   PyObject *__pyx_t_3 = NULL;
19585   __Pyx_TraceDeclarations
19586   __Pyx_RefNannySetupContext("__get__");
19587   __Pyx_TraceCall("__get__", __pyx_f[0], 2252);
19588
19589   /* "csamtools.pyx":2254
19590  *         def __get__(self):
19591  *             cdef bam1_t * src
19592  *             src = self._delegate             # <<<<<<<<<<<<<<
19593  *             return query_end(src)-query_start(src)
19594  * 
19595  */
19596   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19597
19598   /* "csamtools.pyx":2255
19599  *             cdef bam1_t * src
19600  *             src = self._delegate
19601  *             return query_end(src)-query_start(src)             # <<<<<<<<<<<<<<
19602  * 
19603  *     property tags:
19604  */
19605   __Pyx_XDECREF(__pyx_r);
19606   __pyx_t_1 = __pyx_f_9csamtools_query_end(__pyx_v_src); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19607   __pyx_t_2 = __pyx_f_9csamtools_query_start(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19608   __pyx_t_3 = __Pyx_PyInt_to_py_int32_t((__pyx_t_1 - __pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19609   __Pyx_GOTREF(__pyx_t_3);
19610   __pyx_r = __pyx_t_3;
19611   __pyx_t_3 = 0;
19612   goto __pyx_L0;
19613
19614   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
19615   goto __pyx_L0;
19616   __pyx_L1_error:;
19617   __Pyx_XDECREF(__pyx_t_3);
19618   __Pyx_AddTraceback("csamtools.AlignedRead.qlen.__get__");
19619   __pyx_r = NULL;
19620   __pyx_L0:;
19621   __Pyx_XGIVEREF(__pyx_r);
19622   __Pyx_TraceReturn(__pyx_r);
19623   __Pyx_RefNannyFinishContext();
19624   return __pyx_r;
19625 }
19626
19627 /* "csamtools.pyx":2272
19628  *         multiple times.
19629  *         """
19630  *         def __get__(self):             # <<<<<<<<<<<<<<
19631  *             cdef char * ctag
19632  *             cdef bam1_t * src
19633  */
19634
19635 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tags___get__(PyObject *__pyx_v_self); /*proto*/
19636 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tags___get__(PyObject *__pyx_v_self) {
19637   bam1_t *__pyx_v_src;
19638   uint8_t *__pyx_v_s;
19639   char __pyx_v_auxtag[3];
19640   char __pyx_v_auxtype;
19641   PyObject *__pyx_v_result;
19642   PyObject *__pyx_v_value;
19643   PyObject *__pyx_r = NULL;
19644   int __pyx_t_1;
19645   PyObject *__pyx_t_2 = NULL;
19646   char __pyx_t_3;
19647   int __pyx_t_4;
19648   int __pyx_t_5;
19649   PyObject *__pyx_t_6 = NULL;
19650   Py_ssize_t __pyx_t_7;
19651   int __pyx_t_8;
19652   __Pyx_TraceDeclarations
19653   __Pyx_RefNannySetupContext("__get__");
19654   __Pyx_TraceCall("__get__", __pyx_f[0], 2272);
19655   __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
19656   __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
19657
19658   /* "csamtools.pyx":2279
19659  *             cdef char auxtype
19660  * 
19661  *             src = self._delegate             # <<<<<<<<<<<<<<
19662  *             if src.l_aux == 0: return []
19663  * 
19664  */
19665   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
19666
19667   /* "csamtools.pyx":2280
19668  * 
19669  *             src = self._delegate
19670  *             if src.l_aux == 0: return []             # <<<<<<<<<<<<<<
19671  * 
19672  *             s = bam1_aux( src )
19673  */
19674   __pyx_t_1 = (__pyx_v_src->l_aux == 0);
19675   if (__pyx_t_1) {
19676     __Pyx_XDECREF(__pyx_r);
19677     __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19678     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
19679     __pyx_r = ((PyObject *)__pyx_t_2);
19680     __pyx_t_2 = 0;
19681     goto __pyx_L0;
19682     goto __pyx_L5;
19683   }
19684   __pyx_L5:;
19685
19686   /* "csamtools.pyx":2282
19687  *             if src.l_aux == 0: return []
19688  * 
19689  *             s = bam1_aux( src )             # <<<<<<<<<<<<<<
19690  *             result = []
19691  *             auxtag[2] = 0
19692  */
19693   __pyx_v_s = bam1_aux(__pyx_v_src);
19694
19695   /* "csamtools.pyx":2283
19696  * 
19697  *             s = bam1_aux( src )
19698  *             result = []             # <<<<<<<<<<<<<<
19699  *             auxtag[2] = 0
19700  *             while s < (src.data + src.data_len):
19701  */
19702   __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19703   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
19704   __Pyx_DECREF(((PyObject *)__pyx_v_result));
19705   __pyx_v_result = __pyx_t_2;
19706   __pyx_t_2 = 0;
19707
19708   /* "csamtools.pyx":2284
19709  *             s = bam1_aux( src )
19710  *             result = []
19711  *             auxtag[2] = 0             # <<<<<<<<<<<<<<
19712  *             while s < (src.data + src.data_len):
19713  *                 # get tag
19714  */
19715   (__pyx_v_auxtag[2]) = 0;
19716
19717   /* "csamtools.pyx":2285
19718  *             result = []
19719  *             auxtag[2] = 0
19720  *             while s < (src.data + src.data_len):             # <<<<<<<<<<<<<<
19721  *                 # get tag
19722  *                 auxtag[0] = s[0]
19723  */
19724   while (1) {
19725     __pyx_t_1 = (__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->data_len));
19726     if (!__pyx_t_1) break;
19727
19728     /* "csamtools.pyx":2287
19729  *             while s < (src.data + src.data_len):
19730  *                 # get tag
19731  *                 auxtag[0] = s[0]             # <<<<<<<<<<<<<<
19732  *                 auxtag[1] = s[1]
19733  *                 s += 2
19734  */
19735     (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);
19736
19737     /* "csamtools.pyx":2288
19738  *                 # get tag
19739  *                 auxtag[0] = s[0]
19740  *                 auxtag[1] = s[1]             # <<<<<<<<<<<<<<
19741  *                 s += 2
19742  *                 auxtype = s[0]
19743  */
19744     (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);
19745
19746     /* "csamtools.pyx":2289
19747  *                 auxtag[0] = s[0]
19748  *                 auxtag[1] = s[1]
19749  *                 s += 2             # <<<<<<<<<<<<<<
19750  *                 auxtype = s[0]
19751  * 
19752  */
19753     __pyx_v_s = (__pyx_v_s + 2);
19754
19755     /* "csamtools.pyx":2290
19756  *                 auxtag[1] = s[1]
19757  *                 s += 2
19758  *                 auxtype = s[0]             # <<<<<<<<<<<<<<
19759  * 
19760  *                 if auxtype in ('c', 'C'):
19761  */
19762     __pyx_v_auxtype = (__pyx_v_s[0]);
19763
19764     /* "csamtools.pyx":2292
19765  *                 auxtype = s[0]
19766  * 
19767  *                 if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
19768  *                     value = <int>bam_aux2i(s)
19769  *                     s += 1
19770  */
19771     __pyx_t_3 = __pyx_v_auxtype;
19772     __pyx_t_1 = (__pyx_t_3 == 'c');
19773     if (!__pyx_t_1) {
19774       __pyx_t_4 = (__pyx_t_3 == 'C');
19775       __pyx_t_5 = __pyx_t_4;
19776     } else {
19777       __pyx_t_5 = __pyx_t_1;
19778     }
19779     __pyx_t_1 = __pyx_t_5;
19780     if (__pyx_t_1) {
19781
19782       /* "csamtools.pyx":2293
19783  * 
19784  *                 if auxtype in ('c', 'C'):
19785  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
19786  *                     s += 1
19787  *                 elif auxtype in ('s', 'S'):
19788  */
19789       __pyx_t_2 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19790       __Pyx_GOTREF(__pyx_t_2);
19791       __Pyx_DECREF(__pyx_v_value);
19792       __pyx_v_value = __pyx_t_2;
19793       __pyx_t_2 = 0;
19794
19795       /* "csamtools.pyx":2294
19796  *                 if auxtype in ('c', 'C'):
19797  *                     value = <int>bam_aux2i(s)
19798  *                     s += 1             # <<<<<<<<<<<<<<
19799  *                 elif auxtype in ('s', 'S'):
19800  *                     value = <int>bam_aux2i(s)
19801  */
19802       __pyx_v_s = (__pyx_v_s + 1);
19803       goto __pyx_L8;
19804     }
19805
19806     /* "csamtools.pyx":2295
19807  *                     value = <int>bam_aux2i(s)
19808  *                     s += 1
19809  *                 elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
19810  *                     value = <int>bam_aux2i(s)
19811  *                     s += 2
19812  */
19813     __pyx_t_3 = __pyx_v_auxtype;
19814     __pyx_t_1 = (__pyx_t_3 == 's');
19815     if (!__pyx_t_1) {
19816       __pyx_t_5 = (__pyx_t_3 == 'S');
19817       __pyx_t_4 = __pyx_t_5;
19818     } else {
19819       __pyx_t_4 = __pyx_t_1;
19820     }
19821     __pyx_t_1 = __pyx_t_4;
19822     if (__pyx_t_1) {
19823
19824       /* "csamtools.pyx":2296
19825  *                     s += 1
19826  *                 elif auxtype in ('s', 'S'):
19827  *                     value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
19828  *                     s += 2
19829  *                 elif auxtype in ('i', 'I'):
19830  */
19831       __pyx_t_2 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19832       __Pyx_GOTREF(__pyx_t_2);
19833       __Pyx_DECREF(__pyx_v_value);
19834       __pyx_v_value = __pyx_t_2;
19835       __pyx_t_2 = 0;
19836
19837       /* "csamtools.pyx":2297
19838  *                 elif auxtype in ('s', 'S'):
19839  *                     value = <int>bam_aux2i(s)
19840  *                     s += 2             # <<<<<<<<<<<<<<
19841  *                 elif auxtype in ('i', 'I'):
19842  *                     value = <float>bam_aux2i(s)
19843  */
19844       __pyx_v_s = (__pyx_v_s + 2);
19845       goto __pyx_L8;
19846     }
19847
19848     /* "csamtools.pyx":2298
19849  *                     value = <int>bam_aux2i(s)
19850  *                     s += 2
19851  *                 elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
19852  *                     value = <float>bam_aux2i(s)
19853  *                     s += 4
19854  */
19855     __pyx_t_3 = __pyx_v_auxtype;
19856     __pyx_t_1 = (__pyx_t_3 == 'i');
19857     if (!__pyx_t_1) {
19858       __pyx_t_4 = (__pyx_t_3 == 'I');
19859       __pyx_t_5 = __pyx_t_4;
19860     } else {
19861       __pyx_t_5 = __pyx_t_1;
19862     }
19863     __pyx_t_1 = __pyx_t_5;
19864     if (__pyx_t_1) {
19865
19866       /* "csamtools.pyx":2299
19867  *                     s += 2
19868  *                 elif auxtype in ('i', 'I'):
19869  *                     value = <float>bam_aux2i(s)             # <<<<<<<<<<<<<<
19870  *                     s += 4
19871  *                 elif auxtype == 'f':
19872  */
19873       __pyx_t_2 = PyFloat_FromDouble(((float)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19874       __Pyx_GOTREF(__pyx_t_2);
19875       __Pyx_DECREF(__pyx_v_value);
19876       __pyx_v_value = __pyx_t_2;
19877       __pyx_t_2 = 0;
19878
19879       /* "csamtools.pyx":2300
19880  *                 elif auxtype in ('i', 'I'):
19881  *                     value = <float>bam_aux2i(s)
19882  *                     s += 4             # <<<<<<<<<<<<<<
19883  *                 elif auxtype == 'f':
19884  *                     value = <float>bam_aux2f(s)
19885  */
19886       __pyx_v_s = (__pyx_v_s + 4);
19887       goto __pyx_L8;
19888     }
19889
19890     /* "csamtools.pyx":2301
19891  *                     value = <float>bam_aux2i(s)
19892  *                     s += 4
19893  *                 elif auxtype == 'f':             # <<<<<<<<<<<<<<
19894  *                     value = <float>bam_aux2f(s)
19895  *                     s += 4
19896  */
19897     __pyx_t_1 = (__pyx_v_auxtype == 'f');
19898     if (__pyx_t_1) {
19899
19900       /* "csamtools.pyx":2302
19901  *                     s += 4
19902  *                 elif auxtype == 'f':
19903  *                     value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
19904  *                     s += 4
19905  *                 elif auxtype == 'd':
19906  */
19907       __pyx_t_2 = PyFloat_FromDouble(bam_aux2f(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19908       __Pyx_GOTREF(__pyx_t_2);
19909       __Pyx_DECREF(__pyx_v_value);
19910       __pyx_v_value = __pyx_t_2;
19911       __pyx_t_2 = 0;
19912
19913       /* "csamtools.pyx":2303
19914  *                 elif auxtype == 'f':
19915  *                     value = <float>bam_aux2f(s)
19916  *                     s += 4             # <<<<<<<<<<<<<<
19917  *                 elif auxtype == 'd':
19918  *                     value = <double>bam_aux2d(s)
19919  */
19920       __pyx_v_s = (__pyx_v_s + 4);
19921       goto __pyx_L8;
19922     }
19923
19924     /* "csamtools.pyx":2304
19925  *                     value = <float>bam_aux2f(s)
19926  *                     s += 4
19927  *                 elif auxtype == 'd':             # <<<<<<<<<<<<<<
19928  *                     value = <double>bam_aux2d(s)
19929  *                     s += 8
19930  */
19931     __pyx_t_1 = (__pyx_v_auxtype == 'd');
19932     if (__pyx_t_1) {
19933
19934       /* "csamtools.pyx":2305
19935  *                     s += 4
19936  *                 elif auxtype == 'd':
19937  *                     value = <double>bam_aux2d(s)             # <<<<<<<<<<<<<<
19938  *                     s += 8
19939  *                 elif auxtype == 'A':
19940  */
19941       __pyx_t_2 = PyFloat_FromDouble(bam_aux2d(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19942       __Pyx_GOTREF(__pyx_t_2);
19943       __Pyx_DECREF(__pyx_v_value);
19944       __pyx_v_value = __pyx_t_2;
19945       __pyx_t_2 = 0;
19946
19947       /* "csamtools.pyx":2306
19948  *                 elif auxtype == 'd':
19949  *                     value = <double>bam_aux2d(s)
19950  *                     s += 8             # <<<<<<<<<<<<<<
19951  *                 elif auxtype == 'A':
19952  *                     value = "%c" % <char>bam_aux2A(s)
19953  */
19954       __pyx_v_s = (__pyx_v_s + 8);
19955       goto __pyx_L8;
19956     }
19957
19958     /* "csamtools.pyx":2307
19959  *                     value = <double>bam_aux2d(s)
19960  *                     s += 8
19961  *                 elif auxtype == 'A':             # <<<<<<<<<<<<<<
19962  *                     value = "%c" % <char>bam_aux2A(s)
19963  *                     s += 1
19964  */
19965     __pyx_t_1 = (__pyx_v_auxtype == 'A');
19966     if (__pyx_t_1) {
19967
19968       /* "csamtools.pyx":2308
19969  *                     s += 8
19970  *                 elif auxtype == 'A':
19971  *                     value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
19972  *                     s += 1
19973  *                 elif auxtype in ('Z', 'H'):
19974  */
19975       __pyx_t_2 = PyInt_FromLong(bam_aux2A(__pyx_v_s)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19976       __Pyx_GOTREF(__pyx_t_2);
19977       __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
19978       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
19979       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
19980       __Pyx_DECREF(__pyx_v_value);
19981       __pyx_v_value = ((PyObject *)__pyx_t_6);
19982       __pyx_t_6 = 0;
19983
19984       /* "csamtools.pyx":2309
19985  *                 elif auxtype == 'A':
19986  *                     value = "%c" % <char>bam_aux2A(s)
19987  *                     s += 1             # <<<<<<<<<<<<<<
19988  *                 elif auxtype in ('Z', 'H'):
19989  *                     value = <char*>bam_aux2Z(s)
19990  */
19991       __pyx_v_s = (__pyx_v_s + 1);
19992       goto __pyx_L8;
19993     }
19994
19995     /* "csamtools.pyx":2310
19996  *                     value = "%c" % <char>bam_aux2A(s)
19997  *                     s += 1
19998  *                 elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
19999  *                     value = <char*>bam_aux2Z(s)
20000  *                     # +1 for NULL terminated string
20001  */
20002     __pyx_t_3 = __pyx_v_auxtype;
20003     __pyx_t_1 = (__pyx_t_3 == 'Z');
20004     if (!__pyx_t_1) {
20005       __pyx_t_5 = (__pyx_t_3 == 'H');
20006       __pyx_t_4 = __pyx_t_5;
20007     } else {
20008       __pyx_t_4 = __pyx_t_1;
20009     }
20010     __pyx_t_1 = __pyx_t_4;
20011     if (__pyx_t_1) {
20012
20013       /* "csamtools.pyx":2311
20014  *                     s += 1
20015  *                 elif auxtype in ('Z', 'H'):
20016  *                     value = <char*>bam_aux2Z(s)             # <<<<<<<<<<<<<<
20017  *                     # +1 for NULL terminated string
20018  *                     s += len(value) + 1
20019  */
20020       __pyx_t_6 = PyBytes_FromString(bam_aux2Z(__pyx_v_s)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20021       __Pyx_GOTREF(((PyObject *)__pyx_t_6));
20022       __Pyx_DECREF(__pyx_v_value);
20023       __pyx_v_value = ((PyObject *)__pyx_t_6);
20024       __pyx_t_6 = 0;
20025
20026       /* "csamtools.pyx":2313
20027  *                     value = <char*>bam_aux2Z(s)
20028  *                     # +1 for NULL terminated string
20029  *                     s += len(value) + 1             # <<<<<<<<<<<<<<
20030  *                  #
20031  *                 s += 1
20032  */
20033       __pyx_t_7 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20034       __pyx_v_s = (__pyx_v_s + (__pyx_t_7 + 1));
20035       goto __pyx_L8;
20036     }
20037     __pyx_L8:;
20038
20039     /* "csamtools.pyx":2315
20040  *                     s += len(value) + 1
20041  *                  #
20042  *                 s += 1             # <<<<<<<<<<<<<<
20043  * 
20044  *                 result.append( (auxtag, value) )
20045  */
20046     __pyx_v_s = (__pyx_v_s + 1);
20047
20048     /* "csamtools.pyx":2317
20049  *                 s += 1
20050  * 
20051  *                 result.append( (auxtag, value) )             # <<<<<<<<<<<<<<
20052  * 
20053  *             return result
20054  */
20055     if (unlikely(__pyx_v_result == Py_None)) {
20056       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
20057     }
20058     __pyx_t_6 = PyBytes_FromString(__pyx_v_auxtag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20059     __Pyx_GOTREF(((PyObject *)__pyx_t_6));
20060     __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20061     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
20062     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_6));
20063     __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
20064     __Pyx_INCREF(__pyx_v_value);
20065     PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_value);
20066     __Pyx_GIVEREF(__pyx_v_value);
20067     __pyx_t_6 = 0;
20068     __pyx_t_8 = PyList_Append(__pyx_v_result, ((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20069     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
20070   }
20071
20072   /* "csamtools.pyx":2319
20073  *                 result.append( (auxtag, value) )
20074  * 
20075  *             return result             # <<<<<<<<<<<<<<
20076  * 
20077  *         def __set__(self, tags):
20078  */
20079   __Pyx_XDECREF(__pyx_r);
20080   __Pyx_INCREF(((PyObject *)__pyx_v_result));
20081   __pyx_r = ((PyObject *)__pyx_v_result);
20082   goto __pyx_L0;
20083
20084   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20085   goto __pyx_L0;
20086   __pyx_L1_error:;
20087   __Pyx_XDECREF(__pyx_t_2);
20088   __Pyx_XDECREF(__pyx_t_6);
20089   __Pyx_AddTraceback("csamtools.AlignedRead.tags.__get__");
20090   __pyx_r = NULL;
20091   __pyx_L0:;
20092   __Pyx_DECREF(__pyx_v_result);
20093   __Pyx_DECREF(__pyx_v_value);
20094   __Pyx_XGIVEREF(__pyx_r);
20095   __Pyx_TraceReturn(__pyx_r);
20096   __Pyx_RefNannyFinishContext();
20097   return __pyx_r;
20098 }
20099
20100 /* "csamtools.pyx":2321
20101  *             return result
20102  * 
20103  *         def __set__(self, tags):             # <<<<<<<<<<<<<<
20104  *             cdef char * ctag
20105  *             cdef bam1_t * src
20106  */
20107
20108 static int __pyx_pf_9csamtools_11AlignedRead_4tags_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
20109 static int __pyx_pf_9csamtools_11AlignedRead_4tags_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
20110   bam1_t *__pyx_v_src;
20111   uint8_t *__pyx_v_s;
20112   char *__pyx_v_temp;
20113   int __pyx_v_max_size;
20114   int __pyx_v_size;
20115   int __pyx_v_offset;
20116   PyObject *__pyx_v_buffer;
20117   PyObject *__pyx_v_pytag;
20118   PyObject *__pyx_v_value;
20119   PyObject *__pyx_v_t;
20120   PyObject *__pyx_v_fmt;
20121   PyObject *__pyx_v_pytype;
20122   int __pyx_r;
20123   PyObject *__pyx_t_1 = NULL;
20124   int __pyx_t_2;
20125   PyObject *__pyx_t_3 = NULL;
20126   PyObject *__pyx_t_4 = NULL;
20127   Py_ssize_t __pyx_t_5;
20128   PyObject *__pyx_t_6 = NULL;
20129   PyObject *__pyx_t_7 = NULL;
20130   Py_ssize_t __pyx_t_8;
20131   int __pyx_t_9;
20132   PyObject *__pyx_t_10 = NULL;
20133   char *__pyx_t_11;
20134   __Pyx_TraceDeclarations
20135   __Pyx_RefNannySetupContext("__set__");
20136   __Pyx_TraceCall("__set__", __pyx_f[0], 2321);
20137   __pyx_v_buffer = Py_None; __Pyx_INCREF(Py_None);
20138   __pyx_v_pytag = Py_None; __Pyx_INCREF(Py_None);
20139   __pyx_v_value = Py_None; __Pyx_INCREF(Py_None);
20140   __pyx_v_t = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
20141   __pyx_v_fmt = Py_None; __Pyx_INCREF(Py_None);
20142   __pyx_v_pytype = Py_None; __Pyx_INCREF(Py_None);
20143
20144   /* "csamtools.pyx":2330
20145  *             cdef int max_size, size, offset
20146  * 
20147  *             src = self._delegate             # <<<<<<<<<<<<<<
20148  *             max_size = 4000
20149  *             offset = 0
20150  */
20151   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
20152
20153   /* "csamtools.pyx":2331
20154  * 
20155  *             src = self._delegate
20156  *             max_size = 4000             # <<<<<<<<<<<<<<
20157  *             offset = 0
20158  * 
20159  */
20160   __pyx_v_max_size = 4000;
20161
20162   /* "csamtools.pyx":2332
20163  *             src = self._delegate
20164  *             max_size = 4000
20165  *             offset = 0             # <<<<<<<<<<<<<<
20166  * 
20167  *             if tags != None:
20168  */
20169   __pyx_v_offset = 0;
20170
20171   /* "csamtools.pyx":2334
20172  *             offset = 0
20173  * 
20174  *             if tags != None:             # <<<<<<<<<<<<<<
20175  * 
20176  *                 # map samtools code to python.struct code and byte size
20177  */
20178   __pyx_t_1 = PyObject_RichCompare(__pyx_v_tags, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20179   __Pyx_GOTREF(__pyx_t_1);
20180   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20181   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20182   if (__pyx_t_2) {
20183
20184     /* "csamtools.pyx":2337
20185  * 
20186  *                 # map samtools code to python.struct code and byte size
20187  *                 buffer = ctypes.create_string_buffer(max_size)             # <<<<<<<<<<<<<<
20188  * 
20189  *                 for pytag, value in tags:
20190  */
20191     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ctypes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20192     __Pyx_GOTREF(__pyx_t_1);
20193     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_122); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20194     __Pyx_GOTREF(__pyx_t_3);
20195     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20196     __pyx_t_1 = PyInt_FromLong(__pyx_v_max_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20197     __Pyx_GOTREF(__pyx_t_1);
20198     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20199     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
20200     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
20201     __Pyx_GIVEREF(__pyx_t_1);
20202     __pyx_t_1 = 0;
20203     __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20204     __Pyx_GOTREF(__pyx_t_1);
20205     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
20206     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
20207     __Pyx_DECREF(__pyx_v_buffer);
20208     __pyx_v_buffer = __pyx_t_1;
20209     __pyx_t_1 = 0;
20210
20211     /* "csamtools.pyx":2339
20212  *                 buffer = ctypes.create_string_buffer(max_size)
20213  * 
20214  *                 for pytag, value in tags:             # <<<<<<<<<<<<<<
20215  *                     t = type(value)
20216  *                     if t == types.FloatType:
20217  */
20218     if (PyList_CheckExact(__pyx_v_tags) || PyTuple_CheckExact(__pyx_v_tags)) {
20219       __pyx_t_5 = 0; __pyx_t_1 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_1);
20220     } else {
20221       __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20222       __Pyx_GOTREF(__pyx_t_1);
20223     }
20224     for (;;) {
20225       if (likely(PyList_CheckExact(__pyx_t_1))) {
20226         if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
20227         __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
20228       } else if (likely(PyTuple_CheckExact(__pyx_t_1))) {
20229         if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
20230         __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
20231       } else {
20232         __pyx_t_4 = PyIter_Next(__pyx_t_1);
20233         if (!__pyx_t_4) {
20234           if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20235           break;
20236         }
20237         __Pyx_GOTREF(__pyx_t_4);
20238       }
20239       if (PyTuple_CheckExact(__pyx_t_4) && likely(PyTuple_GET_SIZE(__pyx_t_4) == 2)) {
20240         PyObject* tuple = __pyx_t_4;
20241         __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3);
20242         __pyx_t_6 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_6);
20243         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20244         __Pyx_DECREF(__pyx_v_pytag);
20245         __pyx_v_pytag = __pyx_t_3;
20246         __pyx_t_3 = 0;
20247         __Pyx_DECREF(__pyx_v_value);
20248         __pyx_v_value = __pyx_t_6;
20249         __pyx_t_6 = 0;
20250       } else {
20251         __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20252         __Pyx_GOTREF(__pyx_t_7);
20253         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20254         __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_7, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20255         __Pyx_GOTREF(__pyx_t_3);
20256         __pyx_t_6 = __Pyx_UnpackItem(__pyx_t_7, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20257         __Pyx_GOTREF(__pyx_t_6);
20258         if (__Pyx_EndUnpack(__pyx_t_7, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20259         __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
20260         __Pyx_DECREF(__pyx_v_pytag);
20261         __pyx_v_pytag = __pyx_t_3;
20262         __pyx_t_3 = 0;
20263         __Pyx_DECREF(__pyx_v_value);
20264         __pyx_v_value = __pyx_t_6;
20265         __pyx_t_6 = 0;
20266       }
20267
20268       /* "csamtools.pyx":2340
20269  * 
20270  *                 for pytag, value in tags:
20271  *                     t = type(value)             # <<<<<<<<<<<<<<
20272  *                     if t == types.FloatType:
20273  *                         fmt, pytype = "<cccf", 'f'
20274  */
20275       __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
20276       __Pyx_DECREF(((PyObject *)__pyx_v_t));
20277       __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));
20278
20279       /* "csamtools.pyx":2341
20280  *                 for pytag, value in tags:
20281  *                     t = type(value)
20282  *                     if t == types.FloatType:             # <<<<<<<<<<<<<<
20283  *                         fmt, pytype = "<cccf", 'f'
20284  *                     elif t == types.IntType:
20285  */
20286       __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20287       __Pyx_GOTREF(__pyx_t_4);
20288       __pyx_t_6 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__FloatType); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20289       __Pyx_GOTREF(__pyx_t_6);
20290       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20291       __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_t), __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20292       __Pyx_GOTREF(__pyx_t_4);
20293       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20294       __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20295       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20296       if (__pyx_t_2) {
20297
20298         /* "csamtools.pyx":2342
20299  *                     t = type(value)
20300  *                     if t == types.FloatType:
20301  *                         fmt, pytype = "<cccf", 'f'             # <<<<<<<<<<<<<<
20302  *                     elif t == types.IntType:
20303  *                         if value < 0:
20304  */
20305         __pyx_t_4 = ((PyObject *)__pyx_kp_s_123);
20306         __Pyx_INCREF(__pyx_t_4);
20307         __pyx_t_6 = ((PyObject *)__pyx_n_s__f);
20308         __Pyx_INCREF(__pyx_t_6);
20309         __Pyx_DECREF(__pyx_v_fmt);
20310         __pyx_v_fmt = __pyx_t_4;
20311         __pyx_t_4 = 0;
20312         __Pyx_DECREF(__pyx_v_pytype);
20313         __pyx_v_pytype = __pyx_t_6;
20314         __pyx_t_6 = 0;
20315         goto __pyx_L8;
20316       }
20317
20318       /* "csamtools.pyx":2343
20319  *                     if t == types.FloatType:
20320  *                         fmt, pytype = "<cccf", 'f'
20321  *                     elif t == types.IntType:             # <<<<<<<<<<<<<<
20322  *                         if value < 0:
20323  *                             if value >= -127: fmt, pytype = "<cccb", 'c'
20324  */
20325       __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__types); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20326       __Pyx_GOTREF(__pyx_t_6);
20327       __pyx_t_4 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__IntType); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20328       __Pyx_GOTREF(__pyx_t_4);
20329       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20330       __pyx_t_6 = PyObject_RichCompare(((PyObject *)__pyx_v_t), __pyx_t_4, Py_EQ); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20331       __Pyx_GOTREF(__pyx_t_6);
20332       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20333       __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20334       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20335       if (__pyx_t_2) {
20336
20337         /* "csamtools.pyx":2344
20338  *                         fmt, pytype = "<cccf", 'f'
20339  *                     elif t == types.IntType:
20340  *                         if value < 0:             # <<<<<<<<<<<<<<
20341  *                             if value >= -127: fmt, pytype = "<cccb", 'c'
20342  *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
20343  */
20344         __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20345         __Pyx_GOTREF(__pyx_t_6);
20346         __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20347         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20348         if (__pyx_t_2) {
20349
20350           /* "csamtools.pyx":2345
20351  *                     elif t == types.IntType:
20352  *                         if value < 0:
20353  *                             if value >= -127: fmt, pytype = "<cccb", 'c'             # <<<<<<<<<<<<<<
20354  *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
20355  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20356  */
20357           __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_127, Py_GE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20358           __Pyx_GOTREF(__pyx_t_6);
20359           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20360           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20361           if (__pyx_t_2) {
20362             __pyx_t_6 = ((PyObject *)__pyx_kp_s_124);
20363             __Pyx_INCREF(__pyx_t_6);
20364             __pyx_t_4 = ((PyObject *)__pyx_n_s__c);
20365             __Pyx_INCREF(__pyx_t_4);
20366             __Pyx_DECREF(__pyx_v_fmt);
20367             __pyx_v_fmt = __pyx_t_6;
20368             __pyx_t_6 = 0;
20369             __Pyx_DECREF(__pyx_v_pytype);
20370             __pyx_v_pytype = __pyx_t_4;
20371             __pyx_t_4 = 0;
20372             goto __pyx_L10;
20373           }
20374
20375           /* "csamtools.pyx":2346
20376  *                         if value < 0:
20377  *                             if value >= -127: fmt, pytype = "<cccb", 'c'
20378  *                             elif value >= -32767: fmt, pytype = "<ccch", 's'             # <<<<<<<<<<<<<<
20379  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20380  *                             else: fmt, pytype = "<ccci", 'i'[0]
20381  */
20382           __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32767, Py_GE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20383           __Pyx_GOTREF(__pyx_t_4);
20384           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20385           __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20386           if (__pyx_t_2) {
20387             __pyx_t_4 = ((PyObject *)__pyx_kp_s_125);
20388             __Pyx_INCREF(__pyx_t_4);
20389             __pyx_t_6 = ((PyObject *)__pyx_n_s__s);
20390             __Pyx_INCREF(__pyx_t_6);
20391             __Pyx_DECREF(__pyx_v_fmt);
20392             __pyx_v_fmt = __pyx_t_4;
20393             __pyx_t_4 = 0;
20394             __Pyx_DECREF(__pyx_v_pytype);
20395             __pyx_v_pytype = __pyx_t_6;
20396             __pyx_t_6 = 0;
20397             goto __pyx_L10;
20398           }
20399
20400           /* "csamtools.pyx":2347
20401  *                             if value >= -127: fmt, pytype = "<cccb", 'c'
20402  *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
20403  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
20404  *                             else: fmt, pytype = "<ccci", 'i'[0]
20405  *                         else:
20406  */
20407           __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20408           __Pyx_GOTREF(__pyx_t_6);
20409           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20410           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20411           if (__pyx_t_2) {
20412             __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_126), __pyx_v_value); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20413             __Pyx_GOTREF(((PyObject *)__pyx_t_6));
20414             __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20415             __Pyx_GOTREF(((PyObject *)__pyx_t_4));
20416             PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6));
20417             __Pyx_GIVEREF(((PyObject *)__pyx_t_6));
20418             __pyx_t_6 = 0;
20419             __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20420             __Pyx_GOTREF(__pyx_t_6);
20421             __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
20422             __Pyx_Raise(__pyx_t_6, 0, 0);
20423             __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20424             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20425             goto __pyx_L10;
20426           }
20427           /*else*/ {
20428
20429             /* "csamtools.pyx":2348
20430  *                             elif value >= -32767: fmt, pytype = "<ccch", 's'
20431  *                             elif value < -2147483648: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20432  *                             else: fmt, pytype = "<ccci", 'i'[0]             # <<<<<<<<<<<<<<
20433  *                         else:
20434  *                             if value <= 255: fmt, pytype = "<cccB", 'C'
20435  */
20436             __pyx_t_6 = ((PyObject *)__pyx_kp_s_127);
20437             __Pyx_INCREF(__pyx_t_6);
20438             __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_n_s__i), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20439             __Pyx_GOTREF(__pyx_t_4);
20440             __Pyx_DECREF(__pyx_v_fmt);
20441             __pyx_v_fmt = __pyx_t_6;
20442             __pyx_t_6 = 0;
20443             __Pyx_DECREF(__pyx_v_pytype);
20444             __pyx_v_pytype = __pyx_t_4;
20445             __pyx_t_4 = 0;
20446           }
20447           __pyx_L10:;
20448           goto __pyx_L9;
20449         }
20450         /*else*/ {
20451
20452           /* "csamtools.pyx":2350
20453  *                             else: fmt, pytype = "<ccci", 'i'[0]
20454  *                         else:
20455  *                             if value <= 255: fmt, pytype = "<cccB", 'C'             # <<<<<<<<<<<<<<
20456  *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
20457  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20458  */
20459           __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_255, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20460           __Pyx_GOTREF(__pyx_t_4);
20461           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20462           __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20463           if (__pyx_t_2) {
20464             __pyx_t_4 = ((PyObject *)__pyx_kp_s_128);
20465             __Pyx_INCREF(__pyx_t_4);
20466             __pyx_t_6 = ((PyObject *)__pyx_n_s__C);
20467             __Pyx_INCREF(__pyx_t_6);
20468             __Pyx_DECREF(__pyx_v_fmt);
20469             __pyx_v_fmt = __pyx_t_4;
20470             __pyx_t_4 = 0;
20471             __Pyx_DECREF(__pyx_v_pytype);
20472             __pyx_v_pytype = __pyx_t_6;
20473             __pyx_t_6 = 0;
20474             goto __pyx_L11;
20475           }
20476
20477           /* "csamtools.pyx":2351
20478  *                         else:
20479  *                             if value <= 255: fmt, pytype = "<cccB", 'C'
20480  *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'             # <<<<<<<<<<<<<<
20481  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20482  *                             else: fmt, pytype = "<cccI", 'I'
20483  */
20484           __pyx_t_6 = PyObject_RichCompare(__pyx_v_value, __pyx_int_65535, Py_LE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20485           __Pyx_GOTREF(__pyx_t_6);
20486           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20487           __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20488           if (__pyx_t_2) {
20489             __pyx_t_6 = ((PyObject *)__pyx_kp_s_129);
20490             __Pyx_INCREF(__pyx_t_6);
20491             __pyx_t_4 = ((PyObject *)__pyx_n_s__S);
20492             __Pyx_INCREF(__pyx_t_4);
20493             __Pyx_DECREF(__pyx_v_fmt);
20494             __pyx_v_fmt = __pyx_t_6;
20495             __pyx_t_6 = 0;
20496             __Pyx_DECREF(__pyx_v_pytype);
20497             __pyx_v_pytype = __pyx_t_4;
20498             __pyx_t_4 = 0;
20499             goto __pyx_L11;
20500           }
20501
20502           /* "csamtools.pyx":2352
20503  *                             if value <= 255: fmt, pytype = "<cccB", 'C'
20504  *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
20505  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )             # <<<<<<<<<<<<<<
20506  *                             else: fmt, pytype = "<cccI", 'I'
20507  *                     else:
20508  */
20509           __pyx_t_4 = PyObject_RichCompare(__pyx_v_value, __pyx_int_4294967295, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20510           __Pyx_GOTREF(__pyx_t_4);
20511           __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20512           __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20513           if (__pyx_t_2) {
20514             __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_126), __pyx_v_value); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20515             __Pyx_GOTREF(((PyObject *)__pyx_t_4));
20516             __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20517             __Pyx_GOTREF(((PyObject *)__pyx_t_6));
20518             PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_4));
20519             __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
20520             __pyx_t_4 = 0;
20521             __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20522             __Pyx_GOTREF(__pyx_t_4);
20523             __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
20524             __Pyx_Raise(__pyx_t_4, 0, 0);
20525             __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20526             {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20527             goto __pyx_L11;
20528           }
20529           /*else*/ {
20530
20531             /* "csamtools.pyx":2353
20532  *                             elif value <= 65535: fmt, pytype = "<cccH", 'S'
20533  *                             elif value > 4294967295: raise ValueError( "integer %i out of range of BAM/SAM specification" % value )
20534  *                             else: fmt, pytype = "<cccI", 'I'             # <<<<<<<<<<<<<<
20535  *                     else:
20536  *                         # Note: hex strings (H) are not supported yet
20537  */
20538             __pyx_t_4 = ((PyObject *)__pyx_kp_s_130);
20539             __Pyx_INCREF(__pyx_t_4);
20540             __pyx_t_6 = ((PyObject *)__pyx_n_s__I);
20541             __Pyx_INCREF(__pyx_t_6);
20542             __Pyx_DECREF(__pyx_v_fmt);
20543             __pyx_v_fmt = __pyx_t_4;
20544             __pyx_t_4 = 0;
20545             __Pyx_DECREF(__pyx_v_pytype);
20546             __pyx_v_pytype = __pyx_t_6;
20547             __pyx_t_6 = 0;
20548           }
20549           __pyx_L11:;
20550         }
20551         __pyx_L9:;
20552         goto __pyx_L8;
20553       }
20554       /*else*/ {
20555
20556         /* "csamtools.pyx":2356
20557  *                     else:
20558  *                         # Note: hex strings (H) are not supported yet
20559  *                         if len(value) == 1:             # <<<<<<<<<<<<<<
20560  *                             fmt, pytype = "<cccc", 'A'
20561  *                         else:
20562  */
20563         __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20564         __pyx_t_2 = (__pyx_t_8 == 1);
20565         if (__pyx_t_2) {
20566
20567           /* "csamtools.pyx":2357
20568  *                         # Note: hex strings (H) are not supported yet
20569  *                         if len(value) == 1:
20570  *                             fmt, pytype = "<cccc", 'A'             # <<<<<<<<<<<<<<
20571  *                         else:
20572  *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'
20573  */
20574           __pyx_t_6 = ((PyObject *)__pyx_kp_s_131);
20575           __Pyx_INCREF(__pyx_t_6);
20576           __pyx_t_4 = ((PyObject *)__pyx_n_s__A);
20577           __Pyx_INCREF(__pyx_t_4);
20578           __Pyx_DECREF(__pyx_v_fmt);
20579           __pyx_v_fmt = __pyx_t_6;
20580           __pyx_t_6 = 0;
20581           __Pyx_DECREF(__pyx_v_pytype);
20582           __pyx_v_pytype = __pyx_t_4;
20583           __pyx_t_4 = 0;
20584           goto __pyx_L12;
20585         }
20586         /*else*/ {
20587
20588           /* "csamtools.pyx":2359
20589  *                             fmt, pytype = "<cccc", 'A'
20590  *                         else:
20591  *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'             # <<<<<<<<<<<<<<
20592  * 
20593  *                     size = struct.calcsize(fmt)
20594  */
20595           __pyx_t_8 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20596           __pyx_t_4 = PyInt_FromSsize_t((__pyx_t_8 + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20597           __Pyx_GOTREF(__pyx_t_4);
20598           __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_132), __pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20599           __Pyx_GOTREF(((PyObject *)__pyx_t_6));
20600           __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20601           __pyx_t_4 = ((PyObject *)__pyx_n_s__Z);
20602           __Pyx_INCREF(__pyx_t_4);
20603           __Pyx_DECREF(__pyx_v_fmt);
20604           __pyx_v_fmt = ((PyObject *)__pyx_t_6);
20605           __pyx_t_6 = 0;
20606           __Pyx_DECREF(__pyx_v_pytype);
20607           __pyx_v_pytype = __pyx_t_4;
20608           __pyx_t_4 = 0;
20609         }
20610         __pyx_L12:;
20611       }
20612       __pyx_L8:;
20613
20614       /* "csamtools.pyx":2361
20615  *                             fmt, pytype = "<ccc%is" % (len(value)+1), 'Z'
20616  * 
20617  *                     size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
20618  *                     if offset + size > max_size:
20619  *                         raise NotImplementedError("tags field too large")
20620  */
20621       __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20622       __Pyx_GOTREF(__pyx_t_4);
20623       __pyx_t_6 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__calcsize); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20624       __Pyx_GOTREF(__pyx_t_6);
20625       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20626       __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20627       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
20628       __Pyx_INCREF(__pyx_v_fmt);
20629       PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fmt);
20630       __Pyx_GIVEREF(__pyx_v_fmt);
20631       __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20632       __Pyx_GOTREF(__pyx_t_3);
20633       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
20634       __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
20635       __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20636       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
20637       __pyx_v_size = __pyx_t_9;
20638
20639       /* "csamtools.pyx":2362
20640  * 
20641  *                     size = struct.calcsize(fmt)
20642  *                     if offset + size > max_size:             # <<<<<<<<<<<<<<
20643  *                         raise NotImplementedError("tags field too large")
20644  * 
20645  */
20646       __pyx_t_2 = ((__pyx_v_offset + __pyx_v_size) > __pyx_v_max_size);
20647       if (__pyx_t_2) {
20648
20649         /* "csamtools.pyx":2363
20650  *                     size = struct.calcsize(fmt)
20651  *                     if offset + size > max_size:
20652  *                         raise NotImplementedError("tags field too large")             # <<<<<<<<<<<<<<
20653  * 
20654  *                     struct.pack_into( fmt,
20655  */
20656         __pyx_t_3 = PyObject_Call(__pyx_builtin_NotImplementedError, ((PyObject *)__pyx_k_tuple_134), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20657         __Pyx_GOTREF(__pyx_t_3);
20658         __Pyx_Raise(__pyx_t_3, 0, 0);
20659         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
20660         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20661         goto __pyx_L13;
20662       }
20663       __pyx_L13:;
20664
20665       /* "csamtools.pyx":2365
20666  *                         raise NotImplementedError("tags field too large")
20667  * 
20668  *                     struct.pack_into( fmt,             # <<<<<<<<<<<<<<
20669  *                                       buffer,
20670  *                                       offset,
20671  */
20672       __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__struct); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20673       __Pyx_GOTREF(__pyx_t_3);
20674       __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__pack_into); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20675       __Pyx_GOTREF(__pyx_t_4);
20676       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
20677
20678       /* "csamtools.pyx":2367
20679  *                     struct.pack_into( fmt,
20680  *                                       buffer,
20681  *                                       offset,             # <<<<<<<<<<<<<<
20682  *                                       pytag[0],
20683  *                                       pytag[1],
20684  */
20685       __pyx_t_3 = PyInt_FromLong(__pyx_v_offset); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20686       __Pyx_GOTREF(__pyx_t_3);
20687
20688       /* "csamtools.pyx":2368
20689  *                                       buffer,
20690  *                                       offset,
20691  *                                       pytag[0],             # <<<<<<<<<<<<<<
20692  *                                       pytag[1],
20693  *                                       pytype,
20694  */
20695       __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_pytag, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20696       __Pyx_GOTREF(__pyx_t_6);
20697
20698       /* "csamtools.pyx":2369
20699  *                                       offset,
20700  *                                       pytag[0],
20701  *                                       pytag[1],             # <<<<<<<<<<<<<<
20702  *                                       pytype,
20703  *                                       value )
20704  */
20705       __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_pytag, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20706       __Pyx_GOTREF(__pyx_t_7);
20707
20708       /* "csamtools.pyx":2371
20709  *                                       pytag[1],
20710  *                                       pytype,
20711  *                                       value )             # <<<<<<<<<<<<<<
20712  *                     offset += size
20713  * 
20714  */
20715       __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20716       __Pyx_GOTREF(((PyObject *)__pyx_t_10));
20717       __Pyx_INCREF(__pyx_v_fmt);
20718       PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_fmt);
20719       __Pyx_GIVEREF(__pyx_v_fmt);
20720       __Pyx_INCREF(__pyx_v_buffer);
20721       PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_buffer);
20722       __Pyx_GIVEREF(__pyx_v_buffer);
20723       PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3);
20724       __Pyx_GIVEREF(__pyx_t_3);
20725       PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_6);
20726       __Pyx_GIVEREF(__pyx_t_6);
20727       PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_7);
20728       __Pyx_GIVEREF(__pyx_t_7);
20729       __Pyx_INCREF(__pyx_v_pytype);
20730       PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_v_pytype);
20731       __Pyx_GIVEREF(__pyx_v_pytype);
20732       __Pyx_INCREF(__pyx_v_value);
20733       PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_v_value);
20734       __Pyx_GIVEREF(__pyx_v_value);
20735       __pyx_t_3 = 0;
20736       __pyx_t_6 = 0;
20737       __pyx_t_7 = 0;
20738       __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20739       __Pyx_GOTREF(__pyx_t_7);
20740       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
20741       __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
20742       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
20743
20744       /* "csamtools.pyx":2372
20745  *                                       pytype,
20746  *                                       value )
20747  *                     offset += size             # <<<<<<<<<<<<<<
20748  * 
20749  *             # delete the old data and allocate new
20750  */
20751       __pyx_v_offset = (__pyx_v_offset + __pyx_v_size);
20752     }
20753     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20754     goto __pyx_L5;
20755   }
20756   __pyx_L5:;
20757
20758   /* "csamtools.pyx":2380
20759  *                               src.l_aux,
20760  *                               offset,
20761  *                               bam1_aux( src ) )             # <<<<<<<<<<<<<<
20762  * 
20763  *             src.l_aux = offset
20764  */
20765   pysam_bam_update(__pyx_v_src, __pyx_v_src->l_aux, __pyx_v_offset, bam1_aux(__pyx_v_src));
20766
20767   /* "csamtools.pyx":2382
20768  *                               bam1_aux( src ) )
20769  * 
20770  *             src.l_aux = offset             # <<<<<<<<<<<<<<
20771  * 
20772  *             # copy data only if there is any
20773  */
20774   __pyx_v_src->l_aux = __pyx_v_offset;
20775
20776   /* "csamtools.pyx":2385
20777  * 
20778  *             # copy data only if there is any
20779  *             if offset != 0:             # <<<<<<<<<<<<<<
20780  * 
20781  *                 # get location of new data
20782  */
20783   __pyx_t_2 = (__pyx_v_offset != 0);
20784   if (__pyx_t_2) {
20785
20786     /* "csamtools.pyx":2388
20787  * 
20788  *                 # get location of new data
20789  *                 s = bam1_aux( src )             # <<<<<<<<<<<<<<
20790  * 
20791  *                 # check if there is direct path from buffer.raw to tmp
20792  */
20793     __pyx_v_s = bam1_aux(__pyx_v_src);
20794
20795     /* "csamtools.pyx":2391
20796  * 
20797  *                 # check if there is direct path from buffer.raw to tmp
20798  *                 temp = buffer.raw             # <<<<<<<<<<<<<<
20799  *                 memcpy( s, temp, offset )
20800  * 
20801  */
20802     __pyx_t_1 = PyObject_GetAttr(__pyx_v_buffer, __pyx_n_s__raw); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20803     __Pyx_GOTREF(__pyx_t_1);
20804     __pyx_t_11 = PyBytes_AsString(__pyx_t_1); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20805     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
20806     __pyx_v_temp = __pyx_t_11;
20807
20808     /* "csamtools.pyx":2392
20809  *                 # check if there is direct path from buffer.raw to tmp
20810  *                 temp = buffer.raw
20811  *                 memcpy( s, temp, offset )             # <<<<<<<<<<<<<<
20812  * 
20813  *     property flag:
20814  */
20815     memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_offset);
20816     goto __pyx_L14;
20817   }
20818   __pyx_L14:;
20819
20820   __pyx_r = 0;
20821   goto __pyx_L0;
20822   __pyx_L1_error:;
20823   __Pyx_XDECREF(__pyx_t_1);
20824   __Pyx_XDECREF(__pyx_t_3);
20825   __Pyx_XDECREF(__pyx_t_4);
20826   __Pyx_XDECREF(__pyx_t_6);
20827   __Pyx_XDECREF(__pyx_t_7);
20828   __Pyx_XDECREF(__pyx_t_10);
20829   __Pyx_AddTraceback("csamtools.AlignedRead.tags.__set__");
20830   __pyx_r = -1;
20831   __pyx_L0:;
20832   __Pyx_DECREF(__pyx_v_buffer);
20833   __Pyx_DECREF(__pyx_v_pytag);
20834   __Pyx_DECREF(__pyx_v_value);
20835   __Pyx_DECREF(__pyx_v_t);
20836   __Pyx_DECREF(__pyx_v_fmt);
20837   __Pyx_DECREF(__pyx_v_pytype);
20838   __Pyx_TraceReturn(Py_None);
20839   __Pyx_RefNannyFinishContext();
20840   return __pyx_r;
20841 }
20842
20843 /* "csamtools.pyx":2396
20844  *     property flag:
20845  *         """properties flag"""
20846  *         def __get__(self): return self._delegate.core.flag             # <<<<<<<<<<<<<<
20847  *         def __set__(self, flag): self._delegate.core.flag = flag
20848  * 
20849  */
20850
20851 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4flag___get__(PyObject *__pyx_v_self); /*proto*/
20852 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4flag___get__(PyObject *__pyx_v_self) {
20853   PyObject *__pyx_r = NULL;
20854   PyObject *__pyx_t_1 = NULL;
20855   __Pyx_TraceDeclarations
20856   __Pyx_RefNannySetupContext("__get__");
20857   __Pyx_TraceCall("__get__", __pyx_f[0], 2396);
20858   __Pyx_XDECREF(__pyx_r);
20859   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20860   __Pyx_GOTREF(__pyx_t_1);
20861   __pyx_r = __pyx_t_1;
20862   __pyx_t_1 = 0;
20863   goto __pyx_L0;
20864
20865   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20866   goto __pyx_L0;
20867   __pyx_L1_error:;
20868   __Pyx_XDECREF(__pyx_t_1);
20869   __Pyx_AddTraceback("csamtools.AlignedRead.flag.__get__");
20870   __pyx_r = NULL;
20871   __pyx_L0:;
20872   __Pyx_XGIVEREF(__pyx_r);
20873   __Pyx_TraceReturn(__pyx_r);
20874   __Pyx_RefNannyFinishContext();
20875   return __pyx_r;
20876 }
20877
20878 /* "csamtools.pyx":2397
20879  *         """properties flag"""
20880  *         def __get__(self): return self._delegate.core.flag
20881  *         def __set__(self, flag): self._delegate.core.flag = flag             # <<<<<<<<<<<<<<
20882  * 
20883  *     property rname:
20884  */
20885
20886 static int __pyx_pf_9csamtools_11AlignedRead_4flag_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
20887 static int __pyx_pf_9csamtools_11AlignedRead_4flag_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
20888   int __pyx_r;
20889   uint32_t __pyx_t_1;
20890   __Pyx_TraceDeclarations
20891   __Pyx_RefNannySetupContext("__set__");
20892   __Pyx_TraceCall("__set__", __pyx_f[0], 2397);
20893   __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 = 2397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20894   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = __pyx_t_1;
20895
20896   __pyx_r = 0;
20897   goto __pyx_L0;
20898   __pyx_L1_error:;
20899   __Pyx_AddTraceback("csamtools.AlignedRead.flag.__set__");
20900   __pyx_r = -1;
20901   __pyx_L0:;
20902   __Pyx_TraceReturn(Py_None);
20903   __Pyx_RefNannyFinishContext();
20904   return __pyx_r;
20905 }
20906
20907 /* "csamtools.pyx":2415
20908  * 
20909  *         """
20910  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
20911  *         def __set__(self, tid): self._delegate.core.tid = tid
20912  * 
20913  */
20914
20915 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rname___get__(PyObject *__pyx_v_self); /*proto*/
20916 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rname___get__(PyObject *__pyx_v_self) {
20917   PyObject *__pyx_r = NULL;
20918   PyObject *__pyx_t_1 = NULL;
20919   __Pyx_TraceDeclarations
20920   __Pyx_RefNannySetupContext("__get__");
20921   __Pyx_TraceCall("__get__", __pyx_f[0], 2415);
20922   __Pyx_XDECREF(__pyx_r);
20923   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20924   __Pyx_GOTREF(__pyx_t_1);
20925   __pyx_r = __pyx_t_1;
20926   __pyx_t_1 = 0;
20927   goto __pyx_L0;
20928
20929   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20930   goto __pyx_L0;
20931   __pyx_L1_error:;
20932   __Pyx_XDECREF(__pyx_t_1);
20933   __Pyx_AddTraceback("csamtools.AlignedRead.rname.__get__");
20934   __pyx_r = NULL;
20935   __pyx_L0:;
20936   __Pyx_XGIVEREF(__pyx_r);
20937   __Pyx_TraceReturn(__pyx_r);
20938   __Pyx_RefNannyFinishContext();
20939   return __pyx_r;
20940 }
20941
20942 /* "csamtools.pyx":2416
20943  *         """
20944  *         def __get__(self): return self._delegate.core.tid
20945  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
20946  * 
20947  *     property tid:
20948  */
20949
20950 static int __pyx_pf_9csamtools_11AlignedRead_5rname_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
20951 static int __pyx_pf_9csamtools_11AlignedRead_5rname_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
20952   int __pyx_r;
20953   int32_t __pyx_t_1;
20954   __Pyx_TraceDeclarations
20955   __Pyx_RefNannySetupContext("__set__");
20956   __Pyx_TraceCall("__set__", __pyx_f[0], 2416);
20957   __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 = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20958   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid = __pyx_t_1;
20959
20960   __pyx_r = 0;
20961   goto __pyx_L0;
20962   __pyx_L1_error:;
20963   __Pyx_AddTraceback("csamtools.AlignedRead.rname.__set__");
20964   __pyx_r = -1;
20965   __pyx_L0:;
20966   __Pyx_TraceReturn(Py_None);
20967   __Pyx_RefNannyFinishContext();
20968   return __pyx_r;
20969 }
20970
20971 /* "csamtools.pyx":2429
20972  * 
20973  *         """
20974  *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
20975  *         def __set__(self, tid): self._delegate.core.tid = tid
20976  * 
20977  */
20978
20979 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3tid___get__(PyObject *__pyx_v_self); /*proto*/
20980 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3tid___get__(PyObject *__pyx_v_self) {
20981   PyObject *__pyx_r = NULL;
20982   PyObject *__pyx_t_1 = NULL;
20983   __Pyx_TraceDeclarations
20984   __Pyx_RefNannySetupContext("__get__");
20985   __Pyx_TraceCall("__get__", __pyx_f[0], 2429);
20986   __Pyx_XDECREF(__pyx_r);
20987   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
20988   __Pyx_GOTREF(__pyx_t_1);
20989   __pyx_r = __pyx_t_1;
20990   __pyx_t_1 = 0;
20991   goto __pyx_L0;
20992
20993   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
20994   goto __pyx_L0;
20995   __pyx_L1_error:;
20996   __Pyx_XDECREF(__pyx_t_1);
20997   __Pyx_AddTraceback("csamtools.AlignedRead.tid.__get__");
20998   __pyx_r = NULL;
20999   __pyx_L0:;
21000   __Pyx_XGIVEREF(__pyx_r);
21001   __Pyx_TraceReturn(__pyx_r);
21002   __Pyx_RefNannyFinishContext();
21003   return __pyx_r;
21004 }
21005
21006 /* "csamtools.pyx":2430
21007  *         """
21008  *         def __get__(self): return self._delegate.core.tid
21009  *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
21010  * 
21011  *     property pos:
21012  */
21013
21014 static int __pyx_pf_9csamtools_11AlignedRead_3tid_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
21015 static int __pyx_pf_9csamtools_11AlignedRead_3tid_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
21016   int __pyx_r;
21017   int32_t __pyx_t_1;
21018   __Pyx_TraceDeclarations
21019   __Pyx_RefNannySetupContext("__set__");
21020   __Pyx_TraceCall("__set__", __pyx_f[0], 2430);
21021   __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 = 2430; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21022   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.tid = __pyx_t_1;
21023
21024   __pyx_r = 0;
21025   goto __pyx_L0;
21026   __pyx_L1_error:;
21027   __Pyx_AddTraceback("csamtools.AlignedRead.tid.__set__");
21028   __pyx_r = -1;
21029   __pyx_L0:;
21030   __Pyx_TraceReturn(Py_None);
21031   __Pyx_RefNannyFinishContext();
21032   return __pyx_r;
21033 }
21034
21035 /* "csamtools.pyx":2434
21036  *     property pos:
21037  *         """0-based leftmost coordinate"""
21038  *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
21039  *         def __set__(self, pos):
21040  *             ## setting the cigar string also updates the "bin" attribute
21041  */
21042
21043 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3pos___get__(PyObject *__pyx_v_self); /*proto*/
21044 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3pos___get__(PyObject *__pyx_v_self) {
21045   PyObject *__pyx_r = NULL;
21046   PyObject *__pyx_t_1 = NULL;
21047   __Pyx_TraceDeclarations
21048   __Pyx_RefNannySetupContext("__get__");
21049   __Pyx_TraceCall("__get__", __pyx_f[0], 2434);
21050   __Pyx_XDECREF(__pyx_r);
21051   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21052   __Pyx_GOTREF(__pyx_t_1);
21053   __pyx_r = __pyx_t_1;
21054   __pyx_t_1 = 0;
21055   goto __pyx_L0;
21056
21057   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21058   goto __pyx_L0;
21059   __pyx_L1_error:;
21060   __Pyx_XDECREF(__pyx_t_1);
21061   __Pyx_AddTraceback("csamtools.AlignedRead.pos.__get__");
21062   __pyx_r = NULL;
21063   __pyx_L0:;
21064   __Pyx_XGIVEREF(__pyx_r);
21065   __Pyx_TraceReturn(__pyx_r);
21066   __Pyx_RefNannyFinishContext();
21067   return __pyx_r;
21068 }
21069
21070 /* "csamtools.pyx":2435
21071  *         """0-based leftmost coordinate"""
21072  *         def __get__(self): return self._delegate.core.pos
21073  *         def __set__(self, pos):             # <<<<<<<<<<<<<<
21074  *             ## setting the cigar string also updates the "bin" attribute
21075  *             cdef bam1_t * src
21076  */
21077
21078 static int __pyx_pf_9csamtools_11AlignedRead_3pos_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
21079 static int __pyx_pf_9csamtools_11AlignedRead_3pos_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
21080   bam1_t *__pyx_v_src;
21081   int __pyx_r;
21082   int32_t __pyx_t_1;
21083   __Pyx_TraceDeclarations
21084   __Pyx_RefNannySetupContext("__set__");
21085   __Pyx_TraceCall("__set__", __pyx_f[0], 2435);
21086
21087   /* "csamtools.pyx":2438
21088  *             ## setting the cigar string also updates the "bin" attribute
21089  *             cdef bam1_t * src
21090  *             src = self._delegate             # <<<<<<<<<<<<<<
21091  *             if src.core.n_cigar:
21092  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
21093  */
21094   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
21095
21096   /* "csamtools.pyx":2439
21097  *             cdef bam1_t * src
21098  *             src = self._delegate
21099  *             if src.core.n_cigar:             # <<<<<<<<<<<<<<
21100  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
21101  *             else:
21102  */
21103   if (__pyx_v_src->core.n_cigar) {
21104
21105     /* "csamtools.pyx":2440
21106  *             src = self._delegate
21107  *             if src.core.n_cigar:
21108  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )             # <<<<<<<<<<<<<<
21109  *             else:
21110  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
21111  */
21112     __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)));
21113     goto __pyx_L5;
21114   }
21115   /*else*/ {
21116
21117     /* "csamtools.pyx":2442
21118  *                 src.core.bin = bam_reg2bin( src.core.pos, bam_calend( &src.core, bam1_cigar(src)) )
21119  *             else:
21120  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)             # <<<<<<<<<<<<<<
21121  *             self._delegate.core.pos = pos
21122  *     property bin:
21123  */
21124     __pyx_v_src->core.bin = bam_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1));
21125   }
21126   __pyx_L5:;
21127
21128   /* "csamtools.pyx":2443
21129  *             else:
21130  *                 src.core.bin = bam_reg2bin( src.core.pos, src.core.pos + 1)
21131  *             self._delegate.core.pos = pos             # <<<<<<<<<<<<<<
21132  *     property bin:
21133  *         """properties bin"""
21134  */
21135   __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 = 2443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21136   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos = __pyx_t_1;
21137
21138   __pyx_r = 0;
21139   goto __pyx_L0;
21140   __pyx_L1_error:;
21141   __Pyx_AddTraceback("csamtools.AlignedRead.pos.__set__");
21142   __pyx_r = -1;
21143   __pyx_L0:;
21144   __Pyx_TraceReturn(Py_None);
21145   __Pyx_RefNannyFinishContext();
21146   return __pyx_r;
21147 }
21148
21149 /* "csamtools.pyx":2446
21150  *     property bin:
21151  *         """properties bin"""
21152  *         def __get__(self): return self._delegate.core.bin             # <<<<<<<<<<<<<<
21153  *         def __set__(self, bin): self._delegate.core.bin = bin
21154  *     property rlen:
21155  */
21156
21157 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3bin___get__(PyObject *__pyx_v_self); /*proto*/
21158 static PyObject *__pyx_pf_9csamtools_11AlignedRead_3bin___get__(PyObject *__pyx_v_self) {
21159   PyObject *__pyx_r = NULL;
21160   PyObject *__pyx_t_1 = NULL;
21161   __Pyx_TraceDeclarations
21162   __Pyx_RefNannySetupContext("__get__");
21163   __Pyx_TraceCall("__get__", __pyx_f[0], 2446);
21164   __Pyx_XDECREF(__pyx_r);
21165   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.bin); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21166   __Pyx_GOTREF(__pyx_t_1);
21167   __pyx_r = __pyx_t_1;
21168   __pyx_t_1 = 0;
21169   goto __pyx_L0;
21170
21171   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21172   goto __pyx_L0;
21173   __pyx_L1_error:;
21174   __Pyx_XDECREF(__pyx_t_1);
21175   __Pyx_AddTraceback("csamtools.AlignedRead.bin.__get__");
21176   __pyx_r = NULL;
21177   __pyx_L0:;
21178   __Pyx_XGIVEREF(__pyx_r);
21179   __Pyx_TraceReturn(__pyx_r);
21180   __Pyx_RefNannyFinishContext();
21181   return __pyx_r;
21182 }
21183
21184 /* "csamtools.pyx":2447
21185  *         """properties bin"""
21186  *         def __get__(self): return self._delegate.core.bin
21187  *         def __set__(self, bin): self._delegate.core.bin = bin             # <<<<<<<<<<<<<<
21188  *     property rlen:
21189  *         '''length of the read (read only). Returns 0 if not given.'''
21190  */
21191
21192 static int __pyx_pf_9csamtools_11AlignedRead_3bin_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
21193 static int __pyx_pf_9csamtools_11AlignedRead_3bin_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
21194   int __pyx_r;
21195   uint32_t __pyx_t_1;
21196   __Pyx_TraceDeclarations
21197   __Pyx_RefNannySetupContext("__set__");
21198   __Pyx_TraceCall("__set__", __pyx_f[0], 2447);
21199   __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 = 2447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21200   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.bin = __pyx_t_1;
21201
21202   __pyx_r = 0;
21203   goto __pyx_L0;
21204   __pyx_L1_error:;
21205   __Pyx_AddTraceback("csamtools.AlignedRead.bin.__set__");
21206   __pyx_r = -1;
21207   __pyx_L0:;
21208   __Pyx_TraceReturn(Py_None);
21209   __Pyx_RefNannyFinishContext();
21210   return __pyx_r;
21211 }
21212
21213 /* "csamtools.pyx":2450
21214  *     property rlen:
21215  *         '''length of the read (read only). Returns 0 if not given.'''
21216  *         def __get__(self): return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
21217  *     property aend:
21218  *         '''aligned end position of the read on the reference genome.  Returns
21219  */
21220
21221 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4rlen___get__(PyObject *__pyx_v_self); /*proto*/
21222 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4rlen___get__(PyObject *__pyx_v_self) {
21223   PyObject *__pyx_r = NULL;
21224   PyObject *__pyx_t_1 = NULL;
21225   __Pyx_TraceDeclarations
21226   __Pyx_RefNannySetupContext("__get__");
21227   __Pyx_TraceCall("__get__", __pyx_f[0], 2450);
21228   __Pyx_XDECREF(__pyx_r);
21229   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21230   __Pyx_GOTREF(__pyx_t_1);
21231   __pyx_r = __pyx_t_1;
21232   __pyx_t_1 = 0;
21233   goto __pyx_L0;
21234
21235   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21236   goto __pyx_L0;
21237   __pyx_L1_error:;
21238   __Pyx_XDECREF(__pyx_t_1);
21239   __Pyx_AddTraceback("csamtools.AlignedRead.rlen.__get__");
21240   __pyx_r = NULL;
21241   __pyx_L0:;
21242   __Pyx_XGIVEREF(__pyx_r);
21243   __Pyx_TraceReturn(__pyx_r);
21244   __Pyx_RefNannyFinishContext();
21245   return __pyx_r;
21246 }
21247
21248 /* "csamtools.pyx":2454
21249  *         '''aligned end position of the read on the reference genome.  Returns
21250  *         None if not available.'''
21251  *         def __get__(self):             # <<<<<<<<<<<<<<
21252  *             cdef bam1_t * src
21253  *             src = self._delegate
21254  */
21255
21256 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4aend___get__(PyObject *__pyx_v_self); /*proto*/
21257 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4aend___get__(PyObject *__pyx_v_self) {
21258   bam1_t *__pyx_v_src;
21259   PyObject *__pyx_r = NULL;
21260   PyObject *__pyx_t_1 = NULL;
21261   PyObject *__pyx_t_2 = NULL;
21262   int __pyx_t_3;
21263   int __pyx_t_4;
21264   int __pyx_t_5;
21265   __Pyx_TraceDeclarations
21266   __Pyx_RefNannySetupContext("__get__");
21267   __Pyx_TraceCall("__get__", __pyx_f[0], 2454);
21268
21269   /* "csamtools.pyx":2456
21270  *         def __get__(self):
21271  *             cdef bam1_t * src
21272  *             src = self._delegate             # <<<<<<<<<<<<<<
21273  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21274  *                 return None
21275  */
21276   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
21277
21278   /* "csamtools.pyx":2457
21279  *             cdef bam1_t * src
21280  *             src = self._delegate
21281  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
21282  *                 return None
21283  *             return bam_calend(&src.core, bam1_cigar(src))
21284  */
21285   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21286   __Pyx_GOTREF(__pyx_t_1);
21287   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21288   __Pyx_GOTREF(__pyx_t_2);
21289   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21290   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21291   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21292   if (!__pyx_t_3) {
21293     __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
21294     __pyx_t_5 = __pyx_t_4;
21295   } else {
21296     __pyx_t_5 = __pyx_t_3;
21297   }
21298   if (__pyx_t_5) {
21299
21300     /* "csamtools.pyx":2458
21301  *             src = self._delegate
21302  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21303  *                 return None             # <<<<<<<<<<<<<<
21304  *             return bam_calend(&src.core, bam1_cigar(src))
21305  *     property alen:
21306  */
21307     __Pyx_XDECREF(__pyx_r);
21308     __Pyx_INCREF(Py_None);
21309     __pyx_r = Py_None;
21310     goto __pyx_L0;
21311     goto __pyx_L5;
21312   }
21313   __pyx_L5:;
21314
21315   /* "csamtools.pyx":2459
21316  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21317  *                 return None
21318  *             return bam_calend(&src.core, bam1_cigar(src))             # <<<<<<<<<<<<<<
21319  *     property alen:
21320  *         '''aligned length of the read on the reference genome.  Returns None if
21321  */
21322   __Pyx_XDECREF(__pyx_r);
21323   __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 = 2459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21324   __Pyx_GOTREF(__pyx_t_2);
21325   __pyx_r = __pyx_t_2;
21326   __pyx_t_2 = 0;
21327   goto __pyx_L0;
21328
21329   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21330   goto __pyx_L0;
21331   __pyx_L1_error:;
21332   __Pyx_XDECREF(__pyx_t_1);
21333   __Pyx_XDECREF(__pyx_t_2);
21334   __Pyx_AddTraceback("csamtools.AlignedRead.aend.__get__");
21335   __pyx_r = NULL;
21336   __pyx_L0:;
21337   __Pyx_XGIVEREF(__pyx_r);
21338   __Pyx_TraceReturn(__pyx_r);
21339   __Pyx_RefNannyFinishContext();
21340   return __pyx_r;
21341 }
21342
21343 /* "csamtools.pyx":2463
21344  *         '''aligned length of the read on the reference genome.  Returns None if
21345  *         not available.'''
21346  *         def __get__(self):             # <<<<<<<<<<<<<<
21347  *             cdef bam1_t * src
21348  *             src = self._delegate
21349  */
21350
21351 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4alen___get__(PyObject *__pyx_v_self); /*proto*/
21352 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4alen___get__(PyObject *__pyx_v_self) {
21353   bam1_t *__pyx_v_src;
21354   PyObject *__pyx_r = NULL;
21355   PyObject *__pyx_t_1 = NULL;
21356   PyObject *__pyx_t_2 = NULL;
21357   int __pyx_t_3;
21358   int __pyx_t_4;
21359   int __pyx_t_5;
21360   __Pyx_TraceDeclarations
21361   __Pyx_RefNannySetupContext("__get__");
21362   __Pyx_TraceCall("__get__", __pyx_f[0], 2463);
21363
21364   /* "csamtools.pyx":2465
21365  *         def __get__(self):
21366  *             cdef bam1_t * src
21367  *             src = self._delegate             # <<<<<<<<<<<<<<
21368  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21369  *                 return None
21370  */
21371   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
21372
21373   /* "csamtools.pyx":2466
21374  *             cdef bam1_t * src
21375  *             src = self._delegate
21376  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:             # <<<<<<<<<<<<<<
21377  *                 return None
21378  *             return bam_calend(&src.core,
21379  */
21380   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21381   __Pyx_GOTREF(__pyx_t_1);
21382   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21383   __Pyx_GOTREF(__pyx_t_2);
21384   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
21385   __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21386   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
21387   if (!__pyx_t_3) {
21388     __pyx_t_4 = (__pyx_v_src->core.n_cigar == 0);
21389     __pyx_t_5 = __pyx_t_4;
21390   } else {
21391     __pyx_t_5 = __pyx_t_3;
21392   }
21393   if (__pyx_t_5) {
21394
21395     /* "csamtools.pyx":2467
21396  *             src = self._delegate
21397  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21398  *                 return None             # <<<<<<<<<<<<<<
21399  *             return bam_calend(&src.core,
21400  *                                bam1_cigar(src)) - \
21401  */
21402     __Pyx_XDECREF(__pyx_r);
21403     __Pyx_INCREF(Py_None);
21404     __pyx_r = Py_None;
21405     goto __pyx_L0;
21406     goto __pyx_L5;
21407   }
21408   __pyx_L5:;
21409
21410   /* "csamtools.pyx":2468
21411  *             if (self.flag & BAM_FUNMAP) or src.core.n_cigar == 0:
21412  *                 return None
21413  *             return bam_calend(&src.core,             # <<<<<<<<<<<<<<
21414  *                                bam1_cigar(src)) - \
21415  *                                self._delegate.core.pos
21416  */
21417   __Pyx_XDECREF(__pyx_r);
21418
21419   /* "csamtools.pyx":2470
21420  *             return bam_calend(&src.core,
21421  *                                bam1_cigar(src)) - \
21422  *                                self._delegate.core.pos             # <<<<<<<<<<<<<<
21423  * 
21424  *     property mapq:
21425  */
21426   __pyx_t_2 = __Pyx_PyInt_to_py_int32_t((bam_calend((&__pyx_v_src->core), bam1_cigar(__pyx_v_src)) - ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.pos)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21427   __Pyx_GOTREF(__pyx_t_2);
21428   __pyx_r = __pyx_t_2;
21429   __pyx_t_2 = 0;
21430   goto __pyx_L0;
21431
21432   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21433   goto __pyx_L0;
21434   __pyx_L1_error:;
21435   __Pyx_XDECREF(__pyx_t_1);
21436   __Pyx_XDECREF(__pyx_t_2);
21437   __Pyx_AddTraceback("csamtools.AlignedRead.alen.__get__");
21438   __pyx_r = NULL;
21439   __pyx_L0:;
21440   __Pyx_XGIVEREF(__pyx_r);
21441   __Pyx_TraceReturn(__pyx_r);
21442   __Pyx_RefNannyFinishContext();
21443   return __pyx_r;
21444 }
21445
21446 /* "csamtools.pyx":2474
21447  *     property mapq:
21448  *         """mapping quality"""
21449  *         def __get__(self): return self._delegate.core.qual             # <<<<<<<<<<<<<<
21450  *         def __set__(self, qual): self._delegate.core.qual = qual
21451  *     property mrnm:
21452  */
21453
21454 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mapq___get__(PyObject *__pyx_v_self); /*proto*/
21455 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mapq___get__(PyObject *__pyx_v_self) {
21456   PyObject *__pyx_r = NULL;
21457   PyObject *__pyx_t_1 = NULL;
21458   __Pyx_TraceDeclarations
21459   __Pyx_RefNannySetupContext("__get__");
21460   __Pyx_TraceCall("__get__", __pyx_f[0], 2474);
21461   __Pyx_XDECREF(__pyx_r);
21462   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.qual); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2474; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21463   __Pyx_GOTREF(__pyx_t_1);
21464   __pyx_r = __pyx_t_1;
21465   __pyx_t_1 = 0;
21466   goto __pyx_L0;
21467
21468   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21469   goto __pyx_L0;
21470   __pyx_L1_error:;
21471   __Pyx_XDECREF(__pyx_t_1);
21472   __Pyx_AddTraceback("csamtools.AlignedRead.mapq.__get__");
21473   __pyx_r = NULL;
21474   __pyx_L0:;
21475   __Pyx_XGIVEREF(__pyx_r);
21476   __Pyx_TraceReturn(__pyx_r);
21477   __Pyx_RefNannyFinishContext();
21478   return __pyx_r;
21479 }
21480
21481 /* "csamtools.pyx":2475
21482  *         """mapping quality"""
21483  *         def __get__(self): return self._delegate.core.qual
21484  *         def __set__(self, qual): self._delegate.core.qual = qual             # <<<<<<<<<<<<<<
21485  *     property mrnm:
21486  *         """the :term:`reference` id of the mate
21487  */
21488
21489 static int __pyx_pf_9csamtools_11AlignedRead_4mapq_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
21490 static int __pyx_pf_9csamtools_11AlignedRead_4mapq_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
21491   int __pyx_r;
21492   uint32_t __pyx_t_1;
21493   __Pyx_TraceDeclarations
21494   __Pyx_RefNannySetupContext("__set__");
21495   __Pyx_TraceCall("__set__", __pyx_f[0], 2475);
21496   __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 = 2475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21497   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.qual = __pyx_t_1;
21498
21499   __pyx_r = 0;
21500   goto __pyx_L0;
21501   __pyx_L1_error:;
21502   __Pyx_AddTraceback("csamtools.AlignedRead.mapq.__set__");
21503   __pyx_r = -1;
21504   __pyx_L0:;
21505   __Pyx_TraceReturn(Py_None);
21506   __Pyx_RefNannyFinishContext();
21507   return __pyx_r;
21508 }
21509
21510 /* "csamtools.pyx":2480
21511  *         deprecated, use RNEXT instead.
21512  *         """
21513  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
21514  *         def __set__(self, mtid): self._delegate.core.mtid = mtid
21515  *     property rnext:
21516  */
21517
21518 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(PyObject *__pyx_v_self); /*proto*/
21519 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(PyObject *__pyx_v_self) {
21520   PyObject *__pyx_r = NULL;
21521   PyObject *__pyx_t_1 = NULL;
21522   __Pyx_TraceDeclarations
21523   __Pyx_RefNannySetupContext("__get__");
21524   __Pyx_TraceCall("__get__", __pyx_f[0], 2480);
21525   __Pyx_XDECREF(__pyx_r);
21526   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21527   __Pyx_GOTREF(__pyx_t_1);
21528   __pyx_r = __pyx_t_1;
21529   __pyx_t_1 = 0;
21530   goto __pyx_L0;
21531
21532   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21533   goto __pyx_L0;
21534   __pyx_L1_error:;
21535   __Pyx_XDECREF(__pyx_t_1);
21536   __Pyx_AddTraceback("csamtools.AlignedRead.mrnm.__get__");
21537   __pyx_r = NULL;
21538   __pyx_L0:;
21539   __Pyx_XGIVEREF(__pyx_r);
21540   __Pyx_TraceReturn(__pyx_r);
21541   __Pyx_RefNannyFinishContext();
21542   return __pyx_r;
21543 }
21544
21545 /* "csamtools.pyx":2481
21546  *         """
21547  *         def __get__(self): return self._delegate.core.mtid
21548  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
21549  *     property rnext:
21550  *         """the :term:`reference` id of the mate """
21551  */
21552
21553 static int __pyx_pf_9csamtools_11AlignedRead_4mrnm_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
21554 static int __pyx_pf_9csamtools_11AlignedRead_4mrnm_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
21555   int __pyx_r;
21556   int32_t __pyx_t_1;
21557   __Pyx_TraceDeclarations
21558   __Pyx_RefNannySetupContext("__set__");
21559   __Pyx_TraceCall("__set__", __pyx_f[0], 2481);
21560   __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 = 2481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21561   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid = __pyx_t_1;
21562
21563   __pyx_r = 0;
21564   goto __pyx_L0;
21565   __pyx_L1_error:;
21566   __Pyx_AddTraceback("csamtools.AlignedRead.mrnm.__set__");
21567   __pyx_r = -1;
21568   __pyx_L0:;
21569   __Pyx_TraceReturn(Py_None);
21570   __Pyx_RefNannyFinishContext();
21571   return __pyx_r;
21572 }
21573
21574 /* "csamtools.pyx":2484
21575  *     property rnext:
21576  *         """the :term:`reference` id of the mate """
21577  *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
21578  *         def __set__(self, mtid): self._delegate.core.mtid = mtid
21579  *     property mpos:
21580  */
21581
21582 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rnext___get__(PyObject *__pyx_v_self); /*proto*/
21583 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5rnext___get__(PyObject *__pyx_v_self) {
21584   PyObject *__pyx_r = NULL;
21585   PyObject *__pyx_t_1 = NULL;
21586   __Pyx_TraceDeclarations
21587   __Pyx_RefNannySetupContext("__get__");
21588   __Pyx_TraceCall("__get__", __pyx_f[0], 2484);
21589   __Pyx_XDECREF(__pyx_r);
21590   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21591   __Pyx_GOTREF(__pyx_t_1);
21592   __pyx_r = __pyx_t_1;
21593   __pyx_t_1 = 0;
21594   goto __pyx_L0;
21595
21596   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21597   goto __pyx_L0;
21598   __pyx_L1_error:;
21599   __Pyx_XDECREF(__pyx_t_1);
21600   __Pyx_AddTraceback("csamtools.AlignedRead.rnext.__get__");
21601   __pyx_r = NULL;
21602   __pyx_L0:;
21603   __Pyx_XGIVEREF(__pyx_r);
21604   __Pyx_TraceReturn(__pyx_r);
21605   __Pyx_RefNannyFinishContext();
21606   return __pyx_r;
21607 }
21608
21609 /* "csamtools.pyx":2485
21610  *         """the :term:`reference` id of the mate """
21611  *         def __get__(self): return self._delegate.core.mtid
21612  *         def __set__(self, mtid): self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
21613  *     property mpos:
21614  *         """the position of the mate
21615  */
21616
21617 static int __pyx_pf_9csamtools_11AlignedRead_5rnext_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
21618 static int __pyx_pf_9csamtools_11AlignedRead_5rnext_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
21619   int __pyx_r;
21620   int32_t __pyx_t_1;
21621   __Pyx_TraceDeclarations
21622   __Pyx_RefNannySetupContext("__set__");
21623   __Pyx_TraceCall("__set__", __pyx_f[0], 2485);
21624   __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 = 2485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21625   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mtid = __pyx_t_1;
21626
21627   __pyx_r = 0;
21628   goto __pyx_L0;
21629   __pyx_L1_error:;
21630   __Pyx_AddTraceback("csamtools.AlignedRead.rnext.__set__");
21631   __pyx_r = -1;
21632   __pyx_L0:;
21633   __Pyx_TraceReturn(Py_None);
21634   __Pyx_RefNannyFinishContext();
21635   return __pyx_r;
21636 }
21637
21638 /* "csamtools.pyx":2489
21639  *         """the position of the mate
21640  *         deprecated, use PNEXT instead."""
21641  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
21642  *         def __set__(self, mpos): self._delegate.core.mpos = mpos
21643  *     property pnext:
21644  */
21645
21646 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mpos___get__(PyObject *__pyx_v_self); /*proto*/
21647 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4mpos___get__(PyObject *__pyx_v_self) {
21648   PyObject *__pyx_r = NULL;
21649   PyObject *__pyx_t_1 = NULL;
21650   __Pyx_TraceDeclarations
21651   __Pyx_RefNannySetupContext("__get__");
21652   __Pyx_TraceCall("__get__", __pyx_f[0], 2489);
21653   __Pyx_XDECREF(__pyx_r);
21654   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21655   __Pyx_GOTREF(__pyx_t_1);
21656   __pyx_r = __pyx_t_1;
21657   __pyx_t_1 = 0;
21658   goto __pyx_L0;
21659
21660   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21661   goto __pyx_L0;
21662   __pyx_L1_error:;
21663   __Pyx_XDECREF(__pyx_t_1);
21664   __Pyx_AddTraceback("csamtools.AlignedRead.mpos.__get__");
21665   __pyx_r = NULL;
21666   __pyx_L0:;
21667   __Pyx_XGIVEREF(__pyx_r);
21668   __Pyx_TraceReturn(__pyx_r);
21669   __Pyx_RefNannyFinishContext();
21670   return __pyx_r;
21671 }
21672
21673 /* "csamtools.pyx":2490
21674  *         deprecated, use PNEXT instead."""
21675  *         def __get__(self): return self._delegate.core.mpos
21676  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
21677  *     property pnext:
21678  *         """the position of the mate"""
21679  */
21680
21681 static int __pyx_pf_9csamtools_11AlignedRead_4mpos_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
21682 static int __pyx_pf_9csamtools_11AlignedRead_4mpos_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
21683   int __pyx_r;
21684   int32_t __pyx_t_1;
21685   __Pyx_TraceDeclarations
21686   __Pyx_RefNannySetupContext("__set__");
21687   __Pyx_TraceCall("__set__", __pyx_f[0], 2490);
21688   __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 = 2490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21689   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos = __pyx_t_1;
21690
21691   __pyx_r = 0;
21692   goto __pyx_L0;
21693   __pyx_L1_error:;
21694   __Pyx_AddTraceback("csamtools.AlignedRead.mpos.__set__");
21695   __pyx_r = -1;
21696   __pyx_L0:;
21697   __Pyx_TraceReturn(Py_None);
21698   __Pyx_RefNannyFinishContext();
21699   return __pyx_r;
21700 }
21701
21702 /* "csamtools.pyx":2493
21703  *     property pnext:
21704  *         """the position of the mate"""
21705  *         def __get__(self): return self._delegate.core.mpos             # <<<<<<<<<<<<<<
21706  *         def __set__(self, mpos): self._delegate.core.mpos = mpos
21707  *     property isize:
21708  */
21709
21710 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5pnext___get__(PyObject *__pyx_v_self); /*proto*/
21711 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5pnext___get__(PyObject *__pyx_v_self) {
21712   PyObject *__pyx_r = NULL;
21713   PyObject *__pyx_t_1 = NULL;
21714   __Pyx_TraceDeclarations
21715   __Pyx_RefNannySetupContext("__get__");
21716   __Pyx_TraceCall("__get__", __pyx_f[0], 2493);
21717   __Pyx_XDECREF(__pyx_r);
21718   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2493; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21719   __Pyx_GOTREF(__pyx_t_1);
21720   __pyx_r = __pyx_t_1;
21721   __pyx_t_1 = 0;
21722   goto __pyx_L0;
21723
21724   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21725   goto __pyx_L0;
21726   __pyx_L1_error:;
21727   __Pyx_XDECREF(__pyx_t_1);
21728   __Pyx_AddTraceback("csamtools.AlignedRead.pnext.__get__");
21729   __pyx_r = NULL;
21730   __pyx_L0:;
21731   __Pyx_XGIVEREF(__pyx_r);
21732   __Pyx_TraceReturn(__pyx_r);
21733   __Pyx_RefNannyFinishContext();
21734   return __pyx_r;
21735 }
21736
21737 /* "csamtools.pyx":2494
21738  *         """the position of the mate"""
21739  *         def __get__(self): return self._delegate.core.mpos
21740  *         def __set__(self, mpos): self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
21741  *     property isize:
21742  *         """the insert size
21743  */
21744
21745 static int __pyx_pf_9csamtools_11AlignedRead_5pnext_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
21746 static int __pyx_pf_9csamtools_11AlignedRead_5pnext_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
21747   int __pyx_r;
21748   int32_t __pyx_t_1;
21749   __Pyx_TraceDeclarations
21750   __Pyx_RefNannySetupContext("__set__");
21751   __Pyx_TraceCall("__set__", __pyx_f[0], 2494);
21752   __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 = 2494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21753   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.mpos = __pyx_t_1;
21754
21755   __pyx_r = 0;
21756   goto __pyx_L0;
21757   __pyx_L1_error:;
21758   __Pyx_AddTraceback("csamtools.AlignedRead.pnext.__set__");
21759   __pyx_r = -1;
21760   __pyx_L0:;
21761   __Pyx_TraceReturn(Py_None);
21762   __Pyx_RefNannyFinishContext();
21763   return __pyx_r;
21764 }
21765
21766 /* "csamtools.pyx":2498
21767  *         """the insert size
21768  *         deprecated: use tlen instead"""
21769  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
21770  *         def __set__(self, isize): self._delegate.core.isize = isize
21771  *     property tlen:
21772  */
21773
21774 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5isize___get__(PyObject *__pyx_v_self); /*proto*/
21775 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5isize___get__(PyObject *__pyx_v_self) {
21776   PyObject *__pyx_r = NULL;
21777   PyObject *__pyx_t_1 = NULL;
21778   __Pyx_TraceDeclarations
21779   __Pyx_RefNannySetupContext("__get__");
21780   __Pyx_TraceCall("__get__", __pyx_f[0], 2498);
21781   __Pyx_XDECREF(__pyx_r);
21782   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21783   __Pyx_GOTREF(__pyx_t_1);
21784   __pyx_r = __pyx_t_1;
21785   __pyx_t_1 = 0;
21786   goto __pyx_L0;
21787
21788   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21789   goto __pyx_L0;
21790   __pyx_L1_error:;
21791   __Pyx_XDECREF(__pyx_t_1);
21792   __Pyx_AddTraceback("csamtools.AlignedRead.isize.__get__");
21793   __pyx_r = NULL;
21794   __pyx_L0:;
21795   __Pyx_XGIVEREF(__pyx_r);
21796   __Pyx_TraceReturn(__pyx_r);
21797   __Pyx_RefNannyFinishContext();
21798   return __pyx_r;
21799 }
21800
21801 /* "csamtools.pyx":2499
21802  *         deprecated: use tlen instead"""
21803  *         def __get__(self): return self._delegate.core.isize
21804  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
21805  *     property tlen:
21806  *         """the insert size"""
21807  */
21808
21809 static int __pyx_pf_9csamtools_11AlignedRead_5isize_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
21810 static int __pyx_pf_9csamtools_11AlignedRead_5isize_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
21811   int __pyx_r;
21812   int32_t __pyx_t_1;
21813   __Pyx_TraceDeclarations
21814   __Pyx_RefNannySetupContext("__set__");
21815   __Pyx_TraceCall("__set__", __pyx_f[0], 2499);
21816   __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 = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21817   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize = __pyx_t_1;
21818
21819   __pyx_r = 0;
21820   goto __pyx_L0;
21821   __pyx_L1_error:;
21822   __Pyx_AddTraceback("csamtools.AlignedRead.isize.__set__");
21823   __pyx_r = -1;
21824   __pyx_L0:;
21825   __Pyx_TraceReturn(Py_None);
21826   __Pyx_RefNannyFinishContext();
21827   return __pyx_r;
21828 }
21829
21830 /* "csamtools.pyx":2502
21831  *     property tlen:
21832  *         """the insert size"""
21833  *         def __get__(self): return self._delegate.core.isize             # <<<<<<<<<<<<<<
21834  *         def __set__(self, isize): self._delegate.core.isize = isize
21835  *     property is_paired:
21836  */
21837
21838 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tlen___get__(PyObject *__pyx_v_self); /*proto*/
21839 static PyObject *__pyx_pf_9csamtools_11AlignedRead_4tlen___get__(PyObject *__pyx_v_self) {
21840   PyObject *__pyx_r = NULL;
21841   PyObject *__pyx_t_1 = NULL;
21842   __Pyx_TraceDeclarations
21843   __Pyx_RefNannySetupContext("__get__");
21844   __Pyx_TraceCall("__get__", __pyx_f[0], 2502);
21845   __Pyx_XDECREF(__pyx_r);
21846   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21847   __Pyx_GOTREF(__pyx_t_1);
21848   __pyx_r = __pyx_t_1;
21849   __pyx_t_1 = 0;
21850   goto __pyx_L0;
21851
21852   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21853   goto __pyx_L0;
21854   __pyx_L1_error:;
21855   __Pyx_XDECREF(__pyx_t_1);
21856   __Pyx_AddTraceback("csamtools.AlignedRead.tlen.__get__");
21857   __pyx_r = NULL;
21858   __pyx_L0:;
21859   __Pyx_XGIVEREF(__pyx_r);
21860   __Pyx_TraceReturn(__pyx_r);
21861   __Pyx_RefNannyFinishContext();
21862   return __pyx_r;
21863 }
21864
21865 /* "csamtools.pyx":2503
21866  *         """the insert size"""
21867  *         def __get__(self): return self._delegate.core.isize
21868  *         def __set__(self, isize): self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
21869  *     property is_paired:
21870  *         """true if read is paired in sequencing"""
21871  */
21872
21873 static int __pyx_pf_9csamtools_11AlignedRead_4tlen_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
21874 static int __pyx_pf_9csamtools_11AlignedRead_4tlen_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
21875   int __pyx_r;
21876   int32_t __pyx_t_1;
21877   __Pyx_TraceDeclarations
21878   __Pyx_RefNannySetupContext("__set__");
21879   __Pyx_TraceCall("__set__", __pyx_f[0], 2503);
21880   __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 = 2503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21881   ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.isize = __pyx_t_1;
21882
21883   __pyx_r = 0;
21884   goto __pyx_L0;
21885   __pyx_L1_error:;
21886   __Pyx_AddTraceback("csamtools.AlignedRead.tlen.__set__");
21887   __pyx_r = -1;
21888   __pyx_L0:;
21889   __Pyx_TraceReturn(Py_None);
21890   __Pyx_RefNannyFinishContext();
21891   return __pyx_r;
21892 }
21893
21894 /* "csamtools.pyx":2506
21895  *     property is_paired:
21896  *         """true if read is paired in sequencing"""
21897  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
21898  *         def __set__(self,val):
21899  *             if val: self._delegate.core.flag |= BAM_FPAIRED
21900  */
21901
21902 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(PyObject *__pyx_v_self); /*proto*/
21903 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(PyObject *__pyx_v_self) {
21904   PyObject *__pyx_r = NULL;
21905   PyObject *__pyx_t_1 = NULL;
21906   __Pyx_TraceDeclarations
21907   __Pyx_RefNannySetupContext("__get__");
21908   __Pyx_TraceCall("__get__", __pyx_f[0], 2506);
21909   __Pyx_XDECREF(__pyx_r);
21910   __pyx_t_1 = __Pyx_PyBool_FromLong(((((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & 1) != 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21911   __Pyx_GOTREF(__pyx_t_1);
21912   __pyx_r = __pyx_t_1;
21913   __pyx_t_1 = 0;
21914   goto __pyx_L0;
21915
21916   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
21917   goto __pyx_L0;
21918   __pyx_L1_error:;
21919   __Pyx_XDECREF(__pyx_t_1);
21920   __Pyx_AddTraceback("csamtools.AlignedRead.is_paired.__get__");
21921   __pyx_r = NULL;
21922   __pyx_L0:;
21923   __Pyx_XGIVEREF(__pyx_r);
21924   __Pyx_TraceReturn(__pyx_r);
21925   __Pyx_RefNannyFinishContext();
21926   return __pyx_r;
21927 }
21928
21929 /* "csamtools.pyx":2507
21930  *         """true if read is paired in sequencing"""
21931  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
21932  *         def __set__(self,val):             # <<<<<<<<<<<<<<
21933  *             if val: self._delegate.core.flag |= BAM_FPAIRED
21934  *             else: self._delegate.core.flag &= ~BAM_FPAIRED
21935  */
21936
21937 static int __pyx_pf_9csamtools_11AlignedRead_9is_paired_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
21938 static int __pyx_pf_9csamtools_11AlignedRead_9is_paired_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
21939   int __pyx_r;
21940   int __pyx_t_1;
21941   __Pyx_TraceDeclarations
21942   __Pyx_RefNannySetupContext("__set__");
21943   __Pyx_TraceCall("__set__", __pyx_f[0], 2507);
21944
21945   /* "csamtools.pyx":2508
21946  *         def __get__(self): return (self._delegate.core.flag & BAM_FPAIRED) != 0
21947  *         def __set__(self,val):
21948  *             if val: self._delegate.core.flag |= BAM_FPAIRED             # <<<<<<<<<<<<<<
21949  *             else: self._delegate.core.flag &= ~BAM_FPAIRED
21950  *     property is_proper_pair:
21951  */
21952   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2508; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21953   if (__pyx_t_1) {
21954     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 1);
21955     goto __pyx_L5;
21956   }
21957   /*else*/ {
21958
21959     /* "csamtools.pyx":2509
21960  *         def __set__(self,val):
21961  *             if val: self._delegate.core.flag |= BAM_FPAIRED
21962  *             else: self._delegate.core.flag &= ~BAM_FPAIRED             # <<<<<<<<<<<<<<
21963  *     property is_proper_pair:
21964  *         """true if read is mapped in a proper pair"""
21965  */
21966     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~1));
21967   }
21968   __pyx_L5:;
21969
21970   __pyx_r = 0;
21971   goto __pyx_L0;
21972   __pyx_L1_error:;
21973   __Pyx_AddTraceback("csamtools.AlignedRead.is_paired.__set__");
21974   __pyx_r = -1;
21975   __pyx_L0:;
21976   __Pyx_TraceReturn(Py_None);
21977   __Pyx_RefNannyFinishContext();
21978   return __pyx_r;
21979 }
21980
21981 /* "csamtools.pyx":2512
21982  *     property is_proper_pair:
21983  *         """true if read is mapped in a proper pair"""
21984  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
21985  *         def __set__(self,val):
21986  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
21987  */
21988
21989 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(PyObject *__pyx_v_self); /*proto*/
21990 static PyObject *__pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(PyObject *__pyx_v_self) {
21991   PyObject *__pyx_r = NULL;
21992   PyObject *__pyx_t_1 = NULL;
21993   PyObject *__pyx_t_2 = NULL;
21994   __Pyx_TraceDeclarations
21995   __Pyx_RefNannySetupContext("__get__");
21996   __Pyx_TraceCall("__get__", __pyx_f[0], 2512);
21997   __Pyx_XDECREF(__pyx_r);
21998   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
21999   __Pyx_GOTREF(__pyx_t_1);
22000   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22001   __Pyx_GOTREF(__pyx_t_2);
22002   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22003   __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 = 2512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22004   __Pyx_GOTREF(__pyx_t_1);
22005   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22006   __pyx_r = __pyx_t_1;
22007   __pyx_t_1 = 0;
22008   goto __pyx_L0;
22009
22010   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22011   goto __pyx_L0;
22012   __pyx_L1_error:;
22013   __Pyx_XDECREF(__pyx_t_1);
22014   __Pyx_XDECREF(__pyx_t_2);
22015   __Pyx_AddTraceback("csamtools.AlignedRead.is_proper_pair.__get__");
22016   __pyx_r = NULL;
22017   __pyx_L0:;
22018   __Pyx_XGIVEREF(__pyx_r);
22019   __Pyx_TraceReturn(__pyx_r);
22020   __Pyx_RefNannyFinishContext();
22021   return __pyx_r;
22022 }
22023
22024 /* "csamtools.pyx":2513
22025  *         """true if read is mapped in a proper pair"""
22026  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
22027  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22028  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
22029  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
22030  */
22031
22032 static int __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22033 static int __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22034   int __pyx_r;
22035   int __pyx_t_1;
22036   __Pyx_TraceDeclarations
22037   __Pyx_RefNannySetupContext("__set__");
22038   __Pyx_TraceCall("__set__", __pyx_f[0], 2513);
22039
22040   /* "csamtools.pyx":2514
22041  *         def __get__(self): return (self.flag & BAM_FPROPER_PAIR) != 0
22042  *         def __set__(self,val):
22043  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
22044  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR
22045  *     property is_unmapped:
22046  */
22047   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22048   if (__pyx_t_1) {
22049     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 2);
22050     goto __pyx_L5;
22051   }
22052   /*else*/ {
22053
22054     /* "csamtools.pyx":2515
22055  *         def __set__(self,val):
22056  *             if val: self._delegate.core.flag |= BAM_FPROPER_PAIR
22057  *             else: self._delegate.core.flag &= ~BAM_FPROPER_PAIR             # <<<<<<<<<<<<<<
22058  *     property is_unmapped:
22059  *         """true if read itself is unmapped"""
22060  */
22061     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~2));
22062   }
22063   __pyx_L5:;
22064
22065   __pyx_r = 0;
22066   goto __pyx_L0;
22067   __pyx_L1_error:;
22068   __Pyx_AddTraceback("csamtools.AlignedRead.is_proper_pair.__set__");
22069   __pyx_r = -1;
22070   __pyx_L0:;
22071   __Pyx_TraceReturn(Py_None);
22072   __Pyx_RefNannyFinishContext();
22073   return __pyx_r;
22074 }
22075
22076 /* "csamtools.pyx":2518
22077  *     property is_unmapped:
22078  *         """true if read itself is unmapped"""
22079  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
22080  *         def __set__(self,val):
22081  *             if val: self._delegate.core.flag |= BAM_FUNMAP
22082  */
22083
22084 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(PyObject *__pyx_v_self); /*proto*/
22085 static PyObject *__pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(PyObject *__pyx_v_self) {
22086   PyObject *__pyx_r = NULL;
22087   PyObject *__pyx_t_1 = NULL;
22088   PyObject *__pyx_t_2 = NULL;
22089   __Pyx_TraceDeclarations
22090   __Pyx_RefNannySetupContext("__get__");
22091   __Pyx_TraceCall("__get__", __pyx_f[0], 2518);
22092   __Pyx_XDECREF(__pyx_r);
22093   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22094   __Pyx_GOTREF(__pyx_t_1);
22095   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22096   __Pyx_GOTREF(__pyx_t_2);
22097   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22098   __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 = 2518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22099   __Pyx_GOTREF(__pyx_t_1);
22100   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22101   __pyx_r = __pyx_t_1;
22102   __pyx_t_1 = 0;
22103   goto __pyx_L0;
22104
22105   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22106   goto __pyx_L0;
22107   __pyx_L1_error:;
22108   __Pyx_XDECREF(__pyx_t_1);
22109   __Pyx_XDECREF(__pyx_t_2);
22110   __Pyx_AddTraceback("csamtools.AlignedRead.is_unmapped.__get__");
22111   __pyx_r = NULL;
22112   __pyx_L0:;
22113   __Pyx_XGIVEREF(__pyx_r);
22114   __Pyx_TraceReturn(__pyx_r);
22115   __Pyx_RefNannyFinishContext();
22116   return __pyx_r;
22117 }
22118
22119 /* "csamtools.pyx":2519
22120  *         """true if read itself is unmapped"""
22121  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
22122  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22123  *             if val: self._delegate.core.flag |= BAM_FUNMAP
22124  *             else: self._delegate.core.flag &= ~BAM_FUNMAP
22125  */
22126
22127 static int __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22128 static int __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22129   int __pyx_r;
22130   int __pyx_t_1;
22131   __Pyx_TraceDeclarations
22132   __Pyx_RefNannySetupContext("__set__");
22133   __Pyx_TraceCall("__set__", __pyx_f[0], 2519);
22134
22135   /* "csamtools.pyx":2520
22136  *         def __get__(self): return (self.flag & BAM_FUNMAP) != 0
22137  *         def __set__(self,val):
22138  *             if val: self._delegate.core.flag |= BAM_FUNMAP             # <<<<<<<<<<<<<<
22139  *             else: self._delegate.core.flag &= ~BAM_FUNMAP
22140  *     property mate_is_unmapped:
22141  */
22142   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22143   if (__pyx_t_1) {
22144     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 4);
22145     goto __pyx_L5;
22146   }
22147   /*else*/ {
22148
22149     /* "csamtools.pyx":2521
22150  *         def __set__(self,val):
22151  *             if val: self._delegate.core.flag |= BAM_FUNMAP
22152  *             else: self._delegate.core.flag &= ~BAM_FUNMAP             # <<<<<<<<<<<<<<
22153  *     property mate_is_unmapped:
22154  *         """true if the mate is unmapped"""
22155  */
22156     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~4));
22157   }
22158   __pyx_L5:;
22159
22160   __pyx_r = 0;
22161   goto __pyx_L0;
22162   __pyx_L1_error:;
22163   __Pyx_AddTraceback("csamtools.AlignedRead.is_unmapped.__set__");
22164   __pyx_r = -1;
22165   __pyx_L0:;
22166   __Pyx_TraceReturn(Py_None);
22167   __Pyx_RefNannyFinishContext();
22168   return __pyx_r;
22169 }
22170
22171 /* "csamtools.pyx":2524
22172  *     property mate_is_unmapped:
22173  *         """true if the mate is unmapped"""
22174  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
22175  *         def __set__(self,val):
22176  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
22177  */
22178
22179 static PyObject *__pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(PyObject *__pyx_v_self); /*proto*/
22180 static PyObject *__pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(PyObject *__pyx_v_self) {
22181   PyObject *__pyx_r = NULL;
22182   PyObject *__pyx_t_1 = NULL;
22183   PyObject *__pyx_t_2 = NULL;
22184   __Pyx_TraceDeclarations
22185   __Pyx_RefNannySetupContext("__get__");
22186   __Pyx_TraceCall("__get__", __pyx_f[0], 2524);
22187   __Pyx_XDECREF(__pyx_r);
22188   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22189   __Pyx_GOTREF(__pyx_t_1);
22190   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22191   __Pyx_GOTREF(__pyx_t_2);
22192   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22193   __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 = 2524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22194   __Pyx_GOTREF(__pyx_t_1);
22195   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22196   __pyx_r = __pyx_t_1;
22197   __pyx_t_1 = 0;
22198   goto __pyx_L0;
22199
22200   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22201   goto __pyx_L0;
22202   __pyx_L1_error:;
22203   __Pyx_XDECREF(__pyx_t_1);
22204   __Pyx_XDECREF(__pyx_t_2);
22205   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_unmapped.__get__");
22206   __pyx_r = NULL;
22207   __pyx_L0:;
22208   __Pyx_XGIVEREF(__pyx_r);
22209   __Pyx_TraceReturn(__pyx_r);
22210   __Pyx_RefNannyFinishContext();
22211   return __pyx_r;
22212 }
22213
22214 /* "csamtools.pyx":2525
22215  *         """true if the mate is unmapped"""
22216  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
22217  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22218  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
22219  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
22220  */
22221
22222 static int __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22223 static int __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22224   int __pyx_r;
22225   int __pyx_t_1;
22226   __Pyx_TraceDeclarations
22227   __Pyx_RefNannySetupContext("__set__");
22228   __Pyx_TraceCall("__set__", __pyx_f[0], 2525);
22229
22230   /* "csamtools.pyx":2526
22231  *         def __get__(self): return (self.flag & BAM_FMUNMAP) != 0
22232  *         def __set__(self,val):
22233  *             if val: self._delegate.core.flag |= BAM_FMUNMAP             # <<<<<<<<<<<<<<
22234  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP
22235  *     property is_reverse:
22236  */
22237   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22238   if (__pyx_t_1) {
22239     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 8);
22240     goto __pyx_L5;
22241   }
22242   /*else*/ {
22243
22244     /* "csamtools.pyx":2527
22245  *         def __set__(self,val):
22246  *             if val: self._delegate.core.flag |= BAM_FMUNMAP
22247  *             else: self._delegate.core.flag &= ~BAM_FMUNMAP             # <<<<<<<<<<<<<<
22248  *     property is_reverse:
22249  *         """true if read is mapped to reverse strand"""
22250  */
22251     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~8));
22252   }
22253   __pyx_L5:;
22254
22255   __pyx_r = 0;
22256   goto __pyx_L0;
22257   __pyx_L1_error:;
22258   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_unmapped.__set__");
22259   __pyx_r = -1;
22260   __pyx_L0:;
22261   __Pyx_TraceReturn(Py_None);
22262   __Pyx_RefNannyFinishContext();
22263   return __pyx_r;
22264 }
22265
22266 /* "csamtools.pyx":2530
22267  *     property is_reverse:
22268  *         """true if read is mapped to reverse strand"""
22269  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
22270  *         def __set__(self,val):
22271  *             if val: self._delegate.core.flag |= BAM_FREVERSE
22272  */
22273
22274 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(PyObject *__pyx_v_self); /*proto*/
22275 static PyObject *__pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(PyObject *__pyx_v_self) {
22276   PyObject *__pyx_r = NULL;
22277   PyObject *__pyx_t_1 = NULL;
22278   PyObject *__pyx_t_2 = NULL;
22279   __Pyx_TraceDeclarations
22280   __Pyx_RefNannySetupContext("__get__");
22281   __Pyx_TraceCall("__get__", __pyx_f[0], 2530);
22282   __Pyx_XDECREF(__pyx_r);
22283   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22284   __Pyx_GOTREF(__pyx_t_1);
22285   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22286   __Pyx_GOTREF(__pyx_t_2);
22287   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22288   __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 = 2530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22289   __Pyx_GOTREF(__pyx_t_1);
22290   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22291   __pyx_r = __pyx_t_1;
22292   __pyx_t_1 = 0;
22293   goto __pyx_L0;
22294
22295   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22296   goto __pyx_L0;
22297   __pyx_L1_error:;
22298   __Pyx_XDECREF(__pyx_t_1);
22299   __Pyx_XDECREF(__pyx_t_2);
22300   __Pyx_AddTraceback("csamtools.AlignedRead.is_reverse.__get__");
22301   __pyx_r = NULL;
22302   __pyx_L0:;
22303   __Pyx_XGIVEREF(__pyx_r);
22304   __Pyx_TraceReturn(__pyx_r);
22305   __Pyx_RefNannyFinishContext();
22306   return __pyx_r;
22307 }
22308
22309 /* "csamtools.pyx":2531
22310  *         """true if read is mapped to reverse strand"""
22311  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
22312  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22313  *             if val: self._delegate.core.flag |= BAM_FREVERSE
22314  *             else: self._delegate.core.flag &= ~BAM_FREVERSE
22315  */
22316
22317 static int __pyx_pf_9csamtools_11AlignedRead_10is_reverse_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22318 static int __pyx_pf_9csamtools_11AlignedRead_10is_reverse_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22319   int __pyx_r;
22320   int __pyx_t_1;
22321   __Pyx_TraceDeclarations
22322   __Pyx_RefNannySetupContext("__set__");
22323   __Pyx_TraceCall("__set__", __pyx_f[0], 2531);
22324
22325   /* "csamtools.pyx":2532
22326  *         def __get__(self): return (self.flag & BAM_FREVERSE) != 0
22327  *         def __set__(self,val):
22328  *             if val: self._delegate.core.flag |= BAM_FREVERSE             # <<<<<<<<<<<<<<
22329  *             else: self._delegate.core.flag &= ~BAM_FREVERSE
22330  *     property mate_is_reverse:
22331  */
22332   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22333   if (__pyx_t_1) {
22334     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 16);
22335     goto __pyx_L5;
22336   }
22337   /*else*/ {
22338
22339     /* "csamtools.pyx":2533
22340  *         def __set__(self,val):
22341  *             if val: self._delegate.core.flag |= BAM_FREVERSE
22342  *             else: self._delegate.core.flag &= ~BAM_FREVERSE             # <<<<<<<<<<<<<<
22343  *     property mate_is_reverse:
22344  *         """true is read is mapped to reverse strand"""
22345  */
22346     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~16));
22347   }
22348   __pyx_L5:;
22349
22350   __pyx_r = 0;
22351   goto __pyx_L0;
22352   __pyx_L1_error:;
22353   __Pyx_AddTraceback("csamtools.AlignedRead.is_reverse.__set__");
22354   __pyx_r = -1;
22355   __pyx_L0:;
22356   __Pyx_TraceReturn(Py_None);
22357   __Pyx_RefNannyFinishContext();
22358   return __pyx_r;
22359 }
22360
22361 /* "csamtools.pyx":2536
22362  *     property mate_is_reverse:
22363  *         """true is read is mapped to reverse strand"""
22364  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
22365  *         def __set__(self,val):
22366  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
22367  */
22368
22369 static PyObject *__pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(PyObject *__pyx_v_self); /*proto*/
22370 static PyObject *__pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(PyObject *__pyx_v_self) {
22371   PyObject *__pyx_r = NULL;
22372   PyObject *__pyx_t_1 = NULL;
22373   PyObject *__pyx_t_2 = NULL;
22374   __Pyx_TraceDeclarations
22375   __Pyx_RefNannySetupContext("__get__");
22376   __Pyx_TraceCall("__get__", __pyx_f[0], 2536);
22377   __Pyx_XDECREF(__pyx_r);
22378   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22379   __Pyx_GOTREF(__pyx_t_1);
22380   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22381   __Pyx_GOTREF(__pyx_t_2);
22382   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22383   __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 = 2536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22384   __Pyx_GOTREF(__pyx_t_1);
22385   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22386   __pyx_r = __pyx_t_1;
22387   __pyx_t_1 = 0;
22388   goto __pyx_L0;
22389
22390   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22391   goto __pyx_L0;
22392   __pyx_L1_error:;
22393   __Pyx_XDECREF(__pyx_t_1);
22394   __Pyx_XDECREF(__pyx_t_2);
22395   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_reverse.__get__");
22396   __pyx_r = NULL;
22397   __pyx_L0:;
22398   __Pyx_XGIVEREF(__pyx_r);
22399   __Pyx_TraceReturn(__pyx_r);
22400   __Pyx_RefNannyFinishContext();
22401   return __pyx_r;
22402 }
22403
22404 /* "csamtools.pyx":2537
22405  *         """true is read is mapped to reverse strand"""
22406  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
22407  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22408  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
22409  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
22410  */
22411
22412 static int __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22413 static int __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22414   int __pyx_r;
22415   int __pyx_t_1;
22416   __Pyx_TraceDeclarations
22417   __Pyx_RefNannySetupContext("__set__");
22418   __Pyx_TraceCall("__set__", __pyx_f[0], 2537);
22419
22420   /* "csamtools.pyx":2538
22421  *         def __get__(self): return (self.flag & BAM_FMREVERSE) != 0
22422  *         def __set__(self,val):
22423  *             if val: self._delegate.core.flag |= BAM_FMREVERSE             # <<<<<<<<<<<<<<
22424  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE
22425  *     property is_read1:
22426  */
22427   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22428   if (__pyx_t_1) {
22429     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 32);
22430     goto __pyx_L5;
22431   }
22432   /*else*/ {
22433
22434     /* "csamtools.pyx":2539
22435  *         def __set__(self,val):
22436  *             if val: self._delegate.core.flag |= BAM_FMREVERSE
22437  *             else: self._delegate.core.flag &= ~BAM_FMREVERSE             # <<<<<<<<<<<<<<
22438  *     property is_read1:
22439  *         """true if this is read1"""
22440  */
22441     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~32));
22442   }
22443   __pyx_L5:;
22444
22445   __pyx_r = 0;
22446   goto __pyx_L0;
22447   __pyx_L1_error:;
22448   __Pyx_AddTraceback("csamtools.AlignedRead.mate_is_reverse.__set__");
22449   __pyx_r = -1;
22450   __pyx_L0:;
22451   __Pyx_TraceReturn(Py_None);
22452   __Pyx_RefNannyFinishContext();
22453   return __pyx_r;
22454 }
22455
22456 /* "csamtools.pyx":2542
22457  *     property is_read1:
22458  *         """true if this is read1"""
22459  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
22460  *         def __set__(self,val):
22461  *             if val: self._delegate.core.flag |= BAM_FREAD1
22462  */
22463
22464 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(PyObject *__pyx_v_self); /*proto*/
22465 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(PyObject *__pyx_v_self) {
22466   PyObject *__pyx_r = NULL;
22467   PyObject *__pyx_t_1 = NULL;
22468   PyObject *__pyx_t_2 = NULL;
22469   __Pyx_TraceDeclarations
22470   __Pyx_RefNannySetupContext("__get__");
22471   __Pyx_TraceCall("__get__", __pyx_f[0], 2542);
22472   __Pyx_XDECREF(__pyx_r);
22473   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22474   __Pyx_GOTREF(__pyx_t_1);
22475   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22476   __Pyx_GOTREF(__pyx_t_2);
22477   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22478   __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 = 2542; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22479   __Pyx_GOTREF(__pyx_t_1);
22480   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22481   __pyx_r = __pyx_t_1;
22482   __pyx_t_1 = 0;
22483   goto __pyx_L0;
22484
22485   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22486   goto __pyx_L0;
22487   __pyx_L1_error:;
22488   __Pyx_XDECREF(__pyx_t_1);
22489   __Pyx_XDECREF(__pyx_t_2);
22490   __Pyx_AddTraceback("csamtools.AlignedRead.is_read1.__get__");
22491   __pyx_r = NULL;
22492   __pyx_L0:;
22493   __Pyx_XGIVEREF(__pyx_r);
22494   __Pyx_TraceReturn(__pyx_r);
22495   __Pyx_RefNannyFinishContext();
22496   return __pyx_r;
22497 }
22498
22499 /* "csamtools.pyx":2543
22500  *         """true if this is read1"""
22501  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
22502  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22503  *             if val: self._delegate.core.flag |= BAM_FREAD1
22504  *             else: self._delegate.core.flag &= ~BAM_FREAD1
22505  */
22506
22507 static int __pyx_pf_9csamtools_11AlignedRead_8is_read1_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22508 static int __pyx_pf_9csamtools_11AlignedRead_8is_read1_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22509   int __pyx_r;
22510   int __pyx_t_1;
22511   __Pyx_TraceDeclarations
22512   __Pyx_RefNannySetupContext("__set__");
22513   __Pyx_TraceCall("__set__", __pyx_f[0], 2543);
22514
22515   /* "csamtools.pyx":2544
22516  *         def __get__(self): return (self.flag & BAM_FREAD1) != 0
22517  *         def __set__(self,val):
22518  *             if val: self._delegate.core.flag |= BAM_FREAD1             # <<<<<<<<<<<<<<
22519  *             else: self._delegate.core.flag &= ~BAM_FREAD1
22520  *     property is_read2:
22521  */
22522   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2544; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22523   if (__pyx_t_1) {
22524     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 64);
22525     goto __pyx_L5;
22526   }
22527   /*else*/ {
22528
22529     /* "csamtools.pyx":2545
22530  *         def __set__(self,val):
22531  *             if val: self._delegate.core.flag |= BAM_FREAD1
22532  *             else: self._delegate.core.flag &= ~BAM_FREAD1             # <<<<<<<<<<<<<<
22533  *     property is_read2:
22534  *         """true if this is read2"""
22535  */
22536     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~64));
22537   }
22538   __pyx_L5:;
22539
22540   __pyx_r = 0;
22541   goto __pyx_L0;
22542   __pyx_L1_error:;
22543   __Pyx_AddTraceback("csamtools.AlignedRead.is_read1.__set__");
22544   __pyx_r = -1;
22545   __pyx_L0:;
22546   __Pyx_TraceReturn(Py_None);
22547   __Pyx_RefNannyFinishContext();
22548   return __pyx_r;
22549 }
22550
22551 /* "csamtools.pyx":2548
22552  *     property is_read2:
22553  *         """true if this is read2"""
22554  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
22555  *         def __set__(self,val):
22556  *             if val: self._delegate.core.flag |= BAM_FREAD2
22557  */
22558
22559 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(PyObject *__pyx_v_self); /*proto*/
22560 static PyObject *__pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(PyObject *__pyx_v_self) {
22561   PyObject *__pyx_r = NULL;
22562   PyObject *__pyx_t_1 = NULL;
22563   PyObject *__pyx_t_2 = NULL;
22564   __Pyx_TraceDeclarations
22565   __Pyx_RefNannySetupContext("__get__");
22566   __Pyx_TraceCall("__get__", __pyx_f[0], 2548);
22567   __Pyx_XDECREF(__pyx_r);
22568   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22569   __Pyx_GOTREF(__pyx_t_1);
22570   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_128); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22571   __Pyx_GOTREF(__pyx_t_2);
22572   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22573   __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 = 2548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22574   __Pyx_GOTREF(__pyx_t_1);
22575   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22576   __pyx_r = __pyx_t_1;
22577   __pyx_t_1 = 0;
22578   goto __pyx_L0;
22579
22580   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22581   goto __pyx_L0;
22582   __pyx_L1_error:;
22583   __Pyx_XDECREF(__pyx_t_1);
22584   __Pyx_XDECREF(__pyx_t_2);
22585   __Pyx_AddTraceback("csamtools.AlignedRead.is_read2.__get__");
22586   __pyx_r = NULL;
22587   __pyx_L0:;
22588   __Pyx_XGIVEREF(__pyx_r);
22589   __Pyx_TraceReturn(__pyx_r);
22590   __Pyx_RefNannyFinishContext();
22591   return __pyx_r;
22592 }
22593
22594 /* "csamtools.pyx":2549
22595  *         """true if this is read2"""
22596  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
22597  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22598  *             if val: self._delegate.core.flag |= BAM_FREAD2
22599  *             else: self._delegate.core.flag &= ~BAM_FREAD2
22600  */
22601
22602 static int __pyx_pf_9csamtools_11AlignedRead_8is_read2_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22603 static int __pyx_pf_9csamtools_11AlignedRead_8is_read2_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22604   int __pyx_r;
22605   int __pyx_t_1;
22606   __Pyx_TraceDeclarations
22607   __Pyx_RefNannySetupContext("__set__");
22608   __Pyx_TraceCall("__set__", __pyx_f[0], 2549);
22609
22610   /* "csamtools.pyx":2550
22611  *         def __get__(self): return (self.flag & BAM_FREAD2) != 0
22612  *         def __set__(self,val):
22613  *             if val: self._delegate.core.flag |= BAM_FREAD2             # <<<<<<<<<<<<<<
22614  *             else: self._delegate.core.flag &= ~BAM_FREAD2
22615  *     property is_secondary:
22616  */
22617   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22618   if (__pyx_t_1) {
22619     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 128);
22620     goto __pyx_L5;
22621   }
22622   /*else*/ {
22623
22624     /* "csamtools.pyx":2551
22625  *         def __set__(self,val):
22626  *             if val: self._delegate.core.flag |= BAM_FREAD2
22627  *             else: self._delegate.core.flag &= ~BAM_FREAD2             # <<<<<<<<<<<<<<
22628  *     property is_secondary:
22629  *         """true if not primary alignment"""
22630  */
22631     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~128));
22632   }
22633   __pyx_L5:;
22634
22635   __pyx_r = 0;
22636   goto __pyx_L0;
22637   __pyx_L1_error:;
22638   __Pyx_AddTraceback("csamtools.AlignedRead.is_read2.__set__");
22639   __pyx_r = -1;
22640   __pyx_L0:;
22641   __Pyx_TraceReturn(Py_None);
22642   __Pyx_RefNannyFinishContext();
22643   return __pyx_r;
22644 }
22645
22646 /* "csamtools.pyx":2554
22647  *     property is_secondary:
22648  *         """true if not primary alignment"""
22649  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
22650  *         def __set__(self,val):
22651  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
22652  */
22653
22654 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(PyObject *__pyx_v_self); /*proto*/
22655 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(PyObject *__pyx_v_self) {
22656   PyObject *__pyx_r = NULL;
22657   PyObject *__pyx_t_1 = NULL;
22658   PyObject *__pyx_t_2 = NULL;
22659   __Pyx_TraceDeclarations
22660   __Pyx_RefNannySetupContext("__get__");
22661   __Pyx_TraceCall("__get__", __pyx_f[0], 2554);
22662   __Pyx_XDECREF(__pyx_r);
22663   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22664   __Pyx_GOTREF(__pyx_t_1);
22665   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22666   __Pyx_GOTREF(__pyx_t_2);
22667   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22668   __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 = 2554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22669   __Pyx_GOTREF(__pyx_t_1);
22670   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22671   __pyx_r = __pyx_t_1;
22672   __pyx_t_1 = 0;
22673   goto __pyx_L0;
22674
22675   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22676   goto __pyx_L0;
22677   __pyx_L1_error:;
22678   __Pyx_XDECREF(__pyx_t_1);
22679   __Pyx_XDECREF(__pyx_t_2);
22680   __Pyx_AddTraceback("csamtools.AlignedRead.is_secondary.__get__");
22681   __pyx_r = NULL;
22682   __pyx_L0:;
22683   __Pyx_XGIVEREF(__pyx_r);
22684   __Pyx_TraceReturn(__pyx_r);
22685   __Pyx_RefNannyFinishContext();
22686   return __pyx_r;
22687 }
22688
22689 /* "csamtools.pyx":2555
22690  *         """true if not primary alignment"""
22691  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
22692  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22693  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
22694  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
22695  */
22696
22697 static int __pyx_pf_9csamtools_11AlignedRead_12is_secondary_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22698 static int __pyx_pf_9csamtools_11AlignedRead_12is_secondary_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22699   int __pyx_r;
22700   int __pyx_t_1;
22701   __Pyx_TraceDeclarations
22702   __Pyx_RefNannySetupContext("__set__");
22703   __Pyx_TraceCall("__set__", __pyx_f[0], 2555);
22704
22705   /* "csamtools.pyx":2556
22706  *         def __get__(self): return (self.flag & BAM_FSECONDARY) != 0
22707  *         def __set__(self,val):
22708  *             if val: self._delegate.core.flag |= BAM_FSECONDARY             # <<<<<<<<<<<<<<
22709  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY
22710  *     property is_qcfail:
22711  */
22712   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22713   if (__pyx_t_1) {
22714     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 256);
22715     goto __pyx_L5;
22716   }
22717   /*else*/ {
22718
22719     /* "csamtools.pyx":2557
22720  *         def __set__(self,val):
22721  *             if val: self._delegate.core.flag |= BAM_FSECONDARY
22722  *             else: self._delegate.core.flag &= ~BAM_FSECONDARY             # <<<<<<<<<<<<<<
22723  *     property is_qcfail:
22724  *         """true if QC failure"""
22725  */
22726     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~256));
22727   }
22728   __pyx_L5:;
22729
22730   __pyx_r = 0;
22731   goto __pyx_L0;
22732   __pyx_L1_error:;
22733   __Pyx_AddTraceback("csamtools.AlignedRead.is_secondary.__set__");
22734   __pyx_r = -1;
22735   __pyx_L0:;
22736   __Pyx_TraceReturn(Py_None);
22737   __Pyx_RefNannyFinishContext();
22738   return __pyx_r;
22739 }
22740
22741 /* "csamtools.pyx":2560
22742  *     property is_qcfail:
22743  *         """true if QC failure"""
22744  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
22745  *         def __set__(self,val):
22746  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
22747  */
22748
22749 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(PyObject *__pyx_v_self); /*proto*/
22750 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(PyObject *__pyx_v_self) {
22751   PyObject *__pyx_r = NULL;
22752   PyObject *__pyx_t_1 = NULL;
22753   PyObject *__pyx_t_2 = NULL;
22754   __Pyx_TraceDeclarations
22755   __Pyx_RefNannySetupContext("__get__");
22756   __Pyx_TraceCall("__get__", __pyx_f[0], 2560);
22757   __Pyx_XDECREF(__pyx_r);
22758   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22759   __Pyx_GOTREF(__pyx_t_1);
22760   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_512); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22761   __Pyx_GOTREF(__pyx_t_2);
22762   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22763   __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 = 2560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22764   __Pyx_GOTREF(__pyx_t_1);
22765   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22766   __pyx_r = __pyx_t_1;
22767   __pyx_t_1 = 0;
22768   goto __pyx_L0;
22769
22770   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22771   goto __pyx_L0;
22772   __pyx_L1_error:;
22773   __Pyx_XDECREF(__pyx_t_1);
22774   __Pyx_XDECREF(__pyx_t_2);
22775   __Pyx_AddTraceback("csamtools.AlignedRead.is_qcfail.__get__");
22776   __pyx_r = NULL;
22777   __pyx_L0:;
22778   __Pyx_XGIVEREF(__pyx_r);
22779   __Pyx_TraceReturn(__pyx_r);
22780   __Pyx_RefNannyFinishContext();
22781   return __pyx_r;
22782 }
22783
22784 /* "csamtools.pyx":2561
22785  *         """true if QC failure"""
22786  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
22787  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22788  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
22789  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
22790  */
22791
22792 static int __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22793 static int __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22794   int __pyx_r;
22795   int __pyx_t_1;
22796   __Pyx_TraceDeclarations
22797   __Pyx_RefNannySetupContext("__set__");
22798   __Pyx_TraceCall("__set__", __pyx_f[0], 2561);
22799
22800   /* "csamtools.pyx":2562
22801  *         def __get__(self): return (self.flag & BAM_FQCFAIL) != 0
22802  *         def __set__(self,val):
22803  *             if val: self._delegate.core.flag |= BAM_FQCFAIL             # <<<<<<<<<<<<<<
22804  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL
22805  *     property is_duplicate:
22806  */
22807   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22808   if (__pyx_t_1) {
22809     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 512);
22810     goto __pyx_L5;
22811   }
22812   /*else*/ {
22813
22814     /* "csamtools.pyx":2563
22815  *         def __set__(self,val):
22816  *             if val: self._delegate.core.flag |= BAM_FQCFAIL
22817  *             else: self._delegate.core.flag &= ~BAM_FQCFAIL             # <<<<<<<<<<<<<<
22818  *     property is_duplicate:
22819  *         """true if optical or PCR duplicate"""
22820  */
22821     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~512));
22822   }
22823   __pyx_L5:;
22824
22825   __pyx_r = 0;
22826   goto __pyx_L0;
22827   __pyx_L1_error:;
22828   __Pyx_AddTraceback("csamtools.AlignedRead.is_qcfail.__set__");
22829   __pyx_r = -1;
22830   __pyx_L0:;
22831   __Pyx_TraceReturn(Py_None);
22832   __Pyx_RefNannyFinishContext();
22833   return __pyx_r;
22834 }
22835
22836 /* "csamtools.pyx":2566
22837  *     property is_duplicate:
22838  *         """true if optical or PCR duplicate"""
22839  *         def __get__(self): return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
22840  *         def __set__(self,val):
22841  *             if val: self._delegate.core.flag |= BAM_FDUP
22842  */
22843
22844 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(PyObject *__pyx_v_self); /*proto*/
22845 static PyObject *__pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(PyObject *__pyx_v_self) {
22846   PyObject *__pyx_r = NULL;
22847   PyObject *__pyx_t_1 = NULL;
22848   PyObject *__pyx_t_2 = NULL;
22849   __Pyx_TraceDeclarations
22850   __Pyx_RefNannySetupContext("__get__");
22851   __Pyx_TraceCall("__get__", __pyx_f[0], 2566);
22852   __Pyx_XDECREF(__pyx_r);
22853   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22854   __Pyx_GOTREF(__pyx_t_1);
22855   __pyx_t_2 = PyNumber_And(__pyx_t_1, __pyx_int_1024); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22856   __Pyx_GOTREF(__pyx_t_2);
22857   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
22858   __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 = 2566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22859   __Pyx_GOTREF(__pyx_t_1);
22860   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
22861   __pyx_r = __pyx_t_1;
22862   __pyx_t_1 = 0;
22863   goto __pyx_L0;
22864
22865   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
22866   goto __pyx_L0;
22867   __pyx_L1_error:;
22868   __Pyx_XDECREF(__pyx_t_1);
22869   __Pyx_XDECREF(__pyx_t_2);
22870   __Pyx_AddTraceback("csamtools.AlignedRead.is_duplicate.__get__");
22871   __pyx_r = NULL;
22872   __pyx_L0:;
22873   __Pyx_XGIVEREF(__pyx_r);
22874   __Pyx_TraceReturn(__pyx_r);
22875   __Pyx_RefNannyFinishContext();
22876   return __pyx_r;
22877 }
22878
22879 /* "csamtools.pyx":2567
22880  *         """true if optical or PCR duplicate"""
22881  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
22882  *         def __set__(self,val):             # <<<<<<<<<<<<<<
22883  *             if val: self._delegate.core.flag |= BAM_FDUP
22884  *             else: self._delegate.core.flag &= ~BAM_FDUP
22885  */
22886
22887 static int __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
22888 static int __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
22889   int __pyx_r;
22890   int __pyx_t_1;
22891   __Pyx_TraceDeclarations
22892   __Pyx_RefNannySetupContext("__set__");
22893   __Pyx_TraceCall("__set__", __pyx_f[0], 2567);
22894
22895   /* "csamtools.pyx":2568
22896  *         def __get__(self): return (self.flag & BAM_FDUP) != 0
22897  *         def __set__(self,val):
22898  *             if val: self._delegate.core.flag |= BAM_FDUP             # <<<<<<<<<<<<<<
22899  *             else: self._delegate.core.flag &= ~BAM_FDUP
22900  *     property positions:
22901  */
22902   __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_val); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22903   if (__pyx_t_1) {
22904     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag | 1024);
22905     goto __pyx_L5;
22906   }
22907   /*else*/ {
22908
22909     /* "csamtools.pyx":2569
22910  *         def __set__(self,val):
22911  *             if val: self._delegate.core.flag |= BAM_FDUP
22912  *             else: self._delegate.core.flag &= ~BAM_FDUP             # <<<<<<<<<<<<<<
22913  *     property positions:
22914  *         """a list of reference positions that this read aligns to."""
22915  */
22916     ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag = (((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate->core.flag & (~1024));
22917   }
22918   __pyx_L5:;
22919
22920   __pyx_r = 0;
22921   goto __pyx_L0;
22922   __pyx_L1_error:;
22923   __Pyx_AddTraceback("csamtools.AlignedRead.is_duplicate.__set__");
22924   __pyx_r = -1;
22925   __pyx_L0:;
22926   __Pyx_TraceReturn(Py_None);
22927   __Pyx_RefNannyFinishContext();
22928   return __pyx_r;
22929 }
22930
22931 /* "csamtools.pyx":2572
22932  *     property positions:
22933  *         """a list of reference positions that this read aligns to."""
22934  *         def __get__(self):             # <<<<<<<<<<<<<<
22935  *             cdef uint32_t k, i, pos
22936  *             cdef int op
22937  */
22938
22939 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9positions___get__(PyObject *__pyx_v_self); /*proto*/
22940 static PyObject *__pyx_pf_9csamtools_11AlignedRead_9positions___get__(PyObject *__pyx_v_self) {
22941   uint32_t __pyx_v_k;
22942   uint32_t __pyx_v_i;
22943   uint32_t __pyx_v_pos;
22944   int __pyx_v_op;
22945   uint32_t *__pyx_v_cigar_p;
22946   bam1_t *__pyx_v_src;
22947   PyObject *__pyx_v_result;
22948   PyObject *__pyx_v_l;
22949   PyObject *__pyx_r = NULL;
22950   PyObject *__pyx_t_1 = NULL;
22951   int __pyx_t_2;
22952   uint32_t __pyx_t_3;
22953   PyObject *__pyx_t_4 = NULL;
22954   uint32_t __pyx_t_5;
22955   int __pyx_t_6;
22956   __Pyx_TraceDeclarations
22957   __Pyx_RefNannySetupContext("__get__");
22958   __Pyx_TraceCall("__get__", __pyx_f[0], 2572);
22959   __pyx_v_result = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
22960   __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
22961
22962   /* "csamtools.pyx":2578
22963  *             cdef bam1_t * src
22964  * 
22965  *             result = []             # <<<<<<<<<<<<<<
22966  *             src = self._delegate
22967  *             if src.core.n_cigar == 0: return []
22968  */
22969   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2578; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22970   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
22971   __Pyx_DECREF(((PyObject *)__pyx_v_result));
22972   __pyx_v_result = __pyx_t_1;
22973   __pyx_t_1 = 0;
22974
22975   /* "csamtools.pyx":2579
22976  * 
22977  *             result = []
22978  *             src = self._delegate             # <<<<<<<<<<<<<<
22979  *             if src.core.n_cigar == 0: return []
22980  * 
22981  */
22982   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
22983
22984   /* "csamtools.pyx":2580
22985  *             result = []
22986  *             src = self._delegate
22987  *             if src.core.n_cigar == 0: return []             # <<<<<<<<<<<<<<
22988  * 
22989  *             pos = src.core.pos
22990  */
22991   __pyx_t_2 = (__pyx_v_src->core.n_cigar == 0);
22992   if (__pyx_t_2) {
22993     __Pyx_XDECREF(__pyx_r);
22994     __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
22995     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
22996     __pyx_r = ((PyObject *)__pyx_t_1);
22997     __pyx_t_1 = 0;
22998     goto __pyx_L0;
22999     goto __pyx_L5;
23000   }
23001   __pyx_L5:;
23002
23003   /* "csamtools.pyx":2582
23004  *             if src.core.n_cigar == 0: return []
23005  * 
23006  *             pos = src.core.pos             # <<<<<<<<<<<<<<
23007  * 
23008  *             cigar_p = bam1_cigar(src)
23009  */
23010   __pyx_v_pos = __pyx_v_src->core.pos;
23011
23012   /* "csamtools.pyx":2584
23013  *             pos = src.core.pos
23014  * 
23015  *             cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
23016  *             for k from 0 <= k < src.core.n_cigar:
23017  *                 op = cigar_p[k] & BAM_CIGAR_MASK
23018  */
23019   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
23020
23021   /* "csamtools.pyx":2585
23022  * 
23023  *             cigar_p = bam1_cigar(src)
23024  *             for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
23025  *                 op = cigar_p[k] & BAM_CIGAR_MASK
23026  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
23027  */
23028   __pyx_t_3 = __pyx_v_src->core.n_cigar;
23029   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {
23030
23031     /* "csamtools.pyx":2586
23032  *             cigar_p = bam1_cigar(src)
23033  *             for k from 0 <= k < src.core.n_cigar:
23034  *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
23035  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
23036  *                 if op == BAM_CMATCH:
23037  */
23038     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
23039
23040     /* "csamtools.pyx":2587
23041  *             for k from 0 <= k < src.core.n_cigar:
23042  *                 op = cigar_p[k] & BAM_CIGAR_MASK
23043  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
23044  *                 if op == BAM_CMATCH:
23045  *                     for i from pos <= i < pos + l:
23046  */
23047     __pyx_t_1 = PyInt_FromLong(((__pyx_v_cigar_p[__pyx_v_k]) >> 4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2587; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23048     __Pyx_GOTREF(__pyx_t_1);
23049     __Pyx_DECREF(__pyx_v_l);
23050     __pyx_v_l = __pyx_t_1;
23051     __pyx_t_1 = 0;
23052
23053     /* "csamtools.pyx":2588
23054  *                 op = cigar_p[k] & BAM_CIGAR_MASK
23055  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
23056  *                 if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
23057  *                     for i from pos <= i < pos + l:
23058  *                         result.append( i )
23059  */
23060     __pyx_t_2 = (__pyx_v_op == 0);
23061     if (__pyx_t_2) {
23062
23063       /* "csamtools.pyx":2589
23064  *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
23065  *                 if op == BAM_CMATCH:
23066  *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
23067  *                         result.append( i )
23068  * 
23069  */
23070       __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23071       __Pyx_GOTREF(__pyx_t_1);
23072       __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23073       __Pyx_GOTREF(__pyx_t_4);
23074       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
23075       __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 = 2589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23076       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
23077       for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_5; __pyx_v_i++) {
23078
23079         /* "csamtools.pyx":2590
23080  *                 if op == BAM_CMATCH:
23081  *                     for i from pos <= i < pos + l:
23082  *                         result.append( i )             # <<<<<<<<<<<<<<
23083  * 
23084  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
23085  */
23086         if (unlikely(__pyx_v_result == Py_None)) {
23087           PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
23088         }
23089         __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23090         __Pyx_GOTREF(__pyx_t_4);
23091         __pyx_t_6 = PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23092         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
23093       }
23094       goto __pyx_L8;
23095     }
23096     __pyx_L8:;
23097
23098     /* "csamtools.pyx":2592
23099  *                         result.append( i )
23100  * 
23101  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
23102  *                     pos += l
23103  * 
23104  */
23105     switch (__pyx_v_op) {
23106       case 0:
23107       case 2:
23108       case 3:
23109
23110       /* "csamtools.pyx":2593
23111  * 
23112  *                 if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
23113  *                     pos += l             # <<<<<<<<<<<<<<
23114  * 
23115  *             return result
23116  */
23117       __pyx_t_4 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23118       __Pyx_GOTREF(__pyx_t_4);
23119       __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_v_l); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23120       __Pyx_GOTREF(__pyx_t_1);
23121       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
23122       __pyx_t_5 = __Pyx_PyInt_from_py_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_5 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23123       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
23124       __pyx_v_pos = __pyx_t_5;
23125       break;
23126     }
23127   }
23128
23129   /* "csamtools.pyx":2595
23130  *                     pos += l
23131  * 
23132  *             return result             # <<<<<<<<<<<<<<
23133  * 
23134  *     def overlap( self, uint32_t start, uint32_t end ):
23135  */
23136   __Pyx_XDECREF(__pyx_r);
23137   __Pyx_INCREF(((PyObject *)__pyx_v_result));
23138   __pyx_r = ((PyObject *)__pyx_v_result);
23139   goto __pyx_L0;
23140
23141   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23142   goto __pyx_L0;
23143   __pyx_L1_error:;
23144   __Pyx_XDECREF(__pyx_t_1);
23145   __Pyx_XDECREF(__pyx_t_4);
23146   __Pyx_AddTraceback("csamtools.AlignedRead.positions.__get__");
23147   __pyx_r = NULL;
23148   __pyx_L0:;
23149   __Pyx_DECREF(__pyx_v_result);
23150   __Pyx_DECREF(__pyx_v_l);
23151   __Pyx_XGIVEREF(__pyx_r);
23152   __Pyx_TraceReturn(__pyx_r);
23153   __Pyx_RefNannyFinishContext();
23154   return __pyx_r;
23155 }
23156
23157 /* "csamtools.pyx":2597
23158  *             return result
23159  * 
23160  *     def overlap( self, uint32_t start, uint32_t end ):             # <<<<<<<<<<<<<<
23161  *         """return number of aligned bases of read overlapping the interval *start* and *end*
23162  *         on the reference sequence.
23163  */
23164
23165 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
23166 static char __pyx_doc_9csamtools_11AlignedRead_5overlap[] = "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        ";
23167 static PyObject *__pyx_pf_9csamtools_11AlignedRead_5overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
23168   uint32_t __pyx_v_start;
23169   uint32_t __pyx_v_end;
23170   uint32_t __pyx_v_k;
23171   uint32_t __pyx_v_pos;
23172   uint32_t __pyx_v_overlap;
23173   int __pyx_v_op;
23174   int __pyx_v_o;
23175   uint32_t *__pyx_v_cigar_p;
23176   bam1_t *__pyx_v_src;
23177   PyObject *__pyx_v_l;
23178   PyObject *__pyx_r = NULL;
23179   int __pyx_t_1;
23180   uint32_t __pyx_t_2;
23181   PyObject *__pyx_t_3 = NULL;
23182   uint32_t __pyx_t_4;
23183   PyObject *__pyx_t_5 = NULL;
23184   PyObject *__pyx_t_6 = NULL;
23185   PyObject *__pyx_t_7 = NULL;
23186   uint32_t __pyx_t_8;
23187   uint32_t __pyx_t_9;
23188   int __pyx_t_10;
23189   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0};
23190   __Pyx_TraceDeclarations
23191   __Pyx_RefNannySetupContext("overlap");
23192   __Pyx_TraceCall("overlap", __pyx_f[0], 2597);
23193   if (unlikely(__pyx_kwds)) {
23194     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
23195     PyObject* values[2] = {0,0};
23196     switch (PyTuple_GET_SIZE(__pyx_args)) {
23197       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
23198       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
23199       case  0: break;
23200       default: goto __pyx_L5_argtuple_error;
23201     }
23202     switch (PyTuple_GET_SIZE(__pyx_args)) {
23203       case  0:
23204       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
23205       if (likely(values[0])) kw_args--;
23206       else goto __pyx_L5_argtuple_error;
23207       case  1:
23208       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
23209       if (likely(values[1])) kw_args--;
23210       else {
23211         __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23212       }
23213     }
23214     if (unlikely(kw_args > 0)) {
23215       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23216     }
23217     __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 = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23218     __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 = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23219   } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
23220     goto __pyx_L5_argtuple_error;
23221   } else {
23222     __pyx_v_start = __Pyx_PyInt_from_py_uint32_t(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23223     __pyx_v_end = __Pyx_PyInt_from_py_uint32_t(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23224   }
23225   goto __pyx_L4_argument_unpacking_done;
23226   __pyx_L5_argtuple_error:;
23227   __Pyx_RaiseArgtupleInvalid("overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
23228   __pyx_L3_error:;
23229   __Pyx_AddTraceback("csamtools.AlignedRead.overlap");
23230   __Pyx_RefNannyFinishContext();
23231   return NULL;
23232   __pyx_L4_argument_unpacking_done:;
23233   __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
23234
23235   /* "csamtools.pyx":2606
23236  *         cdef bam1_t * src
23237  * 
23238  *         overlap = 0             # <<<<<<<<<<<<<<
23239  * 
23240  *         src = self._delegate
23241  */
23242   __pyx_v_overlap = 0;
23243
23244   /* "csamtools.pyx":2608
23245  *         overlap = 0
23246  * 
23247  *         src = self._delegate             # <<<<<<<<<<<<<<
23248  *         if src.core.n_cigar == 0: return 0
23249  *         pos = src.core.pos
23250  */
23251   __pyx_v_src = ((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate;
23252
23253   /* "csamtools.pyx":2609
23254  * 
23255  *         src = self._delegate
23256  *         if src.core.n_cigar == 0: return 0             # <<<<<<<<<<<<<<
23257  *         pos = src.core.pos
23258  *         o = 0
23259  */
23260   __pyx_t_1 = (__pyx_v_src->core.n_cigar == 0);
23261   if (__pyx_t_1) {
23262     __Pyx_XDECREF(__pyx_r);
23263     __Pyx_INCREF(__pyx_int_0);
23264     __pyx_r = __pyx_int_0;
23265     goto __pyx_L0;
23266     goto __pyx_L6;
23267   }
23268   __pyx_L6:;
23269
23270   /* "csamtools.pyx":2610
23271  *         src = self._delegate
23272  *         if src.core.n_cigar == 0: return 0
23273  *         pos = src.core.pos             # <<<<<<<<<<<<<<
23274  *         o = 0
23275  * 
23276  */
23277   __pyx_v_pos = __pyx_v_src->core.pos;
23278
23279   /* "csamtools.pyx":2611
23280  *         if src.core.n_cigar == 0: return 0
23281  *         pos = src.core.pos
23282  *         o = 0             # <<<<<<<<<<<<<<
23283  * 
23284  *         cigar_p = bam1_cigar(src)
23285  */
23286   __pyx_v_o = 0;
23287
23288   /* "csamtools.pyx":2613
23289  *         o = 0
23290  * 
23291  *         cigar_p = bam1_cigar(src)             # <<<<<<<<<<<<<<
23292  *         for k from 0 <= k < src.core.n_cigar:
23293  *             op = cigar_p[k] & BAM_CIGAR_MASK
23294  */
23295   __pyx_v_cigar_p = bam1_cigar(__pyx_v_src);
23296
23297   /* "csamtools.pyx":2614
23298  * 
23299  *         cigar_p = bam1_cigar(src)
23300  *         for k from 0 <= k < src.core.n_cigar:             # <<<<<<<<<<<<<<
23301  *             op = cigar_p[k] & BAM_CIGAR_MASK
23302  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
23303  */
23304   __pyx_t_2 = __pyx_v_src->core.n_cigar;
23305   for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {
23306
23307     /* "csamtools.pyx":2615
23308  *         cigar_p = bam1_cigar(src)
23309  *         for k from 0 <= k < src.core.n_cigar:
23310  *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
23311  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
23312  * 
23313  */
23314     __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);
23315
23316     /* "csamtools.pyx":2616
23317  *         for k from 0 <= k < src.core.n_cigar:
23318  *             op = cigar_p[k] & BAM_CIGAR_MASK
23319  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
23320  * 
23321  *             if op == BAM_CMATCH:
23322  */
23323     __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 = 2616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23324     __Pyx_GOTREF(__pyx_t_3);
23325     __Pyx_DECREF(__pyx_v_l);
23326     __pyx_v_l = __pyx_t_3;
23327     __pyx_t_3 = 0;
23328
23329     /* "csamtools.pyx":2618
23330  *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
23331  * 
23332  *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
23333  *                 o = min( pos + l, end) - max( pos, start )
23334  *                 if o > 0: overlap += o
23335  */
23336     __pyx_t_1 = (__pyx_v_op == 0);
23337     if (__pyx_t_1) {
23338
23339       /* "csamtools.pyx":2619
23340  * 
23341  *             if op == BAM_CMATCH:
23342  *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
23343  *                 if o > 0: overlap += o
23344  * 
23345  */
23346       __pyx_t_4 = __pyx_v_end;
23347       __pyx_t_3 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23348       __Pyx_GOTREF(__pyx_t_3);
23349       __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23350       __Pyx_GOTREF(__pyx_t_5);
23351       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23352       __pyx_t_6 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23353       __Pyx_GOTREF(__pyx_t_6);
23354       __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 = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23355       __Pyx_GOTREF(__pyx_t_7);
23356       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
23357       __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23358       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
23359       if (__pyx_t_1) {
23360         __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23361         __Pyx_GOTREF(__pyx_t_7);
23362         __pyx_t_3 = __pyx_t_7;
23363         __pyx_t_7 = 0;
23364       } else {
23365         __Pyx_INCREF(__pyx_t_5);
23366         __pyx_t_3 = __pyx_t_5;
23367       }
23368       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
23369       __pyx_t_4 = __pyx_v_start;
23370       __pyx_t_8 = __pyx_v_pos;
23371       if ((__pyx_t_4 > __pyx_t_8)) {
23372         __pyx_t_9 = __pyx_t_4;
23373       } else {
23374         __pyx_t_9 = __pyx_t_8;
23375       }
23376       __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_t_9); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23377       __Pyx_GOTREF(__pyx_t_5);
23378       __pyx_t_7 = PyNumber_Subtract(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23379       __Pyx_GOTREF(__pyx_t_7);
23380       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23381       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
23382       __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 = 2619; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23383       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
23384       __pyx_v_o = __pyx_t_10;
23385
23386       /* "csamtools.pyx":2620
23387  *             if op == BAM_CMATCH:
23388  *                 o = min( pos + l, end) - max( pos, start )
23389  *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
23390  * 
23391  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
23392  */
23393       __pyx_t_1 = (__pyx_v_o > 0);
23394       if (__pyx_t_1) {
23395         __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o);
23396         goto __pyx_L10;
23397       }
23398       __pyx_L10:;
23399       goto __pyx_L9;
23400     }
23401     __pyx_L9:;
23402
23403     /* "csamtools.pyx":2622
23404  *                 if o > 0: overlap += o
23405  * 
23406  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
23407  *                 pos += l
23408  * 
23409  */
23410     switch (__pyx_v_op) {
23411       case 0:
23412       case 2:
23413       case 3:
23414
23415       /* "csamtools.pyx":2623
23416  * 
23417  *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
23418  *                 pos += l             # <<<<<<<<<<<<<<
23419  * 
23420  *         return overlap
23421  */
23422       __pyx_t_7 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23423       __Pyx_GOTREF(__pyx_t_7);
23424       __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23425       __Pyx_GOTREF(__pyx_t_5);
23426       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
23427       __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 = 2623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23428       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
23429       __pyx_v_pos = __pyx_t_9;
23430       break;
23431     }
23432   }
23433
23434   /* "csamtools.pyx":2625
23435  *                 pos += l
23436  * 
23437  *         return overlap             # <<<<<<<<<<<<<<
23438  * 
23439  *     def opt(self, tag):
23440  */
23441   __Pyx_XDECREF(__pyx_r);
23442   __pyx_t_5 = __Pyx_PyInt_to_py_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23443   __Pyx_GOTREF(__pyx_t_5);
23444   __pyx_r = __pyx_t_5;
23445   __pyx_t_5 = 0;
23446   goto __pyx_L0;
23447
23448   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23449   goto __pyx_L0;
23450   __pyx_L1_error:;
23451   __Pyx_XDECREF(__pyx_t_3);
23452   __Pyx_XDECREF(__pyx_t_5);
23453   __Pyx_XDECREF(__pyx_t_6);
23454   __Pyx_XDECREF(__pyx_t_7);
23455   __Pyx_AddTraceback("csamtools.AlignedRead.overlap");
23456   __pyx_r = NULL;
23457   __pyx_L0:;
23458   __Pyx_DECREF(__pyx_v_l);
23459   __Pyx_XGIVEREF(__pyx_r);
23460   __Pyx_TraceReturn(__pyx_r);
23461   __Pyx_RefNannyFinishContext();
23462   return __pyx_r;
23463 }
23464
23465 /* "csamtools.pyx":2627
23466  *         return overlap
23467  * 
23468  *     def opt(self, tag):             # <<<<<<<<<<<<<<
23469  *         """retrieves optional data given a two-letter *tag*"""
23470  *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
23471  */
23472
23473 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
23474 static char __pyx_doc_9csamtools_11AlignedRead_6opt[] = "AlignedRead.opt(self, tag)\nretrieves optional data given a two-letter *tag*";
23475 static PyObject *__pyx_pf_9csamtools_11AlignedRead_6opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
23476   uint8_t *__pyx_v_v;
23477   PyObject *__pyx_v_type;
23478   PyObject *__pyx_r = NULL;
23479   char *__pyx_t_1;
23480   int __pyx_t_2;
23481   PyObject *__pyx_t_3 = NULL;
23482   PyObject *__pyx_t_4 = NULL;
23483   int __pyx_t_5;
23484   int __pyx_t_6;
23485   int __pyx_t_7;
23486   int __pyx_t_8;
23487   __Pyx_TraceDeclarations
23488   __Pyx_RefNannySetupContext("opt");
23489   __Pyx_TraceCall("opt", __pyx_f[0], 2627);
23490   __pyx_v_type = Py_None; __Pyx_INCREF(Py_None);
23491
23492   /* "csamtools.pyx":2631
23493  *         #see bam_aux.c: bam_aux_get() and bam_aux2i() etc
23494  *         cdef uint8_t * v
23495  *         v = bam_aux_get(self._delegate, tag)             # <<<<<<<<<<<<<<
23496  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
23497  *         type = chr(v[0])
23498  */
23499   __pyx_t_1 = PyBytes_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23500   __pyx_v_v = bam_aux_get(((struct __pyx_obj_9csamtools_AlignedRead *)__pyx_v_self)->_delegate, __pyx_t_1);
23501
23502   /* "csamtools.pyx":2632
23503  *         cdef uint8_t * v
23504  *         v = bam_aux_get(self._delegate, tag)
23505  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )             # <<<<<<<<<<<<<<
23506  *         type = chr(v[0])
23507  *         if type == 'c' or type == 'C' or type == 's' or type == 'S':
23508  */
23509   __pyx_t_2 = (__pyx_v_v == NULL);
23510   if (__pyx_t_2) {
23511     __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_135), __pyx_v_tag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23512     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
23513     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23514     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
23515     PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3));
23516     __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
23517     __pyx_t_3 = 0;
23518     __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23519     __Pyx_GOTREF(__pyx_t_3);
23520     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
23521     __Pyx_Raise(__pyx_t_3, 0, 0);
23522     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23523     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23524     goto __pyx_L5;
23525   }
23526   __pyx_L5:;
23527
23528   /* "csamtools.pyx":2633
23529  *         v = bam_aux_get(self._delegate, tag)
23530  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
23531  *         type = chr(v[0])             # <<<<<<<<<<<<<<
23532  *         if type == 'c' or type == 'C' or type == 's' or type == 'S':
23533  *             return <int>bam_aux2i(v)
23534  */
23535   __pyx_t_3 = __Pyx_PyInt_to_py_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23536   __Pyx_GOTREF(__pyx_t_3);
23537   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23538   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
23539   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
23540   __Pyx_GIVEREF(__pyx_t_3);
23541   __pyx_t_3 = 0;
23542   __pyx_t_3 = PyObject_Call(__pyx_builtin_chr, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23543   __Pyx_GOTREF(__pyx_t_3);
23544   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
23545   __Pyx_DECREF(__pyx_v_type);
23546   __pyx_v_type = __pyx_t_3;
23547   __pyx_t_3 = 0;
23548
23549   /* "csamtools.pyx":2634
23550  *         if v == NULL: raise KeyError( "tag '%s' not present" % tag )
23551  *         type = chr(v[0])
23552  *         if type == 'c' or type == 'C' or type == 's' or type == 'S':             # <<<<<<<<<<<<<<
23553  *             return <int>bam_aux2i(v)
23554  *         elif type == 'i' or type == 'I':
23555  */
23556   __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__c), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23557   __Pyx_GOTREF(__pyx_t_3);
23558   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23559   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23560   if (!__pyx_t_2) {
23561     __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__C), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23562     __Pyx_GOTREF(__pyx_t_3);
23563     __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23564     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23565     if (!__pyx_t_5) {
23566       __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__s), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23567       __Pyx_GOTREF(__pyx_t_3);
23568       __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23569       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23570       if (!__pyx_t_6) {
23571         __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__S), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23572         __Pyx_GOTREF(__pyx_t_3);
23573         __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23574         __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23575         __pyx_t_8 = __pyx_t_7;
23576       } else {
23577         __pyx_t_8 = __pyx_t_6;
23578       }
23579       __pyx_t_6 = __pyx_t_8;
23580     } else {
23581       __pyx_t_6 = __pyx_t_5;
23582     }
23583     __pyx_t_5 = __pyx_t_6;
23584   } else {
23585     __pyx_t_5 = __pyx_t_2;
23586   }
23587   if (__pyx_t_5) {
23588
23589     /* "csamtools.pyx":2635
23590  *         type = chr(v[0])
23591  *         if type == 'c' or type == 'C' or type == 's' or type == 'S':
23592  *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
23593  *         elif type == 'i' or type == 'I':
23594  *             return <int32_t>bam_aux2i(v)
23595  */
23596     __Pyx_XDECREF(__pyx_r);
23597     __pyx_t_3 = PyInt_FromLong(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23598     __Pyx_GOTREF(__pyx_t_3);
23599     __pyx_r = __pyx_t_3;
23600     __pyx_t_3 = 0;
23601     goto __pyx_L0;
23602     goto __pyx_L6;
23603   }
23604
23605   /* "csamtools.pyx":2636
23606  *         if type == 'c' or type == 'C' or type == 's' or type == 'S':
23607  *             return <int>bam_aux2i(v)
23608  *         elif type == 'i' or type == 'I':             # <<<<<<<<<<<<<<
23609  *             return <int32_t>bam_aux2i(v)
23610  *         elif type == 'f' or type == 'F':
23611  */
23612   __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__i), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23613   __Pyx_GOTREF(__pyx_t_3);
23614   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23615   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23616   if (!__pyx_t_5) {
23617     __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__I), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23618     __Pyx_GOTREF(__pyx_t_3);
23619     __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23620     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23621     __pyx_t_6 = __pyx_t_2;
23622   } else {
23623     __pyx_t_6 = __pyx_t_5;
23624   }
23625   if (__pyx_t_6) {
23626
23627     /* "csamtools.pyx":2637
23628  *             return <int>bam_aux2i(v)
23629  *         elif type == 'i' or type == 'I':
23630  *             return <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
23631  *         elif type == 'f' or type == 'F':
23632  *             return <float>bam_aux2f(v)
23633  */
23634     __Pyx_XDECREF(__pyx_r);
23635     __pyx_t_3 = __Pyx_PyInt_to_py_int32_t(bam_aux2i(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23636     __Pyx_GOTREF(__pyx_t_3);
23637     __pyx_r = __pyx_t_3;
23638     __pyx_t_3 = 0;
23639     goto __pyx_L0;
23640     goto __pyx_L6;
23641   }
23642
23643   /* "csamtools.pyx":2638
23644  *         elif type == 'i' or type == 'I':
23645  *             return <int32_t>bam_aux2i(v)
23646  *         elif type == 'f' or type == 'F':             # <<<<<<<<<<<<<<
23647  *             return <float>bam_aux2f(v)
23648  *         elif type == 'd' or type == 'D':
23649  */
23650   __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__f), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23651   __Pyx_GOTREF(__pyx_t_3);
23652   __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23653   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23654   if (!__pyx_t_6) {
23655     __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__F), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23656     __Pyx_GOTREF(__pyx_t_3);
23657     __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23658     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23659     __pyx_t_2 = __pyx_t_5;
23660   } else {
23661     __pyx_t_2 = __pyx_t_6;
23662   }
23663   if (__pyx_t_2) {
23664
23665     /* "csamtools.pyx":2639
23666  *             return <int32_t>bam_aux2i(v)
23667  *         elif type == 'f' or type == 'F':
23668  *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
23669  *         elif type == 'd' or type == 'D':
23670  *             return <double>bam_aux2d(v)
23671  */
23672     __Pyx_XDECREF(__pyx_r);
23673     __pyx_t_3 = PyFloat_FromDouble(bam_aux2f(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23674     __Pyx_GOTREF(__pyx_t_3);
23675     __pyx_r = __pyx_t_3;
23676     __pyx_t_3 = 0;
23677     goto __pyx_L0;
23678     goto __pyx_L6;
23679   }
23680
23681   /* "csamtools.pyx":2640
23682  *         elif type == 'f' or type == 'F':
23683  *             return <float>bam_aux2f(v)
23684  *         elif type == 'd' or type == 'D':             # <<<<<<<<<<<<<<
23685  *             return <double>bam_aux2d(v)
23686  *         elif type == 'A':
23687  */
23688   __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__d), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23689   __Pyx_GOTREF(__pyx_t_3);
23690   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23691   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23692   if (!__pyx_t_2) {
23693     __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__D), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23694     __Pyx_GOTREF(__pyx_t_3);
23695     __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23696     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23697     __pyx_t_5 = __pyx_t_6;
23698   } else {
23699     __pyx_t_5 = __pyx_t_2;
23700   }
23701   if (__pyx_t_5) {
23702
23703     /* "csamtools.pyx":2641
23704  *             return <float>bam_aux2f(v)
23705  *         elif type == 'd' or type == 'D':
23706  *             return <double>bam_aux2d(v)             # <<<<<<<<<<<<<<
23707  *         elif type == 'A':
23708  *             # there might a more efficient way
23709  */
23710     __Pyx_XDECREF(__pyx_r);
23711     __pyx_t_3 = PyFloat_FromDouble(bam_aux2d(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23712     __Pyx_GOTREF(__pyx_t_3);
23713     __pyx_r = __pyx_t_3;
23714     __pyx_t_3 = 0;
23715     goto __pyx_L0;
23716     goto __pyx_L6;
23717   }
23718
23719   /* "csamtools.pyx":2642
23720  *         elif type == 'd' or type == 'D':
23721  *             return <double>bam_aux2d(v)
23722  *         elif type == 'A':             # <<<<<<<<<<<<<<
23723  *             # there might a more efficient way
23724  *             # to convert a char into a string
23725  */
23726   __pyx_t_3 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__A), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23727   __Pyx_GOTREF(__pyx_t_3);
23728   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23729   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23730   if (__pyx_t_5) {
23731
23732     /* "csamtools.pyx":2645
23733  *             # there might a more efficient way
23734  *             # to convert a char into a string
23735  *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
23736  *         elif type == 'Z':
23737  *             return <char*>bam_aux2Z(v)
23738  */
23739     __Pyx_XDECREF(__pyx_r);
23740     __pyx_t_3 = PyInt_FromLong(bam_aux2A(__pyx_v_v)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23741     __Pyx_GOTREF(__pyx_t_3);
23742     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_121), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2645; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23743     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
23744     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23745     __pyx_r = ((PyObject *)__pyx_t_4);
23746     __pyx_t_4 = 0;
23747     goto __pyx_L0;
23748     goto __pyx_L6;
23749   }
23750
23751   /* "csamtools.pyx":2646
23752  *             # to convert a char into a string
23753  *             return '%c' % <char>bam_aux2A(v)
23754  *         elif type == 'Z':             # <<<<<<<<<<<<<<
23755  *             return <char*>bam_aux2Z(v)
23756  * 
23757  */
23758   __pyx_t_4 = PyObject_RichCompare(__pyx_v_type, ((PyObject *)__pyx_n_s__Z), Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23759   __Pyx_GOTREF(__pyx_t_4);
23760   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23761   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
23762   if (__pyx_t_5) {
23763
23764     /* "csamtools.pyx":2647
23765  *             return '%c' % <char>bam_aux2A(v)
23766  *         elif type == 'Z':
23767  *             return <char*>bam_aux2Z(v)             # <<<<<<<<<<<<<<
23768  * 
23769  *     def fancy_str (self):
23770  */
23771     __Pyx_XDECREF(__pyx_r);
23772     __pyx_t_4 = PyBytes_FromString(bam_aux2Z(__pyx_v_v)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23773     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
23774     __pyx_r = ((PyObject *)__pyx_t_4);
23775     __pyx_t_4 = 0;
23776     goto __pyx_L0;
23777     goto __pyx_L6;
23778   }
23779   __pyx_L6:;
23780
23781   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
23782   goto __pyx_L0;
23783   __pyx_L1_error:;
23784   __Pyx_XDECREF(__pyx_t_3);
23785   __Pyx_XDECREF(__pyx_t_4);
23786   __Pyx_AddTraceback("csamtools.AlignedRead.opt");
23787   __pyx_r = NULL;
23788   __pyx_L0:;
23789   __Pyx_DECREF(__pyx_v_type);
23790   __Pyx_XGIVEREF(__pyx_r);
23791   __Pyx_TraceReturn(__pyx_r);
23792   __Pyx_RefNannyFinishContext();
23793   return __pyx_r;
23794 }
23795
23796 /* "csamtools.pyx":2649
23797  *             return <char*>bam_aux2Z(v)
23798  * 
23799  *     def fancy_str (self):             # <<<<<<<<<<<<<<
23800  *         """returns list of fieldnames/values in pretty format for debugging
23801  *         """
23802  */
23803
23804 static PyObject *__pyx_pf_9csamtools_11AlignedRead_7fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
23805 static char __pyx_doc_9csamtools_11AlignedRead_7fancy_str[] = "AlignedRead.fancy_str(self)\nreturns list of fieldnames/values in pretty format for debugging\n        ";
23806 static PyObject *__pyx_pf_9csamtools_11AlignedRead_7fancy_str(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
23807   PyObject *__pyx_v_ret_string;
23808   PyObject *__pyx_v_field_names;
23809   PyObject *__pyx_v_fields_names_in_order;
23810   PyObject *__pyx_v_f;
23811   PyObject *__pyx_r = NULL;
23812   PyObject *__pyx_t_1 = NULL;
23813   Py_ssize_t __pyx_t_2;
23814   PyObject *__pyx_t_3 = NULL;
23815   int __pyx_t_4;
23816   int __pyx_t_5;
23817   PyObject *__pyx_t_6 = NULL;
23818   PyObject *__pyx_t_7 = NULL;
23819   PyObject *__pyx_t_8 = NULL;
23820   PyObject *__pyx_t_9 = NULL;
23821   int __pyx_t_10;
23822   __Pyx_TraceDeclarations
23823   __Pyx_RefNannySetupContext("fancy_str");
23824   __Pyx_TraceCall("fancy_str", __pyx_f[0], 2649);
23825   __pyx_v_ret_string = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
23826   __pyx_v_field_names = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
23827   __pyx_v_fields_names_in_order = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
23828   __pyx_v_f = Py_None; __Pyx_INCREF(Py_None);
23829
23830   /* "csamtools.pyx":2652
23831  *         """returns list of fieldnames/values in pretty format for debugging
23832  *         """
23833  *         ret_string = []             # <<<<<<<<<<<<<<
23834  *         field_names = {
23835  *            "tid":           "Contig index",
23836  */
23837   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23838   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
23839   __Pyx_DECREF(((PyObject *)__pyx_v_ret_string));
23840   __pyx_v_ret_string = __pyx_t_1;
23841   __pyx_t_1 = 0;
23842
23843   /* "csamtools.pyx":2653
23844  *         """
23845  *         ret_string = []
23846  *         field_names = {             # <<<<<<<<<<<<<<
23847  *            "tid":           "Contig index",
23848  *            "pos":           "Mapped position on contig",
23849  */
23850   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23851   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
23852   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__tid), ((PyObject *)__pyx_kp_s_136)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23853   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), ((PyObject *)__pyx_kp_s_137)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23854   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mtid), ((PyObject *)__pyx_kp_s_138)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23855   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mpos), ((PyObject *)__pyx_kp_s_139)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23856   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__isize), ((PyObject *)__pyx_kp_s_140)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23857   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__flag), ((PyObject *)__pyx_kp_s_141)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23858   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__n_cigar), ((PyObject *)__pyx_kp_s_142)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23859   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__cigar), ((PyObject *)__pyx_kp_s_143)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23860   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qual), ((PyObject *)__pyx_kp_s_144)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23861   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bin), ((PyObject *)__pyx_kp_s_145)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23862   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qname), ((PyObject *)__pyx_kp_s_146)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23863   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qname), ((PyObject *)__pyx_kp_s_147)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23864   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_qseq), ((PyObject *)__pyx_kp_s_148)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23865   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__qseq), ((PyObject *)__pyx_kp_s_149)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23866   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__bqual), ((PyObject *)__pyx_kp_s_150)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23867   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__l_aux), ((PyObject *)__pyx_kp_s_151)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23868   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__m_data), ((PyObject *)__pyx_kp_s_152)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23869   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__data_len), ((PyObject *)__pyx_kp_s_153)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23870   __Pyx_DECREF(((PyObject *)__pyx_v_field_names));
23871   __pyx_v_field_names = __pyx_t_1;
23872   __pyx_t_1 = 0;
23873
23874   /* "csamtools.pyx":2673
23875  *            "data_len":      "Current data length",
23876  *            }
23877  *         fields_names_in_order = ["tid", "pos", "mtid", "mpos", "isize", "flag",             # <<<<<<<<<<<<<<
23878  *                                  "n_cigar", "cigar", "qual", "bin", "l_qname", "qname",
23879  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
23880  */
23881   __pyx_t_1 = PyList_New(18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23882   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
23883   __Pyx_INCREF(((PyObject *)__pyx_n_s__tid));
23884   PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__tid));
23885   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__tid));
23886   __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
23887   PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__pos));
23888   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
23889   __Pyx_INCREF(((PyObject *)__pyx_n_s__mtid));
23890   PyList_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_n_s__mtid));
23891   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mtid));
23892   __Pyx_INCREF(((PyObject *)__pyx_n_s__mpos));
23893   PyList_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_n_s__mpos));
23894   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mpos));
23895   __Pyx_INCREF(((PyObject *)__pyx_n_s__isize));
23896   PyList_SET_ITEM(__pyx_t_1, 4, ((PyObject *)__pyx_n_s__isize));
23897   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__isize));
23898   __Pyx_INCREF(((PyObject *)__pyx_n_s__flag));
23899   PyList_SET_ITEM(__pyx_t_1, 5, ((PyObject *)__pyx_n_s__flag));
23900   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__flag));
23901   __Pyx_INCREF(((PyObject *)__pyx_n_s__n_cigar));
23902   PyList_SET_ITEM(__pyx_t_1, 6, ((PyObject *)__pyx_n_s__n_cigar));
23903   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__n_cigar));
23904   __Pyx_INCREF(((PyObject *)__pyx_n_s__cigar));
23905   PyList_SET_ITEM(__pyx_t_1, 7, ((PyObject *)__pyx_n_s__cigar));
23906   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cigar));
23907   __Pyx_INCREF(((PyObject *)__pyx_n_s__qual));
23908   PyList_SET_ITEM(__pyx_t_1, 8, ((PyObject *)__pyx_n_s__qual));
23909   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qual));
23910   __Pyx_INCREF(((PyObject *)__pyx_n_s__bin));
23911   PyList_SET_ITEM(__pyx_t_1, 9, ((PyObject *)__pyx_n_s__bin));
23912   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bin));
23913   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qname));
23914   PyList_SET_ITEM(__pyx_t_1, 10, ((PyObject *)__pyx_n_s__l_qname));
23915   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qname));
23916   __Pyx_INCREF(((PyObject *)__pyx_n_s__qname));
23917   PyList_SET_ITEM(__pyx_t_1, 11, ((PyObject *)__pyx_n_s__qname));
23918   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qname));
23919   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_qseq));
23920   PyList_SET_ITEM(__pyx_t_1, 12, ((PyObject *)__pyx_n_s__l_qseq));
23921   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_qseq));
23922   __Pyx_INCREF(((PyObject *)__pyx_n_s__qseq));
23923   PyList_SET_ITEM(__pyx_t_1, 13, ((PyObject *)__pyx_n_s__qseq));
23924   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__qseq));
23925   __Pyx_INCREF(((PyObject *)__pyx_n_s__bqual));
23926   PyList_SET_ITEM(__pyx_t_1, 14, ((PyObject *)__pyx_n_s__bqual));
23927   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bqual));
23928   __Pyx_INCREF(((PyObject *)__pyx_n_s__l_aux));
23929   PyList_SET_ITEM(__pyx_t_1, 15, ((PyObject *)__pyx_n_s__l_aux));
23930   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__l_aux));
23931   __Pyx_INCREF(((PyObject *)__pyx_n_s__m_data));
23932   PyList_SET_ITEM(__pyx_t_1, 16, ((PyObject *)__pyx_n_s__m_data));
23933   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__m_data));
23934   __Pyx_INCREF(((PyObject *)__pyx_n_s__data_len));
23935   PyList_SET_ITEM(__pyx_t_1, 17, ((PyObject *)__pyx_n_s__data_len));
23936   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__data_len));
23937   __Pyx_DECREF(((PyObject *)__pyx_v_fields_names_in_order));
23938   __pyx_v_fields_names_in_order = __pyx_t_1;
23939   __pyx_t_1 = 0;
23940
23941   /* "csamtools.pyx":2677
23942  *                                  "l_qseq", "qseq", "bqual", "l_aux", "m_data", "data_len"]
23943  * 
23944  *         for f in fields_names_in_order:             # <<<<<<<<<<<<<<
23945  *             if not f in self.__dict__:
23946  *                 continue
23947  */
23948   if (unlikely(__pyx_v_fields_names_in_order == Py_None)) {
23949     PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2677; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
23950   }
23951   __pyx_t_2 = 0; __pyx_t_1 = ((PyObject *)__pyx_v_fields_names_in_order); __Pyx_INCREF(__pyx_t_1);
23952   for (;;) {
23953     if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
23954     __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++;
23955     __Pyx_DECREF(__pyx_v_f);
23956     __pyx_v_f = __pyx_t_3;
23957     __pyx_t_3 = 0;
23958
23959     /* "csamtools.pyx":2678
23960  * 
23961  *         for f in fields_names_in_order:
23962  *             if not f in self.__dict__:             # <<<<<<<<<<<<<<
23963  *                 continue
23964  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
23965  */
23966     __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____dict__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23967     __Pyx_GOTREF(__pyx_t_3);
23968     __pyx_t_4 = ((PySequence_Contains(__pyx_t_3, __pyx_v_f))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23969     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
23970     __pyx_t_5 = (!__pyx_t_4);
23971     if (__pyx_t_5) {
23972
23973       /* "csamtools.pyx":2679
23974  *         for f in fields_names_in_order:
23975  *             if not f in self.__dict__:
23976  *                 continue             # <<<<<<<<<<<<<<
23977  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
23978  * 
23979  */
23980       goto __pyx_L5_continue;
23981       goto __pyx_L7;
23982     }
23983     __pyx_L7:;
23984
23985     /* "csamtools.pyx":2680
23986  *             if not f in self.__dict__:
23987  *                 continue
23988  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
23989  * 
23990  *         for f in self.__dict__:
23991  */
23992     if (unlikely(__pyx_v_ret_string == Py_None)) {
23993       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
23994     }
23995     __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 = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23996     __Pyx_GOTREF(__pyx_t_3);
23997     __pyx_t_6 = PyNumber_Add(((PyObject *)__pyx_kp_s_155), __pyx_v_f); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
23998     __Pyx_GOTREF(__pyx_t_6);
23999     __pyx_t_7 = PyNumber_Add(__pyx_t_6, ((PyObject *)__pyx_kp_s_156)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24000     __Pyx_GOTREF(__pyx_t_7);
24001     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24002     __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24003     __Pyx_GOTREF(__pyx_t_6);
24004     __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24005     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24006     __Pyx_INCREF(__pyx_v_f);
24007     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
24008     __Pyx_GIVEREF(__pyx_v_f);
24009     __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 = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24010     __Pyx_GOTREF(__pyx_t_9);
24011     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
24012     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24013     __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24014     __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24015     PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
24016     __Pyx_GIVEREF(__pyx_t_3);
24017     PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
24018     __Pyx_GIVEREF(__pyx_t_7);
24019     PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
24020     __Pyx_GIVEREF(__pyx_t_9);
24021     __pyx_t_3 = 0;
24022     __pyx_t_7 = 0;
24023     __pyx_t_9 = 0;
24024     __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_154), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24025     __Pyx_GOTREF(((PyObject *)__pyx_t_9));
24026     __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24027     __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 = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24028     __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
24029     __pyx_L5_continue:;
24030   }
24031   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24032
24033   /* "csamtools.pyx":2682
24034  *             ret_string.append("%-30s %-10s= %s" % (field_names[f], "(" + f + ")", self.__getattribute__(f)))
24035  * 
24036  *         for f in self.__dict__:             # <<<<<<<<<<<<<<
24037  *             if not f in field_names:
24038  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
24039  */
24040   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____dict__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24041   __Pyx_GOTREF(__pyx_t_1);
24042   if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
24043     __pyx_t_2 = 0; __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9);
24044   } else {
24045     __pyx_t_2 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24046     __Pyx_GOTREF(__pyx_t_9);
24047   }
24048   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24049   for (;;) {
24050     if (likely(PyList_CheckExact(__pyx_t_9))) {
24051       if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_9)) break;
24052       __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
24053     } else if (likely(PyTuple_CheckExact(__pyx_t_9))) {
24054       if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
24055       __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++;
24056     } else {
24057       __pyx_t_1 = PyIter_Next(__pyx_t_9);
24058       if (!__pyx_t_1) {
24059         if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24060         break;
24061       }
24062       __Pyx_GOTREF(__pyx_t_1);
24063     }
24064     __Pyx_DECREF(__pyx_v_f);
24065     __pyx_v_f = __pyx_t_1;
24066     __pyx_t_1 = 0;
24067
24068     /* "csamtools.pyx":2683
24069  * 
24070  *         for f in self.__dict__:
24071  *             if not f in field_names:             # <<<<<<<<<<<<<<
24072  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
24073  *         return ret_string
24074  */
24075     if (unlikely(__pyx_v_field_names == Py_None)) {
24076       PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2683; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
24077     }
24078     __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 = 2683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24079     __pyx_t_4 = (!__pyx_t_5);
24080     if (__pyx_t_4) {
24081
24082       /* "csamtools.pyx":2684
24083  *         for f in self.__dict__:
24084  *             if not f in field_names:
24085  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))             # <<<<<<<<<<<<<<
24086  *         return ret_string
24087  * 
24088  */
24089       if (unlikely(__pyx_v_ret_string == Py_None)) {
24090         PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
24091       }
24092       __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s____getattribute__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24093       __Pyx_GOTREF(__pyx_t_1);
24094       __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24095       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24096       __Pyx_INCREF(__pyx_v_f);
24097       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
24098       __Pyx_GIVEREF(__pyx_v_f);
24099       __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 = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24100       __Pyx_GOTREF(__pyx_t_7);
24101       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24102       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24103       __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24104       __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24105       __Pyx_INCREF(__pyx_v_f);
24106       PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_f);
24107       __Pyx_GIVEREF(__pyx_v_f);
24108       __Pyx_INCREF(((PyObject *)__pyx_kp_s_12));
24109       PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_kp_s_12));
24110       __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_12));
24111       PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
24112       __Pyx_GIVEREF(__pyx_t_7);
24113       __pyx_t_7 = 0;
24114       __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_154), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24115       __Pyx_GOTREF(((PyObject *)__pyx_t_7));
24116       __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24117       __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 = 2684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24118       __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
24119       goto __pyx_L10;
24120     }
24121     __pyx_L10:;
24122   }
24123   __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
24124
24125   /* "csamtools.pyx":2685
24126  *             if not f in field_names:
24127  *                 ret_string.append("%-30s %-10s= %s" % (f, "", self.__getattribute__(f)))
24128  *         return ret_string             # <<<<<<<<<<<<<<
24129  * 
24130  * cdef class PileupProxy:
24131  */
24132   __Pyx_XDECREF(__pyx_r);
24133   __Pyx_INCREF(((PyObject *)__pyx_v_ret_string));
24134   __pyx_r = ((PyObject *)__pyx_v_ret_string);
24135   goto __pyx_L0;
24136
24137   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24138   goto __pyx_L0;
24139   __pyx_L1_error:;
24140   __Pyx_XDECREF(__pyx_t_1);
24141   __Pyx_XDECREF(__pyx_t_3);
24142   __Pyx_XDECREF(__pyx_t_6);
24143   __Pyx_XDECREF(__pyx_t_7);
24144   __Pyx_XDECREF(__pyx_t_8);
24145   __Pyx_XDECREF(__pyx_t_9);
24146   __Pyx_AddTraceback("csamtools.AlignedRead.fancy_str");
24147   __pyx_r = NULL;
24148   __pyx_L0:;
24149   __Pyx_DECREF(__pyx_v_ret_string);
24150   __Pyx_DECREF(__pyx_v_field_names);
24151   __Pyx_DECREF(__pyx_v_fields_names_in_order);
24152   __Pyx_DECREF(__pyx_v_f);
24153   __Pyx_XGIVEREF(__pyx_r);
24154   __Pyx_TraceReturn(__pyx_r);
24155   __Pyx_RefNannyFinishContext();
24156   return __pyx_r;
24157 }
24158
24159 /* "csamtools.pyx":2709
24160  *     cdef int n_pu
24161  * 
24162  *     def __init__(self):             # <<<<<<<<<<<<<<
24163  *         raise TypeError("This class cannot be instantiated from Python")
24164  * 
24165  */
24166
24167 static int __pyx_pf_9csamtools_11PileupProxy___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
24168 static int __pyx_pf_9csamtools_11PileupProxy___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
24169   int __pyx_r;
24170   PyObject *__pyx_t_1 = NULL;
24171   __Pyx_TraceDeclarations
24172   __Pyx_RefNannySetupContext("__init__");
24173   __Pyx_TraceCall("__init__", __pyx_f[0], 2709);
24174   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
24175     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
24176   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
24177
24178   /* "csamtools.pyx":2710
24179  * 
24180  *     def __init__(self):
24181  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
24182  * 
24183  *     def __str__(self):
24184  */
24185   __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_158), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24186   __Pyx_GOTREF(__pyx_t_1);
24187   __Pyx_Raise(__pyx_t_1, 0, 0);
24188   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24189   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24190
24191   __pyx_r = 0;
24192   goto __pyx_L0;
24193   __pyx_L1_error:;
24194   __Pyx_XDECREF(__pyx_t_1);
24195   __Pyx_AddTraceback("csamtools.PileupProxy.__init__");
24196   __pyx_r = -1;
24197   __pyx_L0:;
24198   __Pyx_TraceReturn(Py_None);
24199   __Pyx_RefNannyFinishContext();
24200   return __pyx_r;
24201 }
24202
24203 /* "csamtools.pyx":2712
24204  *         raise TypeError("This class cannot be instantiated from Python")
24205  * 
24206  *     def __str__(self):             # <<<<<<<<<<<<<<
24207  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
24208  *             "\n" +\
24209  */
24210
24211 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1__str__(PyObject *__pyx_v_self); /*proto*/
24212 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1__str__(PyObject *__pyx_v_self) {
24213   PyObject *__pyx_r = NULL;
24214   PyObject *__pyx_t_1 = NULL;
24215   PyObject *__pyx_t_2 = NULL;
24216   PyObject *__pyx_t_3 = NULL;
24217   PyObject *__pyx_t_4 = NULL;
24218   PyObject *__pyx_t_5 = NULL;
24219   __Pyx_TraceDeclarations
24220   __Pyx_RefNannySetupContext("__str__");
24221   __Pyx_TraceCall("__str__", __pyx_f[0], 2712);
24222
24223   /* "csamtools.pyx":2713
24224  * 
24225  *     def __str__(self):
24226  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
24227  *             "\n" +\
24228  *             "\n".join( map(str, self.pileups) )
24229  */
24230   __Pyx_XDECREF(__pyx_r);
24231
24232   /* "csamtools.pyx":2714
24233  *     def __str__(self):
24234  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
24235  *             "\n" +\             # <<<<<<<<<<<<<<
24236  *             "\n".join( map(str, self.pileups) )
24237  * 
24238  */
24239   __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24240   __Pyx_GOTREF(__pyx_t_1);
24241
24242   /* "csamtools.pyx":2713
24243  * 
24244  *     def __str__(self):
24245  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\             # <<<<<<<<<<<<<<
24246  *             "\n" +\
24247  *             "\n".join( map(str, self.pileups) )
24248  */
24249   __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24250   __Pyx_GOTREF(__pyx_t_2);
24251   __pyx_t_3 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24252   __Pyx_GOTREF(__pyx_t_3);
24253   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__n); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24254   __Pyx_GOTREF(__pyx_t_4);
24255   __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24256   __Pyx_GOTREF(((PyObject *)__pyx_t_5));
24257   PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
24258   __Pyx_GIVEREF(__pyx_t_2);
24259   PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
24260   __Pyx_GIVEREF(__pyx_t_3);
24261   PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4);
24262   __Pyx_GIVEREF(__pyx_t_4);
24263   __pyx_t_2 = 0;
24264   __pyx_t_3 = 0;
24265   __pyx_t_4 = 0;
24266   __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24267   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
24268   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
24269   PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
24270   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
24271   PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_5));
24272   __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
24273   __pyx_t_5 = 0;
24274   __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 = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24275   __Pyx_GOTREF(__pyx_t_5);
24276   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
24277   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24278   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
24279   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
24280   __Pyx_GIVEREF(__pyx_t_5);
24281   __pyx_t_5 = 0;
24282   __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 = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24283   __Pyx_GOTREF(__pyx_t_5);
24284   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24285   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
24286   __pyx_t_4 = PyNumber_Add(__pyx_t_5, ((PyObject *)__pyx_kp_s_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24287   __Pyx_GOTREF(__pyx_t_4);
24288   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
24289
24290   /* "csamtools.pyx":2715
24291  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
24292  *             "\n" +\
24293  *             "\n".join( map(str, self.pileups) )             # <<<<<<<<<<<<<<
24294  * 
24295  *     property tid:
24296  */
24297   __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_2), __pyx_n_s__join); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24298   __Pyx_GOTREF(__pyx_t_5);
24299   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pileups); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24300   __Pyx_GOTREF(__pyx_t_1);
24301   __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24302   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
24303   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
24304   PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
24305   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
24306   PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
24307   __Pyx_GIVEREF(__pyx_t_1);
24308   __pyx_t_1 = 0;
24309   __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 = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24310   __Pyx_GOTREF(__pyx_t_1);
24311   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
24312   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24313   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
24314   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
24315   __Pyx_GIVEREF(__pyx_t_1);
24316   __pyx_t_1 = 0;
24317   __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 = 2715; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24318   __Pyx_GOTREF(__pyx_t_1);
24319   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
24320   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
24321   __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24322   __Pyx_GOTREF(__pyx_t_3);
24323   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
24324   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24325   __pyx_r = __pyx_t_3;
24326   __pyx_t_3 = 0;
24327   goto __pyx_L0;
24328
24329   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24330   goto __pyx_L0;
24331   __pyx_L1_error:;
24332   __Pyx_XDECREF(__pyx_t_1);
24333   __Pyx_XDECREF(__pyx_t_2);
24334   __Pyx_XDECREF(__pyx_t_3);
24335   __Pyx_XDECREF(__pyx_t_4);
24336   __Pyx_XDECREF(__pyx_t_5);
24337   __Pyx_AddTraceback("csamtools.PileupProxy.__str__");
24338   __pyx_r = NULL;
24339   __pyx_L0:;
24340   __Pyx_XGIVEREF(__pyx_r);
24341   __Pyx_TraceReturn(__pyx_r);
24342   __Pyx_RefNannyFinishContext();
24343   return __pyx_r;
24344 }
24345
24346 /* "csamtools.pyx":2719
24347  *     property tid:
24348  *         '''the chromosome ID as is defined in the header'''
24349  *         def __get__(self): return self.tid             # <<<<<<<<<<<<<<
24350  * 
24351  *     property n:
24352  */
24353
24354 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3tid___get__(PyObject *__pyx_v_self); /*proto*/
24355 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3tid___get__(PyObject *__pyx_v_self) {
24356   PyObject *__pyx_r = NULL;
24357   PyObject *__pyx_t_1 = NULL;
24358   __Pyx_TraceDeclarations
24359   __Pyx_RefNannySetupContext("__get__");
24360   __Pyx_TraceCall("__get__", __pyx_f[0], 2719);
24361   __Pyx_XDECREF(__pyx_r);
24362   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24363   __Pyx_GOTREF(__pyx_t_1);
24364   __pyx_r = __pyx_t_1;
24365   __pyx_t_1 = 0;
24366   goto __pyx_L0;
24367
24368   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24369   goto __pyx_L0;
24370   __pyx_L1_error:;
24371   __Pyx_XDECREF(__pyx_t_1);
24372   __Pyx_AddTraceback("csamtools.PileupProxy.tid.__get__");
24373   __pyx_r = NULL;
24374   __pyx_L0:;
24375   __Pyx_XGIVEREF(__pyx_r);
24376   __Pyx_TraceReturn(__pyx_r);
24377   __Pyx_RefNannyFinishContext();
24378   return __pyx_r;
24379 }
24380
24381 /* "csamtools.pyx":2723
24382  *     property n:
24383  *         '''number of reads mapping to this column.'''
24384  *         def __get__(self): return self.n_pu             # <<<<<<<<<<<<<<
24385  *         def __set__(self, n): self.n_pu = n
24386  * 
24387  */
24388
24389 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1n___get__(PyObject *__pyx_v_self); /*proto*/
24390 static PyObject *__pyx_pf_9csamtools_11PileupProxy_1n___get__(PyObject *__pyx_v_self) {
24391   PyObject *__pyx_r = NULL;
24392   PyObject *__pyx_t_1 = NULL;
24393   __Pyx_TraceDeclarations
24394   __Pyx_RefNannySetupContext("__get__");
24395   __Pyx_TraceCall("__get__", __pyx_f[0], 2723);
24396   __Pyx_XDECREF(__pyx_r);
24397   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24398   __Pyx_GOTREF(__pyx_t_1);
24399   __pyx_r = __pyx_t_1;
24400   __pyx_t_1 = 0;
24401   goto __pyx_L0;
24402
24403   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24404   goto __pyx_L0;
24405   __pyx_L1_error:;
24406   __Pyx_XDECREF(__pyx_t_1);
24407   __Pyx_AddTraceback("csamtools.PileupProxy.n.__get__");
24408   __pyx_r = NULL;
24409   __pyx_L0:;
24410   __Pyx_XGIVEREF(__pyx_r);
24411   __Pyx_TraceReturn(__pyx_r);
24412   __Pyx_RefNannyFinishContext();
24413   return __pyx_r;
24414 }
24415
24416 /* "csamtools.pyx":2724
24417  *         '''number of reads mapping to this column.'''
24418  *         def __get__(self): return self.n_pu
24419  *         def __set__(self, n): self.n_pu = n             # <<<<<<<<<<<<<<
24420  * 
24421  *     property pos:
24422  */
24423
24424 static int __pyx_pf_9csamtools_11PileupProxy_1n_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
24425 static int __pyx_pf_9csamtools_11PileupProxy_1n_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
24426   int __pyx_r;
24427   int __pyx_t_1;
24428   __Pyx_TraceDeclarations
24429   __Pyx_RefNannySetupContext("__set__");
24430   __Pyx_TraceCall("__set__", __pyx_f[0], 2724);
24431   __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 = 2724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24432   ((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->n_pu = __pyx_t_1;
24433
24434   __pyx_r = 0;
24435   goto __pyx_L0;
24436   __pyx_L1_error:;
24437   __Pyx_AddTraceback("csamtools.PileupProxy.n.__set__");
24438   __pyx_r = -1;
24439   __pyx_L0:;
24440   __Pyx_TraceReturn(Py_None);
24441   __Pyx_RefNannyFinishContext();
24442   return __pyx_r;
24443 }
24444
24445 /* "csamtools.pyx":2727
24446  * 
24447  *     property pos:
24448  *         def __get__(self): return self.pos             # <<<<<<<<<<<<<<
24449  * 
24450  *     property pileups:
24451  */
24452
24453 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3pos___get__(PyObject *__pyx_v_self); /*proto*/
24454 static PyObject *__pyx_pf_9csamtools_11PileupProxy_3pos___get__(PyObject *__pyx_v_self) {
24455   PyObject *__pyx_r = NULL;
24456   PyObject *__pyx_t_1 = NULL;
24457   __Pyx_TraceDeclarations
24458   __Pyx_RefNannySetupContext("__get__");
24459   __Pyx_TraceCall("__get__", __pyx_f[0], 2727);
24460   __Pyx_XDECREF(__pyx_r);
24461   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24462   __Pyx_GOTREF(__pyx_t_1);
24463   __pyx_r = __pyx_t_1;
24464   __pyx_t_1 = 0;
24465   goto __pyx_L0;
24466
24467   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24468   goto __pyx_L0;
24469   __pyx_L1_error:;
24470   __Pyx_XDECREF(__pyx_t_1);
24471   __Pyx_AddTraceback("csamtools.PileupProxy.pos.__get__");
24472   __pyx_r = NULL;
24473   __pyx_L0:;
24474   __Pyx_XGIVEREF(__pyx_r);
24475   __Pyx_TraceReturn(__pyx_r);
24476   __Pyx_RefNannyFinishContext();
24477   return __pyx_r;
24478 }
24479
24480 /* "csamtools.pyx":2731
24481  *     property pileups:
24482  *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
24483  *         def __get__(self):             # <<<<<<<<<<<<<<
24484  *             cdef int x
24485  *             pileups = []
24486  */
24487
24488 static PyObject *__pyx_pf_9csamtools_11PileupProxy_7pileups___get__(PyObject *__pyx_v_self); /*proto*/
24489 static PyObject *__pyx_pf_9csamtools_11PileupProxy_7pileups___get__(PyObject *__pyx_v_self) {
24490   int __pyx_v_x;
24491   PyObject *__pyx_v_pileups;
24492   PyObject *__pyx_r = NULL;
24493   PyObject *__pyx_t_1 = NULL;
24494   int __pyx_t_2;
24495   int __pyx_t_3;
24496   __Pyx_TraceDeclarations
24497   __Pyx_RefNannySetupContext("__get__");
24498   __Pyx_TraceCall("__get__", __pyx_f[0], 2731);
24499   __pyx_v_pileups = ((PyObject*)Py_None); __Pyx_INCREF(Py_None);
24500
24501   /* "csamtools.pyx":2733
24502  *         def __get__(self):
24503  *             cdef int x
24504  *             pileups = []             # <<<<<<<<<<<<<<
24505  *             # warning: there could be problems if self.n and self.buf are
24506  *             # out of sync.
24507  */
24508   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24509   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
24510   __Pyx_DECREF(((PyObject *)__pyx_v_pileups));
24511   __pyx_v_pileups = __pyx_t_1;
24512   __pyx_t_1 = 0;
24513
24514   /* "csamtools.pyx":2736
24515  *             # warning: there could be problems if self.n and self.buf are
24516  *             # out of sync.
24517  *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
24518  *                 pileups.append( makePileupRead( &(self.plp[x])) )
24519  *             return pileups
24520  */
24521   __pyx_t_2 = ((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->n_pu;
24522   for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_2; __pyx_v_x++) {
24523
24524     /* "csamtools.pyx":2737
24525  *             # out of sync.
24526  *             for x from 0 <= x < self.n_pu:
24527  *                 pileups.append( makePileupRead( &(self.plp[x])) )             # <<<<<<<<<<<<<<
24528  *             return pileups
24529  * 
24530  */
24531     if (unlikely(__pyx_v_pileups == Py_None)) {
24532       PyErr_SetString(PyExc_AttributeError, "'NoneType' object has no attribute 'append'"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 
24533     }
24534     __pyx_t_1 = __pyx_f_9csamtools_makePileupRead((&(((struct __pyx_obj_9csamtools_PileupProxy *)__pyx_v_self)->plp[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24535     __Pyx_GOTREF(__pyx_t_1);
24536     __pyx_t_3 = PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24537     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24538   }
24539
24540   /* "csamtools.pyx":2738
24541  *             for x from 0 <= x < self.n_pu:
24542  *                 pileups.append( makePileupRead( &(self.plp[x])) )
24543  *             return pileups             # <<<<<<<<<<<<<<
24544  * 
24545  * cdef class PileupRead:
24546  */
24547   __Pyx_XDECREF(__pyx_r);
24548   __Pyx_INCREF(((PyObject *)__pyx_v_pileups));
24549   __pyx_r = ((PyObject *)__pyx_v_pileups);
24550   goto __pyx_L0;
24551
24552   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24553   goto __pyx_L0;
24554   __pyx_L1_error:;
24555   __Pyx_XDECREF(__pyx_t_1);
24556   __Pyx_AddTraceback("csamtools.PileupProxy.pileups.__get__");
24557   __pyx_r = NULL;
24558   __pyx_L0:;
24559   __Pyx_DECREF(__pyx_v_pileups);
24560   __Pyx_XGIVEREF(__pyx_r);
24561   __Pyx_TraceReturn(__pyx_r);
24562   __Pyx_RefNannyFinishContext();
24563   return __pyx_r;
24564 }
24565
24566 /* "csamtools.pyx":2753
24567  *          uint32_t _is_tail
24568  * 
24569  *     def __init__(self):             # <<<<<<<<<<<<<<
24570  *         raise TypeError("This class cannot be instantiated from Python")
24571  * 
24572  */
24573
24574 static int __pyx_pf_9csamtools_10PileupRead___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
24575 static int __pyx_pf_9csamtools_10PileupRead___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
24576   int __pyx_r;
24577   PyObject *__pyx_t_1 = NULL;
24578   __Pyx_TraceDeclarations
24579   __Pyx_RefNannySetupContext("__init__");
24580   __Pyx_TraceCall("__init__", __pyx_f[0], 2753);
24581   if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
24582     __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
24583   if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
24584
24585   /* "csamtools.pyx":2754
24586  * 
24587  *     def __init__(self):
24588  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
24589  * 
24590  *     def __str__(self):
24591  */
24592   __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_159), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24593   __Pyx_GOTREF(__pyx_t_1);
24594   __Pyx_Raise(__pyx_t_1, 0, 0);
24595   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24596   {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24597
24598   __pyx_r = 0;
24599   goto __pyx_L0;
24600   __pyx_L1_error:;
24601   __Pyx_XDECREF(__pyx_t_1);
24602   __Pyx_AddTraceback("csamtools.PileupRead.__init__");
24603   __pyx_r = -1;
24604   __pyx_L0:;
24605   __Pyx_TraceReturn(Py_None);
24606   __Pyx_RefNannyFinishContext();
24607   return __pyx_r;
24608 }
24609
24610 /* "csamtools.pyx":2756
24611  *         raise TypeError("This class cannot be instantiated from Python")
24612  * 
24613  *     def __str__(self):             # <<<<<<<<<<<<<<
24614  *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )
24615  * 
24616  */
24617
24618 static PyObject *__pyx_pf_9csamtools_10PileupRead_1__str__(PyObject *__pyx_v_self); /*proto*/
24619 static PyObject *__pyx_pf_9csamtools_10PileupRead_1__str__(PyObject *__pyx_v_self) {
24620   PyObject *__pyx_r = NULL;
24621   PyObject *__pyx_t_1 = NULL;
24622   PyObject *__pyx_t_2 = NULL;
24623   PyObject *__pyx_t_3 = NULL;
24624   PyObject *__pyx_t_4 = NULL;
24625   PyObject *__pyx_t_5 = NULL;
24626   PyObject *__pyx_t_6 = NULL;
24627   PyObject *__pyx_t_7 = NULL;
24628   PyObject *__pyx_t_8 = NULL;
24629   PyObject *__pyx_t_9 = NULL;
24630   __Pyx_TraceDeclarations
24631   __Pyx_RefNannySetupContext("__str__");
24632   __Pyx_TraceCall("__str__", __pyx_f[0], 2756);
24633
24634   /* "csamtools.pyx":2757
24635  * 
24636  *     def __str__(self):
24637  *         return "\t".join( map(str, (self.alignment, self.qpos, self.indel, self.level, self.is_del, self.is_head, self.is_tail ) ) )             # <<<<<<<<<<<<<<
24638  * 
24639  *     property alignment:
24640  */
24641   __Pyx_XDECREF(__pyx_r);
24642   __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24643   __Pyx_GOTREF(__pyx_t_1);
24644   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__alignment); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24645   __Pyx_GOTREF(__pyx_t_2);
24646   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24647   __Pyx_GOTREF(__pyx_t_3);
24648   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__indel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24649   __Pyx_GOTREF(__pyx_t_4);
24650   __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__level); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24651   __Pyx_GOTREF(__pyx_t_5);
24652   __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_del); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24653   __Pyx_GOTREF(__pyx_t_6);
24654   __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_head); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24655   __Pyx_GOTREF(__pyx_t_7);
24656   __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__is_tail); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24657   __Pyx_GOTREF(__pyx_t_8);
24658   __pyx_t_9 = PyTuple_New(7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24659   __Pyx_GOTREF(((PyObject *)__pyx_t_9));
24660   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2);
24661   __Pyx_GIVEREF(__pyx_t_2);
24662   PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
24663   __Pyx_GIVEREF(__pyx_t_3);
24664   PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_4);
24665   __Pyx_GIVEREF(__pyx_t_4);
24666   PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_5);
24667   __Pyx_GIVEREF(__pyx_t_5);
24668   PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_6);
24669   __Pyx_GIVEREF(__pyx_t_6);
24670   PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_7);
24671   __Pyx_GIVEREF(__pyx_t_7);
24672   PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_8);
24673   __Pyx_GIVEREF(__pyx_t_8);
24674   __pyx_t_2 = 0;
24675   __pyx_t_3 = 0;
24676   __pyx_t_4 = 0;
24677   __pyx_t_5 = 0;
24678   __pyx_t_6 = 0;
24679   __pyx_t_7 = 0;
24680   __pyx_t_8 = 0;
24681   __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24682   __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24683   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
24684   PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
24685   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
24686   PyTuple_SET_ITEM(__pyx_t_8, 1, ((PyObject *)__pyx_t_9));
24687   __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
24688   __pyx_t_9 = 0;
24689   __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 = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24690   __Pyx_GOTREF(__pyx_t_9);
24691   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24692   __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24693   __Pyx_GOTREF(((PyObject *)__pyx_t_8));
24694   PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
24695   __Pyx_GIVEREF(__pyx_t_9);
24696   __pyx_t_9 = 0;
24697   __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 = 2757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24698   __Pyx_GOTREF(__pyx_t_9);
24699   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
24700   __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
24701   __pyx_r = __pyx_t_9;
24702   __pyx_t_9 = 0;
24703   goto __pyx_L0;
24704
24705   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24706   goto __pyx_L0;
24707   __pyx_L1_error:;
24708   __Pyx_XDECREF(__pyx_t_1);
24709   __Pyx_XDECREF(__pyx_t_2);
24710   __Pyx_XDECREF(__pyx_t_3);
24711   __Pyx_XDECREF(__pyx_t_4);
24712   __Pyx_XDECREF(__pyx_t_5);
24713   __Pyx_XDECREF(__pyx_t_6);
24714   __Pyx_XDECREF(__pyx_t_7);
24715   __Pyx_XDECREF(__pyx_t_8);
24716   __Pyx_XDECREF(__pyx_t_9);
24717   __Pyx_AddTraceback("csamtools.PileupRead.__str__");
24718   __pyx_r = NULL;
24719   __pyx_L0:;
24720   __Pyx_XGIVEREF(__pyx_r);
24721   __Pyx_TraceReturn(__pyx_r);
24722   __Pyx_RefNannyFinishContext();
24723   return __pyx_r;
24724 }
24725
24726 /* "csamtools.pyx":2761
24727  *     property alignment:
24728  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
24729  *         def __get__(self):             # <<<<<<<<<<<<<<
24730  *             return self._alignment
24731  *     property qpos:
24732  */
24733
24734 static PyObject *__pyx_pf_9csamtools_10PileupRead_9alignment___get__(PyObject *__pyx_v_self); /*proto*/
24735 static PyObject *__pyx_pf_9csamtools_10PileupRead_9alignment___get__(PyObject *__pyx_v_self) {
24736   PyObject *__pyx_r = NULL;
24737   __Pyx_TraceDeclarations
24738   __Pyx_RefNannySetupContext("__get__");
24739   __Pyx_TraceCall("__get__", __pyx_f[0], 2761);
24740
24741   /* "csamtools.pyx":2762
24742  *         """a :class:`pysam.AlignedRead` object of the aligned read"""
24743  *         def __get__(self):
24744  *             return self._alignment             # <<<<<<<<<<<<<<
24745  *     property qpos:
24746  *         """position of the read base at the pileup site, 0-based"""
24747  */
24748   __Pyx_XDECREF(__pyx_r);
24749   __Pyx_INCREF(((PyObject *)((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_alignment));
24750   __pyx_r = ((PyObject *)((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_alignment);
24751   goto __pyx_L0;
24752
24753   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24754   __pyx_L0:;
24755   __Pyx_XGIVEREF(__pyx_r);
24756   __Pyx_TraceReturn(__pyx_r);
24757   __Pyx_RefNannyFinishContext();
24758   return __pyx_r;
24759 }
24760
24761 /* "csamtools.pyx":2765
24762  *     property qpos:
24763  *         """position of the read base at the pileup site, 0-based"""
24764  *         def __get__(self):             # <<<<<<<<<<<<<<
24765  *             return self._qpos
24766  *     property indel:
24767  */
24768
24769 static PyObject *__pyx_pf_9csamtools_10PileupRead_4qpos___get__(PyObject *__pyx_v_self); /*proto*/
24770 static PyObject *__pyx_pf_9csamtools_10PileupRead_4qpos___get__(PyObject *__pyx_v_self) {
24771   PyObject *__pyx_r = NULL;
24772   PyObject *__pyx_t_1 = NULL;
24773   __Pyx_TraceDeclarations
24774   __Pyx_RefNannySetupContext("__get__");
24775   __Pyx_TraceCall("__get__", __pyx_f[0], 2765);
24776
24777   /* "csamtools.pyx":2766
24778  *         """position of the read base at the pileup site, 0-based"""
24779  *         def __get__(self):
24780  *             return self._qpos             # <<<<<<<<<<<<<<
24781  *     property indel:
24782  *         """indel length; 0 for no indel, positive for ins and negative for del"""
24783  */
24784   __Pyx_XDECREF(__pyx_r);
24785   __pyx_t_1 = __Pyx_PyInt_to_py_int32_t(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24786   __Pyx_GOTREF(__pyx_t_1);
24787   __pyx_r = __pyx_t_1;
24788   __pyx_t_1 = 0;
24789   goto __pyx_L0;
24790
24791   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24792   goto __pyx_L0;
24793   __pyx_L1_error:;
24794   __Pyx_XDECREF(__pyx_t_1);
24795   __Pyx_AddTraceback("csamtools.PileupRead.qpos.__get__");
24796   __pyx_r = NULL;
24797   __pyx_L0:;
24798   __Pyx_XGIVEREF(__pyx_r);
24799   __Pyx_TraceReturn(__pyx_r);
24800   __Pyx_RefNannyFinishContext();
24801   return __pyx_r;
24802 }
24803
24804 /* "csamtools.pyx":2769
24805  *     property indel:
24806  *         """indel length; 0 for no indel, positive for ins and negative for del"""
24807  *         def __get__(self):             # <<<<<<<<<<<<<<
24808  *             return self._indel
24809  *     property is_del:
24810  */
24811
24812 static PyObject *__pyx_pf_9csamtools_10PileupRead_5indel___get__(PyObject *__pyx_v_self); /*proto*/
24813 static PyObject *__pyx_pf_9csamtools_10PileupRead_5indel___get__(PyObject *__pyx_v_self) {
24814   PyObject *__pyx_r = NULL;
24815   PyObject *__pyx_t_1 = NULL;
24816   __Pyx_TraceDeclarations
24817   __Pyx_RefNannySetupContext("__get__");
24818   __Pyx_TraceCall("__get__", __pyx_f[0], 2769);
24819
24820   /* "csamtools.pyx":2770
24821  *         """indel length; 0 for no indel, positive for ins and negative for del"""
24822  *         def __get__(self):
24823  *             return self._indel             # <<<<<<<<<<<<<<
24824  *     property is_del:
24825  *         """1 iff the base on the padded read is a deletion"""
24826  */
24827   __Pyx_XDECREF(__pyx_r);
24828   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24829   __Pyx_GOTREF(__pyx_t_1);
24830   __pyx_r = __pyx_t_1;
24831   __pyx_t_1 = 0;
24832   goto __pyx_L0;
24833
24834   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24835   goto __pyx_L0;
24836   __pyx_L1_error:;
24837   __Pyx_XDECREF(__pyx_t_1);
24838   __Pyx_AddTraceback("csamtools.PileupRead.indel.__get__");
24839   __pyx_r = NULL;
24840   __pyx_L0:;
24841   __Pyx_XGIVEREF(__pyx_r);
24842   __Pyx_TraceReturn(__pyx_r);
24843   __Pyx_RefNannyFinishContext();
24844   return __pyx_r;
24845 }
24846
24847 /* "csamtools.pyx":2773
24848  *     property is_del:
24849  *         """1 iff the base on the padded read is a deletion"""
24850  *         def __get__(self):             # <<<<<<<<<<<<<<
24851  *             return self._is_del
24852  *     property is_head:
24853  */
24854
24855 static PyObject *__pyx_pf_9csamtools_10PileupRead_6is_del___get__(PyObject *__pyx_v_self); /*proto*/
24856 static PyObject *__pyx_pf_9csamtools_10PileupRead_6is_del___get__(PyObject *__pyx_v_self) {
24857   PyObject *__pyx_r = NULL;
24858   PyObject *__pyx_t_1 = NULL;
24859   __Pyx_TraceDeclarations
24860   __Pyx_RefNannySetupContext("__get__");
24861   __Pyx_TraceCall("__get__", __pyx_f[0], 2773);
24862
24863   /* "csamtools.pyx":2774
24864  *         """1 iff the base on the padded read is a deletion"""
24865  *         def __get__(self):
24866  *             return self._is_del             # <<<<<<<<<<<<<<
24867  *     property is_head:
24868  *         def __get__(self):
24869  */
24870   __Pyx_XDECREF(__pyx_r);
24871   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24872   __Pyx_GOTREF(__pyx_t_1);
24873   __pyx_r = __pyx_t_1;
24874   __pyx_t_1 = 0;
24875   goto __pyx_L0;
24876
24877   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24878   goto __pyx_L0;
24879   __pyx_L1_error:;
24880   __Pyx_XDECREF(__pyx_t_1);
24881   __Pyx_AddTraceback("csamtools.PileupRead.is_del.__get__");
24882   __pyx_r = NULL;
24883   __pyx_L0:;
24884   __Pyx_XGIVEREF(__pyx_r);
24885   __Pyx_TraceReturn(__pyx_r);
24886   __Pyx_RefNannyFinishContext();
24887   return __pyx_r;
24888 }
24889
24890 /* "csamtools.pyx":2776
24891  *             return self._is_del
24892  *     property is_head:
24893  *         def __get__(self):             # <<<<<<<<<<<<<<
24894  *             return self._is_head
24895  *     property is_tail:
24896  */
24897
24898 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_head___get__(PyObject *__pyx_v_self); /*proto*/
24899 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_head___get__(PyObject *__pyx_v_self) {
24900   PyObject *__pyx_r = NULL;
24901   PyObject *__pyx_t_1 = NULL;
24902   __Pyx_TraceDeclarations
24903   __Pyx_RefNannySetupContext("__get__");
24904   __Pyx_TraceCall("__get__", __pyx_f[0], 2776);
24905
24906   /* "csamtools.pyx":2777
24907  *     property is_head:
24908  *         def __get__(self):
24909  *             return self._is_head             # <<<<<<<<<<<<<<
24910  *     property is_tail:
24911  *         def __get__(self):
24912  */
24913   __Pyx_XDECREF(__pyx_r);
24914   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24915   __Pyx_GOTREF(__pyx_t_1);
24916   __pyx_r = __pyx_t_1;
24917   __pyx_t_1 = 0;
24918   goto __pyx_L0;
24919
24920   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24921   goto __pyx_L0;
24922   __pyx_L1_error:;
24923   __Pyx_XDECREF(__pyx_t_1);
24924   __Pyx_AddTraceback("csamtools.PileupRead.is_head.__get__");
24925   __pyx_r = NULL;
24926   __pyx_L0:;
24927   __Pyx_XGIVEREF(__pyx_r);
24928   __Pyx_TraceReturn(__pyx_r);
24929   __Pyx_RefNannyFinishContext();
24930   return __pyx_r;
24931 }
24932
24933 /* "csamtools.pyx":2779
24934  *             return self._is_head
24935  *     property is_tail:
24936  *         def __get__(self):             # <<<<<<<<<<<<<<
24937  *             return self._is_tail
24938  *     property level:
24939  */
24940
24941 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_tail___get__(PyObject *__pyx_v_self); /*proto*/
24942 static PyObject *__pyx_pf_9csamtools_10PileupRead_7is_tail___get__(PyObject *__pyx_v_self) {
24943   PyObject *__pyx_r = NULL;
24944   PyObject *__pyx_t_1 = NULL;
24945   __Pyx_TraceDeclarations
24946   __Pyx_RefNannySetupContext("__get__");
24947   __Pyx_TraceCall("__get__", __pyx_f[0], 2779);
24948
24949   /* "csamtools.pyx":2780
24950  *     property is_tail:
24951  *         def __get__(self):
24952  *             return self._is_tail             # <<<<<<<<<<<<<<
24953  *     property level:
24954  *         def __get__(self):
24955  */
24956   __Pyx_XDECREF(__pyx_r);
24957   __pyx_t_1 = __Pyx_PyInt_to_py_uint32_t(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
24958   __Pyx_GOTREF(__pyx_t_1);
24959   __pyx_r = __pyx_t_1;
24960   __pyx_t_1 = 0;
24961   goto __pyx_L0;
24962
24963   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
24964   goto __pyx_L0;
24965   __pyx_L1_error:;
24966   __Pyx_XDECREF(__pyx_t_1);
24967   __Pyx_AddTraceback("csamtools.PileupRead.is_tail.__get__");
24968   __pyx_r = NULL;
24969   __pyx_L0:;
24970   __Pyx_XGIVEREF(__pyx_r);
24971   __Pyx_TraceReturn(__pyx_r);
24972   __Pyx_RefNannyFinishContext();
24973   return __pyx_r;
24974 }
24975
24976 /* "csamtools.pyx":2782
24977  *             return self._is_tail
24978  *     property level:
24979  *         def __get__(self):             # <<<<<<<<<<<<<<
24980  *             return self._level
24981  * 
24982  */
24983
24984 static PyObject *__pyx_pf_9csamtools_10PileupRead_5level___get__(PyObject *__pyx_v_self); /*proto*/
24985 static PyObject *__pyx_pf_9csamtools_10PileupRead_5level___get__(PyObject *__pyx_v_self) {
24986   PyObject *__pyx_r = NULL;
24987   PyObject *__pyx_t_1 = NULL;
24988   __Pyx_TraceDeclarations
24989   __Pyx_RefNannySetupContext("__get__");
24990   __Pyx_TraceCall("__get__", __pyx_f[0], 2782);
24991
24992   /* "csamtools.pyx":2783
24993  *     property level:
24994  *         def __get__(self):
24995  *             return self._level             # <<<<<<<<<<<<<<
24996  * 
24997  * class Outs:
24998  */
24999   __Pyx_XDECREF(__pyx_r);
25000   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_PileupRead *)__pyx_v_self)->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25001   __Pyx_GOTREF(__pyx_t_1);
25002   __pyx_r = __pyx_t_1;
25003   __pyx_t_1 = 0;
25004   goto __pyx_L0;
25005
25006   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25007   goto __pyx_L0;
25008   __pyx_L1_error:;
25009   __Pyx_XDECREF(__pyx_t_1);
25010   __Pyx_AddTraceback("csamtools.PileupRead.level.__get__");
25011   __pyx_r = NULL;
25012   __pyx_L0:;
25013   __Pyx_XGIVEREF(__pyx_r);
25014   __Pyx_TraceReturn(__pyx_r);
25015   __Pyx_RefNannyFinishContext();
25016   return __pyx_r;
25017 }
25018
25019 /* "csamtools.pyx":2787
25020  * class Outs:
25021  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
25022  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
25023  *         self.streams = []
25024  *         self.id = id
25025  */
25026
25027 static PyObject *__pyx_pf_9csamtools_4Outs___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
25028 static char __pyx_doc_9csamtools_4Outs___init__[] = "Outs.__init__(self, id=1)";
25029 static PyMethodDef __pyx_mdef_9csamtools_4Outs___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_9csamtools_4Outs___init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs___init__)};
25030 static PyObject *__pyx_pf_9csamtools_4Outs___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
25031   PyObject *__pyx_v_self = 0;
25032   PyObject *__pyx_v_id = 0;
25033   PyObject *__pyx_r = NULL;
25034   PyObject *__pyx_t_1 = NULL;
25035   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__id,0};
25036   __Pyx_TraceDeclarations
25037   __Pyx_RefNannySetupContext("__init__");
25038   __Pyx_TraceCall("__init__", __pyx_f[0], 2787);
25039   __pyx_self = __pyx_self;
25040   if (unlikely(__pyx_kwds)) {
25041     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
25042     PyObject* values[2] = {0,0};
25043     values[1] = ((PyObject *)__pyx_int_1);
25044     switch (PyTuple_GET_SIZE(__pyx_args)) {
25045       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
25046       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
25047       case  0: break;
25048       default: goto __pyx_L5_argtuple_error;
25049     }
25050     switch (PyTuple_GET_SIZE(__pyx_args)) {
25051       case  0:
25052       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
25053       if (likely(values[0])) kw_args--;
25054       else goto __pyx_L5_argtuple_error;
25055       case  1:
25056       if (kw_args > 0) {
25057         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__id);
25058         if (value) { values[1] = value; kw_args--; }
25059       }
25060     }
25061     if (unlikely(kw_args > 0)) {
25062       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25063     }
25064     __pyx_v_self = values[0];
25065     __pyx_v_id = values[1];
25066   } else {
25067     __pyx_v_id = ((PyObject *)__pyx_int_1);
25068     switch (PyTuple_GET_SIZE(__pyx_args)) {
25069       case  2: __pyx_v_id = PyTuple_GET_ITEM(__pyx_args, 1);
25070       case  1: __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
25071       break;
25072       default: goto __pyx_L5_argtuple_error;
25073     }
25074   }
25075   goto __pyx_L4_argument_unpacking_done;
25076   __pyx_L5_argtuple_error:;
25077   __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25078   __pyx_L3_error:;
25079   __Pyx_AddTraceback("csamtools.Outs.__init__");
25080   __Pyx_RefNannyFinishContext();
25081   return NULL;
25082   __pyx_L4_argument_unpacking_done:;
25083
25084   /* "csamtools.pyx":2788
25085  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
25086  *     def __init__(self, id = 1):
25087  *         self.streams = []             # <<<<<<<<<<<<<<
25088  *         self.id = id
25089  * 
25090  */
25091   __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25092   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
25093   if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__streams, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25094   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25095
25096   /* "csamtools.pyx":2789
25097  *     def __init__(self, id = 1):
25098  *         self.streams = []
25099  *         self.id = id             # <<<<<<<<<<<<<<
25100  * 
25101  *     def setdevice(self, filename):
25102  */
25103   if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__id, __pyx_v_id) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25104
25105   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25106   goto __pyx_L0;
25107   __pyx_L1_error:;
25108   __Pyx_XDECREF(__pyx_t_1);
25109   __Pyx_AddTraceback("csamtools.Outs.__init__");
25110   __pyx_r = NULL;
25111   __pyx_L0:;
25112   __Pyx_XGIVEREF(__pyx_r);
25113   __Pyx_TraceReturn(__pyx_r);
25114   __Pyx_RefNannyFinishContext();
25115   return __pyx_r;
25116 }
25117
25118 /* "csamtools.pyx":2791
25119  *         self.id = id
25120  * 
25121  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
25122  *         '''open an existing file, like "/dev/null"'''
25123  *         fd = os.open(filename, os.O_WRONLY)
25124  */
25125
25126 static PyObject *__pyx_pf_9csamtools_4Outs_1setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
25127 static char __pyx_doc_9csamtools_4Outs_1setdevice[] = "Outs.setdevice(self, filename)\nopen an existing file, like \"/dev/null\"";
25128 static PyMethodDef __pyx_mdef_9csamtools_4Outs_1setdevice = {__Pyx_NAMESTR("setdevice"), (PyCFunction)__pyx_pf_9csamtools_4Outs_1setdevice, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_1setdevice)};
25129 static PyObject *__pyx_pf_9csamtools_4Outs_1setdevice(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
25130   PyObject *__pyx_v_self = 0;
25131   PyObject *__pyx_v_filename = 0;
25132   PyObject *__pyx_v_fd;
25133   PyObject *__pyx_r = NULL;
25134   PyObject *__pyx_t_1 = NULL;
25135   PyObject *__pyx_t_2 = NULL;
25136   PyObject *__pyx_t_3 = NULL;
25137   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
25138   __Pyx_TraceDeclarations
25139   __Pyx_RefNannySetupContext("setdevice");
25140   __Pyx_TraceCall("setdevice", __pyx_f[0], 2791);
25141   __pyx_self = __pyx_self;
25142   if (unlikely(__pyx_kwds)) {
25143     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
25144     PyObject* values[2] = {0,0};
25145     switch (PyTuple_GET_SIZE(__pyx_args)) {
25146       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
25147       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
25148       case  0: break;
25149       default: goto __pyx_L5_argtuple_error;
25150     }
25151     switch (PyTuple_GET_SIZE(__pyx_args)) {
25152       case  0:
25153       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
25154       if (likely(values[0])) kw_args--;
25155       else goto __pyx_L5_argtuple_error;
25156       case  1:
25157       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
25158       if (likely(values[1])) kw_args--;
25159       else {
25160         __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25161       }
25162     }
25163     if (unlikely(kw_args > 0)) {
25164       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setdevice") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25165     }
25166     __pyx_v_self = values[0];
25167     __pyx_v_filename = values[1];
25168   } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
25169     goto __pyx_L5_argtuple_error;
25170   } else {
25171     __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
25172     __pyx_v_filename = PyTuple_GET_ITEM(__pyx_args, 1);
25173   }
25174   goto __pyx_L4_argument_unpacking_done;
25175   __pyx_L5_argtuple_error:;
25176   __Pyx_RaiseArgtupleInvalid("setdevice", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25177   __pyx_L3_error:;
25178   __Pyx_AddTraceback("csamtools.Outs.setdevice");
25179   __Pyx_RefNannyFinishContext();
25180   return NULL;
25181   __pyx_L4_argument_unpacking_done:;
25182   __pyx_v_fd = Py_None; __Pyx_INCREF(Py_None);
25183
25184   /* "csamtools.pyx":2793
25185  *     def setdevice(self, filename):
25186  *         '''open an existing file, like "/dev/null"'''
25187  *         fd = os.open(filename, os.O_WRONLY)             # <<<<<<<<<<<<<<
25188  *         self.setfd(fd)
25189  * 
25190  */
25191   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25192   __Pyx_GOTREF(__pyx_t_1);
25193   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25194   __Pyx_GOTREF(__pyx_t_2);
25195   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25196   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25197   __Pyx_GOTREF(__pyx_t_1);
25198   __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 = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25199   __Pyx_GOTREF(__pyx_t_3);
25200   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25201   __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25202   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
25203   __Pyx_INCREF(__pyx_v_filename);
25204   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_filename);
25205   __Pyx_GIVEREF(__pyx_v_filename);
25206   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
25207   __Pyx_GIVEREF(__pyx_t_3);
25208   __pyx_t_3 = 0;
25209   __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 = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25210   __Pyx_GOTREF(__pyx_t_3);
25211   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25212   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25213   __Pyx_DECREF(__pyx_v_fd);
25214   __pyx_v_fd = __pyx_t_3;
25215   __pyx_t_3 = 0;
25216
25217   /* "csamtools.pyx":2794
25218  *         '''open an existing file, like "/dev/null"'''
25219  *         fd = os.open(filename, os.O_WRONLY)
25220  *         self.setfd(fd)             # <<<<<<<<<<<<<<
25221  * 
25222  *     def setfile(self, filename):
25223  */
25224   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25225   __Pyx_GOTREF(__pyx_t_3);
25226   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25227   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
25228   __Pyx_INCREF(__pyx_v_fd);
25229   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fd);
25230   __Pyx_GIVEREF(__pyx_v_fd);
25231   __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 = 2794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25232   __Pyx_GOTREF(__pyx_t_2);
25233   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25234   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25235   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25236
25237   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25238   goto __pyx_L0;
25239   __pyx_L1_error:;
25240   __Pyx_XDECREF(__pyx_t_1);
25241   __Pyx_XDECREF(__pyx_t_2);
25242   __Pyx_XDECREF(__pyx_t_3);
25243   __Pyx_AddTraceback("csamtools.Outs.setdevice");
25244   __pyx_r = NULL;
25245   __pyx_L0:;
25246   __Pyx_DECREF(__pyx_v_fd);
25247   __Pyx_XGIVEREF(__pyx_r);
25248   __Pyx_TraceReturn(__pyx_r);
25249   __Pyx_RefNannyFinishContext();
25250   return __pyx_r;
25251 }
25252
25253 /* "csamtools.pyx":2796
25254  *         self.setfd(fd)
25255  * 
25256  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
25257  *         '''open a new file.'''
25258  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
25259  */
25260
25261 static PyObject *__pyx_pf_9csamtools_4Outs_2setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
25262 static char __pyx_doc_9csamtools_4Outs_2setfile[] = "Outs.setfile(self, filename)\nopen a new file.";
25263 static PyMethodDef __pyx_mdef_9csamtools_4Outs_2setfile = {__Pyx_NAMESTR("setfile"), (PyCFunction)__pyx_pf_9csamtools_4Outs_2setfile, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_2setfile)};
25264 static PyObject *__pyx_pf_9csamtools_4Outs_2setfile(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
25265   PyObject *__pyx_v_self = 0;
25266   PyObject *__pyx_v_filename = 0;
25267   PyObject *__pyx_v_fd;
25268   PyObject *__pyx_r = NULL;
25269   PyObject *__pyx_t_1 = NULL;
25270   PyObject *__pyx_t_2 = NULL;
25271   PyObject *__pyx_t_3 = NULL;
25272   PyObject *__pyx_t_4 = NULL;
25273   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__filename,0};
25274   __Pyx_TraceDeclarations
25275   __Pyx_RefNannySetupContext("setfile");
25276   __Pyx_TraceCall("setfile", __pyx_f[0], 2796);
25277   __pyx_self = __pyx_self;
25278   if (unlikely(__pyx_kwds)) {
25279     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
25280     PyObject* values[2] = {0,0};
25281     switch (PyTuple_GET_SIZE(__pyx_args)) {
25282       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
25283       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
25284       case  0: break;
25285       default: goto __pyx_L5_argtuple_error;
25286     }
25287     switch (PyTuple_GET_SIZE(__pyx_args)) {
25288       case  0:
25289       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
25290       if (likely(values[0])) kw_args--;
25291       else goto __pyx_L5_argtuple_error;
25292       case  1:
25293       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename);
25294       if (likely(values[1])) kw_args--;
25295       else {
25296         __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25297       }
25298     }
25299     if (unlikely(kw_args > 0)) {
25300       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setfile") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25301     }
25302     __pyx_v_self = values[0];
25303     __pyx_v_filename = values[1];
25304   } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
25305     goto __pyx_L5_argtuple_error;
25306   } else {
25307     __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
25308     __pyx_v_filename = PyTuple_GET_ITEM(__pyx_args, 1);
25309   }
25310   goto __pyx_L4_argument_unpacking_done;
25311   __pyx_L5_argtuple_error:;
25312   __Pyx_RaiseArgtupleInvalid("setfile", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25313   __pyx_L3_error:;
25314   __Pyx_AddTraceback("csamtools.Outs.setfile");
25315   __Pyx_RefNannyFinishContext();
25316   return NULL;
25317   __pyx_L4_argument_unpacking_done:;
25318   __pyx_v_fd = Py_None; __Pyx_INCREF(Py_None);
25319
25320   /* "csamtools.pyx":2798
25321  *     def setfile(self, filename):
25322  *         '''open a new file.'''
25323  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);             # <<<<<<<<<<<<<<
25324  *         self.setfd(fd)
25325  * 
25326  */
25327   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25328   __Pyx_GOTREF(__pyx_t_1);
25329   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__open); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25330   __Pyx_GOTREF(__pyx_t_2);
25331   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25332   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25333   __Pyx_GOTREF(__pyx_t_1);
25334   __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 = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25335   __Pyx_GOTREF(__pyx_t_3);
25336   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25337   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25338   __Pyx_GOTREF(__pyx_t_1);
25339   __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 = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25340   __Pyx_GOTREF(__pyx_t_4);
25341   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25342   __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25343   __Pyx_GOTREF(__pyx_t_1);
25344   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25345   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
25346   __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25347   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
25348   __Pyx_INCREF(__pyx_v_filename);
25349   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_filename);
25350   __Pyx_GIVEREF(__pyx_v_filename);
25351   PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
25352   __Pyx_GIVEREF(__pyx_t_1);
25353   __Pyx_INCREF(__pyx_int_0660);
25354   PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_0660);
25355   __Pyx_GIVEREF(__pyx_int_0660);
25356   __pyx_t_1 = 0;
25357   __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 = 2798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25358   __Pyx_GOTREF(__pyx_t_1);
25359   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25360   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
25361   __Pyx_DECREF(__pyx_v_fd);
25362   __pyx_v_fd = __pyx_t_1;
25363   __pyx_t_1 = 0;
25364
25365   /* "csamtools.pyx":2799
25366  *         '''open a new file.'''
25367  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
25368  *         self.setfd(fd)             # <<<<<<<<<<<<<<
25369  * 
25370  *     def setfd(self, fd):
25371  */
25372   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25373   __Pyx_GOTREF(__pyx_t_1);
25374   __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25375   __Pyx_GOTREF(((PyObject *)__pyx_t_4));
25376   __Pyx_INCREF(__pyx_v_fd);
25377   PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fd);
25378   __Pyx_GIVEREF(__pyx_v_fd);
25379   __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 = 2799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25380   __Pyx_GOTREF(__pyx_t_2);
25381   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25382   __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
25383   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25384
25385   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25386   goto __pyx_L0;
25387   __pyx_L1_error:;
25388   __Pyx_XDECREF(__pyx_t_1);
25389   __Pyx_XDECREF(__pyx_t_2);
25390   __Pyx_XDECREF(__pyx_t_3);
25391   __Pyx_XDECREF(__pyx_t_4);
25392   __Pyx_AddTraceback("csamtools.Outs.setfile");
25393   __pyx_r = NULL;
25394   __pyx_L0:;
25395   __Pyx_DECREF(__pyx_v_fd);
25396   __Pyx_XGIVEREF(__pyx_r);
25397   __Pyx_TraceReturn(__pyx_r);
25398   __Pyx_RefNannyFinishContext();
25399   return __pyx_r;
25400 }
25401
25402 /* "csamtools.pyx":2801
25403  *         self.setfd(fd)
25404  * 
25405  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
25406  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
25407  *         self.streams.append(ofd)
25408  */
25409
25410 static PyObject *__pyx_pf_9csamtools_4Outs_3setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
25411 static char __pyx_doc_9csamtools_4Outs_3setfd[] = "Outs.setfd(self, fd)";
25412 static PyMethodDef __pyx_mdef_9csamtools_4Outs_3setfd = {__Pyx_NAMESTR("setfd"), (PyCFunction)__pyx_pf_9csamtools_4Outs_3setfd, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_3setfd)};
25413 static PyObject *__pyx_pf_9csamtools_4Outs_3setfd(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
25414   PyObject *__pyx_v_self = 0;
25415   PyObject *__pyx_v_fd = 0;
25416   PyObject *__pyx_v_ofd;
25417   PyObject *__pyx_r = NULL;
25418   PyObject *__pyx_t_1 = NULL;
25419   PyObject *__pyx_t_2 = NULL;
25420   PyObject *__pyx_t_3 = NULL;
25421   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__fd,0};
25422   __Pyx_TraceDeclarations
25423   __Pyx_RefNannySetupContext("setfd");
25424   __Pyx_TraceCall("setfd", __pyx_f[0], 2801);
25425   __pyx_self = __pyx_self;
25426   if (unlikely(__pyx_kwds)) {
25427     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
25428     PyObject* values[2] = {0,0};
25429     switch (PyTuple_GET_SIZE(__pyx_args)) {
25430       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
25431       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
25432       case  0: break;
25433       default: goto __pyx_L5_argtuple_error;
25434     }
25435     switch (PyTuple_GET_SIZE(__pyx_args)) {
25436       case  0:
25437       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self);
25438       if (likely(values[0])) kw_args--;
25439       else goto __pyx_L5_argtuple_error;
25440       case  1:
25441       values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fd);
25442       if (likely(values[1])) kw_args--;
25443       else {
25444         __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25445       }
25446     }
25447     if (unlikely(kw_args > 0)) {
25448       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "setfd") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25449     }
25450     __pyx_v_self = values[0];
25451     __pyx_v_fd = values[1];
25452   } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
25453     goto __pyx_L5_argtuple_error;
25454   } else {
25455     __pyx_v_self = PyTuple_GET_ITEM(__pyx_args, 0);
25456     __pyx_v_fd = PyTuple_GET_ITEM(__pyx_args, 1);
25457   }
25458   goto __pyx_L4_argument_unpacking_done;
25459   __pyx_L5_argtuple_error:;
25460   __Pyx_RaiseArgtupleInvalid("setfd", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25461   __pyx_L3_error:;
25462   __Pyx_AddTraceback("csamtools.Outs.setfd");
25463   __Pyx_RefNannyFinishContext();
25464   return NULL;
25465   __pyx_L4_argument_unpacking_done:;
25466   __pyx_v_ofd = Py_None; __Pyx_INCREF(Py_None);
25467
25468   /* "csamtools.pyx":2802
25469  * 
25470  *     def setfd(self, fd):
25471  *         ofd = os.dup(self.id)      #  Save old stream on new unit.             # <<<<<<<<<<<<<<
25472  *         self.streams.append(ofd)
25473  *         sys.stdout.flush()          #  Buffered data goes to old stream.
25474  */
25475   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25476   __Pyx_GOTREF(__pyx_t_1);
25477   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25478   __Pyx_GOTREF(__pyx_t_2);
25479   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25480   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25481   __Pyx_GOTREF(__pyx_t_1);
25482   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25483   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
25484   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
25485   __Pyx_GIVEREF(__pyx_t_1);
25486   __pyx_t_1 = 0;
25487   __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 = 2802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25488   __Pyx_GOTREF(__pyx_t_1);
25489   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25490   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
25491   __Pyx_DECREF(__pyx_v_ofd);
25492   __pyx_v_ofd = __pyx_t_1;
25493   __pyx_t_1 = 0;
25494
25495   /* "csamtools.pyx":2803
25496  *     def setfd(self, fd):
25497  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
25498  *         self.streams.append(ofd)             # <<<<<<<<<<<<<<
25499  *         sys.stdout.flush()          #  Buffered data goes to old stream.
25500  *         sys.stderr.flush()          #  Buffered data goes to old stream.
25501  */
25502   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25503   __Pyx_GOTREF(__pyx_t_1);
25504   __pyx_t_3 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_ofd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25505   __Pyx_GOTREF(__pyx_t_3);
25506   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25507   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25508
25509   /* "csamtools.pyx":2804
25510  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
25511  *         self.streams.append(ofd)
25512  *         sys.stdout.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
25513  *         sys.stderr.flush()          #  Buffered data goes to old stream.
25514  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
25515  */
25516   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25517   __Pyx_GOTREF(__pyx_t_3);
25518   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25519   __Pyx_GOTREF(__pyx_t_1);
25520   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25521   __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25522   __Pyx_GOTREF(__pyx_t_3);
25523   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25524   __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 = 2804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25525   __Pyx_GOTREF(__pyx_t_1);
25526   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25527   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25528
25529   /* "csamtools.pyx":2805
25530  *         self.streams.append(ofd)
25531  *         sys.stdout.flush()          #  Buffered data goes to old stream.
25532  *         sys.stderr.flush()          #  Buffered data goes to old stream.             # <<<<<<<<<<<<<<
25533  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
25534  *         os.close(fd)                #  Close other unit (look out, caller.)
25535  */
25536   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25537   __Pyx_GOTREF(__pyx_t_1);
25538   __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25539   __Pyx_GOTREF(__pyx_t_3);
25540   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25541   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25542   __Pyx_GOTREF(__pyx_t_1);
25543   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25544   __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 = 2805; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25545   __Pyx_GOTREF(__pyx_t_3);
25546   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25547   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25548
25549   /* "csamtools.pyx":2806
25550  *         sys.stdout.flush()          #  Buffered data goes to old stream.
25551  *         sys.stderr.flush()          #  Buffered data goes to old stream.
25552  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.             # <<<<<<<<<<<<<<
25553  *         os.close(fd)                #  Close other unit (look out, caller.)
25554  * 
25555  */
25556   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25557   __Pyx_GOTREF(__pyx_t_3);
25558   __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__dup2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25559   __Pyx_GOTREF(__pyx_t_1);
25560   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25561   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25562   __Pyx_GOTREF(__pyx_t_3);
25563   __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25564   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
25565   __Pyx_INCREF(__pyx_v_fd);
25566   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fd);
25567   __Pyx_GIVEREF(__pyx_v_fd);
25568   PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
25569   __Pyx_GIVEREF(__pyx_t_3);
25570   __pyx_t_3 = 0;
25571   __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 = 2806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25572   __Pyx_GOTREF(__pyx_t_3);
25573   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25574   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
25575   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25576
25577   /* "csamtools.pyx":2807
25578  *         sys.stderr.flush()          #  Buffered data goes to old stream.
25579  *         os.dup2(fd, self.id)        #  Open unit 1 on new stream.
25580  *         os.close(fd)                #  Close other unit (look out, caller.)             # <<<<<<<<<<<<<<
25581  * 
25582  *     def restore(self):
25583  */
25584   __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25585   __Pyx_GOTREF(__pyx_t_3);
25586   __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25587   __Pyx_GOTREF(__pyx_t_2);
25588   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25589   __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25590   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
25591   __Pyx_INCREF(__pyx_v_fd);
25592   PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fd);
25593   __Pyx_GIVEREF(__pyx_v_fd);
25594   __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 = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25595   __Pyx_GOTREF(__pyx_t_1);
25596   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
25597   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
25598   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25599
25600   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25601   goto __pyx_L0;
25602   __pyx_L1_error:;
25603   __Pyx_XDECREF(__pyx_t_1);
25604   __Pyx_XDECREF(__pyx_t_2);
25605   __Pyx_XDECREF(__pyx_t_3);
25606   __Pyx_AddTraceback("csamtools.Outs.setfd");
25607   __pyx_r = NULL;
25608   __pyx_L0:;
25609   __Pyx_DECREF(__pyx_v_ofd);
25610   __Pyx_XGIVEREF(__pyx_r);
25611   __Pyx_TraceReturn(__pyx_r);
25612   __Pyx_RefNannyFinishContext();
25613   return __pyx_r;
25614 }
25615
25616 /* "csamtools.pyx":2809
25617  *         os.close(fd)                #  Close other unit (look out, caller.)
25618  * 
25619  *     def restore(self):             # <<<<<<<<<<<<<<
25620  *         '''restore previous output stream'''
25621  *         if self.streams:
25622  */
25623
25624 static PyObject *__pyx_pf_9csamtools_4Outs_4restore(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
25625 static char __pyx_doc_9csamtools_4Outs_4restore[] = "Outs.restore(self)\nrestore previous output stream";
25626 static PyMethodDef __pyx_mdef_9csamtools_4Outs_4restore = {__Pyx_NAMESTR("restore"), (PyCFunction)__pyx_pf_9csamtools_4Outs_4restore, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_4Outs_4restore)};
25627 static PyObject *__pyx_pf_9csamtools_4Outs_4restore(PyObject *__pyx_self, PyObject *__pyx_v_self) {
25628   PyObject *__pyx_r = NULL;
25629   PyObject *__pyx_t_1 = NULL;
25630   int __pyx_t_2;
25631   PyObject *__pyx_t_3 = NULL;
25632   PyObject *__pyx_t_4 = NULL;
25633   PyObject *__pyx_t_5 = NULL;
25634   __Pyx_TraceDeclarations
25635   __Pyx_RefNannySetupContext("restore");
25636   __Pyx_TraceCall("restore", __pyx_f[0], 2809);
25637   __pyx_self = __pyx_self;
25638
25639   /* "csamtools.pyx":2811
25640  *     def restore(self):
25641  *         '''restore previous output stream'''
25642  *         if self.streams:             # <<<<<<<<<<<<<<
25643  *             # the following was not sufficient, hence flush both stderr and stdout
25644  *             # os.fsync( self.id )
25645  */
25646   __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25647   __Pyx_GOTREF(__pyx_t_1);
25648   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25649   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25650   if (__pyx_t_2) {
25651
25652     /* "csamtools.pyx":2814
25653  *             # the following was not sufficient, hence flush both stderr and stdout
25654  *             # os.fsync( self.id )
25655  *             sys.stdout.flush()             # <<<<<<<<<<<<<<
25656  *             sys.stderr.flush()
25657  *             os.dup2(self.streams[-1], self.id)
25658  */
25659     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25660     __Pyx_GOTREF(__pyx_t_1);
25661     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stdout); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25662     __Pyx_GOTREF(__pyx_t_3);
25663     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25664     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25665     __Pyx_GOTREF(__pyx_t_1);
25666     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25667     __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 = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25668     __Pyx_GOTREF(__pyx_t_3);
25669     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25670     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25671
25672     /* "csamtools.pyx":2815
25673  *             # os.fsync( self.id )
25674  *             sys.stdout.flush()
25675  *             sys.stderr.flush()             # <<<<<<<<<<<<<<
25676  *             os.dup2(self.streams[-1], self.id)
25677  *             os.close(self.streams[-1])
25678  */
25679     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25680     __Pyx_GOTREF(__pyx_t_3);
25681     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stderr); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25682     __Pyx_GOTREF(__pyx_t_1);
25683     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25684     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25685     __Pyx_GOTREF(__pyx_t_3);
25686     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25687     __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 = 2815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25688     __Pyx_GOTREF(__pyx_t_1);
25689     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25690     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25691
25692     /* "csamtools.pyx":2816
25693  *             sys.stdout.flush()
25694  *             sys.stderr.flush()
25695  *             os.dup2(self.streams[-1], self.id)             # <<<<<<<<<<<<<<
25696  *             os.close(self.streams[-1])
25697  *             del self.streams[-1]
25698  */
25699     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25700     __Pyx_GOTREF(__pyx_t_1);
25701     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dup2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25702     __Pyx_GOTREF(__pyx_t_3);
25703     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25704     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25705     __Pyx_GOTREF(__pyx_t_1);
25706     __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25707     __Pyx_GOTREF(__pyx_t_4);
25708     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25709     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25710     __Pyx_GOTREF(__pyx_t_1);
25711     __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25712     __Pyx_GOTREF(((PyObject *)__pyx_t_5));
25713     PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
25714     __Pyx_GIVEREF(__pyx_t_4);
25715     PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
25716     __Pyx_GIVEREF(__pyx_t_1);
25717     __pyx_t_4 = 0;
25718     __pyx_t_1 = 0;
25719     __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 = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25720     __Pyx_GOTREF(__pyx_t_1);
25721     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25722     __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
25723     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25724
25725     /* "csamtools.pyx":2817
25726  *             sys.stderr.flush()
25727  *             os.dup2(self.streams[-1], self.id)
25728  *             os.close(self.streams[-1])             # <<<<<<<<<<<<<<
25729  *             del self.streams[-1]
25730  * 
25731  */
25732     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25733     __Pyx_GOTREF(__pyx_t_1);
25734     __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__close); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25735     __Pyx_GOTREF(__pyx_t_5);
25736     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25737     __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25738     __Pyx_GOTREF(__pyx_t_1);
25739     __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25740     __Pyx_GOTREF(__pyx_t_3);
25741     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25742     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25743     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
25744     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
25745     __Pyx_GIVEREF(__pyx_t_3);
25746     __pyx_t_3 = 0;
25747     __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 = 2817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25748     __Pyx_GOTREF(__pyx_t_3);
25749     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
25750     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
25751     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25752
25753     /* "csamtools.pyx":2818
25754  *             os.dup2(self.streams[-1], self.id)
25755  *             os.close(self.streams[-1])
25756  *             del self.streams[-1]             # <<<<<<<<<<<<<<
25757  * 
25758  * def _samtools_dispatch( method,
25759  */
25760     __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__streams); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25761     __Pyx_GOTREF(__pyx_t_3);
25762     if (__Pyx_DelItemInt(__pyx_t_3, -1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25763     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25764     goto __pyx_L5;
25765   }
25766   __pyx_L5:;
25767
25768   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
25769   goto __pyx_L0;
25770   __pyx_L1_error:;
25771   __Pyx_XDECREF(__pyx_t_1);
25772   __Pyx_XDECREF(__pyx_t_3);
25773   __Pyx_XDECREF(__pyx_t_4);
25774   __Pyx_XDECREF(__pyx_t_5);
25775   __Pyx_AddTraceback("csamtools.Outs.restore");
25776   __pyx_r = NULL;
25777   __pyx_L0:;
25778   __Pyx_XGIVEREF(__pyx_r);
25779   __Pyx_TraceReturn(__pyx_r);
25780   __Pyx_RefNannyFinishContext();
25781   return __pyx_r;
25782 }
25783
25784 /* "csamtools.pyx":2820
25785  *             del self.streams[-1]
25786  * 
25787  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
25788  *                         args = (),
25789  *                         catch_stdout = True,
25790  */
25791
25792 static PyObject *__pyx_pf_9csamtools__samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
25793 static char __pyx_doc_9csamtools__samtools_dispatch[] = "_samtools_dispatch(method, args=(), catch_stdout=True, catch_stderr=False)\ncall ``method`` in samtools providing arguments in args.\n    \n    .. note:: \n       This method redirects stdout and (optionally) stderr to capture it \n       from samtools. If for some reason stdout/stderr 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    ";
25794 static PyMethodDef __pyx_mdef_9csamtools__samtools_dispatch = {__Pyx_NAMESTR("_samtools_dispatch"), (PyCFunction)__pyx_pf_9csamtools__samtools_dispatch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools__samtools_dispatch)};
25795 static PyObject *__pyx_pf_9csamtools__samtools_dispatch(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
25796   PyObject *__pyx_v_method = 0;
25797   PyObject *__pyx_v_args = 0;
25798   PyObject *__pyx_v_catch_stdout = 0;
25799   PyObject *__pyx_v_catch_stderr = 0;
25800   PyObject *__pyx_v_stderr_h;
25801   PyObject *__pyx_v_stderr_f;
25802   PyObject *__pyx_v_stderr_save;
25803   PyObject *__pyx_v_stdout_h;
25804   PyObject *__pyx_v_stdout_f;
25805   PyObject *__pyx_v_stdout_save;
25806   char **__pyx_v_cargs;
25807   int __pyx_v_i;
25808   int __pyx_v_n;
25809   int __pyx_v_retval;
25810   PyObject *__pyx_v_out_stdout;
25811   PyObject *__pyx_v_out_stderr;
25812   PyObject *__pyx_r = NULL;
25813   PyObject *__pyx_t_1 = NULL;
25814   int __pyx_t_2;
25815   PyObject *__pyx_t_3 = NULL;
25816   PyObject *__pyx_t_4 = NULL;
25817   int __pyx_t_5;
25818   PyObject *__pyx_t_6 = NULL;
25819   Py_ssize_t __pyx_t_7;
25820   char *__pyx_t_8;
25821   int __pyx_t_9;
25822   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__method,&__pyx_n_s__args,&__pyx_n_s__catch_stdout,&__pyx_n_s__catch_stderr,0};
25823   __Pyx_TraceDeclarations
25824   __Pyx_RefNannySetupContext("_samtools_dispatch");
25825   __Pyx_TraceCall("_samtools_dispatch", __pyx_f[0], 2820);
25826   __pyx_self = __pyx_self;
25827   if (unlikely(__pyx_kwds)) {
25828     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
25829     PyObject* values[4] = {0,0,0,0};
25830
25831     /* "csamtools.pyx":2821
25832  * 
25833  * def _samtools_dispatch( method,
25834  *                         args = (),             # <<<<<<<<<<<<<<
25835  *                         catch_stdout = True,
25836  *                         catch_stderr = False,
25837  */
25838     values[1] = ((PyObject *)__pyx_empty_tuple);
25839     values[2] = __pyx_k_160;
25840     values[3] = __pyx_k_161;
25841     switch (PyTuple_GET_SIZE(__pyx_args)) {
25842       case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
25843       case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
25844       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
25845       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
25846       case  0: break;
25847       default: goto __pyx_L5_argtuple_error;
25848     }
25849     switch (PyTuple_GET_SIZE(__pyx_args)) {
25850       case  0:
25851       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__method);
25852       if (likely(values[0])) kw_args--;
25853       else goto __pyx_L5_argtuple_error;
25854       case  1:
25855       if (kw_args > 0) {
25856         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__args);
25857         if (value) { values[1] = value; kw_args--; }
25858       }
25859       case  2:
25860       if (kw_args > 0) {
25861         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__catch_stdout);
25862         if (value) { values[2] = value; kw_args--; }
25863       }
25864       case  3:
25865       if (kw_args > 0) {
25866         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__catch_stderr);
25867         if (value) { values[3] = value; kw_args--; }
25868       }
25869     }
25870     if (unlikely(kw_args > 0)) {
25871       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "_samtools_dispatch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25872     }
25873     __pyx_v_method = values[0];
25874     __pyx_v_args = values[1];
25875     __pyx_v_catch_stdout = values[2];
25876     __pyx_v_catch_stderr = values[3];
25877   } else {
25878     __pyx_v_args = ((PyObject *)__pyx_empty_tuple);
25879     __pyx_v_catch_stdout = __pyx_k_160;
25880     __pyx_v_catch_stderr = __pyx_k_161;
25881     switch (PyTuple_GET_SIZE(__pyx_args)) {
25882       case  4: __pyx_v_catch_stderr = PyTuple_GET_ITEM(__pyx_args, 3);
25883       case  3: __pyx_v_catch_stdout = PyTuple_GET_ITEM(__pyx_args, 2);
25884       case  2: __pyx_v_args = PyTuple_GET_ITEM(__pyx_args, 1);
25885       case  1: __pyx_v_method = PyTuple_GET_ITEM(__pyx_args, 0);
25886       break;
25887       default: goto __pyx_L5_argtuple_error;
25888     }
25889   }
25890   goto __pyx_L4_argument_unpacking_done;
25891   __pyx_L5_argtuple_error:;
25892   __Pyx_RaiseArgtupleInvalid("_samtools_dispatch", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
25893   __pyx_L3_error:;
25894   __Pyx_AddTraceback("csamtools._samtools_dispatch");
25895   __Pyx_RefNannyFinishContext();
25896   return NULL;
25897   __pyx_L4_argument_unpacking_done:;
25898   __Pyx_INCREF(__pyx_v_args);
25899   __pyx_v_stderr_h = Py_None; __Pyx_INCREF(Py_None);
25900   __pyx_v_stderr_f = Py_None; __Pyx_INCREF(Py_None);
25901   __pyx_v_stderr_save = Py_None; __Pyx_INCREF(Py_None);
25902   __pyx_v_stdout_h = Py_None; __Pyx_INCREF(Py_None);
25903   __pyx_v_stdout_f = Py_None; __Pyx_INCREF(Py_None);
25904   __pyx_v_stdout_save = Py_None; __Pyx_INCREF(Py_None);
25905   __pyx_v_out_stdout = Py_None; __Pyx_INCREF(Py_None);
25906   __pyx_v_out_stderr = Py_None; __Pyx_INCREF(Py_None);
25907
25908   /* "csamtools.pyx":2848
25909  * 
25910  *     # some special cases
25911  *     if method == "index":             # <<<<<<<<<<<<<<
25912  *         if not os.path.exists( args[0] ):
25913  *             raise IOError( "No such file or directory: '%s'" % args[0] )
25914  */
25915   __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__index), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25916   __Pyx_GOTREF(__pyx_t_1);
25917   __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25918   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25919   if (__pyx_t_2) {
25920
25921     /* "csamtools.pyx":2849
25922  *     # some special cases
25923  *     if method == "index":
25924  *         if not os.path.exists( args[0] ):             # <<<<<<<<<<<<<<
25925  *             raise IOError( "No such file or directory: '%s'" % args[0] )
25926  * 
25927  */
25928     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25929     __Pyx_GOTREF(__pyx_t_1);
25930     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25931     __Pyx_GOTREF(__pyx_t_3);
25932     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25933     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__exists); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25934     __Pyx_GOTREF(__pyx_t_1);
25935     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25936     __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25937     __Pyx_GOTREF(__pyx_t_3);
25938     __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25939     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
25940     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
25941     __Pyx_GIVEREF(__pyx_t_3);
25942     __pyx_t_3 = 0;
25943     __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 = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25944     __Pyx_GOTREF(__pyx_t_3);
25945     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
25946     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
25947     __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25948     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25949     __pyx_t_5 = (!__pyx_t_2);
25950     if (__pyx_t_5) {
25951
25952       /* "csamtools.pyx":2850
25953  *     if method == "index":
25954  *         if not os.path.exists( args[0] ):
25955  *             raise IOError( "No such file or directory: '%s'" % args[0] )             # <<<<<<<<<<<<<<
25956  * 
25957  *     # redirect stderr and stdout to file
25958  */
25959       __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_args, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25960       __Pyx_GOTREF(__pyx_t_3);
25961       __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_162), __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25962       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
25963       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
25964       __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25965       __Pyx_GOTREF(((PyObject *)__pyx_t_3));
25966       PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_4));
25967       __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
25968       __pyx_t_4 = 0;
25969       __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 = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25970       __Pyx_GOTREF(__pyx_t_4);
25971       __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
25972       __Pyx_Raise(__pyx_t_4, 0, 0);
25973       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
25974       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25975       goto __pyx_L7;
25976     }
25977     __pyx_L7:;
25978     goto __pyx_L6;
25979   }
25980   __pyx_L6:;
25981
25982   /* "csamtools.pyx":2853
25983  * 
25984  *     # redirect stderr and stdout to file
25985  *     if catch_stderr:             # <<<<<<<<<<<<<<
25986  *         stderr_h, stderr_f = tempfile.mkstemp()
25987  *         stderr_save = Outs( sys.stderr.fileno() )
25988  */
25989   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stderr); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
25990   if (__pyx_t_5) {
25991
25992     /* "csamtools.pyx":2854
25993  *     # redirect stderr and stdout to file
25994  *     if catch_stderr:
25995  *         stderr_h, stderr_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
25996  *         stderr_save = Outs( sys.stderr.fileno() )
25997  *         stderr_save.setfd( stderr_h )
25998  */
25999     __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26000     __Pyx_GOTREF(__pyx_t_4);
26001     __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26002     __Pyx_GOTREF(__pyx_t_3);
26003     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26004     __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 = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26005     __Pyx_GOTREF(__pyx_t_4);
26006     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26007     if (PyTuple_CheckExact(__pyx_t_4) && likely(PyTuple_GET_SIZE(__pyx_t_4) == 2)) {
26008       PyObject* tuple = __pyx_t_4;
26009       __pyx_t_3 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_3);
26010       __pyx_t_1 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_1);
26011       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26012       __Pyx_DECREF(__pyx_v_stderr_h);
26013       __pyx_v_stderr_h = __pyx_t_3;
26014       __pyx_t_3 = 0;
26015       __Pyx_DECREF(__pyx_v_stderr_f);
26016       __pyx_v_stderr_f = __pyx_t_1;
26017       __pyx_t_1 = 0;
26018     } else {
26019       __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26020       __Pyx_GOTREF(__pyx_t_6);
26021       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26022       __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26023       __Pyx_GOTREF(__pyx_t_3);
26024       __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26025       __Pyx_GOTREF(__pyx_t_1);
26026       if (__Pyx_EndUnpack(__pyx_t_6, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26027       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
26028       __Pyx_DECREF(__pyx_v_stderr_h);
26029       __pyx_v_stderr_h = __pyx_t_3;
26030       __pyx_t_3 = 0;
26031       __Pyx_DECREF(__pyx_v_stderr_f);
26032       __pyx_v_stderr_f = __pyx_t_1;
26033       __pyx_t_1 = 0;
26034     }
26035
26036     /* "csamtools.pyx":2855
26037  *     if catch_stderr:
26038  *         stderr_h, stderr_f = tempfile.mkstemp()
26039  *         stderr_save = Outs( sys.stderr.fileno() )             # <<<<<<<<<<<<<<
26040  *         stderr_save.setfd( stderr_h )
26041  * 
26042  */
26043     __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26044     __Pyx_GOTREF(__pyx_t_4);
26045     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26046     __Pyx_GOTREF(__pyx_t_1);
26047     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26048     __Pyx_GOTREF(__pyx_t_3);
26049     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26050     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fileno); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26051     __Pyx_GOTREF(__pyx_t_1);
26052     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26053     __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 = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26054     __Pyx_GOTREF(__pyx_t_3);
26055     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26056     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26057     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
26058     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
26059     __Pyx_GIVEREF(__pyx_t_3);
26060     __pyx_t_3 = 0;
26061     __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26062     __Pyx_GOTREF(__pyx_t_3);
26063     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26064     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
26065     __Pyx_DECREF(__pyx_v_stderr_save);
26066     __pyx_v_stderr_save = __pyx_t_3;
26067     __pyx_t_3 = 0;
26068
26069     /* "csamtools.pyx":2856
26070  *         stderr_h, stderr_f = tempfile.mkstemp()
26071  *         stderr_save = Outs( sys.stderr.fileno() )
26072  *         stderr_save.setfd( stderr_h )             # <<<<<<<<<<<<<<
26073  * 
26074  *     if catch_stdout:
26075  */
26076     __pyx_t_3 = PyObject_GetAttr(__pyx_v_stderr_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26077     __Pyx_GOTREF(__pyx_t_3);
26078     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26079     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
26080     __Pyx_INCREF(__pyx_v_stderr_h);
26081     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stderr_h);
26082     __Pyx_GIVEREF(__pyx_v_stderr_h);
26083     __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26084     __Pyx_GOTREF(__pyx_t_4);
26085     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26086     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
26087     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26088     goto __pyx_L8;
26089   }
26090   __pyx_L8:;
26091
26092   /* "csamtools.pyx":2858
26093  *         stderr_save.setfd( stderr_h )
26094  * 
26095  *     if catch_stdout:             # <<<<<<<<<<<<<<
26096  *         stdout_h, stdout_f = tempfile.mkstemp()
26097  *         stdout_save = Outs( sys.stdout.fileno() )
26098  */
26099   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26100   if (__pyx_t_5) {
26101
26102     /* "csamtools.pyx":2859
26103  * 
26104  *     if catch_stdout:
26105  *         stdout_h, stdout_f = tempfile.mkstemp()             # <<<<<<<<<<<<<<
26106  *         stdout_save = Outs( sys.stdout.fileno() )
26107  *         stdout_save.setfd( stdout_h )
26108  */
26109     __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__tempfile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26110     __Pyx_GOTREF(__pyx_t_4);
26111     __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mkstemp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26112     __Pyx_GOTREF(__pyx_t_1);
26113     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26114     __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26115     __Pyx_GOTREF(__pyx_t_4);
26116     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26117     if (PyTuple_CheckExact(__pyx_t_4) && likely(PyTuple_GET_SIZE(__pyx_t_4) == 2)) {
26118       PyObject* tuple = __pyx_t_4;
26119       __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
26120       __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
26121       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26122       __Pyx_DECREF(__pyx_v_stdout_h);
26123       __pyx_v_stdout_h = __pyx_t_1;
26124       __pyx_t_1 = 0;
26125       __Pyx_DECREF(__pyx_v_stdout_f);
26126       __pyx_v_stdout_f = __pyx_t_3;
26127       __pyx_t_3 = 0;
26128     } else {
26129       __pyx_t_6 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26130       __Pyx_GOTREF(__pyx_t_6);
26131       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26132       __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_6, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26133       __Pyx_GOTREF(__pyx_t_1);
26134       __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_6, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26135       __Pyx_GOTREF(__pyx_t_3);
26136       if (__Pyx_EndUnpack(__pyx_t_6, 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26137       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
26138       __Pyx_DECREF(__pyx_v_stdout_h);
26139       __pyx_v_stdout_h = __pyx_t_1;
26140       __pyx_t_1 = 0;
26141       __Pyx_DECREF(__pyx_v_stdout_f);
26142       __pyx_v_stdout_f = __pyx_t_3;
26143       __pyx_t_3 = 0;
26144     }
26145
26146     /* "csamtools.pyx":2860
26147  *     if catch_stdout:
26148  *         stdout_h, stdout_f = tempfile.mkstemp()
26149  *         stdout_save = Outs( sys.stdout.fileno() )             # <<<<<<<<<<<<<<
26150  *         stdout_save.setfd( stdout_h )
26151  * 
26152  */
26153     __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__Outs); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26154     __Pyx_GOTREF(__pyx_t_4);
26155     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26156     __Pyx_GOTREF(__pyx_t_3);
26157     __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__stdout); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26158     __Pyx_GOTREF(__pyx_t_1);
26159     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26160     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26161     __Pyx_GOTREF(__pyx_t_3);
26162     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26163     __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 = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26164     __Pyx_GOTREF(__pyx_t_1);
26165     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26166     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26167     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
26168     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
26169     __Pyx_GIVEREF(__pyx_t_1);
26170     __pyx_t_1 = 0;
26171     __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26172     __Pyx_GOTREF(__pyx_t_1);
26173     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26174     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
26175     __Pyx_DECREF(__pyx_v_stdout_save);
26176     __pyx_v_stdout_save = __pyx_t_1;
26177     __pyx_t_1 = 0;
26178
26179     /* "csamtools.pyx":2861
26180  *         stdout_h, stdout_f = tempfile.mkstemp()
26181  *         stdout_save = Outs( sys.stdout.fileno() )
26182  *         stdout_save.setfd( stdout_h )             # <<<<<<<<<<<<<<
26183  * 
26184  *         # patch for `samtools view`
26185  */
26186     __pyx_t_1 = PyObject_GetAttr(__pyx_v_stdout_save, __pyx_n_s__setfd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26187     __Pyx_GOTREF(__pyx_t_1);
26188     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26189     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
26190     __Pyx_INCREF(__pyx_v_stdout_h);
26191     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_h);
26192     __Pyx_GIVEREF(__pyx_v_stdout_h);
26193     __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26194     __Pyx_GOTREF(__pyx_t_4);
26195     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26196     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
26197     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26198
26199     /* "csamtools.pyx":2866
26200  *         # samtools `view` closes stdout, from which I can not
26201  *         # recover. Thus redirect output to file with -o option.
26202  *         if method == "view":             # <<<<<<<<<<<<<<
26203  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
26204  *             args = ( "-o", stdout_f ) + args
26205  */
26206     __pyx_t_4 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__view), Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26207     __Pyx_GOTREF(__pyx_t_4);
26208     __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26209     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26210     if (__pyx_t_5) {
26211
26212       /* "csamtools.pyx":2867
26213  *         # recover. Thus redirect output to file with -o option.
26214  *         if method == "view":
26215  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
26216  *             args = ( "-o", stdout_f ) + args
26217  * 
26218  */
26219       __pyx_t_5 = ((PySequence_Contains(__pyx_v_args, ((PyObject *)__pyx_kp_s_163)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26220       if (__pyx_t_5) {
26221         __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_165), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26222         __Pyx_GOTREF(__pyx_t_4);
26223         __Pyx_Raise(__pyx_t_4, 0, 0);
26224         __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26225         {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26226         goto __pyx_L11;
26227       }
26228       __pyx_L11:;
26229
26230       /* "csamtools.pyx":2868
26231  *         if method == "view":
26232  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")
26233  *             args = ( "-o", stdout_f ) + args             # <<<<<<<<<<<<<<
26234  * 
26235  *     # do the function call to samtools
26236  */
26237       __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26238       __Pyx_GOTREF(((PyObject *)__pyx_t_4));
26239       __Pyx_INCREF(((PyObject *)__pyx_kp_s_163));
26240       PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_163));
26241       __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_163));
26242       __Pyx_INCREF(__pyx_v_stdout_f);
26243       PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_stdout_f);
26244       __Pyx_GIVEREF(__pyx_v_stdout_f);
26245       __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_4), __pyx_v_args); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26246       __Pyx_GOTREF(__pyx_t_3);
26247       __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
26248       __Pyx_DECREF(__pyx_v_args);
26249       __pyx_v_args = __pyx_t_3;
26250       __pyx_t_3 = 0;
26251       goto __pyx_L10;
26252     }
26253     __pyx_L10:;
26254     goto __pyx_L9;
26255   }
26256   __pyx_L9:;
26257
26258   /* "csamtools.pyx":2874
26259  *     cdef int i, n, retval
26260  * 
26261  *     n = len(args)             # <<<<<<<<<<<<<<
26262  *     # allocate two more for first (dummy) argument (contains command)
26263  *     cargs = <char**>calloc( n+2, sizeof( char *) )
26264  */
26265   __pyx_t_7 = PyObject_Length(__pyx_v_args); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26266   __pyx_v_n = __pyx_t_7;
26267
26268   /* "csamtools.pyx":2876
26269  *     n = len(args)
26270  *     # allocate two more for first (dummy) argument (contains command)
26271  *     cargs = <char**>calloc( n+2, sizeof( char *) )             # <<<<<<<<<<<<<<
26272  *     cargs[0] = "samtools"
26273  *     cargs[1] = method
26274  */
26275   __pyx_v_cargs = ((char **)calloc((__pyx_v_n + 2), (sizeof(char *))));
26276
26277   /* "csamtools.pyx":2877
26278  *     # allocate two more for first (dummy) argument (contains command)
26279  *     cargs = <char**>calloc( n+2, sizeof( char *) )
26280  *     cargs[0] = "samtools"             # <<<<<<<<<<<<<<
26281  *     cargs[1] = method
26282  *     for i from 0 <= i < n: cargs[i+2] = args[i]
26283  */
26284   (__pyx_v_cargs[0]) = __pyx_k__samtools;
26285
26286   /* "csamtools.pyx":2878
26287  *     cargs = <char**>calloc( n+2, sizeof( char *) )
26288  *     cargs[0] = "samtools"
26289  *     cargs[1] = method             # <<<<<<<<<<<<<<
26290  *     for i from 0 <= i < n: cargs[i+2] = args[i]
26291  * 
26292  */
26293   __pyx_t_8 = PyBytes_AsString(__pyx_v_method); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26294   (__pyx_v_cargs[1]) = __pyx_t_8;
26295
26296   /* "csamtools.pyx":2879
26297  *     cargs[0] = "samtools"
26298  *     cargs[1] = method
26299  *     for i from 0 <= i < n: cargs[i+2] = args[i]             # <<<<<<<<<<<<<<
26300  * 
26301  *     retval = pysam_dispatch(n+2, cargs)
26302  */
26303   __pyx_t_9 = __pyx_v_n;
26304   for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {
26305     __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 = 2879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26306     __Pyx_GOTREF(__pyx_t_3);
26307     __pyx_t_8 = PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26308     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26309     (__pyx_v_cargs[(__pyx_v_i + 2)]) = __pyx_t_8;
26310   }
26311
26312   /* "csamtools.pyx":2881
26313  *     for i from 0 <= i < n: cargs[i+2] = args[i]
26314  * 
26315  *     retval = pysam_dispatch(n+2, cargs)             # <<<<<<<<<<<<<<
26316  *     free( cargs )
26317  * 
26318  */
26319   __pyx_v_retval = pysam_dispatch((__pyx_v_n + 2), __pyx_v_cargs);
26320
26321   /* "csamtools.pyx":2882
26322  * 
26323  *     retval = pysam_dispatch(n+2, cargs)
26324  *     free( cargs )             # <<<<<<<<<<<<<<
26325  * 
26326  *     # restore stdout/stderr. This will also flush, so
26327  */
26328   free(__pyx_v_cargs);
26329
26330   /* "csamtools.pyx":2886
26331  *     # restore stdout/stderr. This will also flush, so
26332  *     # needs to be before reading back the file contents
26333  *     if catch_stdout:             # <<<<<<<<<<<<<<
26334  *         stdout_save.restore()
26335  *         out_stdout = open( stdout_f, "r").readlines()
26336  */
26337   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stdout); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26338   if (__pyx_t_5) {
26339
26340     /* "csamtools.pyx":2887
26341  *     # needs to be before reading back the file contents
26342  *     if catch_stdout:
26343  *         stdout_save.restore()             # <<<<<<<<<<<<<<
26344  *         out_stdout = open( stdout_f, "r").readlines()
26345  *         os.remove( stdout_f )
26346  */
26347     __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 = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26348     __Pyx_GOTREF(__pyx_t_3);
26349     __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 = 2887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26350     __Pyx_GOTREF(__pyx_t_4);
26351     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26352     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26353
26354     /* "csamtools.pyx":2888
26355  *     if catch_stdout:
26356  *         stdout_save.restore()
26357  *         out_stdout = open( stdout_f, "r").readlines()             # <<<<<<<<<<<<<<
26358  *         os.remove( stdout_f )
26359  *     else:
26360  */
26361     __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26362     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
26363     __Pyx_INCREF(__pyx_v_stdout_f);
26364     PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_stdout_f);
26365     __Pyx_GIVEREF(__pyx_v_stdout_f);
26366     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
26367     PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_n_s__r));
26368     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
26369     __pyx_t_3 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26370     __Pyx_GOTREF(__pyx_t_3);
26371     __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
26372     __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__readlines); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26373     __Pyx_GOTREF(__pyx_t_4);
26374     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26375     __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 = 2888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26376     __Pyx_GOTREF(__pyx_t_3);
26377     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26378     __Pyx_DECREF(__pyx_v_out_stdout);
26379     __pyx_v_out_stdout = __pyx_t_3;
26380     __pyx_t_3 = 0;
26381
26382     /* "csamtools.pyx":2889
26383  *         stdout_save.restore()
26384  *         out_stdout = open( stdout_f, "r").readlines()
26385  *         os.remove( stdout_f )             # <<<<<<<<<<<<<<
26386  *     else:
26387  *         out_stdout = []
26388  */
26389     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26390     __Pyx_GOTREF(__pyx_t_3);
26391     __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__remove); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26392     __Pyx_GOTREF(__pyx_t_4);
26393     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26394     __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26395     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
26396     __Pyx_INCREF(__pyx_v_stdout_f);
26397     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stdout_f);
26398     __Pyx_GIVEREF(__pyx_v_stdout_f);
26399     __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26400     __Pyx_GOTREF(__pyx_t_1);
26401     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26402     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
26403     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26404     goto __pyx_L14;
26405   }
26406   /*else*/ {
26407
26408     /* "csamtools.pyx":2891
26409  *         os.remove( stdout_f )
26410  *     else:
26411  *         out_stdout = []             # <<<<<<<<<<<<<<
26412  * 
26413  *     if catch_stderr:
26414  */
26415     __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26416     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
26417     __Pyx_DECREF(__pyx_v_out_stdout);
26418     __pyx_v_out_stdout = ((PyObject *)__pyx_t_1);
26419     __pyx_t_1 = 0;
26420   }
26421   __pyx_L14:;
26422
26423   /* "csamtools.pyx":2893
26424  *         out_stdout = []
26425  * 
26426  *     if catch_stderr:             # <<<<<<<<<<<<<<
26427  *         stderr_save.restore()
26428  *         out_stderr = open( stderr_f, "r").readlines()
26429  */
26430   __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_catch_stderr); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26431   if (__pyx_t_5) {
26432
26433     /* "csamtools.pyx":2894
26434  * 
26435  *     if catch_stderr:
26436  *         stderr_save.restore()             # <<<<<<<<<<<<<<
26437  *         out_stderr = open( stderr_f, "r").readlines()
26438  *         os.remove( stderr_f )
26439  */
26440     __pyx_t_1 = PyObject_GetAttr(__pyx_v_stderr_save, __pyx_n_s__restore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26441     __Pyx_GOTREF(__pyx_t_1);
26442     __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 = 2894; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26443     __Pyx_GOTREF(__pyx_t_3);
26444     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26445     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26446
26447     /* "csamtools.pyx":2895
26448  *     if catch_stderr:
26449  *         stderr_save.restore()
26450  *         out_stderr = open( stderr_f, "r").readlines()             # <<<<<<<<<<<<<<
26451  *         os.remove( stderr_f )
26452  *     else:
26453  */
26454     __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26455     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
26456     __Pyx_INCREF(__pyx_v_stderr_f);
26457     PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_stderr_f);
26458     __Pyx_GIVEREF(__pyx_v_stderr_f);
26459     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
26460     PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__r));
26461     __Pyx_GIVEREF(((PyObject *)__pyx_n_s__r));
26462     __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26463     __Pyx_GOTREF(__pyx_t_1);
26464     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
26465     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__readlines); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26466     __Pyx_GOTREF(__pyx_t_3);
26467     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26468     __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 = 2895; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26469     __Pyx_GOTREF(__pyx_t_1);
26470     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26471     __Pyx_DECREF(__pyx_v_out_stderr);
26472     __pyx_v_out_stderr = __pyx_t_1;
26473     __pyx_t_1 = 0;
26474
26475     /* "csamtools.pyx":2896
26476  *         stderr_save.restore()
26477  *         out_stderr = open( stderr_f, "r").readlines()
26478  *         os.remove( stderr_f )             # <<<<<<<<<<<<<<
26479  *     else:
26480  *         out_stderr = []
26481  */
26482     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26483     __Pyx_GOTREF(__pyx_t_1);
26484     __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__remove); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26485     __Pyx_GOTREF(__pyx_t_3);
26486     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
26487     __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26488     __Pyx_GOTREF(((PyObject *)__pyx_t_1));
26489     __Pyx_INCREF(__pyx_v_stderr_f);
26490     PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stderr_f);
26491     __Pyx_GIVEREF(__pyx_v_stderr_f);
26492     __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2896; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26493     __Pyx_GOTREF(__pyx_t_4);
26494     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
26495     __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
26496     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
26497     goto __pyx_L15;
26498   }
26499   /*else*/ {
26500
26501     /* "csamtools.pyx":2898
26502  *         os.remove( stderr_f )
26503  *     else:
26504  *         out_stderr = []             # <<<<<<<<<<<<<<
26505  * 
26506  *     return retval, out_stderr, out_stdout
26507  */
26508     __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26509     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
26510     __Pyx_DECREF(__pyx_v_out_stderr);
26511     __pyx_v_out_stderr = ((PyObject *)__pyx_t_4);
26512     __pyx_t_4 = 0;
26513   }
26514   __pyx_L15:;
26515
26516   /* "csamtools.pyx":2900
26517  *         out_stderr = []
26518  * 
26519  *     return retval, out_stderr, out_stdout             # <<<<<<<<<<<<<<
26520  * 
26521  * cdef class SNPCall:
26522  */
26523   __Pyx_XDECREF(__pyx_r);
26524   __pyx_t_4 = PyInt_FromLong(__pyx_v_retval); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26525   __Pyx_GOTREF(__pyx_t_4);
26526   __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2900; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26527   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
26528   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
26529   __Pyx_GIVEREF(__pyx_t_4);
26530   __Pyx_INCREF(__pyx_v_out_stderr);
26531   PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_out_stderr);
26532   __Pyx_GIVEREF(__pyx_v_out_stderr);
26533   __Pyx_INCREF(__pyx_v_out_stdout);
26534   PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_out_stdout);
26535   __Pyx_GIVEREF(__pyx_v_out_stdout);
26536   __pyx_t_4 = 0;
26537   __pyx_r = ((PyObject *)__pyx_t_1);
26538   __pyx_t_1 = 0;
26539   goto __pyx_L0;
26540
26541   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26542   goto __pyx_L0;
26543   __pyx_L1_error:;
26544   __Pyx_XDECREF(__pyx_t_1);
26545   __Pyx_XDECREF(__pyx_t_3);
26546   __Pyx_XDECREF(__pyx_t_4);
26547   __Pyx_XDECREF(__pyx_t_6);
26548   __Pyx_AddTraceback("csamtools._samtools_dispatch");
26549   __pyx_r = NULL;
26550   __pyx_L0:;
26551   __Pyx_DECREF(__pyx_v_stderr_h);
26552   __Pyx_DECREF(__pyx_v_stderr_f);
26553   __Pyx_DECREF(__pyx_v_stderr_save);
26554   __Pyx_DECREF(__pyx_v_stdout_h);
26555   __Pyx_DECREF(__pyx_v_stdout_f);
26556   __Pyx_DECREF(__pyx_v_stdout_save);
26557   __Pyx_DECREF(__pyx_v_out_stdout);
26558   __Pyx_DECREF(__pyx_v_out_stderr);
26559   __Pyx_DECREF(__pyx_v_args);
26560   __Pyx_XGIVEREF(__pyx_r);
26561   __Pyx_TraceReturn(__pyx_r);
26562   __Pyx_RefNannyFinishContext();
26563   return __pyx_r;
26564 }
26565
26566 /* "csamtools.pyx":2915
26567  *     property tid:
26568  *         '''the chromosome ID as is defined in the header'''
26569  *         def __get__(self):             # <<<<<<<<<<<<<<
26570  *             return self._tid
26571  * 
26572  */
26573
26574 static PyObject *__pyx_pf_9csamtools_7SNPCall_3tid___get__(PyObject *__pyx_v_self); /*proto*/
26575 static PyObject *__pyx_pf_9csamtools_7SNPCall_3tid___get__(PyObject *__pyx_v_self) {
26576   PyObject *__pyx_r = NULL;
26577   PyObject *__pyx_t_1 = NULL;
26578   __Pyx_TraceDeclarations
26579   __Pyx_RefNannySetupContext("__get__");
26580   __Pyx_TraceCall("__get__", __pyx_f[0], 2915);
26581
26582   /* "csamtools.pyx":2916
26583  *         '''the chromosome ID as is defined in the header'''
26584  *         def __get__(self):
26585  *             return self._tid             # <<<<<<<<<<<<<<
26586  * 
26587  *     property pos:
26588  */
26589   __Pyx_XDECREF(__pyx_r);
26590   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26591   __Pyx_GOTREF(__pyx_t_1);
26592   __pyx_r = __pyx_t_1;
26593   __pyx_t_1 = 0;
26594   goto __pyx_L0;
26595
26596   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26597   goto __pyx_L0;
26598   __pyx_L1_error:;
26599   __Pyx_XDECREF(__pyx_t_1);
26600   __Pyx_AddTraceback("csamtools.SNPCall.tid.__get__");
26601   __pyx_r = NULL;
26602   __pyx_L0:;
26603   __Pyx_XGIVEREF(__pyx_r);
26604   __Pyx_TraceReturn(__pyx_r);
26605   __Pyx_RefNannyFinishContext();
26606   return __pyx_r;
26607 }
26608
26609 /* "csamtools.pyx":2920
26610  *     property pos:
26611  *        '''nucleotide position of SNP.'''
26612  *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
26613  * 
26614  *     property reference_base:
26615  */
26616
26617 static PyObject *__pyx_pf_9csamtools_7SNPCall_3pos___get__(PyObject *__pyx_v_self); /*proto*/
26618 static PyObject *__pyx_pf_9csamtools_7SNPCall_3pos___get__(PyObject *__pyx_v_self) {
26619   PyObject *__pyx_r = NULL;
26620   PyObject *__pyx_t_1 = NULL;
26621   __Pyx_TraceDeclarations
26622   __Pyx_RefNannySetupContext("__get__");
26623   __Pyx_TraceCall("__get__", __pyx_f[0], 2920);
26624   __Pyx_XDECREF(__pyx_r);
26625   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2920; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26626   __Pyx_GOTREF(__pyx_t_1);
26627   __pyx_r = __pyx_t_1;
26628   __pyx_t_1 = 0;
26629   goto __pyx_L0;
26630
26631   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26632   goto __pyx_L0;
26633   __pyx_L1_error:;
26634   __Pyx_XDECREF(__pyx_t_1);
26635   __Pyx_AddTraceback("csamtools.SNPCall.pos.__get__");
26636   __pyx_r = NULL;
26637   __pyx_L0:;
26638   __Pyx_XGIVEREF(__pyx_r);
26639   __Pyx_TraceReturn(__pyx_r);
26640   __Pyx_RefNannyFinishContext();
26641   return __pyx_r;
26642 }
26643
26644 /* "csamtools.pyx":2924
26645  *     property reference_base:
26646  *        '''reference base at pos. ``N`` if no reference sequence supplied.'''
26647  *        def __get__(self): return PyString_FromStringAndSize( &self._reference_base, 1 )             # <<<<<<<<<<<<<<
26648  * 
26649  *     property genotype:
26650  */
26651
26652 static PyObject *__pyx_pf_9csamtools_7SNPCall_14reference_base___get__(PyObject *__pyx_v_self); /*proto*/
26653 static PyObject *__pyx_pf_9csamtools_7SNPCall_14reference_base___get__(PyObject *__pyx_v_self) {
26654   PyObject *__pyx_r = NULL;
26655   PyObject *__pyx_t_1 = NULL;
26656   __Pyx_TraceDeclarations
26657   __Pyx_RefNannySetupContext("__get__");
26658   __Pyx_TraceCall("__get__", __pyx_f[0], 2924);
26659   __Pyx_XDECREF(__pyx_r);
26660   __pyx_t_1 = PyString_FromStringAndSize((&((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26661   __Pyx_GOTREF(__pyx_t_1);
26662   __pyx_r = __pyx_t_1;
26663   __pyx_t_1 = 0;
26664   goto __pyx_L0;
26665
26666   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26667   goto __pyx_L0;
26668   __pyx_L1_error:;
26669   __Pyx_XDECREF(__pyx_t_1);
26670   __Pyx_AddTraceback("csamtools.SNPCall.reference_base.__get__");
26671   __pyx_r = NULL;
26672   __pyx_L0:;
26673   __Pyx_XGIVEREF(__pyx_r);
26674   __Pyx_TraceReturn(__pyx_r);
26675   __Pyx_RefNannyFinishContext();
26676   return __pyx_r;
26677 }
26678
26679 /* "csamtools.pyx":2928
26680  *     property genotype:
26681  *        '''the genotype called.'''
26682  *        def __get__(self): return PyString_FromStringAndSize( &self._genotype, 1 )             # <<<<<<<<<<<<<<
26683  * 
26684  *     property consensus_quality:
26685  */
26686
26687 static PyObject *__pyx_pf_9csamtools_7SNPCall_8genotype___get__(PyObject *__pyx_v_self); /*proto*/
26688 static PyObject *__pyx_pf_9csamtools_7SNPCall_8genotype___get__(PyObject *__pyx_v_self) {
26689   PyObject *__pyx_r = NULL;
26690   PyObject *__pyx_t_1 = NULL;
26691   __Pyx_TraceDeclarations
26692   __Pyx_RefNannySetupContext("__get__");
26693   __Pyx_TraceCall("__get__", __pyx_f[0], 2928);
26694   __Pyx_XDECREF(__pyx_r);
26695   __pyx_t_1 = PyString_FromStringAndSize((&((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2928; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26696   __Pyx_GOTREF(__pyx_t_1);
26697   __pyx_r = __pyx_t_1;
26698   __pyx_t_1 = 0;
26699   goto __pyx_L0;
26700
26701   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26702   goto __pyx_L0;
26703   __pyx_L1_error:;
26704   __Pyx_XDECREF(__pyx_t_1);
26705   __Pyx_AddTraceback("csamtools.SNPCall.genotype.__get__");
26706   __pyx_r = NULL;
26707   __pyx_L0:;
26708   __Pyx_XGIVEREF(__pyx_r);
26709   __Pyx_TraceReturn(__pyx_r);
26710   __Pyx_RefNannyFinishContext();
26711   return __pyx_r;
26712 }
26713
26714 /* "csamtools.pyx":2932
26715  *     property consensus_quality:
26716  *        '''the genotype quality (Phred-scaled).'''
26717  *        def __get__(self): return self._consensus_quality             # <<<<<<<<<<<<<<
26718  * 
26719  *     property snp_quality:
26720  */
26721
26722 static PyObject *__pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(PyObject *__pyx_v_self); /*proto*/
26723 static PyObject *__pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(PyObject *__pyx_v_self) {
26724   PyObject *__pyx_r = NULL;
26725   PyObject *__pyx_t_1 = NULL;
26726   __Pyx_TraceDeclarations
26727   __Pyx_RefNannySetupContext("__get__");
26728   __Pyx_TraceCall("__get__", __pyx_f[0], 2932);
26729   __Pyx_XDECREF(__pyx_r);
26730   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26731   __Pyx_GOTREF(__pyx_t_1);
26732   __pyx_r = __pyx_t_1;
26733   __pyx_t_1 = 0;
26734   goto __pyx_L0;
26735
26736   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26737   goto __pyx_L0;
26738   __pyx_L1_error:;
26739   __Pyx_XDECREF(__pyx_t_1);
26740   __Pyx_AddTraceback("csamtools.SNPCall.consensus_quality.__get__");
26741   __pyx_r = NULL;
26742   __pyx_L0:;
26743   __Pyx_XGIVEREF(__pyx_r);
26744   __Pyx_TraceReturn(__pyx_r);
26745   __Pyx_RefNannyFinishContext();
26746   return __pyx_r;
26747 }
26748
26749 /* "csamtools.pyx":2936
26750  *     property snp_quality:
26751  *        '''the snp quality (Phred scaled) - probability of consensus being identical to reference sequence.'''
26752  *        def __get__(self): return self._snp_quality             # <<<<<<<<<<<<<<
26753  * 
26754  *     property mapping_quality:
26755  */
26756
26757 static PyObject *__pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(PyObject *__pyx_v_self); /*proto*/
26758 static PyObject *__pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(PyObject *__pyx_v_self) {
26759   PyObject *__pyx_r = NULL;
26760   PyObject *__pyx_t_1 = NULL;
26761   __Pyx_TraceDeclarations
26762   __Pyx_RefNannySetupContext("__get__");
26763   __Pyx_TraceCall("__get__", __pyx_f[0], 2936);
26764   __Pyx_XDECREF(__pyx_r);
26765   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26766   __Pyx_GOTREF(__pyx_t_1);
26767   __pyx_r = __pyx_t_1;
26768   __pyx_t_1 = 0;
26769   goto __pyx_L0;
26770
26771   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26772   goto __pyx_L0;
26773   __pyx_L1_error:;
26774   __Pyx_XDECREF(__pyx_t_1);
26775   __Pyx_AddTraceback("csamtools.SNPCall.snp_quality.__get__");
26776   __pyx_r = NULL;
26777   __pyx_L0:;
26778   __Pyx_XGIVEREF(__pyx_r);
26779   __Pyx_TraceReturn(__pyx_r);
26780   __Pyx_RefNannyFinishContext();
26781   return __pyx_r;
26782 }
26783
26784 /* "csamtools.pyx":2940
26785  *     property mapping_quality:
26786  *        '''the root mean square (rms) of the mapping quality of all reads involved in the call.'''
26787  *        def __get__(self): return self._rms_mapping_quality             # <<<<<<<<<<<<<<
26788  * 
26789  *     property coverage:
26790  */
26791
26792 static PyObject *__pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(PyObject *__pyx_v_self); /*proto*/
26793 static PyObject *__pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(PyObject *__pyx_v_self) {
26794   PyObject *__pyx_r = NULL;
26795   PyObject *__pyx_t_1 = NULL;
26796   __Pyx_TraceDeclarations
26797   __Pyx_RefNannySetupContext("__get__");
26798   __Pyx_TraceCall("__get__", __pyx_f[0], 2940);
26799   __Pyx_XDECREF(__pyx_r);
26800   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26801   __Pyx_GOTREF(__pyx_t_1);
26802   __pyx_r = __pyx_t_1;
26803   __pyx_t_1 = 0;
26804   goto __pyx_L0;
26805
26806   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26807   goto __pyx_L0;
26808   __pyx_L1_error:;
26809   __Pyx_XDECREF(__pyx_t_1);
26810   __Pyx_AddTraceback("csamtools.SNPCall.mapping_quality.__get__");
26811   __pyx_r = NULL;
26812   __pyx_L0:;
26813   __Pyx_XGIVEREF(__pyx_r);
26814   __Pyx_TraceReturn(__pyx_r);
26815   __Pyx_RefNannyFinishContext();
26816   return __pyx_r;
26817 }
26818
26819 /* "csamtools.pyx":2944
26820  *     property coverage:
26821  *        '''coverage or read depth - the number of reads involved in the call.'''
26822  *        def __get__(self): return self._coverage             # <<<<<<<<<<<<<<
26823  * 
26824  *     def __str__(self):
26825  */
26826
26827 static PyObject *__pyx_pf_9csamtools_7SNPCall_8coverage___get__(PyObject *__pyx_v_self); /*proto*/
26828 static PyObject *__pyx_pf_9csamtools_7SNPCall_8coverage___get__(PyObject *__pyx_v_self) {
26829   PyObject *__pyx_r = NULL;
26830   PyObject *__pyx_t_1 = NULL;
26831   __Pyx_TraceDeclarations
26832   __Pyx_RefNannySetupContext("__get__");
26833   __Pyx_TraceCall("__get__", __pyx_f[0], 2944);
26834   __Pyx_XDECREF(__pyx_r);
26835   __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_9csamtools_SNPCall *)__pyx_v_self)->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26836   __Pyx_GOTREF(__pyx_t_1);
26837   __pyx_r = __pyx_t_1;
26838   __pyx_t_1 = 0;
26839   goto __pyx_L0;
26840
26841   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
26842   goto __pyx_L0;
26843   __pyx_L1_error:;
26844   __Pyx_XDECREF(__pyx_t_1);
26845   __Pyx_AddTraceback("csamtools.SNPCall.coverage.__get__");
26846   __pyx_r = NULL;
26847   __pyx_L0:;
26848   __Pyx_XGIVEREF(__pyx_r);
26849   __Pyx_TraceReturn(__pyx_r);
26850   __Pyx_RefNannyFinishContext();
26851   return __pyx_r;
26852 }
26853
26854 /* "csamtools.pyx":2946
26855  *        def __get__(self): return self._coverage
26856  * 
26857  *     def __str__(self):             # <<<<<<<<<<<<<<
26858  * 
26859  *         return "\t".join( map(str, (
26860  */
26861
26862 static PyObject *__pyx_pf_9csamtools_7SNPCall___str__(PyObject *__pyx_v_self); /*proto*/
26863 static PyObject *__pyx_pf_9csamtools_7SNPCall___str__(PyObject *__pyx_v_self) {
26864   PyObject *__pyx_r = NULL;
26865   PyObject *__pyx_t_1 = NULL;
26866   PyObject *__pyx_t_2 = NULL;
26867   PyObject *__pyx_t_3 = NULL;
26868   PyObject *__pyx_t_4 = NULL;
26869   PyObject *__pyx_t_5 = NULL;
26870   PyObject *__pyx_t_6 = NULL;
26871   PyObject *__pyx_t_7 = NULL;
26872   PyObject *__pyx_t_8 = NULL;
26873   PyObject *__pyx_t_9 = NULL;
26874   PyObject *__pyx_t_10 = NULL;
26875   __Pyx_TraceDeclarations
26876   __Pyx_RefNannySetupContext("__str__");
26877   __Pyx_TraceCall("__str__", __pyx_f[0], 2946);
26878
26879   /* "csamtools.pyx":2948
26880  *     def __str__(self):
26881  * 
26882  *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
26883  *                     self.tid,
26884  *                     self.pos,
26885  */
26886   __Pyx_XDECREF(__pyx_r);
26887   __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_1), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26888   __Pyx_GOTREF(__pyx_t_1);
26889
26890   /* "csamtools.pyx":2949
26891  * 
26892  *         return "\t".join( map(str, (
26893  *                     self.tid,             # <<<<<<<<<<<<<<
26894  *                     self.pos,
26895  *                     self.reference_base,
26896  */
26897   __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26898   __Pyx_GOTREF(__pyx_t_2);
26899
26900   /* "csamtools.pyx":2950
26901  *         return "\t".join( map(str, (
26902  *                     self.tid,
26903  *                     self.pos,             # <<<<<<<<<<<<<<
26904  *                     self.reference_base,
26905  *                     self.genotype,
26906  */
26907   __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26908   __Pyx_GOTREF(__pyx_t_3);
26909
26910   /* "csamtools.pyx":2951
26911  *                     self.tid,
26912  *                     self.pos,
26913  *                     self.reference_base,             # <<<<<<<<<<<<<<
26914  *                     self.genotype,
26915  *                     self.consensus_quality,
26916  */
26917   __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__reference_base); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26918   __Pyx_GOTREF(__pyx_t_4);
26919
26920   /* "csamtools.pyx":2952
26921  *                     self.pos,
26922  *                     self.reference_base,
26923  *                     self.genotype,             # <<<<<<<<<<<<<<
26924  *                     self.consensus_quality,
26925  *                     self.snp_quality,
26926  */
26927   __pyx_t_5 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__genotype); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26928   __Pyx_GOTREF(__pyx_t_5);
26929
26930   /* "csamtools.pyx":2953
26931  *                     self.reference_base,
26932  *                     self.genotype,
26933  *                     self.consensus_quality,             # <<<<<<<<<<<<<<
26934  *                     self.snp_quality,
26935  *                     self.mapping_quality,
26936  */
26937   __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__consensus_quality); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26938   __Pyx_GOTREF(__pyx_t_6);
26939
26940   /* "csamtools.pyx":2954
26941  *                     self.genotype,
26942  *                     self.consensus_quality,
26943  *                     self.snp_quality,             # <<<<<<<<<<<<<<
26944  *                     self.mapping_quality,
26945  *                     self.coverage ) ) )
26946  */
26947   __pyx_t_7 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__snp_quality); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26948   __Pyx_GOTREF(__pyx_t_7);
26949
26950   /* "csamtools.pyx":2955
26951  *                     self.consensus_quality,
26952  *                     self.snp_quality,
26953  *                     self.mapping_quality,             # <<<<<<<<<<<<<<
26954  *                     self.coverage ) ) )
26955  * 
26956  */
26957   __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__mapping_quality); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26958   __Pyx_GOTREF(__pyx_t_8);
26959
26960   /* "csamtools.pyx":2956
26961  *                     self.snp_quality,
26962  *                     self.mapping_quality,
26963  *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
26964  * 
26965  * 
26966  */
26967   __pyx_t_9 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__coverage); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26968   __Pyx_GOTREF(__pyx_t_9);
26969   __pyx_t_10 = PyTuple_New(8); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26970   __Pyx_GOTREF(((PyObject *)__pyx_t_10));
26971   PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
26972   __Pyx_GIVEREF(__pyx_t_2);
26973   PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
26974   __Pyx_GIVEREF(__pyx_t_3);
26975   PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4);
26976   __Pyx_GIVEREF(__pyx_t_4);
26977   PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_5);
26978   __Pyx_GIVEREF(__pyx_t_5);
26979   PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_6);
26980   __Pyx_GIVEREF(__pyx_t_6);
26981   PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_7);
26982   __Pyx_GIVEREF(__pyx_t_7);
26983   PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_8);
26984   __Pyx_GIVEREF(__pyx_t_8);
26985   PyTuple_SET_ITEM(__pyx_t_10, 7, __pyx_t_9);
26986   __Pyx_GIVEREF(__pyx_t_9);
26987   __pyx_t_2 = 0;
26988   __pyx_t_3 = 0;
26989   __pyx_t_4 = 0;
26990   __pyx_t_5 = 0;
26991   __pyx_t_6 = 0;
26992   __pyx_t_7 = 0;
26993   __pyx_t_8 = 0;
26994   __pyx_t_9 = 0;
26995   __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
26996   __Pyx_GOTREF(((PyObject *)__pyx_t_9));
26997   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
26998   PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
26999   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
27000   PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_t_10));
27001   __Pyx_GIVEREF(((PyObject *)__pyx_t_10));
27002   __pyx_t_10 = 0;
27003   __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 = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27004   __Pyx_GOTREF(__pyx_t_10);
27005   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
27006   __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27007   __Pyx_GOTREF(((PyObject *)__pyx_t_9));
27008   PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
27009   __Pyx_GIVEREF(__pyx_t_10);
27010   __pyx_t_10 = 0;
27011   __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 = 2948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27012   __Pyx_GOTREF(__pyx_t_10);
27013   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27014   __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
27015   __pyx_r = __pyx_t_10;
27016   __pyx_t_10 = 0;
27017   goto __pyx_L0;
27018
27019   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27020   goto __pyx_L0;
27021   __pyx_L1_error:;
27022   __Pyx_XDECREF(__pyx_t_1);
27023   __Pyx_XDECREF(__pyx_t_2);
27024   __Pyx_XDECREF(__pyx_t_3);
27025   __Pyx_XDECREF(__pyx_t_4);
27026   __Pyx_XDECREF(__pyx_t_5);
27027   __Pyx_XDECREF(__pyx_t_6);
27028   __Pyx_XDECREF(__pyx_t_7);
27029   __Pyx_XDECREF(__pyx_t_8);
27030   __Pyx_XDECREF(__pyx_t_9);
27031   __Pyx_XDECREF(__pyx_t_10);
27032   __Pyx_AddTraceback("csamtools.SNPCall.__str__");
27033   __pyx_r = NULL;
27034   __pyx_L0:;
27035   __Pyx_XGIVEREF(__pyx_r);
27036   __Pyx_TraceReturn(__pyx_r);
27037   __Pyx_RefNannyFinishContext();
27038   return __pyx_r;
27039 }
27040
27041 /* "csamtools.pyx":3472
27042  *     cdef int owns_samfile
27043  * 
27044  *     def __init__(self, Samfile samfile, int reopen = True ):             # <<<<<<<<<<<<<<
27045  *         self.samfile = samfile
27046  * 
27047  */
27048
27049 static int __pyx_pf_9csamtools_12IndexedReads___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
27050 static int __pyx_pf_9csamtools_12IndexedReads___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
27051   struct __pyx_obj_9csamtools_Samfile *__pyx_v_samfile = 0;
27052   int __pyx_v_reopen;
27053   PyObject *__pyx_v_mode;
27054   PyObject *__pyx_v_store;
27055   int __pyx_r;
27056   PyObject *__pyx_t_1 = NULL;
27057   PyObject *__pyx_t_2 = NULL;
27058   char *__pyx_t_3;
27059   static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__reopen,0};
27060   __Pyx_TraceDeclarations
27061   __Pyx_RefNannySetupContext("__init__");
27062   __Pyx_TraceCall("__init__", __pyx_f[0], 3472);
27063   if (unlikely(__pyx_kwds)) {
27064     Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
27065     PyObject* values[2] = {0,0};
27066     switch (PyTuple_GET_SIZE(__pyx_args)) {
27067       case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
27068       case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
27069       case  0: break;
27070       default: goto __pyx_L5_argtuple_error;
27071     }
27072     switch (PyTuple_GET_SIZE(__pyx_args)) {
27073       case  0:
27074       values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile);
27075       if (likely(values[0])) kw_args--;
27076       else goto __pyx_L5_argtuple_error;
27077       case  1:
27078       if (kw_args > 0) {
27079         PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reopen);
27080         if (value) { values[1] = value; kw_args--; }
27081       }
27082     }
27083     if (unlikely(kw_args > 0)) {
27084       if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
27085     }
27086     __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)values[0]);
27087     if (values[1]) {
27088       __pyx_v_reopen = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
27089     } else {
27090       __pyx_v_reopen = ((int)1);
27091     }
27092   } else {
27093     __pyx_v_reopen = ((int)1);
27094     switch (PyTuple_GET_SIZE(__pyx_args)) {
27095       case  2: __pyx_v_reopen = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_reopen == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
27096       case  1: __pyx_v_samfile = ((struct __pyx_obj_9csamtools_Samfile *)PyTuple_GET_ITEM(__pyx_args, 0));
27097       break;
27098       default: goto __pyx_L5_argtuple_error;
27099     }
27100   }
27101   goto __pyx_L4_argument_unpacking_done;
27102   __pyx_L5_argtuple_error:;
27103   __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
27104   __pyx_L3_error:;
27105   __Pyx_AddTraceback("csamtools.IndexedReads.__init__");
27106   __Pyx_RefNannyFinishContext();
27107   return -1;
27108   __pyx_L4_argument_unpacking_done:;
27109   __pyx_v_mode = Py_None; __Pyx_INCREF(Py_None);
27110   __pyx_v_store = Py_None; __Pyx_INCREF(Py_None);
27111   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27112
27113   /* "csamtools.pyx":3473
27114  * 
27115  *     def __init__(self, Samfile samfile, int reopen = True ):
27116  *         self.samfile = samfile             # <<<<<<<<<<<<<<
27117  * 
27118  *         if samfile.isbam: mode = "rb"
27119  */
27120   __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
27121   __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
27122   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile);
27123   __Pyx_DECREF(((PyObject *)((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile));
27124   ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile = __pyx_v_samfile;
27125
27126   /* "csamtools.pyx":3475
27127  *         self.samfile = samfile
27128  * 
27129  *         if samfile.isbam: mode = "rb"             # <<<<<<<<<<<<<<
27130  *         else: mode = "r"
27131  * 
27132  */
27133   if (__pyx_v_samfile->isbam) {
27134     __Pyx_INCREF(((PyObject *)__pyx_n_s__rb));
27135     __Pyx_DECREF(__pyx_v_mode);
27136     __pyx_v_mode = ((PyObject *)__pyx_n_s__rb);
27137     goto __pyx_L6;
27138   }
27139   /*else*/ {
27140
27141     /* "csamtools.pyx":3476
27142  * 
27143  *         if samfile.isbam: mode = "rb"
27144  *         else: mode = "r"             # <<<<<<<<<<<<<<
27145  * 
27146  *         # reopen the file - note that this makes the iterator
27147  */
27148     __Pyx_INCREF(((PyObject *)__pyx_n_s__r));
27149     __Pyx_DECREF(__pyx_v_mode);
27150     __pyx_v_mode = ((PyObject *)__pyx_n_s__r);
27151   }
27152   __pyx_L6:;
27153
27154   /* "csamtools.pyx":3480
27155  *         # reopen the file - note that this makes the iterator
27156  *         # slow and causes pileup to slow down significantly.
27157  *         if reopen:             # <<<<<<<<<<<<<<
27158  *             store = StderrStore()
27159  *             self.fp = samopen( samfile._filename, mode, NULL )
27160  */
27161   if (__pyx_v_reopen) {
27162
27163     /* "csamtools.pyx":3481
27164  *         # slow and causes pileup to slow down significantly.
27165  *         if reopen:
27166  *             store = StderrStore()             # <<<<<<<<<<<<<<
27167  *             self.fp = samopen( samfile._filename, mode, NULL )
27168  *             store.release()
27169  */
27170     __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStore); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27171     __Pyx_GOTREF(__pyx_t_1);
27172     __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 = 3481; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27173     __Pyx_GOTREF(__pyx_t_2);
27174     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27175     __Pyx_DECREF(__pyx_v_store);
27176     __pyx_v_store = __pyx_t_2;
27177     __pyx_t_2 = 0;
27178
27179     /* "csamtools.pyx":3482
27180  *         if reopen:
27181  *             store = StderrStore()
27182  *             self.fp = samopen( samfile._filename, mode, NULL )             # <<<<<<<<<<<<<<
27183  *             store.release()
27184  *             assert self.fp != NULL
27185  */
27186     __pyx_t_3 = PyBytes_AsString(__pyx_v_mode); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27187     ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp = samopen(__pyx_v_samfile->_filename, __pyx_t_3, NULL);
27188
27189     /* "csamtools.pyx":3483
27190  *             store = StderrStore()
27191  *             self.fp = samopen( samfile._filename, mode, NULL )
27192  *             store.release()             # <<<<<<<<<<<<<<
27193  *             assert self.fp != NULL
27194  *             self.owns_samfile = True
27195  */
27196     __pyx_t_2 = PyObject_GetAttr(__pyx_v_store, __pyx_n_s__release); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27197     __Pyx_GOTREF(__pyx_t_2);
27198     __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 = 3483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27199     __Pyx_GOTREF(__pyx_t_1);
27200     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27201     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27202
27203     /* "csamtools.pyx":3484
27204  *             self.fp = samopen( samfile._filename, mode, NULL )
27205  *             store.release()
27206  *             assert self.fp != NULL             # <<<<<<<<<<<<<<
27207  *             self.owns_samfile = True
27208  *         else:
27209  */
27210     #ifndef CYTHON_WITHOUT_ASSERTIONS
27211     if (unlikely(!(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp != NULL))) {
27212       PyErr_SetNone(PyExc_AssertionError);
27213       {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27214     }
27215     #endif
27216
27217     /* "csamtools.pyx":3485
27218  *             store.release()
27219  *             assert self.fp != NULL
27220  *             self.owns_samfile = True             # <<<<<<<<<<<<<<
27221  *         else:
27222  *             self.fp = samfile.samfile
27223  */
27224     ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->owns_samfile = 1;
27225     goto __pyx_L7;
27226   }
27227   /*else*/ {
27228
27229     /* "csamtools.pyx":3487
27230  *             self.owns_samfile = True
27231  *         else:
27232  *             self.fp = samfile.samfile             # <<<<<<<<<<<<<<
27233  *             self.owns_samfile = False
27234  * 
27235  */
27236     ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp = __pyx_v_samfile->samfile;
27237
27238     /* "csamtools.pyx":3488
27239  *         else:
27240  *             self.fp = samfile.samfile
27241  *             self.owns_samfile = False             # <<<<<<<<<<<<<<
27242  * 
27243  *         assert samfile.isbam, "can only IndexReads on bam files"
27244  */
27245     ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->owns_samfile = 0;
27246   }
27247   __pyx_L7:;
27248
27249   /* "csamtools.pyx":3490
27250  *             self.owns_samfile = False
27251  * 
27252  *         assert samfile.isbam, "can only IndexReads on bam files"             # <<<<<<<<<<<<<<
27253  * 
27254  *     def build( self ):
27255  */
27256   #ifndef CYTHON_WITHOUT_ASSERTIONS
27257   if (unlikely(!__pyx_v_samfile->isbam)) {
27258     PyErr_SetObject(PyExc_AssertionError, ((PyObject *)__pyx_kp_s_167));
27259     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27260   }
27261   #endif
27262
27263   __pyx_r = 0;
27264   goto __pyx_L0;
27265   __pyx_L1_error:;
27266   __Pyx_XDECREF(__pyx_t_1);
27267   __Pyx_XDECREF(__pyx_t_2);
27268   __Pyx_AddTraceback("csamtools.IndexedReads.__init__");
27269   __pyx_r = -1;
27270   __pyx_L0:;
27271   __Pyx_DECREF(__pyx_v_mode);
27272   __Pyx_DECREF(__pyx_v_store);
27273   __Pyx_TraceReturn(Py_None);
27274   __Pyx_RefNannyFinishContext();
27275   return __pyx_r;
27276 }
27277
27278 /* "csamtools.pyx":3492
27279  *         assert samfile.isbam, "can only IndexReads on bam files"
27280  * 
27281  *     def build( self ):             # <<<<<<<<<<<<<<
27282  *         '''build index.'''
27283  * 
27284  */
27285
27286 static PyObject *__pyx_pf_9csamtools_12IndexedReads_1build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
27287 static char __pyx_doc_9csamtools_12IndexedReads_1build[] = "IndexedReads.build(self)\nbuild index.";
27288 static PyObject *__pyx_pf_9csamtools_12IndexedReads_1build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
27289   int __pyx_v_ret;
27290   bam1_t *__pyx_v_b;
27291   uint64_t __pyx_v_pos;
27292   char *__pyx_v_qname;
27293   PyObject *__pyx_r = NULL;
27294   PyObject *__pyx_t_1 = NULL;
27295   PyObject *__pyx_t_2 = NULL;
27296   PyObject *__pyx_t_3 = NULL;
27297   int __pyx_t_4;
27298   __Pyx_TraceDeclarations
27299   __Pyx_RefNannySetupContext("build");
27300   __Pyx_TraceCall("build", __pyx_f[0], 3492);
27301
27302   /* "csamtools.pyx":3495
27303  *         '''build index.'''
27304  * 
27305  *         self.index = collections.defaultdict( list )             # <<<<<<<<<<<<<<
27306  * 
27307  *         # this method will start indexing from the current file position
27308  */
27309   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__collections); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27310   __Pyx_GOTREF(__pyx_t_1);
27311   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__defaultdict); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27312   __Pyx_GOTREF(__pyx_t_2);
27313   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27314   __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27315   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
27316   __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
27317   PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)(&PyList_Type))));
27318   __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
27319   __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 = 3495; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27320   __Pyx_GOTREF(__pyx_t_3);
27321   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27322   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
27323   __Pyx_GIVEREF(__pyx_t_3);
27324   __Pyx_GOTREF(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index);
27325   __Pyx_DECREF(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index);
27326   ((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index = __pyx_t_3;
27327   __pyx_t_3 = 0;
27328
27329   /* "csamtools.pyx":3499
27330  *         # this method will start indexing from the current file position
27331  *         # if you decide
27332  *         cdef int ret = 1             # <<<<<<<<<<<<<<
27333  *         cdef bam1_t * b = <bam1_t*> calloc(1, sizeof( bam1_t) )
27334  * 
27335  */
27336   __pyx_v_ret = 1;
27337
27338   /* "csamtools.pyx":3500
27339  *         # if you decide
27340  *         cdef int ret = 1
27341  *         cdef bam1_t * b = <bam1_t*> calloc(1, sizeof( bam1_t) )             # <<<<<<<<<<<<<<
27342  * 
27343  *         cdef uint64_t pos
27344  */
27345   __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));
27346
27347   /* "csamtools.pyx":3504
27348  *         cdef uint64_t pos
27349  * 
27350  *         while ret > 0:             # <<<<<<<<<<<<<<
27351  *             pos = bam_tell( self.fp.x.bam )
27352  *             ret = samread( self.fp, b)
27353  */
27354   while (1) {
27355     __pyx_t_4 = (__pyx_v_ret > 0);
27356     if (!__pyx_t_4) break;
27357
27358     /* "csamtools.pyx":3505
27359  * 
27360  *         while ret > 0:
27361  *             pos = bam_tell( self.fp.x.bam )             # <<<<<<<<<<<<<<
27362  *             ret = samread( self.fp, b)
27363  *             if ret > 0:
27364  */
27365     __pyx_v_pos = bam_tell(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp->x.bam);
27366
27367     /* "csamtools.pyx":3506
27368  *         while ret > 0:
27369  *             pos = bam_tell( self.fp.x.bam )
27370  *             ret = samread( self.fp, b)             # <<<<<<<<<<<<<<
27371  *             if ret > 0:
27372  *                 qname = bam1_qname( b )
27373  */
27374     __pyx_v_ret = samread(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp, __pyx_v_b);
27375
27376     /* "csamtools.pyx":3507
27377  *             pos = bam_tell( self.fp.x.bam )
27378  *             ret = samread( self.fp, b)
27379  *             if ret > 0:             # <<<<<<<<<<<<<<
27380  *                 qname = bam1_qname( b )
27381  *                 self.index[qname].append( pos )
27382  */
27383     __pyx_t_4 = (__pyx_v_ret > 0);
27384     if (__pyx_t_4) {
27385
27386       /* "csamtools.pyx":3508
27387  *             ret = samread( self.fp, b)
27388  *             if ret > 0:
27389  *                 qname = bam1_qname( b )             # <<<<<<<<<<<<<<
27390  *                 self.index[qname].append( pos )
27391  * 
27392  */
27393       __pyx_v_qname = bam1_qname(__pyx_v_b);
27394
27395       /* "csamtools.pyx":3509
27396  *             if ret > 0:
27397  *                 qname = bam1_qname( b )
27398  *                 self.index[qname].append( pos )             # <<<<<<<<<<<<<<
27399  * 
27400  *         bam_destroy1( b )
27401  */
27402       __pyx_t_3 = PyBytes_FromString(__pyx_v_qname); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27403       __Pyx_GOTREF(((PyObject *)__pyx_t_3));
27404       __pyx_t_1 = PyObject_GetItem(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index, ((PyObject *)__pyx_t_3)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27405       __Pyx_GOTREF(__pyx_t_1);
27406       __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
27407       __pyx_t_3 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27408       __Pyx_GOTREF(__pyx_t_3);
27409       __pyx_t_2 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3509; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27410       __Pyx_GOTREF(__pyx_t_2);
27411       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
27412       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
27413       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
27414       goto __pyx_L7;
27415     }
27416     __pyx_L7:;
27417   }
27418
27419   /* "csamtools.pyx":3511
27420  *                 self.index[qname].append( pos )
27421  * 
27422  *         bam_destroy1( b )             # <<<<<<<<<<<<<<
27423  * 
27424  *     def find( self, qname ):
27425  */
27426   bam_destroy1(__pyx_v_b);
27427
27428   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27429   goto __pyx_L0;
27430   __pyx_L1_error:;
27431   __Pyx_XDECREF(__pyx_t_1);
27432   __Pyx_XDECREF(__pyx_t_2);
27433   __Pyx_XDECREF(__pyx_t_3);
27434   __Pyx_AddTraceback("csamtools.IndexedReads.build");
27435   __pyx_r = NULL;
27436   __pyx_L0:;
27437   __Pyx_XGIVEREF(__pyx_r);
27438   __Pyx_TraceReturn(__pyx_r);
27439   __Pyx_RefNannyFinishContext();
27440   return __pyx_r;
27441 }
27442
27443 /* "csamtools.pyx":3513
27444  *         bam_destroy1( b )
27445  * 
27446  *     def find( self, qname ):             # <<<<<<<<<<<<<<
27447  *         if qname in self.index:
27448  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
27449  */
27450
27451 static PyObject *__pyx_pf_9csamtools_12IndexedReads_2find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
27452 static char __pyx_doc_9csamtools_12IndexedReads_2find[] = "IndexedReads.find(self, qname)";
27453 static PyObject *__pyx_pf_9csamtools_12IndexedReads_2find(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
27454   PyObject *__pyx_r = NULL;
27455   int __pyx_t_1;
27456   PyObject *__pyx_t_2 = NULL;
27457   PyObject *__pyx_t_3 = NULL;
27458   PyObject *__pyx_t_4 = NULL;
27459   __Pyx_TraceDeclarations
27460   __Pyx_RefNannySetupContext("find");
27461   __Pyx_TraceCall("find", __pyx_f[0], 3513);
27462
27463   /* "csamtools.pyx":3514
27464  * 
27465  *     def find( self, qname ):
27466  *         if qname in self.index:             # <<<<<<<<<<<<<<
27467  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
27468  *         else:
27469  */
27470   __pyx_t_1 = ((PySequence_Contains(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index, __pyx_v_qname))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27471   if (__pyx_t_1) {
27472
27473     /* "csamtools.pyx":3515
27474  *     def find( self, qname ):
27475  *         if qname in self.index:
27476  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )             # <<<<<<<<<<<<<<
27477  *         else:
27478  *             raise KeyError( "read %s not found" % qname )
27479  */
27480     __Pyx_XDECREF(__pyx_r);
27481     __pyx_t_2 = PyObject_GetItem(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->index, __pyx_v_qname); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27482     __Pyx_GOTREF(__pyx_t_2);
27483     __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27484     __Pyx_GOTREF(((PyObject *)__pyx_t_3));
27485     __Pyx_INCREF(((PyObject *)((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile));
27486     PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile));
27487     __Pyx_GIVEREF(((PyObject *)((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->samfile));
27488     PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
27489     __Pyx_GIVEREF(__pyx_t_2);
27490     __pyx_t_2 = 0;
27491     __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27492     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
27493     __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27494     __Pyx_GOTREF(__pyx_t_4);
27495     if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reopen), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27496     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
27497     __pyx_t_4 = PyEval_CallObjectWithKeywords(((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 = 3515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27498     __Pyx_GOTREF(__pyx_t_4);
27499     __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
27500     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
27501     __pyx_r = __pyx_t_4;
27502     __pyx_t_4 = 0;
27503     goto __pyx_L0;
27504     goto __pyx_L5;
27505   }
27506   /*else*/ {
27507
27508     /* "csamtools.pyx":3517
27509  *             return IteratorRowSelection( self.samfile, self.index[qname], reopen = False )
27510  *         else:
27511  *             raise KeyError( "read %s not found" % qname )             # <<<<<<<<<<<<<<
27512  * 
27513  *     def __dealloc__(self):
27514  */
27515     __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_168), __pyx_v_qname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27516     __Pyx_GOTREF(((PyObject *)__pyx_t_4));
27517     __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27518     __Pyx_GOTREF(((PyObject *)__pyx_t_2));
27519     PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_4));
27520     __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
27521     __pyx_t_4 = 0;
27522     __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 = 3517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27523     __Pyx_GOTREF(__pyx_t_4);
27524     __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
27525     __Pyx_Raise(__pyx_t_4, 0, 0);
27526     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
27527     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
27528   }
27529   __pyx_L5:;
27530
27531   __pyx_r = Py_None; __Pyx_INCREF(Py_None);
27532   goto __pyx_L0;
27533   __pyx_L1_error:;
27534   __Pyx_XDECREF(__pyx_t_2);
27535   __Pyx_XDECREF(__pyx_t_3);
27536   __Pyx_XDECREF(__pyx_t_4);
27537   __Pyx_AddTraceback("csamtools.IndexedReads.find");
27538   __pyx_r = NULL;
27539   __pyx_L0:;
27540   __Pyx_XGIVEREF(__pyx_r);
27541   __Pyx_TraceReturn(__pyx_r);
27542   __Pyx_RefNannyFinishContext();
27543   return __pyx_r;
27544 }
27545
27546 /* "csamtools.pyx":3519
27547  *             raise KeyError( "read %s not found" % qname )
27548  * 
27549  *     def __dealloc__(self):             # <<<<<<<<<<<<<<
27550  *         if self.owns_samfile: samclose( self.fp )
27551  * 
27552  */
27553
27554 static void __pyx_pf_9csamtools_12IndexedReads_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
27555 static void __pyx_pf_9csamtools_12IndexedReads_3__dealloc__(PyObject *__pyx_v_self) {
27556   __Pyx_TraceDeclarations
27557   __Pyx_RefNannySetupContext("__dealloc__");
27558   __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3519);
27559
27560   /* "csamtools.pyx":3520
27561  * 
27562  *     def __dealloc__(self):
27563  *         if self.owns_samfile: samclose( self.fp )             # <<<<<<<<<<<<<<
27564  * 
27565  * __all__ = ["Samfile",
27566  */
27567   if (((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->owns_samfile) {
27568     samclose(((struct __pyx_obj_9csamtools_IndexedReads *)__pyx_v_self)->fp);
27569     goto __pyx_L5;
27570   }
27571   __pyx_L5:;
27572
27573   __Pyx_TraceReturn(Py_None);
27574   __Pyx_RefNannyFinishContext();
27575 }
27576
27577 static PyObject *__pyx_tp_new_9csamtools_AlignedRead(PyTypeObject *t, PyObject *a, PyObject *k) {
27578   PyObject *o = (*t->tp_alloc)(t, 0);
27579   if (!o) return 0;
27580   return o;
27581 }
27582
27583 static void __pyx_tp_dealloc_9csamtools_AlignedRead(PyObject *o) {
27584   {
27585     PyObject *etype, *eval, *etb;
27586     PyErr_Fetch(&etype, &eval, &etb);
27587     ++Py_REFCNT(o);
27588     __pyx_pf_9csamtools_11AlignedRead_1__dealloc__(o);
27589     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
27590     --Py_REFCNT(o);
27591     PyErr_Restore(etype, eval, etb);
27592   }
27593   (*Py_TYPE(o)->tp_free)(o);
27594 }
27595
27596 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qname(PyObject *o, void *x) {
27597   return __pyx_pf_9csamtools_11AlignedRead_5qname___get__(o);
27598 }
27599
27600 static int __pyx_setprop_9csamtools_11AlignedRead_qname(PyObject *o, PyObject *v, void *x) {
27601   if (v) {
27602     return __pyx_pf_9csamtools_11AlignedRead_5qname_1__set__(o, v);
27603   }
27604   else {
27605     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27606     return -1;
27607   }
27608 }
27609
27610 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_cigar(PyObject *o, void *x) {
27611   return __pyx_pf_9csamtools_11AlignedRead_5cigar___get__(o);
27612 }
27613
27614 static int __pyx_setprop_9csamtools_11AlignedRead_cigar(PyObject *o, PyObject *v, void *x) {
27615   if (v) {
27616     return __pyx_pf_9csamtools_11AlignedRead_5cigar_1__set__(o, v);
27617   }
27618   else {
27619     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27620     return -1;
27621   }
27622 }
27623
27624 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_seq(PyObject *o, void *x) {
27625   return __pyx_pf_9csamtools_11AlignedRead_3seq___get__(o);
27626 }
27627
27628 static int __pyx_setprop_9csamtools_11AlignedRead_seq(PyObject *o, PyObject *v, void *x) {
27629   if (v) {
27630     return __pyx_pf_9csamtools_11AlignedRead_3seq_1__set__(o, v);
27631   }
27632   else {
27633     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27634     return -1;
27635   }
27636 }
27637
27638 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qual(PyObject *o, void *x) {
27639   return __pyx_pf_9csamtools_11AlignedRead_4qual___get__(o);
27640 }
27641
27642 static int __pyx_setprop_9csamtools_11AlignedRead_qual(PyObject *o, PyObject *v, void *x) {
27643   if (v) {
27644     return __pyx_pf_9csamtools_11AlignedRead_4qual_1__set__(o, v);
27645   }
27646   else {
27647     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27648     return -1;
27649   }
27650 }
27651
27652 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_query(PyObject *o, void *x) {
27653   return __pyx_pf_9csamtools_11AlignedRead_5query___get__(o);
27654 }
27655
27656 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qqual(PyObject *o, void *x) {
27657   return __pyx_pf_9csamtools_11AlignedRead_5qqual___get__(o);
27658 }
27659
27660 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qstart(PyObject *o, void *x) {
27661   return __pyx_pf_9csamtools_11AlignedRead_6qstart___get__(o);
27662 }
27663
27664 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qend(PyObject *o, void *x) {
27665   return __pyx_pf_9csamtools_11AlignedRead_4qend___get__(o);
27666 }
27667
27668 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_qlen(PyObject *o, void *x) {
27669   return __pyx_pf_9csamtools_11AlignedRead_4qlen___get__(o);
27670 }
27671
27672 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tags(PyObject *o, void *x) {
27673   return __pyx_pf_9csamtools_11AlignedRead_4tags___get__(o);
27674 }
27675
27676 static int __pyx_setprop_9csamtools_11AlignedRead_tags(PyObject *o, PyObject *v, void *x) {
27677   if (v) {
27678     return __pyx_pf_9csamtools_11AlignedRead_4tags_1__set__(o, v);
27679   }
27680   else {
27681     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27682     return -1;
27683   }
27684 }
27685
27686 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_flag(PyObject *o, void *x) {
27687   return __pyx_pf_9csamtools_11AlignedRead_4flag___get__(o);
27688 }
27689
27690 static int __pyx_setprop_9csamtools_11AlignedRead_flag(PyObject *o, PyObject *v, void *x) {
27691   if (v) {
27692     return __pyx_pf_9csamtools_11AlignedRead_4flag_1__set__(o, v);
27693   }
27694   else {
27695     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27696     return -1;
27697   }
27698 }
27699
27700 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rname(PyObject *o, void *x) {
27701   return __pyx_pf_9csamtools_11AlignedRead_5rname___get__(o);
27702 }
27703
27704 static int __pyx_setprop_9csamtools_11AlignedRead_rname(PyObject *o, PyObject *v, void *x) {
27705   if (v) {
27706     return __pyx_pf_9csamtools_11AlignedRead_5rname_1__set__(o, v);
27707   }
27708   else {
27709     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27710     return -1;
27711   }
27712 }
27713
27714 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tid(PyObject *o, void *x) {
27715   return __pyx_pf_9csamtools_11AlignedRead_3tid___get__(o);
27716 }
27717
27718 static int __pyx_setprop_9csamtools_11AlignedRead_tid(PyObject *o, PyObject *v, void *x) {
27719   if (v) {
27720     return __pyx_pf_9csamtools_11AlignedRead_3tid_1__set__(o, v);
27721   }
27722   else {
27723     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27724     return -1;
27725   }
27726 }
27727
27728 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_pos(PyObject *o, void *x) {
27729   return __pyx_pf_9csamtools_11AlignedRead_3pos___get__(o);
27730 }
27731
27732 static int __pyx_setprop_9csamtools_11AlignedRead_pos(PyObject *o, PyObject *v, void *x) {
27733   if (v) {
27734     return __pyx_pf_9csamtools_11AlignedRead_3pos_1__set__(o, v);
27735   }
27736   else {
27737     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27738     return -1;
27739   }
27740 }
27741
27742 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_bin(PyObject *o, void *x) {
27743   return __pyx_pf_9csamtools_11AlignedRead_3bin___get__(o);
27744 }
27745
27746 static int __pyx_setprop_9csamtools_11AlignedRead_bin(PyObject *o, PyObject *v, void *x) {
27747   if (v) {
27748     return __pyx_pf_9csamtools_11AlignedRead_3bin_1__set__(o, v);
27749   }
27750   else {
27751     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27752     return -1;
27753   }
27754 }
27755
27756 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rlen(PyObject *o, void *x) {
27757   return __pyx_pf_9csamtools_11AlignedRead_4rlen___get__(o);
27758 }
27759
27760 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_aend(PyObject *o, void *x) {
27761   return __pyx_pf_9csamtools_11AlignedRead_4aend___get__(o);
27762 }
27763
27764 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_alen(PyObject *o, void *x) {
27765   return __pyx_pf_9csamtools_11AlignedRead_4alen___get__(o);
27766 }
27767
27768 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mapq(PyObject *o, void *x) {
27769   return __pyx_pf_9csamtools_11AlignedRead_4mapq___get__(o);
27770 }
27771
27772 static int __pyx_setprop_9csamtools_11AlignedRead_mapq(PyObject *o, PyObject *v, void *x) {
27773   if (v) {
27774     return __pyx_pf_9csamtools_11AlignedRead_4mapq_1__set__(o, v);
27775   }
27776   else {
27777     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27778     return -1;
27779   }
27780 }
27781
27782 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mrnm(PyObject *o, void *x) {
27783   return __pyx_pf_9csamtools_11AlignedRead_4mrnm___get__(o);
27784 }
27785
27786 static int __pyx_setprop_9csamtools_11AlignedRead_mrnm(PyObject *o, PyObject *v, void *x) {
27787   if (v) {
27788     return __pyx_pf_9csamtools_11AlignedRead_4mrnm_1__set__(o, v);
27789   }
27790   else {
27791     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27792     return -1;
27793   }
27794 }
27795
27796 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_rnext(PyObject *o, void *x) {
27797   return __pyx_pf_9csamtools_11AlignedRead_5rnext___get__(o);
27798 }
27799
27800 static int __pyx_setprop_9csamtools_11AlignedRead_rnext(PyObject *o, PyObject *v, void *x) {
27801   if (v) {
27802     return __pyx_pf_9csamtools_11AlignedRead_5rnext_1__set__(o, v);
27803   }
27804   else {
27805     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27806     return -1;
27807   }
27808 }
27809
27810 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mpos(PyObject *o, void *x) {
27811   return __pyx_pf_9csamtools_11AlignedRead_4mpos___get__(o);
27812 }
27813
27814 static int __pyx_setprop_9csamtools_11AlignedRead_mpos(PyObject *o, PyObject *v, void *x) {
27815   if (v) {
27816     return __pyx_pf_9csamtools_11AlignedRead_4mpos_1__set__(o, v);
27817   }
27818   else {
27819     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27820     return -1;
27821   }
27822 }
27823
27824 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_pnext(PyObject *o, void *x) {
27825   return __pyx_pf_9csamtools_11AlignedRead_5pnext___get__(o);
27826 }
27827
27828 static int __pyx_setprop_9csamtools_11AlignedRead_pnext(PyObject *o, PyObject *v, void *x) {
27829   if (v) {
27830     return __pyx_pf_9csamtools_11AlignedRead_5pnext_1__set__(o, v);
27831   }
27832   else {
27833     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27834     return -1;
27835   }
27836 }
27837
27838 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_isize(PyObject *o, void *x) {
27839   return __pyx_pf_9csamtools_11AlignedRead_5isize___get__(o);
27840 }
27841
27842 static int __pyx_setprop_9csamtools_11AlignedRead_isize(PyObject *o, PyObject *v, void *x) {
27843   if (v) {
27844     return __pyx_pf_9csamtools_11AlignedRead_5isize_1__set__(o, v);
27845   }
27846   else {
27847     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27848     return -1;
27849   }
27850 }
27851
27852 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_tlen(PyObject *o, void *x) {
27853   return __pyx_pf_9csamtools_11AlignedRead_4tlen___get__(o);
27854 }
27855
27856 static int __pyx_setprop_9csamtools_11AlignedRead_tlen(PyObject *o, PyObject *v, void *x) {
27857   if (v) {
27858     return __pyx_pf_9csamtools_11AlignedRead_4tlen_1__set__(o, v);
27859   }
27860   else {
27861     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27862     return -1;
27863   }
27864 }
27865
27866 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_paired(PyObject *o, void *x) {
27867   return __pyx_pf_9csamtools_11AlignedRead_9is_paired___get__(o);
27868 }
27869
27870 static int __pyx_setprop_9csamtools_11AlignedRead_is_paired(PyObject *o, PyObject *v, void *x) {
27871   if (v) {
27872     return __pyx_pf_9csamtools_11AlignedRead_9is_paired_1__set__(o, v);
27873   }
27874   else {
27875     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27876     return -1;
27877   }
27878 }
27879
27880 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, void *x) {
27881   return __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair___get__(o);
27882 }
27883
27884 static int __pyx_setprop_9csamtools_11AlignedRead_is_proper_pair(PyObject *o, PyObject *v, void *x) {
27885   if (v) {
27886     return __pyx_pf_9csamtools_11AlignedRead_14is_proper_pair_1__set__(o, v);
27887   }
27888   else {
27889     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27890     return -1;
27891   }
27892 }
27893
27894 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_unmapped(PyObject *o, void *x) {
27895   return __pyx_pf_9csamtools_11AlignedRead_11is_unmapped___get__(o);
27896 }
27897
27898 static int __pyx_setprop_9csamtools_11AlignedRead_is_unmapped(PyObject *o, PyObject *v, void *x) {
27899   if (v) {
27900     return __pyx_pf_9csamtools_11AlignedRead_11is_unmapped_1__set__(o, v);
27901   }
27902   else {
27903     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27904     return -1;
27905   }
27906 }
27907
27908 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, void *x) {
27909   return __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped___get__(o);
27910 }
27911
27912 static int __pyx_setprop_9csamtools_11AlignedRead_mate_is_unmapped(PyObject *o, PyObject *v, void *x) {
27913   if (v) {
27914     return __pyx_pf_9csamtools_11AlignedRead_16mate_is_unmapped_1__set__(o, v);
27915   }
27916   else {
27917     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27918     return -1;
27919   }
27920 }
27921
27922 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_reverse(PyObject *o, void *x) {
27923   return __pyx_pf_9csamtools_11AlignedRead_10is_reverse___get__(o);
27924 }
27925
27926 static int __pyx_setprop_9csamtools_11AlignedRead_is_reverse(PyObject *o, PyObject *v, void *x) {
27927   if (v) {
27928     return __pyx_pf_9csamtools_11AlignedRead_10is_reverse_1__set__(o, v);
27929   }
27930   else {
27931     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27932     return -1;
27933   }
27934 }
27935
27936 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, void *x) {
27937   return __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse___get__(o);
27938 }
27939
27940 static int __pyx_setprop_9csamtools_11AlignedRead_mate_is_reverse(PyObject *o, PyObject *v, void *x) {
27941   if (v) {
27942     return __pyx_pf_9csamtools_11AlignedRead_15mate_is_reverse_1__set__(o, v);
27943   }
27944   else {
27945     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27946     return -1;
27947   }
27948 }
27949
27950 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_read1(PyObject *o, void *x) {
27951   return __pyx_pf_9csamtools_11AlignedRead_8is_read1___get__(o);
27952 }
27953
27954 static int __pyx_setprop_9csamtools_11AlignedRead_is_read1(PyObject *o, PyObject *v, void *x) {
27955   if (v) {
27956     return __pyx_pf_9csamtools_11AlignedRead_8is_read1_1__set__(o, v);
27957   }
27958   else {
27959     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27960     return -1;
27961   }
27962 }
27963
27964 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_read2(PyObject *o, void *x) {
27965   return __pyx_pf_9csamtools_11AlignedRead_8is_read2___get__(o);
27966 }
27967
27968 static int __pyx_setprop_9csamtools_11AlignedRead_is_read2(PyObject *o, PyObject *v, void *x) {
27969   if (v) {
27970     return __pyx_pf_9csamtools_11AlignedRead_8is_read2_1__set__(o, v);
27971   }
27972   else {
27973     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27974     return -1;
27975   }
27976 }
27977
27978 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_secondary(PyObject *o, void *x) {
27979   return __pyx_pf_9csamtools_11AlignedRead_12is_secondary___get__(o);
27980 }
27981
27982 static int __pyx_setprop_9csamtools_11AlignedRead_is_secondary(PyObject *o, PyObject *v, void *x) {
27983   if (v) {
27984     return __pyx_pf_9csamtools_11AlignedRead_12is_secondary_1__set__(o, v);
27985   }
27986   else {
27987     PyErr_SetString(PyExc_NotImplementedError, "__del__");
27988     return -1;
27989   }
27990 }
27991
27992 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_qcfail(PyObject *o, void *x) {
27993   return __pyx_pf_9csamtools_11AlignedRead_9is_qcfail___get__(o);
27994 }
27995
27996 static int __pyx_setprop_9csamtools_11AlignedRead_is_qcfail(PyObject *o, PyObject *v, void *x) {
27997   if (v) {
27998     return __pyx_pf_9csamtools_11AlignedRead_9is_qcfail_1__set__(o, v);
27999   }
28000   else {
28001     PyErr_SetString(PyExc_NotImplementedError, "__del__");
28002     return -1;
28003   }
28004 }
28005
28006 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_is_duplicate(PyObject *o, void *x) {
28007   return __pyx_pf_9csamtools_11AlignedRead_12is_duplicate___get__(o);
28008 }
28009
28010 static int __pyx_setprop_9csamtools_11AlignedRead_is_duplicate(PyObject *o, PyObject *v, void *x) {
28011   if (v) {
28012     return __pyx_pf_9csamtools_11AlignedRead_12is_duplicate_1__set__(o, v);
28013   }
28014   else {
28015     PyErr_SetString(PyExc_NotImplementedError, "__del__");
28016     return -1;
28017   }
28018 }
28019
28020 static PyObject *__pyx_getprop_9csamtools_11AlignedRead_positions(PyObject *o, void *x) {
28021   return __pyx_pf_9csamtools_11AlignedRead_9positions___get__(o);
28022 }
28023
28024 static PyMethodDef __pyx_methods_9csamtools_AlignedRead[] = {
28025   {__Pyx_NAMESTR("compare"), (PyCFunction)__pyx_pf_9csamtools_11AlignedRead_3compare, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_3compare)},
28026   {__Pyx_NAMESTR("overlap"), (PyCFunction)__pyx_pf_9csamtools_11AlignedRead_5overlap, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_5overlap)},
28027   {__Pyx_NAMESTR("opt"), (PyCFunction)__pyx_pf_9csamtools_11AlignedRead_6opt, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_6opt)},
28028   {__Pyx_NAMESTR("fancy_str"), (PyCFunction)__pyx_pf_9csamtools_11AlignedRead_7fancy_str, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_11AlignedRead_7fancy_str)},
28029   {0, 0, 0, 0}
28030 };
28031
28032 static struct PyGetSetDef __pyx_getsets_9csamtools_AlignedRead[] = {
28033   {(char *)"qname", __pyx_getprop_9csamtools_11AlignedRead_qname, __pyx_setprop_9csamtools_11AlignedRead_qname, __Pyx_DOCSTR(__pyx_k_169), 0},
28034   {(char *)"cigar", __pyx_getprop_9csamtools_11AlignedRead_cigar, __pyx_setprop_9csamtools_11AlignedRead_cigar, __Pyx_DOCSTR(__pyx_k_170), 0},
28035   {(char *)"seq", __pyx_getprop_9csamtools_11AlignedRead_seq, __pyx_setprop_9csamtools_11AlignedRead_seq, __Pyx_DOCSTR(__pyx_k_171), 0},
28036   {(char *)"qual", __pyx_getprop_9csamtools_11AlignedRead_qual, __pyx_setprop_9csamtools_11AlignedRead_qual, __Pyx_DOCSTR(__pyx_k_172), 0},
28037   {(char *)"query", __pyx_getprop_9csamtools_11AlignedRead_query, 0, __Pyx_DOCSTR(__pyx_k_173), 0},
28038   {(char *)"qqual", __pyx_getprop_9csamtools_11AlignedRead_qqual, 0, __Pyx_DOCSTR(__pyx_k_174), 0},
28039   {(char *)"qstart", __pyx_getprop_9csamtools_11AlignedRead_qstart, 0, __Pyx_DOCSTR(__pyx_k_175), 0},
28040   {(char *)"qend", __pyx_getprop_9csamtools_11AlignedRead_qend, 0, __Pyx_DOCSTR(__pyx_k_176), 0},
28041   {(char *)"qlen", __pyx_getprop_9csamtools_11AlignedRead_qlen, 0, __Pyx_DOCSTR(__pyx_k_177), 0},
28042   {(char *)"tags", __pyx_getprop_9csamtools_11AlignedRead_tags, __pyx_setprop_9csamtools_11AlignedRead_tags, __Pyx_DOCSTR(__pyx_k_178), 0},
28043   {(char *)"flag", __pyx_getprop_9csamtools_11AlignedRead_flag, __pyx_setprop_9csamtools_11AlignedRead_flag, __Pyx_DOCSTR(__pyx_k_179), 0},
28044   {(char *)"rname", __pyx_getprop_9csamtools_11AlignedRead_rname, __pyx_setprop_9csamtools_11AlignedRead_rname, __Pyx_DOCSTR(__pyx_k_180), 0},
28045   {(char *)"tid", __pyx_getprop_9csamtools_11AlignedRead_tid, __pyx_setprop_9csamtools_11AlignedRead_tid, __Pyx_DOCSTR(__pyx_k_181), 0},
28046   {(char *)"pos", __pyx_getprop_9csamtools_11AlignedRead_pos, __pyx_setprop_9csamtools_11AlignedRead_pos, __Pyx_DOCSTR(__pyx_k_182), 0},
28047   {(char *)"bin", __pyx_getprop_9csamtools_11AlignedRead_bin, __pyx_setprop_9csamtools_11AlignedRead_bin, __Pyx_DOCSTR(__pyx_k_183), 0},
28048   {(char *)"rlen", __pyx_getprop_9csamtools_11AlignedRead_rlen, 0, __Pyx_DOCSTR(__pyx_k_184), 0},
28049   {(char *)"aend", __pyx_getprop_9csamtools_11AlignedRead_aend, 0, __Pyx_DOCSTR(__pyx_k_185), 0},
28050   {(char *)"alen", __pyx_getprop_9csamtools_11AlignedRead_alen, 0, __Pyx_DOCSTR(__pyx_k_186), 0},
28051   {(char *)"mapq", __pyx_getprop_9csamtools_11AlignedRead_mapq, __pyx_setprop_9csamtools_11AlignedRead_mapq, __Pyx_DOCSTR(__pyx_k_187), 0},
28052   {(char *)"mrnm", __pyx_getprop_9csamtools_11AlignedRead_mrnm, __pyx_setprop_9csamtools_11AlignedRead_mrnm, __Pyx_DOCSTR(__pyx_k_188), 0},
28053   {(char *)"rnext", __pyx_getprop_9csamtools_11AlignedRead_rnext, __pyx_setprop_9csamtools_11AlignedRead_rnext, __Pyx_DOCSTR(__pyx_k_189), 0},
28054   {(char *)"mpos", __pyx_getprop_9csamtools_11AlignedRead_mpos, __pyx_setprop_9csamtools_11AlignedRead_mpos, __Pyx_DOCSTR(__pyx_k_190), 0},
28055   {(char *)"pnext", __pyx_getprop_9csamtools_11AlignedRead_pnext, __pyx_setprop_9csamtools_11AlignedRead_pnext, __Pyx_DOCSTR(__pyx_k_191), 0},
28056   {(char *)"isize", __pyx_getprop_9csamtools_11AlignedRead_isize, __pyx_setprop_9csamtools_11AlignedRead_isize, __Pyx_DOCSTR(__pyx_k_192), 0},
28057   {(char *)"tlen", __pyx_getprop_9csamtools_11AlignedRead_tlen, __pyx_setprop_9csamtools_11AlignedRead_tlen, __Pyx_DOCSTR(__pyx_k_193), 0},
28058   {(char *)"is_paired", __pyx_getprop_9csamtools_11AlignedRead_is_paired, __pyx_setprop_9csamtools_11AlignedRead_is_paired, __Pyx_DOCSTR(__pyx_k_194), 0},
28059   {(char *)"is_proper_pair", __pyx_getprop_9csamtools_11AlignedRead_is_proper_pair, __pyx_setprop_9csamtools_11AlignedRead_is_proper_pair, __Pyx_DOCSTR(__pyx_k_195), 0},
28060   {(char *)"is_unmapped", __pyx_getprop_9csamtools_11AlignedRead_is_unmapped, __pyx_setprop_9csamtools_11AlignedRead_is_unmapped, __Pyx_DOCSTR(__pyx_k_196), 0},
28061   {(char *)"mate_is_unmapped", __pyx_getprop_9csamtools_11AlignedRead_mate_is_unmapped, __pyx_setprop_9csamtools_11AlignedRead_mate_is_unmapped, __Pyx_DOCSTR(__pyx_k_197), 0},
28062   {(char *)"is_reverse", __pyx_getprop_9csamtools_11AlignedRead_is_reverse, __pyx_setprop_9csamtools_11AlignedRead_is_reverse, __Pyx_DOCSTR(__pyx_k_198), 0},
28063   {(char *)"mate_is_reverse", __pyx_getprop_9csamtools_11AlignedRead_mate_is_reverse, __pyx_setprop_9csamtools_11AlignedRead_mate_is_reverse, __Pyx_DOCSTR(__pyx_k_199), 0},
28064   {(char *)"is_read1", __pyx_getprop_9csamtools_11AlignedRead_is_read1, __pyx_setprop_9csamtools_11AlignedRead_is_read1, __Pyx_DOCSTR(__pyx_k_200), 0},
28065   {(char *)"is_read2", __pyx_getprop_9csamtools_11AlignedRead_is_read2, __pyx_setprop_9csamtools_11AlignedRead_is_read2, __Pyx_DOCSTR(__pyx_k_201), 0},
28066   {(char *)"is_secondary", __pyx_getprop_9csamtools_11AlignedRead_is_secondary, __pyx_setprop_9csamtools_11AlignedRead_is_secondary, __Pyx_DOCSTR(__pyx_k_202), 0},
28067   {(char *)"is_qcfail", __pyx_getprop_9csamtools_11AlignedRead_is_qcfail, __pyx_setprop_9csamtools_11AlignedRead_is_qcfail, __Pyx_DOCSTR(__pyx_k_203), 0},
28068   {(char *)"is_duplicate", __pyx_getprop_9csamtools_11AlignedRead_is_duplicate, __pyx_setprop_9csamtools_11AlignedRead_is_duplicate, __Pyx_DOCSTR(__pyx_k_204), 0},
28069   {(char *)"positions", __pyx_getprop_9csamtools_11AlignedRead_positions, 0, __Pyx_DOCSTR(__pyx_k_205), 0},
28070   {0, 0, 0, 0, 0}
28071 };
28072
28073 static PyNumberMethods __pyx_tp_as_number_AlignedRead = {
28074   0, /*nb_add*/
28075   0, /*nb_subtract*/
28076   0, /*nb_multiply*/
28077   #if PY_MAJOR_VERSION < 3
28078   0, /*nb_divide*/
28079   #endif
28080   0, /*nb_remainder*/
28081   0, /*nb_divmod*/
28082   0, /*nb_power*/
28083   0, /*nb_negative*/
28084   0, /*nb_positive*/
28085   0, /*nb_absolute*/
28086   0, /*nb_nonzero*/
28087   0, /*nb_invert*/
28088   0, /*nb_lshift*/
28089   0, /*nb_rshift*/
28090   0, /*nb_and*/
28091   0, /*nb_xor*/
28092   0, /*nb_or*/
28093   #if PY_MAJOR_VERSION < 3
28094   0, /*nb_coerce*/
28095   #endif
28096   0, /*nb_int*/
28097   #if PY_MAJOR_VERSION < 3
28098   0, /*nb_long*/
28099   #else
28100   0, /*reserved*/
28101   #endif
28102   0, /*nb_float*/
28103   #if PY_MAJOR_VERSION < 3
28104   0, /*nb_oct*/
28105   #endif
28106   #if PY_MAJOR_VERSION < 3
28107   0, /*nb_hex*/
28108   #endif
28109   0, /*nb_inplace_add*/
28110   0, /*nb_inplace_subtract*/
28111   0, /*nb_inplace_multiply*/
28112   #if PY_MAJOR_VERSION < 3
28113   0, /*nb_inplace_divide*/
28114   #endif
28115   0, /*nb_inplace_remainder*/
28116   0, /*nb_inplace_power*/
28117   0, /*nb_inplace_lshift*/
28118   0, /*nb_inplace_rshift*/
28119   0, /*nb_inplace_and*/
28120   0, /*nb_inplace_xor*/
28121   0, /*nb_inplace_or*/
28122   0, /*nb_floor_divide*/
28123   0, /*nb_true_divide*/
28124   0, /*nb_inplace_floor_divide*/
28125   0, /*nb_inplace_true_divide*/
28126   #if PY_VERSION_HEX >= 0x02050000
28127   0, /*nb_index*/
28128   #endif
28129 };
28130
28131 static PySequenceMethods __pyx_tp_as_sequence_AlignedRead = {
28132   0, /*sq_length*/
28133   0, /*sq_concat*/
28134   0, /*sq_repeat*/
28135   0, /*sq_item*/
28136   0, /*sq_slice*/
28137   0, /*sq_ass_item*/
28138   0, /*sq_ass_slice*/
28139   0, /*sq_contains*/
28140   0, /*sq_inplace_concat*/
28141   0, /*sq_inplace_repeat*/
28142 };
28143
28144 static PyMappingMethods __pyx_tp_as_mapping_AlignedRead = {
28145   0, /*mp_length*/
28146   0, /*mp_subscript*/
28147   0, /*mp_ass_subscript*/
28148 };
28149
28150 static PyBufferProcs __pyx_tp_as_buffer_AlignedRead = {
28151   #if PY_MAJOR_VERSION < 3
28152   0, /*bf_getreadbuffer*/
28153   #endif
28154   #if PY_MAJOR_VERSION < 3
28155   0, /*bf_getwritebuffer*/
28156   #endif
28157   #if PY_MAJOR_VERSION < 3
28158   0, /*bf_getsegcount*/
28159   #endif
28160   #if PY_MAJOR_VERSION < 3
28161   0, /*bf_getcharbuffer*/
28162   #endif
28163   #if PY_VERSION_HEX >= 0x02060000
28164   0, /*bf_getbuffer*/
28165   #endif
28166   #if PY_VERSION_HEX >= 0x02060000
28167   0, /*bf_releasebuffer*/
28168   #endif
28169 };
28170
28171 static PyTypeObject __pyx_type_9csamtools_AlignedRead = {
28172   PyVarObject_HEAD_INIT(0, 0)
28173   __Pyx_NAMESTR("csamtools.AlignedRead"), /*tp_name*/
28174   sizeof(struct __pyx_obj_9csamtools_AlignedRead), /*tp_basicsize*/
28175   0, /*tp_itemsize*/
28176   __pyx_tp_dealloc_9csamtools_AlignedRead, /*tp_dealloc*/
28177   0, /*tp_print*/
28178   0, /*tp_getattr*/
28179   0, /*tp_setattr*/
28180   #if PY_MAJOR_VERSION < 3
28181   0, /*tp_compare*/
28182   #else
28183   0, /*reserved*/
28184   #endif
28185   0, /*tp_repr*/
28186   &__pyx_tp_as_number_AlignedRead, /*tp_as_number*/
28187   &__pyx_tp_as_sequence_AlignedRead, /*tp_as_sequence*/
28188   &__pyx_tp_as_mapping_AlignedRead, /*tp_as_mapping*/
28189   __pyx_pf_9csamtools_11AlignedRead_4__hash__, /*tp_hash*/
28190   0, /*tp_call*/
28191   __pyx_pf_9csamtools_11AlignedRead_2__str__, /*tp_str*/
28192   0, /*tp_getattro*/
28193   0, /*tp_setattro*/
28194   &__pyx_tp_as_buffer_AlignedRead, /*tp_as_buffer*/
28195   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
28196   __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    "), /*tp_doc*/
28197   0, /*tp_traverse*/
28198   0, /*tp_clear*/
28199   0, /*tp_richcompare*/
28200   0, /*tp_weaklistoffset*/
28201   0, /*tp_iter*/
28202   0, /*tp_iternext*/
28203   __pyx_methods_9csamtools_AlignedRead, /*tp_methods*/
28204   0, /*tp_members*/
28205   __pyx_getsets_9csamtools_AlignedRead, /*tp_getset*/
28206   0, /*tp_base*/
28207   0, /*tp_dict*/
28208   0, /*tp_descr_get*/
28209   0, /*tp_descr_set*/
28210   0, /*tp_dictoffset*/
28211   __pyx_pf_9csamtools_11AlignedRead___init__, /*tp_init*/
28212   0, /*tp_alloc*/
28213   __pyx_tp_new_9csamtools_AlignedRead, /*tp_new*/
28214   0, /*tp_free*/
28215   0, /*tp_is_gc*/
28216   0, /*tp_bases*/
28217   0, /*tp_mro*/
28218   0, /*tp_cache*/
28219   0, /*tp_subclasses*/
28220   0, /*tp_weaklist*/
28221   0, /*tp_del*/
28222   #if PY_VERSION_HEX >= 0x02060000
28223   0, /*tp_version_tag*/
28224   #endif
28225 };
28226 static struct __pyx_vtabstruct_9csamtools_Samfile __pyx_vtable_9csamtools_Samfile;
28227
28228 static PyObject *__pyx_tp_new_9csamtools_Samfile(PyTypeObject *t, PyObject *a, PyObject *k) {
28229   struct __pyx_obj_9csamtools_Samfile *p;
28230   PyObject *o = (*t->tp_alloc)(t, 0);
28231   if (!o) return 0;
28232   p = ((struct __pyx_obj_9csamtools_Samfile *)o);
28233   p->__pyx_vtab = __pyx_vtabptr_9csamtools_Samfile;
28234   if (__pyx_pf_9csamtools_7Samfile___cinit__(o, a, k) < 0) {
28235     Py_DECREF(o); o = 0;
28236   }
28237   return o;
28238 }
28239
28240 static void __pyx_tp_dealloc_9csamtools_Samfile(PyObject *o) {
28241   {
28242     PyObject *etype, *eval, *etb;
28243     PyErr_Fetch(&etype, &eval, &etb);
28244     ++Py_REFCNT(o);
28245     __pyx_pf_9csamtools_7Samfile_15__dealloc__(o);
28246     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
28247     --Py_REFCNT(o);
28248     PyErr_Restore(etype, eval, etb);
28249   }
28250   (*Py_TYPE(o)->tp_free)(o);
28251 }
28252
28253 static PyObject *__pyx_getprop_9csamtools_7Samfile_filename(PyObject *o, void *x) {
28254   return __pyx_pf_9csamtools_7Samfile_8filename___get__(o);
28255 }
28256
28257 static PyObject *__pyx_getprop_9csamtools_7Samfile_nreferences(PyObject *o, void *x) {
28258   return __pyx_pf_9csamtools_7Samfile_11nreferences___get__(o);
28259 }
28260
28261 static PyObject *__pyx_getprop_9csamtools_7Samfile_references(PyObject *o, void *x) {
28262   return __pyx_pf_9csamtools_7Samfile_10references___get__(o);
28263 }
28264
28265 static PyObject *__pyx_getprop_9csamtools_7Samfile_lengths(PyObject *o, void *x) {
28266   return __pyx_pf_9csamtools_7Samfile_7lengths___get__(o);
28267 }
28268
28269 static PyObject *__pyx_getprop_9csamtools_7Samfile_mapped(PyObject *o, void *x) {
28270   return __pyx_pf_9csamtools_7Samfile_6mapped___get__(o);
28271 }
28272
28273 static PyObject *__pyx_getprop_9csamtools_7Samfile_unmapped(PyObject *o, void *x) {
28274   return __pyx_pf_9csamtools_7Samfile_8unmapped___get__(o);
28275 }
28276
28277 static PyObject *__pyx_getprop_9csamtools_7Samfile_text(PyObject *o, void *x) {
28278   return __pyx_pf_9csamtools_7Samfile_4text___get__(o);
28279 }
28280
28281 static PyObject *__pyx_getprop_9csamtools_7Samfile_header(PyObject *o, void *x) {
28282   return __pyx_pf_9csamtools_7Samfile_6header___get__(o);
28283 }
28284
28285 static PyMethodDef __pyx_methods_9csamtools_Samfile[] = {
28286   {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_1_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_1_isOpen)},
28287   {__Pyx_NAMESTR("_hasIndex"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_2_hasIndex, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_2_hasIndex)},
28288   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_3_open, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_3_open)},
28289   {__Pyx_NAMESTR("gettid"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_4gettid, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_4gettid)},
28290   {__Pyx_NAMESTR("getrname"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_5getrname, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_5getrname)},
28291   {__Pyx_NAMESTR("_parseRegion"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_6_parseRegion, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_6_parseRegion)},
28292   {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_7reset, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_7reset)},
28293   {__Pyx_NAMESTR("seek"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_8seek, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_8seek)},
28294   {__Pyx_NAMESTR("tell"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_9tell, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_9tell)},
28295   {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_10fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_10fetch)},
28296   {__Pyx_NAMESTR("mate"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_11mate, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_11mate)},
28297   {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_12count, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_12count)},
28298   {__Pyx_NAMESTR("pileup"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_13pileup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_13pileup)},
28299   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_14close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_14close)},
28300   {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_16write, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_16write)},
28301   {__Pyx_NAMESTR("__enter__"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_17__enter__, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_17__enter__)},
28302   {__Pyx_NAMESTR("__exit__"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_18__exit__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_18__exit__)},
28303   {__Pyx_NAMESTR("_buildLine"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_19_buildLine, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_19_buildLine)},
28304   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_7Samfile_21__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_7Samfile_21__next__)},
28305   {0, 0, 0, 0}
28306 };
28307
28308 static struct PyGetSetDef __pyx_getsets_9csamtools_Samfile[] = {
28309   {(char *)"filename", __pyx_getprop_9csamtools_7Samfile_filename, 0, __Pyx_DOCSTR(__pyx_k_206), 0},
28310   {(char *)"nreferences", __pyx_getprop_9csamtools_7Samfile_nreferences, 0, __Pyx_DOCSTR(__pyx_k_207), 0},
28311   {(char *)"references", __pyx_getprop_9csamtools_7Samfile_references, 0, __Pyx_DOCSTR(__pyx_k_208), 0},
28312   {(char *)"lengths", __pyx_getprop_9csamtools_7Samfile_lengths, 0, __Pyx_DOCSTR(__pyx_k_209), 0},
28313   {(char *)"mapped", __pyx_getprop_9csamtools_7Samfile_mapped, 0, __Pyx_DOCSTR(__pyx_k_210), 0},
28314   {(char *)"unmapped", __pyx_getprop_9csamtools_7Samfile_unmapped, 0, __Pyx_DOCSTR(__pyx_k_211), 0},
28315   {(char *)"text", __pyx_getprop_9csamtools_7Samfile_text, 0, __Pyx_DOCSTR(__pyx_k_212), 0},
28316   {(char *)"header", __pyx_getprop_9csamtools_7Samfile_header, 0, __Pyx_DOCSTR(__pyx_k_213), 0},
28317   {0, 0, 0, 0, 0}
28318 };
28319
28320 static PyNumberMethods __pyx_tp_as_number_Samfile = {
28321   0, /*nb_add*/
28322   0, /*nb_subtract*/
28323   0, /*nb_multiply*/
28324   #if PY_MAJOR_VERSION < 3
28325   0, /*nb_divide*/
28326   #endif
28327   0, /*nb_remainder*/
28328   0, /*nb_divmod*/
28329   0, /*nb_power*/
28330   0, /*nb_negative*/
28331   0, /*nb_positive*/
28332   0, /*nb_absolute*/
28333   0, /*nb_nonzero*/
28334   0, /*nb_invert*/
28335   0, /*nb_lshift*/
28336   0, /*nb_rshift*/
28337   0, /*nb_and*/
28338   0, /*nb_xor*/
28339   0, /*nb_or*/
28340   #if PY_MAJOR_VERSION < 3
28341   0, /*nb_coerce*/
28342   #endif
28343   0, /*nb_int*/
28344   #if PY_MAJOR_VERSION < 3
28345   0, /*nb_long*/
28346   #else
28347   0, /*reserved*/
28348   #endif
28349   0, /*nb_float*/
28350   #if PY_MAJOR_VERSION < 3
28351   0, /*nb_oct*/
28352   #endif
28353   #if PY_MAJOR_VERSION < 3
28354   0, /*nb_hex*/
28355   #endif
28356   0, /*nb_inplace_add*/
28357   0, /*nb_inplace_subtract*/
28358   0, /*nb_inplace_multiply*/
28359   #if PY_MAJOR_VERSION < 3
28360   0, /*nb_inplace_divide*/
28361   #endif
28362   0, /*nb_inplace_remainder*/
28363   0, /*nb_inplace_power*/
28364   0, /*nb_inplace_lshift*/
28365   0, /*nb_inplace_rshift*/
28366   0, /*nb_inplace_and*/
28367   0, /*nb_inplace_xor*/
28368   0, /*nb_inplace_or*/
28369   0, /*nb_floor_divide*/
28370   0, /*nb_true_divide*/
28371   0, /*nb_inplace_floor_divide*/
28372   0, /*nb_inplace_true_divide*/
28373   #if PY_VERSION_HEX >= 0x02050000
28374   0, /*nb_index*/
28375   #endif
28376 };
28377
28378 static PySequenceMethods __pyx_tp_as_sequence_Samfile = {
28379   0, /*sq_length*/
28380   0, /*sq_concat*/
28381   0, /*sq_repeat*/
28382   0, /*sq_item*/
28383   0, /*sq_slice*/
28384   0, /*sq_ass_item*/
28385   0, /*sq_ass_slice*/
28386   0, /*sq_contains*/
28387   0, /*sq_inplace_concat*/
28388   0, /*sq_inplace_repeat*/
28389 };
28390
28391 static PyMappingMethods __pyx_tp_as_mapping_Samfile = {
28392   0, /*mp_length*/
28393   0, /*mp_subscript*/
28394   0, /*mp_ass_subscript*/
28395 };
28396
28397 static PyBufferProcs __pyx_tp_as_buffer_Samfile = {
28398   #if PY_MAJOR_VERSION < 3
28399   0, /*bf_getreadbuffer*/
28400   #endif
28401   #if PY_MAJOR_VERSION < 3
28402   0, /*bf_getwritebuffer*/
28403   #endif
28404   #if PY_MAJOR_VERSION < 3
28405   0, /*bf_getsegcount*/
28406   #endif
28407   #if PY_MAJOR_VERSION < 3
28408   0, /*bf_getcharbuffer*/
28409   #endif
28410   #if PY_VERSION_HEX >= 0x02060000
28411   0, /*bf_getbuffer*/
28412   #endif
28413   #if PY_VERSION_HEX >= 0x02060000
28414   0, /*bf_releasebuffer*/
28415   #endif
28416 };
28417
28418 static PyTypeObject __pyx_type_9csamtools_Samfile = {
28419   PyVarObject_HEAD_INIT(0, 0)
28420   __Pyx_NAMESTR("csamtools.Samfile"), /*tp_name*/
28421   sizeof(struct __pyx_obj_9csamtools_Samfile), /*tp_basicsize*/
28422   0, /*tp_itemsize*/
28423   __pyx_tp_dealloc_9csamtools_Samfile, /*tp_dealloc*/
28424   0, /*tp_print*/
28425   0, /*tp_getattr*/
28426   0, /*tp_setattr*/
28427   #if PY_MAJOR_VERSION < 3
28428   0, /*tp_compare*/
28429   #else
28430   0, /*reserved*/
28431   #endif
28432   0, /*tp_repr*/
28433   &__pyx_tp_as_number_Samfile, /*tp_as_number*/
28434   &__pyx_tp_as_sequence_Samfile, /*tp_as_sequence*/
28435   &__pyx_tp_as_mapping_Samfile, /*tp_as_mapping*/
28436   0, /*tp_hash*/
28437   0, /*tp_call*/
28438   0, /*tp_str*/
28439   0, /*tp_getattro*/
28440   0, /*tp_setattro*/
28441   &__pyx_tp_as_buffer_Samfile, /*tp_as_buffer*/
28442   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
28443   __Pyx_DOCSTR("*(filename, mode=None, template = None, referencenames = None, referencelengths = None, text = NULL, header = None,\n         add_sq_text = False )*\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.\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    "), /*tp_doc*/
28444   0, /*tp_traverse*/
28445   0, /*tp_clear*/
28446   0, /*tp_richcompare*/
28447   0, /*tp_weaklistoffset*/
28448   __pyx_pf_9csamtools_7Samfile_20__iter__, /*tp_iter*/
28449   __pyx_pf_9csamtools_7Samfile_21__next__, /*tp_iternext*/
28450   __pyx_methods_9csamtools_Samfile, /*tp_methods*/
28451   0, /*tp_members*/
28452   __pyx_getsets_9csamtools_Samfile, /*tp_getset*/
28453   0, /*tp_base*/
28454   0, /*tp_dict*/
28455   0, /*tp_descr_get*/
28456   0, /*tp_descr_set*/
28457   0, /*tp_dictoffset*/
28458   0, /*tp_init*/
28459   0, /*tp_alloc*/
28460   __pyx_tp_new_9csamtools_Samfile, /*tp_new*/
28461   0, /*tp_free*/
28462   0, /*tp_is_gc*/
28463   0, /*tp_bases*/
28464   0, /*tp_mro*/
28465   0, /*tp_cache*/
28466   0, /*tp_subclasses*/
28467   0, /*tp_weaklist*/
28468   0, /*tp_del*/
28469   #if PY_VERSION_HEX >= 0x02060000
28470   0, /*tp_version_tag*/
28471   #endif
28472 };
28473
28474 static PyObject *__pyx_tp_new_9csamtools_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k) {
28475   PyObject *o = (*t->tp_alloc)(t, 0);
28476   if (!o) return 0;
28477   return o;
28478 }
28479
28480 static void __pyx_tp_dealloc_9csamtools_IteratorRow(PyObject *o) {
28481   (*Py_TYPE(o)->tp_free)(o);
28482 }
28483
28484 static PyMethodDef __pyx_methods_9csamtools_IteratorRow[] = {
28485   {0, 0, 0, 0}
28486 };
28487
28488 static PyNumberMethods __pyx_tp_as_number_IteratorRow = {
28489   0, /*nb_add*/
28490   0, /*nb_subtract*/
28491   0, /*nb_multiply*/
28492   #if PY_MAJOR_VERSION < 3
28493   0, /*nb_divide*/
28494   #endif
28495   0, /*nb_remainder*/
28496   0, /*nb_divmod*/
28497   0, /*nb_power*/
28498   0, /*nb_negative*/
28499   0, /*nb_positive*/
28500   0, /*nb_absolute*/
28501   0, /*nb_nonzero*/
28502   0, /*nb_invert*/
28503   0, /*nb_lshift*/
28504   0, /*nb_rshift*/
28505   0, /*nb_and*/
28506   0, /*nb_xor*/
28507   0, /*nb_or*/
28508   #if PY_MAJOR_VERSION < 3
28509   0, /*nb_coerce*/
28510   #endif
28511   0, /*nb_int*/
28512   #if PY_MAJOR_VERSION < 3
28513   0, /*nb_long*/
28514   #else
28515   0, /*reserved*/
28516   #endif
28517   0, /*nb_float*/
28518   #if PY_MAJOR_VERSION < 3
28519   0, /*nb_oct*/
28520   #endif
28521   #if PY_MAJOR_VERSION < 3
28522   0, /*nb_hex*/
28523   #endif
28524   0, /*nb_inplace_add*/
28525   0, /*nb_inplace_subtract*/
28526   0, /*nb_inplace_multiply*/
28527   #if PY_MAJOR_VERSION < 3
28528   0, /*nb_inplace_divide*/
28529   #endif
28530   0, /*nb_inplace_remainder*/
28531   0, /*nb_inplace_power*/
28532   0, /*nb_inplace_lshift*/
28533   0, /*nb_inplace_rshift*/
28534   0, /*nb_inplace_and*/
28535   0, /*nb_inplace_xor*/
28536   0, /*nb_inplace_or*/
28537   0, /*nb_floor_divide*/
28538   0, /*nb_true_divide*/
28539   0, /*nb_inplace_floor_divide*/
28540   0, /*nb_inplace_true_divide*/
28541   #if PY_VERSION_HEX >= 0x02050000
28542   0, /*nb_index*/
28543   #endif
28544 };
28545
28546 static PySequenceMethods __pyx_tp_as_sequence_IteratorRow = {
28547   0, /*sq_length*/
28548   0, /*sq_concat*/
28549   0, /*sq_repeat*/
28550   0, /*sq_item*/
28551   0, /*sq_slice*/
28552   0, /*sq_ass_item*/
28553   0, /*sq_ass_slice*/
28554   0, /*sq_contains*/
28555   0, /*sq_inplace_concat*/
28556   0, /*sq_inplace_repeat*/
28557 };
28558
28559 static PyMappingMethods __pyx_tp_as_mapping_IteratorRow = {
28560   0, /*mp_length*/
28561   0, /*mp_subscript*/
28562   0, /*mp_ass_subscript*/
28563 };
28564
28565 static PyBufferProcs __pyx_tp_as_buffer_IteratorRow = {
28566   #if PY_MAJOR_VERSION < 3
28567   0, /*bf_getreadbuffer*/
28568   #endif
28569   #if PY_MAJOR_VERSION < 3
28570   0, /*bf_getwritebuffer*/
28571   #endif
28572   #if PY_MAJOR_VERSION < 3
28573   0, /*bf_getsegcount*/
28574   #endif
28575   #if PY_MAJOR_VERSION < 3
28576   0, /*bf_getcharbuffer*/
28577   #endif
28578   #if PY_VERSION_HEX >= 0x02060000
28579   0, /*bf_getbuffer*/
28580   #endif
28581   #if PY_VERSION_HEX >= 0x02060000
28582   0, /*bf_releasebuffer*/
28583   #endif
28584 };
28585
28586 static PyTypeObject __pyx_type_9csamtools_IteratorRow = {
28587   PyVarObject_HEAD_INIT(0, 0)
28588   __Pyx_NAMESTR("csamtools.IteratorRow"), /*tp_name*/
28589   sizeof(struct __pyx_obj_9csamtools_IteratorRow), /*tp_basicsize*/
28590   0, /*tp_itemsize*/
28591   __pyx_tp_dealloc_9csamtools_IteratorRow, /*tp_dealloc*/
28592   0, /*tp_print*/
28593   0, /*tp_getattr*/
28594   0, /*tp_setattr*/
28595   #if PY_MAJOR_VERSION < 3
28596   0, /*tp_compare*/
28597   #else
28598   0, /*reserved*/
28599   #endif
28600   0, /*tp_repr*/
28601   &__pyx_tp_as_number_IteratorRow, /*tp_as_number*/
28602   &__pyx_tp_as_sequence_IteratorRow, /*tp_as_sequence*/
28603   &__pyx_tp_as_mapping_IteratorRow, /*tp_as_mapping*/
28604   0, /*tp_hash*/
28605   0, /*tp_call*/
28606   0, /*tp_str*/
28607   0, /*tp_getattro*/
28608   0, /*tp_setattro*/
28609   &__pyx_tp_as_buffer_IteratorRow, /*tp_as_buffer*/
28610   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
28611   __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*/
28612   0, /*tp_traverse*/
28613   0, /*tp_clear*/
28614   0, /*tp_richcompare*/
28615   0, /*tp_weaklistoffset*/
28616   0, /*tp_iter*/
28617   0, /*tp_iternext*/
28618   __pyx_methods_9csamtools_IteratorRow, /*tp_methods*/
28619   0, /*tp_members*/
28620   0, /*tp_getset*/
28621   0, /*tp_base*/
28622   0, /*tp_dict*/
28623   0, /*tp_descr_get*/
28624   0, /*tp_descr_set*/
28625   0, /*tp_dictoffset*/
28626   0, /*tp_init*/
28627   0, /*tp_alloc*/
28628   __pyx_tp_new_9csamtools_IteratorRow, /*tp_new*/
28629   0, /*tp_free*/
28630   0, /*tp_is_gc*/
28631   0, /*tp_bases*/
28632   0, /*tp_mro*/
28633   0, /*tp_cache*/
28634   0, /*tp_subclasses*/
28635   0, /*tp_weaklist*/
28636   0, /*tp_del*/
28637   #if PY_VERSION_HEX >= 0x02060000
28638   0, /*tp_version_tag*/
28639   #endif
28640 };
28641 static struct __pyx_vtabstruct_9csamtools_IteratorRowAll __pyx_vtable_9csamtools_IteratorRowAll;
28642
28643 static PyObject *__pyx_tp_new_9csamtools_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
28644   struct __pyx_obj_9csamtools_IteratorRowAll *p;
28645   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
28646   if (!o) return 0;
28647   p = ((struct __pyx_obj_9csamtools_IteratorRowAll *)o);
28648   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowAll;
28649   if (__pyx_pf_9csamtools_14IteratorRowAll___cinit__(o, a, k) < 0) {
28650     Py_DECREF(o); o = 0;
28651   }
28652   return o;
28653 }
28654
28655 static void __pyx_tp_dealloc_9csamtools_IteratorRowAll(PyObject *o) {
28656   {
28657     PyObject *etype, *eval, *etb;
28658     PyErr_Fetch(&etype, &eval, &etb);
28659     ++Py_REFCNT(o);
28660     __pyx_pf_9csamtools_14IteratorRowAll_3__dealloc__(o);
28661     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
28662     --Py_REFCNT(o);
28663     PyErr_Restore(etype, eval, etb);
28664   }
28665   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
28666 }
28667
28668 static PyMethodDef __pyx_methods_9csamtools_IteratorRowAll[] = {
28669   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_14IteratorRowAll_2__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorRowAll_2__next__)},
28670   {0, 0, 0, 0}
28671 };
28672
28673 static PyNumberMethods __pyx_tp_as_number_IteratorRowAll = {
28674   0, /*nb_add*/
28675   0, /*nb_subtract*/
28676   0, /*nb_multiply*/
28677   #if PY_MAJOR_VERSION < 3
28678   0, /*nb_divide*/
28679   #endif
28680   0, /*nb_remainder*/
28681   0, /*nb_divmod*/
28682   0, /*nb_power*/
28683   0, /*nb_negative*/
28684   0, /*nb_positive*/
28685   0, /*nb_absolute*/
28686   0, /*nb_nonzero*/
28687   0, /*nb_invert*/
28688   0, /*nb_lshift*/
28689   0, /*nb_rshift*/
28690   0, /*nb_and*/
28691   0, /*nb_xor*/
28692   0, /*nb_or*/
28693   #if PY_MAJOR_VERSION < 3
28694   0, /*nb_coerce*/
28695   #endif
28696   0, /*nb_int*/
28697   #if PY_MAJOR_VERSION < 3
28698   0, /*nb_long*/
28699   #else
28700   0, /*reserved*/
28701   #endif
28702   0, /*nb_float*/
28703   #if PY_MAJOR_VERSION < 3
28704   0, /*nb_oct*/
28705   #endif
28706   #if PY_MAJOR_VERSION < 3
28707   0, /*nb_hex*/
28708   #endif
28709   0, /*nb_inplace_add*/
28710   0, /*nb_inplace_subtract*/
28711   0, /*nb_inplace_multiply*/
28712   #if PY_MAJOR_VERSION < 3
28713   0, /*nb_inplace_divide*/
28714   #endif
28715   0, /*nb_inplace_remainder*/
28716   0, /*nb_inplace_power*/
28717   0, /*nb_inplace_lshift*/
28718   0, /*nb_inplace_rshift*/
28719   0, /*nb_inplace_and*/
28720   0, /*nb_inplace_xor*/
28721   0, /*nb_inplace_or*/
28722   0, /*nb_floor_divide*/
28723   0, /*nb_true_divide*/
28724   0, /*nb_inplace_floor_divide*/
28725   0, /*nb_inplace_true_divide*/
28726   #if PY_VERSION_HEX >= 0x02050000
28727   0, /*nb_index*/
28728   #endif
28729 };
28730
28731 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowAll = {
28732   0, /*sq_length*/
28733   0, /*sq_concat*/
28734   0, /*sq_repeat*/
28735   0, /*sq_item*/
28736   0, /*sq_slice*/
28737   0, /*sq_ass_item*/
28738   0, /*sq_ass_slice*/
28739   0, /*sq_contains*/
28740   0, /*sq_inplace_concat*/
28741   0, /*sq_inplace_repeat*/
28742 };
28743
28744 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowAll = {
28745   0, /*mp_length*/
28746   0, /*mp_subscript*/
28747   0, /*mp_ass_subscript*/
28748 };
28749
28750 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowAll = {
28751   #if PY_MAJOR_VERSION < 3
28752   0, /*bf_getreadbuffer*/
28753   #endif
28754   #if PY_MAJOR_VERSION < 3
28755   0, /*bf_getwritebuffer*/
28756   #endif
28757   #if PY_MAJOR_VERSION < 3
28758   0, /*bf_getsegcount*/
28759   #endif
28760   #if PY_MAJOR_VERSION < 3
28761   0, /*bf_getcharbuffer*/
28762   #endif
28763   #if PY_VERSION_HEX >= 0x02060000
28764   0, /*bf_getbuffer*/
28765   #endif
28766   #if PY_VERSION_HEX >= 0x02060000
28767   0, /*bf_releasebuffer*/
28768   #endif
28769 };
28770
28771 static PyTypeObject __pyx_type_9csamtools_IteratorRowAll = {
28772   PyVarObject_HEAD_INIT(0, 0)
28773   __Pyx_NAMESTR("csamtools.IteratorRowAll"), /*tp_name*/
28774   sizeof(struct __pyx_obj_9csamtools_IteratorRowAll), /*tp_basicsize*/
28775   0, /*tp_itemsize*/
28776   __pyx_tp_dealloc_9csamtools_IteratorRowAll, /*tp_dealloc*/
28777   0, /*tp_print*/
28778   0, /*tp_getattr*/
28779   0, /*tp_setattr*/
28780   #if PY_MAJOR_VERSION < 3
28781   0, /*tp_compare*/
28782   #else
28783   0, /*reserved*/
28784   #endif
28785   0, /*tp_repr*/
28786   &__pyx_tp_as_number_IteratorRowAll, /*tp_as_number*/
28787   &__pyx_tp_as_sequence_IteratorRowAll, /*tp_as_sequence*/
28788   &__pyx_tp_as_mapping_IteratorRowAll, /*tp_as_mapping*/
28789   0, /*tp_hash*/
28790   0, /*tp_call*/
28791   0, /*tp_str*/
28792   0, /*tp_getattro*/
28793   0, /*tp_setattro*/
28794   &__pyx_tp_as_buffer_IteratorRowAll, /*tp_as_buffer*/
28795   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
28796   __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*/
28797   0, /*tp_traverse*/
28798   0, /*tp_clear*/
28799   0, /*tp_richcompare*/
28800   0, /*tp_weaklistoffset*/
28801   __pyx_pf_9csamtools_14IteratorRowAll_1__iter__, /*tp_iter*/
28802   __pyx_pf_9csamtools_14IteratorRowAll_2__next__, /*tp_iternext*/
28803   __pyx_methods_9csamtools_IteratorRowAll, /*tp_methods*/
28804   0, /*tp_members*/
28805   0, /*tp_getset*/
28806   0, /*tp_base*/
28807   0, /*tp_dict*/
28808   0, /*tp_descr_get*/
28809   0, /*tp_descr_set*/
28810   0, /*tp_dictoffset*/
28811   0, /*tp_init*/
28812   0, /*tp_alloc*/
28813   __pyx_tp_new_9csamtools_IteratorRowAll, /*tp_new*/
28814   0, /*tp_free*/
28815   0, /*tp_is_gc*/
28816   0, /*tp_bases*/
28817   0, /*tp_mro*/
28818   0, /*tp_cache*/
28819   0, /*tp_subclasses*/
28820   0, /*tp_weaklist*/
28821   0, /*tp_del*/
28822   #if PY_VERSION_HEX >= 0x02060000
28823   0, /*tp_version_tag*/
28824   #endif
28825 };
28826
28827 static PyObject *__pyx_tp_new_9csamtools_PileupProxy(PyTypeObject *t, PyObject *a, PyObject *k) {
28828   PyObject *o = (*t->tp_alloc)(t, 0);
28829   if (!o) return 0;
28830   return o;
28831 }
28832
28833 static void __pyx_tp_dealloc_9csamtools_PileupProxy(PyObject *o) {
28834   (*Py_TYPE(o)->tp_free)(o);
28835 }
28836
28837 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_tid(PyObject *o, void *x) {
28838   return __pyx_pf_9csamtools_11PileupProxy_3tid___get__(o);
28839 }
28840
28841 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_n(PyObject *o, void *x) {
28842   return __pyx_pf_9csamtools_11PileupProxy_1n___get__(o);
28843 }
28844
28845 static int __pyx_setprop_9csamtools_11PileupProxy_n(PyObject *o, PyObject *v, void *x) {
28846   if (v) {
28847     return __pyx_pf_9csamtools_11PileupProxy_1n_1__set__(o, v);
28848   }
28849   else {
28850     PyErr_SetString(PyExc_NotImplementedError, "__del__");
28851     return -1;
28852   }
28853 }
28854
28855 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_pos(PyObject *o, void *x) {
28856   return __pyx_pf_9csamtools_11PileupProxy_3pos___get__(o);
28857 }
28858
28859 static PyObject *__pyx_getprop_9csamtools_11PileupProxy_pileups(PyObject *o, void *x) {
28860   return __pyx_pf_9csamtools_11PileupProxy_7pileups___get__(o);
28861 }
28862
28863 static PyMethodDef __pyx_methods_9csamtools_PileupProxy[] = {
28864   {0, 0, 0, 0}
28865 };
28866
28867 static struct PyGetSetDef __pyx_getsets_9csamtools_PileupProxy[] = {
28868   {(char *)"tid", __pyx_getprop_9csamtools_11PileupProxy_tid, 0, __Pyx_DOCSTR(__pyx_k_214), 0},
28869   {(char *)"n", __pyx_getprop_9csamtools_11PileupProxy_n, __pyx_setprop_9csamtools_11PileupProxy_n, __Pyx_DOCSTR(__pyx_k_215), 0},
28870   {(char *)"pos", __pyx_getprop_9csamtools_11PileupProxy_pos, 0, 0, 0},
28871   {(char *)"pileups", __pyx_getprop_9csamtools_11PileupProxy_pileups, 0, __Pyx_DOCSTR(__pyx_k_216), 0},
28872   {0, 0, 0, 0, 0}
28873 };
28874
28875 static PyNumberMethods __pyx_tp_as_number_PileupProxy = {
28876   0, /*nb_add*/
28877   0, /*nb_subtract*/
28878   0, /*nb_multiply*/
28879   #if PY_MAJOR_VERSION < 3
28880   0, /*nb_divide*/
28881   #endif
28882   0, /*nb_remainder*/
28883   0, /*nb_divmod*/
28884   0, /*nb_power*/
28885   0, /*nb_negative*/
28886   0, /*nb_positive*/
28887   0, /*nb_absolute*/
28888   0, /*nb_nonzero*/
28889   0, /*nb_invert*/
28890   0, /*nb_lshift*/
28891   0, /*nb_rshift*/
28892   0, /*nb_and*/
28893   0, /*nb_xor*/
28894   0, /*nb_or*/
28895   #if PY_MAJOR_VERSION < 3
28896   0, /*nb_coerce*/
28897   #endif
28898   0, /*nb_int*/
28899   #if PY_MAJOR_VERSION < 3
28900   0, /*nb_long*/
28901   #else
28902   0, /*reserved*/
28903   #endif
28904   0, /*nb_float*/
28905   #if PY_MAJOR_VERSION < 3
28906   0, /*nb_oct*/
28907   #endif
28908   #if PY_MAJOR_VERSION < 3
28909   0, /*nb_hex*/
28910   #endif
28911   0, /*nb_inplace_add*/
28912   0, /*nb_inplace_subtract*/
28913   0, /*nb_inplace_multiply*/
28914   #if PY_MAJOR_VERSION < 3
28915   0, /*nb_inplace_divide*/
28916   #endif
28917   0, /*nb_inplace_remainder*/
28918   0, /*nb_inplace_power*/
28919   0, /*nb_inplace_lshift*/
28920   0, /*nb_inplace_rshift*/
28921   0, /*nb_inplace_and*/
28922   0, /*nb_inplace_xor*/
28923   0, /*nb_inplace_or*/
28924   0, /*nb_floor_divide*/
28925   0, /*nb_true_divide*/
28926   0, /*nb_inplace_floor_divide*/
28927   0, /*nb_inplace_true_divide*/
28928   #if PY_VERSION_HEX >= 0x02050000
28929   0, /*nb_index*/
28930   #endif
28931 };
28932
28933 static PySequenceMethods __pyx_tp_as_sequence_PileupProxy = {
28934   0, /*sq_length*/
28935   0, /*sq_concat*/
28936   0, /*sq_repeat*/
28937   0, /*sq_item*/
28938   0, /*sq_slice*/
28939   0, /*sq_ass_item*/
28940   0, /*sq_ass_slice*/
28941   0, /*sq_contains*/
28942   0, /*sq_inplace_concat*/
28943   0, /*sq_inplace_repeat*/
28944 };
28945
28946 static PyMappingMethods __pyx_tp_as_mapping_PileupProxy = {
28947   0, /*mp_length*/
28948   0, /*mp_subscript*/
28949   0, /*mp_ass_subscript*/
28950 };
28951
28952 static PyBufferProcs __pyx_tp_as_buffer_PileupProxy = {
28953   #if PY_MAJOR_VERSION < 3
28954   0, /*bf_getreadbuffer*/
28955   #endif
28956   #if PY_MAJOR_VERSION < 3
28957   0, /*bf_getwritebuffer*/
28958   #endif
28959   #if PY_MAJOR_VERSION < 3
28960   0, /*bf_getsegcount*/
28961   #endif
28962   #if PY_MAJOR_VERSION < 3
28963   0, /*bf_getcharbuffer*/
28964   #endif
28965   #if PY_VERSION_HEX >= 0x02060000
28966   0, /*bf_getbuffer*/
28967   #endif
28968   #if PY_VERSION_HEX >= 0x02060000
28969   0, /*bf_releasebuffer*/
28970   #endif
28971 };
28972
28973 static PyTypeObject __pyx_type_9csamtools_PileupProxy = {
28974   PyVarObject_HEAD_INIT(0, 0)
28975   __Pyx_NAMESTR("csamtools.PileupProxy"), /*tp_name*/
28976   sizeof(struct __pyx_obj_9csamtools_PileupProxy), /*tp_basicsize*/
28977   0, /*tp_itemsize*/
28978   __pyx_tp_dealloc_9csamtools_PileupProxy, /*tp_dealloc*/
28979   0, /*tp_print*/
28980   0, /*tp_getattr*/
28981   0, /*tp_setattr*/
28982   #if PY_MAJOR_VERSION < 3
28983   0, /*tp_compare*/
28984   #else
28985   0, /*reserved*/
28986   #endif
28987   0, /*tp_repr*/
28988   &__pyx_tp_as_number_PileupProxy, /*tp_as_number*/
28989   &__pyx_tp_as_sequence_PileupProxy, /*tp_as_sequence*/
28990   &__pyx_tp_as_mapping_PileupProxy, /*tp_as_mapping*/
28991   0, /*tp_hash*/
28992   0, /*tp_call*/
28993   __pyx_pf_9csamtools_11PileupProxy_1__str__, /*tp_str*/
28994   0, /*tp_getattro*/
28995   0, /*tp_setattro*/
28996   &__pyx_tp_as_buffer_PileupProxy, /*tp_as_buffer*/
28997   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
28998   __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*/
28999   0, /*tp_traverse*/
29000   0, /*tp_clear*/
29001   0, /*tp_richcompare*/
29002   0, /*tp_weaklistoffset*/
29003   0, /*tp_iter*/
29004   0, /*tp_iternext*/
29005   __pyx_methods_9csamtools_PileupProxy, /*tp_methods*/
29006   0, /*tp_members*/
29007   __pyx_getsets_9csamtools_PileupProxy, /*tp_getset*/
29008   0, /*tp_base*/
29009   0, /*tp_dict*/
29010   0, /*tp_descr_get*/
29011   0, /*tp_descr_set*/
29012   0, /*tp_dictoffset*/
29013   __pyx_pf_9csamtools_11PileupProxy___init__, /*tp_init*/
29014   0, /*tp_alloc*/
29015   __pyx_tp_new_9csamtools_PileupProxy, /*tp_new*/
29016   0, /*tp_free*/
29017   0, /*tp_is_gc*/
29018   0, /*tp_bases*/
29019   0, /*tp_mro*/
29020   0, /*tp_cache*/
29021   0, /*tp_subclasses*/
29022   0, /*tp_weaklist*/
29023   0, /*tp_del*/
29024   #if PY_VERSION_HEX >= 0x02060000
29025   0, /*tp_version_tag*/
29026   #endif
29027 };
29028
29029 static PyObject *__pyx_tp_new_9csamtools_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k) {
29030   struct __pyx_obj_9csamtools_PileupRead *p;
29031   PyObject *o = (*t->tp_alloc)(t, 0);
29032   if (!o) return 0;
29033   p = ((struct __pyx_obj_9csamtools_PileupRead *)o);
29034   p->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
29035   return o;
29036 }
29037
29038 static void __pyx_tp_dealloc_9csamtools_PileupRead(PyObject *o) {
29039   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
29040   Py_XDECREF(((PyObject *)p->_alignment));
29041   (*Py_TYPE(o)->tp_free)(o);
29042 }
29043
29044 static int __pyx_tp_traverse_9csamtools_PileupRead(PyObject *o, visitproc v, void *a) {
29045   int e;
29046   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
29047   if (p->_alignment) {
29048     e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
29049   }
29050   return 0;
29051 }
29052
29053 static int __pyx_tp_clear_9csamtools_PileupRead(PyObject *o) {
29054   struct __pyx_obj_9csamtools_PileupRead *p = (struct __pyx_obj_9csamtools_PileupRead *)o;
29055   PyObject* tmp;
29056   tmp = ((PyObject*)p->_alignment);
29057   p->_alignment = ((struct __pyx_obj_9csamtools_AlignedRead *)Py_None); Py_INCREF(Py_None);
29058   Py_XDECREF(tmp);
29059   return 0;
29060 }
29061
29062 static PyObject *__pyx_getprop_9csamtools_10PileupRead_alignment(PyObject *o, void *x) {
29063   return __pyx_pf_9csamtools_10PileupRead_9alignment___get__(o);
29064 }
29065
29066 static PyObject *__pyx_getprop_9csamtools_10PileupRead_qpos(PyObject *o, void *x) {
29067   return __pyx_pf_9csamtools_10PileupRead_4qpos___get__(o);
29068 }
29069
29070 static PyObject *__pyx_getprop_9csamtools_10PileupRead_indel(PyObject *o, void *x) {
29071   return __pyx_pf_9csamtools_10PileupRead_5indel___get__(o);
29072 }
29073
29074 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_del(PyObject *o, void *x) {
29075   return __pyx_pf_9csamtools_10PileupRead_6is_del___get__(o);
29076 }
29077
29078 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_head(PyObject *o, void *x) {
29079   return __pyx_pf_9csamtools_10PileupRead_7is_head___get__(o);
29080 }
29081
29082 static PyObject *__pyx_getprop_9csamtools_10PileupRead_is_tail(PyObject *o, void *x) {
29083   return __pyx_pf_9csamtools_10PileupRead_7is_tail___get__(o);
29084 }
29085
29086 static PyObject *__pyx_getprop_9csamtools_10PileupRead_level(PyObject *o, void *x) {
29087   return __pyx_pf_9csamtools_10PileupRead_5level___get__(o);
29088 }
29089
29090 static PyMethodDef __pyx_methods_9csamtools_PileupRead[] = {
29091   {0, 0, 0, 0}
29092 };
29093
29094 static struct PyGetSetDef __pyx_getsets_9csamtools_PileupRead[] = {
29095   {(char *)"alignment", __pyx_getprop_9csamtools_10PileupRead_alignment, 0, __Pyx_DOCSTR(__pyx_k_217), 0},
29096   {(char *)"qpos", __pyx_getprop_9csamtools_10PileupRead_qpos, 0, __Pyx_DOCSTR(__pyx_k_218), 0},
29097   {(char *)"indel", __pyx_getprop_9csamtools_10PileupRead_indel, 0, __Pyx_DOCSTR(__pyx_k_219), 0},
29098   {(char *)"is_del", __pyx_getprop_9csamtools_10PileupRead_is_del, 0, __Pyx_DOCSTR(__pyx_k_220), 0},
29099   {(char *)"is_head", __pyx_getprop_9csamtools_10PileupRead_is_head, 0, 0, 0},
29100   {(char *)"is_tail", __pyx_getprop_9csamtools_10PileupRead_is_tail, 0, 0, 0},
29101   {(char *)"level", __pyx_getprop_9csamtools_10PileupRead_level, 0, 0, 0},
29102   {0, 0, 0, 0, 0}
29103 };
29104
29105 static PyNumberMethods __pyx_tp_as_number_PileupRead = {
29106   0, /*nb_add*/
29107   0, /*nb_subtract*/
29108   0, /*nb_multiply*/
29109   #if PY_MAJOR_VERSION < 3
29110   0, /*nb_divide*/
29111   #endif
29112   0, /*nb_remainder*/
29113   0, /*nb_divmod*/
29114   0, /*nb_power*/
29115   0, /*nb_negative*/
29116   0, /*nb_positive*/
29117   0, /*nb_absolute*/
29118   0, /*nb_nonzero*/
29119   0, /*nb_invert*/
29120   0, /*nb_lshift*/
29121   0, /*nb_rshift*/
29122   0, /*nb_and*/
29123   0, /*nb_xor*/
29124   0, /*nb_or*/
29125   #if PY_MAJOR_VERSION < 3
29126   0, /*nb_coerce*/
29127   #endif
29128   0, /*nb_int*/
29129   #if PY_MAJOR_VERSION < 3
29130   0, /*nb_long*/
29131   #else
29132   0, /*reserved*/
29133   #endif
29134   0, /*nb_float*/
29135   #if PY_MAJOR_VERSION < 3
29136   0, /*nb_oct*/
29137   #endif
29138   #if PY_MAJOR_VERSION < 3
29139   0, /*nb_hex*/
29140   #endif
29141   0, /*nb_inplace_add*/
29142   0, /*nb_inplace_subtract*/
29143   0, /*nb_inplace_multiply*/
29144   #if PY_MAJOR_VERSION < 3
29145   0, /*nb_inplace_divide*/
29146   #endif
29147   0, /*nb_inplace_remainder*/
29148   0, /*nb_inplace_power*/
29149   0, /*nb_inplace_lshift*/
29150   0, /*nb_inplace_rshift*/
29151   0, /*nb_inplace_and*/
29152   0, /*nb_inplace_xor*/
29153   0, /*nb_inplace_or*/
29154   0, /*nb_floor_divide*/
29155   0, /*nb_true_divide*/
29156   0, /*nb_inplace_floor_divide*/
29157   0, /*nb_inplace_true_divide*/
29158   #if PY_VERSION_HEX >= 0x02050000
29159   0, /*nb_index*/
29160   #endif
29161 };
29162
29163 static PySequenceMethods __pyx_tp_as_sequence_PileupRead = {
29164   0, /*sq_length*/
29165   0, /*sq_concat*/
29166   0, /*sq_repeat*/
29167   0, /*sq_item*/
29168   0, /*sq_slice*/
29169   0, /*sq_ass_item*/
29170   0, /*sq_ass_slice*/
29171   0, /*sq_contains*/
29172   0, /*sq_inplace_concat*/
29173   0, /*sq_inplace_repeat*/
29174 };
29175
29176 static PyMappingMethods __pyx_tp_as_mapping_PileupRead = {
29177   0, /*mp_length*/
29178   0, /*mp_subscript*/
29179   0, /*mp_ass_subscript*/
29180 };
29181
29182 static PyBufferProcs __pyx_tp_as_buffer_PileupRead = {
29183   #if PY_MAJOR_VERSION < 3
29184   0, /*bf_getreadbuffer*/
29185   #endif
29186   #if PY_MAJOR_VERSION < 3
29187   0, /*bf_getwritebuffer*/
29188   #endif
29189   #if PY_MAJOR_VERSION < 3
29190   0, /*bf_getsegcount*/
29191   #endif
29192   #if PY_MAJOR_VERSION < 3
29193   0, /*bf_getcharbuffer*/
29194   #endif
29195   #if PY_VERSION_HEX >= 0x02060000
29196   0, /*bf_getbuffer*/
29197   #endif
29198   #if PY_VERSION_HEX >= 0x02060000
29199   0, /*bf_releasebuffer*/
29200   #endif
29201 };
29202
29203 static PyTypeObject __pyx_type_9csamtools_PileupRead = {
29204   PyVarObject_HEAD_INIT(0, 0)
29205   __Pyx_NAMESTR("csamtools.PileupRead"), /*tp_name*/
29206   sizeof(struct __pyx_obj_9csamtools_PileupRead), /*tp_basicsize*/
29207   0, /*tp_itemsize*/
29208   __pyx_tp_dealloc_9csamtools_PileupRead, /*tp_dealloc*/
29209   0, /*tp_print*/
29210   0, /*tp_getattr*/
29211   0, /*tp_setattr*/
29212   #if PY_MAJOR_VERSION < 3
29213   0, /*tp_compare*/
29214   #else
29215   0, /*reserved*/
29216   #endif
29217   0, /*tp_repr*/
29218   &__pyx_tp_as_number_PileupRead, /*tp_as_number*/
29219   &__pyx_tp_as_sequence_PileupRead, /*tp_as_sequence*/
29220   &__pyx_tp_as_mapping_PileupRead, /*tp_as_mapping*/
29221   0, /*tp_hash*/
29222   0, /*tp_call*/
29223   __pyx_pf_9csamtools_10PileupRead_1__str__, /*tp_str*/
29224   0, /*tp_getattro*/
29225   0, /*tp_setattro*/
29226   &__pyx_tp_as_buffer_PileupRead, /*tp_as_buffer*/
29227   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
29228   __Pyx_DOCSTR("PileupRead()\nA read aligned to a column.\n    "), /*tp_doc*/
29229   __pyx_tp_traverse_9csamtools_PileupRead, /*tp_traverse*/
29230   __pyx_tp_clear_9csamtools_PileupRead, /*tp_clear*/
29231   0, /*tp_richcompare*/
29232   0, /*tp_weaklistoffset*/
29233   0, /*tp_iter*/
29234   0, /*tp_iternext*/
29235   __pyx_methods_9csamtools_PileupRead, /*tp_methods*/
29236   0, /*tp_members*/
29237   __pyx_getsets_9csamtools_PileupRead, /*tp_getset*/
29238   0, /*tp_base*/
29239   0, /*tp_dict*/
29240   0, /*tp_descr_get*/
29241   0, /*tp_descr_set*/
29242   0, /*tp_dictoffset*/
29243   __pyx_pf_9csamtools_10PileupRead___init__, /*tp_init*/
29244   0, /*tp_alloc*/
29245   __pyx_tp_new_9csamtools_PileupRead, /*tp_new*/
29246   0, /*tp_free*/
29247   0, /*tp_is_gc*/
29248   0, /*tp_bases*/
29249   0, /*tp_mro*/
29250   0, /*tp_cache*/
29251   0, /*tp_subclasses*/
29252   0, /*tp_weaklist*/
29253   0, /*tp_del*/
29254   #if PY_VERSION_HEX >= 0x02060000
29255   0, /*tp_version_tag*/
29256   #endif
29257 };
29258 static struct __pyx_vtabstruct_9csamtools_Fastafile __pyx_vtable_9csamtools_Fastafile;
29259
29260 static PyObject *__pyx_tp_new_9csamtools_Fastafile(PyTypeObject *t, PyObject *a, PyObject *k) {
29261   struct __pyx_obj_9csamtools_Fastafile *p;
29262   PyObject *o = (*t->tp_alloc)(t, 0);
29263   if (!o) return 0;
29264   p = ((struct __pyx_obj_9csamtools_Fastafile *)o);
29265   p->__pyx_vtab = __pyx_vtabptr_9csamtools_Fastafile;
29266   if (__pyx_pf_9csamtools_9Fastafile___cinit__(o, a, k) < 0) {
29267     Py_DECREF(o); o = 0;
29268   }
29269   return o;
29270 }
29271
29272 static void __pyx_tp_dealloc_9csamtools_Fastafile(PyObject *o) {
29273   {
29274     PyObject *etype, *eval, *etb;
29275     PyErr_Fetch(&etype, &eval, &etb);
29276     ++Py_REFCNT(o);
29277     __pyx_pf_9csamtools_9Fastafile_5__dealloc__(o);
29278     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
29279     --Py_REFCNT(o);
29280     PyErr_Restore(etype, eval, etb);
29281   }
29282   (*Py_TYPE(o)->tp_free)(o);
29283 }
29284
29285 static PyObject *__pyx_getprop_9csamtools_9Fastafile_filename(PyObject *o, void *x) {
29286   return __pyx_pf_9csamtools_9Fastafile_8filename___get__(o);
29287 }
29288
29289 static PyMethodDef __pyx_methods_9csamtools_Fastafile[] = {
29290   {__Pyx_NAMESTR("_isOpen"), (PyCFunction)__pyx_pf_9csamtools_9Fastafile_1_isOpen, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_1_isOpen)},
29291   {__Pyx_NAMESTR("_open"), (PyCFunction)__pyx_pf_9csamtools_9Fastafile_3_open, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_3_open)},
29292   {__Pyx_NAMESTR("close"), (PyCFunction)__pyx_pf_9csamtools_9Fastafile_4close, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_4close)},
29293   {__Pyx_NAMESTR("fetch"), (PyCFunction)__pyx_pf_9csamtools_9Fastafile_6fetch, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_9csamtools_9Fastafile_6fetch)},
29294   {0, 0, 0, 0}
29295 };
29296
29297 static struct PyGetSetDef __pyx_getsets_9csamtools_Fastafile[] = {
29298   {(char *)"filename", __pyx_getprop_9csamtools_9Fastafile_filename, 0, __Pyx_DOCSTR(__pyx_k_206), 0},
29299   {0, 0, 0, 0, 0}
29300 };
29301
29302 static PyNumberMethods __pyx_tp_as_number_Fastafile = {
29303   0, /*nb_add*/
29304   0, /*nb_subtract*/
29305   0, /*nb_multiply*/
29306   #if PY_MAJOR_VERSION < 3
29307   0, /*nb_divide*/
29308   #endif
29309   0, /*nb_remainder*/
29310   0, /*nb_divmod*/
29311   0, /*nb_power*/
29312   0, /*nb_negative*/
29313   0, /*nb_positive*/
29314   0, /*nb_absolute*/
29315   0, /*nb_nonzero*/
29316   0, /*nb_invert*/
29317   0, /*nb_lshift*/
29318   0, /*nb_rshift*/
29319   0, /*nb_and*/
29320   0, /*nb_xor*/
29321   0, /*nb_or*/
29322   #if PY_MAJOR_VERSION < 3
29323   0, /*nb_coerce*/
29324   #endif
29325   0, /*nb_int*/
29326   #if PY_MAJOR_VERSION < 3
29327   0, /*nb_long*/
29328   #else
29329   0, /*reserved*/
29330   #endif
29331   0, /*nb_float*/
29332   #if PY_MAJOR_VERSION < 3
29333   0, /*nb_oct*/
29334   #endif
29335   #if PY_MAJOR_VERSION < 3
29336   0, /*nb_hex*/
29337   #endif
29338   0, /*nb_inplace_add*/
29339   0, /*nb_inplace_subtract*/
29340   0, /*nb_inplace_multiply*/
29341   #if PY_MAJOR_VERSION < 3
29342   0, /*nb_inplace_divide*/
29343   #endif
29344   0, /*nb_inplace_remainder*/
29345   0, /*nb_inplace_power*/
29346   0, /*nb_inplace_lshift*/
29347   0, /*nb_inplace_rshift*/
29348   0, /*nb_inplace_and*/
29349   0, /*nb_inplace_xor*/
29350   0, /*nb_inplace_or*/
29351   0, /*nb_floor_divide*/
29352   0, /*nb_true_divide*/
29353   0, /*nb_inplace_floor_divide*/
29354   0, /*nb_inplace_true_divide*/
29355   #if PY_VERSION_HEX >= 0x02050000
29356   0, /*nb_index*/
29357   #endif
29358 };
29359
29360 static PySequenceMethods __pyx_tp_as_sequence_Fastafile = {
29361   __pyx_pf_9csamtools_9Fastafile_2__len__, /*sq_length*/
29362   0, /*sq_concat*/
29363   0, /*sq_repeat*/
29364   0, /*sq_item*/
29365   0, /*sq_slice*/
29366   0, /*sq_ass_item*/
29367   0, /*sq_ass_slice*/
29368   0, /*sq_contains*/
29369   0, /*sq_inplace_concat*/
29370   0, /*sq_inplace_repeat*/
29371 };
29372
29373 static PyMappingMethods __pyx_tp_as_mapping_Fastafile = {
29374   __pyx_pf_9csamtools_9Fastafile_2__len__, /*mp_length*/
29375   0, /*mp_subscript*/
29376   0, /*mp_ass_subscript*/
29377 };
29378
29379 static PyBufferProcs __pyx_tp_as_buffer_Fastafile = {
29380   #if PY_MAJOR_VERSION < 3
29381   0, /*bf_getreadbuffer*/
29382   #endif
29383   #if PY_MAJOR_VERSION < 3
29384   0, /*bf_getwritebuffer*/
29385   #endif
29386   #if PY_MAJOR_VERSION < 3
29387   0, /*bf_getsegcount*/
29388   #endif
29389   #if PY_MAJOR_VERSION < 3
29390   0, /*bf_getcharbuffer*/
29391   #endif
29392   #if PY_VERSION_HEX >= 0x02060000
29393   0, /*bf_getbuffer*/
29394   #endif
29395   #if PY_VERSION_HEX >= 0x02060000
29396   0, /*bf_releasebuffer*/
29397   #endif
29398 };
29399
29400 static PyTypeObject __pyx_type_9csamtools_Fastafile = {
29401   PyVarObject_HEAD_INIT(0, 0)
29402   __Pyx_NAMESTR("csamtools.Fastafile"), /*tp_name*/
29403   sizeof(struct __pyx_obj_9csamtools_Fastafile), /*tp_basicsize*/
29404   0, /*tp_itemsize*/
29405   __pyx_tp_dealloc_9csamtools_Fastafile, /*tp_dealloc*/
29406   0, /*tp_print*/
29407   0, /*tp_getattr*/
29408   0, /*tp_setattr*/
29409   #if PY_MAJOR_VERSION < 3
29410   0, /*tp_compare*/
29411   #else
29412   0, /*reserved*/
29413   #endif
29414   0, /*tp_repr*/
29415   &__pyx_tp_as_number_Fastafile, /*tp_as_number*/
29416   &__pyx_tp_as_sequence_Fastafile, /*tp_as_sequence*/
29417   &__pyx_tp_as_mapping_Fastafile, /*tp_as_mapping*/
29418   0, /*tp_hash*/
29419   0, /*tp_call*/
29420   0, /*tp_str*/
29421   0, /*tp_getattro*/
29422   0, /*tp_setattro*/
29423   &__pyx_tp_as_buffer_Fastafile, /*tp_as_buffer*/
29424   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
29425   __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*/
29426   0, /*tp_traverse*/
29427   0, /*tp_clear*/
29428   0, /*tp_richcompare*/
29429   0, /*tp_weaklistoffset*/
29430   0, /*tp_iter*/
29431   0, /*tp_iternext*/
29432   __pyx_methods_9csamtools_Fastafile, /*tp_methods*/
29433   0, /*tp_members*/
29434   __pyx_getsets_9csamtools_Fastafile, /*tp_getset*/
29435   0, /*tp_base*/
29436   0, /*tp_dict*/
29437   0, /*tp_descr_get*/
29438   0, /*tp_descr_set*/
29439   0, /*tp_dictoffset*/
29440   0, /*tp_init*/
29441   0, /*tp_alloc*/
29442   __pyx_tp_new_9csamtools_Fastafile, /*tp_new*/
29443   0, /*tp_free*/
29444   0, /*tp_is_gc*/
29445   0, /*tp_bases*/
29446   0, /*tp_mro*/
29447   0, /*tp_cache*/
29448   0, /*tp_subclasses*/
29449   0, /*tp_weaklist*/
29450   0, /*tp_del*/
29451   #if PY_VERSION_HEX >= 0x02060000
29452   0, /*tp_version_tag*/
29453   #endif
29454 };
29455 static struct __pyx_vtabstruct_9csamtools_IteratorRowRegion __pyx_vtable_9csamtools_IteratorRowRegion;
29456
29457 static PyObject *__pyx_tp_new_9csamtools_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
29458   struct __pyx_obj_9csamtools_IteratorRowRegion *p;
29459   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
29460   if (!o) return 0;
29461   p = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)o);
29462   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowRegion;
29463   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
29464   if (__pyx_pf_9csamtools_17IteratorRowRegion___cinit__(o, a, k) < 0) {
29465     Py_DECREF(o); o = 0;
29466   }
29467   return o;
29468 }
29469
29470 static void __pyx_tp_dealloc_9csamtools_IteratorRowRegion(PyObject *o) {
29471   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
29472   {
29473     PyObject *etype, *eval, *etb;
29474     PyErr_Fetch(&etype, &eval, &etb);
29475     ++Py_REFCNT(o);
29476     __pyx_pf_9csamtools_17IteratorRowRegion_3__dealloc__(o);
29477     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
29478     --Py_REFCNT(o);
29479     PyErr_Restore(etype, eval, etb);
29480   }
29481   Py_XDECREF(((PyObject *)p->samfile));
29482   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
29483 }
29484
29485 static int __pyx_tp_traverse_9csamtools_IteratorRowRegion(PyObject *o, visitproc v, void *a) {
29486   int e;
29487   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
29488   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
29489     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
29490   }
29491   if (p->samfile) {
29492     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
29493   }
29494   return 0;
29495 }
29496
29497 static int __pyx_tp_clear_9csamtools_IteratorRowRegion(PyObject *o) {
29498   struct __pyx_obj_9csamtools_IteratorRowRegion *p = (struct __pyx_obj_9csamtools_IteratorRowRegion *)o;
29499   PyObject* tmp;
29500   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
29501     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
29502   }
29503   tmp = ((PyObject*)p->samfile);
29504   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
29505   Py_XDECREF(tmp);
29506   return 0;
29507 }
29508
29509 static PyMethodDef __pyx_methods_9csamtools_IteratorRowRegion[] = {
29510   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_17IteratorRowRegion_2__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_17IteratorRowRegion_2__next__)},
29511   {0, 0, 0, 0}
29512 };
29513
29514 static PyNumberMethods __pyx_tp_as_number_IteratorRowRegion = {
29515   0, /*nb_add*/
29516   0, /*nb_subtract*/
29517   0, /*nb_multiply*/
29518   #if PY_MAJOR_VERSION < 3
29519   0, /*nb_divide*/
29520   #endif
29521   0, /*nb_remainder*/
29522   0, /*nb_divmod*/
29523   0, /*nb_power*/
29524   0, /*nb_negative*/
29525   0, /*nb_positive*/
29526   0, /*nb_absolute*/
29527   0, /*nb_nonzero*/
29528   0, /*nb_invert*/
29529   0, /*nb_lshift*/
29530   0, /*nb_rshift*/
29531   0, /*nb_and*/
29532   0, /*nb_xor*/
29533   0, /*nb_or*/
29534   #if PY_MAJOR_VERSION < 3
29535   0, /*nb_coerce*/
29536   #endif
29537   0, /*nb_int*/
29538   #if PY_MAJOR_VERSION < 3
29539   0, /*nb_long*/
29540   #else
29541   0, /*reserved*/
29542   #endif
29543   0, /*nb_float*/
29544   #if PY_MAJOR_VERSION < 3
29545   0, /*nb_oct*/
29546   #endif
29547   #if PY_MAJOR_VERSION < 3
29548   0, /*nb_hex*/
29549   #endif
29550   0, /*nb_inplace_add*/
29551   0, /*nb_inplace_subtract*/
29552   0, /*nb_inplace_multiply*/
29553   #if PY_MAJOR_VERSION < 3
29554   0, /*nb_inplace_divide*/
29555   #endif
29556   0, /*nb_inplace_remainder*/
29557   0, /*nb_inplace_power*/
29558   0, /*nb_inplace_lshift*/
29559   0, /*nb_inplace_rshift*/
29560   0, /*nb_inplace_and*/
29561   0, /*nb_inplace_xor*/
29562   0, /*nb_inplace_or*/
29563   0, /*nb_floor_divide*/
29564   0, /*nb_true_divide*/
29565   0, /*nb_inplace_floor_divide*/
29566   0, /*nb_inplace_true_divide*/
29567   #if PY_VERSION_HEX >= 0x02050000
29568   0, /*nb_index*/
29569   #endif
29570 };
29571
29572 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowRegion = {
29573   0, /*sq_length*/
29574   0, /*sq_concat*/
29575   0, /*sq_repeat*/
29576   0, /*sq_item*/
29577   0, /*sq_slice*/
29578   0, /*sq_ass_item*/
29579   0, /*sq_ass_slice*/
29580   0, /*sq_contains*/
29581   0, /*sq_inplace_concat*/
29582   0, /*sq_inplace_repeat*/
29583 };
29584
29585 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowRegion = {
29586   0, /*mp_length*/
29587   0, /*mp_subscript*/
29588   0, /*mp_ass_subscript*/
29589 };
29590
29591 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowRegion = {
29592   #if PY_MAJOR_VERSION < 3
29593   0, /*bf_getreadbuffer*/
29594   #endif
29595   #if PY_MAJOR_VERSION < 3
29596   0, /*bf_getwritebuffer*/
29597   #endif
29598   #if PY_MAJOR_VERSION < 3
29599   0, /*bf_getsegcount*/
29600   #endif
29601   #if PY_MAJOR_VERSION < 3
29602   0, /*bf_getcharbuffer*/
29603   #endif
29604   #if PY_VERSION_HEX >= 0x02060000
29605   0, /*bf_getbuffer*/
29606   #endif
29607   #if PY_VERSION_HEX >= 0x02060000
29608   0, /*bf_releasebuffer*/
29609   #endif
29610 };
29611
29612 static PyTypeObject __pyx_type_9csamtools_IteratorRowRegion = {
29613   PyVarObject_HEAD_INIT(0, 0)
29614   __Pyx_NAMESTR("csamtools.IteratorRowRegion"), /*tp_name*/
29615   sizeof(struct __pyx_obj_9csamtools_IteratorRowRegion), /*tp_basicsize*/
29616   0, /*tp_itemsize*/
29617   __pyx_tp_dealloc_9csamtools_IteratorRowRegion, /*tp_dealloc*/
29618   0, /*tp_print*/
29619   0, /*tp_getattr*/
29620   0, /*tp_setattr*/
29621   #if PY_MAJOR_VERSION < 3
29622   0, /*tp_compare*/
29623   #else
29624   0, /*reserved*/
29625   #endif
29626   0, /*tp_repr*/
29627   &__pyx_tp_as_number_IteratorRowRegion, /*tp_as_number*/
29628   &__pyx_tp_as_sequence_IteratorRowRegion, /*tp_as_sequence*/
29629   &__pyx_tp_as_mapping_IteratorRowRegion, /*tp_as_mapping*/
29630   0, /*tp_hash*/
29631   0, /*tp_call*/
29632   0, /*tp_str*/
29633   0, /*tp_getattro*/
29634   0, /*tp_setattro*/
29635   &__pyx_tp_as_buffer_IteratorRowRegion, /*tp_as_buffer*/
29636   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
29637   __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*/
29638   __pyx_tp_traverse_9csamtools_IteratorRowRegion, /*tp_traverse*/
29639   __pyx_tp_clear_9csamtools_IteratorRowRegion, /*tp_clear*/
29640   0, /*tp_richcompare*/
29641   0, /*tp_weaklistoffset*/
29642   __pyx_pf_9csamtools_17IteratorRowRegion_1__iter__, /*tp_iter*/
29643   __pyx_pf_9csamtools_17IteratorRowRegion_2__next__, /*tp_iternext*/
29644   __pyx_methods_9csamtools_IteratorRowRegion, /*tp_methods*/
29645   0, /*tp_members*/
29646   0, /*tp_getset*/
29647   0, /*tp_base*/
29648   0, /*tp_dict*/
29649   0, /*tp_descr_get*/
29650   0, /*tp_descr_set*/
29651   0, /*tp_dictoffset*/
29652   0, /*tp_init*/
29653   0, /*tp_alloc*/
29654   __pyx_tp_new_9csamtools_IteratorRowRegion, /*tp_new*/
29655   0, /*tp_free*/
29656   0, /*tp_is_gc*/
29657   0, /*tp_bases*/
29658   0, /*tp_mro*/
29659   0, /*tp_cache*/
29660   0, /*tp_subclasses*/
29661   0, /*tp_weaklist*/
29662   0, /*tp_del*/
29663   #if PY_VERSION_HEX >= 0x02060000
29664   0, /*tp_version_tag*/
29665   #endif
29666 };
29667
29668 static PyObject *__pyx_tp_new_9csamtools_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
29669   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p;
29670   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
29671   if (!o) return 0;
29672   p = ((struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o);
29673   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
29674   p->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
29675   if (__pyx_pf_9csamtools_18IteratorRowAllRefs___cinit__(o, a, k) < 0) {
29676     Py_DECREF(o); o = 0;
29677   }
29678   return o;
29679 }
29680
29681 static void __pyx_tp_dealloc_9csamtools_IteratorRowAllRefs(PyObject *o) {
29682   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
29683   Py_XDECREF(((PyObject *)p->samfile));
29684   Py_XDECREF(((PyObject *)p->rowiter));
29685   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
29686 }
29687
29688 static int __pyx_tp_traverse_9csamtools_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
29689   int e;
29690   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
29691   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
29692     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
29693   }
29694   if (p->samfile) {
29695     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
29696   }
29697   if (p->rowiter) {
29698     e = (*v)(((PyObject*)p->rowiter), a); if (e) return e;
29699   }
29700   return 0;
29701 }
29702
29703 static int __pyx_tp_clear_9csamtools_IteratorRowAllRefs(PyObject *o) {
29704   struct __pyx_obj_9csamtools_IteratorRowAllRefs *p = (struct __pyx_obj_9csamtools_IteratorRowAllRefs *)o;
29705   PyObject* tmp;
29706   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
29707     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
29708   }
29709   tmp = ((PyObject*)p->samfile);
29710   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
29711   Py_XDECREF(tmp);
29712   tmp = ((PyObject*)p->rowiter);
29713   p->rowiter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
29714   Py_XDECREF(tmp);
29715   return 0;
29716 }
29717
29718 static PyMethodDef __pyx_methods_9csamtools_IteratorRowAllRefs[] = {
29719   {__Pyx_NAMESTR("nextiter"), (PyCFunction)__pyx_pf_9csamtools_18IteratorRowAllRefs_1nextiter, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_18IteratorRowAllRefs_1nextiter)},
29720   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_18IteratorRowAllRefs_3__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_18IteratorRowAllRefs_3__next__)},
29721   {0, 0, 0, 0}
29722 };
29723
29724 static PyNumberMethods __pyx_tp_as_number_IteratorRowAllRefs = {
29725   0, /*nb_add*/
29726   0, /*nb_subtract*/
29727   0, /*nb_multiply*/
29728   #if PY_MAJOR_VERSION < 3
29729   0, /*nb_divide*/
29730   #endif
29731   0, /*nb_remainder*/
29732   0, /*nb_divmod*/
29733   0, /*nb_power*/
29734   0, /*nb_negative*/
29735   0, /*nb_positive*/
29736   0, /*nb_absolute*/
29737   0, /*nb_nonzero*/
29738   0, /*nb_invert*/
29739   0, /*nb_lshift*/
29740   0, /*nb_rshift*/
29741   0, /*nb_and*/
29742   0, /*nb_xor*/
29743   0, /*nb_or*/
29744   #if PY_MAJOR_VERSION < 3
29745   0, /*nb_coerce*/
29746   #endif
29747   0, /*nb_int*/
29748   #if PY_MAJOR_VERSION < 3
29749   0, /*nb_long*/
29750   #else
29751   0, /*reserved*/
29752   #endif
29753   0, /*nb_float*/
29754   #if PY_MAJOR_VERSION < 3
29755   0, /*nb_oct*/
29756   #endif
29757   #if PY_MAJOR_VERSION < 3
29758   0, /*nb_hex*/
29759   #endif
29760   0, /*nb_inplace_add*/
29761   0, /*nb_inplace_subtract*/
29762   0, /*nb_inplace_multiply*/
29763   #if PY_MAJOR_VERSION < 3
29764   0, /*nb_inplace_divide*/
29765   #endif
29766   0, /*nb_inplace_remainder*/
29767   0, /*nb_inplace_power*/
29768   0, /*nb_inplace_lshift*/
29769   0, /*nb_inplace_rshift*/
29770   0, /*nb_inplace_and*/
29771   0, /*nb_inplace_xor*/
29772   0, /*nb_inplace_or*/
29773   0, /*nb_floor_divide*/
29774   0, /*nb_true_divide*/
29775   0, /*nb_inplace_floor_divide*/
29776   0, /*nb_inplace_true_divide*/
29777   #if PY_VERSION_HEX >= 0x02050000
29778   0, /*nb_index*/
29779   #endif
29780 };
29781
29782 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowAllRefs = {
29783   0, /*sq_length*/
29784   0, /*sq_concat*/
29785   0, /*sq_repeat*/
29786   0, /*sq_item*/
29787   0, /*sq_slice*/
29788   0, /*sq_ass_item*/
29789   0, /*sq_ass_slice*/
29790   0, /*sq_contains*/
29791   0, /*sq_inplace_concat*/
29792   0, /*sq_inplace_repeat*/
29793 };
29794
29795 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowAllRefs = {
29796   0, /*mp_length*/
29797   0, /*mp_subscript*/
29798   0, /*mp_ass_subscript*/
29799 };
29800
29801 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowAllRefs = {
29802   #if PY_MAJOR_VERSION < 3
29803   0, /*bf_getreadbuffer*/
29804   #endif
29805   #if PY_MAJOR_VERSION < 3
29806   0, /*bf_getwritebuffer*/
29807   #endif
29808   #if PY_MAJOR_VERSION < 3
29809   0, /*bf_getsegcount*/
29810   #endif
29811   #if PY_MAJOR_VERSION < 3
29812   0, /*bf_getcharbuffer*/
29813   #endif
29814   #if PY_VERSION_HEX >= 0x02060000
29815   0, /*bf_getbuffer*/
29816   #endif
29817   #if PY_VERSION_HEX >= 0x02060000
29818   0, /*bf_releasebuffer*/
29819   #endif
29820 };
29821
29822 static PyTypeObject __pyx_type_9csamtools_IteratorRowAllRefs = {
29823   PyVarObject_HEAD_INIT(0, 0)
29824   __Pyx_NAMESTR("csamtools.IteratorRowAllRefs"), /*tp_name*/
29825   sizeof(struct __pyx_obj_9csamtools_IteratorRowAllRefs), /*tp_basicsize*/
29826   0, /*tp_itemsize*/
29827   __pyx_tp_dealloc_9csamtools_IteratorRowAllRefs, /*tp_dealloc*/
29828   0, /*tp_print*/
29829   0, /*tp_getattr*/
29830   0, /*tp_setattr*/
29831   #if PY_MAJOR_VERSION < 3
29832   0, /*tp_compare*/
29833   #else
29834   0, /*reserved*/
29835   #endif
29836   0, /*tp_repr*/
29837   &__pyx_tp_as_number_IteratorRowAllRefs, /*tp_as_number*/
29838   &__pyx_tp_as_sequence_IteratorRowAllRefs, /*tp_as_sequence*/
29839   &__pyx_tp_as_mapping_IteratorRowAllRefs, /*tp_as_mapping*/
29840   0, /*tp_hash*/
29841   0, /*tp_call*/
29842   0, /*tp_str*/
29843   0, /*tp_getattro*/
29844   0, /*tp_setattro*/
29845   &__pyx_tp_as_buffer_IteratorRowAllRefs, /*tp_as_buffer*/
29846   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
29847   __Pyx_DOCSTR("iterates over all mapped reads by chaining iterators over each reference\n    "), /*tp_doc*/
29848   __pyx_tp_traverse_9csamtools_IteratorRowAllRefs, /*tp_traverse*/
29849   __pyx_tp_clear_9csamtools_IteratorRowAllRefs, /*tp_clear*/
29850   0, /*tp_richcompare*/
29851   0, /*tp_weaklistoffset*/
29852   __pyx_pf_9csamtools_18IteratorRowAllRefs_2__iter__, /*tp_iter*/
29853   __pyx_pf_9csamtools_18IteratorRowAllRefs_3__next__, /*tp_iternext*/
29854   __pyx_methods_9csamtools_IteratorRowAllRefs, /*tp_methods*/
29855   0, /*tp_members*/
29856   0, /*tp_getset*/
29857   0, /*tp_base*/
29858   0, /*tp_dict*/
29859   0, /*tp_descr_get*/
29860   0, /*tp_descr_set*/
29861   0, /*tp_dictoffset*/
29862   0, /*tp_init*/
29863   0, /*tp_alloc*/
29864   __pyx_tp_new_9csamtools_IteratorRowAllRefs, /*tp_new*/
29865   0, /*tp_free*/
29866   0, /*tp_is_gc*/
29867   0, /*tp_bases*/
29868   0, /*tp_mro*/
29869   0, /*tp_cache*/
29870   0, /*tp_subclasses*/
29871   0, /*tp_weaklist*/
29872   0, /*tp_del*/
29873   #if PY_VERSION_HEX >= 0x02060000
29874   0, /*tp_version_tag*/
29875   #endif
29876 };
29877 static struct __pyx_vtabstruct_9csamtools_IteratorRowSelection __pyx_vtable_9csamtools_IteratorRowSelection;
29878
29879 static PyObject *__pyx_tp_new_9csamtools_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
29880   struct __pyx_obj_9csamtools_IteratorRowSelection *p;
29881   PyObject *o = __pyx_tp_new_9csamtools_IteratorRow(t, a, k);
29882   if (!o) return 0;
29883   p = ((struct __pyx_obj_9csamtools_IteratorRowSelection *)o);
29884   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorRowSelection;
29885   p->positions = Py_None; Py_INCREF(Py_None);
29886   if (__pyx_pf_9csamtools_20IteratorRowSelection___cinit__(o, a, k) < 0) {
29887     Py_DECREF(o); o = 0;
29888   }
29889   return o;
29890 }
29891
29892 static void __pyx_tp_dealloc_9csamtools_IteratorRowSelection(PyObject *o) {
29893   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
29894   {
29895     PyObject *etype, *eval, *etb;
29896     PyErr_Fetch(&etype, &eval, &etb);
29897     ++Py_REFCNT(o);
29898     __pyx_pf_9csamtools_20IteratorRowSelection_3__dealloc__(o);
29899     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
29900     --Py_REFCNT(o);
29901     PyErr_Restore(etype, eval, etb);
29902   }
29903   Py_XDECREF(p->positions);
29904   __pyx_tp_dealloc_9csamtools_IteratorRow(o);
29905 }
29906
29907 static int __pyx_tp_traverse_9csamtools_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
29908   int e;
29909   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
29910   if (__pyx_ptype_9csamtools_IteratorRow->tp_traverse) {
29911     e = __pyx_ptype_9csamtools_IteratorRow->tp_traverse(o, v, a); if (e) return e;
29912   }
29913   if (p->positions) {
29914     e = (*v)(p->positions, a); if (e) return e;
29915   }
29916   return 0;
29917 }
29918
29919 static int __pyx_tp_clear_9csamtools_IteratorRowSelection(PyObject *o) {
29920   struct __pyx_obj_9csamtools_IteratorRowSelection *p = (struct __pyx_obj_9csamtools_IteratorRowSelection *)o;
29921   PyObject* tmp;
29922   if (__pyx_ptype_9csamtools_IteratorRow->tp_clear) {
29923     __pyx_ptype_9csamtools_IteratorRow->tp_clear(o);
29924   }
29925   tmp = ((PyObject*)p->positions);
29926   p->positions = Py_None; Py_INCREF(Py_None);
29927   Py_XDECREF(tmp);
29928   return 0;
29929 }
29930
29931 static PyMethodDef __pyx_methods_9csamtools_IteratorRowSelection[] = {
29932   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_20IteratorRowSelection_2__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_20IteratorRowSelection_2__next__)},
29933   {0, 0, 0, 0}
29934 };
29935
29936 static PyNumberMethods __pyx_tp_as_number_IteratorRowSelection = {
29937   0, /*nb_add*/
29938   0, /*nb_subtract*/
29939   0, /*nb_multiply*/
29940   #if PY_MAJOR_VERSION < 3
29941   0, /*nb_divide*/
29942   #endif
29943   0, /*nb_remainder*/
29944   0, /*nb_divmod*/
29945   0, /*nb_power*/
29946   0, /*nb_negative*/
29947   0, /*nb_positive*/
29948   0, /*nb_absolute*/
29949   0, /*nb_nonzero*/
29950   0, /*nb_invert*/
29951   0, /*nb_lshift*/
29952   0, /*nb_rshift*/
29953   0, /*nb_and*/
29954   0, /*nb_xor*/
29955   0, /*nb_or*/
29956   #if PY_MAJOR_VERSION < 3
29957   0, /*nb_coerce*/
29958   #endif
29959   0, /*nb_int*/
29960   #if PY_MAJOR_VERSION < 3
29961   0, /*nb_long*/
29962   #else
29963   0, /*reserved*/
29964   #endif
29965   0, /*nb_float*/
29966   #if PY_MAJOR_VERSION < 3
29967   0, /*nb_oct*/
29968   #endif
29969   #if PY_MAJOR_VERSION < 3
29970   0, /*nb_hex*/
29971   #endif
29972   0, /*nb_inplace_add*/
29973   0, /*nb_inplace_subtract*/
29974   0, /*nb_inplace_multiply*/
29975   #if PY_MAJOR_VERSION < 3
29976   0, /*nb_inplace_divide*/
29977   #endif
29978   0, /*nb_inplace_remainder*/
29979   0, /*nb_inplace_power*/
29980   0, /*nb_inplace_lshift*/
29981   0, /*nb_inplace_rshift*/
29982   0, /*nb_inplace_and*/
29983   0, /*nb_inplace_xor*/
29984   0, /*nb_inplace_or*/
29985   0, /*nb_floor_divide*/
29986   0, /*nb_true_divide*/
29987   0, /*nb_inplace_floor_divide*/
29988   0, /*nb_inplace_true_divide*/
29989   #if PY_VERSION_HEX >= 0x02050000
29990   0, /*nb_index*/
29991   #endif
29992 };
29993
29994 static PySequenceMethods __pyx_tp_as_sequence_IteratorRowSelection = {
29995   0, /*sq_length*/
29996   0, /*sq_concat*/
29997   0, /*sq_repeat*/
29998   0, /*sq_item*/
29999   0, /*sq_slice*/
30000   0, /*sq_ass_item*/
30001   0, /*sq_ass_slice*/
30002   0, /*sq_contains*/
30003   0, /*sq_inplace_concat*/
30004   0, /*sq_inplace_repeat*/
30005 };
30006
30007 static PyMappingMethods __pyx_tp_as_mapping_IteratorRowSelection = {
30008   0, /*mp_length*/
30009   0, /*mp_subscript*/
30010   0, /*mp_ass_subscript*/
30011 };
30012
30013 static PyBufferProcs __pyx_tp_as_buffer_IteratorRowSelection = {
30014   #if PY_MAJOR_VERSION < 3
30015   0, /*bf_getreadbuffer*/
30016   #endif
30017   #if PY_MAJOR_VERSION < 3
30018   0, /*bf_getwritebuffer*/
30019   #endif
30020   #if PY_MAJOR_VERSION < 3
30021   0, /*bf_getsegcount*/
30022   #endif
30023   #if PY_MAJOR_VERSION < 3
30024   0, /*bf_getcharbuffer*/
30025   #endif
30026   #if PY_VERSION_HEX >= 0x02060000
30027   0, /*bf_getbuffer*/
30028   #endif
30029   #if PY_VERSION_HEX >= 0x02060000
30030   0, /*bf_releasebuffer*/
30031   #endif
30032 };
30033
30034 static PyTypeObject __pyx_type_9csamtools_IteratorRowSelection = {
30035   PyVarObject_HEAD_INIT(0, 0)
30036   __Pyx_NAMESTR("csamtools.IteratorRowSelection"), /*tp_name*/
30037   sizeof(struct __pyx_obj_9csamtools_IteratorRowSelection), /*tp_basicsize*/
30038   0, /*tp_itemsize*/
30039   __pyx_tp_dealloc_9csamtools_IteratorRowSelection, /*tp_dealloc*/
30040   0, /*tp_print*/
30041   0, /*tp_getattr*/
30042   0, /*tp_setattr*/
30043   #if PY_MAJOR_VERSION < 3
30044   0, /*tp_compare*/
30045   #else
30046   0, /*reserved*/
30047   #endif
30048   0, /*tp_repr*/
30049   &__pyx_tp_as_number_IteratorRowSelection, /*tp_as_number*/
30050   &__pyx_tp_as_sequence_IteratorRowSelection, /*tp_as_sequence*/
30051   &__pyx_tp_as_mapping_IteratorRowSelection, /*tp_as_mapping*/
30052   0, /*tp_hash*/
30053   0, /*tp_call*/
30054   0, /*tp_str*/
30055   0, /*tp_getattro*/
30056   0, /*tp_setattro*/
30057   &__pyx_tp_as_buffer_IteratorRowSelection, /*tp_as_buffer*/
30058   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
30059   __Pyx_DOCSTR("*(Samfile samfile)*\n\n    iterate over reads in *samfile* at a given list of file positions.\n    "), /*tp_doc*/
30060   __pyx_tp_traverse_9csamtools_IteratorRowSelection, /*tp_traverse*/
30061   __pyx_tp_clear_9csamtools_IteratorRowSelection, /*tp_clear*/
30062   0, /*tp_richcompare*/
30063   0, /*tp_weaklistoffset*/
30064   __pyx_pf_9csamtools_20IteratorRowSelection_1__iter__, /*tp_iter*/
30065   __pyx_pf_9csamtools_20IteratorRowSelection_2__next__, /*tp_iternext*/
30066   __pyx_methods_9csamtools_IteratorRowSelection, /*tp_methods*/
30067   0, /*tp_members*/
30068   0, /*tp_getset*/
30069   0, /*tp_base*/
30070   0, /*tp_dict*/
30071   0, /*tp_descr_get*/
30072   0, /*tp_descr_set*/
30073   0, /*tp_dictoffset*/
30074   0, /*tp_init*/
30075   0, /*tp_alloc*/
30076   __pyx_tp_new_9csamtools_IteratorRowSelection, /*tp_new*/
30077   0, /*tp_free*/
30078   0, /*tp_is_gc*/
30079   0, /*tp_bases*/
30080   0, /*tp_mro*/
30081   0, /*tp_cache*/
30082   0, /*tp_subclasses*/
30083   0, /*tp_weaklist*/
30084   0, /*tp_del*/
30085   #if PY_VERSION_HEX >= 0x02060000
30086   0, /*tp_version_tag*/
30087   #endif
30088 };
30089 static struct __pyx_vtabstruct_9csamtools_IteratorColumn __pyx_vtable_9csamtools_IteratorColumn;
30090
30091 static PyObject *__pyx_tp_new_9csamtools_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
30092   struct __pyx_obj_9csamtools_IteratorColumn *p;
30093   PyObject *o = (*t->tp_alloc)(t, 0);
30094   if (!o) return 0;
30095   p = ((struct __pyx_obj_9csamtools_IteratorColumn *)o);
30096   p->__pyx_vtab = __pyx_vtabptr_9csamtools_IteratorColumn;
30097   p->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
30098   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
30099   p->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
30100   p->stepper = Py_None; Py_INCREF(Py_None);
30101   if (__pyx_pf_9csamtools_14IteratorColumn___cinit__(o, a, k) < 0) {
30102     Py_DECREF(o); o = 0;
30103   }
30104   return o;
30105 }
30106
30107 static void __pyx_tp_dealloc_9csamtools_IteratorColumn(PyObject *o) {
30108   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
30109   {
30110     PyObject *etype, *eval, *etb;
30111     PyErr_Fetch(&etype, &eval, &etb);
30112     ++Py_REFCNT(o);
30113     __pyx_pf_9csamtools_14IteratorColumn_4__dealloc__(o);
30114     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
30115     --Py_REFCNT(o);
30116     PyErr_Restore(etype, eval, etb);
30117   }
30118   Py_XDECREF(((PyObject *)p->iter));
30119   Py_XDECREF(((PyObject *)p->samfile));
30120   Py_XDECREF(((PyObject *)p->fastafile));
30121   Py_XDECREF(p->stepper);
30122   (*Py_TYPE(o)->tp_free)(o);
30123 }
30124
30125 static int __pyx_tp_traverse_9csamtools_IteratorColumn(PyObject *o, visitproc v, void *a) {
30126   int e;
30127   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
30128   if (p->iter) {
30129     e = (*v)(((PyObject*)p->iter), a); if (e) return e;
30130   }
30131   if (p->samfile) {
30132     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
30133   }
30134   if (p->fastafile) {
30135     e = (*v)(((PyObject*)p->fastafile), a); if (e) return e;
30136   }
30137   if (p->stepper) {
30138     e = (*v)(p->stepper, a); if (e) return e;
30139   }
30140   return 0;
30141 }
30142
30143 static int __pyx_tp_clear_9csamtools_IteratorColumn(PyObject *o) {
30144   struct __pyx_obj_9csamtools_IteratorColumn *p = (struct __pyx_obj_9csamtools_IteratorColumn *)o;
30145   PyObject* tmp;
30146   tmp = ((PyObject*)p->iter);
30147   p->iter = ((struct __pyx_obj_9csamtools_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
30148   Py_XDECREF(tmp);
30149   tmp = ((PyObject*)p->samfile);
30150   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
30151   Py_XDECREF(tmp);
30152   tmp = ((PyObject*)p->fastafile);
30153   p->fastafile = ((struct __pyx_obj_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
30154   Py_XDECREF(tmp);
30155   tmp = ((PyObject*)p->stepper);
30156   p->stepper = Py_None; Py_INCREF(Py_None);
30157   Py_XDECREF(tmp);
30158   return 0;
30159 }
30160
30161 static PyObject *__pyx_getprop_9csamtools_14IteratorColumn_seq_len(PyObject *o, void *x) {
30162   return __pyx_pf_9csamtools_14IteratorColumn_7seq_len___get__(o);
30163 }
30164
30165 static PyMethodDef __pyx_methods_9csamtools_IteratorColumn[] = {
30166   {__Pyx_NAMESTR("addReference"), (PyCFunction)__pyx_pf_9csamtools_14IteratorColumn_2addReference, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorColumn_2addReference)},
30167   {__Pyx_NAMESTR("hasReference"), (PyCFunction)__pyx_pf_9csamtools_14IteratorColumn_3hasReference, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_14IteratorColumn_3hasReference)},
30168   {0, 0, 0, 0}
30169 };
30170
30171 static struct PyGetSetDef __pyx_getsets_9csamtools_IteratorColumn[] = {
30172   {(char *)"seq_len", __pyx_getprop_9csamtools_14IteratorColumn_seq_len, 0, __Pyx_DOCSTR(__pyx_k_221), 0},
30173   {0, 0, 0, 0, 0}
30174 };
30175
30176 static PyNumberMethods __pyx_tp_as_number_IteratorColumn = {
30177   0, /*nb_add*/
30178   0, /*nb_subtract*/
30179   0, /*nb_multiply*/
30180   #if PY_MAJOR_VERSION < 3
30181   0, /*nb_divide*/
30182   #endif
30183   0, /*nb_remainder*/
30184   0, /*nb_divmod*/
30185   0, /*nb_power*/
30186   0, /*nb_negative*/
30187   0, /*nb_positive*/
30188   0, /*nb_absolute*/
30189   0, /*nb_nonzero*/
30190   0, /*nb_invert*/
30191   0, /*nb_lshift*/
30192   0, /*nb_rshift*/
30193   0, /*nb_and*/
30194   0, /*nb_xor*/
30195   0, /*nb_or*/
30196   #if PY_MAJOR_VERSION < 3
30197   0, /*nb_coerce*/
30198   #endif
30199   0, /*nb_int*/
30200   #if PY_MAJOR_VERSION < 3
30201   0, /*nb_long*/
30202   #else
30203   0, /*reserved*/
30204   #endif
30205   0, /*nb_float*/
30206   #if PY_MAJOR_VERSION < 3
30207   0, /*nb_oct*/
30208   #endif
30209   #if PY_MAJOR_VERSION < 3
30210   0, /*nb_hex*/
30211   #endif
30212   0, /*nb_inplace_add*/
30213   0, /*nb_inplace_subtract*/
30214   0, /*nb_inplace_multiply*/
30215   #if PY_MAJOR_VERSION < 3
30216   0, /*nb_inplace_divide*/
30217   #endif
30218   0, /*nb_inplace_remainder*/
30219   0, /*nb_inplace_power*/
30220   0, /*nb_inplace_lshift*/
30221   0, /*nb_inplace_rshift*/
30222   0, /*nb_inplace_and*/
30223   0, /*nb_inplace_xor*/
30224   0, /*nb_inplace_or*/
30225   0, /*nb_floor_divide*/
30226   0, /*nb_true_divide*/
30227   0, /*nb_inplace_floor_divide*/
30228   0, /*nb_inplace_true_divide*/
30229   #if PY_VERSION_HEX >= 0x02050000
30230   0, /*nb_index*/
30231   #endif
30232 };
30233
30234 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumn = {
30235   0, /*sq_length*/
30236   0, /*sq_concat*/
30237   0, /*sq_repeat*/
30238   0, /*sq_item*/
30239   0, /*sq_slice*/
30240   0, /*sq_ass_item*/
30241   0, /*sq_ass_slice*/
30242   0, /*sq_contains*/
30243   0, /*sq_inplace_concat*/
30244   0, /*sq_inplace_repeat*/
30245 };
30246
30247 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumn = {
30248   0, /*mp_length*/
30249   0, /*mp_subscript*/
30250   0, /*mp_ass_subscript*/
30251 };
30252
30253 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumn = {
30254   #if PY_MAJOR_VERSION < 3
30255   0, /*bf_getreadbuffer*/
30256   #endif
30257   #if PY_MAJOR_VERSION < 3
30258   0, /*bf_getwritebuffer*/
30259   #endif
30260   #if PY_MAJOR_VERSION < 3
30261   0, /*bf_getsegcount*/
30262   #endif
30263   #if PY_MAJOR_VERSION < 3
30264   0, /*bf_getcharbuffer*/
30265   #endif
30266   #if PY_VERSION_HEX >= 0x02060000
30267   0, /*bf_getbuffer*/
30268   #endif
30269   #if PY_VERSION_HEX >= 0x02060000
30270   0, /*bf_releasebuffer*/
30271   #endif
30272 };
30273
30274 static PyTypeObject __pyx_type_9csamtools_IteratorColumn = {
30275   PyVarObject_HEAD_INIT(0, 0)
30276   __Pyx_NAMESTR("csamtools.IteratorColumn"), /*tp_name*/
30277   sizeof(struct __pyx_obj_9csamtools_IteratorColumn), /*tp_basicsize*/
30278   0, /*tp_itemsize*/
30279   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
30280   0, /*tp_print*/
30281   0, /*tp_getattr*/
30282   0, /*tp_setattr*/
30283   #if PY_MAJOR_VERSION < 3
30284   0, /*tp_compare*/
30285   #else
30286   0, /*reserved*/
30287   #endif
30288   0, /*tp_repr*/
30289   &__pyx_tp_as_number_IteratorColumn, /*tp_as_number*/
30290   &__pyx_tp_as_sequence_IteratorColumn, /*tp_as_sequence*/
30291   &__pyx_tp_as_mapping_IteratorColumn, /*tp_as_mapping*/
30292   0, /*tp_hash*/
30293   0, /*tp_call*/
30294   0, /*tp_str*/
30295   0, /*tp_getattro*/
30296   0, /*tp_setattro*/
30297   &__pyx_tp_as_buffer_IteratorColumn, /*tp_as_buffer*/
30298   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
30299   __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 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    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*/
30300   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
30301   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
30302   0, /*tp_richcompare*/
30303   0, /*tp_weaklistoffset*/
30304   __pyx_pf_9csamtools_14IteratorColumn_1__iter__, /*tp_iter*/
30305   0, /*tp_iternext*/
30306   __pyx_methods_9csamtools_IteratorColumn, /*tp_methods*/
30307   0, /*tp_members*/
30308   __pyx_getsets_9csamtools_IteratorColumn, /*tp_getset*/
30309   0, /*tp_base*/
30310   0, /*tp_dict*/
30311   0, /*tp_descr_get*/
30312   0, /*tp_descr_set*/
30313   0, /*tp_dictoffset*/
30314   0, /*tp_init*/
30315   0, /*tp_alloc*/
30316   __pyx_tp_new_9csamtools_IteratorColumn, /*tp_new*/
30317   0, /*tp_free*/
30318   0, /*tp_is_gc*/
30319   0, /*tp_bases*/
30320   0, /*tp_mro*/
30321   0, /*tp_cache*/
30322   0, /*tp_subclasses*/
30323   0, /*tp_weaklist*/
30324   0, /*tp_del*/
30325   #if PY_VERSION_HEX >= 0x02060000
30326   0, /*tp_version_tag*/
30327   #endif
30328 };
30329 static struct __pyx_vtabstruct_9csamtools_IteratorColumnRegion __pyx_vtable_9csamtools_IteratorColumnRegion;
30330
30331 static PyObject *__pyx_tp_new_9csamtools_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
30332   struct __pyx_obj_9csamtools_IteratorColumnRegion *p;
30333   PyObject *o = __pyx_tp_new_9csamtools_IteratorColumn(t, a, k);
30334   if (!o) return 0;
30335   p = ((struct __pyx_obj_9csamtools_IteratorColumnRegion *)o);
30336   p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_9csamtools_IteratorColumn*)__pyx_vtabptr_9csamtools_IteratorColumnRegion;
30337   if (__pyx_pf_9csamtools_20IteratorColumnRegion___cinit__(o, a, k) < 0) {
30338     Py_DECREF(o); o = 0;
30339   }
30340   return o;
30341 }
30342
30343 static PyMethodDef __pyx_methods_9csamtools_IteratorColumnRegion[] = {
30344   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_20IteratorColumnRegion_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_20IteratorColumnRegion_1__next__)},
30345   {0, 0, 0, 0}
30346 };
30347
30348 static PyNumberMethods __pyx_tp_as_number_IteratorColumnRegion = {
30349   0, /*nb_add*/
30350   0, /*nb_subtract*/
30351   0, /*nb_multiply*/
30352   #if PY_MAJOR_VERSION < 3
30353   0, /*nb_divide*/
30354   #endif
30355   0, /*nb_remainder*/
30356   0, /*nb_divmod*/
30357   0, /*nb_power*/
30358   0, /*nb_negative*/
30359   0, /*nb_positive*/
30360   0, /*nb_absolute*/
30361   0, /*nb_nonzero*/
30362   0, /*nb_invert*/
30363   0, /*nb_lshift*/
30364   0, /*nb_rshift*/
30365   0, /*nb_and*/
30366   0, /*nb_xor*/
30367   0, /*nb_or*/
30368   #if PY_MAJOR_VERSION < 3
30369   0, /*nb_coerce*/
30370   #endif
30371   0, /*nb_int*/
30372   #if PY_MAJOR_VERSION < 3
30373   0, /*nb_long*/
30374   #else
30375   0, /*reserved*/
30376   #endif
30377   0, /*nb_float*/
30378   #if PY_MAJOR_VERSION < 3
30379   0, /*nb_oct*/
30380   #endif
30381   #if PY_MAJOR_VERSION < 3
30382   0, /*nb_hex*/
30383   #endif
30384   0, /*nb_inplace_add*/
30385   0, /*nb_inplace_subtract*/
30386   0, /*nb_inplace_multiply*/
30387   #if PY_MAJOR_VERSION < 3
30388   0, /*nb_inplace_divide*/
30389   #endif
30390   0, /*nb_inplace_remainder*/
30391   0, /*nb_inplace_power*/
30392   0, /*nb_inplace_lshift*/
30393   0, /*nb_inplace_rshift*/
30394   0, /*nb_inplace_and*/
30395   0, /*nb_inplace_xor*/
30396   0, /*nb_inplace_or*/
30397   0, /*nb_floor_divide*/
30398   0, /*nb_true_divide*/
30399   0, /*nb_inplace_floor_divide*/
30400   0, /*nb_inplace_true_divide*/
30401   #if PY_VERSION_HEX >= 0x02050000
30402   0, /*nb_index*/
30403   #endif
30404 };
30405
30406 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumnRegion = {
30407   0, /*sq_length*/
30408   0, /*sq_concat*/
30409   0, /*sq_repeat*/
30410   0, /*sq_item*/
30411   0, /*sq_slice*/
30412   0, /*sq_ass_item*/
30413   0, /*sq_ass_slice*/
30414   0, /*sq_contains*/
30415   0, /*sq_inplace_concat*/
30416   0, /*sq_inplace_repeat*/
30417 };
30418
30419 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumnRegion = {
30420   0, /*mp_length*/
30421   0, /*mp_subscript*/
30422   0, /*mp_ass_subscript*/
30423 };
30424
30425 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumnRegion = {
30426   #if PY_MAJOR_VERSION < 3
30427   0, /*bf_getreadbuffer*/
30428   #endif
30429   #if PY_MAJOR_VERSION < 3
30430   0, /*bf_getwritebuffer*/
30431   #endif
30432   #if PY_MAJOR_VERSION < 3
30433   0, /*bf_getsegcount*/
30434   #endif
30435   #if PY_MAJOR_VERSION < 3
30436   0, /*bf_getcharbuffer*/
30437   #endif
30438   #if PY_VERSION_HEX >= 0x02060000
30439   0, /*bf_getbuffer*/
30440   #endif
30441   #if PY_VERSION_HEX >= 0x02060000
30442   0, /*bf_releasebuffer*/
30443   #endif
30444 };
30445
30446 static PyTypeObject __pyx_type_9csamtools_IteratorColumnRegion = {
30447   PyVarObject_HEAD_INIT(0, 0)
30448   __Pyx_NAMESTR("csamtools.IteratorColumnRegion"), /*tp_name*/
30449   sizeof(struct __pyx_obj_9csamtools_IteratorColumnRegion), /*tp_basicsize*/
30450   0, /*tp_itemsize*/
30451   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
30452   0, /*tp_print*/
30453   0, /*tp_getattr*/
30454   0, /*tp_setattr*/
30455   #if PY_MAJOR_VERSION < 3
30456   0, /*tp_compare*/
30457   #else
30458   0, /*reserved*/
30459   #endif
30460   0, /*tp_repr*/
30461   &__pyx_tp_as_number_IteratorColumnRegion, /*tp_as_number*/
30462   &__pyx_tp_as_sequence_IteratorColumnRegion, /*tp_as_sequence*/
30463   &__pyx_tp_as_mapping_IteratorColumnRegion, /*tp_as_mapping*/
30464   0, /*tp_hash*/
30465   0, /*tp_call*/
30466   0, /*tp_str*/
30467   0, /*tp_getattro*/
30468   0, /*tp_setattro*/
30469   &__pyx_tp_as_buffer_IteratorColumnRegion, /*tp_as_buffer*/
30470   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
30471   __Pyx_DOCSTR("iterates over a region only.\n    "), /*tp_doc*/
30472   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
30473   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
30474   0, /*tp_richcompare*/
30475   0, /*tp_weaklistoffset*/
30476   0, /*tp_iter*/
30477   __pyx_pf_9csamtools_20IteratorColumnRegion_1__next__, /*tp_iternext*/
30478   __pyx_methods_9csamtools_IteratorColumnRegion, /*tp_methods*/
30479   0, /*tp_members*/
30480   0, /*tp_getset*/
30481   0, /*tp_base*/
30482   0, /*tp_dict*/
30483   0, /*tp_descr_get*/
30484   0, /*tp_descr_set*/
30485   0, /*tp_dictoffset*/
30486   0, /*tp_init*/
30487   0, /*tp_alloc*/
30488   __pyx_tp_new_9csamtools_IteratorColumnRegion, /*tp_new*/
30489   0, /*tp_free*/
30490   0, /*tp_is_gc*/
30491   0, /*tp_bases*/
30492   0, /*tp_mro*/
30493   0, /*tp_cache*/
30494   0, /*tp_subclasses*/
30495   0, /*tp_weaklist*/
30496   0, /*tp_del*/
30497   #if PY_VERSION_HEX >= 0x02060000
30498   0, /*tp_version_tag*/
30499   #endif
30500 };
30501 static struct __pyx_vtabstruct_9csamtools_IteratorColumnAllRefs __pyx_vtable_9csamtools_IteratorColumnAllRefs;
30502
30503 static PyObject *__pyx_tp_new_9csamtools_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
30504   struct __pyx_obj_9csamtools_IteratorColumnAllRefs *p;
30505   PyObject *o = __pyx_tp_new_9csamtools_IteratorColumn(t, a, k);
30506   if (!o) return 0;
30507   p = ((struct __pyx_obj_9csamtools_IteratorColumnAllRefs *)o);
30508   p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_9csamtools_IteratorColumn*)__pyx_vtabptr_9csamtools_IteratorColumnAllRefs;
30509   if (__pyx_pf_9csamtools_21IteratorColumnAllRefs___cinit__(o, a, k) < 0) {
30510     Py_DECREF(o); o = 0;
30511   }
30512   return o;
30513 }
30514
30515 static PyMethodDef __pyx_methods_9csamtools_IteratorColumnAllRefs[] = {
30516   {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_9csamtools_21IteratorColumnAllRefs_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(__pyx_doc_9csamtools_21IteratorColumnAllRefs_1__next__)},
30517   {0, 0, 0, 0}
30518 };
30519
30520 static PyNumberMethods __pyx_tp_as_number_IteratorColumnAllRefs = {
30521   0, /*nb_add*/
30522   0, /*nb_subtract*/
30523   0, /*nb_multiply*/
30524   #if PY_MAJOR_VERSION < 3
30525   0, /*nb_divide*/
30526   #endif
30527   0, /*nb_remainder*/
30528   0, /*nb_divmod*/
30529   0, /*nb_power*/
30530   0, /*nb_negative*/
30531   0, /*nb_positive*/
30532   0, /*nb_absolute*/
30533   0, /*nb_nonzero*/
30534   0, /*nb_invert*/
30535   0, /*nb_lshift*/
30536   0, /*nb_rshift*/
30537   0, /*nb_and*/
30538   0, /*nb_xor*/
30539   0, /*nb_or*/
30540   #if PY_MAJOR_VERSION < 3
30541   0, /*nb_coerce*/
30542   #endif
30543   0, /*nb_int*/
30544   #if PY_MAJOR_VERSION < 3
30545   0, /*nb_long*/
30546   #else
30547   0, /*reserved*/
30548   #endif
30549   0, /*nb_float*/
30550   #if PY_MAJOR_VERSION < 3
30551   0, /*nb_oct*/
30552   #endif
30553   #if PY_MAJOR_VERSION < 3
30554   0, /*nb_hex*/
30555   #endif
30556   0, /*nb_inplace_add*/
30557   0, /*nb_inplace_subtract*/
30558   0, /*nb_inplace_multiply*/
30559   #if PY_MAJOR_VERSION < 3
30560   0, /*nb_inplace_divide*/
30561   #endif
30562   0, /*nb_inplace_remainder*/
30563   0, /*nb_inplace_power*/
30564   0, /*nb_inplace_lshift*/
30565   0, /*nb_inplace_rshift*/
30566   0, /*nb_inplace_and*/
30567   0, /*nb_inplace_xor*/
30568   0, /*nb_inplace_or*/
30569   0, /*nb_floor_divide*/
30570   0, /*nb_true_divide*/
30571   0, /*nb_inplace_floor_divide*/
30572   0, /*nb_inplace_true_divide*/
30573   #if PY_VERSION_HEX >= 0x02050000
30574   0, /*nb_index*/
30575   #endif
30576 };
30577
30578 static PySequenceMethods __pyx_tp_as_sequence_IteratorColumnAllRefs = {
30579   0, /*sq_length*/
30580   0, /*sq_concat*/
30581   0, /*sq_repeat*/
30582   0, /*sq_item*/
30583   0, /*sq_slice*/
30584   0, /*sq_ass_item*/
30585   0, /*sq_ass_slice*/
30586   0, /*sq_contains*/
30587   0, /*sq_inplace_concat*/
30588   0, /*sq_inplace_repeat*/
30589 };
30590
30591 static PyMappingMethods __pyx_tp_as_mapping_IteratorColumnAllRefs = {
30592   0, /*mp_length*/
30593   0, /*mp_subscript*/
30594   0, /*mp_ass_subscript*/
30595 };
30596
30597 static PyBufferProcs __pyx_tp_as_buffer_IteratorColumnAllRefs = {
30598   #if PY_MAJOR_VERSION < 3
30599   0, /*bf_getreadbuffer*/
30600   #endif
30601   #if PY_MAJOR_VERSION < 3
30602   0, /*bf_getwritebuffer*/
30603   #endif
30604   #if PY_MAJOR_VERSION < 3
30605   0, /*bf_getsegcount*/
30606   #endif
30607   #if PY_MAJOR_VERSION < 3
30608   0, /*bf_getcharbuffer*/
30609   #endif
30610   #if PY_VERSION_HEX >= 0x02060000
30611   0, /*bf_getbuffer*/
30612   #endif
30613   #if PY_VERSION_HEX >= 0x02060000
30614   0, /*bf_releasebuffer*/
30615   #endif
30616 };
30617
30618 static PyTypeObject __pyx_type_9csamtools_IteratorColumnAllRefs = {
30619   PyVarObject_HEAD_INIT(0, 0)
30620   __Pyx_NAMESTR("csamtools.IteratorColumnAllRefs"), /*tp_name*/
30621   sizeof(struct __pyx_obj_9csamtools_IteratorColumnAllRefs), /*tp_basicsize*/
30622   0, /*tp_itemsize*/
30623   __pyx_tp_dealloc_9csamtools_IteratorColumn, /*tp_dealloc*/
30624   0, /*tp_print*/
30625   0, /*tp_getattr*/
30626   0, /*tp_setattr*/
30627   #if PY_MAJOR_VERSION < 3
30628   0, /*tp_compare*/
30629   #else
30630   0, /*reserved*/
30631   #endif
30632   0, /*tp_repr*/
30633   &__pyx_tp_as_number_IteratorColumnAllRefs, /*tp_as_number*/
30634   &__pyx_tp_as_sequence_IteratorColumnAllRefs, /*tp_as_sequence*/
30635   &__pyx_tp_as_mapping_IteratorColumnAllRefs, /*tp_as_mapping*/
30636   0, /*tp_hash*/
30637   0, /*tp_call*/
30638   0, /*tp_str*/
30639   0, /*tp_getattro*/
30640   0, /*tp_setattro*/
30641   &__pyx_tp_as_buffer_IteratorColumnAllRefs, /*tp_as_buffer*/
30642   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
30643   __Pyx_DOCSTR("iterates over all columns by chaining iterators over each reference\n    "), /*tp_doc*/
30644   __pyx_tp_traverse_9csamtools_IteratorColumn, /*tp_traverse*/
30645   __pyx_tp_clear_9csamtools_IteratorColumn, /*tp_clear*/
30646   0, /*tp_richcompare*/
30647   0, /*tp_weaklistoffset*/
30648   0, /*tp_iter*/
30649   __pyx_pf_9csamtools_21IteratorColumnAllRefs_1__next__, /*tp_iternext*/
30650   __pyx_methods_9csamtools_IteratorColumnAllRefs, /*tp_methods*/
30651   0, /*tp_members*/
30652   0, /*tp_getset*/
30653   0, /*tp_base*/
30654   0, /*tp_dict*/
30655   0, /*tp_descr_get*/
30656   0, /*tp_descr_set*/
30657   0, /*tp_dictoffset*/
30658   0, /*tp_init*/
30659   0, /*tp_alloc*/
30660   __pyx_tp_new_9csamtools_IteratorColumnAllRefs, /*tp_new*/
30661   0, /*tp_free*/
30662   0, /*tp_is_gc*/
30663   0, /*tp_bases*/
30664   0, /*tp_mro*/
30665   0, /*tp_cache*/
30666   0, /*tp_subclasses*/
30667   0, /*tp_weaklist*/
30668   0, /*tp_del*/
30669   #if PY_VERSION_HEX >= 0x02060000
30670   0, /*tp_version_tag*/
30671   #endif
30672 };
30673
30674 static PyObject *__pyx_tp_new_9csamtools_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k) {
30675   PyObject *o = (*t->tp_alloc)(t, 0);
30676   if (!o) return 0;
30677   return o;
30678 }
30679
30680 static void __pyx_tp_dealloc_9csamtools_SNPCall(PyObject *o) {
30681   (*Py_TYPE(o)->tp_free)(o);
30682 }
30683
30684 static PyObject *__pyx_getprop_9csamtools_7SNPCall_tid(PyObject *o, void *x) {
30685   return __pyx_pf_9csamtools_7SNPCall_3tid___get__(o);
30686 }
30687
30688 static PyObject *__pyx_getprop_9csamtools_7SNPCall_pos(PyObject *o, void *x) {
30689   return __pyx_pf_9csamtools_7SNPCall_3pos___get__(o);
30690 }
30691
30692 static PyObject *__pyx_getprop_9csamtools_7SNPCall_reference_base(PyObject *o, void *x) {
30693   return __pyx_pf_9csamtools_7SNPCall_14reference_base___get__(o);
30694 }
30695
30696 static PyObject *__pyx_getprop_9csamtools_7SNPCall_genotype(PyObject *o, void *x) {
30697   return __pyx_pf_9csamtools_7SNPCall_8genotype___get__(o);
30698 }
30699
30700 static PyObject *__pyx_getprop_9csamtools_7SNPCall_consensus_quality(PyObject *o, void *x) {
30701   return __pyx_pf_9csamtools_7SNPCall_17consensus_quality___get__(o);
30702 }
30703
30704 static PyObject *__pyx_getprop_9csamtools_7SNPCall_snp_quality(PyObject *o, void *x) {
30705   return __pyx_pf_9csamtools_7SNPCall_11snp_quality___get__(o);
30706 }
30707
30708 static PyObject *__pyx_getprop_9csamtools_7SNPCall_mapping_quality(PyObject *o, void *x) {
30709   return __pyx_pf_9csamtools_7SNPCall_15mapping_quality___get__(o);
30710 }
30711
30712 static PyObject *__pyx_getprop_9csamtools_7SNPCall_coverage(PyObject *o, void *x) {
30713   return __pyx_pf_9csamtools_7SNPCall_8coverage___get__(o);
30714 }
30715
30716 static PyMethodDef __pyx_methods_9csamtools_SNPCall[] = {
30717   {0, 0, 0, 0}
30718 };
30719
30720 static struct PyGetSetDef __pyx_getsets_9csamtools_SNPCall[] = {
30721   {(char *)"tid", __pyx_getprop_9csamtools_7SNPCall_tid, 0, __Pyx_DOCSTR(__pyx_k_214), 0},
30722   {(char *)"pos", __pyx_getprop_9csamtools_7SNPCall_pos, 0, __Pyx_DOCSTR(__pyx_k_222), 0},
30723   {(char *)"reference_base", __pyx_getprop_9csamtools_7SNPCall_reference_base, 0, __Pyx_DOCSTR(__pyx_k_223), 0},
30724   {(char *)"genotype", __pyx_getprop_9csamtools_7SNPCall_genotype, 0, __Pyx_DOCSTR(__pyx_k_224), 0},
30725   {(char *)"consensus_quality", __pyx_getprop_9csamtools_7SNPCall_consensus_quality, 0, __Pyx_DOCSTR(__pyx_k_225), 0},
30726   {(char *)"snp_quality", __pyx_getprop_9csamtools_7SNPCall_snp_quality, 0, __Pyx_DOCSTR(__pyx_k_226), 0},
30727   {(char *)"mapping_quality", __pyx_getprop_9csamtools_7SNPCall_mapping_quality, 0, __Pyx_DOCSTR(__pyx_k_227), 0},
30728   {(char *)"coverage", __pyx_getprop_9csamtools_7SNPCall_coverage, 0, __Pyx_DOCSTR(__pyx_k_228), 0},
30729   {0, 0, 0, 0, 0}
30730 };
30731
30732 static PyNumberMethods __pyx_tp_as_number_SNPCall = {
30733   0, /*nb_add*/
30734   0, /*nb_subtract*/
30735   0, /*nb_multiply*/
30736   #if PY_MAJOR_VERSION < 3
30737   0, /*nb_divide*/
30738   #endif
30739   0, /*nb_remainder*/
30740   0, /*nb_divmod*/
30741   0, /*nb_power*/
30742   0, /*nb_negative*/
30743   0, /*nb_positive*/
30744   0, /*nb_absolute*/
30745   0, /*nb_nonzero*/
30746   0, /*nb_invert*/
30747   0, /*nb_lshift*/
30748   0, /*nb_rshift*/
30749   0, /*nb_and*/
30750   0, /*nb_xor*/
30751   0, /*nb_or*/
30752   #if PY_MAJOR_VERSION < 3
30753   0, /*nb_coerce*/
30754   #endif
30755   0, /*nb_int*/
30756   #if PY_MAJOR_VERSION < 3
30757   0, /*nb_long*/
30758   #else
30759   0, /*reserved*/
30760   #endif
30761   0, /*nb_float*/
30762   #if PY_MAJOR_VERSION < 3
30763   0, /*nb_oct*/
30764   #endif
30765   #if PY_MAJOR_VERSION < 3
30766   0, /*nb_hex*/
30767   #endif
30768   0, /*nb_inplace_add*/
30769   0, /*nb_inplace_subtract*/
30770   0, /*nb_inplace_multiply*/
30771   #if PY_MAJOR_VERSION < 3
30772   0, /*nb_inplace_divide*/
30773   #endif
30774   0, /*nb_inplace_remainder*/
30775   0, /*nb_inplace_power*/
30776   0, /*nb_inplace_lshift*/
30777   0, /*nb_inplace_rshift*/
30778   0, /*nb_inplace_and*/
30779   0, /*nb_inplace_xor*/
30780   0, /*nb_inplace_or*/
30781   0, /*nb_floor_divide*/
30782   0, /*nb_true_divide*/
30783   0, /*nb_inplace_floor_divide*/
30784   0, /*nb_inplace_true_divide*/
30785   #if PY_VERSION_HEX >= 0x02050000
30786   0, /*nb_index*/
30787   #endif
30788 };
30789
30790 static PySequenceMethods __pyx_tp_as_sequence_SNPCall = {
30791   0, /*sq_length*/
30792   0, /*sq_concat*/
30793   0, /*sq_repeat*/
30794   0, /*sq_item*/
30795   0, /*sq_slice*/
30796   0, /*sq_ass_item*/
30797   0, /*sq_ass_slice*/
30798   0, /*sq_contains*/
30799   0, /*sq_inplace_concat*/
30800   0, /*sq_inplace_repeat*/
30801 };
30802
30803 static PyMappingMethods __pyx_tp_as_mapping_SNPCall = {
30804   0, /*mp_length*/
30805   0, /*mp_subscript*/
30806   0, /*mp_ass_subscript*/
30807 };
30808
30809 static PyBufferProcs __pyx_tp_as_buffer_SNPCall = {
30810   #if PY_MAJOR_VERSION < 3
30811   0, /*bf_getreadbuffer*/
30812   #endif
30813   #if PY_MAJOR_VERSION < 3
30814   0, /*bf_getwritebuffer*/
30815   #endif
30816   #if PY_MAJOR_VERSION < 3
30817   0, /*bf_getsegcount*/
30818   #endif
30819   #if PY_MAJOR_VERSION < 3
30820   0, /*bf_getcharbuffer*/
30821   #endif
30822   #if PY_VERSION_HEX >= 0x02060000
30823   0, /*bf_getbuffer*/
30824   #endif
30825   #if PY_VERSION_HEX >= 0x02060000
30826   0, /*bf_releasebuffer*/
30827   #endif
30828 };
30829
30830 static PyTypeObject __pyx_type_9csamtools_SNPCall = {
30831   PyVarObject_HEAD_INIT(0, 0)
30832   __Pyx_NAMESTR("csamtools.SNPCall"), /*tp_name*/
30833   sizeof(struct __pyx_obj_9csamtools_SNPCall), /*tp_basicsize*/
30834   0, /*tp_itemsize*/
30835   __pyx_tp_dealloc_9csamtools_SNPCall, /*tp_dealloc*/
30836   0, /*tp_print*/
30837   0, /*tp_getattr*/
30838   0, /*tp_setattr*/
30839   #if PY_MAJOR_VERSION < 3
30840   0, /*tp_compare*/
30841   #else
30842   0, /*reserved*/
30843   #endif
30844   0, /*tp_repr*/
30845   &__pyx_tp_as_number_SNPCall, /*tp_as_number*/
30846   &__pyx_tp_as_sequence_SNPCall, /*tp_as_sequence*/
30847   &__pyx_tp_as_mapping_SNPCall, /*tp_as_mapping*/
30848   0, /*tp_hash*/
30849   0, /*tp_call*/
30850   __pyx_pf_9csamtools_7SNPCall___str__, /*tp_str*/
30851   0, /*tp_getattro*/
30852   0, /*tp_setattro*/
30853   &__pyx_tp_as_buffer_SNPCall, /*tp_as_buffer*/
30854   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
30855   __Pyx_DOCSTR("the results of a SNP call."), /*tp_doc*/
30856   0, /*tp_traverse*/
30857   0, /*tp_clear*/
30858   0, /*tp_richcompare*/
30859   0, /*tp_weaklistoffset*/
30860   0, /*tp_iter*/
30861   0, /*tp_iternext*/
30862   __pyx_methods_9csamtools_SNPCall, /*tp_methods*/
30863   0, /*tp_members*/
30864   __pyx_getsets_9csamtools_SNPCall, /*tp_getset*/
30865   0, /*tp_base*/
30866   0, /*tp_dict*/
30867   0, /*tp_descr_get*/
30868   0, /*tp_descr_set*/
30869   0, /*tp_dictoffset*/
30870   0, /*tp_init*/
30871   0, /*tp_alloc*/
30872   __pyx_tp_new_9csamtools_SNPCall, /*tp_new*/
30873   0, /*tp_free*/
30874   0, /*tp_is_gc*/
30875   0, /*tp_bases*/
30876   0, /*tp_mro*/
30877   0, /*tp_cache*/
30878   0, /*tp_subclasses*/
30879   0, /*tp_weaklist*/
30880   0, /*tp_del*/
30881   #if PY_VERSION_HEX >= 0x02060000
30882   0, /*tp_version_tag*/
30883   #endif
30884 };
30885
30886 static PyObject *__pyx_tp_new_9csamtools_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k) {
30887   struct __pyx_obj_9csamtools_IndexedReads *p;
30888   PyObject *o = (*t->tp_alloc)(t, 0);
30889   if (!o) return 0;
30890   p = ((struct __pyx_obj_9csamtools_IndexedReads *)o);
30891   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
30892   p->index = Py_None; Py_INCREF(Py_None);
30893   return o;
30894 }
30895
30896 static void __pyx_tp_dealloc_9csamtools_IndexedReads(PyObject *o) {
30897   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
30898   {
30899     PyObject *etype, *eval, *etb;
30900     PyErr_Fetch(&etype, &eval, &etb);
30901     ++Py_REFCNT(o);
30902     __pyx_pf_9csamtools_12IndexedReads_3__dealloc__(o);
30903     if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
30904     --Py_REFCNT(o);
30905     PyErr_Restore(etype, eval, etb);
30906   }
30907   Py_XDECREF(((PyObject *)p->samfile));
30908   Py_XDECREF(p->index);
30909   (*Py_TYPE(o)->tp_free)(o);
30910 }
30911
30912 static int __pyx_tp_traverse_9csamtools_IndexedReads(PyObject *o, visitproc v, void *a) {
30913   int e;
30914   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
30915   if (p->samfile) {
30916     e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
30917   }
30918   if (p->index) {
30919     e = (*v)(p->index, a); if (e) return e;
30920   }
30921   return 0;
30922 }
30923
30924 static int __pyx_tp_clear_9csamtools_IndexedReads(PyObject *o) {
30925   struct __pyx_obj_9csamtools_IndexedReads *p = (struct __pyx_obj_9csamtools_IndexedReads *)o;
30926   PyObject* tmp;
30927   tmp = ((PyObject*)p->samfile);
30928   p->samfile = ((struct __pyx_obj_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
30929   Py_XDECREF(tmp);
30930   tmp = ((PyObject*)p->index);
30931   p->index = Py_None; Py_INCREF(Py_None);
30932   Py_XDECREF(tmp);
30933   return 0;
30934 }
30935
30936 static PyMethodDef __pyx_methods_9csamtools_IndexedReads[] = {
30937   {__Pyx_NAMESTR("build"), (PyCFunction)__pyx_pf_9csamtools_12IndexedReads_1build, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_9csamtools_12IndexedReads_1build)},
30938   {__Pyx_NAMESTR("find"), (PyCFunction)__pyx_pf_9csamtools_12IndexedReads_2find, METH_O, __Pyx_DOCSTR(__pyx_doc_9csamtools_12IndexedReads_2find)},
30939   {0, 0, 0, 0}
30940 };
30941
30942 static PyNumberMethods __pyx_tp_as_number_IndexedReads = {
30943   0, /*nb_add*/
30944   0, /*nb_subtract*/
30945   0, /*nb_multiply*/
30946   #if PY_MAJOR_VERSION < 3
30947   0, /*nb_divide*/
30948   #endif
30949   0, /*nb_remainder*/
30950   0, /*nb_divmod*/
30951   0, /*nb_power*/
30952   0, /*nb_negative*/
30953   0, /*nb_positive*/
30954   0, /*nb_absolute*/
30955   0, /*nb_nonzero*/
30956   0, /*nb_invert*/
30957   0, /*nb_lshift*/
30958   0, /*nb_rshift*/
30959   0, /*nb_and*/
30960   0, /*nb_xor*/
30961   0, /*nb_or*/
30962   #if PY_MAJOR_VERSION < 3
30963   0, /*nb_coerce*/
30964   #endif
30965   0, /*nb_int*/
30966   #if PY_MAJOR_VERSION < 3
30967   0, /*nb_long*/
30968   #else
30969   0, /*reserved*/
30970   #endif
30971   0, /*nb_float*/
30972   #if PY_MAJOR_VERSION < 3
30973   0, /*nb_oct*/
30974   #endif
30975   #if PY_MAJOR_VERSION < 3
30976   0, /*nb_hex*/
30977   #endif
30978   0, /*nb_inplace_add*/
30979   0, /*nb_inplace_subtract*/
30980   0, /*nb_inplace_multiply*/
30981   #if PY_MAJOR_VERSION < 3
30982   0, /*nb_inplace_divide*/
30983   #endif
30984   0, /*nb_inplace_remainder*/
30985   0, /*nb_inplace_power*/
30986   0, /*nb_inplace_lshift*/
30987   0, /*nb_inplace_rshift*/
30988   0, /*nb_inplace_and*/
30989   0, /*nb_inplace_xor*/
30990   0, /*nb_inplace_or*/
30991   0, /*nb_floor_divide*/
30992   0, /*nb_true_divide*/
30993   0, /*nb_inplace_floor_divide*/
30994   0, /*nb_inplace_true_divide*/
30995   #if PY_VERSION_HEX >= 0x02050000
30996   0, /*nb_index*/
30997   #endif
30998 };
30999
31000 static PySequenceMethods __pyx_tp_as_sequence_IndexedReads = {
31001   0, /*sq_length*/
31002   0, /*sq_concat*/
31003   0, /*sq_repeat*/
31004   0, /*sq_item*/
31005   0, /*sq_slice*/
31006   0, /*sq_ass_item*/
31007   0, /*sq_ass_slice*/
31008   0, /*sq_contains*/
31009   0, /*sq_inplace_concat*/
31010   0, /*sq_inplace_repeat*/
31011 };
31012
31013 static PyMappingMethods __pyx_tp_as_mapping_IndexedReads = {
31014   0, /*mp_length*/
31015   0, /*mp_subscript*/
31016   0, /*mp_ass_subscript*/
31017 };
31018
31019 static PyBufferProcs __pyx_tp_as_buffer_IndexedReads = {
31020   #if PY_MAJOR_VERSION < 3
31021   0, /*bf_getreadbuffer*/
31022   #endif
31023   #if PY_MAJOR_VERSION < 3
31024   0, /*bf_getwritebuffer*/
31025   #endif
31026   #if PY_MAJOR_VERSION < 3
31027   0, /*bf_getsegcount*/
31028   #endif
31029   #if PY_MAJOR_VERSION < 3
31030   0, /*bf_getcharbuffer*/
31031   #endif
31032   #if PY_VERSION_HEX >= 0x02060000
31033   0, /*bf_getbuffer*/
31034   #endif
31035   #if PY_VERSION_HEX >= 0x02060000
31036   0, /*bf_releasebuffer*/
31037   #endif
31038 };
31039
31040 static PyTypeObject __pyx_type_9csamtools_IndexedReads = {
31041   PyVarObject_HEAD_INIT(0, 0)
31042   __Pyx_NAMESTR("csamtools.IndexedReads"), /*tp_name*/
31043   sizeof(struct __pyx_obj_9csamtools_IndexedReads), /*tp_basicsize*/
31044   0, /*tp_itemsize*/
31045   __pyx_tp_dealloc_9csamtools_IndexedReads, /*tp_dealloc*/
31046   0, /*tp_print*/
31047   0, /*tp_getattr*/
31048   0, /*tp_setattr*/
31049   #if PY_MAJOR_VERSION < 3
31050   0, /*tp_compare*/
31051   #else
31052   0, /*reserved*/
31053   #endif
31054   0, /*tp_repr*/
31055   &__pyx_tp_as_number_IndexedReads, /*tp_as_number*/
31056   &__pyx_tp_as_sequence_IndexedReads, /*tp_as_sequence*/
31057   &__pyx_tp_as_mapping_IndexedReads, /*tp_as_mapping*/
31058   0, /*tp_hash*/
31059   0, /*tp_call*/
31060   0, /*tp_str*/
31061   0, /*tp_getattro*/
31062   0, /*tp_setattro*/
31063   &__pyx_tp_as_buffer_IndexedReads, /*tp_as_buffer*/
31064   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
31065   __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*/
31066   __pyx_tp_traverse_9csamtools_IndexedReads, /*tp_traverse*/
31067   __pyx_tp_clear_9csamtools_IndexedReads, /*tp_clear*/
31068   0, /*tp_richcompare*/
31069   0, /*tp_weaklistoffset*/
31070   0, /*tp_iter*/
31071   0, /*tp_iternext*/
31072   __pyx_methods_9csamtools_IndexedReads, /*tp_methods*/
31073   0, /*tp_members*/
31074   0, /*tp_getset*/
31075   0, /*tp_base*/
31076   0, /*tp_dict*/
31077   0, /*tp_descr_get*/
31078   0, /*tp_descr_set*/
31079   0, /*tp_dictoffset*/
31080   __pyx_pf_9csamtools_12IndexedReads___init__, /*tp_init*/
31081   0, /*tp_alloc*/
31082   __pyx_tp_new_9csamtools_IndexedReads, /*tp_new*/
31083   0, /*tp_free*/
31084   0, /*tp_is_gc*/
31085   0, /*tp_bases*/
31086   0, /*tp_mro*/
31087   0, /*tp_cache*/
31088   0, /*tp_subclasses*/
31089   0, /*tp_weaklist*/
31090   0, /*tp_del*/
31091   #if PY_VERSION_HEX >= 0x02060000
31092   0, /*tp_version_tag*/
31093   #endif
31094 };
31095
31096 static PyMethodDef __pyx_methods[] = {
31097   {0, 0, 0, 0}
31098 };
31099
31100 #if PY_MAJOR_VERSION >= 3
31101 static struct PyModuleDef __pyx_moduledef = {
31102     PyModuleDef_HEAD_INIT,
31103     __Pyx_NAMESTR("csamtools"),
31104     0, /* m_doc */
31105     -1, /* m_size */
31106     __pyx_methods /* m_methods */,
31107     NULL, /* m_reload */
31108     NULL, /* m_traverse */
31109     NULL, /* m_clear */
31110     NULL /* m_free */
31111 };
31112 #endif
31113
31114 static __Pyx_StringTabEntry __pyx_string_tab[] = {
31115   {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
31116   {&__pyx_kp_s_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 0, 1, 0},
31117   {&__pyx_kp_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 0},
31118   {&__pyx_kp_s_103, __pyx_k_103, sizeof(__pyx_k_103), 0, 0, 1, 0},
31119   {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0},
31120   {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
31121   {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0},
31122   {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0},
31123   {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0},
31124   {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0},
31125   {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
31126   {&__pyx_kp_s_120, __pyx_k_120, sizeof(__pyx_k_120), 0, 0, 1, 0},
31127   {&__pyx_kp_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 0},
31128   {&__pyx_n_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 1},
31129   {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0},
31130   {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0},
31131   {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0},
31132   {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0},
31133   {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0},
31134   {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0},
31135   {&__pyx_kp_s_129, __pyx_k_129, sizeof(__pyx_k_129), 0, 0, 1, 0},
31136   {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
31137   {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0},
31138   {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0},
31139   {&__pyx_kp_s_132, __pyx_k_132, sizeof(__pyx_k_132), 0, 0, 1, 0},
31140   {&__pyx_kp_s_133, __pyx_k_133, sizeof(__pyx_k_133), 0, 0, 1, 0},
31141   {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0},
31142   {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0},
31143   {&__pyx_kp_s_137, __pyx_k_137, sizeof(__pyx_k_137), 0, 0, 1, 0},
31144   {&__pyx_kp_s_138, __pyx_k_138, sizeof(__pyx_k_138), 0, 0, 1, 0},
31145   {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0},
31146   {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
31147   {&__pyx_kp_s_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 0, 1, 0},
31148   {&__pyx_kp_s_141, __pyx_k_141, sizeof(__pyx_k_141), 0, 0, 1, 0},
31149   {&__pyx_kp_s_142, __pyx_k_142, sizeof(__pyx_k_142), 0, 0, 1, 0},
31150   {&__pyx_kp_s_143, __pyx_k_143, sizeof(__pyx_k_143), 0, 0, 1, 0},
31151   {&__pyx_kp_s_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 0, 1, 0},
31152   {&__pyx_kp_s_145, __pyx_k_145, sizeof(__pyx_k_145), 0, 0, 1, 0},
31153   {&__pyx_kp_s_146, __pyx_k_146, sizeof(__pyx_k_146), 0, 0, 1, 0},
31154   {&__pyx_kp_s_147, __pyx_k_147, sizeof(__pyx_k_147), 0, 0, 1, 0},
31155   {&__pyx_kp_s_148, __pyx_k_148, sizeof(__pyx_k_148), 0, 0, 1, 0},
31156   {&__pyx_kp_s_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 0, 1, 0},
31157   {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
31158   {&__pyx_kp_s_150, __pyx_k_150, sizeof(__pyx_k_150), 0, 0, 1, 0},
31159   {&__pyx_kp_s_151, __pyx_k_151, sizeof(__pyx_k_151), 0, 0, 1, 0},
31160   {&__pyx_kp_s_152, __pyx_k_152, sizeof(__pyx_k_152), 0, 0, 1, 0},
31161   {&__pyx_kp_s_153, __pyx_k_153, sizeof(__pyx_k_153), 0, 0, 1, 0},
31162   {&__pyx_kp_s_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 0, 1, 0},
31163   {&__pyx_kp_s_155, __pyx_k_155, sizeof(__pyx_k_155), 0, 0, 1, 0},
31164   {&__pyx_kp_s_156, __pyx_k_156, sizeof(__pyx_k_156), 0, 0, 1, 0},
31165   {&__pyx_kp_s_157, __pyx_k_157, sizeof(__pyx_k_157), 0, 0, 1, 0},
31166   {&__pyx_kp_s_162, __pyx_k_162, sizeof(__pyx_k_162), 0, 0, 1, 0},
31167   {&__pyx_kp_s_163, __pyx_k_163, sizeof(__pyx_k_163), 0, 0, 1, 0},
31168   {&__pyx_kp_s_164, __pyx_k_164, sizeof(__pyx_k_164), 0, 0, 1, 0},
31169   {&__pyx_n_s_166, __pyx_k_166, sizeof(__pyx_k_166), 0, 0, 1, 1},
31170   {&__pyx_kp_s_167, __pyx_k_167, sizeof(__pyx_k_167), 0, 0, 1, 0},
31171   {&__pyx_kp_s_168, __pyx_k_168, sizeof(__pyx_k_168), 0, 0, 1, 0},
31172   {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
31173   {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0},
31174   {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
31175   {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
31176   {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
31177   {&__pyx_kp_s_230, __pyx_k_230, sizeof(__pyx_k_230), 0, 0, 1, 0},
31178   {&__pyx_kp_s_231, __pyx_k_231, sizeof(__pyx_k_231), 0, 0, 1, 0},
31179   {&__pyx_kp_s_232, __pyx_k_232, sizeof(__pyx_k_232), 0, 0, 1, 0},
31180   {&__pyx_kp_s_238, __pyx_k_238, sizeof(__pyx_k_238), 0, 0, 1, 0},
31181   {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
31182   {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
31183   {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
31184   {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0},
31185   {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0},
31186   {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
31187   {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0},
31188   {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0},
31189   {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0},
31190   {&__pyx_kp_s_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 0, 1, 0},
31191   {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0},
31192   {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0},
31193   {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0},
31194   {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0},
31195   {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
31196   {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0},
31197   {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0},
31198   {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0},
31199   {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0},
31200   {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0},
31201   {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0},
31202   {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0},
31203   {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0},
31204   {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0},
31205   {&__pyx_kp_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 0},
31206   {&__pyx_kp_s_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 1, 0},
31207   {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0},
31208   {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0},
31209   {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0},
31210   {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0},
31211   {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
31212   {&__pyx_kp_s_91, __pyx_k_91, sizeof(__pyx_k_91), 0, 0, 1, 0},
31213   {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0},
31214   {&__pyx_kp_s_94, __pyx_k_94, sizeof(__pyx_k_94), 0, 0, 1, 0},
31215   {&__pyx_kp_s_96, __pyx_k_96, sizeof(__pyx_k_96), 0, 0, 1, 0},
31216   {&__pyx_kp_s_97, __pyx_k_97, sizeof(__pyx_k_97), 0, 0, 1, 0},
31217   {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0},
31218   {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0},
31219   {&__pyx_n_s__A, __pyx_k__A, sizeof(__pyx_k__A), 0, 0, 1, 1},
31220   {&__pyx_n_s__AS, __pyx_k__AS, sizeof(__pyx_k__AS), 0, 0, 1, 1},
31221   {&__pyx_n_s__AlignedRead, __pyx_k__AlignedRead, sizeof(__pyx_k__AlignedRead), 0, 0, 1, 1},
31222   {&__pyx_n_s__AttributeError, __pyx_k__AttributeError, sizeof(__pyx_k__AttributeError), 0, 0, 1, 1},
31223   {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1},
31224   {&__pyx_n_s__CL, __pyx_k__CL, sizeof(__pyx_k__CL), 0, 0, 1, 1},
31225   {&__pyx_n_s__CN, __pyx_k__CN, sizeof(__pyx_k__CN), 0, 0, 1, 1},
31226   {&__pyx_n_s__CO, __pyx_k__CO, sizeof(__pyx_k__CO), 0, 0, 1, 1},
31227   {&__pyx_n_s__D, __pyx_k__D, sizeof(__pyx_k__D), 0, 0, 1, 1},
31228   {&__pyx_n_s__DS, __pyx_k__DS, sizeof(__pyx_k__DS), 0, 0, 1, 1},
31229   {&__pyx_n_s__DT, __pyx_k__DT, sizeof(__pyx_k__DT), 0, 0, 1, 1},
31230   {&__pyx_n_s__DictType, __pyx_k__DictType, sizeof(__pyx_k__DictType), 0, 0, 1, 1},
31231   {&__pyx_n_s__F, __pyx_k__F, sizeof(__pyx_k__F), 0, 0, 1, 1},
31232   {&__pyx_n_s__Fastafile, __pyx_k__Fastafile, sizeof(__pyx_k__Fastafile), 0, 0, 1, 1},
31233   {&__pyx_n_s__FloatType, __pyx_k__FloatType, sizeof(__pyx_k__FloatType), 0, 0, 1, 1},
31234   {&__pyx_n_s__GO, __pyx_k__GO, sizeof(__pyx_k__GO), 0, 0, 1, 1},
31235   {&__pyx_n_s__HD, __pyx_k__HD, sizeof(__pyx_k__HD), 0, 0, 1, 1},
31236   {&__pyx_n_s__I, __pyx_k__I, sizeof(__pyx_k__I), 0, 0, 1, 1},
31237   {&__pyx_n_s__ID, __pyx_k__ID, sizeof(__pyx_k__ID), 0, 0, 1, 1},
31238   {&__pyx_n_s__IOError, __pyx_k__IOError, sizeof(__pyx_k__IOError), 0, 0, 1, 1},
31239   {&__pyx_n_s__IndexedReads, __pyx_k__IndexedReads, sizeof(__pyx_k__IndexedReads), 0, 0, 1, 1},
31240   {&__pyx_n_s__IntType, __pyx_k__IntType, sizeof(__pyx_k__IntType), 0, 0, 1, 1},
31241   {&__pyx_n_s__IteratorColumn, __pyx_k__IteratorColumn, sizeof(__pyx_k__IteratorColumn), 0, 0, 1, 1},
31242   {&__pyx_n_s__IteratorRow, __pyx_k__IteratorRow, sizeof(__pyx_k__IteratorRow), 0, 0, 1, 1},
31243   {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1},
31244   {&__pyx_n_s__LB, __pyx_k__LB, sizeof(__pyx_k__LB), 0, 0, 1, 1},
31245   {&__pyx_n_s__LN, __pyx_k__LN, sizeof(__pyx_k__LN), 0, 0, 1, 1},
31246   {&__pyx_n_s__M5, __pyx_k__M5, sizeof(__pyx_k__M5), 0, 0, 1, 1},
31247   {&__pyx_n_s__NotImplementedError, __pyx_k__NotImplementedError, sizeof(__pyx_k__NotImplementedError), 0, 0, 1, 1},
31248   {&__pyx_n_s__OSError, __pyx_k__OSError, sizeof(__pyx_k__OSError), 0, 0, 1, 1},
31249   {&__pyx_n_s__O_CREAT, __pyx_k__O_CREAT, sizeof(__pyx_k__O_CREAT), 0, 0, 1, 1},
31250   {&__pyx_n_s__O_WRONLY, __pyx_k__O_WRONLY, sizeof(__pyx_k__O_WRONLY), 0, 0, 1, 1},
31251   {&__pyx_n_s__Outs, __pyx_k__Outs, sizeof(__pyx_k__Outs), 0, 0, 1, 1},
31252   {&__pyx_n_s__OverflowError, __pyx_k__OverflowError, sizeof(__pyx_k__OverflowError), 0, 0, 1, 1},
31253   {&__pyx_n_s__PG, __pyx_k__PG, sizeof(__pyx_k__PG), 0, 0, 1, 1},
31254   {&__pyx_n_s__PI, __pyx_k__PI, sizeof(__pyx_k__PI), 0, 0, 1, 1},
31255   {&__pyx_n_s__PL, __pyx_k__PL, sizeof(__pyx_k__PL), 0, 0, 1, 1},
31256   {&__pyx_n_s__PN, __pyx_k__PN, sizeof(__pyx_k__PN), 0, 0, 1, 1},
31257   {&__pyx_n_s__PU, __pyx_k__PU, sizeof(__pyx_k__PU), 0, 0, 1, 1},
31258   {&__pyx_n_s__PileupColumn, __pyx_k__PileupColumn, sizeof(__pyx_k__PileupColumn), 0, 0, 1, 1},
31259   {&__pyx_n_s__PileupProxy, __pyx_k__PileupProxy, sizeof(__pyx_k__PileupProxy), 0, 0, 1, 1},
31260   {&__pyx_n_s__PileupRead, __pyx_k__PileupRead, sizeof(__pyx_k__PileupRead), 0, 0, 1, 1},
31261   {&__pyx_n_s__RG, __pyx_k__RG, sizeof(__pyx_k__RG), 0, 0, 1, 1},
31262   {&__pyx_n_s__S, __pyx_k__S, sizeof(__pyx_k__S), 0, 0, 1, 1},
31263   {&__pyx_n_s__SM, __pyx_k__SM, sizeof(__pyx_k__SM), 0, 0, 1, 1},
31264   {&__pyx_n_s__SN, __pyx_k__SN, sizeof(__pyx_k__SN), 0, 0, 1, 1},
31265   {&__pyx_n_s__SO, __pyx_k__SO, sizeof(__pyx_k__SO), 0, 0, 1, 1},
31266   {&__pyx_n_s__SP, __pyx_k__SP, sizeof(__pyx_k__SP), 0, 0, 1, 1},
31267   {&__pyx_n_s__SQ, __pyx_k__SQ, sizeof(__pyx_k__SQ), 0, 0, 1, 1},
31268   {&__pyx_n_s__Samfile, __pyx_k__Samfile, sizeof(__pyx_k__Samfile), 0, 0, 1, 1},
31269   {&__pyx_n_s__StderrStore, __pyx_k__StderrStore, sizeof(__pyx_k__StderrStore), 0, 0, 1, 1},
31270   {&__pyx_n_s__StderrStoreWindows, __pyx_k__StderrStoreWindows, sizeof(__pyx_k__StderrStoreWindows), 0, 0, 1, 1},
31271   {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1},
31272   {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
31273   {&__pyx_n_s__UR, __pyx_k__UR, sizeof(__pyx_k__UR), 0, 0, 1, 1},
31274   {&__pyx_n_s__VALID_HEADERS, __pyx_k__VALID_HEADERS, sizeof(__pyx_k__VALID_HEADERS), 0, 0, 1, 1},
31275   {&__pyx_n_s__VALID_HEADER_FIELDS, __pyx_k__VALID_HEADER_FIELDS, sizeof(__pyx_k__VALID_HEADER_FIELDS), 0, 0, 1, 1},
31276   {&__pyx_n_s__VALID_HEADER_ORDER, __pyx_k__VALID_HEADER_ORDER, sizeof(__pyx_k__VALID_HEADER_ORDER), 0, 0, 1, 1},
31277   {&__pyx_n_s__VALID_HEADER_TYPES, __pyx_k__VALID_HEADER_TYPES, sizeof(__pyx_k__VALID_HEADER_TYPES), 0, 0, 1, 1},
31278   {&__pyx_n_s__VN, __pyx_k__VN, sizeof(__pyx_k__VN), 0, 0, 1, 1},
31279   {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
31280   {&__pyx_n_s__Windows, __pyx_k__Windows, sizeof(__pyx_k__Windows), 0, 0, 1, 1},
31281   {&__pyx_n_s__Z, __pyx_k__Z, sizeof(__pyx_k__Z), 0, 0, 1, 1},
31282   {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1},
31283   {&__pyx_n_s____del__, __pyx_k____del__, sizeof(__pyx_k____del__), 0, 0, 1, 1},
31284   {&__pyx_n_s____dict__, __pyx_k____dict__, sizeof(__pyx_k____dict__), 0, 0, 1, 1},
31285   {&__pyx_n_s____getattribute__, __pyx_k____getattribute__, sizeof(__pyx_k____getattribute__), 0, 0, 1, 1},
31286   {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1},
31287   {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
31288   {&__pyx_n_s____str__, __pyx_k____str__, sizeof(__pyx_k____str__), 0, 0, 1, 1},
31289   {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
31290   {&__pyx_n_s___alignment, __pyx_k___alignment, sizeof(__pyx_k___alignment), 0, 0, 1, 1},
31291   {&__pyx_n_s___buildHeader, __pyx_k___buildHeader, sizeof(__pyx_k___buildHeader), 0, 0, 1, 1},
31292   {&__pyx_n_s___buildLine, __pyx_k___buildLine, sizeof(__pyx_k___buildLine), 0, 0, 1, 1},
31293   {&__pyx_n_s___consensus_quality, __pyx_k___consensus_quality, sizeof(__pyx_k___consensus_quality), 0, 0, 1, 1},
31294   {&__pyx_n_s___coverage, __pyx_k___coverage, sizeof(__pyx_k___coverage), 0, 0, 1, 1},
31295   {&__pyx_n_s___delegate, __pyx_k___delegate, sizeof(__pyx_k___delegate), 0, 0, 1, 1},
31296   {&__pyx_n_s___filename, __pyx_k___filename, sizeof(__pyx_k___filename), 0, 0, 1, 1},
31297   {&__pyx_n_s___genotype, __pyx_k___genotype, sizeof(__pyx_k___genotype), 0, 0, 1, 1},
31298   {&__pyx_n_s___hasIndex, __pyx_k___hasIndex, sizeof(__pyx_k___hasIndex), 0, 0, 1, 1},
31299   {&__pyx_n_s___indel, __pyx_k___indel, sizeof(__pyx_k___indel), 0, 0, 1, 1},
31300   {&__pyx_n_s___isOpen, __pyx_k___isOpen, sizeof(__pyx_k___isOpen), 0, 0, 1, 1},
31301   {&__pyx_n_s___is_del, __pyx_k___is_del, sizeof(__pyx_k___is_del), 0, 0, 1, 1},
31302   {&__pyx_n_s___is_head, __pyx_k___is_head, sizeof(__pyx_k___is_head), 0, 0, 1, 1},
31303   {&__pyx_n_s___is_tail, __pyx_k___is_tail, sizeof(__pyx_k___is_tail), 0, 0, 1, 1},
31304   {&__pyx_n_s___level, __pyx_k___level, sizeof(__pyx_k___level), 0, 0, 1, 1},
31305   {&__pyx_n_s___logfile, __pyx_k___logfile, sizeof(__pyx_k___logfile), 0, 0, 1, 1},
31306   {&__pyx_n_s___open, __pyx_k___open, sizeof(__pyx_k___open), 0, 0, 1, 1},
31307   {&__pyx_n_s___parseRegion, __pyx_k___parseRegion, sizeof(__pyx_k___parseRegion), 0, 0, 1, 1},
31308   {&__pyx_n_s___pos, __pyx_k___pos, sizeof(__pyx_k___pos), 0, 0, 1, 1},
31309   {&__pyx_n_s___qpos, __pyx_k___qpos, sizeof(__pyx_k___qpos), 0, 0, 1, 1},
31310   {&__pyx_n_s___reference_base, __pyx_k___reference_base, sizeof(__pyx_k___reference_base), 0, 0, 1, 1},
31311   {&__pyx_n_s___samtools_dispatch, __pyx_k___samtools_dispatch, sizeof(__pyx_k___samtools_dispatch), 0, 0, 1, 1},
31312   {&__pyx_n_s___snp_quality, __pyx_k___snp_quality, sizeof(__pyx_k___snp_quality), 0, 0, 1, 1},
31313   {&__pyx_n_s___tid, __pyx_k___tid, sizeof(__pyx_k___tid), 0, 0, 1, 1},
31314   {&__pyx_n_s__add_sq_text, __pyx_k__add_sq_text, sizeof(__pyx_k__add_sq_text), 0, 0, 1, 1},
31315   {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1},
31316   {&__pyx_n_s__all, __pyx_k__all, sizeof(__pyx_k__all), 0, 0, 1, 1},
31317   {&__pyx_n_s__append, __pyx_k__append, sizeof(__pyx_k__append), 0, 0, 1, 1},
31318   {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
31319   {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1},
31320   {&__pyx_n_s__bam, __pyx_k__bam, sizeof(__pyx_k__bam), 0, 0, 1, 1},
31321   {&__pyx_n_s__beg, __pyx_k__beg, sizeof(__pyx_k__beg), 0, 0, 1, 1},
31322   {&__pyx_n_s__bin, __pyx_k__bin, sizeof(__pyx_k__bin), 0, 0, 1, 1},
31323   {&__pyx_n_s__bqual, __pyx_k__bqual, sizeof(__pyx_k__bqual), 0, 0, 1, 1},
31324   {&__pyx_n_s__c, __pyx_k__c, sizeof(__pyx_k__c), 0, 0, 1, 1},
31325   {&__pyx_n_s__calcsize, __pyx_k__calcsize, sizeof(__pyx_k__calcsize), 0, 0, 1, 1},
31326   {&__pyx_n_s__callback, __pyx_k__callback, sizeof(__pyx_k__callback), 0, 0, 1, 1},
31327   {&__pyx_n_s__catch_stderr, __pyx_k__catch_stderr, sizeof(__pyx_k__catch_stderr), 0, 0, 1, 1},
31328   {&__pyx_n_s__catch_stdout, __pyx_k__catch_stdout, sizeof(__pyx_k__catch_stdout), 0, 0, 1, 1},
31329   {&__pyx_n_s__chr, __pyx_k__chr, sizeof(__pyx_k__chr), 0, 0, 1, 1},
31330   {&__pyx_n_s__cigar, __pyx_k__cigar, sizeof(__pyx_k__cigar), 0, 0, 1, 1},
31331   {&__pyx_n_s__close, __pyx_k__close, sizeof(__pyx_k__close), 0, 0, 1, 1},
31332   {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1},
31333   {&__pyx_n_s__cnext, __pyx_k__cnext, sizeof(__pyx_k__cnext), 0, 0, 1, 1},
31334   {&__pyx_n_s__collections, __pyx_k__collections, sizeof(__pyx_k__collections), 0, 0, 1, 1},
31335   {&__pyx_n_s__consensus_quality, __pyx_k__consensus_quality, sizeof(__pyx_k__consensus_quality), 0, 0, 1, 1},
31336   {&__pyx_n_s__core, __pyx_k__core, sizeof(__pyx_k__core), 0, 0, 1, 1},
31337   {&__pyx_n_s__coverage, __pyx_k__coverage, sizeof(__pyx_k__coverage), 0, 0, 1, 1},
31338   {&__pyx_n_s__csamtools, __pyx_k__csamtools, sizeof(__pyx_k__csamtools), 0, 0, 1, 1},
31339   {&__pyx_n_s__ctypes, __pyx_k__ctypes, sizeof(__pyx_k__ctypes), 0, 0, 1, 1},
31340   {&__pyx_n_s__current_pos, __pyx_k__current_pos, sizeof(__pyx_k__current_pos), 0, 0, 1, 1},
31341   {&__pyx_n_s__d, __pyx_k__d, sizeof(__pyx_k__d), 0, 0, 1, 1},
31342   {&__pyx_n_s__data, __pyx_k__data, sizeof(__pyx_k__data), 0, 0, 1, 1},
31343   {&__pyx_n_s__data_len, __pyx_k__data_len, sizeof(__pyx_k__data_len), 0, 0, 1, 1},
31344   {&__pyx_n_s__defaultdict, __pyx_k__defaultdict, sizeof(__pyx_k__defaultdict), 0, 0, 1, 1},
31345   {&__pyx_n_s__devnull, __pyx_k__devnull, sizeof(__pyx_k__devnull), 0, 0, 1, 1},
31346   {&__pyx_n_s__dup, __pyx_k__dup, sizeof(__pyx_k__dup), 0, 0, 1, 1},
31347   {&__pyx_n_s__dup2, __pyx_k__dup2, sizeof(__pyx_k__dup2), 0, 0, 1, 1},
31348   {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
31349   {&__pyx_n_s__exc_type, __pyx_k__exc_type, sizeof(__pyx_k__exc_type), 0, 0, 1, 1},
31350   {&__pyx_n_s__exc_value, __pyx_k__exc_value, sizeof(__pyx_k__exc_value), 0, 0, 1, 1},
31351   {&__pyx_n_s__exists, __pyx_k__exists, sizeof(__pyx_k__exists), 0, 0, 1, 1},
31352   {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1},
31353   {&__pyx_n_s__fastafile, __pyx_k__fastafile, sizeof(__pyx_k__fastafile), 0, 0, 1, 1},
31354   {&__pyx_n_s__fd, __pyx_k__fd, sizeof(__pyx_k__fd), 0, 0, 1, 1},
31355   {&__pyx_n_s__fields, __pyx_k__fields, sizeof(__pyx_k__fields), 0, 0, 1, 1},
31356   {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1},
31357   {&__pyx_n_s__fileno, __pyx_k__fileno, sizeof(__pyx_k__fileno), 0, 0, 1, 1},
31358   {&__pyx_n_s__flag, __pyx_k__flag, sizeof(__pyx_k__flag), 0, 0, 1, 1},
31359   {&__pyx_n_s__flush, __pyx_k__flush, sizeof(__pyx_k__flush), 0, 0, 1, 1},
31360   {&__pyx_n_s__fp, __pyx_k__fp, sizeof(__pyx_k__fp), 0, 0, 1, 1},
31361   {&__pyx_n_s__genotype, __pyx_k__genotype, sizeof(__pyx_k__genotype), 0, 0, 1, 1},
31362   {&__pyx_n_s__gettid, __pyx_k__gettid, sizeof(__pyx_k__gettid), 0, 0, 1, 1},
31363   {&__pyx_n_s__hash, __pyx_k__hash, sizeof(__pyx_k__hash), 0, 0, 1, 1},
31364   {&__pyx_n_s__header, __pyx_k__header, sizeof(__pyx_k__header), 0, 0, 1, 1},
31365   {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
31366   {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1},
31367   {&__pyx_n_s__indel, __pyx_k__indel, sizeof(__pyx_k__indel), 0, 0, 1, 1},
31368   {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1},
31369   {&__pyx_n_s__is_del, __pyx_k__is_del, sizeof(__pyx_k__is_del), 0, 0, 1, 1},
31370   {&__pyx_n_s__is_head, __pyx_k__is_head, sizeof(__pyx_k__is_head), 0, 0, 1, 1},
31371   {&__pyx_n_s__is_tail, __pyx_k__is_tail, sizeof(__pyx_k__is_tail), 0, 0, 1, 1},
31372   {&__pyx_n_s__isbam, __pyx_k__isbam, sizeof(__pyx_k__isbam), 0, 0, 1, 1},
31373   {&__pyx_n_s__isize, __pyx_k__isize, sizeof(__pyx_k__isize), 0, 0, 1, 1},
31374   {&__pyx_n_s__isremote, __pyx_k__isremote, sizeof(__pyx_k__isremote), 0, 0, 1, 1},
31375   {&__pyx_n_s__isstream, __pyx_k__isstream, sizeof(__pyx_k__isstream), 0, 0, 1, 1},
31376   {&__pyx_n_s__isupper, __pyx_k__isupper, sizeof(__pyx_k__isupper), 0, 0, 1, 1},
31377   {&__pyx_n_s__iter, __pyx_k__iter, sizeof(__pyx_k__iter), 0, 0, 1, 1},
31378   {&__pyx_n_s__iterdata, __pyx_k__iterdata, sizeof(__pyx_k__iterdata), 0, 0, 1, 1},
31379   {&__pyx_n_s__itertools, __pyx_k__itertools, sizeof(__pyx_k__itertools), 0, 0, 1, 1},
31380   {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1},
31381   {&__pyx_n_s__l_aux, __pyx_k__l_aux, sizeof(__pyx_k__l_aux), 0, 0, 1, 1},
31382   {&__pyx_n_s__l_qname, __pyx_k__l_qname, sizeof(__pyx_k__l_qname), 0, 0, 1, 1},
31383   {&__pyx_n_s__l_qseq, __pyx_k__l_qseq, sizeof(__pyx_k__l_qseq), 0, 0, 1, 1},
31384   {&__pyx_n_s__l_text, __pyx_k__l_text, sizeof(__pyx_k__l_text), 0, 0, 1, 1},
31385   {&__pyx_n_s__level, __pyx_k__level, sizeof(__pyx_k__level), 0, 0, 1, 1},
31386   {&__pyx_n_s__m_data, __pyx_k__m_data, sizeof(__pyx_k__m_data), 0, 0, 1, 1},
31387   {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1},
31388   {&__pyx_n_s__mapping_quality, __pyx_k__mapping_quality, sizeof(__pyx_k__mapping_quality), 0, 0, 1, 1},
31389   {&__pyx_n_s__mapq, __pyx_k__mapq, sizeof(__pyx_k__mapq), 0, 0, 1, 1},
31390   {&__pyx_n_s__mask, __pyx_k__mask, sizeof(__pyx_k__mask), 0, 0, 1, 1},
31391   {&__pyx_n_s__mate, __pyx_k__mate, sizeof(__pyx_k__mate), 0, 0, 1, 1},
31392   {&__pyx_n_s__max_depth, __pyx_k__max_depth, sizeof(__pyx_k__max_depth), 0, 0, 1, 1},
31393   {&__pyx_n_s__method, __pyx_k__method, sizeof(__pyx_k__method), 0, 0, 1, 1},
31394   {&__pyx_n_s__mkstemp, __pyx_k__mkstemp, sizeof(__pyx_k__mkstemp), 0, 0, 1, 1},
31395   {&__pyx_n_s__mode, __pyx_k__mode, sizeof(__pyx_k__mode), 0, 0, 1, 1},
31396   {&__pyx_n_s__mpos, __pyx_k__mpos, sizeof(__pyx_k__mpos), 0, 0, 1, 1},
31397   {&__pyx_n_s__mrnm, __pyx_k__mrnm, sizeof(__pyx_k__mrnm), 0, 0, 1, 1},
31398   {&__pyx_n_s__mtid, __pyx_k__mtid, sizeof(__pyx_k__mtid), 0, 0, 1, 1},
31399   {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
31400   {&__pyx_n_s__n_cigar, __pyx_k__n_cigar, sizeof(__pyx_k__n_cigar), 0, 0, 1, 1},
31401   {&__pyx_n_s__n_plp, __pyx_k__n_plp, sizeof(__pyx_k__n_plp), 0, 0, 1, 1},
31402   {&__pyx_n_s__n_pu, __pyx_k__n_pu, sizeof(__pyx_k__n_pu), 0, 0, 1, 1},
31403   {&__pyx_n_s__n_targets, __pyx_k__n_targets, sizeof(__pyx_k__n_targets), 0, 0, 1, 1},
31404   {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1},
31405   {&__pyx_n_s__nextiter, __pyx_k__nextiter, sizeof(__pyx_k__nextiter), 0, 0, 1, 1},
31406   {&__pyx_n_s__nreferences, __pyx_k__nreferences, sizeof(__pyx_k__nreferences), 0, 0, 1, 1},
31407   {&__pyx_n_s__object, __pyx_k__object, sizeof(__pyx_k__object), 0, 0, 1, 1},
31408   {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1},
31409   {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1},
31410   {&__pyx_n_s__os, __pyx_k__os, sizeof(__pyx_k__os), 0, 0, 1, 1},
31411   {&__pyx_n_s__owns_samfile, __pyx_k__owns_samfile, sizeof(__pyx_k__owns_samfile), 0, 0, 1, 1},
31412   {&__pyx_n_s__pack_into, __pyx_k__pack_into, sizeof(__pyx_k__pack_into), 0, 0, 1, 1},
31413   {&__pyx_n_s__path, __pyx_k__path, sizeof(__pyx_k__path), 0, 0, 1, 1},
31414   {&__pyx_n_s__pileup_iter, __pyx_k__pileup_iter, sizeof(__pyx_k__pileup_iter), 0, 0, 1, 1},
31415   {&__pyx_n_s__pileups, __pyx_k__pileups, sizeof(__pyx_k__pileups), 0, 0, 1, 1},
31416   {&__pyx_n_s__platform, __pyx_k__platform, sizeof(__pyx_k__platform), 0, 0, 1, 1},
31417   {&__pyx_n_s__plp, __pyx_k__plp, sizeof(__pyx_k__plp), 0, 0, 1, 1},
31418   {&__pyx_n_s__port, __pyx_k__port, sizeof(__pyx_k__port), 0, 0, 1, 1},
31419   {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
31420   {&__pyx_n_s__positions, __pyx_k__positions, sizeof(__pyx_k__positions), 0, 0, 1, 1},
31421   {&__pyx_n_s__qname, __pyx_k__qname, sizeof(__pyx_k__qname), 0, 0, 1, 1},
31422   {&__pyx_n_s__qpos, __pyx_k__qpos, sizeof(__pyx_k__qpos), 0, 0, 1, 1},
31423   {&__pyx_n_s__qseq, __pyx_k__qseq, sizeof(__pyx_k__qseq), 0, 0, 1, 1},
31424   {&__pyx_n_s__qual, __pyx_k__qual, sizeof(__pyx_k__qual), 0, 0, 1, 1},
31425   {&__pyx_n_s__r, __pyx_k__r, sizeof(__pyx_k__r), 0, 0, 1, 1},
31426   {&__pyx_n_s__rU, __pyx_k__rU, sizeof(__pyx_k__rU), 0, 0, 1, 1},
31427   {&__pyx_n_s__raw, __pyx_k__raw, sizeof(__pyx_k__raw), 0, 0, 1, 1},
31428   {&__pyx_n_s__rb, __pyx_k__rb, sizeof(__pyx_k__rb), 0, 0, 1, 1},
31429   {&__pyx_n_s__re, __pyx_k__re, sizeof(__pyx_k__re), 0, 0, 1, 1},
31430   {&__pyx_n_s__readAndRelease, __pyx_k__readAndRelease, sizeof(__pyx_k__readAndRelease), 0, 0, 1, 1},
31431   {&__pyx_n_s__readlines, __pyx_k__readlines, sizeof(__pyx_k__readlines), 0, 0, 1, 1},
31432   {&__pyx_n_s__record, __pyx_k__record, sizeof(__pyx_k__record), 0, 0, 1, 1},
31433   {&__pyx_n_s__reference, __pyx_k__reference, sizeof(__pyx_k__reference), 0, 0, 1, 1},
31434   {&__pyx_n_s__reference_base, __pyx_k__reference_base, sizeof(__pyx_k__reference_base), 0, 0, 1, 1},
31435   {&__pyx_n_s__referencelengths, __pyx_k__referencelengths, sizeof(__pyx_k__referencelengths), 0, 0, 1, 1},
31436   {&__pyx_n_s__referencenames, __pyx_k__referencenames, sizeof(__pyx_k__referencenames), 0, 0, 1, 1},
31437   {&__pyx_n_s__region, __pyx_k__region, sizeof(__pyx_k__region), 0, 0, 1, 1},
31438   {&__pyx_n_s__release, __pyx_k__release, sizeof(__pyx_k__release), 0, 0, 1, 1},
31439   {&__pyx_n_s__remove, __pyx_k__remove, sizeof(__pyx_k__remove), 0, 0, 1, 1},
31440   {&__pyx_n_s__reopen, __pyx_k__reopen, sizeof(__pyx_k__reopen), 0, 0, 1, 1},
31441   {&__pyx_n_s__restore, __pyx_k__restore, sizeof(__pyx_k__restore), 0, 0, 1, 1},
31442   {&__pyx_n_s__retval, __pyx_k__retval, sizeof(__pyx_k__retval), 0, 0, 1, 1},
31443   {&__pyx_n_s__rg2lib, __pyx_k__rg2lib, sizeof(__pyx_k__rg2lib), 0, 0, 1, 1},
31444   {&__pyx_n_s__rlen, __pyx_k__rlen, sizeof(__pyx_k__rlen), 0, 0, 1, 1},
31445   {&__pyx_n_s__rname, __pyx_k__rname, sizeof(__pyx_k__rname), 0, 0, 1, 1},
31446   {&__pyx_n_s__rowiter, __pyx_k__rowiter, sizeof(__pyx_k__rowiter), 0, 0, 1, 1},
31447   {&__pyx_n_s__s, __pyx_k__s, sizeof(__pyx_k__s), 0, 0, 1, 1},
31448   {&__pyx_n_s__samfile, __pyx_k__samfile, sizeof(__pyx_k__samfile), 0, 0, 1, 1},
31449   {&__pyx_n_s__samtools, __pyx_k__samtools, sizeof(__pyx_k__samtools), 0, 0, 1, 1},
31450   {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1},
31451   {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1},
31452   {&__pyx_n_s__seq, __pyx_k__seq, sizeof(__pyx_k__seq), 0, 0, 1, 1},
31453   {&__pyx_n_s__seq_len, __pyx_k__seq_len, sizeof(__pyx_k__seq_len), 0, 0, 1, 1},
31454   {&__pyx_n_s__setdevice, __pyx_k__setdevice, sizeof(__pyx_k__setdevice), 0, 0, 1, 1},
31455   {&__pyx_n_s__setfd, __pyx_k__setfd, sizeof(__pyx_k__setfd), 0, 0, 1, 1},
31456   {&__pyx_n_s__setfile, __pyx_k__setfile, sizeof(__pyx_k__setfile), 0, 0, 1, 1},
31457   {&__pyx_n_s__setupIteratorData, __pyx_k__setupIteratorData, sizeof(__pyx_k__setupIteratorData), 0, 0, 1, 1},
31458   {&__pyx_n_s__snp_quality, __pyx_k__snp_quality, sizeof(__pyx_k__snp_quality), 0, 0, 1, 1},
31459   {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
31460   {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
31461   {&__pyx_n_s__start_offset, __pyx_k__start_offset, sizeof(__pyx_k__start_offset), 0, 0, 1, 1},
31462   {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1},
31463   {&__pyx_n_s__stderr, __pyx_k__stderr, sizeof(__pyx_k__stderr), 0, 0, 1, 1},
31464   {&__pyx_n_s__stderr_f, __pyx_k__stderr_f, sizeof(__pyx_k__stderr_f), 0, 0, 1, 1},
31465   {&__pyx_n_s__stderr_h, __pyx_k__stderr_h, sizeof(__pyx_k__stderr_h), 0, 0, 1, 1},
31466   {&__pyx_n_s__stderr_save, __pyx_k__stderr_save, sizeof(__pyx_k__stderr_save), 0, 0, 1, 1},
31467   {&__pyx_n_s__stdout, __pyx_k__stdout, sizeof(__pyx_k__stdout), 0, 0, 1, 1},
31468   {&__pyx_n_s__stepper, __pyx_k__stepper, sizeof(__pyx_k__stepper), 0, 0, 1, 1},
31469   {&__pyx_n_s__streams, __pyx_k__streams, sizeof(__pyx_k__streams), 0, 0, 1, 1},
31470   {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1},
31471   {&__pyx_n_s__struct, __pyx_k__struct, sizeof(__pyx_k__struct), 0, 0, 1, 1},
31472   {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
31473   {&__pyx_n_s__system, __pyx_k__system, sizeof(__pyx_k__system), 0, 0, 1, 1},
31474   {&__pyx_n_s__tags, __pyx_k__tags, sizeof(__pyx_k__tags), 0, 0, 1, 1},
31475   {&__pyx_n_s__target_len, __pyx_k__target_len, sizeof(__pyx_k__target_len), 0, 0, 1, 1},
31476   {&__pyx_n_s__target_name, __pyx_k__target_name, sizeof(__pyx_k__target_name), 0, 0, 1, 1},
31477   {&__pyx_n_s__tempfile, __pyx_k__tempfile, sizeof(__pyx_k__tempfile), 0, 0, 1, 1},
31478   {&__pyx_n_s__template, __pyx_k__template, sizeof(__pyx_k__template), 0, 0, 1, 1},
31479   {&__pyx_n_s__text, __pyx_k__text, sizeof(__pyx_k__text), 0, 0, 1, 1},
31480   {&__pyx_n_s__tid, __pyx_k__tid, sizeof(__pyx_k__tid), 0, 0, 1, 1},
31481   {&__pyx_n_s__traceback, __pyx_k__traceback, sizeof(__pyx_k__traceback), 0, 0, 1, 1},
31482   {&__pyx_n_s__types, __pyx_k__types, sizeof(__pyx_k__types), 0, 0, 1, 1},
31483   {&__pyx_n_s__until_eof, __pyx_k__until_eof, sizeof(__pyx_k__until_eof), 0, 0, 1, 1},
31484   {&__pyx_n_s__view, __pyx_k__view, sizeof(__pyx_k__view), 0, 0, 1, 1},
31485   {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1},
31486   {&__pyx_n_s__wb, __pyx_k__wb, sizeof(__pyx_k__wb), 0, 0, 1, 1},
31487   {&__pyx_n_s__wbu, __pyx_k__wbu, sizeof(__pyx_k__wbu), 0, 0, 1, 1},
31488   {&__pyx_n_s__wh, __pyx_k__wh, sizeof(__pyx_k__wh), 0, 0, 1, 1},
31489   {&__pyx_n_s__where, __pyx_k__where, sizeof(__pyx_k__where), 0, 0, 1, 1},
31490   {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1},
31491   {&__pyx_n_s__x, __pyx_k__x, sizeof(__pyx_k__x), 0, 0, 1, 1},
31492   {0, 0, 0, 0, 0, 0, 0}
31493 };
31494 static int __Pyx_InitCachedBuiltins(void) {
31495   __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31496   __pyx_builtin_object = __Pyx_GetName(__pyx_b, __pyx_n_s__object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31497   __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31498   __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31499   __pyx_builtin_IOError = __Pyx_GetName(__pyx_b, __pyx_n_s__IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31500   __pyx_builtin_OverflowError = __Pyx_GetName(__pyx_b, __pyx_n_s__OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31501   __pyx_builtin_NotImplementedError = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31502   __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31503   __pyx_builtin_AttributeError = __Pyx_GetName(__pyx_b, __pyx_n_s__AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31504   __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31505   __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31506   __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31507   __pyx_builtin_chr = __Pyx_GetName(__pyx_b, __pyx_n_s__chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31508   __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31509   return 0;
31510   __pyx_L1_error:;
31511   return -1;
31512 }
31513
31514 static int __Pyx_InitCachedConstants(void) {
31515   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants");
31516
31517   /* "csamtools.pyx":271
31518  *     def __len__(self):
31519  *         if self.fastafile == NULL:
31520  *             raise ValueError( "calling len() on closed file" )             # <<<<<<<<<<<<<<
31521  * 
31522  *         return faidx_fetch_nseq(self.fastafile)
31523  */
31524   __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31525   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
31526   __Pyx_INCREF(((PyObject *)__pyx_kp_s_3));
31527   PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3));
31528   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3));
31529   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
31530
31531   /* "csamtools.pyx":303
31532  *         '''number of :term:`filename` associated with this object.'''
31533  *         def __get__(self):
31534  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31535  *             return self._filename
31536  * 
31537  */
31538   __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31539   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7));
31540   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31541   PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_kp_s_6));
31542   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31543   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7));
31544
31545   /* "csamtools.pyx":328
31546  * 
31547  *         if not self._isOpen():
31548  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31549  * 
31550  *         cdef int length
31551  */
31552   __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31553   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_8));
31554   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31555   PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_kp_s_6));
31556   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31557   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8));
31558
31559   /* "csamtools.pyx":334
31560  * 
31561  *         if not region:
31562  *             if reference is None: raise ValueError( 'no sequence/region supplied.' )             # <<<<<<<<<<<<<<
31563  *             if start is None: start = 0
31564  *             if end is None: end = max_pos -1
31565  */
31566   __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31567   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
31568   __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
31569   PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9));
31570   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
31571   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
31572
31573   /* "csamtools.pyx":636
31574  *         returns -1 if reference is not known.
31575  *         '''
31576  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31577  *         return pysam_reference2tid( self.samfile.header, reference )
31578  * 
31579  */
31580   __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31581   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_29));
31582   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31583   PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_6));
31584   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31585   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));
31586
31587   /* "csamtools.pyx":642
31588  *         '''
31589  *         convert numerical :term:`tid` into :term:`reference` name.'''
31590  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31591  *         if not 0 <= tid < self.samfile.header.n_targets:
31592  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
31593  */
31594   __pyx_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31595   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_30));
31596   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31597   PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_6));
31598   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31599   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30));
31600
31601   /* "csamtools.pyx":650
31602  *         '''
31603  *         convert numerical :term:`tid` into :term:`reference` name.'''
31604  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31605  *         if not 0 <= tid < self.samfile.header.n_targets:
31606  *             raise ValueError( "tid %i out of range 0<=tid<%i" % (tid, self.samfile.header.n_targets ) )
31607  */
31608   __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 650; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31609   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_32));
31610   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31611   PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_6));
31612   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31613   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32));
31614
31615   /* "csamtools.pyx":699
31616  *             if len(parts) >= 3: rend = int(parts[2])
31617  * 
31618  *         if not reference: return 0, 0, 0, 0             # <<<<<<<<<<<<<<
31619  * 
31620  *         rtid = self.gettid( reference )
31621  */
31622   __pyx_k_tuple_34 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31623   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_34));
31624   __Pyx_INCREF(__pyx_int_0);
31625   PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, __pyx_int_0);
31626   __Pyx_GIVEREF(__pyx_int_0);
31627   __Pyx_INCREF(__pyx_int_0);
31628   PyTuple_SET_ITEM(__pyx_k_tuple_34, 1, __pyx_int_0);
31629   __Pyx_GIVEREF(__pyx_int_0);
31630   __Pyx_INCREF(__pyx_int_0);
31631   PyTuple_SET_ITEM(__pyx_k_tuple_34, 2, __pyx_int_0);
31632   __Pyx_GIVEREF(__pyx_int_0);
31633   __Pyx_INCREF(__pyx_int_0);
31634   PyTuple_SET_ITEM(__pyx_k_tuple_34, 3, __pyx_int_0);
31635   __Pyx_GIVEREF(__pyx_int_0);
31636   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34));
31637
31638   /* "csamtools.pyx":719
31639  * 
31640  *         if not self._isOpen():
31641  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31642  *         if not self.isbam:
31643  *             raise NotImplementedError("seek only available in bam files")
31644  */
31645   __pyx_k_tuple_37 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31646   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_37));
31647   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31648   PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, ((PyObject *)__pyx_kp_s_6));
31649   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31650   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));
31651
31652   /* "csamtools.pyx":721
31653  *             raise ValueError( "I/O operation on closed file" )
31654  *         if not self.isbam:
31655  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
31656  *         if self.isstream:
31657  *             raise OSError("seek no available in streams")
31658  */
31659   __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31660   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_39));
31661   __Pyx_INCREF(((PyObject *)__pyx_kp_s_38));
31662   PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_kp_s_38));
31663   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_38));
31664   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39));
31665
31666   /* "csamtools.pyx":723
31667  *             raise NotImplementedError("seek only available in bam files")
31668  *         if self.isstream:
31669  *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
31670  * 
31671  *         return bam_seek( self.samfile.x.bam, offset, where )
31672  */
31673   __pyx_k_tuple_41 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31674   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_41));
31675   __Pyx_INCREF(((PyObject *)__pyx_kp_s_40));
31676   PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_kp_s_40));
31677   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_40));
31678   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41));
31679
31680   /* "csamtools.pyx":732
31681  *         '''
31682  *         if not self._isOpen():
31683  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31684  *         if not self.isbam:
31685  *             raise NotImplementedError("seek only available in bam files")
31686  */
31687   __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31688   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_42));
31689   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31690   PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_6));
31691   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31692   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));
31693
31694   /* "csamtools.pyx":734
31695  *             raise ValueError( "I/O operation on closed file" )
31696  *         if not self.isbam:
31697  *             raise NotImplementedError("seek only available in bam files")             # <<<<<<<<<<<<<<
31698  * 
31699  *         return bam_tell( self.samfile.x.bam )
31700  */
31701   __pyx_k_tuple_43 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31702   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_43));
31703   __Pyx_INCREF(((PyObject *)__pyx_kp_s_38));
31704   PyTuple_SET_ITEM(__pyx_k_tuple_43, 0, ((PyObject *)__pyx_kp_s_38));
31705   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_38));
31706   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_43));
31707
31708   /* "csamtools.pyx":769
31709  * 
31710  *         if not self._isOpen():
31711  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31712  * 
31713  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
31714  */
31715   __pyx_k_tuple_45 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31716   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_45));
31717   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31718   PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_kp_s_6));
31719   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31720   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45));
31721
31722   /* "csamtools.pyx":778
31723  *         if self.isbam:
31724  *             if not until_eof and not self._hasIndex() and not self.isremote:
31725  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
31726  * 
31727  *             if callback:
31728  */
31729   __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31730   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_47));
31731   __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
31732   PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_kp_s_46));
31733   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
31734   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47));
31735
31736   /* "csamtools.pyx":781
31737  * 
31738  *             if callback:
31739  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
31740  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )
31741  *                 return bam_fetch(self.samfile.x.bam,
31742  */
31743   __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31744   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_49));
31745   __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
31746   PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_48));
31747   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
31748   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49));
31749
31750   /* "csamtools.pyx":782
31751  *             if callback:
31752  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )
31753  *                 if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
31754  *                 return bam_fetch(self.samfile.x.bam,
31755  *                                  self.index,
31756  */
31757   __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31758   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_51));
31759   __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
31760   PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_50));
31761   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
31762   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51));
31763
31764   /* "csamtools.pyx":803
31765  *             # this happens if a bamfile is opened with mode 'r'
31766  *             if has_coord:
31767  *                 raise ValueError ("fetching by region is not available for sam files" )             # <<<<<<<<<<<<<<
31768  * 
31769  *             if self.samfile.header.n_targets == 0:
31770  */
31771   __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31772   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_53));
31773   __Pyx_INCREF(((PyObject *)__pyx_kp_s_52));
31774   PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_kp_s_52));
31775   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_52));
31776   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53));
31777
31778   /* "csamtools.pyx":806
31779  * 
31780  *             if self.samfile.header.n_targets == 0:
31781  *                 raise ValueError( "fetch called for samfile without header")             # <<<<<<<<<<<<<<
31782  * 
31783  *             if callback:
31784  */
31785   __pyx_k_tuple_55 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31786   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_55));
31787   __Pyx_INCREF(((PyObject *)__pyx_kp_s_54));
31788   PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_kp_s_54));
31789   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_54));
31790   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));
31791
31792   /* "csamtools.pyx":809
31793  * 
31794  *             if callback:
31795  *                 raise NotImplementedError( "callback not implemented yet" )             # <<<<<<<<<<<<<<
31796  *             else:
31797  *                 return IteratorRowAll( self, reopen=reopen )
31798  */
31799   __pyx_k_tuple_57 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31800   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_57));
31801   __Pyx_INCREF(((PyObject *)__pyx_kp_s_56));
31802   PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_kp_s_56));
31803   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_56));
31804   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57));
31805
31806   /* "csamtools.pyx":850
31807  * 
31808  *         if mate_data.mate == NULL:
31809  *             raise ValueError( "mate not found" )             # <<<<<<<<<<<<<<
31810  * 
31811  *         cdef AlignedRead dest = AlignedRead.__new__(AlignedRead)
31812  */
31813   __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31814   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_61));
31815   __Pyx_INCREF(((PyObject *)__pyx_kp_s_60));
31816   PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_kp_s_60));
31817   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60));
31818   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));
31819
31820   /* "csamtools.pyx":875
31821  * 
31822  *         if not self._isOpen():
31823  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31824  * 
31825  *         region, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
31826  */
31827   __pyx_k_tuple_63 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31828   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_63));
31829   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31830   PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_kp_s_6));
31831   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31832   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));
31833
31834   /* "csamtools.pyx":884
31835  *         if self.isbam:
31836  *             if not until_eof and not self._hasIndex() and not self.isremote:
31837  *                 raise ValueError( "fetch called on bamfile without index" )             # <<<<<<<<<<<<<<
31838  * 
31839  *             if not region:
31840  */
31841   __pyx_k_tuple_64 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31842   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_64));
31843   __Pyx_INCREF(((PyObject *)__pyx_kp_s_46));
31844   PyTuple_SET_ITEM(__pyx_k_tuple_64, 0, ((PyObject *)__pyx_kp_s_46));
31845   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46));
31846   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_64));
31847
31848   /* "csamtools.pyx":887
31849  * 
31850  *             if not region:
31851  *                 raise ValueError( "counting functionality requires a region/reference" )             # <<<<<<<<<<<<<<
31852  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )
31853  *             bam_fetch(self.samfile.x.bam,
31854  */
31855   __pyx_k_tuple_66 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_66)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31856   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_66));
31857   __Pyx_INCREF(((PyObject *)__pyx_kp_s_65));
31858   PyTuple_SET_ITEM(__pyx_k_tuple_66, 0, ((PyObject *)__pyx_kp_s_65));
31859   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_65));
31860   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_66));
31861
31862   /* "csamtools.pyx":888
31863  *             if not region:
31864  *                 raise ValueError( "counting functionality requires a region/reference" )
31865  *             if not self._hasIndex(): raise ValueError( "no index available for fetch" )             # <<<<<<<<<<<<<<
31866  *             bam_fetch(self.samfile.x.bam,
31867  *                              self.index,
31868  */
31869   __pyx_k_tuple_67 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31870   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_67));
31871   __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
31872   PyTuple_SET_ITEM(__pyx_k_tuple_67, 0, ((PyObject *)__pyx_kp_s_50));
31873   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
31874   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_67));
31875
31876   /* "csamtools.pyx":898
31877  *             return counter
31878  *         else:
31879  *             raise ValueError ("count for a region is not available for sam files" )             # <<<<<<<<<<<<<<
31880  * 
31881  *     def pileup( self,
31882  */
31883   __pyx_k_tuple_69 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31884   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_69));
31885   __Pyx_INCREF(((PyObject *)__pyx_kp_s_68));
31886   PyTuple_SET_ITEM(__pyx_k_tuple_69, 0, ((PyObject *)__pyx_kp_s_68));
31887   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_68));
31888   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_69));
31889
31890   /* "csamtools.pyx":952
31891  * 
31892  *         if not self._isOpen():
31893  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31894  * 
31895  *         has_coord, rtid, rstart, rend = self._parseRegion( reference, start, end, region )
31896  */
31897   __pyx_k_tuple_70 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31898   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_70));
31899   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31900   PyTuple_SET_ITEM(__pyx_k_tuple_70, 0, ((PyObject *)__pyx_kp_s_6));
31901   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31902   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_70));
31903
31904   /* "csamtools.pyx":957
31905  * 
31906  *         if self.isbam:
31907  *             if not self._hasIndex(): raise ValueError( "no index available for pileup" )             # <<<<<<<<<<<<<<
31908  * 
31909  *             if callback:
31910  */
31911   __pyx_k_tuple_72 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31912   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_72));
31913   __Pyx_INCREF(((PyObject *)__pyx_kp_s_71));
31914   PyTuple_SET_ITEM(__pyx_k_tuple_72, 0, ((PyObject *)__pyx_kp_s_71));
31915   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_71));
31916   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_72));
31917
31918   /* "csamtools.pyx":960
31919  * 
31920  *             if callback:
31921  *                 if not has_coord: raise ValueError( "callback functionality requires a region/reference" )             # <<<<<<<<<<<<<<
31922  * 
31923  *                 buf = bam_plbuf_init( <bam_pileup_f>pileup_callback, <void*>callback )
31924  */
31925   __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31926   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_73));
31927   __Pyx_INCREF(((PyObject *)__pyx_kp_s_48));
31928   PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_48));
31929   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48));
31930   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73));
31931
31932   /* "csamtools.pyx":981
31933  * 
31934  *         else:
31935  *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
31936  * 
31937  *     def close( self ):
31938  */
31939   __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31940   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_75));
31941   __Pyx_INCREF(((PyObject *)__pyx_kp_s_74));
31942   PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74));
31943   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74));
31944   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));
31945
31946   /* "csamtools.pyx":1025
31947  *         '''number of :term:`filename` associated with this object.'''
31948  *         def __get__(self):
31949  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31950  *             return self._filename
31951  * 
31952  */
31953   __pyx_k_tuple_76 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31954   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_76));
31955   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31956   PyTuple_SET_ITEM(__pyx_k_tuple_76, 0, ((PyObject *)__pyx_kp_s_6));
31957   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31958   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_76));
31959
31960   /* "csamtools.pyx":1031
31961  *         '''number of :term:`reference` sequences in the file.'''
31962  *         def __get__(self):
31963  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31964  *             return self.samfile.header.n_targets
31965  * 
31966  */
31967   __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31968   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_77));
31969   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31970   PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, ((PyObject *)__pyx_kp_s_6));
31971   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31972   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77));
31973
31974   /* "csamtools.pyx":1037
31975  *         """tuple with the names of :term:`reference` sequences."""
31976  *         def __get__(self):
31977  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31978  *             t = []
31979  *             for x from 0 <= x < self.samfile.header.n_targets:
31980  */
31981   __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31982   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_78));
31983   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31984   PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, ((PyObject *)__pyx_kp_s_6));
31985   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
31986   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78));
31987
31988   /* "csamtools.pyx":1048
31989  *         """
31990  *         def __get__(self):
31991  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
31992  *             t = []
31993  *             for x from 0 <= x < self.samfile.header.n_targets:
31994  */
31995   __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
31996   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_79));
31997   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
31998   PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, ((PyObject *)__pyx_kp_s_6));
31999   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32000   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79));
32001
32002   /* "csamtools.pyx":1058
32003  *         """
32004  *         def __get__(self):
32005  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32006  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )
32007  * 
32008  */
32009   __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32010   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_80));
32011   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32012   PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, ((PyObject *)__pyx_kp_s_6));
32013   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32014   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80));
32015
32016   /* "csamtools.pyx":1059
32017  *         def __get__(self):
32018  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
32019  *             if not self.isbam: raise AttributeError( "Samfile.mapped only available in bam files" )             # <<<<<<<<<<<<<<
32020  * 
32021  *             cdef int tid
32022  */
32023   __pyx_k_tuple_82 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32024   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_82));
32025   __Pyx_INCREF(((PyObject *)__pyx_kp_s_81));
32026   PyTuple_SET_ITEM(__pyx_k_tuple_82, 0, ((PyObject *)__pyx_kp_s_81));
32027   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_81));
32028   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_82));
32029
32030   /* "csamtools.pyx":1071
32031  *         """
32032  *         def __get__(self):
32033  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32034  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )
32035  *             cdef int tid
32036  */
32037   __pyx_k_tuple_83 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32038   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_83));
32039   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32040   PyTuple_SET_ITEM(__pyx_k_tuple_83, 0, ((PyObject *)__pyx_kp_s_6));
32041   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32042   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_83));
32043
32044   /* "csamtools.pyx":1072
32045  *         def __get__(self):
32046  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
32047  *             if not self.isbam: raise AttributeError( "Samfile.unmapped only available in bam files" )             # <<<<<<<<<<<<<<
32048  *             cdef int tid
32049  *             cdef uint32_t total = 0
32050  */
32051   __pyx_k_tuple_85 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32052   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_85));
32053   __Pyx_INCREF(((PyObject *)__pyx_kp_s_84));
32054   PyTuple_SET_ITEM(__pyx_k_tuple_85, 0, ((PyObject *)__pyx_kp_s_84));
32055   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84));
32056   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_85));
32057
32058   /* "csamtools.pyx":1084
32059  *         '''full contents of the :term:`sam file` header as a string.'''
32060  *         def __get__(self):
32061  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32062  *             return PyString_FromStringAndSize(self.samfile.header.text, self.samfile.header.l_text)
32063  * 
32064  */
32065   __pyx_k_tuple_86 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32066   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_86));
32067   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32068   PyTuple_SET_ITEM(__pyx_k_tuple_86, 0, ((PyObject *)__pyx_kp_s_6));
32069   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32070   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_86));
32071
32072   /* "csamtools.pyx":1092
32073  *         '''
32074  *         def __get__(self):
32075  *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32076  * 
32077  *             result = {}
32078  */
32079   __pyx_k_tuple_87 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32080   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_87));
32081   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32082   PyTuple_SET_ITEM(__pyx_k_tuple_87, 0, ((PyObject *)__pyx_kp_s_6));
32083   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32084   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_87));
32085
32086   /* "csamtools.pyx":1099
32087  *                 # convert to python string (note: call self.text to create 0-terminated string)
32088  *                 t = self.text
32089  *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
32090  *                     if not line.strip(): continue
32091  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
32092  */
32093   __pyx_k_tuple_88 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32094   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_88));
32095   __Pyx_INCREF(((PyObject *)__pyx_kp_s_2));
32096   PyTuple_SET_ITEM(__pyx_k_tuple_88, 0, ((PyObject *)__pyx_kp_s_2));
32097   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2));
32098   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_88));
32099
32100   /* "csamtools.pyx":1101
32101  *                 for line in t.split("\n"):
32102  *                     if not line.strip(): continue
32103  *                     assert line.startswith("@"), "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
32104  *                     fields = line[1:].split("\t")
32105  *                     record = fields[0]
32106  */
32107   __pyx_k_tuple_90 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32108   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_90));
32109   __Pyx_INCREF(((PyObject *)__pyx_kp_s_89));
32110   PyTuple_SET_ITEM(__pyx_k_tuple_90, 0, ((PyObject *)__pyx_kp_s_89));
32111   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89));
32112   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_90));
32113
32114   /* "csamtools.pyx":1102
32115  *                     if not line.strip(): continue
32116  *                     assert line.startswith("@"), "header line without '@': '%s'" % line
32117  *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
32118  *                     record = fields[0]
32119  *                     assert record in VALID_HEADER_TYPES, "header line with invalid type '%s': '%s'" % (record, line)
32120  */
32121   __pyx_k_tuple_92 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32122   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_92));
32123   __Pyx_INCREF(((PyObject *)__pyx_kp_s_1));
32124   PyTuple_SET_ITEM(__pyx_k_tuple_92, 0, ((PyObject *)__pyx_kp_s_1));
32125   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1));
32126   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_92));
32127
32128   /* "csamtools.pyx":1115
32129  *                     x = {}
32130  *                     for field in fields[1:]:
32131  *                         key, value = field.split(":",1)             # <<<<<<<<<<<<<<
32132  *                         # uppercase keys must be valid
32133  *                         # lowercase are permitted for user fields
32134  */
32135   __pyx_k_tuple_95 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32136   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_95));
32137   __Pyx_INCREF(((PyObject *)__pyx_kp_s_94));
32138   PyTuple_SET_ITEM(__pyx_k_tuple_95, 0, ((PyObject *)__pyx_kp_s_94));
32139   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_94));
32140   __Pyx_INCREF(__pyx_int_1);
32141   PyTuple_SET_ITEM(__pyx_k_tuple_95, 1, __pyx_int_1);
32142   __Pyx_GIVEREF(__pyx_int_1);
32143   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95));
32144
32145   /* "csamtools.pyx":1217
32146  *     ###############################################################
32147  *     def __iter__(self):
32148  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32149  *         if not self.isbam and self.samfile.header.n_targets == 0:
32150  *                 raise NotImplementedError( "can not iterate over samfile without header")
32151  */
32152   __pyx_k_tuple_102 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_102)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32153   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_102));
32154   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32155   PyTuple_SET_ITEM(__pyx_k_tuple_102, 0, ((PyObject *)__pyx_kp_s_6));
32156   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32157   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_102));
32158
32159   /* "csamtools.pyx":1219
32160  *         if not self._isOpen(): raise ValueError( "I/O operation on closed file" )
32161  *         if not self.isbam and self.samfile.header.n_targets == 0:
32162  *                 raise NotImplementedError( "can not iterate over samfile without header")             # <<<<<<<<<<<<<<
32163  *         return self
32164  * 
32165  */
32166   __pyx_k_tuple_104 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32167   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_104));
32168   __Pyx_INCREF(((PyObject *)__pyx_kp_s_103));
32169   PyTuple_SET_ITEM(__pyx_k_tuple_104, 0, ((PyObject *)__pyx_kp_s_103));
32170   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_103));
32171   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_104));
32172
32173   /* "csamtools.pyx":1296
32174  * 
32175  *         if not samfile._isOpen():
32176  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32177  * 
32178  *         if not samfile._hasIndex():
32179  */
32180   __pyx_k_tuple_105 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32181   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_105));
32182   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32183   PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_kp_s_6));
32184   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32185   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105));
32186
32187   /* "csamtools.pyx":1299
32188  * 
32189  *         if not samfile._hasIndex():
32190  *             raise ValueError( "no index available for iteration" )             # <<<<<<<<<<<<<<
32191  * 
32192  *         # makes sure that samfile stays alive as long as the
32193  */
32194   __pyx_k_tuple_107 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32195   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_107));
32196   __Pyx_INCREF(((PyObject *)__pyx_kp_s_106));
32197   PyTuple_SET_ITEM(__pyx_k_tuple_107, 0, ((PyObject *)__pyx_kp_s_106));
32198   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106));
32199   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107));
32200
32201   /* "csamtools.pyx":1369
32202  * 
32203  *         if not samfile._isOpen():
32204  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32205  * 
32206  *         if samfile.isbam: mode = "rb"
32207  */
32208   __pyx_k_tuple_108 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32209   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_108));
32210   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32211   PyTuple_SET_ITEM(__pyx_k_tuple_108, 0, ((PyObject *)__pyx_kp_s_6));
32212   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32213   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_108));
32214
32215   /* "csamtools.pyx":1424
32216  *     def __cinit__(self, Samfile samfile):
32217  *         assert samfile._isOpen()
32218  *         if not samfile._hasIndex(): raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
32219  *         self.samfile = samfile
32220  *         self.tid = -1
32221  */
32222   __pyx_k_tuple_109 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_109)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32223   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_109));
32224   __Pyx_INCREF(((PyObject *)__pyx_kp_s_50));
32225   PyTuple_SET_ITEM(__pyx_k_tuple_109, 0, ((PyObject *)__pyx_kp_s_50));
32226   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50));
32227   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_109));
32228
32229   /* "csamtools.pyx":1477
32230  * 
32231  *         if not samfile._isOpen():
32232  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32233  * 
32234  *         if not samfile._isOpen():
32235  */
32236   __pyx_k_tuple_110 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_110)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32237   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_110));
32238   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32239   PyTuple_SET_ITEM(__pyx_k_tuple_110, 0, ((PyObject *)__pyx_kp_s_6));
32240   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32241   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_110));
32242
32243   /* "csamtools.pyx":1480
32244  * 
32245  *         if not samfile._isOpen():
32246  *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
32247  * 
32248  *         assert samfile.isbam, "can only use this iterator on bam files"
32249  */
32250   __pyx_k_tuple_111 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_111)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32251   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_111));
32252   __Pyx_INCREF(((PyObject *)__pyx_kp_s_6));
32253   PyTuple_SET_ITEM(__pyx_k_tuple_111, 0, ((PyObject *)__pyx_kp_s_6));
32254   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_6));
32255   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_111));
32256
32257   /* "csamtools.pyx":1796
32258  *             self.cnext()
32259  *             if self.n_plp < 0:
32260  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
32261  * 
32262  *             if self.plp == NULL:
32263  */
32264   __pyx_k_tuple_117 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32265   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_117));
32266   __Pyx_INCREF(((PyObject *)__pyx_kp_s_116));
32267   PyTuple_SET_ITEM(__pyx_k_tuple_117, 0, ((PyObject *)__pyx_kp_s_116));
32268   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_116));
32269   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_117));
32270
32271   /* "csamtools.pyx":1828
32272  * 
32273  *             if self.n_plp < 0:
32274  *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
32275  * 
32276  *             # return result, if within same reference
32277  */
32278   __pyx_k_tuple_118 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32279   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_118));
32280   __Pyx_INCREF(((PyObject *)__pyx_kp_s_116));
32281   PyTuple_SET_ITEM(__pyx_k_tuple_118, 0, ((PyObject *)__pyx_kp_s_116));
32282   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_116));
32283   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));
32284
32285   /* "csamtools.pyx":2363
32286  *                     size = struct.calcsize(fmt)
32287  *                     if offset + size > max_size:
32288  *                         raise NotImplementedError("tags field too large")             # <<<<<<<<<<<<<<
32289  * 
32290  *                     struct.pack_into( fmt,
32291  */
32292   __pyx_k_tuple_134 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32293   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_134));
32294   __Pyx_INCREF(((PyObject *)__pyx_kp_s_133));
32295   PyTuple_SET_ITEM(__pyx_k_tuple_134, 0, ((PyObject *)__pyx_kp_s_133));
32296   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_133));
32297   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
32298
32299   /* "csamtools.pyx":2710
32300  * 
32301  *     def __init__(self):
32302  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
32303  * 
32304  *     def __str__(self):
32305  */
32306   __pyx_k_tuple_158 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32307   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_158));
32308   __Pyx_INCREF(((PyObject *)__pyx_kp_s_157));
32309   PyTuple_SET_ITEM(__pyx_k_tuple_158, 0, ((PyObject *)__pyx_kp_s_157));
32310   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_157));
32311   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_158));
32312
32313   /* "csamtools.pyx":2754
32314  * 
32315  *     def __init__(self):
32316  *         raise TypeError("This class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
32317  * 
32318  *     def __str__(self):
32319  */
32320   __pyx_k_tuple_159 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_159)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2754; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32321   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_159));
32322   __Pyx_INCREF(((PyObject *)__pyx_kp_s_157));
32323   PyTuple_SET_ITEM(__pyx_k_tuple_159, 0, ((PyObject *)__pyx_kp_s_157));
32324   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_157));
32325   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_159));
32326
32327   /* "csamtools.pyx":2867
32328  *         # recover. Thus redirect output to file with -o option.
32329  *         if method == "view":
32330  *             if "-o" in args: raise ValueError("option -o is forbidden in samtools view")             # <<<<<<<<<<<<<<
32331  *             args = ( "-o", stdout_f ) + args
32332  * 
32333  */
32334   __pyx_k_tuple_165 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_165)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32335   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_165));
32336   __Pyx_INCREF(((PyObject *)__pyx_kp_s_164));
32337   PyTuple_SET_ITEM(__pyx_k_tuple_165, 0, ((PyObject *)__pyx_kp_s_164));
32338   __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_164));
32339   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_165));
32340
32341   /* "csamtools.pyx":224
32342  * 
32343  * # order of records within sam headers
32344  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
32345  * 
32346  * # type conversions within sam header records
32347  */
32348   __pyx_k_tuple_233 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_233)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32349   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_233));
32350   __Pyx_INCREF(((PyObject *)__pyx_n_s__HD));
32351   PyTuple_SET_ITEM(__pyx_k_tuple_233, 0, ((PyObject *)__pyx_n_s__HD));
32352   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__HD));
32353   __Pyx_INCREF(((PyObject *)__pyx_n_s__SQ));
32354   PyTuple_SET_ITEM(__pyx_k_tuple_233, 1, ((PyObject *)__pyx_n_s__SQ));
32355   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SQ));
32356   __Pyx_INCREF(((PyObject *)__pyx_n_s__RG));
32357   PyTuple_SET_ITEM(__pyx_k_tuple_233, 2, ((PyObject *)__pyx_n_s__RG));
32358   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__RG));
32359   __Pyx_INCREF(((PyObject *)__pyx_n_s__PG));
32360   PyTuple_SET_ITEM(__pyx_k_tuple_233, 3, ((PyObject *)__pyx_n_s__PG));
32361   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PG));
32362   __Pyx_INCREF(((PyObject *)__pyx_n_s__CO));
32363   PyTuple_SET_ITEM(__pyx_k_tuple_233, 4, ((PyObject *)__pyx_n_s__CO));
32364   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CO));
32365   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_233));
32366
32367   /* "csamtools.pyx":233
32368  * 
32369  * # output order of fields within records
32370  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
32371  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
32372  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
32373  */
32374   __pyx_k_tuple_234 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_234)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32375   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_234));
32376   __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
32377   PyTuple_SET_ITEM(__pyx_k_tuple_234, 0, ((PyObject *)__pyx_n_s__VN));
32378   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
32379   __Pyx_INCREF(((PyObject *)__pyx_n_s__SO));
32380   PyTuple_SET_ITEM(__pyx_k_tuple_234, 1, ((PyObject *)__pyx_n_s__SO));
32381   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SO));
32382   __Pyx_INCREF(((PyObject *)__pyx_n_s__GO));
32383   PyTuple_SET_ITEM(__pyx_k_tuple_234, 2, ((PyObject *)__pyx_n_s__GO));
32384   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__GO));
32385   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_234));
32386
32387   /* "csamtools.pyx":234
32388  * # output order of fields within records
32389  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
32390  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
32391  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
32392  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
32393  */
32394   __pyx_k_tuple_235 = PyTuple_New(6); if (unlikely(!__pyx_k_tuple_235)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32395   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_235));
32396   __Pyx_INCREF(((PyObject *)__pyx_n_s__SN));
32397   PyTuple_SET_ITEM(__pyx_k_tuple_235, 0, ((PyObject *)__pyx_n_s__SN));
32398   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SN));
32399   __Pyx_INCREF(((PyObject *)__pyx_n_s__LN));
32400   PyTuple_SET_ITEM(__pyx_k_tuple_235, 1, ((PyObject *)__pyx_n_s__LN));
32401   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LN));
32402   __Pyx_INCREF(((PyObject *)__pyx_n_s__AS));
32403   PyTuple_SET_ITEM(__pyx_k_tuple_235, 2, ((PyObject *)__pyx_n_s__AS));
32404   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AS));
32405   __Pyx_INCREF(((PyObject *)__pyx_n_s__M5));
32406   PyTuple_SET_ITEM(__pyx_k_tuple_235, 3, ((PyObject *)__pyx_n_s__M5));
32407   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__M5));
32408   __Pyx_INCREF(((PyObject *)__pyx_n_s__UR));
32409   PyTuple_SET_ITEM(__pyx_k_tuple_235, 4, ((PyObject *)__pyx_n_s__UR));
32410   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__UR));
32411   __Pyx_INCREF(((PyObject *)__pyx_n_s__SP));
32412   PyTuple_SET_ITEM(__pyx_k_tuple_235, 5, ((PyObject *)__pyx_n_s__SP));
32413   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SP));
32414   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_235));
32415
32416   /* "csamtools.pyx":235
32417  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
32418  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
32419  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),             # <<<<<<<<<<<<<<
32420  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
32421  * 
32422  */
32423   __pyx_k_tuple_236 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_236)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32424   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_236));
32425   __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
32426   PyTuple_SET_ITEM(__pyx_k_tuple_236, 0, ((PyObject *)__pyx_n_s__ID));
32427   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
32428   __Pyx_INCREF(((PyObject *)__pyx_n_s__SM));
32429   PyTuple_SET_ITEM(__pyx_k_tuple_236, 1, ((PyObject *)__pyx_n_s__SM));
32430   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__SM));
32431   __Pyx_INCREF(((PyObject *)__pyx_n_s__LB));
32432   PyTuple_SET_ITEM(__pyx_k_tuple_236, 2, ((PyObject *)__pyx_n_s__LB));
32433   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__LB));
32434   __Pyx_INCREF(((PyObject *)__pyx_n_s__DS));
32435   PyTuple_SET_ITEM(__pyx_k_tuple_236, 3, ((PyObject *)__pyx_n_s__DS));
32436   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DS));
32437   __Pyx_INCREF(((PyObject *)__pyx_n_s__PU));
32438   PyTuple_SET_ITEM(__pyx_k_tuple_236, 4, ((PyObject *)__pyx_n_s__PU));
32439   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PU));
32440   __Pyx_INCREF(((PyObject *)__pyx_n_s__PI));
32441   PyTuple_SET_ITEM(__pyx_k_tuple_236, 5, ((PyObject *)__pyx_n_s__PI));
32442   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PI));
32443   __Pyx_INCREF(((PyObject *)__pyx_n_s__CN));
32444   PyTuple_SET_ITEM(__pyx_k_tuple_236, 6, ((PyObject *)__pyx_n_s__CN));
32445   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CN));
32446   __Pyx_INCREF(((PyObject *)__pyx_n_s__DT));
32447   PyTuple_SET_ITEM(__pyx_k_tuple_236, 7, ((PyObject *)__pyx_n_s__DT));
32448   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__DT));
32449   __Pyx_INCREF(((PyObject *)__pyx_n_s__PL));
32450   PyTuple_SET_ITEM(__pyx_k_tuple_236, 8, ((PyObject *)__pyx_n_s__PL));
32451   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PL));
32452   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_236));
32453
32454   /* "csamtools.pyx":236
32455  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
32456  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
32457  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }             # <<<<<<<<<<<<<<
32458  * 
32459  * 
32460  */
32461   __pyx_k_tuple_237 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_237)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32462   __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_237));
32463   __Pyx_INCREF(((PyObject *)__pyx_n_s__PN));
32464   PyTuple_SET_ITEM(__pyx_k_tuple_237, 0, ((PyObject *)__pyx_n_s__PN));
32465   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PN));
32466   __Pyx_INCREF(((PyObject *)__pyx_n_s__ID));
32467   PyTuple_SET_ITEM(__pyx_k_tuple_237, 1, ((PyObject *)__pyx_n_s__ID));
32468   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ID));
32469   __Pyx_INCREF(((PyObject *)__pyx_n_s__VN));
32470   PyTuple_SET_ITEM(__pyx_k_tuple_237, 2, ((PyObject *)__pyx_n_s__VN));
32471   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__VN));
32472   __Pyx_INCREF(((PyObject *)__pyx_n_s__CL));
32473   PyTuple_SET_ITEM(__pyx_k_tuple_237, 3, ((PyObject *)__pyx_n_s__CL));
32474   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CL));
32475   __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_237));
32476   __Pyx_RefNannyFinishContext();
32477   return 0;
32478   __pyx_L1_error:;
32479   __Pyx_RefNannyFinishContext();
32480   return -1;
32481 }
32482
32483 static int __Pyx_InitGlobals(void) {
32484   if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
32485   __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;};
32486   __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;};
32487   __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;};
32488   __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;};
32489   __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;};
32490   __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;};
32491   __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;};
32492   __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;};
32493   __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;};
32494   __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;};
32495   __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;};
32496   __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;};
32497   __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;};
32498   __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;};
32499   __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;};
32500   __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;};
32501   __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;};
32502   __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;};
32503   __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;};
32504   __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;};
32505   __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;};
32506   return 0;
32507   __pyx_L1_error:;
32508   return -1;
32509 }
32510
32511 #if PY_MAJOR_VERSION < 3
32512 PyMODINIT_FUNC initcsamtools(void); /*proto*/
32513 PyMODINIT_FUNC initcsamtools(void)
32514 #else
32515 PyMODINIT_FUNC PyInit_csamtools(void); /*proto*/
32516 PyMODINIT_FUNC PyInit_csamtools(void)
32517 #endif
32518 {
32519   PyObject *__pyx_t_1 = NULL;
32520   PyObject *__pyx_t_2 = NULL;
32521   PyObject *__pyx_t_3 = NULL;
32522   int __pyx_t_4;
32523   #if CYTHON_REFNANNY
32524   void* __pyx_refnanny = NULL;
32525   __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
32526   if (!__Pyx_RefNanny) {
32527       PyErr_Clear();
32528       __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
32529       if (!__Pyx_RefNanny)
32530           Py_FatalError("failed to import 'refnanny' module");
32531   }
32532   __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_csamtools(void)", __LINE__, __FILE__);
32533   #endif
32534   __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;}
32535   __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;}
32536   #ifdef __pyx_binding_PyCFunctionType_USED
32537   if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32538   #endif
32539   /*--- Library function declarations ---*/
32540   /*--- Threads initialization code ---*/
32541   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
32542   #ifdef WITH_THREAD /* Python build with threading support? */
32543   PyEval_InitThreads();
32544   #endif
32545   #endif
32546   /*--- Module creation code ---*/
32547   #if PY_MAJOR_VERSION < 3
32548   __pyx_m = Py_InitModule4(__Pyx_NAMESTR("csamtools"), __pyx_methods, 0, 0, PYTHON_API_VERSION);
32549   #else
32550   __pyx_m = PyModule_Create(&__pyx_moduledef);
32551   #endif
32552   if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
32553   #if PY_MAJOR_VERSION < 3
32554   Py_INCREF(__pyx_m);
32555   #endif
32556   __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
32557   if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
32558   if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
32559   /*--- Initialize various global constants etc. ---*/
32560   if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32561   if (__pyx_module_is_main_csamtools) {
32562     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;};
32563   }
32564   /*--- Builtin init code ---*/
32565   if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32566   /*--- Constants init code ---*/
32567   if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32568   /*--- Global init code ---*/
32569   /*--- Function export code ---*/
32570   /*--- Type init code ---*/
32571   __pyx_ptype_9csamtools_file = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "file", sizeof(PyFileObject), 0); if (unlikely(!__pyx_ptype_9csamtools_file)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32572   if (PyType_Ready(&__pyx_type_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32573   {
32574     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_AlignedRead, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32575     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32576       __pyx_wrapperbase_9csamtools_11AlignedRead_2__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32577       __pyx_wrapperbase_9csamtools_11AlignedRead_2__str__.doc = __pyx_doc_9csamtools_11AlignedRead_2__str__;
32578       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_11AlignedRead_2__str__;
32579     }
32580   }
32581   if (__Pyx_SetAttrString(__pyx_m, "AlignedRead", (PyObject *)&__pyx_type_9csamtools_AlignedRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32582   __pyx_ptype_9csamtools_AlignedRead = &__pyx_type_9csamtools_AlignedRead;
32583   __pyx_vtabptr_9csamtools_Samfile = &__pyx_vtable_9csamtools_Samfile;
32584   __pyx_vtable_9csamtools_Samfile._buildHeader = (bam_header_t *(*)(struct __pyx_obj_9csamtools_Samfile *, PyObject *))__pyx_f_9csamtools_7Samfile__buildHeader;
32585   __pyx_vtable_9csamtools_Samfile.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_Samfile *))__pyx_f_9csamtools_7Samfile_getCurrent;
32586   __pyx_vtable_9csamtools_Samfile.cnext = (int (*)(struct __pyx_obj_9csamtools_Samfile *))__pyx_f_9csamtools_7Samfile_cnext;
32587   __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;
32588   __pyx_vtable_9csamtools_Samfile._getrname = (char *(*)(struct __pyx_obj_9csamtools_Samfile *, int))__pyx_f_9csamtools_7Samfile__getrname;
32589   if (PyType_Ready(&__pyx_type_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32590   {
32591     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_Samfile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32592     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32593       __pyx_wrapperbase_9csamtools_7Samfile_21__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32594       __pyx_wrapperbase_9csamtools_7Samfile_21__next__.doc = __pyx_doc_9csamtools_7Samfile_21__next__;
32595       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_7Samfile_21__next__;
32596     }
32597   }
32598   if (__Pyx_SetVtable(__pyx_type_9csamtools_Samfile.tp_dict, __pyx_vtabptr_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32599   if (__Pyx_SetAttrString(__pyx_m, "Samfile", (PyObject *)&__pyx_type_9csamtools_Samfile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32600   __pyx_ptype_9csamtools_Samfile = &__pyx_type_9csamtools_Samfile;
32601   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32602   if (__Pyx_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_9csamtools_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32603   __pyx_ptype_9csamtools_IteratorRow = &__pyx_type_9csamtools_IteratorRow;
32604   __pyx_vtabptr_9csamtools_IteratorRowAll = &__pyx_vtable_9csamtools_IteratorRowAll;
32605   __pyx_vtable_9csamtools_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowAll *))__pyx_f_9csamtools_14IteratorRowAll_getCurrent;
32606   __pyx_vtable_9csamtools_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowAll *))__pyx_f_9csamtools_14IteratorRowAll_cnext;
32607   __pyx_type_9csamtools_IteratorRowAll.tp_base = __pyx_ptype_9csamtools_IteratorRow;
32608   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32609   {
32610     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32611     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32612       __pyx_wrapperbase_9csamtools_14IteratorRowAll_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32613       __pyx_wrapperbase_9csamtools_14IteratorRowAll_2__next__.doc = __pyx_doc_9csamtools_14IteratorRowAll_2__next__;
32614       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_14IteratorRowAll_2__next__;
32615     }
32616   }
32617   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowAll.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32618   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_9csamtools_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32619   __pyx_ptype_9csamtools_IteratorRowAll = &__pyx_type_9csamtools_IteratorRowAll;
32620   if (PyType_Ready(&__pyx_type_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32621   if (__Pyx_SetAttrString(__pyx_m, "PileupProxy", (PyObject *)&__pyx_type_9csamtools_PileupProxy) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32622   __pyx_ptype_9csamtools_PileupProxy = &__pyx_type_9csamtools_PileupProxy;
32623   if (PyType_Ready(&__pyx_type_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32624   if (__Pyx_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_9csamtools_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32625   __pyx_ptype_9csamtools_PileupRead = &__pyx_type_9csamtools_PileupRead;
32626   __pyx_vtabptr_9csamtools_Fastafile = &__pyx_vtable_9csamtools_Fastafile;
32627   __pyx_vtable_9csamtools_Fastafile._fetch = (char *(*)(struct __pyx_obj_9csamtools_Fastafile *, char *, int, int, int *))__pyx_f_9csamtools_9Fastafile__fetch;
32628   if (PyType_Ready(&__pyx_type_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32629   if (__Pyx_SetVtable(__pyx_type_9csamtools_Fastafile.tp_dict, __pyx_vtabptr_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32630   if (__Pyx_SetAttrString(__pyx_m, "Fastafile", (PyObject *)&__pyx_type_9csamtools_Fastafile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32631   __pyx_ptype_9csamtools_Fastafile = &__pyx_type_9csamtools_Fastafile;
32632   __pyx_vtabptr_9csamtools_IteratorRowRegion = &__pyx_vtable_9csamtools_IteratorRowRegion;
32633   __pyx_vtable_9csamtools_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowRegion *))__pyx_f_9csamtools_17IteratorRowRegion_getCurrent;
32634   __pyx_vtable_9csamtools_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowRegion *))__pyx_f_9csamtools_17IteratorRowRegion_cnext;
32635   __pyx_type_9csamtools_IteratorRowRegion.tp_base = __pyx_ptype_9csamtools_IteratorRow;
32636   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32637   {
32638     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32639     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32640       __pyx_wrapperbase_9csamtools_17IteratorRowRegion_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32641       __pyx_wrapperbase_9csamtools_17IteratorRowRegion_2__next__.doc = __pyx_doc_9csamtools_17IteratorRowRegion_2__next__;
32642       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_17IteratorRowRegion_2__next__;
32643     }
32644   }
32645   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowRegion.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32646   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_9csamtools_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32647   __pyx_ptype_9csamtools_IteratorRowRegion = &__pyx_type_9csamtools_IteratorRowRegion;
32648   __pyx_type_9csamtools_IteratorRowAllRefs.tp_base = __pyx_ptype_9csamtools_IteratorRow;
32649   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32650   {
32651     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32652     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32653       __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_3__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32654       __pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_3__next__.doc = __pyx_doc_9csamtools_18IteratorRowAllRefs_3__next__;
32655       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_18IteratorRowAllRefs_3__next__;
32656     }
32657   }
32658   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_9csamtools_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32659   __pyx_ptype_9csamtools_IteratorRowAllRefs = &__pyx_type_9csamtools_IteratorRowAllRefs;
32660   __pyx_vtabptr_9csamtools_IteratorRowSelection = &__pyx_vtable_9csamtools_IteratorRowSelection;
32661   __pyx_vtable_9csamtools_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_9csamtools_IteratorRowSelection *))__pyx_f_9csamtools_20IteratorRowSelection_getCurrent;
32662   __pyx_vtable_9csamtools_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorRowSelection *))__pyx_f_9csamtools_20IteratorRowSelection_cnext;
32663   __pyx_type_9csamtools_IteratorRowSelection.tp_base = __pyx_ptype_9csamtools_IteratorRow;
32664   if (PyType_Ready(&__pyx_type_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32665   {
32666     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32667     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32668       __pyx_wrapperbase_9csamtools_20IteratorRowSelection_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32669       __pyx_wrapperbase_9csamtools_20IteratorRowSelection_2__next__.doc = __pyx_doc_9csamtools_20IteratorRowSelection_2__next__;
32670       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_20IteratorRowSelection_2__next__;
32671     }
32672   }
32673   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorRowSelection.tp_dict, __pyx_vtabptr_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32674   if (__Pyx_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_9csamtools_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1461; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32675   __pyx_ptype_9csamtools_IteratorRowSelection = &__pyx_type_9csamtools_IteratorRowSelection;
32676   __pyx_vtabptr_9csamtools_IteratorColumn = &__pyx_vtable_9csamtools_IteratorColumn;
32677   __pyx_vtable_9csamtools_IteratorColumn.cnext = (int (*)(struct __pyx_obj_9csamtools_IteratorColumn *))__pyx_f_9csamtools_14IteratorColumn_cnext;
32678   __pyx_vtable_9csamtools_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_9csamtools_IteratorColumn *))__pyx_f_9csamtools_14IteratorColumn_getSequence;
32679   __pyx_vtable_9csamtools_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *))__pyx_f_9csamtools_14IteratorColumn_setMask;
32680   __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;
32681   __pyx_vtable_9csamtools_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_9csamtools_14IteratorColumn_reset;
32682   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32683   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumn.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32684   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_9csamtools_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32685   __pyx_ptype_9csamtools_IteratorColumn = &__pyx_type_9csamtools_IteratorColumn;
32686   __pyx_vtabptr_9csamtools_IteratorColumnRegion = &__pyx_vtable_9csamtools_IteratorColumnRegion;
32687   __pyx_vtable_9csamtools_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_9csamtools_IteratorColumn;
32688   __pyx_type_9csamtools_IteratorColumnRegion.tp_base = __pyx_ptype_9csamtools_IteratorColumn;
32689   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32690   {
32691     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32692     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32693       __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_1__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32694       __pyx_wrapperbase_9csamtools_20IteratorColumnRegion_1__next__.doc = __pyx_doc_9csamtools_20IteratorColumnRegion_1__next__;
32695       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_20IteratorColumnRegion_1__next__;
32696     }
32697   }
32698   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumnRegion.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32699   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_9csamtools_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32700   __pyx_ptype_9csamtools_IteratorColumnRegion = &__pyx_type_9csamtools_IteratorColumnRegion;
32701   __pyx_vtabptr_9csamtools_IteratorColumnAllRefs = &__pyx_vtable_9csamtools_IteratorColumnAllRefs;
32702   __pyx_vtable_9csamtools_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_9csamtools_IteratorColumn;
32703   __pyx_type_9csamtools_IteratorColumnAllRefs.tp_base = __pyx_ptype_9csamtools_IteratorColumn;
32704   if (PyType_Ready(&__pyx_type_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32705   {
32706     PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&__pyx_type_9csamtools_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32707     if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
32708       __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_1__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
32709       __pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_1__next__.doc = __pyx_doc_9csamtools_21IteratorColumnAllRefs_1__next__;
32710       ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_9csamtools_21IteratorColumnAllRefs_1__next__;
32711     }
32712   }
32713   if (__Pyx_SetVtable(__pyx_type_9csamtools_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32714   if (__Pyx_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_9csamtools_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1806; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32715   __pyx_ptype_9csamtools_IteratorColumnAllRefs = &__pyx_type_9csamtools_IteratorColumnAllRefs;
32716   if (PyType_Ready(&__pyx_type_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32717   if (__Pyx_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_9csamtools_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32718   __pyx_ptype_9csamtools_SNPCall = &__pyx_type_9csamtools_SNPCall;
32719   if (PyType_Ready(&__pyx_type_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32720   if (__Pyx_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_9csamtools_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32721   __pyx_ptype_9csamtools_IndexedReads = &__pyx_type_9csamtools_IndexedReads;
32722   /*--- Type import code ---*/
32723   __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[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32724   __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[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32725   /*--- Function import code ---*/
32726   /*--- Execution code ---*/
32727
32728   /* "csamtools.pyx":4
32729  * # cython: profile=True
32730  * # adds doc-strings for sphinx
32731  * import tempfile             # <<<<<<<<<<<<<<
32732  * import os
32733  * import sys
32734  */
32735   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__tempfile), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32736   __Pyx_GOTREF(__pyx_t_1);
32737   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;}
32738   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32739
32740   /* "csamtools.pyx":5
32741  * # adds doc-strings for sphinx
32742  * import tempfile
32743  * import os             # <<<<<<<<<<<<<<
32744  * import sys
32745  * import types
32746  */
32747   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__os), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32748   __Pyx_GOTREF(__pyx_t_1);
32749   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;}
32750   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32751
32752   /* "csamtools.pyx":6
32753  * import tempfile
32754  * import os
32755  * import sys             # <<<<<<<<<<<<<<
32756  * import types
32757  * import itertools
32758  */
32759   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32760   __Pyx_GOTREF(__pyx_t_1);
32761   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;}
32762   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32763
32764   /* "csamtools.pyx":7
32765  * import os
32766  * import sys
32767  * import types             # <<<<<<<<<<<<<<
32768  * import itertools
32769  * import struct
32770  */
32771   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__types), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32772   __Pyx_GOTREF(__pyx_t_1);
32773   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;}
32774   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32775
32776   /* "csamtools.pyx":8
32777  * import sys
32778  * import types
32779  * import itertools             # <<<<<<<<<<<<<<
32780  * import struct
32781  * import ctypes
32782  */
32783   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__itertools), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32784   __Pyx_GOTREF(__pyx_t_1);
32785   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;}
32786   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32787
32788   /* "csamtools.pyx":9
32789  * import types
32790  * import itertools
32791  * import struct             # <<<<<<<<<<<<<<
32792  * import ctypes
32793  * import collections
32794  */
32795   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__struct), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32796   __Pyx_GOTREF(__pyx_t_1);
32797   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;}
32798   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32799
32800   /* "csamtools.pyx":10
32801  * import itertools
32802  * import struct
32803  * import ctypes             # <<<<<<<<<<<<<<
32804  * import collections
32805  * import re
32806  */
32807   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__ctypes), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32808   __Pyx_GOTREF(__pyx_t_1);
32809   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;}
32810   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32811
32812   /* "csamtools.pyx":11
32813  * import struct
32814  * import ctypes
32815  * import collections             # <<<<<<<<<<<<<<
32816  * import re
32817  * import platform
32818  */
32819   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__collections), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32820   __Pyx_GOTREF(__pyx_t_1);
32821   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;}
32822   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32823
32824   /* "csamtools.pyx":12
32825  * import ctypes
32826  * import collections
32827  * import re             # <<<<<<<<<<<<<<
32828  * import platform
32829  * from cpython cimport PyString_FromStringAndSize, PyString_AS_STRING
32830  */
32831   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__re), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32832   __Pyx_GOTREF(__pyx_t_1);
32833   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;}
32834   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32835
32836   /* "csamtools.pyx":13
32837  * import collections
32838  * import re
32839  * import platform             # <<<<<<<<<<<<<<
32840  * from cpython cimport PyString_FromStringAndSize, PyString_AS_STRING
32841  * from cpython cimport PyErr_SetString
32842  */
32843   __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__platform), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32844   __Pyx_GOTREF(__pyx_t_1);
32845   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;}
32846   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32847
32848   /* "csamtools.pyx":63
32849  * #####################################################################
32850  * # hard-coded constants
32851  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
32852  * cdef int max_pos = 2 << 29
32853  * 
32854  */
32855   __pyx_v_9csamtools_bam_nt16_rev_table = __pyx_k_229;
32856
32857   /* "csamtools.pyx":64
32858  * # hard-coded constants
32859  * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"
32860  * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
32861  * 
32862  * # redirect stderr to 0
32863  */
32864   __pyx_v_9csamtools_max_pos = 1073741824;
32865
32866   /* "csamtools.pyx":67
32867  * 
32868  * # redirect stderr to 0
32869  * _logfile = open(os.path.devnull, "w")             # <<<<<<<<<<<<<<
32870  * pysam_set_stderr( PyFile_AsFile( _logfile ) )
32871  * 
32872  */
32873   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__os); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32874   __Pyx_GOTREF(__pyx_t_1);
32875   __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__path); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32876   __Pyx_GOTREF(__pyx_t_2);
32877   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32878   __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__devnull); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32879   __Pyx_GOTREF(__pyx_t_1);
32880   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32881   __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32882   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
32883   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
32884   __Pyx_GIVEREF(__pyx_t_1);
32885   __Pyx_INCREF(((PyObject *)__pyx_n_s__w));
32886   PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w));
32887   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w));
32888   __pyx_t_1 = 0;
32889   __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32890   __Pyx_GOTREF(__pyx_t_1);
32891   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
32892   if (PyObject_SetAttr(__pyx_m, __pyx_n_s___logfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32893   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32894
32895   /* "csamtools.pyx":68
32896  * # redirect stderr to 0
32897  * _logfile = open(os.path.devnull, "w")
32898  * pysam_set_stderr( PyFile_AsFile( _logfile ) )             # <<<<<<<<<<<<<<
32899  * 
32900  * #####################################################################
32901  */
32902   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___logfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32903   __Pyx_GOTREF(__pyx_t_1);
32904   pysam_set_stderr(PyFile_AsFile(__pyx_t_1));
32905   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
32906
32907   /* "csamtools.pyx":117
32908  *     (<object>f)(a)
32909  * 
32910  * class PileupColumn(object):             # <<<<<<<<<<<<<<
32911  *     '''A pileup column. A pileup column contains
32912  *     all the reads that map to a certain target base.
32913  */
32914   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32915   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
32916
32917   /* "csamtools.pyx":130
32918  *         list of reads (:class:`pysam.PileupRead`) aligned to this column
32919  *     '''
32920  *     def __str__(self):             # <<<<<<<<<<<<<<
32921  *         return "\t".join( map(str, (self.tid, self.pos, self.n))) +\
32922  *             "\n" + "\n".join( map(str, self.pileups) )
32923  */
32924   __pyx_t_2 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_12PileupColumn___str__, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32925   __Pyx_GOTREF(__pyx_t_2);
32926   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____str__, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32927   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
32928
32929   /* "csamtools.pyx":117
32930  *     (<object>f)(a)
32931  * 
32932  * class PileupColumn(object):             # <<<<<<<<<<<<<<
32933  *     '''A pileup column. A pileup column contains
32934  *     all the reads that map to a certain target base.
32935  */
32936   __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32937   __Pyx_GOTREF(((PyObject *)__pyx_t_2));
32938   __Pyx_INCREF(__pyx_builtin_object);
32939   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object);
32940   __Pyx_GIVEREF(__pyx_builtin_object);
32941   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_230)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32942   __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__PileupColumn, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32943   __Pyx_GOTREF(__pyx_t_3);
32944   __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
32945   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PileupColumn, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32946   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32947   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
32948
32949   /* "csamtools.pyx":174
32950  *     return 0
32951  * 
32952  * class StderrStore():             # <<<<<<<<<<<<<<
32953  *     '''
32954  *     stderr is captured.
32955  */
32956   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32957   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
32958
32959   /* "csamtools.pyx":178
32960  *     stderr is captured.
32961  *     '''
32962  *     def __init__(self):             # <<<<<<<<<<<<<<
32963  *         return
32964  *         self.stderr_h, self.stderr_f = tempfile.mkstemp()
32965  */
32966   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_11StderrStore___init__, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32967   __Pyx_GOTREF(__pyx_t_3);
32968   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32969   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32970
32971   /* "csamtools.pyx":184
32972  *         self.stderr_save.setfd( self.stderr_h )
32973  * 
32974  *     def readAndRelease( self ):             # <<<<<<<<<<<<<<
32975  *         return []
32976  *         self.stderr_save.restore()
32977  */
32978   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_11StderrStore_1readAndRelease, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32979   __Pyx_GOTREF(__pyx_t_3);
32980   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32981   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32982
32983   /* "csamtools.pyx":193
32984  *         return lines
32985  * 
32986  *     def release(self):             # <<<<<<<<<<<<<<
32987  *         return
32988  *         self.stderr_save.restore()
32989  */
32990   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_11StderrStore_2release, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32991   __Pyx_GOTREF(__pyx_t_3);
32992   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
32993   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
32994
32995   /* "csamtools.pyx":199
32996  *             os.remove( self.stderr_f )
32997  * 
32998  *     def __del__(self):             # <<<<<<<<<<<<<<
32999  *         self.release()
33000  * 
33001  */
33002   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_11StderrStore_3__del__, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33003   __Pyx_GOTREF(__pyx_t_3);
33004   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____del__, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33005   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33006
33007   /* "csamtools.pyx":174
33008  *     return 0
33009  * 
33010  * class StderrStore():             # <<<<<<<<<<<<<<
33011  *     '''
33012  *     stderr is captured.
33013  */
33014   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_231)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33015   __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStore, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33016   __Pyx_GOTREF(__pyx_t_3);
33017   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33018   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33019   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33020
33021   /* "csamtools.pyx":202
33022  *         self.release()
33023  * 
33024  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
33025  *     '''does nothing. stderr can't be redirected on windows'''
33026  *     def __init__(self): pass
33027  */
33028   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33029   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
33030
33031   /* "csamtools.pyx":204
33032  * class StderrStoreWindows():
33033  *     '''does nothing. stderr can't be redirected on windows'''
33034  *     def __init__(self): pass             # <<<<<<<<<<<<<<
33035  *     def readAndRelease(self): return []
33036  *     def release(self): pass
33037  */
33038   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows___init__, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33039   __Pyx_GOTREF(__pyx_t_3);
33040   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33041   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33042
33043   /* "csamtools.pyx":205
33044  *     '''does nothing. stderr can't be redirected on windows'''
33045  *     def __init__(self): pass
33046  *     def readAndRelease(self): return []             # <<<<<<<<<<<<<<
33047  *     def release(self): pass
33048  * 
33049  */
33050   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows_1readAndRelease, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33051   __Pyx_GOTREF(__pyx_t_3);
33052   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__readAndRelease, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33053   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33054
33055   /* "csamtools.pyx":206
33056  *     def __init__(self): pass
33057  *     def readAndRelease(self): return []
33058  *     def release(self): pass             # <<<<<<<<<<<<<<
33059  * 
33060  * if platform.system()=='Windows':
33061  */
33062   __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_18StderrStoreWindows_2release, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33063   __Pyx_GOTREF(__pyx_t_3);
33064   if (PyObject_SetItem(__pyx_t_1, __pyx_n_s__release, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33065   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33066
33067   /* "csamtools.pyx":202
33068  *         self.release()
33069  * 
33070  * class StderrStoreWindows():             # <<<<<<<<<<<<<<
33071  *     '''does nothing. stderr can't be redirected on windows'''
33072  *     def __init__(self): pass
33073  */
33074   if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_232)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33075   __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1), __pyx_n_s__StderrStoreWindows, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33076   __Pyx_GOTREF(__pyx_t_3);
33077   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStoreWindows, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33078   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33079   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33080
33081   /* "csamtools.pyx":208
33082  *     def release(self): pass
33083  * 
33084  * if platform.system()=='Windows':             # <<<<<<<<<<<<<<
33085  *     del StderrStore
33086  *     StderrStore = StderrStoreWindows
33087  */
33088   __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__platform); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33089   __Pyx_GOTREF(__pyx_t_1);
33090   __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__system); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33091   __Pyx_GOTREF(__pyx_t_3);
33092   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33093   __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 = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33094   __Pyx_GOTREF(__pyx_t_1);
33095   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33096   __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, ((PyObject *)__pyx_n_s__Windows), Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33097   __Pyx_GOTREF(__pyx_t_3);
33098   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33099   __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33100   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33101   if (__pyx_t_4) {
33102
33103     /* "csamtools.pyx":209
33104  * 
33105  * if platform.system()=='Windows':
33106  *     del StderrStore             # <<<<<<<<<<<<<<
33107  *     StderrStore = StderrStoreWindows
33108  * 
33109  */
33110     if (__Pyx_DelAttrString(__pyx_m, "StderrStore") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33111
33112     /* "csamtools.pyx":210
33113  * if platform.system()=='Windows':
33114  *     del StderrStore
33115  *     StderrStore = StderrStoreWindows             # <<<<<<<<<<<<<<
33116  * 
33117  * 
33118  */
33119     __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__StderrStoreWindows); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33120     __Pyx_GOTREF(__pyx_t_3);
33121     if (PyObject_SetAttr(__pyx_m, __pyx_n_s__StderrStore, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33122     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33123     goto __pyx_L2;
33124   }
33125   __pyx_L2:;
33126
33127   /* "csamtools.pyx":217
33128  * ######################################################################
33129  * # valid types for sam headers
33130  * VALID_HEADER_TYPES = { "HD" : dict,             # <<<<<<<<<<<<<<
33131  *                        "SQ" : list,
33132  *                        "RG" : list,
33133  */
33134   __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33135   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33136   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__HD), ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33137
33138   /* "csamtools.pyx":218
33139  * # valid types for sam headers
33140  * VALID_HEADER_TYPES = { "HD" : dict,
33141  *                        "SQ" : list,             # <<<<<<<<<<<<<<
33142  *                        "RG" : list,
33143  *                        "PG" : list,
33144  */
33145   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33146
33147   /* "csamtools.pyx":219
33148  * VALID_HEADER_TYPES = { "HD" : dict,
33149  *                        "SQ" : list,
33150  *                        "RG" : list,             # <<<<<<<<<<<<<<
33151  *                        "PG" : list,
33152  *                        "CO" : list }
33153  */
33154   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__RG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33155
33156   /* "csamtools.pyx":220
33157  *                        "SQ" : list,
33158  *                        "RG" : list,
33159  *                        "PG" : list,             # <<<<<<<<<<<<<<
33160  *                        "CO" : list }
33161  * 
33162  */
33163   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PG), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33164
33165   /* "csamtools.pyx":221
33166  *                        "RG" : list,
33167  *                        "PG" : list,
33168  *                        "CO" : list }             # <<<<<<<<<<<<<<
33169  * 
33170  * # order of records within sam headers
33171  */
33172   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__CO), ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33173   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_TYPES, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33174   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33175
33176   /* "csamtools.pyx":224
33177  * 
33178  * # order of records within sam headers
33179  * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO" )             # <<<<<<<<<<<<<<
33180  * 
33181  * # type conversions within sam header records
33182  */
33183   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADERS, ((PyObject *)__pyx_k_tuple_233)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33184
33185   /* "csamtools.pyx":227
33186  * 
33187  * # type conversions within sam header records
33188  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },             # <<<<<<<<<<<<<<
33189  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
33190  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
33191  */
33192   __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33193   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33194   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33195   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
33196   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33197   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33198   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__GO), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33199   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33200   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33201
33202   /* "csamtools.pyx":228
33203  * # type conversions within sam header records
33204  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
33205  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },             # <<<<<<<<<<<<<<
33206  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
33207  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }
33208  */
33209   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33210   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
33211   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33212   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LN), ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33213   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__AS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33214   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__M5), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33215   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__UR), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33216   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SP), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33217   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33218   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33219
33220   /* "csamtools.pyx":229
33221  * VALID_HEADER_FIELDS = { "HD" : { "VN" : str, "SO" : str, "GO" : str },
33222  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
33223  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },             # <<<<<<<<<<<<<<
33224  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }
33225  * 
33226  */
33227   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33228   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
33229   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33230   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__SM), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33231   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__LB), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33232   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DS), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33233   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PU), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33234   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PI), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33235   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33236   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__DT), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33237   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33238   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33239   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33240
33241   /* "csamtools.pyx":230
33242  *                         "SQ" : { "SN" : str, "LN" : int, "AS" : str, "M5" : str, "UR" : str, "SP" : str },
33243  *                         "RG" : { "ID" : str, "SM" : str, "LB" : str, "DS" : str, "PU" : str, "PI" : str, "CN" : str, "DT" : str, "PL" : str, },
33244  *                         "PG" : { "PN" : str, "ID" : str, "VN" : str, "CL" : str }, }             # <<<<<<<<<<<<<<
33245  * 
33246  * # output order of fields within records
33247  */
33248   __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33249   __Pyx_GOTREF(((PyObject *)__pyx_t_1));
33250   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__PN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33251   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ID), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33252   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__VN), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33253   if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__CL), ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33254   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33255   __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
33256   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_FIELDS, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33257   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33258
33259   /* "csamtools.pyx":233
33260  * 
33261  * # output order of fields within records
33262  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),             # <<<<<<<<<<<<<<
33263  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
33264  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
33265  */
33266   __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33267   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33268   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__HD), ((PyObject *)__pyx_k_tuple_234)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33269
33270   /* "csamtools.pyx":234
33271  * # output order of fields within records
33272  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
33273  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),             # <<<<<<<<<<<<<<
33274  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
33275  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
33276  */
33277   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__SQ), ((PyObject *)__pyx_k_tuple_235)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33278
33279   /* "csamtools.pyx":235
33280  * VALID_HEADER_ORDER = { "HD" : ( "VN", "SO", "GO" ),
33281  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
33282  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),             # <<<<<<<<<<<<<<
33283  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }
33284  * 
33285  */
33286   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__RG), ((PyObject *)__pyx_k_tuple_236)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33287
33288   /* "csamtools.pyx":236
33289  *                        "SQ" : ( "SN", "LN", "AS", "M5" , "UR" , "SP" ),
33290  *                        "RG" : ( "ID", "SM", "LB", "DS" , "PU" , "PI" , "CN" , "DT", "PL" ),
33291  *                        "PG" : ( "PN", "ID", "VN", "CL" ), }             # <<<<<<<<<<<<<<
33292  * 
33293  * 
33294  */
33295   if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__PG), ((PyObject *)__pyx_k_tuple_237)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33296   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__VALID_HEADER_ORDER, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33297   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33298
33299   /* "csamtools.pyx":485
33300  *                header = None,
33301  *                port = None,
33302  *                add_sq_text = True,             # <<<<<<<<<<<<<<
33303  *               ):
33304  *         '''open a sam/bam file.
33305  */
33306   __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33307   __Pyx_GOTREF(__pyx_t_3);
33308   __pyx_k_16 = __pyx_t_3;
33309   __Pyx_GIVEREF(__pyx_t_3);
33310   __pyx_t_3 = 0;
33311
33312   /* "csamtools.pyx":744
33313  *                region = None,
33314  *                callback = None,
33315  *                until_eof = False ):             # <<<<<<<<<<<<<<
33316  *         '''
33317  *         fetch aligned reads in a :term:`region` using 0-based indexing. The region is specified by
33318  */
33319   __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33320   __Pyx_GOTREF(__pyx_t_3);
33321   __pyx_k_44 = __pyx_t_3;
33322   __Pyx_GIVEREF(__pyx_t_3);
33323   __pyx_t_3 = 0;
33324
33325   /* "csamtools.pyx":861
33326  *                end = None,
33327  *                region = None,
33328  *                until_eof = False ):             # <<<<<<<<<<<<<<
33329  *         '''*(reference = None, start = None, end = None, region = None, callback = None, until_eof = False)*
33330  * 
33331  */
33332   __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33333   __Pyx_GOTREF(__pyx_t_3);
33334   __pyx_k_62 = __pyx_t_3;
33335   __Pyx_GIVEREF(__pyx_t_3);
33336   __pyx_t_3 = 0;
33337
33338   /* "csamtools.pyx":1783
33339  *                   int tid = 0,
33340  *                   int start = 0,
33341  *                   int end = max_pos,             # <<<<<<<<<<<<<<
33342  *                   **kwargs ):
33343  * 
33344  */
33345   __pyx_k_115 = __pyx_v_9csamtools_max_pos;
33346
33347   /* "csamtools.pyx":2785
33348  *             return self._level
33349  * 
33350  * class Outs:             # <<<<<<<<<<<<<<
33351  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
33352  *     def __init__(self, id = 1):
33353  */
33354   __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33355   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33356
33357   /* "csamtools.pyx":2787
33358  * class Outs:
33359  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
33360  *     def __init__(self, id = 1):             # <<<<<<<<<<<<<<
33361  *         self.streams = []
33362  *         self.id = id
33363  */
33364   __pyx_t_1 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_4Outs___init__, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33365   __Pyx_GOTREF(__pyx_t_1);
33366   if (PyObject_SetItem(__pyx_t_3, __pyx_n_s____init__, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33367   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33368
33369   /* "csamtools.pyx":2791
33370  *         self.id = id
33371  * 
33372  *     def setdevice(self, filename):             # <<<<<<<<<<<<<<
33373  *         '''open an existing file, like "/dev/null"'''
33374  *         fd = os.open(filename, os.O_WRONLY)
33375  */
33376   __pyx_t_1 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_4Outs_1setdevice, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33377   __Pyx_GOTREF(__pyx_t_1);
33378   if (PyObject_SetItem(__pyx_t_3, __pyx_n_s__setdevice, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33379   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33380
33381   /* "csamtools.pyx":2796
33382  *         self.setfd(fd)
33383  * 
33384  *     def setfile(self, filename):             # <<<<<<<<<<<<<<
33385  *         '''open a new file.'''
33386  *         fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0660);
33387  */
33388   __pyx_t_1 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_4Outs_2setfile, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33389   __Pyx_GOTREF(__pyx_t_1);
33390   if (PyObject_SetItem(__pyx_t_3, __pyx_n_s__setfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33391   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33392
33393   /* "csamtools.pyx":2801
33394  *         self.setfd(fd)
33395  * 
33396  *     def setfd(self, fd):             # <<<<<<<<<<<<<<
33397  *         ofd = os.dup(self.id)      #  Save old stream on new unit.
33398  *         self.streams.append(ofd)
33399  */
33400   __pyx_t_1 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_4Outs_3setfd, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33401   __Pyx_GOTREF(__pyx_t_1);
33402   if (PyObject_SetItem(__pyx_t_3, __pyx_n_s__setfd, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2801; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33403   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33404
33405   /* "csamtools.pyx":2809
33406  *         os.close(fd)                #  Close other unit (look out, caller.)
33407  * 
33408  *     def restore(self):             # <<<<<<<<<<<<<<
33409  *         '''restore previous output stream'''
33410  *         if self.streams:
33411  */
33412   __pyx_t_1 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_9csamtools_4Outs_4restore, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33413   __Pyx_GOTREF(__pyx_t_1);
33414   if (PyObject_SetItem(__pyx_t_3, __pyx_n_s__restore, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33415   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33416
33417   /* "csamtools.pyx":2785
33418  *             return self._level
33419  * 
33420  * class Outs:             # <<<<<<<<<<<<<<
33421  *     '''http://mail.python.org/pipermail/python-list/2000-June/038406.html'''
33422  *     def __init__(self, id = 1):
33423  */
33424   if (PyDict_SetItemString(((PyObject *)__pyx_t_3), "__doc__", ((PyObject *)__pyx_kp_s_238)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33425   __pyx_t_1 = __Pyx_CreateClass(((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3), __pyx_n_s__Outs, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33426   __Pyx_GOTREF(__pyx_t_1);
33427   if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Outs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33428   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
33429   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33430
33431   /* "csamtools.pyx":2822
33432  * def _samtools_dispatch( method,
33433  *                         args = (),
33434  *                         catch_stdout = True,             # <<<<<<<<<<<<<<
33435  *                         catch_stderr = False,
33436  *                         ):
33437  */
33438   __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33439   __Pyx_GOTREF(__pyx_t_3);
33440   __pyx_k_160 = __pyx_t_3;
33441   __Pyx_GIVEREF(__pyx_t_3);
33442   __pyx_t_3 = 0;
33443
33444   /* "csamtools.pyx":2823
33445  *                         args = (),
33446  *                         catch_stdout = True,
33447  *                         catch_stderr = False,             # <<<<<<<<<<<<<<
33448  *                         ):
33449  *     '''call ``method`` in samtools providing arguments in args.
33450  */
33451   __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33452   __Pyx_GOTREF(__pyx_t_3);
33453   __pyx_k_161 = __pyx_t_3;
33454   __Pyx_GIVEREF(__pyx_t_3);
33455   __pyx_t_3 = 0;
33456
33457   /* "csamtools.pyx":2820
33458  *             del self.streams[-1]
33459  * 
33460  * def _samtools_dispatch( method,             # <<<<<<<<<<<<<<
33461  *                         args = (),
33462  *                         catch_stdout = True,
33463  */
33464   __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_9csamtools__samtools_dispatch, NULL, __pyx_n_s__csamtools); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33465   __Pyx_GOTREF(__pyx_t_3);
33466   if (PyObject_SetAttr(__pyx_m, __pyx_n_s___samtools_dispatch, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33467   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
33468
33469   /* "csamtools.pyx":3522
33470  *         if self.owns_samfile: samclose( self.fp )
33471  * 
33472  * __all__ = ["Samfile",             # <<<<<<<<<<<<<<
33473  *            "Fastafile",
33474  *            "IteratorRow",
33475  */
33476   __pyx_t_3 = PyList_New(9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33477   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33478   __Pyx_INCREF(((PyObject *)__pyx_n_s__Samfile));
33479   PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_n_s__Samfile));
33480   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Samfile));
33481   __Pyx_INCREF(((PyObject *)__pyx_n_s__Fastafile));
33482   PyList_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_n_s__Fastafile));
33483   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Fastafile));
33484   __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorRow));
33485   PyList_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_n_s__IteratorRow));
33486   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorRow));
33487   __Pyx_INCREF(((PyObject *)__pyx_n_s__IteratorColumn));
33488   PyList_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_n_s__IteratorColumn));
33489   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IteratorColumn));
33490   __Pyx_INCREF(((PyObject *)__pyx_n_s__AlignedRead));
33491   PyList_SET_ITEM(__pyx_t_3, 4, ((PyObject *)__pyx_n_s__AlignedRead));
33492   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__AlignedRead));
33493   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupColumn));
33494   PyList_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_n_s__PileupColumn));
33495   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupColumn));
33496   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupProxy));
33497   PyList_SET_ITEM(__pyx_t_3, 6, ((PyObject *)__pyx_n_s__PileupProxy));
33498   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupProxy));
33499   __Pyx_INCREF(((PyObject *)__pyx_n_s__PileupRead));
33500   PyList_SET_ITEM(__pyx_t_3, 7, ((PyObject *)__pyx_n_s__PileupRead));
33501   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PileupRead));
33502   __Pyx_INCREF(((PyObject *)__pyx_n_s__IndexedReads));
33503   PyList_SET_ITEM(__pyx_t_3, 8, ((PyObject *)__pyx_n_s__IndexedReads));
33504   __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IndexedReads));
33505   if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33506   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33507
33508   /* "csamtools.pyx":1
33509  * # cython: embedsignature=True             # <<<<<<<<<<<<<<
33510  * # cython: profile=True
33511  * # adds doc-strings for sphinx
33512  */
33513   __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33514   __Pyx_GOTREF(((PyObject *)__pyx_t_3));
33515   if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
33516   __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
33517
33518   /* "cpython/type.pxd":2
33519  * 
33520  * cdef extern from "Python.h":             # <<<<<<<<<<<<<<
33521  *     # The C structure of the objects used to describe built-in types.
33522  * 
33523  */
33524   goto __pyx_L0;
33525   __pyx_L1_error:;
33526   __Pyx_XDECREF(__pyx_t_1);
33527   __Pyx_XDECREF(__pyx_t_2);
33528   __Pyx_XDECREF(__pyx_t_3);
33529   if (__pyx_m) {
33530     __Pyx_AddTraceback("init csamtools");
33531     Py_DECREF(__pyx_m); __pyx_m = 0;
33532   } else if (!PyErr_Occurred()) {
33533     PyErr_SetString(PyExc_ImportError, "init csamtools");
33534   }
33535   __pyx_L0:;
33536   __Pyx_RefNannyFinishContext();
33537   #if PY_MAJOR_VERSION < 3
33538   return;
33539   #else
33540   return __pyx_m;
33541   #endif
33542 }
33543
33544 /* Runtime support code */
33545
33546 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
33547     PyObject *result;
33548     result = PyObject_GetAttr(dict, name);
33549     if (!result)
33550         PyErr_SetObject(PyExc_NameError, name);
33551     return result;
33552 }
33553
33554
33555 #if CYTHON_PROFILE
33556
33557 static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
33558                                    PyFrameObject** frame,
33559                                    const char *funcname,
33560                                    const char *srcfile,
33561                                    int firstlineno) {
33562     if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
33563         if (*code == NULL) {
33564             *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
33565             if (*code == NULL) return 0;
33566         }
33567         *frame = PyFrame_New(
33568             PyThreadState_GET(),            /*PyThreadState *tstate*/
33569             *code,                          /*PyCodeObject *code*/
33570             PyModule_GetDict(__pyx_m),      /*PyObject *globals*/
33571             0                               /*PyObject *locals*/
33572         );
33573         if (*frame == NULL) return 0;
33574     }
33575     else {
33576         (*frame)->f_tstate = PyThreadState_GET();
33577     }
33578     return PyThreadState_GET()->c_profilefunc(PyThreadState_GET()->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
33579 }
33580
33581 static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
33582     PyObject *py_srcfile = 0;
33583     PyObject *py_funcname = 0;
33584     PyCodeObject *py_code = 0;
33585
33586     #if PY_MAJOR_VERSION < 3
33587     py_funcname = PyString_FromString(funcname);
33588     py_srcfile = PyString_FromString(srcfile);
33589     #else
33590     py_funcname = PyUnicode_FromString(funcname);
33591     py_srcfile = PyUnicode_FromString(srcfile);
33592     #endif
33593     if (!py_funcname | !py_srcfile) goto bad;
33594
33595     py_code = PyCode_New(
33596         0,                /*int argcount,*/
33597         #if PY_MAJOR_VERSION >= 3
33598         0,                /*int kwonlyargcount,*/
33599         #endif
33600         0,                /*int nlocals,*/
33601         0,                /*int stacksize,*/
33602         0,                /*int flags,*/
33603         __pyx_empty_bytes,  /*PyObject *code,*/
33604         __pyx_empty_tuple,  /*PyObject *consts,*/
33605         __pyx_empty_tuple,  /*PyObject *names,*/
33606         __pyx_empty_tuple,  /*PyObject *varnames,*/
33607         __pyx_empty_tuple,  /*PyObject *freevars,*/
33608         __pyx_empty_tuple,  /*PyObject *cellvars,*/
33609         py_srcfile,       /*PyObject *filename,*/
33610         py_funcname,      /*PyObject *name,*/
33611         firstlineno,      /*int firstlineno,*/
33612         __pyx_empty_bytes   /*PyObject *lnotab*/
33613     );
33614
33615 bad:
33616     Py_XDECREF(py_srcfile);
33617     Py_XDECREF(py_funcname);
33618
33619     return py_code;
33620 }
33621
33622 #endif /* CYTHON_PROFILE */
33623
33624 static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
33625     if (unlikely(!type)) {
33626         PyErr_Format(PyExc_SystemError, "Missing type object");
33627         return 0;
33628     }
33629     if (likely(PyObject_TypeCheck(obj, type)))
33630         return 1;
33631     PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
33632                  Py_TYPE(obj)->tp_name, type->tp_name);
33633     return 0;
33634 }
33635
33636 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
33637     PyErr_Format(PyExc_ValueError,
33638         #if PY_VERSION_HEX < 0x02050000
33639                  "need more than %d value%s to unpack", (int)index,
33640         #else
33641                  "need more than %zd value%s to unpack", index,
33642         #endif
33643                  (index == 1) ? "" : "s");
33644 }
33645
33646 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
33647     PyErr_Format(PyExc_ValueError,
33648         #if PY_VERSION_HEX < 0x02050000
33649             "too many values to unpack (expected %d)", (int)expected);
33650         #else
33651             "too many values to unpack (expected %zd)", expected);
33652         #endif
33653 }
33654
33655 static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
33656     PyObject *item;
33657     if (!(item = PyIter_Next(iter))) {
33658         if (!PyErr_Occurred()) {
33659             __Pyx_RaiseNeedMoreValuesError(index);
33660         }
33661     }
33662     return item;
33663 }
33664
33665 static int __Pyx_EndUnpack(PyObject *iter, Py_ssize_t expected) {
33666     PyObject *item;
33667     if ((item = PyIter_Next(iter))) {
33668         Py_DECREF(item);
33669         __Pyx_RaiseTooManyValuesError(expected);
33670         return -1;
33671     }
33672     else if (!PyErr_Occurred())
33673         return 0;
33674     else
33675         return -1;
33676 }
33677
33678 static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
33679     PyObject *kwdict,
33680     const char* function_name,
33681     int kw_allowed)
33682 {
33683     PyObject* key = 0;
33684     Py_ssize_t pos = 0;
33685     while (PyDict_Next(kwdict, &pos, &key, 0)) {
33686         #if PY_MAJOR_VERSION < 3
33687         if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
33688         #else
33689         if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
33690         #endif
33691             goto invalid_keyword_type;
33692     }
33693     if ((!kw_allowed) && unlikely(key))
33694         goto invalid_keyword;
33695     return 1;
33696 invalid_keyword_type:
33697     PyErr_Format(PyExc_TypeError,
33698         "%s() keywords must be strings", function_name);
33699     return 0;
33700 invalid_keyword:
33701     PyErr_Format(PyExc_TypeError,
33702     #if PY_MAJOR_VERSION < 3
33703         "%s() got an unexpected keyword argument '%s'",
33704         function_name, PyString_AsString(key));
33705     #else
33706         "%s() got an unexpected keyword argument '%U'",
33707         function_name, key);
33708     #endif
33709     return 0;
33710 }
33711
33712 static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
33713     PyObject *tmp_type, *tmp_value, *tmp_tb;
33714     PyThreadState *tstate = PyThreadState_GET();
33715
33716     tmp_type = tstate->curexc_type;
33717     tmp_value = tstate->curexc_value;
33718     tmp_tb = tstate->curexc_traceback;
33719     tstate->curexc_type = type;
33720     tstate->curexc_value = value;
33721     tstate->curexc_traceback = tb;
33722     Py_XDECREF(tmp_type);
33723     Py_XDECREF(tmp_value);
33724     Py_XDECREF(tmp_tb);
33725 }
33726
33727 static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
33728     PyThreadState *tstate = PyThreadState_GET();
33729     *type = tstate->curexc_type;
33730     *value = tstate->curexc_value;
33731     *tb = tstate->curexc_traceback;
33732
33733     tstate->curexc_type = 0;
33734     tstate->curexc_value = 0;
33735     tstate->curexc_traceback = 0;
33736 }
33737
33738
33739 #if PY_MAJOR_VERSION < 3
33740 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
33741     Py_XINCREF(type);
33742     Py_XINCREF(value);
33743     Py_XINCREF(tb);
33744     /* First, check the traceback argument, replacing None with NULL. */
33745     if (tb == Py_None) {
33746         Py_DECREF(tb);
33747         tb = 0;
33748     }
33749     else if (tb != NULL && !PyTraceBack_Check(tb)) {
33750         PyErr_SetString(PyExc_TypeError,
33751             "raise: arg 3 must be a traceback or None");
33752         goto raise_error;
33753     }
33754     /* Next, replace a missing value with None */
33755     if (value == NULL) {
33756         value = Py_None;
33757         Py_INCREF(value);
33758     }
33759     #if PY_VERSION_HEX < 0x02050000
33760     if (!PyClass_Check(type))
33761     #else
33762     if (!PyType_Check(type))
33763     #endif
33764     {
33765         /* Raising an instance.  The value should be a dummy. */
33766         if (value != Py_None) {
33767             PyErr_SetString(PyExc_TypeError,
33768                 "instance exception may not have a separate value");
33769             goto raise_error;
33770         }
33771         /* Normalize to raise <class>, <instance> */
33772         Py_DECREF(value);
33773         value = type;
33774         #if PY_VERSION_HEX < 0x02050000
33775             if (PyInstance_Check(type)) {
33776                 type = (PyObject*) ((PyInstanceObject*)type)->in_class;
33777                 Py_INCREF(type);
33778             }
33779             else {
33780                 type = 0;
33781                 PyErr_SetString(PyExc_TypeError,
33782                     "raise: exception must be an old-style class or instance");
33783                 goto raise_error;
33784             }
33785         #else
33786             type = (PyObject*) Py_TYPE(type);
33787             Py_INCREF(type);
33788             if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
33789                 PyErr_SetString(PyExc_TypeError,
33790                     "raise: exception class must be a subclass of BaseException");
33791                 goto raise_error;
33792             }
33793         #endif
33794     }
33795
33796     __Pyx_ErrRestore(type, value, tb);
33797     return;
33798 raise_error:
33799     Py_XDECREF(value);
33800     Py_XDECREF(type);
33801     Py_XDECREF(tb);
33802     return;
33803 }
33804
33805 #else /* Python 3+ */
33806
33807 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
33808     if (tb == Py_None) {
33809         tb = 0;
33810     } else if (tb && !PyTraceBack_Check(tb)) {
33811         PyErr_SetString(PyExc_TypeError,
33812             "raise: arg 3 must be a traceback or None");
33813         goto bad;
33814     }
33815     if (value == Py_None)
33816         value = 0;
33817
33818     if (PyExceptionInstance_Check(type)) {
33819         if (value) {
33820             PyErr_SetString(PyExc_TypeError,
33821                 "instance exception may not have a separate value");
33822             goto bad;
33823         }
33824         value = type;
33825         type = (PyObject*) Py_TYPE(value);
33826     } else if (!PyExceptionClass_Check(type)) {
33827         PyErr_SetString(PyExc_TypeError,
33828             "raise: exception class must be a subclass of BaseException");
33829         goto bad;
33830     }
33831
33832     PyErr_SetObject(type, value);
33833
33834     if (tb) {
33835         PyThreadState *tstate = PyThreadState_GET();
33836         PyObject* tmp_tb = tstate->curexc_traceback;
33837         if (tb != tmp_tb) {
33838             Py_INCREF(tb);
33839             tstate->curexc_traceback = tb;
33840             Py_XDECREF(tmp_tb);
33841         }
33842     }
33843
33844 bad:
33845     return;
33846 }
33847 #endif
33848
33849 static void __Pyx_RaiseDoubleKeywordsError(
33850     const char* func_name,
33851     PyObject* kw_name)
33852 {
33853     PyErr_Format(PyExc_TypeError,
33854         #if PY_MAJOR_VERSION >= 3
33855         "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
33856         #else
33857         "%s() got multiple values for keyword argument '%s'", func_name,
33858         PyString_AS_STRING(kw_name));
33859         #endif
33860 }
33861
33862 static int __Pyx_ParseOptionalKeywords(
33863     PyObject *kwds,
33864     PyObject **argnames[],
33865     PyObject *kwds2,
33866     PyObject *values[],
33867     Py_ssize_t num_pos_args,
33868     const char* function_name)
33869 {
33870     PyObject *key = 0, *value = 0;
33871     Py_ssize_t pos = 0;
33872     PyObject*** name;
33873     PyObject*** first_kw_arg = argnames + num_pos_args;
33874
33875     while (PyDict_Next(kwds, &pos, &key, &value)) {
33876         name = first_kw_arg;
33877         while (*name && (**name != key)) name++;
33878         if (*name) {
33879             values[name-argnames] = value;
33880         } else {
33881             #if PY_MAJOR_VERSION < 3
33882             if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
33883             #else
33884             if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
33885             #endif
33886                 goto invalid_keyword_type;
33887             } else {
33888                 for (name = first_kw_arg; *name; name++) {
33889                     #if PY_MAJOR_VERSION >= 3
33890                     if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
33891                         PyUnicode_Compare(**name, key) == 0) break;
33892                     #else
33893                     if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
33894                         _PyString_Eq(**name, key)) break;
33895                     #endif
33896                 }
33897                 if (*name) {
33898                     values[name-argnames] = value;
33899                 } else {
33900                     /* unexpected keyword found */
33901                     for (name=argnames; name != first_kw_arg; name++) {
33902                         if (**name == key) goto arg_passed_twice;
33903                         #if PY_MAJOR_VERSION >= 3
33904                         if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
33905                             PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
33906                         #else
33907                         if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
33908                             _PyString_Eq(**name, key)) goto arg_passed_twice;
33909                         #endif
33910                     }
33911                     if (kwds2) {
33912                         if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
33913                     } else {
33914                         goto invalid_keyword;
33915                     }
33916                 }
33917             }
33918         }
33919     }
33920     return 0;
33921 arg_passed_twice:
33922     __Pyx_RaiseDoubleKeywordsError(function_name, **name);
33923     goto bad;
33924 invalid_keyword_type:
33925     PyErr_Format(PyExc_TypeError,
33926         "%s() keywords must be strings", function_name);
33927     goto bad;
33928 invalid_keyword:
33929     PyErr_Format(PyExc_TypeError,
33930     #if PY_MAJOR_VERSION < 3
33931         "%s() got an unexpected keyword argument '%s'",
33932         function_name, PyString_AsString(key));
33933     #else
33934         "%s() got an unexpected keyword argument '%U'",
33935         function_name, key);
33936     #endif
33937 bad:
33938     return -1;
33939 }
33940
33941 static void __Pyx_RaiseArgtupleInvalid(
33942     const char* func_name,
33943     int exact,
33944     Py_ssize_t num_min,
33945     Py_ssize_t num_max,
33946     Py_ssize_t num_found)
33947 {
33948     Py_ssize_t num_expected;
33949     const char *number, *more_or_less;
33950
33951     if (num_found < num_min) {
33952         num_expected = num_min;
33953         more_or_less = "at least";
33954     } else {
33955         num_expected = num_max;
33956         more_or_less = "at most";
33957     }
33958     if (exact) {
33959         more_or_less = "exactly";
33960     }
33961     number = (num_expected == 1) ? "" : "s";
33962     PyErr_Format(PyExc_TypeError,
33963         #if PY_VERSION_HEX < 0x02050000
33964             "%s() takes %s %d positional argument%s (%d given)",
33965         #else
33966             "%s() takes %s %zd positional argument%s (%zd given)",
33967         #endif
33968         func_name, more_or_less, num_expected, number, num_found);
33969 }
33970
33971 static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
33972     const char *name, int exact)
33973 {
33974     if (!type) {
33975         PyErr_Format(PyExc_SystemError, "Missing type object");
33976         return 0;
33977     }
33978     if (none_allowed && obj == Py_None) return 1;
33979     else if (exact) {
33980         if (Py_TYPE(obj) == type) return 1;
33981     }
33982     else {
33983         if (PyObject_TypeCheck(obj, type)) return 1;
33984     }
33985     PyErr_Format(PyExc_TypeError,
33986         "Argument '%s' has incorrect type (expected %s, got %s)",
33987         name, type->tp_name, Py_TYPE(obj)->tp_name);
33988     return 0;
33989 }
33990
33991 static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
33992     PyObject *local_type, *local_value, *local_tb;
33993     PyObject *tmp_type, *tmp_value, *tmp_tb;
33994     PyThreadState *tstate = PyThreadState_GET();
33995     local_type = tstate->curexc_type;
33996     local_value = tstate->curexc_value;
33997     local_tb = tstate->curexc_traceback;
33998     tstate->curexc_type = 0;
33999     tstate->curexc_value = 0;
34000     tstate->curexc_traceback = 0;
34001     PyErr_NormalizeException(&local_type, &local_value, &local_tb);
34002     if (unlikely(tstate->curexc_type))
34003         goto bad;
34004     #if PY_MAJOR_VERSION >= 3
34005     if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
34006         goto bad;
34007     #endif
34008     *type = local_type;
34009     *value = local_value;
34010     *tb = local_tb;
34011     Py_INCREF(local_type);
34012     Py_INCREF(local_value);
34013     Py_INCREF(local_tb);
34014     tmp_type = tstate->exc_type;
34015     tmp_value = tstate->exc_value;
34016     tmp_tb = tstate->exc_traceback;
34017     tstate->exc_type = local_type;
34018     tstate->exc_value = local_value;
34019     tstate->exc_traceback = local_tb;
34020     /* Make sure tstate is in a consistent state when we XDECREF
34021        these objects (XDECREF may run arbitrary code). */
34022     Py_XDECREF(tmp_type);
34023     Py_XDECREF(tmp_value);
34024     Py_XDECREF(tmp_tb);
34025     return 0;
34026 bad:
34027     *type = 0;
34028     *value = 0;
34029     *tb = 0;
34030     Py_XDECREF(local_type);
34031     Py_XDECREF(local_value);
34032     Py_XDECREF(local_tb);
34033     return -1;
34034 }
34035
34036
34037
34038 static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
34039     PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
34040 }
34041
34042 static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
34043     long q = a / b;
34044     long r = a - q*b;
34045     q -= ((r != 0) & ((r ^ b) < 0));
34046     return q;
34047 }
34048
34049 static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
34050     long r = a % b;
34051     r += ((r != 0) & ((r ^ b) < 0)) * b;
34052     return r;
34053 }
34054
34055
34056 static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
34057     PyThreadState *tstate = PyThreadState_GET();
34058     *type = tstate->exc_type;
34059     *value = tstate->exc_value;
34060     *tb = tstate->exc_traceback;
34061     Py_XINCREF(*type);
34062     Py_XINCREF(*value);
34063     Py_XINCREF(*tb);
34064 }
34065
34066 static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
34067     PyObject *tmp_type, *tmp_value, *tmp_tb;
34068     PyThreadState *tstate = PyThreadState_GET();
34069     tmp_type = tstate->exc_type;
34070     tmp_value = tstate->exc_value;
34071     tmp_tb = tstate->exc_traceback;
34072     tstate->exc_type = type;
34073     tstate->exc_value = value;
34074     tstate->exc_traceback = tb;
34075     Py_XDECREF(tmp_type);
34076     Py_XDECREF(tmp_value);
34077     Py_XDECREF(tmp_tb);
34078 }
34079
34080 static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
34081     PyObject *py_import = 0;
34082     PyObject *empty_list = 0;
34083     PyObject *module = 0;
34084     PyObject *global_dict = 0;
34085     PyObject *empty_dict = 0;
34086     PyObject *list;
34087     py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
34088     if (!py_import)
34089         goto bad;
34090     if (from_list)
34091         list = from_list;
34092     else {
34093         empty_list = PyList_New(0);
34094         if (!empty_list)
34095             goto bad;
34096         list = empty_list;
34097     }
34098     global_dict = PyModule_GetDict(__pyx_m);
34099     if (!global_dict)
34100         goto bad;
34101     empty_dict = PyDict_New();
34102     if (!empty_dict)
34103         goto bad;
34104     module = PyObject_CallFunctionObjArgs(py_import,
34105         name, global_dict, empty_dict, list, NULL);
34106 bad:
34107     Py_XDECREF(empty_list);
34108     Py_XDECREF(py_import);
34109     Py_XDECREF(empty_dict);
34110     return module;
34111 }
34112
34113 static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) {
34114     PyObject *metaclass;
34115     /* Default metaclass */
34116 #if PY_MAJOR_VERSION < 3
34117     if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
34118         PyObject *base = PyTuple_GET_ITEM(bases, 0);
34119         metaclass = PyObject_GetAttrString(base, "__class__");
34120         if (!metaclass) {
34121             PyErr_Clear();
34122             metaclass = (PyObject*) Py_TYPE(base);
34123         }
34124     } else {
34125         metaclass = (PyObject *) &PyClass_Type;
34126     }
34127 #else
34128     if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
34129         PyObject *base = PyTuple_GET_ITEM(bases, 0);
34130         metaclass = (PyObject*) Py_TYPE(base);
34131     } else {
34132         metaclass = (PyObject *) &PyType_Type;
34133     }
34134 #endif
34135     Py_INCREF(metaclass);
34136     return metaclass;
34137 }
34138
34139 static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
34140                                    PyObject *modname) {
34141     PyObject *result;
34142     PyObject *metaclass;
34143
34144     if (PyDict_SetItemString(dict, "__module__", modname) < 0)
34145         return NULL;
34146
34147     /* Python2 __metaclass__ */
34148     metaclass = PyDict_GetItemString(dict, "__metaclass__");
34149     if (metaclass) {
34150         Py_INCREF(metaclass);
34151     } else {
34152         metaclass = __Pyx_FindPy2Metaclass(bases);
34153     }
34154     result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
34155     Py_DECREF(metaclass);
34156     return result;
34157 }
34158
34159
34160 static PyObject *__pyx_binding_PyCFunctionType_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) {
34161         __pyx_binding_PyCFunctionType_object *op = PyObject_GC_New(__pyx_binding_PyCFunctionType_object, __pyx_binding_PyCFunctionType);
34162     if (op == NULL)
34163         return NULL;
34164         op->func.m_ml = ml;
34165         Py_XINCREF(self);
34166         op->func.m_self = self;
34167         Py_XINCREF(module);
34168         op->func.m_module = module;
34169         PyObject_GC_Track(op);
34170         return (PyObject *)op;
34171 }
34172
34173 static void __pyx_binding_PyCFunctionType_dealloc(__pyx_binding_PyCFunctionType_object *m) {
34174         PyObject_GC_UnTrack(m);
34175         Py_XDECREF(m->func.m_self);
34176         Py_XDECREF(m->func.m_module);
34177     PyObject_GC_Del(m);
34178 }
34179
34180 static PyObject *__pyx_binding_PyCFunctionType_descr_get(PyObject *func, PyObject *obj, PyObject *type) {
34181         if (obj == Py_None)
34182                 obj = NULL;
34183         return PyMethod_New(func, obj, type);
34184 }
34185
34186 static int __pyx_binding_PyCFunctionType_init(void) {
34187     __pyx_binding_PyCFunctionType_type = PyCFunction_Type;
34188     __pyx_binding_PyCFunctionType_type.tp_name = __Pyx_NAMESTR("cython_binding_builtin_function_or_method");
34189     __pyx_binding_PyCFunctionType_type.tp_dealloc = (destructor)__pyx_binding_PyCFunctionType_dealloc;
34190     __pyx_binding_PyCFunctionType_type.tp_descr_get = __pyx_binding_PyCFunctionType_descr_get;
34191     if (PyType_Ready(&__pyx_binding_PyCFunctionType_type) < 0) {
34192         return -1;
34193     }
34194     __pyx_binding_PyCFunctionType = &__pyx_binding_PyCFunctionType_type;
34195     return 0;
34196
34197 }
34198
34199 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t val) {
34200     const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
34201     const int is_unsigned = const_zero < neg_one;
34202     if ((sizeof(uint32_t) == sizeof(char))  ||
34203         (sizeof(uint32_t) == sizeof(short))) {
34204         return PyInt_FromLong((long)val);
34205     } else if ((sizeof(uint32_t) == sizeof(int)) ||
34206                (sizeof(uint32_t) == sizeof(long))) {
34207         if (is_unsigned)
34208             return PyLong_FromUnsignedLong((unsigned long)val);
34209         else
34210             return PyInt_FromLong((long)val);
34211     } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
34212         if (is_unsigned)
34213             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
34214         else
34215             return PyLong_FromLongLong((PY_LONG_LONG)val);
34216     } else {
34217         int one = 1; int little = (int)*(unsigned char *)&one;
34218         unsigned char *bytes = (unsigned char *)&val;
34219         return _PyLong_FromByteArray(bytes, sizeof(uint32_t), 
34220                                      little, !is_unsigned);
34221     }
34222 }
34223
34224 static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject* x) {
34225     const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
34226     const int is_unsigned = const_zero < neg_one;
34227     if (sizeof(uint32_t) == sizeof(char)) {
34228         if (is_unsigned)
34229             return (uint32_t)__Pyx_PyInt_AsUnsignedChar(x);
34230         else
34231             return (uint32_t)__Pyx_PyInt_AsSignedChar(x);
34232     } else if (sizeof(uint32_t) == sizeof(short)) {
34233         if (is_unsigned)
34234             return (uint32_t)__Pyx_PyInt_AsUnsignedShort(x);
34235         else
34236             return (uint32_t)__Pyx_PyInt_AsSignedShort(x);
34237     } else if (sizeof(uint32_t) == sizeof(int)) {
34238         if (is_unsigned)
34239             return (uint32_t)__Pyx_PyInt_AsUnsignedInt(x);
34240         else
34241             return (uint32_t)__Pyx_PyInt_AsSignedInt(x);
34242     } else if (sizeof(uint32_t) == sizeof(long)) {
34243         if (is_unsigned)
34244             return (uint32_t)__Pyx_PyInt_AsUnsignedLong(x);
34245         else
34246             return (uint32_t)__Pyx_PyInt_AsSignedLong(x);
34247     } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
34248         if (is_unsigned)
34249             return (uint32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
34250         else
34251             return (uint32_t)__Pyx_PyInt_AsSignedLongLong(x);
34252     }  else {
34253         uint32_t val;
34254         PyObject *v = __Pyx_PyNumber_Int(x);
34255         #if PY_VERSION_HEX < 0x03000000
34256         if (likely(v) && !PyLong_Check(v)) {
34257             PyObject *tmp = v;
34258             v = PyNumber_Long(tmp);
34259             Py_DECREF(tmp);
34260         }
34261         #endif
34262         if (likely(v)) {
34263             int one = 1; int is_little = (int)*(unsigned char *)&one;
34264             unsigned char *bytes = (unsigned char *)&val;
34265             int ret = _PyLong_AsByteArray((PyLongObject *)v,
34266                                           bytes, sizeof(val),
34267                                           is_little, !is_unsigned);
34268             Py_DECREF(v);
34269             if (likely(!ret))
34270                 return val;
34271         }
34272         return (uint32_t)-1;
34273     }
34274 }
34275
34276 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int32_t(int32_t val) {
34277     const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
34278     const int is_unsigned = const_zero < neg_one;
34279     if ((sizeof(int32_t) == sizeof(char))  ||
34280         (sizeof(int32_t) == sizeof(short))) {
34281         return PyInt_FromLong((long)val);
34282     } else if ((sizeof(int32_t) == sizeof(int)) ||
34283                (sizeof(int32_t) == sizeof(long))) {
34284         if (is_unsigned)
34285             return PyLong_FromUnsignedLong((unsigned long)val);
34286         else
34287             return PyInt_FromLong((long)val);
34288     } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
34289         if (is_unsigned)
34290             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
34291         else
34292             return PyLong_FromLongLong((PY_LONG_LONG)val);
34293     } else {
34294         int one = 1; int little = (int)*(unsigned char *)&one;
34295         unsigned char *bytes = (unsigned char *)&val;
34296         return _PyLong_FromByteArray(bytes, sizeof(int32_t), 
34297                                      little, !is_unsigned);
34298     }
34299 }
34300
34301 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_int64_t(int64_t val) {
34302     const int64_t neg_one = (int64_t)-1, const_zero = (int64_t)0;
34303     const int is_unsigned = const_zero < neg_one;
34304     if ((sizeof(int64_t) == sizeof(char))  ||
34305         (sizeof(int64_t) == sizeof(short))) {
34306         return PyInt_FromLong((long)val);
34307     } else if ((sizeof(int64_t) == sizeof(int)) ||
34308                (sizeof(int64_t) == sizeof(long))) {
34309         if (is_unsigned)
34310             return PyLong_FromUnsignedLong((unsigned long)val);
34311         else
34312             return PyInt_FromLong((long)val);
34313     } else if (sizeof(int64_t) == sizeof(PY_LONG_LONG)) {
34314         if (is_unsigned)
34315             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
34316         else
34317             return PyLong_FromLongLong((PY_LONG_LONG)val);
34318     } else {
34319         int one = 1; int little = (int)*(unsigned char *)&one;
34320         unsigned char *bytes = (unsigned char *)&val;
34321         return _PyLong_FromByteArray(bytes, sizeof(int64_t), 
34322                                      little, !is_unsigned);
34323     }
34324 }
34325
34326 static CYTHON_INLINE uint64_t __Pyx_PyInt_from_py_uint64_t(PyObject* x) {
34327     const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
34328     const int is_unsigned = const_zero < neg_one;
34329     if (sizeof(uint64_t) == sizeof(char)) {
34330         if (is_unsigned)
34331             return (uint64_t)__Pyx_PyInt_AsUnsignedChar(x);
34332         else
34333             return (uint64_t)__Pyx_PyInt_AsSignedChar(x);
34334     } else if (sizeof(uint64_t) == sizeof(short)) {
34335         if (is_unsigned)
34336             return (uint64_t)__Pyx_PyInt_AsUnsignedShort(x);
34337         else
34338             return (uint64_t)__Pyx_PyInt_AsSignedShort(x);
34339     } else if (sizeof(uint64_t) == sizeof(int)) {
34340         if (is_unsigned)
34341             return (uint64_t)__Pyx_PyInt_AsUnsignedInt(x);
34342         else
34343             return (uint64_t)__Pyx_PyInt_AsSignedInt(x);
34344     } else if (sizeof(uint64_t) == sizeof(long)) {
34345         if (is_unsigned)
34346             return (uint64_t)__Pyx_PyInt_AsUnsignedLong(x);
34347         else
34348             return (uint64_t)__Pyx_PyInt_AsSignedLong(x);
34349     } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
34350         if (is_unsigned)
34351             return (uint64_t)__Pyx_PyInt_AsUnsignedLongLong(x);
34352         else
34353             return (uint64_t)__Pyx_PyInt_AsSignedLongLong(x);
34354     }  else {
34355         uint64_t val;
34356         PyObject *v = __Pyx_PyNumber_Int(x);
34357         #if PY_VERSION_HEX < 0x03000000
34358         if (likely(v) && !PyLong_Check(v)) {
34359             PyObject *tmp = v;
34360             v = PyNumber_Long(tmp);
34361             Py_DECREF(tmp);
34362         }
34363         #endif
34364         if (likely(v)) {
34365             int one = 1; int is_little = (int)*(unsigned char *)&one;
34366             unsigned char *bytes = (unsigned char *)&val;
34367             int ret = _PyLong_AsByteArray((PyLongObject *)v,
34368                                           bytes, sizeof(val),
34369                                           is_little, !is_unsigned);
34370             Py_DECREF(v);
34371             if (likely(!ret))
34372                 return val;
34373         }
34374         return (uint64_t)-1;
34375     }
34376 }
34377
34378 static CYTHON_INLINE int32_t __Pyx_PyInt_from_py_int32_t(PyObject* x) {
34379     const int32_t neg_one = (int32_t)-1, const_zero = (int32_t)0;
34380     const int is_unsigned = const_zero < neg_one;
34381     if (sizeof(int32_t) == sizeof(char)) {
34382         if (is_unsigned)
34383             return (int32_t)__Pyx_PyInt_AsUnsignedChar(x);
34384         else
34385             return (int32_t)__Pyx_PyInt_AsSignedChar(x);
34386     } else if (sizeof(int32_t) == sizeof(short)) {
34387         if (is_unsigned)
34388             return (int32_t)__Pyx_PyInt_AsUnsignedShort(x);
34389         else
34390             return (int32_t)__Pyx_PyInt_AsSignedShort(x);
34391     } else if (sizeof(int32_t) == sizeof(int)) {
34392         if (is_unsigned)
34393             return (int32_t)__Pyx_PyInt_AsUnsignedInt(x);
34394         else
34395             return (int32_t)__Pyx_PyInt_AsSignedInt(x);
34396     } else if (sizeof(int32_t) == sizeof(long)) {
34397         if (is_unsigned)
34398             return (int32_t)__Pyx_PyInt_AsUnsignedLong(x);
34399         else
34400             return (int32_t)__Pyx_PyInt_AsSignedLong(x);
34401     } else if (sizeof(int32_t) == sizeof(PY_LONG_LONG)) {
34402         if (is_unsigned)
34403             return (int32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
34404         else
34405             return (int32_t)__Pyx_PyInt_AsSignedLongLong(x);
34406     }  else {
34407         int32_t val;
34408         PyObject *v = __Pyx_PyNumber_Int(x);
34409         #if PY_VERSION_HEX < 0x03000000
34410         if (likely(v) && !PyLong_Check(v)) {
34411             PyObject *tmp = v;
34412             v = PyNumber_Long(tmp);
34413             Py_DECREF(tmp);
34414         }
34415         #endif
34416         if (likely(v)) {
34417             int one = 1; int is_little = (int)*(unsigned char *)&one;
34418             unsigned char *bytes = (unsigned char *)&val;
34419             int ret = _PyLong_AsByteArray((PyLongObject *)v,
34420                                           bytes, sizeof(val),
34421                                           is_little, !is_unsigned);
34422             Py_DECREF(v);
34423             if (likely(!ret))
34424                 return val;
34425         }
34426         return (int32_t)-1;
34427     }
34428 }
34429
34430 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint8_t(uint8_t val) {
34431     const uint8_t neg_one = (uint8_t)-1, const_zero = (uint8_t)0;
34432     const int is_unsigned = const_zero < neg_one;
34433     if ((sizeof(uint8_t) == sizeof(char))  ||
34434         (sizeof(uint8_t) == sizeof(short))) {
34435         return PyInt_FromLong((long)val);
34436     } else if ((sizeof(uint8_t) == sizeof(int)) ||
34437                (sizeof(uint8_t) == sizeof(long))) {
34438         if (is_unsigned)
34439             return PyLong_FromUnsignedLong((unsigned long)val);
34440         else
34441             return PyInt_FromLong((long)val);
34442     } else if (sizeof(uint8_t) == sizeof(PY_LONG_LONG)) {
34443         if (is_unsigned)
34444             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
34445         else
34446             return PyLong_FromLongLong((PY_LONG_LONG)val);
34447     } else {
34448         int one = 1; int little = (int)*(unsigned char *)&one;
34449         unsigned char *bytes = (unsigned char *)&val;
34450         return _PyLong_FromByteArray(bytes, sizeof(uint8_t), 
34451                                      little, !is_unsigned);
34452     }
34453 }
34454
34455 static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t val) {
34456     const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
34457     const int is_unsigned = const_zero < neg_one;
34458     if ((sizeof(uint64_t) == sizeof(char))  ||
34459         (sizeof(uint64_t) == sizeof(short))) {
34460         return PyInt_FromLong((long)val);
34461     } else if ((sizeof(uint64_t) == sizeof(int)) ||
34462                (sizeof(uint64_t) == sizeof(long))) {
34463         if (is_unsigned)
34464             return PyLong_FromUnsignedLong((unsigned long)val);
34465         else
34466             return PyInt_FromLong((long)val);
34467     } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
34468         if (is_unsigned)
34469             return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
34470         else
34471             return PyLong_FromLongLong((PY_LONG_LONG)val);
34472     } else {
34473         int one = 1; int little = (int)*(unsigned char *)&one;
34474         unsigned char *bytes = (unsigned char *)&val;
34475         return _PyLong_FromByteArray(bytes, sizeof(uint64_t), 
34476                                      little, !is_unsigned);
34477     }
34478 }
34479
34480 static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
34481     const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
34482     const int is_unsigned = neg_one > const_zero;
34483     if (sizeof(unsigned char) < sizeof(long)) {
34484         long val = __Pyx_PyInt_AsLong(x);
34485         if (unlikely(val != (long)(unsigned char)val)) {
34486             if (!unlikely(val == -1 && PyErr_Occurred())) {
34487                 PyErr_SetString(PyExc_OverflowError,
34488                     (is_unsigned && unlikely(val < 0)) ?
34489                     "can't convert negative value to unsigned char" :
34490                     "value too large to convert to unsigned char");
34491             }
34492             return (unsigned char)-1;
34493         }
34494         return (unsigned char)val;
34495     }
34496     return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
34497 }
34498
34499 static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
34500     const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
34501     const int is_unsigned = neg_one > const_zero;
34502     if (sizeof(unsigned short) < sizeof(long)) {
34503         long val = __Pyx_PyInt_AsLong(x);
34504         if (unlikely(val != (long)(unsigned short)val)) {
34505             if (!unlikely(val == -1 && PyErr_Occurred())) {
34506                 PyErr_SetString(PyExc_OverflowError,
34507                     (is_unsigned && unlikely(val < 0)) ?
34508                     "can't convert negative value to unsigned short" :
34509                     "value too large to convert to unsigned short");
34510             }
34511             return (unsigned short)-1;
34512         }
34513         return (unsigned short)val;
34514     }
34515     return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
34516 }
34517
34518 static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
34519     const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
34520     const int is_unsigned = neg_one > const_zero;
34521     if (sizeof(unsigned int) < sizeof(long)) {
34522         long val = __Pyx_PyInt_AsLong(x);
34523         if (unlikely(val != (long)(unsigned int)val)) {
34524             if (!unlikely(val == -1 && PyErr_Occurred())) {
34525                 PyErr_SetString(PyExc_OverflowError,
34526                     (is_unsigned && unlikely(val < 0)) ?
34527                     "can't convert negative value to unsigned int" :
34528                     "value too large to convert to unsigned int");
34529             }
34530             return (unsigned int)-1;
34531         }
34532         return (unsigned int)val;
34533     }
34534     return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
34535 }
34536
34537 static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
34538     const char neg_one = (char)-1, const_zero = 0;
34539     const int is_unsigned = neg_one > const_zero;
34540     if (sizeof(char) < sizeof(long)) {
34541         long val = __Pyx_PyInt_AsLong(x);
34542         if (unlikely(val != (long)(char)val)) {
34543             if (!unlikely(val == -1 && PyErr_Occurred())) {
34544                 PyErr_SetString(PyExc_OverflowError,
34545                     (is_unsigned && unlikely(val < 0)) ?
34546                     "can't convert negative value to char" :
34547                     "value too large to convert to char");
34548             }
34549             return (char)-1;
34550         }
34551         return (char)val;
34552     }
34553     return (char)__Pyx_PyInt_AsLong(x);
34554 }
34555
34556 static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
34557     const short neg_one = (short)-1, const_zero = 0;
34558     const int is_unsigned = neg_one > const_zero;
34559     if (sizeof(short) < sizeof(long)) {
34560         long val = __Pyx_PyInt_AsLong(x);
34561         if (unlikely(val != (long)(short)val)) {
34562             if (!unlikely(val == -1 && PyErr_Occurred())) {
34563                 PyErr_SetString(PyExc_OverflowError,
34564                     (is_unsigned && unlikely(val < 0)) ?
34565                     "can't convert negative value to short" :
34566                     "value too large to convert to short");
34567             }
34568             return (short)-1;
34569         }
34570         return (short)val;
34571     }
34572     return (short)__Pyx_PyInt_AsLong(x);
34573 }
34574
34575 static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
34576     const int neg_one = (int)-1, const_zero = 0;
34577     const int is_unsigned = neg_one > const_zero;
34578     if (sizeof(int) < sizeof(long)) {
34579         long val = __Pyx_PyInt_AsLong(x);
34580         if (unlikely(val != (long)(int)val)) {
34581             if (!unlikely(val == -1 && PyErr_Occurred())) {
34582                 PyErr_SetString(PyExc_OverflowError,
34583                     (is_unsigned && unlikely(val < 0)) ?
34584                     "can't convert negative value to int" :
34585                     "value too large to convert to int");
34586             }
34587             return (int)-1;
34588         }
34589         return (int)val;
34590     }
34591     return (int)__Pyx_PyInt_AsLong(x);
34592 }
34593
34594 static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
34595     const signed char neg_one = (signed char)-1, const_zero = 0;
34596     const int is_unsigned = neg_one > const_zero;
34597     if (sizeof(signed char) < sizeof(long)) {
34598         long val = __Pyx_PyInt_AsLong(x);
34599         if (unlikely(val != (long)(signed char)val)) {
34600             if (!unlikely(val == -1 && PyErr_Occurred())) {
34601                 PyErr_SetString(PyExc_OverflowError,
34602                     (is_unsigned && unlikely(val < 0)) ?
34603                     "can't convert negative value to signed char" :
34604                     "value too large to convert to signed char");
34605             }
34606             return (signed char)-1;
34607         }
34608         return (signed char)val;
34609     }
34610     return (signed char)__Pyx_PyInt_AsSignedLong(x);
34611 }
34612
34613 static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
34614     const signed short neg_one = (signed short)-1, const_zero = 0;
34615     const int is_unsigned = neg_one > const_zero;
34616     if (sizeof(signed short) < sizeof(long)) {
34617         long val = __Pyx_PyInt_AsLong(x);
34618         if (unlikely(val != (long)(signed short)val)) {
34619             if (!unlikely(val == -1 && PyErr_Occurred())) {
34620                 PyErr_SetString(PyExc_OverflowError,
34621                     (is_unsigned && unlikely(val < 0)) ?
34622                     "can't convert negative value to signed short" :
34623                     "value too large to convert to signed short");
34624             }
34625             return (signed short)-1;
34626         }
34627         return (signed short)val;
34628     }
34629     return (signed short)__Pyx_PyInt_AsSignedLong(x);
34630 }
34631
34632 static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
34633     const signed int neg_one = (signed int)-1, const_zero = 0;
34634     const int is_unsigned = neg_one > const_zero;
34635     if (sizeof(signed int) < sizeof(long)) {
34636         long val = __Pyx_PyInt_AsLong(x);
34637         if (unlikely(val != (long)(signed int)val)) {
34638             if (!unlikely(val == -1 && PyErr_Occurred())) {
34639                 PyErr_SetString(PyExc_OverflowError,
34640                     (is_unsigned && unlikely(val < 0)) ?
34641                     "can't convert negative value to signed int" :
34642                     "value too large to convert to signed int");
34643             }
34644             return (signed int)-1;
34645         }
34646         return (signed int)val;
34647     }
34648     return (signed int)__Pyx_PyInt_AsSignedLong(x);
34649 }
34650
34651 static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
34652     const int neg_one = (int)-1, const_zero = 0;
34653     const int is_unsigned = neg_one > const_zero;
34654     if (sizeof(int) < sizeof(long)) {
34655         long val = __Pyx_PyInt_AsLong(x);
34656         if (unlikely(val != (long)(int)val)) {
34657             if (!unlikely(val == -1 && PyErr_Occurred())) {
34658                 PyErr_SetString(PyExc_OverflowError,
34659                     (is_unsigned && unlikely(val < 0)) ?
34660                     "can't convert negative value to int" :
34661                     "value too large to convert to int");
34662             }
34663             return (int)-1;
34664         }
34665         return (int)val;
34666     }
34667     return (int)__Pyx_PyInt_AsLong(x);
34668 }
34669
34670 static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
34671     const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
34672     const int is_unsigned = neg_one > const_zero;
34673 #if PY_VERSION_HEX < 0x03000000
34674     if (likely(PyInt_Check(x))) {
34675         long val = PyInt_AS_LONG(x);
34676         if (is_unsigned && unlikely(val < 0)) {
34677             PyErr_SetString(PyExc_OverflowError,
34678                             "can't convert negative value to unsigned long");
34679             return (unsigned long)-1;
34680         }
34681         return (unsigned long)val;
34682     } else
34683 #endif
34684     if (likely(PyLong_Check(x))) {
34685         if (is_unsigned) {
34686             if (unlikely(Py_SIZE(x) < 0)) {
34687                 PyErr_SetString(PyExc_OverflowError,
34688                                 "can't convert negative value to unsigned long");
34689                 return (unsigned long)-1;
34690             }
34691             return PyLong_AsUnsignedLong(x);
34692         } else {
34693             return PyLong_AsLong(x);
34694         }
34695     } else {
34696         unsigned long val;
34697         PyObject *tmp = __Pyx_PyNumber_Int(x);
34698         if (!tmp) return (unsigned long)-1;
34699         val = __Pyx_PyInt_AsUnsignedLong(tmp);
34700         Py_DECREF(tmp);
34701         return val;
34702     }
34703 }
34704
34705 static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
34706     const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
34707     const int is_unsigned = neg_one > const_zero;
34708 #if PY_VERSION_HEX < 0x03000000
34709     if (likely(PyInt_Check(x))) {
34710         long val = PyInt_AS_LONG(x);
34711         if (is_unsigned && unlikely(val < 0)) {
34712             PyErr_SetString(PyExc_OverflowError,
34713                             "can't convert negative value to unsigned PY_LONG_LONG");
34714             return (unsigned PY_LONG_LONG)-1;
34715         }
34716         return (unsigned PY_LONG_LONG)val;
34717     } else
34718 #endif
34719     if (likely(PyLong_Check(x))) {
34720         if (is_unsigned) {
34721             if (unlikely(Py_SIZE(x) < 0)) {
34722                 PyErr_SetString(PyExc_OverflowError,
34723                                 "can't convert negative value to unsigned PY_LONG_LONG");
34724                 return (unsigned PY_LONG_LONG)-1;
34725             }
34726             return PyLong_AsUnsignedLongLong(x);
34727         } else {
34728             return PyLong_AsLongLong(x);
34729         }
34730     } else {
34731         unsigned PY_LONG_LONG val;
34732         PyObject *tmp = __Pyx_PyNumber_Int(x);
34733         if (!tmp) return (unsigned PY_LONG_LONG)-1;
34734         val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
34735         Py_DECREF(tmp);
34736         return val;
34737     }
34738 }
34739
34740 static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
34741     const long neg_one = (long)-1, const_zero = 0;
34742     const int is_unsigned = neg_one > const_zero;
34743 #if PY_VERSION_HEX < 0x03000000
34744     if (likely(PyInt_Check(x))) {
34745         long val = PyInt_AS_LONG(x);
34746         if (is_unsigned && unlikely(val < 0)) {
34747             PyErr_SetString(PyExc_OverflowError,
34748                             "can't convert negative value to long");
34749             return (long)-1;
34750         }
34751         return (long)val;
34752     } else
34753 #endif
34754     if (likely(PyLong_Check(x))) {
34755         if (is_unsigned) {
34756             if (unlikely(Py_SIZE(x) < 0)) {
34757                 PyErr_SetString(PyExc_OverflowError,
34758                                 "can't convert negative value to long");
34759                 return (long)-1;
34760             }
34761             return PyLong_AsUnsignedLong(x);
34762         } else {
34763             return PyLong_AsLong(x);
34764         }
34765     } else {
34766         long val;
34767         PyObject *tmp = __Pyx_PyNumber_Int(x);
34768         if (!tmp) return (long)-1;
34769         val = __Pyx_PyInt_AsLong(tmp);
34770         Py_DECREF(tmp);
34771         return val;
34772     }
34773 }
34774
34775 static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
34776     const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
34777     const int is_unsigned = neg_one > const_zero;
34778 #if PY_VERSION_HEX < 0x03000000
34779     if (likely(PyInt_Check(x))) {
34780         long val = PyInt_AS_LONG(x);
34781         if (is_unsigned && unlikely(val < 0)) {
34782             PyErr_SetString(PyExc_OverflowError,
34783                             "can't convert negative value to PY_LONG_LONG");
34784             return (PY_LONG_LONG)-1;
34785         }
34786         return (PY_LONG_LONG)val;
34787     } else
34788 #endif
34789     if (likely(PyLong_Check(x))) {
34790         if (is_unsigned) {
34791             if (unlikely(Py_SIZE(x) < 0)) {
34792                 PyErr_SetString(PyExc_OverflowError,
34793                                 "can't convert negative value to PY_LONG_LONG");
34794                 return (PY_LONG_LONG)-1;
34795             }
34796             return PyLong_AsUnsignedLongLong(x);
34797         } else {
34798             return PyLong_AsLongLong(x);
34799         }
34800     } else {
34801         PY_LONG_LONG val;
34802         PyObject *tmp = __Pyx_PyNumber_Int(x);
34803         if (!tmp) return (PY_LONG_LONG)-1;
34804         val = __Pyx_PyInt_AsLongLong(tmp);
34805         Py_DECREF(tmp);
34806         return val;
34807     }
34808 }
34809
34810 static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
34811     const signed long neg_one = (signed long)-1, const_zero = 0;
34812     const int is_unsigned = neg_one > const_zero;
34813 #if PY_VERSION_HEX < 0x03000000
34814     if (likely(PyInt_Check(x))) {
34815         long val = PyInt_AS_LONG(x);
34816         if (is_unsigned && unlikely(val < 0)) {
34817             PyErr_SetString(PyExc_OverflowError,
34818                             "can't convert negative value to signed long");
34819             return (signed long)-1;
34820         }
34821         return (signed long)val;
34822     } else
34823 #endif
34824     if (likely(PyLong_Check(x))) {
34825         if (is_unsigned) {
34826             if (unlikely(Py_SIZE(x) < 0)) {
34827                 PyErr_SetString(PyExc_OverflowError,
34828                                 "can't convert negative value to signed long");
34829                 return (signed long)-1;
34830             }
34831             return PyLong_AsUnsignedLong(x);
34832         } else {
34833             return PyLong_AsLong(x);
34834         }
34835     } else {
34836         signed long val;
34837         PyObject *tmp = __Pyx_PyNumber_Int(x);
34838         if (!tmp) return (signed long)-1;
34839         val = __Pyx_PyInt_AsSignedLong(tmp);
34840         Py_DECREF(tmp);
34841         return val;
34842     }
34843 }
34844
34845 static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
34846     const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
34847     const int is_unsigned = neg_one > const_zero;
34848 #if PY_VERSION_HEX < 0x03000000
34849     if (likely(PyInt_Check(x))) {
34850         long val = PyInt_AS_LONG(x);
34851         if (is_unsigned && unlikely(val < 0)) {
34852             PyErr_SetString(PyExc_OverflowError,
34853                             "can't convert negative value to signed PY_LONG_LONG");
34854             return (signed PY_LONG_LONG)-1;
34855         }
34856         return (signed PY_LONG_LONG)val;
34857     } else
34858 #endif
34859     if (likely(PyLong_Check(x))) {
34860         if (is_unsigned) {
34861             if (unlikely(Py_SIZE(x) < 0)) {
34862                 PyErr_SetString(PyExc_OverflowError,
34863                                 "can't convert negative value to signed PY_LONG_LONG");
34864                 return (signed PY_LONG_LONG)-1;
34865             }
34866             return PyLong_AsUnsignedLongLong(x);
34867         } else {
34868             return PyLong_AsLongLong(x);
34869         }
34870     } else {
34871         signed PY_LONG_LONG val;
34872         PyObject *tmp = __Pyx_PyNumber_Int(x);
34873         if (!tmp) return (signed PY_LONG_LONG)-1;
34874         val = __Pyx_PyInt_AsSignedLongLong(tmp);
34875         Py_DECREF(tmp);
34876         return val;
34877     }
34878 }
34879
34880 static void __Pyx_WriteUnraisable(const char *name) {
34881     PyObject *old_exc, *old_val, *old_tb;
34882     PyObject *ctx;
34883     __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
34884     #if PY_MAJOR_VERSION < 3
34885     ctx = PyString_FromString(name);
34886     #else
34887     ctx = PyUnicode_FromString(name);
34888     #endif
34889     __Pyx_ErrRestore(old_exc, old_val, old_tb);
34890     if (!ctx) {
34891         PyErr_WriteUnraisable(Py_None);
34892     } else {
34893         PyErr_WriteUnraisable(ctx);
34894         Py_DECREF(ctx);
34895     }
34896 }
34897
34898 #ifndef __PYX_HAVE_RT_ImportType
34899 #define __PYX_HAVE_RT_ImportType
34900 static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
34901     long size, int strict)
34902 {
34903     PyObject *py_module = 0;
34904     PyObject *result = 0;
34905     PyObject *py_name = 0;
34906     char warning[200];
34907
34908     py_module = __Pyx_ImportModule(module_name);
34909     if (!py_module)
34910         goto bad;
34911     #if PY_MAJOR_VERSION < 3
34912     py_name = PyString_FromString(class_name);
34913     #else
34914     py_name = PyUnicode_FromString(class_name);
34915     #endif
34916     if (!py_name)
34917         goto bad;
34918     result = PyObject_GetAttr(py_module, py_name);
34919     Py_DECREF(py_name);
34920     py_name = 0;
34921     Py_DECREF(py_module);
34922     py_module = 0;
34923     if (!result)
34924         goto bad;
34925     if (!PyType_Check(result)) {
34926         PyErr_Format(PyExc_TypeError,
34927             "%s.%s is not a type object",
34928             module_name, class_name);
34929         goto bad;
34930     }
34931     if (!strict && ((PyTypeObject *)result)->tp_basicsize > size) {
34932         PyOS_snprintf(warning, sizeof(warning),
34933             "%s.%s size changed, may indicate binary incompatibility",
34934             module_name, class_name);
34935         #if PY_VERSION_HEX < 0x02050000
34936         PyErr_Warn(NULL, warning);
34937         #else
34938         PyErr_WarnEx(NULL, warning, 0);
34939         #endif
34940     }
34941     else if (((PyTypeObject *)result)->tp_basicsize != size) {
34942         PyErr_Format(PyExc_ValueError,
34943             "%s.%s has the wrong size, try recompiling",
34944             module_name, class_name);
34945         goto bad;
34946     }
34947     return (PyTypeObject *)result;
34948 bad:
34949     Py_XDECREF(py_module);
34950     Py_XDECREF(result);
34951     return 0;
34952 }
34953 #endif
34954
34955 #ifndef __PYX_HAVE_RT_ImportModule
34956 #define __PYX_HAVE_RT_ImportModule
34957 static PyObject *__Pyx_ImportModule(const char *name) {
34958     PyObject *py_name = 0;
34959     PyObject *py_module = 0;
34960
34961     #if PY_MAJOR_VERSION < 3
34962     py_name = PyString_FromString(name);
34963     #else
34964     py_name = PyUnicode_FromString(name);
34965     #endif
34966     if (!py_name)
34967         goto bad;
34968     py_module = PyImport_Import(py_name);
34969     Py_DECREF(py_name);
34970     return py_module;
34971 bad:
34972     Py_XDECREF(py_name);
34973     return 0;
34974 }
34975 #endif
34976
34977 static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
34978 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
34979     PyObject *ob = PyCapsule_New(vtable, 0, 0);
34980 #else
34981     PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
34982 #endif
34983     if (!ob)
34984         goto bad;
34985     if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
34986         goto bad;
34987     Py_DECREF(ob);
34988     return 0;
34989 bad:
34990     Py_XDECREF(ob);
34991     return -1;
34992 }
34993
34994 #include "compile.h"
34995 #include "frameobject.h"
34996 #include "traceback.h"
34997
34998 static void __Pyx_AddTraceback(const char *funcname) {
34999     PyObject *py_srcfile = 0;
35000     PyObject *py_funcname = 0;
35001     PyObject *py_globals = 0;
35002     PyCodeObject *py_code = 0;
35003     PyFrameObject *py_frame = 0;
35004
35005     #if PY_MAJOR_VERSION < 3
35006     py_srcfile = PyString_FromString(__pyx_filename);
35007     #else
35008     py_srcfile = PyUnicode_FromString(__pyx_filename);
35009     #endif
35010     if (!py_srcfile) goto bad;
35011     if (__pyx_clineno) {
35012         #if PY_MAJOR_VERSION < 3
35013         py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
35014         #else
35015         py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
35016         #endif
35017     }
35018     else {
35019         #if PY_MAJOR_VERSION < 3
35020         py_funcname = PyString_FromString(funcname);
35021         #else
35022         py_funcname = PyUnicode_FromString(funcname);
35023         #endif
35024     }
35025     if (!py_funcname) goto bad;
35026     py_globals = PyModule_GetDict(__pyx_m);
35027     if (!py_globals) goto bad;
35028     py_code = PyCode_New(
35029         0,            /*int argcount,*/
35030         #if PY_MAJOR_VERSION >= 3
35031         0,            /*int kwonlyargcount,*/
35032         #endif
35033         0,            /*int nlocals,*/
35034         0,            /*int stacksize,*/
35035         0,            /*int flags,*/
35036         __pyx_empty_bytes, /*PyObject *code,*/
35037         __pyx_empty_tuple,  /*PyObject *consts,*/
35038         __pyx_empty_tuple,  /*PyObject *names,*/
35039         __pyx_empty_tuple,  /*PyObject *varnames,*/
35040         __pyx_empty_tuple,  /*PyObject *freevars,*/
35041         __pyx_empty_tuple,  /*PyObject *cellvars,*/
35042         py_srcfile,   /*PyObject *filename,*/
35043         py_funcname,  /*PyObject *name,*/
35044         __pyx_lineno,   /*int firstlineno,*/
35045         __pyx_empty_bytes  /*PyObject *lnotab*/
35046     );
35047     if (!py_code) goto bad;
35048     py_frame = PyFrame_New(
35049         PyThreadState_GET(), /*PyThreadState *tstate,*/
35050         py_code,             /*PyCodeObject *code,*/
35051         py_globals,          /*PyObject *globals,*/
35052         0                    /*PyObject *locals*/
35053     );
35054     if (!py_frame) goto bad;
35055     py_frame->f_lineno = __pyx_lineno;
35056     PyTraceBack_Here(py_frame);
35057 bad:
35058     Py_XDECREF(py_srcfile);
35059     Py_XDECREF(py_funcname);
35060     Py_XDECREF(py_code);
35061     Py_XDECREF(py_frame);
35062 }
35063
35064 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
35065     while (t->p) {
35066         #if PY_MAJOR_VERSION < 3
35067         if (t->is_unicode) {
35068             *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
35069         } else if (t->intern) {
35070             *t->p = PyString_InternFromString(t->s);
35071         } else {
35072             *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
35073         }
35074         #else  /* Python 3+ has unicode identifiers */
35075         if (t->is_unicode | t->is_str) {
35076             if (t->intern) {
35077                 *t->p = PyUnicode_InternFromString(t->s);
35078             } else if (t->encoding) {
35079                 *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
35080             } else {
35081                 *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
35082             }
35083         } else {
35084             *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
35085         }
35086         #endif
35087         if (!*t->p)
35088             return -1;
35089         ++t;
35090     }
35091     return 0;
35092 }
35093
35094 /* Type Conversion Functions */
35095
35096 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
35097    int is_true = x == Py_True;
35098    if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
35099    else return PyObject_IsTrue(x);
35100 }
35101
35102 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
35103   PyNumberMethods *m;
35104   const char *name = NULL;
35105   PyObject *res = NULL;
35106 #if PY_VERSION_HEX < 0x03000000
35107   if (PyInt_Check(x) || PyLong_Check(x))
35108 #else
35109   if (PyLong_Check(x))
35110 #endif
35111     return Py_INCREF(x), x;
35112   m = Py_TYPE(x)->tp_as_number;
35113 #if PY_VERSION_HEX < 0x03000000
35114   if (m && m->nb_int) {
35115     name = "int";
35116     res = PyNumber_Int(x);
35117   }
35118   else if (m && m->nb_long) {
35119     name = "long";
35120     res = PyNumber_Long(x);
35121   }
35122 #else
35123   if (m && m->nb_int) {
35124     name = "int";
35125     res = PyNumber_Long(x);
35126   }
35127 #endif
35128   if (res) {
35129 #if PY_VERSION_HEX < 0x03000000
35130     if (!PyInt_Check(res) && !PyLong_Check(res)) {
35131 #else
35132     if (!PyLong_Check(res)) {
35133 #endif
35134       PyErr_Format(PyExc_TypeError,
35135                    "__%s__ returned non-%s (type %.200s)",
35136                    name, name, Py_TYPE(res)->tp_name);
35137       Py_DECREF(res);
35138       return NULL;
35139     }
35140   }
35141   else if (!PyErr_Occurred()) {
35142     PyErr_SetString(PyExc_TypeError,
35143                     "an integer is required");
35144   }
35145   return res;
35146 }
35147
35148 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
35149   Py_ssize_t ival;
35150   PyObject* x = PyNumber_Index(b);
35151   if (!x) return -1;
35152   ival = PyInt_AsSsize_t(x);
35153   Py_DECREF(x);
35154   return ival;
35155 }
35156
35157 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
35158 #if PY_VERSION_HEX < 0x02050000
35159    if (ival <= LONG_MAX)
35160        return PyInt_FromLong((long)ival);
35161    else {
35162        unsigned char *bytes = (unsigned char *) &ival;
35163        int one = 1; int little = (int)*(unsigned char*)&one;
35164        return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
35165    }
35166 #else
35167    return PyInt_FromSize_t(ival);
35168 #endif
35169 }
35170
35171 static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
35172    unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
35173    if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
35174        return (size_t)-1;
35175    } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
35176        PyErr_SetString(PyExc_OverflowError,
35177                        "value too large to convert to size_t");
35178        return (size_t)-1;
35179    }
35180    return (size_t)val;
35181 }
35182
35183
35184 #endif /* Py_PYTHON_H */