大量“在替换迭代器中使用%genetic_code中未初始化的值”

时间:2017-10-13 23:34:30

标签: perl

我想将DNA或RNA的序列翻译成蛋白质,但是在运行之后,我有大量的“在translateRNAToProtein.pl第95行第1行的替换迭代器中使用%genetic_code中未初始化的值”。警告。我仔细检查了翻译表,没有错误。我的代码如下:

use strict;
use warnings;
use feature qw(say);

translation (my $sequence);
my %genetic_code = (
    UCA => 'S',
UCC => 'S',
UCG => 'S',
UCU => 'S',
UUC => 'F',
UUU => 'F',
UUA => 'L',
UUG => 'L',
UAC => 'Y',
UAU => 'Y',
UAA => '_',
UAG => '_',
UGC => 'C',
UGU => 'C',
UGA => '_',
UGG => 'W',
CUA => 'L',
CUC => 'L',
CUG => 'L',
CUU => 'L',
CCA => 'P',
CCC => 'P',
CCG => 'P',
CCU => 'P',
CAC => 'H',
CAU => 'H',
CAA => 'Q',
CAG => 'Q',
CGA => 'R',
CGC => 'R',
CGG => 'R',
CGU => 'R',
AUA => 'I',
AUC => 'I',
AUU => 'I',
AUG => 'M',
ACA => 'U',
ACC => 'U',
ACG => 'U',
ACU => 'U',
AAC => 'N',
AAU => 'N',
AAA => 'K',
AAG => 'K',
AGC => 'S',
AGU => 'S',
AGA => 'R',
AGG => 'R',
GUA => 'V',
GUC => 'V',
GUG => 'V',
GUU => 'V',
GCA => 'A',
GCC => 'A',
GCG => 'A',
GCU => 'A',
GAC => 'D',
GAU => 'D',
GAA => 'E',
GAG => 'E',
GGA => 'G',
GGC => 'G',
GGG => 'G',
GGU => 'G',
);

sub translation {
    say "enter a RNA or DNA sequence: ";
    my $sequence = <STDIN>;
    chomp $sequence;
    $sequence = uc ($sequence);
    if ($sequence =~ /T/){
        $sequence =~ tr/ATGC/UACG/;
    }

    say "\nThe result of translation is:\n\n";  
    foreach ($a = 0; $a < 3; $a++) {
        my $main_seq = substr($sequence, $a);
        if ($main_seq =~ /(AUG(...)*(UAG|UGA|UAA))/){
            $main_seq = $1;

            $main_seq =~ s/(...)/$genetic_code{$1}/g;       #Here is the warning place
            say "$main_seq\n";
        }

        else {
            say "No start or stop codon!"
        }

    }
}

其他部分工作正常。例如,当我输入669 bp的DNA时:

TACATCCACCACACCATTTCCGCCAATGAAATTTGCATGCAAATCAATCCAGGTTCTTCAAACTGTATGCCCAGTCAACCCAGTCATGCAACACTGACCATTGAATCCATCAATTCAGAAACAGACGAAAGGACCAAGACACGGTTTCGCTGCAGGTTTGAAGGGTGCAAACGAACTTACAGCTCTGCTGGAAACTTGAAAGCACACACTAAAAGTCACACAGGGGAGTATACATTTAAATGTACTGAAGAAGAATGTGGGAAGGCATTTCTCAACTCCCACAGCCTAAAGATTCATGTCAGAGTACACACCAAAGATCGTCCCTATGGCTGTGACATTGGGGGATGTGACAAGAACTTCAACACACTCTACCGATTGAAAGCTCATCAGAGGGTACACAACGGCACCACCTTTAAATGTGAACAATCTGGATGTGTGAAATTCTTCACCACCCTCAGTGACTTACGGAAACACGAACGTGTCCATTCGGGAGACCGGCCATTCAAATGCGAGCACGAAGATTGCAACAAGTCATTTCGCAATAGCCATCATCTGAAATCGCACATGTTATCTCATACGGGTGAACGACCCTACACATGCAGTGATTCTGCATGTGGACGAACCTTCGCCAAGCGTAATTCGTGGAAGTTGCATCTATTGAAGCATGAA

它可以正确识别它,将其转换为RNA并找到从起始密码子到终止密码子的序列:

