File Coverage

blib/lib/BioX/Workflow/Command/run/Rules/Directives/Types/List.pm
Criterion Covered Total %
statement 3 19 15.7
branch n/a
condition n/a
subroutine 1 4 25.0
pod 2 3 66.6
total 6 26 23.0


line stmt bran cond sub pod time code
1             package BioX::Workflow::Command::run::Rules::Directives::Types::List;
2              
3 1     1   853 use Moose::Role;
  1         4  
  1         11  
4              
5             =head2 Iterables
6              
7             Lists to iterate by
8              
9             Chunks and chroms are included by default
10              
11             =cut
12              
13             =head2 chunks
14              
15             Special iterable. Iterate through a list of numbers
16              
17             =cut
18              
19             has 'chunks' => (
20             is => 'rw',
21             isa => 'HashRef',
22             default => sub { {} }
23             );
24              
25             has 'chunk' => ( is => 'rw' );
26              
27             has 'use_chunks' => (
28             is => 'rw',
29             traits => ['Bool'],
30             isa => 'Bool',
31             default => 0,
32             handles => {
33             'no_chunks' => 'not',
34             }
35             );
36              
37             has 'chunk_list' => (
38             traits => ['Array'],
39             is => 'rw',
40             isa => 'ArrayRef',
41             lazy => 1,
42             default => sub {
43             my $self = shift;
44             if ( !exists $self->chunks->{start} || !exists $self->chunks->{end} ) {
45             return [];
46             }
47             my @array = ();
48             for (
49             my $x = $self->chunks->{start} ;
50             $x <= $self->chunks->{end} ;
51             $x = $x + $self->chunks->{step}
52             )
53             {
54             push( @array, $x );
55             }
56             return \@array;
57             },
58             handles => {
59             'all_chunk_lists' => 'elements',
60             },
61             );
62              
63             =head2 chroms_list
64              
65             Iterate by chroms. Default is human chromosomes.
66              
67             To change create a first rule with the template
68              
69             =cut
70              
71             has 'chroms_list' => (
72             traits => ['Array'],
73             is => 'rw',
74             isa => 'ArrayRef',
75             default => sub {
76             return [ 1 .. 22, 'X', 'Y', 'MT' ];
77             },
78             handles => {
79             'all_chrom_lists' => 'elements',
80             },
81             );
82              
83             has 'chrom' => ( is => 'rw' );
84              
85             has 'use_chroms' => (
86             is => 'rw',
87             traits => ['Bool'],
88             isa => 'Bool',
89             default => 0,
90             handles => {
91             'no_chroms' => 'not',
92             }
93             );
94              
95             =head3 create_ITERABLE_attr
96              
97             For every argument that ends in _list, create an array, a single val, and a boolean
98              
99             If iterable is
100              
101             some_list
102              
103             We get an array 'some_list', boolean value 'use_somes', and blank/placeholder of 'some'
104              
105             The boolean value is set to 0
106              
107             You can only use one iterable per flow
108              
109             =cut
110              
111             sub create_ITERABLE_attr {
112 0     0 1   my $self = shift;
113 0           my $meta = shift;
114 0           my $k = shift;
115              
116 0           my $t = $k;
117 0           $t =~ s/_list//;
118              
119 0           $self->create_ARRAY_attr( $meta, $k );
120 0           $self->create_blank_attr( $meta, $t );
121 0           $self->create_BOOL_attr( $meta, $t );
122             }
123              
124             sub create_BOOL_attr {
125 0     0 0   my $self = shift;
126 0           my $meta = shift;
127 0           my $k = shift;
128              
129 0           $meta->add_attribute(
130             'use_'
131             . $k
132             . 's' => (
133             traits => ['Bool'],
134             is => 'rw',
135             isa => 'Bool',
136             default => 0,
137             handles => {
138             'no_' . $k . 's' => 'not',
139             }
140             )
141             );
142             }
143              
144             =head3 create_blank_attr
145              
146             placeholder for ITERABLE
147              
148             =cut
149              
150             sub create_blank_attr {
151 0     0 1   my $self = shift;
152 0           my $meta = shift;
153 0           my $k = shift;
154              
155 0           $meta->add_attribute(
156             $k => (
157             is => 'rw',
158             default => '',
159             )
160             );
161             }
162              
163             =head2 Set Register Types
164              
165             When we are iterating over the local variables, we can create types based on regular expressions
166              
167             INPUT, OUTPUT, *_dir, indir, outdir all create paths - but only the leaves of the data structure
168             *_list transforms the whole data structure
169              
170             =cut
171              
172             after 'BUILD' => sub {
173             my $self = shift;
174              
175             $self->set_register_types( 'list',
176             { builder => 'create_ITERABLE_attr', lookup => ['.*_list$'] } );
177             };
178              
179             1;