Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jerowe committed Jun 23, 2017
2 parents e91cb04 + 4bb81ee commit f38e9f1
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 13 deletions.
3 changes: 3 additions & 0 deletions lib/BioX/Workflow/Command/run/Utils/Rules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,12 @@ sub walk_indir_outdir_sample {
my $attr = shift;
my $text = shift;

$DB::single = 2;
my $use_iters = $self->use_iterables;
my $dummy_sample = $self->dummy_sample;

my @samples = @{$attr->samples} if $attr->has_samples;

foreach my $sample ( $attr->all_samples ) {
my $new_text = $text;
$new_text =~ s/$dummy_sample/$sample/g;
Expand Down
8 changes: 5 additions & 3 deletions lib/BioX/Workflow/Command/run/Utils/Samples.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ sub get_samples {

#Backwards compatibility
#For both file_rule and sample_rule
if ( $self->first_index_global_keys( sub { $_ eq 'sample_rule' } ) != -1 ) {
if ( $self->first_index_global_keys( sub { $_ eq 'file_rule' } ) != -1 )
{
$text = $self->global_attr->sample_rule;
}
elsif ( $self->first_index_global_keys( sub { $_ eq 'file_rule' } ) != -1 )
{
elsif ( $self->first_index_global_keys( sub { $_ eq 'sample_rule' } ) != -1 ) {
$text = $self->global_attr->sample_rule;
}
else {
Expand Down Expand Up @@ -234,6 +234,8 @@ sub check_sample_exist {
if ( $self->has_samples && !$self->resample ) {
my (@samples) = $self->sorted_samples;
$self->samples( \@samples );
## Fixes Issue #19
$self->global_attr->samples(\@samples);
$self->app_log->info('Samples passed in on command line.');
$exists = 1;
}
Expand Down
8 changes: 7 additions & 1 deletion t/lib/TestMethod/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ sub make_test_dir {
sub make_test_env {
my $self = shift;
my $workflow = shift;
my $args = shift || [];

MooseX::App::ParsedArgv->new( argv => [ "run", "--workflow", $workflow ] );
my $init_args = [ "run", "--workflow", $workflow ];
if($args && ref($args) eq 'ARRAY'){
map { push (@{$init_args}, $_) } @{$args};
}

MooseX::App::ParsedArgv->new( argv => $init_args );

my $test = BioX::Workflow::Command->new_with_command();

Expand Down
113 changes: 113 additions & 0 deletions t/lib/TestsFor/BioX/Workflow/Command/run/Test009.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package TestsFor::BioX::Workflow::Command::run::Test009;

use Test::Class::Moose;
use Cwd;
use FindBin qw($Bin);
use File::Path qw(make_path remove_tree);
use Data::Dumper;
use Capture::Tiny ':all';
use BioX::Workflow::Command;
use YAML::XS;
use Data::Walk;
use File::Slurp;
use File::Spec;
use DateTime;
use DateTime::Format::Strptime;
use Storable qw(dclone);

extends 'TestMethod::Base';

=head1 Purpose
This tests references -
https://github.com/biosails/BioX-Workflow-Command/issues/19 Refactoring the
'check_sample_exists' function didn't add the samples to the global samples attr
=cut

sub write_test_file {
my $test_dir = shift;

my $fh;
my $href = {
global => [
{ sample_rule => "Sample_.*" },
{ root_dir => 'data/analysis' },
{ root_dir => 'data/analysis' },
{ indir => 'data/raw' },
{ outdir => 'data/processed' },
{ jellyfish_dir => 'data/analysis/{$sample}/jellyfish' },
{ find_sample_bydir => 1 },
{ by_sample_outdir => 1 },
{ HPC => [ { account => 'gencore' } ] },
],
rules => [
{
pre_assembly_jellyfish_count => {
'local' => [
{ root_dir => 'data/raw' },
{ outdir => '{$self->jellyfish_dir}' },
{
INPUT => '{$self->jellyfish_dir}/some_input_rule1'
},
{ OUTPUT => '{$self->jellyfish_dir}/some_input_rule1' },
{ HPC => [ { 'deps' => 'some_dep' } ] }
],
process =>
'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT}',
},
},
]
};

#Write out the config
open( $fh, ">$test_dir/conf/test1.1.yml" )
or die print "Couldn't open file! $!";
my $yaml = Dump $href;
print $fh $yaml;
close($fh);

make_path( $test_dir . "/data/raw/Sample_01" );
write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" );
}

sub construct_tests {
my $test_methods = TestMethod::Base->new();
my $test_dir = $test_methods->make_test_dir();

write_test_file($test_dir);

my $t = "$test_dir/conf/test1.1.yml";
my $test = $test_methods->make_test_env( $t, [ '--samples', 'Sample_01' ] );
my $rules = $test->workflow_data->{rules};

return ( $test, $test_dir, $rules );
}

sub test_001 {
my ( $test, $test_dir, $rules ) = construct_tests;

$test->set_rule_names;
$test->filter_rule_keys;

foreach my $rule ( @{$rules} ) {
_init_rule( $test, $rule );
}

$test->post_process_rules;
is_deeply( $test->samples, ['Sample_01'] );

ok((-d 'data/analysis/Sample_01/jellyfish'));

ok(1);
}

sub _init_rule {
my $test = shift;
my $rule = shift;

$test->local_rule($rule);
$test->process_rule;
$test->p_rule_name( $test->rule_name );
$test->p_local_attr( dclone( $test->local_attr ) );
}
19 changes: 10 additions & 9 deletions t/test_class_tests.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use Test::Class::Moose::Runner;

Test::Class::Moose::Runner->new(
test_classes => [
'TestsFor::BioX::Workflow::Command::Test001',
'TestsFor::BioX::Workflow::Command::run::Test001',
'TestsFor::BioX::Workflow::Command::run::Test002',
'TestsFor::BioX::Workflow::Command::run::Test003',
'TestsFor::BioX::Workflow::Command::run::Test004',
'TestsFor::BioX::Workflow::Command::run::Test005',
'TestsFor::BioX::Workflow::Command::run::Test006',
'TestsFor::BioX::Workflow::Command::run::Test007',
'TestsFor::BioX::Workflow::Command::run::Test008',
# 'TestsFor::BioX::Workflow::Command::Test001',
# 'TestsFor::BioX::Workflow::Command::run::Test001',
# 'TestsFor::BioX::Workflow::Command::run::Test002',
# 'TestsFor::BioX::Workflow::Command::run::Test003',
# 'TestsFor::BioX::Workflow::Command::run::Test004',
# 'TestsFor::BioX::Workflow::Command::run::Test005',
# 'TestsFor::BioX::Workflow::Command::run::Test006',
# 'TestsFor::BioX::Workflow::Command::run::Test007',
# 'TestsFor::BioX::Workflow::Command::run::Test008',
'TestsFor::BioX::Workflow::Command::run::Test009',
],
)->runtests;

0 comments on commit f38e9f1

Please sign in to comment.