The regex won't be recompiled, just once, as the ``re`` module memoizes the
compilations


On Mon, Dec 2, 2013 at 3:00 PM, adamrp <notifications@github.com> wrote:

> In qiime/quality_filter_fasta.py:
>
> > +    if (window == 0):
> > +        return True
> > +    #initialize with sum of first window
> > +    window_score = sum(qual_scores[:window])
> > +    idx = 0
> > +    while (window_score/float(window) >= min_average
> > +           and idx < l-window):
> > +            #'Move' window
> > +            window_score += qual_scores[idx+window] - qual_scores[idx]
> > +            idx += 1
> > +    if (idx == l-window):
> > +        # we processed all qual_scores, must be good
> > +        # Return index for truncation purposes
> > +        return False, idx
> > +    else:
> > +        return True, idx
>
> The code below should work. However the regex will be recompiled every
> time the function is called, which could lead to considerable overhead
> since this is a function that will be called lots and lots of times. For
> that reason, it might actually be better to define this function in a
> non-global scope (i.e., define it closer to where it is used; see my
> comment on line 906).
>
> from re import search
> def seq_exceeds_homopolymers(curr_seq, max_len=6):
>     if search('A{max_len+1} | T{max_len+1} | G{max_len+1} | C{max_len+1}', curr_seq):
>         return True
>
>     return False
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/qiime/qiime/pull/1214/files#r8041888>
> .
>