计算 GC 含量
作者:gerdr
http://rosalind.info/problems/gc/
示例输入
>Rosalind_6404 CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC TCCCACTAATAATTCTGAGG >Rosalind_5959 CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT ATATCCATTTGTCAGCAGACACGC >Rosalind_0808 CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC TGGGAACCTGCGGGCAGTAGGTGGAAT
示例输出
Rosalind_0808 60.919540
源代码: gc-gerdr.pl
use v6; grammar FASTA { token TOP { ^ \n* <DNA-string>+ } token DNA-string { '>' (\N+) \n (<[ACGT\n]>+) } } my $actions = class { method TOP($/) { make $<DNA-string>>>.ast } method DNA-string($/) { make [~$0, 100 * +.comb(/<[GC]>/) / +.comb(/<[ACGT]>/)] given ~$1 } }; my $default-input = q:to/END/; >Rosalind_6404 CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC TCCCACTAATAATTCTGAGG >Rosalind_5959 CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT ATATCCATTTGTCAGCAGACACGC >Rosalind_0808 CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC TGGGAACCTGCGGGCAGTAGGTGGAAT END sub MAIN($input-file = Nil) { my $input = $input-file ?? $input-file.IO.slurp !! $default-input; FASTA.parse($_, :$actions).ast.sort(*.[1]).[*-1] ~ '%' ==> say() given $input; }