in reply to MOLECULAR WEIGHT SUM
Hi mgbioinfo,
Have you printed out your variables at various points during the script to see that they contain what you think? Like:
#!/usr/bin/perl -w use strict; use Data::Dumper; ... while ( my $line = <STDIN> ) { # No need to declare $line until here. my @AA = $line; # No need to declare @AA until here. # Might need to split the line, though +... print Dumper \@AA; # See what's really in that array. Note the bac +kslash. ...
Later, in your loop, you pull an element from your array, but when you try to use it as the hash key, your syntax is wrong. Change:
To this:foreach $AA(@AA) { #I want now the sum of protein's molecular weight. $sum += $MWs{ "$AA(@AA)" }; # ^^ # incorrect syntax }
# Sum the proteins' molecular weights. my $sum; # no need to declare $sum until here. # Also no need to initialize to zero; Perl will do that when + you add to it. foreach my $AA ( @AA ) { print "AA: $AA Weight: $MWs{ $AA }\n"; $sum += $MWs{ $AA }; }
Hope this helps!
|
|---|