gpt4 book ai didi

bioinformatics - 使用 perl 6 计算 DNA 核苷酸

转载 作者:行者123 更新时间:2023-12-04 13:58:30 25 4
gpt4 key购买 nike

下午好,我正在尝试使用 perl6 计算 DNA 序列中字母 A C T G 出现的次数。我尝试过其他方法,我只是
试图以另一种方式完成它。这是我想出的一些代码

use v6;

my $default-input = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";

sub MAIN(Str $input = $default-input)
{
say "{bag($input.comb)<A C G T>}";
}



use v6;

my $default-input = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";

sub MAIN($input = $default-input)
{
"{<A C G T>.map({ +$input.comb(/$_/) })}".say;

样本数据集
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC

最佳答案

multi sub MAIN ( \DNA ) {
my Int %bag = A => 0, C => 0, G => 0, T => 0;

# doesn't keep the whole thing in memory
# like .comb.Bag would have
for DNA.comb {
%bag{$_}++
}
.say for %bag<A C G T> :p;
}

multi sub MAIN ( 'example' ){
samewith "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
}

multi sub MAIN ( Bool :STDIN($)! ){
samewith $*IN
}

multi sub MAIN ( Str :filename(:$file)! where .IO.f ){
samewith $file.IO
}

~$ ./test.p6
Usage:
./test.p6 <DNA>
./test.p6 example
./test.p6 --STDIN
./test.p6 --filename|--file=<Str>

~$ ./test.p6 example
A => 20
C => 12
G => 17
T => 21

~$ ./test.p6 --STDIN < test.in
A => 20
C => 12
G => 17
T => 21

~$ ./test.p6 --file=test.in
A => 20
C => 12
G => 17
T => 21

关于bioinformatics - 使用 perl 6 计算 DNA 核苷酸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37036062/

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