[Bioperl-l] tr/// and eval
Heikki Lehvaslaiho
heikki@ebi.ac.uk
10 Oct 2002 14:59:06 +0100
Pat,
The following script is a bit more "perlish" way of doing it.
-Heikki
#!/usr/bin/perl
use strict;
my $ecoli="GAAGTCGTAACAAGGTAACCGTAGGGGAACCT";
my $offset = 0;
my %res;
while ($offset < length($ecoli)) {
my $n = uc substr($ecoli, $offset, 1);
$res{$n}++;
$offset++;
}
On Thu, 2002-10-10 at 13:33, Pat Schloss wrote:
> 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";
>
>
>
>
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
--
______ _/ _/_____________________________________________________
_/ _/ http://www.ebi.ac.uk/mutations/
_/ _/ _/ Heikki Lehvaslaiho heikki@ebi.ac.uk
_/_/_/_/_/ EMBL Outstation, European Bioinformatics Institute
_/ _/ _/ Wellcome Trust Genome Campus, Hinxton
_/ _/ _/ Cambs. CB10 1SD, United Kingdom
_/ Phone: +44 (0)1223 494 644 FAX: +44 (0)1223 494 468
___ _/_/_/_/_/________________________________________________________