[Purdue-pm] RADpools

Rick Westerman westerman at purdue.edu
Wed Oct 20 06:02:05 PDT 2010


On 10/20/2010 08:59 AM, Rick Westerman wrote:
>
>> The code in question (with extra comments):
>>
>>     for my $i ( 1 .. $mid_length ) {
>>         for my $base (qw{A C G T}) {
>>             my $fuzzycode  = $mid;
>>             my $prebase_i  = $i - 1;
>>             my $postbase_i = $mid_length - $i;
>>             $fuzzycode =~ s{
>>              ^([ACGT]{$prebase_i})     #capture bases, if any, before
>>     current base
>>               ([ACGT])                 #current base
>>               ([ACGT]{$postbase_i})$}  #capture bases, if any, after
>>     current base
>>             {$1$base$3}xms;            #replace current base with $base
>>             push @{ $mid_pools{$fuzzycode} }, $pool_name;
>>         }
>>     }
>>
>> Actually, I don't see any problem with this code.
>
> Readability is the issue.   IMHO, the author is using a sledgehammer 
> when a peen hammer would do.  Speedups are not the issue.  The 
> following is much more clear ... especially to the the novice Perl 
> programmer who is not that familiar with regexes.
>
>
> for my $i ( 0 .. $mid_length - 1) {
>     for my $base (qw{A C G T}) {
>         my $fuzzycode = $mid;
>         substr($fuzzycode, $i, 1, $base);
>         push @{ $mid_pools{$fuzzycode} }, $pool_name;
>         print "$fuzzycode\n";
>     }
> }
>
>
> Explaining substr should be a piece of cake compared to regex captures 
> and replacements.

And, I hope this is obvious, the extra print statement is my code above 
was just for verification purposes so that I could make sure that my 
code did the same as the original regex code.  If my code fragment was 
to be put in the RADpools code then the print statement would, of 
course, be removed.

-- 
Rick Westerman westerman at purdue.edu Bioinformatics specialist at the 
Genomics Facility. Phone: (765) 494-0505 FAX: (765) 496-7255 Department 
of Horticulture and Landscape Architecture 625 Agriculture Mall Drive 
West Lafayette, IN 47907-2010 Physically located in room S049, WSLR 
building
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/purdue-pm/attachments/20101020/5d4a0e6f/attachment.html>


More information about the Purdue-pm mailing list