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 11, 2017
2 parents d72c445 + fd24115 commit 3f31428
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 48 deletions.
5 changes: 5 additions & 0 deletions lib/BioX/Workflow/Command/Utils/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/BioX/Workflow/Command/run/Utils/Directives.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
}
Expand Down
68 changes: 38 additions & 30 deletions lib/BioX/Workflow/Command/run/Utils/Rules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<EOF;
global:
- indir: data/raw
- outdir: data/processed
- file_rule: (sample.*)$
- by_sample_outdir: 1
- find_sample_bydir: 1
- copy1:
local:
- indir: '{\$self->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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = <<EOF;
global:
- indir: data/raw
- outdir: data/processed
- file_rule: (sample.*)$
- by_sample_outdir: 1
- find_sample_bydir: 1
- copy1:
local:
- indir: '{\$self->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;
32 changes: 26 additions & 6 deletions lib/BioX/Workflow/Command/run/Utils/Samples.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
114 changes: 114 additions & 0 deletions t/lib/TestsFor/BioX/Workflow/Command/run/Test007.pm
Original file line number Diff line number Diff line change
@@ -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 ) );
}
1 change: 1 addition & 0 deletions t/test_class_tests.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 3f31428

Please sign in to comment.