Skip to content

Commit fd24115

Browse files
committed
finished updated
1 parent 2574bae commit fd24115

File tree

7 files changed

+190
-48
lines changed

7 files changed

+190
-48
lines changed

lib/BioX/Workflow/Command/Utils/Plugin.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ after 'BUILD' => sub {
5959

6060
$self->app_load_plugins( $self->plugins );
6161
$self->parse_plugin_opts( $self->plugins_opts );
62+
63+
##Must reload the configs to get any options from the plugins
64+
if ( $self->has_config_files ) {
65+
$self->load_configs;
66+
}
6267
};
6368

6469
=head3 app_load_plugin

lib/BioX/Workflow/Command/run/Utils/Directives.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ sub create_attr {
426426
if ( $k eq 'stash' ) {
427427
$self->merge_stash($v);
428428
}
429+
elsif($self->can($k)){
430+
next;
431+
}
429432
elsif ( $k =~ m/_list/ ) {
430433
$self->create_ITERABLE_attr( $meta, $k );
431434
}
@@ -592,11 +595,12 @@ sub interpol_directive {
592595
my $source = shift;
593596
my $text = '';
594597

595-
if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{\$/ ) {
598+
#The $ is not always at the beginning
599+
if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{/ ) {
596600
return $self->interpol_directive_cache->{$source};
597601
}
598602

599-
if ( $source !~ m/{\$/ ) {
603+
if ( $source !~ m/{/ ) {
600604
$self->interpol_directive_cache->{$source} = $source;
601605
return $source;
602606
}

lib/BioX/Workflow/Command/run/Utils/Rules.pm

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -490,36 +490,6 @@ sub sanity_check_rule {
490490
'Rule: ' . $self->rule_name . ' passes sanity check' );
491491
}
492492

493-
sub sanity_check_fail {
494-
my $self = shift;
495-
496-
my $rule_example = <<EOF;
497-
global:
498-
- indir: data/raw
499-
- outdir: data/processed
500-
- file_rule: (sample.*)$
501-
- by_sample_outdir: 1
502-
- find_sample_bydir: 1
503-
- copy1:
504-
local:
505-
- indir: '{\$self->my_dir}'
506-
- INPUT: '{\$self->indir}/{\$sample}.csv'
507-
- HPC:
508-
- mem: '40GB'
509-
- walltime: '40GB'
510-
process: |
511-
echo 'MyDir on {\$self->my_dir}'
512-
echo 'Indir on {\$self->indir}'
513-
echo 'Outdir on {\$self->outdir}'
514-
echo 'INPUT on {\$self->INPUT}'
515-
EOF
516-
$self->app_log->fatal('Skipping this rule.');
517-
$self->app_log->fatal(
518-
'Here is an example workflow. For more information please see biox-workflow.pl new --help.'
519-
);
520-
$self->app_log->fatal($rule_example);
521-
}
522-
523493
=head3 template_process
524494
525495
Do the actual processing of the rule->process
@@ -554,6 +524,15 @@ sub template_process {
554524
$self->write_rule_meta('before_meta');
555525
}
556526

527+
=head3 use_iterables
528+
529+
Check the global and local keys to see if we are using any iterables
530+
531+
use_chroms: 1
532+
use_chunks: 1
533+
534+
=cut
535+
557536
sub use_iterables {
558537
my $self = shift;
559538

@@ -937,4 +916,33 @@ sub carry_directives {
937916
$self->local_attr->stash( dclone( $self->p_local_attr->stash ) );
938917
}
939918

919+
sub sanity_check_fail {
920+
my $self = shift;
921+
922+
my $rule_example = <<EOF;
923+
global:
924+
- indir: data/raw
925+
- outdir: data/processed
926+
- file_rule: (sample.*)$
927+
- by_sample_outdir: 1
928+
- find_sample_bydir: 1
929+
- copy1:
930+
local:
931+
- indir: '{\$self->my_dir}'
932+
- INPUT: '{\$self->indir}/{\$sample}.csv'
933+
- HPC:
934+
- mem: '40GB'
935+
- walltime: '40GB'
936+
process: |
937+
echo 'MyDir on {\$self->my_dir}'
938+
echo 'Indir on {\$self->indir}'
939+
echo 'Outdir on {\$self->outdir}'
940+
echo 'INPUT on {\$self->INPUT}'
941+
EOF
942+
$self->app_log->fatal('Skipping this rule.');
943+
$self->app_log->fatal(
944+
'Here is an example workflow. For more information please see biox-workflow.pl new --help.'
945+
);
946+
$self->app_log->fatal($rule_example);
947+
}
940948
1;

lib/BioX/Workflow/Command/run/Utils/Samples.pm

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,14 @@ sub get_samples {
152152
#Stupid resample
153153
$self->get_global_keys;
154154

155-
if ( $self->has_samples && !$self->resample ) {
156-
my (@samples) = $self->sorted_samples;
157-
$self->samples( \@samples );
158-
return;
159-
}
155+
my $exists = $self->check_sample_exist;
156+
return if $exists;
160157

161158
#We need to evaluate the global_dirs incase the indir has a var
162159
#But we don't keep it around, because that would be madness
163160
#TODO Fix this we should process these the same way we process rule names
164-
$attr = dclone( $self->global_attr );
161+
$attr = dclone( $self->global_attr );
162+
165163
# $DB::single = 2;
166164
if ( $attr->indir =~ m/\{\$/ ) {
167165
$attr->walk_process_data( $self->global_keys );
@@ -225,6 +223,28 @@ sub get_samples {
225223
$self->write_sample_meta;
226224
}
227225

226+
sub check_sample_exist {
227+
my $self = shift;
228+
229+
my $exists = 0;
230+
if ( $self->has_samples && !$self->resample ) {
231+
my (@samples) = $self->sorted_samples;
232+
$self->samples( \@samples );
233+
$self->app_log->info('Samples passed in on command line.');
234+
$exists = 1;
235+
}
236+
elsif ( $self->global_attr->has_samples ) {
237+
my (@samples) = @{$self->global_attr->samples};
238+
@samples = sort(@samples);
239+
$self->samples( \@samples );
240+
$self->app_log->info('Samples were defined in the global key.');
241+
$exists = 1;
242+
}
243+
244+
$self->write_sample_meta if $exists;
245+
return $exists;
246+
}
247+
228248
=head2 match_samples
229249
230250
Match samples based on regex written in sample_rule

t/lib/TestsFor/BioX/Workflow/Command/run/Test006.pm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,6 @@ sub test_002 {
154154

155155
}
156156

157-
sub create_times {
158-
my $now = DateTime->now( time_zone => 'local' );
159-
my $strp = DateTime::Format::Strptime->new(
160-
pattern => '%a %b %e %T %Y',
161-
time_zone => 'local',
162-
);
163-
164-
return $now, $strp;
165-
}
166-
167157
sub _init_rule {
168158
my $test = shift;
169159
my $rule = shift;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package TestsFor::BioX::Workflow::Command::run::Test007;
2+
3+
use Test::Class::Moose;
4+
use Cwd;
5+
use FindBin qw($Bin);
6+
use File::Path qw(make_path remove_tree);
7+
use Data::Dumper;
8+
use Capture::Tiny ':all';
9+
use BioX::Workflow::Command;
10+
use YAML::XS;
11+
use Data::Walk;
12+
use File::Slurp;
13+
use File::Spec;
14+
use DateTime;
15+
use DateTime::Format::Strptime;
16+
use Storable qw(dclone);
17+
18+
extends 'TestMethod::Base';
19+
20+
sub write_test_file {
21+
my $test_dir = shift;
22+
23+
my $fh;
24+
my $href = {
25+
global => [
26+
{ sample_rule => "Sample_.*" },
27+
{ root_dir => 'data/raw' },
28+
{ indir => '{$self->root_dir}' },
29+
{ outdir => 'data/processed' },
30+
{ find_sample_bydir => 1 },
31+
{ by_sample_outdir => 1 },
32+
{ chroms_list => [1,2,3,4,5]},
33+
{ samples => ['Sample_01']},
34+
],
35+
rules => [
36+
{
37+
t3_rule1 => {
38+
'local' => [
39+
{ root_dir => 'data/raw' },
40+
{
41+
INPUT =>
42+
'{$self->root_dir}/{$sample}/some_input_rule1.{$self->chunk}'
43+
},
44+
{ OUTPUT => ['some_output_rule1'] },
45+
{ use_chunks => 1 },
46+
],
47+
process =>
48+
'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT->[0]}',
49+
},
50+
},
51+
]
52+
};
53+
54+
#Write out the config
55+
open( $fh, ">$test_dir/conf/test1.1.yml" )
56+
or die print "Couldn't open file! $!";
57+
my $yaml = Dump $href;
58+
print $fh $yaml;
59+
close($fh);
60+
61+
make_path( $test_dir . "/data/raw/Sample_01" );
62+
make_path( $test_dir . "/data/raw/Sample_02" );
63+
write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" );
64+
write_file( $test_dir . "/data/raw/Sample_02/" . "some_input_rule1" );
65+
}
66+
67+
sub construct_tests {
68+
my $test_methods = TestMethod::Base->new();
69+
my $test_dir = $test_methods->make_test_dir();
70+
write_test_file($test_dir);
71+
72+
my $t = "$test_dir/conf/test1.1.yml";
73+
my $test = $test_methods->make_test_env($t);
74+
my $rules = $test->workflow_data->{rules};
75+
76+
return ( $test, $test_dir, $rules );
77+
}
78+
79+
sub test_001 {
80+
my ( $test, $test_dir, $rules ) = construct_tests;
81+
82+
$test->check_sample_exist;
83+
is_deeply($test->samples, ['Sample_01']);
84+
is_deeply($test->global_attr->chroms_list, [1,2,3,4,5]);
85+
86+
# $test->stdout(1);
87+
$test->set_rule_names;
88+
$test->filter_rule_keys;
89+
90+
foreach my $rule ( @{$rules} ) {
91+
_init_rule( $test, $rule );
92+
}
93+
94+
$test->post_process_rules;
95+
is_deeply($test->samples, ['Sample_01']);
96+
97+
diag Dumper ($test->global_attr->chroms_list);
98+
diag Dumper ($test->global_attr->samples);
99+
diag Dumper($test->global_attr->has_samples);
100+
101+
102+
ok(1);
103+
}
104+
105+
106+
sub _init_rule {
107+
my $test = shift;
108+
my $rule = shift;
109+
110+
$test->local_rule($rule);
111+
$test->process_rule;
112+
$test->p_rule_name( $test->rule_name );
113+
$test->p_local_attr( dclone( $test->local_attr ) );
114+
}

t/test_class_tests.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Test::Class::Moose::Runner->new(
1313
'TestsFor::BioX::Workflow::Command::run::Test004',
1414
'TestsFor::BioX::Workflow::Command::run::Test005',
1515
'TestsFor::BioX::Workflow::Command::run::Test006',
16+
'TestsFor::BioX::Workflow::Command::run::Test007',
1617
],
1718
)->runtests;

0 commit comments

Comments
 (0)