Skip to content

Commit f0b00b7

Browse files
committed
Merge branch 'develop'
2 parents 53d2b60 + 28ae96a commit f0b00b7

File tree

30 files changed

+1587
-1079
lines changed

30 files changed

+1587
-1079
lines changed

'

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package BioX::Workflow::Command::run::Rules::Directives::Walk;
2+
3+
use Moose::Role;
4+
5+
1;

inotify-hookable.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export DEV='DEV'
44
inotify-hookable \
55
--watch-directories lib \
6-
--watch-directories t/lib/TestsFor/ \
7-
--watch-directories t/lib/TestMethod/ \
6+
--watch-directories t \
7+
--watch-directories t \
88
--watch-files t/test_class_tests.t \
99
--on-modify-command "prove -v t/test_class_tests.t"

lib/BioX/Workflow/Command/Utils/Create.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package BioX::Workflow::Command::Utils::Create;
2+
23
use MooseX::App::Role;
34
use BioX::Workflow::Command::Utils::Traits qw(ArrayRefOfStrs);
45
use Storable qw(dclone);

lib/BioX/Workflow/Command/Utils/Files/TrackChanges.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package BioX::Workflow::Command::Utils::Files::TrackChanges;
22

33
use Moose::Role;
4-
use DBM::Deep;
5-
use File::Spec;
4+
# use DBM::Deep;
5+
# use File::Spec;
66

77
#TODO most of these should be in run
88

lib/BioX/Workflow/Command/run.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use File::Copy;
77

88
extends 'BioX::Workflow::Command';
99
use BioX::Workflow::Command::Utils::Traits qw(ArrayRefOfStrs);
10-
use BioX::Workflow::Command::run::Utils::Directives;
10+
use BioX::Workflow::Command::run::Rules::Directives;
1111

