gpt4 book ai didi

perl - 使用 perl 脚本编辑帮助以在数组中的特定位置开始和停止

转载 作者:行者123 更新时间:2023-12-02 00:37:12 25 4
gpt4 key购买 nike

寻求故障排除和编辑方面的帮助。这是家庭作业。我的教授鼓励使用论坛。我还没有使用 Perl Functions 或 Subs 的经验,所以请将回复限制在适当的级别,以便我能够理解。

该脚本的目的是读取一串DNA(或命令行文件,我稍后会添加),将其翻译成RNA,然后以大写单字母氨基的形式返回蛋白质的值酸名。

脚本的作用:

  1. Take 3 character "codons" from the first character and give them a single letter Symbol (an uppercase one-letter amino acid name from the hash table)

  2. Print RNA Proteins which are strings that start with the AUG ("M") and ends with UAG, UAA or UGA.

  3. If a gap is encountered a new line is started and process is repeated. We can assume that gaps are multiples of threes.

据我所知主要问题:

  1. I don't know where to have the data loop through the hash table. I've tried placing it before and after my Foreach block. I've also taken the Foreach block out altogether and tried While & If.

  2. The Foreach block doesn't seem to be processing all of the @all_codons array and only stopping at AUG.

  3. The obvious and biggest problem is that it's returning nothing. Somewhere along the way the $next_codon value is being assigned "false". I've tried commenting each line out piece by piece - last line that returned anything was My $start and from there on it's all false.

脚本:

$^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";
}
}

最佳答案

我不明白“通过哈希表进行数据循环”部分。

在我看来,对于每个密码子,您需要检查它是起始密码子、终止密码子、缺口还是氨基酸。你需要一些方法来保持状态(下面是 $in_gene)。

my $in_gene = 0;

foreach my $next_codon(@all_codons){
if ($next_codon eq 'AUG') {
$in_gene = 1;
}
elsif ($next_codon =~ m/U(AA|GA|AG)/) {
$in_gene = 0;
}
elsif ($in_gene == 1) {
my $aminoacid = $codon_codes{$next_codon};
print "\n" and next unless defined $aminoacid;
print $aminoacid;
}
}

这打印

l
lqak
l
q
k

关于perl - 使用 perl 脚本编辑帮助以在数组中的特定位置开始和停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com