Skip to content

Commit f38e9f1

Browse files
committed
Merge branch 'develop'
2 parents e91cb04 + 4bb81ee commit f38e9f1

File tree

5 files changed

+138
-13
lines changed

5 files changed

+138
-13
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,12 @@ sub walk_indir_outdir_sample {
696696
my $attr = shift;
697697
my $text = shift;
698698

699+
$DB::single = 2;
699700
my $use_iters = $self->use_iterables;
700701
my $dummy_sample = $self->dummy_sample;
701702

703+
my @samples = @{$attr->samples} if $attr->has_samples;
704+
702705
foreach my $sample ( $attr->all_samples ) {
703706
my $new_text = $text;
704707
$new_text =~ s/$dummy_sample/$sample/g;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ sub get_samples {
167167

168168
#Backwards compatibility
169169
#For both file_rule and sample_rule
170-
if ( $self->first_index_global_keys( sub { $_ eq 'sample_rule' } ) != -1 ) {
170+
if ( $self->first_index_global_keys( sub { $_ eq 'file_rule' } ) != -1 )
171+
{
171172
$text = $self->global_attr->sample_rule;
172173
}
173-
elsif ( $self->first_index_global_keys( sub { $_ eq 'file_rule' } ) != -1 )
174-
{
174+
elsif ( $self->first_index_global_keys( sub { $_ eq 'sample_rule' } ) != -1 ) {
175175
$text = $self->global_attr->sample_rule;
176176
}
177177
else {
@@ -234,6 +234,8 @@ sub check_sample_exist {
234234
if ( $self->has_samples && !$self->resample ) {
235235
my (@samples) = $self->sorted_samples;
236236
$self->samples( \@samples );
237+
## Fixes Issue #19
238+
$self->global_attr->samples(\@samples);
237239
$self->app_log->info('Samples passed in on command line.');
238240
$exists = 1;
239241
}

t/lib/TestMethod/Base.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ sub make_test_dir {
3333
sub make_test_env {
3434
my $self = shift;
3535
my $workflow = shift;
36+
my $args = shift || [];
3637

37-
MooseX::App::ParsedArgv->new( argv => [ "run", "--workflow", $workflow ] );
38+
my $init_args = [ "run", "--workflow", $workflow ];
39+
if($args && ref($args) eq 'ARRAY'){
40+
map { push (@{$init_args}, $_) } @{$args};
41+
}
42+
43+
MooseX::App::ParsedArgv->new( argv => $init_args );
3844

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package TestsFor::BioX::Workflow::Command::run::Test009;
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+
=head1 Purpose
21+
22+
This tests references -
23+
https://github.com/biosails/BioX-Workflow-Command/issues/19 Refactoring the
24+
'check_sample_exists' function didn't add the samples to the global samples attr
25+
26+
=cut
27+
28+
sub write_test_file {
29+
my $test_dir = shift;
30+
31+
my $fh;
32+
my $href = {
33+
global => [
34+
{ sample_rule => "Sample_.*" },
35+
{ root_dir => 'data/analysis' },
36+
{ root_dir => 'data/analysis' },
37+
{ indir => 'data/raw' },
38+
{ outdir => 'data/processed' },
39+
{ jellyfish_dir => 'data/analysis/{$sample}/jellyfish' },
40+
{ find_sample_bydir => 1 },
41+
{ by_sample_outdir => 1 },
42+
{ HPC => [ { account => 'gencore' } ] },
43+
],
44+
rules => [
45+
{
46+
pre_assembly_jellyfish_count => {
47+
'local' => [
48+
{ root_dir => 'data/raw' },
49+
{ outdir => '{$self->jellyfish_dir}' },
50+
{
51+
INPUT => '{$self->jellyfish_dir}/some_input_rule1'
52+
},
53+
{ OUTPUT => '{$self->jellyfish_dir}/some_input_rule1' },
54+
{ HPC => [ { 'deps' => 'some_dep' } ] }
55+
],
56+
process =>
57+
'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT}',
58+
},
59+
},
60+
]
61+
};
62+
63+
#Write out the config
64+
open( $fh, ">$test_dir/conf/test1.1.yml" )
65+
or die print "Couldn't open file! $!";
66+
my $yaml = Dump $href;
67+
print $fh $yaml;
68+
close($fh);
69+
70+
make_path( $test_dir . "/data/raw/Sample_01" );
71+
write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" );
72+
}
73+
74+
sub construct_tests {
75+
my $test_methods = TestMethod::Base->new();
76+
my $test_dir = $test_methods->make_test_dir();
77+
78+
write_test_file($test_dir);
79+
80+
my $t = "$test_dir/conf/test1.1.yml";
81+
my $test = $test_methods->make_test_env( $t, [ '--samples', 'Sample_01' ] );
82+
my $rules = $test->workflow_data->{rules};
83+
84+
return ( $test, $test_dir, $rules );
85+
}
86+
87+
sub test_001 {
88+
my ( $test, $test_dir, $rules ) = construct_tests;
89+
90+
$test->set_rule_names;
91+
$test->filter_rule_keys;
92+
93+
foreach my $rule ( @{$rules} ) {
94+
_init_rule( $test, $rule );
95+
}
96+
97+
$test->post_process_rules;
98+
is_deeply( $test->samples, ['Sample_01'] );
99+
100+
ok((-d 'data/analysis/Sample_01/jellyfish'));
101+
102+
ok(1);
103+
}
104+
105+
sub _init_rule {
106+
my $test = shift;
107+
my $rule = shift;
108+
109+
$test->local_rule($rule);
110+
$test->process_rule;
111+
$test->p_rule_name( $test->rule_name );
112+
$test->p_local_attr( dclone( $test->local_attr ) );
113+
}

t/test_class_tests.t

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use Test::Class::Moose::Runner;
77

88
Test::Class::Moose::Runner->new(
99
test_classes => [
10-
'TestsFor::BioX::Workflow::Command::Test001',
11-
'TestsFor::BioX::Workflow::Command::run::Test001',
12-
'TestsFor::BioX::Workflow::Command::run::Test002',
13-
'TestsFor::BioX::Workflow::Command::run::Test003',
14-
'TestsFor::BioX::Workflow::Command::run::Test004',
15-
'TestsFor::BioX::Workflow::Command::run::Test005',
16-
'TestsFor::BioX::Workflow::Command::run::Test006',
17-
'TestsFor::BioX::Workflow::Command::run::Test007',
18-
'TestsFor::BioX::Workflow::Command::run::Test008',
10+
# 'TestsFor::BioX::Workflow::Command::Test001',
11+
# 'TestsFor::BioX::Workflow::Command::run::Test001',
12+
# 'TestsFor::BioX::Workflow::Command::run::Test002',
13+
# 'TestsFor::BioX::Workflow::Command::run::Test003',
14+
# 'TestsFor::BioX::Workflow::Command::run::Test004',
15+
# 'TestsFor::BioX::Workflow::Command::run::Test005',
16+
# 'TestsFor::BioX::Workflow::Command::run::Test006',
17+
# 'TestsFor::BioX::Workflow::Command::run::Test007',
18+
# 'TestsFor::BioX::Workflow::Command::run::Test008',
19+
'TestsFor::BioX::Workflow::Command::run::Test009',
1920
],
2021
)->runtests;

0 commit comments

Comments
 (0)