[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] More Simplification



> From: Vicki Brown [mailto:vlb@cfcl.com]
> Sent: Saturday, June 19, 1999 11:08
> To: fwp@technofile.org
> Subject: [FWP] More Simplification
> 
> Problem: Convert all characters not in the set [AaTtCcGg] to [Nn],
> preserving case
> 
> Solution A (presented to me)
> 
>        $seq =~ s/([^ACTGNactgn])/chr(ord(N) - (ord(uc($1)) -
ord($1)))/eg;
> 
> There were a few problems with this, not the least of which was that
> it didn't work under Perl 4.18 (and some of the code running around
> the place was still running under Perl 4!)
> 
> Solution B (mine)
> 
>          $seq =~ tr/[A-Zatcgn]/n/c;
>          $seq =~ tr/[a-zATCGN]/N/c;
> 
> 
> I thought this was reasonably elegant, especially because the solution
> came to me as I was heading up the on-ramp onto the freeway on the
> way home (good solutions are the ones you don't _need_ the 
> computer for)
> 
> Anyone have a nicer solution?

Here's the original solution, expressed in proper Perl 4:

$seq =~ s/([^ACTGNactgn])/pack('C', ord('N') - ord("\U$1") +
ord($1))/eg;

I have been using string-wise exclusive-or to solve this problem, but
that doesn't work in Perl 4, along with lots of other things!

The double-tr solution is undoubtedly *much* faster.

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com 

==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org