FIJI42 has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Translation Substring Error (updated)
by haukex (Archbishop) on Nov 09, 2017 at 15:47 UTC | |
by FIJI42 (Acolyte) on Nov 09, 2017 at 16:12 UTC | |
by haukex (Archbishop) on Nov 09, 2017 at 16:18 UTC | |
by haukex (Archbishop) on Nov 09, 2017 at 16:36 UTC | |
Re: Translation Substring Error
by toolic (Bishop) on Nov 09, 2017 at 15:49 UTC | |
by FIJI42 (Acolyte) on Nov 09, 2017 at 16:06 UTC | |
by Laurent_R (Canon) on Nov 09, 2017 at 16:12 UTC | |
Re: Translation Substring Error
by Laurent_R (Canon) on Nov 09, 2017 at 16:01 UTC | |
by FIJI42 (Acolyte) on Nov 09, 2017 at 16:08 UTC | |
Re: Translation Substring Error
by kcott (Archbishop) on Nov 11, 2017 at 07:52 UTC | |
Re: Translation Substring Error
by johngg (Canon) on Nov 09, 2017 at 23:10 UTC | |
Re: Translation Substring Error
by Ultimatt (Acolyte) on Nov 14, 2017 at 13:53 UTC |
Back to
Seekers of Perl Wisdom