| 1 | package BioX::Workflow::Rules; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | =head1 BioX::Workflow::Rules | ||||||||||
| 6 | |||||||||||
| 7 | Check rules, select rules, match against rules. Its all about the rules. | ||||||||||
| 8 | |||||||||||
| 9 | =head2 Variables | ||||||||||
| 10 | |||||||||||
| 11 | =head3 select_rules | ||||||||||
| 12 | |||||||||||
| 13 | Select a subsection of rules | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | has 'select_rules' => ( | ||||||||||
| 18 | traits => ['Array'], | ||||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | isa => 'ArrayRef[Str]', | ||||||||||
| 21 | 6 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 2 | required => 0, | |||||||||
| 23 | handles => { | ||||||||||
| 24 | all_select_rules => 'elements', | ||||||||||
| 25 | add_select_rule => 'push', | ||||||||||
| 26 | map_select_rules => 'map', | ||||||||||
| 27 | filter_select_rules => 'grep', | ||||||||||
| 28 | find_select_rule => 'first', | ||||||||||
| 29 | get_select_rule => 'get', | ||||||||||
| 30 | join_select_rules => 'join', | ||||||||||
| 31 | count_select_rules => 'count', | ||||||||||
| 32 | has_select_rules => 'count', | ||||||||||
| 33 | has_no_select_rules => 'is_empty', | ||||||||||
| 34 | sorted_select_rules => 'sort', | ||||||||||
| 35 | }, | ||||||||||
| 36 | documentation => q{Select a subselection of rules.}, | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | =head3 match_rules | ||||||||||
| 40 | |||||||||||
| 41 | Select a subsection of rules by regexp | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | has 'match_rules' => ( | ||||||||||
| 46 | traits => ['Array'], | ||||||||||
| 47 | is => 'rw', | ||||||||||
| 48 | isa => 'ArrayRef[Str]', | ||||||||||
| 49 | 6 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 2 | required => 0, | |||||||||
| 51 | handles => { | ||||||||||
| 52 | all_match_rules => 'elements', | ||||||||||
| 53 | add_match_rule => 'push', | ||||||||||
| 54 | map_match_rules => 'map', | ||||||||||
| 55 | filter_match_rules => 'grep', | ||||||||||
| 56 | find_match_rule => 'first', | ||||||||||
| 57 | get_match_rule => 'get', | ||||||||||
| 58 | join_match_rules => 'join', | ||||||||||
| 59 | count_match_rules => 'count', | ||||||||||
| 60 | has_match_rules => 'count', | ||||||||||
| 61 | has_no_match_rules => 'is_empty', | ||||||||||
| 62 | sorted_match_rules => 'sort', | ||||||||||
| 63 | }, | ||||||||||
| 64 | documentation => q{Select a subselection of rules by regular expression}, | ||||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | =head3 number_rules | ||||||||||
| 68 | |||||||||||
| 69 | Instead of | ||||||||||
| 70 | outdir/ | ||||||||||
| 71 | rule1 | ||||||||||
| 72 | rule2 | ||||||||||
| 73 | |||||||||||
| 74 | outdir/ | ||||||||||
| 75 | 001-rule1 | ||||||||||
| 76 | 002-rule2 | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 2 | has 'number_rules' => ( | |||||||||
| 81 | is => 'rw', | ||||||||||
| 82 | isa => 'Bool', | ||||||||||
| 83 | default => 0, | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | =head3 counter_rules | ||||||||||
| 87 | |||||||||||
| 88 | Keep track of the number of our rules. Only used when --number_rules enabled | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 2 | has 'counter_rules' => ( | |||||||||
| 93 | traits => ['Counter'], | ||||||||||
| 94 | is => 'rw', | ||||||||||
| 95 | isa => 'Num', | ||||||||||
| 96 | default => 1, | ||||||||||
| 97 | handles => { | ||||||||||
| 98 | inc_counter_rules => 'inc', | ||||||||||
| 99 | dec_counter_rules => 'dec', | ||||||||||
| 100 | reset_counter_rules => 'reset', | ||||||||||
| 101 | }, | ||||||||||
| 102 | ); | ||||||||||
| 103 | |||||||||||
| 104 | =head3 override_process | ||||||||||
| 105 | |||||||||||
| 106 | local: | ||||||||||
| 107 | - override_process: 1 | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | 2 | has 'override_process' => ( | |||||||||
| 112 | traits => ['Bool'], | ||||||||||
| 113 | is => 'rw', | ||||||||||
| 114 | isa => 'Bool', | ||||||||||
| 115 | default => 0, | ||||||||||
| 116 | predicate => 'has_override_process', | ||||||||||
| 117 | documentation => | ||||||||||
| 118 | q(Instead of for my $sample (@sample){ DO STUFF } just DOSTUFF), | ||||||||||
| 119 | handles => { | ||||||||||
| 120 | set_override_process => 'set', | ||||||||||
| 121 | clear_override_process => 'unset', | ||||||||||
| 122 | }, | ||||||||||
| 123 | ); | ||||||||||
| 124 | |||||||||||
| 125 | =head2 Subroutines | ||||||||||
| 126 | |||||||||||
| 127 | =head3 check_rules | ||||||||||
| 128 | |||||||||||
| 129 | If we have select_rules or match_rule only process those rules and skip all others | ||||||||||
| 130 | |||||||||||
| 131 | =cut | ||||||||||
| 132 | |||||||||||
| 133 | 9 | ▶ | sub check_rules{ | ||||||||
|
Subroutine
check_rules: called CC=7 SCAR=29.1
Pod
documented
| |||||||||||
| 134 | 9 | my $self = shift; | |||||||||
| 135 | |||||||||||
| 136 | 9 | my $ret = 0; | |||||||||
| 137 | 9 | my $p = $self->key; | |||||||||
| 138 | |||||||||||
| 139 | 9 | $DB::single=2; | |||||||||
| 140 | 9 | $DB::single=2; | |||||||||
| 141 | |||||||||||
| 142 | 9 | ▶ | if ( $self->has_select_rules ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | ▶ | if ( !$self->filter_select_rules( sub {/^$p$/} ) ) { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 144 | 0 | $ret = 1; | |||||||||
| 145 | } | ||||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 9 | ▶ | if ( $self->has_match_rules ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | ▶ | if ( !$self->map_match_rules( sub {$p =~ m/$_/} ) ) { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 150 | 0 | $ret = 1; | |||||||||
| 151 | } | ||||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | 9 | ▶ | if($ret){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 155 | 0 | $self->OUTPUT_to_INPUT; | |||||||||
| 156 | 0 | $self->clear_process_attr; | |||||||||
| 157 | |||||||||||
| 158 | 0 | $self->pkey( $self->key ); | |||||||||
| 159 | 0 | ▶ | $self->indir( $self->outdir . "/" . $self->pkey ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | if $self->auto_name; | ||||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 9 | return $ret; | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | 2 | 1; | |||||||||