Skip to content

Commit

Permalink
add nl-in fix for FASTA parsing, with pretty noticeable speedup, thx …
Browse files Browse the repository at this point in the history
…timotimo!
  • Loading branch information
cjfields committed Sep 9, 2016
1 parent 684cf15 commit d00d853
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions lib/Bio/SeqIO/fasta.pm6
Expand Up @@ -21,37 +21,24 @@ class Bio::SeqIO::fasta does Bio::Role::SeqStream does Bio::Role::IO {
has $.width = 60;
has $.block = $!width; # NYI

# Note multi method signature
multi method initialize-io(:$!width?, :$fh?, :$file?, *%args) {
nextsame;
#callwith(:nl("\n>"), :$fh, :$file, |%args);
# we reset the input record sep here
callwith(:nl-in("\n>"), :$fh, :$file, |%args);
}

# 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
# time; one key future optimization requires implementation in Rakudo:
# 1) Grammar parsing of a stream of data (e.g. Cat), which is now considered
# a post-6.0 update

method !chunkify {
return if $.fh.eof();
my $current_record;
while $.fh.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;
while $.fh.get -> $chunk {
if $chunk !~~ /^^\>/ {
return ">$chunk";
}
return $chunk;
}
return $current_record;
};

method next-Seq {
Expand Down

0 comments on commit d00d853

Please sign in to comment.