@@ -13,6 +13,7 @@ use Data::Dumper;
1313use Scalar::Util ' blessed' ;
1414use Try::Tiny;
1515use Safe;
16+ use Storable qw( dclone) ;
1617
1718# use File::Basename;
1819use 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
269271Lists 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+
275283has ' 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+
442522sub 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+
455583sub 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 );
0 commit comments