« lib/BioX/Workflow/Command/Utils/Files.pm
↑ Summary
lib/BioX/Workflow/Command/run/Rules/Directives/Types/Roles/File.pm »
| 1 | package BioX::Workflow::Command::run::Rules::Directives::Types::Path; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose::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/Path Paths AbsPath AbsFile/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Data::Walk 2.01; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head2 File Options | ||||||||||
| 12 | |||||||||||
| 13 | =head3 indir outdir | ||||||||||
| 14 | |||||||||||
| 15 | The initial indir is where samples are found | ||||||||||
| 16 | |||||||||||
| 17 | All output is written relative to the outdir | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | has 'indir' => ( | ||||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | isa => Path, | ||||||||||
| 24 | coerce => 1, | ||||||||||
| 25 | required => 0, | ||||||||||
| 26 | 0 | ▶ | default => sub { cwd(); }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 1 | predicate => 'has_indir', | |||||||||
| 28 | clearer => 'clear_indir', | ||||||||||
| 29 | documentation => q(Directory to look for samples), | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | has 'outdir' => ( | ||||||||||
| 33 | is => 'rw', | ||||||||||
| 34 | isa => Path, | ||||||||||
| 35 | coerce => 1, | ||||||||||
| 36 | required => 0, | ||||||||||
| 37 | 0 | ▶ | default => sub { cwd(); }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 38 | 1 | predicate => 'has_outdir', | |||||||||
| 39 | clearer => 'clear_outdir', | ||||||||||
| 40 | documentation => q(Output directories for rules and processes), | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | has 'cwd' => ( | ||||||||||
| 44 | is => 'rw', | ||||||||||
| 45 | isa => Path, | ||||||||||
| 46 | coerce => 1, | ||||||||||
| 47 | required => 0, | ||||||||||
| 48 | 0 | ▶ | default => sub { cwd(); }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 1 | predicate => 'has_cwd', | |||||||||
| 50 | clearer => 'clear_cwd', | ||||||||||
| 51 | documentation => q(Placeholder for the cwd.), | ||||||||||
| 52 | ); | ||||||||||
| 53 | |||||||||||
| 54 | =head3 INPUT OUTPUT | ||||||||||
| 55 | |||||||||||
| 56 | Special variables that can have input/output | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 1 | has 'OUTPUT' => ( | |||||||||
| 61 | is => 'rw', | ||||||||||
| 62 | required => 0, | ||||||||||
| 63 | predicate => 'has_OUTPUT', | ||||||||||
| 64 | documentation => q(At the end of each process the OUTPUT becomes | ||||||||||
| 65 | the INPUT.) | ||||||||||
| 66 | ); | ||||||||||
| 67 | |||||||||||
| 68 | 1 | has 'INPUT' => ( | |||||||||
| 69 | is => 'rw', | ||||||||||
| 70 | required => 0, | ||||||||||
| 71 | predicate => 'has_INPUT', | ||||||||||
| 72 | documentation => q(See OUTPUT) | ||||||||||
| 73 | ); | ||||||||||
| 74 | |||||||||||
| 75 | =head3 coerce_abs_dir | ||||||||||
| 76 | |||||||||||
| 77 | Coerce dirs to absolute paths (True) | ||||||||||
| 78 | Keep paths as relative directories (False) | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | 1 | has 'coerce_abs_dir' => ( | |||||||||
| 83 | is => 'rw', | ||||||||||
| 84 | isa => 'Bool', | ||||||||||
| 85 | default => 1, | ||||||||||
| 86 | documentation => q{Coerce '*_dir' to absolute directories}, | ||||||||||
| 87 | predicate => 'has_coerce_abs_dir', | ||||||||||
| 88 | clearer => 'clear_coerce_abs_dir', | ||||||||||
| 89 | ); | ||||||||||
| 90 | |||||||||||
| 91 | =head3 create_outdir | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | 1 | has 'create_outdir' => ( | |||||||||
| 96 | is => 'rw', | ||||||||||
| 97 | isa => 'Bool', | ||||||||||
| 98 | predicate => 'has_create_outdir', | ||||||||||
| 99 | clearer => 'clear_create_outdir', | ||||||||||
| 100 | documentation => | ||||||||||
| 101 | q(Create the outdir. You may want to turn this off if doing a rule that doesn't write anything, such as checking if files exist), | ||||||||||
| 102 | default => 1, | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | after 'BUILD' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 106 | 0 | my $self = shift; | |||||||||
| 107 | |||||||||||
| 108 | 0 | $self->set_register_process_directives( | |||||||||
| 109 | 'path', | ||||||||||
| 110 | { | ||||||||||
| 111 | builder => 'process_directive_path', | ||||||||||
| 112 | lookup => | ||||||||||
| 113 | [ '^indir$', '^outdir$', '^INPUT$', '^OUTPUT$', '.*_dir$', '^cwd$' ] | ||||||||||
| 114 | } | ||||||||||
| 115 | ); | ||||||||||
| 116 | 1 | }; | |||||||||
| 117 | |||||||||||
| 118 | =head2 Type Specific Process Directives | ||||||||||
| 119 | |||||||||||
| 120 | Sometimes you want a type specific way of processing directives. This will generally require two different methods | ||||||||||
| 121 | |||||||||||
| 122 | process_directive* | ||||||||||
| 123 | walk_directives* | ||||||||||
| 124 | |||||||||||
| 125 | process_directive gives some official parameters | ||||||||||
| 126 | walk_directives walks the data structure | ||||||||||
| 127 | |||||||||||
| 128 | Take a look at the methods in 'BioX::Workflow::Command::run::Rules::Directives::Walk' | ||||||||||
| 129 | |||||||||||
| 130 | Your functions will probably be very similar | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 0 | ▶ | sub process_directive_path { | ||||||||
|
Subroutine
process_directive_path: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 135 | 0 | my $self = shift; | |||||||||
| 136 | 0 | my $k = shift; | |||||||||
| 137 | 0 | my $v = shift; | |||||||||
| 138 | |||||||||||
| 139 | 0 | ▶ | if ( ref($v) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | walk { | ||||||||||
| 141 | 0 | ▶ | wanted => sub { $self->walk_directives_path(@_) } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 142 | }, | ||||||||||
| 143 | 0 | $self->$k; | |||||||||
| 144 | } | ||||||||||
| 145 | else { | ||||||||||
| 146 | 0 | my $text = ''; | |||||||||
| 147 | 0 | ▶ | $text = $self->interpol_directive($v) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | ▶ | if ( $text ne '' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | $text = $self->return_path($text); | |||||||||
| 150 | } | ||||||||||
| 151 | 0 | $self->$k($text); | |||||||||
| 152 | } | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | =head3 walk_directives_paths | ||||||||||
| 156 | |||||||||||
| 157 | Invoke with | ||||||||||
| 158 | walk { wanted => sub { $self->directives(@_) } }, $self->other_thing; | ||||||||||
| 159 | |||||||||||
| 160 | Acts funny with $self->some_other_thing is not a reference | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||
| 163 | |||||||||||
| 164 | 0 | ▶ | sub walk_directives_path { | ||||||||
|
Subroutine
walk_directives_path: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 165 | 0 | my $self = shift; | |||||||||
| 166 | 0 | my $ref = shift; | |||||||||
| 167 | |||||||||||
| 168 | 0 | ▶ | return if ref($ref); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 169 | 0 | ▶ | return unless $ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | |||||||||||
| 171 | 0 | my $text = ''; | |||||||||
| 172 | 0 | ▶ | $text = $self->interpol_directive($ref) if $ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 0 | $text = $self->return_path($text); | |||||||||
| 174 | |||||||||||
| 175 | 0 | $self->update_directive($text); | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | 0 | ▶ | sub return_path { | ||||||||
|
Subroutine
return_path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 179 | 0 | my $self = shift; | |||||||||
| 180 | 0 | my $text = shift; | |||||||||
| 181 | |||||||||||
| 182 | 0 | ▶ | if ( $self->coerce_abs_dir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | 0 | $text = path($text)->absolute; | |||||||||
| 184 | 0 | $text = path($text); | |||||||||
| 185 | } | ||||||||||
| 186 | else { | ||||||||||
| 187 | 0 | $text = path($text); | |||||||||
| 188 | } | ||||||||||
| 189 | 0 | return "$text"; | |||||||||
| 190 | } | ||||||||||
| 191 | |||||||||||
| 192 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 193 | |||||||||||
| 194 | 1 | 1; | |||||||||