BioX-Seq
view release on metacpan or search on metacpan
$parser = BioX::Seq::Fetch->new($test2_fa, with_description => 0);
$seq = $parser->fetch_seq('Test1|someseq');
ok( $seq->seq eq 'AATGCAAGTACGTAAGACTTATAGCAGTAGGATGGAATGATAGCCATAG', "fetch non-gz" );
# out-of-bounds
throws_ok { $seq = $parser->fetch_seq('Test1|someseq',-1,3) } qr/out of bounds/, "Fetch too low";
throws_ok { $seq = $parser->fetch_seq('Test1|someseq',1,300) } qr/out of bounds/, "Fetch too high";
#misc error conditions
throws_ok { BioX::Seq::Fetch->new(undef) } qr/Must define/, "Fetch undefined filename";
throws_ok { BioX::Seq::Fetch->new('nonexistent_file') } qr/Error opening/, "Fetch nonexistent filename";
throws_ok { BioX::Seq::Fetch->new($test_notbgzip) } qr/with bgzip/, "Fetch with regular gzip";
throws_ok { BioX::Seq::Fetch->new($test_bad) } qr/Unexpected content/, "Fetch invalid chars";
throws_ok { BioX::Seq::Fetch->new($test_fa) } qr/Base length mismatch/, "Fetch uneven lines";
throws_ok { BioX::Seq::Fetch->new($test_endings) } qr/Line length mismatch/, "Fetch weird line endings";
throws_ok { BioX::Seq::Fetch->new($test_duplicates) } qr/duplicate entries/, "Fetch duplicate IDs";
#----------------------------------------------------------------------------#
# Fetch utils
#----------------------------------------------------------------------------#
# rev_com()
$seq = 'AATGAGACAGGTGNNRSGGG';
my $rc = rev_com($seq);
ok( $rc eq 'CCCSYNNCACCTGTCTCATT', "check rev_com()" );
# is_nucleic()
my $aa = 'MERTTSQYPAVARS';
ok( ! is_nucleic($aa), "check amino acid" );
ok( is_nucleic($rc), "check nucleic acid" );
# all_orfs() / build_ORF_regex()
$parser = BioX::Seq::Stream->new($test_orfs);
$seq = $parser->next_seq();
my $orf = $parser->next_seq();
my @orfs = all_orfs(
$seq,
3,
300,
);
ok( scalar(@orfs) == 4, "check ORF count" );
ok( $orfs[1]->[0] eq "$orf", "check ORF seq" );
ok( $orfs[1]->[1] == 1784, "check ORF start" );
ok( $orfs[1]->[2] == 1371, "check ORF stop" );
@orfs = all_orfs(
$seq,
0,
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
my $dsrc_bin_tmp = $BioX::Seq::Stream::DSRC_BIN;
$BioX::Seq::Stream::DSRC_BIN = undef;
throws_ok { BioX::Seq::Stream->new($test_dsrc) } qr/no dsrc/, "missing dsrc";
$BioX::Seq::Stream::DSRC_BIN = 'nonexistent';
throws_ok { BioX::Seq::Stream->new($test_dsrc) } qr/[Error opening|not recognized]/, "bad dsrc binary";
$BioX::Seq::Stream::DSRC_BIN = $dsrc_bin_tmp;
# simulate missing fqzc
my $fqzc_bin_tmp = $BioX::Seq::Stream::FQZC_BIN;
$BioX::Seq::Stream::FQZC_BIN = undef;
throws_ok { BioX::Seq::Stream->new($test_fqz) } qr/no fqz/, "missing fqz";
$BioX::Seq::Stream::FQZC_BIN = 'nonexistent bin';
throws_ok { BioX::Seq::Stream->new($test_fqz) } qr/[Error opening|not recognized]/, "bad fqz binary";
$BioX::Seq::Stream::FQZC_BIN = $fqzc_bin_tmp;
#----------------------------------------------------------------------------#
# Finish up
#----------------------------------------------------------------------------#
unlink $_ for (@tmp_files);
done_testing();
exit;
( run in 1.522 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )