下午好,我正在尝试使用perl6.i计算字母A C T G在DNA序列中出现的次数我试过其他方式我只是
试图以另一种方式完成它.以下是我提出的一些代码
试图以另一种方式完成它.以下是我提出的一些代码
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