def filter(self):
        for name, comment, seq, qual in self.parent.filter():
            trimmed = False

            upseq = seq.upper()
            best_match = 0
            best_i = -1

            for i in xrange(self.min_filter_len, len(seq)+1):
                matches = 0.0
                total = 0
                for s, a in zip(upseq[-i:], self.trim_seq):
                    total += 1
                    if s == a or a == 'N':
                        matches += 1

                if ((matches / total) >= self.mismatch_pct) and matches >= best_match:
                    best_match = matches
                    best_i = i
                elif best_match:
                    break

            if best_match:
                orig_seq = seq
                i = best_i

                # since we are now trimming from the 3' end, we can
                # safely ignore if this is a color-space file with a
                # prefix base

                seq = seq[:-i]
                qual = qual[:-i]

                if len(qual) == 0:
                    self.removed += 1
                    if self.discard:
                        self.discard(name)
                    if self.verbose:
                        sys.stderr.write('[Trim] %s (removed) seq:%s clipped at:%s (%s/%s)-> %s\n' % (name, orig_seq, i, matches, total, seq[:i]))
                else:
                    self.altered += 1
                    if self.verbose:
                        sys.stderr.write('[Trim] %s (altered) seq:%s clipped at:%s (%s/%s)-> %s\n' % (name, orig_seq, i, matches, total, seq[:i]))

                    yield((name, '%s #trim' % comment, seq, qual))

            else:
                self.kept += 1
                if self.verbose:
                    sys.stderr.write('[Trim] %s (kept)\n' % name)
                yield (name, comment, seq, qual)
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/fastq/filter.py/TrimFilter.filter/original