I have a subroutine for a basic one frame translation that is giving me an error for "Use of uninitialized value $codon in hash element" and "substr outside of string". I think my problem is I need to modify the subroutine's for loop to account for nucleotide sequences with odd numbers of acids (i.e. not in multiples of 3).
Does anyone have suggestions for how to modify the code properly?
Here is the subroutine I'm using in a simple example:
use strict;
use warnings;
my $amino_acid='';
my $s1 = 'ATGCCCGTAC'; ## Sequence 1
my $s2 = 'GCTTCCCAGCGC'; ## Sequence 2
print "Sequence 1 Translation:";
OneFrameTranslation ($s1); ## Calls subroutine
print "$amino_acid\n";
print "Sequence 2 Translation:";
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($seqarray,$i,3);
$amino_acid = $genetic_code{$codon};
}
return ($amino_acid);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.