« lib/BioX/Workflow/Command/stats.pm
↑ Summary
lib/BioX/Workflow/Command/run/Rules/Directives/Types/Path.pm »
| 1 | package BioX::Workflow::Command::Utils::Files; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use MooseX::App::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use MooseX::Types::Path::Tiny qw/AbsFile/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use DateTime; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Config::Any; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | 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 | 0 | ▶ | default => sub { return {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 1 | ); | |||||||||
| 33 | |||||||||||
| 34 | option 'outfile' => ( | ||||||||||
| 35 | is => 'rw', | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 0 | my $self = shift; | |||||||||
| 40 | 0 | my $workflow = $self->workflow; | |||||||||
| 41 | 0 | my @files = fileparse( $self->workflow, qr/\.[^.]*/ ); | |||||||||
| 42 | 0 | my $dt = DateTime->now( time_zone => 'local' ); | |||||||||
| 43 | 0 | my $file_name = | |||||||||
| 44 | $files[0] . '_' . $dt->ymd . '_' . $dt->time('-') . '.sh'; | ||||||||||
| 45 | 0 | return File::Spec->rel2abs( $file_name ); | |||||||||
| 46 | }, | ||||||||||
| 47 | 1 | documentation => 'Write your workflow to a file', | |||||||||
| 48 | cmd_aliases => ['o'], | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | 1 | 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 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 63 | 0 | my $self = shift; | |||||||||
| 64 | 0 | my $fh = new IO::File; | |||||||||
| 65 | 0 | ▶ | if ( $self->stdout ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $fh->fdopen( fileno(STDOUT), "w" ); | |||||||||
| 67 | } | ||||||||||
| 68 | else { | ||||||||||
| 69 | 0 | $fh->open( "> " . $self->outfile ); | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | return $fh; | |||||||||
| 72 | }, | ||||||||||
| 73 | 1 | ); | |||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub load_yaml_workflow { | ||||||||
|
Subroutine
load_yaml_workflow: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 76 | 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 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 85 | 0 | $cfg = Config::Any->load_files( { files => \@files, use_ext => 1 } ); | |||||||||
| 86 | } | ||||||||||
| 87 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 88 | 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 | ▶ | $self->app_log->info('Your workflow is valid'."\n") if $valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | #TODO Add Layering | ||||||||||
| 98 | 0 | for (@$cfg) { | |||||||||
| 99 | 0 | my ( $filename, $config ) = %$_; | |||||||||
| 100 | 0 | $self->workflow_data($config); | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 0 | ▶ | if ( !exists $self->workflow_data->{global} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 0 | $self->workflow_data->{global} = []; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | $self->get_line_declarations if $valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | |||||||||||
| 109 | 0 | return $valid; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 1 | 1; | |||||||||