[Bioperl-l] tr/// and eval

Pat Schloss pds@plantpath.wisc.edu
10 Oct 2002 07:33:40 -0500


Hi all, 

I'm trying to write a program with the simple task of counting the
number of A's, T's, G's, and C's (and binary combinations of those
letters, i.e. AA, AG, AC...) in a DNA sequence string.  I'm still in the
process of trying to gain some level of proficiency with perl so I'd
rather not use a module at this point.  Hopefully someone can help with
my problem. 

What I'd like to do pretty much expressed in the code below.  The
problem I'm having is that when I do the tr/// I'm trying to interpolate
into the search a different letter of my modified alphabet.  When I
looked at Programming Perl, it says you have to use the eval function to
interpolate a search variable.  Wall, et al. show how to do it if the
string being used is $_, but not if the string is some other variable,
$ecoli in my case.  The $_ value I'm using is the different values of my
alphabet.  So, I'm not sure where to put the "eval" or if what I'm doing
is possible (sure it is!).  I've moved the eval around but can't get
anything to work.  Help!? 

Pat 

#!/usr/bin/perl 
$ecoli=GAAGTCGTAACAAGGTAACCGTAGGGGAACCT"; 

my @alphabet=qw* A T G C*; 

foreach (@alphabet) { 
${$_} = ($ecoli=~ tr/$_//); 
print "$_, ${$_}\n"; 
} 

print "a= $A, t= $T, g=$G, c=$C\n";