Hi,
Try this:
use strict;
use warnings;
my $s1 = 'ATGCCCGTAC'; ## Sequence 1
my $s2 = 'GCTTCCCAGCGC'; ## Sequence 2
print "Sequence 1 Translation:";
my $amino_acid = OneFrameTranslation ($s1); ## Calls subroutine
print "$amino_acid\n";
print "Sequence 2 Translation:";
$amino_acid = OneFrameTranslation ($s2); ## Calls subroutine
print "$amino_acid\n";
### Subroutine ###
sub OneFrameTranslation {
my ($seq) = shift;
my $amino_acid='';
my $seqarray='';
my %genetic_code = (
'TTT' => 'F', 'TTC' => 'F', 'TTA' => 'L', 'TTG' => 'L',
'CTT' => 'L', 'CTC' => 'L', 'CTA' => 'L', 'CTG' => 'L',
'ATT' => 'I', 'ATC' => 'I', 'ATA' => 'I', 'ATG' => 'M',
'GTT' => 'V', 'GTC' => 'V', 'GTA' => 'V', 'GTG' => 'V',
'TCT' => 'S', 'TCC' => 'S', 'TCA' => 'S', 'TCG' => 'S',
'CCT' => 'P', 'CCC' => 'P', 'CCA' => 'P', 'CCG' => 'P',
'ACT' => 'T', 'ACC' => 'T', 'ACA' => 'T', 'ACG' => 'T',
'GCT' => 'A', 'GCC' => 'A', 'GCA' => 'A', 'GCG' => 'A',
'TAT' => 'Y', 'TAC' => 'Y', 'TAA' => '*', 'TAG' => '*',
'CAT' => 'H', 'CAC' => 'H', 'CAA' => 'Q', 'CAG' => 'Q',
'AAT' => 'N', 'AAC' => 'N', 'AAA' => 'K', 'AAG' => 'K',
'GAT' => 'D', 'GAC' => 'D', 'GAA' => 'E', 'GAG' => 'E',
'TGT' => 'C', 'TGC' => 'C', 'TGA' => '*', 'TGG' => 'W',
'CGT' => 'R', 'CGC' => 'R', 'CGA' => 'R', 'CGG' => 'R',
'AGT' => 'S', 'AGC' => 'S', 'AGA' => 'R', 'AGG' => 'R',
'GGT' => 'G', 'GGC' => 'G', 'GGA' => 'G', 'GGG' => 'G'
);
## '---' = 3 character codon in hash above
## '-' = one letter amino acid abbreviation in hash above
my @seqarray = split(//,$seq); ## Explodes the string
for (my $i=0; $i<=$#seqarray-2; $i=$i+3) {
my $codon = substr($seq,$i,3);
$amino_acid .= $genetic_code{$codon};
}
return ($amino_acid);
}
The main errors in your code is that the
$seqarray is never initialized to anything (note that this is different from
@seqarray) and that you don't use the return values from your subroutines.
Update: haukex and toolic were faster than me. Also note I only made the minimal changes, you don't really need to create @seqarray, since you're not really using it (except in the $i<=$#seqarray-2 for loop termination clause where you could simply use the length of the sequence).