Created
September 12, 2016 23:41
-
-
Save zoffixznet/887cd4ffaca5403c19d0bd4f3b9511dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
grammar CDHit { | |
token TOP { <record>+ } | |
token record { <id> <member>+ } | |
token id { ^^ <seq_id> \n } | |
token num { \d+ } | |
token len { <-[,]>+ } | |
token seq_id { '>' (\S+) } | |
token pct { <[\d.]>+ '%' } | |
token member { | |
<num> \s+ <len> ',' \s+ <seq_id> \s+ 'at' \s+ <pct> \n | |
} | |
} | |
class CDHit::Actions { | |
method TOP ($/) { make $<record>».made } | |
method record ($/) { | |
make { id => $<id>.made, members => $<member>».made } | |
} | |
method id ($/) { make $<seq_id>.made } | |
method seq_id ($/) { make ~$/[0] } | |
method member ($/) { | |
make { | |
num => +$<num>, | |
len => ~$<len>, | |
id => ~$<seq_id>[0], | |
pct => ~$<pct>, | |
} | |
} | |
} | |
subset File of Str where *.IO.f; | |
sub MAIN { | |
my $result = CDHit.parse(q:to/IN/, :actions(CDHit::Actions)).made[0]<id>; | |
>Cluster_5086 | |
0 358aa, >gi|317183610|gb|ADV... at 66.76% | |
1 361aa, >gi|315661179|gb|ADU... at 70.36% | |
>Cluster_10030 | |
0 85aa, >gi|315661182|gb|ADU... at 64.71% | |
1 85aa, >gi|268687968|emb|CB... at 75.29% | |
2 100aa, >gi|747172712|gb|AJE... at 74.00% | |
IN | |
dd $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment