- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
寻找有关如何处理我的 Perl 编程作业以编写 RNA 合成程序的建议。我总结并概述了下面的程序。具体来说,我正在寻找对以下 block 的反馈(我将编号以方便引用)。我已经阅读了 Andrew Johnson 的 Elements of Programming with Perl (好书)的第 6 章。我还阅读了 perlfunc 和 perlop pod-pages,没有任何关于从哪里开始的内容。
程序说明:程序应从命令行读取输入文件,将其翻译成 RNA,然后将 RNA 转录成大写的单字母氨基酸名称序列。
接受以命令行命名的文件
here I will use the <> operator
检查以确保文件仅包含 acgt 或 die
if ( <> ne [acgt] ) { die "usage: file must only contain nucleotides \n"; }
将DNA转录成RNA(每个A被U替换,T被A替换,C被G替换,G被C替换)
not sure how to do this
将此转录本并从“AUG”的第一次出现开始将其分解为 3 个字符“密码子”
not sure but I'm thinking this is where I will start a %hash variables?
取 3 个字符“密码子”并给它们一个单字母符号(大写的单字母氨基酸名称)
Assign a key a value using (there are 70 possibilities here so I'm not sure where to store or how to access)
如果遇到间隙,则开始新行并重复处理
not sure but we can assume that gaps are multiples of threes.
我的方法是否正确?是否有一个我忽略的 Perl 函数可以简化主程序?
必须是独立程序(密码子名称和符号的存储值)。
当程序读取一个没有符号的密码子时,这是 RNA 中的一个缺口,它应该开始一个新的输出行,并从下一次出现的“AUG”开始。为简单起见,我们可以假设间隙总是三的倍数。
在我花任何额外的时间进行研究之前,我希望得到确认,我正在采取正确的方法。感谢您花时间阅读并分享您的专业知识!
最佳答案
1. here I will use the <> operator
好的,您的计划是逐行读取文件。不要忘记 chomp
每一行,否则你的序列中会出现换行符。
2. Check to make sure the file only contains acgt or die
if ( <> ne [acgt] ) { die "usage: file must only contain nucleotides \n"; }
在 while 循环中,<>
运算符将读取的行放入特殊变量 $_
,除非您明确指定它( my $line = <>
)。
在上面的代码中,您正在从文件中读取一行并将其丢弃。您需要保存该行。
另外,ne
运算符比较两个字符串,而不是一个字符串和一个正则表达式。您需要 !~
此处的运算符(或 =~
之一,具有否定字符类 [^acgt]
。如果您需要不区分大小写的测试,请查看 i
标志以进行正则表达式匹配。
3. Transcribe the DNA to RNA (Every A replaced by U, T replaced by A, C replaced by G, G replaced by C).
正如 GWW 所说,检查你的生物学。 T->U 是转录的唯一步骤。您会找到 tr
(音译)运算符在这里很有帮助。
4. Take this transcription & break it into 3 character 'codons' starting at the first occurance of "AUG"
not sure but I'm thinking this is where I will start a %hash variables?
我会在这里使用缓冲区。在 while(<>)
之外定义一个标量环形。使用index
匹配“AUG”。如果你没有找到它,把最后两个基放在那个标量上(你可以使用substr $line, -2, 2
)。在循环的下一次迭代中(使用 .=
)将行添加到这两个基础,然后 then 再次测试“AUG”。如果你成功了,你会知道在哪里,所以你可以标记地点并开始翻译。
5. Take the 3 character "codons" and give them a single letter Symbol (an uppercase one-letter amino acid name)
Assign a key a value using (there are 70 possibilities here so I'm not sure where to store or how to access)
再次,正如 GWW 所说,建立一个哈希表:
%codons = ( AUG => 'M', ...)
.
然后您可以使用(例如)split
构建您正在检查的当前行的数组,一次构建三个元素的密码子,并从哈希表中获取正确的氨基酸代码。
6.If a gap is encountered a new line is started and process is repeated
not sure but we can assume that gaps are multiples of threes.
见上文。您可以使用 exists $codons{$current_codon}
测试是否存在间隙。 .
7. Am I approaching this the right way? Is there a Perl function that I'm overlooking that can simplify the main program?
你知道,看看上面的内容,它似乎太复杂了。我 build 了一些积木;子程序 read_codon
和 translate
: 我认为它们极大地帮助了程序的逻辑。
我知道这是一项家庭作业,但我认为它可能会帮助您了解其他可能的方法:
use warnings; use strict;
use feature 'state';
# read_codon works by using the new [state][1] feature in Perl 5.10
# both @buffer and $handle represent 'state' on this function:
# Both permits abstracting reading codons from processing the file
# line-by-line.
# Once read_colon is called for the first time, both are initialized.
# Since $handle is a state variable, the current file handle position
# is never reset. Similarly, @buffer always holds whatever was left
# from the previous call.
# The base case is that @buffer contains less than 3bp, in which case
# we need to read a new line, remove the "\n" character,
# split it and push the resulting list to the end of the @buffer.
# If we encounter EOF on the $handle, then we have exhausted the file,
# and the @buffer as well, so we 'return' undef.
# otherwise we pick the first 3bp of the @buffer, join them into a string,
# transcribe it and return it.
sub read_codon {
my ($file) = @_;
state @buffer;
open state $handle, '<', $file or die $!;
if (@buffer < 3) {
my $new_line = scalar <$handle> or return;
chomp $new_line;
push @buffer, split //, $new_line;
}
return transcribe(
join '',
shift @buffer,
shift @buffer,
shift @buffer
);
}
sub transcribe {
my ($codon) = @_;
$codon =~ tr/T/U/;
return $codon;
}
# translate works by using the new [state][1] feature in Perl 5.10
# the $TRANSLATE state is initialized to 0
# as codons are passed to it,
# the sub updates the state according to start and stop codons.
# Since $TRANSLATE is a state variable, it is only initialized once,
# (the first time the sub is called)
# If the current state is 'translating',
# then the sub returns the appropriate amino-acid from the %codes table, if any.
# Thus this provides a logical way to the caller of this sub to determine whether
# it should print an amino-acid or not: if not, the sub will return undef.
# %codes could also be a state variable, but since it is not actually a 'state',
# it is initialized once, in a code block visible form the sub,
# but separate from the rest of the program, since it is 'private' to the sub
{
our %codes = (
AUG => 'M',
...
);
sub translate {
my ($codon) = @_ or return;
state $TRANSLATE = 0;
$TRANSLATE = 1 if $codon =~ m/AUG/i;
$TRANSLATE = 0 if $codon =~ m/U(AA|GA|AG)/i;
return $codes{$codon} if $TRANSLATE;
}
}
关于模拟 RNA 合成的 Perl 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4112003/
如果我的 Perl 程序使用 Perl 模块,它将如何确定在哪里可以找到包含模块代码的文件? 例如,如果程序包含: use MyModule1; # Example 1 us
我在一个文件中有一些不同格式的数字:8.3、0.001、9e-18。我正在寻找一种简单的方法来读取它们并存储它们而不会损失任何精度。这在 AWK 中很容易,但在 Perl 中是如何完成的呢?我只愿意使
我在一个文件中有一些不同格式的数字:8.3、0.001、9e-18。我正在寻找一种简单的方法来读取它们并存储它们而不会损失任何精度。这在 AWK 中很容易,但在 Perl 中是如何完成的呢?我只愿意使
我正在自学 Perl,并且在我的 Windows 8 64 位系统上安装了 Strawberry。 Strawberry 命令行似乎工作正常,我在 C 驱动器上的 Strawberry 文件夹中创建了
我在 Perl 模块 IO::Socket::SSL 中发现了一个错误,我可能会修复它,但是,我担心测试修复。我从 Debian 下载了源码包(因为我打算为它制作一个 Debian 包或补丁)并查看了
我有一个 perl 文件,它使用了两个 perl 模块 A.pm 和 B.pm。 但是在 B.pm 中我需要调用 A.pm 的子程序。即使我在 A.pm 中使用并尝试使用它,我仍然遇到未定义的错误。
有没有办法在 Perl 运行时加载整个模块?我原以为我用 autouse 找到了一个很好的解决方案,但以下代码无法编译: package tryAutouse2; use autouse 'tryAu
过去,我编写过许多 perl 模块,以及不止一些独立的 perl 程序,但我之前从未发布过多文件 perl 程序。 我有一个几乎处于 beta 阶段的 perl 程序,它将被开源发布。它需要一些数据文
我有 1 个 perl 脚本,我们在其中编写了几个子例程。例子: # Try_1.pl main(); sub main{ --- --- check(); } check { -- --} 现在,
似乎 CPAN 上的一些(很多?)模块部分是使用 XS 在 C 中实现的,如果需要,可以回退到纯 perl 实现。虽然这很聪明,但它显然会损害性能,我想知道它是否会发生,以便我可以解决问题。 有没有一
我对 perl 很陌生。我希望我可以从 perl 安装一些软件包,我这样做是这样的: perl -MCPAN -e 'install VM::EC2' 我猜它由于依赖而失败,它显示: Result:
给定一个 Perl 包 Foo.pm,例如 package Foo; use strict; sub bar { # some code here } sub baz { # more
我有一个用 Perl 编写的测试生成器。它生成连接到模拟器的测试。这些测试本身是用 Perl 编写的,并通过其 API 连接到模拟器。我希望生成的代码是人类可读的,这意味着我希望它能够正确缩进和格式化
我正在学习 Perl,非常新的用户。我可以知道这些 Perl 代码之间有什么区别吗? #!/usr/bin/perl & #!/usr/bin/perl -w 最佳答案 那不是 perl 代码,它是
我不认为这是一个重复的问题。这专门针对 Perl 模块附带的脚本。 通常,在安装多个 Perl 版本时,您可以将 perl 可执行文件标记为版本号 (perl5.32),这样它们就可以在 /whate
我有一个在文件中使用 Blowfish 加密的程序和第二个 perl 程序,它提示输入用于将其解密为字符串的密码,我希望不必将解密的源代码写入硬盘驱动器,尽管将它放在内存中并不是真正的问题,因为运行程
有没有人为 Perl 中的惰性求值列表找到了一个好的解决方案?我尝试了很多方法来改变类似的东西 for my $item ( map { ... } @list ) { } 进入懒惰的评估——例如,通
我安装了多个版本的 Perl。 我已经指定了要使用的版本。但是为了验证,我想从 .pl 脚本本身输出 Perl 的版本。 这可能吗? 在 Perl 脚本中解析“perl --version”的输出似乎
人们还经常问“我怎样才能编译 Perl?”而他们真正想要的是创建一个可以在机器上运行的可执行文件,即使他们没有安装 Perl。 我知道有几种解决方案: perl2exe靛蓝之星 它是商业的。我从未尝试
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 8年前关闭。 Improve this
我是一名优秀的程序员,十分优秀!