diff --git a/lib/BioX/Workflow/Command/Utils/Plugin.pm b/lib/BioX/Workflow/Command/Utils/Plugin.pm index 611cdee..ff0029d 100644 --- a/lib/BioX/Workflow/Command/Utils/Plugin.pm +++ b/lib/BioX/Workflow/Command/Utils/Plugin.pm @@ -59,6 +59,11 @@ after 'BUILD' => sub { $self->app_load_plugins( $self->plugins ); $self->parse_plugin_opts( $self->plugins_opts ); + + ##Must reload the configs to get any options from the plugins + if ( $self->has_config_files ) { + $self->load_configs; + } }; =head3 app_load_plugin diff --git a/lib/BioX/Workflow/Command/run/Utils/Directives.pm b/lib/BioX/Workflow/Command/run/Utils/Directives.pm index 5f60834..1fc67c4 100644 --- a/lib/BioX/Workflow/Command/run/Utils/Directives.pm +++ b/lib/BioX/Workflow/Command/run/Utils/Directives.pm @@ -426,6 +426,9 @@ sub create_attr { if ( $k eq 'stash' ) { $self->merge_stash($v); } + elsif($self->can($k)){ + next; + } elsif ( $k =~ m/_list/ ) { $self->create_ITERABLE_attr( $meta, $k ); } @@ -592,11 +595,12 @@ sub interpol_directive { my $source = shift; my $text = ''; - if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{\$/ ) { + #The $ is not always at the beginning + if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{/ ) { return $self->interpol_directive_cache->{$source}; } - if ( $source !~ m/{\$/ ) { + if ( $source !~ m/{/ ) { $self->interpol_directive_cache->{$source} = $source; return $source; } diff --git a/lib/BioX/Workflow/Command/run/Utils/Rules.pm b/lib/BioX/Workflow/Command/run/Utils/Rules.pm index c13f570..b28016f 100644 --- a/lib/BioX/Workflow/Command/run/Utils/Rules.pm +++ b/lib/BioX/Workflow/Command/run/Utils/Rules.pm @@ -490,36 +490,6 @@ sub sanity_check_rule { 'Rule: ' . $self->rule_name . ' passes sanity check' ); } -sub sanity_check_fail { - my $self = shift; - - my $rule_example = <my_dir}' - - INPUT: '{\$self->indir}/{\$sample}.csv' - - HPC: - - mem: '40GB' - - walltime: '40GB' - process: | - echo 'MyDir on {\$self->my_dir}' - echo 'Indir on {\$self->indir}' - echo 'Outdir on {\$self->outdir}' - echo 'INPUT on {\$self->INPUT}' -EOF - $self->app_log->fatal('Skipping this rule.'); - $self->app_log->fatal( -'Here is an example workflow. For more information please see biox-workflow.pl new --help.' - ); - $self->app_log->fatal($rule_example); -} - =head3 template_process Do the actual processing of the rule->process @@ -554,6 +524,15 @@ sub template_process { $self->write_rule_meta('before_meta'); } +=head3 use_iterables + +Check the global and local keys to see if we are using any iterables + + use_chroms: 1 + use_chunks: 1 + +=cut + sub use_iterables { my $self = shift; @@ -937,4 +916,33 @@ sub carry_directives { $self->local_attr->stash( dclone( $self->p_local_attr->stash ) ); } +sub sanity_check_fail { + my $self = shift; + + my $rule_example = <my_dir}' + - INPUT: '{\$self->indir}/{\$sample}.csv' + - HPC: + - mem: '40GB' + - walltime: '40GB' + process: | + echo 'MyDir on {\$self->my_dir}' + echo 'Indir on {\$self->indir}' + echo 'Outdir on {\$self->outdir}' + echo 'INPUT on {\$self->INPUT}' +EOF + $self->app_log->fatal('Skipping this rule.'); + $self->app_log->fatal( +'Here is an example workflow. For more information please see biox-workflow.pl new --help.' + ); + $self->app_log->fatal($rule_example); +} 1; diff --git a/lib/BioX/Workflow/Command/run/Utils/Samples.pm b/lib/BioX/Workflow/Command/run/Utils/Samples.pm index ab76403..5777615 100644 --- a/lib/BioX/Workflow/Command/run/Utils/Samples.pm +++ b/lib/BioX/Workflow/Command/run/Utils/Samples.pm @@ -152,16 +152,14 @@ sub get_samples { #Stupid resample $self->get_global_keys; - if ( $self->has_samples && !$self->resample ) { - my (@samples) = $self->sorted_samples; - $self->samples( \@samples ); - return; - } + my $exists = $self->check_sample_exist; + return if $exists; #We need to evaluate the global_dirs incase the indir has a var #But we don't keep it around, because that would be madness #TODO Fix this we should process these the same way we process rule names - $attr = dclone( $self->global_attr ); + $attr = dclone( $self->global_attr ); + # $DB::single = 2; if ( $attr->indir =~ m/\{\$/ ) { $attr->walk_process_data( $self->global_keys ); @@ -225,6 +223,28 @@ sub get_samples { $self->write_sample_meta; } +sub check_sample_exist { + my $self = shift; + + my $exists = 0; + if ( $self->has_samples && !$self->resample ) { + my (@samples) = $self->sorted_samples; + $self->samples( \@samples ); + $self->app_log->info('Samples passed in on command line.'); + $exists = 1; + } + elsif ( $self->global_attr->has_samples ) { + my (@samples) = @{$self->global_attr->samples}; + @samples = sort(@samples); + $self->samples( \@samples ); + $self->app_log->info('Samples were defined in the global key.'); + $exists = 1; + } + + $self->write_sample_meta if $exists; + return $exists; +} + =head2 match_samples Match samples based on regex written in sample_rule diff --git a/t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm b/t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm index 82351a3..eedfa6d 100644 --- a/t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm +++ b/t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm @@ -154,16 +154,6 @@ sub test_002 { } -sub create_times { - my $now = DateTime->now( time_zone => 'local' ); - my $strp = DateTime::Format::Strptime->new( - pattern => '%a %b %e %T %Y', - time_zone => 'local', - ); - - return $now, $strp; -} - sub _init_rule { my $test = shift; my $rule = shift; diff --git a/t/lib/TestsFor/BioX/Workflow/Command/run/Test007.pm b/t/lib/TestsFor/BioX/Workflow/Command/run/Test007.pm new file mode 100644 index 0000000..9413010 --- /dev/null +++ b/t/lib/TestsFor/BioX/Workflow/Command/run/Test007.pm @@ -0,0 +1,114 @@ +package TestsFor::BioX::Workflow::Command::run::Test007; + +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'; + +sub write_test_file { + my $test_dir = shift; + + my $fh; + my $href = { + global => [ + { sample_rule => "Sample_.*" }, + { root_dir => 'data/raw' }, + { indir => '{$self->root_dir}' }, + { outdir => 'data/processed' }, + { find_sample_bydir => 1 }, + { by_sample_outdir => 1 }, + { chroms_list => [1,2,3,4,5]}, + { samples => ['Sample_01']}, + ], + rules => [ + { + t3_rule1 => { + 'local' => [ + { root_dir => 'data/raw' }, + { + INPUT => +'{$self->root_dir}/{$sample}/some_input_rule1.{$self->chunk}' + }, + { OUTPUT => ['some_output_rule1'] }, + { use_chunks => 1 }, + ], + process => +'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT->[0]}', + }, + }, + ] + }; + + #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" ); + make_path( $test_dir . "/data/raw/Sample_02" ); + write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" ); + write_file( $test_dir . "/data/raw/Sample_02/" . "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); + my $rules = $test->workflow_data->{rules}; + + return ( $test, $test_dir, $rules ); +} + +sub test_001 { + my ( $test, $test_dir, $rules ) = construct_tests; + + $test->check_sample_exist; + is_deeply($test->samples, ['Sample_01']); + is_deeply($test->global_attr->chroms_list, [1,2,3,4,5]); + + # $test->stdout(1); + $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']); + + diag Dumper ($test->global_attr->chroms_list); + diag Dumper ($test->global_attr->samples); + diag Dumper($test->global_attr->has_samples); + + + 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 ) ); +} diff --git a/t/test_class_tests.t b/t/test_class_tests.t index d807341..76ba9dd 100644 --- a/t/test_class_tests.t +++ b/t/test_class_tests.t @@ -13,5 +13,6 @@ Test::Class::Moose::Runner->new( 'TestsFor::BioX::Workflow::Command::run::Test004', 'TestsFor::BioX::Workflow::Command::run::Test005', 'TestsFor::BioX::Workflow::Command::run::Test006', + 'TestsFor::BioX::Workflow::Command::run::Test007', ], )->runtests;