def fastq_stats(fastq, quiet=False):
    lengths = []    # how many reads are exactly this length?
    posquals = []   # accumulator of quality values for each position
                    # (not all the values, but an accumulator for each value at each position)
    qualities = []  # quality accumulator for each position

    total = []  # how many reads are at least this length?
                # (used for dividing an accumulator later)

    total_reads = 0
    line = 0
    try:
        for read in fastq.fetch(quiet=quiet):
            # Note: all lengths are based on the FASTQ quality score, which
            # will be the correct length for base- and color-space files. The
            # sequence may have a prefix in color-space files

            line += 4
            total_reads += 1

            while len(total) <= len(read.qual):
                total.append(0)

            for x in xrange(len(read.qual)):
                total[x + 1] += 1

            while len(lengths) <= len(read.qual):
                lengths.append(0)
                qualities.append(0)
                posquals.append([])

            lengths[len(read.qual)] += 1

            for idx, q in enumerate([ord(x) - 33 for x in read.qual]):
                if q < 0:
                    q = 0
                qualities[idx + 1] += q
                while len(posquals[idx + 1]) <= q:
                    posquals[idx + 1].append(0)
                posquals[idx + 1][q] += 1

    except __HOLE__:
        pass

    return FASTQStats._make([fastq, total_reads, total, lengths, qualities, posquals])
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/fastq/stats.py/fastq_stats