Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl6
- # a minimal Stockholm alignment format parser that reads
- # ONLY single-line alignments and dumps each sequence (without additional
- # gap characters) to a file
- use Grammar::Tracer;
- grammar StockholmParser {
- token TOP { <header>+ <alignment> <consensus> <sep>? <.eol> }
- token header { ['#'|'#='] [\N]+ <.eol> }
- token alignment { <aln>+ }
- token aln { <id> \s+ <seq> <.eol> }
- token id { [\S+] }
- token consensus { '#=GC SS_cons' <ws> <form> <.eol> }
- token form { <[ ( ) . ]>+ }
- token seq { <[\w\-]>+ }
- token eol { \n [\h*\n]* }
- token sep { '//' }
- }
- class Stk-actions {
- method seq($/) {make $/.subst(:g, '-','') }
- }
- sub MAIN ( $filename ){
- say "processing $filename";
- my $result = StockholmParser.parsefile($filename, actions => Stk-actions.new);
- # note $result;
- for $result<alignment><aln>.flat -> $a {
- my $fh=open "$a<id>.fa", :w;
- $fh.say($a<seq>.made);
- $fh.close
- }
- }
Add Comment
Please, Sign In to add comment