Skip to content

Instantly share code, notes, and snippets.

@cjfields
Last active September 8, 2016 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjfields/50c7611d8f2ab78821780e7397a08bd5 to your computer and use it in GitHub Desktop.
Save cjfields/50c7611d8f2ab78821780e7397a08bd5 to your computer and use it in GitHub Desktop.
Parsing a FASTA file
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Bio::SeqIO;
my $file = shift;
my $in = Bio::SeqIO->new(-format => 'fasta', -file => $file);
my $ct = 0;
while (my $record = $in->next_seq) {
$ct++;
}
say "Count: $ct";
use v6;
use Bio::SeqIO;
my $file = @*ARGS.shift;
my $in = Bio::SeqIO.new(:format<fasta>, :file($file));
my $ct = 0;
while $in.next-Seq -> $record {
$ct++;
}
say "Count: $ct";
use v6;
use Bio::Grammar::Fasta;
my $file = @*ARGS.shift;
my $data = Bio::Grammar::Fasta.parsefile($file);
my $ct = 0;
for $data<record> -> $record {
$ct++;
}
say $ct;
[cjfields@Chriss-MacBook-Air bioperl6]$ time perl fasta.pl sequence.fasta
Count: 12097
real 0m0.434s
user 0m0.416s
sys 0m0.014s
[cjfields@Chriss-MacBook-Air bioperl6]$ time perl6 fasta.pl6 sequence.fasta
Count: 12097
real 0m4.406s
user 0m4.284s
sys 0m0.102s
[cjfields@Chriss-MacBook-Air bioperl6]$ time perl6 grammar.pl6 sequence.fasta
12097
real 0m2.571s
user 0m2.491s
sys 0m0.074s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment