BioX-Seq
view release on metacpan or search on metacpan
lib/BioX/Seq/Stream.pm view on Meta::CPAN
}
else {
$self->{fh} = \*STDIN;
}
# handle files coming from different platforms
#my @layers = PerlIO::get_layers($self->{fh});
#binmode($self->{fh},':unix:stdio:crlf');
$self->_guess_format;
$self->_init;
return $self;
}
sub fast {
my ($self, $bool) = @_;
$self->{fast} = $bool // 1;
}
sub _guess_format {
my ($self) = @_;
# Filetype guessing must be based on first two bytes (or less)
# which are stored in an object buffer
my $r = (read $self->{fh}, $self->{buffer}, 2);
die "failed to read initial bytes" if ($r != 2);
my $search_path = abs_path(__FILE__);
$search_path =~ s/\.pm$//i;
my @matched;
for my $module ( glob "$search_path/*.pm" ) {
my ($name,$path,$suff) = fileparse($module, qr/\.pm/i);
my $classname = blessed($self) . "::$name";
eval "require $classname";
if ($classname->_check_type($self)) {
push @matched, $classname;
}
}
die "Failed to guess filetype\n" if (scalar(@matched) < 1);
# uncoverable branch true
die "Multiple filetypes matched\n" if (scalar(@matched) > 1);
eval "require $matched[0]";
bless $self => $matched[0];
}
1;
300,
);
ok( scalar(@orfs) == 5, "check ORF count 2" );
throws_ok { all_orfs($seq) } qr/Missing mode/, "missing mode";
throws_ok { all_orfs($seq, 0) } qr/Missing min/, "missing minimum length";
throws_ok { BioX::Seq::Stream->new($test_onebyte) } qr/initial bytes/, "truncated input";
throws_ok { BioX::Seq::Stream->new($test_foobar) } qr/Failed to guess/, "non-sequence input";
# simulate missing zstd
my $zstd_bin_tmp = $BioX::Seq::Stream::ZSTD_BIN;
$BioX::Seq::Stream::ZSTD_BIN = undef;
throws_ok { BioX::Seq::Stream->new($test_zst) } qr/no zstd/, "missing zstd";
$BioX::Seq::Stream::ZSTD_BIN = 'nonexistent';
throws_ok { BioX::Seq::Stream->new($test_zst) } qr/[Error opening|not recognized]/, "bad zstd binary";
$BioX::Seq::Stream::ZSTD_BIN = $zstd_bin_tmp;
# simulate missing dsrc
( run in 0.586 second using v1.01-cache-2.11-cpan-748bfb374f4 )