Skip to content

Commit 9818e1d

Browse files
committed
Merge branch 'develop'
2 parents 0f93946 + 8b0cc94 commit 9818e1d

File tree

4 files changed

+226
-39
lines changed

4 files changed

+226
-39
lines changed

lib/BioX/Workflow/Command/run/Utils/Directives.pm

Lines changed: 143 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use Data::Dumper;
1313
use Scalar::Util 'blessed';
1414
use Try::Tiny;
1515
use Safe;
16+
use Storable qw(dclone);
1617

1718
# use File::Basename;
1819
use File::Spec;
@@ -264,6 +265,7 @@ has 'HPC' => (
264265
##This is useful for features where we want to do things like
265266
##split a file into parts
266267
##count by kmers, etc
268+
267269
=head2 Iterables
268270
269271
Lists to iterate by
@@ -272,6 +274,12 @@ Chunks and chroms are included by default
272274
273275
=cut
274276

277+
=head2 chunks
278+
279+
Special iterable. Iterate through a list of numbers
280+
281+
=cut
282+
275283
has 'chunks' => (
276284
is => 'rw',
277285
isa => 'HashRef',
@@ -286,18 +294,67 @@ has 'use_chunks' => (
286294
isa => 'Bool',
287295
default => 0,
288296
handles => {
289-
'no_chunks' => 'not',
297+
'no_chunks' => 'not',
290298
}
291299
);
292300

301+
has 'chunk_list' => (
302+
traits => ['Array'],
303+
is => 'rw',
304+
isa => 'ArrayRef',
305+
lazy => 1,
306+
default => sub {
307+
my $self = shift;
308+
if ( !exists $self->chunks->{start} || !exists $self->chunks->{end} ) {
309+
return [];
310+
}
311+
my @array = ();
312+
for (
313+
my $x = $self->chunks->{start} ;
314+
$x <= $self->chunks->{end} ;
315+
$x = $x + $self->chunks->{step}
316+
)
317+
{
318+
push( @array, $x );
319+
}
320+
return \@array;
321+
},
322+
handles => {
323+
'all_chunk_lists' => 'elements',
324+
},
325+
);
326+
327+
=head2 chroms_list
328+
329+
Iterate by chroms. Default is human chromosomes.
330+
331+
To change create a first rule with the template
332+
333+
=cut
334+
335+
has 'chroms_list' => (
336+
traits => ['Array'],
337+
is => 'rw',
338+
isa => 'ArrayRef',
339+
default => sub {
340+
return [ 1 .. 22, 'X', 'Y', 'MT' ];
341+
},
342+
handles => {
343+
'all_chrom_lists' => 'elements',
344+
},
345+
);
346+
347+
has 'chrom' => ( is => 'rw' );
293348

294-
has 'chroms' => (
295-
is => 'rw',
296-
isa => 'ArrayRef',
297-
default => sub {
298-
return [1 .. 22, 'X', 'Y', 'MT'];
299-
},
300-
)
349+
has 'use_chroms' => (
350+
is => 'rw',
351+
traits => ['Bool'],
352+
isa => 'Bool',
353+
default => 0,
354+
handles => {
355+
'no_chroms' => 'not',
356+
}
357+
);
301358

302359
=head2 stash
303360
@@ -368,6 +425,9 @@ sub create_attr {
368425
if ( $k eq 'stash' ) {
369426
$self->merge_stash($v);
370427
}
428+
elsif ( $k =~ m/_list/ ) {
429+
$self->create_ITERABLE_attr( $meta, $k );
430+
}
371431
elsif ( ref($v) eq 'HASH' ) {
372432
$self->create_HASH_attr( $meta, $k );
373433
}
@@ -408,10 +468,10 @@ sub create_ARRAY_attr {
408468
clearer => "clear_$k",
409469
default => sub { [] },
410470
handles => {
411-
"all_$k" => 'elements',
412-
"count_$k" => 'count',
413-
"has_$k" => 'count',
414-
"has_no_$k" => 'is_empty',
471+
"all_$k" . "s" => 'elements',
472+
"count_$k" => 'count',
473+
"has_$k" => 'count',
474+
"has_no_$k" => 'is_empty',
415475
},
416476
)
417477
);
@@ -439,6 +499,26 @@ sub create_HASH_attr {
439499
);
440500
}
441501

502+
sub create_BOOL_attr {
503+
my $self = shift;
504+
my $meta = shift;
505+
my $k = shift;
506+
507+
$meta->add_attribute(
508+
'use_'
509+
. $k
510+
. 's' => (
511+
traits => ['Bool'],
512+
is => 'rw',
513+
isa => 'Bool',
514+
default => 0,
515+
handles => {
516+
'no_' . $k . 's' => 'not',
517+
}
518+
)
519+
);
520+
}
521+
442522
sub create_reg_attr {
443523
my $self = shift;
444524
my $meta = shift;
@@ -452,6 +532,54 @@ sub create_reg_attr {
452532
);
453533
}
454534

535+
=head3 create_blank_attr
536+
537+
placeholder for ITERABLE
538+
539+
=cut
540+
541+
sub create_blank_attr {
542+
my $self = shift;
543+
my $meta = shift;
544+
my $k = shift;
545+
546+
$meta->add_attribute(
547+
$k => (
548+
is => 'rw',
549+
default => '',
550+
)
551+
);
552+
}
553+
554+
=head3 create_ITERABLE_attr
555+
556+
For every argument that ends in _list, create an array, a single val, and a boolean
557+
558+
If iterable is
559+
560+
some_list
561+
562+
We get an array 'some_list', boolean value 'use_somes', and blank/placeholder of 'some'
563+
564+
The boolean value is set to 0
565+
566+
You can only use one iterable per flow
567+
568+
=cut
569+
570+
sub create_ITERABLE_attr {
571+
my $self = shift;
572+
my $meta = shift;
573+
my $k = shift;
574+
575+
my $t = $k;
576+
$t =~ s/_list//;
577+
578+
$self->create_ARRAY_attr( $meta, $k );
579+
$self->create_blank_attr( $meta, $t );
580+
$self->create_BOOL_attr( $meta, $t );
581+
}
582+
455583
sub interpol_directive {
456584
my $self = shift;
457585
my $source = shift;
@@ -469,6 +597,9 @@ sub interpol_directive {
469597
);
470598

471599
my $fill_in = { self => \$self };
600+
#TODO reference keys by value instead of $self->
601+
# my @keys = keys %{$self};
602+
$fill_in->{INPUT} = $self->INPUT;
472603
$fill_in->{sample} = $self->sample if $self->has_sample;
473604

474605
$text = $template->fill_in( HASH => $fill_in, BROKEN => \&my_broken );

lib/BioX/Workflow/Command/run/Utils/Rules.pm

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ sub set_rule_names {
265265
$self->app_log->info( 'Found rules:' . "\t" . join( ', ', @rule_names ) );
266266
}
267267

268+
#TODO This is confusing change names
269+
268270
=head3 set_rule_keys
269271
270272
If we have any select_* or select_match, get those rules before we start processing
@@ -554,8 +556,7 @@ sub template_process {
554556

555557
##TODO for modify chunks
556558
foreach my $sample ( $self->all_samples ) {
557-
558-
$texts = $self->check_chunks( $sample, $texts );
559+
$texts = $self->check_iterables( $sample, $texts );
559560
}
560561

561562
$self->process_obj->{ $self->rule_name }->{text} = $texts;
@@ -573,23 +574,45 @@ sub template_process {
573574
}
574575
}
575576

576-
sub check_chunks {
577+
sub check_iterables {
577578
my $self = shift;
578579
my $sample = shift;
579580
my $texts = shift;
580581

581-
if ( $self->local_attr->no_chunks ) {
582+
#First check the global for any lists
583+
my $iter = '';
584+
my $use_iter = 0;
585+
my @use = ();
586+
map {
587+
if ( $_ =~ m/^use_/ ) { push( @use, $_ ) }
588+
} @{ $self->rule_keys };
589+
map {
590+
if ( $_ =~ m/^use_/ ) { push( @use, $_ ) }
591+
} @{ $self->local_rule_keys };
592+
593+
594+
my $use = pop(@use);
595+
596+
if(! $use){
582597
$texts = $self->in_template_process( $sample, $texts );
583598
return $texts;
584599
}
585600

586-
##TODO ADD CHECKS
587-
my $start = $self->local_attr->chunks->{start} || 0;
588-
my $end = $self->local_attr->chunks->{end};
589-
my $step = $self->local_attr->chunks->{step} || 1;
601+
my $base = $use;
602+
$base =~ s/use_//;
603+
604+
my $no = 'no_'.$base;
605+
my $elem = $base;
606+
$elem =~ s/s$//;
607+
my $all = 'all_'.$elem.'_lists';
608+
609+
if ( $self->local_attr->$no ) {
610+
$texts = $self->in_template_process( $sample, $texts );
611+
return $texts;
612+
}
590613

591-
for ( my $x = $start ; $x <= $end ; $x = $x + $step ) {
592-
$self->local_attr->chunk($x);
614+
foreach my $chunk ( $self->local_attr->$all) {
615+
$self->local_attr->$elem($chunk);
593616
$texts = $self->in_template_process( $sample, $texts );
594617
}
595618
return $texts;

t/lib/TestsFor/BioX/Workflow/Command/run/Test002.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ sub test_003 : Tags(get_samples) {
166166

167167
ok( $test->global_attr->indir->can('absolute'),
168168
'Indir has method absolute' );
169-
ok( $test->global_attr->can('all_some_array'), 'Array has all method' );
169+
ok( $test->global_attr->can('all_some_arrays'), 'Array has all method' );
170170
ok( $test->global_attr->can('some_hash_pairs'), 'Hash has pairs method' );
171171
}
172172

0 commit comments

Comments
 (0)