Seek troubleshooting help. This is homework. My professor recommends using forums. I have no experience with Perl functions or Subs, so please limit the answers to the appropriate level so that I can understand.
The purpose of the script is to read the DNA string (or a file from the command line, which I will add later), translate it into RNA, and then return the protein value in the form of uppercase single-letter amino acid names.
Script function:
Take 3 βcodonβ characters from the first character and give them one character. Symbol (uppercase single-letter amino acid name from the hash table)
Printing RNA proteins, which are lines starting with AUG ("M") and ending with UAG, UAA or UGA.
If a space occurs, a new line begins and the process repeats. We can assume that spaces are multiples of triples.
The main problems, as far as I can tell:
I do not know where the data cycle through the hash table will go. I tried to place it before and after my Foreach block. I also completely blocked the Foreach block and tried While and If.
The Foreach block does not seem to process the entire @all_codons array and stops only on AUG.
The obvious and biggest problem is that it returns nothing. Somewhere along the way, the value of $ next_codon is set to false. I tried to comment on each line in parts - the last line in which something was returned was My $ start and from there everything is false.
script:
$^W = 1;
use strict;
my $dna_string = "CCCCAAATGCTGGGATTACAGGCGTGAGCCACCACGCCCGGCCACTTGGCATGAATTTAATTCCCGCCATAAACCTGTGAGATAGGTAATTCTGTTATATCCACTTTACAAATGAAGAGACTGAGGCAAAGAAAGATGATGTAACTTACGCAAAGC";
my %codon_codes = (
"UUU" => "f", "UUC" => "f", "UUA" => "l", "UUG" => "l",
"CUU" => "l", "CUC" => "l", "CUA" => "l", "CUG" => "l",
"AUU" => "i", "AUC" => "i", "AUA" => "i", "AUG" => "m",
"GUU" => "v", "GUC" => "v", "GUA" => "v", "GUG" => "v",
"UCU" => "s", "UCC" => "s", "UCA" => "s", "UCG" => "s",
"CCU" => "p", "CCC" => "p", "CCA" => "p", "CCG" => "p",
"ACU" => "t", "ACC" => "t", "ACA" => "t", "ACG" => "t",
"GCU" => "a", "GCC" => "a", "GCA" => "a", "GCG" => "a",
"UAU" => "y", "UAC" => "y", "UAA" => " ", "UAG" => " ",
"CAU" => "h", "CAC" => "h", "CAA" => "q", "CAG" => "q",
"AAU" => "n", "AAC" => "n", "AAA" => "k", "AAG" => "k"
);
my $rna_string = $dna_string;
$rna_string =~ tr/[tT]/U/;
my @all_codons = ($rna_string =~ m/.../g);
foreach my $next_codon(@all_codons){
while ($next_codon =~ /AUG/gi){
my $start = pos ($next_codon) -3;
last unless $next_codon =~ /U(AA|GA|AG)/gi;
my $stop = pos($next_codon);
my $genelen = $stop - $start;
my $gene = substr ($next_codon, $start, $genelen);
print "\n" . join($start+1, $stop, $gene,) . "\n";
}
}