[med-svn] [python-cutadapt] 01/04: Imported Upstream version 1.9.1

Olivier Sallou osallou at debian.org
Thu Dec 10 13:00:42 UTC 2015


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

osallou pushed a commit to branch master
in repository python-cutadapt.

commit e14cd5adf2348e48184411f4dc025739950fb2dd
Author: Olivier Sallou <olivier.sallou at debian.org>
Date:   Thu Dec 10 13:55:52 2015 +0100

    Imported Upstream version 1.9.1
---
 CHANGES.rst                         |   39 +-
 PKG-INFO                            |    2 +-
 cutadapt/__init__.py                |    2 +-
 cutadapt/_align.c                   | 8367 ++++++++++++++++++++++++++++-------
 cutadapt/_align.pyx                 |  282 +-
 cutadapt/_align.so                  |  Bin 385272 -> 532496 bytes
 cutadapt/_qualtrim.c                | 1598 ++++---
 cutadapt/_qualtrim.so               |  Bin 118544 -> 92136 bytes
 cutadapt/_seqio.c                   | 3452 ++++++++-------
 cutadapt/_seqio.pyx                 |   65 +-
 cutadapt/_seqio.so                  |  Bin 427936 -> 397664 bytes
 cutadapt/adapters.py                |  162 +-
 cutadapt/align.py                   |    8 +-
 cutadapt/filters.py                 |  230 +-
 cutadapt/modifiers.py               |  153 +-
 cutadapt/report.py                  |   64 +-
 cutadapt/scripts/cutadapt.py        |  581 +--
 cutadapt/seqio.py                   |  413 +-
 doc/guide.rst                       |  349 +-
 doc/ideas.rst                       |   47 +-
 tests/cut/illumina.info.txt         |  200 +-
 tests/cut/illumina5.info.txt        |   16 +-
 tests/cut/interleaved.fastq         |   16 +
 tests/cut/no_indels.fasta           |   18 +
 tests/cut/paired-filterboth.1.fastq |   16 +
 tests/cut/paired-filterboth.2.fastq |   16 +
 tests/cut/paired-too-short.1.fastq  |    4 +
 tests/cut/paired-too-short.2.fastq  |    4 +
 tests/cut/suffix.fastq              |   60 +-
 tests/data/interleaved.fastq        |   32 +
 tests/data/no_indels.fasta          |   20 +
 tests/data/simple.fasta~            |    6 -
 tests/testadapters.py               |   32 +-
 tests/testalign.py                  |   46 +-
 tests/testfilters.py                |   11 +-
 tests/testpaired.py                 |  105 +-
 tests/tests.py                      |   15 +-
 tests/testseqio.py                  |  450 +-
 38 files changed, 11689 insertions(+), 5192 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index abfcef0..deafe82 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2,9 +2,46 @@
 Changes
 =======
 
-v1.8.1
+v1.9.1
+------
+
+* Added ``--pair-filter`` option, which :ref:`modifies how filtering criteria
+  apply to paired-end reads <filtering-paired>`
+* Add ``--too-short-paired-output`` and ``--too-long-paired-output`` options.
+* Fix incorrect number of trimmed bases reported if ``--times`` option was used.
+
+v1.9
 ----
 
+* Indels in the alignment can now be disabled for all adapter types (use
+  ``--no-indels``).
+* Quality values are now printed in the info file (``--info-file``)
+  when trimming FASTQ files. Fixes issue #144.
+* Options ``--prefix`` and ``--suffix``, which modify read names, now accept the
+  placeholder ``{name}`` and will replace it with the name of the found adapter.
+  Fixes issue #104.
+* Interleaved FASTQ files: With the ``--interleaved`` switch, paired-end reads
+  will be read from and written to interleaved FASTQ files. Fixes issue #113.
+* Anchored 5' adapters can now be specified by writing ``-a SEQUENCE...`` (note
+  the three dots).
+* Fix ``--discard-untrimmed`` and ``--discard-trimmed`` not working as expected
+  in paired-end mode (issue #146).
+* The minimum overlap is now automatically reduced to the adapter length if it
+  is too large. Fixes part of issue #153.
+* Thanks to Wolfgang Gerlach, there is now a Dockerfile.
+* The new ``--debug`` switch makes cutadapt print out the alignment matrix.
+
+v1.8.3
+------
+
+* Fix issue #95: Untrimmed reads were not listed in the info file.
+* Fix issue #138: pip install cutadapt did not work with new setuptools versions.
+* Fix issue #137: Avoid a hang when writing to two or more gzip-compressed
+  output files in Python 2.6.
+
+v1.8.1
+------
+
 * Fix #110: Counts for 'too short' and 'too long' reads were swapped in statistics.
 * Fix #115: Make ``--trim-n`` work also on second read for paired-end data.
 
diff --git a/PKG-INFO b/PKG-INFO
index 4f304ba..55eefca 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cutadapt
-Version: 1.8.3
+Version: 1.9.1
 Summary: trim adapters from high-throughput sequencing reads
 Home-page: https://cutadapt.readthedocs.org/
 Author: Marcel Martin
diff --git a/cutadapt/__init__.py b/cutadapt/__init__.py
index 7d8fa4f..c999841 100644
--- a/cutadapt/__init__.py
+++ b/cutadapt/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import print_function, division, absolute_import
 import sys
 
-__version__ = '1.8.3'
+__version__ = '1.9.1'
 
 def check_importability():  # pragma: no cover
 	try:
diff --git a/cutadapt/_align.c b/cutadapt/_align.c
index 9a4fbb5..9770fbf 100644
--- a/cutadapt/_align.c
+++ b/cutadapt/_align.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.22.1 */
+/* Generated by Cython 0.23.4 */
 
 /* BEGIN: Cython Metadata
 {
@@ -9,25 +9,13 @@
 END: Cython Metadata */
 
 #define PY_SSIZE_T_CLEAN
-#ifndef CYTHON_USE_PYLONG_INTERNALS
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#else
-#include "pyconfig.h"
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 1
-#else
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#endif
-#endif
-#endif
 #include "Python.h"
 #ifndef Py_PYTHON_H
     #error Python headers needed to compile C extensions, please install development version of Python.
 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
     #error Cython requires Python 2.6+ or Python 3.2+.
 #else
-#define CYTHON_ABI "0_22_1"
+#define CYTHON_ABI "0_23_4"
 #include <stddef.h>
 #ifndef offsetof
 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
@@ -62,6 +50,9 @@ END: Cython Metadata */
 #define CYTHON_COMPILING_IN_PYPY 0
 #define CYTHON_COMPILING_IN_CPYTHON 1
 #endif
+#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
+#define CYTHON_USE_PYLONG_INTERNALS 1
+#endif
 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
 #define Py_OptimizeFlag 0
 #endif
@@ -69,12 +60,12 @@ END: Cython Metadata */
 #define CYTHON_FORMAT_SSIZE_T "z"
 #if PY_MAJOR_VERSION < 3
   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyClass_Type
 #else
   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyType_Type
 #endif
@@ -92,7 +83,7 @@ END: Cython Metadata */
 #endif
 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
   #define CYTHON_PEP393_ENABLED 1
-  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
+  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                               0 : _PyUnicode_Ready((PyObject *)(op)))
   #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
   #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
@@ -111,12 +102,10 @@ END: Cython Metadata */
 #if CYTHON_COMPILING_IN_PYPY
   #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
   #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
-  #define __Pyx_PyFrozenSet_Size(s)         PyObject_Size(s)
 #else
   #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
-  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
       PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
-  #define __Pyx_PyFrozenSet_Size(s)         PySet_Size(s)
 #endif
 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
   #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
@@ -184,16 +173,18 @@ END: Cython Metadata */
 #else
   #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
 #endif
-#ifndef CYTHON_INLINE
-  #if defined(__GNUC__)
-    #define CYTHON_INLINE __inline__
-  #elif defined(_MSC_VER)
-    #define CYTHON_INLINE __inline
-  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-    #define CYTHON_INLINE inline
-  #else
-    #define CYTHON_INLINE
-  #endif
+#if PY_VERSION_HEX >= 0x030500B1
+#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
+#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
+#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
+typedef struct {
+    unaryfunc am_await;
+    unaryfunc am_aiter;
+    unaryfunc am_anext;
+} __Pyx_PyAsyncMethodsStruct;
+#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
+#else
+#define __Pyx_PyType_AsAsync(obj) NULL
 #endif
 #ifndef CYTHON_RESTRICT
   #if defined(__GNUC__)
@@ -206,35 +197,33 @@ END: Cython Metadata */
     #define CYTHON_RESTRICT
   #endif
 #endif
+#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
+
+#ifndef CYTHON_INLINE
+  #if defined(__GNUC__)
+    #define CYTHON_INLINE __inline__
+  #elif defined(_MSC_VER)
+    #define CYTHON_INLINE __inline
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_INLINE inline
+  #else
+    #define CYTHON_INLINE
+  #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+  #define _USE_MATH_DEFINES
+#endif
+#include <math.h>
 #ifdef NAN
 #define __PYX_NAN() ((float) NAN)
 #else
 static CYTHON_INLINE float __PYX_NAN() {
-  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
-   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
-   a quiet NaN. */
   float value;
   memset(&value, 0xFF, sizeof(value));
   return value;
 }
 #endif
-#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
-#ifdef __cplusplus
-template<typename T>
-void __Pyx_call_destructor(T* x) {
-    x->~T();
-}
-template<typename T>
-class __Pyx_FakeReference {
-  public:
-    __Pyx_FakeReference() : ptr(NULL) { }
-    __Pyx_FakeReference(T& ref) : ptr(&ref) { }
-    T *operator->() { return ptr; }
-    operator T&() { return *ptr; }
-  private:
-    T *ptr;
-};
-#endif
 
 
 #if PY_MAJOR_VERSION >= 3
@@ -253,10 +242,6 @@ class __Pyx_FakeReference {
   #endif
 #endif
 
-#if defined(WIN32) || defined(MS_WINDOWS)
-#define _USE_MATH_DEFINES
-#endif
-#include <math.h>
 #define __PYX_HAVE__cutadapt___align
 #define __PYX_HAVE_API__cutadapt___align
 #ifdef _OPENMP
@@ -295,16 +280,34 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
 #define __PYX_DEFAULT_STRING_ENCODING ""
 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
-#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (    \
-    (sizeof(type) < sizeof(Py_ssize_t))  ||             \
-    (sizeof(type) > sizeof(Py_ssize_t) &&               \
-          likely(v < (type)PY_SSIZE_T_MAX ||            \
-                 v == (type)PY_SSIZE_T_MAX)  &&         \
-          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||       \
-                                v == (type)PY_SSIZE_T_MIN)))  ||  \
-    (sizeof(type) == sizeof(Py_ssize_t) &&              \
-          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||        \
+#define __Pyx_uchar_cast(c) ((unsigned char)c)
+#define __Pyx_long_cast(x) ((long)x)
+#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
+    (sizeof(type) < sizeof(Py_ssize_t))  ||\
+    (sizeof(type) > sizeof(Py_ssize_t) &&\
+          likely(v < (type)PY_SSIZE_T_MAX ||\
+                 v == (type)PY_SSIZE_T_MAX)  &&\
+          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
+                                v == (type)PY_SSIZE_T_MIN)))  ||\
+    (sizeof(type) == sizeof(Py_ssize_t) &&\
+          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                                v == (type)PY_SSIZE_T_MAX)))  )
+#if defined (__cplusplus) && __cplusplus >= 201103L
+    #include <cstdlib>
+    #define __Pyx_sst_abs(value) std::abs(value)
+#elif SIZEOF_INT >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) abs(value)
+#elif SIZEOF_LONG >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) labs(value)
+#elif defined (_MSC_VER) && defined (_M_X64)
+    #define __Pyx_sst_abs(value) _abs64(value)
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define __Pyx_sst_abs(value) llabs(value)
+#elif defined (__GNUC__)
+    #define __Pyx_sst_abs(value) __builtin_llabs(value)
+#else
+    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
+#endif
 static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
@@ -339,8 +342,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
 #define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
 #define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
-#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
-#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
+#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
@@ -453,12 +457,15 @@ static const char *__pyx_f[] = {
 
 /*--- Type declarations ---*/
 struct __pyx_obj_8cutadapt_6_align_Aligner;
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__;
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr;
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr;
 struct __pyx_t_8cutadapt_6_align__Entry;
 typedef struct __pyx_t_8cutadapt_6_align__Entry __pyx_t_8cutadapt_6_align__Entry;
 struct __pyx_t_8cutadapt_6_align__Match;
 typedef struct __pyx_t_8cutadapt_6_align__Match __pyx_t_8cutadapt_6_align__Match;
 
-/* "cutadapt/_align.pyx":18
+/* "cutadapt/_align.pyx":10
  * 
  * # structure for a DP matrix entry
  * ctypedef struct _Entry:             # <<<<<<<<<<<<<<
@@ -471,7 +478,7 @@ struct __pyx_t_8cutadapt_6_align__Entry {
   int origin;
 };
 
-/* "cutadapt/_align.pyx":24
+/* "cutadapt/_align.pyx":16
  * 
  * 
  * ctypedef struct _Match:             # <<<<<<<<<<<<<<
@@ -486,7 +493,7 @@ struct __pyx_t_8cutadapt_6_align__Match {
   int query_stop;
 };
 
-/* "cutadapt/_align.pyx":92
+/* "cutadapt/_align.pyx":118
  * 
  * 
  * cdef class Aligner:             # <<<<<<<<<<<<<<
@@ -499,10 +506,63 @@ struct __pyx_obj_8cutadapt_6_align_Aligner {
   __pyx_t_8cutadapt_6_align__Entry *column;
   double max_error_rate;
   int flags;
-  int min_overlap;
+  int _insertion_cost;
+  int _deletion_cost;
+  int _min_overlap;
   int wildcard_ref;
   int wildcard_query;
+  int debug;
+  PyObject *_dpmatrix;
   PyObject *_reference;
+  PyObject *str_reference;
+};
+
+
+/* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
+ * 
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
+ */
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ {
+  PyObject_HEAD
+  PyObject *__pyx_v_row;
+  PyObject *__pyx_v_self;
+};
+
+
+/* "cutadapt/_align.pyx":111
+ * 		Return a representation of the matrix as a string.
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]             # <<<<<<<<<<<<<<
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ */
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr {
+  PyObject_HEAD
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *__pyx_outer_scope;
+  PyObject *__pyx_v_c;
+  PyObject *__pyx_t_0;
+  Py_ssize_t __pyx_t_1;
+  PyObject *(*__pyx_t_2)(PyObject *);
+};
+
+
+/* "cutadapt/_align.pyx":113
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)             # <<<<<<<<<<<<<<
+ * 			rows.append(r)
+ * 		return '\n'.join(rows)
+ */
+struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr {
+  PyObject_HEAD
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *__pyx_outer_scope;
+  PyObject *__pyx_v_v;
+  PyObject *__pyx_t_0;
+  Py_ssize_t __pyx_t_1;
+  PyObject *(*__pyx_t_2)(PyObject *);
 };
 
 
@@ -523,19 +583,19 @@ struct __pyx_obj_8cutadapt_6_align_Aligner {
   static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
   #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
 #ifdef WITH_THREAD
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
-          if (acquire_gil) { \
-              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
-              PyGILState_Release(__pyx_gilstate_save); \
-          } else { \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          if (acquire_gil) {\
+              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+              PyGILState_Release(__pyx_gilstate_save);\
+          } else {\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
           }
 #else
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
           __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
 #endif
-  #define __Pyx_RefNannyFinishContext() \
+  #define __Pyx_RefNannyFinishContext()\
           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
   #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
   #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
@@ -558,13 +618,13 @@ struct __pyx_obj_8cutadapt_6_align_Aligner {
   #define __Pyx_XGOTREF(r)
   #define __Pyx_XGIVEREF(r)
 #endif
-#define __Pyx_XDECREF_SET(r, v) do {                            \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_XDECREF(tmp);                              \
+#define __Pyx_XDECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_XDECREF(tmp);\
     } while (0)
-#define __Pyx_DECREF_SET(r, v) do {                             \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_DECREF(tmp);                               \
+#define __Pyx_DECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_DECREF(tmp);\
     } while (0)
 #define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
 #define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
@@ -592,16 +652,28 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg
 #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
 #endif
 
+static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);
+
+typedef struct {
+    PyObject *type;
+    PyObject **method_name;
+    PyCFunction func;
+    PyObject *method;
+    int flag;
+} __Pyx_CachedCFunction;
+
+static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
 #if CYTHON_COMPILING_IN_CPYTHON
-static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
+#define __Pyx_CallUnboundCMethod0(cfunc, self)\
+    ((likely((cfunc)->func)) ?\
+        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
+         (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
+             ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) : __Pyx__CallUnboundCMethod0(cfunc, self)))) :\
+        __Pyx__CallUnboundCMethod0(cfunc, self))
+#else
+#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
 #endif
 
-static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
-
-static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);
-
-static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);
-
 static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
 
 static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
@@ -610,6 +682,29 @@ static CYTHON_INLINE int __Pyx_IterFinish(void);
 
 static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
 
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
+
+#if PY_MAJOR_VERSION >= 3
+#define __Pyx_PyObject_Ord(c)\
+    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
+#else
+#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
+#endif
+static long __Pyx__PyObject_Ord(PyObject* c);
+
+#define __Pyx_SetItemInt_ByteArray(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_SetItemInt_ByteArray_Fast(o, (Py_ssize_t)i, v, wraparound, boundscheck) :\
+    (PyErr_SetString(PyExc_IndexError, "bytearray index out of range"), -1))
+static CYTHON_INLINE int __Pyx_SetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, unsigned char v,
+                                                         int wraparound, int boundscheck);
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
+#endif
+
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
+
 #if CYTHON_COMPILING_IN_CPYTHON
 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
 #else
@@ -621,12 +716,32 @@ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
 
 static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
 
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
-    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
     const char* function_name);
 
-static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
-    const char *name, int exact);
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
+#endif
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
+    PyListObject* L = (PyListObject*) list;
+    Py_ssize_t len = Py_SIZE(list);
+    if (likely(L->allocated > len)) {
+        Py_INCREF(x);
+        PyList_SET_ITEM(list, len, x);
+        Py_SIZE(list) = len+1;
+        return 0;
+    }
+    return PyList_Append(list, x);
+}
+#else
+#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
+#endif
 
 #if CYTHON_COMPILING_IN_CPYTHON
 #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
@@ -645,25 +760,20 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr
 #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
 #endif
 
-static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
-static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
-
-#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
-    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
+#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
                __Pyx_GetItemInt_Generic(o, to_py_func(i))))
-#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
-#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
@@ -671,8 +781,128 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                      int is_list, int wraparound, int boundscheck);
 
+#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
+               __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
+static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
+static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
+                                               int is_list, int wraparound, int boundscheck);
+
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);
+
+#if PY_MAJOR_VERSION < 3
+#define __Pyx_PyString_Join __Pyx_PyBytes_Join
+#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
+#else
+#define __Pyx_PyString_Join PyUnicode_Join
+#define __Pyx_PyBaseString_Join PyUnicode_Join
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+    #if PY_MAJOR_VERSION < 3
+    #define __Pyx_PyBytes_Join _PyString_Join
+    #else
+    #define __Pyx_PyBytes_Join _PyBytes_Join
+    #endif
+#else
+static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values);
+#endif
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
+    PyListObject* L = (PyListObject*) list;
+    Py_ssize_t len = Py_SIZE(list);
+    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
+        Py_INCREF(x);
+        PyList_SET_ITEM(list, len, x);
+        Py_SIZE(list) = len+1;
+        return 0;
+    }
+    return PyList_Append(list, x);
+}
+#else
+#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
+#endif
+
+static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
+    const char *name, int exact);
+
+static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
+static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);
+
+static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
+
 static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
 
+#ifndef __PYX_FORCE_INIT_THREADS
+  #define __PYX_FORCE_INIT_THREADS 0
+#endif
+
+#include <string.h>
+
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
+
+#define __Pyx_CyFunction_USED 1
+#include <structmember.h>
+#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
+#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
+#define __Pyx_CYFUNCTION_CCLASS        0x04
+#define __Pyx_CyFunction_GetClosure(f)\
+    (((__pyx_CyFunctionObject *) (f))->func_closure)
+#define __Pyx_CyFunction_GetClassObj(f)\
+    (((__pyx_CyFunctionObject *) (f))->func_classobj)
+#define __Pyx_CyFunction_Defaults(type, f)\
+    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
+#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
+    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
+typedef struct {
+    PyCFunctionObject func;
+#if PY_VERSION_HEX < 0x030500A0
+    PyObject *func_weakreflist;
+#endif
+    PyObject *func_dict;
+    PyObject *func_name;
+    PyObject *func_qualname;
+    PyObject *func_doc;
+    PyObject *func_globals;
+    PyObject *func_code;
+    PyObject *func_closure;
+    PyObject *func_classobj;
+    void *defaults;
+    int defaults_pyobjects;
+    int flags;
+    PyObject *defaults_tuple;
+    PyObject *defaults_kwdict;
+    PyObject *(*defaults_getter)(PyObject *);
+    PyObject *func_annotations;
+} __pyx_CyFunctionObject;
+static PyTypeObject *__pyx_CyFunctionType = 0;
+#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
+    __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
+static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
+                                      int flags, PyObject* qualname,
+                                      PyObject *self,
+                                      PyObject *module, PyObject *globals,
+                                      PyObject* code);
+static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
+                                                         size_t size,
+                                                         int pyobjects);
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
+                                                            PyObject *tuple);
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
+                                                             PyObject *dict);
+static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
+                                                              PyObject *dict);
+static int __pyx_CyFunction_init(void);
+
+static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
+
+static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
+                                           PyObject *mkw, PyObject *modname, PyObject *doc);
+static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
+                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);
+
 typedef struct {
     int code_line;
     PyCodeObject* code_object;
@@ -694,10 +924,53 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
 
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
 
+static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *);
+
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
 
 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
 
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
+
+static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);
+
+typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *);
+typedef struct {
+    PyObject_HEAD
+    __pyx_coroutine_body_t body;
+    PyObject *closure;
+    PyObject *exc_type;
+    PyObject *exc_value;
+    PyObject *exc_traceback;
+    PyObject *gi_weakreflist;
+    PyObject *classobj;
+    PyObject *yieldfrom;
+    PyObject *gi_name;
+    PyObject *gi_qualname;
+    int resume_label;
+    char is_running;
+} __pyx_CoroutineObject;
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject *type, __pyx_coroutine_body_t body,
+                                                   PyObject *closure, PyObject *name, PyObject *qualname);
+static int __Pyx_Coroutine_clear(PyObject *self);
+#if 1 || PY_VERSION_HEX < 0x030300B0
+static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue);
+#else
+#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue)
+#endif
+
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);
+
+static int __Pyx_patch_abc(void);
+
+#define __Pyx_Generator_USED
+static PyTypeObject *__pyx_GeneratorType = 0;
+#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
+#define __Pyx_Generator_New(body, closure, name, qualname)\
+    __Pyx__Coroutine_New(__pyx_GeneratorType, body, closure, name, qualname)
+static PyObject *__Pyx_Generator_Next(PyObject *self);
+static int __pyx_Generator_init(void);
+
 static int __Pyx_check_binary_version(void);
 
 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
@@ -707,26 +980,19 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
 
 /* Module declarations from 'cutadapt._align' */
 static PyTypeObject *__pyx_ptype_8cutadapt_6_align_Aligner = 0;
+static PyTypeObject *__pyx_ptype_8cutadapt_6_align___pyx_scope_struct____str__ = 0;
+static PyTypeObject *__pyx_ptype_8cutadapt_6_align___pyx_scope_struct_1_genexpr = 0;
+static PyTypeObject *__pyx_ptype_8cutadapt_6_align___pyx_scope_struct_2_genexpr = 0;
 static PyObject *__pyx_v_8cutadapt_6_align_ACGT_TABLE = 0;
 static PyObject *__pyx_v_8cutadapt_6_align_IUPAC_TABLE = 0;
 #define __Pyx_MODULE_NAME "cutadapt._align"
 int __pyx_module_is_main_cutadapt___align = 0;
 
 /* Implementation of 'cutadapt._align' */
-static PyObject *__pyx_builtin_ord;
+static PyObject *__pyx_builtin_range;
+static PyObject *__pyx_builtin_zip;
 static PyObject *__pyx_builtin_ValueError;
 static PyObject *__pyx_builtin_MemoryError;
-static PyObject *__pyx_builtin_range;
-static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static int __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_degenerate, int __pyx_v_min_overlap); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_9reference___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_query); /* proto */
-static void __pyx_pf_8cutadapt_6_align_7Aligner_4__dealloc__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_degenerate, int __pyx_v_min_overlap); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ref, PyObject *__pyx_v_query, int __pyx_v_degenerate); /* proto */
-static PyObject *__pyx_tp_new_8cutadapt_6_align_Aligner(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
 static char __pyx_k_[] = "\000";
 static char __pyx_k_A[] = "A";
 static char __pyx_k_B[] = "B";
@@ -748,15 +1014,34 @@ static char __pyx_k_Y[] = "Y";
 static char __pyx_k_c[] = "c";
 static char __pyx_k_d[] = "d";
 static char __pyx_k_i[] = "i";
+static char __pyx_k_j[] = "j";
 static char __pyx_k_m[] = "m";
 static char __pyx_k_n[] = "n";
+static char __pyx_k_r[] = "r";
 static char __pyx_k_t[] = "t";
 static char __pyx_k_v[] = "v";
-static char __pyx_k_ord[] = "ord";
+static char __pyx_k__5[] = "  ";
+static char __pyx_k__6[] = "     ";
+static char __pyx_k__7[] = " ";
+static char __pyx_k__8[] = "\n";
+static char __pyx_k__19[] = "_";
+static char __pyx_k_doc[] = "__doc__";
 static char __pyx_k_ref[] = "ref";
+static char __pyx_k_row[] = "row";
+static char __pyx_k_str[] = "__str__";
+static char __pyx_k_zip[] = "zip";
+static char __pyx_k_0_2d[] = "{0:2d}";
+static char __pyx_k_args[] = "args";
+static char __pyx_k_cost[] = "cost";
+static char __pyx_k_init[] = "__init__";
+static char __pyx_k_join[] = "join";
 static char __pyx_k_main[] = "__main__";
+static char __pyx_k_rows[] = "_rows";
+static char __pyx_k_self[] = "self";
+static char __pyx_k_send[] = "send";
 static char __pyx_k_test[] = "__test__";
 static char __pyx_k_ascii[] = "ascii";
+static char __pyx_k_close[] = "close";
 static char __pyx_k_flags[] = "flags";
 static char __pyx_k_items[] = "items";
 static char __pyx_k_lower[] = "lower";
@@ -764,41 +1049,68 @@ static char __pyx_k_q_ptr[] = "q_ptr";
 static char __pyx_k_query[] = "query";
 static char __pyx_k_r_ptr[] = "r_ptr";
 static char __pyx_k_range[] = "range";
+static char __pyx_k_rjust[] = "rjust";
+static char __pyx_k_throw[] = "throw";
 static char __pyx_k_encode[] = "encode";
+static char __pyx_k_format[] = "format";
 static char __pyx_k_length[] = "length";
 static char __pyx_k_locate[] = "locate";
+static char __pyx_k_module[] = "__module__";
+static char __pyx_k_rows_2[] = "rows";
 static char __pyx_k_aligner[] = "aligner";
+static char __pyx_k_genexpr[] = "genexpr";
 static char __pyx_k_matches[] = "matches";
+static char __pyx_k_prepare[] = "__prepare__";
+static char __pyx_k_DPMatrix[] = "DPMatrix";
+static char __pyx_k_qualname[] = "__qualname__";
+static char __pyx_k_metaclass[] = "__metaclass__";
 static char __pyx_k_ref_bytes[] = "ref_bytes";
 static char __pyx_k_reference[] = "reference";
+static char __pyx_k_set_entry[] = "set_entry";
 static char __pyx_k_translate[] = "translate";
 static char __pyx_k_ValueError[] = "ValueError";
 static char __pyx_k_acgt_table[] = "_acgt_table";
-static char __pyx_k_degenerate[] = "degenerate";
 static char __pyx_k_MemoryError[] = "MemoryError";
 static char __pyx_k_iupac_table[] = "_iupac_table";
 static char __pyx_k_min_overlap[] = "min_overlap";
 static char __pyx_k_query_bytes[] = "query_bytes";
 static char __pyx_k_wildcard_ref[] = "wildcard_ref";
 static char __pyx_k_compare_ascii[] = "compare_ascii";
+static char __pyx_k_DPMatrix___str[] = "DPMatrix.__str__";
 static char __pyx_k_max_error_rate[] = "max_error_rate";
 static char __pyx_k_wildcard_query[] = "wildcard_query";
+static char __pyx_k_DPMatrix___init[] = "DPMatrix.__init__";
 static char __pyx_k_cutadapt__align[] = "cutadapt._align";
 static char __pyx_k_compare_prefixes[] = "compare_prefixes";
+static char __pyx_k_DPMatrix_set_entry[] = "DPMatrix.set_entry";
+static char __pyx_k_Matches_cost_0_mismatches_cost[] = "\n\t\tMatches cost 0, mismatches cost 1. Only insertion/deletion costs can be\n\t\tchanged.\n\t\t";
+static char __pyx_k_The_dynamic_programming_matrix[] = "\n\t\tThe dynamic programming matrix as a DPMatrix object. This attribute is\n\t\tusually None, unless debugging has been enabled with enable_debug().\n\t\t";
+static char __pyx_k_DPMatrix___str___locals_genexpr[] = "DPMatrix.__str__.<locals>.genexpr";
+static char __pyx_k_Insertion_deletion_cost_must_be[] = "Insertion/deletion cost must be at leat 1";
+static char __pyx_k_Representation_of_the_dynamic_p[] = "\n\tRepresentation of the dynamic-programming matrix.\n\n\tThis used only when debugging is enabled in the Aligner class since the\n\tmatrix is normally not stored in full.\n\n\tEntries in the matrix may be None, in which case that value was not\n\tcomputed.\n\t";
 static char __pyx_k_home_marcel_scm_cutadapt_cutada[] = "/home/marcel/scm/cutadapt/cutadapt/_align.pyx";
-static char __pyx_k_minimum_overlap_must_be_at_least[] = "minimum overlap must be at least 1";
+static char __pyx_k_Minimum_overlap_must_be_at_least[] = "Minimum overlap must be at least 1";
 static PyObject *__pyx_kp_b_;
+static PyObject *__pyx_kp_s_0_2d;
 static PyObject *__pyx_n_s_A;
 static PyObject *__pyx_n_s_B;
 static PyObject *__pyx_n_s_C;
 static PyObject *__pyx_n_s_D;
+static PyObject *__pyx_n_s_DPMatrix;
+static PyObject *__pyx_n_s_DPMatrix___init;
+static PyObject *__pyx_n_s_DPMatrix___str;
+static PyObject *__pyx_n_s_DPMatrix___str___locals_genexpr;
+static PyObject *__pyx_n_s_DPMatrix_set_entry;
 static PyObject *__pyx_n_s_G;
 static PyObject *__pyx_n_s_H;
+static PyObject *__pyx_kp_s_Insertion_deletion_cost_must_be;
 static PyObject *__pyx_n_s_K;
 static PyObject *__pyx_n_s_M;
 static PyObject *__pyx_n_s_MemoryError;
+static PyObject *__pyx_kp_s_Minimum_overlap_must_be_at_least;
 static PyObject *__pyx_n_s_N;
 static PyObject *__pyx_n_s_R;
+static PyObject *__pyx_kp_s_Representation_of_the_dynamic_p;
 static PyObject *__pyx_n_s_S;
 static PyObject *__pyx_n_s_T;
 static PyObject *__pyx_n_s_U;
@@ -807,21 +1119,34 @@ static PyObject *__pyx_n_s_ValueError;
 static PyObject *__pyx_n_s_W;
 static PyObject *__pyx_n_s_X;
 static PyObject *__pyx_n_s_Y;
+static PyObject *__pyx_n_s__19;
+static PyObject *__pyx_kp_s__5;
+static PyObject *__pyx_kp_s__6;
+static PyObject *__pyx_kp_s__7;
+static PyObject *__pyx_kp_s__8;
 static PyObject *__pyx_n_s_acgt_table;
 static PyObject *__pyx_n_s_aligner;
+static PyObject *__pyx_n_s_args;
 static PyObject *__pyx_n_s_ascii;
 static PyObject *__pyx_n_s_c;
+static PyObject *__pyx_n_s_close;
 static PyObject *__pyx_n_s_compare_ascii;
 static PyObject *__pyx_n_s_compare_prefixes;
+static PyObject *__pyx_n_s_cost;
 static PyObject *__pyx_n_s_cutadapt__align;
 static PyObject *__pyx_n_s_d;
-static PyObject *__pyx_n_s_degenerate;
+static PyObject *__pyx_n_s_doc;
 static PyObject *__pyx_n_s_encode;
 static PyObject *__pyx_n_s_flags;
+static PyObject *__pyx_n_s_format;
+static PyObject *__pyx_n_s_genexpr;
 static PyObject *__pyx_kp_s_home_marcel_scm_cutadapt_cutada;
 static PyObject *__pyx_n_s_i;
+static PyObject *__pyx_n_s_init;
 static PyObject *__pyx_n_s_items;
 static PyObject *__pyx_n_s_iupac_table;
+static PyObject *__pyx_n_s_j;
+static PyObject *__pyx_n_s_join;
 static PyObject *__pyx_n_s_length;
 static PyObject *__pyx_n_s_locate;
 static PyObject *__pyx_n_s_lower;
@@ -829,24 +1154,61 @@ static PyObject *__pyx_n_s_m;
 static PyObject *__pyx_n_s_main;
 static PyObject *__pyx_n_s_matches;
 static PyObject *__pyx_n_s_max_error_rate;
+static PyObject *__pyx_n_s_metaclass;
 static PyObject *__pyx_n_s_min_overlap;
-static PyObject *__pyx_kp_s_minimum_overlap_must_be_at_least;
+static PyObject *__pyx_n_s_module;
 static PyObject *__pyx_n_s_n;
-static PyObject *__pyx_n_s_ord;
+static PyObject *__pyx_n_s_prepare;
 static PyObject *__pyx_n_s_q_ptr;
+static PyObject *__pyx_n_s_qualname;
 static PyObject *__pyx_n_s_query;
 static PyObject *__pyx_n_s_query_bytes;
+static PyObject *__pyx_n_s_r;
 static PyObject *__pyx_n_s_r_ptr;
 static PyObject *__pyx_n_s_range;
 static PyObject *__pyx_n_s_ref;
 static PyObject *__pyx_n_s_ref_bytes;
 static PyObject *__pyx_n_s_reference;
+static PyObject *__pyx_n_s_rjust;
+static PyObject *__pyx_n_s_row;
+static PyObject *__pyx_n_s_rows;
+static PyObject *__pyx_n_s_rows_2;
+static PyObject *__pyx_n_s_self;
+static PyObject *__pyx_n_s_send;
+static PyObject *__pyx_n_s_set_entry;
+static PyObject *__pyx_n_s_str;
 static PyObject *__pyx_n_s_t;
 static PyObject *__pyx_n_s_test;
+static PyObject *__pyx_n_s_throw;
 static PyObject *__pyx_n_s_translate;
 static PyObject *__pyx_n_s_v;
 static PyObject *__pyx_n_s_wildcard_query;
 static PyObject *__pyx_n_s_wildcard_ref;
+static PyObject *__pyx_n_s_zip;
+static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_2set_entry(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, PyObject *__pyx_v_cost); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___genexpr(PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___3genexpr(PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_4__str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap_2__set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, int __pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_align_7Aligner_10indel_cost___set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_9reference___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_8dpmatrix___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2enable_debug(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_4locate(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_query); /* proto */
+static void __pyx_pf_8cutadapt_6_align_7Aligner_6__dealloc__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query, int __pyx_v_min_overlap); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ref, PyObject *__pyx_v_query, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query); /* proto */
+static PyObject *__pyx_tp_new_8cutadapt_6_align_Aligner(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct____str__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0};
 static PyObject *__pyx_int_0;
 static PyObject *__pyx_int_1;
 static PyObject *__pyx_int_2;
@@ -856,20 +1218,28 @@ static PyObject *__pyx_int_256;
 static PyObject *__pyx_tuple__2;
 static PyObject *__pyx_tuple__3;
 static PyObject *__pyx_tuple__4;
-static PyObject *__pyx_tuple__5;
-static PyObject *__pyx_tuple__6;
-static PyObject *__pyx_tuple__7;
-static PyObject *__pyx_tuple__8;
 static PyObject *__pyx_tuple__9;
+static PyObject *__pyx_tuple__10;
 static PyObject *__pyx_tuple__11;
+static PyObject *__pyx_tuple__12;
 static PyObject *__pyx_tuple__13;
+static PyObject *__pyx_tuple__14;
 static PyObject *__pyx_tuple__15;
-static PyObject *__pyx_codeobj__10;
-static PyObject *__pyx_codeobj__12;
-static PyObject *__pyx_codeobj__14;
+static PyObject *__pyx_tuple__17;
+static PyObject *__pyx_tuple__20;
+static PyObject *__pyx_tuple__22;
+static PyObject *__pyx_tuple__24;
+static PyObject *__pyx_tuple__26;
+static PyObject *__pyx_tuple__28;
 static PyObject *__pyx_codeobj__16;
+static PyObject *__pyx_codeobj__18;
+static PyObject *__pyx_codeobj__21;
+static PyObject *__pyx_codeobj__23;
+static PyObject *__pyx_codeobj__25;
+static PyObject *__pyx_codeobj__27;
+static PyObject *__pyx_codeobj__29;
 
-/* "cutadapt/_align.pyx":32
+/* "cutadapt/_align.pyx":24
  * 
  * 
  * def _acgt_table():             # <<<<<<<<<<<<<<
@@ -907,60 +1277,62 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
   PyObject *__pyx_t_6 = NULL;
   PyObject *__pyx_t_7 = NULL;
   PyObject *(*__pyx_t_8)(PyObject *);
+  unsigned char __pyx_t_9;
+  long __pyx_t_10;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_acgt_table", 0);
 
-  /* "cutadapt/_align.pyx":40
+  /* "cutadapt/_align.pyx":32
  * 	Lowercase versions are also translated, and U is treated the same as T.
  * 	"""
  * 	d = dict(A=1, C=2, G=4, T=8, U=8)             # <<<<<<<<<<<<<<
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_A, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_C, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_G, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_T, __pyx_int_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_U, __pyx_int_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_A, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_C, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_G, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_T, __pyx_int_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_U, __pyx_int_8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_d = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":41
+  /* "cutadapt/_align.pyx":33
  * 	"""
  * 	d = dict(A=1, C=2, G=4, T=8, U=8)
  * 	t = bytearray(b'\0') * 256             # <<<<<<<<<<<<<<
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  */
-  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyByteArray_Type))), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  if (!(likely(PyByteArray_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyByteArray_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_t = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":42
+  /* "cutadapt/_align.pyx":34
  * 	d = dict(A=1, C=2, G=4, T=8, U=8)
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():             # <<<<<<<<<<<<<<
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v
  */
-  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
     __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
     __pyx_t_4 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   for (;;) {
@@ -968,17 +1340,17 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
       if (likely(PyList_CheckExact(__pyx_t_1))) {
         if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         #endif
       } else {
         if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         #endif
       }
@@ -988,7 +1360,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
         PyObject* exc_type = PyErr_Occurred();
         if (exc_type) {
           if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -1004,7 +1376,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -1017,15 +1389,15 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
       __Pyx_INCREF(__pyx_t_5);
       __Pyx_INCREF(__pyx_t_6);
       #else
-      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       #endif
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     } else {
       Py_ssize_t index = -1;
-      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
@@ -1033,7 +1405,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
       __Pyx_GOTREF(__pyx_t_5);
       index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_6);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_8 = NULL;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       goto __pyx_L6_unpacking_done;
@@ -1041,7 +1413,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_8 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L6_unpacking_done:;
     }
     __Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_5);
@@ -1049,63 +1421,50 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
     __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6);
     __pyx_t_6 = 0;
 
-    /* "cutadapt/_align.pyx":43
+    /* "cutadapt/_align.pyx":35
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():
  * 		t[ord(c)] = v             # <<<<<<<<<<<<<<
  * 		t[ord(c.lower())] = v
  * 	return bytes(t)
  */
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_INCREF(__pyx_v_c);
-    __Pyx_GIVEREF(__pyx_v_c);
-    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_c);
-    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (unlikely(PyObject_SetItem(__pyx_v_t, __pyx_t_6, __pyx_v_v) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_9 = __Pyx_PyInt_As_unsigned_char(__pyx_v_v); if (unlikely((__pyx_t_9 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_Ord(__pyx_v_c); if (unlikely(__pyx_t_10 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(__Pyx_SetItemInt_ByteArray(__pyx_v_t, __pyx_t_10, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "cutadapt/_align.pyx":44
+    /* "cutadapt/_align.pyx":36
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v             # <<<<<<<<<<<<<<
  * 	return bytes(t)
  * 
  */
-    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_c, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_9 = __Pyx_PyInt_As_unsigned_char(__pyx_v_v); if (unlikely((__pyx_t_9 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_c, __pyx_n_s_lower); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
     __pyx_t_5 = NULL;
-    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
-      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
       if (likely(__pyx_t_5)) {
-        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
         __Pyx_INCREF(__pyx_t_5);
         __Pyx_INCREF(function);
-        __Pyx_DECREF_SET(__pyx_t_2, function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
       }
     }
     if (__pyx_t_5) {
-      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     } else {
-      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_GIVEREF(__pyx_t_6);
-    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
-    __pyx_t_6 = 0;
-    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (unlikely(PyObject_SetItem(__pyx_v_t, __pyx_t_6, __pyx_v_v) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_10 = __Pyx_PyObject_Ord(__pyx_t_2); if (unlikely(__pyx_t_10 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    if (unlikely(__Pyx_SetItemInt_ByteArray(__pyx_v_t, __pyx_t_10, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "cutadapt/_align.pyx":42
+    /* "cutadapt/_align.pyx":34
  * 	d = dict(A=1, C=2, G=4, T=8, U=8)
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():             # <<<<<<<<<<<<<<
@@ -1115,7 +1474,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":45
+  /* "cutadapt/_align.pyx":37
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v
  * 	return bytes(t)             # <<<<<<<<<<<<<<
@@ -1123,19 +1482,19 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
  * 
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_t);
   __Pyx_GIVEREF(__pyx_v_t);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
-  __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyBytes_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_r = __pyx_t_6;
-  __pyx_t_6 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":32
+  /* "cutadapt/_align.pyx":24
  * 
  * 
  * def _acgt_table():             # <<<<<<<<<<<<<<
@@ -1162,7 +1521,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align__acgt_table(CYTHON_UNUSED PyObject *
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":48
+/* "cutadapt/_align.pyx":40
  * 
  * 
  * def _iupac_table():             # <<<<<<<<<<<<<<
@@ -1204,12 +1563,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
   PyObject *__pyx_t_6 = NULL;
   PyObject *__pyx_t_7 = NULL;
   PyObject *(*__pyx_t_8)(PyObject *);
+  unsigned char __pyx_t_9;
+  long __pyx_t_10;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("_iupac_table", 0);
 
-  /* "cutadapt/_align.pyx":58
+  /* "cutadapt/_align.pyx":50
  * 	expression "x & y != 0".
  * 	"""
  * 	A = 1             # <<<<<<<<<<<<<<
@@ -1218,7 +1579,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
  */
   __pyx_v_A = 1;
 
-  /* "cutadapt/_align.pyx":59
+  /* "cutadapt/_align.pyx":51
  * 	"""
  * 	A = 1
  * 	C = 2             # <<<<<<<<<<<<<<
@@ -1227,7 +1588,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
  */
   __pyx_v_C = 2;
 
-  /* "cutadapt/_align.pyx":60
+  /* "cutadapt/_align.pyx":52
  * 	A = 1
  * 	C = 2
  * 	G = 4             # <<<<<<<<<<<<<<
@@ -1236,7 +1597,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
  */
   __pyx_v_G = 4;
 
-  /* "cutadapt/_align.pyx":61
+  /* "cutadapt/_align.pyx":53
  * 	C = 2
  * 	G = 4
  * 	T = 8             # <<<<<<<<<<<<<<
@@ -1245,243 +1606,243 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
  */
   __pyx_v_T = 8;
 
-  /* "cutadapt/_align.pyx":62
- * 	G = 4
+  /* "cutadapt/_align.pyx":55
  * 	T = 8
- * 	d = dict(             # <<<<<<<<<<<<<<
- * 		X=0,
+ * 	d = dict(
+ * 		X=0,             # <<<<<<<<<<<<<<
  * 		A=A,
+ * 		C=C,
  */
-  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_X, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_X, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_align.pyx":64
+  /* "cutadapt/_align.pyx":56
  * 	d = dict(
  * 		X=0,
  * 		A=A,             # <<<<<<<<<<<<<<
  * 		C=C,
  * 		G=G,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_A); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_A); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_A, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_A, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":65
+  /* "cutadapt/_align.pyx":57
  * 		X=0,
  * 		A=A,
  * 		C=C,             # <<<<<<<<<<<<<<
  * 		G=G,
  * 		T=T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_C); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_C); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_C, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_C, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":66
+  /* "cutadapt/_align.pyx":58
  * 		A=A,
  * 		C=C,
  * 		G=G,             # <<<<<<<<<<<<<<
  * 		T=T,
  * 		U=T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_G); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_G); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_G, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_G, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":67
+  /* "cutadapt/_align.pyx":59
  * 		C=C,
  * 		G=G,
  * 		T=T,             # <<<<<<<<<<<<<<
  * 		U=T,
  * 		R=A|G,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_T); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_T); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_T, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_T, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":68
+  /* "cutadapt/_align.pyx":60
  * 		G=G,
  * 		T=T,
  * 		U=T,             # <<<<<<<<<<<<<<
  * 		R=A|G,
  * 		Y=C|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_T); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_v_T); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_U, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_U, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":69
+  /* "cutadapt/_align.pyx":61
  * 		T=T,
  * 		U=T,
  * 		R=A|G,             # <<<<<<<<<<<<<<
  * 		Y=C|T,
  * 		S=G|C,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_G)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_G)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_R, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_R, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":70
+  /* "cutadapt/_align.pyx":62
  * 		U=T,
  * 		R=A|G,
  * 		Y=C|T,             # <<<<<<<<<<<<<<
  * 		S=G|C,
  * 		W=A|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_C | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_C | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_Y, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_Y, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":71
+  /* "cutadapt/_align.pyx":63
  * 		R=A|G,
  * 		Y=C|T,
  * 		S=G|C,             # <<<<<<<<<<<<<<
  * 		W=A|T,
  * 		K=G|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_G | __pyx_v_C)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_G | __pyx_v_C)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_S, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_S, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":72
+  /* "cutadapt/_align.pyx":64
  * 		Y=C|T,
  * 		S=G|C,
  * 		W=A|T,             # <<<<<<<<<<<<<<
  * 		K=G|T,
  * 		M=A|C,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_W, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_W, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":73
+  /* "cutadapt/_align.pyx":65
  * 		S=G|C,
  * 		W=A|T,
  * 		K=G|T,             # <<<<<<<<<<<<<<
  * 		M=A|C,
  * 		B=C|G|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_G | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_G | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_K, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_K, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":74
+  /* "cutadapt/_align.pyx":66
  * 		W=A|T,
  * 		K=G|T,
  * 		M=A|C,             # <<<<<<<<<<<<<<
  * 		B=C|G|T,
  * 		D=A|G|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_C)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_A | __pyx_v_C)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_M, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_M, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":75
+  /* "cutadapt/_align.pyx":67
  * 		K=G|T,
  * 		M=A|C,
  * 		B=C|G|T,             # <<<<<<<<<<<<<<
  * 		D=A|G|T,
  * 		H=A|C|T,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_C | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_C | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_B, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_B, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":76
+  /* "cutadapt/_align.pyx":68
  * 		M=A|C,
  * 		B=C|G|T,
  * 		D=A|G|T,             # <<<<<<<<<<<<<<
  * 		H=A|C|T,
  * 		V=A|C|G,
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_D, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_D, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":77
+  /* "cutadapt/_align.pyx":69
  * 		B=C|G|T,
  * 		D=A|G|T,
  * 		H=A|C|T,             # <<<<<<<<<<<<<<
  * 		V=A|C|G,
  * 		N=A|C|G|T
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_C) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_C) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_H, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_H, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":78
+  /* "cutadapt/_align.pyx":70
  * 		D=A|G|T,
  * 		H=A|C|T,
  * 		V=A|C|G,             # <<<<<<<<<<<<<<
  * 		N=A|C|G|T
  * 	)
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_C) | __pyx_v_G)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_A | __pyx_v_C) | __pyx_v_G)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_V, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_V, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":79
+  /* "cutadapt/_align.pyx":71
  * 		H=A|C|T,
  * 		V=A|C|G,
  * 		N=A|C|G|T             # <<<<<<<<<<<<<<
  * 	)
  * 	t = bytearray(b'\0') * 256
  */
-  __pyx_t_2 = __Pyx_PyInt_From_long((((__pyx_v_A | __pyx_v_C) | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_long((((__pyx_v_A | __pyx_v_C) | __pyx_v_G) | __pyx_v_T)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_N, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_N, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_v_d = ((PyObject*)__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":81
+  /* "cutadapt/_align.pyx":73
  * 		N=A|C|G|T
  * 	)
  * 	t = bytearray(b'\0') * 256             # <<<<<<<<<<<<<<
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  */
-  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyByteArray_Type))), __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyNumber_Multiply(__pyx_t_1, __pyx_int_256); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  if (!(likely(PyByteArray_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyByteArray_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_t = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":82
+  /* "cutadapt/_align.pyx":74
  * 	)
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():             # <<<<<<<<<<<<<<
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v
  */
-  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
     __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
     __pyx_t_4 = NULL;
   } else {
-    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   for (;;) {
@@ -1489,17 +1850,17 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
       if (likely(PyList_CheckExact(__pyx_t_1))) {
         if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         #endif
       } else {
         if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_2);
         #endif
       }
@@ -1509,7 +1870,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
         PyObject* exc_type = PyErr_Occurred();
         if (exc_type) {
           if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
@@ -1525,7 +1886,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
       if (unlikely(size != 2)) {
         if (size > 2) __Pyx_RaiseTooManyValuesError(2);
         else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
       #if CYTHON_COMPILING_IN_CPYTHON
       if (likely(PyTuple_CheckExact(sequence))) {
@@ -1538,15 +1899,15 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
       __Pyx_INCREF(__pyx_t_5);
       __Pyx_INCREF(__pyx_t_6);
       #else
-      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
-      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       #endif
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     } else {
       Py_ssize_t index = -1;
-      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_7);
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
@@ -1554,7 +1915,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
       __Pyx_GOTREF(__pyx_t_5);
       index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
       __Pyx_GOTREF(__pyx_t_6);
-      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_8 = NULL;
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       goto __pyx_L6_unpacking_done;
@@ -1562,7 +1923,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
       __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
       __pyx_t_8 = NULL;
       if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_L6_unpacking_done:;
     }
     __Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_5);
@@ -1570,63 +1931,50 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
     __Pyx_XDECREF_SET(__pyx_v_v, __pyx_t_6);
     __pyx_t_6 = 0;
 
-    /* "cutadapt/_align.pyx":83
+    /* "cutadapt/_align.pyx":75
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():
  * 		t[ord(c)] = v             # <<<<<<<<<<<<<<
  * 		t[ord(c.lower())] = v
  * 	return bytes(t)
  */
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_INCREF(__pyx_v_c);
-    __Pyx_GIVEREF(__pyx_v_c);
-    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_c);
-    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (unlikely(PyObject_SetItem(__pyx_v_t, __pyx_t_6, __pyx_v_v) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_9 = __Pyx_PyInt_As_unsigned_char(__pyx_v_v); if (unlikely((__pyx_t_9 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_Ord(__pyx_v_c); if (unlikely(__pyx_t_10 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (unlikely(__Pyx_SetItemInt_ByteArray(__pyx_v_t, __pyx_t_10, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "cutadapt/_align.pyx":84
+    /* "cutadapt/_align.pyx":76
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v             # <<<<<<<<<<<<<<
  * 	return bytes(t)
  * 
  */
-    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_c, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_9 = __Pyx_PyInt_As_unsigned_char(__pyx_v_v); if (unlikely((__pyx_t_9 == (unsigned char)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_c, __pyx_n_s_lower); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
     __pyx_t_5 = NULL;
-    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
-      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
+    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
+      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
       if (likely(__pyx_t_5)) {
-        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
         __Pyx_INCREF(__pyx_t_5);
         __Pyx_INCREF(function);
-        __Pyx_DECREF_SET(__pyx_t_2, function);
+        __Pyx_DECREF_SET(__pyx_t_6, function);
       }
     }
     if (__pyx_t_5) {
-      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     } else {
-      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_GIVEREF(__pyx_t_6);
-    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
-    __pyx_t_6 = 0;
-    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (unlikely(PyObject_SetItem(__pyx_v_t, __pyx_t_6, __pyx_v_v) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_10 = __Pyx_PyObject_Ord(__pyx_t_2); if (unlikely(__pyx_t_10 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    if (unlikely(__Pyx_SetItemInt_ByteArray(__pyx_v_t, __pyx_t_10, __pyx_t_9, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "cutadapt/_align.pyx":82
+    /* "cutadapt/_align.pyx":74
  * 	)
  * 	t = bytearray(b'\0') * 256
  * 	for c, v in d.items():             # <<<<<<<<<<<<<<
@@ -1636,7 +1984,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
   }
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":85
+  /* "cutadapt/_align.pyx":77
  * 		t[ord(c)] = v
  * 		t[ord(c.lower())] = v
  * 	return bytes(t)             # <<<<<<<<<<<<<<
@@ -1644,19 +1992,19 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
  * 
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__pyx_v_t);
   __Pyx_GIVEREF(__pyx_v_t);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
-  __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_6);
+  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyBytes_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-  __pyx_r = __pyx_t_6;
-  __pyx_t_6 = 0;
+  __pyx_r = __pyx_t_2;
+  __pyx_t_2 = 0;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":48
+  /* "cutadapt/_align.pyx":40
  * 
  * 
  * def _iupac_table():             # <<<<<<<<<<<<<<
@@ -1683,37 +2031,34 @@ static PyObject *__pyx_pf_8cutadapt_6_align_2_iupac_table(CYTHON_UNUSED PyObject
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":163
- * 	cdef bytes _reference
- * 
- * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 		self.max_error_rate = max_error_rate
- * 		self.flags = flags
+/* "cutadapt/_align.pyx":94
+ * 	computed.
+ * 	"""
+ * 	def __init__(self, reference, query):             # <<<<<<<<<<<<<<
+ * 		m = len(reference)
+ * 		n = len(query)
  */
 
 /* Python wrapper */
-static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_8cutadapt_6_align_8DPMatrix_1__init__ = {"__init__", (PyCFunction)__pyx_pw_8cutadapt_6_align_8DPMatrix_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_self = 0;
   PyObject *__pyx_v_reference = 0;
-  double __pyx_v_max_error_rate;
-  int __pyx_v_flags;
-  int __pyx_v_degenerate;
-  int __pyx_v_min_overlap;
+  PyObject *__pyx_v_query = 0;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
-  int __pyx_r;
+  PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_max_error_rate,&__pyx_n_s_flags,&__pyx_n_s_degenerate,&__pyx_n_s_min_overlap,0};
-    PyObject* values[5] = {0,0,0,0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_reference,&__pyx_n_s_query,0};
+    PyObject* values[3] = {0,0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
-        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
-        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
@@ -1723,12 +2068,1030 @@ static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self
       kw_args = PyDict_Size(__pyx_kwds);
       switch (pos_args) {
         case  0:
-        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference)) != 0)) kw_args--;
+        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
         else goto __pyx_L5_argtuple_error;
         case  1:
-        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_error_rate)) != 0)) kw_args--;
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+        case  2:
+        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+    }
+    __pyx_v_self = values[0];
+    __pyx_v_reference = values[1];
+    __pyx_v_query = values[2];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_8cutadapt_6_align_8DPMatrix___init__(__pyx_self, __pyx_v_self, __pyx_v_reference, __pyx_v_query);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query) {
+  PyObject *__pyx_v_m = NULL;
+  PyObject *__pyx_v_n = NULL;
+  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  Py_ssize_t __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  PyObject *__pyx_t_4 = NULL;
+  PyObject *(*__pyx_t_5)(PyObject *);
+  PyObject *__pyx_t_6 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__init__", 0);
+
+  /* "cutadapt/_align.pyx":95
+ * 	"""
+ * 	def __init__(self, reference, query):
+ * 		m = len(reference)             # <<<<<<<<<<<<<<
+ * 		n = len(query)
+ * 		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_m = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":96
+ * 	def __init__(self, reference, query):
+ * 		m = len(reference)
+ * 		n = len(query)             # <<<<<<<<<<<<<<
+ * 		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]
+ * 		self.reference = reference
+ */
+  __pyx_t_1 = PyObject_Length(__pyx_v_query); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_v_n = __pyx_t_2;
+  __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":97
+ * 		m = len(reference)
+ * 		n = len(query)
+ * 		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]             # <<<<<<<<<<<<<<
+ * 		self.reference = reference
+ * 		self.query = query
+ */
+  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_m, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_4);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
+  __pyx_t_3 = 0;
+  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
+    __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0;
+    __pyx_t_5 = NULL;
+  } else {
+    __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_4);
+    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  for (;;) {
+    if (likely(!__pyx_t_5)) {
+      if (likely(PyList_CheckExact(__pyx_t_4))) {
+        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      } else {
+        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_3);
+        #endif
+      }
+    } else {
+      __pyx_t_3 = __pyx_t_5(__pyx_t_4);
+      if (unlikely(!__pyx_t_3)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_3);
+    }
+    __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_3);
+    __pyx_t_3 = 0;
+    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_n, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_INCREF(Py_None);
+    __Pyx_GIVEREF(Py_None);
+    PyList_SET_ITEM(__pyx_t_6, 0, Py_None);
+    { PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_temp)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_temp);
+      __Pyx_DECREF(__pyx_t_6);
+      __pyx_t_6 = __pyx_temp;
+    }
+    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+  }
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_rows, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":98
+ * 		n = len(query)
+ * 		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]
+ * 		self.reference = reference             # <<<<<<<<<<<<<<
+ * 		self.query = query
+ * 
+ */
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_reference, __pyx_v_reference) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":99
+ * 		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]
+ * 		self.reference = reference
+ * 		self.query = query             # <<<<<<<<<<<<<<
+ * 
+ * 	def set_entry(self, int i, int j, cost):
+ */
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_query, __pyx_v_query) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":94
+ * 	computed.
+ * 	"""
+ * 	def __init__(self, reference, query):             # <<<<<<<<<<<<<<
+ * 		m = len(reference)
+ * 		n = len(query)
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_m);
+  __Pyx_XDECREF(__pyx_v_n);
+  __Pyx_XDECREF(__pyx_v__);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":101
+ * 		self.query = query
+ * 
+ * 	def set_entry(self, int i, int j, cost):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Set an entry in the dynamic programming matrix.
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_3set_entry(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static char __pyx_doc_8cutadapt_6_align_8DPMatrix_2set_entry[] = "\n\t\tSet an entry in the dynamic programming matrix.\n\t\t";
+static PyMethodDef __pyx_mdef_8cutadapt_6_align_8DPMatrix_3set_entry = {"set_entry", (PyCFunction)__pyx_pw_8cutadapt_6_align_8DPMatrix_3set_entry, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8cutadapt_6_align_8DPMatrix_2set_entry};
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_3set_entry(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_self = 0;
+  int __pyx_v_i;
+  int __pyx_v_j;
+  PyObject *__pyx_v_cost = 0;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("set_entry (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_i,&__pyx_n_s_j,&__pyx_n_s_cost,0};
+    PyObject* values[4] = {0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        case  1:
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_i)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_entry", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+        case  2:
+        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_j)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_entry", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+        case  3:
+        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_cost)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("set_entry", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        }
+      }
+      if (unlikely(kw_args > 0)) {
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_entry") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      }
+    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
+      goto __pyx_L5_argtuple_error;
+    } else {
+      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+    }
+    __pyx_v_self = values[0];
+    __pyx_v_i = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_j = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_j == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_cost = values[3];
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L5_argtuple_error:;
+  __Pyx_RaiseArgtupleInvalid("set_entry", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.set_entry", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return NULL;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_8cutadapt_6_align_8DPMatrix_2set_entry(__pyx_self, __pyx_v_self, __pyx_v_i, __pyx_v_j, __pyx_v_cost);
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_2set_entry(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, PyObject *__pyx_v_cost) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("set_entry", 0);
+
+  /* "cutadapt/_align.pyx":105
+ * 		Set an entry in the dynamic programming matrix.
+ * 		"""
+ * 		self._rows[i][j] = cost             # <<<<<<<<<<<<<<
+ * 
+ * 	def __str__(self):
+ */
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_rows); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (unlikely(__Pyx_SetItemInt(__pyx_t_2, __pyx_v_j, __pyx_v_cost, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":101
+ * 		self.query = query
+ * 
+ * 	def set_entry(self, int i, int j, cost):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Set an entry in the dynamic programming matrix.
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.set_entry", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
+ * 
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_5__str__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
+static char __pyx_doc_8cutadapt_6_align_8DPMatrix_4__str__[] = "\n\t\tReturn a representation of the matrix as a string.\n\t\t";
+static PyMethodDef __pyx_mdef_8cutadapt_6_align_8DPMatrix_5__str__ = {"__str__", (PyCFunction)__pyx_pw_8cutadapt_6_align_8DPMatrix_5__str__, METH_O, __pyx_doc_8cutadapt_6_align_8DPMatrix_4__str__};
+static PyObject *__pyx_pw_8cutadapt_6_align_8DPMatrix_5__str__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_align_8DPMatrix_4__str__(__pyx_self, ((PyObject *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+
+/* "cutadapt/_align.pyx":111
+ * 		Return a representation of the matrix as a string.
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]             # <<<<<<<<<<<<<<
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ */
+
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___genexpr(PyObject *__pyx_self) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  __pyx_cur_scope = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_1_genexpr(__pyx_ptype_8cutadapt_6_align___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *) __pyx_self;
+  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_DPMatrix___str___locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  Py_ssize_t __pyx_t_3;
+  PyObject *(*__pyx_t_4)(PyObject *);
+  PyObject *__pyx_t_5 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("None", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_yield;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self, __pyx_n_s_query); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
+    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
+    __pyx_t_4 = NULL;
+  } else {
+    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  for (;;) {
+    if (likely(!__pyx_t_4)) {
+      if (likely(PyList_CheckExact(__pyx_t_2))) {
+        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_1);
+        #endif
+      } else {
+        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_1);
+        #endif
+      }
+    } else {
+      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
+      if (unlikely(!__pyx_t_1)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_1);
+    }
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_c);
+    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_c, __pyx_t_1);
+    __Pyx_GIVEREF(__pyx_t_1);
+    __pyx_t_1 = 0;
+    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_c, __pyx_n_s_rjust); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __pyx_r = __pyx_t_5;
+    __pyx_t_5 = 0;
+    __Pyx_XGIVEREF(__pyx_t_2);
+    __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
+    __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
+    __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    /* return from generator, yielding value */
+    __pyx_generator->resume_label = 1;
+    return __pyx_r;
+    __pyx_L6_resume_from_yield:;
+    __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
+    __pyx_cur_scope->__pyx_t_0 = 0;
+    __Pyx_XGOTREF(__pyx_t_2);
+    __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
+    __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* function exit code */
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_5);
+  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+static PyObject *__pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___5generator1(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+
+/* "cutadapt/_align.pyx":113
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)             # <<<<<<<<<<<<<<
+ * 			rows.append(r)
+ * 		return '\n'.join(rows)
+ */
+
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___3genexpr(PyObject *__pyx_self) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *__pyx_cur_scope;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("genexpr", 0);
+  __pyx_cur_scope = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_2_genexpr(__pyx_ptype_8cutadapt_6_align___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *) __pyx_self;
+  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
+  {
+    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___5generator1, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_DPMatrix___str___locals_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_DECREF(__pyx_cur_scope);
+    __Pyx_RefNannyFinishContext();
+    return (PyObject *) gen;
+  }
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_gb_8cutadapt_6_align_8DPMatrix_7__str___5generator1(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+{
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)__pyx_generator->closure);
+  PyObject *__pyx_r = NULL;
+  PyObject *__pyx_t_1 = NULL;
+  Py_ssize_t __pyx_t_2;
+  PyObject *(*__pyx_t_3)(PyObject *);
+  PyObject *__pyx_t_4 = NULL;
+  int __pyx_t_5;
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *__pyx_t_8 = NULL;
+  PyObject *__pyx_t_9 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("None", 0);
+  switch (__pyx_generator->resume_label) {
+    case 0: goto __pyx_L3_first_run;
+    case 1: goto __pyx_L6_resume_from_yield;
+    default: /* CPython raises the right error here */
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __pyx_L3_first_run:;
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_row)) { __Pyx_RaiseClosureNameError("row"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_row)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_row)) {
+    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_row; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
+    __pyx_t_3 = NULL;
+  } else {
+    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_row); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  for (;;) {
+    if (likely(!__pyx_t_3)) {
+      if (likely(PyList_CheckExact(__pyx_t_1))) {
+        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      } else {
+        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_4);
+        #endif
+      }
+    } else {
+      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
+      if (unlikely(!__pyx_t_4)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_4);
+    }
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_v);
+    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_v, __pyx_t_4);
+    __Pyx_GIVEREF(__pyx_t_4);
+    __pyx_t_4 = 0;
+    __pyx_t_5 = (__pyx_cur_scope->__pyx_v_v == Py_None);
+    if ((__pyx_t_5 != 0)) {
+      __Pyx_INCREF(__pyx_kp_s__5);
+      __pyx_t_4 = __pyx_kp_s__5;
+    } else {
+      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_0_2d, __pyx_n_s_format); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      __pyx_t_8 = NULL;
+      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
+        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
+        if (likely(__pyx_t_8)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
+          __Pyx_INCREF(__pyx_t_8);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_7, function);
+        }
+      }
+      if (!__pyx_t_8) {
+        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_cur_scope->__pyx_v_v); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_6);
+      } else {
+        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_9);
+        __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
+        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_v);
+        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_v);
+        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_cur_scope->__pyx_v_v);
+        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_6);
+        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      }
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __pyx_t_4 = __pyx_t_6;
+      __pyx_t_6 = 0;
+    }
+    __pyx_r = __pyx_t_4;
+    __pyx_t_4 = 0;
+    __Pyx_XGIVEREF(__pyx_t_1);
+    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
+    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
+    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
+    __Pyx_XGIVEREF(__pyx_r);
+    __Pyx_RefNannyFinishContext();
+    /* return from generator, yielding value */
+    __pyx_generator->resume_label = 1;
+    return __pyx_r;
+    __pyx_L6_resume_from_yield:;
+    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
+    __pyx_cur_scope->__pyx_t_0 = 0;
+    __Pyx_XGOTREF(__pyx_t_1);
+    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
+    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
+    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* function exit code */
+  PyErr_SetNone(PyExc_StopIteration);
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_4);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
+  __pyx_generator->resume_label = -1;
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
+ * 
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
+ */
+
+static PyObject *__pyx_pf_8cutadapt_6_align_8DPMatrix_4__str__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *__pyx_cur_scope;
+  PyObject *__pyx_v_rows = NULL;
+  PyObject *__pyx_v_c = NULL;
+  PyObject *__pyx_v_r = NULL;
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  PyObject *__pyx_t_2 = NULL;
+  PyObject *__pyx_t_3 = NULL;
+  Py_ssize_t __pyx_t_4;
+  PyObject *(*__pyx_t_5)(PyObject *);
+  PyObject *__pyx_t_6 = NULL;
+  PyObject *__pyx_t_7 = NULL;
+  PyObject *(*__pyx_t_8)(PyObject *);
+  int __pyx_t_9;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__str__", 0);
+  __pyx_cur_scope = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct____str__(__pyx_ptype_8cutadapt_6_align___pyx_scope_struct____str__, __pyx_empty_tuple, NULL);
+  if (unlikely(!__pyx_cur_scope)) {
+    __Pyx_RefNannyFinishContext();
+    return NULL;
+  }
+  __Pyx_GOTREF(__pyx_cur_scope);
+  __pyx_cur_scope->__pyx_v_self = __pyx_v_self;
+  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
+  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
+
+  /* "cutadapt/_align.pyx":111
+ * 		Return a representation of the matrix as a string.
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]             # <<<<<<<<<<<<<<
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ */
+  __pyx_t_1 = __pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  __pyx_t_1 = PyNumber_Add(__pyx_kp_s__6, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+  __pyx_t_1 = 0;
+  __pyx_v_rows = ((PyObject*)__pyx_t_2);
+  __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":112
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+ * 		for c, row in zip(' ' + self.reference, self._rows):             # <<<<<<<<<<<<<<
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ * 			rows.append(r)
+ */
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_reference); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_1 = PyNumber_Add(__pyx_kp_s__7, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_rows); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+  __pyx_t_1 = 0;
+  __pyx_t_2 = 0;
+  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
+    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
+    __pyx_t_5 = NULL;
+  } else {
+    __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  }
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  for (;;) {
+    if (likely(!__pyx_t_5)) {
+      if (likely(PyList_CheckExact(__pyx_t_3))) {
+        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_2);
+        #endif
+      } else {
+        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
+        #if CYTHON_COMPILING_IN_CPYTHON
+        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        #else
+        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_2);
+        #endif
+      }
+    } else {
+      __pyx_t_2 = __pyx_t_5(__pyx_t_3);
+      if (unlikely(!__pyx_t_2)) {
+        PyObject* exc_type = PyErr_Occurred();
+        if (exc_type) {
+          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        }
+        break;
+      }
+      __Pyx_GOTREF(__pyx_t_2);
+    }
+    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
+      PyObject* sequence = __pyx_t_2;
+      #if CYTHON_COMPILING_IN_CPYTHON
+      Py_ssize_t size = Py_SIZE(sequence);
+      #else
+      Py_ssize_t size = PySequence_Size(sequence);
+      #endif
+      if (unlikely(size != 2)) {
+        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      }
+      #if CYTHON_COMPILING_IN_CPYTHON
+      if (likely(PyTuple_CheckExact(sequence))) {
+        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
+        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
+      } else {
+        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
+        __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
+      }
+      __Pyx_INCREF(__pyx_t_1);
+      __Pyx_INCREF(__pyx_t_6);
+      #else
+      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_1);
+      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_6);
+      #endif
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    } else {
+      Py_ssize_t index = -1;
+      __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_7);
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
+      index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
+      __Pyx_GOTREF(__pyx_t_1);
+      index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
+      __Pyx_GOTREF(__pyx_t_6);
+      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = NULL;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      goto __pyx_L6_unpacking_done;
+      __pyx_L5_unpacking_failed:;
+      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+      __pyx_t_8 = NULL;
+      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_L6_unpacking_done:;
+    }
+    __Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_1);
+    __pyx_t_1 = 0;
+    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_row);
+    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_row, __pyx_t_6);
+    __Pyx_GIVEREF(__pyx_t_6);
+    __pyx_t_6 = 0;
+
+    /* "cutadapt/_align.pyx":113
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)             # <<<<<<<<<<<<<<
+ * 			rows.append(r)
+ * 		return '\n'.join(rows)
+ */
+    __pyx_t_2 = PyNumber_Add(__pyx_v_c, __pyx_kp_s__7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_6 = __pyx_pf_8cutadapt_6_align_8DPMatrix_7__str___3genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
+    __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+    __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_6);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_6);
+    __pyx_t_6 = 0;
+
+    /* "cutadapt/_align.pyx":114
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ * 			rows.append(r)             # <<<<<<<<<<<<<<
+ * 		return '\n'.join(rows)
+ * 
+ */
+    __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_rows, __pyx_v_r); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_align.pyx":112
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+ * 		for c, row in zip(' ' + self.reference, self._rows):             # <<<<<<<<<<<<<<
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ * 			rows.append(r)
+ */
+  }
+  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+  /* "cutadapt/_align.pyx":115
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+ * 			rows.append(r)
+ * 		return '\n'.join(rows)             # <<<<<<<<<<<<<<
+ * 
+ * 
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__8, __pyx_v_rows); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_r = __pyx_t_3;
+  __pyx_t_3 = 0;
+  goto __pyx_L0;
+
+  /* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
+ * 
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_6);
+  __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_AddTraceback("cutadapt._align.DPMatrix.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_rows);
+  __Pyx_XDECREF(__pyx_v_c);
+  __Pyx_XDECREF(__pyx_v_r);
+  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":194
+ * 	cdef str str_reference
+ * 
+ * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
+ * 		self.max_error_rate = max_error_rate
+ * 		self.flags = flags
+ */
+
+/* Python wrapper */
+static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+  PyObject *__pyx_v_reference = 0;
+  double __pyx_v_max_error_rate;
+  int __pyx_v_flags;
+  int __pyx_v_wildcard_ref;
+  int __pyx_v_wildcard_query;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+  {
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_max_error_rate,&__pyx_n_s_flags,&__pyx_n_s_wildcard_ref,&__pyx_n_s_wildcard_query,0};
+    PyObject* values[5] = {0,0,0,0,0};
+    if (unlikely(__pyx_kwds)) {
+      Py_ssize_t kw_args;
+      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+      switch (pos_args) {
+        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+        case  0: break;
+        default: goto __pyx_L5_argtuple_error;
+      }
+      kw_args = PyDict_Size(__pyx_kwds);
+      switch (pos_args) {
+        case  0:
+        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference)) != 0)) kw_args--;
+        else goto __pyx_L5_argtuple_error;
+        case  1:
+        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_error_rate)) != 0)) kw_args--;
+        else {
+          __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (kw_args > 0) {
@@ -1737,17 +3100,17 @@ static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self
         }
         case  3:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_degenerate);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_ref);
           if (value) { values[3] = value; kw_args--; }
         }
         case  4:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_min_overlap);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_query);
           if (value) { values[4] = value; kw_args--; }
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -1761,33 +3124,33 @@ static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self
       }
     }
     __pyx_v_reference = ((PyObject*)values[0]);
-    __pyx_v_max_error_rate = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_max_error_rate == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_max_error_rate = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_max_error_rate == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     if (values[2]) {
-      __pyx_v_flags = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_flags = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_flags = ((int)15);
     }
     if (values[3]) {
-      __pyx_v_degenerate = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_degenerate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_wildcard_ref = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_wildcard_ref == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
-      __pyx_v_degenerate = ((int)0);
+      __pyx_v_wildcard_ref = ((int)0);
     }
     if (values[4]) {
-      __pyx_v_min_overlap = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_min_overlap == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_wildcard_query = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_wildcard_query == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
-      __pyx_v_min_overlap = ((int)1);
+      __pyx_v_wildcard_query = ((int)0);
     }
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("cutadapt._align.Aligner.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return -1;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), __pyx_v_reference, __pyx_v_max_error_rate, __pyx_v_flags, __pyx_v_degenerate, __pyx_v_min_overlap);
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), __pyx_v_reference, __pyx_v_max_error_rate, __pyx_v_flags, __pyx_v_wildcard_ref, __pyx_v_wildcard_query);
 
   /* function exit code */
   goto __pyx_L0;
@@ -1798,115 +3161,415 @@ static int __pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(PyObject *__pyx_v_self
   return __pyx_r;
 }
 
-static int __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_degenerate, int __pyx_v_min_overlap) {
+static int __pyx_pf_8cutadapt_6_align_7Aligner___cinit__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_reference, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  PyObject *__pyx_t_2 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__cinit__", 0);
 
-  /* "cutadapt/_align.pyx":164
+  /* "cutadapt/_align.pyx":195
  * 
- * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
+ * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False):
  * 		self.max_error_rate = max_error_rate             # <<<<<<<<<<<<<<
  * 		self.flags = flags
- * 		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
+ * 		self.wildcard_ref = wildcard_ref
  */
   __pyx_v_self->max_error_rate = __pyx_v_max_error_rate;
 
-  /* "cutadapt/_align.pyx":165
- * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
+  /* "cutadapt/_align.pyx":196
+ * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False):
  * 		self.max_error_rate = max_error_rate
  * 		self.flags = flags             # <<<<<<<<<<<<<<
- * 		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
- * 		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
+ * 		self.wildcard_ref = wildcard_ref
+ * 		self.wildcard_query = wildcard_query
  */
   __pyx_v_self->flags = __pyx_v_flags;
 
-  /* "cutadapt/_align.pyx":166
+  /* "cutadapt/_align.pyx":197
  * 		self.max_error_rate = max_error_rate
  * 		self.flags = flags
- * 		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1             # <<<<<<<<<<<<<<
- * 		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
+ * 		self.wildcard_ref = wildcard_ref             # <<<<<<<<<<<<<<
+ * 		self.wildcard_query = wildcard_query
+ * 		self.str_reference = reference
+ */
+  __pyx_v_self->wildcard_ref = __pyx_v_wildcard_ref;
+
+  /* "cutadapt/_align.pyx":198
+ * 		self.flags = flags
+ * 		self.wildcard_ref = wildcard_ref
+ * 		self.wildcard_query = wildcard_query             # <<<<<<<<<<<<<<
+ * 		self.str_reference = reference
+ * 		self.reference = reference
+ */
+  __pyx_v_self->wildcard_query = __pyx_v_wildcard_query;
+
+  /* "cutadapt/_align.pyx":199
+ * 		self.wildcard_ref = wildcard_ref
+ * 		self.wildcard_query = wildcard_query
+ * 		self.str_reference = reference             # <<<<<<<<<<<<<<
+ * 		self.reference = reference
+ * 		self._min_overlap = 1
+ */
+  __Pyx_INCREF(__pyx_v_reference);
+  __Pyx_GIVEREF(__pyx_v_reference);
+  __Pyx_GOTREF(__pyx_v_self->str_reference);
+  __Pyx_DECREF(__pyx_v_self->str_reference);
+  __pyx_v_self->str_reference = __pyx_v_reference;
+
+  /* "cutadapt/_align.pyx":200
+ * 		self.wildcard_query = wildcard_query
+ * 		self.str_reference = reference
+ * 		self.reference = reference             # <<<<<<<<<<<<<<
+ * 		self._min_overlap = 1
+ * 		self.debug = False
+ */
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference, __pyx_v_reference) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":201
+ * 		self.str_reference = reference
  * 		self.reference = reference
+ * 		self._min_overlap = 1             # <<<<<<<<<<<<<<
+ * 		self.debug = False
+ * 		self._dpmatrix = None
+ */
+  __pyx_v_self->_min_overlap = 1;
+
+  /* "cutadapt/_align.pyx":202
+ * 		self.reference = reference
+ * 		self._min_overlap = 1
+ * 		self.debug = False             # <<<<<<<<<<<<<<
+ * 		self._dpmatrix = None
+ * 		self._insertion_cost = 1
+ */
+  __pyx_v_self->debug = 0;
+
+  /* "cutadapt/_align.pyx":203
+ * 		self._min_overlap = 1
+ * 		self.debug = False
+ * 		self._dpmatrix = None             # <<<<<<<<<<<<<<
+ * 		self._insertion_cost = 1
+ * 		self._deletion_cost = 1
+ */
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->_dpmatrix);
+  __Pyx_DECREF(__pyx_v_self->_dpmatrix);
+  __pyx_v_self->_dpmatrix = Py_None;
+
+  /* "cutadapt/_align.pyx":204
+ * 		self.debug = False
+ * 		self._dpmatrix = None
+ * 		self._insertion_cost = 1             # <<<<<<<<<<<<<<
+ * 		self._deletion_cost = 1
+ * 
+ */
+  __pyx_v_self->_insertion_cost = 1;
+
+  /* "cutadapt/_align.pyx":205
+ * 		self._dpmatrix = None
+ * 		self._insertion_cost = 1
+ * 		self._deletion_cost = 1             # <<<<<<<<<<<<<<
+ * 
+ * 	property min_overlap:
+ */
+  __pyx_v_self->_deletion_cost = 1;
+
+  /* "cutadapt/_align.pyx":194
+ * 	cdef str str_reference
+ * 
+ * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
+ * 		self.max_error_rate = max_error_rate
+ * 		self.flags = flags
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_AddTraceback("cutadapt._align.Aligner.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":208
+ * 
+ * 	property min_overlap:
+ * 		def __get__(self):             # <<<<<<<<<<<<<<
+ * 			return self._min_overlap
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap___get__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__get__", 0);
+
+  /* "cutadapt/_align.pyx":209
+ * 	property min_overlap:
+ * 		def __get__(self):
+ * 			return self._min_overlap             # <<<<<<<<<<<<<<
+ * 
+ * 		def __set__(self, int value):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_min_overlap); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+  __pyx_r = __pyx_t_1;
+  __pyx_t_1 = 0;
+  goto __pyx_L0;
+
+  /* "cutadapt/_align.pyx":208
+ * 
+ * 	property min_overlap:
+ * 		def __get__(self):             # <<<<<<<<<<<<<<
+ * 			return self._min_overlap
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cutadapt._align.Aligner.min_overlap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":211
+ * 			return self._min_overlap
+ * 
+ * 		def __set__(self, int value):             # <<<<<<<<<<<<<<
+ * 			if value < 1:
+ * 				raise ValueError('Minimum overlap must be at least 1')
+ */
+
+/* Python wrapper */
+static int __pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_value); /*proto*/
+static int __pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_arg_value) {
+  int __pyx_v_value;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
+  assert(__pyx_arg_value); {
+    __pyx_v_value = __Pyx_PyInt_As_int(__pyx_arg_value); if (unlikely((__pyx_v_value == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  }
+  goto __pyx_L4_argument_unpacking_done;
+  __pyx_L3_error:;
+  __Pyx_AddTraceback("cutadapt._align.Aligner.min_overlap.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_RefNannyFinishContext();
+  return -1;
+  __pyx_L4_argument_unpacking_done:;
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap_2__set__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), ((int)__pyx_v_value));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_8cutadapt_6_align_7Aligner_11min_overlap_2__set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, int __pyx_v_value) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  int __pyx_t_1;
+  PyObject *__pyx_t_2 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__set__", 0);
+
+  /* "cutadapt/_align.pyx":212
+ * 
+ * 		def __set__(self, int value):
+ * 			if value < 1:             # <<<<<<<<<<<<<<
+ * 				raise ValueError('Minimum overlap must be at least 1')
+ * 			self._min_overlap = value
+ */
+  __pyx_t_1 = ((__pyx_v_value < 1) != 0);
+  if (__pyx_t_1) {
+
+    /* "cutadapt/_align.pyx":213
+ * 		def __set__(self, int value):
+ * 			if value < 1:
+ * 				raise ValueError('Minimum overlap must be at least 1')             # <<<<<<<<<<<<<<
+ * 			self._min_overlap = value
+ * 
+ */
+    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_align.pyx":212
+ * 
+ * 		def __set__(self, int value):
+ * 			if value < 1:             # <<<<<<<<<<<<<<
+ * 				raise ValueError('Minimum overlap must be at least 1')
+ * 			self._min_overlap = value
+ */
+  }
+
+  /* "cutadapt/_align.pyx":214
+ * 			if value < 1:
+ * 				raise ValueError('Minimum overlap must be at least 1')
+ * 			self._min_overlap = value             # <<<<<<<<<<<<<<
+ * 
+ * 	property indel_cost:
+ */
+  __pyx_v_self->_min_overlap = __pyx_v_value;
+
+  /* "cutadapt/_align.pyx":211
+ * 			return self._min_overlap
+ * 
+ * 		def __set__(self, int value):             # <<<<<<<<<<<<<<
+ * 			if value < 1:
+ * 				raise ValueError('Minimum overlap must be at least 1')
+ */
+
+  /* function exit code */
+  __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_AddTraceback("cutadapt._align.Aligner.min_overlap.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":221
+ * 		changed.
+ * 		"""
+ * 		def __set__(self, value):             # <<<<<<<<<<<<<<
+ * 			if value < 1:
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
  */
-  __pyx_v_self->wildcard_ref = (__pyx_v_degenerate & 1);
 
-  /* "cutadapt/_align.pyx":167
- * 		self.flags = flags
- * 		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
- * 		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2             # <<<<<<<<<<<<<<
- * 		self.reference = reference
- * 		if min_overlap < 1:
+/* Python wrapper */
+static int __pyx_pw_8cutadapt_6_align_7Aligner_10indel_cost_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_pw_8cutadapt_6_align_7Aligner_10indel_cost_1__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_10indel_cost___set__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), ((PyObject *)__pyx_v_value));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_8cutadapt_6_align_7Aligner_10indel_cost___set__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_value) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_t_2;
+  int __pyx_t_3;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
+  __Pyx_RefNannySetupContext("__set__", 0);
+
+  /* "cutadapt/_align.pyx":222
+ * 		"""
+ * 		def __set__(self, value):
+ * 			if value < 1:             # <<<<<<<<<<<<<<
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
+ * 			self._insertion_cost = value
  */
-  __pyx_v_self->wildcard_query = (__pyx_v_degenerate & 2);
+  __pyx_t_1 = PyObject_RichCompare(__pyx_v_value, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+  if (__pyx_t_2) {
 
-  /* "cutadapt/_align.pyx":168
- * 		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
- * 		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
- * 		self.reference = reference             # <<<<<<<<<<<<<<
- * 		if min_overlap < 1:
- * 			raise ValueError("minimum overlap must be at least 1")
+    /* "cutadapt/_align.pyx":223
+ * 		def __set__(self, value):
+ * 			if value < 1:
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')             # <<<<<<<<<<<<<<
+ * 			self._insertion_cost = value
+ * 			self._deletion_cost = value
  */
-  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference, __pyx_v_reference) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_1);
+    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_align.pyx":169
- * 		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
- * 		self.reference = reference
- * 		if min_overlap < 1:             # <<<<<<<<<<<<<<
- * 			raise ValueError("minimum overlap must be at least 1")
- * 		self.min_overlap = min_overlap
+    /* "cutadapt/_align.pyx":222
+ * 		"""
+ * 		def __set__(self, value):
+ * 			if value < 1:             # <<<<<<<<<<<<<<
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
+ * 			self._insertion_cost = value
  */
-  __pyx_t_1 = ((__pyx_v_min_overlap < 1) != 0);
-  if (__pyx_t_1) {
+  }
 
-    /* "cutadapt/_align.pyx":170
- * 		self.reference = reference
- * 		if min_overlap < 1:
- * 			raise ValueError("minimum overlap must be at least 1")             # <<<<<<<<<<<<<<
- * 		self.min_overlap = min_overlap
+  /* "cutadapt/_align.pyx":224
+ * 			if value < 1:
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
+ * 			self._insertion_cost = value             # <<<<<<<<<<<<<<
+ * 			self._deletion_cost = value
  * 
  */
-    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_2);
-    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  }
+  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_v_self->_insertion_cost = __pyx_t_3;
 
-  /* "cutadapt/_align.pyx":171
- * 		if min_overlap < 1:
- * 			raise ValueError("minimum overlap must be at least 1")
- * 		self.min_overlap = min_overlap             # <<<<<<<<<<<<<<
+  /* "cutadapt/_align.pyx":225
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
+ * 			self._insertion_cost = value
+ * 			self._deletion_cost = value             # <<<<<<<<<<<<<<
  * 
  * 	property reference:
  */
-  __pyx_v_self->min_overlap = __pyx_v_min_overlap;
+  __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_v_self->_deletion_cost = __pyx_t_3;
 
-  /* "cutadapt/_align.pyx":163
- * 	cdef bytes _reference
- * 
- * 	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 		self.max_error_rate = max_error_rate
- * 		self.flags = flags
+  /* "cutadapt/_align.pyx":221
+ * 		changed.
+ * 		"""
+ * 		def __set__(self, value):             # <<<<<<<<<<<<<<
+ * 			if value < 1:
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')
  */
 
   /* function exit code */
   __pyx_r = 0;
   goto __pyx_L0;
   __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_2);
-  __Pyx_AddTraceback("cutadapt._align.Aligner.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cutadapt._align.Aligner.indel_cost.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = -1;
   __pyx_L0:;
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":174
+/* "cutadapt/_align.pyx":228
  * 
  * 	property reference:
  * 		def __get__(self):             # <<<<<<<<<<<<<<
@@ -1932,7 +3595,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_9reference___get__(struct _
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
 
-  /* "cutadapt/_align.pyx":175
+  /* "cutadapt/_align.pyx":229
  * 	property reference:
  * 		def __get__(self):
  * 			return self._reference             # <<<<<<<<<<<<<<
@@ -1944,7 +3607,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_9reference___get__(struct _
   __pyx_r = __pyx_v_self->_reference;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":174
+  /* "cutadapt/_align.pyx":228
  * 
  * 	property reference:
  * 		def __get__(self):             # <<<<<<<<<<<<<<
@@ -1959,7 +3622,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_9reference___get__(struct _
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":177
+/* "cutadapt/_align.pyx":231
  * 			return self._reference
  * 
  * 		def __set__(self, str reference):             # <<<<<<<<<<<<<<
@@ -1976,7 +3639,7 @@ static int __pyx_pw_8cutadapt_6_align_7Aligner_9reference_3__set__(PyObject *__p
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), ((PyObject*)__pyx_v_reference));
 
   /* function exit code */
@@ -2003,17 +3666,17 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__set__", 0);
 
-  /* "cutadapt/_align.pyx":178
+  /* "cutadapt/_align.pyx":232
  * 
  * 		def __set__(self, str reference):
  * 			mem = <_Entry*> PyMem_Realloc(self.column, (len(reference) + 1) * sizeof(_Entry))             # <<<<<<<<<<<<<<
  * 			if not mem:
  * 				raise MemoryError()
  */
-  __pyx_t_1 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_mem = ((__pyx_t_8cutadapt_6_align__Entry *)PyMem_Realloc(__pyx_v_self->column, ((__pyx_t_1 + 1) * (sizeof(__pyx_t_8cutadapt_6_align__Entry)))));
 
-  /* "cutadapt/_align.pyx":179
+  /* "cutadapt/_align.pyx":233
  * 		def __set__(self, str reference):
  * 			mem = <_Entry*> PyMem_Realloc(self.column, (len(reference) + 1) * sizeof(_Entry))
  * 			if not mem:             # <<<<<<<<<<<<<<
@@ -2023,17 +3686,25 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
   __pyx_t_2 = ((!(__pyx_v_mem != 0)) != 0);
   if (__pyx_t_2) {
 
-    /* "cutadapt/_align.pyx":180
+    /* "cutadapt/_align.pyx":234
  * 			mem = <_Entry*> PyMem_Realloc(self.column, (len(reference) + 1) * sizeof(_Entry))
  * 			if not mem:
  * 				raise MemoryError()             # <<<<<<<<<<<<<<
  * 			self.column = mem
  * 			self._reference = reference.encode('ascii')
  */
-    PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_align.pyx":233
+ * 		def __set__(self, str reference):
+ * 			mem = <_Entry*> PyMem_Realloc(self.column, (len(reference) + 1) * sizeof(_Entry))
+ * 			if not mem:             # <<<<<<<<<<<<<<
+ * 				raise MemoryError()
+ * 			self.column = mem
+ */
   }
 
-  /* "cutadapt/_align.pyx":181
+  /* "cutadapt/_align.pyx":235
  * 			if not mem:
  * 				raise MemoryError()
  * 			self.column = mem             # <<<<<<<<<<<<<<
@@ -2042,36 +3713,36 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
  */
   __pyx_v_self->column = __pyx_v_mem;
 
-  /* "cutadapt/_align.pyx":182
+  /* "cutadapt/_align.pyx":236
  * 				raise MemoryError()
  * 			self.column = mem
  * 			self._reference = reference.encode('ascii')             # <<<<<<<<<<<<<<
  * 			self.m = len(reference)
  * 			if self.wildcard_ref:
  */
-  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_reference, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_reference, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GIVEREF(__pyx_t_4);
   __Pyx_GOTREF(__pyx_v_self->_reference);
   __Pyx_DECREF(__pyx_v_self->_reference);
   __pyx_v_self->_reference = ((PyObject*)__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "cutadapt/_align.pyx":183
+  /* "cutadapt/_align.pyx":237
  * 			self.column = mem
  * 			self._reference = reference.encode('ascii')
  * 			self.m = len(reference)             # <<<<<<<<<<<<<<
  * 			if self.wildcard_ref:
  * 				self._reference = self._reference.translate(IUPAC_TABLE)
  */
-  __pyx_t_1 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Length(__pyx_v_reference); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_self->m = __pyx_t_1;
 
-  /* "cutadapt/_align.pyx":184
+  /* "cutadapt/_align.pyx":238
  * 			self._reference = reference.encode('ascii')
  * 			self.m = len(reference)
  * 			if self.wildcard_ref:             # <<<<<<<<<<<<<<
@@ -2081,14 +3752,14 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
   __pyx_t_2 = (__pyx_v_self->wildcard_ref != 0);
   if (__pyx_t_2) {
 
-    /* "cutadapt/_align.pyx":185
+    /* "cutadapt/_align.pyx":239
  * 			self.m = len(reference)
  * 			if self.wildcard_ref:
  * 				self._reference = self._reference.translate(IUPAC_TABLE)             # <<<<<<<<<<<<<<
  * 			elif self.wildcard_query:
  * 				self._reference = self._reference.translate(ACGT_TABLE)
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_reference, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_reference, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_5 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -2101,47 +3772,55 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
       }
     }
     if (!__pyx_t_5) {
-      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
     } else {
-      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_8cutadapt_6_align_IUPAC_TABLE);
-      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GIVEREF(__pyx_t_4);
     __Pyx_GOTREF(__pyx_v_self->_reference);
     __Pyx_DECREF(__pyx_v_self->_reference);
     __pyx_v_self->_reference = ((PyObject*)__pyx_t_4);
     __pyx_t_4 = 0;
+
+    /* "cutadapt/_align.pyx":238
+ * 			self._reference = reference.encode('ascii')
+ * 			self.m = len(reference)
+ * 			if self.wildcard_ref:             # <<<<<<<<<<<<<<
+ * 				self._reference = self._reference.translate(IUPAC_TABLE)
+ * 			elif self.wildcard_query:
+ */
     goto __pyx_L4;
   }
 
-  /* "cutadapt/_align.pyx":186
+  /* "cutadapt/_align.pyx":240
  * 			if self.wildcard_ref:
  * 				self._reference = self._reference.translate(IUPAC_TABLE)
  * 			elif self.wildcard_query:             # <<<<<<<<<<<<<<
  * 				self._reference = self._reference.translate(ACGT_TABLE)
- * 
+ * 			self.str_reference = reference
  */
   __pyx_t_2 = (__pyx_v_self->wildcard_query != 0);
   if (__pyx_t_2) {
 
-    /* "cutadapt/_align.pyx":187
+    /* "cutadapt/_align.pyx":241
  * 				self._reference = self._reference.translate(IUPAC_TABLE)
  * 			elif self.wildcard_query:
  * 				self._reference = self._reference.translate(ACGT_TABLE)             # <<<<<<<<<<<<<<
+ * 			self.str_reference = reference
  * 
- * 	def locate(self, str query):
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_reference, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_reference, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_6 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -2154,31 +3833,51 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
       }
     }
     if (!__pyx_t_6) {
-      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
     } else {
-      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_5);
       __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_8cutadapt_6_align_ACGT_TABLE);
-      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_4);
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GIVEREF(__pyx_t_4);
     __Pyx_GOTREF(__pyx_v_self->_reference);
     __Pyx_DECREF(__pyx_v_self->_reference);
     __pyx_v_self->_reference = ((PyObject*)__pyx_t_4);
     __pyx_t_4 = 0;
-    goto __pyx_L4;
+
+    /* "cutadapt/_align.pyx":240
+ * 			if self.wildcard_ref:
+ * 				self._reference = self._reference.translate(IUPAC_TABLE)
+ * 			elif self.wildcard_query:             # <<<<<<<<<<<<<<
+ * 				self._reference = self._reference.translate(ACGT_TABLE)
+ * 			self.str_reference = reference
+ */
   }
   __pyx_L4:;
 
-  /* "cutadapt/_align.pyx":177
+  /* "cutadapt/_align.pyx":242
+ * 			elif self.wildcard_query:
+ * 				self._reference = self._reference.translate(ACGT_TABLE)
+ * 			self.str_reference = reference             # <<<<<<<<<<<<<<
+ * 
+ * 	property dpmatrix:
+ */
+  __Pyx_INCREF(__pyx_v_reference);
+  __Pyx_GIVEREF(__pyx_v_reference);
+  __Pyx_GOTREF(__pyx_v_self->str_reference);
+  __Pyx_DECREF(__pyx_v_self->str_reference);
+  __pyx_v_self->str_reference = __pyx_v_reference;
+
+  /* "cutadapt/_align.pyx":231
  * 			return self._reference
  * 
  * 		def __set__(self, str reference):             # <<<<<<<<<<<<<<
@@ -2201,8 +3900,112 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":189
- * 				self._reference = self._reference.translate(ACGT_TABLE)
+/* "cutadapt/_align.pyx":249
+ * 		usually None, unless debugging has been enabled with enable_debug().
+ * 		"""
+ * 		def __get__(self):             # <<<<<<<<<<<<<<
+ * 			return self._dpmatrix
+ * 
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_8dpmatrix_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_8dpmatrix_1__get__(PyObject *__pyx_v_self) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_8dpmatrix___get__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_8dpmatrix___get__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__get__", 0);
+
+  /* "cutadapt/_align.pyx":250
+ * 		"""
+ * 		def __get__(self):
+ * 			return self._dpmatrix             # <<<<<<<<<<<<<<
+ * 
+ * 	def enable_debug(self):
+ */
+  __Pyx_XDECREF(__pyx_r);
+  __Pyx_INCREF(__pyx_v_self->_dpmatrix);
+  __pyx_r = __pyx_v_self->_dpmatrix;
+  goto __pyx_L0;
+
+  /* "cutadapt/_align.pyx":249
+ * 		usually None, unless debugging has been enabled with enable_debug().
+ * 		"""
+ * 		def __get__(self):             # <<<<<<<<<<<<<<
+ * 			return self._dpmatrix
+ * 
+ */
+
+  /* function exit code */
+  __pyx_L0:;
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":252
+ * 			return self._dpmatrix
+ * 
+ * 	def enable_debug(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Store the dynamic programming matrix while running the locate() method
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_3enable_debug(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static char __pyx_doc_8cutadapt_6_align_7Aligner_2enable_debug[] = "\n\t\tStore the dynamic programming matrix while running the locate() method\n\t\tand make it available in the .dpmatrix attribute.\n\t\t";
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_3enable_debug(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+  PyObject *__pyx_r = 0;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("enable_debug (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_2enable_debug(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2enable_debug(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self) {
+  PyObject *__pyx_r = NULL;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("enable_debug", 0);
+
+  /* "cutadapt/_align.pyx":257
+ * 		and make it available in the .dpmatrix attribute.
+ * 		"""
+ * 		self.debug = True             # <<<<<<<<<<<<<<
+ * 
+ * 	def locate(self, str query):
+ */
+  __pyx_v_self->debug = 1;
+
+  /* "cutadapt/_align.pyx":252
+ * 			return self._dpmatrix
+ * 
+ * 	def enable_debug(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Store the dynamic programming matrix while running the locate() method
+ */
+
+  /* function exit code */
+  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_align.pyx":259
+ * 		self.debug = True
  * 
  * 	def locate(self, str query):             # <<<<<<<<<<<<<<
  * 		"""
@@ -2210,17 +4013,17 @@ static int __pyx_pf_8cutadapt_6_align_7Aligner_9reference_2__set__(struct __pyx_
  */
 
 /* Python wrapper */
-static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_3locate(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
-static char __pyx_doc_8cutadapt_6_align_7Aligner_2locate[] = "\n\t\tlocate(query) -> (refstart, refstop, querystart, querystop, matches, errors)\n\n\t\tFind the query within the reference associated with this aligner. The\n\t\tintervals (querystart, querystop) and (refstart, refstop) give the\n\t\tlocation of the match.\n\n\t\tThat is, the substrings query[querystart:querystop] and\n\t\tself.reference[refstart:refstop] were found to align best to each other,\n\t\twith the given number of [...]
-static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_3locate(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_5locate(PyObject *__pyx_v_self, PyObject *__pyx_v_query); /*proto*/
+static char __pyx_doc_8cutadapt_6_align_7Aligner_4locate[] = "\n\t\tlocate(query) -> (refstart, refstop, querystart, querystop, matches, errors)\n\n\t\tFind the query within the reference associated with this aligner. The\n\t\tintervals (querystart, querystop) and (refstart, refstop) give the\n\t\tlocation of the match.\n\n\t\tThat is, the substrings query[querystart:querystop] and\n\t\tself.reference[refstart:refstop] were found to align best to each other,\n\t\twith the given number of [...]
+static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_5locate(PyObject *__pyx_v_self, PyObject *__pyx_v_query) {
   CYTHON_UNUSED int __pyx_lineno = 0;
   CYTHON_UNUSED const char *__pyx_filename = NULL;
   CYTHON_UNUSED int __pyx_clineno = 0;
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("locate (wrapper)", 0);
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_2locate(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), ((PyObject*)__pyx_v_query));
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_8cutadapt_6_align_7Aligner_4locate(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self), ((PyObject*)__pyx_v_query));
 
   /* function exit code */
   goto __pyx_L0;
@@ -2231,7 +4034,7 @@ static PyObject *__pyx_pw_8cutadapt_6_align_7Aligner_3locate(PyObject *__pyx_v_s
   return __pyx_r;
 }
 
-static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_query) {
+static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_4locate(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self, PyObject *__pyx_v_query) {
   char *__pyx_v_s1;
   PyObject *__pyx_v_query_bytes = 0;
   char *__pyx_v_s2;
@@ -2290,43 +4093,43 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("locate", 0);
 
-  /* "cutadapt/_align.pyx":203
+  /* "cutadapt/_align.pyx":273
  * 		The alignment itself is not returned.
  * 		"""
  * 		cdef char* s1 = self._reference             # <<<<<<<<<<<<<<
  * 		cdef bytes query_bytes = query.encode('ascii')
  * 		cdef char* s2 = query_bytes
  */
-  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_self->_reference); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_self->_reference); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_s1 = __pyx_t_1;
 
-  /* "cutadapt/_align.pyx":204
+  /* "cutadapt/_align.pyx":274
  * 		"""
  * 		cdef char* s1 = self._reference
  * 		cdef bytes query_bytes = query.encode('ascii')             # <<<<<<<<<<<<<<
  * 		cdef char* s2 = query_bytes
  * 		cdef int m = self.m
  */
-  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_query_bytes = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "cutadapt/_align.pyx":205
+  /* "cutadapt/_align.pyx":275
  * 		cdef char* s1 = self._reference
  * 		cdef bytes query_bytes = query.encode('ascii')
  * 		cdef char* s2 = query_bytes             # <<<<<<<<<<<<<<
  * 		cdef int m = self.m
  * 		cdef int n = len(query)
  */
-  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_s2 = __pyx_t_1;
 
-  /* "cutadapt/_align.pyx":206
+  /* "cutadapt/_align.pyx":276
  * 		cdef bytes query_bytes = query.encode('ascii')
  * 		cdef char* s2 = query_bytes
  * 		cdef int m = self.m             # <<<<<<<<<<<<<<
@@ -2336,17 +4139,17 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_4 = __pyx_v_self->m;
   __pyx_v_m = __pyx_t_4;
 
-  /* "cutadapt/_align.pyx":207
+  /* "cutadapt/_align.pyx":277
  * 		cdef char* s2 = query_bytes
  * 		cdef int m = self.m
  * 		cdef int n = len(query)             # <<<<<<<<<<<<<<
  * 		cdef _Entry* column = self.column
  * 		cdef double max_error_rate = self.max_error_rate
  */
-  __pyx_t_5 = PyObject_Length(__pyx_v_query); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyObject_Length(__pyx_v_query); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_n = __pyx_t_5;
 
-  /* "cutadapt/_align.pyx":208
+  /* "cutadapt/_align.pyx":278
  * 		cdef int m = self.m
  * 		cdef int n = len(query)
  * 		cdef _Entry* column = self.column             # <<<<<<<<<<<<<<
@@ -2356,7 +4159,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_6 = __pyx_v_self->column;
   __pyx_v_column = __pyx_t_6;
 
-  /* "cutadapt/_align.pyx":209
+  /* "cutadapt/_align.pyx":279
  * 		cdef int n = len(query)
  * 		cdef _Entry* column = self.column
  * 		cdef double max_error_rate = self.max_error_rate             # <<<<<<<<<<<<<<
@@ -2366,7 +4169,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_7 = __pyx_v_self->max_error_rate;
   __pyx_v_max_error_rate = __pyx_t_7;
 
-  /* "cutadapt/_align.pyx":210
+  /* "cutadapt/_align.pyx":280
  * 		cdef _Entry* column = self.column
  * 		cdef double max_error_rate = self.max_error_rate
  * 		cdef bint start_in_ref = self.flags & START_WITHIN_SEQ1             # <<<<<<<<<<<<<<
@@ -2375,7 +4178,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_start_in_ref = (__pyx_v_self->flags & 1);
 
-  /* "cutadapt/_align.pyx":211
+  /* "cutadapt/_align.pyx":281
  * 		cdef double max_error_rate = self.max_error_rate
  * 		cdef bint start_in_ref = self.flags & START_WITHIN_SEQ1
  * 		cdef bint start_in_query = self.flags & START_WITHIN_SEQ2             # <<<<<<<<<<<<<<
@@ -2384,7 +4187,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_start_in_query = (__pyx_v_self->flags & 2);
 
-  /* "cutadapt/_align.pyx":212
+  /* "cutadapt/_align.pyx":282
  * 		cdef bint start_in_ref = self.flags & START_WITHIN_SEQ1
  * 		cdef bint start_in_query = self.flags & START_WITHIN_SEQ2
  * 		cdef bint stop_in_ref = self.flags & STOP_WITHIN_SEQ1             # <<<<<<<<<<<<<<
@@ -2393,7 +4196,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_stop_in_ref = (__pyx_v_self->flags & 4);
 
-  /* "cutadapt/_align.pyx":213
+  /* "cutadapt/_align.pyx":283
  * 		cdef bint start_in_query = self.flags & START_WITHIN_SEQ2
  * 		cdef bint stop_in_ref = self.flags & STOP_WITHIN_SEQ1
  * 		cdef bint stop_in_query = self.flags & STOP_WITHIN_SEQ2             # <<<<<<<<<<<<<<
@@ -2402,7 +4205,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_stop_in_query = (__pyx_v_self->flags & 8);
 
-  /* "cutadapt/_align.pyx":215
+  /* "cutadapt/_align.pyx":285
  * 		cdef bint stop_in_query = self.flags & STOP_WITHIN_SEQ2
  * 
  * 		if self.wildcard_query:             # <<<<<<<<<<<<<<
@@ -2412,14 +4215,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = (__pyx_v_self->wildcard_query != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":216
+    /* "cutadapt/_align.pyx":286
  * 
  * 		if self.wildcard_query:
  * 			query_bytes = query_bytes.translate(IUPAC_TABLE)             # <<<<<<<<<<<<<<
  * 			s2 = query_bytes
  * 		elif self.wildcard_ref:
  */
-    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_t_9 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
@@ -2432,37 +4235,45 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       }
     }
     if (!__pyx_t_9) {
-      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
     } else {
-      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_10);
       __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_8cutadapt_6_align_IUPAC_TABLE);
-      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
     }
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_query_bytes, ((PyObject*)__pyx_t_3));
     __pyx_t_3 = 0;
 
-    /* "cutadapt/_align.pyx":217
+    /* "cutadapt/_align.pyx":287
  * 		if self.wildcard_query:
  * 			query_bytes = query_bytes.translate(IUPAC_TABLE)
  * 			s2 = query_bytes             # <<<<<<<<<<<<<<
  * 		elif self.wildcard_ref:
  * 			query_bytes = query_bytes.translate(ACGT_TABLE)
  */
-    __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_s2 = __pyx_t_1;
+
+    /* "cutadapt/_align.pyx":285
+ * 		cdef bint stop_in_query = self.flags & STOP_WITHIN_SEQ2
+ * 
+ * 		if self.wildcard_query:             # <<<<<<<<<<<<<<
+ * 			query_bytes = query_bytes.translate(IUPAC_TABLE)
+ * 			s2 = query_bytes
+ */
     goto __pyx_L3;
   }
 
-  /* "cutadapt/_align.pyx":218
+  /* "cutadapt/_align.pyx":288
  * 			query_bytes = query_bytes.translate(IUPAC_TABLE)
  * 			s2 = query_bytes
  * 		elif self.wildcard_ref:             # <<<<<<<<<<<<<<
@@ -2472,14 +4283,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = (__pyx_v_self->wildcard_ref != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":219
+    /* "cutadapt/_align.pyx":289
  * 			s2 = query_bytes
  * 		elif self.wildcard_ref:
  * 			query_bytes = query_bytes.translate(ACGT_TABLE)             # <<<<<<<<<<<<<<
  * 			s2 = query_bytes
  * 		cdef bint compare_ascii = not (self.wildcard_query or self.wildcard_ref)
  */
-    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __pyx_t_10 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
@@ -2492,38 +4303,45 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       }
     }
     if (!__pyx_t_10) {
-      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
     } else {
-      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10); __pyx_t_10 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_8cutadapt_6_align_ACGT_TABLE);
-      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
     }
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_query_bytes, ((PyObject*)__pyx_t_3));
     __pyx_t_3 = 0;
 
-    /* "cutadapt/_align.pyx":220
+    /* "cutadapt/_align.pyx":290
  * 		elif self.wildcard_ref:
  * 			query_bytes = query_bytes.translate(ACGT_TABLE)
  * 			s2 = query_bytes             # <<<<<<<<<<<<<<
  * 		cdef bint compare_ascii = not (self.wildcard_query or self.wildcard_ref)
  * 		"""
  */
-    __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_s2 = __pyx_t_1;
-    goto __pyx_L3;
+
+    /* "cutadapt/_align.pyx":288
+ * 			query_bytes = query_bytes.translate(IUPAC_TABLE)
+ * 			s2 = query_bytes
+ * 		elif self.wildcard_ref:             # <<<<<<<<<<<<<<
+ * 			query_bytes = query_bytes.translate(ACGT_TABLE)
+ * 			s2 = query_bytes
+ */
   }
   __pyx_L3:;
 
-  /* "cutadapt/_align.pyx":221
+  /* "cutadapt/_align.pyx":291
  * 			query_bytes = query_bytes.translate(ACGT_TABLE)
  * 			s2 = query_bytes
  * 		cdef bint compare_ascii = not (self.wildcard_query or self.wildcard_ref)             # <<<<<<<<<<<<<<
@@ -2541,7 +4359,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_L4_bool_binop_done:;
   __pyx_v_compare_ascii = (!__pyx_t_8);
 
-  /* "cutadapt/_align.pyx":235
+  /* "cutadapt/_align.pyx":305
  * 
  * 		# maximum no. of errors
  * 		cdef int k = <int> (max_error_rate * m)             # <<<<<<<<<<<<<<
@@ -2550,7 +4368,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_k = ((int)(__pyx_v_max_error_rate * __pyx_v_m));
 
-  /* "cutadapt/_align.pyx":238
+  /* "cutadapt/_align.pyx":308
  * 
  * 		# Determine largest and smallest column we need to compute
  * 		cdef int max_n = n             # <<<<<<<<<<<<<<
@@ -2559,7 +4377,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_max_n = __pyx_v_n;
 
-  /* "cutadapt/_align.pyx":239
+  /* "cutadapt/_align.pyx":309
  * 		# Determine largest and smallest column we need to compute
  * 		cdef int max_n = n
  * 		cdef int min_n = 0             # <<<<<<<<<<<<<<
@@ -2568,7 +4386,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_min_n = 0;
 
-  /* "cutadapt/_align.pyx":240
+  /* "cutadapt/_align.pyx":310
  * 		cdef int max_n = n
  * 		cdef int min_n = 0
  * 		if not start_in_query:             # <<<<<<<<<<<<<<
@@ -2578,7 +4396,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = ((!(__pyx_v_start_in_query != 0)) != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":242
+    /* "cutadapt/_align.pyx":312
  * 		if not start_in_query:
  * 			# costs can only get worse after column m
  * 			max_n = min(n, m + k)             # <<<<<<<<<<<<<<
@@ -2593,11 +4411,17 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       __pyx_t_13 = __pyx_t_12;
     }
     __pyx_v_max_n = __pyx_t_13;
-    goto __pyx_L6;
+
+    /* "cutadapt/_align.pyx":310
+ * 		cdef int max_n = n
+ * 		cdef int min_n = 0
+ * 		if not start_in_query:             # <<<<<<<<<<<<<<
+ * 			# costs can only get worse after column m
+ * 			max_n = min(n, m + k)
+ */
   }
-  __pyx_L6:;
 
-  /* "cutadapt/_align.pyx":243
+  /* "cutadapt/_align.pyx":313
  * 			# costs can only get worse after column m
  * 			max_n = min(n, m + k)
  * 		if not stop_in_query:             # <<<<<<<<<<<<<<
@@ -2607,7 +4431,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = ((!(__pyx_v_stop_in_query != 0)) != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":244
+    /* "cutadapt/_align.pyx":314
  * 			max_n = min(n, m + k)
  * 		if not stop_in_query:
  * 			min_n = max(0, n - m - k)             # <<<<<<<<<<<<<<
@@ -2622,15 +4446,21 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       __pyx_t_15 = __pyx_t_14;
     }
     __pyx_v_min_n = __pyx_t_15;
-    goto __pyx_L7;
+
+    /* "cutadapt/_align.pyx":313
+ * 			# costs can only get worse after column m
+ * 			max_n = min(n, m + k)
+ * 		if not stop_in_query:             # <<<<<<<<<<<<<<
+ * 			min_n = max(0, n - m - k)
+ * 
+ */
   }
-  __pyx_L7:;
 
-  /* "cutadapt/_align.pyx":256
+  /* "cutadapt/_align.pyx":326
  * 		# TODO (later)
  * 		# fill out columns only until 'last'
  * 		if not start_in_ref and not start_in_query:             # <<<<<<<<<<<<<<
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
  */
   __pyx_t_11 = ((!(__pyx_v_start_in_ref != 0)) != 0);
@@ -2644,30 +4474,30 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_L9_bool_binop_done:;
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":257
+    /* "cutadapt/_align.pyx":327
  * 		# fill out columns only until 'last'
  * 		if not start_in_ref and not start_in_query:
- * 			for i in range(0, m + 1):             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):             # <<<<<<<<<<<<<<
  * 				column[i].matches = 0
- * 				column[i].cost = max(i, min_n)
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost
  */
     __pyx_t_15 = (__pyx_v_m + 1);
     for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
       __pyx_v_i = __pyx_t_13;
 
-      /* "cutadapt/_align.pyx":258
+      /* "cutadapt/_align.pyx":328
  * 		if not start_in_ref and not start_in_query:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0             # <<<<<<<<<<<<<<
- * 				column[i].cost = max(i, min_n)
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost
  * 				column[i].origin = 0
  */
       (__pyx_v_column[__pyx_v_i]).matches = 0;
 
-      /* "cutadapt/_align.pyx":259
- * 			for i in range(0, m + 1):
+      /* "cutadapt/_align.pyx":329
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
- * 				column[i].cost = max(i, min_n)             # <<<<<<<<<<<<<<
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost             # <<<<<<<<<<<<<<
  * 				column[i].origin = 0
  * 		elif start_in_ref and not start_in_query:
  */
@@ -2678,25 +4508,33 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       } else {
         __pyx_t_16 = __pyx_t_12;
       }
-      (__pyx_v_column[__pyx_v_i]).cost = __pyx_t_16;
+      (__pyx_v_column[__pyx_v_i]).cost = (__pyx_t_16 * __pyx_v_self->_insertion_cost);
 
-      /* "cutadapt/_align.pyx":260
+      /* "cutadapt/_align.pyx":330
  * 				column[i].matches = 0
- * 				column[i].cost = max(i, min_n)
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost
  * 				column[i].origin = 0             # <<<<<<<<<<<<<<
  * 		elif start_in_ref and not start_in_query:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  */
       (__pyx_v_column[__pyx_v_i]).origin = 0;
     }
+
+    /* "cutadapt/_align.pyx":326
+ * 		# TODO (later)
+ * 		# fill out columns only until 'last'
+ * 		if not start_in_ref and not start_in_query:             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):
+ * 				column[i].matches = 0
+ */
     goto __pyx_L8;
   }
 
-  /* "cutadapt/_align.pyx":261
- * 				column[i].cost = max(i, min_n)
+  /* "cutadapt/_align.pyx":331
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost
  * 				column[i].origin = 0
  * 		elif start_in_ref and not start_in_query:             # <<<<<<<<<<<<<<
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
  */
   __pyx_t_11 = (__pyx_v_start_in_ref != 0);
@@ -2710,41 +4548,41 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_L13_bool_binop_done:;
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":262
+    /* "cutadapt/_align.pyx":332
  * 				column[i].origin = 0
  * 		elif start_in_ref and not start_in_query:
- * 			for i in range(0, m + 1):             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):             # <<<<<<<<<<<<<<
  * 				column[i].matches = 0
- * 				column[i].cost = min_n
+ * 				column[i].cost = min_n * self._insertion_cost
  */
     __pyx_t_15 = (__pyx_v_m + 1);
     for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
       __pyx_v_i = __pyx_t_13;
 
-      /* "cutadapt/_align.pyx":263
+      /* "cutadapt/_align.pyx":333
  * 		elif start_in_ref and not start_in_query:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0             # <<<<<<<<<<<<<<
- * 				column[i].cost = min_n
+ * 				column[i].cost = min_n * self._insertion_cost
  * 				column[i].origin = min(0, min_n - i)
  */
       (__pyx_v_column[__pyx_v_i]).matches = 0;
 
-      /* "cutadapt/_align.pyx":264
- * 			for i in range(0, m + 1):
+      /* "cutadapt/_align.pyx":334
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
- * 				column[i].cost = min_n             # <<<<<<<<<<<<<<
+ * 				column[i].cost = min_n * self._insertion_cost             # <<<<<<<<<<<<<<
  * 				column[i].origin = min(0, min_n - i)
  * 		elif not start_in_ref and start_in_query:
  */
-      (__pyx_v_column[__pyx_v_i]).cost = __pyx_v_min_n;
+      (__pyx_v_column[__pyx_v_i]).cost = (__pyx_v_min_n * __pyx_v_self->_insertion_cost);
 
-      /* "cutadapt/_align.pyx":265
+      /* "cutadapt/_align.pyx":335
  * 				column[i].matches = 0
- * 				column[i].cost = min_n
+ * 				column[i].cost = min_n * self._insertion_cost
  * 				column[i].origin = min(0, min_n - i)             # <<<<<<<<<<<<<<
  * 		elif not start_in_ref and start_in_query:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  */
       __pyx_t_16 = (__pyx_v_min_n - __pyx_v_i);
       __pyx_t_14 = 0;
@@ -2755,14 +4593,22 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       }
       (__pyx_v_column[__pyx_v_i]).origin = __pyx_t_17;
     }
+
+    /* "cutadapt/_align.pyx":331
+ * 				column[i].cost = max(i, min_n) * self._insertion_cost
+ * 				column[i].origin = 0
+ * 		elif start_in_ref and not start_in_query:             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):
+ * 				column[i].matches = 0
+ */
     goto __pyx_L8;
   }
 
-  /* "cutadapt/_align.pyx":266
- * 				column[i].cost = min_n
+  /* "cutadapt/_align.pyx":336
+ * 				column[i].cost = min_n * self._insertion_cost
  * 				column[i].origin = min(0, min_n - i)
  * 		elif not start_in_ref and start_in_query:             # <<<<<<<<<<<<<<
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
  */
   __pyx_t_11 = ((!(__pyx_v_start_in_ref != 0)) != 0);
@@ -2776,41 +4622,41 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_L17_bool_binop_done:;
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":267
+    /* "cutadapt/_align.pyx":337
  * 				column[i].origin = min(0, min_n - i)
  * 		elif not start_in_ref and start_in_query:
- * 			for i in range(0, m + 1):             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):             # <<<<<<<<<<<<<<
  * 				column[i].matches = 0
- * 				column[i].cost = i
+ * 				column[i].cost = i * self._insertion_cost
  */
     __pyx_t_15 = (__pyx_v_m + 1);
     for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
       __pyx_v_i = __pyx_t_13;
 
-      /* "cutadapt/_align.pyx":268
+      /* "cutadapt/_align.pyx":338
  * 		elif not start_in_ref and start_in_query:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0             # <<<<<<<<<<<<<<
- * 				column[i].cost = i
+ * 				column[i].cost = i * self._insertion_cost
  * 				column[i].origin = max(0, min_n - i)
  */
       (__pyx_v_column[__pyx_v_i]).matches = 0;
 
-      /* "cutadapt/_align.pyx":269
- * 			for i in range(0, m + 1):
+      /* "cutadapt/_align.pyx":339
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
- * 				column[i].cost = i             # <<<<<<<<<<<<<<
+ * 				column[i].cost = i * self._insertion_cost             # <<<<<<<<<<<<<<
  * 				column[i].origin = max(0, min_n - i)
  * 		else:
  */
-      (__pyx_v_column[__pyx_v_i]).cost = __pyx_v_i;
+      (__pyx_v_column[__pyx_v_i]).cost = (__pyx_v_i * __pyx_v_self->_insertion_cost);
 
-      /* "cutadapt/_align.pyx":270
+      /* "cutadapt/_align.pyx":340
  * 				column[i].matches = 0
- * 				column[i].cost = i
+ * 				column[i].cost = i * self._insertion_cost
  * 				column[i].origin = max(0, min_n - i)             # <<<<<<<<<<<<<<
  * 		else:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  */
       __pyx_t_16 = (__pyx_v_min_n - __pyx_v_i);
       __pyx_t_17 = 0;
@@ -2821,34 +4667,42 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       }
       (__pyx_v_column[__pyx_v_i]).origin = __pyx_t_14;
     }
+
+    /* "cutadapt/_align.pyx":336
+ * 				column[i].cost = min_n * self._insertion_cost
+ * 				column[i].origin = min(0, min_n - i)
+ * 		elif not start_in_ref and start_in_query:             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):
+ * 				column[i].matches = 0
+ */
     goto __pyx_L8;
   }
-  /*else*/ {
 
-    /* "cutadapt/_align.pyx":272
+  /* "cutadapt/_align.pyx":342
  * 				column[i].origin = max(0, min_n - i)
  * 		else:
- * 			for i in range(0, m + 1):             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):             # <<<<<<<<<<<<<<
  * 				column[i].matches = 0
- * 				column[i].cost = min(i, min_n)
+ * 				column[i].cost = min(i, min_n) * self._insertion_cost
  */
+  /*else*/ {
     __pyx_t_15 = (__pyx_v_m + 1);
     for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
       __pyx_v_i = __pyx_t_13;
 
-      /* "cutadapt/_align.pyx":273
+      /* "cutadapt/_align.pyx":343
  * 		else:
- * 			for i in range(0, m + 1):
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0             # <<<<<<<<<<<<<<
- * 				column[i].cost = min(i, min_n)
+ * 				column[i].cost = min(i, min_n) * self._insertion_cost
  * 				column[i].origin = min_n - i
  */
       (__pyx_v_column[__pyx_v_i]).matches = 0;
 
-      /* "cutadapt/_align.pyx":274
- * 			for i in range(0, m + 1):
+      /* "cutadapt/_align.pyx":344
+ * 			for i in range(m + 1):
  * 				column[i].matches = 0
- * 				column[i].cost = min(i, min_n)             # <<<<<<<<<<<<<<
+ * 				column[i].cost = min(i, min_n) * self._insertion_cost             # <<<<<<<<<<<<<<
  * 				column[i].origin = min_n - i
  * 
  */
@@ -2859,22 +4713,142 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       } else {
         __pyx_t_12 = __pyx_t_4;
       }
-      (__pyx_v_column[__pyx_v_i]).cost = __pyx_t_12;
+      (__pyx_v_column[__pyx_v_i]).cost = (__pyx_t_12 * __pyx_v_self->_insertion_cost);
 
-      /* "cutadapt/_align.pyx":275
+      /* "cutadapt/_align.pyx":345
  * 				column[i].matches = 0
- * 				column[i].cost = min(i, min_n)
+ * 				column[i].cost = min(i, min_n) * self._insertion_cost
  * 				column[i].origin = min_n - i             # <<<<<<<<<<<<<<
  * 
- * 		cdef _Match best
+ * 		if self.debug:
  */
       (__pyx_v_column[__pyx_v_i]).origin = (__pyx_v_min_n - __pyx_v_i);
     }
   }
   __pyx_L8:;
 
-  /* "cutadapt/_align.pyx":278
+  /* "cutadapt/_align.pyx":347
+ * 				column[i].origin = min_n - i
+ * 
+ * 		if self.debug:             # <<<<<<<<<<<<<<
+ * 			self._dpmatrix = DPMatrix(self.str_reference, query)
+ * 			for i in range(m + 1):
+ */
+  __pyx_t_8 = (__pyx_v_self->debug != 0);
+  if (__pyx_t_8) {
+
+    /* "cutadapt/_align.pyx":348
+ * 
+ * 		if self.debug:
+ * 			self._dpmatrix = DPMatrix(self.str_reference, query)             # <<<<<<<<<<<<<<
+ * 			for i in range(m + 1):
+ * 				self._dpmatrix.set_entry(i, min_n, column[i].cost)
+ */
+    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_DPMatrix); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_2);
+    __pyx_t_9 = NULL;
+    __pyx_t_5 = 0;
+    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
+      if (likely(__pyx_t_9)) {
+        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+        __Pyx_INCREF(__pyx_t_9);
+        __Pyx_INCREF(function);
+        __Pyx_DECREF_SET(__pyx_t_2, function);
+        __pyx_t_5 = 1;
+      }
+    }
+    __pyx_t_10 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_10);
+    if (__pyx_t_9) {
+      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
+    }
+    __Pyx_INCREF(__pyx_v_self->str_reference);
+    __Pyx_GIVEREF(__pyx_v_self->str_reference);
+    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_5, __pyx_v_self->str_reference);
+    __Pyx_INCREF(__pyx_v_query);
+    __Pyx_GIVEREF(__pyx_v_query);
+    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_5, __pyx_v_query);
+    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_3);
+    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+    __Pyx_GIVEREF(__pyx_t_3);
+    __Pyx_GOTREF(__pyx_v_self->_dpmatrix);
+    __Pyx_DECREF(__pyx_v_self->_dpmatrix);
+    __pyx_v_self->_dpmatrix = __pyx_t_3;
+    __pyx_t_3 = 0;
+
+    /* "cutadapt/_align.pyx":349
+ * 		if self.debug:
+ * 			self._dpmatrix = DPMatrix(self.str_reference, query)
+ * 			for i in range(m + 1):             # <<<<<<<<<<<<<<
+ * 				self._dpmatrix.set_entry(i, min_n, column[i].cost)
+ * 		cdef _Match best
+ */
+    __pyx_t_15 = (__pyx_v_m + 1);
+    for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
+      __pyx_v_i = __pyx_t_13;
+
+      /* "cutadapt/_align.pyx":350
+ * 			self._dpmatrix = DPMatrix(self.str_reference, query)
+ * 			for i in range(m + 1):
+ * 				self._dpmatrix.set_entry(i, min_n, column[i].cost)             # <<<<<<<<<<<<<<
+ * 		cdef _Match best
+ * 		best.ref_stop = m
+ */
+      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_dpmatrix, __pyx_n_s_set_entry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_2);
+      __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_10);
+      __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_min_n); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_9);
+      __pyx_t_18 = __Pyx_PyInt_From_int((__pyx_v_column[__pyx_v_i]).cost); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_18);
+      __pyx_t_19 = NULL;
+      __pyx_t_5 = 0;
+      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
+        __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_2);
+        if (likely(__pyx_t_19)) {
+          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+          __Pyx_INCREF(__pyx_t_19);
+          __Pyx_INCREF(function);
+          __Pyx_DECREF_SET(__pyx_t_2, function);
+          __pyx_t_5 = 1;
+        }
+      }
+      __pyx_t_20 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_20);
+      if (__pyx_t_19) {
+        __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_19); __pyx_t_19 = NULL;
+      }
+      __Pyx_GIVEREF(__pyx_t_10);
+      PyTuple_SET_ITEM(__pyx_t_20, 0+__pyx_t_5, __pyx_t_10);
+      __Pyx_GIVEREF(__pyx_t_9);
+      PyTuple_SET_ITEM(__pyx_t_20, 1+__pyx_t_5, __pyx_t_9);
+      __Pyx_GIVEREF(__pyx_t_18);
+      PyTuple_SET_ITEM(__pyx_t_20, 2+__pyx_t_5, __pyx_t_18);
+      __pyx_t_10 = 0;
+      __pyx_t_9 = 0;
+      __pyx_t_18 = 0;
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_3);
+      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
+      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+    }
+
+    /* "cutadapt/_align.pyx":347
+ * 				column[i].origin = min_n - i
  * 
+ * 		if self.debug:             # <<<<<<<<<<<<<<
+ * 			self._dpmatrix = DPMatrix(self.str_reference, query)
+ * 			for i in range(m + 1):
+ */
+  }
+
+  /* "cutadapt/_align.pyx":352
+ * 				self._dpmatrix.set_entry(i, min_n, column[i].cost)
  * 		cdef _Match best
  * 		best.ref_stop = m             # <<<<<<<<<<<<<<
  * 		best.query_stop = n
@@ -2882,7 +4856,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_best.ref_stop = __pyx_v_m;
 
-  /* "cutadapt/_align.pyx":279
+  /* "cutadapt/_align.pyx":353
  * 		cdef _Match best
  * 		best.ref_stop = m
  * 		best.query_stop = n             # <<<<<<<<<<<<<<
@@ -2891,7 +4865,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_best.query_stop = __pyx_v_n;
 
-  /* "cutadapt/_align.pyx":280
+  /* "cutadapt/_align.pyx":354
  * 		best.ref_stop = m
  * 		best.query_stop = n
  * 		best.cost = m + n             # <<<<<<<<<<<<<<
@@ -2900,7 +4874,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_best.cost = (__pyx_v_m + __pyx_v_n);
 
-  /* "cutadapt/_align.pyx":281
+  /* "cutadapt/_align.pyx":355
  * 		best.query_stop = n
  * 		best.cost = m + n
  * 		best.origin = 0             # <<<<<<<<<<<<<<
@@ -2909,7 +4883,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_best.origin = 0;
 
-  /* "cutadapt/_align.pyx":282
+  /* "cutadapt/_align.pyx":356
  * 		best.cost = m + n
  * 		best.origin = 0
  * 		best.matches = 0             # <<<<<<<<<<<<<<
@@ -2918,18 +4892,25 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
   __pyx_v_best.matches = 0;
 
-  /* "cutadapt/_align.pyx":285
+  /* "cutadapt/_align.pyx":359
  * 
  * 		# Ukkonen's trick: index of the last cell that is less than k.
- * 		cdef int last = k + 1             # <<<<<<<<<<<<<<
+ * 		cdef int last = min(m, k + 1)             # <<<<<<<<<<<<<<
  * 		if start_in_ref:
  * 			last = m
  */
-  __pyx_v_last = (__pyx_v_k + 1);
+  __pyx_t_15 = (__pyx_v_k + 1);
+  __pyx_t_13 = __pyx_v_m;
+  if (((__pyx_t_15 < __pyx_t_13) != 0)) {
+    __pyx_t_14 = __pyx_t_15;
+  } else {
+    __pyx_t_14 = __pyx_t_13;
+  }
+  __pyx_v_last = __pyx_t_14;
 
-  /* "cutadapt/_align.pyx":286
+  /* "cutadapt/_align.pyx":360
  * 		# Ukkonen's trick: index of the last cell that is less than k.
- * 		cdef int last = k + 1
+ * 		cdef int last = min(m, k + 1)
  * 		if start_in_ref:             # <<<<<<<<<<<<<<
  * 			last = m
  * 
@@ -2937,561 +4918,791 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = (__pyx_v_start_in_ref != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":287
- * 		cdef int last = k + 1
+    /* "cutadapt/_align.pyx":361
+ * 		cdef int last = min(m, k + 1)
  * 		if start_in_ref:
  * 			last = m             # <<<<<<<<<<<<<<
  * 
  * 		cdef int cost_diag
  */
     __pyx_v_last = __pyx_v_m;
-    goto __pyx_L23;
-  }
-  __pyx_L23:;
-
-  /* "cutadapt/_align.pyx":298
- * 
- * 		# iterate over columns
- * 		for j in range(min_n + 1, max_n + 1):             # <<<<<<<<<<<<<<
- * 			# remember first entry
- * 			tmp_entry = column[0]
- */
-  __pyx_t_15 = (__pyx_v_max_n + 1);
-  for (__pyx_t_13 = (__pyx_v_min_n + 1); __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
-    __pyx_v_j = __pyx_t_13;
 
-    /* "cutadapt/_align.pyx":300
- * 		for j in range(min_n + 1, max_n + 1):
- * 			# remember first entry
- * 			tmp_entry = column[0]             # <<<<<<<<<<<<<<
+    /* "cutadapt/_align.pyx":360
+ * 		# Ukkonen's trick: index of the last cell that is less than k.
+ * 		cdef int last = min(m, k + 1)
+ * 		if start_in_ref:             # <<<<<<<<<<<<<<
+ * 			last = m
  * 
- * 			# fill in first entry in this column
  */
-    __pyx_v_tmp_entry = (__pyx_v_column[0]);
+  }
 
-    /* "cutadapt/_align.pyx":303
+  /* "cutadapt/_align.pyx":371
+ * 		cdef _Entry tmp_entry
  * 
- * 			# fill in first entry in this column
- * 			if start_in_query:             # <<<<<<<<<<<<<<
- * 				column[0].origin = j
- * 			else:
- */
-    __pyx_t_8 = (__pyx_v_start_in_query != 0);
-    if (__pyx_t_8) {
-
-      /* "cutadapt/_align.pyx":304
- * 			# fill in first entry in this column
- * 			if start_in_query:
- * 				column[0].origin = j             # <<<<<<<<<<<<<<
- * 			else:
- * 				column[0].cost = j * INSERTION_COST
- */
-      (__pyx_v_column[0]).origin = __pyx_v_j;
-      goto __pyx_L26;
-    }
-    /*else*/ {
-
-      /* "cutadapt/_align.pyx":306
- * 				column[0].origin = j
- * 			else:
- * 				column[0].cost = j * INSERTION_COST             # <<<<<<<<<<<<<<
- * 			for i in range(1, last + 1):
- * 				if compare_ascii:
- */
-      (__pyx_v_column[0]).cost = (__pyx_v_j * 1);
-    }
-    __pyx_L26:;
-
-    /* "cutadapt/_align.pyx":307
- * 			else:
- * 				column[0].cost = j * INSERTION_COST
- * 			for i in range(1, last + 1):             # <<<<<<<<<<<<<<
- * 				if compare_ascii:
- * 					characters_equal = (s1[i-1] == s2[j-1])
+ * 		with nogil:             # <<<<<<<<<<<<<<
+ * 			# iterate over columns
+ * 			for j in range(min_n + 1, max_n + 1):
  */
-    __pyx_t_14 = (__pyx_v_last + 1);
-    for (__pyx_t_12 = 1; __pyx_t_12 < __pyx_t_14; __pyx_t_12+=1) {
-      __pyx_v_i = __pyx_t_12;
+  {
+      #ifdef WITH_THREAD
+      PyThreadState *_save;
+      Py_UNBLOCK_THREADS
+      #endif
+      /*try:*/ {
 
-      /* "cutadapt/_align.pyx":308
- * 				column[0].cost = j * INSERTION_COST
- * 			for i in range(1, last + 1):
- * 				if compare_ascii:             # <<<<<<<<<<<<<<
- * 					characters_equal = (s1[i-1] == s2[j-1])
- * 				else:
+        /* "cutadapt/_align.pyx":373
+ * 		with nogil:
+ * 			# iterate over columns
+ * 			for j in range(min_n + 1, max_n + 1):             # <<<<<<<<<<<<<<
+ * 				# remember first entry
+ * 				tmp_entry = column[0]
  */
-      __pyx_t_8 = (__pyx_v_compare_ascii != 0);
-      if (__pyx_t_8) {
+        __pyx_t_14 = (__pyx_v_max_n + 1);
+        for (__pyx_t_13 = (__pyx_v_min_n + 1); __pyx_t_13 < __pyx_t_14; __pyx_t_13+=1) {
+          __pyx_v_j = __pyx_t_13;
 
-        /* "cutadapt/_align.pyx":309
- * 			for i in range(1, last + 1):
- * 				if compare_ascii:
- * 					characters_equal = (s1[i-1] == s2[j-1])             # <<<<<<<<<<<<<<
- * 				else:
- * 					characters_equal = (s1[i-1] & s2[j-1]) != 0
+          /* "cutadapt/_align.pyx":375
+ * 			for j in range(min_n + 1, max_n + 1):
+ * 				# remember first entry
+ * 				tmp_entry = column[0]             # <<<<<<<<<<<<<<
+ * 
+ * 				# fill in first entry in this column
  */
-        __pyx_v_characters_equal = ((__pyx_v_s1[(__pyx_v_i - 1)]) == (__pyx_v_s2[(__pyx_v_j - 1)]));
-        goto __pyx_L29;
-      }
-      /*else*/ {
+          __pyx_v_tmp_entry = (__pyx_v_column[0]);
 
-        /* "cutadapt/_align.pyx":311
- * 					characters_equal = (s1[i-1] == s2[j-1])
+          /* "cutadapt/_align.pyx":378
+ * 
+ * 				# fill in first entry in this column
+ * 				if start_in_query:             # <<<<<<<<<<<<<<
+ * 					column[0].origin = j
  * 				else:
- * 					characters_equal = (s1[i-1] & s2[j-1]) != 0             # <<<<<<<<<<<<<<
- * 				if characters_equal:
- * 					# Characters match: This cannot be an indel.
  */
-        __pyx_v_characters_equal = (((__pyx_v_s1[(__pyx_v_i - 1)]) & (__pyx_v_s2[(__pyx_v_j - 1)])) != 0);
-      }
-      __pyx_L29:;
+          __pyx_t_8 = (__pyx_v_start_in_query != 0);
+          if (__pyx_t_8) {
 
-      /* "cutadapt/_align.pyx":312
+            /* "cutadapt/_align.pyx":379
+ * 				# fill in first entry in this column
+ * 				if start_in_query:
+ * 					column[0].origin = j             # <<<<<<<<<<<<<<
  * 				else:
- * 					characters_equal = (s1[i-1] & s2[j-1]) != 0
- * 				if characters_equal:             # <<<<<<<<<<<<<<
- * 					# Characters match: This cannot be an indel.
- * 					cost = tmp_entry.cost
+ * 					column[0].cost = j * self._insertion_cost
  */
-      __pyx_t_8 = (__pyx_v_characters_equal != 0);
-      if (__pyx_t_8) {
+            (__pyx_v_column[0]).origin = __pyx_v_j;
 
-        /* "cutadapt/_align.pyx":314
- * 				if characters_equal:
- * 					# Characters match: This cannot be an indel.
- * 					cost = tmp_entry.cost             # <<<<<<<<<<<<<<
- * 					origin = tmp_entry.origin
- * 					matches = tmp_entry.matches + 1
- */
-        __pyx_t_16 = __pyx_v_tmp_entry.cost;
-        __pyx_v_cost = __pyx_t_16;
-
-        /* "cutadapt/_align.pyx":315
- * 					# Characters match: This cannot be an indel.
- * 					cost = tmp_entry.cost
- * 					origin = tmp_entry.origin             # <<<<<<<<<<<<<<
- * 					matches = tmp_entry.matches + 1
+            /* "cutadapt/_align.pyx":378
+ * 
+ * 				# fill in first entry in this column
+ * 				if start_in_query:             # <<<<<<<<<<<<<<
+ * 					column[0].origin = j
  * 				else:
  */
-        __pyx_t_16 = __pyx_v_tmp_entry.origin;
-        __pyx_v_origin = __pyx_t_16;
+            goto __pyx_L32;
+          }
 
-        /* "cutadapt/_align.pyx":316
- * 					cost = tmp_entry.cost
- * 					origin = tmp_entry.origin
- * 					matches = tmp_entry.matches + 1             # <<<<<<<<<<<<<<
+          /* "cutadapt/_align.pyx":381
+ * 					column[0].origin = j
  * 				else:
- * 					# Characters do not match.
+ * 					column[0].cost = j * self._insertion_cost             # <<<<<<<<<<<<<<
+ * 				for i in range(1, last + 1):
+ * 					if compare_ascii:
  */
-        __pyx_v_matches = (__pyx_v_tmp_entry.matches + 1);
-        goto __pyx_L30;
-      }
-      /*else*/ {
+          /*else*/ {
+            (__pyx_v_column[0]).cost = (__pyx_v_j * __pyx_v_self->_insertion_cost);
+          }
+          __pyx_L32:;
 
-        /* "cutadapt/_align.pyx":319
+          /* "cutadapt/_align.pyx":382
  * 				else:
- * 					# Characters do not match.
- * 					cost_diag = tmp_entry.cost + 1             # <<<<<<<<<<<<<<
- * 					cost_deletion = column[i].cost + DELETION_COST
- * 					cost_insertion = column[i-1].cost + INSERTION_COST
+ * 					column[0].cost = j * self._insertion_cost
+ * 				for i in range(1, last + 1):             # <<<<<<<<<<<<<<
+ * 					if compare_ascii:
+ * 						characters_equal = (s1[i-1] == s2[j-1])
+ */
+          __pyx_t_15 = (__pyx_v_last + 1);
+          for (__pyx_t_12 = 1; __pyx_t_12 < __pyx_t_15; __pyx_t_12+=1) {
+            __pyx_v_i = __pyx_t_12;
+
+            /* "cutadapt/_align.pyx":383
+ * 					column[0].cost = j * self._insertion_cost
+ * 				for i in range(1, last + 1):
+ * 					if compare_ascii:             # <<<<<<<<<<<<<<
+ * 						characters_equal = (s1[i-1] == s2[j-1])
+ * 					else:
  */
-        __pyx_v_cost_diag = (__pyx_v_tmp_entry.cost + 1);
+            __pyx_t_8 = (__pyx_v_compare_ascii != 0);
+            if (__pyx_t_8) {
 
-        /* "cutadapt/_align.pyx":320
- * 					# Characters do not match.
- * 					cost_diag = tmp_entry.cost + 1
- * 					cost_deletion = column[i].cost + DELETION_COST             # <<<<<<<<<<<<<<
- * 					cost_insertion = column[i-1].cost + INSERTION_COST
- * 
+              /* "cutadapt/_align.pyx":384
+ * 				for i in range(1, last + 1):
+ * 					if compare_ascii:
+ * 						characters_equal = (s1[i-1] == s2[j-1])             # <<<<<<<<<<<<<<
+ * 					else:
+ * 						characters_equal = (s1[i-1] & s2[j-1]) != 0
  */
-        __pyx_v_cost_deletion = ((__pyx_v_column[__pyx_v_i]).cost + 1);
+              __pyx_v_characters_equal = ((__pyx_v_s1[(__pyx_v_i - 1)]) == (__pyx_v_s2[(__pyx_v_j - 1)]));
 
-        /* "cutadapt/_align.pyx":321
- * 					cost_diag = tmp_entry.cost + 1
- * 					cost_deletion = column[i].cost + DELETION_COST
- * 					cost_insertion = column[i-1].cost + INSERTION_COST             # <<<<<<<<<<<<<<
- * 
- * 					if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
+              /* "cutadapt/_align.pyx":383
+ * 					column[0].cost = j * self._insertion_cost
+ * 				for i in range(1, last + 1):
+ * 					if compare_ascii:             # <<<<<<<<<<<<<<
+ * 						characters_equal = (s1[i-1] == s2[j-1])
+ * 					else:
  */
-        __pyx_v_cost_insertion = ((__pyx_v_column[(__pyx_v_i - 1)]).cost + 1);
+              goto __pyx_L35;
+            }
 
-        /* "cutadapt/_align.pyx":323
- * 					cost_insertion = column[i-1].cost + INSERTION_COST
- * 
- * 					if cost_diag <= cost_deletion and cost_diag <= cost_insertion:             # <<<<<<<<<<<<<<
- * 						# MISMATCH
- * 						cost = cost_diag
+            /* "cutadapt/_align.pyx":386
+ * 						characters_equal = (s1[i-1] == s2[j-1])
+ * 					else:
+ * 						characters_equal = (s1[i-1] & s2[j-1]) != 0             # <<<<<<<<<<<<<<
+ * 					if characters_equal:
+ * 						# Characters match: This cannot be an indel.
  */
-        __pyx_t_11 = ((__pyx_v_cost_diag <= __pyx_v_cost_deletion) != 0);
-        if (__pyx_t_11) {
-        } else {
-          __pyx_t_8 = __pyx_t_11;
-          goto __pyx_L32_bool_binop_done;
-        }
-        __pyx_t_11 = ((__pyx_v_cost_diag <= __pyx_v_cost_insertion) != 0);
-        __pyx_t_8 = __pyx_t_11;
-        __pyx_L32_bool_binop_done:;
-        if (__pyx_t_8) {
+            /*else*/ {
+              __pyx_v_characters_equal = (((__pyx_v_s1[(__pyx_v_i - 1)]) & (__pyx_v_s2[(__pyx_v_j - 1)])) != 0);
+            }
+            __pyx_L35:;
 
-          /* "cutadapt/_align.pyx":325
- * 					if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
- * 						# MISMATCH
- * 						cost = cost_diag             # <<<<<<<<<<<<<<
+            /* "cutadapt/_align.pyx":387
+ * 					else:
+ * 						characters_equal = (s1[i-1] & s2[j-1]) != 0
+ * 					if characters_equal:             # <<<<<<<<<<<<<<
+ * 						# Characters match: This cannot be an indel.
+ * 						cost = tmp_entry.cost
+ */
+            __pyx_t_8 = (__pyx_v_characters_equal != 0);
+            if (__pyx_t_8) {
+
+              /* "cutadapt/_align.pyx":389
+ * 					if characters_equal:
+ * 						# Characters match: This cannot be an indel.
+ * 						cost = tmp_entry.cost             # <<<<<<<<<<<<<<
  * 						origin = tmp_entry.origin
- * 						matches = tmp_entry.matches
+ * 						matches = tmp_entry.matches + 1
  */
-          __pyx_v_cost = __pyx_v_cost_diag;
+              __pyx_t_16 = __pyx_v_tmp_entry.cost;
+              __pyx_v_cost = __pyx_t_16;
 
-          /* "cutadapt/_align.pyx":326
- * 						# MISMATCH
- * 						cost = cost_diag
+              /* "cutadapt/_align.pyx":390
+ * 						# Characters match: This cannot be an indel.
+ * 						cost = tmp_entry.cost
  * 						origin = tmp_entry.origin             # <<<<<<<<<<<<<<
- * 						matches = tmp_entry.matches
- * 					elif cost_insertion <= cost_deletion:
- */
-          __pyx_t_16 = __pyx_v_tmp_entry.origin;
-          __pyx_v_origin = __pyx_t_16;
-
-          /* "cutadapt/_align.pyx":327
- * 						cost = cost_diag
- * 						origin = tmp_entry.origin
- * 						matches = tmp_entry.matches             # <<<<<<<<<<<<<<
- * 					elif cost_insertion <= cost_deletion:
- * 						# INSERTION
+ * 						matches = tmp_entry.matches + 1
+ * 					else:
  */
-          __pyx_t_16 = __pyx_v_tmp_entry.matches;
-          __pyx_v_matches = __pyx_t_16;
-          goto __pyx_L31;
-        }
+              __pyx_t_16 = __pyx_v_tmp_entry.origin;
+              __pyx_v_origin = __pyx_t_16;
 
-        /* "cutadapt/_align.pyx":328
+              /* "cutadapt/_align.pyx":391
+ * 						cost = tmp_entry.cost
  * 						origin = tmp_entry.origin
- * 						matches = tmp_entry.matches
- * 					elif cost_insertion <= cost_deletion:             # <<<<<<<<<<<<<<
- * 						# INSERTION
- * 						cost = cost_insertion
- */
-        __pyx_t_8 = ((__pyx_v_cost_insertion <= __pyx_v_cost_deletion) != 0);
-        if (__pyx_t_8) {
-
-          /* "cutadapt/_align.pyx":330
- * 					elif cost_insertion <= cost_deletion:
- * 						# INSERTION
- * 						cost = cost_insertion             # <<<<<<<<<<<<<<
- * 						origin = column[i-1].origin
- * 						matches = column[i-1].matches
- */
-          __pyx_v_cost = __pyx_v_cost_insertion;
-
-          /* "cutadapt/_align.pyx":331
- * 						# INSERTION
- * 						cost = cost_insertion
- * 						origin = column[i-1].origin             # <<<<<<<<<<<<<<
- * 						matches = column[i-1].matches
+ * 						matches = tmp_entry.matches + 1             # <<<<<<<<<<<<<<
  * 					else:
+ * 						# Characters do not match.
  */
-          __pyx_t_16 = (__pyx_v_column[(__pyx_v_i - 1)]).origin;
-          __pyx_v_origin = __pyx_t_16;
+              __pyx_v_matches = (__pyx_v_tmp_entry.matches + 1);
 
-          /* "cutadapt/_align.pyx":332
- * 						cost = cost_insertion
- * 						origin = column[i-1].origin
- * 						matches = column[i-1].matches             # <<<<<<<<<<<<<<
+              /* "cutadapt/_align.pyx":387
  * 					else:
- * 						# DELETION
+ * 						characters_equal = (s1[i-1] & s2[j-1]) != 0
+ * 					if characters_equal:             # <<<<<<<<<<<<<<
+ * 						# Characters match: This cannot be an indel.
+ * 						cost = tmp_entry.cost
  */
-          __pyx_t_16 = (__pyx_v_column[(__pyx_v_i - 1)]).matches;
-          __pyx_v_matches = __pyx_t_16;
-          goto __pyx_L31;
-        }
-        /*else*/ {
+              goto __pyx_L36;
+            }
 
-          /* "cutadapt/_align.pyx":335
+            /* "cutadapt/_align.pyx":394
  * 					else:
- * 						# DELETION
- * 						cost = cost_deletion             # <<<<<<<<<<<<<<
- * 						origin = column[i].origin
- * 						matches = column[i].matches
- */
-          __pyx_v_cost = __pyx_v_cost_deletion;
-
-          /* "cutadapt/_align.pyx":336
- * 						# DELETION
- * 						cost = cost_deletion
- * 						origin = column[i].origin             # <<<<<<<<<<<<<<
- * 						matches = column[i].matches
- * 
- */
-          __pyx_t_16 = (__pyx_v_column[__pyx_v_i]).origin;
-          __pyx_v_origin = __pyx_t_16;
-
-          /* "cutadapt/_align.pyx":337
- * 						cost = cost_deletion
- * 						origin = column[i].origin
- * 						matches = column[i].matches             # <<<<<<<<<<<<<<
- * 
- * 				# remember current cell for next iteration
- */
-          __pyx_t_16 = (__pyx_v_column[__pyx_v_i]).matches;
-          __pyx_v_matches = __pyx_t_16;
-        }
-        __pyx_L31:;
-      }
-      __pyx_L30:;
+ * 						# Characters do not match.
+ * 						cost_diag = tmp_entry.cost + 1             # <<<<<<<<<<<<<<
+ * 						cost_deletion = column[i].cost + self._deletion_cost
+ * 						cost_insertion = column[i-1].cost + self._insertion_cost
+ */
+            /*else*/ {
+              __pyx_v_cost_diag = (__pyx_v_tmp_entry.cost + 1);
+
+              /* "cutadapt/_align.pyx":395
+ * 						# Characters do not match.
+ * 						cost_diag = tmp_entry.cost + 1
+ * 						cost_deletion = column[i].cost + self._deletion_cost             # <<<<<<<<<<<<<<
+ * 						cost_insertion = column[i-1].cost + self._insertion_cost
+ * 
+ */
+              __pyx_v_cost_deletion = ((__pyx_v_column[__pyx_v_i]).cost + __pyx_v_self->_deletion_cost);
+
+              /* "cutadapt/_align.pyx":396
+ * 						cost_diag = tmp_entry.cost + 1
+ * 						cost_deletion = column[i].cost + self._deletion_cost
+ * 						cost_insertion = column[i-1].cost + self._insertion_cost             # <<<<<<<<<<<<<<
+ * 
+ * 						if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
+ */
+              __pyx_v_cost_insertion = ((__pyx_v_column[(__pyx_v_i - 1)]).cost + __pyx_v_self->_insertion_cost);
+
+              /* "cutadapt/_align.pyx":398
+ * 						cost_insertion = column[i-1].cost + self._insertion_cost
+ * 
+ * 						if cost_diag <= cost_deletion and cost_diag <= cost_insertion:             # <<<<<<<<<<<<<<
+ * 							# MISMATCH
+ * 							cost = cost_diag
+ */
+              __pyx_t_11 = ((__pyx_v_cost_diag <= __pyx_v_cost_deletion) != 0);
+              if (__pyx_t_11) {
+              } else {
+                __pyx_t_8 = __pyx_t_11;
+                goto __pyx_L38_bool_binop_done;
+              }
+              __pyx_t_11 = ((__pyx_v_cost_diag <= __pyx_v_cost_insertion) != 0);
+              __pyx_t_8 = __pyx_t_11;
+              __pyx_L38_bool_binop_done:;
+              if (__pyx_t_8) {
+
+                /* "cutadapt/_align.pyx":400
+ * 						if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
+ * 							# MISMATCH
+ * 							cost = cost_diag             # <<<<<<<<<<<<<<
+ * 							origin = tmp_entry.origin
+ * 							matches = tmp_entry.matches
+ */
+                __pyx_v_cost = __pyx_v_cost_diag;
+
+                /* "cutadapt/_align.pyx":401
+ * 							# MISMATCH
+ * 							cost = cost_diag
+ * 							origin = tmp_entry.origin             # <<<<<<<<<<<<<<
+ * 							matches = tmp_entry.matches
+ * 						elif cost_insertion <= cost_deletion:
+ */
+                __pyx_t_16 = __pyx_v_tmp_entry.origin;
+                __pyx_v_origin = __pyx_t_16;
+
+                /* "cutadapt/_align.pyx":402
+ * 							cost = cost_diag
+ * 							origin = tmp_entry.origin
+ * 							matches = tmp_entry.matches             # <<<<<<<<<<<<<<
+ * 						elif cost_insertion <= cost_deletion:
+ * 							# INSERTION
+ */
+                __pyx_t_16 = __pyx_v_tmp_entry.matches;
+                __pyx_v_matches = __pyx_t_16;
+
+                /* "cutadapt/_align.pyx":398
+ * 						cost_insertion = column[i-1].cost + self._insertion_cost
+ * 
+ * 						if cost_diag <= cost_deletion and cost_diag <= cost_insertion:             # <<<<<<<<<<<<<<
+ * 							# MISMATCH
+ * 							cost = cost_diag
+ */
+                goto __pyx_L37;
+              }
+
+              /* "cutadapt/_align.pyx":403
+ * 							origin = tmp_entry.origin
+ * 							matches = tmp_entry.matches
+ * 						elif cost_insertion <= cost_deletion:             # <<<<<<<<<<<<<<
+ * 							# INSERTION
+ * 							cost = cost_insertion
+ */
+              __pyx_t_8 = ((__pyx_v_cost_insertion <= __pyx_v_cost_deletion) != 0);
+              if (__pyx_t_8) {
+
+                /* "cutadapt/_align.pyx":405
+ * 						elif cost_insertion <= cost_deletion:
+ * 							# INSERTION
+ * 							cost = cost_insertion             # <<<<<<<<<<<<<<
+ * 							origin = column[i-1].origin
+ * 							matches = column[i-1].matches
+ */
+                __pyx_v_cost = __pyx_v_cost_insertion;
+
+                /* "cutadapt/_align.pyx":406
+ * 							# INSERTION
+ * 							cost = cost_insertion
+ * 							origin = column[i-1].origin             # <<<<<<<<<<<<<<
+ * 							matches = column[i-1].matches
+ * 						else:
+ */
+                __pyx_t_16 = (__pyx_v_column[(__pyx_v_i - 1)]).origin;
+                __pyx_v_origin = __pyx_t_16;
+
+                /* "cutadapt/_align.pyx":407
+ * 							cost = cost_insertion
+ * 							origin = column[i-1].origin
+ * 							matches = column[i-1].matches             # <<<<<<<<<<<<<<
+ * 						else:
+ * 							# DELETION
+ */
+                __pyx_t_16 = (__pyx_v_column[(__pyx_v_i - 1)]).matches;
+                __pyx_v_matches = __pyx_t_16;
+
+                /* "cutadapt/_align.pyx":403
+ * 							origin = tmp_entry.origin
+ * 							matches = tmp_entry.matches
+ * 						elif cost_insertion <= cost_deletion:             # <<<<<<<<<<<<<<
+ * 							# INSERTION
+ * 							cost = cost_insertion
+ */
+                goto __pyx_L37;
+              }
+
+              /* "cutadapt/_align.pyx":410
+ * 						else:
+ * 							# DELETION
+ * 							cost = cost_deletion             # <<<<<<<<<<<<<<
+ * 							origin = column[i].origin
+ * 							matches = column[i].matches
+ */
+              /*else*/ {
+                __pyx_v_cost = __pyx_v_cost_deletion;
+
+                /* "cutadapt/_align.pyx":411
+ * 							# DELETION
+ * 							cost = cost_deletion
+ * 							origin = column[i].origin             # <<<<<<<<<<<<<<
+ * 							matches = column[i].matches
+ * 
+ */
+                __pyx_t_16 = (__pyx_v_column[__pyx_v_i]).origin;
+                __pyx_v_origin = __pyx_t_16;
+
+                /* "cutadapt/_align.pyx":412
+ * 							cost = cost_deletion
+ * 							origin = column[i].origin
+ * 							matches = column[i].matches             # <<<<<<<<<<<<<<
+ * 
+ * 					# remember current cell for next iteration
+ */
+                __pyx_t_16 = (__pyx_v_column[__pyx_v_i]).matches;
+                __pyx_v_matches = __pyx_t_16;
+              }
+              __pyx_L37:;
+            }
+            __pyx_L36:;
 
-      /* "cutadapt/_align.pyx":340
+            /* "cutadapt/_align.pyx":415
  * 
- * 				# remember current cell for next iteration
- * 				tmp_entry = column[i]             # <<<<<<<<<<<<<<
+ * 					# remember current cell for next iteration
+ * 					tmp_entry = column[i]             # <<<<<<<<<<<<<<
  * 
- * 				column[i].cost = cost
+ * 					column[i].cost = cost
  */
-      __pyx_v_tmp_entry = (__pyx_v_column[__pyx_v_i]);
+            __pyx_v_tmp_entry = (__pyx_v_column[__pyx_v_i]);
 
-      /* "cutadapt/_align.pyx":342
- * 				tmp_entry = column[i]
+            /* "cutadapt/_align.pyx":417
+ * 					tmp_entry = column[i]
  * 
- * 				column[i].cost = cost             # <<<<<<<<<<<<<<
- * 				column[i].origin = origin
- * 				column[i].matches = matches
+ * 					column[i].cost = cost             # <<<<<<<<<<<<<<
+ * 					column[i].origin = origin
+ * 					column[i].matches = matches
  */
-      (__pyx_v_column[__pyx_v_i]).cost = __pyx_v_cost;
+            (__pyx_v_column[__pyx_v_i]).cost = __pyx_v_cost;
 
-      /* "cutadapt/_align.pyx":343
+            /* "cutadapt/_align.pyx":418
  * 
- * 				column[i].cost = cost
- * 				column[i].origin = origin             # <<<<<<<<<<<<<<
- * 				column[i].matches = matches
- * 			while last >= 0 and column[last].cost > k:
- */
-      (__pyx_v_column[__pyx_v_i]).origin = __pyx_v_origin;
-
-      /* "cutadapt/_align.pyx":344
- * 				column[i].cost = cost
- * 				column[i].origin = origin
- * 				column[i].matches = matches             # <<<<<<<<<<<<<<
- * 			while last >= 0 and column[last].cost > k:
- * 				last -= 1
- */
-      (__pyx_v_column[__pyx_v_i]).matches = __pyx_v_matches;
-    }
-
-    /* "cutadapt/_align.pyx":345
- * 				column[i].origin = origin
- * 				column[i].matches = matches
- * 			while last >= 0 and column[last].cost > k:             # <<<<<<<<<<<<<<
- * 				last -= 1
- * 			# last can be -1 here, but will be incremented next.
- */
-    while (1) {
-      __pyx_t_11 = ((__pyx_v_last >= 0) != 0);
-      if (__pyx_t_11) {
-      } else {
-        __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L36_bool_binop_done;
-      }
-      __pyx_t_11 = (((__pyx_v_column[__pyx_v_last]).cost > __pyx_v_k) != 0);
-      __pyx_t_8 = __pyx_t_11;
-      __pyx_L36_bool_binop_done:;
-      if (!__pyx_t_8) break;
-
-      /* "cutadapt/_align.pyx":346
- * 				column[i].matches = matches
- * 			while last >= 0 and column[last].cost > k:
- * 				last -= 1             # <<<<<<<<<<<<<<
- * 			# last can be -1 here, but will be incremented next.
- * 			# TODO if last is -1, can we stop searching?
+ * 					column[i].cost = cost
+ * 					column[i].origin = origin             # <<<<<<<<<<<<<<
+ * 					column[i].matches = matches
+ * 				if self.debug:
  */
-      __pyx_v_last = (__pyx_v_last - 1);
-    }
-
-    /* "cutadapt/_align.pyx":349
- * 			# last can be -1 here, but will be incremented next.
- * 			# TODO if last is -1, can we stop searching?
- * 			if last < m:             # <<<<<<<<<<<<<<
- * 				last += 1
- * 			elif stop_in_query:
- */
-    __pyx_t_8 = ((__pyx_v_last < __pyx_v_m) != 0);
-    if (__pyx_t_8) {
+            (__pyx_v_column[__pyx_v_i]).origin = __pyx_v_origin;
 
-      /* "cutadapt/_align.pyx":350
- * 			# TODO if last is -1, can we stop searching?
- * 			if last < m:
- * 				last += 1             # <<<<<<<<<<<<<<
- * 			elif stop_in_query:
- * 				# Found a match. If requested, find best match in last row.
+            /* "cutadapt/_align.pyx":419
+ * 					column[i].cost = cost
+ * 					column[i].origin = origin
+ * 					column[i].matches = matches             # <<<<<<<<<<<<<<
+ * 				if self.debug:
+ * 					with gil:
  */
-      __pyx_v_last = (__pyx_v_last + 1);
-      goto __pyx_L38;
-    }
+            (__pyx_v_column[__pyx_v_i]).matches = __pyx_v_matches;
+          }
 
-    /* "cutadapt/_align.pyx":351
- * 			if last < m:
- * 				last += 1
- * 			elif stop_in_query:             # <<<<<<<<<<<<<<
- * 				# Found a match. If requested, find best match in last row.
- * 				# length of the aligned part of the reference
+          /* "cutadapt/_align.pyx":420
+ * 					column[i].origin = origin
+ * 					column[i].matches = matches
+ * 				if self.debug:             # <<<<<<<<<<<<<<
+ * 					with gil:
+ * 						for i in range(last + 1):
  */
-    __pyx_t_8 = (__pyx_v_stop_in_query != 0);
-    if (__pyx_t_8) {
+          __pyx_t_8 = (__pyx_v_self->debug != 0);
+          if (__pyx_t_8) {
 
-      /* "cutadapt/_align.pyx":354
- * 				# Found a match. If requested, find best match in last row.
- * 				# length of the aligned part of the reference
- * 				length = m + min(column[m].origin, 0)             # <<<<<<<<<<<<<<
- * 				cost = column[m].cost
- * 				matches = column[m].matches
+            /* "cutadapt/_align.pyx":421
+ * 					column[i].matches = matches
+ * 				if self.debug:
+ * 					with gil:             # <<<<<<<<<<<<<<
+ * 						for i in range(last + 1):
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)
  */
-      __pyx_t_14 = 0;
-      __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).origin;
-      if (((__pyx_t_14 < __pyx_t_12) != 0)) {
-        __pyx_t_17 = __pyx_t_14;
-      } else {
-        __pyx_t_17 = __pyx_t_12;
-      }
-      __pyx_v_length = (__pyx_v_m + __pyx_t_17);
+            {
+                #ifdef WITH_THREAD
+                PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
+                #endif
+                /*try:*/ {
+
+                  /* "cutadapt/_align.pyx":422
+ * 				if self.debug:
+ * 					with gil:
+ * 						for i in range(last + 1):             # <<<<<<<<<<<<<<
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)
+ * 				while last >= 0 and column[last].cost > k:
+ */
+                  __pyx_t_15 = (__pyx_v_last + 1);
+                  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_15; __pyx_t_12+=1) {
+                    __pyx_v_i = __pyx_t_12;
+
+                    /* "cutadapt/_align.pyx":423
+ * 					with gil:
+ * 						for i in range(last + 1):
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)             # <<<<<<<<<<<<<<
+ * 				while last >= 0 and column[last].cost > k:
+ * 					last -= 1
+ */
+                    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_dpmatrix, __pyx_n_s_set_entry); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_2);
+                    __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_20);
+                    __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_j); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_18);
+                    __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_column[__pyx_v_i]).cost); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_9);
+                    __pyx_t_10 = NULL;
+                    __pyx_t_5 = 0;
+                    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
+                      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
+                      if (likely(__pyx_t_10)) {
+                        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
+                        __Pyx_INCREF(__pyx_t_10);
+                        __Pyx_INCREF(function);
+                        __Pyx_DECREF_SET(__pyx_t_2, function);
+                        __pyx_t_5 = 1;
+                      }
+                    }
+                    __pyx_t_19 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_19);
+                    if (__pyx_t_10) {
+                      __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); __pyx_t_10 = NULL;
+                    }
+                    __Pyx_GIVEREF(__pyx_t_20);
+                    PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_5, __pyx_t_20);
+                    __Pyx_GIVEREF(__pyx_t_18);
+                    PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_5, __pyx_t_18);
+                    __Pyx_GIVEREF(__pyx_t_9);
+                    PyTuple_SET_ITEM(__pyx_t_19, 2+__pyx_t_5, __pyx_t_9);
+                    __pyx_t_20 = 0;
+                    __pyx_t_18 = 0;
+                    __pyx_t_9 = 0;
+                    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L44_error;}
+                    __Pyx_GOTREF(__pyx_t_3);
+                    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
+                    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+                    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+                  }
+                }
 
-      /* "cutadapt/_align.pyx":355
- * 				# length of the aligned part of the reference
- * 				length = m + min(column[m].origin, 0)
- * 				cost = column[m].cost             # <<<<<<<<<<<<<<
- * 				matches = column[m].matches
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
- */
-      __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).cost;
-      __pyx_v_cost = __pyx_t_12;
+                /* "cutadapt/_align.pyx":421
+ * 					column[i].matches = matches
+ * 				if self.debug:
+ * 					with gil:             # <<<<<<<<<<<<<<
+ * 						for i in range(last + 1):
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)
+ */
+                /*finally:*/ {
+                  /*normal exit:*/{
+                    #ifdef WITH_THREAD
+                    PyGILState_Release(__pyx_gilstate_save);
+                    #endif
+                    goto __pyx_L45;
+                  }
+                  __pyx_L44_error: {
+                    #ifdef WITH_THREAD
+                    PyGILState_Release(__pyx_gilstate_save);
+                    #endif
+                    goto __pyx_L28_error;
+                  }
+                  __pyx_L45:;
+                }
+            }
 
-      /* "cutadapt/_align.pyx":356
- * 				length = m + min(column[m].origin, 0)
- * 				cost = column[m].cost
- * 				matches = column[m].matches             # <<<<<<<<<<<<<<
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
- * 					# update
+            /* "cutadapt/_align.pyx":420
+ * 					column[i].origin = origin
+ * 					column[i].matches = matches
+ * 				if self.debug:             # <<<<<<<<<<<<<<
+ * 					with gil:
+ * 						for i in range(last + 1):
  */
-      __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).matches;
-      __pyx_v_matches = __pyx_t_12;
+          }
 
-      /* "cutadapt/_align.pyx":357
- * 				cost = column[m].cost
- * 				matches = column[m].matches
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
- * 					# update
- * 					best.matches = matches
+          /* "cutadapt/_align.pyx":424
+ * 						for i in range(last + 1):
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)
+ * 				while last >= 0 and column[last].cost > k:             # <<<<<<<<<<<<<<
+ * 					last -= 1
+ * 				# last can be -1 here, but will be incremented next.
  */
-      __pyx_t_11 = ((__pyx_v_length >= __pyx_v_self->min_overlap) != 0);
-      if (__pyx_t_11) {
-      } else {
-        __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L40_bool_binop_done;
-      }
-      __pyx_t_11 = ((__pyx_v_cost <= (__pyx_v_length * __pyx_v_max_error_rate)) != 0);
-      if (__pyx_t_11) {
-      } else {
-        __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L40_bool_binop_done;
-      }
-      __pyx_t_11 = ((__pyx_v_matches > __pyx_v_best.matches) != 0);
-      if (!__pyx_t_11) {
-      } else {
-        __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L40_bool_binop_done;
-      }
-      __pyx_t_11 = ((__pyx_v_matches == __pyx_v_best.matches) != 0);
-      if (__pyx_t_11) {
-      } else {
-        __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L40_bool_binop_done;
-      }
-      __pyx_t_11 = ((__pyx_v_cost < __pyx_v_best.cost) != 0);
-      __pyx_t_8 = __pyx_t_11;
-      __pyx_L40_bool_binop_done:;
-      if (__pyx_t_8) {
+          while (1) {
+            __pyx_t_11 = ((__pyx_v_last >= 0) != 0);
+            if (__pyx_t_11) {
+            } else {
+              __pyx_t_8 = __pyx_t_11;
+              goto __pyx_L50_bool_binop_done;
+            }
+            __pyx_t_11 = (((__pyx_v_column[__pyx_v_last]).cost > __pyx_v_k) != 0);
+            __pyx_t_8 = __pyx_t_11;
+            __pyx_L50_bool_binop_done:;
+            if (!__pyx_t_8) break;
+
+            /* "cutadapt/_align.pyx":425
+ * 							self._dpmatrix.set_entry(i, j, column[i].cost)
+ * 				while last >= 0 and column[last].cost > k:
+ * 					last -= 1             # <<<<<<<<<<<<<<
+ * 				# last can be -1 here, but will be incremented next.
+ * 				# TODO if last is -1, can we stop searching?
+ */
+            __pyx_v_last = (__pyx_v_last - 1);
+          }
 
-        /* "cutadapt/_align.pyx":359
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
- * 					# update
- * 					best.matches = matches             # <<<<<<<<<<<<<<
- * 					best.cost = cost
- * 					best.origin = column[m].origin
- */
-        __pyx_v_best.matches = __pyx_v_matches;
+          /* "cutadapt/_align.pyx":428
+ * 				# last can be -1 here, but will be incremented next.
+ * 				# TODO if last is -1, can we stop searching?
+ * 				if last < m:             # <<<<<<<<<<<<<<
+ * 					last += 1
+ * 				elif stop_in_query:
+ */
+          __pyx_t_8 = ((__pyx_v_last < __pyx_v_m) != 0);
+          if (__pyx_t_8) {
+
+            /* "cutadapt/_align.pyx":429
+ * 				# TODO if last is -1, can we stop searching?
+ * 				if last < m:
+ * 					last += 1             # <<<<<<<<<<<<<<
+ * 				elif stop_in_query:
+ * 					# Found a match. If requested, find best match in last row.
+ */
+            __pyx_v_last = (__pyx_v_last + 1);
+
+            /* "cutadapt/_align.pyx":428
+ * 				# last can be -1 here, but will be incremented next.
+ * 				# TODO if last is -1, can we stop searching?
+ * 				if last < m:             # <<<<<<<<<<<<<<
+ * 					last += 1
+ * 				elif stop_in_query:
+ */
+            goto __pyx_L52;
+          }
 
-        /* "cutadapt/_align.pyx":360
- * 					# update
- * 					best.matches = matches
- * 					best.cost = cost             # <<<<<<<<<<<<<<
- * 					best.origin = column[m].origin
- * 					best.ref_stop = m
+          /* "cutadapt/_align.pyx":430
+ * 				if last < m:
+ * 					last += 1
+ * 				elif stop_in_query:             # <<<<<<<<<<<<<<
+ * 					# Found a match. If requested, find best match in last row.
+ * 					# length of the aligned part of the reference
+ */
+          __pyx_t_8 = (__pyx_v_stop_in_query != 0);
+          if (__pyx_t_8) {
+
+            /* "cutadapt/_align.pyx":433
+ * 					# Found a match. If requested, find best match in last row.
+ * 					# length of the aligned part of the reference
+ * 					length = m + min(column[m].origin, 0)             # <<<<<<<<<<<<<<
+ * 					cost = column[m].cost
+ * 					matches = column[m].matches
+ */
+            __pyx_t_15 = 0;
+            __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).origin;
+            if (((__pyx_t_15 < __pyx_t_12) != 0)) {
+              __pyx_t_17 = __pyx_t_15;
+            } else {
+              __pyx_t_17 = __pyx_t_12;
+            }
+            __pyx_v_length = (__pyx_v_m + __pyx_t_17);
+
+            /* "cutadapt/_align.pyx":434
+ * 					# length of the aligned part of the reference
+ * 					length = m + min(column[m].origin, 0)
+ * 					cost = column[m].cost             # <<<<<<<<<<<<<<
+ * 					matches = column[m].matches
+ * 					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+ */
+            __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).cost;
+            __pyx_v_cost = __pyx_t_12;
+
+            /* "cutadapt/_align.pyx":435
+ * 					length = m + min(column[m].origin, 0)
+ * 					cost = column[m].cost
+ * 					matches = column[m].matches             # <<<<<<<<<<<<<<
+ * 					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+ * 						# update
+ */
+            __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).matches;
+            __pyx_v_matches = __pyx_t_12;
+
+            /* "cutadapt/_align.pyx":436
+ * 					cost = column[m].cost
+ * 					matches = column[m].matches
+ * 					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
+ * 						# update
+ * 						best.matches = matches
+ */
+            __pyx_t_11 = ((__pyx_v_length >= __pyx_v_self->_min_overlap) != 0);
+            if (__pyx_t_11) {
+            } else {
+              __pyx_t_8 = __pyx_t_11;
+              goto __pyx_L54_bool_binop_done;
+            }
+            __pyx_t_11 = ((__pyx_v_cost <= (__pyx_v_length * __pyx_v_max_error_rate)) != 0);
+            if (__pyx_t_11) {
+            } else {
+              __pyx_t_8 = __pyx_t_11;
+              goto __pyx_L54_bool_binop_done;
+            }
+            __pyx_t_11 = ((__pyx_v_matches > __pyx_v_best.matches) != 0);
+            if (!__pyx_t_11) {
+            } else {
+              __pyx_t_8 = __pyx_t_11;
+              goto __pyx_L54_bool_binop_done;
+            }
+            __pyx_t_11 = ((__pyx_v_matches == __pyx_v_best.matches) != 0);
+            if (__pyx_t_11) {
+            } else {
+              __pyx_t_8 = __pyx_t_11;
+              goto __pyx_L54_bool_binop_done;
+            }
+            __pyx_t_11 = ((__pyx_v_cost < __pyx_v_best.cost) != 0);
+            __pyx_t_8 = __pyx_t_11;
+            __pyx_L54_bool_binop_done:;
+            if (__pyx_t_8) {
+
+              /* "cutadapt/_align.pyx":438
+ * 					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+ * 						# update
+ * 						best.matches = matches             # <<<<<<<<<<<<<<
+ * 						best.cost = cost
+ * 						best.origin = column[m].origin
+ */
+              __pyx_v_best.matches = __pyx_v_matches;
+
+              /* "cutadapt/_align.pyx":439
+ * 						# update
+ * 						best.matches = matches
+ * 						best.cost = cost             # <<<<<<<<<<<<<<
+ * 						best.origin = column[m].origin
+ * 						best.ref_stop = m
+ */
+              __pyx_v_best.cost = __pyx_v_cost;
+
+              /* "cutadapt/_align.pyx":440
+ * 						best.matches = matches
+ * 						best.cost = cost
+ * 						best.origin = column[m].origin             # <<<<<<<<<<<<<<
+ * 						best.ref_stop = m
+ * 						best.query_stop = j
+ */
+              __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).origin;
+              __pyx_v_best.origin = __pyx_t_12;
+
+              /* "cutadapt/_align.pyx":441
+ * 						best.cost = cost
+ * 						best.origin = column[m].origin
+ * 						best.ref_stop = m             # <<<<<<<<<<<<<<
+ * 						best.query_stop = j
+ * 						if cost == 0 and matches == m:
+ */
+              __pyx_v_best.ref_stop = __pyx_v_m;
+
+              /* "cutadapt/_align.pyx":442
+ * 						best.origin = column[m].origin
+ * 						best.ref_stop = m
+ * 						best.query_stop = j             # <<<<<<<<<<<<<<
+ * 						if cost == 0 and matches == m:
+ * 							# exact match, stop early
+ */
+              __pyx_v_best.query_stop = __pyx_v_j;
+
+              /* "cutadapt/_align.pyx":443
+ * 						best.ref_stop = m
+ * 						best.query_stop = j
+ * 						if cost == 0 and matches == m:             # <<<<<<<<<<<<<<
+ * 							# exact match, stop early
+ * 							break
+ */
+              __pyx_t_11 = ((__pyx_v_cost == 0) != 0);
+              if (__pyx_t_11) {
+              } else {
+                __pyx_t_8 = __pyx_t_11;
+                goto __pyx_L60_bool_binop_done;
+              }
+              __pyx_t_11 = ((__pyx_v_matches == __pyx_v_m) != 0);
+              __pyx_t_8 = __pyx_t_11;
+              __pyx_L60_bool_binop_done:;
+              if (__pyx_t_8) {
+
+                /* "cutadapt/_align.pyx":445
+ * 						if cost == 0 and matches == m:
+ * 							# exact match, stop early
+ * 							break             # <<<<<<<<<<<<<<
+ * 				# column finished
+ * 
+ */
+                goto __pyx_L31_break;
+
+                /* "cutadapt/_align.pyx":443
+ * 						best.ref_stop = m
+ * 						best.query_stop = j
+ * 						if cost == 0 and matches == m:             # <<<<<<<<<<<<<<
+ * 							# exact match, stop early
+ * 							break
+ */
+              }
+
+              /* "cutadapt/_align.pyx":436
+ * 					cost = column[m].cost
+ * 					matches = column[m].matches
+ * 					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
+ * 						# update
+ * 						best.matches = matches
  */
-        __pyx_v_best.cost = __pyx_v_cost;
+            }
 
-        /* "cutadapt/_align.pyx":361
- * 					best.matches = matches
- * 					best.cost = cost
- * 					best.origin = column[m].origin             # <<<<<<<<<<<<<<
- * 					best.ref_stop = m
- * 					best.query_stop = j
+            /* "cutadapt/_align.pyx":430
+ * 				if last < m:
+ * 					last += 1
+ * 				elif stop_in_query:             # <<<<<<<<<<<<<<
+ * 					# Found a match. If requested, find best match in last row.
+ * 					# length of the aligned part of the reference
  */
-        __pyx_t_12 = (__pyx_v_column[__pyx_v_m]).origin;
-        __pyx_v_best.origin = __pyx_t_12;
-
-        /* "cutadapt/_align.pyx":362
- * 					best.cost = cost
- * 					best.origin = column[m].origin
- * 					best.ref_stop = m             # <<<<<<<<<<<<<<
- * 					best.query_stop = j
- * 					if cost == 0 and matches == m:
- */
-        __pyx_v_best.ref_stop = __pyx_v_m;
-
-        /* "cutadapt/_align.pyx":363
- * 					best.origin = column[m].origin
- * 					best.ref_stop = m
- * 					best.query_stop = j             # <<<<<<<<<<<<<<
- * 					if cost == 0 and matches == m:
- * 						# exact match, stop early
- */
-        __pyx_v_best.query_stop = __pyx_v_j;
-
-        /* "cutadapt/_align.pyx":364
- * 					best.ref_stop = m
- * 					best.query_stop = j
- * 					if cost == 0 and matches == m:             # <<<<<<<<<<<<<<
- * 						# exact match, stop early
- * 						break
- */
-        __pyx_t_11 = ((__pyx_v_cost == 0) != 0);
-        if (__pyx_t_11) {
-        } else {
-          __pyx_t_8 = __pyx_t_11;
-          goto __pyx_L46_bool_binop_done;
+          }
+          __pyx_L52:;
         }
-        __pyx_t_11 = ((__pyx_v_matches == __pyx_v_m) != 0);
-        __pyx_t_8 = __pyx_t_11;
-        __pyx_L46_bool_binop_done:;
-        if (__pyx_t_8) {
+        __pyx_L31_break:;
+      }
 
-          /* "cutadapt/_align.pyx":366
- * 					if cost == 0 and matches == m:
- * 						# exact match, stop early
- * 						break             # <<<<<<<<<<<<<<
- * 			# column finished
+      /* "cutadapt/_align.pyx":371
+ * 		cdef _Entry tmp_entry
  * 
+ * 		with nogil:             # <<<<<<<<<<<<<<
+ * 			# iterate over columns
+ * 			for j in range(min_n + 1, max_n + 1):
  */
-          goto __pyx_L25_break;
+      /*finally:*/ {
+        /*normal exit:*/{
+          #ifdef WITH_THREAD
+          Py_BLOCK_THREADS
+          #endif
+          goto __pyx_L29;
         }
-        goto __pyx_L39;
+        __pyx_L28_error: {
+          #ifdef WITH_THREAD
+          Py_BLOCK_THREADS
+          #endif
+          goto __pyx_L1_error;
+        }
+        __pyx_L29:;
       }
-      __pyx_L39:;
-      goto __pyx_L38;
-    }
-    __pyx_L38:;
   }
-  __pyx_L25_break:;
 
-  /* "cutadapt/_align.pyx":369
- * 			# column finished
+  /* "cutadapt/_align.pyx":448
+ * 				# column finished
  * 
  * 		if max_n == n:             # <<<<<<<<<<<<<<
  * 			first_i = 0 if stop_in_ref else m
@@ -3500,7 +5711,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = ((__pyx_v_max_n == __pyx_v_n) != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":370
+    /* "cutadapt/_align.pyx":449
  * 
  * 		if max_n == n:
  * 			first_i = 0 if stop_in_ref else m             # <<<<<<<<<<<<<<
@@ -3508,24 +5719,24 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  * 			for i in range(first_i, m+1):
  */
     if ((__pyx_v_stop_in_ref != 0)) {
-      __pyx_t_15 = 0;
+      __pyx_t_14 = 0;
     } else {
-      __pyx_t_15 = __pyx_v_m;
+      __pyx_t_14 = __pyx_v_m;
     }
-    __pyx_v_first_i = __pyx_t_15;
+    __pyx_v_first_i = __pyx_t_14;
 
-    /* "cutadapt/_align.pyx":372
+    /* "cutadapt/_align.pyx":451
  * 			first_i = 0 if stop_in_ref else m
  * 			# search in last column # TODO last?
  * 			for i in range(first_i, m+1):             # <<<<<<<<<<<<<<
  * 				length = i + min(column[i].origin, 0)
  * 				cost = column[i].cost
  */
-    __pyx_t_15 = (__pyx_v_m + 1);
-    for (__pyx_t_13 = __pyx_v_first_i; __pyx_t_13 < __pyx_t_15; __pyx_t_13+=1) {
+    __pyx_t_14 = (__pyx_v_m + 1);
+    for (__pyx_t_13 = __pyx_v_first_i; __pyx_t_13 < __pyx_t_14; __pyx_t_13+=1) {
       __pyx_v_i = __pyx_t_13;
 
-      /* "cutadapt/_align.pyx":373
+      /* "cutadapt/_align.pyx":452
  * 			# search in last column # TODO last?
  * 			for i in range(first_i, m+1):
  * 				length = i + min(column[i].origin, 0)             # <<<<<<<<<<<<<<
@@ -3535,70 +5746,70 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
       __pyx_t_17 = 0;
       __pyx_t_12 = (__pyx_v_column[__pyx_v_i]).origin;
       if (((__pyx_t_17 < __pyx_t_12) != 0)) {
-        __pyx_t_14 = __pyx_t_17;
+        __pyx_t_15 = __pyx_t_17;
       } else {
-        __pyx_t_14 = __pyx_t_12;
+        __pyx_t_15 = __pyx_t_12;
       }
-      __pyx_v_length = (__pyx_v_i + __pyx_t_14);
+      __pyx_v_length = (__pyx_v_i + __pyx_t_15);
 
-      /* "cutadapt/_align.pyx":374
+      /* "cutadapt/_align.pyx":453
  * 			for i in range(first_i, m+1):
  * 				length = i + min(column[i].origin, 0)
  * 				cost = column[i].cost             # <<<<<<<<<<<<<<
  * 				matches = column[i].matches
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+ * 				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
  */
       __pyx_t_12 = (__pyx_v_column[__pyx_v_i]).cost;
       __pyx_v_cost = __pyx_t_12;
 
-      /* "cutadapt/_align.pyx":375
+      /* "cutadapt/_align.pyx":454
  * 				length = i + min(column[i].origin, 0)
  * 				cost = column[i].cost
  * 				matches = column[i].matches             # <<<<<<<<<<<<<<
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+ * 				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
  * 					# update best
  */
       __pyx_t_12 = (__pyx_v_column[__pyx_v_i]).matches;
       __pyx_v_matches = __pyx_t_12;
 
-      /* "cutadapt/_align.pyx":376
+      /* "cutadapt/_align.pyx":455
  * 				cost = column[i].cost
  * 				matches = column[i].matches
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
+ * 				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
  * 					# update best
  * 					best.matches = matches
  */
-      __pyx_t_11 = ((__pyx_v_length >= __pyx_v_self->min_overlap) != 0);
+      __pyx_t_11 = ((__pyx_v_length >= __pyx_v_self->_min_overlap) != 0);
       if (__pyx_t_11) {
       } else {
         __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L52_bool_binop_done;
+        goto __pyx_L66_bool_binop_done;
       }
       __pyx_t_11 = ((__pyx_v_cost <= (__pyx_v_length * __pyx_v_max_error_rate)) != 0);
       if (__pyx_t_11) {
       } else {
         __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L52_bool_binop_done;
+        goto __pyx_L66_bool_binop_done;
       }
       __pyx_t_11 = ((__pyx_v_matches > __pyx_v_best.matches) != 0);
       if (!__pyx_t_11) {
       } else {
         __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L52_bool_binop_done;
+        goto __pyx_L66_bool_binop_done;
       }
       __pyx_t_11 = ((__pyx_v_matches == __pyx_v_best.matches) != 0);
       if (__pyx_t_11) {
       } else {
         __pyx_t_8 = __pyx_t_11;
-        goto __pyx_L52_bool_binop_done;
+        goto __pyx_L66_bool_binop_done;
       }
       __pyx_t_11 = ((__pyx_v_cost < __pyx_v_best.cost) != 0);
       __pyx_t_8 = __pyx_t_11;
-      __pyx_L52_bool_binop_done:;
+      __pyx_L66_bool_binop_done:;
       if (__pyx_t_8) {
 
-        /* "cutadapt/_align.pyx":378
- * 				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+        /* "cutadapt/_align.pyx":457
+ * 				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
  * 					# update best
  * 					best.matches = matches             # <<<<<<<<<<<<<<
  * 					best.cost = cost
@@ -3606,7 +5817,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
         __pyx_v_best.matches = __pyx_v_matches;
 
-        /* "cutadapt/_align.pyx":379
+        /* "cutadapt/_align.pyx":458
  * 					# update best
  * 					best.matches = matches
  * 					best.cost = cost             # <<<<<<<<<<<<<<
@@ -3615,7 +5826,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
         __pyx_v_best.cost = __pyx_v_cost;
 
-        /* "cutadapt/_align.pyx":380
+        /* "cutadapt/_align.pyx":459
  * 					best.matches = matches
  * 					best.cost = cost
  * 					best.origin = column[i].origin             # <<<<<<<<<<<<<<
@@ -3625,34 +5836,46 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
         __pyx_t_12 = (__pyx_v_column[__pyx_v_i]).origin;
         __pyx_v_best.origin = __pyx_t_12;
 
-        /* "cutadapt/_align.pyx":381
+        /* "cutadapt/_align.pyx":460
  * 					best.cost = cost
  * 					best.origin = column[i].origin
  * 					best.ref_stop = i             # <<<<<<<<<<<<<<
  * 					best.query_stop = n
- * 
+ * 		if best.cost == m + n:
  */
         __pyx_v_best.ref_stop = __pyx_v_i;
 
-        /* "cutadapt/_align.pyx":382
+        /* "cutadapt/_align.pyx":461
  * 					best.origin = column[i].origin
  * 					best.ref_stop = i
  * 					best.query_stop = n             # <<<<<<<<<<<<<<
- * 
  * 		if best.cost == m + n:
+ * 			# best.cost was initialized with this value.
  */
         __pyx_v_best.query_stop = __pyx_v_n;
-        goto __pyx_L51;
+
+        /* "cutadapt/_align.pyx":455
+ * 				cost = column[i].cost
+ * 				matches = column[i].matches
+ * 				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):             # <<<<<<<<<<<<<<
+ * 					# update best
+ * 					best.matches = matches
+ */
       }
-      __pyx_L51:;
     }
-    goto __pyx_L48;
+
+    /* "cutadapt/_align.pyx":448
+ * 				# column finished
+ * 
+ * 		if max_n == n:             # <<<<<<<<<<<<<<
+ * 			first_i = 0 if stop_in_ref else m
+ * 			# search in last column # TODO last?
+ */
   }
-  __pyx_L48:;
 
-  /* "cutadapt/_align.pyx":384
+  /* "cutadapt/_align.pyx":462
+ * 					best.ref_stop = i
  * 					best.query_stop = n
- * 
  * 		if best.cost == m + n:             # <<<<<<<<<<<<<<
  * 			# best.cost was initialized with this value.
  * 			# If it is unchanged, no alignment was found that has
@@ -3660,7 +5883,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = ((__pyx_v_best.cost == (__pyx_v_m + __pyx_v_n)) != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":388
+    /* "cutadapt/_align.pyx":466
  * 			# If it is unchanged, no alignment was found that has
  * 			# an error rate within the allowed range.
  * 			return None             # <<<<<<<<<<<<<<
@@ -3671,9 +5894,17 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
     __Pyx_INCREF(Py_None);
     __pyx_r = Py_None;
     goto __pyx_L0;
+
+    /* "cutadapt/_align.pyx":462
+ * 					best.ref_stop = i
+ * 					best.query_stop = n
+ * 		if best.cost == m + n:             # <<<<<<<<<<<<<<
+ * 			# best.cost was initialized with this value.
+ * 			# If it is unchanged, no alignment was found that has
+ */
   }
 
-  /* "cutadapt/_align.pyx":391
+  /* "cutadapt/_align.pyx":469
  * 
  * 		cdef int start1, start2
  * 		if best.origin >= 0:             # <<<<<<<<<<<<<<
@@ -3683,7 +5914,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   __pyx_t_8 = ((__pyx_v_best.origin >= 0) != 0);
   if (__pyx_t_8) {
 
-    /* "cutadapt/_align.pyx":392
+    /* "cutadapt/_align.pyx":470
  * 		cdef int start1, start2
  * 		if best.origin >= 0:
  * 			start1 = 0             # <<<<<<<<<<<<<<
@@ -3692,7 +5923,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
     __pyx_v_start1 = 0;
 
-    /* "cutadapt/_align.pyx":393
+    /* "cutadapt/_align.pyx":471
  * 		if best.origin >= 0:
  * 			start1 = 0
  * 			start2 = best.origin             # <<<<<<<<<<<<<<
@@ -3701,20 +5932,28 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
     __pyx_t_13 = __pyx_v_best.origin;
     __pyx_v_start2 = __pyx_t_13;
-    goto __pyx_L58;
+
+    /* "cutadapt/_align.pyx":469
+ * 
+ * 		cdef int start1, start2
+ * 		if best.origin >= 0:             # <<<<<<<<<<<<<<
+ * 			start1 = 0
+ * 			start2 = best.origin
+ */
+    goto __pyx_L72;
   }
-  /*else*/ {
 
-    /* "cutadapt/_align.pyx":395
+  /* "cutadapt/_align.pyx":473
  * 			start2 = best.origin
  * 		else:
  * 			start1 = -best.origin             # <<<<<<<<<<<<<<
  * 			start2 = 0
  * 
  */
+  /*else*/ {
     __pyx_v_start1 = (-__pyx_v_best.origin);
 
-    /* "cutadapt/_align.pyx":396
+    /* "cutadapt/_align.pyx":474
  * 		else:
  * 			start1 = -best.origin
  * 			start2 = 0             # <<<<<<<<<<<<<<
@@ -3723,9 +5962,9 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
     __pyx_v_start2 = 0;
   }
-  __pyx_L58:;
+  __pyx_L72:;
 
-  /* "cutadapt/_align.pyx":398
+  /* "cutadapt/_align.pyx":476
  * 			start2 = 0
  * 
  * 		assert best.ref_stop - start1 > 0  # Do not return empty alignments.             # <<<<<<<<<<<<<<
@@ -3736,12 +5975,12 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   if (unlikely(!Py_OptimizeFlag)) {
     if (unlikely(!(((__pyx_v_best.ref_stop - __pyx_v_start1) > 0) != 0))) {
       PyErr_SetNone(PyExc_AssertionError);
-      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
   }
   #endif
 
-  /* "cutadapt/_align.pyx":399
+  /* "cutadapt/_align.pyx":477
  * 
  * 		assert best.ref_stop - start1 > 0  # Do not return empty alignments.
  * 		return (start1, best.ref_stop, start2, best.query_stop, best.matches, best.cost)             # <<<<<<<<<<<<<<
@@ -3749,44 +5988,44 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  * 	def __dealloc__(self):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_start1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_start1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_best.ref_stop); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_best.ref_stop); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_start2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_start2); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_19);
+  __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_v_best.query_stop); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
-  __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_best.query_stop); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_10);
-  __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_best.matches); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_best.matches); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_18);
-  __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_v_best.cost); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_19);
-  __pyx_t_20 = PyTuple_New(6); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_v_best.cost); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_20);
+  __pyx_t_10 = PyTuple_New(6); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_10);
   __Pyx_GIVEREF(__pyx_t_3);
-  PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_2);
-  PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_2);
+  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2);
+  __Pyx_GIVEREF(__pyx_t_19);
+  PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_19);
   __Pyx_GIVEREF(__pyx_t_9);
-  PyTuple_SET_ITEM(__pyx_t_20, 2, __pyx_t_9);
-  __Pyx_GIVEREF(__pyx_t_10);
-  PyTuple_SET_ITEM(__pyx_t_20, 3, __pyx_t_10);
+  PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_9);
   __Pyx_GIVEREF(__pyx_t_18);
-  PyTuple_SET_ITEM(__pyx_t_20, 4, __pyx_t_18);
-  __Pyx_GIVEREF(__pyx_t_19);
-  PyTuple_SET_ITEM(__pyx_t_20, 5, __pyx_t_19);
+  PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_18);
+  __Pyx_GIVEREF(__pyx_t_20);
+  PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_20);
   __pyx_t_3 = 0;
   __pyx_t_2 = 0;
+  __pyx_t_19 = 0;
   __pyx_t_9 = 0;
-  __pyx_t_10 = 0;
   __pyx_t_18 = 0;
-  __pyx_t_19 = 0;
-  __pyx_r = __pyx_t_20;
   __pyx_t_20 = 0;
+  __pyx_r = __pyx_t_10;
+  __pyx_t_10 = 0;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":189
- * 				self._reference = self._reference.translate(ACGT_TABLE)
+  /* "cutadapt/_align.pyx":259
+ * 		self.debug = True
  * 
  * 	def locate(self, str query):             # <<<<<<<<<<<<<<
  * 		"""
@@ -3811,7 +6050,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":401
+/* "cutadapt/_align.pyx":479
  * 		return (start1, best.ref_stop, start2, best.query_stop, best.matches, best.cost)
  * 
  * 	def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -3820,21 +6059,21 @@ static PyObject *__pyx_pf_8cutadapt_6_align_7Aligner_2locate(struct __pyx_obj_8c
  */
 
 /* Python wrapper */
-static void __pyx_pw_8cutadapt_6_align_7Aligner_5__dealloc__(PyObject *__pyx_v_self); /*proto*/
-static void __pyx_pw_8cutadapt_6_align_7Aligner_5__dealloc__(PyObject *__pyx_v_self) {
+static void __pyx_pw_8cutadapt_6_align_7Aligner_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_pw_8cutadapt_6_align_7Aligner_7__dealloc__(PyObject *__pyx_v_self) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
-  __pyx_pf_8cutadapt_6_align_7Aligner_4__dealloc__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self));
+  __pyx_pf_8cutadapt_6_align_7Aligner_6__dealloc__(((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_v_self));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
 }
 
-static void __pyx_pf_8cutadapt_6_align_7Aligner_4__dealloc__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self) {
+static void __pyx_pf_8cutadapt_6_align_7Aligner_6__dealloc__(struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_self) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__dealloc__", 0);
 
-  /* "cutadapt/_align.pyx":402
+  /* "cutadapt/_align.pyx":480
  * 
  * 	def __dealloc__(self):
  * 		PyMem_Free(self.column)             # <<<<<<<<<<<<<<
@@ -3843,7 +6082,7 @@ static void __pyx_pf_8cutadapt_6_align_7Aligner_4__dealloc__(struct __pyx_obj_8c
  */
   PyMem_Free(__pyx_v_self->column);
 
-  /* "cutadapt/_align.pyx":401
+  /* "cutadapt/_align.pyx":479
  * 		return (start1, best.ref_stop, start2, best.query_stop, best.matches, best.cost)
  * 
  * 	def __dealloc__(self):             # <<<<<<<<<<<<<<
@@ -3855,12 +6094,12 @@ static void __pyx_pf_8cutadapt_6_align_7Aligner_4__dealloc__(struct __pyx_obj_8c
   __Pyx_RefNannyFinishContext();
 }
 
-/* "cutadapt/_align.pyx":405
+/* "cutadapt/_align.pyx":483
  * 
  * 
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
- * 	return aligner.locate(query)
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):             # <<<<<<<<<<<<<<
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap
  */
 
 /* Python wrapper */
@@ -3871,7 +6110,8 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
   PyObject *__pyx_v_query = 0;
   double __pyx_v_max_error_rate;
   int __pyx_v_flags;
-  int __pyx_v_degenerate;
+  int __pyx_v_wildcard_ref;
+  int __pyx_v_wildcard_query;
   int __pyx_v_min_overlap;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
@@ -3880,12 +6120,13 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("locate (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_query,&__pyx_n_s_max_error_rate,&__pyx_n_s_flags,&__pyx_n_s_degenerate,&__pyx_n_s_min_overlap,0};
-    PyObject* values[6] = {0,0,0,0,0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_query,&__pyx_n_s_max_error_rate,&__pyx_n_s_flags,&__pyx_n_s_wildcard_ref,&__pyx_n_s_wildcard_query,&__pyx_n_s_min_overlap,0};
+    PyObject* values[7] = {0,0,0,0,0,0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
+        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
@@ -3903,12 +6144,12 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_error_rate)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 7, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  3:
         if (kw_args > 0) {
@@ -3917,20 +6158,26 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
         }
         case  4:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_degenerate);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_ref);
           if (value) { values[4] = value; kw_args--; }
         }
         case  5:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_min_overlap);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_query);
           if (value) { values[5] = value; kw_args--; }
         }
+        case  6:
+        if (kw_args > 0) {
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_min_overlap);
+          if (value) { values[6] = value; kw_args--; }
+        }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "locate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "locate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
         case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
         case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
         case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
@@ -3943,34 +6190,39 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
     }
     __pyx_v_reference = ((PyObject*)values[0]);
     __pyx_v_query = ((PyObject*)values[1]);
-    __pyx_v_max_error_rate = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_max_error_rate == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    __pyx_v_max_error_rate = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_max_error_rate == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     if (values[3]) {
-      __pyx_v_flags = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_flags = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_flags = ((int)15);
     }
     if (values[4]) {
-      __pyx_v_degenerate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_degenerate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_wildcard_ref = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_wildcard_ref == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
-      __pyx_v_degenerate = ((int)0);
+      __pyx_v_wildcard_ref = ((int)0);
     }
     if (values[5]) {
-      __pyx_v_min_overlap = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_min_overlap == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_wildcard_query = __Pyx_PyObject_IsTrue(values[5]); if (unlikely((__pyx_v_wildcard_query == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    } else {
+      __pyx_v_wildcard_query = ((int)0);
+    }
+    if (values[6]) {
+      __pyx_v_min_overlap = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_min_overlap == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
       __pyx_v_min_overlap = ((int)1);
     }
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("locate", 0, 3, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("cutadapt._align.locate", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return NULL;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_8cutadapt_6_align_4locate(__pyx_self, __pyx_v_reference, __pyx_v_query, __pyx_v_max_error_rate, __pyx_v_flags, __pyx_v_degenerate, __pyx_v_min_overlap);
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_reference), (&PyString_Type), 1, "reference", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_8cutadapt_6_align_4locate(__pyx_self, __pyx_v_reference, __pyx_v_query, __pyx_v_max_error_rate, __pyx_v_flags, __pyx_v_wildcard_ref, __pyx_v_wildcard_query, __pyx_v_min_overlap);
 
   /* function exit code */
   goto __pyx_L0;
@@ -3981,7 +6233,7 @@ static PyObject *__pyx_pw_8cutadapt_6_align_5locate(PyObject *__pyx_self, PyObje
   return __pyx_r;
 }
 
-static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_degenerate, int __pyx_v_min_overlap) {
+static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_query, double __pyx_v_max_error_rate, int __pyx_v_flags, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query, int __pyx_v_min_overlap) {
   struct __pyx_obj_8cutadapt_6_align_Aligner *__pyx_v_aligner = NULL;
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
@@ -3995,22 +6247,22 @@ static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__py
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("locate", 0);
 
-  /* "cutadapt/_align.pyx":406
+  /* "cutadapt/_align.pyx":484
  * 
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)             # <<<<<<<<<<<<<<
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)             # <<<<<<<<<<<<<<
+ * 	aligner.min_overlap = min_overlap
  * 	return aligner.locate(query)
- * 
  */
-  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_max_error_rate); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyFloat_FromDouble(__pyx_v_max_error_rate); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_degenerate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_wildcard_ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_min_overlap); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_wildcard_query); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __Pyx_INCREF(__pyx_v_reference);
   __Pyx_GIVEREF(__pyx_v_reference);
@@ -4027,21 +6279,33 @@ static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__py
   __pyx_t_2 = 0;
   __pyx_t_3 = 0;
   __pyx_t_4 = 0;
-  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_align_Aligner)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_8cutadapt_6_align_Aligner), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 484; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
   __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
   __pyx_v_aligner = ((struct __pyx_obj_8cutadapt_6_align_Aligner *)__pyx_t_4);
   __pyx_t_4 = 0;
 
-  /* "cutadapt/_align.pyx":407
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
+  /* "cutadapt/_align.pyx":485
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap             # <<<<<<<<<<<<<<
+ * 	return aligner.locate(query)
+ * 
+ */
+  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_min_overlap); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_4);
+  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_aligner), __pyx_n_s_min_overlap, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+
+  /* "cutadapt/_align.pyx":486
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap
  * 	return aligner.locate(query)             # <<<<<<<<<<<<<<
  * 
  * 
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_aligner), __pyx_n_s_locate); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_aligner), __pyx_n_s_locate); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_5);
   __pyx_t_3 = NULL;
   if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
@@ -4054,16 +6318,16 @@ static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__py
     }
   }
   if (!__pyx_t_3) {
-    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_query); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_query); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
   } else {
-    __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
     __Pyx_INCREF(__pyx_v_query);
     __Pyx_GIVEREF(__pyx_v_query);
     PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_query);
-    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   }
@@ -4072,12 +6336,12 @@ static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__py
   __pyx_t_4 = 0;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":405
+  /* "cutadapt/_align.pyx":483
  * 
  * 
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
- * 	return aligner.locate(query)
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):             # <<<<<<<<<<<<<<
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap
  */
 
   /* function exit code */
@@ -4096,22 +6360,23 @@ static PyObject *__pyx_pf_8cutadapt_6_align_4locate(CYTHON_UNUSED PyObject *__py
   return __pyx_r;
 }
 
-/* "cutadapt/_align.pyx":410
+/* "cutadapt/_align.pyx":489
  * 
  * 
- * def compare_prefixes(str ref, str query, int degenerate=0):             # <<<<<<<<<<<<<<
+ * def compare_prefixes(str ref, str query, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Find out whether one string is the prefix of the other one, allowing
  */
 
 /* Python wrapper */
 static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_8cutadapt_6_align_6compare_prefixes[] = "\n\tFind out whether one string is the prefix of the other one, allowing\n\tIUPAC wildcards if the appropriate bit is set in the degenerate flag\n\tparameter.\n\n\tThis is used to find an anchored 5' adapter (type 'FRONT') in the 'no indels' mode.\n\tThis is very simple as only the number of errors needs to be counted.\n\n\tThis function returns a tuple compatible with what Aligner.locate outputs.\n\t";
+static char __pyx_doc_8cutadapt_6_align_6compare_prefixes[] = "\n\tFind out whether one string is the prefix of the other one, allowing\n\tIUPAC wildcards in ref and/or query if the appropriate flag is set.\n\n\tThis is used to find an anchored 5' adapter (type 'FRONT') in the 'no indels' mode.\n\tThis is very simple as only the number of errors needs to be counted.\n\n\tThis function returns a tuple compatible with what Aligner.locate outputs.\n\t";
 static PyMethodDef __pyx_mdef_8cutadapt_6_align_7compare_prefixes = {"compare_prefixes", (PyCFunction)__pyx_pw_8cutadapt_6_align_7compare_prefixes, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8cutadapt_6_align_6compare_prefixes};
 static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_ref = 0;
   PyObject *__pyx_v_query = 0;
-  int __pyx_v_degenerate;
+  int __pyx_v_wildcard_ref;
+  int __pyx_v_wildcard_query;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
@@ -4119,12 +6384,13 @@ static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_se
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("compare_prefixes (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ref,&__pyx_n_s_query,&__pyx_n_s_degenerate,0};
-    PyObject* values[3] = {0,0,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ref,&__pyx_n_s_query,&__pyx_n_s_wildcard_ref,&__pyx_n_s_wildcard_query,0};
+    PyObject* values[4] = {0,0,0,0};
     if (unlikely(__pyx_kwds)) {
       Py_ssize_t kw_args;
       const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
       switch (pos_args) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
@@ -4139,19 +6405,25 @@ static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_se
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_query)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("compare_prefixes", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("compare_prefixes", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_degenerate);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_ref);
           if (value) { values[2] = value; kw_args--; }
         }
+        case  3:
+        if (kw_args > 0) {
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_wildcard_query);
+          if (value) { values[3] = value; kw_args--; }
+        }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "compare_prefixes") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "compare_prefixes") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
+        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
         case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
         case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
@@ -4162,22 +6434,27 @@ static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_se
     __pyx_v_ref = ((PyObject*)values[0]);
     __pyx_v_query = ((PyObject*)values[1]);
     if (values[2]) {
-      __pyx_v_degenerate = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_degenerate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+      __pyx_v_wildcard_ref = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_wildcard_ref == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
     } else {
-      __pyx_v_degenerate = ((int)0);
+      __pyx_v_wildcard_ref = ((int)0);
+    }
+    if (values[3]) {
+      __pyx_v_wildcard_query = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_wildcard_query == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+    } else {
+      __pyx_v_wildcard_query = ((int)0);
     }
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("compare_prefixes", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("compare_prefixes", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("cutadapt._align.compare_prefixes", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
   return NULL;
   __pyx_L4_argument_unpacking_done:;
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ref), (&PyString_Type), 1, "ref", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_8cutadapt_6_align_6compare_prefixes(__pyx_self, __pyx_v_ref, __pyx_v_query, __pyx_v_degenerate);
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_ref), (&PyString_Type), 1, "ref", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_query), (&PyString_Type), 1, "query", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_8cutadapt_6_align_6compare_prefixes(__pyx_self, __pyx_v_ref, __pyx_v_query, __pyx_v_wildcard_ref, __pyx_v_wildcard_query);
 
   /* function exit code */
   goto __pyx_L0;
@@ -4188,15 +6465,13 @@ static PyObject *__pyx_pw_8cutadapt_6_align_7compare_prefixes(PyObject *__pyx_se
   return __pyx_r;
 }
 
-static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ref, PyObject *__pyx_v_query, int __pyx_v_degenerate) {
+static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ref, PyObject *__pyx_v_query, int __pyx_v_wildcard_ref, int __pyx_v_wildcard_query) {
   int __pyx_v_m;
   int __pyx_v_n;
   PyObject *__pyx_v_query_bytes = 0;
   PyObject *__pyx_v_ref_bytes = 0;
   char *__pyx_v_r_ptr;
   char *__pyx_v_q_ptr;
-  int __pyx_v_wildcard_ref;
-  int __pyx_v_wildcard_query;
   int __pyx_v_length;
   int __pyx_v_i;
   int __pyx_v_matches;
@@ -4219,79 +6494,61 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("compare_prefixes", 0);
 
-  /* "cutadapt/_align.pyx":421
+  /* "cutadapt/_align.pyx":499
  * 	This function returns a tuple compatible with what Aligner.locate outputs.
  * 	"""
  * 	cdef int m = len(ref)             # <<<<<<<<<<<<<<
  * 	cdef int n = len(query)
  * 	cdef bytes query_bytes = query.encode('ascii')
  */
-  __pyx_t_1 = PyObject_Length(__pyx_v_ref); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Length(__pyx_v_ref); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_m = __pyx_t_1;
 
-  /* "cutadapt/_align.pyx":422
+  /* "cutadapt/_align.pyx":500
  * 	"""
  * 	cdef int m = len(ref)
  * 	cdef int n = len(query)             # <<<<<<<<<<<<<<
  * 	cdef bytes query_bytes = query.encode('ascii')
  * 	cdef bytes ref_bytes = ref.encode('ascii')
  */
-  __pyx_t_1 = PyObject_Length(__pyx_v_query); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyObject_Length(__pyx_v_query); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_n = __pyx_t_1;
 
-  /* "cutadapt/_align.pyx":423
+  /* "cutadapt/_align.pyx":501
  * 	cdef int m = len(ref)
  * 	cdef int n = len(query)
  * 	cdef bytes query_bytes = query.encode('ascii')             # <<<<<<<<<<<<<<
  * 	cdef bytes ref_bytes = ref.encode('ascii')
  * 	cdef char* r_ptr
  */
-  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_query, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_query_bytes = ((PyObject*)__pyx_t_3);
   __pyx_t_3 = 0;
 
-  /* "cutadapt/_align.pyx":424
+  /* "cutadapt/_align.pyx":502
  * 	cdef int n = len(query)
  * 	cdef bytes query_bytes = query.encode('ascii')
  * 	cdef bytes ref_bytes = ref.encode('ascii')             # <<<<<<<<<<<<<<
  * 	cdef char* r_ptr
  * 	cdef char* q_ptr
  */
-  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_v_ref_bytes = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_align.pyx":427
+  /* "cutadapt/_align.pyx":505
  * 	cdef char* r_ptr
  * 	cdef char* q_ptr
- * 	cdef bint wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1             # <<<<<<<<<<<<<<
- * 	cdef bint wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
- * 	cdef int length = min(m, n)
- */
-  __pyx_v_wildcard_ref = (__pyx_v_degenerate & 1);
-
-  /* "cutadapt/_align.pyx":428
- * 	cdef char* q_ptr
- * 	cdef bint wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
- * 	cdef bint wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2             # <<<<<<<<<<<<<<
- * 	cdef int length = min(m, n)
- * 	cdef int i, matches = 0
- */
-  __pyx_v_wildcard_query = (__pyx_v_degenerate & 2);
-
-  /* "cutadapt/_align.pyx":429
- * 	cdef bint wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
- * 	cdef bint wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
  * 	cdef int length = min(m, n)             # <<<<<<<<<<<<<<
  * 	cdef int i, matches = 0
  * 	cdef bint compare_ascii = False
@@ -4305,8 +6562,8 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   }
   __pyx_v_length = __pyx_t_6;
 
-  /* "cutadapt/_align.pyx":430
- * 	cdef bint wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
+  /* "cutadapt/_align.pyx":506
+ * 	cdef char* q_ptr
  * 	cdef int length = min(m, n)
  * 	cdef int i, matches = 0             # <<<<<<<<<<<<<<
  * 	cdef bint compare_ascii = False
@@ -4314,7 +6571,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
  */
   __pyx_v_matches = 0;
 
-  /* "cutadapt/_align.pyx":431
+  /* "cutadapt/_align.pyx":507
  * 	cdef int length = min(m, n)
  * 	cdef int i, matches = 0
  * 	cdef bint compare_ascii = False             # <<<<<<<<<<<<<<
@@ -4323,7 +6580,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
  */
   __pyx_v_compare_ascii = 0;
 
-  /* "cutadapt/_align.pyx":433
+  /* "cutadapt/_align.pyx":509
  * 	cdef bint compare_ascii = False
  * 
  * 	if wildcard_ref:             # <<<<<<<<<<<<<<
@@ -4333,14 +6590,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_7 = (__pyx_v_wildcard_ref != 0);
   if (__pyx_t_7) {
 
-    /* "cutadapt/_align.pyx":434
+    /* "cutadapt/_align.pyx":510
  * 
  * 	if wildcard_ref:
  * 		ref_bytes = ref_bytes.translate(IUPAC_TABLE)             # <<<<<<<<<<<<<<
  * 	elif wildcard_query:
  * 		ref_bytes = ref_bytes.translate(ACGT_TABLE)
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_8 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -4353,27 +6610,35 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
       }
     }
     if (!__pyx_t_8) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
     } else {
-      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_8cutadapt_6_align_IUPAC_TABLE);
-      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_ref_bytes, ((PyObject*)__pyx_t_2));
     __pyx_t_2 = 0;
+
+    /* "cutadapt/_align.pyx":509
+ * 	cdef bint compare_ascii = False
+ * 
+ * 	if wildcard_ref:             # <<<<<<<<<<<<<<
+ * 		ref_bytes = ref_bytes.translate(IUPAC_TABLE)
+ * 	elif wildcard_query:
+ */
     goto __pyx_L3;
   }
 
-  /* "cutadapt/_align.pyx":435
+  /* "cutadapt/_align.pyx":511
  * 	if wildcard_ref:
  * 		ref_bytes = ref_bytes.translate(IUPAC_TABLE)
  * 	elif wildcard_query:             # <<<<<<<<<<<<<<
@@ -4383,14 +6648,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_7 = (__pyx_v_wildcard_query != 0);
   if (__pyx_t_7) {
 
-    /* "cutadapt/_align.pyx":436
+    /* "cutadapt/_align.pyx":512
  * 		ref_bytes = ref_bytes.translate(IUPAC_TABLE)
  * 	elif wildcard_query:
  * 		ref_bytes = ref_bytes.translate(ACGT_TABLE)             # <<<<<<<<<<<<<<
  * 	else:
  * 		compare_ascii = True
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ref_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_9 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -4403,39 +6668,47 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
       }
     }
     if (!__pyx_t_9) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
     } else {
-      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_8cutadapt_6_align_ACGT_TABLE);
-      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_ref_bytes, ((PyObject*)__pyx_t_2));
     __pyx_t_2 = 0;
+
+    /* "cutadapt/_align.pyx":511
+ * 	if wildcard_ref:
+ * 		ref_bytes = ref_bytes.translate(IUPAC_TABLE)
+ * 	elif wildcard_query:             # <<<<<<<<<<<<<<
+ * 		ref_bytes = ref_bytes.translate(ACGT_TABLE)
+ * 	else:
+ */
     goto __pyx_L3;
   }
-  /*else*/ {
 
-    /* "cutadapt/_align.pyx":438
+  /* "cutadapt/_align.pyx":514
  * 		ref_bytes = ref_bytes.translate(ACGT_TABLE)
  * 	else:
  * 		compare_ascii = True             # <<<<<<<<<<<<<<
  * 	if wildcard_query:
  * 		query_bytes = query_bytes.translate(IUPAC_TABLE)
  */
+  /*else*/ {
     __pyx_v_compare_ascii = 1;
   }
   __pyx_L3:;
 
-  /* "cutadapt/_align.pyx":439
+  /* "cutadapt/_align.pyx":515
  * 	else:
  * 		compare_ascii = True
  * 	if wildcard_query:             # <<<<<<<<<<<<<<
@@ -4445,14 +6718,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_7 = (__pyx_v_wildcard_query != 0);
   if (__pyx_t_7) {
 
-    /* "cutadapt/_align.pyx":440
+    /* "cutadapt/_align.pyx":516
  * 		compare_ascii = True
  * 	if wildcard_query:
  * 		query_bytes = query_bytes.translate(IUPAC_TABLE)             # <<<<<<<<<<<<<<
  * 	elif wildcard_ref:
  * 		query_bytes = query_bytes.translate(ACGT_TABLE)
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_8 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -4465,27 +6738,35 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
       }
     }
     if (!__pyx_t_8) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_IUPAC_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
     } else {
-      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_9);
       __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
       PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_8cutadapt_6_align_IUPAC_TABLE);
-      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_query_bytes, ((PyObject*)__pyx_t_2));
     __pyx_t_2 = 0;
+
+    /* "cutadapt/_align.pyx":515
+ * 	else:
+ * 		compare_ascii = True
+ * 	if wildcard_query:             # <<<<<<<<<<<<<<
+ * 		query_bytes = query_bytes.translate(IUPAC_TABLE)
+ * 	elif wildcard_ref:
+ */
     goto __pyx_L4;
   }
 
-  /* "cutadapt/_align.pyx":441
+  /* "cutadapt/_align.pyx":517
  * 	if wildcard_query:
  * 		query_bytes = query_bytes.translate(IUPAC_TABLE)
  * 	elif wildcard_ref:             # <<<<<<<<<<<<<<
@@ -4495,14 +6776,14 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_7 = (__pyx_v_wildcard_ref != 0);
   if (__pyx_t_7) {
 
-    /* "cutadapt/_align.pyx":442
+    /* "cutadapt/_align.pyx":518
  * 		query_bytes = query_bytes.translate(IUPAC_TABLE)
  * 	elif wildcard_ref:
  * 		query_bytes = query_bytes.translate(ACGT_TABLE)             # <<<<<<<<<<<<<<
  * 
  * 	if compare_ascii:
  */
-    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_query_bytes, __pyx_n_s_translate); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __pyx_t_9 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
@@ -4515,28 +6796,35 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
       }
     }
     if (!__pyx_t_9) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_8cutadapt_6_align_ACGT_TABLE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
     } else {
-      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_8);
       __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9); __pyx_t_9 = NULL;
       __Pyx_INCREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       __Pyx_GIVEREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
       PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_8cutadapt_6_align_ACGT_TABLE);
-      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
     }
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 518; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF_SET(__pyx_v_query_bytes, ((PyObject*)__pyx_t_2));
     __pyx_t_2 = 0;
-    goto __pyx_L4;
+
+    /* "cutadapt/_align.pyx":517
+ * 	if wildcard_query:
+ * 		query_bytes = query_bytes.translate(IUPAC_TABLE)
+ * 	elif wildcard_ref:             # <<<<<<<<<<<<<<
+ * 		query_bytes = query_bytes.translate(ACGT_TABLE)
+ * 
+ */
   }
   __pyx_L4:;
 
-  /* "cutadapt/_align.pyx":444
+  /* "cutadapt/_align.pyx":520
  * 		query_bytes = query_bytes.translate(ACGT_TABLE)
  * 
  * 	if compare_ascii:             # <<<<<<<<<<<<<<
@@ -4546,7 +6834,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_7 = (__pyx_v_compare_ascii != 0);
   if (__pyx_t_7) {
 
-    /* "cutadapt/_align.pyx":445
+    /* "cutadapt/_align.pyx":521
  * 
  * 	if compare_ascii:
  * 		for i in range(length):             # <<<<<<<<<<<<<<
@@ -4557,25 +6845,25 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
     for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_6; __pyx_t_4+=1) {
       __pyx_v_i = __pyx_t_4;
 
-      /* "cutadapt/_align.pyx":446
+      /* "cutadapt/_align.pyx":522
  * 	if compare_ascii:
  * 		for i in range(length):
  * 			if ref[i] == query[i]:             # <<<<<<<<<<<<<<
  * 				matches += 1
  * 	else:
  */
-      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_ref, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_ref, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
       __Pyx_GOTREF(__pyx_t_2);
-      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_query, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_query, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
       __Pyx_GOTREF(__pyx_t_3);
-      __pyx_t_8 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 522; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
       if (__pyx_t_7) {
 
-        /* "cutadapt/_align.pyx":447
+        /* "cutadapt/_align.pyx":523
  * 		for i in range(length):
  * 			if ref[i] == query[i]:
  * 				matches += 1             # <<<<<<<<<<<<<<
@@ -4583,35 +6871,49 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
  * 		r_ptr = ref_bytes
  */
         __pyx_v_matches = (__pyx_v_matches + 1);
-        goto __pyx_L8;
+
+        /* "cutadapt/_align.pyx":522
+ * 	if compare_ascii:
+ * 		for i in range(length):
+ * 			if ref[i] == query[i]:             # <<<<<<<<<<<<<<
+ * 				matches += 1
+ * 	else:
+ */
       }
-      __pyx_L8:;
     }
+
+    /* "cutadapt/_align.pyx":520
+ * 		query_bytes = query_bytes.translate(ACGT_TABLE)
+ * 
+ * 	if compare_ascii:             # <<<<<<<<<<<<<<
+ * 		for i in range(length):
+ * 			if ref[i] == query[i]:
+ */
     goto __pyx_L5;
   }
-  /*else*/ {
 
-    /* "cutadapt/_align.pyx":449
+  /* "cutadapt/_align.pyx":525
  * 				matches += 1
  * 	else:
  * 		r_ptr = ref_bytes             # <<<<<<<<<<<<<<
  * 		q_ptr = query_bytes
  * 		for i in range(length):
  */
-    __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_ref_bytes); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  /*else*/ {
+    __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_ref_bytes); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_r_ptr = __pyx_t_10;
 
-    /* "cutadapt/_align.pyx":450
+    /* "cutadapt/_align.pyx":526
  * 	else:
  * 		r_ptr = ref_bytes
  * 		q_ptr = query_bytes             # <<<<<<<<<<<<<<
  * 		for i in range(length):
  * 			if (r_ptr[i] & q_ptr[i]) != 0:
  */
-    __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_v_query_bytes); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __pyx_v_q_ptr = __pyx_t_10;
 
-    /* "cutadapt/_align.pyx":451
+    /* "cutadapt/_align.pyx":527
  * 		r_ptr = ref_bytes
  * 		q_ptr = query_bytes
  * 		for i in range(length):             # <<<<<<<<<<<<<<
@@ -4622,7 +6924,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
     for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_6; __pyx_t_4+=1) {
       __pyx_v_i = __pyx_t_4;
 
-      /* "cutadapt/_align.pyx":452
+      /* "cutadapt/_align.pyx":528
  * 		q_ptr = query_bytes
  * 		for i in range(length):
  * 			if (r_ptr[i] & q_ptr[i]) != 0:             # <<<<<<<<<<<<<<
@@ -4632,7 +6934,7 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
       __pyx_t_7 = ((((__pyx_v_r_ptr[__pyx_v_i]) & (__pyx_v_q_ptr[__pyx_v_i])) != 0) != 0);
       if (__pyx_t_7) {
 
-        /* "cutadapt/_align.pyx":453
+        /* "cutadapt/_align.pyx":529
  * 		for i in range(length):
  * 			if (r_ptr[i] & q_ptr[i]) != 0:
  * 				matches += 1             # <<<<<<<<<<<<<<
@@ -4640,28 +6942,34 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
  * 	# length - matches = no. of errors
  */
         __pyx_v_matches = (__pyx_v_matches + 1);
-        goto __pyx_L11;
+
+        /* "cutadapt/_align.pyx":528
+ * 		q_ptr = query_bytes
+ * 		for i in range(length):
+ * 			if (r_ptr[i] & q_ptr[i]) != 0:             # <<<<<<<<<<<<<<
+ * 				matches += 1
+ * 
+ */
       }
-      __pyx_L11:;
     }
   }
   __pyx_L5:;
 
-  /* "cutadapt/_align.pyx":456
+  /* "cutadapt/_align.pyx":532
  * 
  * 	# length - matches = no. of errors
  * 	return (0, length, 0, length, matches, length - matches)             # <<<<<<<<<<<<<<
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_length); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_length); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_8);
-  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
-  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_matches); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_matches); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_length - __pyx_v_matches)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_9 = __Pyx_PyInt_From_int((__pyx_v_length - __pyx_v_matches)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_9);
-  __pyx_t_11 = PyTuple_New(6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_11 = PyTuple_New(6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 532; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_11);
   __Pyx_INCREF(__pyx_int_0);
   __Pyx_GIVEREF(__pyx_int_0);
@@ -4685,104 +6993,507 @@ static PyObject *__pyx_pf_8cutadapt_6_align_6compare_prefixes(CYTHON_UNUSED PyOb
   __pyx_t_11 = 0;
   goto __pyx_L0;
 
-  /* "cutadapt/_align.pyx":410
+  /* "cutadapt/_align.pyx":489
  * 
  * 
- * def compare_prefixes(str ref, str query, int degenerate=0):             # <<<<<<<<<<<<<<
+ * def compare_prefixes(str ref, str query, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Find out whether one string is the prefix of the other one, allowing
  */
 
-  /* function exit code */
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_2);
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_XDECREF(__pyx_t_8);
-  __Pyx_XDECREF(__pyx_t_9);
-  __Pyx_XDECREF(__pyx_t_11);
-  __Pyx_AddTraceback("cutadapt._align.compare_prefixes", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
-  __pyx_L0:;
-  __Pyx_XDECREF(__pyx_v_query_bytes);
-  __Pyx_XDECREF(__pyx_v_ref_bytes);
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
+  /* function exit code */
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_2);
+  __Pyx_XDECREF(__pyx_t_3);
+  __Pyx_XDECREF(__pyx_t_8);
+  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_11);
+  __Pyx_AddTraceback("cutadapt._align.compare_prefixes", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = NULL;
+  __pyx_L0:;
+  __Pyx_XDECREF(__pyx_v_query_bytes);
+  __Pyx_XDECREF(__pyx_v_ref_bytes);
+  __Pyx_XGIVEREF(__pyx_r);
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static PyObject *__pyx_tp_new_8cutadapt_6_align_Aligner(PyTypeObject *t, PyObject *a, PyObject *k) {
+  struct __pyx_obj_8cutadapt_6_align_Aligner *p;
+  PyObject *o;
+  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
+    o = (*t->tp_alloc)(t, 0);
+  } else {
+    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
+  }
+  if (unlikely(!o)) return 0;
+  p = ((struct __pyx_obj_8cutadapt_6_align_Aligner *)o);
+  p->_dpmatrix = Py_None; Py_INCREF(Py_None);
+  p->_reference = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->str_reference = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  if (unlikely(__pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(o, a, k) < 0)) {
+    Py_DECREF(o); o = 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_8cutadapt_6_align_Aligner(PyObject *o) {
+  struct __pyx_obj_8cutadapt_6_align_Aligner *p = (struct __pyx_obj_8cutadapt_6_align_Aligner *)o;
+  #if PY_VERSION_HEX >= 0x030400a1
+  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
+    if (PyObject_CallFinalizerFromDealloc(o)) return;
+  }
+  #endif
+  PyObject_GC_UnTrack(o);
+  {
+    PyObject *etype, *eval, *etb;
+    PyErr_Fetch(&etype, &eval, &etb);
+    ++Py_REFCNT(o);
+    __pyx_pw_8cutadapt_6_align_7Aligner_7__dealloc__(o);
+    --Py_REFCNT(o);
+    PyErr_Restore(etype, eval, etb);
+  }
+  Py_CLEAR(p->_dpmatrix);
+  Py_CLEAR(p->_reference);
+  Py_CLEAR(p->str_reference);
+  (*Py_TYPE(o)->tp_free)(o);
+}
+
+static int __pyx_tp_traverse_8cutadapt_6_align_Aligner(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_8cutadapt_6_align_Aligner *p = (struct __pyx_obj_8cutadapt_6_align_Aligner *)o;
+  if (p->_dpmatrix) {
+    e = (*v)(p->_dpmatrix, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_8cutadapt_6_align_Aligner(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_8cutadapt_6_align_Aligner *p = (struct __pyx_obj_8cutadapt_6_align_Aligner *)o;
+  tmp = ((PyObject*)p->_dpmatrix);
+  p->_dpmatrix = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyObject *__pyx_getprop_8cutadapt_6_align_7Aligner_min_overlap(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_1__get__(o);
+}
+
+static int __pyx_setprop_8cutadapt_6_align_7Aligner_min_overlap(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
+  if (v) {
+    return __pyx_pw_8cutadapt_6_align_7Aligner_11min_overlap_3__set__(o, v);
+  }
+  else {
+    PyErr_SetString(PyExc_NotImplementedError, "__del__");
+    return -1;
+  }
+}
+
+static int __pyx_setprop_8cutadapt_6_align_7Aligner_indel_cost(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
+  if (v) {
+    return __pyx_pw_8cutadapt_6_align_7Aligner_10indel_cost_1__set__(o, v);
+  }
+  else {
+    PyErr_SetString(PyExc_NotImplementedError, "__del__");
+    return -1;
+  }
+}
+
+static PyObject *__pyx_getprop_8cutadapt_6_align_7Aligner_reference(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_8cutadapt_6_align_7Aligner_9reference_1__get__(o);
+}
+
+static int __pyx_setprop_8cutadapt_6_align_7Aligner_reference(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
+  if (v) {
+    return __pyx_pw_8cutadapt_6_align_7Aligner_9reference_3__set__(o, v);
+  }
+  else {
+    PyErr_SetString(PyExc_NotImplementedError, "__del__");
+    return -1;
+  }
+}
+
+static PyObject *__pyx_getprop_8cutadapt_6_align_7Aligner_dpmatrix(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_8cutadapt_6_align_7Aligner_8dpmatrix_1__get__(o);
+}
+
+static PyMethodDef __pyx_methods_8cutadapt_6_align_Aligner[] = {
+  {"enable_debug", (PyCFunction)__pyx_pw_8cutadapt_6_align_7Aligner_3enable_debug, METH_NOARGS, __pyx_doc_8cutadapt_6_align_7Aligner_2enable_debug},
+  {"locate", (PyCFunction)__pyx_pw_8cutadapt_6_align_7Aligner_5locate, METH_O, __pyx_doc_8cutadapt_6_align_7Aligner_4locate},
+  {0, 0, 0, 0}
+};
+
+static struct PyGetSetDef __pyx_getsets_8cutadapt_6_align_Aligner[] = {
+  {(char *)"min_overlap", __pyx_getprop_8cutadapt_6_align_7Aligner_min_overlap, __pyx_setprop_8cutadapt_6_align_7Aligner_min_overlap, 0, 0},
+  {(char *)"indel_cost", 0, __pyx_setprop_8cutadapt_6_align_7Aligner_indel_cost, __pyx_k_Matches_cost_0_mismatches_cost, 0},
+  {(char *)"reference", __pyx_getprop_8cutadapt_6_align_7Aligner_reference, __pyx_setprop_8cutadapt_6_align_7Aligner_reference, 0, 0},
+  {(char *)"dpmatrix", __pyx_getprop_8cutadapt_6_align_7Aligner_dpmatrix, 0, __pyx_k_The_dynamic_programming_matrix, 0},
+  {0, 0, 0, 0, 0}
+};
+
+static PyTypeObject __pyx_type_8cutadapt_6_align_Aligner = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "cutadapt._align.Aligner", /*tp_name*/
+  sizeof(struct __pyx_obj_8cutadapt_6_align_Aligner), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_8cutadapt_6_align_Aligner, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  "\n\tTODO documentation still uses s1 (reference) and s2 (query).\n\n\tLocate one string within another by computing an optimal semiglobal\n\talignment between string1 and string2.\n\n\tThe alignment uses unit costs, which means that mismatches, insertions and deletions are\n\tcounted as one error.\n\n\tflags is a bitwise 'or' of the allowed flags.\n\tTo allow skipping of a prefix of string1 at no cost, set the\n\tSTART_WITHIN_SEQ1 flag.\n\tTo allow skipping of a prefix of string2 at n [...]
+  __pyx_tp_traverse_8cutadapt_6_align_Aligner, /*tp_traverse*/
+  __pyx_tp_clear_8cutadapt_6_align_Aligner, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  __pyx_methods_8cutadapt_6_align_Aligner, /*tp_methods*/
+  0, /*tp_members*/
+  __pyx_getsets_8cutadapt_6_align_Aligner, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_8cutadapt_6_align_Aligner, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *__pyx_freelist_8cutadapt_6_align___pyx_scope_struct____str__[8];
+static int __pyx_freecount_8cutadapt_6_align___pyx_scope_struct____str__ = 0;
+
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct____str__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct____str__ > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__)))) {
+    o = (PyObject*)__pyx_freelist_8cutadapt_6_align___pyx_scope_struct____str__[--__pyx_freecount_8cutadapt_6_align___pyx_scope_struct____str__];
+    memset(o, 0, sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct____str__(PyObject *o) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_v_row);
+  Py_CLEAR(p->__pyx_v_self);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct____str__ < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__)))) {
+    __pyx_freelist_8cutadapt_6_align___pyx_scope_struct____str__[__pyx_freecount_8cutadapt_6_align___pyx_scope_struct____str__++] = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
+}
+
+static int __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct____str__(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)o;
+  if (p->__pyx_v_row) {
+    e = (*v)(p->__pyx_v_row, a); if (e) return e;
+  }
+  if (p->__pyx_v_self) {
+    e = (*v)(p->__pyx_v_self, a); if (e) return e;
+  }
+  return 0;
+}
+
+static int __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct____str__(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)o;
+  tmp = ((PyObject*)p->__pyx_v_row);
+  p->__pyx_v_row = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_v_self);
+  p->__pyx_v_self = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyTypeObject __pyx_type_8cutadapt_6_align___pyx_scope_struct____str__ = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "cutadapt._align.__pyx_scope_struct____str__", /*tp_name*/
+  sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct____str__, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct____str__, /*tp_traverse*/
+  __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct____str__, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_8cutadapt_6_align___pyx_scope_struct____str__, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
+  #if PY_VERSION_HEX >= 0x030400a1
+  0, /*tp_finalize*/
+  #endif
+};
+
+static struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *__pyx_freelist_8cutadapt_6_align___pyx_scope_struct_1_genexpr[8];
+static int __pyx_freecount_8cutadapt_6_align___pyx_scope_struct_1_genexpr = 0;
 
-static PyObject *__pyx_tp_new_8cutadapt_6_align_Aligner(PyTypeObject *t, PyObject *a, PyObject *k) {
-  struct __pyx_obj_8cutadapt_6_align_Aligner *p;
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
   PyObject *o;
-  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr)))) {
+    o = (PyObject*)__pyx_freelist_8cutadapt_6_align___pyx_scope_struct_1_genexpr[--__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_1_genexpr];
+    memset(o, 0, sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
     o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
+  }
+  return o;
+}
+
+static void __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct_1_genexpr(PyObject *o) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_outer_scope);
+  Py_CLEAR(p->__pyx_v_c);
+  Py_CLEAR(p->__pyx_t_0);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr)))) {
+    __pyx_freelist_8cutadapt_6_align___pyx_scope_struct_1_genexpr[__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)o);
   } else {
-    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
+    (*Py_TYPE(o)->tp_free)(o);
   }
-  if (unlikely(!o)) return 0;
-  p = ((struct __pyx_obj_8cutadapt_6_align_Aligner *)o);
-  p->_reference = ((PyObject*)Py_None); Py_INCREF(Py_None);
-  if (unlikely(__pyx_pw_8cutadapt_6_align_7Aligner_1__cinit__(o, a, k) < 0)) {
-    Py_DECREF(o); o = 0;
+}
+
+static int __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)o;
+  if (p->__pyx_outer_scope) {
+    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
   }
-  return o;
+  if (p->__pyx_v_c) {
+    e = (*v)(p->__pyx_v_c, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
+  }
+  return 0;
 }
 
-static void __pyx_tp_dealloc_8cutadapt_6_align_Aligner(PyObject *o) {
-  struct __pyx_obj_8cutadapt_6_align_Aligner *p = (struct __pyx_obj_8cutadapt_6_align_Aligner *)o;
+static int __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct_1_genexpr(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr *)o;
+  tmp = ((PyObject*)p->__pyx_outer_scope);
+  p->__pyx_outer_scope = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_v_c);
+  p->__pyx_v_c = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_t_0);
+  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
+
+static PyTypeObject __pyx_type_8cutadapt_6_align___pyx_scope_struct_1_genexpr = {
+  PyVarObject_HEAD_INIT(0, 0)
+  "cutadapt._align.__pyx_scope_struct_1_genexpr", /*tp_name*/
+  sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
+  0, /*tp_itemsize*/
+  __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
+  0, /*tp_print*/
+  0, /*tp_getattr*/
+  0, /*tp_setattr*/
+  #if PY_MAJOR_VERSION < 3
+  0, /*tp_compare*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
+  #endif
+  0, /*tp_repr*/
+  0, /*tp_as_number*/
+  0, /*tp_as_sequence*/
+  0, /*tp_as_mapping*/
+  0, /*tp_hash*/
+  0, /*tp_call*/
+  0, /*tp_str*/
+  0, /*tp_getattro*/
+  0, /*tp_setattro*/
+  0, /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct_1_genexpr, /*tp_traverse*/
+  __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct_1_genexpr, /*tp_clear*/
+  0, /*tp_richcompare*/
+  0, /*tp_weaklistoffset*/
+  0, /*tp_iter*/
+  0, /*tp_iternext*/
+  0, /*tp_methods*/
+  0, /*tp_members*/
+  0, /*tp_getset*/
+  0, /*tp_base*/
+  0, /*tp_dict*/
+  0, /*tp_descr_get*/
+  0, /*tp_descr_set*/
+  0, /*tp_dictoffset*/
+  0, /*tp_init*/
+  0, /*tp_alloc*/
+  __pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_1_genexpr, /*tp_new*/
+  0, /*tp_free*/
+  0, /*tp_is_gc*/
+  0, /*tp_bases*/
+  0, /*tp_mro*/
+  0, /*tp_cache*/
+  0, /*tp_subclasses*/
+  0, /*tp_weaklist*/
+  0, /*tp_del*/
+  0, /*tp_version_tag*/
   #if PY_VERSION_HEX >= 0x030400a1
-  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
-    if (PyObject_CallFinalizerFromDealloc(o)) return;
-  }
+  0, /*tp_finalize*/
   #endif
-  {
-    PyObject *etype, *eval, *etb;
-    PyErr_Fetch(&etype, &eval, &etb);
-    ++Py_REFCNT(o);
-    __pyx_pw_8cutadapt_6_align_7Aligner_5__dealloc__(o);
-    --Py_REFCNT(o);
-    PyErr_Restore(etype, eval, etb);
+};
+
+static struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *__pyx_freelist_8cutadapt_6_align___pyx_scope_struct_2_genexpr[8];
+static int __pyx_freecount_8cutadapt_6_align___pyx_scope_struct_2_genexpr = 0;
+
+static PyObject *__pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_2_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
+  PyObject *o;
+  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr)))) {
+    o = (PyObject*)__pyx_freelist_8cutadapt_6_align___pyx_scope_struct_2_genexpr[--__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_2_genexpr];
+    memset(o, 0, sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr));
+    (void) PyObject_INIT(o, t);
+    PyObject_GC_Track(o);
+  } else {
+    o = (*t->tp_alloc)(t, 0);
+    if (unlikely(!o)) return 0;
   }
-  Py_CLEAR(p->_reference);
-  (*Py_TYPE(o)->tp_free)(o);
+  return o;
 }
 
-static PyObject *__pyx_getprop_8cutadapt_6_align_7Aligner_reference(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_8cutadapt_6_align_7Aligner_9reference_1__get__(o);
+static void __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct_2_genexpr(PyObject *o) {
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)o;
+  PyObject_GC_UnTrack(o);
+  Py_CLEAR(p->__pyx_outer_scope);
+  Py_CLEAR(p->__pyx_v_v);
+  Py_CLEAR(p->__pyx_t_0);
+  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr)))) {
+    __pyx_freelist_8cutadapt_6_align___pyx_scope_struct_2_genexpr[__pyx_freecount_8cutadapt_6_align___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)o);
+  } else {
+    (*Py_TYPE(o)->tp_free)(o);
+  }
 }
 
-static int __pyx_setprop_8cutadapt_6_align_7Aligner_reference(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
-  if (v) {
-    return __pyx_pw_8cutadapt_6_align_7Aligner_9reference_3__set__(o, v);
+static int __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) {
+  int e;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)o;
+  if (p->__pyx_outer_scope) {
+    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
   }
-  else {
-    PyErr_SetString(PyExc_NotImplementedError, "__del__");
-    return -1;
+  if (p->__pyx_v_v) {
+    e = (*v)(p->__pyx_v_v, a); if (e) return e;
+  }
+  if (p->__pyx_t_0) {
+    e = (*v)(p->__pyx_t_0, a); if (e) return e;
   }
+  return 0;
 }
 
-static PyMethodDef __pyx_methods_8cutadapt_6_align_Aligner[] = {
-  {"locate", (PyCFunction)__pyx_pw_8cutadapt_6_align_7Aligner_3locate, METH_O, __pyx_doc_8cutadapt_6_align_7Aligner_2locate},
-  {0, 0, 0, 0}
-};
-
-static struct PyGetSetDef __pyx_getsets_8cutadapt_6_align_Aligner[] = {
-  {(char *)"reference", __pyx_getprop_8cutadapt_6_align_7Aligner_reference, __pyx_setprop_8cutadapt_6_align_7Aligner_reference, 0, 0},
-  {0, 0, 0, 0, 0}
-};
+static int __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct_2_genexpr(PyObject *o) {
+  PyObject* tmp;
+  struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr *)o;
+  tmp = ((PyObject*)p->__pyx_outer_scope);
+  p->__pyx_outer_scope = ((struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct____str__ *)Py_None); Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_v_v);
+  p->__pyx_v_v = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  tmp = ((PyObject*)p->__pyx_t_0);
+  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
+  Py_XDECREF(tmp);
+  return 0;
+}
 
-static PyTypeObject __pyx_type_8cutadapt_6_align_Aligner = {
+static PyTypeObject __pyx_type_8cutadapt_6_align___pyx_scope_struct_2_genexpr = {
   PyVarObject_HEAD_INIT(0, 0)
-  "cutadapt._align.Aligner", /*tp_name*/
-  sizeof(struct __pyx_obj_8cutadapt_6_align_Aligner), /*tp_basicsize*/
+  "cutadapt._align.__pyx_scope_struct_2_genexpr", /*tp_name*/
+  sizeof(struct __pyx_obj_8cutadapt_6_align___pyx_scope_struct_2_genexpr), /*tp_basicsize*/
   0, /*tp_itemsize*/
-  __pyx_tp_dealloc_8cutadapt_6_align_Aligner, /*tp_dealloc*/
+  __pyx_tp_dealloc_8cutadapt_6_align___pyx_scope_struct_2_genexpr, /*tp_dealloc*/
   0, /*tp_print*/
   0, /*tp_getattr*/
   0, /*tp_setattr*/
   #if PY_MAJOR_VERSION < 3
   0, /*tp_compare*/
-  #else
-  0, /*reserved*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
   #endif
   0, /*tp_repr*/
   0, /*tp_as_number*/
@@ -4794,17 +7505,17 @@ static PyTypeObject __pyx_type_8cutadapt_6_align_Aligner = {
   0, /*tp_getattro*/
   0, /*tp_setattro*/
   0, /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
-  "\n\tTODO documentation still uses s1 (reference) and s2 (query).\n\n\tLocate one string within another by computing an optimal semiglobal\n\talignment between string1 and string2.\n\n\tThe alignment uses unit costs, which means that mismatches, insertions and deletions are\n\tcounted as one error.\n\n\tflags is a bitwise 'or' of the allowed flags.\n\tTo allow skipping of a prefix of string1 at no cost, set the\n\tSTART_WITHIN_SEQ1 flag.\n\tTo allow skipping of a prefix of string2 at n [...]
-  0, /*tp_traverse*/
-  0, /*tp_clear*/
+  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
+  0, /*tp_doc*/
+  __pyx_tp_traverse_8cutadapt_6_align___pyx_scope_struct_2_genexpr, /*tp_traverse*/
+  __pyx_tp_clear_8cutadapt_6_align___pyx_scope_struct_2_genexpr, /*tp_clear*/
   0, /*tp_richcompare*/
   0, /*tp_weaklistoffset*/
   0, /*tp_iter*/
   0, /*tp_iternext*/
-  __pyx_methods_8cutadapt_6_align_Aligner, /*tp_methods*/
+  0, /*tp_methods*/
   0, /*tp_members*/
-  __pyx_getsets_8cutadapt_6_align_Aligner, /*tp_getset*/
+  0, /*tp_getset*/
   0, /*tp_base*/
   0, /*tp_dict*/
   0, /*tp_descr_get*/
@@ -4812,7 +7523,7 @@ static PyTypeObject __pyx_type_8cutadapt_6_align_Aligner = {
   0, /*tp_dictoffset*/
   0, /*tp_init*/
   0, /*tp_alloc*/
-  __pyx_tp_new_8cutadapt_6_align_Aligner, /*tp_new*/
+  __pyx_tp_new_8cutadapt_6_align___pyx_scope_struct_2_genexpr, /*tp_new*/
   0, /*tp_free*/
   0, /*tp_is_gc*/
   0, /*tp_bases*/
@@ -4851,17 +7562,26 @@ static struct PyModuleDef __pyx_moduledef = {
 
 static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_b_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 0, 0},
+  {&__pyx_kp_s_0_2d, __pyx_k_0_2d, sizeof(__pyx_k_0_2d), 0, 0, 1, 0},
   {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
   {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1},
   {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
   {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1},
+  {&__pyx_n_s_DPMatrix, __pyx_k_DPMatrix, sizeof(__pyx_k_DPMatrix), 0, 0, 1, 1},
+  {&__pyx_n_s_DPMatrix___init, __pyx_k_DPMatrix___init, sizeof(__pyx_k_DPMatrix___init), 0, 0, 1, 1},
+  {&__pyx_n_s_DPMatrix___str, __pyx_k_DPMatrix___str, sizeof(__pyx_k_DPMatrix___str), 0, 0, 1, 1},
+  {&__pyx_n_s_DPMatrix___str___locals_genexpr, __pyx_k_DPMatrix___str___locals_genexpr, sizeof(__pyx_k_DPMatrix___str___locals_genexpr), 0, 0, 1, 1},
+  {&__pyx_n_s_DPMatrix_set_entry, __pyx_k_DPMatrix_set_entry, sizeof(__pyx_k_DPMatrix_set_entry), 0, 0, 1, 1},
   {&__pyx_n_s_G, __pyx_k_G, sizeof(__pyx_k_G), 0, 0, 1, 1},
   {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1},
+  {&__pyx_kp_s_Insertion_deletion_cost_must_be, __pyx_k_Insertion_deletion_cost_must_be, sizeof(__pyx_k_Insertion_deletion_cost_must_be), 0, 0, 1, 0},
   {&__pyx_n_s_K, __pyx_k_K, sizeof(__pyx_k_K), 0, 0, 1, 1},
   {&__pyx_n_s_M, __pyx_k_M, sizeof(__pyx_k_M), 0, 0, 1, 1},
   {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
+  {&__pyx_kp_s_Minimum_overlap_must_be_at_least, __pyx_k_Minimum_overlap_must_be_at_least, sizeof(__pyx_k_Minimum_overlap_must_be_at_least), 0, 0, 1, 0},
   {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
   {&__pyx_n_s_R, __pyx_k_R, sizeof(__pyx_k_R), 0, 0, 1, 1},
+  {&__pyx_kp_s_Representation_of_the_dynamic_p, __pyx_k_Representation_of_the_dynamic_p, sizeof(__pyx_k_Representation_of_the_dynamic_p), 0, 0, 1, 0},
   {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1},
   {&__pyx_n_s_T, __pyx_k_T, sizeof(__pyx_k_T), 0, 0, 1, 1},
   {&__pyx_n_s_U, __pyx_k_U, sizeof(__pyx_k_U), 0, 0, 1, 1},
@@ -4870,21 +7590,34 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_W, __pyx_k_W, sizeof(__pyx_k_W), 0, 0, 1, 1},
   {&__pyx_n_s_X, __pyx_k_X, sizeof(__pyx_k_X), 0, 0, 1, 1},
   {&__pyx_n_s_Y, __pyx_k_Y, sizeof(__pyx_k_Y), 0, 0, 1, 1},
+  {&__pyx_n_s__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 0, 1, 1},
+  {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0},
+  {&__pyx_kp_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 0},
+  {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0},
+  {&__pyx_kp_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 0},
   {&__pyx_n_s_acgt_table, __pyx_k_acgt_table, sizeof(__pyx_k_acgt_table), 0, 0, 1, 1},
   {&__pyx_n_s_aligner, __pyx_k_aligner, sizeof(__pyx_k_aligner), 0, 0, 1, 1},
+  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
   {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
   {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
+  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
   {&__pyx_n_s_compare_ascii, __pyx_k_compare_ascii, sizeof(__pyx_k_compare_ascii), 0, 0, 1, 1},
   {&__pyx_n_s_compare_prefixes, __pyx_k_compare_prefixes, sizeof(__pyx_k_compare_prefixes), 0, 0, 1, 1},
+  {&__pyx_n_s_cost, __pyx_k_cost, sizeof(__pyx_k_cost), 0, 0, 1, 1},
   {&__pyx_n_s_cutadapt__align, __pyx_k_cutadapt__align, sizeof(__pyx_k_cutadapt__align), 0, 0, 1, 1},
   {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1},
-  {&__pyx_n_s_degenerate, __pyx_k_degenerate, sizeof(__pyx_k_degenerate), 0, 0, 1, 1},
+  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
   {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
   {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1},
+  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
+  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
   {&__pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_k_home_marcel_scm_cutadapt_cutada, sizeof(__pyx_k_home_marcel_scm_cutadapt_cutada), 0, 0, 1, 0},
   {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
+  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
   {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
   {&__pyx_n_s_iupac_table, __pyx_k_iupac_table, sizeof(__pyx_k_iupac_table), 0, 0, 1, 1},
+  {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
+  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
   {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1},
   {&__pyx_n_s_locate, __pyx_k_locate, sizeof(__pyx_k_locate), 0, 0, 1, 1},
   {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1},
@@ -4892,31 +7625,44 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
   {&__pyx_n_s_matches, __pyx_k_matches, sizeof(__pyx_k_matches), 0, 0, 1, 1},
   {&__pyx_n_s_max_error_rate, __pyx_k_max_error_rate, sizeof(__pyx_k_max_error_rate), 0, 0, 1, 1},
+  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
   {&__pyx_n_s_min_overlap, __pyx_k_min_overlap, sizeof(__pyx_k_min_overlap), 0, 0, 1, 1},
-  {&__pyx_kp_s_minimum_overlap_must_be_at_least, __pyx_k_minimum_overlap_must_be_at_least, sizeof(__pyx_k_minimum_overlap_must_be_at_least), 0, 0, 1, 0},
+  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
   {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
-  {&__pyx_n_s_ord, __pyx_k_ord, sizeof(__pyx_k_ord), 0, 0, 1, 1},
+  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
   {&__pyx_n_s_q_ptr, __pyx_k_q_ptr, sizeof(__pyx_k_q_ptr), 0, 0, 1, 1},
+  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
   {&__pyx_n_s_query, __pyx_k_query, sizeof(__pyx_k_query), 0, 0, 1, 1},
   {&__pyx_n_s_query_bytes, __pyx_k_query_bytes, sizeof(__pyx_k_query_bytes), 0, 0, 1, 1},
+  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
   {&__pyx_n_s_r_ptr, __pyx_k_r_ptr, sizeof(__pyx_k_r_ptr), 0, 0, 1, 1},
   {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
   {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1},
   {&__pyx_n_s_ref_bytes, __pyx_k_ref_bytes, sizeof(__pyx_k_ref_bytes), 0, 0, 1, 1},
   {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1},
+  {&__pyx_n_s_rjust, __pyx_k_rjust, sizeof(__pyx_k_rjust), 0, 0, 1, 1},
+  {&__pyx_n_s_row, __pyx_k_row, sizeof(__pyx_k_row), 0, 0, 1, 1},
+  {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1},
+  {&__pyx_n_s_rows_2, __pyx_k_rows_2, sizeof(__pyx_k_rows_2), 0, 0, 1, 1},
+  {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
+  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
+  {&__pyx_n_s_set_entry, __pyx_k_set_entry, sizeof(__pyx_k_set_entry), 0, 0, 1, 1},
+  {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1},
   {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
   {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
+  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
   {&__pyx_n_s_translate, __pyx_k_translate, sizeof(__pyx_k_translate), 0, 0, 1, 1},
   {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
   {&__pyx_n_s_wildcard_query, __pyx_k_wildcard_query, sizeof(__pyx_k_wildcard_query), 0, 0, 1, 1},
   {&__pyx_n_s_wildcard_ref, __pyx_k_wildcard_ref, sizeof(__pyx_k_wildcard_ref), 0, 0, 1, 1},
+  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
   {0, 0, 0, 0, 0, 0, 0}
 };
 static int __Pyx_InitCachedBuiltins(void) {
-  __pyx_builtin_ord = __Pyx_GetBuiltinName(__pyx_n_s_ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   return 0;
   __pyx_L1_error:;
   return -1;
@@ -4926,130 +7672,188 @@ static int __Pyx_InitCachedConstants(void) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
 
-  /* "cutadapt/_align.pyx":41
+  /* "cutadapt/_align.pyx":33
  * 	"""
  * 	d = dict(A=1, C=2, G=4, T=8, U=8)
  * 	t = bytearray(b'\0') * 256             # <<<<<<<<<<<<<<
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  */
-  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_tuple__2);
   __Pyx_GIVEREF(__pyx_tuple__2);
 
-  /* "cutadapt/_align.pyx":81
+  /* "cutadapt/_align.pyx":73
  * 		N=A|C|G|T
  * 	)
  * 	t = bytearray(b'\0') * 256             # <<<<<<<<<<<<<<
  * 	for c, v in d.items():
  * 		t[ord(c)] = v
  */
-  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_tuple__3);
   __Pyx_GIVEREF(__pyx_tuple__3);
 
-  /* "cutadapt/_align.pyx":170
- * 		self.reference = reference
- * 		if min_overlap < 1:
- * 			raise ValueError("minimum overlap must be at least 1")             # <<<<<<<<<<<<<<
- * 		self.min_overlap = min_overlap
- * 
+  /* "cutadapt/_align.pyx":111
+ * 		Return a representation of the matrix as a string.
+ * 		"""
+ * 		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]             # <<<<<<<<<<<<<<
+ * 		for c, row in zip(' ' + self.reference, self._rows):
+ * 			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
  */
-  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_minimum_overlap_must_be_at_least); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_int_2); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_tuple__4);
   __Pyx_GIVEREF(__pyx_tuple__4);
 
-  /* "cutadapt/_align.pyx":182
+  /* "cutadapt/_align.pyx":213
+ * 		def __set__(self, int value):
+ * 			if value < 1:
+ * 				raise ValueError('Minimum overlap must be at least 1')             # <<<<<<<<<<<<<<
+ * 			self._min_overlap = value
+ * 
+ */
+  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_Minimum_overlap_must_be_at_least); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__9);
+  __Pyx_GIVEREF(__pyx_tuple__9);
+
+  /* "cutadapt/_align.pyx":223
+ * 		def __set__(self, value):
+ * 			if value < 1:
+ * 				raise ValueError('Insertion/deletion cost must be at leat 1')             # <<<<<<<<<<<<<<
+ * 			self._insertion_cost = value
+ * 			self._deletion_cost = value
+ */
+  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Insertion_deletion_cost_must_be); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__10);
+  __Pyx_GIVEREF(__pyx_tuple__10);
+
+  /* "cutadapt/_align.pyx":236
  * 				raise MemoryError()
  * 			self.column = mem
  * 			self._reference = reference.encode('ascii')             # <<<<<<<<<<<<<<
  * 			self.m = len(reference)
  * 			if self.wildcard_ref:
  */
-  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__5);
-  __Pyx_GIVEREF(__pyx_tuple__5);
+  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__11);
+  __Pyx_GIVEREF(__pyx_tuple__11);
 
-  /* "cutadapt/_align.pyx":204
+  /* "cutadapt/_align.pyx":274
  * 		"""
  * 		cdef char* s1 = self._reference
  * 		cdef bytes query_bytes = query.encode('ascii')             # <<<<<<<<<<<<<<
  * 		cdef char* s2 = query_bytes
  * 		cdef int m = self.m
  */
-  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__6);
-  __Pyx_GIVEREF(__pyx_tuple__6);
+  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__12);
+  __Pyx_GIVEREF(__pyx_tuple__12);
 
-  /* "cutadapt/_align.pyx":423
+  /* "cutadapt/_align.pyx":501
  * 	cdef int m = len(ref)
  * 	cdef int n = len(query)
  * 	cdef bytes query_bytes = query.encode('ascii')             # <<<<<<<<<<<<<<
  * 	cdef bytes ref_bytes = ref.encode('ascii')
  * 	cdef char* r_ptr
  */
-  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__7);
-  __Pyx_GIVEREF(__pyx_tuple__7);
+  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__13);
+  __Pyx_GIVEREF(__pyx_tuple__13);
 
-  /* "cutadapt/_align.pyx":424
+  /* "cutadapt/_align.pyx":502
  * 	cdef int n = len(query)
  * 	cdef bytes query_bytes = query.encode('ascii')
  * 	cdef bytes ref_bytes = ref.encode('ascii')             # <<<<<<<<<<<<<<
  * 	cdef char* r_ptr
  * 	cdef char* q_ptr
  */
-  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__8);
-  __Pyx_GIVEREF(__pyx_tuple__8);
+  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__14);
+  __Pyx_GIVEREF(__pyx_tuple__14);
 
-  /* "cutadapt/_align.pyx":32
+  /* "cutadapt/_align.pyx":24
  * 
  * 
  * def _acgt_table():             # <<<<<<<<<<<<<<
  * 	"""
  * 	Return a translation table that maps A, C, G, T characters to the lower
  */
-  __pyx_tuple__9 = PyTuple_Pack(4, __pyx_n_s_d, __pyx_n_s_t, __pyx_n_s_c, __pyx_n_s_v); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__9);
-  __Pyx_GIVEREF(__pyx_tuple__9);
-  __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_acgt_table, 32, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__15 = PyTuple_Pack(4, __pyx_n_s_d, __pyx_n_s_t, __pyx_n_s_c, __pyx_n_s_v); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__15);
+  __Pyx_GIVEREF(__pyx_tuple__15);
+  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_acgt_table, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_align.pyx":48
+  /* "cutadapt/_align.pyx":40
  * 
  * 
  * def _iupac_table():             # <<<<<<<<<<<<<<
  * 	"""
  * 	Return a translation table for IUPAC characters.
  */
-  __pyx_tuple__11 = PyTuple_Pack(8, __pyx_n_s_A, __pyx_n_s_C, __pyx_n_s_G, __pyx_n_s_T, __pyx_n_s_d, __pyx_n_s_t, __pyx_n_s_c, __pyx_n_s_v); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__11);
-  __Pyx_GIVEREF(__pyx_tuple__11);
-  __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(0, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_iupac_table, 48, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__17 = PyTuple_Pack(8, __pyx_n_s_A, __pyx_n_s_C, __pyx_n_s_G, __pyx_n_s_T, __pyx_n_s_d, __pyx_n_s_t, __pyx_n_s_c, __pyx_n_s_v); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__17);
+  __Pyx_GIVEREF(__pyx_tuple__17);
+  __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(0, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_iupac_table, 40, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":94
+ * 	computed.
+ * 	"""
+ * 	def __init__(self, reference, query):             # <<<<<<<<<<<<<<
+ * 		m = len(reference)
+ * 		n = len(query)
+ */
+  __pyx_tuple__20 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_reference, __pyx_n_s_query, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s__19); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__20);
+  __Pyx_GIVEREF(__pyx_tuple__20);
+  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(3, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_init, 94, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_align.pyx":405
+  /* "cutadapt/_align.pyx":101
+ * 		self.query = query
  * 
+ * 	def set_entry(self, int i, int j, cost):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Set an entry in the dynamic programming matrix.
+ */
+  __pyx_tuple__22 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_cost); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__22);
+  __Pyx_GIVEREF(__pyx_tuple__22);
+  __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_set_entry, 101, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
  * 
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
- * 	return aligner.locate(query)
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
  */
-  __pyx_tuple__13 = PyTuple_Pack(7, __pyx_n_s_reference, __pyx_n_s_query, __pyx_n_s_max_error_rate, __pyx_n_s_flags, __pyx_n_s_degenerate, __pyx_n_s_min_overlap, __pyx_n_s_aligner); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__13);
-  __Pyx_GIVEREF(__pyx_tuple__13);
-  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(6, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_locate, 405, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__24 = PyTuple_Pack(8, __pyx_n_s_self, __pyx_n_s_rows_2, __pyx_n_s_c, __pyx_n_s_row, __pyx_n_s_r, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__24);
+  __Pyx_GIVEREF(__pyx_tuple__24);
+  __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(1, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_str, 107, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_align.pyx":483
+ * 
+ * 
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):             # <<<<<<<<<<<<<<
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap
+ */
+  __pyx_tuple__26 = PyTuple_Pack(8, __pyx_n_s_reference, __pyx_n_s_query, __pyx_n_s_max_error_rate, __pyx_n_s_flags, __pyx_n_s_wildcard_ref, __pyx_n_s_wildcard_query, __pyx_n_s_min_overlap, __pyx_n_s_aligner); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__26);
+  __Pyx_GIVEREF(__pyx_tuple__26);
+  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(7, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_locate, 483, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_align.pyx":410
+  /* "cutadapt/_align.pyx":489
  * 
  * 
- * def compare_prefixes(str ref, str query, int degenerate=0):             # <<<<<<<<<<<<<<
+ * def compare_prefixes(str ref, str query, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Find out whether one string is the prefix of the other one, allowing
  */
-  __pyx_tuple__15 = PyTuple_Pack(15, __pyx_n_s_ref, __pyx_n_s_query, __pyx_n_s_degenerate, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s_query_bytes, __pyx_n_s_ref_bytes, __pyx_n_s_r_ptr, __pyx_n_s_q_ptr, __pyx_n_s_wildcard_ref, __pyx_n_s_wildcard_query, __pyx_n_s_length, __pyx_n_s_i, __pyx_n_s_matches, __pyx_n_s_compare_ascii); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__15);
-  __Pyx_GIVEREF(__pyx_tuple__15);
-  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(3, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_compare_prefixes, 410, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__28 = PyTuple_Pack(14, __pyx_n_s_ref, __pyx_n_s_query, __pyx_n_s_wildcard_ref, __pyx_n_s_wildcard_query, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s_query_bytes, __pyx_n_s_ref_bytes, __pyx_n_s_r_ptr, __pyx_n_s_q_ptr, __pyx_n_s_length, __pyx_n_s_i, __pyx_n_s_matches, __pyx_n_s_compare_ascii); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__28);
+  __Pyx_GIVEREF(__pyx_tuple__28);
+  __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(4, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_compare_prefixes, 489, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_RefNannyFinishContext();
   return 0;
   __pyx_L1_error:;
@@ -5058,6 +7862,7 @@ static int __Pyx_InitCachedConstants(void) {
 }
 
 static int __Pyx_InitGlobals(void) {
+  __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
   if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -5095,18 +7900,24 @@ PyMODINIT_FUNC PyInit__align(void)
   }
   #endif
   __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__align(void)", 0);
-  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #ifdef __Pyx_CyFunction_USED
-  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   #ifdef __Pyx_FusedFunction_USED
   if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_Coroutine_USED
+  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   #ifdef __Pyx_Generator_USED
   if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_StopAsyncIteration_USED
+  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   /*--- Library function declarations ---*/
   /*--- Threads initialization code ---*/
   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
@@ -5129,12 +7940,12 @@ PyMODINIT_FUNC PyInit__align(void)
   #endif
   if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   /*--- Initialize various global constants etc. ---*/
-  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
   if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   if (__pyx_module_is_main_cutadapt___align) {
-    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #if PY_MAJOR_VERSION >= 3
   {
@@ -5145,56 +7956,68 @@ PyMODINIT_FUNC PyInit__align(void)
   }
   #endif
   /*--- Builtin init code ---*/
-  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Constants init code ---*/
-  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Global init code ---*/
   __pyx_v_8cutadapt_6_align_ACGT_TABLE = ((PyObject*)Py_None); Py_INCREF(Py_None);
   __pyx_v_8cutadapt_6_align_IUPAC_TABLE = ((PyObject*)Py_None); Py_INCREF(Py_None);
   /*--- Variable export code ---*/
   /*--- Function export code ---*/
   /*--- Type init code ---*/
-  if (PyType_Ready(&__pyx_type_8cutadapt_6_align_Aligner) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_8cutadapt_6_align_Aligner) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_type_8cutadapt_6_align_Aligner.tp_print = 0;
-  if (PyObject_SetAttrString(__pyx_m, "Aligner", (PyObject *)&__pyx_type_8cutadapt_6_align_Aligner) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetAttrString(__pyx_m, "Aligner", (PyObject *)&__pyx_type_8cutadapt_6_align_Aligner) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_8cutadapt_6_align_Aligner = &__pyx_type_8cutadapt_6_align_Aligner;
+  if (PyType_Ready(&__pyx_type_8cutadapt_6_align___pyx_scope_struct____str__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_type_8cutadapt_6_align___pyx_scope_struct____str__.tp_print = 0;
+  __pyx_ptype_8cutadapt_6_align___pyx_scope_struct____str__ = &__pyx_type_8cutadapt_6_align___pyx_scope_struct____str__;
+  if (PyType_Ready(&__pyx_type_8cutadapt_6_align___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_type_8cutadapt_6_align___pyx_scope_struct_1_genexpr.tp_print = 0;
+  __pyx_ptype_8cutadapt_6_align___pyx_scope_struct_1_genexpr = &__pyx_type_8cutadapt_6_align___pyx_scope_struct_1_genexpr;
+  if (PyType_Ready(&__pyx_type_8cutadapt_6_align___pyx_scope_struct_2_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_type_8cutadapt_6_align___pyx_scope_struct_2_genexpr.tp_print = 0;
+  __pyx_ptype_8cutadapt_6_align___pyx_scope_struct_2_genexpr = &__pyx_type_8cutadapt_6_align___pyx_scope_struct_2_genexpr;
   /*--- Type import code ---*/
   /*--- Variable import code ---*/
   /*--- Function import code ---*/
   /*--- Execution code ---*/
+  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
 
-  /* "cutadapt/_align.pyx":32
+  /* "cutadapt/_align.pyx":24
  * 
  * 
  * def _acgt_table():             # <<<<<<<<<<<<<<
  * 	"""
  * 	Return a translation table that maps A, C, G, T characters to the lower
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_1_acgt_table, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_1_acgt_table, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_d, __pyx_n_s_acgt_table, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_acgt_table, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":48
+  /* "cutadapt/_align.pyx":40
  * 
  * 
  * def _iupac_table():             # <<<<<<<<<<<<<<
  * 	"""
  * 	Return a translation table for IUPAC characters.
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_3_iupac_table, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_3_iupac_table, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iupac_table, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_iupac_table, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":88
+  /* "cutadapt/_align.pyx":80
  * 
  * 
  * cdef bytes ACGT_TABLE = _acgt_table()             # <<<<<<<<<<<<<<
  * cdef bytes IUPAC_TABLE = _iupac_table()
  * 
  */
-  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_acgt_table); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_acgt_table); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_t_3 = NULL;
   if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
@@ -5207,27 +8030,27 @@ PyMODINIT_FUNC PyInit__align(void)
     }
   }
   if (__pyx_t_3) {
-    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   } else {
-    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_XGOTREF(__pyx_v_8cutadapt_6_align_ACGT_TABLE);
   __Pyx_DECREF_SET(__pyx_v_8cutadapt_6_align_ACGT_TABLE, ((PyObject*)__pyx_t_1));
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":89
+  /* "cutadapt/_align.pyx":81
  * 
  * cdef bytes ACGT_TABLE = _acgt_table()
  * cdef bytes IUPAC_TABLE = _iupac_table()             # <<<<<<<<<<<<<<
  * 
  * 
  */
-  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_iupac_table); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_iupac_table); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_t_3 = NULL;
   if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
@@ -5240,41 +8063,100 @@ PyMODINIT_FUNC PyInit__align(void)
     }
   }
   if (__pyx_t_3) {
-    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   } else {
-    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_XGOTREF(__pyx_v_8cutadapt_6_align_IUPAC_TABLE);
   __Pyx_DECREF_SET(__pyx_v_8cutadapt_6_align_IUPAC_TABLE, ((PyObject*)__pyx_t_1));
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":405
+  /* "cutadapt/_align.pyx":84
  * 
  * 
- * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):             # <<<<<<<<<<<<<<
- * 	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
- * 	return aligner.locate(query)
+ * class DPMatrix:             # <<<<<<<<<<<<<<
+ * 	"""
+ * 	Representation of the dynamic-programming matrix.
+ */
+  __pyx_t_1 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_DPMatrix, __pyx_n_s_DPMatrix, (PyObject *) NULL, __pyx_n_s_cutadapt__align, __pyx_kp_s_Representation_of_the_dynamic_p); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_1);
+
+  /* "cutadapt/_align.pyx":94
+ * 	computed.
+ * 	"""
+ * 	def __init__(self, reference, query):             # <<<<<<<<<<<<<<
+ * 		m = len(reference)
+ * 		n = len(query)
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_8DPMatrix_1__init__, 0, __pyx_n_s_DPMatrix___init, NULL, __pyx_n_s_cutadapt__align, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s_init, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":101
+ * 		self.query = query
+ * 
+ * 	def set_entry(self, int i, int j, cost):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Set an entry in the dynamic programming matrix.
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_8DPMatrix_3set_entry, 0, __pyx_n_s_DPMatrix_set_entry, NULL, __pyx_n_s_cutadapt__align, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s_set_entry, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":107
+ * 		self._rows[i][j] = cost
+ * 
+ * 	def __str__(self):             # <<<<<<<<<<<<<<
+ * 		"""
+ * 		Return a representation of the matrix as a string.
+ */
+  __pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_8DPMatrix_5__str__, 0, __pyx_n_s_DPMatrix___str, NULL, __pyx_n_s_cutadapt__align, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyObject_SetItem(__pyx_t_1, __pyx_n_s_str, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+  /* "cutadapt/_align.pyx":84
+ * 
+ * 
+ * class DPMatrix:             # <<<<<<<<<<<<<<
+ * 	"""
+ * 	Representation of the dynamic-programming matrix.
+ */
+  __pyx_t_2 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_DPMatrix, __pyx_empty_tuple, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_DPMatrix, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /* "cutadapt/_align.pyx":483
+ * 
+ * 
+ * def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):             # <<<<<<<<<<<<<<
+ * 	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+ * 	aligner.min_overlap = min_overlap
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_5locate, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_5locate, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_d, __pyx_n_s_locate, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_locate, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_align.pyx":410
+  /* "cutadapt/_align.pyx":489
  * 
  * 
- * def compare_prefixes(str ref, str query, int degenerate=0):             # <<<<<<<<<<<<<<
+ * def compare_prefixes(str ref, str query, bint wildcard_ref=False, bint wildcard_query=False):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Find out whether one string is the prefix of the other one, allowing
  */
-  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_7compare_prefixes, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8cutadapt_6_align_7compare_prefixes, NULL, __pyx_n_s_cutadapt__align); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compare_prefixes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compare_prefixes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 489; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
   /* "cutadapt/_align.pyx":1
@@ -5339,36 +8221,17 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
 #endif
     }
     return result;
-}
-
-#if CYTHON_COMPILING_IN_CPYTHON
-static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
-    PyObject *result;
-    ternaryfunc call = func->ob_type->tp_call;
-    if (unlikely(!call))
-        return PyObject_Call(func, arg, kw);
-    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
-        return NULL;
-    result = (*call)(func, arg, kw);
-    Py_LeaveRecursiveCall();
-    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
-        PyErr_SetString(
-            PyExc_SystemError,
-            "NULL result without error in PyObject_Call");
-    }
-    return result;
-}
-#endif
-
-#if CYTHON_COMPILING_IN_CPYTHON
-static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
-    PyObject *self, *result;
-    PyCFunction cfunc;
-    cfunc = PyCFunction_GET_FUNCTION(func);
-    self = PyCFunction_GET_SELF(func);
+}
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+    PyObject *result;
+    ternaryfunc call = func->ob_type->tp_call;
+    if (unlikely(!call))
+        return PyObject_Call(func, arg, kw);
     if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
         return NULL;
-    result = cfunc(self, arg);
+    result = (*call)(func, arg, kw);
     Py_LeaveRecursiveCall();
     if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
         PyErr_SetString(
@@ -5379,70 +8242,46 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject
 }
 #endif
 
+static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
+    PyObject *method;
+    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
+    if (unlikely(!method))
+        return -1;
+    target->method = method;
 #if CYTHON_COMPILING_IN_CPYTHON
-static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
-    PyObject *result;
-    PyObject *args = PyTuple_New(1);
-    if (unlikely(!args)) return NULL;
-    Py_INCREF(arg);
-    PyTuple_SET_ITEM(args, 0, arg);
-    result = __Pyx_PyObject_Call(func, args, NULL);
-    Py_DECREF(args);
-    return result;
-}
-static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
-#ifdef __Pyx_CyFunction_USED
-    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
-#else
-    if (likely(PyCFunction_Check(func))) {
-#endif
-        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
-            return __Pyx_PyObject_CallMethO(func, arg);
-        }
+    #if PY_MAJOR_VERSION >= 3
+    if (likely(PyObject_TypeCheck(method, &PyMethodDescr_Type)))
+    #endif
+    {
+        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
+        target->func = descr->d_method->ml_meth;
+        target->flag = descr->d_method->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_O | METH_NOARGS);
     }
-    return __Pyx__PyObject_CallOneArg(func, arg);
-}
-#else
-static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
-    PyObject* args = PyTuple_Pack(1, arg);
-    return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
-}
 #endif
+    return 0;
+}
 
-static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
-    PyObject *method, *result = NULL;
-    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
-    if (unlikely(!method)) goto bad;
+static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
+    PyObject *args, *result = NULL;
+    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
 #if CYTHON_COMPILING_IN_CPYTHON
-    if (likely(PyMethod_Check(method))) {
-        PyObject *self = PyMethod_GET_SELF(method);
-        if (likely(self)) {
-            PyObject *args;
-            PyObject *function = PyMethod_GET_FUNCTION(method);
-            args = PyTuple_New(2);
-            if (unlikely(!args)) goto bad;
-            Py_INCREF(self);
-            PyTuple_SET_ITEM(args, 0, self);
-            Py_INCREF(arg);
-            PyTuple_SET_ITEM(args, 1, arg);
-            Py_INCREF(function);
-            Py_DECREF(method); method = NULL;
-            result = __Pyx_PyObject_Call(function, args, NULL);
-            Py_DECREF(args);
-            Py_DECREF(function);
-            return result;
-        }
-    }
+    args = PyTuple_New(1);
+    if (unlikely(!args)) goto bad;
+    Py_INCREF(self);
+    PyTuple_SET_ITEM(args, 0, self);
+#else
+    args = PyTuple_Pack(1, self);
+    if (unlikely(!args)) goto bad;
 #endif
-    result = __Pyx_PyObject_CallOneArg(method, arg);
+    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
+    Py_DECREF(args);
 bad:
-    Py_XDECREF(method);
     return result;
 }
 
 static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
     if (PY_MAJOR_VERSION >= 3)
-        return __Pyx_PyObject_CallMethod1((PyObject*)&PyDict_Type, __pyx_n_s_items, d);
+        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d);
     else
         return PyDict_Items(d);
 }
@@ -5503,6 +8342,136 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
     return 0;
 }
 
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
+   Py_ssize_t length;
+   #if CYTHON_PEP393_ENABLED
+   length = PyUnicode_GET_LENGTH(x);
+   if (likely(length == 1)) {
+       return PyUnicode_READ_CHAR(x, 0);
+   }
+   #else
+   length = PyUnicode_GET_SIZE(x);
+   if (likely(length == 1)) {
+       return PyUnicode_AS_UNICODE(x)[0];
+   }
+   #if Py_UNICODE_SIZE == 2
+   else if (PyUnicode_GET_SIZE(x) == 2) {
+       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
+       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
+           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
+           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
+               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
+           }
+       }
+   }
+   #endif
+   #endif
+   PyErr_Format(PyExc_ValueError,
+                "only single character unicode strings can be converted to Py_UCS4, "
+                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
+   return (Py_UCS4)-1;
+}
+
+static long __Pyx__PyObject_Ord(PyObject* c) {
+    Py_ssize_t size;
+    if (PyBytes_Check(c)) {
+        size = PyBytes_GET_SIZE(c);
+        if (likely(size == 1)) {
+            return (unsigned char) PyBytes_AS_STRING(c)[0];
+        }
+#if PY_MAJOR_VERSION < 3
+    } else if (PyUnicode_Check(c)) {
+        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
+#endif
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
+    } else if (PyByteArray_Check(c)) {
+        size = PyByteArray_GET_SIZE(c);
+        if (likely(size == 1)) {
+            return (unsigned char) PyByteArray_AS_STRING(c)[0];
+        }
+#endif
+    } else {
+        PyErr_Format(PyExc_TypeError,
+            "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
+        return (long)(Py_UCS4)-1;
+    }
+    PyErr_Format(PyExc_TypeError,
+        "ord() expected a character, but string of length %zd found", size);
+    return (long)(Py_UCS4)-1;
+}
+
+static CYTHON_INLINE int __Pyx_SetItemInt_ByteArray_Fast(PyObject* string, Py_ssize_t i, unsigned char v,
+                                                         int wraparound, int boundscheck) {
+    Py_ssize_t length;
+    if (wraparound | boundscheck) {
+        length = PyByteArray_GET_SIZE(string);
+        if (wraparound & unlikely(i < 0)) i += length;
+        if ((!boundscheck) || likely((0 <= i) & (i < length))) {
+            PyByteArray_AS_STRING(string)[i] = (char) v;
+            return 0;
+        } else {
+            PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
+            return -1;
+        }
+    } else {
+        PyByteArray_AS_STRING(string)[i] = (char) v;
+        return 0;
+    }
+}
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
+    PyObject *self, *result;
+    PyCFunction cfunc;
+    cfunc = PyCFunction_GET_FUNCTION(func);
+    self = PyCFunction_GET_SELF(func);
+    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
+        return NULL;
+    result = cfunc(self, arg);
+    Py_LeaveRecursiveCall();
+    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
+        PyErr_SetString(
+            PyExc_SystemError,
+            "NULL result without error in PyObject_Call");
+    }
+    return result;
+}
+#endif
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_New(1);
+    if (unlikely(!args)) return NULL;
+    Py_INCREF(arg);
+    PyTuple_SET_ITEM(args, 0, arg);
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+#ifdef __Pyx_CyFunction_USED
+    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
+#else
+    if (likely(PyCFunction_Check(func))) {
+#endif
+        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
+            return __Pyx_PyObject_CallMethO(func, arg);
+        }
+    }
+    return __Pyx__PyObject_CallOneArg(func, arg);
+}
+#else
+static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
+    PyObject *result;
+    PyObject *args = PyTuple_Pack(1, arg);
+    if (unlikely(!args)) return NULL;
+    result = __Pyx_PyObject_Call(func, args, NULL);
+    Py_DECREF(args);
+    return result;
+}
+#endif
+
 #if CYTHON_COMPILING_IN_CPYTHON
 static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
 #ifdef __Pyx_CyFunction_USED
@@ -5612,50 +8581,290 @@ static int __Pyx_ParseOptionalKeywords(
                     values[name-argnames] = value;
                     break;
                 }
-                name++;
+                name++;
+            }
+            if (*name) continue;
+            else {
+                PyObject*** argname = argnames;
+                while (argname != first_kw_arg) {
+                    int cmp = (**argname == key) ? 0 :
+                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
+                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
+                    #endif
+                        PyUnicode_Compare(**argname, key);
+                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
+                    if (cmp == 0) goto arg_passed_twice;
+                    argname++;
+                }
+            }
+        } else
+            goto invalid_keyword_type;
+        if (kwds2) {
+            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
+        } else {
+            goto invalid_keyword;
+        }
+    }
+    return 0;
+arg_passed_twice:
+    __Pyx_RaiseDoubleKeywordsError(function_name, key);
+    goto bad;
+invalid_keyword_type:
+    PyErr_Format(PyExc_TypeError,
+        "%.200s() keywords must be strings", function_name);
+    goto bad;
+invalid_keyword:
+    PyErr_Format(PyExc_TypeError,
+    #if PY_MAJOR_VERSION < 3
+        "%.200s() got an unexpected keyword argument '%.200s'",
+        function_name, PyString_AsString(key));
+    #else
+        "%s() got an unexpected keyword argument '%U'",
+        function_name, key);
+    #endif
+bad:
+    return -1;
+}
+
+#if CYTHON_USE_PYLONG_INTERNALS
+  #include "longintrepr.h"
+#endif
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op1))) {
+        const long b = intval;
+        long x;
+        long a = PyInt_AS_LONG(op1);
+            x = (long)((unsigned long)a + b);
+            if (likely((x^a) >= 0 || (x^b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_add(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
+    if (likely(PyLong_CheckExact(op1))) {
+        const long b = intval;
+        long a, x;
+        const PY_LONG_LONG llb = intval;
+        PY_LONG_LONG lla, llx;
+        const digit* digits = ((PyLongObject*)op1)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op1);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            a = likely(size) ? digits[0] : 0;
+            if (size == -1) a = -a;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
+            }
+        }
+                x = a + b;
+            return PyLong_FromLong(x);
+        long_long:
+                llx = lla + llb;
+            return PyLong_FromLongLong(llx);
+    }
+    #endif
+    if (PyFloat_CheckExact(op1)) {
+        const long b = intval;
+        double a = PyFloat_AS_DOUBLE(op1);
+            double result;
+            PyFPE_START_PROTECT("add", return NULL)
+            result = ((double)a) + (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
+}
+#endif
+
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
+    PyObject *r;
+    if (!j) return NULL;
+    r = PyObject_GetItem(o, j);
+    Py_DECREF(j);
+    return r;
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
+    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
+        PyObject *r = PyList_GET_ITEM(o, i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
+    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
+        PyObject *r = PyTuple_GET_ITEM(o, i);
+        Py_INCREF(r);
+        return r;
+    }
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#else
+    return PySequence_GetItem(o, i);
+#endif
+}
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
+                                                     CYTHON_NCP_UNUSED int wraparound,
+                                                     CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (is_list || PyList_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
+        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
+            PyObject *r = PyList_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    }
+    else if (PyTuple_CheckExact(o)) {
+        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
+        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
+            PyObject *r = PyTuple_GET_ITEM(o, n);
+            Py_INCREF(r);
+            return r;
+        }
+    } else {
+        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+        if (likely(m && m->sq_item)) {
+            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
+                Py_ssize_t l = m->sq_length(o);
+                if (likely(l >= 0)) {
+                    i += l;
+                } else {
+                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
+                        PyErr_Clear();
+                    else
+                        return NULL;
+                }
             }
-            if (*name) continue;
-            else {
-                PyObject*** argname = argnames;
-                while (argname != first_kw_arg) {
-                    int cmp = (**argname == key) ? 0 :
-                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
-                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
-                    #endif
-                        PyUnicode_Compare(**argname, key);
-                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
-                    if (cmp == 0) goto arg_passed_twice;
-                    argname++;
+            return m->sq_item(o, i);
+        }
+    }
+#else
+    if (is_list || PySequence_Check(o)) {
+        return PySequence_GetItem(o, i);
+    }
+#endif
+    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+}
+
+static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
+    int r;
+    if (!j) return -1;
+    r = PyObject_SetItem(o, j, v);
+    Py_DECREF(j);
+    return r;
+}
+static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
+                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (is_list || PyList_CheckExact(o)) {
+        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
+        if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
+            PyObject* old = PyList_GET_ITEM(o, n);
+            Py_INCREF(v);
+            PyList_SET_ITEM(o, n, v);
+            Py_DECREF(old);
+            return 1;
+        }
+    } else {
+        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+        if (likely(m && m->sq_ass_item)) {
+            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
+                Py_ssize_t l = m->sq_length(o);
+                if (likely(l >= 0)) {
+                    i += l;
+                } else {
+                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
+                        PyErr_Clear();
+                    else
+                        return -1;
                 }
             }
-        } else
-            goto invalid_keyword_type;
-        if (kwds2) {
-            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
-        } else {
-            goto invalid_keyword;
+            return m->sq_ass_item(o, i, v);
         }
     }
-    return 0;
-arg_passed_twice:
-    __Pyx_RaiseDoubleKeywordsError(function_name, key);
-    goto bad;
-invalid_keyword_type:
-    PyErr_Format(PyExc_TypeError,
-        "%.200s() keywords must be strings", function_name);
-    goto bad;
-invalid_keyword:
-    PyErr_Format(PyExc_TypeError,
-    #if PY_MAJOR_VERSION < 3
-        "%.200s() got an unexpected keyword argument '%.200s'",
-        function_name, PyString_AsString(key));
-    #else
-        "%s() got an unexpected keyword argument '%U'",
-        function_name, key);
-    #endif
-bad:
-    return -1;
+#else
+#if CYTHON_COMPILING_IN_PYPY
+    if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) {
+#else
+    if (is_list || PySequence_Check(o)) {
+#endif
+        return PySequence_SetItem(o, i, v);
+    }
+#endif
+    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
+}
+
+static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
+    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
+}
+
+#if !CYTHON_COMPILING_IN_CPYTHON
+static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
+    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
 }
+#endif
 
 static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
     PyErr_Format(PyExc_TypeError,
@@ -5868,107 +9077,734 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
         }
 #endif
     }
-bad:
-    Py_XDECREF(owned_instance);
-    return;
+bad:
+    Py_XDECREF(owned_instance);
+    return;
+}
+#endif
+
+static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
+    PyObject *result;
+#if CYTHON_COMPILING_IN_CPYTHON
+    result = PyDict_GetItem(__pyx_d, name);
+    if (likely(result)) {
+        Py_INCREF(result);
+    } else {
+#else
+    result = PyObject_GetItem(__pyx_d, name);
+    if (!result) {
+        PyErr_Clear();
+#endif
+        result = __Pyx_GetBuiltinName(name);
+    }
+    return result;
+}
+
+static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
+    PyObject* fake_module;
+    PyTypeObject* cached_type = NULL;
+    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+    if (!fake_module) return NULL;
+    Py_INCREF(fake_module);
+    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
+    if (cached_type) {
+        if (!PyType_Check((PyObject*)cached_type)) {
+            PyErr_Format(PyExc_TypeError,
+                "Shared Cython type %.200s is not a type object",
+                type->tp_name);
+            goto bad;
+        }
+        if (cached_type->tp_basicsize != type->tp_basicsize) {
+            PyErr_Format(PyExc_TypeError,
+                "Shared Cython type %.200s has the wrong size, try recompiling",
+                type->tp_name);
+            goto bad;
+        }
+    } else {
+        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
+        PyErr_Clear();
+        if (PyType_Ready(type) < 0) goto bad;
+        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
+            goto bad;
+        Py_INCREF(type);
+        cached_type = type;
+    }
+done:
+    Py_DECREF(fake_module);
+    return cached_type;
+bad:
+    Py_XDECREF(cached_type);
+    cached_type = NULL;
+    goto done;
+}
+
+static PyObject *
+__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
+{
+    if (unlikely(op->func_doc == NULL)) {
+        if (op->func.m_ml->ml_doc) {
+#if PY_MAJOR_VERSION >= 3
+            op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
+#else
+            op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
+#endif
+            if (unlikely(op->func_doc == NULL))
+                return NULL;
+        } else {
+            Py_INCREF(Py_None);
+            return Py_None;
+        }
+    }
+    Py_INCREF(op->func_doc);
+    return op->func_doc;
+}
+static int
+__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
+{
+    PyObject *tmp = op->func_doc;
+    if (value == NULL) {
+        value = Py_None;
+    }
+    Py_INCREF(value);
+    op->func_doc = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
+{
+    if (unlikely(op->func_name == NULL)) {
+#if PY_MAJOR_VERSION >= 3
+        op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
+#else
+        op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
+#endif
+        if (unlikely(op->func_name == NULL))
+            return NULL;
+    }
+    Py_INCREF(op->func_name);
+    return op->func_name;
+}
+static int
+__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
+#else
+    if (unlikely(value == NULL || !PyString_Check(value))) {
+#endif
+        PyErr_SetString(PyExc_TypeError,
+                        "__name__ must be set to a string object");
+        return -1;
+    }
+    tmp = op->func_name;
+    Py_INCREF(value);
+    op->func_name = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
+{
+    Py_INCREF(op->func_qualname);
+    return op->func_qualname;
+}
+static int
+__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
+#else
+    if (unlikely(value == NULL || !PyString_Check(value))) {
+#endif
+        PyErr_SetString(PyExc_TypeError,
+                        "__qualname__ must be set to a string object");
+        return -1;
+    }
+    tmp = op->func_qualname;
+    Py_INCREF(value);
+    op->func_qualname = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
+{
+    PyObject *self;
+    self = m->func_closure;
+    if (self == NULL)
+        self = Py_None;
+    Py_INCREF(self);
+    return self;
+}
+static PyObject *
+__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
+{
+    if (unlikely(op->func_dict == NULL)) {
+        op->func_dict = PyDict_New();
+        if (unlikely(op->func_dict == NULL))
+            return NULL;
+    }
+    Py_INCREF(op->func_dict);
+    return op->func_dict;
+}
+static int
+__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
+{
+    PyObject *tmp;
+    if (unlikely(value == NULL)) {
+        PyErr_SetString(PyExc_TypeError,
+               "function's dictionary may not be deleted");
+        return -1;
+    }
+    if (unlikely(!PyDict_Check(value))) {
+        PyErr_SetString(PyExc_TypeError,
+               "setting function's dictionary to a non-dict");
+        return -1;
+    }
+    tmp = op->func_dict;
+    Py_INCREF(value);
+    op->func_dict = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
+{
+    Py_INCREF(op->func_globals);
+    return op->func_globals;
+}
+static PyObject *
+__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
+{
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+static PyObject *
+__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
+{
+    PyObject* result = (op->func_code) ? op->func_code : Py_None;
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
+    int result = 0;
+    PyObject *res = op->defaults_getter((PyObject *) op);
+    if (unlikely(!res))
+        return -1;
+    #if CYTHON_COMPILING_IN_CPYTHON
+    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
+    Py_INCREF(op->defaults_tuple);
+    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
+    Py_INCREF(op->defaults_kwdict);
+    #else
+    op->defaults_tuple = PySequence_ITEM(res, 0);
+    if (unlikely(!op->defaults_tuple)) result = -1;
+    else {
+        op->defaults_kwdict = PySequence_ITEM(res, 1);
+        if (unlikely(!op->defaults_kwdict)) result = -1;
+    }
+    #endif
+    Py_DECREF(res);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
+    PyObject* tmp;
+    if (!value) {
+        value = Py_None;
+    } else if (value != Py_None && !PyTuple_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__defaults__ must be set to a tuple object");
+        return -1;
+    }
+    Py_INCREF(value);
+    tmp = op->defaults_tuple;
+    op->defaults_tuple = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
+    PyObject* result = op->defaults_tuple;
+    if (unlikely(!result)) {
+        if (op->defaults_getter) {
+            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
+            result = op->defaults_tuple;
+        } else {
+            result = Py_None;
+        }
+    }
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
+    PyObject* tmp;
+    if (!value) {
+        value = Py_None;
+    } else if (value != Py_None && !PyDict_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__kwdefaults__ must be set to a dict object");
+        return -1;
+    }
+    Py_INCREF(value);
+    tmp = op->defaults_kwdict;
+    op->defaults_kwdict = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
+    PyObject* result = op->defaults_kwdict;
+    if (unlikely(!result)) {
+        if (op->defaults_getter) {
+            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
+            result = op->defaults_kwdict;
+        } else {
+            result = Py_None;
+        }
+    }
+    Py_INCREF(result);
+    return result;
+}
+static int
+__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
+    PyObject* tmp;
+    if (!value || value == Py_None) {
+        value = NULL;
+    } else if (!PyDict_Check(value)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "__annotations__ must be set to a dict object");
+        return -1;
+    }
+    Py_XINCREF(value);
+    tmp = op->func_annotations;
+    op->func_annotations = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
+    PyObject* result = op->func_annotations;
+    if (unlikely(!result)) {
+        result = PyDict_New();
+        if (unlikely(!result)) return NULL;
+        op->func_annotations = result;
+    }
+    Py_INCREF(result);
+    return result;
+}
+static PyGetSetDef __pyx_CyFunction_getsets[] = {
+    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
+    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
+    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
+    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
+    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
+    {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
+    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
+    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
+    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
+    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
+    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
+    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
+    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
+    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
+    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
+    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
+    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
+    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
+    {0, 0, 0, 0, 0}
+};
+static PyMemberDef __pyx_CyFunction_members[] = {
+    {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
+    {0, 0, 0,  0, 0}
+};
+static PyObject *
+__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
+{
+#if PY_MAJOR_VERSION >= 3
+    return PyUnicode_FromString(m->func.m_ml->ml_name);
+#else
+    return PyString_FromString(m->func.m_ml->ml_name);
+#endif
+}
+static PyMethodDef __pyx_CyFunction_methods[] = {
+    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
+    {0, 0, 0, 0}
+};
+#if PY_VERSION_HEX < 0x030500A0
+#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
+#else
+#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
+#endif
+static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
+                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
+    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
+    if (op == NULL)
+        return NULL;
+    op->flags = flags;
+    __Pyx_CyFunction_weakreflist(op) = NULL;
+    op->func.m_ml = ml;
+    op->func.m_self = (PyObject *) op;
+    Py_XINCREF(closure);
+    op->func_closure = closure;
+    Py_XINCREF(module);
+    op->func.m_module = module;
+    op->func_dict = NULL;
+    op->func_name = NULL;
+    Py_INCREF(qualname);
+    op->func_qualname = qualname;
+    op->func_doc = NULL;
+    op->func_classobj = NULL;
+    op->func_globals = globals;
+    Py_INCREF(op->func_globals);
+    Py_XINCREF(code);
+    op->func_code = code;
+    op->defaults_pyobjects = 0;
+    op->defaults = NULL;
+    op->defaults_tuple = NULL;
+    op->defaults_kwdict = NULL;
+    op->defaults_getter = NULL;
+    op->func_annotations = NULL;
+    PyObject_GC_Track(op);
+    return (PyObject *) op;
+}
+static int
+__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
+{
+    Py_CLEAR(m->func_closure);
+    Py_CLEAR(m->func.m_module);
+    Py_CLEAR(m->func_dict);
+    Py_CLEAR(m->func_name);
+    Py_CLEAR(m->func_qualname);
+    Py_CLEAR(m->func_doc);
+    Py_CLEAR(m->func_globals);
+    Py_CLEAR(m->func_code);
+    Py_CLEAR(m->func_classobj);
+    Py_CLEAR(m->defaults_tuple);
+    Py_CLEAR(m->defaults_kwdict);
+    Py_CLEAR(m->func_annotations);
+    if (m->defaults) {
+        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
+        int i;
+        for (i = 0; i < m->defaults_pyobjects; i++)
+            Py_XDECREF(pydefaults[i]);
+        PyMem_Free(m->defaults);
+        m->defaults = NULL;
+    }
+    return 0;
+}
+static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
+{
+    PyObject_GC_UnTrack(m);
+    if (__Pyx_CyFunction_weakreflist(m) != NULL)
+        PyObject_ClearWeakRefs((PyObject *) m);
+    __Pyx_CyFunction_clear(m);
+    PyObject_GC_Del(m);
+}
+static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
+{
+    Py_VISIT(m->func_closure);
+    Py_VISIT(m->func.m_module);
+    Py_VISIT(m->func_dict);
+    Py_VISIT(m->func_name);
+    Py_VISIT(m->func_qualname);
+    Py_VISIT(m->func_doc);
+    Py_VISIT(m->func_globals);
+    Py_VISIT(m->func_code);
+    Py_VISIT(m->func_classobj);
+    Py_VISIT(m->defaults_tuple);
+    Py_VISIT(m->defaults_kwdict);
+    if (m->defaults) {
+        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
+        int i;
+        for (i = 0; i < m->defaults_pyobjects; i++)
+            Py_VISIT(pydefaults[i]);
+    }
+    return 0;
+}
+static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
+{
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
+        Py_INCREF(func);
+        return func;
+    }
+    if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
+        if (type == NULL)
+            type = (PyObject *)(Py_TYPE(obj));
+        return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
+    }
+    if (obj == Py_None)
+        obj = NULL;
+    return __Pyx_PyMethod_New(func, obj, type);
 }
+static PyObject*
+__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
+{
+#if PY_MAJOR_VERSION >= 3
+    return PyUnicode_FromFormat("<cyfunction %U at %p>",
+                                op->func_qualname, (void *)op);
+#else
+    return PyString_FromFormat("<cyfunction %s at %p>",
+                               PyString_AsString(op->func_qualname), (void *)op);
 #endif
-
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
-    PyObject *r;
-    if (!j) return NULL;
-    r = PyObject_GetItem(o, j);
-    Py_DECREF(j);
-    return r;
 }
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
-                                                              CYTHON_NCP_UNUSED int wraparound,
-                                                              CYTHON_NCP_UNUSED int boundscheck) {
-#if CYTHON_COMPILING_IN_CPYTHON
-    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
-    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
-        PyObject *r = PyList_GET_ITEM(o, i);
-        Py_INCREF(r);
-        return r;
+#if CYTHON_COMPILING_IN_PYPY
+static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+    PyCFunctionObject* f = (PyCFunctionObject*)func;
+    PyCFunction meth = f->m_ml->ml_meth;
+    PyObject *self = f->m_self;
+    Py_ssize_t size;
+    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
+    case METH_VARARGS:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0))
+            return (*meth)(self, arg);
+        break;
+    case METH_VARARGS | METH_KEYWORDS:
+        return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
+    case METH_NOARGS:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
+            size = PyTuple_GET_SIZE(arg);
+            if (likely(size == 0))
+                return (*meth)(self, NULL);
+            PyErr_Format(PyExc_TypeError,
+                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                f->m_ml->ml_name, size);
+            return NULL;
+        }
+        break;
+    case METH_O:
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
+            size = PyTuple_GET_SIZE(arg);
+            if (likely(size == 1)) {
+                PyObject *result, *arg0 = PySequence_ITEM(arg, 0);
+                if (unlikely(!arg0)) return NULL;
+                result = (*meth)(self, arg0);
+                Py_DECREF(arg0);
+                return result;
+            }
+            PyErr_Format(PyExc_TypeError,
+                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
+                f->m_ml->ml_name, size);
+            return NULL;
+        }
+        break;
+    default:
+        PyErr_SetString(PyExc_SystemError, "Bad call flags in "
+                        "__Pyx_CyFunction_Call. METH_OLDARGS is no "
+                        "longer supported!");
+        return NULL;
     }
-    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
+                 f->m_ml->ml_name);
+    return NULL;
+}
 #else
-    return PySequence_GetItem(o, i);
-#endif
+static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
+	return PyCFunction_Call(func, arg, kw);
 }
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
-                                                              CYTHON_NCP_UNUSED int wraparound,
-                                                              CYTHON_NCP_UNUSED int boundscheck) {
-#if CYTHON_COMPILING_IN_CPYTHON
-    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
-    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
-        PyObject *r = PyTuple_GET_ITEM(o, i);
-        Py_INCREF(r);
-        return r;
-    }
-    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+#endif
+static PyTypeObject __pyx_CyFunctionType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "cython_function_or_method",
+    sizeof(__pyx_CyFunctionObject),
+    0,
+    (destructor) __Pyx_CyFunction_dealloc,
+    0,
+    0,
+    0,
+#if PY_MAJOR_VERSION < 3
+    0,
 #else
-    return PySequence_GetItem(o, i);
+    0,
 #endif
-}
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
-                                                     CYTHON_NCP_UNUSED int wraparound,
-                                                     CYTHON_NCP_UNUSED int boundscheck) {
-#if CYTHON_COMPILING_IN_CPYTHON
-    if (is_list || PyList_CheckExact(o)) {
-        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
-        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
-            PyObject *r = PyList_GET_ITEM(o, n);
-            Py_INCREF(r);
-            return r;
-        }
+    (reprfunc) __Pyx_CyFunction_repr,
+    0,
+    0,
+    0,
+    0,
+    __Pyx_CyFunction_Call,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    0,
+    (traverseproc) __Pyx_CyFunction_traverse,
+    (inquiry) __Pyx_CyFunction_clear,
+    0,
+#if PY_VERSION_HEX < 0x030500A0
+    offsetof(__pyx_CyFunctionObject, func_weakreflist),
+#else
+    offsetof(PyCFunctionObject, m_weakreflist),
+#endif
+    0,
+    0,
+    __pyx_CyFunction_methods,
+    __pyx_CyFunction_members,
+    __pyx_CyFunction_getsets,
+    0,
+    0,
+    __Pyx_CyFunction_descr_get,
+    0,
+    offsetof(__pyx_CyFunctionObject, func_dict),
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    0,
+#endif
+};
+static int __pyx_CyFunction_init(void) {
+#if !CYTHON_COMPILING_IN_PYPY
+    __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
+#endif
+    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
+    if (__pyx_CyFunctionType == NULL) {
+        return -1;
     }
-    else if (PyTuple_CheckExact(o)) {
-        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
-        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
-            PyObject *r = PyTuple_GET_ITEM(o, n);
-            Py_INCREF(r);
-            return r;
+    return 0;
+}
+static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults = PyMem_Malloc(size);
+    if (!m->defaults)
+        return PyErr_NoMemory();
+    memset(m->defaults, 0, size);
+    m->defaults_pyobjects = pyobjects;
+    return m->defaults;
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults_tuple = tuple;
+    Py_INCREF(tuple);
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->defaults_kwdict = dict;
+    Py_INCREF(dict);
+}
+static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
+    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
+    m->func_annotations = dict;
+    Py_INCREF(dict);
+}
+
+static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
+    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
+    for (i=0; i < nbases; i++) {
+        PyTypeObject *tmptype;
+        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
+        tmptype = Py_TYPE(tmp);
+#if PY_MAJOR_VERSION < 3
+        if (tmptype == &PyClass_Type)
+            continue;
+#endif
+        if (!metaclass) {
+            metaclass = tmptype;
+            continue;
         }
-    } else {
-        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
-        if (likely(m && m->sq_item)) {
-            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
-                Py_ssize_t l = m->sq_length(o);
-                if (likely(l >= 0)) {
-                    i += l;
-                } else {
-                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
-                        PyErr_Clear();
-                    else
-                        return NULL;
-                }
-            }
-            return m->sq_item(o, i);
+        if (PyType_IsSubtype(metaclass, tmptype))
+            continue;
+        if (PyType_IsSubtype(tmptype, metaclass)) {
+            metaclass = tmptype;
+            continue;
         }
+        PyErr_SetString(PyExc_TypeError,
+                        "metaclass conflict: "
+                        "the metaclass of a derived class "
+                        "must be a (non-strict) subclass "
+                        "of the metaclasses of all its bases");
+        return NULL;
     }
+    if (!metaclass) {
+#if PY_MAJOR_VERSION < 3
+        metaclass = &PyClass_Type;
 #else
-    if (is_list || PySequence_Check(o)) {
-        return PySequence_GetItem(o, i);
-    }
+        metaclass = &PyType_Type;
 #endif
-    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
+    }
+    Py_INCREF((PyObject*) metaclass);
+    return (PyObject*) metaclass;
 }
 
-static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
-    PyObject *result;
-#if CYTHON_COMPILING_IN_CPYTHON
-    result = PyDict_GetItem(__pyx_d, name);
-    if (likely(result)) {
-        Py_INCREF(result);
+static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
+                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
+    PyObject *ns;
+    if (metaclass) {
+        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
+        if (prep) {
+            PyObject *pargs = PyTuple_Pack(2, name, bases);
+            if (unlikely(!pargs)) {
+                Py_DECREF(prep);
+                return NULL;
+            }
+            ns = PyObject_Call(prep, pargs, mkw);
+            Py_DECREF(prep);
+            Py_DECREF(pargs);
+        } else {
+            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
+                return NULL;
+            PyErr_Clear();
+            ns = PyDict_New();
+        }
     } else {
-#else
-    result = PyObject_GetItem(__pyx_d, name);
-    if (!result) {
-        PyErr_Clear();
-#endif
-        result = __Pyx_GetBuiltinName(name);
+        ns = PyDict_New();
+    }
+    if (unlikely(!ns))
+        return NULL;
+    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
+    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
+    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
+    return ns;
+bad:
+    Py_DECREF(ns);
+    return NULL;
+}
+static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
+                                      PyObject *dict, PyObject *mkw,
+                                      int calculate_metaclass, int allow_py2_metaclass) {
+    PyObject *result, *margs;
+    PyObject *owned_metaclass = NULL;
+    if (allow_py2_metaclass) {
+        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
+        if (owned_metaclass) {
+            metaclass = owned_metaclass;
+        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
+            PyErr_Clear();
+        } else {
+            return NULL;
+        }
+    }
+    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
+        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
+        Py_XDECREF(owned_metaclass);
+        if (unlikely(!metaclass))
+            return NULL;
+        owned_metaclass = metaclass;
+    }
+    margs = PyTuple_Pack(3, name, bases, dict);
+    if (unlikely(!margs)) {
+        result = NULL;
+    } else {
+        result = PyObject_Call(metaclass, margs, mkw);
+        Py_DECREF(margs);
     }
+    Py_XDECREF(owned_metaclass);
     return result;
 }
 
@@ -5978,7 +9814,7 @@ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int co
         return count;
     }
     while (start < end) {
-        mid = (start + end) / 2;
+        mid = start + (end - start) / 2;
         if (code_line < entries[mid].code_line) {
             end = mid;
         } else if (code_line > entries[mid].code_line) {
@@ -6131,29 +9967,29 @@ bad:
     Py_XDECREF(py_frame);
 }
 
-#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)       \
-    {                                                                     \
-        func_type value = func_value;                                     \
-        if (sizeof(target_type) < sizeof(func_type)) {                    \
-            if (unlikely(value != (func_type) (target_type) value)) {     \
-                func_type zero = 0;                                       \
-                if (is_unsigned && unlikely(value < zero))                \
-                    goto raise_neg_overflow;                              \
-                else                                                      \
-                    goto raise_overflow;                                  \
-            }                                                             \
-        }                                                                 \
-        return (target_type) value;                                       \
+#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
+#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
+#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
+    {\
+        func_type value = func_value;\
+        if (sizeof(target_type) < sizeof(func_type)) {\
+            if (unlikely(value != (func_type) (target_type) value)) {\
+                func_type zero = 0;\
+                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
+                    return (target_type) -1;\
+                if (is_unsigned && unlikely(value < zero))\
+                    goto raise_neg_overflow;\
+                else\
+                    goto raise_overflow;\
+            }\
+        }\
+        return (target_type) value;\
     }
 
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-  #include "longintrepr.h"
- #endif
-#endif
-
 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
-    const int neg_one = (int) -1, const_zero = 0;
+    const int neg_one = (int) -1, const_zero = (int) 0;
     const int is_unsigned = neg_one > const_zero;
 #if PY_MAJOR_VERSION < 3
     if (likely(PyInt_Check(x))) {
@@ -6170,13 +10006,39 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
 #endif
     if (likely(PyLong_Check(x))) {
         if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(int, digit, ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (int) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
 #if CYTHON_COMPILING_IN_CPYTHON
             if (unlikely(Py_SIZE(x) < 0)) {
@@ -6192,24 +10054,77 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
             }
 #endif
             if (sizeof(int) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
             } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
             }
         } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +(((PyLongObject*)x)->ob_digit[0]));
-                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (int) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
             if (sizeof(int) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
             } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(int, PY_LONG_LONG, PyLong_AsLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
             }
         }
         {
@@ -6258,7 +10173,7 @@ raise_neg_overflow:
 }
 
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
-    const long neg_one = (long) -1, const_zero = 0;
+    const long neg_one = (long) -1, const_zero = (long) 0;
     const int is_unsigned = neg_one > const_zero;
     if (is_unsigned) {
         if (sizeof(long) < sizeof(long)) {
@@ -6283,8 +10198,192 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
     }
 }
 
+static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
+    const unsigned char neg_one = (unsigned char) -1, const_zero = (unsigned char) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(unsigned char) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(unsigned char, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (unsigned char) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (unsigned char) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(unsigned char, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) >= 2 * PyLong_SHIFT) {
+                            return (unsigned char) (((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) >= 3 * PyLong_SHIFT) {
+                            return (unsigned char) (((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) >= 4 * PyLong_SHIFT) {
+                            return (unsigned char) (((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (unsigned char) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(unsigned char) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned long, PyLong_AsUnsignedLong(x))
+            } else if (sizeof(unsigned char) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (unsigned char) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(unsigned char, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(unsigned char,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(unsigned char) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
+                            return (unsigned char) (((unsigned char)-1)*(((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
+                            return (unsigned char) ((((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
+                            return (unsigned char) (((unsigned char)-1)*(((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
+                            return (unsigned char) ((((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) {
+                            return (unsigned char) (((unsigned char)-1)*(((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) {
+                            return (unsigned char) ((((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(unsigned char) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, long, PyLong_AsLong(x))
+            } else if (sizeof(unsigned char) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, PY_LONG_LONG, PyLong_AsLongLong(x))
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            unsigned char val;
+            PyObject *v = __Pyx_PyNumber_Int(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (unsigned char) -1;
+        }
+    } else {
+        unsigned char val;
+        PyObject *tmp = __Pyx_PyNumber_Int(x);
+        if (!tmp) return (unsigned char) -1;
+        val = __Pyx_PyInt_As_unsigned_char(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to unsigned char");
+    return (unsigned char) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to unsigned char");
+    return (unsigned char) -1;
+}
+
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
-    const int neg_one = (int) -1, const_zero = 0;
+    const int neg_one = (int) -1, const_zero = (int) 0;
     const int is_unsigned = neg_one > const_zero;
     if (is_unsigned) {
         if (sizeof(int) < sizeof(long)) {
@@ -6310,7 +10409,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
 }
 
 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
-    const long neg_one = (long) -1, const_zero = 0;
+    const long neg_one = (long) -1, const_zero = (long) 0;
     const int is_unsigned = neg_one > const_zero;
 #if PY_MAJOR_VERSION < 3
     if (likely(PyInt_Check(x))) {
@@ -6327,13 +10426,39 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
 #endif
     if (likely(PyLong_Check(x))) {
         if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(long, digit, ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (long) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
 #if CYTHON_COMPILING_IN_CPYTHON
             if (unlikely(Py_SIZE(x) < 0)) {
@@ -6349,24 +10474,77 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
             }
 #endif
             if (sizeof(long) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
             } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
             }
         } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +(((PyLongObject*)x)->ob_digit[0]));
-                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (long) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
             if (sizeof(long) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
             } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(long, PY_LONG_LONG, PyLong_AsLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
             }
         }
         {
@@ -6414,6 +10592,754 @@ raise_neg_overflow:
     return (long) -1;
 }
 
+static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
+    PyObject *tmp_type, *tmp_value, *tmp_tb;
+#if CYTHON_COMPILING_IN_CPYTHON
+    PyThreadState *tstate = PyThreadState_GET();
+    tmp_type = tstate->exc_type;
+    tmp_value = tstate->exc_value;
+    tmp_tb = tstate->exc_traceback;
+    tstate->exc_type = *type;
+    tstate->exc_value = *value;
+    tstate->exc_traceback = *tb;
+#else
+    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
+    PyErr_SetExcInfo(*type, *value, *tb);
+#endif
+    *type = tmp_type;
+    *value = tmp_value;
+    *tb = tmp_tb;
+}
+
+static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
+    PyObject *method, *result = NULL;
+    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
+    if (unlikely(!method)) goto bad;
+#if CYTHON_COMPILING_IN_CPYTHON
+    if (likely(PyMethod_Check(method))) {
+        PyObject *self = PyMethod_GET_SELF(method);
+        if (likely(self)) {
+            PyObject *args;
+            PyObject *function = PyMethod_GET_FUNCTION(method);
+            args = PyTuple_New(2);
+            if (unlikely(!args)) goto bad;
+            Py_INCREF(self);
+            PyTuple_SET_ITEM(args, 0, self);
+            Py_INCREF(arg);
+            PyTuple_SET_ITEM(args, 1, arg);
+            Py_INCREF(function);
+            Py_DECREF(method); method = NULL;
+            result = __Pyx_PyObject_Call(function, args, NULL);
+            Py_DECREF(args);
+            Py_DECREF(function);
+            return result;
+        }
+    }
+#endif
+    result = __Pyx_PyObject_CallOneArg(method, arg);
+bad:
+    Py_XDECREF(method);
+    return result;
+}
+
+#include <structmember.h>
+#include <frameobject.h>
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
+static PyObject *__Pyx_Coroutine_Close(PyObject *self);
+static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
+#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
+#if 1 || PY_VERSION_HEX < 0x030300B0
+static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
+    PyObject *et, *ev, *tb;
+    PyObject *value = NULL;
+    __Pyx_ErrFetch(&et, &ev, &tb);
+    if (!et) {
+        Py_XDECREF(tb);
+        Py_XDECREF(ev);
+        Py_INCREF(Py_None);
+        *pvalue = Py_None;
+        return 0;
+    }
+    if (likely(et == PyExc_StopIteration)) {
+#if PY_VERSION_HEX >= 0x030300A0
+        if (ev && Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
+            value = ((PyStopIterationObject *)ev)->value;
+            Py_INCREF(value);
+            Py_DECREF(ev);
+            Py_XDECREF(tb);
+            Py_DECREF(et);
+            *pvalue = value;
+            return 0;
+        }
+#endif
+        if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
+            if (!ev) {
+                Py_INCREF(Py_None);
+                ev = Py_None;
+            } else if (PyTuple_Check(ev)) {
+                if (PyTuple_GET_SIZE(ev) >= 1) {
+                    PyObject *value;
+#if CYTHON_COMPILING_IN_CPYTHON
+                    value = PySequence_ITEM(ev, 0);
+#else
+                    value = PyTuple_GET_ITEM(ev, 0);
+                    Py_INCREF(value);
+#endif
+                    Py_DECREF(ev);
+                    ev = value;
+                } else {
+                    Py_INCREF(Py_None);
+                    Py_DECREF(ev);
+                    ev = Py_None;
+                }
+            }
+            Py_XDECREF(tb);
+            Py_DECREF(et);
+            *pvalue = ev;
+            return 0;
+        }
+    } else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
+        __Pyx_ErrRestore(et, ev, tb);
+        return -1;
+    }
+    PyErr_NormalizeException(&et, &ev, &tb);
+    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
+        __Pyx_ErrRestore(et, ev, tb);
+        return -1;
+    }
+    Py_XDECREF(tb);
+    Py_DECREF(et);
+#if PY_VERSION_HEX >= 0x030300A0
+    value = ((PyStopIterationObject *)ev)->value;
+    Py_INCREF(value);
+    Py_DECREF(ev);
+#else
+    {
+        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
+        Py_DECREF(ev);
+        if (likely(args)) {
+            value = PySequence_GetItem(args, 0);
+            Py_DECREF(args);
+        }
+        if (unlikely(!value)) {
+            __Pyx_ErrRestore(NULL, NULL, NULL);
+            Py_INCREF(Py_None);
+            value = Py_None;
+        }
+    }
+#endif
+    *pvalue = value;
+    return 0;
+}
+#endif
+static CYTHON_INLINE
+void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) {
+    PyObject *exc_type = self->exc_type;
+    PyObject *exc_value = self->exc_value;
+    PyObject *exc_traceback = self->exc_traceback;
+    self->exc_type = NULL;
+    self->exc_value = NULL;
+    self->exc_traceback = NULL;
+    Py_XDECREF(exc_type);
+    Py_XDECREF(exc_value);
+    Py_XDECREF(exc_traceback);
+}
+static CYTHON_INLINE
+int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) {
+    if (unlikely(gen->is_running)) {
+        PyErr_SetString(PyExc_ValueError,
+                        "generator already executing");
+        return 1;
+    }
+    return 0;
+}
+static CYTHON_INLINE
+PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
+    PyObject *retval;
+    assert(!self->is_running);
+    if (unlikely(self->resume_label == 0)) {
+        if (unlikely(value && value != Py_None)) {
+            PyErr_SetString(PyExc_TypeError,
+                            "can't send non-None value to a "
+                            "just-started generator");
+            return NULL;
+        }
+    }
+    if (unlikely(self->resume_label == -1)) {
+        PyErr_SetNone(PyExc_StopIteration);
+        return NULL;
+    }
+    if (value) {
+#if CYTHON_COMPILING_IN_PYPY
+#else
+        if (self->exc_traceback) {
+            PyThreadState *tstate = PyThreadState_GET();
+            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
+            PyFrameObject *f = tb->tb_frame;
+            Py_XINCREF(tstate->frame);
+            assert(f->f_back == NULL);
+            f->f_back = tstate->frame;
+        }
+#endif
+        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
+                            &self->exc_traceback);
+    } else {
+        __Pyx_Coroutine_ExceptionClear(self);
+    }
+    self->is_running = 1;
+    retval = self->body((PyObject *) self, value);
+    self->is_running = 0;
+    if (retval) {
+        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
+                            &self->exc_traceback);
+#if CYTHON_COMPILING_IN_PYPY
+#else
+        if (self->exc_traceback) {
+            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
+            PyFrameObject *f = tb->tb_frame;
+            Py_CLEAR(f->f_back);
+        }
+#endif
+    } else {
+        __Pyx_Coroutine_ExceptionClear(self);
+    }
+    return retval;
+}
+static CYTHON_INLINE
+PyObject *__Pyx_Coroutine_MethodReturn(PyObject *retval) {
+    if (unlikely(!retval && !PyErr_Occurred())) {
+        PyErr_SetNone(PyExc_StopIteration);
+    }
+    return retval;
+}
+static CYTHON_INLINE
+PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
+    PyObject *ret;
+    PyObject *val = NULL;
+    __Pyx_Coroutine_Undelegate(gen);
+    __Pyx_PyGen_FetchStopIterationValue(&val);
+    ret = __Pyx_Coroutine_SendEx(gen, val);
+    Py_XDECREF(val);
+    return ret;
+}
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
+    PyObject *retval;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
+        return NULL;
+    if (yf) {
+        PyObject *ret;
+        gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
+        if (__Pyx_Generator_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        {
+            if (value == Py_None)
+                ret = PyIter_Next(yf);
+            else
+                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
+        }
+        gen->is_running = 0;
+        if (likely(ret)) {
+            return ret;
+        }
+        retval = __Pyx_Coroutine_FinishDelegation(gen);
+    } else {
+        retval = __Pyx_Coroutine_SendEx(gen, value);
+    }
+    return __Pyx_Coroutine_MethodReturn(retval);
+}
+static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
+    PyObject *retval = NULL;
+    int err = 0;
+    #ifdef __Pyx_Generator_USED
+    if (__Pyx_Generator_CheckExact(yf)) {
+        retval = __Pyx_Coroutine_Close(yf);
+        if (!retval)
+            return -1;
+    } else
+    #endif
+    #ifdef __Pyx_Coroutine_USED
+    if (__Pyx_Coroutine_CheckExact(yf)) {
+        retval = __Pyx_Coroutine_Close(yf);
+        if (!retval)
+            return -1;
+    } else
+    #endif
+    {
+        PyObject *meth;
+        gen->is_running = 1;
+        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
+        if (unlikely(!meth)) {
+            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+                PyErr_WriteUnraisable(yf);
+            }
+            PyErr_Clear();
+        } else {
+            retval = PyObject_CallFunction(meth, NULL);
+            Py_DECREF(meth);
+            if (!retval)
+                err = -1;
+        }
+        gen->is_running = 0;
+    }
+    Py_XDECREF(retval);
+    return err;
+}
+static PyObject *__Pyx_Generator_Next(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
+        return NULL;
+    if (yf) {
+        PyObject *ret;
+        gen->is_running = 1;
+        ret = Py_TYPE(yf)->tp_iternext(yf);
+        gen->is_running = 0;
+        if (likely(ret)) {
+            return ret;
+        }
+        return __Pyx_Coroutine_FinishDelegation(gen);
+    }
+    return __Pyx_Coroutine_SendEx(gen, Py_None);
+}
+static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject *retval, *raised_exception;
+    PyObject *yf = gen->yieldfrom;
+    int err = 0;
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
+        return NULL;
+    if (yf) {
+        Py_INCREF(yf);
+        err = __Pyx_Coroutine_CloseIter(gen, yf);
+        __Pyx_Coroutine_Undelegate(gen);
+        Py_DECREF(yf);
+    }
+    if (err == 0)
+        PyErr_SetNone(PyExc_GeneratorExit);
+    retval = __Pyx_Coroutine_SendEx(gen, NULL);
+    if (retval) {
+        Py_DECREF(retval);
+        PyErr_SetString(PyExc_RuntimeError,
+                        "generator ignored GeneratorExit");
+        return NULL;
+    }
+    raised_exception = PyErr_Occurred();
+    if (!raised_exception
+        || raised_exception == PyExc_StopIteration
+        || raised_exception == PyExc_GeneratorExit
+        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
+        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
+    {
+        if (raised_exception) PyErr_Clear();
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+    return NULL;
+}
+static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject *typ;
+    PyObject *tb = NULL;
+    PyObject *val = NULL;
+    PyObject *yf = gen->yieldfrom;
+    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
+        return NULL;
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
+        return NULL;
+    if (yf) {
+        PyObject *ret;
+        Py_INCREF(yf);
+        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
+            int err = __Pyx_Coroutine_CloseIter(gen, yf);
+            Py_DECREF(yf);
+            __Pyx_Coroutine_Undelegate(gen);
+            if (err < 0)
+                return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
+            goto throw_here;
+        }
+        gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
+        if (__Pyx_Generator_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Throw(yf, args);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Throw(yf, args);
+        } else
+        #endif
+        {
+            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
+            if (unlikely(!meth)) {
+                Py_DECREF(yf);
+                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+                    gen->is_running = 0;
+                    return NULL;
+                }
+                PyErr_Clear();
+                __Pyx_Coroutine_Undelegate(gen);
+                gen->is_running = 0;
+                goto throw_here;
+            }
+            ret = PyObject_CallObject(meth, args);
+            Py_DECREF(meth);
+        }
+        gen->is_running = 0;
+        Py_DECREF(yf);
+        if (!ret) {
+            ret = __Pyx_Coroutine_FinishDelegation(gen);
+        }
+        return __Pyx_Coroutine_MethodReturn(ret);
+    }
+throw_here:
+    __Pyx_Raise(typ, val, tb, NULL);
+    return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
+}
+static int __Pyx_Coroutine_traverse(PyObject *self, visitproc visit, void *arg) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    Py_VISIT(gen->closure);
+    Py_VISIT(gen->classobj);
+    Py_VISIT(gen->yieldfrom);
+    Py_VISIT(gen->exc_type);
+    Py_VISIT(gen->exc_value);
+    Py_VISIT(gen->exc_traceback);
+    return 0;
+}
+static int __Pyx_Coroutine_clear(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    Py_CLEAR(gen->closure);
+    Py_CLEAR(gen->classobj);
+    Py_CLEAR(gen->yieldfrom);
+    Py_CLEAR(gen->exc_type);
+    Py_CLEAR(gen->exc_value);
+    Py_CLEAR(gen->exc_traceback);
+    Py_CLEAR(gen->gi_name);
+    Py_CLEAR(gen->gi_qualname);
+    return 0;
+}
+static void __Pyx_Coroutine_dealloc(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    PyObject_GC_UnTrack(gen);
+    if (gen->gi_weakreflist != NULL)
+        PyObject_ClearWeakRefs(self);
+    if (gen->resume_label > 0) {
+        PyObject_GC_Track(self);
+#if PY_VERSION_HEX >= 0x030400a1
+        if (PyObject_CallFinalizerFromDealloc(self))
+#else
+        Py_TYPE(gen)->tp_del(self);
+        if (self->ob_refcnt > 0)
+#endif
+        {
+            return;
+        }
+        PyObject_GC_UnTrack(self);
+    }
+    __Pyx_Coroutine_clear(self);
+    PyObject_GC_Del(gen);
+}
+static void __Pyx_Coroutine_del(PyObject *self) {
+    PyObject *res;
+    PyObject *error_type, *error_value, *error_traceback;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
+    if (gen->resume_label <= 0)
+        return ;
+#if PY_VERSION_HEX < 0x030400a1
+    assert(self->ob_refcnt == 0);
+    self->ob_refcnt = 1;
+#endif
+    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
+    res = __Pyx_Coroutine_Close(self);
+    if (res == NULL)
+        PyErr_WriteUnraisable(self);
+    else
+        Py_DECREF(res);
+    __Pyx_ErrRestore(error_type, error_value, error_traceback);
+#if PY_VERSION_HEX < 0x030400a1
+    assert(self->ob_refcnt > 0);
+    if (--self->ob_refcnt == 0) {
+        return;
+    }
+    {
+        Py_ssize_t refcnt = self->ob_refcnt;
+        _Py_NewReference(self);
+        self->ob_refcnt = refcnt;
+    }
+#if CYTHON_COMPILING_IN_CPYTHON
+    assert(PyType_IS_GC(self->ob_type) &&
+           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
+    _Py_DEC_REFTOTAL;
+#endif
+#ifdef COUNT_ALLOCS
+    --Py_TYPE(self)->tp_frees;
+    --Py_TYPE(self)->tp_allocs;
+#endif
+#endif
+}
+static PyObject *
+__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self)
+{
+    Py_INCREF(self->gi_name);
+    return self->gi_name;
+}
+static int
+__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
+#else
+    if (unlikely(value == NULL || !PyString_Check(value))) {
+#endif
+        PyErr_SetString(PyExc_TypeError,
+                        "__name__ must be set to a string object");
+        return -1;
+    }
+    tmp = self->gi_name;
+    Py_INCREF(value);
+    self->gi_name = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static PyObject *
+__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
+{
+    Py_INCREF(self->gi_qualname);
+    return self->gi_qualname;
+}
+static int
+__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value)
+{
+    PyObject *tmp;
+#if PY_MAJOR_VERSION >= 3
+    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
+#else
+    if (unlikely(value == NULL || !PyString_Check(value))) {
+#endif
+        PyErr_SetString(PyExc_TypeError,
+                        "__qualname__ must be set to a string object");
+        return -1;
+    }
+    tmp = self->gi_qualname;
+    Py_INCREF(value);
+    self->gi_qualname = value;
+    Py_XDECREF(tmp);
+    return 0;
+}
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject* type, __pyx_coroutine_body_t body,
+                                                   PyObject *closure, PyObject *name, PyObject *qualname) {
+    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
+    if (gen == NULL)
+        return NULL;
+    gen->body = body;
+    gen->closure = closure;
+    Py_XINCREF(closure);
+    gen->is_running = 0;
+    gen->resume_label = 0;
+    gen->classobj = NULL;
+    gen->yieldfrom = NULL;
+    gen->exc_type = NULL;
+    gen->exc_value = NULL;
+    gen->exc_traceback = NULL;
+    gen->gi_weakreflist = NULL;
+    Py_XINCREF(qualname);
+    gen->gi_qualname = qualname;
+    Py_XINCREF(name);
+    gen->gi_name = name;
+    PyObject_GC_Track(gen);
+    return gen;
+}
+
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    int result;
+    PyObject *globals, *result_obj;
+    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
+    #ifdef __Pyx_Coroutine_USED
+        (PyObject*)__pyx_CoroutineType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_generator_type",
+    #ifdef __Pyx_Generator_USED
+        (PyObject*)__pyx_GeneratorType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
+    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
+    if (unlikely(!result_obj)) goto ignore;
+    Py_DECREF(result_obj);
+    Py_DECREF(globals);
+    return module;
+ignore:
+    Py_XDECREF(globals);
+    PyErr_WriteUnraisable(module);
+    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
+        Py_DECREF(module);
+        module = NULL;
+    }
+#else
+    py_code++;
+#endif
+    return module;
+}
+
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+static PyObject* __Pyx_patch_abc_module(PyObject *module);
+static PyObject* __Pyx_patch_abc_module(PyObject *module) {
+    module = __Pyx_Coroutine_patch_module(
+        module, ""
+"if _cython_generator_type is not None:\n"
+"    try: Generator = _module.Generator\n"
+"    except AttributeError: pass\n"
+"    else: Generator.register(_cython_generator_type)\n"
+"if _cython_coroutine_type is not None:\n"
+"    try: Coroutine = _module.Coroutine\n"
+"    except AttributeError: pass\n"
+"    else: Coroutine.register(_cython_coroutine_type)\n"
+    );
+    return module;
+}
+#endif
+static int __Pyx_patch_abc(void) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    static int abc_patched = 0;
+    if (!abc_patched) {
+        PyObject *module;
+        module = PyImport_ImportModule((PY_VERSION_HEX >= 0x03030000) ? "collections.abc" : "collections");
+        if (!module) {
+            PyErr_WriteUnraisable(NULL);
+            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
+                    ((PY_VERSION_HEX >= 0x03030000) ?
+                        "Cython module failed to register with collections.abc module" :
+                        "Cython module failed to register with collections module"), 1) < 0)) {
+                return -1;
+            }
+        } else {
+            module = __Pyx_patch_abc_module(module);
+            abc_patched = 1;
+            if (unlikely(!module))
+                return -1;
+            Py_DECREF(module);
+        }
+        module = PyImport_ImportModule("backports_abc");
+        if (module) {
+            module = __Pyx_patch_abc_module(module);
+            Py_XDECREF(module);
+        }
+        if (!module) {
+            PyErr_Clear();
+        }
+    }
+#else
+    if (0) __Pyx_Coroutine_patch_module(NULL, NULL);
+#endif
+    return 0;
+}
+
+static PyMethodDef __pyx_Generator_methods[] = {
+    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
+     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
+    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
+     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
+    {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS,
+     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
+    {0, 0, 0, 0}
+};
+static PyMemberDef __pyx_Generator_memberlist[] = {
+    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
+    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
+     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
+    {0, 0, 0, 0, 0}
+};
+static PyGetSetDef __pyx_Generator_getsets[] = {
+    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
+     (char*) PyDoc_STR("name of the generator"), 0},
+    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
+     (char*) PyDoc_STR("qualified name of the generator"), 0},
+    {0, 0, 0, 0, 0}
+};
+static PyTypeObject __pyx_GeneratorType_type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    "generator",
+    sizeof(__pyx_CoroutineObject),
+    0,
+    (destructor) __Pyx_Coroutine_dealloc,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
+    0,
+    (traverseproc) __Pyx_Coroutine_traverse,
+    0,
+    0,
+    offsetof(__pyx_CoroutineObject, gi_weakreflist),
+    0,
+    (iternextfunc) __Pyx_Generator_Next,
+    __pyx_Generator_methods,
+    __pyx_Generator_memberlist,
+    __pyx_Generator_getsets,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    0,
+#else
+    __Pyx_Coroutine_del,
+#endif
+    0,
+#if PY_VERSION_HEX >= 0x030400a1
+    __Pyx_Coroutine_del,
+#endif
+};
+static int __pyx_Generator_init(void) {
+    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
+    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
+    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
+    if (unlikely(!__pyx_GeneratorType)) {
+        return -1;
+    }
+    return 0;
+}
+
 static int __Pyx_check_binary_version(void) {
     char ctversion[4], rtversion[4];
     PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
@@ -6467,7 +11393,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
     return __Pyx_PyObject_AsStringAndSize(o, &ignore);
 }
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
-#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
     if (
 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
             __Pyx_sys_getdefaultencoding_not_ascii &&
@@ -6508,7 +11434,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_
 #endif
     } else
 #endif
-#if !CYTHON_COMPILING_IN_PYPY
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
     if (PyByteArray_Check(o)) {
         *length = PyByteArray_GET_SIZE(o);
         return PyByteArray_AS_STRING(o);
@@ -6538,7 +11464,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
 #else
   if (PyLong_Check(x))
 #endif
-    return Py_INCREF(x), x;
+    return __Pyx_NewRef(x);
   m = Py_TYPE(x)->tp_as_number;
 #if PY_MAJOR_VERSION < 3
   if (m && m->nb_int) {
@@ -6578,18 +11504,55 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
   Py_ssize_t ival;
   PyObject *x;
 #if PY_MAJOR_VERSION < 3
-  if (likely(PyInt_CheckExact(b)))
-      return PyInt_AS_LONG(b);
+  if (likely(PyInt_CheckExact(b))) {
+    if (sizeof(Py_ssize_t) >= sizeof(long))
+        return PyInt_AS_LONG(b);
+    else
+        return PyInt_AsSsize_t(x);
+  }
 #endif
   if (likely(PyLong_CheckExact(b))) {
-    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
-     #if CYTHON_USE_PYLONG_INTERNALS
-       switch (Py_SIZE(b)) {
-       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
-       case  0: return 0;
-       case  1: return ((PyLongObject*)b)->ob_digit[0];
-       }
-     #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    const digit* digits = ((PyLongObject*)b)->ob_digit;
+    const Py_ssize_t size = Py_SIZE(b);
+    if (likely(__Pyx_sst_abs(size) <= 1)) {
+        ival = likely(size) ? digits[0] : 0;
+        if (size == -1) ival = -ival;
+        return ival;
+    } else {
+      switch (size) {
+         case 2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+      }
+    }
     #endif
     return PyLong_AsSsize_t(b);
   }
diff --git a/cutadapt/_align.pyx b/cutadapt/_align.pyx
index 1fe51b5..6c8fa47 100644
--- a/cutadapt/_align.pyx
+++ b/cutadapt/_align.pyx
@@ -5,14 +5,6 @@ DEF START_WITHIN_SEQ2 = 2
 DEF STOP_WITHIN_SEQ1 = 4
 DEF STOP_WITHIN_SEQ2 = 8
 DEF SEMIGLOBAL = 15
-DEF ALLOW_WILDCARD_SEQ1 = 1
-DEF ALLOW_WILDCARD_SEQ2 = 2
-
-DEF INSERTION_COST = 1
-DEF DELETION_COST = 1
-DEF MATCH_COST = 0
-DEF MISMATCH_COST = 1
-DEF WILDCARD_CHAR = 'N'
 
 # structure for a DP matrix entry
 ctypedef struct _Entry:
@@ -89,6 +81,40 @@ cdef bytes ACGT_TABLE = _acgt_table()
 cdef bytes IUPAC_TABLE = _iupac_table()
 
 
+class DPMatrix:
+	"""
+	Representation of the dynamic-programming matrix.
+
+	This used only when debugging is enabled in the Aligner class since the
+	matrix is normally not stored in full.
+
+	Entries in the matrix may be None, in which case that value was not
+	computed.
+	"""
+	def __init__(self, reference, query):
+		m = len(reference)
+		n = len(query)
+		self._rows = [ [None] * (n+1) for _ in range(m + 1) ]
+		self.reference = reference
+		self.query = query
+
+	def set_entry(self, int i, int j, cost):
+		"""
+		Set an entry in the dynamic programming matrix.
+		"""
+		self._rows[i][j] = cost
+
+	def __str__(self):
+		"""
+		Return a representation of the matrix as a string.
+		"""
+		rows = ['     ' + ' '.join(c.rjust(2) for c in self.query)]
+		for c, row in zip(' ' + self.reference, self._rows):
+			r = c + ' ' + ' '.join('  ' if v is None else '{0:2d}'.format(v) for v in row)
+			rows.append(r)
+		return '\n'.join(rows)
+
+
 cdef class Aligner:
 	"""
 	TODO documentation still uses s1 (reference) and s2 (query).
@@ -145,7 +171,7 @@ cdef class Aligner:
 	It is always the case that at least one of start1 and start2 is zero.
 
 	IUPAC wildcard characters can be allowed in the reference and the query
-	by setting the appropriate bit in the 'degenerate' flag.
+	by setting the appropriate flags.
 
 	If neither flag is set, the full ASCII alphabet is used for comparison.
 	If any of the flags is set, all non-IUPAC characters in the sequences
@@ -155,20 +181,48 @@ cdef class Aligner:
 	cdef _Entry* column  # one column of the DP matrix
 	cdef double max_error_rate
 	cdef int flags
-	cdef int min_overlap
+	cdef int _insertion_cost
+	cdef int _deletion_cost
+	cdef int _min_overlap
 	cdef bint wildcard_ref
 	cdef bint wildcard_query
-	cdef bytes _reference
+	cdef bint debug
+	cdef object _dpmatrix
+	cdef bytes _reference  # TODO rename to translated_reference or so
+	cdef str str_reference
 
-	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
+	def __cinit__(self, str reference, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False):
 		self.max_error_rate = max_error_rate
 		self.flags = flags
-		self.wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
-		self.wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
+		self.wildcard_ref = wildcard_ref
+		self.wildcard_query = wildcard_query
+		self.str_reference = reference
 		self.reference = reference
-		if min_overlap < 1:
-			raise ValueError("minimum overlap must be at least 1")
-		self.min_overlap = min_overlap
+		self._min_overlap = 1
+		self.debug = False
+		self._dpmatrix = None
+		self._insertion_cost = 1
+		self._deletion_cost = 1
+
+	property min_overlap:
+		def __get__(self):
+			return self._min_overlap
+
+		def __set__(self, int value):
+			if value < 1:
+				raise ValueError('Minimum overlap must be at least 1')
+			self._min_overlap = value
+
+	property indel_cost:
+		"""
+		Matches cost 0, mismatches cost 1. Only insertion/deletion costs can be
+		changed.
+		"""
+		def __set__(self, value):
+			if value < 1:
+				raise ValueError('Insertion/deletion cost must be at leat 1')
+			self._insertion_cost = value
+			self._deletion_cost = value
 
 	property reference:
 		def __get__(self):
@@ -185,6 +239,22 @@ cdef class Aligner:
 				self._reference = self._reference.translate(IUPAC_TABLE)
 			elif self.wildcard_query:
 				self._reference = self._reference.translate(ACGT_TABLE)
+			self.str_reference = reference
+
+	property dpmatrix:
+		"""
+		The dynamic programming matrix as a DPMatrix object. This attribute is
+		usually None, unless debugging has been enabled with enable_debug().
+		"""
+		def __get__(self):
+			return self._dpmatrix
+
+	def enable_debug(self):
+		"""
+		Store the dynamic programming matrix while running the locate() method
+		and make it available in the .dpmatrix attribute.
+		"""
+		self.debug = True
 
 	def locate(self, str query):
 		"""
@@ -254,26 +324,30 @@ cdef class Aligner:
 		# TODO (later)
 		# fill out columns only until 'last'
 		if not start_in_ref and not start_in_query:
-			for i in range(0, m + 1):
+			for i in range(m + 1):
 				column[i].matches = 0
-				column[i].cost = max(i, min_n)
+				column[i].cost = max(i, min_n) * self._insertion_cost
 				column[i].origin = 0
 		elif start_in_ref and not start_in_query:
-			for i in range(0, m + 1):
+			for i in range(m + 1):
 				column[i].matches = 0
-				column[i].cost = min_n
+				column[i].cost = min_n * self._insertion_cost
 				column[i].origin = min(0, min_n - i)
 		elif not start_in_ref and start_in_query:
-			for i in range(0, m + 1):
+			for i in range(m + 1):
 				column[i].matches = 0
-				column[i].cost = i
+				column[i].cost = i * self._insertion_cost
 				column[i].origin = max(0, min_n - i)
 		else:
-			for i in range(0, m + 1):
+			for i in range(m + 1):
 				column[i].matches = 0
-				column[i].cost = min(i, min_n)
+				column[i].cost = min(i, min_n) * self._insertion_cost
 				column[i].origin = min_n - i
 
+		if self.debug:
+			self._dpmatrix = DPMatrix(self.str_reference, query)
+			for i in range(m + 1):
+				self._dpmatrix.set_entry(i, min_n, column[i].cost)
 		cdef _Match best
 		best.ref_stop = m
 		best.query_stop = n
@@ -282,7 +356,7 @@ cdef class Aligner:
 		best.matches = 0
 
 		# Ukkonen's trick: index of the last cell that is less than k.
-		cdef int last = k + 1
+		cdef int last = min(m, k + 1)
 		if start_in_ref:
 			last = m
 
@@ -294,77 +368,82 @@ cdef class Aligner:
 		cdef bint characters_equal
 		cdef _Entry tmp_entry
 
-		# iterate over columns
-		for j in range(min_n + 1, max_n + 1):
-			# remember first entry
-			tmp_entry = column[0]
-
-			# fill in first entry in this column
-			if start_in_query:
-				column[0].origin = j
-			else:
-				column[0].cost = j * INSERTION_COST
-			for i in range(1, last + 1):
-				if compare_ascii:
-					characters_equal = (s1[i-1] == s2[j-1])
-				else:
-					characters_equal = (s1[i-1] & s2[j-1]) != 0
-				if characters_equal:
-					# Characters match: This cannot be an indel.
-					cost = tmp_entry.cost
-					origin = tmp_entry.origin
-					matches = tmp_entry.matches + 1
+		with nogil:
+			# iterate over columns
+			for j in range(min_n + 1, max_n + 1):
+				# remember first entry
+				tmp_entry = column[0]
+
+				# fill in first entry in this column
+				if start_in_query:
+					column[0].origin = j
 				else:
-					# Characters do not match.
-					cost_diag = tmp_entry.cost + 1
-					cost_deletion = column[i].cost + DELETION_COST
-					cost_insertion = column[i-1].cost + INSERTION_COST
-
-					if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
-						# MISMATCH
-						cost = cost_diag
+					column[0].cost = j * self._insertion_cost
+				for i in range(1, last + 1):
+					if compare_ascii:
+						characters_equal = (s1[i-1] == s2[j-1])
+					else:
+						characters_equal = (s1[i-1] & s2[j-1]) != 0
+					if characters_equal:
+						# Characters match: This cannot be an indel.
+						cost = tmp_entry.cost
 						origin = tmp_entry.origin
-						matches = tmp_entry.matches
-					elif cost_insertion <= cost_deletion:
-						# INSERTION
-						cost = cost_insertion
-						origin = column[i-1].origin
-						matches = column[i-1].matches
+						matches = tmp_entry.matches + 1
 					else:
-						# DELETION
-						cost = cost_deletion
-						origin = column[i].origin
-						matches = column[i].matches
-
-				# remember current cell for next iteration
-				tmp_entry = column[i]
-
-				column[i].cost = cost
-				column[i].origin = origin
-				column[i].matches = matches
-			while last >= 0 and column[last].cost > k:
-				last -= 1
-			# last can be -1 here, but will be incremented next.
-			# TODO if last is -1, can we stop searching?
-			if last < m:
-				last += 1
-			elif stop_in_query:
-				# Found a match. If requested, find best match in last row.
-				# length of the aligned part of the reference
-				length = m + min(column[m].origin, 0)
-				cost = column[m].cost
-				matches = column[m].matches
-				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
-					# update
-					best.matches = matches
-					best.cost = cost
-					best.origin = column[m].origin
-					best.ref_stop = m
-					best.query_stop = j
-					if cost == 0 and matches == m:
-						# exact match, stop early
-						break
-			# column finished
+						# Characters do not match.
+						cost_diag = tmp_entry.cost + 1
+						cost_deletion = column[i].cost + self._deletion_cost
+						cost_insertion = column[i-1].cost + self._insertion_cost
+
+						if cost_diag <= cost_deletion and cost_diag <= cost_insertion:
+							# MISMATCH
+							cost = cost_diag
+							origin = tmp_entry.origin
+							matches = tmp_entry.matches
+						elif cost_insertion <= cost_deletion:
+							# INSERTION
+							cost = cost_insertion
+							origin = column[i-1].origin
+							matches = column[i-1].matches
+						else:
+							# DELETION
+							cost = cost_deletion
+							origin = column[i].origin
+							matches = column[i].matches
+
+					# remember current cell for next iteration
+					tmp_entry = column[i]
+
+					column[i].cost = cost
+					column[i].origin = origin
+					column[i].matches = matches
+				if self.debug:
+					with gil:
+						for i in range(last + 1):
+							self._dpmatrix.set_entry(i, j, column[i].cost)
+				while last >= 0 and column[last].cost > k:
+					last -= 1
+				# last can be -1 here, but will be incremented next.
+				# TODO if last is -1, can we stop searching?
+				if last < m:
+					last += 1
+				elif stop_in_query:
+					# Found a match. If requested, find best match in last row.
+					# length of the aligned part of the reference
+					length = m + min(column[m].origin, 0)
+					cost = column[m].cost
+					matches = column[m].matches
+					if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+						# update
+						best.matches = matches
+						best.cost = cost
+						best.origin = column[m].origin
+						best.ref_stop = m
+						best.query_stop = j
+						if cost == 0 and matches == m:
+							# exact match, stop early
+							break
+				# column finished
 
 		if max_n == n:
 			first_i = 0 if stop_in_ref else m
@@ -373,14 +452,13 @@ cdef class Aligner:
 				length = i + min(column[i].origin, 0)
 				cost = column[i].cost
 				matches = column[i].matches
-				if length >= self.min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
+				if length >= self._min_overlap and cost <= length * max_error_rate and (matches > best.matches or (matches == best.matches and cost < best.cost)):
 					# update best
 					best.matches = matches
 					best.cost = cost
 					best.origin = column[i].origin
 					best.ref_stop = i
 					best.query_stop = n
-
 		if best.cost == m + n:
 			# best.cost was initialized with this value.
 			# If it is unchanged, no alignment was found that has
@@ -402,16 +480,16 @@ cdef class Aligner:
 		PyMem_Free(self.column)
 
 
-def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, int degenerate=0, int min_overlap=1):
-	aligner = Aligner(reference, max_error_rate, flags, degenerate, min_overlap)
+def locate(str reference, str query, double max_error_rate, int flags=SEMIGLOBAL, bint wildcard_ref=False, bint wildcard_query=False, int min_overlap=1):
+	aligner = Aligner(reference, max_error_rate, flags, wildcard_ref, wildcard_query)
+	aligner.min_overlap = min_overlap
 	return aligner.locate(query)
 
 
-def compare_prefixes(str ref, str query, int degenerate=0):
+def compare_prefixes(str ref, str query, bint wildcard_ref=False, bint wildcard_query=False):
 	"""
 	Find out whether one string is the prefix of the other one, allowing
-	IUPAC wildcards if the appropriate bit is set in the degenerate flag
-	parameter.
+	IUPAC wildcards in ref and/or query if the appropriate flag is set.
 
 	This is used to find an anchored 5' adapter (type 'FRONT') in the 'no indels' mode.
 	This is very simple as only the number of errors needs to be counted.
@@ -424,8 +502,6 @@ def compare_prefixes(str ref, str query, int degenerate=0):
 	cdef bytes ref_bytes = ref.encode('ascii')
 	cdef char* r_ptr
 	cdef char* q_ptr
-	cdef bint wildcard_ref = degenerate & ALLOW_WILDCARD_SEQ1
-	cdef bint wildcard_query = degenerate & ALLOW_WILDCARD_SEQ2
 	cdef int length = min(m, n)
 	cdef int i, matches = 0
 	cdef bint compare_ascii = False
diff --git a/cutadapt/_align.so b/cutadapt/_align.so
index cf9c75c..c2c2133 100755
Binary files a/cutadapt/_align.so and b/cutadapt/_align.so differ
diff --git a/cutadapt/_qualtrim.c b/cutadapt/_qualtrim.c
index 88caf62..045cb63 100644
--- a/cutadapt/_qualtrim.c
+++ b/cutadapt/_qualtrim.c
@@ -1,26 +1,20 @@
-/* Generated by Cython 0.20.2 (Debian 0.20.2-1) on Mon Mar 16 17:13:50 2015 */
+/* Generated by Cython 0.23.1 */
+
+/* BEGIN: Cython Metadata
+{
+    "distutils": {}
+}
+END: Cython Metadata */
 
 #define PY_SSIZE_T_CLEAN
-#ifndef CYTHON_USE_PYLONG_INTERNALS
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#else
-#include "pyconfig.h"
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 1
-#else
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#endif
-#endif
-#endif
 #include "Python.h"
 #ifndef Py_PYTHON_H
     #error Python headers needed to compile C extensions, please install development version of Python.
-#elif PY_VERSION_HEX < 0x02040000
-    #error Cython requires Python 2.4+.
+#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
+    #error Cython requires Python 2.6+ or Python 3.2+.
 #else
-#define CYTHON_ABI "0_20_2"
-#include <stddef.h> /* For offsetof */
+#define CYTHON_ABI "0_23_1"
+#include <stddef.h>
 #ifndef offsetof
 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
 #endif
@@ -54,98 +48,40 @@
 #define CYTHON_COMPILING_IN_PYPY 0
 #define CYTHON_COMPILING_IN_CPYTHON 1
 #endif
-#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600
-#define Py_OptimizeFlag 0
+#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
+#define CYTHON_USE_PYLONG_INTERNALS 1
 #endif
-#if PY_VERSION_HEX < 0x02050000
-  typedef int Py_ssize_t;
-  #define PY_SSIZE_T_MAX INT_MAX
-  #define PY_SSIZE_T_MIN INT_MIN
-  #define PY_FORMAT_SIZE_T ""
-  #define CYTHON_FORMAT_SSIZE_T ""
-  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
-  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_As_int(o)
-  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
-                                (PyErr_Format(PyExc_TypeError, \
-                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
-                                 (PyObject*)0))
-  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
-                                  !PyComplex_Check(o))
-  #define PyIndex_Check __Pyx_PyIndex_Check
-  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
-  #define __PYX_BUILD_PY_SSIZE_T "i"
-#else
-  #define __PYX_BUILD_PY_SSIZE_T "n"
-  #define CYTHON_FORMAT_SSIZE_T "z"
-  #define __Pyx_PyIndex_Check PyIndex_Check
-#endif
-#if PY_VERSION_HEX < 0x02060000
-  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
-  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
-  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
-  #define PyVarObject_HEAD_INIT(type, size) \
-          PyObject_HEAD_INIT(type) size,
-  #define PyType_Modified(t)
-  typedef struct {
-     void *buf;
-     PyObject *obj;
-     Py_ssize_t len;
-     Py_ssize_t itemsize;
-     int readonly;
-     int ndim;
-     char *format;
-     Py_ssize_t *shape;
-     Py_ssize_t *strides;
-     Py_ssize_t *suboffsets;
-     void *internal;
-  } Py_buffer;
-  #define PyBUF_SIMPLE 0
-  #define PyBUF_WRITABLE 0x0001
-  #define PyBUF_FORMAT 0x0004
-  #define PyBUF_ND 0x0008
-  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
-  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
-  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
-  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
-  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
-  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
-  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
-  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
-  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
+#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
+#define Py_OptimizeFlag 0
 #endif
+#define __PYX_BUILD_PY_SSIZE_T "n"
+#define CYTHON_FORMAT_SSIZE_T "z"
 #if PY_MAJOR_VERSION < 3
   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyClass_Type
 #else
   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyType_Type
 #endif
-#if PY_VERSION_HEX < 0x02060000
-  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
-#endif
-#if PY_MAJOR_VERSION >= 3
+#ifndef Py_TPFLAGS_CHECKTYPES
   #define Py_TPFLAGS_CHECKTYPES 0
+#endif
+#ifndef Py_TPFLAGS_HAVE_INDEX
   #define Py_TPFLAGS_HAVE_INDEX 0
 #endif
-#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
+#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
   #define Py_TPFLAGS_HAVE_NEWBUFFER 0
 #endif
-#if PY_VERSION_HEX < 0x02060000
-  #define Py_TPFLAGS_HAVE_VERSION_TAG 0
-#endif
-#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT)
-  #define Py_TPFLAGS_IS_ABSTRACT 0
-#endif
-#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE)
+#ifndef Py_TPFLAGS_HAVE_FINALIZE
   #define Py_TPFLAGS_HAVE_FINALIZE 0
 #endif
 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
   #define CYTHON_PEP393_ENABLED 1
-  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
+  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                               0 : _PyUnicode_Ready((PyObject *)(op)))
   #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
   #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
@@ -166,10 +102,13 @@
   #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
 #else
   #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
-  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
       PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
 #endif
-#define __Pyx_PyString_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
+#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
+  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
+#endif
+#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
 #define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
 #if PY_MAJOR_VERSION >= 3
   #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
@@ -183,36 +122,13 @@
   #define PyString_Check               PyUnicode_Check
   #define PyString_CheckExact          PyUnicode_CheckExact
 #endif
-#if PY_VERSION_HEX < 0x02060000
-  #define PyBytesObject                PyStringObject
-  #define PyBytes_Type                 PyString_Type
-  #define PyBytes_Check                PyString_Check
-  #define PyBytes_CheckExact           PyString_CheckExact
-  #define PyBytes_FromString           PyString_FromString
-  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
-  #define PyBytes_FromFormat           PyString_FromFormat
-  #define PyBytes_DecodeEscape         PyString_DecodeEscape
-  #define PyBytes_AsString             PyString_AsString
-  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
-  #define PyBytes_Size                 PyString_Size
-  #define PyBytes_AS_STRING            PyString_AS_STRING
-  #define PyBytes_GET_SIZE             PyString_GET_SIZE
-  #define PyBytes_Repr                 PyString_Repr
-  #define PyBytes_Concat               PyString_Concat
-  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
-#endif
 #if PY_MAJOR_VERSION >= 3
   #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
   #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
 #else
-  #define __Pyx_PyBaseString_Check(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj) || \
-                                         PyString_Check(obj) || PyUnicode_Check(obj))
+  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
   #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
 #endif
-#if PY_VERSION_HEX < 0x02060000
-  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
-  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
-#endif
 #ifndef PySet_CheckExact
   #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
 #endif
@@ -237,6 +153,11 @@
 #if PY_MAJOR_VERSION >= 3
   #define PyBoolObject                 PyLongObject
 #endif
+#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
+  #ifndef PyUnicode_InternFromString
+    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
+  #endif
+#endif
 #if PY_VERSION_HEX < 0x030200A4
   typedef long Py_hash_t;
   #define __Pyx_PyInt_FromHash_t PyInt_FromLong
@@ -245,43 +166,37 @@
   #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
   #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
 #endif
-#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
-  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
-  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
-  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
-#else
-  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
-        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
-        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
-            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
-  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
-        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
-        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
-            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
-  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
-        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
-        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
-            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
-#endif
 #if PY_MAJOR_VERSION >= 3
-  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
-#endif
-#if PY_VERSION_HEX < 0x02050000
-  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
-  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
-  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
+  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
 #else
-  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
-  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
-  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
+  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
 #endif
-#if PY_VERSION_HEX < 0x02050000
-  #define __Pyx_NAMESTR(n) ((char *)(n))
-  #define __Pyx_DOCSTR(n)  ((char *)(n))
+#if PY_VERSION_HEX >= 0x030500B1
+#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
+#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
+#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
+typedef struct {
+    unaryfunc am_await;
+    unaryfunc am_aiter;
+    unaryfunc am_anext;
+} __Pyx_PyAsyncMethodsStruct;
+#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
 #else
-  #define __Pyx_NAMESTR(n) (n)
-  #define __Pyx_DOCSTR(n)  (n)
+#define __Pyx_PyType_AsAsync(obj) NULL
+#endif
+#ifndef CYTHON_RESTRICT
+  #if defined(__GNUC__)
+    #define CYTHON_RESTRICT __restrict__
+  #elif defined(_MSC_VER) && _MSC_VER >= 1400
+    #define CYTHON_RESTRICT __restrict
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_RESTRICT restrict
+  #else
+    #define CYTHON_RESTRICT
+  #endif
 #endif
+#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
+
 #ifndef CYTHON_INLINE
   #if defined(__GNUC__)
     #define CYTHON_INLINE __inline__
@@ -293,35 +208,20 @@
     #define CYTHON_INLINE
   #endif
 #endif
-#ifndef CYTHON_RESTRICT
-  #if defined(__GNUC__)
-    #define CYTHON_RESTRICT __restrict__
-  #elif defined(_MSC_VER) && _MSC_VER >= 1400
-    #define CYTHON_RESTRICT __restrict
-  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-    #define CYTHON_RESTRICT restrict
-  #else
-    #define CYTHON_RESTRICT
-  #endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+  #define _USE_MATH_DEFINES
 #endif
+#include <math.h>
 #ifdef NAN
 #define __PYX_NAN() ((float) NAN)
 #else
 static CYTHON_INLINE float __PYX_NAN() {
-  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
-   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
-   a quiet NaN. */
   float value;
   memset(&value, 0xFF, sizeof(value));
   return value;
 }
 #endif
-#ifdef __cplusplus
-template<typename T>
-void __Pyx_call_destructor(T* x) {
-    x->~T();
-}
-#endif
 
 
 #if PY_MAJOR_VERSION >= 3
@@ -340,10 +240,6 @@ void __Pyx_call_destructor(T* x) {
   #endif
 #endif
 
-#if defined(WIN32) || defined(MS_WINDOWS)
-#define _USE_MATH_DEFINES
-#endif
-#include <math.h>
 #define __PYX_HAVE__cutadapt___qualtrim
 #define __PYX_HAVE_API__cutadapt___qualtrim
 #ifdef _OPENMP
@@ -367,24 +263,49 @@ void __Pyx_call_destructor(T* x) {
 #   define CYTHON_UNUSED
 # endif
 #endif
+#ifndef CYTHON_NCP_UNUSED
+# if CYTHON_COMPILING_IN_CPYTHON
+#  define CYTHON_NCP_UNUSED
+# else
+#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
+# endif
+#endif
 typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
-                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
+                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
 
 #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
 #define __PYX_DEFAULT_STRING_ENCODING ""
 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
-#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (    \
-    (sizeof(type) < sizeof(Py_ssize_t))  ||             \
-    (sizeof(type) > sizeof(Py_ssize_t) &&               \
-          likely(v < (type)PY_SSIZE_T_MAX ||            \
-                 v == (type)PY_SSIZE_T_MAX)  &&         \
-          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||       \
-                                v == (type)PY_SSIZE_T_MIN)))  ||  \
-    (sizeof(type) == sizeof(Py_ssize_t) &&              \
-          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||        \
+#define __Pyx_uchar_cast(c) ((unsigned char)c)
+#define __Pyx_long_cast(x) ((long)x)
+#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
+    (sizeof(type) < sizeof(Py_ssize_t))  ||\
+    (sizeof(type) > sizeof(Py_ssize_t) &&\
+          likely(v < (type)PY_SSIZE_T_MAX ||\
+                 v == (type)PY_SSIZE_T_MAX)  &&\
+          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
+                                v == (type)PY_SSIZE_T_MIN)))  ||\
+    (sizeof(type) == sizeof(Py_ssize_t) &&\
+          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                                v == (type)PY_SSIZE_T_MAX)))  )
+#if defined (__cplusplus) && __cplusplus >= 201103L
+    #include <cstdlib>
+    #define __Pyx_sst_abs(value) std::abs(value)
+#elif SIZEOF_INT >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) abs(value)
+#elif SIZEOF_LONG >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) labs(value)
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define __Pyx_sst_abs(value) llabs(value)
+#elif defined (_MSC_VER) && defined (_M_X64)
+    #define __Pyx_sst_abs(value) _abs64(value)
+#elif defined (__GNUC__)
+    #define __Pyx_sst_abs(value) __builtin_llabs(value)
+#else
+    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
+#endif
 static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
@@ -401,11 +322,11 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
 #endif
 #define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
 #define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
-#define __Pyx_PyObject_FromUString(s)  __Pyx_PyObject_FromString((const char*)s)
-#define __Pyx_PyBytes_FromUString(s)   __Pyx_PyBytes_FromString((const char*)s)
-#define __Pyx_PyByteArray_FromUString(s)   __Pyx_PyByteArray_FromString((const char*)s)
-#define __Pyx_PyStr_FromUString(s)     __Pyx_PyStr_FromString((const char*)s)
-#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((const char*)s)
+#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
+#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
+#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
+#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
+#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
 #if PY_MAJOR_VERSION < 3
 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
 {
@@ -419,8 +340,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
 #define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
 #define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
-#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
-#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
+#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
@@ -441,7 +363,7 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) {
     const char* default_encoding_c;
     sys = PyImport_ImportModule("sys");
     if (!sys) goto bad;
-    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
+    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
     Py_DECREF(sys);
     if (!default_encoding) goto bad;
     default_encoding_c = PyBytes_AsString(default_encoding);
@@ -528,10 +450,12 @@ static const char *__pyx_filename;
 
 
 static const char *__pyx_f[] = {
-  "_qualtrim.pyx",
+  "cutadapt/_qualtrim.pyx",
 };
 
 /*--- Type declarations ---*/
+
+/* --- Runtime support code (head) --- */
 #ifndef CYTHON_REFNANNY
   #define CYTHON_REFNANNY 0
 #endif
@@ -545,22 +469,22 @@ static const char *__pyx_f[] = {
     void (*FinishContext)(void**);
   } __Pyx_RefNannyAPIStruct;
   static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
-  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
+  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
   #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
 #ifdef WITH_THREAD
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
-          if (acquire_gil) { \
-              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
-              PyGILState_Release(__pyx_gilstate_save); \
-          } else { \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          if (acquire_gil) {\
+              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+              PyGILState_Release(__pyx_gilstate_save);\
+          } else {\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
           }
 #else
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
           __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
 #endif
-  #define __Pyx_RefNannyFinishContext() \
+  #define __Pyx_RefNannyFinishContext()\
           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
   #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
   #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
@@ -582,14 +506,14 @@ static const char *__pyx_f[] = {
   #define __Pyx_XDECREF(r) Py_XDECREF(r)
   #define __Pyx_XGOTREF(r)
   #define __Pyx_XGIVEREF(r)
-#endif /* CYTHON_REFNANNY */
-#define __Pyx_XDECREF_SET(r, v) do {                            \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_XDECREF(tmp);                              \
+#endif
+#define __Pyx_XDECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_XDECREF(tmp);\
     } while (0)
-#define __Pyx_DECREF_SET(r, v) do {                             \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_DECREF(tmp);                               \
+#define __Pyx_DECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_DECREF(tmp);\
     } while (0)
 #define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
 #define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
@@ -609,34 +533,34 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject
 #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
 #endif
 
-static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/
+static PyObject *__Pyx_GetBuiltinName(PyObject *name);
 
 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
-    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
+    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
 
-static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
 
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
-    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
-    const char* function_name); /*proto*/
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
+    const char* function_name);
 
 static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
-    const char *name, int exact); /*proto*/
+    const char *name, int exact);
 
-#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
-    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
+#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
                __Pyx_GetItemInt_Generic(o, to_py_func(i))))
-#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
-#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
@@ -644,21 +568,15 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                      int is_list, int wraparound, int boundscheck);
 
-#if CYTHON_COMPILING_IN_CPYTHON
-static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
+
+#if PY_MAJOR_VERSION >= 3
+#define __Pyx_PyObject_Ord(c)\
+    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
 #else
-#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
+#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
 #endif
-
-static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
-
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
-
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
-
-static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
-
-static int __Pyx_check_binary_version(void);
+static long __Pyx__PyObject_Ord(PyObject* c);
 
 typedef struct {
     int code_line;
@@ -675,9 +593,19 @@ static PyCodeObject *__pyx_find_code_object(int code_line);
 static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
 
 static void __Pyx_AddTraceback(const char *funcname, int c_line,
-                               int py_line, const char *filename); /*proto*/
+                               int py_line, const char *filename);
+
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
+
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
+
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
+
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
+
+static int __Pyx_check_binary_version(void);
 
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
+static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
 
 
 /* Module declarations from 'cutadapt._qualtrim' */
@@ -686,13 +614,10 @@ int __pyx_module_is_main_cutadapt___qualtrim = 0;
 
 /* Implementation of 'cutadapt._qualtrim' */
 static PyObject *__pyx_builtin_range;
-static PyObject *__pyx_builtin_ord;
 static PyObject *__pyx_builtin_reversed;
 static PyObject *__pyx_builtin_xrange;
-static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_qualities, int __pyx_v_cutoff_front, int __pyx_v_cutoff_back, int __pyx_v_base); /* proto */
 static char __pyx_k_i[] = "i";
 static char __pyx_k_s[] = "s";
-static char __pyx_k_ord[] = "ord";
 static char __pyx_k_base[] = "base";
 static char __pyx_k_main[] = "__main__";
 static char __pyx_k_stop[] = "stop";
@@ -717,7 +642,6 @@ static PyObject *__pyx_kp_s_home_marcel_scm_cutadapt_cutada;
 static PyObject *__pyx_n_s_i;
 static PyObject *__pyx_n_s_main;
 static PyObject *__pyx_n_s_max_qual;
-static PyObject *__pyx_n_s_ord;
 static PyObject *__pyx_n_s_qualities;
 static PyObject *__pyx_n_s_quality_trim_index;
 static PyObject *__pyx_n_s_range;
@@ -727,6 +651,7 @@ static PyObject *__pyx_n_s_start;
 static PyObject *__pyx_n_s_stop;
 static PyObject *__pyx_n_s_test;
 static PyObject *__pyx_n_s_xrange;
+static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_qualities, int __pyx_v_cutoff_front, int __pyx_v_cutoff_back, int __pyx_v_base); /* proto */
 static PyObject *__pyx_tuple_;
 static PyObject *__pyx_codeobj__2;
 
@@ -741,7 +666,7 @@ static PyObject *__pyx_codeobj__2;
 /* Python wrapper */
 static PyObject *__pyx_pw_8cutadapt_9_qualtrim_1quality_trim_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
 static char __pyx_doc_8cutadapt_9_qualtrim_quality_trim_index[] = "\n\tFind the positions at which to trim low-quality ends from a nucleotide sequence.\n\tReturn tuple (start, stop) that indicates the good-quality segment.\n\n\tQualities are assumed to be ASCII-encoded as chr(qual + base).\n\n\tThe algorithm is the same as the one used by BWA within the function\n\t'bwa_trim_read':\n\t- Subtract the cutoff value from all qualities.\n\t- Compute partial sums from all indices to the end of [...]
-static PyMethodDef __pyx_mdef_8cutadapt_9_qualtrim_1quality_trim_index = {__Pyx_NAMESTR("quality_trim_index"), (PyCFunction)__pyx_pw_8cutadapt_9_qualtrim_1quality_trim_index, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8cutadapt_9_qualtrim_quality_trim_index)};
+static PyMethodDef __pyx_mdef_8cutadapt_9_qualtrim_1quality_trim_index = {"quality_trim_index", (PyCFunction)__pyx_pw_8cutadapt_9_qualtrim_1quality_trim_index, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8cutadapt_9_qualtrim_quality_trim_index};
 static PyObject *__pyx_pw_8cutadapt_9_qualtrim_1quality_trim_index(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_qualities = 0;
   int __pyx_v_cutoff_front;
@@ -841,12 +766,11 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
   Py_ssize_t __pyx_t_1;
   int __pyx_t_2;
   PyObject *__pyx_t_3 = NULL;
-  PyObject *__pyx_t_4 = NULL;
-  PyObject *__pyx_t_5 = NULL;
-  PyObject *__pyx_t_6 = NULL;
+  long __pyx_t_4;
+  int __pyx_t_5;
+  int __pyx_t_6;
   PyObject *__pyx_t_7 = NULL;
-  int __pyx_t_8;
-  int __pyx_t_9;
+  PyObject *__pyx_t_8 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
@@ -907,37 +831,11 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 		if s < 0:
  * 			break
  */
-    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_s); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_qualities, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_cutoff_front); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_qualities, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
-    __Pyx_GOTREF(__pyx_t_5);
-    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
-    __Pyx_GIVEREF(__pyx_t_5);
-    __pyx_t_5 = 0;
-    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_base); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_7 = PyNumber_Subtract(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_7);
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __pyx_t_6 = PyNumber_Subtract(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_7);
+    __pyx_t_4 = __Pyx_PyObject_Ord(__pyx_t_3); if (unlikely(__pyx_t_4 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    __pyx_v_s = __pyx_t_8;
+    __pyx_v_s = (__pyx_v_s + (__pyx_v_cutoff_front - (__pyx_t_4 - __pyx_v_base)));
 
     /* "cutadapt/_qualtrim.pyx":30
  * 	for i in range(len(qualities)):
@@ -946,8 +844,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			break
  * 		if s > max_qual:
  */
-    __pyx_t_9 = ((__pyx_v_s < 0) != 0);
-    if (__pyx_t_9) {
+    __pyx_t_5 = ((__pyx_v_s < 0) != 0);
+    if (__pyx_t_5) {
 
       /* "cutadapt/_qualtrim.pyx":31
  * 		s += cutoff_front - (ord(qualities[i]) - base)
@@ -957,6 +855,14 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			max_qual = s
  */
       goto __pyx_L4_break;
+
+      /* "cutadapt/_qualtrim.pyx":30
+ * 	for i in range(len(qualities)):
+ * 		s += cutoff_front - (ord(qualities[i]) - base)
+ * 		if s < 0:             # <<<<<<<<<<<<<<
+ * 			break
+ * 		if s > max_qual:
+ */
     }
 
     /* "cutadapt/_qualtrim.pyx":32
@@ -966,8 +872,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			max_qual = s
  * 			start = i + 1
  */
-    __pyx_t_9 = ((__pyx_v_s > __pyx_v_max_qual) != 0);
-    if (__pyx_t_9) {
+    __pyx_t_5 = ((__pyx_v_s > __pyx_v_max_qual) != 0);
+    if (__pyx_t_5) {
 
       /* "cutadapt/_qualtrim.pyx":33
  * 			break
@@ -986,9 +892,15 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 	# same for 3' end
  */
       __pyx_v_start = (__pyx_v_i + 1);
-      goto __pyx_L6;
+
+      /* "cutadapt/_qualtrim.pyx":32
+ * 		if s < 0:
+ * 			break
+ * 		if s > max_qual:             # <<<<<<<<<<<<<<
+ * 			max_qual = s
+ * 			start = i + 1
+ */
     }
-    __pyx_L6:;
   }
   __pyx_L4_break:;
 
@@ -1028,37 +940,11 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 		if s < 0:
  * 			break
  */
-    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_s); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_7);
-    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_cutoff_back); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
     __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_qualities, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
     __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
-    __Pyx_GIVEREF(__pyx_t_3);
-    __pyx_t_3 = 0;
-    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_base); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_5 = PyNumber_Subtract(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
+    __pyx_t_4 = __Pyx_PyObject_Ord(__pyx_t_3); if (unlikely(__pyx_t_4 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyNumber_Subtract(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_5);
-    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
-    __pyx_v_s = __pyx_t_8;
+    __pyx_v_s = (__pyx_v_s + (__pyx_v_cutoff_back - (__pyx_t_4 - __pyx_v_base)));
 
     /* "cutadapt/_qualtrim.pyx":41
  * 	for i in reversed(xrange(len(qualities))):
@@ -1067,8 +953,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			break
  * 		if s > max_qual:
  */
-    __pyx_t_9 = ((__pyx_v_s < 0) != 0);
-    if (__pyx_t_9) {
+    __pyx_t_5 = ((__pyx_v_s < 0) != 0);
+    if (__pyx_t_5) {
 
       /* "cutadapt/_qualtrim.pyx":42
  * 		s += cutoff_back - (ord(qualities[i]) - base)
@@ -1078,6 +964,14 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			max_qual = s
  */
       goto __pyx_L8_break;
+
+      /* "cutadapt/_qualtrim.pyx":41
+ * 	for i in reversed(xrange(len(qualities))):
+ * 		s += cutoff_back - (ord(qualities[i]) - base)
+ * 		if s < 0:             # <<<<<<<<<<<<<<
+ * 			break
+ * 		if s > max_qual:
+ */
     }
 
     /* "cutadapt/_qualtrim.pyx":43
@@ -1087,8 +981,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 			max_qual = s
  * 			stop = i
  */
-    __pyx_t_9 = ((__pyx_v_s > __pyx_v_max_qual) != 0);
-    if (__pyx_t_9) {
+    __pyx_t_5 = ((__pyx_v_s > __pyx_v_max_qual) != 0);
+    if (__pyx_t_5) {
 
       /* "cutadapt/_qualtrim.pyx":44
  * 			break
@@ -1107,9 +1001,15 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 		start, stop = 0, 0
  */
       __pyx_v_stop = __pyx_v_i;
-      goto __pyx_L10;
+
+      /* "cutadapt/_qualtrim.pyx":43
+ * 		if s < 0:
+ * 			break
+ * 		if s > max_qual:             # <<<<<<<<<<<<<<
+ * 			max_qual = s
+ * 			stop = i
+ */
     }
-    __pyx_L10:;
   }
   __pyx_L8_break:;
 
@@ -1120,8 +1020,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 		start, stop = 0, 0
  * 	return (start, stop)
  */
-  __pyx_t_9 = ((__pyx_v_start >= __pyx_v_stop) != 0);
-  if (__pyx_t_9) {
+  __pyx_t_5 = ((__pyx_v_start >= __pyx_v_stop) != 0);
+  if (__pyx_t_5) {
 
     /* "cutadapt/_qualtrim.pyx":47
  * 			stop = i
@@ -1130,12 +1030,18 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 	return (start, stop)
  */
     __pyx_t_2 = 0;
-    __pyx_t_8 = 0;
+    __pyx_t_6 = 0;
     __pyx_v_start = __pyx_t_2;
-    __pyx_v_stop = __pyx_t_8;
-    goto __pyx_L11;
+    __pyx_v_stop = __pyx_t_6;
+
+    /* "cutadapt/_qualtrim.pyx":46
+ * 			max_qual = s
+ * 			stop = i
+ * 	if start >= stop:             # <<<<<<<<<<<<<<
+ * 		start, stop = 0, 0
+ * 	return (start, stop)
+ */
   }
-  __pyx_L11:;
 
   /* "cutadapt/_qualtrim.pyx":48
  * 	if start >= stop:
@@ -1143,20 +1049,20 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
  * 	return (start, stop)             # <<<<<<<<<<<<<<
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_5);
-  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_stop); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_3);
+  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_stop); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_7);
-  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
-  __Pyx_GIVEREF(__pyx_t_5);
-  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_4);
-  __Pyx_GIVEREF(__pyx_t_4);
-  __pyx_t_5 = 0;
-  __pyx_t_4 = 0;
-  __pyx_r = __pyx_t_7;
+  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_8);
+  __Pyx_GIVEREF(__pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
+  __Pyx_GIVEREF(__pyx_t_7);
+  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
+  __pyx_t_3 = 0;
   __pyx_t_7 = 0;
+  __pyx_r = __pyx_t_8;
+  __pyx_t_8 = 0;
   goto __pyx_L0;
 
   /* "cutadapt/_qualtrim.pyx":6
@@ -1170,10 +1076,8 @@ static PyObject *__pyx_pf_8cutadapt_9_qualtrim_quality_trim_index(CYTHON_UNUSED
   /* function exit code */
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_XDECREF(__pyx_t_4);
-  __Pyx_XDECREF(__pyx_t_5);
-  __Pyx_XDECREF(__pyx_t_6);
   __Pyx_XDECREF(__pyx_t_7);
+  __Pyx_XDECREF(__pyx_t_8);
   __Pyx_AddTraceback("cutadapt._qualtrim.quality_trim_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = NULL;
   __pyx_L0:;
@@ -1193,8 +1097,8 @@ static struct PyModuleDef __pyx_moduledef = {
   #else
     PyModuleDef_HEAD_INIT,
   #endif
-    __Pyx_NAMESTR("_qualtrim"),
-    __Pyx_DOCSTR(__pyx_k_Quality_trimming), /* m_doc */
+    "_qualtrim",
+    __pyx_k_Quality_trimming, /* m_doc */
     -1, /* m_size */
     __pyx_methods /* m_methods */,
     NULL, /* m_reload */
@@ -1213,7 +1117,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
   {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
   {&__pyx_n_s_max_qual, __pyx_k_max_qual, sizeof(__pyx_k_max_qual), 0, 0, 1, 1},
-  {&__pyx_n_s_ord, __pyx_k_ord, sizeof(__pyx_k_ord), 0, 0, 1, 1},
   {&__pyx_n_s_qualities, __pyx_k_qualities, sizeof(__pyx_k_qualities), 0, 0, 1, 1},
   {&__pyx_n_s_quality_trim_index, __pyx_k_quality_trim_index, sizeof(__pyx_k_quality_trim_index), 0, 0, 1, 1},
   {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
@@ -1227,7 +1130,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
 };
 static int __Pyx_InitCachedBuiltins(void) {
   __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ord = __Pyx_GetBuiltinName(__pyx_n_s_ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_builtin_reversed = __Pyx_GetBuiltinName(__pyx_n_s_reversed); if (!__pyx_builtin_reversed) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if PY_MAJOR_VERSION >= 3
   __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -1291,18 +1193,24 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   }
   #endif
   __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__qualtrim(void)", 0);
-  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #ifdef __Pyx_CyFunction_USED
-  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   #ifdef __Pyx_FusedFunction_USED
   if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_Coroutine_USED
+  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   #ifdef __Pyx_Generator_USED
   if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_StopAsyncIteration_USED
+  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   /*--- Library function declarations ---*/
   /*--- Threads initialization code ---*/
   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
@@ -1312,25 +1220,25 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   #endif
   /*--- Module creation code ---*/
   #if PY_MAJOR_VERSION < 3
-  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_qualtrim"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_Quality_trimming), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
+  __pyx_m = Py_InitModule4("_qualtrim", __pyx_methods, __pyx_k_Quality_trimming, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
   #else
   __pyx_m = PyModule_Create(&__pyx_moduledef);
   #endif
   if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   Py_INCREF(__pyx_d);
-  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if CYTHON_COMPILING_IN_PYPY
   Py_INCREF(__pyx_b);
   #endif
-  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   /*--- Initialize various global constants etc. ---*/
-  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
   if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   if (__pyx_module_is_main_cutadapt___qualtrim) {
-    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;};
+    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #if PY_MAJOR_VERSION >= 3
   {
@@ -1341,9 +1249,9 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   }
   #endif
   /*--- Builtin init code ---*/
-  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Constants init code ---*/
-  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Global init code ---*/
   /*--- Variable export code ---*/
   /*--- Function export code ---*/
@@ -1352,6 +1260,9 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   /*--- Variable import code ---*/
   /*--- Function import code ---*/
   /*--- Execution code ---*/
+  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
 
   /* "cutadapt/_qualtrim.pyx":6
  * """
@@ -1374,11 +1285,16 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   __Pyx_GOTREF(__pyx_t_1);
   if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+
+  /*--- Wrapped vars code ---*/
+
   goto __pyx_L0;
   __pyx_L1_error:;
   __Pyx_XDECREF(__pyx_t_1);
   if (__pyx_m) {
-    __Pyx_AddTraceback("init cutadapt._qualtrim", __pyx_clineno, __pyx_lineno, __pyx_filename);
+    if (__pyx_d) {
+      __Pyx_AddTraceback("init cutadapt._qualtrim", __pyx_clineno, __pyx_lineno, __pyx_filename);
+    }
     Py_DECREF(__pyx_m); __pyx_m = 0;
   } else if (!PyErr_Occurred()) {
     PyErr_SetString(PyExc_ImportError, "init cutadapt._qualtrim");
@@ -1392,7 +1308,7 @@ PyMODINIT_FUNC PyInit__qualtrim(void)
   #endif
 }
 
-/* Runtime support code */
+/* --- Runtime support code --- */
 #if CYTHON_REFNANNY
 static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
     PyObject *m = NULL, *p = NULL;
@@ -1407,7 +1323,7 @@ end:
     Py_XDECREF(m);
     return (__Pyx_RefNannyAPIStruct *)r;
 }
-#endif /* CYTHON_REFNANNY */
+#endif
 
 static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
     PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
@@ -1595,7 +1511,8 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j
     return r;
 }
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
-                                                              int wraparound, int boundscheck) {
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
 #if CYTHON_COMPILING_IN_CPYTHON
     if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
     if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
@@ -1609,7 +1526,8 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_
 #endif
 }
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
-                                                              int wraparound, int boundscheck) {
+                                                              CYTHON_NCP_UNUSED int wraparound,
+                                                              CYTHON_NCP_UNUSED int boundscheck) {
 #if CYTHON_COMPILING_IN_CPYTHON
     if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
     if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
@@ -1622,8 +1540,9 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize
     return PySequence_GetItem(o, i);
 #endif
 }
-static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
-                                                     int is_list, int wraparound, int boundscheck) {
+static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
+                                                     CYTHON_NCP_UNUSED int wraparound,
+                                                     CYTHON_NCP_UNUSED int boundscheck) {
 #if CYTHON_COMPILING_IN_CPYTHON
     if (is_list || PyList_CheckExact(o)) {
         Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
@@ -1665,335 +1584,83 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
     return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
 }
 
-#if CYTHON_COMPILING_IN_CPYTHON
-static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
-    PyObject *result;
-    ternaryfunc call = func->ob_type->tp_call;
-    if (unlikely(!call))
-        return PyObject_Call(func, arg, kw);
-#if PY_VERSION_HEX >= 0x02060000
-    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
-        return NULL;
-#endif
-    result = (*call)(func, arg, kw);
-#if PY_VERSION_HEX >= 0x02060000
-    Py_LeaveRecursiveCall();
-#endif
-    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
-        PyErr_SetString(
-            PyExc_SystemError,
-            "NULL result without error in PyObject_Call");
-    }
-    return result;
+static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
+   Py_ssize_t length;
+   #if CYTHON_PEP393_ENABLED
+   length = PyUnicode_GET_LENGTH(x);
+   if (likely(length == 1)) {
+       return PyUnicode_READ_CHAR(x, 0);
+   }
+   #else
+   length = PyUnicode_GET_SIZE(x);
+   if (likely(length == 1)) {
+       return PyUnicode_AS_UNICODE(x)[0];
+   }
+   #if Py_UNICODE_SIZE == 2
+   else if (PyUnicode_GET_SIZE(x) == 2) {
+       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
+       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
+           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
+           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
+               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
+           }
+       }
+   }
+   #endif
+   #endif
+   PyErr_Format(PyExc_ValueError,
+                "only single character unicode strings can be converted to Py_UCS4, "
+                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
+   return (Py_UCS4)-1;
 }
-#endif
-
-#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func)             \
-    {                                                                     \
-        func_type value = func(x);                                        \
-        if (sizeof(target_type) < sizeof(func_type)) {                    \
-            if (unlikely(value != (func_type) (target_type) value)) {     \
-                func_type zero = 0;                                       \
-                PyErr_SetString(PyExc_OverflowError,                      \
-                    (is_unsigned && unlikely(value < zero)) ?             \
-                    "can't convert negative value to " #target_type :     \
-                    "value too large to convert to " #target_type);       \
-                return (target_type) -1;                                  \
-            }                                                             \
-        }                                                                 \
-        return (target_type) value;                                       \
-    }
 
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-  #include "longintrepr.h"
- #endif
-#endif
-static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
-    const int neg_one = (int) -1, const_zero = 0;
-    const int is_unsigned = neg_one > const_zero;
-#if PY_MAJOR_VERSION < 3
-    if (likely(PyInt_Check(x))) {
-        if (sizeof(int) < sizeof(long)) {
-            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG)
-        } else {
-            long val = PyInt_AS_LONG(x);
-            if (is_unsigned && unlikely(val < 0)) {
-                PyErr_SetString(PyExc_OverflowError,
-                                "can't convert negative value to int");
-                return (int) -1;
-            }
-            return (int) val;
+static long __Pyx__PyObject_Ord(PyObject* c) {
+    Py_ssize_t size;
+    if (PyBytes_Check(c)) {
+        size = PyBytes_GET_SIZE(c);
+        if (likely(size == 1)) {
+            return (unsigned char) PyBytes_AS_STRING(c)[0];
         }
-    } else
-#endif
-    if (likely(PyLong_Check(x))) {
-        if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-            if (sizeof(digit) <= sizeof(int)) {
-                switch (Py_SIZE(x)) {
-                    case  0: return 0;
-                    case  1: return (int) ((PyLongObject*)x)->ob_digit[0];
-                }
-            }
- #endif
-#endif
-            if (unlikely(Py_SIZE(x) < 0)) {
-                PyErr_SetString(PyExc_OverflowError,
-                                "can't convert negative value to int");
-                return (int) -1;
-            }
-            if (sizeof(int) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong)
-            } else if (sizeof(int) <= sizeof(unsigned long long)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong)
-            }
-        } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-            if (sizeof(digit) <= sizeof(int)) {
-                switch (Py_SIZE(x)) {
-                    case  0: return 0;
-                    case  1: return +(int) ((PyLongObject*)x)->ob_digit[0];
-                    case -1: return -(int) ((PyLongObject*)x)->ob_digit[0];
-                }
-            }
- #endif
-#endif
-            if (sizeof(int) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong)
-            } else if (sizeof(int) <= sizeof(long long)) {
-                __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong)
-            }
+#if PY_MAJOR_VERSION < 3
+    } else if (PyUnicode_Check(c)) {
+        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
+#endif
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
+    } else if (PyByteArray_Check(c)) {
+        size = PyByteArray_GET_SIZE(c);
+        if (likely(size == 1)) {
+            return (unsigned char) PyByteArray_AS_STRING(c)[0];
         }
-        {
-#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
-            PyErr_SetString(PyExc_RuntimeError,
-                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
-#else
-            int val;
-            PyObject *v = __Pyx_PyNumber_Int(x);
- #if PY_MAJOR_VERSION < 3
-            if (likely(v) && !PyLong_Check(v)) {
-                PyObject *tmp = v;
-                v = PyNumber_Long(tmp);
-                Py_DECREF(tmp);
-            }
- #endif
-            if (likely(v)) {
-                int one = 1; int is_little = (int)*(unsigned char *)&one;
-                unsigned char *bytes = (unsigned char *)&val;
-                int ret = _PyLong_AsByteArray((PyLongObject *)v,
-                                              bytes, sizeof(val),
-                                              is_little, !is_unsigned);
-                Py_DECREF(v);
-                if (likely(!ret))
-                    return val;
-            }
 #endif
-            return (int) -1;
-        }
     } else {
-        int val;
-        PyObject *tmp = __Pyx_PyNumber_Int(x);
-        if (!tmp) return (int) -1;
-        val = __Pyx_PyInt_As_int(tmp);
-        Py_DECREF(tmp);
-        return val;
+        PyErr_Format(PyExc_TypeError,
+            "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
+        return (long)(Py_UCS4)-1;
     }
+    PyErr_Format(PyExc_TypeError,
+        "ord() expected a character, but string of length %zd found", size);
+    return (long)(Py_UCS4)-1;
 }
 
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
-    const int neg_one = (int) -1, const_zero = 0;
-    const int is_unsigned = neg_one > const_zero;
-    if (is_unsigned) {
-        if (sizeof(int) < sizeof(long)) {
-            return PyInt_FromLong((long) value);
-        } else if (sizeof(int) <= sizeof(unsigned long)) {
-            return PyLong_FromUnsignedLong((unsigned long) value);
-        } else if (sizeof(int) <= sizeof(unsigned long long)) {
-            return PyLong_FromUnsignedLongLong((unsigned long long) value);
-        }
-    } else {
-        if (sizeof(int) <= sizeof(long)) {
-            return PyInt_FromLong((long) value);
-        } else if (sizeof(int) <= sizeof(long long)) {
-            return PyLong_FromLongLong((long long) value);
+static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
+    int start = 0, mid = 0, end = count - 1;
+    if (end >= 0 && code_line > entries[end].code_line) {
+        return count;
+    }
+    while (start < end) {
+        mid = start + (end - start) / 2;
+        if (code_line < entries[mid].code_line) {
+            end = mid;
+        } else if (code_line > entries[mid].code_line) {
+             start = mid + 1;
+        } else {
+            return mid;
         }
     }
-    {
-        int one = 1; int little = (int)*(unsigned char *)&one;
-        unsigned char *bytes = (unsigned char *)&value;
-        return _PyLong_FromByteArray(bytes, sizeof(int),
-                                     little, !is_unsigned);
-    }
-}
-
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
-    const long neg_one = (long) -1, const_zero = 0;
-    const int is_unsigned = neg_one > const_zero;
-    if (is_unsigned) {
-        if (sizeof(long) < sizeof(long)) {
-            return PyInt_FromLong((long) value);
-        } else if (sizeof(long) <= sizeof(unsigned long)) {
-            return PyLong_FromUnsignedLong((unsigned long) value);
-        } else if (sizeof(long) <= sizeof(unsigned long long)) {
-            return PyLong_FromUnsignedLongLong((unsigned long long) value);
-        }
-    } else {
-        if (sizeof(long) <= sizeof(long)) {
-            return PyInt_FromLong((long) value);
-        } else if (sizeof(long) <= sizeof(long long)) {
-            return PyLong_FromLongLong((long long) value);
-        }
-    }
-    {
-        int one = 1; int little = (int)*(unsigned char *)&one;
-        unsigned char *bytes = (unsigned char *)&value;
-        return _PyLong_FromByteArray(bytes, sizeof(long),
-                                     little, !is_unsigned);
-    }
-}
-
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-  #include "longintrepr.h"
- #endif
-#endif
-static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
-    const long neg_one = (long) -1, const_zero = 0;
-    const int is_unsigned = neg_one > const_zero;
-#if PY_MAJOR_VERSION < 3
-    if (likely(PyInt_Check(x))) {
-        if (sizeof(long) < sizeof(long)) {
-            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG)
-        } else {
-            long val = PyInt_AS_LONG(x);
-            if (is_unsigned && unlikely(val < 0)) {
-                PyErr_SetString(PyExc_OverflowError,
-                                "can't convert negative value to long");
-                return (long) -1;
-            }
-            return (long) val;
-        }
-    } else
-#endif
-    if (likely(PyLong_Check(x))) {
-        if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-            if (sizeof(digit) <= sizeof(long)) {
-                switch (Py_SIZE(x)) {
-                    case  0: return 0;
-                    case  1: return (long) ((PyLongObject*)x)->ob_digit[0];
-                }
-            }
- #endif
-#endif
-            if (unlikely(Py_SIZE(x) < 0)) {
-                PyErr_SetString(PyExc_OverflowError,
-                                "can't convert negative value to long");
-                return (long) -1;
-            }
-            if (sizeof(long) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong)
-            } else if (sizeof(long) <= sizeof(unsigned long long)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong)
-            }
-        } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-            if (sizeof(digit) <= sizeof(long)) {
-                switch (Py_SIZE(x)) {
-                    case  0: return 0;
-                    case  1: return +(long) ((PyLongObject*)x)->ob_digit[0];
-                    case -1: return -(long) ((PyLongObject*)x)->ob_digit[0];
-                }
-            }
- #endif
-#endif
-            if (sizeof(long) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong)
-            } else if (sizeof(long) <= sizeof(long long)) {
-                __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong)
-            }
-        }
-        {
-#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
-            PyErr_SetString(PyExc_RuntimeError,
-                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
-#else
-            long val;
-            PyObject *v = __Pyx_PyNumber_Int(x);
- #if PY_MAJOR_VERSION < 3
-            if (likely(v) && !PyLong_Check(v)) {
-                PyObject *tmp = v;
-                v = PyNumber_Long(tmp);
-                Py_DECREF(tmp);
-            }
- #endif
-            if (likely(v)) {
-                int one = 1; int is_little = (int)*(unsigned char *)&one;
-                unsigned char *bytes = (unsigned char *)&val;
-                int ret = _PyLong_AsByteArray((PyLongObject *)v,
-                                              bytes, sizeof(val),
-                                              is_little, !is_unsigned);
-                Py_DECREF(v);
-                if (likely(!ret))
-                    return val;
-            }
-#endif
-            return (long) -1;
-        }
-    } else {
-        long val;
-        PyObject *tmp = __Pyx_PyNumber_Int(x);
-        if (!tmp) return (long) -1;
-        val = __Pyx_PyInt_As_long(tmp);
-        Py_DECREF(tmp);
-        return val;
-    }
-}
-
-static int __Pyx_check_binary_version(void) {
-    char ctversion[4], rtversion[4];
-    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
-    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
-    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
-        char message[200];
-        PyOS_snprintf(message, sizeof(message),
-                      "compiletime version %s of module '%.100s' "
-                      "does not match runtime version %s",
-                      ctversion, __Pyx_MODULE_NAME, rtversion);
-        #if PY_VERSION_HEX < 0x02050000
-        return PyErr_Warn(NULL, message);
-        #else
-        return PyErr_WarnEx(NULL, message, 1);
-        #endif
-    }
-    return 0;
-}
-
-static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
-    int start = 0, mid = 0, end = count - 1;
-    if (end >= 0 && code_line > entries[end].code_line) {
-        return count;
-    }
-    while (start < end) {
-        mid = (start + end) / 2;
-        if (code_line < entries[mid].code_line) {
-            end = mid;
-        } else if (code_line > entries[mid].code_line) {
-             start = mid + 1;
-        } else {
-            return mid;
-        }
-    }
-    if (code_line <= entries[mid].code_line) {
-        return mid;
-    } else {
-        return mid + 1;
+    if (code_line <= entries[mid].code_line) {
+        return mid;
+    } else {
+        return mid + 1;
     }
 }
 static PyCodeObject *__pyx_find_code_object(int code_line) {
@@ -2085,11 +1752,11 @@ static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
     }
     if (!py_funcname) goto bad;
     py_code = __Pyx_PyCode_New(
-        0,            /*int argcount,*/
-        0,            /*int kwonlyargcount,*/
-        0,            /*int nlocals,*/
-        0,            /*int stacksize,*/
-        0,            /*int flags,*/
+        0,
+        0,
+        0,
+        0,
+        0,
         __pyx_empty_bytes, /*PyObject *code,*/
         __pyx_empty_tuple, /*PyObject *consts,*/
         __pyx_empty_tuple, /*PyObject *names,*/
@@ -2098,7 +1765,7 @@ static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
         __pyx_empty_tuple, /*PyObject *cellvars,*/
         py_srcfile,   /*PyObject *filename,*/
         py_funcname,  /*PyObject *name,*/
-        py_line,      /*int firstlineno,*/
+        py_line,
         __pyx_empty_bytes  /*PyObject *lnotab*/
     );
     Py_DECREF(py_srcfile);
@@ -2112,7 +1779,6 @@ bad:
 static void __Pyx_AddTraceback(const char *funcname, int c_line,
                                int py_line, const char *filename) {
     PyCodeObject *py_code = 0;
-    PyObject *py_globals = 0;
     PyFrameObject *py_frame = 0;
     py_code = __pyx_find_code_object(c_line ? c_line : py_line);
     if (!py_code) {
@@ -2121,12 +1787,10 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
         if (!py_code) goto bad;
         __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
     }
-    py_globals = PyModule_GetDict(__pyx_m);
-    if (!py_globals) goto bad;
     py_frame = PyFrame_New(
         PyThreadState_GET(), /*PyThreadState *tstate,*/
         py_code,             /*PyCodeObject *code,*/
-        py_globals,          /*PyObject *globals,*/
+        __pyx_d,      /*PyObject *globals,*/
         0                    /*PyObject *locals*/
     );
     if (!py_frame) goto bad;
@@ -2137,6 +1801,466 @@ bad:
     Py_XDECREF(py_frame);
 }
 
+#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
+#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
+#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
+    {\
+        func_type value = func_value;\
+        if (sizeof(target_type) < sizeof(func_type)) {\
+            if (unlikely(value != (func_type) (target_type) value)) {\
+                func_type zero = 0;\
+                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
+                    return (target_type) -1;\
+                if (is_unsigned && unlikely(value < zero))\
+                    goto raise_neg_overflow;\
+                else\
+                    goto raise_overflow;\
+            }\
+        }\
+        return (target_type) value;\
+    }
+
+#if CYTHON_USE_PYLONG_INTERNALS
+  #include "longintrepr.h"
+#endif
+
+static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
+    const int neg_one = (int) -1, const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(int) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (int) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (int) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(int) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
+            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (int) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) -(((((int)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) -(((((((int)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) -(((((((((int)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(int) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
+            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            int val;
+            PyObject *v = __Pyx_PyNumber_Int(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (int) -1;
+        }
+    } else {
+        int val;
+        PyObject *tmp = __Pyx_PyNumber_Int(x);
+        if (!tmp) return (int) -1;
+        val = __Pyx_PyInt_As_int(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to int");
+    return (int) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to int");
+    return (int) -1;
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
+    const int neg_one = (int) -1, const_zero = (int) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(int) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+        }
+    } else {
+        if (sizeof(int) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(int),
+                                     little, !is_unsigned);
+    }
+}
+
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
+    const long neg_one = (long) -1, const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+    if (is_unsigned) {
+        if (sizeof(long) < sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(long) <= sizeof(unsigned long)) {
+            return PyLong_FromUnsignedLong((unsigned long) value);
+        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
+        }
+    } else {
+        if (sizeof(long) <= sizeof(long)) {
+            return PyInt_FromLong((long) value);
+        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+            return PyLong_FromLongLong((PY_LONG_LONG) value);
+        }
+    }
+    {
+        int one = 1; int little = (int)*(unsigned char *)&one;
+        unsigned char *bytes = (unsigned char *)&value;
+        return _PyLong_FromByteArray(bytes, sizeof(long),
+                                     little, !is_unsigned);
+    }
+}
+
+static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
+    const long neg_one = (long) -1, const_zero = (long) 0;
+    const int is_unsigned = neg_one > const_zero;
+#if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_Check(x))) {
+        if (sizeof(long) < sizeof(long)) {
+            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
+        } else {
+            long val = PyInt_AS_LONG(x);
+            if (is_unsigned && unlikely(val < 0)) {
+                goto raise_neg_overflow;
+            }
+            return (long) val;
+        }
+    } else
+#endif
+    if (likely(PyLong_Check(x))) {
+        if (is_unsigned) {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+#if CYTHON_COMPILING_IN_CPYTHON
+            if (unlikely(Py_SIZE(x) < 0)) {
+                goto raise_neg_overflow;
+            }
+#else
+            {
+                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
+                if (unlikely(result < 0))
+                    return (long) -1;
+                if (unlikely(result == 1))
+                    goto raise_neg_overflow;
+            }
+#endif
+            if (sizeof(long) <= sizeof(unsigned long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
+            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+            }
+        } else {
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
+            switch (Py_SIZE(x)) {
+                case  0: return (long) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) -(((((long)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) -(((((((long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) -(((((((((long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+                        }
+                    }
+                    break;
+            }
+#endif
+            if (sizeof(long) <= sizeof(long)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
+            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
+                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
+            }
+        }
+        {
+#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
+            PyErr_SetString(PyExc_RuntimeError,
+                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
+#else
+            long val;
+            PyObject *v = __Pyx_PyNumber_Int(x);
+ #if PY_MAJOR_VERSION < 3
+            if (likely(v) && !PyLong_Check(v)) {
+                PyObject *tmp = v;
+                v = PyNumber_Long(tmp);
+                Py_DECREF(tmp);
+            }
+ #endif
+            if (likely(v)) {
+                int one = 1; int is_little = (int)*(unsigned char *)&one;
+                unsigned char *bytes = (unsigned char *)&val;
+                int ret = _PyLong_AsByteArray((PyLongObject *)v,
+                                              bytes, sizeof(val),
+                                              is_little, !is_unsigned);
+                Py_DECREF(v);
+                if (likely(!ret))
+                    return val;
+            }
+#endif
+            return (long) -1;
+        }
+    } else {
+        long val;
+        PyObject *tmp = __Pyx_PyNumber_Int(x);
+        if (!tmp) return (long) -1;
+        val = __Pyx_PyInt_As_long(tmp);
+        Py_DECREF(tmp);
+        return val;
+    }
+raise_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "value too large to convert to long");
+    return (long) -1;
+raise_neg_overflow:
+    PyErr_SetString(PyExc_OverflowError,
+        "can't convert negative value to long");
+    return (long) -1;
+}
+
+static int __Pyx_check_binary_version(void) {
+    char ctversion[4], rtversion[4];
+    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
+    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
+    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
+        char message[200];
+        PyOS_snprintf(message, sizeof(message),
+                      "compiletime version %s of module '%.100s' "
+                      "does not match runtime version %s",
+                      ctversion, __Pyx_MODULE_NAME, rtversion);
+        return PyErr_WarnEx(NULL, message, 1);
+    }
+    return 0;
+}
+
 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
     while (t->p) {
         #if PY_MAJOR_VERSION < 3
@@ -2147,7 +2271,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
         } else {
             *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
         }
-        #else  /* Python 3+ has unicode identifiers */
+        #else
         if (t->is_unicode | t->is_str) {
             if (t->intern) {
                 *t->p = PyUnicode_InternFromString(t->s);
@@ -2175,7 +2299,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
     return __Pyx_PyObject_AsStringAndSize(o, &ignore);
 }
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
-#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
     if (
 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
             __Pyx_sys_getdefaultencoding_not_ascii &&
@@ -2197,11 +2321,11 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_
                 }
             }
         }
-#endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/
+#endif
         *length = PyBytes_GET_SIZE(defenc);
         return defenc_c;
-#else /* PY_VERSION_HEX < 0x03030000 */
-        if (PyUnicode_READY(o) == -1) return NULL;
+#else
+        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
 #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
         if (PyUnicode_IS_ASCII(o)) {
             *length = PyUnicode_GET_LENGTH(o);
@@ -2210,20 +2334,18 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_
             PyUnicode_AsASCIIString(o);
             return NULL;
         }
-#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
+#else
         return PyUnicode_AsUTF8AndSize(o, length);
-#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
-#endif /* PY_VERSION_HEX < 0x03030000 */
+#endif
+#endif
     } else
-#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII  || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */
-#if !CYTHON_COMPILING_IN_PYPY
-#if PY_VERSION_HEX >= 0x02060000
+#endif
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
     if (PyByteArray_Check(o)) {
         *length = PyByteArray_GET_SIZE(o);
         return PyByteArray_AS_STRING(o);
     } else
 #endif
-#endif
     {
         char* result;
         int r = PyBytes_AsStringAndSize(o, &result, length);
@@ -2248,7 +2370,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
 #else
   if (PyLong_Check(x))
 #endif
-    return Py_INCREF(x), x;
+    return __Pyx_NewRef(x);
   m = Py_TYPE(x)->tp_as_number;
 #if PY_MAJOR_VERSION < 3
   if (m && m->nb_int) {
@@ -2284,33 +2406,61 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
   }
   return res;
 }
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-  #include "longintrepr.h"
- #endif
-#endif
 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
   Py_ssize_t ival;
   PyObject *x;
 #if PY_MAJOR_VERSION < 3
-  if (likely(PyInt_CheckExact(b)))
-      return PyInt_AS_LONG(b);
+  if (likely(PyInt_CheckExact(b))) {
+    if (sizeof(Py_ssize_t) >= sizeof(long))
+        return PyInt_AS_LONG(b);
+    else
+        return PyInt_AsSsize_t(x);
+  }
 #endif
   if (likely(PyLong_CheckExact(b))) {
-    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
-     #if CYTHON_USE_PYLONG_INTERNALS
-       switch (Py_SIZE(b)) {
-       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
-       case  0: return 0;
-       case  1: return ((PyLongObject*)b)->ob_digit[0];
-       }
-     #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    const digit* digits = ((PyLongObject*)b)->ob_digit;
+    const Py_ssize_t size = Py_SIZE(b);
+    if (likely(__Pyx_sst_abs(size) <= 1)) {
+        ival = likely(size) ? digits[0] : 0;
+        if (size == -1) ival = -ival;
+        return ival;
+    } else {
+      switch (size) {
+         case 2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+         case -2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+         case 3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+         case -3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+         case 4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+         case -4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | digits[2]) << PyLong_SHIFT) | digits[1]) << PyLong_SHIFT) | digits[0]));
+           }
+           break;
+      }
+    }
     #endif
-  #if PY_VERSION_HEX < 0x02060000
-    return PyInt_AsSsize_t(b);
-  #else
     return PyLong_AsSsize_t(b);
-  #endif
   }
   x = PyNumber_Index(b);
   if (!x) return -1;
@@ -2319,17 +2469,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
   return ival;
 }
 static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
-#if PY_VERSION_HEX < 0x02050000
-   if (ival <= LONG_MAX)
-       return PyInt_FromLong((long)ival);
-   else {
-       unsigned char *bytes = (unsigned char *) &ival;
-       int one = 1; int little = (int)*(unsigned char*)&one;
-       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
-   }
-#else
-   return PyInt_FromSize_t(ival);
-#endif
+    return PyInt_FromSize_t(ival);
 }
 
 
diff --git a/cutadapt/_qualtrim.so b/cutadapt/_qualtrim.so
index 8846605..91bedf2 100755
Binary files a/cutadapt/_qualtrim.so and b/cutadapt/_qualtrim.so differ
diff --git a/cutadapt/_seqio.c b/cutadapt/_seqio.c
index e291d29..3ffc7d9 100644
--- a/cutadapt/_seqio.c
+++ b/cutadapt/_seqio.c
@@ -1,4 +1,4 @@
-/* Generated by Cython 0.22.1 */
+/* Generated by Cython 0.23.3 */
 
 /* BEGIN: Cython Metadata
 {
@@ -7,25 +7,13 @@
 END: Cython Metadata */
 
 #define PY_SSIZE_T_CLEAN
-#ifndef CYTHON_USE_PYLONG_INTERNALS
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#else
-#include "pyconfig.h"
-#ifdef PYLONG_BITS_IN_DIGIT
-#define CYTHON_USE_PYLONG_INTERNALS 1
-#else
-#define CYTHON_USE_PYLONG_INTERNALS 0
-#endif
-#endif
-#endif
 #include "Python.h"
 #ifndef Py_PYTHON_H
     #error Python headers needed to compile C extensions, please install development version of Python.
 #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
     #error Cython requires Python 2.6+ or Python 3.2+.
 #else
-#define CYTHON_ABI "0_22_1"
+#define CYTHON_ABI "0_23_3"
 #include <stddef.h>
 #ifndef offsetof
 #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
@@ -60,6 +48,9 @@ END: Cython Metadata */
 #define CYTHON_COMPILING_IN_PYPY 0
 #define CYTHON_COMPILING_IN_CPYTHON 1
 #endif
+#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
+#define CYTHON_USE_PYLONG_INTERNALS 1
+#endif
 #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
 #define Py_OptimizeFlag 0
 #endif
@@ -67,12 +58,12 @@ END: Cython Metadata */
 #define CYTHON_FORMAT_SSIZE_T "z"
 #if PY_MAJOR_VERSION < 3
   #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyClass_Type
 #else
   #define __Pyx_BUILTIN_MODULE_NAME "builtins"
-  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
+  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
           PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
   #define __Pyx_DefaultClassType PyType_Type
 #endif
@@ -90,7 +81,7 @@ END: Cython Metadata */
 #endif
 #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
   #define CYTHON_PEP393_ENABLED 1
-  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
+  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                               0 : _PyUnicode_Ready((PyObject *)(op)))
   #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
   #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
@@ -109,12 +100,10 @@ END: Cython Metadata */
 #if CYTHON_COMPILING_IN_PYPY
   #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
   #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
-  #define __Pyx_PyFrozenSet_Size(s)         PyObject_Size(s)
 #else
   #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
-  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
+  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
       PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
-  #define __Pyx_PyFrozenSet_Size(s)         PySet_Size(s)
 #endif
 #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
   #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
@@ -182,16 +171,18 @@ END: Cython Metadata */
 #else
   #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
 #endif
-#ifndef CYTHON_INLINE
-  #if defined(__GNUC__)
-    #define CYTHON_INLINE __inline__
-  #elif defined(_MSC_VER)
-    #define CYTHON_INLINE __inline
-  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-    #define CYTHON_INLINE inline
-  #else
-    #define CYTHON_INLINE
-  #endif
+#if PY_VERSION_HEX >= 0x030500B1
+#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
+#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
+#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
+typedef struct {
+    unaryfunc am_await;
+    unaryfunc am_aiter;
+    unaryfunc am_anext;
+} __Pyx_PyAsyncMethodsStruct;
+#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
+#else
+#define __Pyx_PyType_AsAsync(obj) NULL
 #endif
 #ifndef CYTHON_RESTRICT
   #if defined(__GNUC__)
@@ -204,35 +195,33 @@ END: Cython Metadata */
     #define CYTHON_RESTRICT
   #endif
 #endif
+#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
+
+#ifndef CYTHON_INLINE
+  #if defined(__GNUC__)
+    #define CYTHON_INLINE __inline__
+  #elif defined(_MSC_VER)
+    #define CYTHON_INLINE __inline
+  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define CYTHON_INLINE inline
+  #else
+    #define CYTHON_INLINE
+  #endif
+#endif
+
+#if defined(WIN32) || defined(MS_WINDOWS)
+  #define _USE_MATH_DEFINES
+#endif
+#include <math.h>
 #ifdef NAN
 #define __PYX_NAN() ((float) NAN)
 #else
 static CYTHON_INLINE float __PYX_NAN() {
-  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
-   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
-   a quiet NaN. */
   float value;
   memset(&value, 0xFF, sizeof(value));
   return value;
 }
 #endif
-#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
-#ifdef __cplusplus
-template<typename T>
-void __Pyx_call_destructor(T* x) {
-    x->~T();
-}
-template<typename T>
-class __Pyx_FakeReference {
-  public:
-    __Pyx_FakeReference() : ptr(NULL) { }
-    __Pyx_FakeReference(T& ref) : ptr(&ref) { }
-    T *operator->() { return ptr; }
-    operator T&() { return *ptr; }
-  private:
-    T *ptr;
-};
-#endif
 
 
 #if PY_MAJOR_VERSION >= 3
@@ -251,10 +240,6 @@ class __Pyx_FakeReference {
   #endif
 #endif
 
-#if defined(WIN32) || defined(MS_WINDOWS)
-#define _USE_MATH_DEFINES
-#endif
-#include <math.h>
 #define __PYX_HAVE__cutadapt___seqio
 #define __PYX_HAVE_API__cutadapt___seqio
 #ifdef _OPENMP
@@ -293,16 +278,34 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
 #define __PYX_DEFAULT_STRING_ENCODING ""
 #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
 #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
-#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (    \
-    (sizeof(type) < sizeof(Py_ssize_t))  ||             \
-    (sizeof(type) > sizeof(Py_ssize_t) &&               \
-          likely(v < (type)PY_SSIZE_T_MAX ||            \
-                 v == (type)PY_SSIZE_T_MAX)  &&         \
-          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||       \
-                                v == (type)PY_SSIZE_T_MIN)))  ||  \
-    (sizeof(type) == sizeof(Py_ssize_t) &&              \
-          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||        \
+#define __Pyx_uchar_cast(c) ((unsigned char)c)
+#define __Pyx_long_cast(x) ((long)x)
+#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
+    (sizeof(type) < sizeof(Py_ssize_t))  ||\
+    (sizeof(type) > sizeof(Py_ssize_t) &&\
+          likely(v < (type)PY_SSIZE_T_MAX ||\
+                 v == (type)PY_SSIZE_T_MAX)  &&\
+          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
+                                v == (type)PY_SSIZE_T_MIN)))  ||\
+    (sizeof(type) == sizeof(Py_ssize_t) &&\
+          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                                v == (type)PY_SSIZE_T_MAX)))  )
+#if defined (__cplusplus) && __cplusplus >= 201103L
+    #include <cstdlib>
+    #define __Pyx_sst_abs(value) std::abs(value)
+#elif SIZEOF_INT >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) abs(value)
+#elif SIZEOF_LONG >= SIZEOF_SIZE_T
+    #define __Pyx_sst_abs(value) labs(value)
+#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+    #define __Pyx_sst_abs(value) llabs(value)
+#elif defined (_MSC_VER) && defined (_M_X64)
+    #define __Pyx_sst_abs(value) _abs64(value)
+#elif defined (__GNUC__)
+    #define __Pyx_sst_abs(value) __builtin_llabs(value)
+#else
+    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
+#endif
 static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
 #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
@@ -337,8 +340,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
 #define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
 #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
 #define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
-#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
-#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
+#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
+#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
 static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
 static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
@@ -470,17 +474,17 @@ struct __pyx_obj_8cutadapt_6_seqio_Sequence {
   PyObject *name;
   PyObject *sequence;
   PyObject *qualities;
+  PyObject *name2;
   PyObject *match;
-  int twoheaders;
 };
 
 
-/* "cutadapt/_seqio.pyx":119
+/* "cutadapt/_seqio.pyx":106
  * 		self.delivers_qualities = True
  * 
  * 	def __iter__(self):             # <<<<<<<<<<<<<<
  * 		"""
- * 		Return tuples: (name, sequence, qualities).
+ * 		Yield Sequence objects
  */
 struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ {
   PyObject_HEAD
@@ -488,12 +492,12 @@ struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ {
   PyObject *__pyx_v_it;
   PyObject *__pyx_v_line;
   PyObject *__pyx_v_name;
+  PyObject *__pyx_v_name2;
   PyObject *__pyx_v_qualities;
   PyObject *__pyx_v_self;
   PyObject *__pyx_v_sequence;
   PyObject *__pyx_v_sequence_class;
   int __pyx_v_strip;
-  int __pyx_v_twoheaders;
   PyObject *__pyx_t_0;
   Py_ssize_t __pyx_t_1;
   PyObject *(*__pyx_t_2)(PyObject *);
@@ -517,19 +521,19 @@ struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ {
   static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
   #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
 #ifdef WITH_THREAD
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
-          if (acquire_gil) { \
-              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
-              PyGILState_Release(__pyx_gilstate_save); \
-          } else { \
-              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
+          if (acquire_gil) {\
+              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
+              PyGILState_Release(__pyx_gilstate_save);\
+          } else {\
+              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
           }
 #else
-  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
+  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
           __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
 #endif
-  #define __Pyx_RefNannyFinishContext() \
+  #define __Pyx_RefNannyFinishContext()\
           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
   #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
   #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
@@ -552,13 +556,13 @@ struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ {
   #define __Pyx_XGOTREF(r)
   #define __Pyx_XGIVEREF(r)
 #endif
-#define __Pyx_XDECREF_SET(r, v) do {                            \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_XDECREF(tmp);                              \
+#define __Pyx_XDECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_XDECREF(tmp);\
     } while (0)
-#define __Pyx_DECREF_SET(r, v) do {                             \
-        PyObject *tmp = (PyObject *) r;                         \
-        r = v; __Pyx_DECREF(tmp);                               \
+#define __Pyx_DECREF_SET(r, v) do {\
+        PyObject *tmp = (PyObject *) r;\
+        r = v; __Pyx_DECREF(tmp);\
     } while (0)
 #define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
 #define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
@@ -582,13 +586,20 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name);
 
 static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
 
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
-    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
     const char* function_name);
 
 static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
     Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
 
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
+#else
+#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
+    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
+#endif
+
 static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
         PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
         PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
@@ -642,20 +653,20 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr
 #define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
 static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *);
 
-#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
-    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
+#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
+    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
                __Pyx_GetItemInt_Generic(o, to_py_func(i))))
-#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
-#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
-    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
-    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
+#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
+    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
+    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
     (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
 static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                               int wraparound, int boundscheck);
@@ -675,108 +686,22 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int
 #define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
 #endif
 
-static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize_t start,
-                                         Py_ssize_t end, int direction)
-{
-    const char* self_ptr = PyBytes_AS_STRING(self);
-    Py_ssize_t self_len = PyBytes_GET_SIZE(self);
-    const char* sub_ptr;
-    Py_ssize_t sub_len;
-    int retval;
-    Py_buffer view;
-    view.obj = NULL;
-    if ( PyBytes_Check(arg) ) {
-        sub_ptr = PyBytes_AS_STRING(arg);
-        sub_len = PyBytes_GET_SIZE(arg);
-    }
-#if PY_MAJOR_VERSION < 3
-    else if ( PyUnicode_Check(arg) ) {
-        return PyUnicode_Tailmatch(self, arg, start, end, direction);
-    }
-#endif
-    else {
-        if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1))
-            return -1;
-        sub_ptr = (const char*) view.buf;
-        sub_len = view.len;
-    }
-    if (end > self_len)
-        end = self_len;
-    else if (end < 0)
-        end += self_len;
-    if (end < 0)
-        end = 0;
-    if (start < 0)
-        start += self_len;
-    if (start < 0)
-        start = 0;
-    if (direction > 0) {
-        if (end-sub_len > start)
-            start = end - sub_len;
-    }
-    if (start + sub_len <= end)
-        retval = !memcmp(self_ptr+start, sub_ptr, (size_t)sub_len);
-    else
-        retval = 0;
-    if (view.obj)
-        PyBuffer_Release(&view);
-    return retval;
-}
-static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr, Py_ssize_t start,
-                                   Py_ssize_t end, int direction)
-{
-    if (unlikely(PyTuple_Check(substr))) {
-        Py_ssize_t i, count = PyTuple_GET_SIZE(substr);
-        for (i = 0; i < count; i++) {
-            int result;
-#if CYTHON_COMPILING_IN_CPYTHON
-            result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substr, i),
-                                                   start, end, direction);
-#else
-            PyObject* sub = PySequence_ITEM(substr, i);
-            if (unlikely(!sub)) return -1;
-            result = __Pyx_PyBytes_SingleTailmatch(self, sub, start, end, direction);
-            Py_DECREF(sub);
-#endif
-            if (result) {
-                return result;
-            }
-        }
-        return 0;
-    }
-    return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction);
-}
+static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg,
+                                         Py_ssize_t start, Py_ssize_t end, int direction);
+static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr,
+                                   Py_ssize_t start, Py_ssize_t end, int direction);
 
 static int __Pyx_PyUnicode_Tailmatch(PyObject* s, PyObject* substr,
-                                     Py_ssize_t start, Py_ssize_t end, int direction) {
-    if (unlikely(PyTuple_Check(substr))) {
-        Py_ssize_t i, count = PyTuple_GET_SIZE(substr);
-        for (i = 0; i < count; i++) {
-            int result;
-#if CYTHON_COMPILING_IN_CPYTHON
-            result = PyUnicode_Tailmatch(s, PyTuple_GET_ITEM(substr, i),
-                                         start, end, direction);
-#else
-            PyObject* sub = PySequence_ITEM(substr, i);
-            if (unlikely(!sub)) return -1;
-            result = PyUnicode_Tailmatch(s, sub, start, end, direction);
-            Py_DECREF(sub);
-#endif
-            if (result) {
-                return result;
-            }
-        }
-        return 0;
-    }
-    return PyUnicode_Tailmatch(s, substr, start, end, direction);
-}
+                                     Py_ssize_t start, Py_ssize_t end, int direction);
 
 static CYTHON_INLINE int __Pyx_PyStr_Tailmatch(PyObject* self, PyObject* arg, Py_ssize_t start,
                                                Py_ssize_t end, int direction);
 
 static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);
 
-static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */
+static CYTHON_INLINE long __Pyx_mod_long(long, long);
+
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
 
 static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
 
@@ -794,13 +719,13 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
 #define __Pyx_CYFUNCTION_STATICMETHOD  0x01
 #define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
 #define __Pyx_CYFUNCTION_CCLASS        0x04
-#define __Pyx_CyFunction_GetClosure(f) \
+#define __Pyx_CyFunction_GetClosure(f)\
     (((__pyx_CyFunctionObject *) (f))->func_closure)
-#define __Pyx_CyFunction_GetClassObj(f) \
+#define __Pyx_CyFunction_GetClassObj(f)\
     (((__pyx_CyFunctionObject *) (f))->func_classobj)
-#define __Pyx_CyFunction_Defaults(type, f) \
+#define __Pyx_CyFunction_Defaults(type, f)\
     ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
-#define __Pyx_CyFunction_SetDefaultsGetter(f, g) \
+#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
     ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
 typedef struct {
     PyCFunctionObject func;
@@ -824,7 +749,7 @@ typedef struct {
     PyObject *func_annotations;
 } __pyx_CyFunctionObject;
 static PyTypeObject *__pyx_CyFunctionType = 0;
-#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code) \
+#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
     __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
 static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
                                       int flags, PyObject* qualname,
@@ -840,7 +765,7 @@ static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                              PyObject *dict);
 static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                               PyObject *dict);
-static int __Pyx_CyFunction_init(void);
+static int __pyx_CyFunction_init(void);
 
 typedef struct {
     int code_line;
@@ -859,8 +784,6 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
 static void __Pyx_AddTraceback(const char *funcname, int c_line,
                                int py_line, const char *filename);
 
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
-
 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
 
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
@@ -871,13 +794,10 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
 
 static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);
 
-#define __Pyx_Generator_USED
-#include <structmember.h>
-#include <frameobject.h>
-typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *);
+typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *);
 typedef struct {
     PyObject_HEAD
-    __pyx_generator_body_t body;
+    __pyx_coroutine_body_t body;
     PyObject *closure;
     PyObject *exc_type;
     PyObject *exc_value;
@@ -889,17 +809,28 @@ typedef struct {
     PyObject *gi_qualname;
     int resume_label;
     char is_running;
-} __pyx_GeneratorObject;
-static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
-                                                  PyObject *closure, PyObject *name, PyObject *qualname);
-static int __pyx_Generator_init(void);
-static int __Pyx_Generator_clear(PyObject* self);
+} __pyx_CoroutineObject;
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject *type, __pyx_coroutine_body_t body,
+                                                   PyObject *closure, PyObject *name, PyObject *qualname);
+static int __Pyx_Coroutine_clear(PyObject *self);
 #if 1 || PY_VERSION_HEX < 0x030300B0
 static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue);
 #else
 #define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue)
 #endif
 
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);
+
+static int __Pyx_patch_abc(void);
+
+#define __Pyx_Generator_USED
+static PyTypeObject *__pyx_GeneratorType = 0;
+#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
+#define __Pyx_Generator_New(body, closure, name, qualname)\
+    __Pyx__Coroutine_New(__pyx_GeneratorType, body, closure, name, qualname)
+static PyObject *__Pyx_Generator_Next(PyObject *self);
+static int __pyx_Generator_init(void);
+
 static int __Pyx_check_binary_version(void);
 
 static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
@@ -916,49 +847,15 @@ static PyObject *__pyx_builtin_Exception;
 static PyObject *__pyx_builtin_object;
 static PyObject *__pyx_builtin_NotImplementedError;
 static PyObject *__pyx_builtin_ValueError;
-static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_s, PyObject *__pyx_v_n); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_sequence, PyObject *__pyx_v_qualities, int __pyx_v_twoheaders, PyObject *__pyx_v_match); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_4__repr__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static Py_ssize_t __pyx_pf_8cutadapt_6_seqio_8Sequence_6__len__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10__reduce__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_12write(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_outfile); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_4name___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_4name_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_4name_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_11__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_file, PyObject *__pyx_v_sequence_class); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_5close(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_7__enter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
-static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_9__exit__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args); /* proto */
-static PyObject *__pyx_tp_new_8cutadapt_6_seqio_Sequence(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
-static PyObject *__pyx_tp_new_8cutadapt_6_seqio___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
 static char __pyx_k_[] = "...";
 static char __pyx_k_i[] = "i";
 static char __pyx_k_n[] = "n";
 static char __pyx_k_s[] = "s";
 static char __pyx_k__2[] = "";
 static char __pyx_k__3[] = "@";
-static char __pyx_k__4[] = "\n";
-static char __pyx_k__5[] = "\n+";
-static char __pyx_k__6[] = ">";
-static char __pyx_k__7[] = "\r\n";
-static char __pyx_k__8[] = "+\n";
-static char __pyx_k__9[] = "+";
-static char __pyx_k_fp[] = "fp";
+static char __pyx_k__4[] = "\r\n";
+static char __pyx_k__5[] = "+\n";
+static char __pyx_k__6[] = "+";
 static char __pyx_k_it[] = "it";
 static char __pyx_k_doc[] = "__doc__";
 static char __pyx_k_args[] = "args";
@@ -976,10 +873,11 @@ static char __pyx_k_class[] = "__class__";
 static char __pyx_k_close[] = "close";
 static char __pyx_k_enter[] = "__enter__";
 static char __pyx_k_match[] = "match";
+static char __pyx_k_name2[] = "name2";
 static char __pyx_k_strip[] = "strip";
 static char __pyx_k_throw[] = "throw";
-static char __pyx_k_write[] = "write";
 static char __pyx_k_xopen[] = "xopen";
+static char __pyx_k_file_2[] = "_file";
 static char __pyx_k_format[] = "format";
 static char __pyx_k_import[] = "__import__";
 static char __pyx_k_module[] = "__module__";
@@ -993,10 +891,9 @@ static char __pyx_k_Exception[] = "Exception";
 static char __pyx_k_metaclass[] = "__metaclass__";
 static char __pyx_k_qualities[] = "qualities";
 static char __pyx_k_ValueError[] = "ValueError";
-static char __pyx_k_twoheaders[] = "twoheaders";
 static char __pyx_k_FastqReader[] = "FastqReader";
 static char __pyx_k_FormatError[] = "FormatError";
-static char __pyx_k_file_passed[] = "_file_passed";
+static char __pyx_k_close_on_exit[] = "_close_on_exit";
 static char __pyx_k_qualities_0_r[] = ", qualities={0!r}";
 static char __pyx_k_sequence_class[] = "sequence_class";
 static char __pyx_k_cutadapt__seqio[] = "cutadapt._seqio";
@@ -1015,8 +912,8 @@ static char __pyx_k_Reader_for_FASTQ_files_Does_not[] = "\n\tReader for FASTQ fi
 static char __pyx_k_home_marcel_scm_cutadapt_cutada[] = "/home/marcel/scm/cutadapt/cutadapt/_seqio.pyx";
 static char __pyx_k_I_O_operation_on_closed_FastqRea[] = "I/O operation on closed FastqReader";
 static char __pyx_k_In_read_named_0_r_length_of_qual[] = "In read named {0!r}: length of quality sequence ({1}) and length of read ({2}) do not match";
-static char __pyx_k_at_line_0_expected_a_line_starti[] = "at line {0}, expected a line starting with '@'";
-static char __pyx_k_at_line_0_expected_a_line_starti_2[] = "at line {0}, expected a line starting with '+'";
+static char __pyx_k_Line_0_in_FASTQ_file_is_expected[] = "Line {0} in FASTQ file is expected to start with '@', but found {1!r}";
+static char __pyx_k_Line_0_in_FASTQ_file_is_expected_2[] = "Line {0} in FASTQ file is expected to start with '+', but found {1!r}";
 static PyObject *__pyx_kp_s_;
 static PyObject *__pyx_kp_s_At_line_0_Sequence_descriptions;
 static PyObject *__pyx_n_s_Exception;
@@ -1030,6 +927,8 @@ static PyObject *__pyx_n_s_FastqReader_close;
 static PyObject *__pyx_n_s_FormatError;
 static PyObject *__pyx_kp_s_I_O_operation_on_closed_FastqRea;
 static PyObject *__pyx_kp_s_In_read_named_0_r_length_of_qual;
+static PyObject *__pyx_kp_s_Line_0_in_FASTQ_file_is_expected;
+static PyObject *__pyx_kp_s_Line_0_in_FASTQ_file_is_expected_2;
 static PyObject *__pyx_n_s_NotImplementedError;
 static PyObject *__pyx_kp_s_Raised_when_an_input_file_FASTA;
 static PyObject *__pyx_kp_s_Reader_for_FASTQ_files_Does_not;
@@ -1040,23 +939,18 @@ static PyObject *__pyx_kp_s__3;
 static PyObject *__pyx_kp_s__4;
 static PyObject *__pyx_kp_s__5;
 static PyObject *__pyx_kp_s__6;
-static PyObject *__pyx_kp_s__7;
-static PyObject *__pyx_kp_s__8;
-static PyObject *__pyx_kp_s__9;
 static PyObject *__pyx_n_s_args;
-static PyObject *__pyx_kp_s_at_line_0_expected_a_line_starti;
-static PyObject *__pyx_kp_s_at_line_0_expected_a_line_starti_2;
 static PyObject *__pyx_n_s_class;
 static PyObject *__pyx_n_s_close;
+static PyObject *__pyx_n_s_close_on_exit;
 static PyObject *__pyx_n_s_cutadapt__seqio;
 static PyObject *__pyx_n_s_delivers_qualities;
 static PyObject *__pyx_n_s_doc;
 static PyObject *__pyx_n_s_enter;
 static PyObject *__pyx_n_s_exit;
 static PyObject *__pyx_n_s_file;
-static PyObject *__pyx_n_s_file_passed;
+static PyObject *__pyx_n_s_file_2;
 static PyObject *__pyx_n_s_format;
-static PyObject *__pyx_n_s_fp;
 static PyObject *__pyx_kp_s_home_marcel_scm_cutadapt_cutada;
 static PyObject *__pyx_n_s_i;
 static PyObject *__pyx_n_s_import;
@@ -1070,6 +964,7 @@ static PyObject *__pyx_n_s_metaclass;
 static PyObject *__pyx_n_s_module;
 static PyObject *__pyx_n_s_n;
 static PyObject *__pyx_n_s_name;
+static PyObject *__pyx_n_s_name2;
 static PyObject *__pyx_n_s_object;
 static PyObject *__pyx_n_s_prepare;
 static PyObject *__pyx_n_s_qualities;
@@ -1085,26 +980,54 @@ static PyObject *__pyx_n_s_shorten;
 static PyObject *__pyx_n_s_strip;
 static PyObject *__pyx_n_s_test;
 static PyObject *__pyx_n_s_throw;
-static PyObject *__pyx_n_s_twoheaders;
-static PyObject *__pyx_n_s_write;
 static PyObject *__pyx_n_s_xopen;
+static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_s, PyObject *__pyx_v_n); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_sequence, PyObject *__pyx_v_qualities, PyObject *__pyx_v_name2, PyObject *__pyx_v_match); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_4__repr__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static Py_ssize_t __pyx_pf_8cutadapt_6_seqio_8Sequence_6__len__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10__reduce__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_4name___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_4name_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_4name_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5name2___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_11__defaults__(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_file, PyObject *__pyx_v_sequence_class); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_2__iter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_5close(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_7__enter__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
+static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_9__exit__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_args); /* proto */
+static PyObject *__pyx_tp_new_8cutadapt_6_seqio_Sequence(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
+static PyObject *__pyx_tp_new_8cutadapt_6_seqio___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
 static PyObject *__pyx_int_3;
 static PyObject *__pyx_int_100;
+static PyObject *__pyx_tuple__7;
+static PyObject *__pyx_tuple__8;
+static PyObject *__pyx_tuple__9;
 static PyObject *__pyx_tuple__10;
-static PyObject *__pyx_tuple__11;
 static PyObject *__pyx_tuple__12;
-static PyObject *__pyx_tuple__13;
-static PyObject *__pyx_tuple__15;
-static PyObject *__pyx_tuple__17;
-static PyObject *__pyx_tuple__19;
-static PyObject *__pyx_tuple__21;
-static PyObject *__pyx_tuple__23;
-static PyObject *__pyx_codeobj__14;
-static PyObject *__pyx_codeobj__16;
-static PyObject *__pyx_codeobj__18;
-static PyObject *__pyx_codeobj__20;
-static PyObject *__pyx_codeobj__22;
-static PyObject *__pyx_codeobj__24;
+static PyObject *__pyx_tuple__14;
+static PyObject *__pyx_tuple__16;
+static PyObject *__pyx_tuple__18;
+static PyObject *__pyx_tuple__20;
+static PyObject *__pyx_codeobj__11;
+static PyObject *__pyx_codeobj__13;
+static PyObject *__pyx_codeobj__15;
+static PyObject *__pyx_codeobj__17;
+static PyObject *__pyx_codeobj__19;
+static PyObject *__pyx_codeobj__21;
 
 /* "cutadapt/_seqio.pyx":16
  * 
@@ -1216,6 +1139,14 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__p
     __Pyx_INCREF(Py_None);
     __pyx_r = Py_None;
     goto __pyx_L0;
+
+    /* "cutadapt/_seqio.pyx":18
+ * def _shorten(s, n=100):
+ * 	"""Shorten string s to at most n characters, appending "..." if necessary."""
+ * 	if s is None:             # <<<<<<<<<<<<<<
+ * 		return None
+ * 	if len(s) > n:
+ */
   }
 
   /* "cutadapt/_seqio.pyx":20
@@ -1241,7 +1172,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__p
  * 	return s
  * 
  */
-    __pyx_t_5 = PyNumber_Subtract(__pyx_v_n, __pyx_int_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_v_n, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
     __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_v_s, 0, 0, NULL, &__pyx_t_5, NULL, 0, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
@@ -1251,9 +1182,15 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__p
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_5);
     __pyx_t_5 = 0;
-    goto __pyx_L4;
+
+    /* "cutadapt/_seqio.pyx":20
+ * 	if s is None:
+ * 		return None
+ * 	if len(s) > n:             # <<<<<<<<<<<<<<
+ * 		s = s[:n-3] + '...'
+ * 	return s
+ */
   }
-  __pyx_L4:;
 
   /* "cutadapt/_seqio.pyx":22
  * 	if len(s) > n:
@@ -1289,10 +1226,10 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio__shorten(CYTHON_UNUSED PyObject *__p
 }
 
 /* "cutadapt/_seqio.pyx":41
- * 		public bint twoheaders
+ * 		public object match
  * 
- * 	def __init__(self, str name, str sequence, str qualities=None,             # <<<<<<<<<<<<<<
- * 			  bint twoheaders=False, match=None):
+ * 	def __init__(self, str name, str sequence, str qualities=None, str name2='',             # <<<<<<<<<<<<<<
+ * 			match=None):
  * 		"""Set qualities to None if there are no quality values"""
  */
 
@@ -1306,7 +1243,7 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
   PyObject *__pyx_v_name = 0;
   PyObject *__pyx_v_sequence = 0;
   PyObject *__pyx_v_qualities = 0;
-  int __pyx_v_twoheaders;
+  PyObject *__pyx_v_name2 = 0;
   PyObject *__pyx_v_match = 0;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
@@ -1315,14 +1252,15 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
   {
-    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_sequence,&__pyx_n_s_qualities,&__pyx_n_s_twoheaders,&__pyx_n_s_match,0};
+    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_sequence,&__pyx_n_s_qualities,&__pyx_n_s_name2,&__pyx_n_s_match,0};
     PyObject* values[5] = {0,0,0,0,0};
     values[2] = ((PyObject*)Py_None);
+    values[3] = ((PyObject*)__pyx_kp_s__2);
 
     /* "cutadapt/_seqio.pyx":42
  * 
- * 	def __init__(self, str name, str sequence, str qualities=None,
- * 			  bint twoheaders=False, match=None):             # <<<<<<<<<<<<<<
+ * 	def __init__(self, str name, str sequence, str qualities=None, str name2='',
+ * 			match=None):             # <<<<<<<<<<<<<<
  * 		"""Set qualities to None if there are no quality values"""
  * 		self.name = name
  */
@@ -1356,7 +1294,7 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
         }
         case  3:
         if (kw_args > 0) {
-          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_twoheaders);
+          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_name2);
           if (value) { values[3] = value; kw_args--; }
         }
         case  4:
@@ -1382,11 +1320,7 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
     __pyx_v_name = ((PyObject*)values[0]);
     __pyx_v_sequence = ((PyObject*)values[1]);
     __pyx_v_qualities = ((PyObject*)values[2]);
-    if (values[3]) {
-      __pyx_v_twoheaders = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_twoheaders == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
-    } else {
-      __pyx_v_twoheaders = ((int)0);
-    }
+    __pyx_v_name2 = ((PyObject*)values[3]);
     __pyx_v_match = values[4];
   }
   goto __pyx_L4_argument_unpacking_done;
@@ -1400,13 +1334,14 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name), (&PyString_Type), 1, "name", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sequence), (&PyString_Type), 1, "sequence", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_qualities), (&PyString_Type), 1, "qualities", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), __pyx_v_name, __pyx_v_sequence, __pyx_v_qualities, __pyx_v_twoheaders, __pyx_v_match);
+  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name2), (&PyString_Type), 1, "name2", 1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), __pyx_v_name, __pyx_v_sequence, __pyx_v_qualities, __pyx_v_name2, __pyx_v_match);
 
   /* "cutadapt/_seqio.pyx":41
- * 		public bint twoheaders
+ * 		public object match
  * 
- * 	def __init__(self, str name, str sequence, str qualities=None,             # <<<<<<<<<<<<<<
- * 			  bint twoheaders=False, match=None):
+ * 	def __init__(self, str name, str sequence, str qualities=None, str name2='',             # <<<<<<<<<<<<<<
+ * 			match=None):
  * 		"""Set qualities to None if there are no quality values"""
  */
 
@@ -1419,7 +1354,7 @@ static int __pyx_pw_8cutadapt_6_seqio_8Sequence_1__init__(PyObject *__pyx_v_self
   return __pyx_r;
 }
 
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_sequence, PyObject *__pyx_v_qualities, int __pyx_v_twoheaders, PyObject *__pyx_v_match) {
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_name, PyObject *__pyx_v_sequence, PyObject *__pyx_v_qualities, PyObject *__pyx_v_name2, PyObject *__pyx_v_match) {
   PyObject *__pyx_v_rname = NULL;
   int __pyx_r;
   __Pyx_RefNannyDeclarations
@@ -1442,7 +1377,7 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
   __Pyx_RefNannySetupContext("__init__", 0);
 
   /* "cutadapt/_seqio.pyx":44
- * 			  bint twoheaders=False, match=None):
+ * 			match=None):
  * 		"""Set qualities to None if there are no quality values"""
  * 		self.name = name             # <<<<<<<<<<<<<<
  * 		self.sequence = sequence
@@ -1459,7 +1394,7 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
  * 		self.name = name
  * 		self.sequence = sequence             # <<<<<<<<<<<<<<
  * 		self.qualities = qualities
- * 		self.twoheaders = twoheaders
+ * 		self.name2 = name2
  */
   __Pyx_INCREF(__pyx_v_sequence);
   __Pyx_GIVEREF(__pyx_v_sequence);
@@ -1471,7 +1406,7 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
  * 		self.name = name
  * 		self.sequence = sequence
  * 		self.qualities = qualities             # <<<<<<<<<<<<<<
- * 		self.twoheaders = twoheaders
+ * 		self.name2 = name2
  * 		self.match = match
  */
   __Pyx_INCREF(__pyx_v_qualities);
@@ -1483,15 +1418,19 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
   /* "cutadapt/_seqio.pyx":47
  * 		self.sequence = sequence
  * 		self.qualities = qualities
- * 		self.twoheaders = twoheaders             # <<<<<<<<<<<<<<
+ * 		self.name2 = name2             # <<<<<<<<<<<<<<
  * 		self.match = match
  * 		if qualities is not None and len(qualities) != len(sequence):
  */
-  __pyx_v_self->twoheaders = __pyx_v_twoheaders;
+  __Pyx_INCREF(__pyx_v_name2);
+  __Pyx_GIVEREF(__pyx_v_name2);
+  __Pyx_GOTREF(__pyx_v_self->name2);
+  __Pyx_DECREF(__pyx_v_self->name2);
+  __pyx_v_self->name2 = __pyx_v_name2;
 
   /* "cutadapt/_seqio.pyx":48
  * 		self.qualities = qualities
- * 		self.twoheaders = twoheaders
+ * 		self.name2 = name2
  * 		self.match = match             # <<<<<<<<<<<<<<
  * 		if qualities is not None and len(qualities) != len(sequence):
  * 			rname = _shorten(name)
@@ -1503,7 +1442,7 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
   __pyx_v_self->match = __pyx_v_match;
 
   /* "cutadapt/_seqio.pyx":49
- * 		self.twoheaders = twoheaders
+ * 		self.name2 = name2
  * 		self.match = match
  * 		if qualities is not None and len(qualities) != len(sequence):             # <<<<<<<<<<<<<<
  * 			rname = _shorten(name)
@@ -1644,13 +1583,21 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence___init__(struct __pyx_obj_8cutad
     __Pyx_Raise(__pyx_t_6, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_seqio.pyx":49
+ * 		self.name2 = name2
+ * 		self.match = match
+ * 		if qualities is not None and len(qualities) != len(sequence):             # <<<<<<<<<<<<<<
+ * 			rname = _shorten(name)
+ * 			raise FormatError("In read named {0!r}: length of quality sequence ({1}) and length of read ({2}) do not match".format(
+ */
   }
 
   /* "cutadapt/_seqio.pyx":41
- * 		public bint twoheaders
+ * 		public object match
  * 
- * 	def __init__(self, str name, str sequence, str qualities=None,             # <<<<<<<<<<<<<<
- * 			  bint twoheaders=False, match=None):
+ * 	def __init__(self, str name, str sequence, str qualities=None, str name2='',             # <<<<<<<<<<<<<<
+ * 			match=None):
  * 		"""Set qualities to None if there are no quality values"""
  */
 
@@ -1708,9 +1655,8 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_
   PyObject *__pyx_t_4 = NULL;
   int __pyx_t_5;
   PyObject *__pyx_t_6 = NULL;
-  PyObject *__pyx_t_7 = NULL;
-  Py_ssize_t __pyx_t_8;
-  PyObject *__pyx_t_9 = NULL;
+  Py_ssize_t __pyx_t_7;
+  PyObject *__pyx_t_8 = NULL;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
@@ -1732,7 +1678,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_
  * 			self.name,
  * 			self.sequence[key],             # <<<<<<<<<<<<<<
  * 			self.qualities[key] if self.qualities is not None else None,
- * 			self.twoheaders,
+ * 			self.name2,
  */
   __pyx_t_3 = PyObject_GetItem(__pyx_v_self->sequence, __pyx_v_key); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __Pyx_GOTREF(__pyx_t_3);
@@ -1741,7 +1687,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_
  * 			self.name,
  * 			self.sequence[key],
  * 			self.qualities[key] if self.qualities is not None else None,             # <<<<<<<<<<<<<<
- * 			self.twoheaders,
+ * 			self.name2,
  * 			self.match)
  */
   __pyx_t_5 = (__pyx_v_self->qualities != ((PyObject*)Py_None));
@@ -1755,58 +1701,48 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_
     __pyx_t_4 = Py_None;
   }
 
-  /* "cutadapt/_seqio.pyx":60
- * 			self.sequence[key],
- * 			self.qualities[key] if self.qualities is not None else None,
- * 			self.twoheaders,             # <<<<<<<<<<<<<<
- * 			self.match)
- * 
- */
-  __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_self->twoheaders); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_6);
-
   /* "cutadapt/_seqio.pyx":61
  * 			self.qualities[key] if self.qualities is not None else None,
- * 			self.twoheaders,
+ * 			self.name2,
  * 			self.match)             # <<<<<<<<<<<<<<
  * 
  * 	def __repr__(self):
  */
-  __pyx_t_7 = NULL;
-  __pyx_t_8 = 0;
+  __pyx_t_6 = NULL;
+  __pyx_t_7 = 0;
   if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
-    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
-    if (likely(__pyx_t_7)) {
+    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2);
+    if (likely(__pyx_t_6)) {
       PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
-      __Pyx_INCREF(__pyx_t_7);
+      __Pyx_INCREF(__pyx_t_6);
       __Pyx_INCREF(function);
       __Pyx_DECREF_SET(__pyx_t_2, function);
-      __pyx_t_8 = 1;
+      __pyx_t_7 = 1;
     }
   }
-  __pyx_t_9 = PyTuple_New(5+__pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_9);
-  if (__pyx_t_7) {
-    __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+  __pyx_t_8 = PyTuple_New(5+__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_8);
+  if (__pyx_t_6) {
+    __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
   }
   __Pyx_INCREF(__pyx_v_self->name);
   __Pyx_GIVEREF(__pyx_v_self->name);
-  PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_self->name);
+  PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_v_self->name);
   __Pyx_GIVEREF(__pyx_t_3);
-  PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_3);
+  PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_3);
   __Pyx_GIVEREF(__pyx_t_4);
-  PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, __pyx_t_4);
-  __Pyx_GIVEREF(__pyx_t_6);
-  PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_8, __pyx_t_6);
+  PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_4);
+  __Pyx_INCREF(__pyx_v_self->name2);
+  __Pyx_GIVEREF(__pyx_v_self->name2);
+  PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_7, __pyx_v_self->name2);
   __Pyx_INCREF(__pyx_v_self->match);
   __Pyx_GIVEREF(__pyx_v_self->match);
-  PyTuple_SET_ITEM(__pyx_t_9, 4+__pyx_t_8, __pyx_v_self->match);
+  PyTuple_SET_ITEM(__pyx_t_8, 4+__pyx_t_7, __pyx_v_self->match);
   __pyx_t_3 = 0;
   __pyx_t_4 = 0;
-  __pyx_t_6 = 0;
-  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_r = __pyx_t_1;
   __pyx_t_1 = 0;
@@ -1827,8 +1763,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_2__getitem__(struct __pyx_
   __Pyx_XDECREF(__pyx_t_3);
   __Pyx_XDECREF(__pyx_t_4);
   __Pyx_XDECREF(__pyx_t_6);
-  __Pyx_XDECREF(__pyx_t_7);
-  __Pyx_XDECREF(__pyx_t_9);
+  __Pyx_XDECREF(__pyx_t_8);
   __Pyx_AddTraceback("cutadapt._seqio.Sequence.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_r = NULL;
   __pyx_L0:;
@@ -1962,13 +1897,19 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_4__repr__(struct __pyx_obj
     __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
     __Pyx_DECREF_SET(__pyx_v_qstr, __pyx_t_3);
     __pyx_t_3 = 0;
-    goto __pyx_L3;
-  }
-  __pyx_L3:;
 
-  /* "cutadapt/_seqio.pyx":67
- * 		if self.qualities is not None:
- * 			qstr = ', qualities={0!r}'.format(_shorten(self.qualities))
+    /* "cutadapt/_seqio.pyx":65
+ * 	def __repr__(self):
+ * 		qstr = ''
+ * 		if self.qualities is not None:             # <<<<<<<<<<<<<<
+ * 			qstr = ', qualities={0!r}'.format(_shorten(self.qualities))
+ * 		return '<Sequence(name={0!r}, sequence={1!r}{2})>'.format(_shorten(self.name), _shorten(self.sequence), qstr)
+ */
+  }
+
+  /* "cutadapt/_seqio.pyx":67
+ * 		if self.qualities is not None:
+ * 			qstr = ', qualities={0!r}'.format(_shorten(self.qualities))
  * 		return '<Sequence(name={0!r}, sequence={1!r}{2})>'.format(_shorten(self.name), _shorten(self.sequence), qstr)             # <<<<<<<<<<<<<<
  * 
  * 	def __len__(self):
@@ -2293,16 +2234,24 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8__richcmp__(PyObject *__p
       __Pyx_INCREF(__pyx_v_eq);
       __pyx_r = __pyx_v_eq;
       goto __pyx_L0;
+
+      /* "cutadapt/_seqio.pyx":77
+ * 				self.sequence == other.sequence and \
+ * 				self.qualities == other.qualities
+ * 			if op == 2:             # <<<<<<<<<<<<<<
+ * 				return eq
+ * 			else:
+ */
     }
-    /*else*/ {
 
-      /* "cutadapt/_seqio.pyx":80
+    /* "cutadapt/_seqio.pyx":80
  * 				return eq
  * 			else:
  * 				return not eq             # <<<<<<<<<<<<<<
  * 		else:
  * 			raise NotImplementedError()
  */
+    /*else*/ {
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_eq); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_3 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
@@ -2311,16 +2260,24 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8__richcmp__(PyObject *__p
       __pyx_t_3 = 0;
       goto __pyx_L0;
     }
+
+    /* "cutadapt/_seqio.pyx":73
+ * 
+ * 	def __richcmp__(self, other, int op):
+ * 		if 2 <= op <= 3:             # <<<<<<<<<<<<<<
+ * 			eq = self.name == other.name and \
+ * 				self.sequence == other.sequence and \
+ */
   }
-  /*else*/ {
 
-    /* "cutadapt/_seqio.pyx":82
+  /* "cutadapt/_seqio.pyx":82
  * 				return not eq
  * 		else:
  * 			raise NotImplementedError()             # <<<<<<<<<<<<<<
  * 
  * 	def __reduce__(self):
  */
+  /*else*/ {
     __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_3);
     __Pyx_Raise(__pyx_t_3, 0, 0, 0);
@@ -2355,7 +2312,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_8__richcmp__(PyObject *__p
  * 			raise NotImplementedError()
  * 
  * 	def __reduce__(self):             # <<<<<<<<<<<<<<
- * 		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))
+ * 		return (Sequence, (self.name, self.sequence, self.qualities, self.name2))
  * 
  */
 
@@ -2385,44 +2342,42 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10__reduce__(struct __pyx_
   /* "cutadapt/_seqio.pyx":85
  * 
  * 	def __reduce__(self):
- * 		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))             # <<<<<<<<<<<<<<
+ * 		return (Sequence, (self.name, self.sequence, self.qualities, self.name2))             # <<<<<<<<<<<<<<
+ * 
  * 
- * 	def write(self, outfile):
  */
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->twoheaders); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_v_self->name);
   __Pyx_GIVEREF(__pyx_v_self->name);
-  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->name);
+  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name);
   __Pyx_INCREF(__pyx_v_self->sequence);
   __Pyx_GIVEREF(__pyx_v_self->sequence);
-  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->sequence);
+  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->sequence);
   __Pyx_INCREF(__pyx_v_self->qualities);
   __Pyx_GIVEREF(__pyx_v_self->qualities);
-  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_self->qualities);
+  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_self->qualities);
+  __Pyx_INCREF(__pyx_v_self->name2);
+  __Pyx_GIVEREF(__pyx_v_self->name2);
+  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_self->name2);
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_t_2);
+  __Pyx_INCREF(((PyObject *)__pyx_ptype_8cutadapt_6_seqio_Sequence));
+  __Pyx_GIVEREF(((PyObject *)__pyx_ptype_8cutadapt_6_seqio_Sequence));
+  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_8cutadapt_6_seqio_Sequence));
   __Pyx_GIVEREF(__pyx_t_1);
-  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1);
+  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
   __pyx_t_1 = 0;
-  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __Pyx_INCREF(((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence)));
-  __Pyx_GIVEREF(((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence)));
-  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence)));
-  __Pyx_GIVEREF(__pyx_t_2);
-  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
+  __pyx_r = __pyx_t_2;
   __pyx_t_2 = 0;
-  __pyx_r = __pyx_t_1;
-  __pyx_t_1 = 0;
   goto __pyx_L0;
 
   /* "cutadapt/_seqio.pyx":84
  * 			raise NotImplementedError()
  * 
  * 	def __reduce__(self):             # <<<<<<<<<<<<<<
- * 		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))
+ * 		return (Sequence, (self.name, self.sequence, self.qualities, self.name2))
  * 
  */
 
@@ -2438,204 +2393,6 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10__reduce__(struct __pyx_
   return __pyx_r;
 }
 
-/* "cutadapt/_seqio.pyx":87
- * 		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))
- * 
- * 	def write(self, outfile):             # <<<<<<<<<<<<<<
- * 		if self.qualities is not None:
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'
- */
-
-/* Python wrapper */
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_13write(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile); /*proto*/
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_13write(PyObject *__pyx_v_self, PyObject *__pyx_v_outfile) {
-  PyObject *__pyx_r = 0;
-  __Pyx_RefNannyDeclarations
-  __Pyx_RefNannySetupContext("write (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_12write(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), ((PyObject *)__pyx_v_outfile));
-
-  /* function exit code */
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_12write(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_outfile) {
-  PyObject *__pyx_v_s = NULL;
-  PyObject *__pyx_r = NULL;
-  __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  int __pyx_t_2;
-  PyObject *__pyx_t_3 = NULL;
-  PyObject *__pyx_t_4 = NULL;
-  PyObject *__pyx_t_5 = NULL;
-  PyObject *__pyx_t_6 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
-  __Pyx_RefNannySetupContext("write", 0);
-
-  /* "cutadapt/_seqio.pyx":88
- * 
- * 	def write(self, outfile):
- * 		if self.qualities is not None:             # <<<<<<<<<<<<<<
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'
- * 			if self.twoheaders:
- */
-  __pyx_t_1 = (__pyx_v_self->qualities != ((PyObject*)Py_None));
-  __pyx_t_2 = (__pyx_t_1 != 0);
-  if (__pyx_t_2) {
-
-    /* "cutadapt/_seqio.pyx":89
- * 	def write(self, outfile):
- * 		if self.qualities is not None:
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'             # <<<<<<<<<<<<<<
- * 			if self.twoheaders:
- * 				s += self.name
- */
-    __pyx_t_3 = PyNumber_Add(__pyx_kp_s__3, __pyx_v_self->name); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_v_self->sequence); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_v_s = __pyx_t_4;
-    __pyx_t_4 = 0;
-
-    /* "cutadapt/_seqio.pyx":90
- * 		if self.qualities is not None:
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'
- * 			if self.twoheaders:             # <<<<<<<<<<<<<<
- * 				s += self.name
- * 			s += '\n' + self.qualities + '\n'
- */
-    __pyx_t_2 = (__pyx_v_self->twoheaders != 0);
-    if (__pyx_t_2) {
-
-      /* "cutadapt/_seqio.pyx":91
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'
- * 			if self.twoheaders:
- * 				s += self.name             # <<<<<<<<<<<<<<
- * 			s += '\n' + self.qualities + '\n'
- * 		else:
- */
-      __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_s, __pyx_v_self->name); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_4);
-      __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_4);
-      __pyx_t_4 = 0;
-      goto __pyx_L4;
-    }
-    __pyx_L4:;
-
-    /* "cutadapt/_seqio.pyx":92
- * 			if self.twoheaders:
- * 				s += self.name
- * 			s += '\n' + self.qualities + '\n'             # <<<<<<<<<<<<<<
- * 		else:
- * 			s = '>' + self.name + '\n' + self.sequence + '\n'
- */
-    __pyx_t_4 = PyNumber_Add(__pyx_kp_s__4, __pyx_v_self->qualities); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_kp_s__4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_4);
-    __pyx_t_4 = 0;
-    goto __pyx_L3;
-  }
-  /*else*/ {
-
-    /* "cutadapt/_seqio.pyx":94
- * 			s += '\n' + self.qualities + '\n'
- * 		else:
- * 			s = '>' + self.name + '\n' + self.sequence + '\n'             # <<<<<<<<<<<<<<
- * 		outfile.write(s)
- * 
- */
-    __pyx_t_4 = PyNumber_Add(__pyx_kp_s__6, __pyx_v_self->name); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_kp_s__4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_v_self->sequence); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_4);
-    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-    __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_kp_s__4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-    __pyx_v_s = __pyx_t_3;
-    __pyx_t_3 = 0;
-  }
-  __pyx_L3:;
-
-  /* "cutadapt/_seqio.pyx":95
- * 		else:
- * 			s = '>' + self.name + '\n' + self.sequence + '\n'
- * 		outfile.write(s)             # <<<<<<<<<<<<<<
- * 
- * 
- */
-  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_outfile, __pyx_n_s_write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_4);
-  __pyx_t_5 = NULL;
-  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
-    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
-    if (likely(__pyx_t_5)) {
-      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
-      __Pyx_INCREF(__pyx_t_5);
-      __Pyx_INCREF(function);
-      __Pyx_DECREF_SET(__pyx_t_4, function);
-    }
-  }
-  if (!__pyx_t_5) {
-    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_s); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-  } else {
-    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_6);
-    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
-    __Pyx_INCREF(__pyx_v_s);
-    __Pyx_GIVEREF(__pyx_v_s);
-    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_s);
-    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_3);
-    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-  }
-  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
-  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-
-  /* "cutadapt/_seqio.pyx":87
- * 		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))
- * 
- * 	def write(self, outfile):             # <<<<<<<<<<<<<<
- * 		if self.qualities is not None:
- * 			s = '@' + self.name + '\n' + self.sequence + '\n+'
- */
-
-  /* function exit code */
-  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_3);
-  __Pyx_XDECREF(__pyx_t_4);
-  __Pyx_XDECREF(__pyx_t_5);
-  __Pyx_XDECREF(__pyx_t_6);
-  __Pyx_AddTraceback("cutadapt._seqio.Sequence.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
-  __pyx_L0:;
-  __Pyx_XDECREF(__pyx_v_s);
-  __Pyx_XGIVEREF(__pyx_r);
-  __Pyx_RefNannyFinishContext();
-  return __pyx_r;
-}
-
 /* "cutadapt/_seqio.pyx":35
  * 	"""
  * 	cdef:
@@ -2749,7 +2506,7 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence_4name_4__del__(struct __pyx_obj_
  * 		public str name
  * 		public str sequence             # <<<<<<<<<<<<<<
  * 		public str qualities
- * 		public object match
+ * 		public str name2
  */
 
 /* Python wrapper */
@@ -2856,8 +2613,8 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence_8sequence_4__del__(struct __pyx_
  * 		public str name
  * 		public str sequence
  * 		public str qualities             # <<<<<<<<<<<<<<
+ * 		public str name2
  * 		public object match
- * 		public bint twoheaders
  */
 
 /* Python wrapper */
@@ -2963,31 +2720,31 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence_9qualities_4__del__(struct __pyx
 /* "cutadapt/_seqio.pyx":38
  * 		public str sequence
  * 		public str qualities
- * 		public object match             # <<<<<<<<<<<<<<
- * 		public bint twoheaders
+ * 		public str name2             # <<<<<<<<<<<<<<
+ * 		public object match
  * 
  */
 
 /* Python wrapper */
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_1__get__(PyObject *__pyx_v_self) {
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2___get__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5name2___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__get__", 0);
   __Pyx_XDECREF(__pyx_r);
-  __Pyx_INCREF(__pyx_v_self->match);
-  __pyx_r = __pyx_v_self->match;
+  __Pyx_INCREF(__pyx_v_self->name2);
+  __pyx_r = __pyx_v_self->name2;
   goto __pyx_L0;
 
   /* function exit code */
@@ -2998,56 +2755,69 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(struct __py
 }
 
 /* Python wrapper */
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), ((PyObject *)__pyx_v_value));
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_2__set__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), ((PyObject *)__pyx_v_value));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value) {
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
+  PyObject *__pyx_t_1 = NULL;
+  int __pyx_lineno = 0;
+  const char *__pyx_filename = NULL;
+  int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__set__", 0);
-  __Pyx_INCREF(__pyx_v_value);
-  __Pyx_GIVEREF(__pyx_v_value);
-  __Pyx_GOTREF(__pyx_v_self->match);
-  __Pyx_DECREF(__pyx_v_self->match);
-  __pyx_v_self->match = __pyx_v_value;
+  if (!(likely(PyString_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_v_value)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __pyx_v_value;
+  __Pyx_INCREF(__pyx_t_1);
+  __Pyx_GIVEREF(__pyx_t_1);
+  __Pyx_GOTREF(__pyx_v_self->name2);
+  __Pyx_DECREF(__pyx_v_self->name2);
+  __pyx_v_self->name2 = ((PyObject*)__pyx_t_1);
+  __pyx_t_1 = 0;
 
   /* function exit code */
   __pyx_r = 0;
+  goto __pyx_L0;
+  __pyx_L1_error:;
+  __Pyx_XDECREF(__pyx_t_1);
+  __Pyx_AddTraceback("cutadapt._seqio.Sequence.name2.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+  __pyx_r = -1;
+  __pyx_L0:;
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
 /* Python wrapper */
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(PyObject *__pyx_v_self); /*proto*/
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(PyObject *__pyx_v_self) {
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_5__del__(PyObject *__pyx_v_self); /*proto*/
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_5__del__(PyObject *__pyx_v_self) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_4__del__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5name2_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__del__", 0);
   __Pyx_INCREF(Py_None);
   __Pyx_GIVEREF(Py_None);
-  __Pyx_GOTREF(__pyx_v_self->match);
-  __Pyx_DECREF(__pyx_v_self->match);
-  __pyx_v_self->match = Py_None;
+  __Pyx_GOTREF(__pyx_v_self->name2);
+  __Pyx_DECREF(__pyx_v_self->name2);
+  __pyx_v_self->name2 = ((PyObject*)Py_None);
 
   /* function exit code */
   __pyx_r = 0;
@@ -3057,45 +2827,35 @@ static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(struct __pyx_obj
 
 /* "cutadapt/_seqio.pyx":39
  * 		public str qualities
- * 		public object match
- * 		public bint twoheaders             # <<<<<<<<<<<<<<
+ * 		public str name2
+ * 		public object match             # <<<<<<<<<<<<<<
  * 
- * 	def __init__(self, str name, str sequence, str qualities=None,
+ * 	def __init__(self, str name, str sequence, str qualities=None, str name2='',
  */
 
 /* Python wrapper */
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(PyObject *__pyx_v_self) {
   PyObject *__pyx_r = 0;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders___get__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
+static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_5match___get__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
   PyObject *__pyx_r = NULL;
   __Pyx_RefNannyDeclarations
-  PyObject *__pyx_t_1 = NULL;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__get__", 0);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->twoheaders); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_t_1);
-  __pyx_r = __pyx_t_1;
-  __pyx_t_1 = 0;
+  __Pyx_INCREF(__pyx_v_self->match);
+  __pyx_r = __pyx_v_self->match;
   goto __pyx_L0;
 
   /* function exit code */
-  __pyx_L1_error:;
-  __Pyx_XDECREF(__pyx_t_1);
-  __Pyx_AddTraceback("cutadapt._seqio.Sequence.twoheaders.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = NULL;
   __pyx_L0:;
   __Pyx_XGIVEREF(__pyx_r);
   __Pyx_RefNannyFinishContext();
@@ -3103,43 +2863,66 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders___get__(struc
 }
 
 /* Python wrapper */
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
-static int __pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
-  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders_2__set__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), ((PyObject *)__pyx_v_value));
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self), ((PyObject *)__pyx_v_value));
 
   /* function exit code */
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-static int __pyx_pf_8cutadapt_6_seqio_8Sequence_10twoheaders_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value) {
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_2__set__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self, PyObject *__pyx_v_value) {
   int __pyx_r;
   __Pyx_RefNannyDeclarations
-  int __pyx_t_1;
-  int __pyx_lineno = 0;
-  const char *__pyx_filename = NULL;
-  int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__set__", 0);
-  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_v_self->twoheaders = __pyx_t_1;
+  __Pyx_INCREF(__pyx_v_value);
+  __Pyx_GIVEREF(__pyx_v_value);
+  __Pyx_GOTREF(__pyx_v_self->match);
+  __Pyx_DECREF(__pyx_v_self->match);
+  __pyx_v_self->match = __pyx_v_value;
 
   /* function exit code */
   __pyx_r = 0;
-  goto __pyx_L0;
-  __pyx_L1_error:;
-  __Pyx_AddTraceback("cutadapt._seqio.Sequence.twoheaders.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
-  __pyx_r = -1;
-  __pyx_L0:;
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
 
-/* "cutadapt/_seqio.pyx":102
- * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
- * 	"""
+/* Python wrapper */
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(PyObject *__pyx_v_self); /*proto*/
+static int __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(PyObject *__pyx_v_self) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
+  __pyx_r = __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(((struct __pyx_obj_8cutadapt_6_seqio_Sequence *)__pyx_v_self));
+
+  /* function exit code */
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+static int __pyx_pf_8cutadapt_6_seqio_8Sequence_5match_4__del__(struct __pyx_obj_8cutadapt_6_seqio_Sequence *__pyx_v_self) {
+  int __pyx_r;
+  __Pyx_RefNannyDeclarations
+  __Pyx_RefNannySetupContext("__del__", 0);
+  __Pyx_INCREF(Py_None);
+  __Pyx_GIVEREF(Py_None);
+  __Pyx_GOTREF(__pyx_v_self->match);
+  __Pyx_DECREF(__pyx_v_self->match);
+  __pyx_v_self->match = Py_None;
+
+  /* function exit code */
+  __pyx_r = 0;
+  __Pyx_RefNannyFinishContext();
+  return __pyx_r;
+}
+
+/* "cutadapt/_seqio.pyx":94
+ * 	_close_on_exit = False
+ * 
  * 	def __init__(self, file, sequence_class=Sequence):             # <<<<<<<<<<<<<<
  * 		"""
  * 		file is a filename or a file-like object.
@@ -3155,12 +2938,12 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_11__defaults__(CYTHON_
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__defaults__", 0);
   __Pyx_XDECREF(__pyx_r);
-  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_INCREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_sequence_class);
   __Pyx_GIVEREF(__Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_sequence_class);
   PyTuple_SET_ITEM(__pyx_t_1, 0, __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_self)->__pyx_arg_sequence_class);
-  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_1);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
@@ -3186,7 +2969,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_11__defaults__(CYTHON_
 
 /* Python wrapper */
 static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_8cutadapt_6_seqio_11FastqReader___init__[] = "\n\t\tfile is a filename or a file-like object.\n\t\tIf file is a filename, then .gz files are supported.\n\n\t\tcolorspace -- Usually (when this is False), there must be n characters in the sequence and\n\t\tn quality values. When this is True, there must be n+1 characters in the sequence and n quality values.\n\t\t";
+static char __pyx_doc_8cutadapt_6_seqio_11FastqReader___init__[] = "\n\t\tfile is a filename or a file-like object.\n\t\tIf file is a filename, then .gz files are supported.\n\t\t";
 static PyMethodDef __pyx_mdef_8cutadapt_6_seqio_11FastqReader_1__init__ = {"__init__", (PyCFunction)__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8cutadapt_6_seqio_11FastqReader___init__};
 static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_self = 0;
@@ -3221,7 +3004,7 @@ static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__(PyObject *__
         case  1:
         if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_file)) != 0)) kw_args--;
         else {
-          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
         }
         case  2:
         if (kw_args > 0) {
@@ -3230,7 +3013,7 @@ static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__(PyObject *__
         }
       }
       if (unlikely(kw_args > 0)) {
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else {
       switch (PyTuple_GET_SIZE(__pyx_args)) {
@@ -3247,7 +3030,7 @@ static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_1__init__(PyObject *__
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_AddTraceback("cutadapt._seqio.FastqReader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __Pyx_RefNannyFinishContext();
@@ -3275,25 +3058,25 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED
   __Pyx_RefNannySetupContext("__init__", 0);
   __Pyx_INCREF(__pyx_v_file);
 
-  /* "cutadapt/_seqio.pyx":110
- * 		n quality values. When this is True, there must be n+1 characters in the sequence and n quality values.
+  /* "cutadapt/_seqio.pyx":99
+ * 		If file is a filename, then .gz files are supported.
  * 		"""
  * 		if isinstance(file, basestring):             # <<<<<<<<<<<<<<
  * 			file = xopen(file)
- * 			self._file_passed = False
+ * 			self._close_on_exit = True
  */
   __pyx_t_1 = __Pyx_PyBaseString_Check(__pyx_v_file); 
   __pyx_t_2 = (__pyx_t_1 != 0);
   if (__pyx_t_2) {
 
-    /* "cutadapt/_seqio.pyx":111
+    /* "cutadapt/_seqio.pyx":100
  * 		"""
  * 		if isinstance(file, basestring):
  * 			file = xopen(file)             # <<<<<<<<<<<<<<
- * 			self._file_passed = False
- * 		else:
+ * 			self._close_on_exit = True
+ * 		self._file = file
  */
-    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_xopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_xopen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_4);
     __pyx_t_5 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
@@ -3306,16 +3089,16 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED
       }
     }
     if (!__pyx_t_5) {
-      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_file); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_file); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
     } else {
-      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_6);
       __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
       __Pyx_INCREF(__pyx_v_file);
       __Pyx_GIVEREF(__pyx_v_file);
       PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_file);
-      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_3);
       __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     }
@@ -3323,59 +3106,54 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED
     __Pyx_DECREF_SET(__pyx_v_file, __pyx_t_3);
     __pyx_t_3 = 0;
 
-    /* "cutadapt/_seqio.pyx":112
+    /* "cutadapt/_seqio.pyx":101
  * 		if isinstance(file, basestring):
  * 			file = xopen(file)
- * 			self._file_passed = False             # <<<<<<<<<<<<<<
- * 		else:
- * 			self._file_passed = True
+ * 			self._close_on_exit = True             # <<<<<<<<<<<<<<
+ * 		self._file = file
+ * 		self.sequence_class = sequence_class
  */
-    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_file_passed, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
-  }
-  /*else*/ {
+    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_close_on_exit, Py_True) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-    /* "cutadapt/_seqio.pyx":114
- * 			self._file_passed = False
- * 		else:
- * 			self._file_passed = True             # <<<<<<<<<<<<<<
- * 		self.fp = file
- * 		self.sequence_class = sequence_class
+    /* "cutadapt/_seqio.pyx":99
+ * 		If file is a filename, then .gz files are supported.
+ * 		"""
+ * 		if isinstance(file, basestring):             # <<<<<<<<<<<<<<
+ * 			file = xopen(file)
+ * 			self._close_on_exit = True
  */
-    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_file_passed, Py_True) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
-  __pyx_L3:;
 
-  /* "cutadapt/_seqio.pyx":115
- * 		else:
- * 			self._file_passed = True
- * 		self.fp = file             # <<<<<<<<<<<<<<
+  /* "cutadapt/_seqio.pyx":102
+ * 			file = xopen(file)
+ * 			self._close_on_exit = True
+ * 		self._file = file             # <<<<<<<<<<<<<<
  * 		self.sequence_class = sequence_class
  * 		self.delivers_qualities = True
  */
-  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fp, __pyx_v_file) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_file_2, __pyx_v_file) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":116
- * 			self._file_passed = True
- * 		self.fp = file
+  /* "cutadapt/_seqio.pyx":103
+ * 			self._close_on_exit = True
+ * 		self._file = file
  * 		self.sequence_class = sequence_class             # <<<<<<<<<<<<<<
  * 		self.delivers_qualities = True
  * 
  */
-  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_sequence_class, __pyx_v_sequence_class) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_sequence_class, __pyx_v_sequence_class) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":117
- * 		self.fp = file
+  /* "cutadapt/_seqio.pyx":104
+ * 		self._file = file
  * 		self.sequence_class = sequence_class
  * 		self.delivers_qualities = True             # <<<<<<<<<<<<<<
  * 
  * 	def __iter__(self):
  */
-  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_delivers_qualities, Py_True) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_delivers_qualities, Py_True) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":102
- * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
- * 	"""
+  /* "cutadapt/_seqio.pyx":94
+ * 	_close_on_exit = False
+ * 
  * 	def __init__(self, file, sequence_class=Sequence):             # <<<<<<<<<<<<<<
  * 		"""
  * 		file is a filename or a file-like object.
@@ -3397,19 +3175,19 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader___init__(CYTHON_UNUSED
   __Pyx_RefNannyFinishContext();
   return __pyx_r;
 }
-static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
 
-/* "cutadapt/_seqio.pyx":119
+/* "cutadapt/_seqio.pyx":106
  * 		self.delivers_qualities = True
  * 
  * 	def __iter__(self):             # <<<<<<<<<<<<<<
  * 		"""
- * 		Return tuples: (name, sequence, qualities).
+ * 		Yield Sequence objects
  */
 
 /* Python wrapper */
 static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_3__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
-static char __pyx_doc_8cutadapt_6_seqio_11FastqReader_2__iter__[] = "\n\t\tReturn tuples: (name, sequence, qualities).\n\t\tqualities is a string and it contains the unmodified, encoded qualities.\n\t\t";
+static char __pyx_doc_8cutadapt_6_seqio_11FastqReader_2__iter__[] = "\n\t\tYield Sequence objects\n\t\t";
 static PyMethodDef __pyx_mdef_8cutadapt_6_seqio_11FastqReader_3__iter__ = {"__iter__", (PyCFunction)__pyx_pw_8cutadapt_6_seqio_11FastqReader_3__iter__, METH_O, __pyx_doc_8cutadapt_6_seqio_11FastqReader_2__iter__};
 static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_3__iter__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
   PyObject *__pyx_r = 0;
@@ -3440,7 +3218,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_2__iter__(CYTHON_UNUSE
   __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self);
   __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self);
   {
-    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_FastqReader___iter); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_FastqReader___iter); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_cur_scope);
     __Pyx_RefNannyFinishContext();
     return (PyObject *) gen;
@@ -3456,7 +3234,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_2__iter__(CYTHON_UNUSE
   return __pyx_r;
 }
 
-static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
+static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
 {
   struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ *__pyx_cur_scope = ((struct __pyx_obj_8cutadapt_6_seqio___pyx_scope_struct____iter__ *)__pyx_generator->closure);
   PyObject *__pyx_r = NULL;
@@ -3469,10 +3247,10 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
   PyObject *__pyx_t_7 = NULL;
   PyObject *__pyx_t_8 = NULL;
   PyObject *__pyx_t_9 = NULL;
-  int __pyx_t_10;
-  Py_ssize_t __pyx_t_11;
-  PyObject *(*__pyx_t_12)(PyObject *);
-  PyObject *__pyx_t_13 = NULL;
+  Py_ssize_t __pyx_t_10;
+  PyObject *__pyx_t_11 = NULL;
+  int __pyx_t_12;
+  PyObject *(*__pyx_t_13)(PyObject *);
   Py_ssize_t __pyx_t_14;
   PyObject *__pyx_t_15 = NULL;
   Py_ssize_t __pyx_t_16;
@@ -3489,120 +3267,127 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
     return NULL;
   }
   __pyx_L3_first_run:;
-  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":124
- * 		qualities is a string and it contains the unmodified, encoded qualities.
+  /* "cutadapt/_seqio.pyx":110
+ * 		Yield Sequence objects
  * 		"""
  * 		cdef int i = 0             # <<<<<<<<<<<<<<
  * 		cdef int strip
- * 		cdef str line, name, qualities, sequence
+ * 		cdef str line, name, qualities, sequence, name2
  */
   __pyx_cur_scope->__pyx_v_i = 0;
 
-  /* "cutadapt/_seqio.pyx":128
- * 		cdef str line, name, qualities, sequence
- * 		cdef bint twoheaders
+  /* "cutadapt/_seqio.pyx":113
+ * 		cdef int strip
+ * 		cdef str line, name, qualities, sequence, name2
  * 		sequence_class = self.sequence_class             # <<<<<<<<<<<<<<
  * 
- * 		it = iter(self.fp)
+ * 		it = iter(self._file)
  */
-  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_sequence_class); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_sequence_class); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_GIVEREF(__pyx_t_1);
   __pyx_cur_scope->__pyx_v_sequence_class = __pyx_t_1;
   __pyx_t_1 = 0;
 
-  /* "cutadapt/_seqio.pyx":130
+  /* "cutadapt/_seqio.pyx":115
  * 		sequence_class = self.sequence_class
  * 
- * 		it = iter(self.fp)             # <<<<<<<<<<<<<<
+ * 		it = iter(self._file)             # <<<<<<<<<<<<<<
  * 		line = next(it)
  * 		if not (line and line[0] == '@'):
  */
-  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_fp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_file_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __Pyx_GIVEREF(__pyx_t_2);
   __pyx_cur_scope->__pyx_v_it = __pyx_t_2;
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_seqio.pyx":131
+  /* "cutadapt/_seqio.pyx":116
  * 
- * 		it = iter(self.fp)
+ * 		it = iter(self._file)
  * 		line = next(it)             # <<<<<<<<<<<<<<
  * 		if not (line and line[0] == '@'):
- * 			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  */
-  __pyx_t_2 = __Pyx_PyIter_Next(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyIter_Next(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GIVEREF(__pyx_t_2);
   __pyx_cur_scope->__pyx_v_line = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_seqio.pyx":132
- * 		it = iter(self.fp)
+  /* "cutadapt/_seqio.pyx":117
+ * 		it = iter(self._file)
  * 		line = next(it)
  * 		if not (line and line[0] == '@'):             # <<<<<<<<<<<<<<
- * 			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 		strip = -2 if line.endswith('\r\n') else -1
  */
-  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if (__pyx_t_4) {
   } else {
     __pyx_t_3 = __pyx_t_4;
     goto __pyx_L5_bool_binop_done;
   }
-  __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+  __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __pyx_t_3 = __pyx_t_4;
   __pyx_L5_bool_binop_done:;
   __pyx_t_4 = ((!__pyx_t_3) != 0);
   if (__pyx_t_4) {
 
-    /* "cutadapt/_seqio.pyx":133
+    /* "cutadapt/_seqio.pyx":118
  * 		line = next(it)
  * 		if not (line and line[0] == '@'):
- * 			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))             # <<<<<<<<<<<<<<
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))             # <<<<<<<<<<<<<<
  * 		strip = -2 if line.endswith('\r\n') else -1
  * 		name = line[1:strip]
  */
-    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
-    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_at_line_0_expected_a_line_starti, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Line_0_in_FASTQ_file_is_expected, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
-    __pyx_t_7 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_7 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_7);
-    __pyx_t_8 = NULL;
+    if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
+      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    }
+    __pyx_t_8 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, 10); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_8);
+    __pyx_t_9 = NULL;
+    __pyx_t_10 = 0;
     if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
-      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
-      if (likely(__pyx_t_8)) {
+      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
+      if (likely(__pyx_t_9)) {
         PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
-        __Pyx_INCREF(__pyx_t_8);
+        __Pyx_INCREF(__pyx_t_9);
         __Pyx_INCREF(function);
         __Pyx_DECREF_SET(__pyx_t_6, function);
+        __pyx_t_10 = 1;
       }
     }
-    if (!__pyx_t_8) {
-      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-      __Pyx_GOTREF(__pyx_t_5);
-    } else {
-      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_9);
-      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
-      __Pyx_GIVEREF(__pyx_t_7);
-      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
-      __pyx_t_7 = 0;
-      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_5);
-      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
-    }
+    __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_11);
+    if (__pyx_t_9) {
+      __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
+    }
+    __Pyx_GIVEREF(__pyx_t_7);
+    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_t_7);
+    __Pyx_GIVEREF(__pyx_t_8);
+    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_t_8);
+    __pyx_t_7 = 0;
+    __pyx_t_8 = 0;
+    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_5);
+    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __pyx_t_6 = NULL;
     if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
@@ -3615,47 +3400,55 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
       }
     }
     if (!__pyx_t_6) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
       __Pyx_GOTREF(__pyx_t_2);
     } else {
-      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_9);
-      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
+      __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_11);
+      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_6); __pyx_t_6 = NULL;
       __Pyx_GIVEREF(__pyx_t_5);
-      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_5);
+      PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_5);
       __pyx_t_5 = 0;
-      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_2);
-      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
     }
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     __Pyx_Raise(__pyx_t_2, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_seqio.pyx":117
+ * 		it = iter(self._file)
+ * 		line = next(it)
+ * 		if not (line and line[0] == '@'):             # <<<<<<<<<<<<<<
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
+ * 		strip = -2 if line.endswith('\r\n') else -1
+ */
   }
 
-  /* "cutadapt/_seqio.pyx":134
+  /* "cutadapt/_seqio.pyx":119
  * 		if not (line and line[0] == '@'):
- * 			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 		strip = -2 if line.endswith('\r\n') else -1             # <<<<<<<<<<<<<<
  * 		name = line[1:strip]
  * 
  */
   if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
     PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "endswith");
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
-  __pyx_t_4 = __Pyx_PyStr_Tailmatch(__pyx_cur_scope->__pyx_v_line, __pyx_kp_s__7, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_PyStr_Tailmatch(__pyx_cur_scope->__pyx_v_line, __pyx_kp_s__4, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   if ((__pyx_t_4 != 0)) {
-    __pyx_t_10 = -2;
+    __pyx_t_12 = -2;
   } else {
-    __pyx_t_10 = -1;
+    __pyx_t_12 = -1;
   }
-  __pyx_cur_scope->__pyx_v_strip = __pyx_t_10;
+  __pyx_cur_scope->__pyx_v_strip = __pyx_t_12;
 
-  /* "cutadapt/_seqio.pyx":135
- * 			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+  /* "cutadapt/_seqio.pyx":120
+ * 			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 		strip = -2 if line.endswith('\r\n') else -1
  * 		name = line[1:strip]             # <<<<<<<<<<<<<<
  * 
@@ -3663,15 +3456,15 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  */
   if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
     PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
-  __pyx_t_2 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_GIVEREF(__pyx_t_2);
   __pyx_cur_scope->__pyx_v_name = ((PyObject*)__pyx_t_2);
   __pyx_t_2 = 0;
 
-  /* "cutadapt/_seqio.pyx":137
+  /* "cutadapt/_seqio.pyx":122
  * 		name = line[1:strip]
  * 
  * 		i = 1             # <<<<<<<<<<<<<<
@@ -3680,7 +3473,7 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  */
   __pyx_cur_scope->__pyx_v_i = 1;
 
-  /* "cutadapt/_seqio.pyx":138
+  /* "cutadapt/_seqio.pyx":123
  * 
  * 		i = 1
  * 		for line in it:             # <<<<<<<<<<<<<<
@@ -3688,181 +3481,196 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  * 				if not (line and line[0] == '@'):
  */
   if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_it)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_it)) {
-    __pyx_t_2 = __pyx_cur_scope->__pyx_v_it; __Pyx_INCREF(__pyx_t_2); __pyx_t_11 = 0;
-    __pyx_t_12 = NULL;
+    __pyx_t_2 = __pyx_cur_scope->__pyx_v_it; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0;
+    __pyx_t_13 = NULL;
   } else {
-    __pyx_t_11 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_12 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_13 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   for (;;) {
-    if (likely(!__pyx_t_12)) {
+    if (likely(!__pyx_t_13)) {
       if (likely(PyList_CheckExact(__pyx_t_2))) {
-        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_2)) break;
+        if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_1); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         #endif
       } else {
-        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+        if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
         #if CYTHON_COMPILING_IN_CPYTHON
-        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_1); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         #else
-        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         #endif
       }
     } else {
-      __pyx_t_1 = __pyx_t_12(__pyx_t_2);
+      __pyx_t_1 = __pyx_t_13(__pyx_t_2);
       if (unlikely(!__pyx_t_1)) {
         PyObject* exc_type = PyErr_Occurred();
         if (exc_type) {
           if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
-          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
         break;
       }
       __Pyx_GOTREF(__pyx_t_1);
     }
-    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_line);
     __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_line, ((PyObject*)__pyx_t_1));
     __Pyx_GIVEREF(__pyx_t_1);
     __pyx_t_1 = 0;
 
-    /* "cutadapt/_seqio.pyx":163
- * 					else:
- * 						twoheaders = False
- * 			elif i == 3:             # <<<<<<<<<<<<<<
- * 				if len(line) == len(sequence) - strip:
- * 					qualities = line[:strip]
- */
-    switch (__pyx_cur_scope->__pyx_v_i) {
-
-      /* "cutadapt/_seqio.pyx":139
+    /* "cutadapt/_seqio.pyx":124
  * 		i = 1
  * 		for line in it:
  * 			if i == 0:             # <<<<<<<<<<<<<<
  * 				if not (line and line[0] == '@'):
- * 					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  */
+    switch (__pyx_cur_scope->__pyx_v_i) {
       case 0:
 
-      /* "cutadapt/_seqio.pyx":140
+      /* "cutadapt/_seqio.pyx":125
  * 		for line in it:
  * 			if i == 0:
  * 				if not (line and line[0] == '@'):             # <<<<<<<<<<<<<<
- * 					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 				name = line[1:strip]
  */
-      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       if (__pyx_t_3) {
       } else {
         __pyx_t_4 = __pyx_t_3;
         goto __pyx_L10_bool_binop_done;
       }
-      __pyx_t_1 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+      __pyx_t_1 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s__3, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_t_4 = __pyx_t_3;
       __pyx_L10_bool_binop_done:;
       __pyx_t_3 = ((!__pyx_t_4) != 0);
       if (__pyx_t_3) {
 
-        /* "cutadapt/_seqio.pyx":141
+        /* "cutadapt/_seqio.pyx":126
  * 			if i == 0:
  * 				if not (line and line[0] == '@'):
- * 					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))             # <<<<<<<<<<<<<<
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))             # <<<<<<<<<<<<<<
  * 				name = line[1:strip]
  * 			elif i == 1:
  */
-        __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_9);
-        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_at_line_0_expected_a_line_starti, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_11);
+        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Line_0_in_FASTQ_file_is_expected, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_6);
-        __pyx_t_7 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_8);
+        if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
+          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        }
+        __pyx_t_7 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, 10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_7);
-        __pyx_t_8 = NULL;
+        __pyx_t_9 = NULL;
+        __pyx_t_14 = 0;
         if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
-          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
-          if (likely(__pyx_t_8)) {
+          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
+          if (likely(__pyx_t_9)) {
             PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
-            __Pyx_INCREF(__pyx_t_8);
+            __Pyx_INCREF(__pyx_t_9);
             __Pyx_INCREF(function);
             __Pyx_DECREF_SET(__pyx_t_6, function);
+            __pyx_t_14 = 1;
           }
         }
-        if (!__pyx_t_8) {
-          __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-          __Pyx_GOTREF(__pyx_t_5);
-        } else {
-          __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(__pyx_t_13);
-          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_8); __pyx_t_8 = NULL;
-          __Pyx_GIVEREF(__pyx_t_7);
-          PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_7);
-          __pyx_t_7 = 0;
-          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_13, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(__pyx_t_5);
-          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+        __pyx_t_15 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_15);
+        if (__pyx_t_9) {
+          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); __pyx_t_9 = NULL;
         }
+        __Pyx_GIVEREF(__pyx_t_8);
+        PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_14, __pyx_t_8);
+        __Pyx_GIVEREF(__pyx_t_7);
+        PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_14, __pyx_t_7);
+        __pyx_t_8 = 0;
+        __pyx_t_7 = 0;
+        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_15, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_5);
+        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
         __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
         __pyx_t_6 = NULL;
-        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
-          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
+        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
+          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
           if (likely(__pyx_t_6)) {
-            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
             __Pyx_INCREF(__pyx_t_6);
             __Pyx_INCREF(function);
-            __Pyx_DECREF_SET(__pyx_t_9, function);
+            __Pyx_DECREF_SET(__pyx_t_11, function);
           }
         }
         if (!__pyx_t_6) {
-          __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
           __Pyx_GOTREF(__pyx_t_1);
         } else {
-          __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(__pyx_t_13);
-          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_6); __pyx_t_6 = NULL;
+          __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_15);
+          __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_6); __pyx_t_6 = NULL;
           __Pyx_GIVEREF(__pyx_t_5);
-          PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_5);
+          PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_5);
           __pyx_t_5 = 0;
-          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
-          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
         }
-        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
         __Pyx_Raise(__pyx_t_1, 0, 0, 0);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+        /* "cutadapt/_seqio.pyx":125
+ * 		for line in it:
+ * 			if i == 0:
+ * 				if not (line and line[0] == '@'):             # <<<<<<<<<<<<<<
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
+ * 				name = line[1:strip]
+ */
       }
 
-      /* "cutadapt/_seqio.pyx":142
+      /* "cutadapt/_seqio.pyx":127
  * 				if not (line and line[0] == '@'):
- * 					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 				name = line[1:strip]             # <<<<<<<<<<<<<<
  * 			elif i == 1:
  * 				sequence = line[:strip]
  */
       if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
         PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
-      __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_name);
       __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_name, ((PyObject*)__pyx_t_1));
       __Pyx_GIVEREF(__pyx_t_1);
       __pyx_t_1 = 0;
+
+      /* "cutadapt/_seqio.pyx":124
+ * 		i = 1
+ * 		for line in it:
+ * 			if i == 0:             # <<<<<<<<<<<<<<
+ * 				if not (line and line[0] == '@'):
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
+ */
       break;
 
-      /* "cutadapt/_seqio.pyx":143
- * 					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+      /* "cutadapt/_seqio.pyx":128
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
  * 				name = line[1:strip]
  * 			elif i == 1:             # <<<<<<<<<<<<<<
  * 				sequence = line[:strip]
@@ -3870,7 +3678,7 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  */
       case 1:
 
-      /* "cutadapt/_seqio.pyx":144
+      /* "cutadapt/_seqio.pyx":129
  * 				name = line[1:strip]
  * 			elif i == 1:
  * 				sequence = line[:strip]             # <<<<<<<<<<<<<<
@@ -3879,324 +3687,384 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  */
       if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
         PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
-        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       }
-      __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_sequence);
       __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_sequence, ((PyObject*)__pyx_t_1));
       __Pyx_GIVEREF(__pyx_t_1);
       __pyx_t_1 = 0;
+
+      /* "cutadapt/_seqio.pyx":128
+ * 					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
+ * 				name = line[1:strip]
+ * 			elif i == 1:             # <<<<<<<<<<<<<<
+ * 				sequence = line[:strip]
+ * 			elif i == 2:
+ */
       break;
 
-      /* "cutadapt/_seqio.pyx":145
+      /* "cutadapt/_seqio.pyx":130
  * 			elif i == 1:
  * 				sequence = line[:strip]
  * 			elif i == 2:             # <<<<<<<<<<<<<<
  * 				if line == '+\n':  # check most common case first
- * 					twoheaders = False
+ * 					name2 = ''
  */
       case 2:
 
-      /* "cutadapt/_seqio.pyx":146
+      /* "cutadapt/_seqio.pyx":131
  * 				sequence = line[:strip]
  * 			elif i == 2:
  * 				if line == '+\n':  # check most common case first             # <<<<<<<<<<<<<<
- * 					twoheaders = False
+ * 					name2 = ''
  * 				else:
  */
-      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_cur_scope->__pyx_v_line, __pyx_kp_s__8, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_cur_scope->__pyx_v_line, __pyx_kp_s__5, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_4 = (__pyx_t_3 != 0);
       if (__pyx_t_4) {
 
-        /* "cutadapt/_seqio.pyx":147
+        /* "cutadapt/_seqio.pyx":132
  * 			elif i == 2:
  * 				if line == '+\n':  # check most common case first
- * 					twoheaders = False             # <<<<<<<<<<<<<<
+ * 					name2 = ''             # <<<<<<<<<<<<<<
  * 				else:
  * 					line = line[:strip]
  */
-        __pyx_cur_scope->__pyx_v_twoheaders = 0;
+        __Pyx_INCREF(__pyx_kp_s__2);
+        __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name2);
+        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_name2, __pyx_kp_s__2);
+        __Pyx_GIVEREF(__pyx_kp_s__2);
+
+        /* "cutadapt/_seqio.pyx":131
+ * 				sequence = line[:strip]
+ * 			elif i == 2:
+ * 				if line == '+\n':  # check most common case first             # <<<<<<<<<<<<<<
+ * 					name2 = ''
+ * 				else:
+ */
         goto __pyx_L12;
       }
-      /*else*/ {
 
-        /* "cutadapt/_seqio.pyx":149
- * 					twoheaders = False
+      /* "cutadapt/_seqio.pyx":134
+ * 					name2 = ''
  * 				else:
  * 					line = line[:strip]             # <<<<<<<<<<<<<<
  * 					if not (line and line[0] == '+'):
- * 						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
  */
+      /*else*/ {
         if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
-        __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_line);
         __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_line, ((PyObject*)__pyx_t_1));
         __Pyx_GIVEREF(__pyx_t_1);
         __pyx_t_1 = 0;
 
-        /* "cutadapt/_seqio.pyx":150
+        /* "cutadapt/_seqio.pyx":135
  * 				else:
  * 					line = line[:strip]
  * 					if not (line and line[0] == '+'):             # <<<<<<<<<<<<<<
- * 						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
  * 					if len(line) > 1:
  */
-        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         if (__pyx_t_3) {
         } else {
           __pyx_t_4 = __pyx_t_3;
           goto __pyx_L14_bool_binop_done;
         }
-        __pyx_t_1 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+        __pyx_t_1 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_line, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s__9, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s__6, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __pyx_t_4 = __pyx_t_3;
         __pyx_L14_bool_binop_done:;
         __pyx_t_3 = ((!__pyx_t_4) != 0);
         if (__pyx_t_3) {
 
-          /* "cutadapt/_seqio.pyx":151
+          /* "cutadapt/_seqio.pyx":136
  * 					line = line[:strip]
  * 					if not (line and line[0] == '+'):
- * 						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))             # <<<<<<<<<<<<<<
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))             # <<<<<<<<<<<<<<
  * 					if len(line) > 1:
- * 						twoheaders = True
+ * 						if not line[1:] == name:
  */
-          __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-          __Pyx_GOTREF(__pyx_t_9);
-          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_at_line_0_expected_a_line_starti_2, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_11);
+          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_Line_0_in_FASTQ_file_is_expected_2, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_5);
-          __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_6);
-          __pyx_t_7 = NULL;
+          __pyx_t_7 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, 10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_7);
+          __pyx_t_8 = NULL;
+          __pyx_t_14 = 0;
           if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
-            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
-            if (likely(__pyx_t_7)) {
+            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
+            if (likely(__pyx_t_8)) {
               PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
-              __Pyx_INCREF(__pyx_t_7);
+              __Pyx_INCREF(__pyx_t_8);
               __Pyx_INCREF(function);
               __Pyx_DECREF_SET(__pyx_t_5, function);
+              __pyx_t_14 = 1;
             }
           }
-          if (!__pyx_t_7) {
-            __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
-            __Pyx_GOTREF(__pyx_t_13);
-          } else {
-            __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_8);
-            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
-            __Pyx_GIVEREF(__pyx_t_6);
-            PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6);
-            __pyx_t_6 = 0;
-            __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_13);
-            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+          __pyx_t_9 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_9);
+          if (__pyx_t_8) {
+            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
           }
+          __Pyx_GIVEREF(__pyx_t_6);
+          PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_14, __pyx_t_6);
+          __Pyx_GIVEREF(__pyx_t_7);
+          PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_14, __pyx_t_7);
+          __pyx_t_6 = 0;
+          __pyx_t_7 = 0;
+          __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __Pyx_GOTREF(__pyx_t_15);
+          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
           __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
           __pyx_t_5 = NULL;
-          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
-            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
+          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
+            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_11);
             if (likely(__pyx_t_5)) {
-              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
+              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
               __Pyx_INCREF(__pyx_t_5);
               __Pyx_INCREF(function);
-              __Pyx_DECREF_SET(__pyx_t_9, function);
+              __Pyx_DECREF_SET(__pyx_t_11, function);
             }
           }
           if (!__pyx_t_5) {
-            __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
+            __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
             __Pyx_GOTREF(__pyx_t_1);
           } else {
-            __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_8);
-            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
-            __Pyx_GIVEREF(__pyx_t_13);
-            PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_13);
-            __pyx_t_13 = 0;
-            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_9);
+            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
+            __Pyx_GIVEREF(__pyx_t_15);
+            PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_15);
+            __pyx_t_15 = 0;
+            __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_1);
-            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
           }
-          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
           __Pyx_Raise(__pyx_t_1, 0, 0, 0);
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+          /* "cutadapt/_seqio.pyx":135
+ * 				else:
+ * 					line = line[:strip]
+ * 					if not (line and line[0] == '+'):             # <<<<<<<<<<<<<<
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
+ * 					if len(line) > 1:
+ */
         }
 
-        /* "cutadapt/_seqio.pyx":152
+        /* "cutadapt/_seqio.pyx":137
  * 					if not (line and line[0] == '+'):
- * 						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
  * 					if len(line) > 1:             # <<<<<<<<<<<<<<
- * 						twoheaders = True
  * 						if not line[1:] == name:
+ * 							raise FormatError(
  */
-        __pyx_t_14 = PyObject_Length(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_14 = PyObject_Length(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __pyx_t_3 = ((__pyx_t_14 > 1) != 0);
         if (__pyx_t_3) {
 
-          /* "cutadapt/_seqio.pyx":153
- * 						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))
- * 					if len(line) > 1:
- * 						twoheaders = True             # <<<<<<<<<<<<<<
- * 						if not line[1:] == name:
- * 							raise FormatError(
- */
-          __pyx_cur_scope->__pyx_v_twoheaders = 1;
-
-          /* "cutadapt/_seqio.pyx":154
+          /* "cutadapt/_seqio.pyx":138
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
  * 					if len(line) > 1:
- * 						twoheaders = True
  * 						if not line[1:] == name:             # <<<<<<<<<<<<<<
  * 							raise FormatError(
  * 								"At line {0}: Sequence descriptions in the FASTQ file don't match "
  */
-          __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_GOTREF(__pyx_t_1);
-          __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_cur_scope->__pyx_v_name, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_cur_scope->__pyx_v_name, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
           __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
           __pyx_t_4 = ((!(__pyx_t_3 != 0)) != 0);
           if (__pyx_t_4) {
 
-            /* "cutadapt/_seqio.pyx":155
- * 						twoheaders = True
+            /* "cutadapt/_seqio.pyx":139
+ * 					if len(line) > 1:
  * 						if not line[1:] == name:
  * 							raise FormatError(             # <<<<<<<<<<<<<<
  * 								"At line {0}: Sequence descriptions in the FASTQ file don't match "
  * 								"({1!r} != {2!r}).\n"
  */
-            __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_9);
+            __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_11);
 
-            /* "cutadapt/_seqio.pyx":159
+            /* "cutadapt/_seqio.pyx":143
  * 								"({1!r} != {2!r}).\n"
  * 								"The second sequence description must be either empty "
  * 								"or equal to the first description.".format(i+1,             # <<<<<<<<<<<<<<
  * 									name, line[1:]))
- * 					else:
+ * 						name2 = name
  */
-            __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_At_line_0_Sequence_descriptions, __pyx_n_s_format); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_13);
-            __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_kp_s_At_line_0_Sequence_descriptions, __pyx_n_s_format); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_15);
+            __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_i + 1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
             __Pyx_GOTREF(__pyx_t_5);
 
-            /* "cutadapt/_seqio.pyx":160
+            /* "cutadapt/_seqio.pyx":144
  * 								"The second sequence description must be either empty "
  * 								"or equal to the first description.".format(i+1,
  * 									name, line[1:]))             # <<<<<<<<<<<<<<
+ * 						name2 = name
  * 					else:
- * 						twoheaders = False
  */
-            __pyx_t_6 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_6);
-            __pyx_t_7 = NULL;
+            __pyx_t_7 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_7);
+            __pyx_t_6 = NULL;
             __pyx_t_14 = 0;
-            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_13))) {
-              __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_13);
-              if (likely(__pyx_t_7)) {
-                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
-                __Pyx_INCREF(__pyx_t_7);
+            if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_15))) {
+              __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_15);
+              if (likely(__pyx_t_6)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
+                __Pyx_INCREF(__pyx_t_6);
                 __Pyx_INCREF(function);
-                __Pyx_DECREF_SET(__pyx_t_13, function);
+                __Pyx_DECREF_SET(__pyx_t_15, function);
                 __pyx_t_14 = 1;
               }
             }
-            __pyx_t_15 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_15);
-            if (__pyx_t_7) {
-              __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_7); __pyx_t_7 = NULL;
+            __pyx_t_8 = PyTuple_New(3+__pyx_t_14); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_8);
+            if (__pyx_t_6) {
+              __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
             }
             __Pyx_GIVEREF(__pyx_t_5);
-            PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_14, __pyx_t_5);
+            PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_14, __pyx_t_5);
             __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name);
             __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name);
-            PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_14, __pyx_cur_scope->__pyx_v_name);
-            __Pyx_GIVEREF(__pyx_t_6);
-            PyTuple_SET_ITEM(__pyx_t_15, 2+__pyx_t_14, __pyx_t_6);
+            PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_14, __pyx_cur_scope->__pyx_v_name);
+            __Pyx_GIVEREF(__pyx_t_7);
+            PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_14, __pyx_t_7);
             __pyx_t_5 = 0;
-            __pyx_t_6 = 0;
-            __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_15, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-            __Pyx_GOTREF(__pyx_t_8);
+            __pyx_t_7 = 0;
+            __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            __Pyx_GOTREF(__pyx_t_9);
+            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
             __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
-            __pyx_t_13 = NULL;
-            if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
-              __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_9);
-              if (likely(__pyx_t_13)) {
-                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
-                __Pyx_INCREF(__pyx_t_13);
+            __pyx_t_15 = NULL;
+            if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) {
+              __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_11);
+              if (likely(__pyx_t_15)) {
+                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
+                __Pyx_INCREF(__pyx_t_15);
                 __Pyx_INCREF(function);
-                __Pyx_DECREF_SET(__pyx_t_9, function);
+                __Pyx_DECREF_SET(__pyx_t_11, function);
               }
             }
-            if (!__pyx_t_13) {
-              __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+            if (!__pyx_t_15) {
+              __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_9); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
               __Pyx_GOTREF(__pyx_t_1);
             } else {
-              __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-              __Pyx_GOTREF(__pyx_t_15);
-              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
-              __Pyx_GIVEREF(__pyx_t_8);
-              PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_8);
-              __pyx_t_8 = 0;
-              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_15, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+              __Pyx_GOTREF(__pyx_t_8);
+              __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_15); __pyx_t_15 = NULL;
+              __Pyx_GIVEREF(__pyx_t_9);
+              PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_9);
+              __pyx_t_9 = 0;
+              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
               __Pyx_GOTREF(__pyx_t_1);
-              __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
+              __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
             }
-            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
             __Pyx_Raise(__pyx_t_1, 0, 0, 0);
             __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+            /* "cutadapt/_seqio.pyx":138
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
+ * 					if len(line) > 1:
+ * 						if not line[1:] == name:             # <<<<<<<<<<<<<<
+ * 							raise FormatError(
+ * 								"At line {0}: Sequence descriptions in the FASTQ file don't match "
+ */
           }
+
+          /* "cutadapt/_seqio.pyx":145
+ * 								"or equal to the first description.".format(i+1,
+ * 									name, line[1:]))
+ * 						name2 = name             # <<<<<<<<<<<<<<
+ * 					else:
+ * 						name2 = ''
+ */
+          __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name);
+          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name2);
+          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_name2, __pyx_cur_scope->__pyx_v_name);
+          __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name);
+
+          /* "cutadapt/_seqio.pyx":137
+ * 					if not (line and line[0] == '+'):
+ * 						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
+ * 					if len(line) > 1:             # <<<<<<<<<<<<<<
+ * 						if not line[1:] == name:
+ * 							raise FormatError(
+ */
           goto __pyx_L16;
         }
-        /*else*/ {
 
-          /* "cutadapt/_seqio.pyx":162
- * 									name, line[1:]))
+        /* "cutadapt/_seqio.pyx":147
+ * 						name2 = name
  * 					else:
- * 						twoheaders = False             # <<<<<<<<<<<<<<
+ * 						name2 = ''             # <<<<<<<<<<<<<<
  * 			elif i == 3:
  * 				if len(line) == len(sequence) - strip:
  */
-          __pyx_cur_scope->__pyx_v_twoheaders = 0;
+        /*else*/ {
+          __Pyx_INCREF(__pyx_kp_s__2);
+          __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name2);
+          __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_name2, __pyx_kp_s__2);
+          __Pyx_GIVEREF(__pyx_kp_s__2);
         }
         __pyx_L16:;
       }
       __pyx_L12:;
+
+      /* "cutadapt/_seqio.pyx":130
+ * 			elif i == 1:
+ * 				sequence = line[:strip]
+ * 			elif i == 2:             # <<<<<<<<<<<<<<
+ * 				if line == '+\n':  # check most common case first
+ * 					name2 = ''
+ */
       break;
 
-      /* "cutadapt/_seqio.pyx":163
+      /* "cutadapt/_seqio.pyx":148
  * 					else:
- * 						twoheaders = False
+ * 						name2 = ''
  * 			elif i == 3:             # <<<<<<<<<<<<<<
  * 				if len(line) == len(sequence) - strip:
  * 					qualities = line[:strip]
  */
       case 3:
 
-      /* "cutadapt/_seqio.pyx":164
- * 						twoheaders = False
+      /* "cutadapt/_seqio.pyx":149
+ * 						name2 = ''
  * 			elif i == 3:
  * 				if len(line) == len(sequence) - strip:             # <<<<<<<<<<<<<<
  * 					qualities = line[:strip]
  * 				else:
  */
-      __pyx_t_14 = PyObject_Length(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      if (unlikely(!__pyx_cur_scope->__pyx_v_sequence)) { __Pyx_RaiseUnboundLocalError("sequence"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-      __pyx_t_16 = PyObject_Length(__pyx_cur_scope->__pyx_v_sequence); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_14 = PyObject_Length(__pyx_cur_scope->__pyx_v_line); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      if (unlikely(!__pyx_cur_scope->__pyx_v_sequence)) { __Pyx_RaiseUnboundLocalError("sequence"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+      __pyx_t_16 = PyObject_Length(__pyx_cur_scope->__pyx_v_sequence); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __pyx_t_4 = ((__pyx_t_14 == (__pyx_t_16 - __pyx_cur_scope->__pyx_v_strip)) != 0);
       if (__pyx_t_4) {
 
-        /* "cutadapt/_seqio.pyx":165
+        /* "cutadapt/_seqio.pyx":150
  * 			elif i == 3:
  * 				if len(line) == len(sequence) - strip:
  * 					qualities = line[:strip]             # <<<<<<<<<<<<<<
@@ -4205,73 +4073,79 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
  */
         if (unlikely(__pyx_cur_scope->__pyx_v_line == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
-          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         }
-        __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __pyx_t_1 = PySequence_GetSlice(__pyx_cur_scope->__pyx_v_line, 0, __pyx_cur_scope->__pyx_v_strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_qualities);
         __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_qualities, ((PyObject*)__pyx_t_1));
         __Pyx_GIVEREF(__pyx_t_1);
         __pyx_t_1 = 0;
+
+        /* "cutadapt/_seqio.pyx":149
+ * 						name2 = ''
+ * 			elif i == 3:
+ * 				if len(line) == len(sequence) - strip:             # <<<<<<<<<<<<<<
+ * 					qualities = line[:strip]
+ * 				else:
+ */
         goto __pyx_L18;
       }
-      /*else*/ {
 
-        /* "cutadapt/_seqio.pyx":167
+      /* "cutadapt/_seqio.pyx":152
  * 					qualities = line[:strip]
  * 				else:
  * 					qualities = line.rstrip('\r\n')             # <<<<<<<<<<<<<<
- * 				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)
  * 			i = (i + 1) % 4
  */
-        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_line, __pyx_n_s_rstrip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      /*else*/ {
+        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_line, __pyx_n_s_rstrip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_GOTREF(__pyx_t_1);
-        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-        __Pyx_GOTREF(__pyx_t_9);
+        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        __Pyx_GOTREF(__pyx_t_11);
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-        if (!(likely(PyString_CheckExact(__pyx_t_9))||((__pyx_t_9) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_9)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+        if (!(likely(PyString_CheckExact(__pyx_t_11))||((__pyx_t_11) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_11)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_qualities);
-        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_qualities, ((PyObject*)__pyx_t_9));
-        __Pyx_GIVEREF(__pyx_t_9);
-        __pyx_t_9 = 0;
+        __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_qualities, ((PyObject*)__pyx_t_11));
+        __Pyx_GIVEREF(__pyx_t_11);
+        __pyx_t_11 = 0;
       }
       __pyx_L18:;
 
-      /* "cutadapt/_seqio.pyx":168
+      /* "cutadapt/_seqio.pyx":153
  * 				else:
  * 					qualities = line.rstrip('\r\n')
- * 				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)             # <<<<<<<<<<<<<<
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)             # <<<<<<<<<<<<<<
  * 			i = (i + 1) % 4
  * 		if i != 0:
  */
-      if (unlikely(!__pyx_cur_scope->__pyx_v_sequence)) { __Pyx_RaiseUnboundLocalError("sequence"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
-      __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_9);
+      if (unlikely(!__pyx_cur_scope->__pyx_v_sequence)) { __Pyx_RaiseUnboundLocalError("sequence"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+      __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_11);
       __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name);
       __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name);
-      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_cur_scope->__pyx_v_name);
+      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_cur_scope->__pyx_v_name);
       __Pyx_INCREF(__pyx_cur_scope->__pyx_v_sequence);
       __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_sequence);
-      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_cur_scope->__pyx_v_sequence);
+      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_cur_scope->__pyx_v_sequence);
       __Pyx_INCREF(__pyx_cur_scope->__pyx_v_qualities);
       __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_qualities);
-      PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_cur_scope->__pyx_v_qualities);
-      __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_cur_scope->__pyx_v_qualities);
+      __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_GOTREF(__pyx_t_1);
-      __pyx_t_15 = __Pyx_PyBool_FromLong(__pyx_cur_scope->__pyx_v_twoheaders); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_15);
-      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_twoheaders, __pyx_t_15) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_cur_scope->__pyx_v_sequence_class, __pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-      __Pyx_GOTREF(__pyx_t_15);
-      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+      if (unlikely(!__pyx_cur_scope->__pyx_v_name2)) { __Pyx_RaiseUnboundLocalError("name2"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
+      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_name2, __pyx_cur_scope->__pyx_v_name2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_cur_scope->__pyx_v_sequence_class, __pyx_t_11, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __Pyx_GOTREF(__pyx_t_8);
+      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-      __pyx_r = __pyx_t_15;
-      __pyx_t_15 = 0;
+      __pyx_r = __pyx_t_8;
+      __pyx_t_8 = 0;
       __Pyx_XGIVEREF(__pyx_t_2);
       __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
-      __pyx_cur_scope->__pyx_t_1 = __pyx_t_11;
-      __pyx_cur_scope->__pyx_t_2 = __pyx_t_12;
+      __pyx_cur_scope->__pyx_t_1 = __pyx_t_10;
+      __pyx_cur_scope->__pyx_t_2 = __pyx_t_13;
       __Pyx_XGIVEREF(__pyx_r);
       __Pyx_RefNannyFinishContext();
       /* return from generator, yielding value */
@@ -4281,23 +4155,31 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
       __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
       __pyx_cur_scope->__pyx_t_0 = 0;
       __Pyx_XGOTREF(__pyx_t_2);
-      __pyx_t_11 = __pyx_cur_scope->__pyx_t_1;
-      __pyx_t_12 = __pyx_cur_scope->__pyx_t_2;
-      if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_10 = __pyx_cur_scope->__pyx_t_1;
+      __pyx_t_13 = __pyx_cur_scope->__pyx_t_2;
+      if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+      /* "cutadapt/_seqio.pyx":148
+ * 					else:
+ * 						name2 = ''
+ * 			elif i == 3:             # <<<<<<<<<<<<<<
+ * 				if len(line) == len(sequence) - strip:
+ * 					qualities = line[:strip]
+ */
       break;
       default: break;
     }
 
-    /* "cutadapt/_seqio.pyx":169
+    /* "cutadapt/_seqio.pyx":154
  * 					qualities = line.rstrip('\r\n')
- * 				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)
  * 			i = (i + 1) % 4             # <<<<<<<<<<<<<<
  * 		if i != 0:
  * 			raise FormatError("FASTQ file ended prematurely")
  */
     __pyx_cur_scope->__pyx_v_i = __Pyx_mod_long((__pyx_cur_scope->__pyx_v_i + 1), 4);
 
-    /* "cutadapt/_seqio.pyx":138
+    /* "cutadapt/_seqio.pyx":123
  * 
  * 		i = 1
  * 		for line in it:             # <<<<<<<<<<<<<<
@@ -4307,8 +4189,8 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
   }
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_seqio.pyx":170
- * 				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+  /* "cutadapt/_seqio.pyx":155
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)
  * 			i = (i + 1) % 4
  * 		if i != 0:             # <<<<<<<<<<<<<<
  * 			raise FormatError("FASTQ file ended prematurely")
@@ -4317,29 +4199,37 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
   __pyx_t_4 = ((__pyx_cur_scope->__pyx_v_i != 0) != 0);
   if (__pyx_t_4) {
 
-    /* "cutadapt/_seqio.pyx":171
+    /* "cutadapt/_seqio.pyx":156
  * 			i = (i + 1) % 4
  * 		if i != 0:
  * 			raise FormatError("FASTQ file ended prematurely")             # <<<<<<<<<<<<<<
  * 
  * 	def close(self):
  */
-    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FormatError); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_2);
-    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    __Pyx_GOTREF(__pyx_t_15);
+    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_GOTREF(__pyx_t_8);
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-    __Pyx_Raise(__pyx_t_15, 0, 0, 0);
-    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
+    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_seqio.pyx":155
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)
+ * 			i = (i + 1) % 4
+ * 		if i != 0:             # <<<<<<<<<<<<<<
+ * 			raise FormatError("FASTQ file ended prematurely")
+ * 
+ */
   }
 
-  /* "cutadapt/_seqio.pyx":119
+  /* "cutadapt/_seqio.pyx":106
  * 		self.delivers_qualities = True
  * 
  * 	def __iter__(self):             # <<<<<<<<<<<<<<
  * 		"""
- * 		Return tuples: (name, sequence, qualities).
+ * 		Yield Sequence objects
  */
 
   /* function exit code */
@@ -4353,23 +4243,23 @@ static PyObject *__pyx_gb_8cutadapt_6_seqio_11FastqReader_4generator(__pyx_Gener
   __Pyx_XDECREF(__pyx_t_7);
   __Pyx_XDECREF(__pyx_t_8);
   __Pyx_XDECREF(__pyx_t_9);
-  __Pyx_XDECREF(__pyx_t_13);
+  __Pyx_XDECREF(__pyx_t_11);
   __Pyx_XDECREF(__pyx_t_15);
   __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
   __pyx_L0:;
-  __Pyx_XDECREF(__pyx_r);
+  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
   __pyx_generator->resume_label = -1;
-  __Pyx_Generator_clear((PyObject*)__pyx_generator);
+  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
   __Pyx_RefNannyFinishContext();
-  return NULL;
+  return __pyx_r;
 }
 
-/* "cutadapt/_seqio.pyx":173
+/* "cutadapt/_seqio.pyx":158
  * 			raise FormatError("FASTQ file ended prematurely")
  * 
  * 	def close(self):             # <<<<<<<<<<<<<<
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()
  */
 
 /* Python wrapper */
@@ -4400,42 +4290,41 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_5close(CYTHON_UNUSED P
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("close", 0);
 
-  /* "cutadapt/_seqio.pyx":174
+  /* "cutadapt/_seqio.pyx":159
  * 
  * 	def close(self):
- * 		if not self._file_passed and self.fp is not None:             # <<<<<<<<<<<<<<
- * 			self.fp.close()
- * 			self.fp = None
+ * 		if self._close_on_exit and self._file is not None:             # <<<<<<<<<<<<<<
+ * 			self._file.close()
+ * 			self._file = None
  */
-  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_file_passed); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_close_on_exit); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_4 = ((!__pyx_t_3) != 0);
-  if (__pyx_t_4) {
+  if (__pyx_t_3) {
   } else {
-    __pyx_t_1 = __pyx_t_4;
+    __pyx_t_1 = __pyx_t_3;
     goto __pyx_L4_bool_binop_done;
   }
-  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_file_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
-  __pyx_t_4 = (__pyx_t_2 != Py_None);
+  __pyx_t_3 = (__pyx_t_2 != Py_None);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-  __pyx_t_3 = (__pyx_t_4 != 0);
-  __pyx_t_1 = __pyx_t_3;
+  __pyx_t_4 = (__pyx_t_3 != 0);
+  __pyx_t_1 = __pyx_t_4;
   __pyx_L4_bool_binop_done:;
   if (__pyx_t_1) {
 
-    /* "cutadapt/_seqio.pyx":175
+    /* "cutadapt/_seqio.pyx":160
  * 	def close(self):
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()             # <<<<<<<<<<<<<<
- * 			self.fp = None
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()             # <<<<<<<<<<<<<<
+ * 			self._file = None
  * 
  */
-    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_file_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_5);
-    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_close); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_close); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_6);
     __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     __pyx_t_5 = NULL;
@@ -4449,33 +4338,39 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_5close(CYTHON_UNUSED P
       }
     }
     if (__pyx_t_5) {
-      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
     } else {
-      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     }
     __Pyx_GOTREF(__pyx_t_2);
     __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
     __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-    /* "cutadapt/_seqio.pyx":176
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()
- * 			self.fp = None             # <<<<<<<<<<<<<<
+    /* "cutadapt/_seqio.pyx":161
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()
+ * 			self._file = None             # <<<<<<<<<<<<<<
  * 
  * 	def __enter__(self):
  */
-    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_fp, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-    goto __pyx_L3;
+    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_file_2, Py_None) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_seqio.pyx":159
+ * 
+ * 	def close(self):
+ * 		if self._close_on_exit and self._file is not None:             # <<<<<<<<<<<<<<
+ * 			self._file.close()
+ * 			self._file = None
+ */
   }
-  __pyx_L3:;
 
-  /* "cutadapt/_seqio.pyx":173
+  /* "cutadapt/_seqio.pyx":158
  * 			raise FormatError("FASTQ file ended prematurely")
  * 
  * 	def close(self):             # <<<<<<<<<<<<<<
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()
  */
 
   /* function exit code */
@@ -4493,11 +4388,11 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_5close(CYTHON_UNUSED P
   return __pyx_r;
 }
 
-/* "cutadapt/_seqio.pyx":178
- * 			self.fp = None
+/* "cutadapt/_seqio.pyx":163
+ * 			self._file = None
  * 
  * 	def __enter__(self):             # <<<<<<<<<<<<<<
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")
  */
 
@@ -4526,36 +4421,44 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_7__enter__(CYTHON_UNUS
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__enter__", 0);
 
-  /* "cutadapt/_seqio.pyx":179
+  /* "cutadapt/_seqio.pyx":164
  * 
  * 	def __enter__(self):
- * 		if self.fp is None:             # <<<<<<<<<<<<<<
+ * 		if self._file is None:             # <<<<<<<<<<<<<<
  * 			raise ValueError("I/O operation on closed FastqReader")
  * 		return self
  */
-  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_fp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_file_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
   __pyx_t_2 = (__pyx_t_1 == Py_None);
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
   __pyx_t_3 = (__pyx_t_2 != 0);
   if (__pyx_t_3) {
 
-    /* "cutadapt/_seqio.pyx":180
+    /* "cutadapt/_seqio.pyx":165
  * 	def __enter__(self):
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")             # <<<<<<<<<<<<<<
  * 		return self
  * 
  */
-    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_GOTREF(__pyx_t_1);
     __Pyx_Raise(__pyx_t_1, 0, 0, 0);
     __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
-    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+    /* "cutadapt/_seqio.pyx":164
+ * 
+ * 	def __enter__(self):
+ * 		if self._file is None:             # <<<<<<<<<<<<<<
+ * 			raise ValueError("I/O operation on closed FastqReader")
+ * 		return self
+ */
   }
 
-  /* "cutadapt/_seqio.pyx":181
- * 		if self.fp is None:
+  /* "cutadapt/_seqio.pyx":166
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")
  * 		return self             # <<<<<<<<<<<<<<
  * 
@@ -4566,11 +4469,11 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_7__enter__(CYTHON_UNUS
   __pyx_r = __pyx_v_self;
   goto __pyx_L0;
 
-  /* "cutadapt/_seqio.pyx":178
- * 			self.fp = None
+  /* "cutadapt/_seqio.pyx":163
+ * 			self._file = None
  * 
  * 	def __enter__(self):             # <<<<<<<<<<<<<<
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")
  */
 
@@ -4585,7 +4488,7 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_7__enter__(CYTHON_UNUS
   return __pyx_r;
 }
 
-/* "cutadapt/_seqio.pyx":183
+/* "cutadapt/_seqio.pyx":168
  * 		return self
  * 
  * 	def __exit__(self, *args):             # <<<<<<<<<<<<<<
@@ -4633,7 +4536,7 @@ static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_10__exit__(PyObject *_
       }
       if (unlikely(kw_args > 0)) {
         const Py_ssize_t used_pos_args = (pos_args < 1) ? pos_args : 1;
-        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
       }
     } else if (PyTuple_GET_SIZE(__pyx_args) < 1) {
       goto __pyx_L5_argtuple_error;
@@ -4644,7 +4547,7 @@ static PyObject *__pyx_pw_8cutadapt_6_seqio_11FastqReader_10__exit__(PyObject *_
   }
   goto __pyx_L4_argument_unpacking_done;
   __pyx_L5_argtuple_error:;
-  __Pyx_RaiseArgtupleInvalid("__exit__", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
+  __Pyx_RaiseArgtupleInvalid("__exit__", 0, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
   __pyx_L3_error:;
   __Pyx_DECREF(__pyx_v_args); __pyx_v_args = 0;
   __Pyx_AddTraceback("cutadapt._seqio.FastqReader.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
@@ -4670,12 +4573,12 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_9__exit__(CYTHON_UNUSE
   int __pyx_clineno = 0;
   __Pyx_RefNannySetupContext("__exit__", 0);
 
-  /* "cutadapt/_seqio.pyx":184
+  /* "cutadapt/_seqio.pyx":169
  * 
  * 	def __exit__(self, *args):
  * 		self.close()             # <<<<<<<<<<<<<<
  */
-  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __pyx_t_3 = NULL;
   if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
@@ -4688,16 +4591,16 @@ static PyObject *__pyx_pf_8cutadapt_6_seqio_11FastqReader_9__exit__(CYTHON_UNUSE
     }
   }
   if (__pyx_t_3) {
-    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
     __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   } else {
-    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   __Pyx_GOTREF(__pyx_t_1);
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 
-  /* "cutadapt/_seqio.pyx":183
+  /* "cutadapt/_seqio.pyx":168
  * 		return self
  * 
  * 	def __exit__(self, *args):             # <<<<<<<<<<<<<<
@@ -4732,6 +4635,7 @@ static PyObject *__pyx_tp_new_8cutadapt_6_seqio_Sequence(PyTypeObject *t, CYTHON
   p->name = ((PyObject*)Py_None); Py_INCREF(Py_None);
   p->sequence = ((PyObject*)Py_None); Py_INCREF(Py_None);
   p->qualities = ((PyObject*)Py_None); Py_INCREF(Py_None);
+  p->name2 = ((PyObject*)Py_None); Py_INCREF(Py_None);
   p->match = Py_None; Py_INCREF(Py_None);
   return o;
 }
@@ -4747,6 +4651,7 @@ static void __pyx_tp_dealloc_8cutadapt_6_seqio_Sequence(PyObject *o) {
   Py_CLEAR(p->name);
   Py_CLEAR(p->sequence);
   Py_CLEAR(p->qualities);
+  Py_CLEAR(p->name2);
   Py_CLEAR(p->match);
   (*Py_TYPE(o)->tp_free)(o);
 }
@@ -4815,36 +4720,34 @@ static int __pyx_setprop_8cutadapt_6_seqio_8Sequence_qualities(PyObject *o, PyOb
   }
 }
 
-static PyObject *__pyx_getprop_8cutadapt_6_seqio_8Sequence_match(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(o);
+static PyObject *__pyx_getprop_8cutadapt_6_seqio_8Sequence_name2(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_1__get__(o);
 }
 
-static int __pyx_setprop_8cutadapt_6_seqio_8Sequence_match(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
+static int __pyx_setprop_8cutadapt_6_seqio_8Sequence_name2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
   if (v) {
-    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(o, v);
+    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_3__set__(o, v);
   }
   else {
-    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(o);
+    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5name2_5__del__(o);
   }
 }
 
-static PyObject *__pyx_getprop_8cutadapt_6_seqio_8Sequence_twoheaders(PyObject *o, CYTHON_UNUSED void *x) {
-  return __pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_1__get__(o);
+static PyObject *__pyx_getprop_8cutadapt_6_seqio_8Sequence_match(PyObject *o, CYTHON_UNUSED void *x) {
+  return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_1__get__(o);
 }
 
-static int __pyx_setprop_8cutadapt_6_seqio_8Sequence_twoheaders(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
+static int __pyx_setprop_8cutadapt_6_seqio_8Sequence_match(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
   if (v) {
-    return __pyx_pw_8cutadapt_6_seqio_8Sequence_10twoheaders_3__set__(o, v);
+    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_3__set__(o, v);
   }
   else {
-    PyErr_SetString(PyExc_NotImplementedError, "__del__");
-    return -1;
+    return __pyx_pw_8cutadapt_6_seqio_8Sequence_5match_5__del__(o);
   }
 }
 
 static PyMethodDef __pyx_methods_8cutadapt_6_seqio_Sequence[] = {
   {"__reduce__", (PyCFunction)__pyx_pw_8cutadapt_6_seqio_8Sequence_11__reduce__, METH_NOARGS, 0},
-  {"write", (PyCFunction)__pyx_pw_8cutadapt_6_seqio_8Sequence_13write, METH_O, 0},
   {0, 0, 0, 0}
 };
 
@@ -4852,8 +4755,8 @@ static struct PyGetSetDef __pyx_getsets_8cutadapt_6_seqio_Sequence[] = {
   {(char *)"name", __pyx_getprop_8cutadapt_6_seqio_8Sequence_name, __pyx_setprop_8cutadapt_6_seqio_8Sequence_name, 0, 0},
   {(char *)"sequence", __pyx_getprop_8cutadapt_6_seqio_8Sequence_sequence, __pyx_setprop_8cutadapt_6_seqio_8Sequence_sequence, 0, 0},
   {(char *)"qualities", __pyx_getprop_8cutadapt_6_seqio_8Sequence_qualities, __pyx_setprop_8cutadapt_6_seqio_8Sequence_qualities, 0, 0},
+  {(char *)"name2", __pyx_getprop_8cutadapt_6_seqio_8Sequence_name2, __pyx_setprop_8cutadapt_6_seqio_8Sequence_name2, 0, 0},
   {(char *)"match", __pyx_getprop_8cutadapt_6_seqio_8Sequence_match, __pyx_setprop_8cutadapt_6_seqio_8Sequence_match, 0, 0},
-  {(char *)"twoheaders", __pyx_getprop_8cutadapt_6_seqio_8Sequence_twoheaders, __pyx_setprop_8cutadapt_6_seqio_8Sequence_twoheaders, 0, 0},
   {0, 0, 0, 0, 0}
 };
 
@@ -4887,8 +4790,9 @@ static PyTypeObject __pyx_type_8cutadapt_6_seqio_Sequence = {
   0, /*tp_setattr*/
   #if PY_MAJOR_VERSION < 3
   0, /*tp_compare*/
-  #else
-  0, /*reserved*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
   #endif
   __pyx_pw_8cutadapt_6_seqio_8Sequence_5__repr__, /*tp_repr*/
   0, /*tp_as_number*/
@@ -4901,7 +4805,7 @@ static PyTypeObject __pyx_type_8cutadapt_6_seqio_Sequence = {
   0, /*tp_setattro*/
   0, /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
-  "\n\tA record in a FASTQ file. Also used for FASTA (then the qualities attribute\n\tis None). qualities is a string and it contains the qualities encoded as\n\tascii(qual+33).\n\n\tIf an adapter has been matched to the sequence, the 'match' attribute is\n\tset to the corresponding AdapterMatch instance.\n\t", /*tp_doc*/
+  "\n\tA record in a FASTQ file. Also used for FASTA (then the qualities attribute\n\tis None). qualities is a string and it contains the qualities encoded as\n\tascii(qual+33).\n\n\tIf an adapter has been matched to the sequence, the 'match' attribute is\n\tset to the corresponding Match instance.\n\t", /*tp_doc*/
   __pyx_tp_traverse_8cutadapt_6_seqio_Sequence, /*tp_traverse*/
   __pyx_tp_clear_8cutadapt_6_seqio_Sequence, /*tp_clear*/
   __pyx_pw_8cutadapt_6_seqio_8Sequence_9__richcmp__, /*tp_richcompare*/
@@ -4956,6 +4860,7 @@ static void __pyx_tp_dealloc_8cutadapt_6_seqio___pyx_scope_struct____iter__(PyOb
   Py_CLEAR(p->__pyx_v_it);
   Py_CLEAR(p->__pyx_v_line);
   Py_CLEAR(p->__pyx_v_name);
+  Py_CLEAR(p->__pyx_v_name2);
   Py_CLEAR(p->__pyx_v_qualities);
   Py_CLEAR(p->__pyx_v_self);
   Py_CLEAR(p->__pyx_v_sequence);
@@ -5015,8 +4920,9 @@ static PyTypeObject __pyx_type_8cutadapt_6_seqio___pyx_scope_struct____iter__ =
   0, /*tp_setattr*/
   #if PY_MAJOR_VERSION < 3
   0, /*tp_compare*/
-  #else
-  0, /*reserved*/
+  #endif
+  #if PY_MAJOR_VERSION >= 3
+  0, /*tp_as_async*/
   #endif
   0, /*tp_repr*/
   0, /*tp_as_number*/
@@ -5097,6 +5003,8 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_FormatError, __pyx_k_FormatError, sizeof(__pyx_k_FormatError), 0, 0, 1, 1},
   {&__pyx_kp_s_I_O_operation_on_closed_FastqRea, __pyx_k_I_O_operation_on_closed_FastqRea, sizeof(__pyx_k_I_O_operation_on_closed_FastqRea), 0, 0, 1, 0},
   {&__pyx_kp_s_In_read_named_0_r_length_of_qual, __pyx_k_In_read_named_0_r_length_of_qual, sizeof(__pyx_k_In_read_named_0_r_length_of_qual), 0, 0, 1, 0},
+  {&__pyx_kp_s_Line_0_in_FASTQ_file_is_expected, __pyx_k_Line_0_in_FASTQ_file_is_expected, sizeof(__pyx_k_Line_0_in_FASTQ_file_is_expected), 0, 0, 1, 0},
+  {&__pyx_kp_s_Line_0_in_FASTQ_file_is_expected_2, __pyx_k_Line_0_in_FASTQ_file_is_expected_2, sizeof(__pyx_k_Line_0_in_FASTQ_file_is_expected_2), 0, 0, 1, 0},
   {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
   {&__pyx_kp_s_Raised_when_an_input_file_FASTA, __pyx_k_Raised_when_an_input_file_FASTA, sizeof(__pyx_k_Raised_when_an_input_file_FASTA), 0, 0, 1, 0},
   {&__pyx_kp_s_Reader_for_FASTQ_files_Does_not, __pyx_k_Reader_for_FASTQ_files_Does_not, sizeof(__pyx_k_Reader_for_FASTQ_files_Does_not), 0, 0, 1, 0},
@@ -5107,23 +5015,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0},
   {&__pyx_kp_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 0},
   {&__pyx_kp_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 0},
-  {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0},
-  {&__pyx_kp_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 0},
-  {&__pyx_kp_s__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 0, 1, 0},
   {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
-  {&__pyx_kp_s_at_line_0_expected_a_line_starti, __pyx_k_at_line_0_expected_a_line_starti, sizeof(__pyx_k_at_line_0_expected_a_line_starti), 0, 0, 1, 0},
-  {&__pyx_kp_s_at_line_0_expected_a_line_starti_2, __pyx_k_at_line_0_expected_a_line_starti_2, sizeof(__pyx_k_at_line_0_expected_a_line_starti_2), 0, 0, 1, 0},
   {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
   {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
+  {&__pyx_n_s_close_on_exit, __pyx_k_close_on_exit, sizeof(__pyx_k_close_on_exit), 0, 0, 1, 1},
   {&__pyx_n_s_cutadapt__seqio, __pyx_k_cutadapt__seqio, sizeof(__pyx_k_cutadapt__seqio), 0, 0, 1, 1},
   {&__pyx_n_s_delivers_qualities, __pyx_k_delivers_qualities, sizeof(__pyx_k_delivers_qualities), 0, 0, 1, 1},
   {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
   {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
   {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
   {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
-  {&__pyx_n_s_file_passed, __pyx_k_file_passed, sizeof(__pyx_k_file_passed), 0, 0, 1, 1},
+  {&__pyx_n_s_file_2, __pyx_k_file_2, sizeof(__pyx_k_file_2), 0, 0, 1, 1},
   {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
-  {&__pyx_n_s_fp, __pyx_k_fp, sizeof(__pyx_k_fp), 0, 0, 1, 1},
   {&__pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_k_home_marcel_scm_cutadapt_cutada, sizeof(__pyx_k_home_marcel_scm_cutadapt_cutada), 0, 0, 1, 0},
   {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
   {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
@@ -5137,6 +5040,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
   {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
   {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
+  {&__pyx_n_s_name2, __pyx_k_name2, sizeof(__pyx_k_name2), 0, 0, 1, 1},
   {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
   {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
   {&__pyx_n_s_qualities, __pyx_k_qualities, sizeof(__pyx_k_qualities), 0, 0, 1, 1},
@@ -5152,16 +5056,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
   {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
   {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
   {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
-  {&__pyx_n_s_twoheaders, __pyx_k_twoheaders, sizeof(__pyx_k_twoheaders), 0, 0, 1, 1},
-  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
   {&__pyx_n_s_xopen, __pyx_k_xopen, sizeof(__pyx_k_xopen), 0, 0, 1, 1},
   {0, 0, 0, 0, 0, 0, 0}
 };
 static int __Pyx_InitCachedBuiltins(void) {
   __pyx_builtin_Exception = __Pyx_GetBuiltinName(__pyx_n_s_Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   return 0;
   __pyx_L1_error:;
   return -1;
@@ -5171,38 +5073,38 @@ static int __Pyx_InitCachedConstants(void) {
   __Pyx_RefNannyDeclarations
   __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
 
-  /* "cutadapt/_seqio.pyx":167
+  /* "cutadapt/_seqio.pyx":152
  * 					qualities = line[:strip]
  * 				else:
  * 					qualities = line.rstrip('\r\n')             # <<<<<<<<<<<<<<
- * 				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+ * 				yield sequence_class(name, sequence, qualities, name2=name2)
  * 			i = (i + 1) % 4
  */
-  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s__7); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__10);
-  __Pyx_GIVEREF(__pyx_tuple__10);
+  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s__4); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__7);
+  __Pyx_GIVEREF(__pyx_tuple__7);
 
-  /* "cutadapt/_seqio.pyx":171
+  /* "cutadapt/_seqio.pyx":156
  * 			i = (i + 1) % 4
  * 		if i != 0:
  * 			raise FormatError("FASTQ file ended prematurely")             # <<<<<<<<<<<<<<
  * 
  * 	def close(self):
  */
-  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_FASTQ_file_ended_prematurely); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__11);
-  __Pyx_GIVEREF(__pyx_tuple__11);
+  __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_FASTQ_file_ended_prematurely); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__8);
+  __Pyx_GIVEREF(__pyx_tuple__8);
 
-  /* "cutadapt/_seqio.pyx":180
+  /* "cutadapt/_seqio.pyx":165
  * 	def __enter__(self):
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")             # <<<<<<<<<<<<<<
  * 		return self
  * 
  */
-  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_FastqRea); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__12);
-  __Pyx_GIVEREF(__pyx_tuple__12);
+  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_FastqRea); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__9);
+  __Pyx_GIVEREF(__pyx_tuple__9);
 
   /* "cutadapt/_seqio.pyx":16
  * 
@@ -5211,69 +5113,69 @@ static int __Pyx_InitCachedConstants(void) {
  * 	"""Shorten string s to at most n characters, appending "..." if necessary."""
  * 	if s is None:
  */
-  __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_s, __pyx_n_s_n); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__13);
-  __Pyx_GIVEREF(__pyx_tuple__13);
-  __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_shorten, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_s, __pyx_n_s_n); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__10);
+  __Pyx_GIVEREF(__pyx_tuple__10);
+  __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_shorten, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":102
- * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
- * 	"""
+  /* "cutadapt/_seqio.pyx":94
+ * 	_close_on_exit = False
+ * 
  * 	def __init__(self, file, sequence_class=Sequence):             # <<<<<<<<<<<<<<
  * 		"""
  * 		file is a filename or a file-like object.
  */
-  __pyx_tuple__15 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_file, __pyx_n_s_sequence_class); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__15);
-  __Pyx_GIVEREF(__pyx_tuple__15);
-  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_init, 102, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__12 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_file, __pyx_n_s_sequence_class); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__12);
+  __Pyx_GIVEREF(__pyx_tuple__12);
+  __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_init, 94, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":119
+  /* "cutadapt/_seqio.pyx":106
  * 		self.delivers_qualities = True
  * 
  * 	def __iter__(self):             # <<<<<<<<<<<<<<
  * 		"""
- * 		Return tuples: (name, sequence, qualities).
+ * 		Yield Sequence objects
  */
-  __pyx_tuple__17 = PyTuple_Pack(10, __pyx_n_s_self, __pyx_n_s_i, __pyx_n_s_strip, __pyx_n_s_line, __pyx_n_s_name, __pyx_n_s_qualities, __pyx_n_s_sequence, __pyx_n_s_twoheaders, __pyx_n_s_sequence_class, __pyx_n_s_it); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__17);
-  __Pyx_GIVEREF(__pyx_tuple__17);
-  __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(1, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_iter, 119, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__14 = PyTuple_Pack(10, __pyx_n_s_self, __pyx_n_s_i, __pyx_n_s_strip, __pyx_n_s_line, __pyx_n_s_name, __pyx_n_s_qualities, __pyx_n_s_sequence, __pyx_n_s_name2, __pyx_n_s_sequence_class, __pyx_n_s_it); if (unlikely(!__pyx_tuple__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__14);
+  __Pyx_GIVEREF(__pyx_tuple__14);
+  __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_iter, 106, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":173
+  /* "cutadapt/_seqio.pyx":158
  * 			raise FormatError("FASTQ file ended prematurely")
  * 
  * 	def close(self):             # <<<<<<<<<<<<<<
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()
  */
-  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__19);
-  __Pyx_GIVEREF(__pyx_tuple__19);
-  __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_close, 173, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__16);
+  __Pyx_GIVEREF(__pyx_tuple__16);
+  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_close, 158, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":178
- * 			self.fp = None
+  /* "cutadapt/_seqio.pyx":163
+ * 			self._file = None
  * 
  * 	def __enter__(self):             # <<<<<<<<<<<<<<
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")
  */
-  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__21);
-  __Pyx_GIVEREF(__pyx_tuple__21);
-  __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_enter, 178, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__18);
+  __Pyx_GIVEREF(__pyx_tuple__18);
+  __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_enter, 163, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
 
-  /* "cutadapt/_seqio.pyx":183
+  /* "cutadapt/_seqio.pyx":168
  * 		return self
  * 
  * 	def __exit__(self, *args):             # <<<<<<<<<<<<<<
  * 		self.close()
  */
-  __pyx_tuple__23 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_args); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_GOTREF(__pyx_tuple__23);
-  __Pyx_GIVEREF(__pyx_tuple__23);
-  __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_exit, 183, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_tuple__20 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_args); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_GOTREF(__pyx_tuple__20);
+  __Pyx_GIVEREF(__pyx_tuple__20);
+  __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_marcel_scm_cutadapt_cutada, __pyx_n_s_exit, 168, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_RefNannyFinishContext();
   return 0;
   __pyx_L1_error:;
@@ -5316,18 +5218,24 @@ PyMODINIT_FUNC PyInit__seqio(void)
   }
   #endif
   __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__seqio(void)", 0);
-  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #ifdef __Pyx_CyFunction_USED
-  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   #ifdef __Pyx_FusedFunction_USED
   if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_Coroutine_USED
+  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   #ifdef __Pyx_Generator_USED
   if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
+  #ifdef __Pyx_StopAsyncIteration_USED
+  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
   /*--- Library function declarations ---*/
   /*--- Threads initialization code ---*/
   #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
@@ -5350,12 +5258,12 @@ PyMODINIT_FUNC PyInit__seqio(void)
   #endif
   if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
   /*--- Initialize various global constants etc. ---*/
-  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
   if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   #endif
   if (__pyx_module_is_main_cutadapt___seqio) {
-    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
+    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   }
   #if PY_MAJOR_VERSION >= 3
   {
@@ -5366,9 +5274,9 @@ PyMODINIT_FUNC PyInit__seqio(void)
   }
   #endif
   /*--- Builtin init code ---*/
-  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Constants init code ---*/
-  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   /*--- Global init code ---*/
   /*--- Variable export code ---*/
   /*--- Function export code ---*/
@@ -5397,13 +5305,16 @@ PyMODINIT_FUNC PyInit__seqio(void)
   #endif
   if (PyObject_SetAttrString(__pyx_m, "Sequence", (PyObject *)&__pyx_type_8cutadapt_6_seqio_Sequence) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_ptype_8cutadapt_6_seqio_Sequence = &__pyx_type_8cutadapt_6_seqio_Sequence;
-  if (PyType_Ready(&__pyx_type_8cutadapt_6_seqio___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyType_Ready(&__pyx_type_8cutadapt_6_seqio___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_type_8cutadapt_6_seqio___pyx_scope_struct____iter__.tp_print = 0;
   __pyx_ptype_8cutadapt_6_seqio___pyx_scope_struct____iter__ = &__pyx_type_8cutadapt_6_seqio___pyx_scope_struct____iter__;
   /*--- Type import code ---*/
   /*--- Variable import code ---*/
   /*--- Function import code ---*/
   /*--- Execution code ---*/
+  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  #endif
 
   /* "cutadapt/_seqio.pyx":4
  * # cython: profile=False
@@ -5462,97 +5373,106 @@ PyMODINIT_FUNC PyInit__seqio(void)
   if (PyDict_SetItem(__pyx_d, __pyx_n_s_shorten, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 
-  /* "cutadapt/_seqio.pyx":98
+  /* "cutadapt/_seqio.pyx":88
  * 
  * 
  * class FastqReader(object):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
  */
-  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_2);
   __Pyx_INCREF(__pyx_builtin_object);
   __Pyx_GIVEREF(__pyx_builtin_object);
   PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object);
-  __pyx_t_1 = __Pyx_CalculateMetaclass(NULL, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_1 = __Pyx_CalculateMetaclass(NULL, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_1);
-  __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_1, __pyx_t_2, __pyx_n_s_FastqReader, __pyx_n_s_FastqReader, (PyObject *) NULL, __pyx_n_s_cutadapt__seqio, __pyx_kp_s_Reader_for_FASTQ_files_Does_not); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_3 = __Pyx_Py3MetaclassPrepare(__pyx_t_1, __pyx_t_2, __pyx_n_s_FastqReader, __pyx_n_s_FastqReader, (PyObject *) NULL, __pyx_n_s_cutadapt__seqio, __pyx_kp_s_Reader_for_FASTQ_files_Does_not); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_3);
 
-  /* "cutadapt/_seqio.pyx":102
+  /* "cutadapt/_seqio.pyx":92
  * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
  * 	"""
+ * 	_close_on_exit = False             # <<<<<<<<<<<<<<
+ * 
+ * 	def __init__(self, file, sequence_class=Sequence):
+ */
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_close_on_exit, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+
+  /* "cutadapt/_seqio.pyx":94
+ * 	_close_on_exit = False
+ * 
  * 	def __init__(self, file, sequence_class=Sequence):             # <<<<<<<<<<<<<<
  * 		"""
  * 		file is a filename or a file-like object.
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_1__init__, 0, __pyx_n_s_FastqReader___init, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_1__init__, 0, __pyx_n_s_FastqReader___init, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (!__Pyx_CyFunction_InitDefaults(__pyx_t_4, sizeof(__pyx_defaults), 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
-  __Pyx_INCREF(((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence)));
-  __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_t_4)->__pyx_arg_sequence_class = ((PyObject *)((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence));
-  __Pyx_GIVEREF(((PyObject*)__pyx_ptype_8cutadapt_6_seqio_Sequence));
+  if (!__Pyx_CyFunction_InitDefaults(__pyx_t_4, sizeof(__pyx_defaults), 1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __Pyx_INCREF(((PyObject *)__pyx_ptype_8cutadapt_6_seqio_Sequence));
+  __Pyx_CyFunction_Defaults(__pyx_defaults, __pyx_t_4)->__pyx_arg_sequence_class = ((PyObject *)__pyx_ptype_8cutadapt_6_seqio_Sequence);
+  __Pyx_GIVEREF(__pyx_ptype_8cutadapt_6_seqio_Sequence);
   __Pyx_CyFunction_SetDefaultsGetter(__pyx_t_4, __pyx_pf_8cutadapt_6_seqio_11FastqReader_11__defaults__);
-  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_init, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_init, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "cutadapt/_seqio.pyx":119
+  /* "cutadapt/_seqio.pyx":106
  * 		self.delivers_qualities = True
  * 
  * 	def __iter__(self):             # <<<<<<<<<<<<<<
  * 		"""
- * 		Return tuples: (name, sequence, qualities).
+ * 		Yield Sequence objects
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_3__iter__, 0, __pyx_n_s_FastqReader___iter, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_3__iter__, 0, __pyx_n_s_FastqReader___iter, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_iter, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_iter, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "cutadapt/_seqio.pyx":173
+  /* "cutadapt/_seqio.pyx":158
  * 			raise FormatError("FASTQ file ended prematurely")
  * 
  * 	def close(self):             # <<<<<<<<<<<<<<
- * 		if not self._file_passed and self.fp is not None:
- * 			self.fp.close()
+ * 		if self._close_on_exit and self._file is not None:
+ * 			self._file.close()
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_6close, 0, __pyx_n_s_FastqReader_close, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_6close, 0, __pyx_n_s_FastqReader_close, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_close, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_close, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "cutadapt/_seqio.pyx":178
- * 			self.fp = None
+  /* "cutadapt/_seqio.pyx":163
+ * 			self._file = None
  * 
  * 	def __enter__(self):             # <<<<<<<<<<<<<<
- * 		if self.fp is None:
+ * 		if self._file is None:
  * 			raise ValueError("I/O operation on closed FastqReader")
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_8__enter__, 0, __pyx_n_s_FastqReader___enter, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__22)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_8__enter__, 0, __pyx_n_s_FastqReader___enter, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_enter, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_enter, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "cutadapt/_seqio.pyx":183
+  /* "cutadapt/_seqio.pyx":168
  * 		return self
  * 
  * 	def __exit__(self, *args):             # <<<<<<<<<<<<<<
  * 		self.close()
  */
-  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_10__exit__, 0, __pyx_n_s_FastqReader___exit, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8cutadapt_6_seqio_11FastqReader_10__exit__, 0, __pyx_n_s_FastqReader___exit, NULL, __pyx_n_s_cutadapt__seqio, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_exit, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyObject_SetItem(__pyx_t_3, __pyx_n_s_exit, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 
-  /* "cutadapt/_seqio.pyx":98
+  /* "cutadapt/_seqio.pyx":88
  * 
  * 
  * class FastqReader(object):             # <<<<<<<<<<<<<<
  * 	"""
  * 	Reader for FASTQ files. Does not support multi-line FASTQ files.
  */
-  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_1, __pyx_n_s_FastqReader, __pyx_t_2, __pyx_t_3, NULL, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  __pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_1, __pyx_n_s_FastqReader, __pyx_t_2, __pyx_t_3, NULL, 0, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_GOTREF(__pyx_t_4);
-  if (PyDict_SetItem(__pyx_d, __pyx_n_s_FastqReader, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
+  if (PyDict_SetItem(__pyx_d, __pyx_n_s_FastqReader, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
   __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
   __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
@@ -5762,8 +5682,109 @@ static void __Pyx_RaiseArgtupleInvalid(
                  (num_expected == 1) ? "" : "s", num_found);
 }
 
-static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
-        Py_ssize_t cstart, Py_ssize_t cstop,
+#if CYTHON_USE_PYLONG_INTERNALS
+  #include "longintrepr.h"
+#endif
+
+#if CYTHON_COMPILING_IN_CPYTHON
+static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
+    #if PY_MAJOR_VERSION < 3
+    if (likely(PyInt_CheckExact(op1))) {
+        const long b = intval;
+        long x;
+        long a = PyInt_AS_LONG(op1);
+            x = (long)((unsigned long)a - b);
+            if (likely((x^a) >= 0 || (x^~b) >= 0))
+                return PyInt_FromLong(x);
+            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
+    }
+    #endif
+    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
+    if (likely(PyLong_CheckExact(op1))) {
+        const long b = intval;
+        long a, x;
+        const PY_LONG_LONG llb = intval;
+        PY_LONG_LONG lla, llx;
+        const digit* digits = ((PyLongObject*)op1)->ob_digit;
+        const Py_ssize_t size = Py_SIZE(op1);
+        if (likely(__Pyx_sst_abs(size) <= 1)) {
+            a = likely(size) ? digits[0] : 0;
+            if (size == -1) a = -a;
+        } else {
+            switch (size) {
+                case -2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 2:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case -3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 3:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case -4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                case 4:
+                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
+                        break;
+                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
+                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
+                        goto long_long;
+                    }
+                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
+            }
+        }
+                x = a - b;
+            return PyLong_FromLong(x);
+        long_long:
+                llx = lla - llb;
+            return PyLong_FromLongLong(llx);
+    }
+    #endif
+    if (PyFloat_CheckExact(op1)) {
+        const long b = intval;
+        double a = PyFloat_AS_DOUBLE(op1);
+            double result;
+            PyFPE_START_PROTECT("subtract", return NULL)
+            result = ((double)a) - (double)b;
+            PyFPE_END_PROTECT(result)
+            return PyFloat_FromDouble(result);
+    }
+    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
+}
+#endif
+
+static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
+        Py_ssize_t cstart, Py_ssize_t cstop,
         PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
         int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
 #if CYTHON_COMPILING_IN_CPYTHON
@@ -6414,6 +6435,100 @@ return_ne:
 #endif
 }
 
+static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg,
+                                         Py_ssize_t start, Py_ssize_t end, int direction) {
+    const char* self_ptr = PyBytes_AS_STRING(self);
+    Py_ssize_t self_len = PyBytes_GET_SIZE(self);
+    const char* sub_ptr;
+    Py_ssize_t sub_len;
+    int retval;
+    Py_buffer view;
+    view.obj = NULL;
+    if ( PyBytes_Check(arg) ) {
+        sub_ptr = PyBytes_AS_STRING(arg);
+        sub_len = PyBytes_GET_SIZE(arg);
+    }
+#if PY_MAJOR_VERSION < 3
+    else if ( PyUnicode_Check(arg) ) {
+        return (int) PyUnicode_Tailmatch(self, arg, start, end, direction);
+    }
+#endif
+    else {
+        if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1))
+            return -1;
+        sub_ptr = (const char*) view.buf;
+        sub_len = view.len;
+    }
+    if (end > self_len)
+        end = self_len;
+    else if (end < 0)
+        end += self_len;
+    if (end < 0)
+        end = 0;
+    if (start < 0)
+        start += self_len;
+    if (start < 0)
+        start = 0;
+    if (direction > 0) {
+        if (end-sub_len > start)
+            start = end - sub_len;
+    }
+    if (start + sub_len <= end)
+        retval = !memcmp(self_ptr+start, sub_ptr, (size_t)sub_len);
+    else
+        retval = 0;
+    if (view.obj)
+        PyBuffer_Release(&view);
+    return retval;
+}
+static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr,
+                                   Py_ssize_t start, Py_ssize_t end, int direction) {
+    if (unlikely(PyTuple_Check(substr))) {
+        Py_ssize_t i, count = PyTuple_GET_SIZE(substr);
+        for (i = 0; i < count; i++) {
+            int result;
+#if CYTHON_COMPILING_IN_CPYTHON
+            result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substr, i),
+                                                   start, end, direction);
+#else
+            PyObject* sub = PySequence_ITEM(substr, i);
+            if (unlikely(!sub)) return -1;
+            result = __Pyx_PyBytes_SingleTailmatch(self, sub, start, end, direction);
+            Py_DECREF(sub);
+#endif
+            if (result) {
+                return result;
+            }
+        }
+        return 0;
+    }
+    return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction);
+}
+
+static int __Pyx_PyUnicode_Tailmatch(PyObject* s, PyObject* substr,
+                                     Py_ssize_t start, Py_ssize_t end, int direction) {
+    if (unlikely(PyTuple_Check(substr))) {
+        Py_ssize_t i, count = PyTuple_GET_SIZE(substr);
+        for (i = 0; i < count; i++) {
+            Py_ssize_t result;
+#if CYTHON_COMPILING_IN_CPYTHON
+            result = PyUnicode_Tailmatch(s, PyTuple_GET_ITEM(substr, i),
+                                         start, end, direction);
+#else
+            PyObject* sub = PySequence_ITEM(substr, i);
+            if (unlikely(!sub)) return -1;
+            result = PyUnicode_Tailmatch(s, sub, start, end, direction);
+            Py_DECREF(sub);
+#endif
+            if (result) {
+                return (int) result;
+            }
+        }
+        return 0;
+    }
+    return (int) PyUnicode_Tailmatch(s, substr, start, end, direction);
+}
+
 static CYTHON_INLINE int __Pyx_PyStr_Tailmatch(PyObject* self, PyObject* arg, Py_ssize_t start,
                                                Py_ssize_t end, int direction)
 {
@@ -6433,6 +6548,79 @@ static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
     return r;
 }
 
+static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
+    PyObject *empty_list = 0;
+    PyObject *module = 0;
+    PyObject *global_dict = 0;
+    PyObject *empty_dict = 0;
+    PyObject *list;
+    #if PY_VERSION_HEX < 0x03030000
+    PyObject *py_import;
+    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
+    if (!py_import)
+        goto bad;
+    #endif
+    if (from_list)
+        list = from_list;
+    else {
+        empty_list = PyList_New(0);
+        if (!empty_list)
+            goto bad;
+        list = empty_list;
+    }
+    global_dict = PyModule_GetDict(__pyx_m);
+    if (!global_dict)
+        goto bad;
+    empty_dict = PyDict_New();
+    if (!empty_dict)
+        goto bad;
+    {
+        #if PY_MAJOR_VERSION >= 3
+        if (level == -1) {
+            if (strchr(__Pyx_MODULE_NAME, '.')) {
+                #if PY_VERSION_HEX < 0x03030000
+                PyObject *py_level = PyInt_FromLong(1);
+                if (!py_level)
+                    goto bad;
+                module = PyObject_CallFunctionObjArgs(py_import,
+                    name, global_dict, empty_dict, list, py_level, NULL);
+                Py_DECREF(py_level);
+                #else
+                module = PyImport_ImportModuleLevelObject(
+                    name, global_dict, empty_dict, list, 1);
+                #endif
+                if (!module) {
+                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
+                        goto bad;
+                    PyErr_Clear();
+                }
+            }
+            level = 0;
+        }
+        #endif
+        if (!module) {
+            #if PY_VERSION_HEX < 0x03030000
+            PyObject *py_level = PyInt_FromLong(level);
+            if (!py_level)
+                goto bad;
+            module = PyObject_CallFunctionObjArgs(py_import,
+                name, global_dict, empty_dict, list, py_level, NULL);
+            Py_DECREF(py_level);
+            #else
+            module = PyImport_ImportModuleLevelObject(
+                name, global_dict, empty_dict, list, level);
+            #endif
+        }
+    }
+bad:
+    #if PY_VERSION_HEX < 0x03030000
+    Py_XDECREF(py_import);
+    #endif
+    Py_XDECREF(empty_list);
+    Py_XDECREF(empty_dict);
+    return module;
+}
+
 static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
     PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
     if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
@@ -6741,15 +6929,25 @@ __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
 }
 static int
 __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
+    int result = 0;
     PyObject *res = op->defaults_getter((PyObject *) op);
     if (unlikely(!res))
         return -1;
+    #if CYTHON_COMPILING_IN_CPYTHON
     op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
     Py_INCREF(op->defaults_tuple);
     op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
     Py_INCREF(op->defaults_kwdict);
+    #else
+    op->defaults_tuple = PySequence_ITEM(res, 0);
+    if (unlikely(!op->defaults_tuple)) result = -1;
+    else {
+        op->defaults_kwdict = PySequence_ITEM(res, 1);
+        if (unlikely(!op->defaults_kwdict)) result = -1;
+    }
+    #endif
     Py_DECREF(res);
-    return 0;
+    return result;
 }
 static int
 __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
@@ -6997,20 +7195,20 @@ __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
 #if CYTHON_COMPILING_IN_PYPY
 static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
     PyCFunctionObject* f = (PyCFunctionObject*)func;
-    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
-    PyObject *self = PyCFunction_GET_SELF(func);
+    PyCFunction meth = f->m_ml->ml_meth;
+    PyObject *self = f->m_self;
     Py_ssize_t size;
-    switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
+    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
     case METH_VARARGS:
-        if (likely(kw == NULL) || PyDict_Size(kw) == 0)
+        if (likely(kw == NULL || PyDict_Size(kw) == 0))
             return (*meth)(self, arg);
         break;
     case METH_VARARGS | METH_KEYWORDS:
         return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
     case METH_NOARGS:
-        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
             size = PyTuple_GET_SIZE(arg);
-            if (size == 0)
+            if (likely(size == 0))
                 return (*meth)(self, NULL);
             PyErr_Format(PyExc_TypeError,
                 "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
@@ -7019,10 +7217,15 @@ static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject
         }
         break;
     case METH_O:
-        if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
+        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
             size = PyTuple_GET_SIZE(arg);
-            if (size == 1)
-                return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
+            if (likely(size == 1)) {
+                PyObject *result, *arg0 = PySequence_ITEM(arg, 0);
+                if (unlikely(!arg0)) return NULL;
+                result = (*meth)(self, arg0);
+                Py_DECREF(arg0);
+                return result;
+            }
             PyErr_Format(PyExc_TypeError,
                 "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 f->m_ml->ml_name, size);
@@ -7104,7 +7307,7 @@ static PyTypeObject __pyx_CyFunctionType_type = {
     0,
 #endif
 };
-static int __Pyx_CyFunction_init(void) {
+static int __pyx_CyFunction_init(void) {
 #if !CYTHON_COMPILING_IN_PYPY
     __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
 #endif
@@ -7145,7 +7348,7 @@ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int co
         return count;
     }
     while (start < end) {
-        mid = (start + end) / 2;
+        mid = start + (end - start) / 2;
         if (code_line < entries[mid].code_line) {
             end = mid;
         } else if (code_line > entries[mid].code_line) {
@@ -7298,102 +7501,29 @@ bad:
     Py_XDECREF(py_frame);
 }
 
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
-    PyObject *empty_list = 0;
-    PyObject *module = 0;
-    PyObject *global_dict = 0;
-    PyObject *empty_dict = 0;
-    PyObject *list;
-    #if PY_VERSION_HEX < 0x03030000
-    PyObject *py_import;
-    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
-    if (!py_import)
-        goto bad;
-    #endif
-    if (from_list)
-        list = from_list;
-    else {
-        empty_list = PyList_New(0);
-        if (!empty_list)
-            goto bad;
-        list = empty_list;
+#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
+#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
+    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
+#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
+    {\
+        func_type value = func_value;\
+        if (sizeof(target_type) < sizeof(func_type)) {\
+            if (unlikely(value != (func_type) (target_type) value)) {\
+                func_type zero = 0;\
+                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
+                    return (target_type) -1;\
+                if (is_unsigned && unlikely(value < zero))\
+                    goto raise_neg_overflow;\
+                else\
+                    goto raise_overflow;\
+            }\
+        }\
+        return (target_type) value;\
     }
-    global_dict = PyModule_GetDict(__pyx_m);
-    if (!global_dict)
-        goto bad;
-    empty_dict = PyDict_New();
-    if (!empty_dict)
-        goto bad;
-    {
-        #if PY_MAJOR_VERSION >= 3
-        if (level == -1) {
-            if (strchr(__Pyx_MODULE_NAME, '.')) {
-                #if PY_VERSION_HEX < 0x03030000
-                PyObject *py_level = PyInt_FromLong(1);
-                if (!py_level)
-                    goto bad;
-                module = PyObject_CallFunctionObjArgs(py_import,
-                    name, global_dict, empty_dict, list, py_level, NULL);
-                Py_DECREF(py_level);
-                #else
-                module = PyImport_ImportModuleLevelObject(
-                    name, global_dict, empty_dict, list, 1);
-                #endif
-                if (!module) {
-                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
-                        goto bad;
-                    PyErr_Clear();
-                }
-            }
-            level = 0;
-        }
-        #endif
-        if (!module) {
-            #if PY_VERSION_HEX < 0x03030000
-            PyObject *py_level = PyInt_FromLong(level);
-            if (!py_level)
-                goto bad;
-            module = PyObject_CallFunctionObjArgs(py_import,
-                name, global_dict, empty_dict, list, py_level, NULL);
-            Py_DECREF(py_level);
-            #else
-            module = PyImport_ImportModuleLevelObject(
-                name, global_dict, empty_dict, list, level);
-            #endif
-        }
-    }
-bad:
-    #if PY_VERSION_HEX < 0x03030000
-    Py_XDECREF(py_import);
-    #endif
-    Py_XDECREF(empty_list);
-    Py_XDECREF(empty_dict);
-    return module;
-}
-
-#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)       \
-    {                                                                     \
-        func_type value = func_value;                                     \
-        if (sizeof(target_type) < sizeof(func_type)) {                    \
-            if (unlikely(value != (func_type) (target_type) value)) {     \
-                func_type zero = 0;                                       \
-                if (is_unsigned && unlikely(value < zero))                \
-                    goto raise_neg_overflow;                              \
-                else                                                      \
-                    goto raise_overflow;                                  \
-            }                                                             \
-        }                                                                 \
-        return (target_type) value;                                       \
-    }
-
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
-  #include "longintrepr.h"
- #endif
-#endif
 
 static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
-    const int neg_one = (int) -1, const_zero = 0;
+    const int neg_one = (int) -1, const_zero = (int) 0;
     const int is_unsigned = neg_one > const_zero;
 #if PY_MAJOR_VERSION < 3
     if (likely(PyInt_Check(x))) {
@@ -7410,13 +7540,39 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
 #endif
     if (likely(PyLong_Check(x))) {
         if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(int, digit, ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (int) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
+                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
+                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
+                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
 #if CYTHON_COMPILING_IN_CPYTHON
             if (unlikely(Py_SIZE(x) < 0)) {
@@ -7432,24 +7588,77 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
             }
 #endif
             if (sizeof(int) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
             } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
             }
         } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +(((PyLongObject*)x)->ob_digit[0]));
-                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (int) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
+                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
             if (sizeof(int) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
             } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(int, PY_LONG_LONG, PyLong_AsLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
             }
         }
         {
@@ -7498,7 +7707,7 @@ raise_neg_overflow:
 }
 
 static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
-    const long neg_one = (long) -1, const_zero = 0;
+    const long neg_one = (long) -1, const_zero = (long) 0;
     const int is_unsigned = neg_one > const_zero;
     if (is_unsigned) {
         if (sizeof(long) < sizeof(long)) {
@@ -7524,7 +7733,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
 }
 
 static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
-    const long neg_one = (long) -1, const_zero = 0;
+    const long neg_one = (long) -1, const_zero = (long) 0;
     const int is_unsigned = neg_one > const_zero;
 #if PY_MAJOR_VERSION < 3
     if (likely(PyInt_Check(x))) {
@@ -7541,13 +7750,39 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
 #endif
     if (likely(PyLong_Check(x))) {
         if (is_unsigned) {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(long, digit, ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (long) 0;
+                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
+                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
+                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
+                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
 #if CYTHON_COMPILING_IN_CPYTHON
             if (unlikely(Py_SIZE(x) < 0)) {
@@ -7563,24 +7798,77 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
             }
 #endif
             if (sizeof(long) <= sizeof(unsigned long)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
             } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
             }
         } else {
-#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
- #if CYTHON_USE_PYLONG_INTERNALS
+#if CYTHON_USE_PYLONG_INTERNALS
+            const digit* digits = ((PyLongObject*)x)->ob_digit;
             switch (Py_SIZE(x)) {
-                case  0: return 0;
-                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +(((PyLongObject*)x)->ob_digit[0]));
-                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
+                case  0: return (long) 0;
+                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
+                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
+                case -2:
+                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 2:
+                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -3:
+                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 3:
+                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case -4:
+                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
+                case 4:
+                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
+                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
+                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
+                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
+                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
+                        }
+                    }
+                    break;
             }
- #endif
 #endif
             if (sizeof(long) <= sizeof(long)) {
-                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
             } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
-                __PYX_VERIFY_RETURN_INT(long, PY_LONG_LONG, PyLong_AsLongLong(x))
+                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
             }
         }
         {
@@ -7678,18 +7966,16 @@ bad:
     return result;
 }
 
-static PyObject *__Pyx_Generator_Next(PyObject *self);
-static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
-static PyObject *__Pyx_Generator_Close(PyObject *self);
-static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args);
-static PyTypeObject *__pyx_GeneratorType = 0;
-#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
-#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
+#include <structmember.h>
+#include <frameobject.h>
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
+static PyObject *__Pyx_Coroutine_Close(PyObject *self);
+static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
+#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
 #if 1 || PY_VERSION_HEX < 0x030300B0
 static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
     PyObject *et, *ev, *tb;
     PyObject *value = NULL;
-    int result;
     __Pyx_ErrFetch(&et, &ev, &tb);
     if (!et) {
         Py_XDECREF(tb);
@@ -7698,46 +7984,62 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
         *pvalue = Py_None;
         return 0;
     }
-    if (unlikely(et != PyExc_StopIteration) &&
-            unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) {
-        __Pyx_ErrRestore(et, ev, tb);
-        return -1;
-    }
     if (likely(et == PyExc_StopIteration)) {
-        int error = 0;
-        if (!ev || !(error = PyObject_IsInstance(ev, PyExc_StopIteration))) {
+#if PY_VERSION_HEX >= 0x030300A0
+        if (ev && Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
+            value = ((PyStopIterationObject *)ev)->value;
+            Py_INCREF(value);
+            Py_DECREF(ev);
+            Py_XDECREF(tb);
+            Py_DECREF(et);
+            *pvalue = value;
+            return 0;
+        }
+#endif
+        if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
             if (!ev) {
                 Py_INCREF(Py_None);
                 ev = Py_None;
+            } else if (PyTuple_Check(ev)) {
+                if (PyTuple_GET_SIZE(ev) >= 1) {
+                    PyObject *value;
+#if CYTHON_COMPILING_IN_CPYTHON
+                    value = PySequence_ITEM(ev, 0);
+#else
+                    value = PyTuple_GET_ITEM(ev, 0);
+                    Py_INCREF(value);
+#endif
+                    Py_DECREF(ev);
+                    ev = value;
+                } else {
+                    Py_INCREF(Py_None);
+                    Py_DECREF(ev);
+                    ev = Py_None;
+                }
             }
             Py_XDECREF(tb);
             Py_DECREF(et);
             *pvalue = ev;
             return 0;
         }
-        if (unlikely(error == -1)) {
-            return -1;
-        }
+    } else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
+        __Pyx_ErrRestore(et, ev, tb);
+        return -1;
     }
     PyErr_NormalizeException(&et, &ev, &tb);
-    result = PyObject_IsInstance(ev, PyExc_StopIteration);
-    if (unlikely(!result)) {
+    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
         __Pyx_ErrRestore(et, ev, tb);
         return -1;
     }
     Py_XDECREF(tb);
     Py_DECREF(et);
-    if (unlikely(result == -1)) {
-        Py_DECREF(ev);
-        return -1;
-    }
 #if PY_VERSION_HEX >= 0x030300A0
     value = ((PyStopIterationObject *)ev)->value;
     Py_INCREF(value);
     Py_DECREF(ev);
 #else
     {
-        PyObject* args = PyObject_GetAttr(ev, __pyx_n_s_args);
+        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
         Py_DECREF(ev);
         if (likely(args)) {
             value = PySequence_GetItem(args, 0);
@@ -7755,7 +8057,7 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
 }
 #endif
 static CYTHON_INLINE
-void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
+void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) {
     PyObject *exc_type = self->exc_type;
     PyObject *exc_value = self->exc_value;
     PyObject *exc_traceback = self->exc_traceback;
@@ -7767,7 +8069,7 @@ void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
     Py_XDECREF(exc_traceback);
 }
 static CYTHON_INLINE
-int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
+int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) {
     if (unlikely(gen->is_running)) {
         PyErr_SetString(PyExc_ValueError,
                         "generator already executing");
@@ -7776,7 +8078,7 @@ int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
     return 0;
 }
 static CYTHON_INLINE
-PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
+PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
     PyObject *retval;
     assert(!self->is_running);
     if (unlikely(self->resume_label == 0)) {
@@ -7806,7 +8108,7 @@ PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
         __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                             &self->exc_traceback);
     } else {
-        __Pyx_Generator_ExceptionClear(self);
+        __Pyx_Coroutine_ExceptionClear(self);
     }
     self->is_running = 1;
     retval = self->body((PyObject *) self, value);
@@ -7823,56 +8125,47 @@ PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
         }
 #endif
     } else {
-        __Pyx_Generator_ExceptionClear(self);
+        __Pyx_Coroutine_ExceptionClear(self);
     }
     return retval;
 }
 static CYTHON_INLINE
-PyObject *__Pyx_Generator_MethodReturn(PyObject *retval) {
+PyObject *__Pyx_Coroutine_MethodReturn(PyObject *retval) {
     if (unlikely(!retval && !PyErr_Occurred())) {
         PyErr_SetNone(PyExc_StopIteration);
     }
     return retval;
 }
 static CYTHON_INLINE
-PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) {
+PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
     PyObject *ret;
     PyObject *val = NULL;
-    __Pyx_Generator_Undelegate(gen);
+    __Pyx_Coroutine_Undelegate(gen);
     __Pyx_PyGen_FetchStopIterationValue(&val);
-    ret = __Pyx_Generator_SendEx(gen, val);
+    ret = __Pyx_Coroutine_SendEx(gen, val);
     Py_XDECREF(val);
     return ret;
 }
-static PyObject *__Pyx_Generator_Next(PyObject *self) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
-    PyObject *yf = gen->yieldfrom;
-    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
-        return NULL;
-    if (yf) {
-        PyObject *ret;
-        gen->is_running = 1;
-        ret = Py_TYPE(yf)->tp_iternext(yf);
-        gen->is_running = 0;
-        if (likely(ret)) {
-            return ret;
-        }
-        return __Pyx_Generator_FinishDelegation(gen);
-    }
-    return __Pyx_Generator_SendEx(gen, Py_None);
-}
-static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
+static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
     PyObject *retval;
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
     PyObject *yf = gen->yieldfrom;
-    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
         return NULL;
     if (yf) {
         PyObject *ret;
         gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
         if (__Pyx_Generator_CheckExact(yf)) {
-            ret = __Pyx_Generator_Send(yf, value);
-        } else {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Send(yf, value);
+        } else
+        #endif
+        {
             if (value == Py_None)
                 ret = PyIter_Next(yf);
             else
@@ -7882,23 +8175,33 @@ static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
         if (likely(ret)) {
             return ret;
         }
-        retval = __Pyx_Generator_FinishDelegation(gen);
+        retval = __Pyx_Coroutine_FinishDelegation(gen);
     } else {
-        retval = __Pyx_Generator_SendEx(gen, value);
+        retval = __Pyx_Coroutine_SendEx(gen, value);
     }
-    return __Pyx_Generator_MethodReturn(retval);
+    return __Pyx_Coroutine_MethodReturn(retval);
 }
-static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
+static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
     PyObject *retval = NULL;
     int err = 0;
+    #ifdef __Pyx_Generator_USED
     if (__Pyx_Generator_CheckExact(yf)) {
-        retval = __Pyx_Generator_Close(yf);
+        retval = __Pyx_Coroutine_Close(yf);
         if (!retval)
             return -1;
-    } else {
+    } else
+    #endif
+    #ifdef __Pyx_Coroutine_USED
+    if (__Pyx_Coroutine_CheckExact(yf)) {
+        retval = __Pyx_Coroutine_Close(yf);
+        if (!retval)
+            return -1;
+    } else
+    #endif
+    {
         PyObject *meth;
         gen->is_running = 1;
-        meth = PyObject_GetAttr(yf, __pyx_n_s_close);
+        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
         if (unlikely(!meth)) {
             if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                 PyErr_WriteUnraisable(yf);
@@ -7915,22 +8218,39 @@ static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
     Py_XDECREF(retval);
     return err;
 }
-static PyObject *__Pyx_Generator_Close(PyObject *self) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+static PyObject *__Pyx_Generator_Next(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
+    PyObject *yf = gen->yieldfrom;
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
+        return NULL;
+    if (yf) {
+        PyObject *ret;
+        gen->is_running = 1;
+        ret = Py_TYPE(yf)->tp_iternext(yf);
+        gen->is_running = 0;
+        if (likely(ret)) {
+            return ret;
+        }
+        return __Pyx_Coroutine_FinishDelegation(gen);
+    }
+    return __Pyx_Coroutine_SendEx(gen, Py_None);
+}
+static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     PyObject *retval, *raised_exception;
     PyObject *yf = gen->yieldfrom;
     int err = 0;
-    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
         return NULL;
     if (yf) {
         Py_INCREF(yf);
-        err = __Pyx_Generator_CloseIter(gen, yf);
-        __Pyx_Generator_Undelegate(gen);
+        err = __Pyx_Coroutine_CloseIter(gen, yf);
+        __Pyx_Coroutine_Undelegate(gen);
         Py_DECREF(yf);
     }
     if (err == 0)
         PyErr_SetNone(PyExc_GeneratorExit);
-    retval = __Pyx_Generator_SendEx(gen, NULL);
+    retval = __Pyx_Coroutine_SendEx(gen, NULL);
     if (retval) {
         Py_DECREF(retval);
         PyErr_SetString(PyExc_RuntimeError,
@@ -7950,32 +8270,40 @@ static PyObject *__Pyx_Generator_Close(PyObject *self) {
     }
     return NULL;
 }
-static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     PyObject *typ;
     PyObject *tb = NULL;
     PyObject *val = NULL;
     PyObject *yf = gen->yieldfrom;
     if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
         return NULL;
-    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
+    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
         return NULL;
     if (yf) {
         PyObject *ret;
         Py_INCREF(yf);
         if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
-            int err = __Pyx_Generator_CloseIter(gen, yf);
+            int err = __Pyx_Coroutine_CloseIter(gen, yf);
             Py_DECREF(yf);
-            __Pyx_Generator_Undelegate(gen);
+            __Pyx_Coroutine_Undelegate(gen);
             if (err < 0)
-                return __Pyx_Generator_MethodReturn(__Pyx_Generator_SendEx(gen, NULL));
+                return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
             goto throw_here;
         }
         gen->is_running = 1;
+        #ifdef __Pyx_Generator_USED
         if (__Pyx_Generator_CheckExact(yf)) {
-            ret = __Pyx_Generator_Throw(yf, args);
-        } else {
-            PyObject *meth = PyObject_GetAttr(yf, __pyx_n_s_throw);
+            ret = __Pyx_Coroutine_Throw(yf, args);
+        } else
+        #endif
+        #ifdef __Pyx_Coroutine_USED
+        if (__Pyx_Coroutine_CheckExact(yf)) {
+            ret = __Pyx_Coroutine_Throw(yf, args);
+        } else
+        #endif
+        {
+            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
             if (unlikely(!meth)) {
                 Py_DECREF(yf);
                 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
@@ -7983,7 +8311,7 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
                     return NULL;
                 }
                 PyErr_Clear();
-                __Pyx_Generator_Undelegate(gen);
+                __Pyx_Coroutine_Undelegate(gen);
                 gen->is_running = 0;
                 goto throw_here;
             }
@@ -7993,16 +8321,16 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
         gen->is_running = 0;
         Py_DECREF(yf);
         if (!ret) {
-            ret = __Pyx_Generator_FinishDelegation(gen);
+            ret = __Pyx_Coroutine_FinishDelegation(gen);
         }
-        return __Pyx_Generator_MethodReturn(ret);
+        return __Pyx_Coroutine_MethodReturn(ret);
     }
 throw_here:
     __Pyx_Raise(typ, val, tb, NULL);
-    return __Pyx_Generator_MethodReturn(__Pyx_Generator_SendEx(gen, NULL));
+    return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
 }
-static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+static int __Pyx_Coroutine_traverse(PyObject *self, visitproc visit, void *arg) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     Py_VISIT(gen->closure);
     Py_VISIT(gen->classobj);
     Py_VISIT(gen->yieldfrom);
@@ -8011,8 +8339,8 @@ static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg)
     Py_VISIT(gen->exc_traceback);
     return 0;
 }
-static int __Pyx_Generator_clear(PyObject *self) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+static int __Pyx_Coroutine_clear(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     Py_CLEAR(gen->closure);
     Py_CLEAR(gen->classobj);
     Py_CLEAR(gen->yieldfrom);
@@ -8023,8 +8351,8 @@ static int __Pyx_Generator_clear(PyObject *self) {
     Py_CLEAR(gen->gi_qualname);
     return 0;
 }
-static void __Pyx_Generator_dealloc(PyObject *self) {
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+static void __Pyx_Coroutine_dealloc(PyObject *self) {
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     PyObject_GC_UnTrack(gen);
     if (gen->gi_weakreflist != NULL)
         PyObject_ClearWeakRefs(self);
@@ -8041,13 +8369,13 @@ static void __Pyx_Generator_dealloc(PyObject *self) {
         }
         PyObject_GC_UnTrack(self);
     }
-    __Pyx_Generator_clear(self);
+    __Pyx_Coroutine_clear(self);
     PyObject_GC_Del(gen);
 }
-static void __Pyx_Generator_del(PyObject *self) {
+static void __Pyx_Coroutine_del(PyObject *self) {
     PyObject *res;
     PyObject *error_type, *error_value, *error_traceback;
-    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
+    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
     if (gen->resume_label <= 0)
         return ;
 #if PY_VERSION_HEX < 0x030400a1
@@ -8055,7 +8383,7 @@ static void __Pyx_Generator_del(PyObject *self) {
     self->ob_refcnt = 1;
 #endif
     __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
-    res = __Pyx_Generator_Close(self);
+    res = __Pyx_Coroutine_Close(self);
     if (res == NULL)
         PyErr_WriteUnraisable(self);
     else
@@ -8083,13 +8411,13 @@ static void __Pyx_Generator_del(PyObject *self) {
 #endif
 }
 static PyObject *
-__Pyx_Generator_get_name(__pyx_GeneratorObject *self)
+__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self)
 {
     Py_INCREF(self->gi_name);
     return self->gi_name;
 }
 static int
-__Pyx_Generator_set_name(__pyx_GeneratorObject *self, PyObject *value)
+__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value)
 {
     PyObject *tmp;
 #if PY_MAJOR_VERSION >= 3
@@ -8108,13 +8436,13 @@ __Pyx_Generator_set_name(__pyx_GeneratorObject *self, PyObject *value)
     return 0;
 }
 static PyObject *
-__Pyx_Generator_get_qualname(__pyx_GeneratorObject *self)
+__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
 {
     Py_INCREF(self->gi_qualname);
     return self->gi_qualname;
 }
 static int
-__Pyx_Generator_set_qualname(__pyx_GeneratorObject *self, PyObject *value)
+__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value)
 {
     PyObject *tmp;
 #if PY_MAJOR_VERSION >= 3
@@ -8132,37 +8460,154 @@ __Pyx_Generator_set_qualname(__pyx_GeneratorObject *self, PyObject *value)
     Py_XDECREF(tmp);
     return 0;
 }
-static PyGetSetDef __pyx_Generator_getsets[] = {
-    {(char *) "__name__", (getter)__Pyx_Generator_get_name, (setter)__Pyx_Generator_set_name,
-     (char*) PyDoc_STR("name of the generator"), 0},
-    {(char *) "__qualname__", (getter)__Pyx_Generator_get_qualname, (setter)__Pyx_Generator_set_qualname,
-     (char*) PyDoc_STR("qualified name of the generator"), 0},
-    {0, 0, 0, 0, 0}
+static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject* type, __pyx_coroutine_body_t body,
+                                                   PyObject *closure, PyObject *name, PyObject *qualname) {
+    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
+    if (gen == NULL)
+        return NULL;
+    gen->body = body;
+    gen->closure = closure;
+    Py_XINCREF(closure);
+    gen->is_running = 0;
+    gen->resume_label = 0;
+    gen->classobj = NULL;
+    gen->yieldfrom = NULL;
+    gen->exc_type = NULL;
+    gen->exc_value = NULL;
+    gen->exc_traceback = NULL;
+    gen->gi_weakreflist = NULL;
+    Py_XINCREF(qualname);
+    gen->gi_qualname = qualname;
+    Py_XINCREF(name);
+    gen->gi_name = name;
+    PyObject_GC_Track(gen);
+    return gen;
+}
+
+static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    int result;
+    PyObject *globals, *result_obj;
+    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
+    #ifdef __Pyx_Coroutine_USED
+        (PyObject*)__pyx_CoroutineType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    result = PyDict_SetItemString(globals, "_cython_generator_type",
+    #ifdef __Pyx_Generator_USED
+        (PyObject*)__pyx_GeneratorType);
+    #else
+        Py_None);
+    #endif
+    if (unlikely(result < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
+    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
+    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
+    if (unlikely(!result_obj)) goto ignore;
+    Py_DECREF(result_obj);
+    Py_DECREF(globals);
+    return module;
+ignore:
+    Py_XDECREF(globals);
+    PyErr_WriteUnraisable(module);
+    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
+        Py_DECREF(module);
+        module = NULL;
+    }
+#else
+    py_code++;
+#endif
+    return module;
+}
+
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+static PyObject* __Pyx_patch_abc_module(PyObject *module);
+static PyObject* __Pyx_patch_abc_module(PyObject *module) {
+    module = __Pyx_Coroutine_patch_module(
+        module, ""
+"if _cython_generator_type is not None:\n"
+"    try: Generator = _module.Generator\n"
+"    except AttributeError: pass\n"
+"    else: Generator.register(_cython_generator_type)\n"
+"if _cython_coroutine_type is not None:\n"
+"    try: Coroutine = _module.Coroutine\n"
+"    except AttributeError: pass\n"
+"    else: Coroutine.register(_cython_coroutine_type)\n"
+    );
+    return module;
+}
+#endif
+static int __Pyx_patch_abc(void) {
+#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
+    static int abc_patched = 0;
+    if (!abc_patched) {
+        PyObject *module;
+        module = PyImport_ImportModule((PY_VERSION_HEX >= 0x03030000) ? "collections.abc" : "collections");
+        if (!module) {
+            PyErr_WriteUnraisable(NULL);
+            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
+                    ((PY_VERSION_HEX >= 0x03030000) ?
+                        "Cython module failed to register with collections.abc module" :
+                        "Cython module failed to register with collections module"), 1) < 0)) {
+                return -1;
+            }
+        } else {
+            module = __Pyx_patch_abc_module(module);
+            abc_patched = 1;
+            if (unlikely(!module))
+                return -1;
+            Py_DECREF(module);
+        }
+        module = PyImport_ImportModule("backports_abc");
+        if (module) {
+            module = __Pyx_patch_abc_module(module);
+            Py_XDECREF(module);
+        }
+        if (!module) {
+            PyErr_Clear();
+        }
+    }
+#else
+    if (0) __Pyx_Coroutine_patch_module(NULL, NULL);
+#endif
+    return 0;
+}
+
+static PyMethodDef __pyx_Generator_methods[] = {
+    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
+     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
+    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
+     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
+    {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS,
+     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
+    {0, 0, 0, 0}
 };
 static PyMemberDef __pyx_Generator_memberlist[] = {
-    {(char *) "gi_running", T_BOOL, offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL},
+    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
+    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
+     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
     {0, 0, 0, 0, 0}
 };
-static PyMethodDef __pyx_Generator_methods[] = {
-    {"send", (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
-    {"throw", (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
-    {"close", (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
-    {0, 0, 0, 0}
+static PyGetSetDef __pyx_Generator_getsets[] = {
+    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
+     (char*) PyDoc_STR("name of the generator"), 0},
+    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
+     (char*) PyDoc_STR("qualified name of the generator"), 0},
+    {0, 0, 0, 0, 0}
 };
 static PyTypeObject __pyx_GeneratorType_type = {
     PyVarObject_HEAD_INIT(0, 0)
     "generator",
-    sizeof(__pyx_GeneratorObject),
+    sizeof(__pyx_CoroutineObject),
     0,
-    (destructor) __Pyx_Generator_dealloc,
+    (destructor) __Pyx_Coroutine_dealloc,
     0,
     0,
     0,
-#if PY_MAJOR_VERSION < 3
     0,
-#else
-    0,
-#endif
     0,
     0,
     0,
@@ -8175,10 +8620,10 @@ static PyTypeObject __pyx_GeneratorType_type = {
     0,
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
     0,
-    (traverseproc) __Pyx_Generator_traverse,
+    (traverseproc) __Pyx_Coroutine_traverse,
     0,
     0,
-    offsetof(__pyx_GeneratorObject, gi_weakreflist),
+    offsetof(__pyx_CoroutineObject, gi_weakreflist),
     0,
     (iternextfunc) __Pyx_Generator_Next,
     __pyx_Generator_methods,
@@ -8202,42 +8647,18 @@ static PyTypeObject __pyx_GeneratorType_type = {
 #if PY_VERSION_HEX >= 0x030400a1
     0,
 #else
-    __Pyx_Generator_del,
+    __Pyx_Coroutine_del,
 #endif
     0,
 #if PY_VERSION_HEX >= 0x030400a1
-    __Pyx_Generator_del,
+    __Pyx_Coroutine_del,
 #endif
 };
-static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
-                                                  PyObject *closure, PyObject *name, PyObject *qualname) {
-    __pyx_GeneratorObject *gen =
-        PyObject_GC_New(__pyx_GeneratorObject, __pyx_GeneratorType);
-    if (gen == NULL)
-        return NULL;
-    gen->body = body;
-    gen->closure = closure;
-    Py_XINCREF(closure);
-    gen->is_running = 0;
-    gen->resume_label = 0;
-    gen->classobj = NULL;
-    gen->yieldfrom = NULL;
-    gen->exc_type = NULL;
-    gen->exc_value = NULL;
-    gen->exc_traceback = NULL;
-    gen->gi_weakreflist = NULL;
-    Py_XINCREF(qualname);
-    gen->gi_qualname = qualname;
-    Py_XINCREF(name);
-    gen->gi_name = name;
-    PyObject_GC_Track(gen);
-    return gen;
-}
 static int __pyx_Generator_init(void) {
     __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
     __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
     __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
-    if (__pyx_GeneratorType == NULL) {
+    if (unlikely(!__pyx_GeneratorType)) {
         return -1;
     }
     return 0;
@@ -8296,7 +8717,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
     return __Pyx_PyObject_AsStringAndSize(o, &ignore);
 }
 static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
-#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
+#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
     if (
 #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
             __Pyx_sys_getdefaultencoding_not_ascii &&
@@ -8337,7 +8758,7 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_
 #endif
     } else
 #endif
-#if !CYTHON_COMPILING_IN_PYPY
+#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
     if (PyByteArray_Check(o)) {
         *length = PyByteArray_GET_SIZE(o);
         return PyByteArray_AS_STRING(o);
@@ -8367,7 +8788,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
 #else
   if (PyLong_Check(x))
 #endif
-    return Py_INCREF(x), x;
+    return __Pyx_NewRef(x);
   m = Py_TYPE(x)->tp_as_number;
 #if PY_MAJOR_VERSION < 3
   if (m && m->nb_int) {
@@ -8407,18 +8828,55 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
   Py_ssize_t ival;
   PyObject *x;
 #if PY_MAJOR_VERSION < 3
-  if (likely(PyInt_CheckExact(b)))
-      return PyInt_AS_LONG(b);
+  if (likely(PyInt_CheckExact(b))) {
+    if (sizeof(Py_ssize_t) >= sizeof(long))
+        return PyInt_AS_LONG(b);
+    else
+        return PyInt_AsSsize_t(x);
+  }
 #endif
   if (likely(PyLong_CheckExact(b))) {
-    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
-     #if CYTHON_USE_PYLONG_INTERNALS
-       switch (Py_SIZE(b)) {
-       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
-       case  0: return 0;
-       case  1: return ((PyLongObject*)b)->ob_digit[0];
-       }
-     #endif
+    #if CYTHON_USE_PYLONG_INTERNALS
+    const digit* digits = ((PyLongObject*)b)->ob_digit;
+    const Py_ssize_t size = Py_SIZE(b);
+    if (likely(__Pyx_sst_abs(size) <= 1)) {
+        ival = likely(size) ? digits[0] : 0;
+        if (size == -1) ival = -ival;
+        return ival;
+    } else {
+      switch (size) {
+         case 2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -2:
+           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -3:
+           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case 4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+         case -4:
+           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
+             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
+           }
+           break;
+      }
+    }
     #endif
     return PyLong_AsSsize_t(b);
   }
diff --git a/cutadapt/_seqio.pyx b/cutadapt/_seqio.pyx
index 80d9249..add0442 100644
--- a/cutadapt/_seqio.pyx
+++ b/cutadapt/_seqio.pyx
@@ -29,22 +29,22 @@ cdef class Sequence(object):
 	ascii(qual+33).
 
 	If an adapter has been matched to the sequence, the 'match' attribute is
-	set to the corresponding AdapterMatch instance.
+	set to the corresponding Match instance.
 	"""
 	cdef:
 		public str name
 		public str sequence
 		public str qualities
+		public str name2
 		public object match
-		public bint twoheaders
 
-	def __init__(self, str name, str sequence, str qualities=None,
-			  bint twoheaders=False, match=None):
+	def __init__(self, str name, str sequence, str qualities=None, str name2='',
+			match=None):
 		"""Set qualities to None if there are no quality values"""
 		self.name = name
 		self.sequence = sequence
 		self.qualities = qualities
-		self.twoheaders = twoheaders
+		self.name2 = name2
 		self.match = match
 		if qualities is not None and len(qualities) != len(sequence):
 			rname = _shorten(name)
@@ -57,7 +57,7 @@ cdef class Sequence(object):
 			self.name,
 			self.sequence[key],
 			self.qualities[key] if self.qualities is not None else None,
-			self.twoheaders,
+			self.name2,
 			self.match)
 
 	def __repr__(self):
@@ -82,55 +82,40 @@ cdef class Sequence(object):
 			raise NotImplementedError()
 
 	def __reduce__(self):
-		return (Sequence, (self.name, self.sequence, self.qualities, self.twoheaders))
-
-	def write(self, outfile):
-		if self.qualities is not None:
-			s = '@' + self.name + '\n' + self.sequence + '\n+'
-			if self.twoheaders:
-				s += self.name
-			s += '\n' + self.qualities + '\n'
-		else:
-			s = '>' + self.name + '\n' + self.sequence + '\n'
-		outfile.write(s)
+		return (Sequence, (self.name, self.sequence, self.qualities, self.name2))
 
 
 class FastqReader(object):
 	"""
 	Reader for FASTQ files. Does not support multi-line FASTQ files.
 	"""
+	_close_on_exit = False
+
 	def __init__(self, file, sequence_class=Sequence):
 		"""
 		file is a filename or a file-like object.
 		If file is a filename, then .gz files are supported.
-
-		colorspace -- Usually (when this is False), there must be n characters in the sequence and
-		n quality values. When this is True, there must be n+1 characters in the sequence and n quality values.
 		"""
 		if isinstance(file, basestring):
 			file = xopen(file)
-			self._file_passed = False
-		else:
-			self._file_passed = True
-		self.fp = file
+			self._close_on_exit = True
+		self._file = file
 		self.sequence_class = sequence_class
 		self.delivers_qualities = True
 
 	def __iter__(self):
 		"""
-		Return tuples: (name, sequence, qualities).
-		qualities is a string and it contains the unmodified, encoded qualities.
+		Yield Sequence objects
 		"""
 		cdef int i = 0
 		cdef int strip
-		cdef str line, name, qualities, sequence
-		cdef bint twoheaders
+		cdef str line, name, qualities, sequence, name2
 		sequence_class = self.sequence_class
 
-		it = iter(self.fp)
+		it = iter(self._file)
 		line = next(it)
 		if not (line and line[0] == '@'):
-			raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+			raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
 		strip = -2 if line.endswith('\r\n') else -1
 		name = line[1:strip]
 
@@ -138,19 +123,18 @@ class FastqReader(object):
 		for line in it:
 			if i == 0:
 				if not (line and line[0] == '@'):
-					raise FormatError("at line {0}, expected a line starting with '@'".format(i+1))
+					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
 				name = line[1:strip]
 			elif i == 1:
 				sequence = line[:strip]
 			elif i == 2:
 				if line == '+\n':  # check most common case first
-					twoheaders = False
+					name2 = ''
 				else:
 					line = line[:strip]
 					if not (line and line[0] == '+'):
-						raise FormatError("at line {0}, expected a line starting with '+'".format(i+1))
+						raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
 					if len(line) > 1:
-						twoheaders = True
 						if not line[1:] == name:
 							raise FormatError(
 								"At line {0}: Sequence descriptions in the FASTQ file don't match "
@@ -158,25 +142,26 @@ class FastqReader(object):
 								"The second sequence description must be either empty "
 								"or equal to the first description.".format(i+1,
 									name, line[1:]))
+						name2 = name
 					else:
-						twoheaders = False
+						name2 = ''
 			elif i == 3:
 				if len(line) == len(sequence) - strip:
 					qualities = line[:strip]
 				else:
 					qualities = line.rstrip('\r\n')
-				yield sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+				yield sequence_class(name, sequence, qualities, name2=name2)
 			i = (i + 1) % 4
 		if i != 0:
 			raise FormatError("FASTQ file ended prematurely")
 
 	def close(self):
-		if not self._file_passed and self.fp is not None:
-			self.fp.close()
-			self.fp = None
+		if self._close_on_exit and self._file is not None:
+			self._file.close()
+			self._file = None
 
 	def __enter__(self):
-		if self.fp is None:
+		if self._file is None:
 			raise ValueError("I/O operation on closed FastqReader")
 		return self
 
diff --git a/cutadapt/_seqio.so b/cutadapt/_seqio.so
index fbbf139..d1e8af2 100755
Binary files a/cutadapt/_seqio.so and b/cutadapt/_seqio.so differ
diff --git a/cutadapt/adapters.py b/cutadapt/adapters.py
index 5267967..737da4b 100644
--- a/cutadapt/adapters.py
+++ b/cutadapt/adapters.py
@@ -41,9 +41,51 @@ def parse_adapter(sequence, where):
 		return (sequence[1:], PREFIX)
 	if where == BACK and sequence.endswith('$'):
 		return (sequence[:-1], SUFFIX)
+	if where == BACK and sequence.endswith('...'):
+		return (sequence[:-3], PREFIX)
 	return (sequence, where)
 
 
+def parse_braces(sequence):
+	"""
+	Replace all occurrences of ``x{n}`` (where x is any character) with n
+	occurrences of x. Raise ValueError if the expression cannot be parsed.
+
+	>>> parse_braces('TGA{5}CT')
+	TGAAAAACT
+	"""
+	# Simple DFA with four states, encoded in prev
+	result = ''
+	prev = None
+	for s in re.split('(\{|\})', sequence):
+		if s == '':
+			continue
+		if prev is None:
+			if s == '{':
+				raise ValueError('"{" must be used after a character')
+			if s == '}':
+				raise ValueError('"}" cannot be used here')
+			prev = s
+			result += s
+		elif prev == '{':
+			prev = int(s)
+			if not 0 <= prev <= 10000:
+				raise ValueError('Value {} invalid'.format(prev))
+		elif isinstance(prev, int):
+			if s != '}':
+				raise ValueError('"}" expected')
+			result = result[:-1] + result[-1] * prev
+			prev = None
+		else:
+			if s != '{':
+				raise ValueError('Expected "{"')
+			prev = '{'
+	# Check if we are in a non-terminating state
+	if isinstance(prev, int) or prev == '{':
+		raise ValueError("Unterminated expression")
+	return result
+
+
 def gather_adapters(back, anywhere, front):
 	"""
 	Yield (name, seq, where) tuples from which Adapter instances can be built.
@@ -67,7 +109,7 @@ def gather_adapters(back, anywhere, front):
 				yield (name, seq, w)
 
 
-class AdapterMatch(object):
+class Match(object):
 	"""
 	TODO creating instances of this class is relatively slow and responsible for quite some runtime.
 	"""
@@ -88,7 +130,7 @@ class AdapterMatch(object):
 		self.length = self.astop - self.astart
 
 	def __str__(self):
-		return 'AdapterMatch(astart={0}, astop={1}, rstart={2}, rstop={3}, matches={4}, errors={5})'.format(
+		return 'Match(astart={0}, astop={1}, rstart={2}, rstop={3}, matches={4}, errors={5})'.format(
 			self.astart, self.astop, self.rstart, self.rstop, self.matches, self.errors)
 
 	def _guess_is_front(self):
@@ -126,6 +168,12 @@ class AdapterMatch(object):
 			return self.read.sequence[self.rstop:]
 
 
+def generate_adapter_name(_start=[1]):
+	name = str(_start[0])
+	_start[0] += 1
+	return name
+
+
 class Adapter(object):
 	"""
 	An adapter knows how to match itself to a read.
@@ -154,31 +202,18 @@ class Adapter(object):
 	name -- optional name of the adapter. If not provided, the name is set to a
 		unique number.
 	"""
-	automatic_name = 1
-
 	def __init__(self, sequence, where, max_error_rate, min_overlap=3,
 			read_wildcards=False, adapter_wildcards=True,
 			name=None, indels=True):
-		if name is None:
-			self.name = str(self.__class__.automatic_name)
-			self.__class__.automatic_name += 1
-			self.name_is_generated = True
-		else:
-			self.name = name
-			self.name_is_generated = False
-
-		self.sequence = self.parse_braces(sequence.upper().replace('U', 'T'))
+		self.debug = False
+		self.name = generate_adapter_name() if name is None else name
+		self.sequence = parse_braces(sequence.upper().replace('U', 'T'))
 		self.where = where
 		self.max_error_rate = max_error_rate
-		self.min_overlap = min_overlap
+		self.min_overlap = min(min_overlap, len(self.sequence))
 		self.indels = indels
-		assert where in (PREFIX, SUFFIX) or self.indels
-		self.wildcard_flags = 0
 		self.adapter_wildcards = adapter_wildcards and not set(self.sequence) <= set('ACGT')
-		if read_wildcards:
-			self.wildcard_flags |= align.ALLOW_WILDCARD_SEQ2
-		if self.adapter_wildcards:
-			self.wildcard_flags |= align.ALLOW_WILDCARD_SEQ1
+		self.read_wildcards = read_wildcards
 		# redirect trimmed() to appropriate function depending on adapter type
 		trimmers = {
 			FRONT: self._trimmed_front,
@@ -200,64 +235,36 @@ class Adapter(object):
 		self.adjacent_bases = { 'A': 0, 'C': 0, 'G': 0, 'T': 0, '': 0 }
 
 		self.aligner = align.Aligner(self.sequence, self.max_error_rate,
-			flags=self.where, degenerate=self.wildcard_flags,
-			min_overlap=self.min_overlap)
+			flags=self.where, wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
+		self.aligner.min_overlap = self.min_overlap
+		if not self.indels:
+			# TODO
+			# When indels are disallowed, an entirely different algorithm
+			# should be used.
+			self.aligner.indel_cost = 100000
 
 	def __repr__(self):
-		read_wildcards = bool(align.ALLOW_WILDCARD_SEQ2 & self.wildcard_flags)
 		return '<Adapter(name="{name}", sequence="{sequence}", where={where}, '\
 			'max_error_rate={max_error_rate}, min_overlap={min_overlap}, '\
 			'read_wildcards={read_wildcards}, '\
 			'adapter_wildcards={adapter_wildcards}, '\
-			'indels={indels})>'.format(
-				read_wildcards=read_wildcards,
-				**vars(self))
+			'indels={indels})>'.format(**vars(self))
 
-	@staticmethod
-	def parse_braces(sequence):
+	def enable_debug(self):
 		"""
-		Replace all occurrences of ``x{n}`` (where x is any character) with n
-		occurrences of x. Raise ValueError if the expression cannot be parsed.
-
-		>>> parse_braces('TGA{5}CT')
-		TGAAAAACT
+		Print out the dynamic programming matrix after matching a read to an
+		adapter.
 		"""
-		# Simple DFA with four states, encoded in prev
-		result = ''
-		prev = None
-		for s in re.split('(\{|\})', sequence):
-			if s == '':
-				continue
-			if prev is None:
-				if s == '{':
-					raise ValueError('"{" must be used after a character')
-				if s == '}':
-					raise ValueError('"}" cannot be used here')
-				prev = s
-				result += s
-			elif prev == '{':
-				prev = int(s)
-				if not 0 <= prev <= 10000:
-					raise ValueError('Value {} invalid'.format(prev))
-			elif isinstance(prev, int):
-				if s != '}':
-					raise ValueError('"}" expected')
-				result = result[:-1] + result[-1] * prev
-				prev = None
-			else:
-				if s != '{':
-					raise ValueError('Expected "{"')
-				prev = '{'
-		# Check if we are in a non-terminating state
-		if isinstance(prev, int) or prev == '{':
-			raise ValueError("Unterminated expression")
-		return result
+		self.debug = True
+		self.aligner.enable_debug()
 
 	def match_to(self, read):
 		"""
-		Try to match this adapter to the given read and return an AdapterMatch instance.
+		Attempt to match this adapter to the given read.
 
-		Return None if the minimum overlap length is not met or the error rate is too high.
+		Return an Match instance if a match was found;
+		return None if no match was found given the matching criteria (minimum
+		overlap length, maximum error rate).
 		"""
 		read_seq = read.sequence.upper()
 		pos = -1
@@ -270,29 +277,32 @@ class Adapter(object):
 			else:
 				pos = read_seq.find(self.sequence)
 		if pos >= 0:
-			match = AdapterMatch(
+			match = Match(
 				0, len(self.sequence), pos, pos + len(self.sequence),
 				len(self.sequence), 0, self._front_flag, self, read)
 		else:
 			# try approximate matching
-			if not self.indels:
-				assert self.where in (PREFIX, SUFFIX)
+			if not self.indels and self.where in (PREFIX, SUFFIX):
 				if self.where == PREFIX:
-					alignment = align.compare_prefixes(self.sequence, read_seq, self.wildcard_flags)
+					alignment = align.compare_prefixes(self.sequence, read_seq,
+						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
 				else:
-					alignment = align.compare_suffixes(self.sequence, read_seq, self.wildcard_flags)
+					alignment = align.compare_suffixes(self.sequence, read_seq,
+						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
 				astart, astop, rstart, rstop, matches, errors = alignment
 				if astop - astart >= self.min_overlap and errors / (astop - astart) <= self.max_error_rate:
-					match = AdapterMatch(*(alignment + (self._front_flag, self, read)))
+					match = Match(*(alignment + (self._front_flag, self, read)))
 				else:
 					match = None
 			else:
 				alignment = self.aligner.locate(read_seq)
+				if self.debug:
+					print(self.aligner.dpmatrix)  # pragma: no cover
 				if alignment is None:
 					match = None
 				else:
 					astart, astop, rstart, rstop, matches, errors = alignment
-					match = AdapterMatch(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)
+					match = Match(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)
 
 		if match is None:
 			return None
@@ -343,7 +353,7 @@ class ColorspaceAdapter(Adapter):
 		self.aligner.reference = self.sequence
 
 	def match_to(self, read):
-		"""Return AdapterMatch instance"""
+		"""Return Match instance"""
 		if self.where != PREFIX:
 			return super(ColorspaceAdapter, self).match_to(read)
 		# create artificial adapter that includes a first color that encodes the
@@ -352,15 +362,17 @@ class ColorspaceAdapter(Adapter):
 
 		pos = 0 if read.sequence.startswith(asequence) else -1
 		if pos >= 0:
-			match = AdapterMatch(
+			match = Match(
 				0, len(asequence), pos, pos + len(asequence),
 				len(asequence), 0, self._front_flag, self, read)
 		else:
 			# try approximate matching
 			self.aligner.reference = asequence
 			alignment = self.aligner.locate(read.sequence)
+			if self.debug:
+				print(self.aligner.dpmatrix)  # pragma: no cover
 			if alignment is not None:
-				match = AdapterMatch(*(alignment + (self._front_flag, self, read)))
+				match = Match(*(alignment + (self._front_flag, self, read)))
 			else:
 				match = None
 
diff --git a/cutadapt/align.py b/cutadapt/align.py
index e8da3e8..aabd208 100644
--- a/cutadapt/align.py
+++ b/cutadapt/align.py
@@ -4,8 +4,6 @@ Alignment module.
 """
 from __future__ import print_function, division, absolute_import
 
-import sys
-
 from cutadapt._align import Aligner, compare_prefixes, locate
 
 # flags for global alignment
@@ -20,20 +18,18 @@ START_WITHIN_SEQ1 = 1
 START_WITHIN_SEQ2 = 2
 STOP_WITHIN_SEQ1 = 4
 STOP_WITHIN_SEQ2 = 8
-ALLOW_WILDCARD_SEQ1 = 1
-ALLOW_WILDCARD_SEQ2 = 2
 
 # Use this to get regular semiglobal alignment
 # (all gaps in the beginning or end are free)
 SEMIGLOBAL = START_WITHIN_SEQ1 | START_WITHIN_SEQ2 | STOP_WITHIN_SEQ1 | STOP_WITHIN_SEQ2
 
 
-def compare_suffixes(s1, s2, degenerate=0):
+def compare_suffixes(s1, s2, wildcard_ref=False, wildcard_query=False):
 	"""
 	Find out whether one string is the suffix of the other one, allowing
 	mismatches. Used to find an anchored 3' adapter when no indels are allowed.
 	"""
 	s1 = s1[::-1]
 	s2 = s2[::-1]
-	_, length, _, _, matches, errors = compare_prefixes(s1, s2, degenerate)
+	_, length, _, _, matches, errors = compare_prefixes(s1, s2, wildcard_ref, wildcard_query)
 	return (len(s1) - length, len(s1), len(s2) - length, len(s2), matches, errors)
diff --git a/cutadapt/filters.py b/cutadapt/filters.py
index 8db02da..0407363 100644
--- a/cutadapt/filters.py
+++ b/cutadapt/filters.py
@@ -2,14 +2,21 @@
 """
 Classes for writing and filtering of processed reads.
 
-To determine what happens to a read, a list of filters is created and each
-one is called in turn (via its __call__ method) until one returns True.
+A Filter is a callable that has the read as its only argument. If it is called,
+it returns True if the read should be filtered (discarded), and False if not.
+
+To be used, a filter needs to be wrapped in one of the redirector classes.
+They are called so because they can redirect filtered reads to a file if so
+desired. They also keep statistics.
+
+To determine what happens to a read, a list of redirectors with different
+filters is created and each redirector is called in turn until one returns True.
 The read is then assumed to have been "consumed", that is, either written
-somewhere or filtered (should be discarded). Filters and writers are currently
-not distinguished: The idea is that at least one of the filters will apply.
+somewhere or filtered (should be discarded).
 """
 from __future__ import print_function, division, absolute_import
-from cutadapt.xopen import xopen
+from .xopen import xopen
+from . import seqio
 
 # Constants used when returning from a Filter’s __call__ method to improve
 # readability (it is unintuitive that "return True" means "discard the read").
@@ -17,92 +24,160 @@ DISCARD = True
 KEEP = False
 
 
-class Filter(object):
-	"""Abstract base class for filters"""
-	def __init__(self, check_second=True):
-		"""
-		check_second -- whether the second read in a pair is also checked for
-		its length. If True, the read is discarded if *any* of the two reads are
-		fulfills the criteria for discarding a read.
-		"""
-		self.check_second = check_second
-		self.filtered = 0  # statistics
+class NoFilter(object):
+	"""
+	No filtering, just send each read to the given writer.
+	"""
+	def __init__(self, writer):
+		self.filtered = 0
+		self.writer = writer
+		self.filter = filter
+		self.written = 0  # no of written reads  TODO move to writer
+		self.written_bp = [0, 0]
+
+	def __call__(self, read):
+		self.writer.write(read)
+		self.written += 1
+		self.written_bp[0] += len(read)
+		return DISCARD
+
+
+class PairedNoFilter(object):
+	"""
+	No filtering, just send each paired-end read to the given writer.
+	"""
+	def __init__(self, writer):
+		self.filtered = 0
+		self.writer = writer
+		self.written = 0  # no of written reads or read pairs  TODO move to writer
+		self.written_bp = [0, 0]
+
+	def __call__(self, read1, read2):
+		self.writer.write(read1, read2)
+		self.written += 1
+		self.written_bp[0] += len(read1)
+		self.written_bp[1] += len(read2)
+		return DISCARD
+
+
+class Redirector(object):
+	"""
+	Redirect discarded reads to the given writer. This is for single-end reads.
+	"""
+	def __init__(self, writer, filter):
+		self.filtered = 0
+		self.writer = writer
+		self.filter = filter
+		self.written = 0  # no of written reads  TODO move to writer
+		self.written_bp = [0, 0]
 
-	def discard(self, read):
+	def __call__(self, read):
+		if self.filter(read):
+			self.filtered += 1
+			if self.writer is not None:
+				self.writer.write(read)
+				self.written += 1
+				self.written_bp[0] += len(read)
+			return DISCARD
+		return KEEP
+
+
+class PairedRedirector(object):
+	"""
+	Redirect discarded reads to the given writer. This is for paired-end reads,
+	using the 'new-style' filtering where both reads are inspected. That is,
+	the entire pair is discarded if at least 1 or 2 of the reads match the
+	filtering criteria.
+	"""
+	def __init__(self, writer, filter, min_affected=1):
 		"""
-		Return True if read should be discarded (implement this in a derived class).
+		min_affected -- values 1 and 2 are allowed.
+			1 means: the pair is discarded if any read matches
+			2 means: the pair is discarded if both reads match
 		"""
-		raise NotImplementedError()
+		if not min_affected in (1, 2):
+			raise ValueError("min_affected must be 1 or 2")
+		self.filtered = 0
+		self.writer = writer
+		self.filter = filter
+		self._min_affected = min_affected
+		self.written = 0  # no of written reads or read pairs  TODO move to writer
+		self.written_bp = [0, 0]
 
-	def __call__(self, read1, read2=None):
-		if self.discard(read1) or (
-				self.check_second and read2 is not None and self.discard(read2)):
+	def __call__(self, read1, read2):
+		if self.filter(read1) + self.filter(read2) >= self._min_affected:
 			self.filtered += 1
+			# discard read
+			if self.writer is not None:
+				self.writer.write(read1, read2)
+				self.written += 1
+				self.written_bp[0] += len(read1)
+				self.written_bp[1] += len(read2)
 			return DISCARD
 		return KEEP
 
 
-class RedirectingFilter(Filter):
+class LegacyPairedRedirector(object):
 	"""
-	Abstract base class for a filter that can send the reads it discards to a
-	separate output file.
+	Redirect discarded reads to the given writer. This is for paired-end reads,
+	using the 'legacy' filtering mode (backwards compatibility). That is, if
+	the first read matches the filtering criteria, the pair is discarded. The
+	second read is not inspected.
 	"""
-	def __init__(self, outfile=None, paired_outfile=None, check_second=True):
-		super(RedirectingFilter, self).__init__(check_second)
-		self.outfile = outfile
-		self.paired_outfile = paired_outfile
-		self.written = 0  # no of written reads or read pairs
+	def __init__(self, writer, filter):
+		self.filtered = 0
+		self.writer = writer
+		self.filter = filter
+		self.written = 0  # no of written reads or read pairs  TODO move to writer
 		self.written_bp = [0, 0]
 
-	def __call__(self, read1, read2=None):
-		if super(RedirectingFilter, self).__call__(read1, read2) == DISCARD:
-			if self.outfile is not None:
-				read1.write(self.outfile)
+	def __call__(self, read1, read2):
+		if self.filter(read1):
+			self.filtered += 1
+			# discard read
+			if self.writer is not None:
+				self.writer.write(read1, read2)
 				self.written += 1
 				self.written_bp[0] += len(read1)
-			if read2 is not None and self.paired_outfile is not None:
-				read2.write(self.paired_outfile)
 				self.written_bp[1] += len(read2)
 			return DISCARD
 		return KEEP
 
 
-class TooShortReadFilter(RedirectingFilter):
-	def __init__(self, minimum_length, too_short_outfile, check_second=True):
-		# TODO paired_outfile is left at its default value None (read2 is silently discarded)
-		super(TooShortReadFilter, self).__init__(outfile=too_short_outfile, check_second=check_second)
+class TooShortReadFilter(object):
+	# TODO paired_outfile is left at its default value None (read2 is silently discarded)
+	def __init__(self, minimum_length):
 		self.minimum_length = minimum_length
 
-	def discard(self, read):
+	def __call__(self, read):
 		return len(read) < self.minimum_length
 
 
-class TooLongReadFilter(RedirectingFilter):
-	def __init__(self, maximum_length, too_long_outfile, check_second=True):
-		super(TooLongReadFilter, self).__init__(outfile=too_long_outfile, check_second=check_second)
+class TooLongReadFilter(object):
+	def __init__(self, maximum_length):
 		self.maximum_length = maximum_length
 
-	def discard(self, read):
+	def __call__(self, read):
 		return len(read) > self.maximum_length
 
 
-class NContentFilter(Filter):
+class NContentFilter(object):
 	"""
-	Discards reads over a given threshold of N's. It handles both raw counts of Ns as well
+	Discards a reads that has a number of 'N's over a given threshold. It handles both raw counts of Ns as well
 	as proportions. Note, for raw counts, it is a greater than comparison, so a cutoff
 	of '1' will keep reads with a single N in it.
 	"""
-	def __init__(self, count, check_second=True):
+	def __init__(self, count):
 		"""
 		Count -- if it is below 1.0, it will be considered a proportion, and above and equal to
 		1 will be considered as discarding reads with a number of N's greater than this cutoff.
 		"""
-		super(NContentFilter, self).__init__(check_second)
 		assert count >= 0
 		self.is_proportion = count < 1.0
 		self.cutoff = count
 
-	def discard(self, read):
+	def __call__(self, read):
+		"""Return True when the read should be discarded"""
 		n_count = read.sequence.lower().count('n')
 		if self.is_proportion:
 			if len(read) == 0:
@@ -110,34 +185,21 @@ class NContentFilter(Filter):
 			return n_count / len(read) > self.cutoff
 		else:
 			return n_count > self.cutoff
-		return False
 
 
-class DiscardUntrimmedFilter(RedirectingFilter):
+class DiscardUntrimmedFilter(object):
 	"""
-	A Filter that discards untrimmed reads.
+	Return True if read is untrimmed.
 	"""
-	def __init__(self, untrimmed_outfile, untrimmed_paired_outfile, check_second=True):
-		super(DiscardUntrimmedFilter, self).__init__(
-			outfile=untrimmed_outfile,
-			paired_outfile=untrimmed_paired_outfile,
-			check_second=check_second)
-
-	def discard(self, read):
+	def __call__(self, read):
 		return read.match is None
 
 
-class DiscardTrimmedFilter(RedirectingFilter):
+class DiscardTrimmedFilter(object):
 	"""
-	A filter that discards trimmed reads.
+	Return True if read is trimmed.
 	"""
-	def __init__(self, trimmed_outfile, trimmed_paired_outfile, check_second=True):
-		super(DiscardTrimmedFilter, self).__init__(
-			outfile=trimmed_outfile,
-			paired_outfile=trimmed_paired_outfile,
-			check_second=check_second)
-
-	def discard(self, read):
+	def __call__(self, read):
 		return read.match is not None
 
 
@@ -147,7 +209,7 @@ class Demultiplexer(object):
 	depending on which adapter matches. Files are created when the first read
 	is written to them.
 	"""
-	def __init__(self, path_template, untrimmed_path):
+	def __init__(self, path_template, untrimmed_path, fileformat, colorspace):
 		"""
 		path_template must contain the string '{name}', which will be replaced
 		with the name of the adapter to form the final output path.
@@ -157,34 +219,38 @@ class Demultiplexer(object):
 		assert '{name}' in path_template
 		self.template = path_template
 		self.untrimmed_path = untrimmed_path
-		self.untrimmed_outfile = None
-		self.files = dict()
+		self.untrimmed_writer = None
+		self.writers = dict()
 		self.written = 0
 		self.written_bp = [0, 0]
+		self.fileformat = fileformat
+		self.colorspace = colorspace
 
 	def __call__(self, read1, read2=None):
 		if read2 is None:
 			# single-end read
 			if read1.match is None:
-				if self.untrimmed_outfile is None and self.untrimmed_path is not None:
-					self.untrimmed_outfile = xopen(self.untrimmed_path, 'w')
-				if self.untrimmed_outfile is not None:
+				if self.untrimmed_writer is None and self.untrimmed_path is not None:
+					self.untrimmed_writer = seqio.open(self.untrimmed_path,
+						mode='w', fileformat=self.fileformat, colorspace=self.colorspace)
+				if self.untrimmed_writer is not None:
 					self.written += 1
 					self.written_bp[0] += len(read1)
-					read1.write(self.untrimmed_outfile)
+					self.untrimmed_writer.write(read1)
 			else:
 				name = read1.match.adapter.name
-				if name not in self.files:
-					self.files[name] = xopen(self.template.format(name=name), 'w')
+				if name not in self.writers:
+					self.writers[name] = seqio.open(self.template.replace('{name}', name),
+						mode='w', fileformat=self.fileformat, colorspace=self.colorspace)
 				self.written += 1
 				self.written_bp[0] += len(read1)
-				read1.write(self.files[name])
+				self.writers[name].write(read1)
 			return DISCARD
 		else:
 			assert False, "Not supported"  # pragma: no cover
 
 	def close(self):
-		for f in self.files.values():
-			f.close()
-		if self.untrimmed_outfile is not None:
-			self.untrimmed_outfile.close()
+		for w in self.writers.values():
+			w.close()
+		if self.untrimmed_writer is not None:
+			self.untrimmed_writer.close()
diff --git a/cutadapt/modifiers.py b/cutadapt/modifiers.py
index 37a9cc1..bc96b30 100644
--- a/cutadapt/modifiers.py
+++ b/cutadapt/modifiers.py
@@ -1,10 +1,159 @@
 # coding: utf-8
+"""
+This module implements all the read modifications that cutadapt supports.
+A modifier must be callable. It is implemented as a function if no parameters
+need to be stored, and as a class with a __call__ method if there are parameters
+(or statistics).
+"""
 from __future__ import print_function, division, absolute_import
 import re
 from cutadapt.qualtrim import quality_trim_index
 from cutadapt.compat import maketrans
 
 
+class AdapterCutter(object):
+	"""
+	Repeatedly find one of multiple adapters in reads.
+	The number of times the search is repeated is specified by the
+	times parameter.
+	"""
+
+	def __init__(self, adapters, times=1, wildcard_file=None, info_file=None,
+			rest_writer=None, action='trim'):
+		"""
+		adapters -- list of Adapter objects
+
+		action -- What to do with a found adapter: None, 'trim', or 'mask'
+		"""
+		self.adapters = adapters
+		self.times = times
+		self.wildcard_file = wildcard_file
+		self.info_file = info_file
+		self.rest_writer = rest_writer
+		self.action = action
+		self.with_adapters = 0
+
+	def _best_match(self, read):
+		"""
+		Find the best matching adapter in the given read.
+
+		Return either an Match instance or None if there are no matches.
+		"""
+		best = None
+		for adapter in self.adapters:
+			match = adapter.match_to(read)
+			if match is None:
+				continue
+
+			# the no. of matches determines which adapter fits best
+			if best is None or match.matches > best.matches:
+				best = match
+		return best
+
+	def _write_info(self, read, matches):
+		"""
+		Write to the info, wildcard and rest files.
+		# TODO
+		# This design with a read having a .match attribute and
+		# a match having a .read attribute is really confusing.
+		"""
+		match = read.match
+		if self.rest_writer and match:
+			self.rest_writer.write(match)
+
+		if self.wildcard_file and match:
+			print(match.wildcards(), read.name, file=self.wildcard_file)
+
+		if self.info_file:
+			if match:
+				for m in matches:
+					seq = m.read.sequence
+					qualities = m.read.qualities
+					if qualities is None:
+						qualities = ''
+					print(
+						m.read.name,
+						m.errors,
+						m.rstart,
+						m.rstop,
+						seq[0:m.rstart],
+						seq[m.rstart:m.rstop],
+						seq[m.rstop:],
+						m.adapter.name,
+						qualities[0:m.rstart],
+						qualities[m.rstart:m.rstop],
+						qualities[m.rstop:],
+						sep='\t', file=self.info_file
+					)
+			else:
+				seq = read.sequence
+				qualities = read.qualities if read.qualities is not None else ''
+				print(read.name, -1, seq, qualities, sep='\t', file=self.info_file)
+
+	def __call__(self, read):
+		"""
+		Determine the adapter that best matches the given read.
+		Since the best adapter is searched repeatedly, a list
+		of Match instances is returned, which
+		need to be applied consecutively to the read.
+		The list is empty if there are no adapter matches.
+
+		The read is converted to uppercase before it is compared to the adapter
+		sequences.
+
+		Cut found adapters from a single read. Return modified read.
+		"""
+		matches = []
+
+		# try at most self.times times to remove an adapter
+		trimmed_read = read
+		for t in range(self.times):
+			match = self._best_match(trimmed_read)
+			if match is None:
+				# nothing found
+				break
+			assert match.length > 0
+			assert match.errors / match.length <= match.adapter.max_error_rate
+			assert match.length - match.errors > 0
+			matches.append(match)
+			trimmed_read = match.adapter.trimmed(match)
+
+		trimmed_read.match = matches[-1] if matches else None
+		self._write_info(trimmed_read, matches)
+
+		if not matches:
+			return trimmed_read
+
+		if __debug__:
+			assert len(trimmed_read) < len(read), "Trimmed read isn't shorter than original"
+
+		if self.action == 'trim':
+			# read is already trimmed, nothing to do
+			pass
+		elif self.action == 'mask':
+			# add N from last modification
+			masked_sequence = trimmed_read.sequence
+			for match in sorted(matches, reverse=True, key=lambda m: m.astart):
+				ns = 'N' * (len(match.read.sequence) -
+							len(match.adapter.trimmed(match).sequence))
+				# add N depending on match position
+				if match.front:
+					masked_sequence = ns + masked_sequence
+				else:
+					masked_sequence += ns
+			# set masked sequence as sequence with original quality
+			trimmed_read.sequence = masked_sequence
+			trimmed_read.qualities = matches[0].read.qualities
+
+			assert len(trimmed_read.sequence) == len(read)
+		elif self.action is None:
+			trimmed_read = read
+			trimmed_read.match = matches[-1]
+
+		self.with_adapters += 1
+		return trimmed_read
+
+
 class UnconditionalCutter(object):
 	"""
 	A modifier that unconditionally removes the first n or the last n bases from a read.
@@ -61,7 +210,9 @@ class PrefixSuffixAdder(object):
 
 	def __call__(self, read):
 		read = read[:]
-		read.name = self.prefix + read.name + self.suffix
+		adapter_name = 'no_adapter' if read.match is None else read.match.adapter.name
+		read.name = self.prefix.replace('{name}', adapter_name) + read.name + \
+			self.suffix.replace('{name}', adapter_name)
 		return read
 
 
diff --git a/cutadapt/report.py b/cutadapt/report.py
index 88cfe5e..32f8d03 100644
--- a/cutadapt/report.py
+++ b/cutadapt/report.py
@@ -9,8 +9,8 @@ from collections import namedtuple
 from contextlib import contextmanager
 import textwrap
 from .adapters import BACK, FRONT, PREFIX, SUFFIX, ANYWHERE
-from .modifiers import QualityTrimmer
-from .filters import (TooShortReadFilter, TooLongReadFilter,
+from .modifiers import QualityTrimmer, AdapterCutter
+from .filters import (NoFilter, PairedNoFilter, TooShortReadFilter, TooLongReadFilter,
 	DiscardTrimmedFilter, DiscardUntrimmedFilter, Demultiplexer, NContentFilter)
 
 
@@ -38,39 +38,35 @@ class Statistics:
 		self.written = 0
 		self.written_bp = [0, 0]
 		self.too_many_n = None
+		# Collect statistics from writers/filters
 		for w in writers:
-			if isinstance(w, TooShortReadFilter):
-				self.too_short = w.filtered
-			elif isinstance(w, TooLongReadFilter):
-				self.too_long = w.filtered
-			elif isinstance(w, NContentFilter):
-				self.too_many_n = w.filtered
-			elif isinstance(w, (DiscardTrimmedFilter, DiscardUntrimmedFilter, Demultiplexer)):
+			if isinstance(w, (NoFilter, PairedNoFilter, Demultiplexer)) or isinstance(w.filter, (DiscardTrimmedFilter, DiscardUntrimmedFilter)):
 				self.written += w.written
 				if self.n > 0:
 					self.written_fraction = self.written / self.n
 				self.written_bp = self.written_bp[0] + w.written_bp[0], self.written_bp[1] + w.written_bp[1]
+			elif isinstance(w.filter, TooShortReadFilter):
+				self.too_short = w.filtered
+			elif isinstance(w.filter, TooLongReadFilter):
+				self.too_long = w.filtered
+			elif isinstance(w.filter, NContentFilter):
+				self.too_many_n = w.filtered
 		assert self.written is not None
 
+		# Collect statistics from modifiers
 		self.with_adapters = [0, 0]
-		for i in (0, 1):
-			for adapter in adapters_pair[i]:
-				self.with_adapters[i] += sum(adapter.lengths_front.values())
-				self.with_adapters[i] += sum(adapter.lengths_back.values())
+		self.quality_trimmed_bp = [0, 0]
+		self.did_quality_trimming = False
+		for i, modifiers_list in [(0, modifiers), (1, modifiers2)]:
+			for modifier in modifiers_list:
+				if isinstance(modifier, QualityTrimmer):
+					self.quality_trimmed_bp[i] = modifier.trimmed_bases
+					self.did_quality_trimming = True
+				elif isinstance(modifier, AdapterCutter):
+					self.with_adapters[i] += modifier.with_adapters
 		self.with_adapters_fraction = [ (v / self.n if self.n > 0 else 0) for v in self.with_adapters ]
-
-		self.quality_trimmed_bp = [qtrimmed(modifiers), qtrimmed(modifiers2)]
-
-		if self.quality_trimmed_bp[0] is not None or self.quality_trimmed_bp[1] is not None:
-			self.did_quality_trimming = True
-			if self.quality_trimmed_bp[0] is None:
-				self.quality_trimmed_bp[0] = 0
-			if self.quality_trimmed_bp[1] is None:
-				self.quality_trimmed_bp[1] = 0
-			self.quality_trimmed = sum(self.quality_trimmed_bp)
-			self.quality_trimmed_fraction = self.quality_trimmed / self.total_bp if self.total_bp > 0 else 0.0
-		else:
-			self.did_quality_trimming = False
+		self.quality_trimmed = sum(self.quality_trimmed_bp)
+		self.quality_trimmed_fraction = self.quality_trimmed / self.total_bp if self.total_bp > 0 else 0.0
 
 		self.total_written_bp = sum(self.written_bp)
 		self.total_written_bp_fraction = self.total_written_bp / self.total_bp if self.total_bp > 0 else 0.0
@@ -160,17 +156,6 @@ def print_adjacent_bases(bases, sequence):
 	return False
 
 
-def qtrimmed(modifiers):
-	"""
-	Look for a QualityTrimmer in the given list of modifiers and return its
-	trimmed_bases attribute. If not found, return None.
-	"""
-	for m in modifiers:
-		if isinstance(m, QualityTrimmer):
-			return m.trimmed_bases
-	return None
-
-
 @contextmanager
 def redirect_standard_output(file):
 	if file is None:
@@ -246,15 +231,12 @@ def print_report(stats, adapters_pair):
 			where = adapter.where
 			assert where == ANYWHERE or (where in (BACK, SUFFIX) and total_front == 0) or (where in (FRONT, PREFIX) and total_back == 0)
 
-			name = str(adapter.name)
-			if not adapter.name_is_generated:
-				name = "'{0}'".format(name)
 			if stats.paired:
 				extra = 'First read: ' if which_in_pair == 0 else 'Second read: '
 			else:
 				extra = ''
 
-			print("=" * 3, extra + "Adapter", name, "=" * 3)
+			print("=" * 3, extra + "Adapter", adapter.name, "=" * 3)
 			print()
 			print("Sequence: {0}; Type: {1}; Length: {2}; Trimmed: {3} times.".
 				format(adapter.sequence, ADAPTER_TYPES[adapter.where],
diff --git a/cutadapt/scripts/cutadapt.py b/cutadapt/scripts/cutadapt.py
index f84318d..bfc3c57 100755
--- a/cutadapt/scripts/cutadapt.py
+++ b/cutadapt/scripts/cutadapt.py
@@ -45,12 +45,11 @@ Input may also be in FASTA format. Compressed input and output is supported and
 auto-detected from the file name (.gz, .xz, .bz2). Use the file name '-' for
 standard input/output. Without the -o option, output is sent to standard output.
 
-Some other available features are:
-  * Various other adapter types (5' adapters, "mixed" 5'/3' adapters etc.)
-  * Trimming a fixed number of bases
-  * Quality trimming
-  * Trimming colorspace reads
-  * Filtering reads by various criteria
+Citation:
+
+Marcel Martin. Cutadapt removes adapter sequences from high-throughput
+sequencing reads. EMBnet.Journal, 17(1):10-12, May 2011.
+http://dx.doi.org/10.14806/ej.17.1.200
 
 Use "cutadapt --help" to see all command-line options.
 See http://cutadapt.readthedocs.org/ for full documentation.
@@ -66,8 +65,10 @@ import sys
 import time
 import errno
 from optparse import OptionParser, OptionGroup, SUPPRESS_HELP
+import functools
 import logging
 import platform
+import textwrap
 
 from cutadapt import seqio, __version__
 from cutadapt.xopen import xopen
@@ -75,8 +76,9 @@ from cutadapt.adapters import (Adapter, ColorspaceAdapter, gather_adapters,
 	BACK, FRONT, PREFIX, SUFFIX, ANYWHERE)
 from cutadapt.modifiers import (LengthTagModifier, SuffixRemover, PrefixSuffixAdder,
 	DoubleEncoder, ZeroCapper, PrimerTrimmer, QualityTrimmer, UnconditionalCutter,
-	NEndTrimmer)
-from cutadapt.filters import (TooShortReadFilter, TooLongReadFilter,
+	NEndTrimmer, AdapterCutter)
+from cutadapt.filters import (NoFilter, PairedNoFilter, Redirector, PairedRedirector,
+	LegacyPairedRedirector, TooShortReadFilter, TooLongReadFilter,
 	Demultiplexer, NContentFilter, DiscardUntrimmedFilter, DiscardTrimmedFilter)
 from cutadapt.report import Statistics, print_report, redirect_standard_output
 from cutadapt.compat import next
@@ -98,144 +100,7 @@ class RestFileWriter(object):
 			print(rest, match.read.name, file=self.file)
 
 
-class AdapterCutter(object):
-	"""
-	Repeatedly find one of multiple adapters in reads.
-	The number of times the search is repeated is specified by the
-	times parameter.
-	"""
-
-	def __init__(self, adapters, times=1, wildcard_file=None, info_file=None,
-			rest_writer=None, action='trim'):
-		"""
-		adapters -- list of Adapter objects
-
-		action -- What to do with a found adapter: None, 'trim', or 'mask'
-		"""
-		self.adapters = adapters
-		self.times = times
-		self.wildcard_file = wildcard_file
-		self.info_file = info_file
-		self.rest_writer = rest_writer
-		self.action = action
-		self.reads_matched = 0
-
-	def _best_match(self, read):
-		"""
-		Find the best matching adapter in the given read.
-
-		Return either an AdapterMatch instance or None if there are no matches.
-		"""
-		best = None
-		for adapter in self.adapters:
-			match = adapter.match_to(read)
-			if match is None:
-				continue
-
-			# the no. of matches determines which adapter fits best
-			if best is None or match.matches > best.matches:
-				best = match
-		return best
-
-	def _write_info(self, read, matches):
-		"""
-		Write to the info, wildcard and rest files.
-		# TODO
-		# This design with a read having a .match attribute and
-		# a match having a .read attribute is really confusing.
-		"""
-		match = read.match
-		if self.rest_writer and match:
-			self.rest_writer.write(match)
-
-		if self.wildcard_file and match:
-			print(match.wildcards(), read.name, file=self.wildcard_file)
-
-		if self.info_file:
-			if match:
-				for m in matches:
-					seq = m.read.sequence
-					print(
-						m.read.name,
-						m.errors,
-						m.rstart,
-						m.rstop,
-						seq[0:m.rstart],
-						seq[m.rstart:m.rstop],
-						seq[m.rstop:],
-						m.adapter.name,
-						sep='\t', file=self.info_file
-					)
-			else:
-				seq = read.sequence
-				print(read.name, -1, seq, sep='\t', file=self.info_file)
-
-	def __call__(self, read):
-		"""
-		Determine the adapter that best matches the given read.
-		Since the best adapter is searched repeatedly, a list
-		of AdapterMatch instances is returned, which
-		need to be applied consecutively to the read.
-		The list is empty if there are no adapter matches.
-
-		The read is converted to uppercase before it is compared to the adapter
-		sequences.
-
-		Cut found adapters from a single read. Return modified read.
-		"""
-		matches = []
-
-		# try at most self.times times to remove an adapter
-		trimmed_read = read
-		for t in range(self.times):
-			match = self._best_match(trimmed_read)
-			if match is None:
-				# nothing found
-				break
-			assert match.length > 0
-			assert match.errors / match.length <= match.adapter.max_error_rate
-			assert match.length - match.errors > 0
-			matches.append(match)
-			trimmed_read = match.adapter.trimmed(match)
-
-		trimmed_read.match = matches[-1] if matches else None
-		self._write_info(trimmed_read, matches)
-
-		if not matches:
-			return trimmed_read
-
-		if __debug__:
-			assert len(trimmed_read) < len(read), "Trimmed read isn't shorter than original"
-
-		if self.action == 'trim':
-			# read is already trimmed, nothing to do
-			pass
-		elif self.action == 'mask':
-			# add N from last modification
-			masked_sequence = trimmed_read.sequence
-			for match in sorted(matches, reverse=True, key=lambda m: m.astart):
-				ns = 'N' * (len(match.read.sequence) -
-							len(match.adapter.trimmed(match).sequence))
-				# add N depending on match position
-				if match.front:
-					masked_sequence = ns + masked_sequence
-				else:
-					masked_sequence += ns
-			# set masked sequence as sequence with original quality
-			trimmed_read.sequence = masked_sequence
-			trimmed_read.qualities = matches[0].read.qualities
-
-			assert len(trimmed_read.sequence) == len(read)
-		elif self.action is None:
-			trimmed_read = read
-			trimmed_read.match = matches[-1]
-
-		self.reads_matched += 1  # TODO move to filter class
-
-		return trimmed_read
-
-
-def process_single_reads(reader, modifiers, writers):
+def process_single_reads(reader, modifiers, filters):
 	"""
 	Loop over reads, find adapters, trim reads, apply modifiers and
 	output modified reads.
@@ -249,14 +114,14 @@ def process_single_reads(reader, modifiers, writers):
 		total_bp += len(read.sequence)
 		for modifier in modifiers:
 			read = modifier(read)
-		for writer in writers:
-			if writer(read):
+		for filter in filters:
+			if filter(read):
 				break
 
 	return Statistics(n=n, total_bp1=total_bp, total_bp2=None)
 
 
-def process_paired_reads(paired_reader, modifiers, modifiers2, writers):
+def process_paired_reads(paired_reader, modifiers1, modifiers2, filters):
 	"""
 	Loop over reads, find adapters, trim reads, apply modifiers and
 	output modified reads.
@@ -270,83 +135,35 @@ def process_paired_reads(paired_reader, modifiers, modifiers2, writers):
 		n += 1
 		total1_bp += len(read1.sequence)
 		total2_bp += len(read2.sequence)
-		for modifier in modifiers:
+		for modifier in modifiers1:
 			read1 = modifier(read1)
 		for modifier in modifiers2:
 			read2 = modifier(read2)
-		for writer in writers:
-			# Stop writing as soon as one of the writers was successful.
-			if writer(read1, read2):
+		for filter in filters:
+			# Stop writing as soon as one of the filters was successful.
+			if filter(read1, read2):
 				break
 	return Statistics(n=n, total_bp1=total1_bp, total_bp2=total2_bp)
 
 
-def trimmed_and_untrimmed_files(
-		default_output,
-		output_path,
-		untrimmed_path,
-		discard_trimmed,
-		discard_untrimmed
-		):
-	"""
-	Figure out (from command-line parameters) where trimmed and untrimmed reads
-	should be written.
-
-	Return a pair (trimmed, untrimmed). The values are either open file-like
-	objects or None, in which case no output should be produced. The objects may
-	be identical (for example: (sys.stdout, sys.stdout)).
-
-	The parameters are sorted: Later parameters have higher precedence.
-
-	default_output -- If nothing else is specified below, this file-like object
-		is returned for both trimmed and untrimmed output.
-	output_path -- Path to output file for both trimmed and untrimmed output.
-	untrimmed_path -- Path to an output file for untrimmed reads.
-	discard_trimmed -- bool, overrides earlier options.
-	discard_untrimmed -- bool, overrides earlier options.
-	"""
-	if discard_trimmed:
-		if discard_untrimmed:
-			untrimmed = None
-		elif untrimmed_path is not None:
-			untrimmed = xopen(untrimmed_path, 'w')
-		elif output_path is not None:
-			untrimmed = xopen(output_path, 'w')
-		else:
-			untrimmed = default_output
-		return (None, untrimmed)
-	if discard_untrimmed:
-		trimmed = default_output
-		if output_path is not None:
-			trimmed = xopen(output_path, 'w')
-		return (trimmed, None)
-
-	trimmed = default_output
-	untrimmed = default_output
-	if output_path is not None:
-		trimmed = untrimmed = xopen(output_path, 'w')
-	if untrimmed_path is not None:
-		untrimmed = xopen(untrimmed_path, 'w')
-
-	return (trimmed, untrimmed)
-
-
 def get_option_parser():
 	parser = CutadaptOptionParser(usage=__doc__, version=__version__)
 
+	parser.add_option("--debug", action='store_true', default=False,
+		help="Print debugging information.")
 	parser.add_option("-f", "--format",
 		help="Input file format; can be either 'fasta', 'fastq' or 'sra-fastq'. "
 			"Ignored when reading csfasta/qual files (default: auto-detect "
 			"from file name extension).")
 
 	group = OptionGroup(parser, "Options that influence how the adapters are found",
-		description="Each of the following three parameters (-a, -b, -g) can be used "
+		description="Each of the three parameters -a, -b, -g can be used "
 			"multiple times and in any combination to search for an entire set of "
 			"adapters of possibly different types. Only the best matching "
 			"adapter is trimmed from each read (but see the --times option). "
 			"Instead of giving an adapter directly, you can also write "
 			"file:FILE and the adapter sequences will be read from the given "
-			"FILE (which must be in FASTA format).")
+			"FASTA FILE.")
 	group.add_option("-a", "--adapter", action="append", default=[], metavar="ADAPTER",
 		dest="adapters",
 		help="Sequence of an adapter that was ligated to the 3' end. The "
@@ -374,11 +191,9 @@ def get_option_parser():
 			"of the matching region) (default: %default)")
 	group.add_option("--no-indels", action='store_false', dest='indels', default=True,
 		help="Do not allow indels in the alignments (allow only mismatches). "
-			"Currently only supported for anchored adapters. (default: allow "
-			"both mismatches and indels)")
+			"(default: allow both mismatches and indels)")
 	group.add_option("-n", "--times", type=int, metavar="COUNT", default=1,
-		help="Try to remove adapters at most COUNT times. Useful when an "
-			"adapter gets appended multiple times (default: %default).")
+		help="Remove up to COUNT adapters from each read (default: %default)")
 	group.add_option("-O", "--overlap", type=int, metavar="LENGTH", default=3,
 		help="Minimum overlap length. If the overlap between the read and the "
 			"adapter is shorter than LENGTH, the read is not modified. "
@@ -389,13 +204,48 @@ def get_option_parser():
 	group.add_option("-N", "--no-match-adapter-wildcards", action="store_false",
 		default=True, dest='match_adapter_wildcards',
 		help="Do not interpret IUPAC wildcards in adapters.")
+	group.add_option("--no-trim", dest='action', action='store_const', const=None,
+		help="Match and redirect reads to output/untrimmed-output as usual, "
+			"but do not remove adapters.")
+	group.add_option("--mask-adapter", dest='action', action='store_const', const='mask',
+		help="Mask adapters with 'N' characters instead of trimming them.")
+	parser.add_option_group(group)
+
+	group = OptionGroup(parser, "Additional read modifications")
+	group.add_option("-u", "--cut", action='append', default=[], type=int, metavar="LENGTH",
+		help="Remove LENGTH bases from the beginning or end of each read. "
+			"If LENGTH is positive, bases are removed from the beginning of each read. "
+			"If LENGTH is negative, bases are removed from the end of each read. "
+			"This option can be specified twice if the LENGTHs have different signs.")
+	group.add_option("-q", "--quality-cutoff", default=None, metavar="[5'CUTOFF,]3'CUTOFF",
+		help="Trim low-quality bases from 5' and/or 3' ends of reads before "
+			"adapter removal. If one value is given, only the 3' end is trimmed. "
+			"If two comma-separated cutoffs are given, the 5' end is trimmed with "
+			"the first cutoff, the 3' end with the second. See documentation for "
+			"the algorithm. (default: no trimming)")
+	group.add_option("--quality-base", type=int, default=33,
+		help="Assume that quality values in FASTQ are encoded as ascii(quality "
+			"+ QUALITY_BASE). This needs to be set to 64 for some old Illumina "
+			"FASTQ files. Default: %default")
+	group.add_option("--trim-n", action='store_true', default=False,
+		help="Trim N's on ends of reads.")
+	group.add_option("-x", "--prefix", default='',
+		help="Add this prefix to read names. Use {name} to insert the name of the matching adapter.")
+	group.add_option("-y", "--suffix", default='',
+		help="Add this suffix to read names; can also include {name}")
+	group.add_option("--strip-suffix", action='append', default=[],
+		help="Remove this suffix from read names if present. Can be given multiple times.")
+	group.add_option("--length-tag", metavar="TAG",
+		help="Search for TAG followed by a decimal number in the description "
+			"field of the read. Replace the decimal number with the correct "
+			"length of the trimmed read. For example, use --length-tag 'length=' "
+			"to correct fields like 'length=123'.")
 	parser.add_option_group(group)
 
 	group = OptionGroup(parser, "Options for filtering of processed reads")
 	group.add_option("--discard-trimmed", "--discard", action='store_true', default=False,
-		help="Discard reads that contain the adapter instead of trimming them. "
-			"Also use -O in order to avoid throwing away too many randomly "
-			"matching reads!")
+		help="Discard reads that contain an adapter. Also use -O to avoid "
+			"discarding too many randomly matching reads!")
 	group.add_option("--discard-untrimmed", "--trimmed-only", action='store_true', default=False,
 		help="Discard reads that do not contain the adapter.")
 	group.add_option("-m", "--minimum-length", type=int, default=0, metavar="LENGTH",
@@ -407,14 +257,10 @@ def get_option_parser():
 			"Reads that are too long even before adapter removal "
 			"are also discarded. In colorspace, an initial primer "
 			"is not counted (default: no limit).")
-	group.add_option("--no-trim", dest='action', action='store_const', const=None,
-		help="Match and redirect reads to output/untrimmed-output as usual, "
-			"but do not remove adapters.")
-	group.add_option("--max-n", type=float, default=-1.0, metavar="LENGTH",
-		help="The max proportion of N's allowed in a read. A number < 1 will be treated as a proportion while"
-			 " a number > 1 will be treated as the maximum number of N's contained.")
-	group.add_option("--mask-adapter", dest='action', action='store_const', const='mask',
-		help="Mask adapters with 'N' characters instead of trimming them.")
+	group.add_option("--max-n", type=float, default=-1.0, metavar="COUNT",
+		help="Discard reads with too many N bases. If COUNT is an integer, it "
+			"is treated as the absolute number of N bases. If it is between 0 "
+			"and 1, it is treated as the proportion of N's allowed in a read.")
 	parser.add_option_group(group)
 
 	group = OptionGroup(parser, "Options that influence what gets output to where")
@@ -432,63 +278,37 @@ def get_option_parser():
 		help="When the adapter matches in the middle of a read, write the "
 			"rest (after the adapter) into FILE.")
 	group.add_option("--wildcard-file", metavar="FILE",
-		help="When the adapter has wildcard bases ('N's), write adapter bases "
+		help="When the adapter has N bases (wildcards), write adapter bases "
 			"matching wildcard positions to FILE. When there are indels in the "
 			"alignment, this will often not be accurate.")
 	group.add_option("--too-short-output", metavar="FILE",
-		help="Write reads that are too short (according to length specified by -m) to FILE. (default: discard reads)")
+		help="Write reads that are too short (according to length specified by "
+		"-m) to FILE. (default: discard reads)")
 	group.add_option("--too-long-output", metavar="FILE",
-		help="Write reads that are too long (according to length specified by -M) to FILE. (default: discard reads)")
+		help="Write reads that are too long (according to length specified by "
+		"-M) to FILE. (default: discard reads)")
 	group.add_option("--untrimmed-output", default=None, metavar="FILE",
 		help="Write reads that do not contain the adapter to FILE. (default: "
 			"output to same file as trimmed reads)")
 	parser.add_option_group(group)
 
-	group = OptionGroup(parser, "Additional modifications to the reads")
-	group.add_option("-u", "--cut", action='append', default=[], type=int, metavar="LENGTH",
-		help="Remove LENGTH bases from the beginning or end of each read. "
-			"If LENGTH is positive, the bases are removed from the beginning of each read. "
-			"If LENGTH is negative, the bases are removed from the end of each read. "
-			"This option can be specified twice if the LENGTHs have different signs.")
-	group.add_option("-q", "--quality-cutoff", default=None, metavar="[5'CUTOFF,]3'CUTOFF",
-		help="Trim low-quality bases from 5' and/or 3' ends of reads before "
-			"adapter removal. If one value is given, only the 3' end is trimmed. "
-			"If two comma-separated cutoffs are given, the 5' end is trimmed with "
-			"the first cutoff, the 3' end with the second. The algorithm is the "
-			"same as the one used by BWA (see documentation). (default: no trimming)")
-	group.add_option("--quality-base", type=int, default=33,
-		help="Assume that quality values are encoded as ascii(quality + QUALITY_BASE). The default (33) is usually correct, "
-			 "except for reads produced by some versions of the Illumina pipeline, where this should be set to 64. (Default: %default)")
-	group.add_option("--trim-n", action='store_true', default=False,
-		help="Trim N's on ends of reads.")
-	group.add_option("-x", "--prefix", default='',
-		help="Add this prefix to read names")
-	group.add_option("-y", "--suffix", default='',
-		help="Add this suffix to read names")
-	group.add_option("--strip-suffix", action='append', default=[],
-		help="Remove this suffix from read names if present. Can be given multiple times.")
+	group = OptionGroup(parser, "Colorspace options")
 	group.add_option("-c", "--colorspace", action='store_true', default=False,
-		help="Colorspace mode: Also trim the color that is adjacent to the found adapter.")
+		help="Enable colorspace mode: Also trim the color that is adjacent to the found adapter.")
 	group.add_option("-d", "--double-encode", action='store_true', default=False,
-		help="When in colorspace, double-encode colors (map 0,1,2,3,4 to A,C,G,T,N).")
+		help="Double-encode colors (map 0,1,2,3,4 to A,C,G,T,N).")
 	group.add_option("-t", "--trim-primer", action='store_true', default=False,
-		help="When in colorspace, trim primer base and the first color "
-			"(which is the transition to the first nucleotide)")
+		help="Trim primer base and the first color (which is the transition "
+			"to the first nucleotide)")
 	group.add_option("--strip-f3", action='store_true', default=False,
-		help="For colorspace: Strip the _F3 suffix of read names")
+		help="Strip the _F3 suffix of read names")
 	group.add_option("--maq", "--bwa", action='store_true', default=False,
-		help="MAQ- and BWA-compatible colorspace output. This enables -c, -d, -t, --strip-f3 and -y '/1'.")
-	group.add_option("--length-tag", metavar="TAG",
-		help="Search for TAG followed by a decimal number in the description "
-			"field of the read. Replace the decimal number with the correct "
-			"length of the trimmed read. For example, use --length-tag 'length=' "
-			"to correct fields like 'length=123'.")
+		help="MAQ- and BWA-compatible colorspace output. This enables -c, -d, "
+			"-t, --strip-f3 and -y '/1'.")
 	group.add_option("--no-zero-cap", dest='zero_cap', action='store_false',
-		help="Do not change negative quality values to zero. Colorspace "
-			"quality values of -1 would appear as spaces in the output FASTQ "
-			"file. Since many tools have problems with that, negative qualities "
-			"are converted to zero when trimming colorspace data. Use this "
-			"option to keep negative qualities.")
+		help="Do not change negative quality values to zero in colorspace "
+			"data. By default, they are changed to zero since many tools have "
+			"problems with negative qualities.")
 	group.add_option("--zero-cap", "-z", action='store_true',
 		help="Change negative quality values to zero. This is enabled "
 		"by default when -c/--colorspace is also enabled. Use the above option "
@@ -496,23 +316,38 @@ def get_option_parser():
 	parser.set_defaults(zero_cap=None, action='trim')
 	parser.add_option_group(group)
 
-	group = OptionGroup(parser, "Paired-end options.", description="The "
+	group = OptionGroup(parser, "Paired-end options", description="The "
 		"-A/-G/-B/-U options work like their -a/-b/-g/-u counterparts.")
 	group.add_option("-A", dest='adapters2', action='append', default=[], metavar='ADAPTER',
-		help="3' adapter to be removed from the second read in a pair.")
+		help="3' adapter to be removed from second read in a pair.")
 	group.add_option("-G", dest='front2', action='append', default=[], metavar='ADAPTER',
-		help="5' adapter to be removed from the second read in a pair.")
+		help="5' adapter to be removed from second read in a pair.")
 	group.add_option("-B", dest='anywhere2', action='append', default=[], metavar='ADAPTER',
-		help="5'/3 adapter to be removed from the second read in a pair.")
+		help="5'/3 adapter to be removed from second read in a pair.")
 	group.add_option("-U", dest='cut2', action='append', default=[], type=int, metavar="LENGTH",
-		help="Remove LENGTH bases from the beginning or end of each read (see --cut).")
+		help="Remove LENGTH bases from the beginning or end of each second read (see --cut).")
 	group.add_option("-p", "--paired-output", metavar="FILE",
 		help="Write second read in a pair to FILE.")
+	# Setting the default for pair_filter to None allows us to find out whether
+	# the option was used at all.
+	group.add_option("--pair-filter", metavar='(any|both)', default=None,
+		choices=("any", "both"),
+		help="Which of the reads in a paired-end read have to match the "
+			"filtering criterion in order for it to be filtered. "
+			"Default: any.")
+	group.add_option("--interleaved", action='store_true', default=False,
+		help="Read and write interleaved paired-end reads.")
 	group.add_option("--untrimmed-paired-output", metavar="FILE",
-		help="Write the second read in a pair to this FILE when no adapter "
+		help="Write second read in a pair to this FILE when no adapter "
 			"was found in the first read. Use this option together with "
 			"--untrimmed-output when trimming paired-end reads. (Default: output "
 			"to same file as trimmed reads.)")
+	group.add_option("--too-short-paired-output", metavar="FILE", default=None,
+		help="Write second read in a pair to this file if pair is too short. "
+			"Use together with --too-short-output.")
+	group.add_option("--too-long-paired-output", metavar="FILE", default=None,
+		help="Write second read in a pair to this file if pair is too long. "
+			"Use together with --too-long-output.")
 	parser.add_option_group(group)
 
 	return parser
@@ -537,55 +372,74 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 	elif len(args) > 2:
 		parser.error("Too many parameters.")
 	input_filename = args[0]
+	if input_filename.endswith('.qual'):
+		parser.error("If a .qual file is given, it must be the second argument.")
 
 	# Find out which 'mode' we need to use.
-	# Default: single-read trimming (neither -p nor -A/-G/-B/-U given)
+	# Default: single-read trimming (neither -p nor -A/-G/-B/-U/--interleaved given)
 	paired = False
 	if options.paired_output:
 		# Modify first read only, keep second in sync (-p given, but not -A/-G/-B/-U).
 		# This exists for backwards compatibility ('legacy mode').
 		paired = 'first'
-	if options.adapters2 or options.front2 or options.anywhere2 or options.cut2:
+	# Any of these options switch off legacy mode
+	if (options.adapters2 or options.front2 or options.anywhere2 or
+		options.cut2 or options.interleaved or options.pair_filter or
+		options.too_short_paired_output or options.too_long_paired_output):
 		# Full paired-end trimming when both -p and -A/-G/-B/-U given
-		# Also the read modifications (such as quality trimming) are applied
-		# to second read.
+		# Read modifications (such as quality trimming) are applied also to second read.
 		paired = 'both'
 
-	if paired and len(args) == 1:
+	if paired and len(args) == 1 and not options.interleaved:
 		parser.error("When paired-end trimming is enabled via -A/-G/-B/-U or -p, "
 			"two input files are required.")
-	if paired:
-		input_paired_filename = args[1]
-		quality_filename = None
-	else:
-		input_paired_filename = None
-		if len(args) == 2:
-			if args[0].endswith('.qual'):
-				parser.error("The QUAL file must be the second argument.")
-			quality_filename = args[1]
-		else:
-			quality_filename = None
-
-	if paired:
-		if not options.paired_output:
-			parser.error("When paired-end trimming is enabled via -A/-G/-B/-U, "
-				"a second output file needs to be specified via -p (--paired-output).")
-		if bool(options.untrimmed_output) != bool(options.untrimmed_paired_output):
-			parser.error("When trimming paired-end reads, you must use either none "
-				"or both of the --untrimmed-output/--untrimmed-paired-output options.")
-	else:
+	if options.interleaved and len(args) != 1:
+		parser.error("When reading interleaved files, only one input file may "
+			"be given.")
+	if not paired:
 		if options.untrimmed_paired_output:
 			parser.error("Option --untrimmed-paired-output can only be used when "
 				"trimming paired-end reads (with option -p).")
-		if input_filename.endswith('.qual'):
-			parser.error("Need a FASTA file in addition to the QUAL file.")
-		if options.format is not None and quality_filename is not None:
+
+	# Assign input_paired_filename and quality_filename
+	input_paired_filename = None
+	quality_filename = None
+	if paired:
+		if not options.interleaved:
+			input_paired_filename = args[1]
+			if not options.paired_output:
+				parser.error("When paired-end trimming is enabled via -A/-G/-B/-U, "
+					"a second output file needs to be specified via -p (--paired-output).")
+			if not options.output:
+				parser.error("When you use -p or --paired-output, you must also "
+					"use the -o option.")
+			if bool(options.untrimmed_output) != bool(options.untrimmed_paired_output):
+				parser.error("When trimming paired-end reads, you must use either none "
+					"or both of the --untrimmed-output/--untrimmed-paired-output options.")
+			if options.too_short_output and not options.too_short_paired_output:
+				parser.error("When using --too-short-output with paired-end "
+					"reads, you also need to use --too-short-paired-output")
+			if options.too_long_output and not options.too_long_paired_output:
+				parser.error("When using --too-long-output with paired-end "
+					"reads, you also need to use --too-long-paired-output")
+	elif len(args) == 2:
+		quality_filename = args[1]
+		if options.format is not None:
 			parser.error("If a pair of .fasta and .qual files is given, the -f/--format parameter cannot be used.")
 
 	if options.format is not None and options.format.lower() not in ['fasta', 'fastq', 'sra-fastq']:
 		parser.error("The input file format must be either 'fasta', 'fastq' or "
 			"'sra-fastq' (not '{0}').".format(options.format))
 
+	# Open input file(s)
+	try:
+		reader = seqio.open(input_filename, file2=input_paired_filename,
+				qualfile=quality_filename, colorspace=options.colorspace,
+				fileformat=options.format, interleaved=options.interleaved)
+	except (seqio.UnknownFileType, IOError) as e:
+		parser.error(e)
+	fileformat = 'fastq' if reader.delivers_qualities else 'fasta'
+
 	if options.quality_cutoff is not None:
 		cutoffs = options.quality_cutoff.split(',')
 		if len(cutoffs) == 1:
@@ -602,71 +456,78 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 			parser.error("Expected one value or two values separated by comma for the quality cutoff")
 	else:
 		cutoffs = None
-	writers = []
-	too_short_outfile = None  # too short reads go here
-	too_short_filter = None
+
+	open_writer = functools.partial(seqio.open, mode='w', fileformat=fileformat,
+		colorspace=options.colorspace, interleaved=options.interleaved)
+
+	if options.pair_filter is None:
+		options.pair_filter = 'any'
+	min_affected = 2 if options.pair_filter == 'both' else 1
+	if not paired:
+		filter_wrapper = Redirector
+	elif paired == 'first':
+		filter_wrapper = LegacyPairedRedirector
+	elif paired == 'both':
+		filter_wrapper = functools.partial(PairedRedirector, min_affected=min_affected)
+	filters = []
+	# TODO open_files = []
+	too_short_writer = None  # too short reads go here
 	# TODO pass file name to TooShortReadFilter, add a .close() method?
 	if options.minimum_length > 0:
 		if options.too_short_output:
-			too_short_outfile = xopen(options.too_short_output, 'w')
-		else:
-			too_short_outfile = None
-		too_short_filter = TooShortReadFilter(options.minimum_length,
-			too_short_outfile, paired=='both')
-		writers.append(too_short_filter)
-	too_long_outfile = None  # too long reads go here
-	too_long_filter = None
+			too_short_writer = open_writer(options.too_short_output, options.too_short_paired_output)
+		filters.append(filter_wrapper(too_short_writer, TooShortReadFilter(options.minimum_length)))
+	too_long_writer = None  # too long reads go here
 	if options.maximum_length < sys.maxsize:
 		if options.too_long_output is not None:
-			too_long_outfile = xopen(options.too_long_output, 'w')
-		else:
-			too_long_outfile = None
-		too_long_filter = TooLongReadFilter(options.maximum_length,
-			too_long_outfile, check_second=paired=='both')
-		writers.append(too_long_filter)
+			too_long_writer = open_writer(options.too_long_output, options.too_long_paired_output)
+		filters.append(filter_wrapper(too_long_writer, TooLongReadFilter(options.maximum_length)))
 
 	if options.max_n != -1:
-		writers.append(NContentFilter(options.max_n, check_second=paired=='both'))
+		filters.append(filter_wrapper(None, NContentFilter(options.max_n)))
 
+	if int(options.discard_trimmed) + int(options.discard_untrimmed) + int(options.untrimmed_output is not None) > 1:
+		parser.error("Only one of the --discard-trimmed, --discard-untrimmed "
+			"and --untrimmed-output options can be used at the same time.")
 	demultiplexer = None
+	untrimmed_writer = None
+	writer = None
 	if options.output is not None and '{name}' in options.output:
 		if options.discard_trimmed:
 			parser.error("Do not use --discard-trimmed when demultiplexing.")
 		if paired:
 			parser.error("Demultiplexing not supported for paired-end files, yet.")
-		untrimmed = options.output.format(name='unknown')
+		untrimmed = options.output.replace('{name}', 'unknown')
 		if options.untrimmed_output:
 			untrimmed = options.untrimmed_output
 		if options.discard_untrimmed:
 			untrimmed = None
-		demultiplexer = Demultiplexer(options.output, untrimmed)
-		writers.append(demultiplexer)
-		trimmed_outfile, untrimmed_outfile = None, None
-		trimmed_paired_outfile, untrimmed_paired_outfile = None, None
+		demultiplexer = Demultiplexer(options.output, untrimmed,
+			fileformat=fileformat, colorspace=options.colorspace)
+		filters.append(demultiplexer)
 	else:
-		trimmed_outfile, untrimmed_outfile = trimmed_and_untrimmed_files(
-			default_outfile,
-			options.output,
-			options.untrimmed_output,
-			options.discard_trimmed,
-			options.discard_untrimmed)
-
-		trimmed_paired_outfile, untrimmed_paired_outfile = trimmed_and_untrimmed_files(
-			None,  # applies when not trimming paired-end data
-			options.paired_output,
-			options.untrimmed_paired_output,
-			options.discard_trimmed,
-			options.discard_untrimmed)
-
-		if untrimmed_outfile or untrimmed_paired_outfile:
-			writers.append(DiscardUntrimmedFilter(untrimmed_outfile,
-				untrimmed_paired_outfile, check_second=paired=='both'))
-		writer = DiscardTrimmedFilter(
-			trimmed_outfile, trimmed_paired_outfile,
-			check_second=paired=='both'
-		)
-		writers.append(writer)
-		del writer
+		# Set up the remaining filters to deal with --discard-trimmed,
+		# --discard-untrimmed and --untrimmed-output. These options
+		# are mutually exclusive in order to avoid brain damage.
+		if options.discard_trimmed:
+			filters.append(filter_wrapper(None, DiscardTrimmedFilter()))
+		elif options.discard_untrimmed:
+			filters.append(filter_wrapper(None, DiscardUntrimmedFilter()))
+		elif options.untrimmed_output:
+			untrimmed_writer = open_writer(options.untrimmed_output,
+				options.untrimmed_paired_output)
+			filters.append(filter_wrapper(untrimmed_writer, DiscardUntrimmedFilter()))
+
+		# Finally, figure out where the reads that passed all the previous
+		# filters should go.
+		if options.output is not None:
+			writer = open_writer(options.output, options.paired_output)
+		else:
+			writer = open_writer(default_outfile)
+		if not paired:
+			filters.append(NoFilter(writer))
+		else:
+			filters.append(PairedNoFilter(writer))
 
 	if options.maq:
 		options.colorspace = True
@@ -710,11 +571,11 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 			for name, seq, where in gather_adapters(back, anywhere, front):
 				if not seq:
 					parser.error("The adapter sequence is empty.")
-				if not options.indels and where not in (PREFIX, SUFFIX):
-					parser.error("Not allowing indels is currently supported only for anchored 5' and 3' adapters.")
 				adapter = ADAPTER_CLASS(seq, where, options.error_rate,
 					options.overlap, options.match_read_wildcards,
 					options.match_adapter_wildcards, name=name, indels=options.indels)
+				if options.debug:
+					adapter.enable_debug()
 				adapters.append(adapter)
 			return adapters
 
@@ -733,14 +594,7 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 			options.max_n == -1:
 		parser.error("You need to provide at least one adapter sequence.")
 
-	try:
-		reader = seqio.open(input_filename, file2=input_paired_filename,
-				qualfile=quality_filename, colorspace=options.colorspace,
-				fileformat=options.format)
-	except (seqio.UnknownFileType, IOError) as e:
-		parser.error(e)
-
-	# Create the processing pipeline consisting of a list of "modifiers".
+	# Create the single-end processing pipeline (a list of "modifiers")
 	modifiers = []
 	if options.cut:
 		if len(options.cut) > 2:
@@ -758,10 +612,8 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 				options.wildcard_file, options.info_file,
 				rest_writer, options.action)
 		modifiers.append(adapter_cutter)
-	else:
-		adapter_cutter = None
 
-	# Modifiers that apply to both reads of paired-end reads
+	# Modifiers that apply to both reads of paired-end reads unless in legacy mode
 	modifiers_both = []
 	if options.trim_n:
 		modifiers_both.append(NEndTrimmer())
@@ -817,12 +669,19 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 		options.error_rate * 100,
 		{ False: 'single-end', 'first': 'paired-end legacy', 'both': 'paired-end' }[paired])
 
+	if paired == 'first' and (modifiers_both or cutoffs):
+		logger.warn('\n'.join(textwrap.wrap('WARNING: Requested read '
+			'modifications are applied only to the first '
+			'read since backwards compatibility mode is enabled. '
+			'To modify both reads, also use any of the -A/-B/-G/-U options. '
+			'Use a dummy adapter sequence when necessary: -A XXX')))
+
 	start_time = time.clock()
 	try:
 		if paired:
-			stats = process_paired_reads(reader, modifiers, modifiers2, writers)
+			stats = process_paired_reads(reader, modifiers, modifiers2, filters)
 		else:
-			stats = process_single_reads(reader, modifiers, writers)
+			stats = process_single_reads(reader, modifiers, filters)
 	except KeyboardInterrupt as e:
 		print("Interrupted", file=sys.stderr)
 		sys.exit(130)
@@ -834,9 +693,9 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 		sys.exit("cutadapt: error: {0}".format(e))
 
 	# close open files
-	for f in [trimmed_outfile, untrimmed_outfile, trimmed_paired_outfile,
-			untrimmed_paired_outfile, options.rest_file, options.wildcard_file,
-			options.info_file, too_short_outfile, too_long_outfile,
+	for f in [writer, untrimmed_writer,
+			options.rest_file, options.wildcard_file,
+			options.info_file, too_short_writer, too_long_writer,
 			options.info_file, demultiplexer]:
 		if f is not None and f is not sys.stdin and f is not sys.stdout:
 			f.close()
@@ -844,7 +703,7 @@ def main(cmdlineargs=None, default_outfile=sys.stdout):
 	elapsed_time = time.clock() - start_time
 	if not options.quiet:
 		stats.collect((adapters, adapters2), elapsed_time,
-			modifiers, modifiers2, writers)
+			modifiers, modifiers2, filters)
 		# send statistics to stderr if result was sent to stdout
 		stat_file = sys.stderr if options.output is None else None
 		with redirect_standard_output(stat_file):
diff --git a/cutadapt/seqio.py b/cutadapt/seqio.py
index 39b2e3f..e8ebd33 100644
--- a/cutadapt/seqio.py
+++ b/cutadapt/seqio.py
@@ -1,4 +1,12 @@
 # coding: utf-8
+"""
+Sequence I/O classes: Reading and writing of FASTA and FASTQ files.
+
+TODO
+
+- Sequence.name should be Sequence.description or so (reserve .name for the part
+  before the first space)
+"""
 from __future__ import print_function, division, absolute_import
 import sys
 from os.path import splitext
@@ -26,12 +34,12 @@ def _shorten(s, n=100):
 class Sequence(object):
 	"""qualities is a string and it contains the qualities encoded as ascii(qual+33)."""
 
-	def __init__(self, name, sequence, qualities=None, twoheaders=False, match=None):
+	def __init__(self, name, sequence, qualities=None, name2='', match=None):
 		"""Set qualities to None if there are no quality values"""
 		self.name = name
 		self.sequence = sequence
 		self.qualities = qualities
-		self.twoheaders = twoheaders
+		self.name2 = name2
 		self.match = match
 		if qualities is not None:
 			if len(qualities) != len(sequence):
@@ -45,7 +53,7 @@ class Sequence(object):
 			self.name,
 			self.sequence[key],
 			self.qualities[key] if self.qualities is not None else None,
-		    self.twoheaders,
+		    self.name2,
 		    self.match)
 
 	def __repr__(self):
@@ -65,16 +73,6 @@ class Sequence(object):
 	def __ne__(self, other):
 		return not self.__eq__(other)
 
-	def write(self, outfile):
-		if self.qualities is not None:
-			s = '@' + self.name + '\n' + self.sequence + '\n+'
-			if self.twoheaders:
-				s += self.name
-			s += '\n' + self.qualities + '\n'
-		else:
-			s = '>' + self.name + '\n' + self.sequence + '\n'
-		outfile.write(s)
-
 
 try:
 	from ._seqio import Sequence
@@ -83,7 +81,7 @@ except ImportError:
 
 
 class ColorspaceSequence(Sequence):
-	def __init__(self, name, sequence, qualities, primer=None, twoheaders=False, match=None):
+	def __init__(self, name, sequence, qualities, primer=None, name2='', match=None):
 		# In colorspace, the first character is the last nucleotide of the primer base
 		# and the second character encodes the transition from the primer base to the
 		# first real base of the read.
@@ -97,7 +95,7 @@ class ColorspaceSequence(Sequence):
 			raise FormatError("In read named {0!r}: length of colorspace quality "
 				"sequence ({1}) and length of read ({2}) do not match (primer "
 				"is: {3!r})".format(rname, len(qualities), len(sequence), self.primer))
-		super(ColorspaceSequence, self).__init__(name, sequence, qualities, twoheaders, match)
+		super(ColorspaceSequence, self).__init__(name, sequence, qualities, name2, match)
 		if not self.primer in ('A', 'C', 'G', 'T'):
 			raise FormatError("Primer base is {0!r} in read {1!r}, but it "
 				"should be one of A, C, G, T.".format(
@@ -115,23 +113,13 @@ class ColorspaceSequence(Sequence):
 			self.sequence[key],
 			self.qualities[key] if self.qualities is not None else None,
 			self.primer,
-			self.twoheaders,
+			self.name2,
 			self.match)
 
-	def write(self, outfile):
-		if self.qualities is not None:
-			s = '@' + self.name + '\n' + self.primer + self.sequence + '\n+'
-			if self.twoheaders:
-				s += self.name
-			s += '\n' + self.qualities + '\n'
-		else:
-			s = '>' + self.name + '\n' + self.primer + self.sequence + '\n'
-		outfile.write(s)
-
 
-def sra_colorspace_sequence(name, sequence, qualities, twoheaders):
+def sra_colorspace_sequence(name, sequence, qualities, name2):
 	"""Factory for an SRA colorspace sequence (which has one quality value too many)"""
-	return ColorspaceSequence(name, sequence, qualities[1:], twoheaders=twoheaders)
+	return ColorspaceSequence(name, sequence, qualities[1:], name2=name2)
 
 
 class FileWithPrependedLine(object):
@@ -153,21 +141,23 @@ class FileWithPrependedLine(object):
 		if not line.endswith('\n'):
 			line += '\n'
 		self.first_line = line
-		self.file = file
+		self._file = file
 
 	def __iter__(self):
 		yield self.first_line
-		for line in self.file:
+		for line in self._file:
 			yield line
 
 	def close(self):
-		self.file.close()
+		self._file.close()
 
 
 class FastaReader(object):
 	"""
 	Reader for FASTA files.
 	"""
+	_close_on_exit = False
+
 	def __init__(self, file, keep_linebreaks=False, sequence_class=Sequence):
 		"""
 		file is a filename or a file-like object.
@@ -177,10 +167,8 @@ class FastaReader(object):
 		"""
 		if isinstance(file, basestring):
 			file = xopen(file)
-			self._file_passed = False
-		else:
-			self._file_passed = True
-		self.fp = file
+			self._close_on_exit = True
+		self._file = file
 		self.sequence_class = sequence_class
 		self.delivers_qualities = False
 		self._delimiter = '\n' if keep_linebreaks else ''
@@ -191,7 +179,7 @@ class FastaReader(object):
 		"""
 		name = None
 		seq = []
-		for i, line in enumerate(self.fp):
+		for i, line in enumerate(self._file):
 			# strip() also removes DOS line breaks
 			line = line.strip()
 			if not line:
@@ -213,12 +201,12 @@ class FastaReader(object):
 			yield self.sequence_class(name, self._delimiter.join(seq), None)
 
 	def close(self):
-		if not self._file_passed and self.fp is not None:
-			self.fp.close()
-			self.fp = None
+		if self._close_on_exit and self._file is not None:
+			self._file.close()
+			self._file = None
 
 	def __enter__(self):
-		if self.fp is None:
+		if self._file is None:
 			raise ValueError("I/O operation on closed FastaReader")
 		return self
 
@@ -235,7 +223,9 @@ class FastqReader(object):
 	"""
 	Reader for FASTQ files. Does not support multi-line FASTQ files.
 	"""
-	def __init__(self, file, sequence_class=Sequence):
+	_close_on_exit = False
+
+	def __init__(self, file, sequence_class=Sequence): # TODO could be a class attribute
 		"""
 		file is a filename or a file-like object.
 		If file is a filename, then .gz files are supported.
@@ -245,10 +235,8 @@ class FastqReader(object):
 		"""
 		if isinstance(file, basestring):
 			file = xopen(file)
-			self._file_passed = False
-		else:
-			self._file_passed = True
-		self.fp = file
+			self._close_on_exit = True
+		self._file = file
 		self.sequence_class = sequence_class
 		self.delivers_qualities = True
 
@@ -257,39 +245,39 @@ class FastqReader(object):
 		Return tuples: (name, sequence, qualities).
 		qualities is a string and it contains the unmodified, encoded qualities.
 		"""
-		for i, line in enumerate(self.fp):
+		for i, line in enumerate(self._file):
 			if i % 4 == 0:
 				if not line.startswith('@'):
-					raise FormatError("At line {0}: Expected a line starting with '@'".format(i+1))
+					raise FormatError("Line {0} in FASTQ file is expected to start with '@', but found {1!r}".format(i+1, line[:10]))
 				name = line.strip()[1:]
 			elif i % 4 == 1:
 				sequence = line.strip()
 			elif i % 4 == 2:
 				line = line.strip()
 				if not line.startswith('+'):
-					raise FormatError("At line {0}: Expected a line starting with '+'".format(i+1))
+					raise FormatError("Line {0} in FASTQ file is expected to start with '+', but found {1!r}".format(i+1, line[:10]))
 				if len(line) > 1:
-					twoheaders = True
-					if not line[1:] == name:
+					if line[1:] != name:
 						raise FormatError(
 							"At line {0}: Sequence descriptions in the FASTQ file do not match "
 							"({1!r} != {2!r}).\n"
 							"The second sequence description must be either empty "
 							"or equal to the first description.".format(
-								i+1, name, line.rstrip()[1:]))
+								i+1, name, line[1:].rstrip()))
+					name2 = name
 				else:
-					twoheaders = False
+					name2 = ''
 			elif i % 4 == 3:
 				qualities = line.rstrip('\n\r')
-				yield self.sequence_class(name, sequence, qualities, twoheaders=twoheaders)
+				yield self.sequence_class(name, sequence, qualities, name2=name2)
 
 	def close(self):
-		if not self._file_passed and self.fp is not None:
-			self.fp.close()
-			self.fp = None
+		if self._close_on_exit and self._file is not None:
+			self._file.close()
+			self._file = None
 
 	def __enter__(self):
-		if self.fp is None:
+		if self._file is None:
 			raise ValueError("I/O operation on closed FastqReader")
 		return self
 
@@ -317,6 +305,8 @@ class FastaQualReader(object):
 	"""
 	Reader for reads that are stored in .(CS)FASTA and .QUAL files.
 	"""
+	delivers_qualities = True
+
 	def __init__(self, fastafile, qualfile, sequence_class=Sequence):
 		"""
 		fastafile and qualfile are filenames or file-like objects.
@@ -328,7 +318,6 @@ class FastaQualReader(object):
 		self.fastareader = FastaReader(fastafile)
 		self.qualreader = FastaReader(qualfile, keep_linebreaks=True)
 		self.sequence_class = sequence_class
-		self.delivers_qualities = True
 
 	def __iter__(self):
 		"""
@@ -364,10 +353,26 @@ class ColorspaceFastaQualReader(FastaQualReader):
 		super(ColorspaceFastaQualReader, self).__init__(fastafile, qualfile, sequence_class=ColorspaceSequence)
 
 
+def sequence_names_match(r1, r2):
+	"""
+	Check whether the sequences r1 and r2 have identical names (ignoring /1 and
+	/2 suffixes).
+	"""
+	name1 = r1.name.split(None, 1)[0]
+	name2 = r2.name.split(None, 1)[0]
+	if name1[-2:-1] == '/':
+		name1 = name1[:-2]
+	if name2[-2:-1] == '/':
+		name2 = name2[:-2]
+	return name1 == name2
+
+
 class PairedSequenceReader(object):
 	"""
-	Wrap two SequenceReader instances, making sure that reads are
-	properly paired.
+	Read paired-end reads from two files.
+
+	Wraps two SequenceReader instances, making sure that reads are properly
+	paired.
 	"""
 	def __init__(self, file1, file2, colorspace=False, fileformat=None):
 		self.reader1 = open(file1, colorspace=colorspace, fileformat=fileformat)
@@ -375,6 +380,9 @@ class PairedSequenceReader(object):
 		self.delivers_qualities = self.reader1.delivers_qualities
 
 	def __iter__(self):
+		"""
+		Iterate over the paired reads. Each item is a pair of Sequence objects.
+		"""
 		# Avoid usage of zip() below since it will consume one item too many.
 		it1, it2 = iter(self.reader1), iter(self.reader2)
 		while True:
@@ -392,17 +400,211 @@ class PairedSequenceReader(object):
 				r2 = next(it2)
 			except StopIteration:
 				raise FormatError("Reads are improperly paired. There are more reads in file 1 than in file 2.")
+			if not sequence_names_match(r1, r2):
+				raise FormatError("Reads are improperly paired. Read name '{0}' "
+					"in file 1 does not match '{1}' in file 2.".format(r1.name, r2.name))
+			yield (r1, r2)
+
+	def close(self):
+		self.reader1.close()
+		self.reader2.close()
+
+	def __enter__(self):
+		return self
+
+	def __exit__(self, *args):
+		self.close()
 
-			name1 = r1.name.split(None, 1)[0]
-			name2 = r2.name.split(None, 1)[0]
-			if name1[-2:-1] == '/':
-				name1 = name1[:-2]
-			if name2[-2:-1] == '/':
-				name2 = name2[:-2]
-			if name1 != name2:
-				raise FormatError("Reads are improperly paired. Read name '{0}' in file 1 not equal to '{1}' in file 2.".format(name1, name2))
+
+class InterleavedSequenceReader(object):
+	"""
+	Read paired-end reads from an interleaved FASTQ file.
+	"""
+	def __init__(self, file, colorspace=False, fileformat=None):
+		self.reader = open(file, colorspace=colorspace, fileformat=fileformat)
+		self.delivers_qualities = self.reader.delivers_qualities
+
+	def __iter__(self):
+		# Avoid usage of zip() below since it will consume one item too many.
+		it = iter(self.reader)
+		for r1 in it:
+			try:
+				r2 = next(it)
+			except StopIteration:
+				raise FormatError("Interleaved input file incomplete: Last record has no partner.")
+			if not sequence_names_match(r1, r2):
+				raise FormatError("Reads are improperly paired. Name {0!r} "
+					"(first) does not match {1!r} (second).".format(r1.name, r2.name))
 			yield (r1, r2)
 
+	def close(self):
+		self.reader.close()
+
+	def __enter__(self):
+		return self
+
+	def __exit__(self, *args):
+		self.close()
+
+
+class FastaWriter(object):
+	"""
+	Write FASTA-formatted sequences to a file.
+	"""
+	_close_on_exit = False
+
+	def __init__(self, file, line_length=None):
+		"""
+		If line_length is not None, the lines will
+		be wrapped after line_length characters.
+		"""
+		self.line_length = line_length if line_length != 0 else None
+		if isinstance(file, str):
+			file = xopen(file, 'w')
+			self._close_on_exit = True
+		self._file = file
+
+	def write(self, name_or_seq, sequence=None):
+		"""Write an entry to the the FASTA file.
+
+		If only one parameter (name_or_seq) is given, it must have
+		attributes .name and .sequence, which are then used.
+		Otherwise, the first parameter must be the name and the second
+		the sequence.
+
+		The effect is that you can write this:
+		writer.write("name", "ACCAT")
+		or
+		writer.write(Sequence("name", "ACCAT"))
+		"""
+		if sequence is None:
+			name = name_or_seq.name
+			sequence = name_or_seq.sequence
+		else:
+			name = name_or_seq
+		if self.line_length is not None:
+			print('>{0}'.format(name), file=self._file)
+			for i in range(0, len(sequence), self.line_length):
+				print(sequence[i:i+self.line_length], file=self._file)
+			if len(sequence) == 0:
+				print(file=self._file)
+		else:
+			print('>{0}'.format(name), sequence, file=self._file, sep='\n')
+
+	def close(self):
+		if self._close_on_exit:
+			self._file.close()
+
+	def __enter__(self):
+		if self._file.closed:
+			raise ValueError("I/O operation on closed file")
+		return self
+
+	def __exit__(self, *args):
+		self.close()
+
+
+class ColorspaceFastaWriter(FastaWriter):
+	def write(self, record):
+		name = record.name
+		sequence = record.primer + record.sequence
+		super(ColorspaceFastaWriter, self).write(name, sequence)
+
+
+class FastqWriter(object):
+	"""
+	Write sequences with qualities in FASTQ format.
+
+	FASTQ files are formatted like this:
+	@read name
+	SEQUENCE
+	+
+	QUALITIS
+	"""
+	_close_on_exit = False
+
+	def __init__(self, file):
+		if isinstance(file, str):
+			file = xopen(file, "w")
+			self._close_on_exit = True
+		self._file = file
+
+	def write(self, record):
+		"""
+		Write a Sequence record to the the FASTQ file.
+
+		The record must have attributes .name, .sequence and .qualities.
+		"""
+		s = ('@' + record.name + '\n' + record.sequence + '\n+' +
+				record.name2 + '\n' + record.qualities + '\n')
+		self._file.write(s)
+
+	def writeseq(self, name, sequence, qualities):
+		print("@{0:s}\n{1:s}\n+\n{2:s}".format(
+			name, sequence, qualities), file=self._file)
+
+	def close(self):
+		if self._close_on_exit:
+			self._file.close()
+
+	def __enter__(self):
+		if self._file.closed:
+			raise ValueError("I/O operation on closed file")
+		return self
+
+	def __exit__(self, *args):
+		self.close()
+
+
+class ColorspaceFastqWriter(FastqWriter):
+	def write(self, record):
+		name = record.name
+		sequence = record.primer + record.sequence
+		qualities = record.qualities
+		super(ColorspaceFastqWriter, self).writeseq(name, sequence, qualities)
+
+
+class PairedSequenceWriter(object):
+	def __init__(self, file1, file2, colorspace=False, fileformat='fastq'):
+		self._writer1 = open(file1, colorspace=colorspace, fileformat=fileformat, mode='w')
+		self._writer2 = open(file2, colorspace=colorspace, fileformat=fileformat, mode='w')
+
+	def write(self, read1, read2):
+		self._writer1.write(read1)
+		self._writer2.write(read2)
+
+	def close(self):
+		self._writer1.close()
+		self._writer2.close()
+
+	def __enter__(self):
+		# TODO do not allow this twice
+		return self
+
+	def __exit__(self, *args):
+		self.close()
+
+
+class InterleavedSequenceWriter(object):
+	"""
+	Write paired-end reads to an interleaved FASTA or FASTQ file
+	"""
+	def __init__(self, file, colorspace=False, fileformat='fastq'):
+		self._writer = open(file, colorspace=colorspace, fileformat=fileformat, mode='w')
+
+	def write(self, read1, read2):
+		self._writer.write(read1)
+		self._writer.write(read2)
+
+	def close(self):
+		self._writer.close()
+
+	def __enter__(self):
+		return self
+
+	def __exit__(self, *args):
+		self.close()
+
 
 class UnknownFileType(Exception):
 	"""
@@ -410,16 +612,19 @@ class UnknownFileType(Exception):
 	"""
 
 
-def open(file1, file2=None, qualfile=None, colorspace=False, fileformat=None):
+def open(file1, file2=None, qualfile=None,
+	colorspace=False, fileformat=None, interleaved=False, mode='r'):
 	"""
 	Open sequence file in FASTA or FASTQ format. Parameters file1, file2 and
-	qualfile will be passed to xopen and can therefore be paths to regular or
-	compressed files or file-like objects. If only file1 is provided, a
-	FastaReader or FastqReader (for single-end reads) is returned. If file2
-	is also provided, a PairedSequenceReader is returned. If qualfile is
-	given, a FastaQualReader from file1 and qualfile is returned. One of file2
-	and qualfile must always be None (no paired-end data is supported when
-	reading qualfiles).
+	qualfile can be paths to regular or compressed files or file-like objects.
+	
+	If only file1 is provided and interleaved is True, an
+	InterleavedSequenceReader (for paired-end reads) is returned. If only file1 is provided and interleaved is False, a FastaReader
+	or FastqReader (for single-end reads) is returned. If file2 is also
+	provided, a PairedSequenceReader is returned. If qualfile is given, a
+	FastaQualReader from file1 and qualfile is returned. One of file2 and
+	qualfile must always be None (no paired-end data is supported when reading
+	qualfiles).
 
 	If the colorspace parameter is set to True, the returned readers are
 	ColorspaceFastaReader, ColorspaceFastqReader or ColorspaceFastaQualReader
@@ -432,40 +637,64 @@ def open(file1, file2=None, qualfile=None, colorspace=False, fileformat=None):
 	be skipped by setting fileformat to one of 'fasta', 'fastq', 'sra-fastq'.
 	Colorspace is not auto-detected and must always be requested explicitly.
 	"""
+	if mode not in ('r', 'w'):
+		raise ValueError("Mode must be 'r' or 'w'")
+	if interleaved and (file2 is not None or qualfile is not None):
+		raise ValueError("When interleaved is set, file2 and qualfile must be None")
 	if file2 is not None and qualfile is not None:
 		raise ValueError("Setting both file2 and qualfile is not supported")
 	if file2 is not None:
-		return PairedSequenceReader(file1, file2, colorspace, fileformat)
+		if mode == 'r':
+			return PairedSequenceReader(file1, file2, colorspace, fileformat)
+		else:
+			return PairedSequenceWriter(file1, file2, colorspace, fileformat)
+
+	if interleaved:
+		if mode == 'r':
+			return InterleavedSequenceReader(file1, colorspace, fileformat)
+		else:
+			return InterleavedSequenceWriter(file1, colorspace, fileformat)
 
 	if qualfile is not None:
+		if mode == 'w':
+			raise NotImplementedError('Writing to csfasta/qual not supported')
 		if colorspace:
 			# read from .(CS)FASTA/.QUAL
 			return ColorspaceFastaQualReader(file1, qualfile)
 		else:
 			return FastaQualReader(file1, qualfile)
 	# read from FASTA or FASTQ
-	fastq_reader = ColorspaceFastqReader if colorspace else FastqReader
-	fasta_reader = ColorspaceFastaReader if colorspace else FastaReader
-
-	if fileformat is not None:
+	if mode == 'r':
+		fastq_handler = ColorspaceFastqReader if colorspace else FastqReader
+		fasta_handler = ColorspaceFastaReader if colorspace else FastaReader
+	else:
+		fastq_handler = ColorspaceFastqWriter if colorspace else FastqWriter
+		fasta_handler = ColorspaceFastaWriter if colorspace else FastaWriter
+
+	if fileformat is not None:  # explict file format given
 		fileformat = fileformat.lower()
 		if fileformat == 'fasta':
-			return fasta_reader(file1)
+			return fasta_handler(file1)
 		elif fileformat == 'fastq':
-			return fastq_reader(file1)
+			return fastq_handler(file1)
 		elif fileformat == 'sra-fastq' and colorspace:
+			if mode == 'w':
+				raise NotImplementedError('Writing to sra-fastq not supported')
 			return SRAColorspaceFastqReader(file1)
 		else:
-			raise UnknownFileType("File format {0} is unknown (expected "
+			raise UnknownFileType("File format {0!r} is unknown (expected "
 				"'sra-fastq' (only for colorspace), 'fasta' or 'fastq').".format(fileformat))
 
+	if mode == 'w':
+		raise NotImplementedError('autodetection of file type for output files not implemented')
+
+	# Try to detect the file format
 	name = None
 	if file1 == "-":
 		file1 = sys.stdin
 	elif isinstance(file1, basestring):
 		name = file1
-	elif hasattr(file1, "name"):
-		# Assume that 'file1' is an open file1
+	elif hasattr(file1, "name"):  # file1 seems to be an open file-like object
 		name = file1.name
 
 	if name is not None:
@@ -478,12 +707,12 @@ def open(file1, file2=None, qualfile=None, colorspace=False, fileformat=None):
 		name, ext = splitext(name)
 		ext = ext.lower()
 		if ext in ['.fasta', '.fa', '.fna', '.csfasta', '.csfa']:
-			return fasta_reader(file1)
+			return fasta_handler(file1)
 		elif ext in ['.fastq', '.fq'] or (ext == '.txt' and name.endswith('_sequence')):
-			return fastq_reader(file1)
+			return fastq_handler(file1)
 		else:
-			raise UnknownFileType("Could not determine whether this is FASTA "
-				"or FASTQ: file name extension {0} not recognized".format(ext))
+			raise UnknownFileType("Could not determine whether file {0!r} is FASTA "
+				"or FASTQ: file name extension {1!r} not recognized".format(file1, ext))
 
 	# No name available.
 	# autodetect type by reading from the file
@@ -492,7 +721,7 @@ def open(file1, file2=None, qualfile=None, colorspace=False, fileformat=None):
 			# Skip comment lines (needed for csfasta)
 			continue
 		if line.startswith('>'):
-			return fasta_reader(FileWithPrependedLine(file1, line))
+			return fasta_handler(FileWithPrependedLine(file1, line))
 		if line.startswith('@'):
-			return fastq_reader(FileWithPrependedLine(file1, line))
+			return fastq_handler(FileWithPrependedLine(file1, line))
 	raise UnknownFileType("File is neither FASTQ nor FASTA.")
diff --git a/doc/guide.rst b/doc/guide.rst
index e6b665c..f17c10d 100644
--- a/doc/guide.rst
+++ b/doc/guide.rst
@@ -56,7 +56,7 @@ as expected::
 
     cutadapt -a AACCGGTT -o output.fastq.gz input.fastq.gz
 
-Note that the all of cutadapt's options that expect a file name support this.
+All of cutadapt's options that expect a file name support this.
 
 Files compressed with bzip2 (``.bz2``) or xz (``.xz``) are also supported, but
 only if the Python installation includes the proper modules. xz files require
@@ -78,7 +78,7 @@ can redirect it to a file like this::
 
     cutadapt -a AACCGGTT input.fastq > output.fastq 2> report.txt
 
-Anywhere cutadapt expects a file name, you can also write a dash (``-``) in
+Wherever cutadapt expects a file name, you can also write a dash (``-``) in
 order to specify that standard input or output should be used. For example::
 
     tail -n 4 input.fastq | cutadapt -a AACCGGTT - > output.fastq
@@ -102,8 +102,27 @@ you could use something like this::
     cutadapt -a AACCGGTT -o /dev/null input.fastq
 
 
-Trimming reads
-==============
+Read processing
+===============
+
+Cutadapt can do a lot more in addition to removing adapters. There are various
+command-line options that make it possible to modify and filter reads and to
+redirect them to various output files. Each read is processed in the following
+way:
+
+1. :ref:`Read modification options <modifying-reads>` are applied. This includes
+   :ref:`adapter removal <removing-adapters>`,
+   :ref:`quality trimming <quality-trimming>`, read name modifications etc.
+2. :ref:`Filtering options <filtering>` are applied, such as removal of too
+   short or untrimmed reads. Some of the filters also allow to redirect a read
+   to a separate output file.
+3. If the read has passed all the filters, it is written to the output file.
+
+
+.. _removing-adapters:
+
+Removing adapters
+=================
 
 Cutadapt supports trimming of multiple types of adapters:
 
@@ -170,8 +189,8 @@ starts with an adapter, like this::
 
     ADAPTERSOMETHING
 
-Then the sequence will be empty after trimming. Note that, by default, empty
-reads are not discarded and will appear in the output.
+Then the sequence will be empty after trimming. By default, empty reads are kept
+and will appear in the output.
 
 
 .. _five-prime-adapters:
@@ -246,11 +265,11 @@ Anchored 3' adapters
 --------------------
 
 It is also possible to anchor 3' adapters to the end of the read. This is
-rarely necessary, but if you have, for example, merged overlapping paired-end
-reads, then this may be useful. Add the ``$`` character to the end of an
+rarely necessary, but if you have merged, for example, overlapping paired-end
+reads, then it is useful. Add the ``$`` character to the end of an
 adapter sequence specified via ``-a`` in order to anchor the adapter to the
 end of the read, such as ``-a ADAPTER$``. The adapter will only be found if it
-as a *suffix* of the read, but errors are still allowed as for 5' adapters.
+is a *suffix* of the read, but errors are still allowed as for 5' adapters.
 You can disable insertions and deletions with ``--no-indels``.
 
 Anchored 3' adapters work as if you had reversed the sequence and used an
@@ -268,7 +287,7 @@ Using ``-a ADAPTER$`` will result in::
     MYSEQUENCE
     MYSEQUENCEADAPTERSOMETHINGELSE
 
-That is, only the middle read is trimmed at all.
+Only the middle read is trimmed at all.
 
 
 .. _anywhere-adapters:
@@ -289,7 +308,7 @@ partially). The decision which part of the read to remove is made as follows: If
 there is at least one base before the found adapter, then the adapter is
 considered to be a 3' adapter and the adapter itself and everything
 following it is removed. Otherwise, the adapter is considered to be a 5'
-adapter and it is removed from the read, but the sequence after it it remains.
+adapter and it is removed from the read, but the sequence after it remains.
 
 Here are some examples.
 
@@ -305,7 +324,7 @@ Read before trimming           Read after trimming Detected adapter type
 ``TERMYSEQUENCE``              ``MYSEQUENCE``      5' adapter
 ============================== =================== =====================
 
-The ``-b`` option does not work with colorspace data.
+The ``-b`` option cannot be used with colorspace data.
 
 
 .. _error-tolerance:
@@ -432,6 +451,14 @@ you use this feature. For poly-A trimming, for example, you would write::
     cutadapt -a "A{100}" -o output.fastq input.fastq
 
 
+.. _modifying-reads:
+
+Modifying reads
+===============
+
+This section describes in which ways reads can be modified other than adapter
+removal.
+
 .. _cut-bases:
 
 Removing a fixed number of bases
@@ -512,24 +539,131 @@ the trimming position. Therefore, the read is trimmed to the first four bases,
 which have quality values 42, 40, 26, 27.
 
 
+Modifying read names
+--------------------
+
+If you feel the need to modify the names of processed reads, some of the
+following options may be useful.
+
+Use ``-y`` or ``--suffix`` to append a text to read names. The given string can
+contain the placeholder ``{name}``, which will be replaced with the name of the
+adapter found in that read. For example, writing ::
+
+    cutadapt -a adapter1=ACGT -y ' we found {name}' input.fastq
+
+changes a read named ``read1`` to ``read1 we found adapter1`` if the adapter
+``ACGT`` was found. The options ``-x``/``--prefix`` work the same, but the text
+is added in front of the read name. For both options, spaces need to be
+specified explicitly, as in the above example. If no adapter was found in a
+read, the text ``no_adapter`` is inserted for ``{name}``.
+
+In order to remove a suffix of each read name, use ``--strip-suffix``.
+
+Some old 454 read files contain the length of the read in the name::
+
+    >read1 length=17
+    ACGTACGTACAAAAAAA
+
+If you want to update this to the correct length after trimming, use the option
+``--length-tag``. In this example, this would be ``--length-tag 'length='``.
+After trimming, the read would perhaps look like this::
+
+    >read1 length=10
+    ACGTACGTAC
+
+
+Read modification order
+-----------------------
+
+The read modifications described above are applied in the following order to
+each read. Steps not requested on the command-line are skipped.
+
+1. Unconditional base removal with ``--cut``
+2. Quality trimming (``-q``)
+3. Adapter trimming (``-a``, ``-b``, ``-g`` and uppercase versions)
+4. N-end trimming (``--trim-n``)
+5. Length tag modification (``--length-tag``)
+6. Read name suffixe removal (``--strip-suffix``)
+7. Addition of prefix and suffix to read name (``-x``/``--prefix`` and ``-y``/``--suffix``)
+8. Double-encode the sequence (only colorspace)
+9. Replace negative quality values with zero (zero capping, only colorspace)
+10. Trim primer base (only colorspace)
+
+The last three steps are colorspace-specific.
+
+
+.. _filtering:
+
+Filtering reads
+===============
+
+By default, all processed reads, no matter whether they were trimmed are not,
+are written to the output file specified by the ``-o`` option (or to standard
+output if ``-o`` was not provided). For paired-end reads, the second read in a
+pair is always written to the file specified by the ``-p`` option.
+
+The options described here make it possible to filter reads by either discarding
+them entirely or by redirecting them to other files. When redirecting reads,
+the basic rule is that *each read is written to at most one file*. You cannot
+write reads to more than one output file.
+
+In the following, the term "processed read" refers to a read to which all
+modifications have been applied (adapter removal, quality trimming etc.). A
+processed read can be identical to the input read if no modifications were done.
+
+
+``--minimum-length N`` or ``-m N``
+    Throw away processed reads shorter than *N* bases.
+
+``--too-short-output FILE``
+    Instead of throwing away the reads that are too short according to ``-m``,
+    write them to *FILE* (in FASTA/FASTQ format).
+
+``--maximum-length N`` or ``-M N``
+    Throw away processed reads longer than *N* bases.
+
+``--too-long-output FILE``
+    Instead of throwing away the reads that are too long (according to ``-M``),
+    write them to *FILE* (in FASTA/FASTQ format).
+
+``--untrimmed-output FILE``
+    Write all reads without adapters to *FILE* (in FASTA/FASTQ format) instead
+    of writing them to the regular output file.
+
+``--discard-trimmed``
+   Throw away reads in which an adapter was found.
+
+``--discard-untrimmed``
+   Throw away reads in which *no* adapter was found. This has the same effect as
+   specifying ``--untrimmed-output /dev/null``.
+
+The options ``--too-short-output`` and ``--too-long-output`` are applied first.
+This means, for example, that a read that is too long will never end up in the
+``--untrimmed-output`` file when ``--too-long-output`` was given, no matter
+whether it was trimmed or not.
+
+The options ``--untrimmed-output``, ``--discard-trimmed`` and ``-discard-untrimmed``
+are mutually exclusive.
+
+
 .. _paired-end:
 
 Trimming paired-end reads
 =========================
 
-Cutadapt supports trimming of paired-end reads. Starting with cutadapt 1.8,
-both reads in a pair can be trimmed at the same time. It is no longer necessary
-to run cutadapt twice.
+Cutadapt supports trimming of paired-end reads, trimming both reads in a pair
+at the same time.
 
 Assume the input is in ``reads.1.fastq`` and ``reads.2.fastq`` and that
 ``ADAPTER_FWD`` should be trimmed from the forward reads (first file)
 and ``ADAPTER_REV`` from the reverse reads (second file).
 
-The basic command-line is (``-p`` is the short form of ``--paired-output``)::
+The basic command-line is::
 
     cutadapt -a ADAPTER_FWD -A ADAPTER_REV -o out.1.fastq -p out.2.fastq reads.1.fastq reads.2.fastq
 
-The option ``-A`` is used here to specify an adapter sequence that cutadapt
+``-p`` is the short form of ``--paired-output``. The option ``-A`` is used here
+to specify an adapter sequence that cutadapt
 should remove from the second read in each pair. There are also the options
 ``-G``, ``-B``. All of them work just like their lowercase counterparts,
 except that the adapter is searched for in the second read in each paired-end
@@ -558,12 +692,13 @@ is mandatory you process both files at the same time to make sure that the
 output files are kept synchronized: If a read is removed from one of the files,
 cutadapt will ensure it is also removed from the other file.
 
+
 The following command-line options are applied to *both* reads:
 
-* ``-q``
-* ``--quality-base``
+* ``-q`` (along with ``--quality-base``)
 * ``--times`` applies to all the adapters given
 * ``--no-trim``
+* ``--trim-n``
 * ``--mask``
 * ``--length-tag``
 * ``--prefix``, ``--suffix``
@@ -571,18 +706,79 @@ The following command-line options are applied to *both* reads:
 * ``--colorspace``, ``--bwa``, ``-z``, ``--no-zero-cap``, ``--double-encode``,
   ``--trim-primer``
 
-In paired-end mode, the filtering options discard the read pair if *any*
+The following limitations still exist:
+
+* The ``--info-file``, ``--rest-file`` and ``--wildcard-file`` options write out
+  information only from the first read.
+* Demultiplexing is not yet supported with paired-end data.
+
+
+
+.. _filtering-paired:
+
+Filtering paired-end reads
+--------------------------
+
+The :ref:`filtering options listed above <filtering>` can also be used when
+trimming paired-end data. Since there are two reads, however, the filtering
+criteria are checked for both reads. The question is what to do when a criterion
+applies to only one read and not the other.
+
+By default, the filtering options discard or redirect the read pair if *any*
 of the two reads fulfill the criteria. That is, ``--max-n`` discards the pair
 if one of the two reads has too many ``N`` bases; ``--discard-untrimmed``
 discards the pair if one of the reads does not contain an adapter;
 ``--minimum-length`` discards the pair if one of the reads is too short;
 and ``--maximum-length`` discards the pair if one of the reads is too long.
+Note that the ``--discard-trimmed`` filter would also apply because it is also
+the case that at least one of the reads is *trimmed*!
 
-The following limitations still exist:
+To require that filtering criteria must apply to *both* reads in order for a
+read pair to be considered "filtered", use the option ``--pair-filter=both``.
 
-* The ``--info-file``, ``--rest-file`` and ``--wildcard-file`` options write out
-  information only from the first read.
-* Demultiplexing is not yet supported with paired-end data.
+To further complicate matters, cutadapt switches to a backwards compatibility
+mode ("legacy mode") when none of the uppercase modification options
+(``-A``/``-B``/``-G``/``-U``) are given. In that mode, filtering criteria are
+checked only for the *first* read. Cutadapt will also tell you at the top of
+the report whether legacy mode is active. Check that line if you get strange
+results!
+
+These are the paired-end specific filtering and output options:
+
+``--paired-output FILE`` or ``-p FILE``
+    Write the second read of each processed pair to *FILE* (in FASTA/FASTQ
+    format).
+
+``--untrimmed-paired-output FILE``
+    Used together with ``--untrimmed-output``. The second read in a pair is
+    written to this file when the processed pair was *not* trimmed.
+
+``--pair-filter=(any|both)``
+    Which of the reads in a paired-end read have to match the filtering
+    criterion in order for it to be filtered.
+
+Note that the option names can be abbreviated as long as it is clear which
+option is meant (unique prefix). For example, instead of ``--untrimmed-output``
+and ``--untrimmed-paired-output``, you can write ``--untrimmed-o`` and
+``--untrimmed-p``.
+
+
+Interleaved paired-end reads
+----------------------------
+
+Paired-end reads can be read from a single FASTQ file in which the entries for
+the first and second read from each pair alternate. The first read in each pair
+comes before the second. Enable this file format by adding the ``--interleaved``
+option to the command-line. For example::
+
+    cutadapt --interleaved -q 20 -a ACGT -A TGCA -o trimmed.fastq reads.fastq
+
+The output FASTQ file will also be written interleaved. Cutadapt will detect if
+the input file is not properly interleaved by checking whether read names match
+and whether the file contains an even number of entries.
+
+When ``--interleaved`` is used, legacy mode is disabled (that is,
+read-modification options such as ``-q`` always apply to both reads).
 
 
 Legacy paired-end read trimming
@@ -628,7 +824,7 @@ Finally, remove the temporary files::
 Please see the previous section for a much simpler way of trimming paired-end
 reads!
 
-In the legacy paired-end mode, the read-modifying options such as ``-q`` only
+In legacy paired-end mode, the read-modifying options such as ``-q`` only
 apply to the first file in each call to cutadapt (first ``reads.1.fastq``, then
 ``tmp.2.fastq`` in this example). Reads in the second file are not affected by those
 options, but by the filtering options: If a read in the first file is
@@ -717,7 +913,7 @@ Adapter names are also used in column 8 of :ref:`info files <info-file>`.
 Demultiplexing
 --------------
 
-Cutadapt supports demultiplexing: That is, reads can be written to different
+Cutadapt supports demultiplexing, which means that reads are written to different
 output files depending on which adapter was found in them. To use this, include
 the string ``{name}`` in the name of the output file and give each adapter a name.
 The path is then interpreted as a template and each trimmed read is written
@@ -727,7 +923,7 @@ file in which ``{name}`` is replaced with ``unknown``.
 
 .. note:
     Demultiplexing is currently only supported for single-end reads. Paired-end
-    support is planned for the next version.
+    support is planned for one of the next versions.
 
 Example::
 
@@ -932,71 +1128,6 @@ Cutadapt's output
 =================
 
 
-Where trimmed and untrimmed reads go
-------------------------------------
-
-By default, all processed reads, no matter whether they were trimmed are not,
-are written to the output file specified by the ``-o`` option (or to standard
-output if ``-o`` was not provided). For paired-end reads, the second read in a
-pair is always written to the file specified by the ``-p`` option.
-
-The options described in the following make it possible to redirect the reads
-to other files depending on their length and depending on whether they were
-trimmed or not. However, the basic rule here is that *each read is written to
-at most one file*. You cannot write reads to more than one output file.
-
-In the following, the term "processed read" refers to a read which has been
-quality trimmed (if ``-q`` has been used) and in which all found adapters have
-been removed. A processed read may be identical with the input read if no
-bases were quality-trimmed and no adapters were found.
-
-``--minimum-length N`` or ``-m N``
-    Use this to throw away processed reads shorter than *N* bases.
-
-``--too-short-output FILE``
-    Instead of throwing away the reads that are too short (according to ``-m``),
-    write them to *FILE* (in FASTA/FASTQ format).
-
-``--maximum-length N`` or ``-M N``
-    Use this to throw away processed reads longer than *N* bases.
-
-``--too-long-output FILE``
-    Instead of throwing away the reads that are too long (according to ``-M``),
-    write them to *FILE* (in FASTA/FASTQ format).
-
-``--untrimmed-output FILE``
-    Write all reads without adapters to *FILE* (in FASTA/FASTQ format) instead
-    of writing them to the regular output file.
-
-``--discard-trimmed``
-   Throw away reads in which an adapter was found.
-
-``--discard-untrimmed``
-   Throw away read in which no adapter was found. This has the same effect as
-   specifying ``--untrimmed-output /dev/null``.
-
-The options ``--too-short-output`` and ``--too-long-output`` are applied first.
-This means, for example, that a read that is too long will never end up in the
-``--untrimmed-output`` file when ``--too-long-output`` was given, no matter
-whether it was trimmed or not.
-
-The following options apply only when trimming paired-end data.
-
-``--paired-output FILE`` or ``-p FILE``
-    The second read in a pair is written to *FILE* (in FASTA/FASTQ format), but
-    only if also the first read was written to the first file.
-
-``--untrimmed-paired-output FILE``
-    When the first read in a pair was not trimmed, write the second read to
-    *FILE* instead of writing it to the regular output file. Use this together
-    with ``--untrimmed-output`` when trimming paired-end data.
-
-Note that the option names can be abbreviated as long as it is clear which
-option is meant (unique prefix). For example, instead of ``--untrimmed-output``
-and ``--untrimmed-paired-output``, you can write ``--untrimmed-o`` and
-``--untrimmed-p``.
-
-
 How to read the report
 ----------------------
 
@@ -1090,28 +1221,36 @@ of the input file (unless `--times` is used, see below). The fields are:
 6. Sequence of the read that was matched to the adapter
 7. Sequence of the read to the right of the adapter match (can be empty)
 8. Name of the found adapter.
+9. Quality values corresponding to sequence left of the adapter match (can be empty)
+10. Quality values corresponding to sequence matched to the adapter (can be empty)
+11. Quality values corresponding to sequence to the right of the adapter match (can be empty)
 
-The concatenation of the fields 5-7 yields the full read sequence. Column 8
-identifies the found adapter. `The section about named
-adapters <named-adapters>` describes how to give a name to an adapter. Adapters
-without a name are numbered starting from 1.
+The concatenation of the fields 5-7 yields the full read sequence. Column 8 identifies
+the found adapter. `The section about named adapters <named-adapters>` describes
+how to give a name to an adapter. Adapters without a name are numbered starting
+from 1. Fields 9-11 are empty if quality values are not available.
+Concatenating them yields the full sequence of quality values.
 
 If no adapter was found, the format is as follows:
 
-1.  Read name
-2.  The value -1
-3.  The read sequence
+1. Read name
+2. The value -1
+3. The read sequence
+4. Quality values
 
-When parsing that file, be aware that additional columns may be added in
+When parsing the file, be aware that additional columns may be added in
 the future. Note also that some fields can be empty, resulting in
 consecutive tabs within a line.
 
 If the ``--times`` option is used and greater than 1, each read can appear
 more than once in the info file. There will be one line for each found adapter,
 all with identical read names. Only for the first of those lines will the
-concatenation of columns 5-7 be identical to the original read sequence. For
-subsequent lines, the shown sequence are the ones that were used in subsequent
-rounds of adapter trimming, that is, they get successively shorter.
+concatenation of columns 5-7 be identical to the original read sequence (and
+accordingly for columns 9-11). For subsequent lines, the shown sequence are the
+ones that were used in subsequent rounds of adapter trimming, that is, they get
+successively shorter.
+
+Columns 9-11 have been added in cutadapt version 1.9.
 
 
 .. _algorithm:
@@ -1149,8 +1288,8 @@ of *x* mean? Is that good or bad? How should a threshold be chosen in order to
 avoid finding alignments with too many errors?
 
 For cutadapt, the adapter alignment algorithm uses *unit costs* instead.
-Mismatches, insertions and deletions are therefore counted as one error, which
-is easier to understand and always to specify a single parameter for the
+This means that mismatches, insertions and deletions are counted as one error, which
+is easier to understand and allows to specify a single parameter for the
 algorithm (the maximum error rate) in order to describe how many errors are
 acceptable.
 
diff --git a/doc/ideas.rst b/doc/ideas.rst
index a474205..794be2c 100644
--- a/doc/ideas.rst
+++ b/doc/ideas.rst
@@ -21,9 +21,9 @@ improvements.
 - it seems the str.find optimization isn't very helpful. In any case, it should be
   moved into the Aligner class.
 - allow to remove not the adapter itself, but the sequence before or after it
-- convert adapter to lowercase
+- instead of trimming, convert adapter to lowercase
 - warn when given adapter sequence contains non-IUPAC characters
-- try multithreading again, this time use os.pipe()
+- try multithreading again, this time use os.pipe() or 0mq
 
 
 Specifying adapters
@@ -38,7 +38,7 @@ new adapter types in the feature.
     back,``-a ADAPTER``,``-a ADAPTER`` or ``-a ...ADAPTER``
     suffix,``-a ADAPTER$``,``-a ...ADAPTER$``
     front,``-g ADAPTER``,``-a ADAPTER...``
-    prefix,``-g ^ADAPTER``,``-a ^ADAPTER...``
+    prefix,``-g ^ADAPTER``,``-a ^ADAPTER...`` (or have anchoring by default?)
     anywhere,``-b ADAPTER``, ``-a ...ADAPTER...`` ???
     paired,(not implemented),``-a ADAPTER...ADAPTER`` or ``-a ^ADAPTER...ADAPTER``
 
@@ -55,16 +55,47 @@ picked. Default right now: Leftmost, even for -g adapters.
 
 Allow ``N{3,10}`` as in regular expressions (for a variable-length sequence).
 
+Use parentheses to specify the part of the sequence that should be kept:
+
+* ``-a (...)ADAPTER`` (default)
+* ``-a (...ADAPTER)`` (default)
+* ``-a ADAPTER(...)`` (default)
+* ``-a (ADAPTER...)`` (??)
+
+Or, specify the part that should be removed:
+
+    ``-a ...(ADAPTER...)``
+    ``-a ...ADAPTER(...)``
+    ``-a (ADAPTER)...``
+
+Model somehow all the flags that exist for semiglobal alignment. For start of the adapter:
+
+* Start of adapter can be degraded or not
+* Bases are allowed to be before adapter or not
+
+Not degraded and no bases before allowed = anchored.
+Degraded and bases before allowed = regular 5'
+
+By default, the 5' end should be anchored, the 3' end not.
+
+* ``-a ADAPTER...`` → not degraded, no bases before allowed
+* ``-a N*ADAPTER...`` → not degraded, bases before allowed
+* ``-a ADAPTER^...`` → degraded, no bases before allowed
+* ``-a N*ADAPTER^...`` → degraded, bases before allowed
+* ``-a ...ADAPTER`` → degraded, bases after allowed
+* ``-a ...ADAPTER$`` → not degraded, no bases after allowed
+
+
 
 Paired-end trimming
 -------------------
 
 * Could also use a paired-end read merger, then remove adapters with -a and -g
-* Should minimum overlap be sum of the two overlaps in each read?
 
+Available/used letters for command-line options
+-----------------------------------------------
 
-Single-letter command-line options
-----------------------------------
+* Remaining characters: All uppercase letters except A, B, G, M, N, O, U
+* Lowercase letters: i, j, k, l, s, w
+* Planned/reserved: Q (paired-end quality trimming), j (multithreading)
 
-Remaining characters: All uppercase letters except A, B, G, M, N, O
-Lowercase letters: i, j, k, l, s, w
diff --git a/tests/cut/illumina.info.txt b/tests/cut/illumina.info.txt
index e424484..f8ad1fc 100644
--- a/tests/cut/illumina.info.txt
+++ b/tests/cut/illumina.info.txt
@@ -1,100 +1,100 @@
-SEQ:1:1101:9010:3891#0/1 adapter start: 51	1	51	81	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAGCCAAGATGGGAAAGGTC	adapt
-SEQ:1:1101:9240:3898#0/1	-1	CCAGCAAGGAAGCCAAGATGGGAAAGGTCATGCGGCATACGCTCGGCGCCAGTTTGAATATTAGACATAATTTATCCTCAAGTAAGGGGCCGAAGCCCCTG
-SEQ:1:1101:9207:3899#0/1 adapter start: 64	1	64	94	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAAC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATACATA	adapt
-SEQ:1:1101:9148:3908#0/1 adapter start: 28	1	28	58	ACGACGCAATGGAGAAAGACGGAGAGCG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATAACCGGAG	adapt
-SEQ:1:1101:9044:3916#0/1 adapter start: 78	1	78	101	AACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTATGGAAAACACCAATCTTTCCAAGCAACAGCAGGTTTCCGAGA	GCCTAACTTCTTAGACTGCCTTA		adapt
-SEQ:1:1101:9235:3923#0/1	-1	TTGATGCGGTTATCCATCTGCTTATGGAAGCCAAGCATTGGGGATTGAGAAAGAGTAGAAATGCCACAAGCCTCAATAGCAGGTTTAAGAGCCTCGATACG
-SEQ:1:1101:9086:3930#0/1 adapter start: 46	1	46	76	CCATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGTAGTCGGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCGAAGAAGACTCAAAGCGAACCAA	adapt
-SEQ:1:1101:9028:3936#0/1	-1	CTTGATATTAATAACACTATAGACCACCGCCCCGAAGGGGACGAAAAATGGTTTTTAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGC
-SEQ:1:1101:9185:3939#0/1	-1	CGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGCTCCTGTTGAGTTTATTGCTGCCGTCATTGCTTATTATGTTCATC
-SEQ:1:1101:9140:3961#0/1 adapter start: 66	1	66	96	CAGGAGAAACATACGAAGGCGCATAACGATACCACTGACCCTCAGCAATCTTAAACTTCTTAGACG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AATCA	adapt
-SEQ:1:1101:9073:3961#0/1 adapter start: 49	1	49	79	GTGGCAAGTCTGCCGCTGATAAAGGAAAGGATACTCGTGATTATCTTGC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGCTGCATTTCCTGAGCTTAAT	adapt
-SEQ:1:1101:9196:3971#0/1 adapter start: 18	1	18	48	ACCAGAAGGCGGTTCCTG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AATGAATGGGAAGCCTTCAAGAAGGTGATAAGCAGGAGAAACATACGAAGGCG	adapt
-SEQ:1:1101:9053:3973#0/1	-1	TTCACGTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAGCCGCTTAAAGCTACCAGGTTTATTGCTGTTTGTTTCTATGTGGCTTAAAACGTTACCA
-SEQ:1:1101:9120:3979#0/1	-1	GGCGTTGACAGATGTATCCATCTGAATGCAATGAAGAAAACCACCATTACCAGCATTAACCGTCAAACTATCAAAATATAACGTTGACGATGTAGCTTTAG
-SEQ:1:1101:9045:3988#0/1 adapter start: 91	1	91	101	TAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGCAGTGTTAA	GCCTAACTTC		adapt
-SEQ:1:1101:9418:3756#0/1	-1	TAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCATGAACTTAATCCACTGT
-SEQ:1:1101:9394:3759#0/1	-1	CCCTCGCTTTCCTGCTCCTGTTGAGGTTATTGCTGCCGTCATTGCTTATTATGTTCATCTCGGCAACATTCATACGGTCTGGCTTATCCGTGCAGAGACTG
-SEQ:1:1101:9365:3766#0/1	-1	AAGCACATCACCTTGAATGCCACCGGAGGCGGCTTTTTGACCGCCTCCAAACAATTTAGACATGGCGCCACCAGCAAGAGCAGAAGCAATACCGCCAGCAA
-SEQ:1:1101:9436:3776#0/1	-1	GAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGGAGTCGGA
-SEQ:1:1101:9354:3801#0/1	-1	CCAGCAAGAGCAGAAGCAATACCGCCAGCAATAGCACCAAACATAAATCACCTCACTTAAGTGGCTGGAGACAAATAATCTCTTTAATAACCTGATTCAGC
-SEQ:1:1101:9389:3804#0/1 adapter start: 28	1	28	58	ATTAGAGCCAATACCATCAGCTTTACCG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAA	adapt
-SEQ:1:1101:9477:3819#0/1 adapter start: 28	1	28	58	ATAAAGGAAAGGATACTCGTGATTATCT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGCTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGT	adapt
-SEQ:1:1101:9428:3823#0/1	-1	CGTCAGTAAGAACGTCAGTGTTTCCTGCGCGTACACGCAAGGTAAACGCGAACAATTCAGCGGCTTTAACCGGACGCTCGACGCCATTAATAATGTTTTCC
-SEQ:1:1101:9403:3824#0/1 adapter start: 70	1	70	100	GCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	C	adapt
-SEQ:1:1101:9362:3824#0/1	-1	ACCATGAAACCAACATAAACATTATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATC
-SEQ:1:1101:9480:3842#0/1 adapter start: 54	1	54	84	GTACGGATTGTTCAGTAACTTGACTCATGATTTCTTACCTATTAGTGGTTGAAC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCATCGGACTCAGATA	adapt
-SEQ:1:1101:9286:3846#0/1	-1	TGATTAAACTCCTAAGCAGAAAACCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGTTATAACCTCACACT
-SEQ:1:1101:9403:3867#0/1 adapter start: 1	1	1	31	G	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGT	adapt
-SEQ:1:1101:9341:3873#0/1 adapter start: 88	1	88	101	CCTAAGCAGAAAACCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGTTATAACCTCAC	GCCTAACTTCTTA		adapt
-SEQ:1:1101:9381:3881#0/1 adapter start: 41	1	41	71	ACGTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAGC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCTTAAAGCTACCAGTTATATGGCTGTTG	adapt
-SEQ:1:1101:9360:3884#0/1	-1	TAATACCTTTCTTTTTGGGGTAATTATACTCATCGCGAATATCCTTAAGAGGGCGTTCAGCAGCCAGCTTGCGGCAAAACTGCGTAACCGTCTTCTCGTTC
-SEQ:1:1101:9323:3894#0/1 adapter start: 100	-1	ATACCGATATTGCTGGCGACCCTGTTTTGTATGGCAACTTGCCGCCGCGTGAAATTTCTATGAAGGATGTTTTCCGTTCTGGTGATTCGTCTAAGAAGTTG
-SEQ:1:1101:9267:3900#0/1 adapter start: 89	1	89	101	GTTTTGGATTTAACCGAAGATGATTTCGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCGCTGCGT	GCCTAACTTCTT		adapt
-SEQ:1:1101:9416:3909#0/1	-1	TAAACGTGACGATGAGGGACATAAAAAGTAAAAATGTCTACAGTAGAGTCAATAGCAAGGCCACGACGCAATGGAGAAAGACGGAGAGCGCCAACGGCGTC
-SEQ:1:1101:9360:3917#0/1 adapter start: 68	1	68	98	ATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGGTTGACGCCGGATTTGAGAATCAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAA	adapt
-SEQ:1:1101:9337:3918#0/1 adapter start: 14	1	14	44	CATCAGCACCAGCA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCTCCCAAGCATTAAGCTCAGGAAATGCAGCAGCAAGATAATCACGAGTATCCTTT	adapt
-SEQ:1:1101:9307:3927#0/1 adapter start: 15	1	15	45	TCAGCGCCTTCCATG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATGAGACAGGCCGTTTGAATGTTGACGGGATGAACATAATAAGCAATGACGGCAGC	adapt
-SEQ:1:1101:9479:3929#0/1 adapter start: 9	1	9	39	GACAAATTA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAGCCAATACCATCAGCTTTACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTT	adapt
-SEQ:1:1101:9277:3934#0/1 adapter start: 71	1	71	101	CTGTCTTTTCGTATGCAGGGCGTTGAGTTCGATAATGGTGATATGTATGTTGACGGCCATAAGGCTGCTTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT		adapt
-SEQ:1:1101:9442:3934#0/1	-1	AGACCCATAATGTCAATAGATGTGGTAGAAGTCGTCATTTGGCGAGAAAGCTCAGTCTCAGGAGGAAGCGGAGCAGTCCAAATGTTTTTGAGATGGCAGCA
-SEQ:1:1101:9329:3935#0/1	-1	AGATGGATAACCGCATCAAGCTCTTGGAAGAGATTCTGTCTTTTCGTATGCAGGGCGTTGAGTTCGATAATGGTGATATGTATGTTGACGGCCATAAGGCT
-SEQ:1:1101:9445:3956#0/1 adapter start: 81	1	81	101	TGCAACAACTGAACGGACTGGAAACACTGGTCATAATCATGGTGGCGAATAAGTACGCGTTCTTGCAAATCACCAGAAGGC	GCCTAACTTCTTAGACTGCC		adapt
-SEQ:1:1101:9357:3957#0/1	-1	TTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCATGAACTTAATCCACTG
-SEQ:1:1101:9487:3957#0/1	-1	CAATAAAATCCCTAAGCATTTGTTTCAGGGTTATTTGAATATCTATAACAACTATTTTAAAGCGCCGTGGATGCCTGACCGTACCGAGGCTAACCCTAATG
-SEQ:1:1101:9309:3957#0/1 adapter start: 72	1	72	101	GTCAGATATGGACCTTGCTGCTAAAGGTCTAGGAGCTAAAGAATGGAACAACTCACTAAAAACCAAGCTGTC	GCCTAACTTCTTAGACTGCCTTAAGGACG		adapt
-SEQ:1:1101:9425:3960#0/1	-1	CTGACGCAGAAGAAAACGTGCGTCAAAAATTACGTGCAGAAGGAGTGATGTAATGTCTAAAGGTAAAAAACGTTCTGGCGCTCGCCCTGGTCGTCCGCAGC
-SEQ:1:1101:9337:3969#0/1	-1	GAATTAAATCGAAGTGGACTGCTGGCGGAAAATGAGAAAATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCTTTCGCCATCAACTAA
-SEQ:1:1101:9388:3971#0/1	-1	CTGAATCTCTTTAGTCGCAGTAGGCGGAAAACGAACAAGCGCAAGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGG
-SEQ:1:1101:9414:3978#0/1 adapter start: 99	-1	TTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCGC
-SEQ:1:1101:9494:3983#0/1 adapter start: 72	1	72	101	TAGCACCAAACATAAATCACCTCACTTAAGTGGCTGGAGACAAATAATCTCTTTAATAACCTGATTCAGCGA	GCCTAACTTCTTAGACTGCCTTAAGGACG		adapt
-SEQ:1:1101:9363:3989#0/1 adapter start: 95	-1	CCTCCAAGATTTGGAGGCATGAAAACATACAATTGGGAGGGTGTCAATCCTGACGGTTATTTCCTAGACAAATTAGAGCCAATACCATCAGCTTTGCCTAA
-SEQ:1:1101:9436:3998#0/1 adapter start: 67	1	67	97	TAAATTGTTTGGAGGCGGTCAAAAAGCCGCCTCCGGTGGCATTCAAGGTGATGTGCTTGCTACCGAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AACA	adapt
-SEQ:1:1101:9621:3755#0/1	-1	AGCCAATACCATCAGCTTTACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCAGAAGCAGCA
-SEQ:1:1101:9738:3756#0/1 adapter start: 1	1	1	31	T	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAGTCAAAGCACCTTTAGCGTTAAGGTACTGAATCTCTTTAGTCGCAGTAGGCGGAAAACGAACAAGCGC	adapt
-SEQ:1:1101:9580:3761#0/1 adapter start: 49	1	49	79	TATTAAGCTCATTCAGGCTTCTGCCGTTTTGGATTTAACCGAAGATGAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TTCGATTTTCTGACGAGTAACA	adapt
-SEQ:1:1101:9533:3764#0/1 adapter start: 20	1	20	50	TCTGTTGAACACGACCAGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AACTGGCCTAACGACGTTTGGTCAGTTCCATCAACATCATAGCCAGATGCC	adapt
-SEQ:1:1101:9636:3775#0/1	-1	ATAAGGCCACGTATTTTGCAAGCTATTTAACTGGCGGCGATTGCGTACCCGACGACCAAAATTAGGGTCAACGCTACCTGTAGGAAGTGTCCGCATAAAGT
-SEQ:1:1101:9554:3781#0/1	-1	CACGCTCTTTTAAAATGTCAACAAGAGAATCTCTACCATGAACAAAATGTGACTCATATCTAAACCAGTCCTTGACGAACGTGCCAAGCATATTAAGCCAC
-SEQ:1:1101:9695:3783#0/1 adapter start: 52	1	52	82	AATAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GCCAAGAAAAGCGGCATGG	adapt
-SEQ:1:1101:9572:3788#0/1	-1	ACCAACACGGCGAGTACAACGGCCCAGCTCAGAAGCGAGAACCAGCTGCGCTTGGGTGGGGCGATGGTGATGGTTTGCATGTTTGGCTCCGGTCTGTAGGC
-SEQ:1:1101:9601:3793#0/1	-1	GCCGCTAATCAGGTTGTTTCTGTTGGTGCTGATATTGCTTTTGATGCCGACCCTAAATTTTTTGCCTGTTTGGTTCGCTTTGAGTCTTCTTCGGTTCCGAC
-SEQ:1:1101:9634:3800#0/1	-1	TTTATGCGGACACTTCCTACAGGTAGCGTTGACCCTAATTTTGGTCGTCGGGTACGCAATCGCCGCCAGTTAAATAGCTTGCAAAATACGTGGCCTTATGG
-SEQ:1:1101:9501:3800#0/1 adapter start: 42	1	42	72	TGACCACCTACATACCAAAGACGAGCGCCTTTACGCTTGCCT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TTAGTACCTCGCAACGGCTGCGGACGACC	adapt
-SEQ:1:1101:9703:3807#0/1 adapter start: 27	1	27	57	TAATAACCTGATTCAGCGAAACCAATC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCGGCATTTAGTAGCGGTAAAGTTAGACCAAACCATGAAACCA	adapt
-SEQ:1:1101:9728:3808#0/1 adapter start: 7	1	7	37	CAGAAAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGT	adapt
-SEQ:1:1101:9676:3812#0/1 adapter start: 1	1	1	31	T	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATG	adapt
-SEQ:1:1101:9620:3815#0/1	-1	TCGCGTAGAGGCTTTGCTATTCAGCGTTTGATGAATGCAATGCGACAGGCTCATGCTGATGGTTGGTTTATCGTTTTTGACACTCTCACGTTGGCTGACGA
-SEQ:1:1101:9720:3834#0/1 adapter start: 74	1	74	101	TAGACATTTTTACTTTTTATGTCCCTCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAAGGATGGT	GCCTAACTTCTTAGACTGCCTTAAGGA		adapt
-SEQ:1:1101:9635:3844#0/1 adapter start: 4	1	4	34	GACC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGTAGTCGGAACCGAAGAAGACTCAAAGCGAACC	adapt
-SEQ:1:1101:9744:3849#0/1 adapter start: 55	1	55	85	AAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGTTGAACACGACCAG	adapt
-SEQ:1:1101:9725:3850#0/1	-1	ATAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGA
-SEQ:1:1101:9544:3854#0/1	-1	TAGCGGTAAAGTTAGACCAAACCATGAAACCAACATAAACATTATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAA
-SEQ:1:1101:9581:3856#0/1	-1	GGGCGGTGGTCTATAGTGTTATTAATATCAAGTTGGGGGAGCACATTGTAGCATTGTGCCAATTCATCCATTAACTTCTCAGTAACAGATACAAACTCATC
-SEQ:1:1101:9649:3858#0/1 adapter start: 33	1	33	63	CCTCCAAACAATTTAGACATGGCGCCACCAGCA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AGAGCAGAAGCAATACCGCCAGCAATAGCAACAAACAT	adapt
-SEQ:1:1101:9616:3862#0/1 adapter start: 91	1	91	101	GAATTAAATCGAAGTGGACTGCTGGCGGAAAATGAGAAAATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCTTTCGC	GCCTAACTTC		adapt
-SEQ:1:1101:9696:3866#0/1	-1	CAAGTTGCCATACAAAACAGGGTCGCCAGCAATATCGGTATAAGTCAAAGCACCTTTAGCGTTAAGGTACTGAATCTCTTTAGTCGCAGTAGGCGGAAAAC
-SEQ:1:1101:9512:3869#0/1	-1	GCTCGACGCCATTAATAATGTTTTCCGTAAATTCAGCGCCTTCCATGATGAGACAGGCCGTTTGAATGTTGACGGGATGAACATAATAAGCAATGACGGCA
-SEQ:1:1101:9723:3870#0/1 adapter start: 66	1	66	96	CTTTAGCAGCAAGGTATATATCTGACTTTTTGTTAACGTATTTAGCCACATAGCAACCAACAGACA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TATAA	adapt
-SEQ:1:1101:9667:3874#0/1	-1	CTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGGTTGACGCCGGATTTGAGAATCAAAAAGAGCTTACT
-SEQ:1:1101:9565:3879#0/1 adapter start: 24	1	24	54	AGCCTTATGGCCGTCAACATACAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCACCATTATCGAACTCAACGCCCTGCATACGAAAAGACAGAATCT	adapt
-SEQ:1:1101:9721:3885#0/1 adapter start: 51	1	51	81	TTCCTCAAACGCTTGTTCGGTGGATAAGTTATGGCATTAATCGATTTATTT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCTCGCGGAAGAAAAACAC	adapt
-SEQ:1:1101:9707:3894#0/1 adapter start: 40	1	40	70	AACACCATCCTTCATGAACTTAATCCACTGTTCACCATAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ACGTGACGATGAGGGACATAAAAAGTAAAAA	adapt
-SEQ:1:1101:9560:3900#0/1 adapter start: 6	1	6	36	AGAAGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GCCAGCCTGCAACGTACCTTCAAGAAGTCCTTTACCAGCTTTAGCCATAGCACCAGAAACAAAAC	adapt
-SEQ:1:1101:9696:3913#0/1 adapter start: 2	1	2	32	CC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCC	adapt
-SEQ:1:1101:9574:3914#0/1 adapter start: 5	1	5	35	GAACA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AGCGCAAGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTC	adapt
-SEQ:1:1101:9508:3931#0/1 adapter start: 91	1	91	101	TAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGCTGAACGCCCTCTTAAGGATATTCGCGATGAGTATAATTACCCCAA	GCCTAACTTC		adapt
-SEQ:1:1101:9617:3935#0/1	-1	TAAATTTAATGTGACCGTTTATCGCAATCTGCCGACCACTCGCGATTCAATCATGACTTCGTGATAAAAGATTGAGTGTGAGGTTATAACGCCGAAGCGGT
-SEQ:1:1101:9667:3950#0/1 adapter start: 66	1	66	96	CTTTAGCCATAGCACCAGAAACAAAACTAGGGACGGCCTCATCAGGGTTAGGAACATTAGAGCCTT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAATG	adapt
-SEQ:1:1101:9705:3951#0/1 adapter start: 29	1	29	59	ATTGCGTACCCGACGACCAAAATTAGGGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CAACGCTACCTGTAGGAAGTGTCCGCATAAAGTGCACCGCAT	adapt
-SEQ:1:1101:9527:3965#0/1	-1	AACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGTTTGGTCAGTTCC
-SEQ:1:1101:9550:3969#0/1	-1	AGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGTTTGGTC
-SEQ:1:1101:9636:3973#0/1 adapter start: 9	1	9	39	CAAGCGCAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGT	adapt
-SEQ:1:1101:9726:3981#0/1 adapter start: 66	1	66	96	TTGCTGCCATCTCAAAAACATTTGGACTGCTCCGCTTCCTCCTGAGACTGAGCTTTCTCGCCAAAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GACGA	adapt
-SEQ:1:1101:9603:3981#0/1 adapter start: 32	1	32	62	TCTAAGAAGTTTAAGATTGCTGAGGGTCAGTG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GTATCGTTATGCGCCTTCGTATGTTTCTCCTGCTTATCA	adapt
-SEQ:1:1101:9533:3990#0/1 adapter start: 1	1	1	31	G	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATCCAAAGGA	adapt
-SEQ:1:1101:9583:3992#0/1 adapter start: 20	1	20	50	AAGGTACTGAATCTCTTTAG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCGCAGTAGGCGGAAAACGAACAAGCGCAAGAGTAAACATAGTGCCATGCT	adapt
-SEQ:1:1101:9903:3754#0/1	-1	ACCAAAATTAGGGTCAACGCTACCTGTAGGAAGTGTCCGCATAAAGTGCACCGCATGGAAATGAAGACGGCCATCAGCTGTACCATACTCAGGCACACAAA
-SEQ:1:1101:9878:3755#0/1 adapter start: 32	1	32	62	AGAACGTGAAAAAGCGTCCTGCGTGTAGCGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CTGCGATGGGCATACTGTAACCATAAGGCCACGTATTTT	adapt
-SEQ:1:1101:9833:3756#0/1 adapter start: 65	1	65	95	TCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAAGGATGGTGTTAATGCCACTCCTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCCCGA	adapt
-SEQ:1:1101:9991:3777#0/1	-1	GCTTTGAGTCTTCTTCGGTTCCGACTACCCTCCCGACTGCCTATGATGTTTATCCTTTGGATGGTCGCCATGATGGTGGTTATTATACCGTCAAGGACTGT
+SEQ:1:1101:9010:3891#0/1 adapter start: 51	1	51	81	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAGCCAAGATGGGAAAGGTC	adapt	FFFFFEDBE at 79@@>@CBCBFDBDFDDDDD<@C>ADD at B;5:978 at CBDDF	FDB4B?DB21;84?DDBC9DEBAB;=@<@@	B@@@@B>CCBBDE98>>0 at 7
+SEQ:1:1101:9240:3898#0/1	-1	CCAGCAAGGAAGCCAAGATGGGAAAGGTCATGCGGCATACGCTCGGCGCCAGTTTGAATATTAGACATAATTTATCCTCAAGTAAGGGGCCGAAGCCCCTG	GHGHGHHHHGGGDHHGDCGFEEFHHGDFGEHHGFHHHHHGHEAFDHHGFHHEEFHGHFHHFHGEHFBHHFHHHH at GGGDGDFEEFC@=D?GBGFGF:FB6D
+SEQ:1:1101:9207:3899#0/1 adapter start: 64	1	64	94	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAAC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATACATA	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHCFHHF	HHFHFFFFFBHHGHHHFFHHFHGGHHDEBF	G<FGGDG
+SEQ:1:1101:9148:3908#0/1 adapter start: 28	1	28	58	ACGACGCAATGGAGAAAGACGGAGAGCG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATAACCGGAG	adapt	HHHHHHHHHHHHGHHHHGHHHHHHHHHH	HHHHHHHHHHHHHHHHHGHHHHDHDHHFHH	HHHFFFFFHHHEFBEGEGGFFFHHHFHHHHHHFHHEHHGHEHD
+SEQ:1:1101:9044:3916#0/1 adapter start: 78	1	78	101	AACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTATGGAAAACACCAATCTTTCCAAGCAACAGCAGGTTTCCGAGA	GCCTAACTTCTTAGACTGCCTTA		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHGHHHHHHHHHHHHFHEBFHFFEFHE	FHHGHFHHHHGGHGHHFHGGGHG	
+SEQ:1:1101:9235:3923#0/1	-1	TTGATGCGGTTATCCATCTGCTTATGGAAGCCAAGCATTGGGGATTGAGAAAGAGTAGAAATGCCACAAGCCTCAATAGCAGGTTTAAGAGCCTCGATACG	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHBHHFHFHHHHHFHHCHHFFHHHHEHHFDHCEEHHHFHHFHFEHHHHHHHHHEHHGFHH<FGGFABGGG?
+SEQ:1:1101:9086:3930#0/1 adapter start: 46	1	46	76	CCATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGTAGTCGGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCGAAGAAGACTCAAAGCGAACCAA	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH at HHEHHHFH	HHHFHHHHHFFHFFHHBHFFHFHHCFFHFH	HFHHHHEEHHGHHFEHFHGGEHEFH
+SEQ:1:1101:9028:3936#0/1	-1	CTTGATATTAATAACACTATAGACCACCGCCCCGAAGGGGACGAAAAATGGTTTTTAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGC	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHHCHFHHFHGBEFFFEFEFHEHHHFEHHFEEC>CDCEEEFDFFHHHCFFEFE?EBFEB?3
+SEQ:1:1101:9185:3939#0/1	-1	CGTTGAGGCTTGCGTTTATGGTACGCTGGACTTTGTAGGATACCCTCGCTTTCCTGCTCCTGTTGAGTTTATTGCTGCCGTCATTGCTTATTATGTTCATC	HHHHHHHHHHHHHHFHHEHHHDHHFGHHHCHHHHHDHHHHFECEGBD<DCFHBHBBEEEGCCCDB?C9DECCC3CD<@DA<@>@@?A?DAFF9F<@@08?<
+SEQ:1:1101:9140:3961#0/1 adapter start: 66	1	66	96	CAGGAGAAACATACGAAGGCGCATAACGATACCACTGACCCTCAGCAATCTTAAACTTCTTAGACG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AATCA	adapt	HHHHHHHGHHHHHHHHHHHGHHHHHHHHHHHHHHHHFHHHHHHFGHHHHHHHHHHHHHHHHDHHFH	HHHEHHFHFHHHHHGHHHHHFHGHGHHHHH	EHCFG
+SEQ:1:1101:9073:3961#0/1 adapter start: 49	1	49	79	GTGGCAAGTCTGCCGCTGATAAAGGAAAGGATACTCGTGATTATCTTGC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGCTGCATTTCCTGAGCTTAAT	adapt	HHHHHHHHFHHHHHHGHHHHHHHHHEHHGHHGHHHHHHHHHHGEHHHHH	GFHFFGHFHHGHHCHHFDGHHHHHFHHHFC	DFGHHHHHHCFGHHEGEFBGGB
+SEQ:1:1101:9196:3971#0/1 adapter start: 18	1	18	48	ACCAGAAGGCGGTTCCTG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AATGAATGGGAAGCCTTCAAGAAGGTGATAAGCAGGAGAAACATACGAAGGCG	adapt	HHHHHHHHHFHHHHHHHH	HGHHHGHHHHHHHFHHHHHHHHHHHEHHHH	HHHHHHHHFHHGHHHHHEHFHHHHBHEHHGEHFHFHHFHHHHFBDFHF?HHHH
+SEQ:1:1101:9053:3973#0/1	-1	TTCACGTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAGCCGCTTAAAGCTACCAGGTTTATTGCTGTTTGTTTCTATGTGGCTTAAAACGTTACCA	A39>A################################################################################################
+SEQ:1:1101:9120:3979#0/1	-1	GGCGTTGACAGATGTATCCATCTGAATGCAATGAAGAAAACCACCATTACCAGCATTAACCGTCAAACTATCAAAATATAACGTTGACGATGTAGCTTTAG	HHHHHHHHHHHGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFFGFFDHBHHHFGEHHHFGHHHEHHHGH
+SEQ:1:1101:9045:3988#0/1 adapter start: 91	1	91	101	TAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGCAGTGTTAA	GCCTAACTTC		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHFHHHHHHHHHHHFHHHHHHDHHHHHHHFHFFHHGHEHHGHHHGHGHHFH	GHHFFFEFFE	
+SEQ:1:1101:9418:3756#0/1	-1	TAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCATGAACTTAATCCACTGT	HHHHHHHHHHHHHHHHFHHHGHEHHHFHHHHFFEHHFHHHHGHHFHFHHHGHHHDHFHCHFCFBCFEFDEHHHHHG at GGGGHHGHFFEG=AB at C:EDEEEH
+SEQ:1:1101:9394:3759#0/1	-1	CCCTCGCTTTCCTGCTCCTGTTGAGGTTATTGCTGCCGTCATTGCTTATTATGTTCATCTCGGCAACATTCATACGGTCTGGCTTATCCGTGCAGAGACTG	#####################################################################################################
+SEQ:1:1101:9365:3766#0/1	-1	AAGCACATCACCTTGAATGCCACCGGAGGCGGCTTTTTGACCGCCTCCAAACAATTTAGACATGGCGCCACCAGCAAGAGCAGAAGCAATACCGCCAGCAA	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFFHHHHFHHHHEHHFGHHHHFEHHHHFEHHFDFFAFHEFHFHDFFFFHHDH?DFABFDHADFDHHHFBF
+SEQ:1:1101:9436:3776#0/1	-1	GAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGGAGTCGGA	HHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHHHFHGHHHHHHHGHHHHHHFDHHHHHHHHHHHHHFH?HHHHHFBHEH at GHHGD=EEEE88==%893A@@;
+SEQ:1:1101:9354:3801#0/1	-1	CCAGCAAGAGCAGAAGCAATACCGCCAGCAATAGCACCAAACATAAATCACCTCACTTAAGTGGCTGGAGACAAATAATCTCTTTAATAACCTGATTCAGC	HHHHHHHHHGHHGHHEGHHEHFGFEHHGHGGHHHHHHHFHGHHFHHEFFFHEHHFHHHDHE5EDFCAC+C)4&27DDA?7HFHDHEFGFG,<@7>?>??<A
+SEQ:1:1101:9389:3804#0/1 adapter start: 28	1	28	58	ATTAGAGCCAATACCATCAGCTTTACCG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAA	adapt	GGGGFDGGHFHHHFFFGBEFGGGGGEFE	EFFGHFHHFHFDEFFEFHHHBFEFDD=BDD	DFHBE>EDC at FDDDDCDFE?DEEFGF<EE?F?GGEF>CC@;@D
+SEQ:1:1101:9477:3819#0/1 adapter start: 28	1	28	58	ATAAAGGAAAGGATACTCGTGATTATCT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGCTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGT	adapt	HHHHHHHHHHHHHHHHGHHHHHHHHHHH	HHHHHHHHHHHHHFHHFHFHHHHHHHEHHH	HHEHHHHHHEHHDHDHBHHGCEHHHHHGGEFGG=DGDGCGC68
+SEQ:1:1101:9428:3823#0/1	-1	CGTCAGTAAGAACGTCAGTGTTTCCTGCGCGTACACGCAAGGTAAACGCGAACAATTCAGCGGCTTTAACCGGACGCTCGACGCCATTAATAATGTTTTCC	HHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHFGHGHHHHHHHEHHHHFHHHHHFHHHFHH?FHEFFFDGFDAFDCFAFDBFGBFGFHHHHHHHHHFHFH;8
+SEQ:1:1101:9403:3824#0/1 adapter start: 70	1	70	100	GCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	C	adapt	HHHHHHHHHHHHHHHHHHHEHHHHHHHHHHHHHHHHGDHDHHHHHHHHHGHHHHGHEHGHHHHFFHHHHH	EHFHFEHHFGBFFFDHCEHHHHGH=HHH=G	E
+SEQ:1:1101:9362:3824#0/1	-1	ACCATGAAACCAACATAAACATTATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATC	HHHHHHHGHHHHHHHHHHHHHHHGHHHHHFHHHHHHHHFHHFHHHFHHHHHHHHHFHEHHHFHBHFHHHFCEFDEHHHHGHHHHHHHHHEFFFHHFFFDAG
+SEQ:1:1101:9480:3842#0/1 adapter start: 54	1	54	84	GTACGGATTGTTCAGTAACTTGACTCATGATTTCTTACCTATTAGTGGTTGAAC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCATCGGACTCAGATA	adapt	BDCCC at 5<<<@BBB7DDDDD<<<9>::@<5DDDDDCDCBEDCDDDDBDDDBAA1	/82638?D=CD2*><6BC<CC7;=;*CBCC	AC at 73C2=3<<@,CB at D
+SEQ:1:1101:9286:3846#0/1	-1	TGATTAAACTCCTAAGCAGAAAACCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGTTATAACCTCACACT	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHFHHDGCEGGHHHHFHHFHEHHFHEGHGHGF
+SEQ:1:1101:9403:3867#0/1 adapter start: 1	1	1	31	G	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGT	adapt	H	HHHHHHHHHHHHHHHHHHHHHHHHHHHHGH	HHHHHHHHHHHHHHHHHHHHHHHHHHHFHFHHHHHHHHHDFFBFHGGGFHHHHHHHHHHHHHHEBHHHFB
+SEQ:1:1101:9341:3873#0/1 adapter start: 88	1	88	101	CCTAAGCAGAAAACCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGTTATAACCTCAC	GCCTAACTTCTTA		adapt	HHHHHHHGGFHGHHHHHGHHHHFGHGHHHHEHHHFHFHFHFHH?CEEEDFCEFCDFFHFEABEDF.ECDCDFEEEEEGGFADACDHHH	BAFG3FF:BBE##	
+SEQ:1:1101:9381:3881#0/1 adapter start: 41	1	41	71	ACGTTCTGGTTGGTTGTGGCCTGTTGATGCTAAAGGTGAGC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCTTAAAGCTACCAGTTATATGGCTGTTG	adapt	HHHHHHHHHHHHGHGHDHHHHHHHHFEHHHGGGGFFBGFFF	HFEHEHHEF>FGFF?E?FEFFHBBFEE3E,	;/97-0(6,?=BB at A@D9D###########
+SEQ:1:1101:9360:3884#0/1	-1	TAATACCTTTCTTTTTGGGGTAATTATACTCATCGCGAATATCCTTAAGAGGGCGTTCAGCAGCCAGCTTGCGGCAAAACTGCGTAACCGTCTTCTCGTTC	HGDEHGHDGHFGFGHFDFFF7EEEEGGFGGEGHEGHHHHFFFEHHHFHEHFBFFF>?DEEBF=?CDB:DFBGFBBGDFFHF?FAFGGABFGGFAFE6EDDC
+SEQ:1:1101:9323:3894#0/1 adapter start: 100	-1	ATACCGATATTGCTGGCGACCCTGTTTTGTATGGCAACTTGCCGCCGCGTGAAATTTCTATGAAGGATGTTTTCCGTTCTGGTGATTCGTCTAAGAAGTTG	HHGHHHHHHHHHHHHHHHHHHHEHDHHHHHGEHHFFHHFFFHHHHHHHHFHDHHBHGHB?HHDFFF?EFEHFHBFGEGGFFFDFBHFHHHHHFHHEFFFCF
+SEQ:1:1101:9267:3900#0/1 adapter start: 89	1	89	101	GTTTTGGATTTAACCGAAGATGATTTCGATTTTCTGACGAGTAACAAAGTTTGGATTGCTACTGACCGCTCTCGTGCTCGTCGCTGCGT	GCCTAACTTCTT		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHHHHHHHHFHHHHEHHEHHHFHHHHHHHHHHFHFHECFFHABGGGIGHHHGGFFGF	FCACFECEB5<;	
+SEQ:1:1101:9416:3909#0/1	-1	TAAACGTGACGATGAGGGACATAAAAAGTAAAAATGTCTACAGTAGAGTCAATAGCAAGGCCACGACGCAATGGAGAAAGACGGAGAGCGCCAACGGCGTC	HHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHHHHHHHHHHHHHEHHGHHFEFHEFHFFDHEFHFAFFFA?GDFGFE at FFFB?B7EEFEFE?DAA##
+SEQ:1:1101:9360:3917#0/1 adapter start: 68	1	68	98	ATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGGTTGACGCCGGATTTGAGAATCAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAA	adapt	HHHHHHHHHHHHHHHHHHHFHHHHHHHHHHFHHHHHHHFHEFHHHEHHCFFEFEE9AFFBBDCDCAEE	EFHD??<DFEEEEHHEEBFEGBDEHCHFE?	GE@
+SEQ:1:1101:9337:3918#0/1 adapter start: 14	1	14	44	CATCAGCACCAGCA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCTCCCAAGCATTAAGCTCAGGAAATGCAGCAGCAAGATAATCACGAGTATCCTTT	adapt	FDEGGGCDBEFCDF	FBGFFGGEGEDE=GGGEGGGEFFCCFGF7E	FFEGDEGCF;BFBEBFFCD5FEDCDA=95>>E4 at EC>74<-5@##############
+SEQ:1:1101:9307:3927#0/1 adapter start: 15	1	15	45	TCAGCGCCTTCCATG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATGAGACAGGCCGTTTGAATGTTGACGGGATGAACATAATAAGCAATGACGGCAGC	adapt	FFFFFFFFFFFFFDF	=EEEEDFFFFBEEEEFFFFFFFFFFFDEEB	DFFFFDFFFFEF at FFFBEFFBFFEF--@@<FFBFFFF?FFEBEDEFEFFF######
+SEQ:1:1101:9479:3929#0/1 adapter start: 9	1	9	39	GACAAATTA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAGCCAATACCATCAGCTTTACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTT	adapt	HHHHHHHHH	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH	HHHFHFFHHFHFHHFFFHHHHHHFHHAE?EEHFFCFGGGAGGEGFFHHHHHGFHH?GHGHEG
+SEQ:1:1101:9277:3934#0/1 adapter start: 71	1	71	101	CTGTCTTTTCGTATGCAGGGCGTTGAGTTCGATAATGGTGATATGTATGTTGACGGCCATAAGGCTGCTTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHEHFHHHHFHHHHHFHHEHFHHHFHHFDHHFHHE	FACFGEFFGEHDFFEHBHHDBEFEHFHHBC	
+SEQ:1:1101:9442:3934#0/1	-1	AGACCCATAATGTCAATAGATGTGGTAGAAGTCGTCATTTGGCGAGAAAGCTCAGTCTCAGGAGGAAGCGGAGCAGTCCAAATGTTTTTGAGATGGCAGCA	HHHHHHHHHGHHHHHFGHHBHHEHGFHHDHGDEGDHHHHHFHHHHHAHHH?FEEBEFDFBEBEEFEHFE7ECCDCG=FDFFDFFFHHHHFEEBEF;BEAEG
+SEQ:1:1101:9329:3935#0/1	-1	AGATGGATAACCGCATCAAGCTCTTGGAAGAGATTCTGTCTTTTCGTATGCAGGGCGTTGAGTTCGATAATGGTGATATGTATGTTGACGGCCATAAGGCT	GFGGGEEGDHHHGGEHHHHHHGGFHHEAHHAGDEGEGGEDG at GGGHHGHHFGGH6@CADDHHBEEE at 8EBGEEFGGGHFHHHHGEGFGGEFBGEDDE?E7E
+SEQ:1:1101:9445:3956#0/1 adapter start: 81	1	81	101	TGCAACAACTGAACGGACTGGAAACACTGGTCATAATCATGGTGGCGAATAAGTACGCGTTCTTGCAAATCACCAGAAGGC	GCCTAACTTCTTAGACTGCC		adapt	HHHHHHHHHGFHHHHHHHHHHHHHHGHHHHFHHHHHHHHHHHFGHHHFGHHHHFGHHFHEHHHHHHHHHHHHGBHHHHGFG	GGEGGGGFDHHHFHHGGEBE	
+SEQ:1:1101:9357:3957#0/1	-1	TTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCATGAACTTAATCCACTG	HHHHHHGHHHHHHHHHHGHEHHHHHGHEHHHHHHHHHHHHHHGHEBGGFGFFFFFBH?HCEEED<FEEEFFHHDHHHHEHHHGFHHH:BHHHHFHEFFHFF
+SEQ:1:1101:9487:3957#0/1	-1	CAATAAAATCCCTAAGCATTTGTTTCAGGGTTATTTGAATATCTATAACAACTATTTTAAAGCGCCGTGGATGCCTGACCGTACCGAGGCTAACCCTAATG	HHHHHHHHHHHHHHHGEHHHGHHHHHHHEGFHGHHHGHHHHGGHHHHHGHHHHHHHHHHFHHB>EFHFHBHFHCFHHGGGHEGHEGHEF at GHHFHEDHH;H
+SEQ:1:1101:9309:3957#0/1 adapter start: 72	1	72	101	GTCAGATATGGACCTTGCTGCTAAAGGTCTAGGAGCTAAAGAATGGAACAACTCACTAAAAACCAAGCTGTC	GCCTAACTTCTTAGACTGCCTTAAGGACG		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHGHFHHHFHHHHHHHHGHHHFHHHHHHHFHDHHHHHHFHCHHEAHHDG	GHFHFHDHHHGHHEHHFFH?HHHFDGGG?	
+SEQ:1:1101:9425:3960#0/1	-1	CTGACGCAGAAGAAAACGTGCGTCAAAAATTACGTGCAGAAGGAGTGATGTAATGTCTAAAGGTAAAAAACGTTCTGGCGCTCGCCCTGGTCGTCCGCAGC	8?8?C?BC at BD=ABB==BD?CADD=AD>C@@CCBBDD at B/143'3.>>@9BCBDDDC8@@;<A=<DDDDB?A:A;9:2-74,<82;9877CBCDD/B at 5;<
+SEQ:1:1101:9337:3969#0/1	-1	GAATTAAATCGAAGTGGACTGCTGGCGGAAAATGAGAAAATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCTTTCGCCATCAACTAA	DBFEFFDEEEBFFFFF8FF=D=DDDEEE=E>@???FB=DFB=>C=EEFFFFFEFFFFF:FEF at FEF<FFFFF?DFDD8DDBD=DBFEB at E6FECF@EB8E?
+SEQ:1:1101:9388:3971#0/1	-1	CTGAATCTCTTTAGTCGCAGTAGGCGGAAAACGAACAAGCGCAAGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGG	HHHHHHFHHHHHHHHHHHHHHHHHHHHFHHGHHHFHHHHHHGHHHHHEFHHHFHHFEHHFEHHFFHHHHECFDF?HHHHGEGGHHHFHHHFEGCFFFFF=E
+SEQ:1:1101:9414:3978#0/1 adapter start: 99	-1	TTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGAGAGGAGTGGCATTAACACCATCCTTCGC	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHHHHHHHFFHHHHG at HFHDHGHDHHHHHHFGHHGHG
+SEQ:1:1101:9494:3983#0/1 adapter start: 72	1	72	101	TAGCACCAAACATAAATCACCTCACTTAAGTGGCTGGAGACAAATAATCTCTTTAATAACCTGATTCAGCGA	GCCTAACTTCTTAGACTGCCTTAAGGACG		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHBF?FBHHFEHB?HEFEHBGEDEEBEDEEFACAFE>	EFBGGGFFGHFFHD5DGB=>>@;A>C5?A	
+SEQ:1:1101:9363:3989#0/1 adapter start: 95	-1	CCTCCAAGATTTGGAGGCATGAAAACATACAATTGGGAGGGTGTCAATCCTGACGGTTATTTCCTAGACAAATTAGAGCCAATACCATCAGCTTTGCCTAA	HHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHGHHHHHHHG<GFGGGGFGHHHHHHEEEEHHDEFHHFHHHFHHDHEGHHHHBHHGCGF8ECEEFFEDBA=
+SEQ:1:1101:9436:3998#0/1 adapter start: 67	1	67	97	TAAATTGTTTGGAGGCGGTCAAAAAGCCGCCTCCGGTGGCATTCAAGGTGATGTGCTTGCTACCGAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AACA	adapt	HHHHHHHHHHHHHHHHGGDHHHHHHFHHFGHHHHHHDHHFFDFGEFFHDFCFFEBDFHFFFFEEDEB	EFFF9FEFGGFDBGEBBFGGBFBD6DDAF<	EEBE
+SEQ:1:1101:9621:3755#0/1	-1	AGCCAATACCATCAGCTTTACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCAGAAGCAGCA	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHFHHFF?FHHFHFHHHHEHHC at FEHFHFHBGGGFHHHHHHDHHFFHGFHA
+SEQ:1:1101:9738:3756#0/1 adapter start: 1	1	1	31	T	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AAGTCAAAGCACCTTTAGCGTTAAGGTACTGAATCTCTTTAGTCGCAGTAGGCGGAAAACGAACAAGCGC	adapt	H	HHHHHHHHHHHHHHHHHHHHHHHFHHEHHH	HHHHHHHHHHHHFFGHHHBHHFHHHEHHHHHHFHHHHFHHHDDFGEFFDFFEFFEFHGBEGGDGHEGEFF
+SEQ:1:1101:9580:3761#0/1 adapter start: 49	1	49	79	TATTAAGCTCATTCAGGCTTCTGCCGTTTTGGATTTAACCGAAGATGAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TTCGATTTTCTGACGAGTAACA	adapt	HHHHHHHHHGGHHHHHEHHHFHEHHGEGGHFGDFGHFHFGHHFFDH?EF	HHEFEHEFGGG4ADCDE=ECEC<:=?DD>B	B;FBFFEGGEGB==EGFHH<DB
+SEQ:1:1101:9533:3764#0/1 adapter start: 20	1	20	50	TCTGTTGAACACGACCAGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AACTGGCCTAACGACGTTTGGTCAGTTCCATCAACATCATAGCCAGATGCC	adapt	FEFFFF at FFDFFEFFDDBDD	B??<@FFFEEEEEEEFEEFFFCFFFFEBFF	FD at FBFBFFFE@BFFFFBF=ADD;@?@?AAFBEFFDA=FEFEFFB at -C?BE
+SEQ:1:1101:9636:3775#0/1	-1	ATAAGGCCACGTATTTTGCAAGCTATTTAACTGGCGGCGATTGCGTACCCGACGACCAAAATTAGGGTCAACGCTACCTGTAGGAAGTGTCCGCATAAAGT	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHFH6HHHHHHHHHHFFHFCHFDCHFE;DAD9BDDDDGFGDGDGGB<FDCDCDGF>GEEGB;5
+SEQ:1:1101:9554:3781#0/1	-1	CACGCTCTTTTAAAATGTCAACAAGAGAATCTCTACCATGAACAAAATGTGACTCATATCTAAACCAGTCCTTGACGAACGTGCCAAGCATATTAAGCCAC	HHHHHHHHHHHHHGGHHHHHHGHFHHHHHHEHHFHHHEHHHHHHHEHHGHHHHEHHHGFHHHEHHHHHHEEFFEDFEDFF>ACBAHGHHHHECEGHBCFEE
+SEQ:1:1101:9695:3783#0/1 adapter start: 52	1	52	82	AATAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GCCAAGAAAAGCGGCATGG	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHHHHGHHHHHHHHHHF	HHHHHHFHGEHEHHHHHGHHHHHHHHHFHH	FHGGHHHHHHGGHGFHHHG
+SEQ:1:1101:9572:3788#0/1	-1	ACCAACACGGCGAGTACAACGGCCCAGCTCAGAAGCGAGAACCAGCTGCGCTTGGGTGGGGCGATGGTGATGGTTTGCATGTTTGGCTCCGGTCTGTAGGC	FFFFFFFFF=EBEB0A at A@<BD:EEFFA at EEEDE?EDE8<E?EE=E:BBB>>A?;FED;;<7??A>>9A>?DA1ADD?D:FF:BC;@##############
+SEQ:1:1101:9601:3793#0/1	-1	GCCGCTAATCAGGTTGTTTCTGTTGGTGCTGATATTGCTTTTGATGCCGACCCTAAATTTTTTGCCTGTTTGGTTCGCTTTGAGTCTTCTTCGGTTCCGAC	HHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHEHEGHFHHHHHHHHFHFHCHHHFHFFHHHHHH at HHHHHHGHHHFHHGFHHCFHEGGGFEGE?GCDAD6AD
+SEQ:1:1101:9634:3800#0/1	-1	TTTATGCGGACACTTCCTACAGGTAGCGTTGACCCTAATTTTGGTCGTCGGGTACGCAATCGCCGCCAGTTAAATAGCTTGCAAAATACGTGGCCTTATGG	HHGHFHFHHHHCGHHFHHHHHHGEHHHHHGFBEFHHFEHDHHHGFHHEHHFF9ECD?CEEHED<HBDEEBFEDEEE<FDFDGFBEHHEHCE>F?GEEDEEG
+SEQ:1:1101:9501:3800#0/1 adapter start: 42	1	42	72	TGACCACCTACATACCAAAGACGAGCGCCTTTACGCTTGCCT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TTAGTACCTCGCAACGGCTGCGGACGACC	adapt	HHHHHHHHHHHHHHHHFHHHHHHHHFHHHHHHHHHHHHHHHH	HHHHHFHHHHHHHHHHHHHHFBHAEDBEFB	BEF=ADEEGGGEFCC>B1CCDCB7FGFFE
+SEQ:1:1101:9703:3807#0/1 adapter start: 27	1	27	57	TAATAACCTGATTCAGCGAAACCAATC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CGCGGCATTTAGTAGCGGTAAAGTTAGACCAAACCATGAAACCA	adapt	HHHHHHHHHHHHHHHHHHHHHHGHHHG	HHHFHGFHHHHFFHHHHHDHHHHBGFEFHH	HFHFHFDHFDFFFEHHGHDHHGHHEHHG at E?FDGBEBDGGFFGF
+SEQ:1:1101:9728:3808#0/1 adapter start: 7	1	7	37	CAGAAAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CCTACCGCGCTTCGCTTGGTCAACCCCTCAGCGGCAAAAATTAAAATTTTTACCGCTTCGGCGT	adapt	HHHFHHH	HHHHHHHHHHHHHHHFHHHHHHHHHHHFB8	@B9C?CC at CHCFFFHF=FEED<4:?:>@,@;@>.>6;+?&@><CEC??A><:BC?DE@=7@###
+SEQ:1:1101:9676:3812#0/1 adapter start: 1	1	1	31	T	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATG	adapt	H	HHHHHHHHHHHHHHHHHHHHHHHFHHHHHH	HDHFHHHHHHHECHHEHEHHH=HHFHHFHFHHFHFHGFFEECFFHEFFGFGHFFEHHFHHFFFHF<F:D7
+SEQ:1:1101:9620:3815#0/1	-1	TCGCGTAGAGGCTTTGCTATTCAGCGTTTGATGAATGCAATGCGACAGGCTCATGCTGATGGTTGGTTTATCGTTTTTGACACTCTCACGTTGGCTGACGA	HHHHHHHHHHGGHHHGHHGHHHHHHHHHHGFHGHHHHHHHHHFHDHHHDDHFHFHFHHHHFF9EFF>DG?FCBCDFFFEBFFE at DFEGGEEG?GF>>:;@A
+SEQ:1:1101:9720:3834#0/1 adapter start: 74	1	74	101	TAGACATTTTTACTTTTTATGTCCCTCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAAGGATGGT	GCCTAACTTCTTAGACTGCCTTAAGGA		adapt	HGHHHHHHHHHHHHHHHGGHEGGFGHFGHFHHDGHGHGHHHHHHHHHHFHHHHHFHFHFFHEFHF=FFHFHHFF	HFGAGGHHDHGHBHHHEGDGC>FEC at D	
+SEQ:1:1101:9635:3844#0/1 adapter start: 4	1	4	34	GACC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCCAAAGGATAAACATCATAGGCAGTCGGGAGGGTAGTCGGAACCGAAGAAGACTCAAAGCGAACC	adapt	HHHH	GHHHHHHHHHGHHHHHHGHHGHHHGHGHHH	HFHHH;GGCGFH?HHFHEHHFFHFHFFFHHFDHHHHHHHHHEGHHHHGHGHEHHHHC@?GFEGBGHH
+SEQ:1:1101:9744:3849#0/1 adapter start: 55	1	55	85	AAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TGTTGAACACGACCAG	adapt	HHHHHHHGCHHFHHFHHFFHEHFGCHHGDGHEFFHFHEHHGBBGFCDGFEEFDCF	FGEEEHEHFHHHCFF?EEFDEFD6FHGEHH	HEHHHBBE?:CCDA7G
+SEQ:1:1101:9725:3850#0/1	-1	ATAACCCTGAAACAAATGCTTAGGGATTTTATTGGTATCAGGGTTAATCGTGCCAAGAAAAGCGGCATGGTCAATATAACCAGTAGTGTTAACAGTCGGGA	FDGGGDGGGEGGGGGBGBEGFFFDFFFFGGFGGGGFBGGGGGEFDFFGEGFFEFEDGGEEF9DCF?EFBBEDBBGFGGEGGGGCFGFEB at B7C>CDEEE##
+SEQ:1:1101:9544:3854#0/1	-1	TAGCGGTAAAGTTAGACCAAACCATGAAACCAACATAAACATTATTGCCCGGCGTACGGGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAA	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHHHHHHFFHHHHHHHHHBFHHHHHFHHHHHHHHHHHHHHFCHHHBHE
+SEQ:1:1101:9581:3856#0/1	-1	GGGCGGTGGTCTATAGTGTTATTAATATCAAGTTGGGGGAGCACATTGTAGCATTGTGCCAATTCATCCATTAACTTCTCAGTAACAGATACAAACTCATC	HHHHHHEHHHHHHHGHHHHHHHHHHHHHHHHHHHHHHHFHHHHGHHHHHHHHHHHHHHHGGHHHFHHHHHGHFGHGEGHHHHHHFEHFHGDGGFFGHH at DH
+SEQ:1:1101:9649:3858#0/1 adapter start: 33	1	33	63	CCTCCAAACAATTTAGACATGGCGCCACCAGCA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AGAGCAGAAGCAATACCGCCAGCAATAGCAACAAACAT	adapt	B<B at A@AAB>FEEEE@@BA at 3>8<>CCDDBEE@	DEFFDDFE=EEB at EDEEFDFDECEEBEB:C	-@<698<@BBA at DCBDDFCEBFCCD;DC=D at C######
+SEQ:1:1101:9616:3862#0/1 adapter start: 91	1	91	101	GAATTAAATCGAAGTGGACTGCTGGCGGAAAATGAGAAAATTCGACCTATCCTTGCGCAGCTCGAGAAGCTCTTACTTTGCGACCTTTCGC	GCCTAACTTC		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHHEHHHHHHHHHHHHHHFHHHHHHHFFFHFDHHEHHHGHHHHGDEHHGHHEGH	GCHHHHEHFG	
+SEQ:1:1101:9696:3866#0/1	-1	CAAGTTGCCATACAAAACAGGGTCGCCAGCAATATCGGTATAAGTCAAAGCACCTTTAGCGTTAAGGTACTGAATCTCTTTAGTCGCAGTAGGCGGAAAAC	HHHHHHHHHHHHHHHHHHHHEHEHHHEHHHHFHHHHHHFHHHFHFHHHHHHHHFHHHHFHHFEHBHFEHHHHCEEHHFHHHHHHHHHHHHEHHHHCAFEFG
+SEQ:1:1101:9512:3869#0/1	-1	GCTCGACGCCATTAATAATGTTTTCCGTAAATTCAGCGCCTTCCATGATGAGACAGGCCGTTTGAATGTTGACGGGATGAACATAATAAGCAATGACGGCA	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHFHHHDHHHEHHFFFFFFHFAFEFH?E at FFGGGFGHFHAEFGFFFCEEFF
+SEQ:1:1101:9723:3870#0/1 adapter start: 66	1	66	96	CTTTAGCAGCAAGGTATATATCTGACTTTTTGTTAACGTATTTAGCCACATAGCAACCAACAGACA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TATAA	adapt	##################################################################	##############################	#####
+SEQ:1:1101:9667:3874#0/1	-1	CTGCTGCATTTCCTGAGCTTAATGCTTGGGAGCGTGCTGGTGCTGATGCTTCCTCTGCTGGTATGGTTGACGCCGGATTTGAGAATCAAAAAGAGCTTACT	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHAHHHHEHHD=DAD>D6ADGE at EBE;@?BCGGE?4>ADAAC
+SEQ:1:1101:9565:3879#0/1 adapter start: 24	1	24	54	AGCCTTATGGCCGTCAACATACAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCACCATTATCGAACTCAACGCCCTGCATACGAAAAGACAGAATCT	adapt	HHHHHHHHHHHHHHHHHFHHGFFH	HHHHHHHHHDGHHFHFHHHHHFECHFFHHH	HHEHFCFFFFHEHDEFHHCHHEG?GFEGGEGHHHHHH?HH?EFFFFF
+SEQ:1:1101:9721:3885#0/1 adapter start: 51	1	51	81	TTCCTCAAACGCTTGTTCGGTGGATAAGTTATGGCATTAATCGATTTATTT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATCTCGCGGAAGAAAAACAC	adapt	>BC?:A?=<>::A=528882.53)5.77;407)*9@:AA8CAA########	##############################	####################
+SEQ:1:1101:9707:3894#0/1 adapter start: 40	1	40	70	AACACCATCCTTCATGAACTTAATCCACTGTTCACCATAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ACGTGACGATGAGGGACATAAAAAGTAAAAA	adapt	F at F8DEE@EEBCCCCFFEFDDC=DCCFFF=ADD=D>@AA@	FFFDE99>,>>@=856>;6C<@1:39@>6@	=??:B<B at B@F at FFE<@;B@###########
+SEQ:1:1101:9560:3900#0/1 adapter start: 6	1	6	36	AGAAGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GCCAGCCTGCAACGTACCTTCAAGAAGTCCTTTACCAGCTTTAGCCATAGCACCAGAAACAAAAC	adapt	GGGGGF	GGGGBGGGGFGGGFBEEDEEGFGACDDADF	EFFEDFGGEFECFFDFGFBDBGBFD?@.DCC5:;GFF>AEEEBEDFBF69:<8<B.DAC@;B@@E
+SEQ:1:1101:9696:3913#0/1 adapter start: 2	1	2	32	CC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	ATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCC	adapt	HH	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH	GHHHHGHHHHHHHHGHHFHHHHHHHHHHFHHHHHHHHHHHHFBGGGGFHHHHHHHHHEHHHHHHHHHEH
+SEQ:1:1101:9574:3914#0/1 adapter start: 5	1	5	35	GAACA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	AGCGCAAGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTC	adapt	HHHHH	HHHHHHHHHHFHHHHHHHHFHFHHHEHGHH	HHHHHHHHHHHHHEHHHHHHFGHFHEEFEGEHFCDEFFEFHFHGEHHHHHHHHHHHHFGHDHHFHD
+SEQ:1:1101:9508:3931#0/1 adapter start: 91	1	91	101	TAGAGAACGAGAAGACGGTTACGCAGTTTTGCCGCAAGCTGGCTGCTGAACGCCCTCTTAAGGATATTCGCGATGAGTATAATTACCCCAA	GCCTAACTTC		adapt	HGHHHHHHHHHHHHHHHHHHGHHHHHFHHHGHHHHFHHHHHHHHHD?ACFEF9FFEEBHBAEFB?E<F5CAD(DAEE;AE at C?D at BDGF?F	FFG;?DGDD:	
+SEQ:1:1101:9617:3935#0/1	-1	TAAATTTAATGTGACCGTTTATCGCAATCTGCCGACCACTCGCGATTCAATCATGACTTCGTGATAAAAGATTGAGTGTGAGGTTATAACGCCGAAGCGGT	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHGHHHHHHHHHHHHHHHHHFHHHFFEDFEFHFHHFHFHGHHFHHHFHHEHHHFHHHHFB
+SEQ:1:1101:9667:3950#0/1 adapter start: 66	1	66	96	CTTTAGCCATAGCACCAGAAACAAAACTAGGGACGGCCTCATCAGGGTTAGGAACATTAGAGCCTT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAATG	adapt	HHHHHHHHHHHHHHHHGHHHHHHHHGHHHHHHHHHHHHHHHHHHHHHEHHHHDGHFHHHHHHHBHH	HHHHHHHHHEEGDCGGBBFCFFE;GFBFFH	BDEH=
+SEQ:1:1101:9705:3951#0/1 adapter start: 29	1	29	59	ATTGCGTACCCGACGACCAAAATTAGGGT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CAACGCTACCTGTAGGAAGTGTCCGCATAAAGTGCACCGCAT	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHH	HHHHHHHFHHHHFHHHHFHEHHHHHHHFGH	FHEHHFHFHHHFHBFHHHHHHHHHHHFHEBFHFFFFCFCEF@
+SEQ:1:1101:9527:3965#0/1	-1	AACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGTTTGGTCAGTTCC	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHHHHHHHHHHFHHGHHFHEHHHEFEFF at HFHFGGGDGGHFGDFHFGHGHHFGHG
+SEQ:1:1101:9550:3969#0/1	-1	AGAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGTTGAACACGACCAGAAAACTGGCCTAACGACGTTTGGTC	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHFHHHHHHHHHHHHFHHHFHHFEHHHHHHHHHHHHHGHHFHHHHFHHHHHHHHHHHG
+SEQ:1:1101:9636:3973#0/1 adapter start: 9	1	9	39	CAAGCGCAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GAGTAAACATAGTGCCATGCTCAGGAACAAAGAAACGCGGCACAGAATGTTTATAGGTCTGT	adapt	HHHHHHHHH	HHHHHHHHHHHHHHHHHHHHHHGHHHHHHH	HHHHGHHHHHHFHHHFHHHHHHHBHHHFHHGFHHFEGFHGGHHHHHHHHEHHHFFHHHEEHE
+SEQ:1:1101:9726:3981#0/1 adapter start: 66	1	66	96	TTGCTGCCATCTCAAAAACATTTGGACTGCTCCGCTTCCTCCTGAGACTGAGCTTTCTCGCCAAAT	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GACGA	adapt	HHFEHHHHHHHHHHHHHHHHHHHHHHGHGHHGHGHHHHHHHHHHGGHHHEHHGFHHHHHEHHEHGH	GHGHHEHHBGGGG?GDFGGEGD=GEEGBGE	GFBEA
+SEQ:1:1101:9603:3981#0/1 adapter start: 32	1	32	62	TCTAAGAAGTTTAAGATTGCTGAGGGTCAGTG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GTATCGTTATGCGCCTTCGTATGTTTCTCCTGCTTATCA	adapt	HHHHHHHHHHHHHHHFHHHHHHHHHHEHHHHH	HEHHHHHHHFHHGHGHHHHHFHHEHHFGHH	HHEFHFHHHHHHFGHGHFHHFHHHEHEGFBDGGGB at F;G
+SEQ:1:1101:9533:3990#0/1 adapter start: 1	1	1	31	G	GCCTAACTTCTTAGACTGCCTTAAGGACGT	GGGAAGGACGTCAATAGTCACACAGTCCTTGACGGTATAATAACCACCATCATGGCGACCATCCAAAGGA	adapt	B	EFFEFF=FFEFDFFDFBF at D@DDDBBDD at B	CDDD::@=?BDCCAE@;BEEEE6>B5D>@DEDEEF?F<EFBBFFD8BCDDDCBCEECEEEE2??######
+SEQ:1:1101:9583:3992#0/1 adapter start: 20	1	20	50	AAGGTACTGAATCTCTTTAG	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCGCAGTAGGCGGAAAACGAACAAGCGCAAGAGTAAACATAGTGCCATGCT	adapt	98583=>><>B at CBCD==BB	DCDCCDD=8A>@<3A499:1@@@@CDC@@=	@=<C7:163><6@<@:=<?A0;333+01-97=<><?C@@@<99>>189<16
+SEQ:1:1101:9903:3754#0/1	-1	ACCAAAATTAGGGTCAACGCTACCTGTAGGAAGTGTCCGCATAAAGTGCACCGCATGGAAATGAAGACGGCCATCAGCTGTACCATACTCAGGCACACAAA	GFEGGGGGBGE at EAEEGGFGGEGGFGEFFGFGFFGGEGGGGEFGCFCEFBF7FGEGEF?BFEEFDFFE??AADD+D at C@CGFCE6FDFFDFBGFDD at DAAD
+SEQ:1:1101:9878:3755#0/1 adapter start: 32	1	32	62	AGAACGTGAAAAAGCGTCCTGCGTGTAGCGAA	GCCTAACTTCTTAGACTGCCTTAAGGACGT	CTGCGATGGGCATACTGTAACCATAAGGCCACGTATTTT	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH	HFHHHBHHHHHHHHHFHFHEHHHHHHHHHH	HHHEFHFHHHDFHHHHFGHHHHHFCEHECHHF?D5D7 at D
+SEQ:1:1101:9833:3756#0/1 adapter start: 65	1	65	95	TCATCGTCACGTTTATGGTGAACAGTGGATTAAGTTCATGAAGGATGGTGTTAATGCCACTCCTC	GCCTAACTTCTTAGACTGCCTTAAGGACGT	TCCCGA	adapt	HHHHHHHHHHHHHHHHHFHHHHHHHHHHHHHHHHFHHHHGHHFHHHHHEHEHHHHFHEHHHEHFH	HHFHHFEFFB=;,01:99;;HHHHHHEFGE	EFFBFB
+SEQ:1:1101:9991:3777#0/1	-1	GCTTTGAGTCTTCTTCGGTTCCGACTACCCTCCCGACTGCCTATGATGTTTATCCTTTGGATGGTCGCCATGATGGTGGTTATTATACCGTCAAGGACTGT	HHHHHHHHHHHHHHHHHHHHHHGHHHGHHHHHHHGHHHHHHGHHHHHHHHHHHHHFHHFFDFFFCFFDHCFF;BFGEFGEGFGGFFF.CFDCCEDB=CBC@
diff --git a/tests/cut/illumina5.info.txt b/tests/cut/illumina5.info.txt
index eb2e7dc..b5a6cec 100644
--- a/tests/cut/illumina5.info.txt
+++ b/tests/cut/illumina5.info.txt
@@ -1,8 +1,8 @@
-SEQ:1:1101:9010:3891#0/1 adapter start: 51	0	64	81	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGGGCCTAACTTCTTA	GACTGCCTTAAGGACGT	AAGCCAAGATGGGAAAGGTC	adapt2
-SEQ:1:1101:9010:3891#0/1 adapter start: 51	1	51	64	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGG	GCCTAACTTCTTA		adapt
-SEQ:1:1101:9240:3898#0/1	-1	CCAGCAAGGAAGCCAAGATGGGAAAGGTCATGCGGCATACGCTCGGCGCCAGTTTGAATATTAGACATAATTTATCCTCAAGTAAGGGGCCGAAGCCCCTG
-SEQ:1:1101:9207:3899#0/1 adapter start: 64	0	77	94	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAACGCCTAACTTCTTA	GACTGCCTTAAGGACGT	ATACATA	adapt2
-SEQ:1:1101:9207:3899#0/1 adapter start: 64	1	64	77	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAAC	GCCTAACTTCTTA		adapt
-SEQ:1:1101:9148:3908#0/1 adapter start: 28	0	41	58	ACGACGCAATGGAGAAAGACGGAGAGCGGCCTAACTTCTTA	GACTGCCTTAAGGACGT	CCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATAACCGGAG	adapt2
-SEQ:1:1101:9148:3908#0/1 adapter start: 28	1	28	41	ACGACGCAATGGAGAAAGACGGAGAGCG	GCCTAACTTCTTA		adapt
-SEQ:1:1101:9044:3916#0/1 adapter start: 78	1	78	91	AACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTATGGAAAACACCAATCTTTCCAAGCAACAGCAGGTTTCCGAGA	GCCTAACTTCTTA	GACTGCCTTA	adapt
+SEQ:1:1101:9010:3891#0/1 adapter start: 51	0	64	81	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGGGCCTAACTTCTTA	GACTGCCTTAAGGACGT	AAGCCAAGATGGGAAAGGTC	adapt2	FFFFFEDBE at 79@@>@CBCBFDBDFDDDDD<@C>ADD at B;5:978 at CBDDFFDB4B?DB21;84	?DDBC9DEBAB;=@<@@	B@@@@B>CCBBDE98>>0 at 7
+SEQ:1:1101:9010:3891#0/1 adapter start: 51	1	51	64	ATAACCGGAGTAGTTGAAATGGTAATAAGACGACCAATCTGACCAGCAAGG	GCCTAACTTCTTA		adapt	FFFFFEDBE at 79@@>@CBCBFDBDFDDDDD<@C>ADD at B;5:978 at CBDDF	FDB4B?DB21;84	
+SEQ:1:1101:9240:3898#0/1	-1	CCAGCAAGGAAGCCAAGATGGGAAAGGTCATGCGGCATACGCTCGGCGCCAGTTTGAATATTAGACATAATTTATCCTCAAGTAAGGGGCCGAAGCCCCTG	GHGHGHHHHGGGDHHGDCGFEEFHHGDFGEHHGFHHHHHGHEAFDHHGFHHEEFHGHFHHFHGEHFBHHFHHHH at GGGDGDFEEFC@=D?GBGFGF:FB6D
+SEQ:1:1101:9207:3899#0/1 adapter start: 64	0	77	94	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAACGCCTAACTTCTTA	GACTGCCTTAAGGACGT	ATACATA	adapt2	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHCFHHFHHFHFFFFFBHHG	HHHFFHHFHGGHHDEBF	G<FGGDG
+SEQ:1:1101:9207:3899#0/1 adapter start: 64	1	64	77	TTAACTTCTCAGTAACAGATACAAACTCATCACGAACGTCAGAAGCAGCCTTATGGCCGTCAAC	GCCTAACTTCTTA		adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHFHHHHHHCFHHF	HHFHFFFFFBHHG	
+SEQ:1:1101:9148:3908#0/1 adapter start: 28	0	41	58	ACGACGCAATGGAGAAAGACGGAGAGCGGCCTAACTTCTTA	GACTGCCTTAAGGACGT	CCAACGGCGTCCATCTCGAAGGAGTCGCCAGCGATAACCGGAG	adapt2	HHHHHHHHHHHHGHHHHGHHHHHHHHHHHHHHHHHHHHHHH	HHHHGHHHHDHDHHFHH	HHHFFFFFHHHEFBEGEGGFFFHHHFHHHHHHFHHEHHGHEHD
+SEQ:1:1101:9148:3908#0/1 adapter start: 28	1	28	41	ACGACGCAATGGAGAAAGACGGAGAGCG	GCCTAACTTCTTA		adapt	HHHHHHHHHHHHGHHHHGHHHHHHHHHH	HHHHHHHHHHHHH	
+SEQ:1:1101:9044:3916#0/1 adapter start: 78	1	78	91	AACAGAAGGAGTCTACTGCTCGCGTTGCGTCTATTATGGAAAACACCAATCTTTCCAAGCAACAGCAGGTTTCCGAGA	GCCTAACTTCTTA	GACTGCCTTA	adapt	HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHGHHHHGHHHHHHHHHHHHFHEBFHFFEFHE	FHHGHFHHHHGGH	GHHFHGGGHG
diff --git a/tests/cut/interleaved.fastq b/tests/cut/interleaved.fastq
new file mode 100644
index 0000000..081a90f
--- /dev/null
+++ b/tests/cut/interleaved.fastq
@@ -0,0 +1,16 @@
+ at read1/1 some text
+TTATTTGTCTCCAGC
++
+##HHHHHHHHHHHHH
+ at read1/2 other text
+GCTGGAGACAAATAA
++
+HHHHHHHHHHHHHHH
+ at read3/1
+CCAACTTGATATTAATAACA
++
+HHHHHHHHHHHHHHHHHHHH
+ at read3/2
+TGTTATTAATATCAAGTTGG
++
+#HHHHHHHHHHHHHHHHHHH
diff --git a/tests/cut/no_indels.fasta b/tests/cut/no_indels.fasta
new file mode 100644
index 0000000..7c56412
--- /dev/null
+++ b/tests/cut/no_indels.fasta
@@ -0,0 +1,18 @@
+>3p_orig
+TGAACATAGC
+>3p_mism
+TGAACATAGC
+>3p_del
+TGAACATAGCTTAACATATAACCG
+>3p_ins
+TGAACATAGCTTAGGACATATAACCG
+>3p_frontins
+TAGACATATAACCG
+>5p_orig
+TACTGCTTCTCGAA
+>5p_mism
+TACTGCTTCTCGAA
+>5p_del
+TCCTCGAGATGCCATACTGCTTCTCGAA
+>5p_ins
+TCCTCGAGATATGCCATACTGCTTCTCGAA
diff --git a/tests/cut/paired-filterboth.1.fastq b/tests/cut/paired-filterboth.1.fastq
new file mode 100644
index 0000000..a8b2b28
--- /dev/null
+++ b/tests/cut/paired-filterboth.1.fastq
@@ -0,0 +1,16 @@
+ at read1/1 some text
+TTATTTGTCTCCAGC
++
+##HHHHHHHHHHHHH
+ at read2/1
+CAACAGGCCACA
++
+HHHHHHHHHHHH
+ at read3/1
+CCAACTTGATATTAATAACA
++
+HHHHHHHHHHHHHHHHHHHH
+ at read4/1
+GACAGGCCGTTTGAATGTTGACGGGATGTT
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
diff --git a/tests/cut/paired-filterboth.2.fastq b/tests/cut/paired-filterboth.2.fastq
new file mode 100644
index 0000000..655d545
--- /dev/null
+++ b/tests/cut/paired-filterboth.2.fastq
@@ -0,0 +1,16 @@
+ at read1/2 other text
+GCTGGAGACAAATAACAGT
++
+HHHHHHHHHHHHHHHHHHH
+ at read2/2
+TGTGGCCTGTTGCAGT
++
+###HHHHHHHHHHHHH
+ at read3/2
+TGTTATTAATATCAAGTTGGCAGTG
++
+#HHHHHHHHHHHHHHHHHHHHHHHH
+ at read4/2
+CATCCCGTCAACATTCAAACGGCCTGTCCA
++
+HH############################
diff --git a/tests/cut/paired-too-short.1.fastq b/tests/cut/paired-too-short.1.fastq
new file mode 100644
index 0000000..64322e2
--- /dev/null
+++ b/tests/cut/paired-too-short.1.fastq
@@ -0,0 +1,4 @@
+ at read2/1
+CAACAGGCCACA
++
+HHHHHHHHHHHH
diff --git a/tests/cut/paired-too-short.2.fastq b/tests/cut/paired-too-short.2.fastq
new file mode 100644
index 0000000..96d2253
--- /dev/null
+++ b/tests/cut/paired-too-short.2.fastq
@@ -0,0 +1,4 @@
+ at read2/2
+TGTGGCCTGTTG
++
+###HHHHHHHHH
diff --git a/tests/cut/suffix.fastq b/tests/cut/suffix.fastq
index dd1ad1b..72392e0 100644
--- a/tests/cut/suffix.fastq
+++ b/tests/cut/suffix.fastq
@@ -1,120 +1,120 @@
- at 1_13_85_my_suffix
+ at 1_13_85_my_suffix_no_adapter
 T110020300.0113010210002110102330021
 +
 7&9<&77)&!<7))%4'657-1+9;9,.<8);.;8
- at 1_13_573_my_suffix
+ at 1_13_573_my_suffix_1
 T312311200.30213011011132
 +
 6)3%)&&&&!.1&(6:<'67..*,
- at 1_13_1259_my_suffix
+ at 1_13_1259_my_suffix_1
 T002112130.201222332211
 +
 =;<:&:A;A!9<<<,7:<=3=;
- at 1_13_1440_my_suffix
+ at 1_13_1440_my_suffix_no_adapter
 T110020313.1113211010332111302330001
 +
 =<=A:A=57!7<';<6?5;;6:+:=)71>70<,=:
- at 1_14_177_my_suffix
+ at 1_14_177_my_suffix_no_adapter
 T31330222020233321121323302013303311
 +
 :8957;;54)'98924905;;)6:7;1:3<88(9:
- at 1_14_238_my_suffix
+ at 1_14_238_my_suffix_1
 T0133103120031002212223
 +
 ?><5=;<<<12>=<;1;;=5);
- at 1_15_1098_my_suffix
+ at 1_15_1098_my_suffix_no_adapter
 T32333033222233020223032312232220332
 +
 #,##(#5##*#($$'#.##)$&#%)$1##-$&##%
- at 1_16_404_my_suffix
+ at 1_16_404_my_suffix_1
 T03310320002130202331112
 +
 78;:;;><>9=9;<<2=><<1;5
- at 1_16_904_my_suffix
+ at 1_16_904_my_suffix_no_adapter
 T21230102331022312232132021122111212
 +
 9>=::6;;99=+/'$+#.#&%$&'(($1*$($.#.
- at 1_16_1315_my_suffix
+ at 1_16_1315_my_suffix_1
 T032312311122103330103103
 +
 <9<8A?>?::;6&,%;6/)8<<#/
- at 1_16_1595_my_suffix
+ at 1_16_1595_my_suffix_no_adapter
 T22323211312111230022210011213302012
 +
 >,<=<>@6<;?<=>:/=.>&;;8;)17:=&,>1=+
- at 1_17_1379_my_suffix
+ at 1_17_1379_my_suffix_no_adapter
 T32011212111223230232132311321200123
 +
 /-1179<1;>>8:':7-%/::0&+=<29,7<8(,2
- at 1_18_1692_my_suffix
+ at 1_18_1692_my_suffix_no_adapter
 T12322233031100211233323300112200210
 +
 .#(###5%)%2)',2&:+#+&5,($/1#&4&))$6
- at 1_19_171_my_suffix
+ at 1_19_171_my_suffix_no_adapter
 T10101101220213201111011320201230032
 +
 )6:65/=3*:(8%)%2>&8&%;%0&#;$3$&:$#&
- at 1_22_72_my_suffix
+ at 1_22_72_my_suffix_no_adapter
 T13303032323221212301322233320210233
 +
 3/#678<:.=9::6:(<538295;9+;&*;)+',&
- at 1_22_1377_my_suffix
+ at 1_22_1377_my_suffix_no_adapter
 T22221333311222312201132312022322300
 +
 )##0%.$.1*%,)95+%%14%$#8-###9-()#9+
- at 1_23_585_my_suffix
+ at 1_23_585_my_suffix_1
 T300103103101303121221
 +
 >55;8><96/18?)<3<58<5
- at 1_23_809_my_suffix
+ at 1_23_809_my_suffix_no_adapter
 T13130101101021211013220302223302112
 +
 :7<59@;<<5;/9;=<;7::.)&&&827(+221%(
- at 1_24_138_my_suffix
+ at 1_24_138_my_suffix_1
 T33211130100120323002
 +
 6)68/;906#,25/&;<$0+
- at 1_24_206_my_suffix
+ at 1_24_206_my_suffix_no_adapter
 T33330332002223002020303331321221000
 +
 ))4(&)9592)#)694(,)292:(=7$.18,()65
- at 1_25_143_my_suffix
+ at 1_25_143_my_suffix_no_adapter
 T23202003031200220301303302012203132
 +
 :4;/#&<9;&*;95-7;85&;587#16>%&,9<2&
- at 1_25_1866_my_suffix
+ at 1_25_1866_my_suffix_no_adapter
 T03201321022131101112012330221130311
 +
 =<>9;<@7?(=6,<&?=6=(=<641:?'<1=;':4
- at 1_27_584_my_suffix
+ at 1_27_584_my_suffix_no_adapter
 T10010330110103213112323303012103101
 +
 82'('*.-8+%#2)(-&3.,.2,),+.':&,'(&/
- at 1_27_1227_my_suffix
+ at 1_27_1227_my_suffix_no_adapter
 T02003022123001003201002031303302011
 +
 492:;>A:<;34<<=);:<<;9=7<3::<::3=>'
- at 1_27_1350_my_suffix
+ at 1_27_1350_my_suffix_no_adapter
 T13130101101021211013220222221301231
 +
 95,)<(4./;<938=64=+2/,.4),3':97#33&
- at 1_29_477_my_suffix
+ at 1_29_477_my_suffix_no_adapter
 T13130101101021211013300302223003030
 +
 94=55:75=+:/7><968;;#&+$#3&6,#1#4#'
- at 1_30_882_my_suffix
+ at 1_30_882_my_suffix_1
 T20102033000233
 +
 2(+-:-3<;5##/;
- at 1_31_221_my_suffix
+ at 1_31_221_my_suffix_no_adapter
 T03301311201100030300100233220102031
 +
 89>9>5<139/,&:7969972.274&%:78&&746
- at 1_31_1313_my_suffix
+ at 1_31_1313_my_suffix_1
 T0133113130033012232100010101
 +
 ;3<7=7::)5*4=&;<7>4;795065;9
- at 1_529_129_my_suffix
+ at 1_529_129_my_suffix_no_adapter
 T132222301020322102101322221322302.3302.3.3..221..3
 +
 >>%/((B6-&5A0:6)>;'1)B*38/?(5=%B+!&<-9!%!@!!)%)!!(
diff --git a/tests/data/interleaved.fastq b/tests/data/interleaved.fastq
new file mode 100644
index 0000000..1da3fdb
--- /dev/null
+++ b/tests/data/interleaved.fastq
@@ -0,0 +1,32 @@
+ at read1/1 some text
+TTATTTGTCTCCAGCTTAGACATATCGCCT
++
+##HHHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read1/2 other text
+GCTGGAGACAAATAACAGTGGAGTAGTTTT
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read2/1
+CAACAGGCCACATTAGACATATCGGATGGT
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read2/2
+TGTGGCCTGTTGCAGTGGAGTAACTCCAGC
++
+###HHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read3/1
+CCAACTTGATATTAATAACATTAGACA
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read3/2
+TGTTATTAATATCAAGTTGGCAGTG
++
+#HHHHHHHHHHHHHHHHHHHHHHHH
+ at read4/1
+GACAGGCCGTTTGAATGTTGACGGGATGTT
++
+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
+ at read4/2
+CATCCCGTCAACATTCAAACGGCCTGTCCA
++
+HH############################
diff --git a/tests/data/no_indels.fasta b/tests/data/no_indels.fasta
new file mode 100644
index 0000000..7a6afb7
--- /dev/null
+++ b/tests/data/no_indels.fasta
@@ -0,0 +1,20 @@
+# 3' adapter: TTAGACATAT
+# 5' adapter: GAGATTGCCA
+>3p_orig
+TGAACATAGCTTAGACATATAACCG
+>3p_mism
+TGAACATAGCTTACACATATAACCG
+>3p_del
+TGAACATAGCTTAACATATAACCG
+>3p_ins
+TGAACATAGCTTAGGACATATAACCG
+>3p_frontins
+TAGACATATAACCG
+>5p_orig
+TCCTCGAGATTGCCATACTGCTTCTCGAA
+>5p_mism
+TCCTCGAGATAGCCATACTGCTTCTCGAA
+>5p_del
+TCCTCGAGATGCCATACTGCTTCTCGAA
+>5p_ins
+TCCTCGAGATATGCCATACTGCTTCTCGAA
diff --git a/tests/data/simple.fasta~ b/tests/data/simple.fasta~
deleted file mode 100644
index ba68078..0000000
--- a/tests/data/simple.fasta~
+++ /dev/null
@@ -1,6 +0,0 @@
-# a comment
-# another one
->first_sequence
-SEQUENCE1
->second_sequence
-SEQUENCE2
diff --git a/tests/testadapters.py b/tests/testadapters.py
index c86dc6a..60d55ea 100644
--- a/tests/testadapters.py
+++ b/tests/testadapters.py
@@ -3,7 +3,8 @@ from __future__ import print_function, division, absolute_import
 from nose.tools import raises, assert_raises
 
 from cutadapt.seqio import Sequence
-from cutadapt.adapters import Adapter, AdapterMatch, ColorspaceAdapter, FRONT, BACK
+from cutadapt.adapters import (Adapter, Match, ColorspaceAdapter, FRONT,
+	BACK, parse_braces)
 
 def test_issue_52():
 	adapter = Adapter(
@@ -14,7 +15,7 @@ def test_issue_52():
 		read_wildcards=False,
 		adapter_wildcards=True)
 	read = Sequence(name="abc", sequence='CCCCAGAACTACAGTCCCGGC')
-	am = AdapterMatch(astart=0, astop=17, rstart=5, rstop=21, matches=15, errors=2, front=None, adapter=adapter, read=read)
+	am = Match(astart=0, astop=17, rstart=5, rstop=21, matches=15, errors=2, front=None, adapter=adapter, read=read)
 	assert am.wildcards() == 'GGC'
 	"""
 	The result above should actually be 'CGGC' since the correct
@@ -69,24 +70,19 @@ def test_color():
 
 
 def test_parse_braces():
-	assert Adapter.parse_braces('') == ''
-	assert Adapter.parse_braces('A') == 'A'
-	assert Adapter.parse_braces('A{0}') == ''
-	assert Adapter.parse_braces('A{1}') == 'A'
-	assert Adapter.parse_braces('A{2}') == 'AA'
-	assert Adapter.parse_braces('A{2}C') == 'AAC'
-	assert Adapter.parse_braces('ACGTN{3}TGACCC') == 'ACGTNNNTGACCC'
-	assert Adapter.parse_braces('ACGTN{10}TGACCC') == 'ACGTNNNNNNNNNNTGACCC'
-	assert Adapter.parse_braces('ACGTN{3}TGA{4}CCC') == 'ACGTNNNTGAAAACCC'
-	assert Adapter.parse_braces('ACGTN{0}TGA{4}CCC') == 'ACGTTGAAAACCC'
+	assert parse_braces('') == ''
+	assert parse_braces('A') == 'A'
+	assert parse_braces('A{0}') == ''
+	assert parse_braces('A{1}') == 'A'
+	assert parse_braces('A{2}') == 'AA'
+	assert parse_braces('A{2}C') == 'AAC'
+	assert parse_braces('ACGTN{3}TGACCC') == 'ACGTNNNTGACCC'
+	assert parse_braces('ACGTN{10}TGACCC') == 'ACGTNNNNNNNNNNTGACCC'
+	assert parse_braces('ACGTN{3}TGA{4}CCC') == 'ACGTNNNTGAAAACCC'
+	assert parse_braces('ACGTN{0}TGA{4}CCC') == 'ACGTTGAAAACCC'
 
 
 def test_parse_braces_fail():
 	for expression in ['{', '}', '{}', '{5', '{1}', 'A{-7}', 'A{', 'A{1', 'N{7', 'AN{7', 'A{4{}',
 			'A{4}{3}', 'A{b}', 'A{6X}', 'A{X6}']:
-		print(expression)
-		try:
-			Adapter.parse_braces(expression)
-		except ValueError as e:
-			print(e)
-		assert_raises(ValueError, lambda: Adapter.parse_braces(expression))
+		assert_raises(ValueError, lambda: parse_braces(expression))
diff --git a/tests/testalign.py b/tests/testalign.py
index e5cc27b..0ede180 100644
--- a/tests/testalign.py
+++ b/tests/testalign.py
@@ -2,9 +2,22 @@
 from __future__ import print_function, division, absolute_import
 
 from cutadapt.align import (locate, compare_prefixes, compare_suffixes,
-	ALLOW_WILDCARD_SEQ1, ALLOW_WILDCARD_SEQ2)
+	Aligner)
 from cutadapt.adapters import BACK
 
+
+class TestAligner():
+	def test(self):
+		reference = 'CTCCAGCTTAGACATATC'
+		aligner = Aligner(reference, 0.1, flags=BACK)
+		aligner.locate('CC')
+
+	def test_100_percent_error_rate(self):
+		reference = 'GCTTAGACATATC'
+		aligner = Aligner(reference, 1.0, flags=BACK)
+		aligner.locate('CAA')
+
+
 def test_polya():
 	s = 'AAAAAAAAAAAAAAAAA'
 	t = 'ACAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
@@ -37,49 +50,50 @@ WILDCARD_SEQUENCES = [
 
 def test_compare_prefixes():
 	assert compare_prefixes('AAXAA', 'AAAAATTTTTTTTT') == (0, 5, 0, 5, 4, 1)
-	assert compare_prefixes('AANAA', 'AACAATTTTTTTTT', ALLOW_WILDCARD_SEQ1) == (0, 5, 0, 5, 5, 0)
-	assert compare_prefixes('AANAA', 'AACAATTTTTTTTT', ALLOW_WILDCARD_SEQ1) == (0, 5, 0, 5, 5, 0)
+	assert compare_prefixes('AANAA', 'AACAATTTTTTTTT', wildcard_ref=True) == (0, 5, 0, 5, 5, 0)
+	assert compare_prefixes('AANAA', 'AACAATTTTTTTTT', wildcard_ref=True) == (0, 5, 0, 5, 5, 0)
 	assert compare_prefixes('XAAAAA', 'AAAAATTTTTTTTT') == (0, 6, 0, 6, 4, 2)
 
 	a = WILDCARD_SEQUENCES[0]
 	for s in WILDCARD_SEQUENCES:
 		r = s + 'GCCAGGGTTGATTCGGCTGATCTGGCCG'
-		result = compare_prefixes(a, r, degenerate=ALLOW_WILDCARD_SEQ2)
+		result = compare_prefixes(a, r, wildcard_query=True)
 		assert result == (0, 10, 0, 10, 10, 0), result
 
-		result = compare_prefixes(r, a, degenerate=ALLOW_WILDCARD_SEQ1)
+		result = compare_prefixes(r, a, wildcard_ref=True)
 		assert result == (0, 10, 0, 10, 10, 0)
 
 	for s in WILDCARD_SEQUENCES:
 		for t in WILDCARD_SEQUENCES:
 			r = s + 'GCCAGGG'
-			result = compare_prefixes(s, r, degenerate=ALLOW_WILDCARD_SEQ1|ALLOW_WILDCARD_SEQ2)
+			result = compare_prefixes(s, r, )
 			assert result == (0, 10, 0, 10, 10, 0)
 
-			result = compare_prefixes(r, s, degenerate=ALLOW_WILDCARD_SEQ1|ALLOW_WILDCARD_SEQ2)
+			result = compare_prefixes(r, s, wildcard_ref=True, wildcard_query=True)
 			assert result == (0, 10, 0, 10, 10, 0)
 
 	r = WILDCARD_SEQUENCES[0] + 'GCCAGG'
-	for deg in 0, ALLOW_WILDCARD_SEQ1, ALLOW_WILDCARD_SEQ2, ALLOW_WILDCARD_SEQ1|ALLOW_WILDCARD_SEQ2:
-		result = compare_prefixes('CCCXTTXATC', r, degenerate=deg)
-		assert result == (0, 10, 0, 10, 8, 2)
+	for wildc_ref in (False, True):
+		for wildc_query in (False, True):
+			result = compare_prefixes('CCCXTTXATC', r, wildcard_ref=wildc_ref, wildcard_query=wildc_query)
+			assert result == (0, 10, 0, 10, 8, 2)
 
 
 def test_compare_suffixes():
 	assert compare_suffixes('AAXAA', 'TTTTTTTAAAAA') == (0, 5, 7, 12, 4, 1)
-	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
-	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
+	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
+	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
 	assert compare_suffixes('AAAAAX', 'TTTTTTTAAAAA') == (0, 6, 6, 12, 4, 2)
 
 
 def test_wildcards_in_adapter():
 	r = 'CATCTGTCC' + WILDCARD_SEQUENCES[0] + 'GCCAGGGTTGATTCGGCTGATCTGGCCG'
 	for a in WILDCARD_SEQUENCES:
-		result = locate(a, r, 0.0, BACK, degenerate=ALLOW_WILDCARD_SEQ1)
+		result = locate(a, r, 0.0, BACK, wildcard_ref=True)
 		assert result == (0, 10, 9, 19, 10, 0), result
 
 	a = 'CCCXTTXATC'
-	result = locate(a, r, 0.0, BACK, degenerate=ALLOW_WILDCARD_SEQ1)
+	result = locate(a, r, 0.0, BACK, wildcard_ref=True)
 	assert result is None
 
 
@@ -87,7 +101,7 @@ def test_wildcards_in_read():
 	a = WILDCARD_SEQUENCES[0]
 	for s in WILDCARD_SEQUENCES:
 		r = 'CATCTGTCC' + s + 'GCCAGGGTTGATTCGGCTGATCTGGCCG'
-		result = locate(a, r, 0.0, BACK, degenerate=ALLOW_WILDCARD_SEQ2)
+		result = locate(a, r, 0.0, BACK, wildcard_query=True)
 		if 'X' in s:
 			assert result is None
 		else:
@@ -100,7 +114,7 @@ def test_wildcards_in_both():
 			if 'X' in s or 'X' in a:
 				continue
 			r = 'CATCTGTCC' + s + 'GCCAGGGTTGATTCGGCTGATCTGGCCG'
-			result = locate(a, r, 0.0, BACK, degenerate=ALLOW_WILDCARD_SEQ1|ALLOW_WILDCARD_SEQ2)
+			result = locate(a, r, 0.0, BACK, wildcard_ref=True, wildcard_query=True)
 			assert result == (0, 10, 9, 19, 10, 0), result
 
 
diff --git a/tests/testfilters.py b/tests/testfilters.py
index abd85a1..3976e72 100644
--- a/tests/testfilters.py
+++ b/tests/testfilters.py
@@ -4,7 +4,7 @@ Tests write output (should it return True or False or write)
 """
 from __future__ import print_function, division, absolute_import
 
-from cutadapt.filters import NContentFilter, DISCARD, KEEP
+from cutadapt.filters import NContentFilter, DISCARD, KEEP, LegacyPairedRedirector, PairedRedirector
 from cutadapt.seqio import Sequence
 
 def test_ncontentfilter():
@@ -32,10 +32,11 @@ def test_ncontentfilter_paired():
 		('ANAA', 'AANA', 1, KEEP),
 	]
 	for seq1, seq2, count, expected in params:
-		filter = NContentFilter(count=count, check_second=False)
-		filter_cs = NContentFilter(count=count, check_second=True)
+		filter = NContentFilter(count=count)
+		filter_legacy = LegacyPairedRedirector(None, filter)
+		filter_both = PairedRedirector(None, filter)
 		read1 = Sequence('read1', seq1, qualities='#'*len(seq1))
 		read2 = Sequence('read1', seq2, qualities='#'*len(seq2))
-		assert filter(read1, read2) == filter(read1)
+		assert filter_legacy(read1, read2) == filter(read1)
 		# discard entire pair if one of the reads fulfills criteria
-		assert filter_cs(read1, read2) == expected
+		assert filter_both(read1, read2) == expected
diff --git a/tests/testpaired.py b/tests/testpaired.py
index 6084bb5..9697e2c 100644
--- a/tests/testpaired.py
+++ b/tests/testpaired.py
@@ -18,6 +18,27 @@ def run_paired(params, in1, in2, expected1, expected2):
 			assert files_equal(cutpath(expected2), p2)
 
 
+def run_interleaved(params, inpath, expected):
+	if type(params) is str:
+		params = params.split()
+	with temporary_path("temp-interleaved.fastq") as tmp:
+		params += ['--interleaved', '-o', tmp, datapath(inpath)]
+		assert cutadapt.main(params) is None
+		assert files_equal(cutpath(expected), tmp)
+
+
+def run_interleaved2(params, inpath, expected1, expected2):
+	if type(params) is str:
+		params = params.split()
+	with temporary_path("temp-paired.1.fastq") as p1:
+		with temporary_path("temp-paired.2.fastq") as p2:
+			params += ['--interleaved', '-o', p1, '-p', p2]
+		params += [datapath(inpath)]
+		assert cutadapt.main(params) is None
+		assert files_equal(cutpath(expected), p1)
+		assert files_equal(cutpath(expected), p2)
+
+
 def test_paired_separate():
 	'''test separate trimming of paired-end reads'''
 	run('-a TTAGACATAT', 'paired-separate.1.fastq', 'paired.1.fastq')
@@ -113,7 +134,7 @@ def test_unmatched_read_names():
 		with open(swapped, 'w') as f:
 			f.writelines(lines)
 		with redirect_stderr():
-			cutadapt.main('-a XX --paired-output out.fastq'.split() + [swapped, datapath('paired.2.fastq')])
+			cutadapt.main('-a XX -o out1.fastq --paired-output out2.fastq'.split() + [swapped, datapath('paired.2.fastq')])
 
 
 def test_legacy_minlength():
@@ -167,3 +188,85 @@ def test_paired_end_A_only():
 		in1='paired.1.fastq', in2='paired.2.fastq',
 		expected1='paired-onlyA.1.fastq', expected2='paired-onlyA.2.fastq'
 	)
+
+
+def test_discard_untrimmed():
+	# issue #146
+	# the first adapter is a sequence cut out from the first read
+	run_paired('-a CTCCAGCTTAGACATATC -A XXXXXXXX --discard-untrimmed',
+		in1='paired.1.fastq', in2='paired.2.fastq',
+		expected1='empty.fastq', expected2='empty.fastq'
+	)
+
+
+def test_discard_trimmed():
+	run_paired('-A C -O 1 --discard-trimmed',  # applies everywhere
+		in1='paired.1.fastq', in2='paired.2.fastq',
+		expected1='empty.fastq', expected2='empty.fastq'
+	)
+
+
+def test_interleaved():
+	'''single-pass interleaved paired-end with -q and -m'''
+	run_interleaved('-q 20 -a TTAGACATAT -A CAGTGGAGTA -m 14 -M 90',
+		inpath='interleaved.fastq', expected='interleaved.fastq'
+	)
+
+
+ at raises(SystemExit)
+def test_interleaved_no_paired_output():
+	with temporary_path("temp-paired.1.fastq") as p1:
+		with temporary_path("temp-paired.2.fastq") as p2:
+			params = '-a XX --interleaved'.split()
+			with redirect_stderr():
+				params += [ '-o', p1, '-p1', p2, 'paired.1.fastq', 'paired.2.fastq']
+				cutadapt.main(params)
+
+"""
+def test_interleaved_input_paired_output():
+	'''single-pass interleaved paired-end with -q and -m, paired output'''
+	run_interleaved2('-q 20 -a TTAGACATAT -A CAGTGGAGTA -m 14 -M 90',
+		inpath='interleaved.fastq', expected1='pairedq1.fastq', expected2='pairedq2.fastq'
+	)
+"""
+
+
+def test_pair_filter():
+	run_paired('--pair-filter=both -a TTAGACATAT -A GGAGTA -m 14',
+		in1='paired.1.fastq', in2='paired.2.fastq',
+		expected1='paired-filterboth.1.fastq', expected2='paired-filterboth.2.fastq'
+	)
+
+
+def test_too_short_paired_output():
+	with temporary_path("temp-too-short.1.fastq") as p1:
+		with temporary_path("temp-too-short.2.fastq") as p2:
+			run_paired('-a TTAGACATAT -A CAGTGGAGTA -m 14 --too-short-output '
+				'{0} --too-short-paired-output {1}'.format(p1, p2),
+				in1='paired.1.fastq', in2='paired.2.fastq',
+				expected1='paired.1.fastq', expected2='paired.2.fastq'
+			)
+			assert files_equal(cutpath('paired-too-short.1.fastq'), p1)
+			assert files_equal(cutpath('paired-too-short.2.fastq'), p2)
+
+
+def test_too_long_output():
+	with temporary_path("temp-too-long.1.fastq") as p1:
+		with temporary_path("temp-too-long.2.fastq") as p2:
+			run_paired('-a TTAGACATAT -A CAGTGGAGTA -M 14 --too-long-output '
+				'{0} --too-long-paired-output {1}'.format(p1, p2),
+				in1='paired.1.fastq', in2='paired.2.fastq',
+				expected1='paired-too-short.1.fastq', expected2='paired-too-short.2.fastq'
+			)
+			assert files_equal(cutpath('paired.1.fastq'), p1)
+			assert files_equal(cutpath('paired.2.fastq'), p2)
+
+
+ at raises(SystemExit)
+def test_too_short_output_paired_option_missing():
+	with temporary_path("temp-too-short.1.fastq") as p1:
+		run_paired('-a TTAGACATAT -A CAGTGGAGTA -m 14 --too-short-output '
+			'{0}'.format(p1),
+			in1='paired.1.fastq', in2='paired.2.fastq',
+			expected1='paired.1.fastq', expected2='paired.2.fastq'
+		)
diff --git a/tests/tests.py b/tests/tests.py
index c61d0ec..34b3c1a 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -147,7 +147,7 @@ def test_gz_multiblock():
 
 def test_suffix():
 	'''-y/--suffix parameter, combined with _F3'''
-	run("-c -e 0.12 -a 330201030313112312 -y _my_suffix --strip-f3", "suffix.fastq", "solid.csfasta", 'solid.qual')
+	run("-c -e 0.12 -a 1=330201030313112312 -y _my_suffix_{name} --strip-f3", "suffix.fastq", "solid.csfasta", 'solid.qual')
 
 def test_read_wildcard():
 	'''test wildcards in reads'''
@@ -194,6 +194,9 @@ def test_literal_N2_brace_notation():
 def test_anchored_front():
 	run("-g ^FRONTADAPT -N", "anchored.fasta", "anchored.fasta")
 
+def test_anchored_front_ellipsis_notation():
+	run("-a FRONTADAPT... -N", "anchored.fasta", "anchored.fasta")
+
 def test_anchored_back():
 	run("-a BACKADAPTER$ -N", "anchored-back.fasta", "anchored-back.fasta")
 
@@ -201,6 +204,10 @@ def test_anchored_back_no_indels():
 	run("-a BACKADAPTER$ -N --no-indels", "anchored-back.fasta", "anchored-back.fasta")
 
 
+def test_no_indels():
+	run('-a TTAGACATAT -g GAGATTGCCA --no-indels', 'no_indels.fasta', 'no_indels.fasta')
+
+
 def test_issue_46():
 	'''issue 46 - IndexError with --wildcard-file'''
 	with temporary_path("wildcardtmp.txt") as wildcardtmp:
@@ -225,6 +232,12 @@ def test_info_file_times():
 		assert files_equal(cutpath('illumina5.info.txt'), infotmp)
 
 
+def test_info_file_fasta():
+	with temporary_path("infotmp.txt") as infotmp:
+		# Just make sure that it runs
+		run(['--info-file', infotmp, '-a', 'TTAGACATAT', '-g', 'GAGATTGCCA', '--no-indels'], 'no_indels.fasta', 'no_indels.fasta')
+
+
 def test_named_adapter():
 	run("-a MY_ADAPTER=GCCGAACTTCTTAGACTGCCTTAAGGACGT", "illumina.fastq", "illumina.fastq.gz")
 
diff --git a/tests/testseqio.py b/tests/testseqio.py
index 27fbf13..7c49c96 100644
--- a/tests/testseqio.py
+++ b/tests/testseqio.py
@@ -2,174 +2,300 @@
 from __future__ import print_function, division, absolute_import
 
 import sys
+import os
+import shutil
 from textwrap import dedent
 from nose.tools import raises
-from cutadapt import seqio
+from tempfile import mkdtemp
+from cutadapt.seqio import (Sequence, ColorspaceSequence, FormatError,
+	FastaReader, FastqReader, FastaQualReader, InterleavedSequenceReader,
+	FastaWriter, FastqWriter, InterleavedSequenceWriter, open as openseq)
 from cutadapt.compat import StringIO
 
 
 # files tests/data/simple.fast{q,a}
 simple_fastq = [
-	seqio.Sequence("first_sequence", "SEQUENCE1", ":6;;8<=:<"),
-	seqio.Sequence("second_sequence", "SEQUENCE2", "83<??:(61")
+	Sequence("first_sequence", "SEQUENCE1", ":6;;8<=:<"),
+	Sequence("second_sequence", "SEQUENCE2", "83<??:(61")
 	]
 
-simple_fasta = [ seqio.Sequence(x.name, x.sequence, None) for x in simple_fastq ]
-
-
-def test_fastareader():
-	with seqio.FastaReader("tests/data/simple.fasta") as f:
-		reads = list(f)
-	assert reads == simple_fasta
-
-	fasta = StringIO(">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
-	reads = list(seqio.FastaReader(fasta))
-	assert reads == simple_fasta
-
-
-def test_fastareader_with_comments():
-	fasta = StringIO(dedent(
-		"""
-		# a comment
-		# another one
-		>first_sequence
-		SEQUENCE1
-		>second_sequence
-		SEQUENCE2
-		"""))
-	reads = list(seqio.FastaReader(fasta))
-	assert reads == simple_fasta
-
-
- at raises(seqio.FormatError)
-def test_wrong_fasta_format():
-	fasta = StringIO(dedent(
-		"""
-		# a comment
-		# another one
-		unexpected
-		>first_sequence
-		SEQUENCE1
-		>second_sequence
-		SEQUENCE2
-		"""))
-	reads = list(seqio.FastaReader(fasta))
-
-
-def test_fastqreader():
-	with seqio.FastqReader("tests/data/simple.fastq") as f:
-		reads = list(f)
-	assert reads == simple_fastq
-
-
-def test_fastqreader_dos():
-	with seqio.FastqReader("tests/data/dos.fastq") as f:
-		dos_reads = list(f)
-	with seqio.FastqReader("tests/data/small.fastq") as f:
-		unix_reads = list(f)
-	assert dos_reads == unix_reads
-
-
-def test_fastareader_keeplinebreaks():
-	with seqio.FastaReader("tests/data/simple.fasta", keep_linebreaks=True) as f:
-		reads = list(f)
-	assert reads[0] == simple_fasta[0]
-	assert reads[1].sequence == 'SEQUEN\nCE2'
-
-
- at raises(seqio.FormatError)
-def test_fastq_wrongformat():
-	with seqio.FastqReader("tests/data/withplus.fastq") as f:
-		reads = list(f)
-
-
- at raises(seqio.FormatError)
-def test_fastq_incomplete():
-	fastq = StringIO("@name\nACGT+\n")
-	with seqio.FastqReader(fastq) as fq:
-		list(fq)
-
-
- at raises(seqio.FormatError)
-def test_too_many_qualities():
-	seqio.Sequence(name="name", sequence="ACGT", qualities="#####")
-
-
- at raises(seqio.FormatError)
-def test_too_many_qualities_colorspace():
-	seqio.ColorspaceSequence(name="name", sequence="T0123", qualities="#####")
-
-
- at raises(seqio.FormatError)
-def test_invalid_primer():
-	seqio.ColorspaceSequence(name="name", sequence="K0123", qualities="####")
-
-
- at raises(seqio.FormatError)
-def test_mismatching_read_names():
-	fasta = StringIO(">name\nACG")
-	qual = StringIO(">nome\n3 5 7")
-	list(seqio.FastaQualReader(fasta, qual))
-
-
- at raises(seqio.FormatError)
-def test_invalid_quality_value():
-	fasta = StringIO(">name\nACG")
-	qual = StringIO(">name\n3 xx 7")
-	list(seqio.FastaQualReader(fasta, qual))
-
-
-def test_sequence_reader():
-	# test the autodetection
-	with seqio.open("tests/data/simple.fastq") as f:
-		reads = list(f)
-	assert reads == simple_fastq
-
-	with seqio.open("tests/data/simple.fasta") as f:
-		reads = list(f)
-	assert reads == simple_fasta
-
-	with open("tests/data/simple.fastq") as f:
-		reads = list(seqio.open(f))
-	assert reads == simple_fastq
-
-	# make the name attribute unavailable
-	f = StringIO(open("tests/data/simple.fastq").read())
-	reads = list(seqio.open(f))
-	assert reads == simple_fastq
-
-	f = StringIO(open("tests/data/simple.fasta").read())
-	reads = list(seqio.open(f))
-	assert reads == simple_fasta
-
-
-def test_fasta_context_manager():
-	filename = "tests/data/simple.fasta"
-	with open(filename) as f:
-		assert not f.closed
-		reads = list(seqio.open(f))
-		assert not f.closed
-	assert f.closed
-
-	with seqio.FastaReader(filename) as sr:
-		tmp_sr = sr
-		assert not sr.fp.closed
-		reads = list(sr)
-		assert not sr.fp.closed
-	assert tmp_sr.fp is None
-
-
-def test_fastq_context_manager():
-	filename = "tests/data/simple.fastq"
-	with open(filename) as f:
-		assert not f.closed
-		reads = list(seqio.open(f))
-		assert not f.closed
-	assert f.closed
-
-	with seqio.FastqReader(filename) as sr:
-		tmp_sr = sr
-		assert not sr.fp.closed
-		reads = list(sr)
-		assert not sr.fp.closed
-	assert tmp_sr.fp is None
+simple_fasta = [ Sequence(x.name, x.sequence, None) for x in simple_fastq ]
+
+
+class TestSequence:
+	@raises(FormatError)
+	def test_too_many_qualities(self):
+		Sequence(name="name", sequence="ACGT", qualities="#####")
+
+	@raises(FormatError)
+	def test_too_many_qualities_colorspace(self):
+		ColorspaceSequence(name="name", sequence="T0123", qualities="#####")
+
+	@raises(FormatError)
+	def test_invalid_primer(self):
+		ColorspaceSequence(name="name", sequence="K0123", qualities="####")
+
+
+class TestFastaReader:
+	def test(self):
+		with FastaReader("tests/data/simple.fasta") as f:
+			reads = list(f)
+		assert reads == simple_fasta
+
+		fasta = StringIO(">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
+		reads = list(FastaReader(fasta))
+		assert reads == simple_fasta
+
+	def test_with_comments(self):
+		fasta = StringIO(dedent(
+			"""
+			# a comment
+			# another one
+			>first_sequence
+			SEQUENCE1
+			>second_sequence
+			SEQUENCE2
+			"""))
+		reads = list(FastaReader(fasta))
+		assert reads == simple_fasta
+
+	@raises(FormatError)
+	def test_wrong_format(self):
+		fasta = StringIO(dedent(
+			"""
+			# a comment
+			# another one
+			unexpected
+			>first_sequence
+			SEQUENCE1
+			>second_sequence
+			SEQUENCE2
+			"""))
+		reads = list(FastaReader(fasta))
+
+	def test_fastareader_keeplinebreaks(self):
+		with FastaReader("tests/data/simple.fasta", keep_linebreaks=True) as f:
+			reads = list(f)
+		assert reads[0] == simple_fasta[0]
+		assert reads[1].sequence == 'SEQUEN\nCE2'
+
+	def test_context_manager(self):
+		filename = "tests/data/simple.fasta"
+		with open(filename) as f:
+			assert not f.closed
+			reads = list(openseq(f))
+			assert not f.closed
+		assert f.closed
+
+		with FastaReader(filename) as sr:
+			tmp_sr = sr
+			assert not sr._file.closed
+			reads = list(sr)
+			assert not sr._file.closed
+		assert tmp_sr._file is None
+		# Open it a second time
+		with FastaReader(filename) as sr:
+			pass
+
+
+class TestFastqReader:
+	def test_fastqreader(self):
+		with FastqReader("tests/data/simple.fastq") as f:
+			reads = list(f)
+		assert reads == simple_fastq
+
+	def test_fastqreader_dos(self):
+		with FastqReader("tests/data/dos.fastq") as f:
+			dos_reads = list(f)
+		with FastqReader("tests/data/small.fastq") as f:
+			unix_reads = list(f)
+		assert dos_reads == unix_reads
+
+	@raises(FormatError)
+	def test_fastq_wrongformat(self):
+		with FastqReader("tests/data/withplus.fastq") as f:
+			reads = list(f)
+
+	@raises(FormatError)
+	def test_fastq_incomplete(self):
+		fastq = StringIO("@name\nACGT+\n")
+		with FastqReader(fastq) as fq:
+			list(fq)
+
+	def test_context_manager(self):
+		filename = "tests/data/simple.fastq"
+		with open(filename) as f:
+			assert not f.closed
+			reads = list(openseq(f))
+			assert not f.closed
+		assert f.closed
+
+		with FastqReader(filename) as sr:
+			tmp_sr = sr
+			assert not sr._file.closed
+			reads = list(sr)
+			assert not sr._file.closed
+		assert tmp_sr._file is None
+
+
+class TestFastaQualReader:
+	@raises(FormatError)
+	def test_mismatching_read_names(self):
+		fasta = StringIO(">name\nACG")
+		qual = StringIO(">nome\n3 5 7")
+		list(FastaQualReader(fasta, qual))
+
+	@raises(FormatError)
+	def test_invalid_quality_value(self):
+		fasta = StringIO(">name\nACG")
+		qual = StringIO(">name\n3 xx 7")
+		list(FastaQualReader(fasta, qual))
+
+
+class TestSeqioOpen:
+	def test_sequence_reader(self):
+		# test the autodetection
+		with openseq("tests/data/simple.fastq") as f:
+			reads = list(f)
+		assert reads == simple_fastq
+
+		with openseq("tests/data/simple.fasta") as f:
+			reads = list(f)
+		assert reads == simple_fasta
+
+		with open("tests/data/simple.fastq") as f:
+			reads = list(openseq(f))
+		assert reads == simple_fastq
+
+		# make the name attribute unavailable
+		f = StringIO(open("tests/data/simple.fastq").read())
+		reads = list(openseq(f))
+		assert reads == simple_fastq
+
+		f = StringIO(open("tests/data/simple.fasta").read())
+		reads = list(openseq(f))
+		assert reads == simple_fasta
+
+
+class TestInterleavedReader:
+	def test(self):
+		expected = [
+			(Sequence('read1/1 some text', 'TTATTTGTCTCCAGC', '##HHHHHHHHHHHHH'),
+			Sequence('read1/2 other text', 'GCTGGAGACAAATAA', 'HHHHHHHHHHHHHHH')),
+			(Sequence('read3/1', 'CCAACTTGATATTAATAACA', 'HHHHHHHHHHHHHHHHHHHH'),
+			Sequence('read3/2', 'TGTTATTAATATCAAGTTGG', '#HHHHHHHHHHHHHHHHHHH'))
+		]
+		reads = list(InterleavedSequenceReader("tests/cut/interleaved.fastq"))
+		for (r1, r2), (e1, e2) in zip(reads, expected):
+			print(r1, r2, e1, e2)
+
+		assert reads == expected
+		with openseq("tests/cut/interleaved.fastq", interleaved=True) as f:
+			reads = list(f)
+		assert reads == expected
+
+	@raises(FormatError)
+	def test_missing_partner(self):
+		s = StringIO('@r1\nACG\n+\nHHH')
+		list(InterleavedSequenceReader(s))
+
+	@raises(FormatError)
+	def test_incorrectly_paired(self):
+		s = StringIO('@r1/1\nACG\n+\nHHH\n at wrong_name\nTTT\n+\nHHH')
+		list(InterleavedSequenceReader(s))
+
+
+class TestFastaWriter:
+	def setup(self):
+		self._tmpdir = mkdtemp()
+		self.path = os.path.join(self._tmpdir, 'tmp.fasta')
+
+	def teardown(self):
+		shutil.rmtree(self._tmpdir)
+
+	def test(self):
+		with FastaWriter(self.path) as fw:
+			fw.write("name", "CCATA")
+			fw.write("name2", "HELLO")
+		assert fw._file.closed
+		with open(self.path) as t:
+			assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
+
+	def test_linelength(self):
+		with FastaWriter(self.path, line_length=3) as fw:
+			fw.write("r1", "ACG")
+			fw.write("r2", "CCAT")
+			fw.write("r3", "TACCAG")
+		assert fw._file.closed
+		with open(self.path) as t:
+			d = t.read()
+			assert d == '>r1\nACG\n>r2\nCCA\nT\n>r3\nTAC\nCAG\n'
+
+	def test_write_sequence_object(self):
+		with FastaWriter(self.path) as fw:
+			fw.write(Sequence("name", "CCATA"))
+			fw.write(Sequence("name2", "HELLO"))
+		assert fw._file.closed
+		with open(self.path) as t:
+			assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
+
+	def test_write_to_file_like_object(self):
+		sio = StringIO()
+		with FastaWriter(sio) as fw:
+			fw.write(Sequence("name", "CCATA"))
+			fw.write(Sequence("name2", "HELLO"))
+			assert sio.getvalue() == '>name\nCCATA\n>name2\nHELLO\n'
+		assert not fw._file.closed
+
+	def test_write_zero_length_sequence(self):
+		sio = StringIO()
+		with FastaWriter(sio) as fw:
+			fw.write(Sequence("name", ""))
+			assert sio.getvalue() == '>name\n\n', '{0!r}'.format(sio.getvalue())
+
+
+class TestFastqWriter:
+	def setup(self):
+		self._tmpdir = mkdtemp()
+		self.path = os.path.join(self._tmpdir, 'tmp.fastq')
+
+	def teardown(self):
+		shutil.rmtree(self._tmpdir)
+
+	def test(self):
+		with FastqWriter(self.path) as fq:
+			fq.writeseq("name", "CCATA", "!#!#!")
+			fq.writeseq("name2", "HELLO", "&&&!&&")
+		assert fq._file.closed
+		with open(self.path) as t:
+			assert t.read() == '@name\nCCATA\n+\n!#!#!\n at name2\nHELLO\n+\n&&&!&&\n'
+
+	def test_twoheaders(self):
+		with FastqWriter(self.path) as fq:
+			fq.write(Sequence("name", "CCATA", "!#!#!", name2="name"))
+			fq.write(Sequence("name2", "HELLO", "&&&!&", name2="name2"))
+		assert fq._file.closed
+		with open(self.path) as t:
+			assert t.read() == '@name\nCCATA\n+name\n!#!#!\n at name2\nHELLO\n+name2\n&&&!&\n'
+
+	def test_write_to_file_like_object(self):
+		sio = StringIO()
+		with FastqWriter(sio) as fq:
+			fq.writeseq("name", "CCATA", "!#!#!")
+			fq.writeseq("name2", "HELLO", "&&&!&&")
+		assert sio.getvalue() == '@name\nCCATA\n+\n!#!#!\n at name2\nHELLO\n+\n&&&!&&\n'
+
+
+class TestInterleavedWriter:
+	def test(self):
+		reads = [
+			(Sequence('A/1 comment', 'TTA', '##H'),
+			Sequence('A/2 comment', 'GCT', 'HH#')),
+			(Sequence('B/1', 'CC', 'HH'),
+			Sequence('B/2', 'TG', '#H'))
+		]
+		sio = StringIO()
+		with InterleavedSequenceWriter(sio) as writer:
+			for read1, read2 in reads:
+				writer.write(read1, read2)
+		assert sio.getvalue() == '@A/1 comment\nTTA\n+\n##H\n at A/2 comment\nGCT\n+\nHH#\n at B/1\nCC\n+\nHH\n at B/2\nTG\n+\n#H\n'

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



More information about the debian-med-commit mailing list