Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
remedial FASTA parser with grammar working
- Loading branch information
Showing
4 changed files
with
58 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,55 @@ | ||
use v6; | ||
|
||
use Bio::Role::SeqStream; | ||
use Bio::Grammar::Fasta; | ||
|
||
role Bio::SeqIO::fasta does Bio::Role::SeqStream; | ||
class Bio::Grammar::Fasta::Actions { | ||
|
||
has $!buffer; | ||
method record($/) { | ||
make $<sequence> | ||
} | ||
} | ||
|
||
method chunkify { | ||
# null condition to stop iterator | ||
return if self.fh.eof; | ||
my $current_record; | ||
while self.fh.get -> $line { | ||
if $!buffer { | ||
$current_record = $!buffer; | ||
$!buffer = Nil; | ||
} | ||
if $line ~~ /^^\>/ { | ||
if $current_record.defined { | ||
$!buffer = "$line\n"; | ||
last; | ||
role Bio::SeqIO::fasta does Bio::Role::SeqStream { | ||
has $!buffer; | ||
|
||
has $!actions = Bio::Grammar::Fasta::Actions.new(); | ||
|
||
# TODO: this is a temporary iterator to return one sequence record at a | ||
# time; two future optimizations require implementation in Rakudo: | ||
# 1) Chunking in IO::Handle using nl => "\n>" | ||
# 2) Grammar parsing of a stream of data (e.g. Cat), which is now considered | ||
# a close post-6.0 update | ||
method !chunkify { | ||
return if $.eof(); | ||
my $current_record; | ||
while $.get() -> $line { | ||
if $!buffer { | ||
$current_record = $!buffer; | ||
$!buffer = Nil; | ||
} | ||
if $line ~~ /^^\>/ { | ||
if $current_record.defined { | ||
$!buffer = "$line\n"; | ||
last; | ||
} else { | ||
$current_record = "$line\n"; | ||
} | ||
} else { | ||
$current_record = "$line\n"; | ||
$current_record ~= $line; | ||
} | ||
} else { | ||
$current_record ~= $line; | ||
} | ||
return $current_record; | ||
}; | ||
|
||
|
||
method next-Seq { | ||
my $chunk = self!chunkify; | ||
return if !?$chunk.defined; | ||
my $t = Bio::Grammar::Fasta.subparse($chunk, actions => $!actions, rule => 'record'); | ||
return $t; | ||
} | ||
return $current_record; | ||
}; | ||
|
||
|
||
method write-Seq { ... } | ||
|
||
method next-Seq { | ||
self.chunkify(); | ||
} | ||
|
||
method write-Seq { | ||
|
||
} | ||
} |