import sys
import gzip
from collections import namedtuple
try:
    from bz2 import BZ2File
except ImportError, err:
    BZ2File = lambda x, *args, **kwargs: sys.exit(err)


Seq = namedtuple('Seq', 'id, description, seq')


class Opener(object):
    """Factory for creating file objects. Transparenty opens compressed
    files for reading or writing based on suffix (.gz and .bz2 only).

    Example::

        with Opener()('in.txt') as infile, Opener('w')('out.gz') as outfile:
            outfile.write(infile.read())
    """

    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.writable = 'w' in kwargs.get('mode', args[0] if args else 'r')

    def __call__(self, obj):
        if obj is sys.stdout or obj is sys.stdin:
            return obj
        elif obj == '-':
            return sys.stdout if self.writable else sys.stdin
        else:
            __, suffix = obj.rsplit('.', 1)
            opener = {'bz2': BZ2File,
                      'gz': gzip.open}.get(suffix, open)
            return opener(obj, *self.args, **self.kwargs)


def fastalite(handle):
    """Return a sequence of namedtuple objects with attributes (id,
    description, seq) given open file-like object ``handle``

    """

    header, seq = '', []
    for line in handle:
        if line.startswith('>'):
            if header:
                yield Seq(header.split()[0], header, ''.join(seq))
            header, seq = line[1:].strip(), []
        else:
            seq.append(line.strip())

    if header and seq:
        yield Seq(header.split()[0], header, ''.join(seq))

@@ -170,58 +170,8 @@
 )%0A%0A%0A
-Seq = namedtuple('Seq', 'id, description, seq')%0A%0A%0A
 clas
@@ -1117,20 +1117,42 @@
 objects 
-with
+from a fasta file with%0A   
  attribu
@@ -1159,20 +1159,16 @@
 tes (id,
-%0A   
  descrip
@@ -1205,16 +1205,20 @@
 e object
+%0A   
  %60%60handl
@@ -1227,24 +1227,83 @@
 %60%0A%0A    %22%22%22%0A%0A
+    Seq = namedtuple('Seq', %5B'id', 'description', 'seq'%5D)%0A%0A
     header, 
@@ -1623,28 +1623,1180 @@
 )%5B0%5D, header, ''.join(seq))%0A
+%0A%0Adef fastqlite(handle):%0A    %22%22%22Return a sequence of namedtuple objects from a fastq file with%0A    attributes (id, description, seq, qual) given open file-like%0A    object %60%60handle%60%60. This parser assumes that lines corresponding to%0A    sequences and quality scores are not wrapped.%0A%0A    See https://doi.org/10.1093/nar/gkp1137 for a discussion of the%0A    fastq format.%0A%0A    %22%22%22%0A%0A    Seq = namedtuple('Seq', %5B'id', 'description', 'seq', 'qual'%5D)%0A%0A    header, seq, qual, in_seq = '', %5B%5D, %5B%5D, True%0A    for line in handle:%0A        if line.startswith('@'):%0A            if header and qual:%0A                yield Seq(header.split()%5B0%5D, header, ''.join(seq), ''.join(qual))%0A            header, seq, qual, in_seq = line%5B1:%5D.strip(), %5B%5D, %5B%5D, True%0A        elif line.startswith('+'):%0A            in_seq = False%0A        elif in_seq:%0A            seq.append(line.strip())%0A        else:%0A            qual.append(line.strip())%0A%0A    if header and qual:%0A        yield Seq(header.split()%5B0%5D, header, ''.join(seq), ''.join(qual))%0A%0A%0Aif __name__ == '__main__':%0A    with open('testfiles/276-11_S1_L001_R1_001.fastq') as f:%0A        for seq in fastqlite(f):%0A            print seq%0A

implement first (flawed) version of fastqlite