[Purdue-pm] RADpools
Rick Westerman
westerman at purdue.edu
Wed Oct 20 05:59:27 PDT 2010
> 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.
--
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/3d04eeb5/attachment.html>
More information about the Purdue-pm
mailing list