Skip to content

Instantly share code, notes, and snippets.

@swuecho
Created December 16, 2014 04:24
Show Gist options
  • Save swuecho/9ec08fe5698e8011e294 to your computer and use it in GitHub Desktop.
Save swuecho/9ec08fe5698e8011e294 to your computer and use it in GitHub Desktop.
use v5.20;
use DDP;
my $fasta = <<'END';
>hello
GCTATATAAGC
>world prot
TATAKEKEKELKL
END
my $parser = do {
use Regexp::Grammars;
qr/
<TOP>
<nocontext:>
<token: TOP> <[record]>+
<token: record> <.start=(\>)><id><comment>?\n<sequence>
<token: id> [^\-\s\n]+
<token: comment> \s[^\n]+
<token: sequence> <dna>|<rna>|<aa>
<token: dna> [ACGTRYKMSWBDHVNX\-\n]+
<token: rna> [ACGURYKMSWBDHVNX\-\n]+
<token: aa> [A-Z\*\-\n]+
/;
};
if ( $fasta =~ $parser ) {
p %/;
}
__END__
{
TOP {
record [
[0] {
id "hello",
sequence {
dna "GCTATATAAGC
"
}
},
[1] {
comment " prot",
id "world",
sequence {
dna "TATAK"
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment