Skip to content

Commit 4ca05a0

Browse files
committed
done
1 parent 1bd2c2e commit 4ca05a0

File tree

6 files changed

+140
-99
lines changed

6 files changed

+140
-99
lines changed

lib/BioX/Workflow/Command.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use File::Path qw(make_path);
1111

1212
app_strict 0;
1313

14-
# TODO move this after I have a better idea of where it is going
15-
# TODO nope
1614
option 'cache_dir' => (
1715
is => 'rw',
1816
isa => Path,
@@ -33,8 +31,9 @@ sub BUILD {
3331
before 'BUILD' => sub {
3432
my $self = shift;
3533

36-
# make_path( $self->cache_dir );
37-
# make_path(File::Spec->catdir($self->cache_dir, 'logs'));
34+
make_path( $self->cache_dir );
35+
make_path(File::Spec->catdir($self->cache_dir, 'logs'));
36+
make_path(File::Spec->catdir($self->cache_dir, 'workflows'));
3837
};
3938

4039
no Moose;

lib/BioX/Workflow/Command/run.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package BioX::Workflow::Command::run;
33
use v5.10;
44
use MooseX::App::Command;
55

6+
use File::Copy;
7+
68
extends 'BioX::Workflow::Command';
79
use BioX::Workflow::Command::Utils::Traits qw(ArrayRefOfStrs);
810
use BioX::Workflow::Command::run::Utils::Directives;
@@ -45,6 +47,9 @@ sub execute {
4547
$self->app_log->warn('Exiting now.');
4648
return;
4749
}
50+
51+
52+
copy($self->workflow, $self->cached_workflow );
4853
$self->apply_global_attributes;
4954
$self->get_global_keys;
5055
$self->get_samples;

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package BioX::Workflow::Command::run::Utils::Attributes;
33
use MooseX::App::Role;
44
use BioX::Workflow::Command::Utils::Traits qw(ArrayRefOfStrs);
55
use Storable qw(dclone);
6+
use File::Copy;
7+
use File::Spec;
8+
use File::Basename;
9+
use DateTime;
610

711
=head1 Name
812
@@ -34,6 +38,30 @@ option 'samples' => (
3438
cmd_aliases => ['s'],
3539
);
3640

41+
option 'run_stats' => (
42+
is => 'rw',
43+
isa => 'Bool',
44+
default => 1,
45+
);
46+
47+
has 'cached_workflow' => (
48+
is => 'rw',
49+
isa => 'Str',
50+
lazy => 1,
51+
default => '',
52+
default => sub {
53+
my $self = shift;
54+
55+
my ( $file, $dir, $ext ) = fileparse( $self->workflow, qr/\.[^.]*/ );
56+
my $now = DateTime->now;
57+
my $ymd = $now->ymd;
58+
my $hms = $now->hms;
59+
$hms =~ s/:/-/g;
60+
return File::Spec->catdir( $self->cache_dir, 'workflows',
61+
$file . "_$ymd" . "_$hms" . $ext );
62+
}
63+
);
64+
3765
=head2 Attributes
3866
3967
=cut

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

Lines changed: 102 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,27 @@ sub post_process_rules {
5858

5959
#Create flags for outputs that have a similar input
6060
$self->app_log->info();
61+
6162
# $self->app_log->info( 'Selected rules:' . "\t"
6263
# . join( ', ', @{ $self->select_rule_keys } )
6364
# . "\n" )
6465
# if $self->use_timestamps;
6566
# $self->app_log->info( 'Looking for orphan INPUTs '
6667
# . '(INPUTs with no corresponding OUTPUTs)' );
6768

68-
# my $rule_count = 0;
69-
# foreach my $rule ( $self->all_select_rule_keys ) {
70-
# ##Skip the first rule
71-
# if ( $rule_count == 0 ) {
72-
# $rule_count++;
73-
# next;
74-
# }
75-
# $self->check_input_output($rule);
76-
# }
77-
#
78-
#
79-
# $self->app_log->warn( "Found Orphan Inputs (inputs with no corresponding outputs)\n" . $self->orphan_table )
80-
# if $self->orphan_inputs;
69+
# my $rule_count = 0;
70+
# foreach my $rule ( $self->all_select_rule_keys ) {
71+
# ##Skip the first rule
72+
# if ( $rule_count == 0 ) {
73+
# $rule_count++;
74+
# next;
75+
# }
76+
# $self->check_input_output($rule);
77+
# }
78+
#
79+
#
80+
# $self->app_log->warn( "Found Orphan Inputs (inputs with no corresponding outputs)\n" . $self->orphan_table )
81+
# if $self->orphan_inputs;
8182

8283
$self->dedeps;
8384
$self->process_auto_deps;
@@ -88,7 +89,7 @@ sub post_process_rules {
8889
sub print_process_workflow {
8990
my $self = shift;
9091

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

9495
#TODO This should be named select_rule_names
@@ -102,9 +103,41 @@ sub print_process_workflow {
102103
$self->fh->say("");
103104
map { $self->fh->say($_) } @{$text};
104105

106+
$self->print_stats_rules($rule);
107+
105108
}
106109
}
107110

111+
sub print_stats_rules {
112+
my $self = shift;
113+
my $rule = shift;
114+
115+
return unless $self->run_stats;
116+
$self->fh->say("");
117+
118+
$self->fh->say( $self->comment_char );
119+
$self->fh->say(
120+
$self->comment_char . " Starting " . $rule . "_biox_stats" );
121+
$self->fh->say( $self->comment_char );
122+
$self->fh->say("");
123+
124+
$self->fh->say( $self->comment_char );
125+
$self->fh->say( '### HPC Directives' . "\n" );
126+
$self->fh->say( $self->comment_char );
127+
$self->fh->say( '#HPC jobname=' . $rule . "_biox_stats" );
128+
$self->fh->say( '#HPC deps=' . $rule );
129+
$self->fh->say('#HPC mem=2GB');
130+
$self->fh->say('#HPC cpus_per_task=1');
131+
$self->fh->say( $self->comment_char );
132+
$self->fh->say("");
133+
134+
$self->fh->say(
135+
"biox stats --samples " . join( ',', @{ $self->samples } ) . " \\" );
136+
$self->fh->say( "--select_rules " . $rule . " \\" );
137+
$self->fh->say( "-w " . $self->cached_workflow );
138+
$self->fh->say("");
139+
}
140+
108141
=head3 dedeps
109142
110143
If using select_rules comment out the #HPC deps portion on the first rule
@@ -165,67 +198,64 @@ sub process_auto_deps {
165198
my @text = split( "\n", $before_meta );
166199
$self->process_obj->{$rule}->{meta} = \@text;
167200
}
168-
169-
170201
}
171202

172203
#TODO Add in deps check
173204

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-
190-
sub check_input_output {
191-
my $self = shift;
192-
my $rule = shift;
193-
194-
#if this exists it means we already processed this through hpc-deps
195-
# return if exists $self->graph->{$rule};
196-
$self->graph->{$rule} = [] if !exists $self->graph->{$rule};
197-
198-
my @INPUTS = keys %{ $self->rule_deps->{$rule}->{INPUT} };
199-
200-
#TODO Add Seen
201-
202-
foreach my $srule ( $self->all_select_rule_keys ) {
203-
next if $srule eq $rule;
204-
my @trow = ();
205-
206-
my @inter = grep( $self->rule_deps->{$srule}->{OUTPUT}->{$_}, @INPUTS );
207-
if ( !@inter ) {
208-
$self->orphan_inputs(1);
209-
my @OUTPUTS = keys %{ $self->rule_deps->{$srule}->{OUTPUT} };
210-
map {
211-
my @matches = amatch( $_, @OUTPUTS );
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-
222-
} @INPUTS;
223-
}
224-
else {
225-
push( @{ $self->graph->{$rule} }, $srule );
226-
}
227-
}
228-
229-
}
205+
# has 'orphan_table' => (
206+
# is => 'rw',
207+
# default => sub {
208+
# my $self = shift;
209+
# my $t = Text::ASCIITable->new();
210+
# $t->setCols( [ 'Rule', 'INPUT', 'Possible Matches' ] );
211+
# return $t;
212+
# }
213+
# );
214+
#
215+
# has 'orphan_inputs' => (
216+
# is => 'rw',
217+
# isa => 'Bool',
218+
# default => 0,
219+
# );
220+
#
221+
# sub check_input_output {
222+
# my $self = shift;
223+
# my $rule = shift;
224+
#
225+
# #if this exists it means we already processed this through hpc-deps
226+
# # return if exists $self->graph->{$rule};
227+
# $self->graph->{$rule} = [] if !exists $self->graph->{$rule};
228+
#
229+
# my @INPUTS = keys %{ $self->rule_deps->{$rule}->{INPUT} };
230+
#
231+
# #TODO Add Seen
232+
#
233+
# foreach my $srule ( $self->all_select_rule_keys ) {
234+
# next if $srule eq $rule;
235+
# my @trow = ();
236+
#
237+
# my @inter = grep( $self->rule_deps->{$srule}->{OUTPUT}->{$_}, @INPUTS );
238+
# if ( !@inter ) {
239+
# $self->orphan_inputs(1);
240+
# my @OUTPUTS = keys %{ $self->rule_deps->{$srule}->{OUTPUT} };
241+
# map {
242+
# my @matches = amatch( $_, @OUTPUTS );
243+
# my @rels = map { path($_)->relative->stringify } @matches;
244+
# my $f = path($_)->relative->stringify;
245+
#
246+
# push( @trow, $rule );
247+
# push( @trow, $f );
248+
# push( @trow, join( "\n", @rels ) );
249+
# $self->orphan_table->addRow( \@trow );
250+
# $self->orphan_table->addRowLine();
251+
# @trow = ();
252+
#
253+
# } @INPUTS;
254+
# }
255+
# else {
256+
# push( @{ $self->graph->{$rule} }, $srule );
257+
# }
258+
# }
259+
# }
230260

231261
1;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ sub in_template_process {
628628
$self->local_attr->sample($sample);
629629
$self->sample($sample);
630630
my $text = $self->eval_process();
631-
my $log = $self->write_file_log();
632-
$text .= $log;
631+
# my $log = $self->write_file_log();
632+
# $text .= $log;
633633
push( @{$texts}, $text ) if $self->print_within_rule;
634634

635635
return $texts;

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,27 +269,6 @@ sub write_hpc_array_meta {
269269

270270
%lookup = %{$self->iter_hpc_array($self->global_attr->HPC, \%lookup)};
271271
%lookup = %{$self->iter_hpc_array($self->local_attr->HPC, \%lookup)};
272-
##TODO add in global hpc meta
273-
# foreach my $href ( @{ $self->global_attr->HPC } ) {
274-
# if ( ref($href) eq 'HASH' ) {
275-
# my @keys = keys %{$href};
276-
# map { $lookup{$_} = $href->{$_} } @keys;
277-
# }
278-
# else {
279-
# $self->warn_hpc_meta;
280-
# return;
281-
# }
282-
# }
283-
# foreach my $href ( @{ $self->local_attr->HPC } ) {
284-
# if ( ref($href) eq 'HASH' ) {
285-
# my @keys = keys %{$href};
286-
# map { $lookup{$_} = $href->{$_} } @keys;
287-
# }
288-
# else {
289-
# $self->warn_hpc_meta;
290-
# return;
291-
# }
292-
# }
293272

294273
if ( !exists $lookup{jobname} ) {
295274
$self->local_attr->add_before_meta(

0 commit comments

Comments
 (0)