line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BioX::Workflow::Command::Utils::Files; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
541
|
use MooseX::App::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
6208
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
69
|
use MooseX::Types::Path::Tiny qw/AbsFile/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
2237
|
use File::Basename; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
66
|
|
8
|
1
|
|
|
1
|
|
5
|
use DateTime; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
9
|
1
|
|
|
1
|
|
5
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
10
|
1
|
|
|
1
|
|
6
|
use Config::Any; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
11
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
502
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
option 'workflow' => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => AbsFile, |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
coerce => 1, |
18
|
|
|
|
|
|
|
documentation => 'Supply a workflow', |
19
|
|
|
|
|
|
|
cmd_aliases => ['w'], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head3 workflow_data |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
initial config file read into a perl structure |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'workflow_data' => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'HashRef', |
31
|
|
|
|
|
|
|
default => sub { return {} }, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
option 'outfile' => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
default => sub { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $workflow = $self->workflow; |
41
|
|
|
|
|
|
|
my @files = fileparse( $self->workflow, qr/\.[^.]*/ ); |
42
|
|
|
|
|
|
|
my $dt = DateTime->now( time_zone => 'local' ); |
43
|
|
|
|
|
|
|
my $file_name = |
44
|
|
|
|
|
|
|
$files[0] . '_' . $dt->ymd . '_' . $dt->time('-') . '.sh'; |
45
|
|
|
|
|
|
|
return File::Spec->rel2abs( $file_name ); |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
documentation => 'Write your workflow to a file', |
48
|
|
|
|
|
|
|
cmd_aliases => ['o'], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
option 'stdout' => ( |
52
|
|
|
|
|
|
|
is => 'rw', |
53
|
|
|
|
|
|
|
isa => 'Bool', |
54
|
|
|
|
|
|
|
default => 0, |
55
|
|
|
|
|
|
|
documentation => 'Write workflows to STDOUT', |
56
|
|
|
|
|
|
|
predicate => 'has_stdout', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has 'fh' => ( |
60
|
|
|
|
|
|
|
is => 'rw', |
61
|
|
|
|
|
|
|
lazy => 1, |
62
|
|
|
|
|
|
|
default => sub { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
my $fh = new IO::File; |
65
|
|
|
|
|
|
|
if ( $self->stdout ) { |
66
|
|
|
|
|
|
|
$fh->fdopen( fileno(STDOUT), "w" ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
|
|
|
|
|
|
$fh->open( "> " . $self->outfile ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
return $fh; |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub load_yaml_workflow { |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $cfg; |
79
|
0
|
|
|
|
|
|
my @files = ( $self->workflow ); |
80
|
0
|
|
|
|
|
|
my $valid = 1; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->app_log->info( 'Loading workflow ' . $self->workflow . ' ...' ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
try { |
85
|
0
|
|
|
0
|
|
|
$cfg = Config::Any->load_files( { files => \@files, use_ext => 1 } ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
catch { |
88
|
0
|
|
|
0
|
|
|
$self->app_log->warn( |
89
|
|
|
|
|
|
|
"Unable to load your workflow. The following error was received.\n" |
90
|
|
|
|
|
|
|
); |
91
|
0
|
|
|
|
|
|
$self->app_log->warn("$_\n"); |
92
|
0
|
|
|
|
|
|
$valid = 0; |
93
|
0
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
$self->app_log->info('Your workflow is valid'."\n") if $valid; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#TODO Add Layering |
98
|
0
|
|
|
|
|
|
for (@$cfg) { |
99
|
0
|
|
|
|
|
|
my ( $filename, $config ) = %$_; |
100
|
0
|
|
|
|
|
|
$self->workflow_data($config); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ( !exists $self->workflow_data->{global} ) { |
104
|
0
|
|
|
|
|
|
$self->workflow_data->{global} = []; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $valid; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |