Skip to content

Commit 16c602c

Browse files
committed
Merge branch 'master' into develop
2 parents 559b5b7 + 4cd615d commit 16c602c

File tree

5 files changed

+133
-81
lines changed

5 files changed

+133
-81
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/file_log.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ sub execute {
5757
next;
5858
}
5959

60+
##TODO Make this a table
6061
my $details = File::Details->new($file);
6162
my $mtime = ctime( stat($file)->mtime );
6263
# $self->track_files->{$file}->{mtime} = $mtime;

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} ) {
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: 119 additions & 69 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);
@@ -519,37 +520,6 @@ EOF
519520
$self->app_log->fatal($rule_example);
520521
}
521522

522-
=head3 carry_directives
523-
524-
At the beginning of each rule the previous outdir should be the new indir, and the previous OUTPUT should be the new INPUT
525-
526-
Stash should be carried over
527-
528-
Outdir should be global_attr->outdir/rule_name
529-
530-
=cut
531-
532-
sub carry_directives {
533-
my $self = shift;
534-
535-
$self->local_attr->outdir(
536-
$self->global_attr->outdir . '/' . $self->rule_name );
537-
538-
return unless $self->has_p_rule_name;
539-
540-
$self->local_attr->indir( dclone( $self->p_local_attr->outdir ) );
541-
542-
if ( $self->p_local_attr->has_OUTPUT ) {
543-
if ( ref( $self->p_local_attr->OUTPUT ) ) {
544-
$self->local_attr->INPUT( dclone( $self->p_local_attr->OUTPUT ) );
545-
}
546-
else {
547-
$self->local_attr->INPUT( $self->p_local_attr->OUTPUT );
548-
}
549-
}
550-
551-
$self->local_attr->stash( dclone( $self->p_local_attr->stash ) );
552-
}
553523

