Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
move instance creation into the action class for the grammar
  • Loading branch information
cjfields committed Nov 2, 2014
1 parent 9511726 commit a889dcc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/Bio/SeqIO/fasta.pm6
Expand Up @@ -4,8 +4,19 @@ use Bio::Role::SeqStream;
use Bio::Grammar::Fasta;
use Bio::PrimarySeq;

class Bio::Grammar::Fasta::Actions::PrimarySeq {
method record($/) {
make Bio::PrimarySeq.new(
seq => ~$<sequence>,
description => ~$<description_line><description>,
display_id => ~$<description_line><id>
);
}
}

role Bio::SeqIO::fasta does Bio::Role::SeqStream {
has $!buffer;
has $!actions = Bio::Grammar::Fasta::Actions::PrimarySeq.new();

# TODO: this is a temporary iterator to return one sequence record at a
# time; two future optimizations require implementation in Rakudo:
Expand Down Expand Up @@ -38,13 +49,8 @@ role Bio::SeqIO::fasta does Bio::Role::SeqStream {
method next-Seq {
my $chunk = self!chunkify;
return if !?$chunk.defined;
my $t = Bio::Grammar::Fasta.parse($chunk, rule => 'record');
my $seq = Bio::PrimarySeq.new(
seq => ~$t<sequence>,
description => ~$t<description_line><description>,
display_id => ~$t<description_line><id>
);
return $seq;
my $t = Bio::Grammar::Fasta.subparse($chunk, actions => $!actions, rule => 'record').ast;
return $t;
}

method write-Seq(Bio::PrimarySeq $seq) {
Expand Down

0 comments on commit a889dcc

Please sign in to comment.