Guest User

Untitled

a guest
Feb 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. # a minimal Stockholm alignment format parser that reads
  4. # ONLY single-line alignments and dumps each sequence (without additional
  5. # gap characters) to a file
  6.  
  7. use Grammar::Tracer;
  8.  
  9. grammar StockholmParser {
  10. token TOP { <header>+ <alignment> <consensus> <sep>? <.eol> }
  11. token header { ['#'|'#='] [\N]+ <.eol> }
  12. token alignment { <aln>+ }
  13. token aln { <id> \s+ <seq> <.eol> }
  14. token id { [\S+] }
  15. token consensus { '#=GC SS_cons' <ws> <form> <.eol> }
  16. token form { <[ ( ) . ]>+ }
  17. token seq { <[\w\-]>+ }
  18. token eol { \n [\h*\n]* }
  19. token sep { '//' }
  20. }
  21.  
  22. class Stk-actions {
  23. method seq($/) {make $/.subst(:g, '-','') }
  24. }
  25.  
  26.  
  27. sub MAIN ( $filename ){
  28. say "processing $filename";
  29. my $result = StockholmParser.parsefile($filename, actions => Stk-actions.new);
  30. # note $result;
  31.  
  32. for $result<alignment><aln>.flat -> $a {
  33. my $fh=open "$a<id>.fa", :w;
  34. $fh.say($a<seq>.made);
  35. $fh.close
  36. }
  37. }
Add Comment
Please, Sign In to add comment