554524
=head3 template_process
555525
@@ -570,6 +540,7 @@ sub template_process {
570540

571541
my $dummy_sample = $self->dummy_sample;
572542
my $dummy_texts = $self->check_iterables( $dummy_sample, [] );
543+
573544
foreach my $sample ( $self->all_samples ) {
574545
foreach my $text ( @{$dummy_texts} ) {
575546
my $new_text = $text;
@@ -582,15 +553,6 @@ sub template_process {
582553

583554
$self->process_obj->{ $self->rule_name }->{meta} =
584555
$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-
# }
594556
}
595557

596558
sub use_iterables {
@@ -632,12 +594,14 @@ sub check_iterables {
632594
#First check the global for any lists
633595
my $use_iters = $self->use_iterables;
634596

635-
if ( ! $use_iters ) {
597+
$self->walk_indir_outdir($use_iters);
598+
599+
if ( !$use_iters ) {
636600
$texts = $self->in_template_process( $sample, $texts );
637601
return $texts;
638602
}
639603

640-
my $all = $use_iters->[0];
604+
my $all = $use_iters->[0];
641605
my $elem = $use_iters->[1];
642606

643607
##TODO This should be a separate function
@@ -653,7 +617,6 @@ sub check_iterables {
653617
push( @$texts, $new_text );
654618
}
655619
}
656-
##
657620

658621
return $texts;
659622
}
@@ -673,6 +636,35 @@ sub in_template_process {
673636
return $texts;
674637
}
675638

639+
sub walk_attr {
640+
my $self = shift;
641+
642+
my $attr = dclone( $self->local_attr );
643+
$self->check_indir_outdir($attr);
644+
645+
$DB::single = 2;
646+
647+
$attr->walk_process_data( $self->rule_keys );
648+
649+
return $attr;
650+
}
651+
652+
sub eval_process {
653+
my $self = shift;
654+
655+
my $attr = $self->walk_attr;
656+
$attr->sample( $self->sample ) if $self->has_sample;
657+
658+
my $process = $self->local_rule->{ $self->rule_name }->{process};
659+
my $text = $attr->interpol_directive($process);
660+
$text = clean_text($text);
661+
662+
$self->walk_FILES($attr);
663+
$self->clear_files;
664+
665+
return $text;
666+
}
667+
676668
sub get_global_keys {
677669
my $self = shift;
678670
my @global_keys = ();
@@ -709,45 +701,68 @@ sub get_keys {
709701
$self->rule_keys( \@global_keys );
710702
}
711703

712-
sub walk_attr {
713-
my $self = shift;
704+
##TODO Clean this up and merge with the other walk_iterables
705+
##TODO Write more tests
706+
sub walk_indir_outdir {
707+
my $self = shift;
708+
my $use_iters = shift;
714709

710+
##TODO This is redundant...
715711
my $attr = dclone( $self->local_attr );
716-
$self->check_indir_outdir($attr);
717-
718-
$DB::single = 2;
712+
my $dummy_sample = $self->dummy_sample;
713+
$attr->sample($dummy_sample);
719714

720-
$attr->walk_process_data( $self->rule_keys );
715+
if ( $attr->outdir =~ m/\{\$/ ) {
716+
$attr->walk_process_data( $self->rule_keys );
717+
}
721718

722-
if ( $attr->create_outdir && !$attr->outdir->is_dir ) {
719+
my $text = $attr->interpol_directive( $self->local_attr->outdir );
723720

724-
try {
725-
$attr->outdir->mkpath;
721+
if ( !$use_iters ) {
722+
foreach my $sample ( $attr->all_samples ) {
723+
my $new_text = $text;
724+
$new_text =~ s/$dummy_sample/$sample/g;
725+
$new_text = path($new_text)->absolute if $attr->coerce_abs_dir;
726+
$new_text = path($new_text) if !$attr->coerce_abs_dir;
727+
$self->decide_create_outdir( $attr, $new_text );
726728
}
727-
catch {
728-
$self->app_log->fatal( "We were not able to make the directory.\n\t"
729-
. $attr->outdir
730-
. "\n\tError: $!" );
731-
};
729+
return;
732730
}
733731

734-
return $attr;
735-
}
732+
my $all = $use_iters->[0];
733+
my $elem = $use_iters->[1];
736734

737-
sub eval_process {
738-
my $self = shift;
735+
##TODO This should be a separate function
736+
my $dummy_iter = $self->dummy_iterable;
737+
$attr->$elem($dummy_iter);
739738

740-
my $attr = $self->walk_attr;
741-
$attr->sample( $self->sample ) if $self->has_sample;
739+
##BUG FIX - If outdirs have iterables this will be bad
742740

743-
my $process = $self->local_rule->{ $self->rule_name }->{process};
744-
my $text = $attr->interpol_directive($process);
745-
$text = clean_text($text);
741+
foreach my $chunk ( $self->local_attr->$all ) {
742+
my $new_text = $text;
743+
$new_text =~ s/$dummy_iter/$chunk/g;
744+
$new_text = path($new_text)->absolute if $attr->coerce_abs_dir;
745+
$new_text = path($new_text) if !$attr->coerce_abs_dir;
746+
$self->decide_create_outdir( $attr, $new_text );
747+
}
748+
}
746749

747-
$self->walk_FILES($attr);
748-
$self->clear_files;
750+
sub decide_create_outdir {
751+
my $self = shift;
752+
my $attr = shift;
753+
my $dir = shift;
749754

750-
return $text;
755+
return unless $attr->create_outdir;
756+
return unless $dir;
757+
758+
try {
759+
$dir->mkpath;
760+
}
761+
catch {
762+
$self->app_log->fatal( "We were not able to make the directory.\n\t"
763+
. $attr->outdir
764+
. "\n\tError: $!" );
765+
};
751766
}
752767

753768
sub clean_text {
@@ -812,6 +827,8 @@ sub print_rule {
812827
return $print_rule;
813828
}
814829

830+
##This is not necessary without the use_timestamps
831+
##But I will leave it in as a placeholder
815832
sub print_within_rule {
816833
my $self = shift;
817834

@@ -851,6 +868,7 @@ sub check_indir_outdir {
851868

852869
# If indir/outdir is specified in the local config
853870
# then we don't evaluate it
871+
854872
foreach my $dir ( ( 'indir', 'outdir' ) ) {
855873
if ( grep /$dir/, @{ $self->local_rule_keys } ) {
856874
next;
@@ -875,4 +893,36 @@ sub check_indir_outdir {
875893

876894
}
877895

896+
=head3 carry_directives
897+
898+
At the beginning of each rule the previous outdir should be the new indir, and the previous OUTPUT should be the new INPUT
899+
900+
Stash should be carried over
901+
902+
Outdir should be global_attr->outdir/rule_name
903+
904+
=cut
905+
906+
sub carry_directives {
907+
my $self = shift;
908+
909+
$self->local_attr->outdir(
910+
$self->global_attr->outdir . '/' . $self->rule_name );
911+
912+
return unless $self->has_p_rule_name;
913+
914+
$self->local_attr->indir( dclone( $self->p_local_attr->outdir ) );
915+
916+
if ( $self->p_local_attr->has_OUTPUT ) {
917+
if ( ref( $self->p_local_attr->OUTPUT ) ) {
918+
$self->local_attr->INPUT( dclone( $self->p_local_attr->OUTPUT ) );
919+
}
920+
else {
921+
$self->local_attr->INPUT( $self->p_local_attr->OUTPUT );
922+
}
923+
}
924+
925+
$self->local_attr->stash( dclone( $self->p_local_attr->stash ) );
926+
}
927+
878928
1;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ sub get_samples {
162162
#But we don't keep it around, because that would be madness
163163
#TODO Fix this we should process these the same way we process rule names
164164
$attr = dclone( $self->global_attr );
165-
$DB::single = 2;
166-
if ( $attr->indir =~ m/\{\$self/ ) {
165+
# $DB::single = 2;
166+
if ( $attr->indir =~ m/\{\$/ ) {
167167
$attr->walk_process_data( $self->global_keys );
168168
}
169169

0 commit comments

Comments
 (0)