1212
with 'BioX::Workflow::Command::run::Utils::Samples';
1313
with 'BioX::Workflow::Command::run::Utils::Attributes';
14-
with 'BioX::Workflow::Command::run::Utils::Rules';
14+
with 'BioX::Workflow::Command::run::Rules::Rules';
1515
with 'BioX::Workflow::Command::run::Utils::WriteMeta';
1616
with 'BioX::Workflow::Command::run::Utils::Files::TrackChanges';
1717
with 'BioX::Workflow::Command::run::Utils::Files::ResolveDeps';
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
package BioX::Workflow::Command::run::Rules::Directives;
2+
3+
use Moose;
4+
use namespace::autoclean;
5+
use Moose::Util qw/apply_all_roles/;
6+
7+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::HPC';
8+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::Path';
9+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::List';
10+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::Stash';
11+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::Hash';
12+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::Array';
13+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::CSV';
14+
with 'BioX::Workflow::Command::run::Rules::Directives::Types::Config';
15+
with 'BioX::Workflow::Command::run::Rules::Directives::Interpolate';
16+
with 'BioX::Workflow::Command::run::Rules::Directives::Sample';
17+
with 'BioX::Workflow::Command::run::Rules::Directives::Walk';
18+
with 'BioX::Workflow::Command::Utils::Log';
19+
20+
use Try::Tiny;
21+
22+
=head2 Other Directives
23+
24+
=cut
25+
26+
has 'register_types' => (
27+
traits => ['Hash'],
28+
is => 'rw',
29+
isa => 'HashRef',
30+
default => sub { return {} },
31+
handles => {
32+
'get_register_types' => 'get',
33+
'set_register_types' => 'set',
34+
},
35+
);
36+
37+
has 'register_process_directives' => (
38+
traits => ['Hash'],
39+
is => 'rw',
40+
isa => 'HashRef',
41+
default => sub { return {} },
42+
handles => {
43+
'get_register_process_directives' => 'get',
44+
'set_register_process_directives' => 'set',
45+
},
46+
);
47+
48+
##TODO add this so that we can have user defined types
49+
has 'register_namespace' => (
50+
traits => ['Array'],
51+
is => 'rw',
52+
isa => 'ArrayRef',
53+
default => sub { [] },
54+
handles => {
55+
'all_register_namespace' => 'elements',
56+
'count_register_namespace' => 'count',
57+
'has_register_namespace' => 'count',
58+
'has_no_register_namespace' => 'is_empty',
59+
},
60+
trigger => sub {
61+
my $self = shift;
62+
foreach my $role ( $self->all_register_namespace ) {
63+
try {
64+
apply_all_roles( $self, $role );
65+
}
66+
catch {
67+
$self->app_log->warn(
68+
'There was an error registering role ' . $role );
69+
$self->app_log->warn("$_\n");
70+
}
71+
}
72+
},
73+
);
74+
75+
has 'override_process' => (
76+
traits => ['Bool'],
77+
is => 'rw',
78+
isa => 'Bool',
79+
default => 0,
80+
predicate => 'has_override_process',
81+
documentation =>
82+
q(Instead of for my $sample (@sample){ DO STUFF } just DOSTUFF),
83+
handles => {
84+
set_override_process => 'set',
85+
clear_override_process => 'unset',
86+
},
87+
);
88+
89+
##Add in support for chunks
90+
##This is useful for features where we want to do things like
91+
##split a file into parts
92+
##count by kmers, etc
93+
94+
=head3 create_attr
95+
96+
Add attributes to $self-> namespace
97+
98+
=cut
99+
100+
sub create_attr {
101+
my $self = shift;
102+
my $data = shift;
103+
104+
my $meta = __PACKAGE__->meta;
105+
106+
$meta->make_mutable;
107+
my $seen = {};
108+
109+
for my $attr ( $meta->get_all_attributes ) {
110+
next if $attr->name eq 'stash';
111+
$seen->{ $attr->name } = 1;
112+
}
113+
114+
# Get workflow_data structure
115+
# Workflow is an array of hashes
116+
117+
foreach my $href ( @{$data} ) {
118+
119+
if ( !ref($href) eq 'HASH' ) {
120+
##TODO add more informative structure options here
121+
##TODO Add app_log
122+
warn 'Your variable declarations should be key/value!';
123+
return;
124+
}
125+
126+
while ( my ( $k, $v ) = each( %{$href} ) ) {
127+
128+
if ( !exists $seen->{$k} ) {
129+
130+
if ( $k eq 'stash' ) {
131+
$self->merge_stash($v);
132+
}
133+
elsif ( $self->can($k) ) {
134+
##Should this be next of just skip ?
135+
next;
136+
}
137+
elsif ( $self->search_registered_types( $meta, $k, $v ) ) {
138+
139+
# next;
140+
}
141+
elsif ( ref($v) eq 'HASH' ) {
142+
$self->create_HASH_attr( $meta, $k );
143+
}
144+
elsif ( ref($v) eq 'ARRAY' ) {
145+
$self->create_ARRAY_attr( $meta, $k );
146+
}
147+
else {
148+
$self->create_reg_attr( $meta, $k );
149+
}
150+
}
151+
152+
try{
153+
$self->$k($v) if defined $v;
154+
}
155+
catch{
156+
$self->app_log->warn(
157+
'There was an assiging key. ' . $k );
158+
$self->app_log->warn("$_\n");
159+
}
160+
}
161+
162+
}
163+
164+
$meta->make_immutable;
165+
}
166+
167+
sub search_registered_types {
168+
my $self = shift;
169+
my $meta = shift;
170+
my $k = shift;
171+
my $v = shift;
172+
173+
foreach my $key ( keys %{ $self->register_types } ) {
174+
next unless exists $self->register_types->{$key}->{lookup};
175+
next unless exists $self->register_types->{$key}->{builder};
176+
my $lookup_ref = $self->register_types->{$key}->{lookup};
177+
my $builder = $self->register_types->{$key}->{builder};
178+
179+
foreach my $lookup ( @{$lookup_ref} ) {
180+
if ( $k =~ m/$lookup/ ) {
181+
$self->$builder( $meta, $k, $v );
182+
return 1;
183+
}
184+
}
185+
}
186+
187+
return 0;
188+
}
189+
190+
sub create_reg_attr {
191+
my $self = shift;
192+
my $meta = shift;
193+
my $k = shift;
194+
195+
$meta->add_attribute(
196+
$k => (
197+
is => 'rw',
198+
lazy_build => 1,
199+
)
200+
);
201+
}
202+
203+
=head3 create_blank_attr
204+
205+
placeholder for some types
206+
207+
=cut
208+
209+
sub create_blank_attr {
210+
my $self = shift;
211+
my $meta = shift;
212+
my $k = shift;
213+
214+
$meta->add_attribute(
215+
$k => (
216+
is => 'rw',
217+
default => '',
218+
)
219+
);
220+
}
221+
222+
sub BUILD { }
223+
224+
after 'BUILD' => sub {
225+
my $self = shift;
226+
$self->interpol_directive_cache( {} );
227+
};
228+
229+
no Moose;
230+
__PACKAGE__->meta->make_immutable;
231+
232+
1;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package BioX::Workflow::Command::run::Rules::Directives::Interpolate;
2+
3+
use Moose::Role;
4+
5+
use Text::Template;
6+
use Try::Tiny;
7+
use Safe;
8+
use Storable qw(dclone);
9+
use File::Spec;
10+
use Memoize;
11+
12+
our $c = new Safe;
13+
##Template
14+
15+
has 'interpol_directive_cache' => (
16+
is => 'rw',
17+
isa => 'HashRef',
18+
default => sub { {} },
19+
);
20+
21+
has 'errors' => (
22+
is => 'rw',
23+
isa => 'Bool',
24+
default => 0,
25+
);
26+
27+
has 'before_meta' => (
28+
traits => ['String'],
29+
is => 'rw',
30+
isa => 'Str',
31+
default => q{},
32+
predicate => 'has_before_meta',
33+
required => 0,
34+
handles => {
35+
add_before_meta => 'append',
36+
replace_before_meta => 'replace',
37+
},
38+
);
39+
40+
sub interpol_directive {
41+
my $self = shift;
42+
my $source = shift;
43+
my $text = '';
44+
45+
#The $ is not always at the beginning
46+
if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{/ )
47+
{
48+
return $self->interpol_directive_cache->{$source};
49+
}
50+
51+
if ( $source !~ m/{/ ) {
52+
$self->interpol_directive_cache->{$source} = $source;
53+
return $source;
54+
}
55+
56+
my $template = Text::Template->new(
57+
TYPE => 'STRING',
58+
SOURCE => $source,
59+
SAFE => $c,
60+
);
61+
62+
my $fill_in = { self => \$self };
63+
64+
#TODO reference keys by value instead of $self->
65+
# my @keys = keys %{$self};
66+
# $fill_in->{INPUT} = $self->INPUT;
67+
$fill_in->{sample} = $self->sample if $self->has_sample;
68+
69+
$text = $template->fill_in( HASH => $fill_in, BROKEN => \&my_broken );
70+
71+
$self->interpol_directive_cache->{$source} = $text;
72+
return $text;
73+
}
74+
75+
memoize('my_broken');
76+
77+
sub my_broken {
78+
my %args = @_;
79+
my $err_ref = $args{arg};
80+
my $text = $args{text};
81+
my $error = $args{error};
82+
$error =~ s/via package.*//g;
83+
chomp($error);
84+
if ( $error =~ m/Can't locate object method/ ) {
85+
$error .= "\n# Did you declare $text?";
86+
}
87+
88+
return <<EOF;
89+
90+
###################################################
91+
# The following errors were encountered:
92+
# $text
93+
# $error
94+
###################################################
95+
EOF
96+
}
97+
98+
99+
1;

0 commit comments

Comments
 (0)