Skip to content

Commit eb50e47

Browse files
committed
fixes Issue #19
1 parent 224a5bc commit eb50e47

File tree

4 files changed

+133
-12
lines changed

4 files changed

+133
-12
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
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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/12 The special HPC var
24+
supports arrays and hashes, but it wasn't properly dealt with when they were
25+
mixed and matched
26+
27+
=cut
28+
29+
sub write_test_file {
30+
my $test_dir = shift;
31+
32+
my $fh;
33+
my $href = {
34+
global => [
35+
{ sample_rule => "Sample_.*" },
36+
{ root_dir => 'data/analysis' },
37+
{ root_dir => 'data/analysis' },
38+
{ indir => 'data/raw' },
39+
{ outdir => 'data/processed' },
40+
{jellyfish_dir => 'data/JELLYFISH/{$sample}/jellyfish'},
41+
{ find_sample_bydir => 1 },
42+
{ by_sample_outdir => 1 },
43+
{ HPC => [{account => 'gencore'}] },
44+
],
45+
rules => [
46+
{
47+
pre_assembly_jellyfish_count => {
48+
'local' => [
49+
{ root_dir => 'data/raw' },
50+
{ outdir => '{$self->jellyfish_dir}' },
51+
# { outdir => 'data/THING' },
52+
{
53+
INPUT =>
54+
'{$self->jellyfish_dir}/some_input_rule1'
55+
},
56+
{ OUTPUT => '{$self->jellyfish_dir}/some_input_rule1' },
57+
{ HPC => [{'deps' => 'some_dep'}]}
58+
],
59+
process =>
60+
'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT}',
61+
},
62+
},
63+
]
64+
};
65+
66+
#Write out the config
67+
open( $fh, ">$test_dir/conf/test1.1.yml" )
68+
or die print "Couldn't open file! $!";
69+
my $yaml = Dump $href;
70+
print $fh $yaml;
71+
close($fh);
72+
73+
make_path( $test_dir . "/data/raw/Sample_01" );
74+
write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" );
75+
}
76+
77+
sub construct_tests {
78+
my $test_methods = TestMethod::Base->new();
79+
my $test_dir = $test_methods->make_test_dir();
80+
write_test_file($test_dir);
81+
82+
my $t = "$test_dir/conf/test1.1.yml";
83+
my $test = $test_methods->make_test_env($t);
84+
my $rules = $test->workflow_data->{rules};
85+
86+
return ( $test, $test_dir, $rules );
87+
}
88+
89+
sub test_001 {
90+
my ( $test, $test_dir, $rules ) = construct_tests;
91+
92+
$test->set_rule_names;
93+
$test->filter_rule_keys;
94+
95+
foreach my $rule ( @{$rules} ) {
96+
_init_rule( $test, $rule );
97+
}
98+
99+
$test->post_process_rules;
100+
is_deeply($test->samples, ['Sample_01']);
101+
102+
diag(Dumper(system("tree data")));
103+
ok(1);
104+
}
105+
106+
107+
sub _init_rule {
108+
my $test = shift;
109+
my $rule = shift;
110+
111+
$test->local_rule($rule);
112+
$test->process_rule;
113+
$test->p_rule_name( $test->rule_name );
114+
$test->p_local_attr( dclone( $test->local_attr ) );
115+
}

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)