Skip to content

Commit

Permalink
Merge b64fc9c into ba1746e
Browse files Browse the repository at this point in the history
  • Loading branch information
ebelter committed Aug 20, 2018
2 parents ba1746e + b64fc9c commit e99cedc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/Pacbio/Command/Assembly/BaxToBam/GenerateCommands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Pacbio::Command::Assembly::BaxToBam::GenerateCommands {
},
has_optional_transient => {
_analyses => { is => 'ARRAY', },
_commands_fh => { is => 'IO::Handle', },
_commands_fh => { },
_bam_output_directory => { is => 'Text', },
},
doc => 'insert missing primary contigs from haplotigs',
Expand Down Expand Up @@ -71,8 +71,9 @@ sub __init__ {
$self->_commands_fh(
( $commands_file eq '-' )
? 'STDOUT'
: IO::File->new($commands_file, 'r')
: IO::File->new($commands_file, 'w')
);
$self->fatal_message('Failed to open commands file! %s', $commands_file) if not $self->_commands_fh;

my $bam_output_directory = $self->bam_output_directory;
if ( $bam_output_directory ) {
Expand Down Expand Up @@ -127,6 +128,7 @@ sub execute {
$self->_commands_fh->print("$cmd\n");
}

$self->_commands_fh->close if $self->commands_file ne '-';
1;
}

Expand Down
22 changes: 18 additions & 4 deletions t/Pacbio-Command-Assembly-BaxToBam-GenerateCommands.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use TenxTestEnv;
use File::Temp;
use File::Slurp;
use Test::Exception;
use Test::More tests => 5;
use Test::More tests => 6;

my %test = ( class => 'Pacbio::Command::Assembly::BaxToBam::GenerateCommands', );
subtest 'setup' => sub{
Expand All @@ -18,7 +18,7 @@ subtest 'setup' => sub{

$test{data_dir} = TenxTestEnv::test_data_directory_for_class($test{class});
ok(-d $test{data_dir}->stringify, 'data dir exists');
$test{tempdir} = File::Temp::tempdir(CLEANUP => 1);
$test{tempdir} = Path::Class::dir( File::Temp::tempdir(CLEANUP => 1) );

$test{run_directories} = TenxTestEnv::test_data_directory_for_class('Pacbio::Run');
ok(-d $test{run_directories}->stringify, 'run dirs exists');
Expand Down Expand Up @@ -49,19 +49,20 @@ subtest 'execute with runs' => sub{
subtest 'execute with runs and library name' => sub{
plan tests => 4;

my $output_file = $test{tempdir}->file('runs-and-library-name.txt');
my $library_name = 'EEAI';
my $cmd = $test{class}->create(
bax_sources => [ $test{data_dir}->file('6U00E3')->stringify, ],
bam_to_bax_command => 'bsub -q long -o %LOG bam2bax',
library_name => $library_name,
commands_file => "$output_file",
);
ok($cmd, 'create command');

my $output;
open local(*STDOUT), '>', \$output or die $!;
lives_ok(sub{ $cmd->execute }, 'execute');
ok($cmd->result, 'command result');

my $output = File::Slurp::slurp("$output_file");
my $expected_output = File::Slurp::slurp( $test{data_dir}->file( join('.', 'expected', $library_name, 'out') )->stringify );
my $base_test_data_dir = TenxTestEnv::test_data_directory();
$expected_output =~ s/\%TDD/$base_test_data_dir/g;
Expand Down Expand Up @@ -120,4 +121,17 @@ subtest 'execute with some bams completed' => sub{

};

subtest 'failures' => sub{
plan tests => 2;

my $cmd = $test{class}->create(
bax_sources => [ $test{data_dir}->file('6U00E3')->stringify, ],
bam_to_bax_command => 'bsub -q long -o %LOG bam2bax',
commands_file => '/blah',
);
ok($cmd, 'create command');
throws_ok(sub{ $cmd->execute; }, qr/Failed to open commands file/, 'fails when cannot open commands file');

};

done_testing();

0 comments on commit e99cedc

Please sign in to comment.