| 1 | package BioX::Workflow::SpecialVars; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Cwd qw(abs_path getcwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use File::Path qw(make_path remove_tree); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooseX::Types::Path::Tiny qw/Path Paths AbsPath/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BioX::Workflow::SpecialVars | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Variables that BioX::Workflow treats as special. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Directories - indir, outdir are looped. The indir of one rule is the outdir of the previous rule | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Files - INPUT, OUTPUT are also looped. The INPUT of one rule is the OUTPUT of the previous. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | INPUT and OUTPUT are used by the L<BioX::Workflow::Plugin::Drake> and L<BioX::Workflow::Plugin::FileEixsts> plugins. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 Variables | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head3 auto_name | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Auto_name - Create outdirectory based on rulename | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | global: | ||||||||||||||||||||||||||||
| 26 | - outdir: /home/user/workflow/processed | ||||||||||||||||||||||||||||
| 27 | rule: | ||||||||||||||||||||||||||||
| 28 | normalize: | ||||||||||||||||||||||||||||
| 29 | process: | ||||||||||||||||||||||||||||
| 30 | dostuff {$self->indir}/{$sample}.in >> {$self->outdir}/$sample.out | ||||||||||||||||||||||||||||
| 31 | analyse: | ||||||||||||||||||||||||||||
| 32 | process: | ||||||||||||||||||||||||||||
| 33 | dostuff {$self->indir}/{$sample}.in >> {$self->outdir}/$sample.out | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Would create your directory structure /home/user/workflow/processed/normalize (if it doesn't exist) | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | In addition each indir is the outdir of the previous rule | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | The indir of analyse (though not specified) is normalize. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | has 'auto_name' => ( | |||||||||||||||||||||||||||
| 44 | traits => ['Bool'], | ||||||||||||||||||||||||||||
| 45 | is => 'rw', | ||||||||||||||||||||||||||||
| 46 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 47 | default => 1, | ||||||||||||||||||||||||||||
| 48 | predicate => 'has_auto_name', | ||||||||||||||||||||||||||||
| 49 | handles => { | ||||||||||||||||||||||||||||
| 50 | enforce_struct => 'set', | ||||||||||||||||||||||||||||
| 51 | clear_enforce_struct => 'unset', | ||||||||||||||||||||||||||||
| 52 | clear_auto_name => 'unset', | ||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head3 auto_input | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | This is similar to the auto_name function in the BioX::Workflow. | ||||||||||||||||||||||||||||
| 59 | Instead this says each INPUT should be the previous OUTPUT. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | has 'auto_input' => ( | |||||||||||||||||||||||||||
| 64 | is => 'rw', | ||||||||||||||||||||||||||||
| 65 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 66 | default => 1, | ||||||||||||||||||||||||||||
| 67 | clearer => 'clear_auto_input', | ||||||||||||||||||||||||||||
| 68 | predicate => 'has_auto_input', | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head3 create_outdir | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | has 'create_outdir' => ( | |||||||||||||||||||||||||||
| 76 | is => 'rw', | ||||||||||||||||||||||||||||
| 77 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 78 | predicate => 'has_create_outdir', | ||||||||||||||||||||||||||||
| 79 | clearer => 'clear_create_outdir', | ||||||||||||||||||||||||||||
| 80 | documentation => | ||||||||||||||||||||||||||||
| 81 | 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), | ||||||||||||||||||||||||||||
| 82 | default => 1, | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head3 indir outdir | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | The initial indir is where samples are found | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | All output is written relative to the outdir | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | has 'indir' => ( | ||||||||||||||||||||||||||||
| 94 | is => 'rw', | ||||||||||||||||||||||||||||
| 95 | isa => AbsPath, | ||||||||||||||||||||||||||||
| 96 | coerce => 1, | ||||||||||||||||||||||||||||
| 97 | 6 | ▶ | default => sub { getcwd(); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | 2 | predicate => 'has_indir', | |||||||||||||||||||||||||||
| 99 | clearer => 'clear_indir', | ||||||||||||||||||||||||||||
| 100 | documentation => q(Directory to look for samples), | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | has 'outdir' => ( | ||||||||||||||||||||||||||||
| 104 | is => 'rw', | ||||||||||||||||||||||||||||
| 105 | isa => AbsPath, | ||||||||||||||||||||||||||||
| 106 | coerce => 1, | ||||||||||||||||||||||||||||
| 107 | 6 | ▶ | default => sub { getcwd(); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | 2 | predicate => 'has_outdir', | |||||||||||||||||||||||||||
| 109 | clearer => 'clear_outdir', | ||||||||||||||||||||||||||||
| 110 | documentation => q(Output directories for rules and processes), | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head3 INPUT OUTPUT | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Special variables that can have input/output | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | These variables are also used in L<BioX::Workflow::Plugin::Drake> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | has 'OUTPUT' => ( | |||||||||||||||||||||||||||
| 123 | is => 'rw', | ||||||||||||||||||||||||||||
| 124 | isa => 'Str|Undef', | ||||||||||||||||||||||||||||
| 125 | predicate => 'has_OUTPUT', | ||||||||||||||||||||||||||||
| 126 | clearer => 'clear_OUTPUT', | ||||||||||||||||||||||||||||
| 127 | documentation => | ||||||||||||||||||||||||||||
| 128 | q(At the end of each process the OUTPUT becomes | ||||||||||||||||||||||||||||
| 129 | the INPUT.) | ||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | has 'INPUT' => ( | |||||||||||||||||||||||||||
| 133 | is => 'rw', | ||||||||||||||||||||||||||||
| 134 | isa => 'Str|Undef', | ||||||||||||||||||||||||||||
| 135 | predicate => 'has_INPUT', | ||||||||||||||||||||||||||||
| 136 | clearer => 'clear_INPUT', | ||||||||||||||||||||||||||||
| 137 | documentation => q(See $OUTPUT) | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head2 Subroutines | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head3 OUTPUT_to_INPUT | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | If we are using auto_input chain INPUT/OUTPUT | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 9 | ▶ | sub OUTPUT_to_INPUT { | ||||||||||||||||||||||||||
|
Subroutine
OUTPUT_to_INPUT: called CC=3 SCAR=15.7
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | #Change the output to input | ||||||||||||||||||||||||||||
| 152 | 9 | ▶ | if ( $self->auto_input && $self->local_attr->exists('OUTPUT') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->auto_input and $self->local_attr->exists("OUTPUT")
MC/DC0%0/2
$self->auto_input and $self->local_attr->exists("OUTPUT")
$self->auto_input
$self->local_attr->exists("OUTPUT")
Truth table33%1/3
A and B
A= $self->auto_inputB= $self->local_attr->exists("OUTPUT")
| |||||||||||||||||||||||||||||
| 153 | 0 | my ( $tmp, $indir, $outdir ) = ( | |||||||||||||||||||||||||||
| 154 | $self->local_attr->get_values('OUTPUT'), | ||||||||||||||||||||||||||||
| 155 | $self->indir, $self->outdir | ||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||
| 157 | 0 | $tmp =~ s/{\$self->outdir}/{\$self->indir}/g; | |||||||||||||||||||||||||||
| 158 | 0 | $self->INPUT($tmp); | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | #This is not the best way of doing this.... | ||||||||||||||||||||||||||||
| 161 | 0 | $self->global_attr->set( INPUT => $self->INPUT ); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||
| 164 | 9 | $self->clear_OUTPUT(); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head3 make_outdir | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Set initial indir and outdir | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 93 | ▶ | sub make_outdir { | ||||||||||||||||||||||||||
|
Subroutine
make_outdir: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 93 | my ($self) = @_; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 93 | ▶ | return unless $self->create_outdir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 93 | ▶ | if ( $self->{outdir} =~ m/\{\$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 93 | ▶ | make_path( $self->outdir ) if !-d $self->outdir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head2 reset_special_vars | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | For each sample the process is interpolated | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | {$sample}.csv -> Sample_A.csv | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | We need to set it back to the original for the following rule | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 45 | ▶ | sub reset_special_vars { | ||||||||||||||||||||||||||
|
Subroutine
reset_special_vars: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | 45 | my $self = shift; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 45 | ▶ | $self->INPUT( $self->local_attr->get_values('INPUT') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | if $self->local_attr->exists('INPUT'); | ||||||||||||||||||||||||||||
| 200 | 45 | ▶ | $self->OUTPUT( $self->local_attr->get_values('OUTPUT') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | if $self->local_attr->exists('OUTPUT'); | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 45 | ▶ | $self->indir( $self->local_attr->get_values('indir') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | if $self->local_attr->exists('indir'); | ||||||||||||||||||||||||||||
| 205 | 45 | ▶ | $self->outdir( $self->local_attr->get_values('outdir') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | if $self->local_attr->exists('outdir'); | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 2 | 1; | |||||||||||||||||||||||||||