AUGUAGGUGGUGUGGUAAAGGCGGUUACUUUAAACGUACGUUUAGUUAGGUCCAAGAAGUUUGACAUACGGGUCAGUUGGGUCAGUACGUUGUGACUGGUAACUUAGGUAGUUAAGUCUUUGUCUGCUUUCCUGGUUCUGUGCCAAAGCGACGUCCAAACUUCCCACGUUUGCUUGAAUGUCGAGACGACCUUUGAACUUUCGUGUGUGAUUUUCAGUGUGUCCCCUCAUAUGUAAAUUUACAUGACUUCUUCUUACACCCUUCCGUAAAGAGUUGAGGGUGUCGGAUUUCUAAGUACAGUCUCAUGUGUGGUUUCUAGCAGGGAUACCGACACUGUAA
AUGUCGAGACGACCUUUGAACUUUCGUGUGUGAUUUUCAGUGUGUCCCCUCAUAUGUAAAUUUACAUGACUUCUUCUUACACCCUUCCGUAAAGAGUUGAGGGUGUCGGAUUUCUAAGUACAGUCUCAUGUGUGGUUUCUAGCAGGGAUACCGACACUGUAA
AUGUCGAGACGACCUUUGAACUUUCGUGUGUGAUUUUCAGUGUGUCCCCUCAUAUGUAAAUUUACAUGACUUCUUCUUACACCCUUCCGUAAAGAGUUGAGGGUGUCGGAUUUCUAAGUACAGUCUCAUGUGUGGUUUCUAGCAGGGAUACCGACACUGUAA

然而,当我尝试使用短序列“uacauguauuaacag”来测试此代码时, 它返回“UACAUGUAUUAACAG”,“AUGUAUUAA”(我添加额外的代码打印出来并得到我的预期)和上面显示的三个警告。很明显,这不是翻译表的错误。任何建议表示赞赏!

1 个答案:

答案 0 :(得分:4)

问题似乎是您在定义translation()之前调用了%genetic_code。只需将translation(my $sequence);移至%genetic_code(和&translation)定义之后,即可解决问题。当然,您也应该删除未使用和未初始化的参数。因此,来自:

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw(say);

my %genetic_code = (
    UCA => 'S', UCC => 'S', UCG => 'S', UCU => 'S',
    UUC => 'F', UUU => 'F', UUA => 'L', UUG => 'L',
    UAC => 'Y', UAU => 'Y', UAA => '_', UAG => '_',
    UGC => 'C', UGU => 'C', UGA => '_', UGG => 'W',
    CUA => 'L', CUC => 'L', CUG => 'L', CUU => 'L',
    CCA => 'P', CCC => 'P', CCG => 'P', CCU => 'P',
    CAC => 'H', CAU => 'H', CAA => 'Q', CAG => 'Q',
    CGA => 'R', CGC => 'R', CGG => 'R', CGU => 'R',
    AUA => 'I', AUC => 'I', AUU => 'I', AUG => 'M',
    ACA => 'U', ACC => 'U', ACG => 'U', ACU => 'U',
    AAC => 'N', AAU => 'N', AAA => 'K', AAG => 'K',
    AGC => 'S', AGU => 'S', AGA => 'R', AGG => 'R',
    GUA => 'V', GUC => 'V', GUG => 'V', GUU => 'V',
    GCA => 'A', GCC => 'A', GCG => 'A', GCU => 'A',
    GAC => 'D', GAU => 'D', GAA => 'E', GAG => 'E',
    GGA => 'G', GGC => 'G', GGG => 'G', GGU => 'G',
);

sub translation {
    say "enter a RNA or DNA sequence: ";
    my $sequence = <STDIN>;
    chomp $sequence;
    $sequence = uc ($sequence);
    if ($sequence =~ /T/){
        $sequence =~ tr/ATGC/UACG/;
    }

    say "\nThe result of translation is:\n\n";  
    foreach ($a = 0; $a < 3; $a++) {
        my $main_seq = substr($sequence, $a);
        if ($main_seq =~ /(AUG(...)*(UAG|UGA|UAA))/){
            $main_seq = $1;
            $main_seq =~ s/(...)/$genetic_code{$1}/g;
            say "$main_seq\n";
        }
        else {
            say "No start or stop codon!"
        }
    }
}

translation();

将第一行数据作为输入,输出为:

enter a RNA or DNA sequence: 

The result of translation is:


M_VVW_RRLL_UYV_LGPRSLUYGSVGSVRCDW_LR_LSLCLLSWFCAKAUSKLPUFA_MSRRPLNFRV_FSVCPLICKFU_LLLUPFRKELRVSDF_VQSHVWFLAGIPUL_

MSRRPLNFRV_FSVCPLICKFU_LLLUPFRKELRVSDF_VQSHVWFLAGIPUL_

MSRRPLNFRV_FSVCPLICKFU_LLLUPFRKELRVSDF_VQSHVWFLAGIPUL_

绝对没有关于未初始化值的警告。