Skip to content

Commit 1bd2c2e

Browse files
committed
bug fix for outdirs
1 parent 16c602c commit 1bd2c2e

File tree

4 files changed

+54
-31
lines changed

4 files changed

+54
-31
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,14 @@ sub interpol_directive {
592592
my $source = shift;
593593
my $text = '';
594594

595-
# if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{\$/ ) {
596-
# return $self->interpol_directive_cache->{$source};
597-
# }
598-
599-
# if ( $source !~ m/{\$/ ) {
600-
# $self->interpol_directive_cache->{$source} = $source;
601-
# return $source;
602-
# }
595+
if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{\$/ ) {
596+
return $self->interpol_directive_cache->{$source};
597+
}
598+
599+
if ( $source !~ m/{\$/ ) {
600+
$self->interpol_directive_cache->{$source} = $source;
601+
return $source;
602+
}
603603

604604
my $template = Text::Template->new(
605605
TYPE => 'STRING',

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ EOF
520520
$self->app_log->fatal($rule_example);
521521
}
522522

523-
524523
=head3 template_process
525524
526525
Do the actual processing of the rule->process
@@ -594,7 +593,7 @@ sub check_iterables {
594593
#First check the global for any lists
595594
my $use_iters = $self->use_iterables;
596595

597-
$self->walk_indir_outdir($use_iters);
596+
# $self->walk_indir_outdir($use_iters);
598597

599598
if ( !$use_iters ) {
600599
$texts = $self->in_template_process( $sample, $texts );
@@ -642,8 +641,6 @@ sub walk_attr {
642641
my $attr = dclone( $self->local_attr );
643642
$self->check_indir_outdir($attr);
644643

645-
$DB::single = 2;
646-
647644
$attr->walk_process_data( $self->rule_keys );
648645

649646
return $attr;
@@ -655,6 +652,8 @@ sub eval_process {
655652
my $attr = $self->walk_attr;
656653
$attr->sample( $self->sample ) if $self->has_sample;
657654

655+
$self->walk_indir_outdir($attr);
656+
658657
my $process = $self->local_rule->{ $self->rule_name }->{process};
659658
my $text = $attr->interpol_directive($process);
660659
$text = clean_text($text);
@@ -701,43 +700,56 @@ sub get_keys {
701700
$self->rule_keys( \@global_keys );
702701
}
703702

704-
##TODO Clean this up and merge with the other walk_iterables
705703
##TODO Write more tests
706704
sub walk_indir_outdir {
707-
my $self = shift;
708-
my $use_iters = shift;
705+
my $self = shift;
706+
my $attr = shift;
709707

710-
##TODO This is redundant...
711-
my $attr = dclone( $self->local_attr );
712-
my $dummy_sample = $self->dummy_sample;
713-
$attr->sample($dummy_sample);
708+
my $text = $attr->interpol_directive( $attr->outdir );
714709

715-
if ( $attr->outdir =~ m/\{\$/ ) {
716-
$attr->walk_process_data( $self->rule_keys );
717-
}
710+
$DB::single = 2;
711+
$self->walk_indir_outdir_sample( $attr, $text );
712+
}
718713

719-
my $text = $attr->interpol_directive( $self->local_attr->outdir );
714+
sub walk_indir_outdir_sample {
715+
my $self = shift;
716+
my $attr = shift;
717+
my $text = shift;
720718

721-
if ( !$use_iters ) {
722-
foreach my $sample ( $attr->all_samples ) {
723-
my $new_text = $text;
724-
$new_text =~ s/$dummy_sample/$sample/g;
719+
my $use_iters = $self->use_iterables;
720+
my $dummy_sample = $self->dummy_sample;
721+
722+
foreach my $sample ( $attr->all_samples ) {
723+
my $new_text = $text;
724+
$new_text =~ s/$dummy_sample/$sample/g;
725+
$DB::single = 2;
726+
727+
if ($use_iters) {
728+
$self->walk_indir_outdir_iters( $use_iters, $attr,
729+
$new_text );
730+
}
731+
else {
725732
$new_text = path($new_text)->absolute if $attr->coerce_abs_dir;
726733
$new_text = path($new_text) if !$attr->coerce_abs_dir;
727734
$self->decide_create_outdir( $attr, $new_text );
728735
}
729-
return;
730736
}
737+
}
738+
739+
sub walk_indir_outdir_iters {
740+
my $self = shift;
741+
my $use_iters = shift;
742+
my $attr = shift;
743+
my $text = shift;
744+
745+
return unless $use_iters;
731746

732747
my $all = $use_iters->[0];
733748
my $elem = $use_iters->[1];
734749

735-
##TODO This should be a separate function
736750
my $dummy_iter = $self->dummy_iterable;
737751
$attr->$elem($dummy_iter);
738752

739-
##BUG FIX - If outdirs have iterables this will be bad
740-
741753
foreach my $chunk ( $self->local_attr->$all ) {
742754
my $new_text = $text;
743755
$new_text =~ s/$dummy_iter/$chunk/g;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ sub write_workflow_meta_start {
8989
$self->fh->say("$self->{comment_char} Starting Workflow\n");
9090
$self->fh->say("$self->{comment_char}");
9191
$self->fh->say("$self->{comment_char}");
92+
93+
94+
$self->fh->say("$self->{comment_char} Samples:");
95+
$self->fh->say("$self->{comment_char} \t".join(', ', @{$self->samples}));
96+
$self->fh->say("$self->{comment_char}");
97+
$self->fh->say("$self->{comment_char}");
98+
9299
$self->fh->say("$self->{comment_char} Global Variables:");
93100

94101
foreach my $k ( $self->all_global_keys ) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ sub test_002 {
134134
my ( $test, $test_dir, $rules ) = construct_tests;
135135

136136
$test->samples( [ 'Sample_01', 'Sample_02' ] );
137+
$test->global_attr->samples( [ 'Sample_01', 'Sample_02' ] );
137138

138139
# $test->stdout(1);
139140
$test->set_rule_names;
@@ -143,6 +144,9 @@ sub test_002 {
143144
_init_rule( $test, $rule );
144145
}
145146

147+
ok(-d 'data/processed/Sample_01', 'Sample Dir exists');
148+
ok(-d 'data/processed/Sample_02', 'Sample Dir exists');
149+
146150
# diag Dumper( $test->global_attr->some_list );
147151
# diag Dumper( $test->global_attr->use_somes );
148152
# diag Dumper( $test->global_attr->some );

0 commit comments

Comments
 (0)