Skip to content

Commit cca4d01

Browse files
committed
finished
1 parent 38a47ea commit cca4d01

File tree

8 files changed

+169
-56
lines changed

8 files changed

+169
-56
lines changed

lib/BioX/Workflow/Command/file_log.pm

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,33 @@ option 'files' => (
3737
},
3838
);
3939

40+
#Put a default to keep from breaking backwards compatibility
41+
option 'exit_code' => (
42+
is => 'rw',
43+
required => 0,
44+
default => 0,
45+
);
4046

4147
sub execute {
42-
my $self = shift;
48+
my $self = shift;
4349

44-
foreach my $file ($self->all_files){
50+
foreach my $file ( $self->all_files ) {
4551

46-
if(-e $file){
47-
$self->app_log->info('File '.$file.' exists');
48-
}
49-
else{
50-
$self->app_log->info('File '.$file.' does not exist');
51-
next;
52+
if ( -e $file ) {
53+
$self->app_log->info( 'File ' . $file . ' exists' );
54+
}
55+
else {
56+
$self->app_log->info( 'File ' . $file . ' does not exist' );
57+
next;
58+
}
59+
60+
my $details = File::Details->new($file);
61+
my $mtime = ctime( stat($file)->mtime );
62+
$self->track_files->{$file}->{mtime} = $mtime;
5263
}
5364

54-
my $details = File::Details->new($file);
55-
my $mtime = ctime( stat($file)->mtime );
56-
$self->track_files->{$file}->{mtime} = $mtime;
57-
}
65+
#Preserve the exit code of the previous process
66+
exit($self->exit_code);
5867

5968
}
6069

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ sub apply_local_attr {
174174

175175
$self->local_attr->create_attr(
176176
$self->local_rule->{ $self->rule_name }->{local} );
177+
177178
}
178179

179180
sub apply_global_attributes {

lib/BioX/Workflow/Command/run/Utils/Files/ResolveDeps.pm

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use String::Approx 'amatch';
55
use Algorithm::Dependency::Source::HoA;
66
use Algorithm::Dependency::Ordered;
77
use Try::Tiny;
8+
use Path::Tiny;
9+
use Text::ASCIITable;
810
use Data::Dumper;
911

1012
# Not even close to this yet
@@ -60,13 +62,23 @@ sub post_process_rules {
6062
. join( ', ', @{ $self->select_rule_keys } )
6163
. "\n" )
6264
if $self->use_timestamps;
63-
$self->app_log->info( 'Looking for orphan INPUTs '
64-
. '(INPUTs with no corresponding OUTPUTs)' );
65+
# $self->app_log->info( 'Looking for orphan INPUTs '
66+
# . '(INPUTs with no corresponding OUTPUTs)' );
6567

68+
my $rule_count = 0;
6669
foreach my $rule ( $self->all_select_rule_keys ) {
70+
##Skip the first rule
71+
if ( $rule_count == 0 ) {
72+
$rule_count++;
73+
next;
74+
}
6775
$self->check_input_output($rule);
6876
}
6977

78+
79+
$self->app_log->warn( "Found Orphan Inputs (inputs with no corresponding outputs)\n" . $self->orphan_table )
80+
if $self->orphan_inputs;
81+
7082
$self->dedeps;
7183
$self->process_auto_deps;
7284

@@ -76,12 +88,12 @@ sub post_process_rules {
7688
sub print_process_workflow {
7789
my $self = shift;
7890

91+
$self->app_log->info( 'Post processing rules and printing workflow...' );
7992
foreach my $rule ( $self->all_rule_names ) {
8093

8194
#TODO This should be named select_rule_names
8295
my $index = $self->first_index_select_rule_keys( sub { $_ eq $rule } );
8396
next if $index == -1;
84-
$self->app_log->info( 'Post processing ' . $rule );
8597

8698
my $meta = $self->process_obj->{$rule}->{meta} || [];
8799
my $text = $self->process_obj->{$rule}->{text} || [];
@@ -148,16 +160,33 @@ sub process_auto_deps {
148160
my @deps = @{ $self->graph->{$rule} };
149161
if (@deps) {
150162
chomp($before_meta);
151-
$before_meta .= "\n#HPC deps=" . join( ',', @deps )."\n\n";
163+
$before_meta .= "\n#HPC deps=" . join( ',', @deps ) . "\n\n";
152164
}
153165
my @text = split( "\n", $before_meta );
154166
$self->process_obj->{$rule}->{meta} = \@text;
155167
}
156168

169+
157170
}
158171

159172
#TODO Add in deps check
160173

174+
has 'orphan_table' => (
175+
is => 'rw',
176+
default => sub {
177+
my $self = shift;
178+
my $t = Text::ASCIITable->new();
179+
$t->setCols( [ 'Rule', 'INPUT', 'Possible Matches' ] );
180+
return $t;
181+
}
182+
);
183+
184+
has 'orphan_inputs' => (
185+
is => 'rw',
186+
isa => 'Bool',
187+
default => 0,
188+
);
189+
161190
sub check_input_output {
162191
my $self = shift;
163192
my $rule = shift;
@@ -172,17 +201,24 @@ sub check_input_output {
172201

173202
foreach my $srule ( $self->all_select_rule_keys ) {
174203
next if $srule eq $rule;
204+
my @trow = ();
175205

176206
my @inter = grep( $self->rule_deps->{$srule}->{OUTPUT}->{$_}, @INPUTS );
177207
if ( !@inter ) {
208+
$self->orphan_inputs(1);
178209
my @OUTPUTS = keys %{ $self->rule_deps->{$srule}->{OUTPUT} };
179210
map {
180211
my @matches = amatch( $_, @OUTPUTS );
181-
$self->app_log->warn( "Orphan INPUT:"
182-
. "\tRule: $rule File: $_\n"
183-
. "\tPossible matches include "
184-
. join( ", ", @matches ) )
185-
if @matches
212+
my @rels = map { path($_)->relative->stringify } @matches;
213+
my $f = path($_)->relative->stringify;
214+
215+
push( @trow, $rule );
216+
push( @trow, $f );
217+
push( @trow, join( "\n", @rels ) );
218+
$self->orphan_table->addRow( \@trow );
219+
$self->orphan_table->addRowLine();
220+
@trow = ();
221+
186222
} @INPUTS;
187223
}
188224
else {

lib/BioX/Workflow/Command/run/Utils/Files/TrackChanges.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ sub walk_FILES {
7171
$self->add_graph('INPUT');
7272
$self->clear_files;
7373

74-
$self->app_log->info('Between checks...');
74+
# $self->app_log->info('Between checks...');
7575
my $mod_output = $self->pre_FILES( $attr, 'OUTPUT' );
7676
$self->add_graph('OUTPUT');
7777
$self->clear_files;
@@ -85,7 +85,7 @@ sub pre_FILES {
8585
my $attr = shift;
8686
my $cond = shift;
8787

88-
$self->app_log->info( 'Beginning modification checks for ' . $cond );
88+
# $self->app_log->info( 'Beginning modification checks for ' . $cond );
8989
# REF check?
9090
walk {
9191
wanted => sub { $self->walk_INPUT(@_) }
@@ -167,9 +167,9 @@ sub flag_for_process {
167167
my $basename = basename($file);
168168

169169
#TO LOG OR NOT TO LOG
170-
$self->app_log->info(
170+
$self->app_log->warn(
171171
'File ' . $file . ' has been modified since your last analysis.' );
172-
$self->app_log->info( $basename
172+
$self->app_log->warn( $basename
173173
. ":\n\tLast Recorded Modification:\t"
174174
. $p_mtime
175175
. "\n\tMost Recent Modification:\t"
@@ -252,6 +252,7 @@ sub write_file_log {
252252
$text = <<EOF;
253253
; \\
254254
biox file_log \\
255+
\t--exit_code `echo \$\?` \\
255256
EOF
256257
}
257258

@@ -261,7 +262,7 @@ EOF
261262
\t--file $file \\
262263
EOF
263264
}
264-
$text .= "\t--file $last\n\n";
265+
$text .= "\t--file $last\n\n" if $last;
265266

266267
return $text;
267268
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,22 @@ sub sanity_check_rule {
433433

434434
my @keys = keys %{ $self->local_rule };
435435

436-
$self->app_log->info("");
437-
$self->app_log->info("Beginning sanity check");
436+
# $self->app_log->info("");
437+
# $self->app_log->info("Beginning sanity check");
438438
if ( $#keys != 0 ) {
439-
$self->app_log->fatal('You should only have one rule name!');
439+
$self->app_log->fatal(
440+
'Sanity check fail: There should be one rule name!');
440441
$self->sanity_check_fail;
441442
return;
442443
}
443444

444445
$self->rule_name( $keys[0] );
445-
$self->app_log->info( 'Sanity check on rule ' . $self->rule_name );
446+
447+
# $self->app_log->info( 'Sanity check on rule ' . $self->rule_name );
446448

447449
if ( !exists $self->local_rule->{ $self->rule_name }->{process} ) {
448-
$self->app_log->fatal('Your rule does not have a process!');
450+
$self->app_log->fatal(
451+
'Sanity check fail: Rule does not have a process!');
449452
$self->sanity_check_fail;
450453
return;
451454
}
@@ -458,7 +461,8 @@ sub sanity_check_rule {
458461

459462
if ( !ref($ref) eq 'ARRAY' ) {
460463
$self->app_log->fatal(
461-
'Your variable declarations should begin with an array!');
464+
'Sanity check fail: Your variable declarations should begin with an array!'
465+
);
462466
$self->sanity_check_fail;
463467
return;
464468
}
@@ -537,7 +541,7 @@ Do the actual processing of the rule->process
537541
=cut
538542

539543
sub template_process {
540-
my $self = shift;
544+
my $self = shift;
541545
my $texts = [];
542546

543547
#TODO we should not just spit this out as it compare_mtimes
@@ -550,7 +554,7 @@ sub template_process {
550554
##TODO for modify chunks
551555
foreach my $sample ( $self->all_samples ) {
552556

553-
$texts = $self->check_chunks($sample, $texts);
557+
$texts = $self->check_chunks( $sample, $texts );
554558
}
555559

556560
$self->process_obj->{ $self->rule_name }->{text} = $texts;
@@ -595,9 +599,6 @@ sub in_template_process {
595599
my $sample = shift;
596600
my $texts = shift;
597601

598-
$self->app_log->info(
599-
'Processing Rule: ' . $self->rule_name . ' Sample: ' . $sample );
600-
601602
$self->local_attr->sample($sample);
602603
$self->sample($sample);
603604
my $text = $self->eval_process();

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Could have
143143
144144
=cut
145145

146+
##TODO Add files
147+
146148
sub get_samples {
147149
my $self = shift;
148150
my ( @whole, @basename, $find_sample_bydir, $text, $attr );
@@ -159,8 +161,8 @@ sub get_samples {
159161
#We need to evaluate the global_dirs incase the indir has a var
160162
#But we don't keep it around, because that would be madness
161163
#TODO Fix this we should process these the same way we process rule names
162-
$attr = dclone( $self->global_attr );
163-
$DB::single=2;
164+
$attr = dclone( $self->global_attr );
165+
$DB::single = 2;
164166
if ( $attr->indir =~ m/\{\$self/ ) {
165167
$attr->walk_process_data( $self->global_keys );
166168
}
@@ -176,9 +178,10 @@ sub get_samples {
176178

177179
if ( $attr->find_sample_bydir ) {
178180
@whole = find(
179-
directory => name => qr/$text/,
181+
directory => name => qr/$text/,
180182
maxdepth => 1,
181-
in => $attr->indir
183+
in => $attr->indir,
184+
extras => { follow => 1 },
182185
);
183186

184187
if (@whole) {
@@ -193,8 +196,9 @@ sub get_samples {
193196
}
194197
else {
195198
@whole = find(
196-
file => name => qr/$text/,
199+
file => name => qr/$text/,
197200
maxdepth => 1,
201+
extras => { follow => 1 },
198202
in => $attr->indir
199203
);
200204

0 commit comments

Comments
 (0)