Skip to content

Commit 41649ee

Browse files
committed
Merge branch 'develop'
2 parents 483ca4d + 0a1d877 commit 41649ee

File tree

7 files changed

+144
-102
lines changed

7 files changed

+144
-102
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: 105 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,6 +103,41 @@ sub print_process_workflow {
102103
$self->fh->say("");
103104
map { $self->fh->say($_) } @{$text};
104105

106+
$self->print_stats_rules($rule);
107+
108+
}
109+
}
110+
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+
foreach my $sample ($self->all_samples){
135+
$self->fh->say("");
136+
$self->fh->say(
137+
"biox stats --samples " . $sample . " \\" );
138+
$self->fh->say( "--select_rules " . $rule . " \\" );
139+
$self->fh->say( "-w " . $self->cached_workflow );
140+
$self->fh->say("");
105141
}
106142
}
107143

@@ -165,67 +201,64 @@ sub process_auto_deps {
165201
my @text = split( "\n", $before_meta );
166202
$self->process_obj->{$rule}->{meta} = \@text;
167203
}
168-
169-
170204
}
171205

172206
#TODO Add in deps check
173207

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

231264
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(

lib/BioX/Workflow/Command/stats.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ sub gen_row {
148148

149149
my $rel = '';
150150
$rel = File::Spec->abs2rel($file) if $self->use_full;
151-
$rel = basename($file);
151+
$rel = basename($file) unless $self->use_full;
152152

153153
#Add the filename
154154
push( @trow, $rel );
@@ -168,7 +168,6 @@ sub gen_row {
168168
}
169169
$self->table_log->addRow( \@trow );
170170
}
171-
172171
}
173172

174173
sub iter_file_samples {
@@ -192,7 +191,6 @@ sub iter_file_samples {
192191
}
193192
$self->gen_row( $file, $cond, $sample, \@sample_files );
194193
}
195-
196194
}
197195

198196
sub iter_file_chunks {

0 commit comments

Comments
 (0)