Skip to content

Commit 2cd170b

Browse files
committed
fixed indir/outdir with dummy samplesa nd iterables
1 parent 261eb0e commit 2cd170b

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

lib/BioX/Workflow/Command.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use File::Path qw(make_path);
1212
app_strict 0;
1313

1414
# TODO move this after I have a better idea of where it is going
15+
# TODO nope
1516
option 'cache_dir' => (
1617
is => 'rw',
1718
isa => Path,
@@ -32,8 +33,8 @@ sub BUILD {
3233
before 'BUILD' => sub {
3334
my $self = shift;
3435

35-
make_path( $self->cache_dir );
36-
make_path(File::Spec->catdir($self->cache_dir, 'logs'));
36+
# make_path( $self->cache_dir );
37+
# make_path(File::Spec->catdir($self->cache_dir, 'logs'));
3738
};
3839

3940
no Moose;

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

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use Data::Walk;
77
use Data::Dumper;
88
use File::Path qw(make_path remove_tree);
99
use Try::Tiny;
10+
use Path::Tiny;
1011

1112
with 'BioX::Workflow::Command::Utils::Files::TrackChanges';
1213
use BioX::Workflow::Command::Utils::Traits qw(ArrayRefOfStrs);
@@ -582,15 +583,6 @@ sub template_process {
582583

583584
$self->process_obj->{ $self->rule_name }->{meta} =
584585
$self->write_rule_meta('before_meta');
585-
586-
# return unless $self->use_timestamps;
587-
# if ( $self->local_attr->{_modified} ) {
588-
# $self->app_log->info(
589-
# 'One or more files were modified or are not logged for this rule');
590-
# }
591-
# else {
592-
# $self->app_log->info('Zero files were modified for this rule');
593-
# }
594586
}
595587

596588
sub use_iterables {
@@ -632,12 +624,14 @@ sub check_iterables {
632624
#First check the global for any lists
633625
my $use_iters = $self->use_iterables;
634626

635-
if ( ! $use_iters ) {
627+
$self->walk_indir_outdir($use_iters);
628+
629+
if ( !$use_iters ) {
636630
$texts = $self->in_template_process( $sample, $texts );
637631
return $texts;
638632
}
639633

640-
my $all = $use_iters->[0];
634+
my $all = $use_iters->[0];
641635
my $elem = $use_iters->[1];
642636

643637
##TODO This should be a separate function
@@ -709,31 +703,81 @@ sub get_keys {
709703
$self->rule_keys( \@global_keys );
710704
}
711705

712-
sub walk_attr {
713-
my $self = shift;
706+
##TODO Clean this up and merge with the other walk_iterables
707+
sub walk_indir_outdir {
708+
my $self = shift;
709+
my $use_iters = shift;
714710

715711
my $attr = dclone( $self->local_attr );
716712
$self->check_indir_outdir($attr);
717713

718-
$DB::single = 2;
714+
my $dummy_sample = $self->dummy_sample;
715+
$attr->sample($dummy_sample);
716+
my $text = $attr->interpol_directive( $attr->outdir );
719717

720-
$attr->walk_process_data( $self->rule_keys );
718+
if ( !$use_iters ) {
719+
foreach my $sample ( $attr->all_samples ) {
720+
my $new_text = $text;
721+
$new_text =~ s/$dummy_sample/$sample/g;
722+
$new_text = path($new_text)->absolute if $attr->coerce_abs_dir;
723+
$new_text = path($new_text) if !$attr->coerce_abs_dir;
724+
$self->decide_create_outdir( $attr, $new_text );
725+
}
726+
return;
727+
}
728+
729+
my $all = $use_iters->[0];
730+
my $elem = $use_iters->[1];
731+
732+
##TODO This should be a separate function
733+
my $dummy_iter = $self->dummy_iterable;
734+
$attr->$elem($dummy_iter);
721735

722-
if ( $attr->create_outdir && !$attr->outdir->is_dir ) {
736+
foreach my $chunk ( $self->local_attr->$all ) {
737+
my $new_text = $text;
738+
$new_text =~ s/$dummy_iter/$chunk/g;
739+
$new_text = path($new_text)->absolute if $attr->coerce_abs_dir;
740+
$new_text = path($new_text) if !$attr->coerce_abs_dir;
741+
$self->decide_create_outdir( $attr, $new_text );
742+
}
743+
}
744+
745+
sub decide_create_outdir {
746+
my $self = shift;
747+
my $attr = shift;
748+
my $dir = shift;
749+
750+
if ( $attr->create_outdir ) {
723751

724752
try {
725-
$attr->outdir->mkpath;
753+
$dir->mkpath;
726754
}
727755
catch {
728756
$self->app_log->fatal( "We were not able to make the directory.\n\t"
729757
. $attr->outdir
730758
. "\n\tError: $!" );
731759
};
732760
}
761+
}
762+
763+
sub walk_attr {
764+
my $self = shift;
765+
766+
my $attr = dclone( $self->local_attr );
767+
$self->check_indir_outdir($attr);
768+
769+
$DB::single = 2;
770+
771+
$attr->walk_process_data( $self->rule_keys );
733772

734773
return $attr;
735774
}
736775

776+
sub make_outdirs {
777+
my $self = shift;
778+
779+
}
780+
737781
sub eval_process {
738782
my $self = shift;
739783

0 commit comments

Comments
 (0)