annotate cpt_psm_comparison_table/lib/CPT/Parameter.pm @ 0:b8b8b52904a5 draft

Uploaded
author cpt
date Tue, 05 Jul 2022 05:42:59 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
1 package CPT::Parameter;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
2 use Moose::Role;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
3 use strict;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
4 use warnings;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
5 use autodie;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
6 use Carp;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
7
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
8 #requires 'galaxy_command';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
9 requires 'galaxy_input';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
10 requires 'galaxy_output';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
11 requires 'validate_individual';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
12 requires 'getopt_format';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
13
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
14 # Long name for this parameter (mandatory)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
15 has 'name' => ( is => 'rw', isa => 'Str' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
16
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
17 # Short name for this paramter (optional)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
18 has 'short' => ( is => 'rw', isa => 'Str' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
19 has 'multiple' => ( is => 'rw', isa => 'Bool' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
20 has 'description' => ( is => 'rw', isa => 'Str' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
21
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
22 # Attr
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
23 # Default supplied parameters
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
24 has 'default' => ( is => 'rw', isa => 'Any' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
25 # User supplied values
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
26 has 'value' => ( is => 'rw', isa => 'Any' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
27 has 'required' => ( is => 'rw', isa => 'Bool' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
28 has 'hidden' => ( is => 'rw', isa => 'Bool' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
29
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
30 # Set of error messages to be returned
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
31 has 'errors' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
32
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
33 # Unimplemented
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
34 # Are there any implications of setting this
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
35 has 'implies' => ( is => 'rw', isa => 'ArrayRef' );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
36
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
37 # Internal
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
38 has '_index' => ( is => 'rw', isa => 'Int', default => 0 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
39
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
40 # Galaxy Specific
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
41 has '_galaxy_specific' => (is => 'rw', isa => 'Bool', default => 0);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
42 # implies option is somehow intertwined with whether or not this is being produced for use in galaxy.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
43 has '_show_in_galaxy' => (is => 'rw', isa => 'Bool', default => 1);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
44 # This is a custom override. If the object is hidden by default, it will causae it to be shown. If the object is visible by default, it can cause it to be hidden.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
45
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
46
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
47
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
48 sub galaxy_command {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
49 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
50 my $value = $self->get_galaxy_command_identifier();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
51
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
52 # If it's hidden, specific to galaxy, and hidden from galaxy users,
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
53 # then it is safe to assume we've specified a SANE default.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
54 if($self->hidden() && $self->_galaxy_specific()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
55 $value = $self->default();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
56 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
57 my $string;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
58
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
59 # If it's a repeat, we handle that
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
60 $string .= $self->handle_possible_galaxy_command_repeat_start();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
61 # If it's required we set it to a value IF we have one. Otherwise value
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
62 # will be the galaxy_identifier.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
63 if($self->required()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
64 $string .= sprintf( '--%s "${%s}"' . "\n",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
65 $self->get_galaxy_cli_identifier(), $value
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
66 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
67 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
68 # If
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
69 # This code is only relevant if we're multiple, otherwise the loop will
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
70 # not pass here
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
71 if ( !$self->multiple() ){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
72 $string .= sprintf('#if $%s and $%s is not "None":' . "\n",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
73 $self->get_galaxy_cli_identifier(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
74 $self->get_galaxy_cli_identifier()
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
75 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
76 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
77 # Flag
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
78 $string .= sprintf( '--%s "${%s}"'."\n",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
79 $self->get_galaxy_cli_identifier(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
80 $value
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
81 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
82 # End
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
83 if ( !$self->multiple() ){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
84 $string .= "#end if\n";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
85 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
86 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
87 $string .= $self->handle_possible_galaxy_command_repeat_end();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
88 return $string;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
89 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
90
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
91
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
92
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
93 sub getOptionsArray {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
94 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
95 my @getoptions;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
96 push( @getoptions, $self->getopt_identifier() );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
97
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
98 my $mod_desc = $self->description();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
99 if(defined $self->default()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
100 if(ref $self->default() eq 'ARRAY'){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
101 $mod_desc .= sprintf(" (Default: %s)", join(",",@{$self->default()}));
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
102 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
103 $mod_desc .= sprintf(" (Default: %s)", $self->default());
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
104 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
105 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
106 if(substr(blessed($self),0,22) eq 'CPT::Parameter::Option'){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
107 my %kv = %{$self->options()};
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
108 my @k = keys(%kv);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
109 $mod_desc .= sprintf(" (Options: %s)",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
110 join(
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
111 ", ",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
112 map { $kv{$_} . " [$_]" } @k
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
113 )
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
114 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
115 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
116 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
117
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
118 push( @getoptions, $mod_desc );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
119
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
120 # Values to copy over: required, hidden, default, values
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
121 my %attr = ();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
122 if ( $self->required() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
123 $attr{required} = $self->required();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
124 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
125 if ( $self->hidden() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
126 $attr{hidden} = $self->hidden();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
127 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
128 if ( $self->default() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
129 $attr{default} = $self->default();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
130 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
131 push( @getoptions, \%attr );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
132 return \@getoptions;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
133 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
134
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
135
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
136 sub getopt_identifier {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
137 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
138 if ( defined( $self->short() ) && length($self->short()) > 0 ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
139 return sprintf( "%s|%s%s%s", $self->name(), $self->short(), $self->getopt_format(), ( $self->multiple() ? '@' : '' ), );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
140 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
141 else {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
142 return sprintf( "%s%s%s", $self->name(), $self->getopt_format(), ( $self->multiple() ? '@' : '' ), )
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
143
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
144 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
145 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
146
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
147
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
148 sub get_galaxy_command_identifier {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
149 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
150 if($self->multiple()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
151 return sprintf('%s.%s', $self->get_repeat_idx_name(), $self->get_galaxy_cli_identifier());
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
152 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
153 return $self->get_galaxy_cli_identifier();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
154 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
155 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
156
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
157
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
158 sub get_galaxy_cli_identifier {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
159 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
160 return $self->name();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
161 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
162
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
163
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
164 sub is_optional {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
165 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
166 # Want coerced to int.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
167 #return !$self->required();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
168 if($self->required()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
169 return 0;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
170 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
171 return 1;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
172 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
173 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
174
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
175
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
176 sub is_optional_galaxy {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
177 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
178 return $self->is_optional() ? "True" : "False";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
179 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
180
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
181
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
182 sub update_index {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
183 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
184 if($self->multiple()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
185 my $size = scalar( @{ $self->value() } );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
186 # E.g:
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
187 # [1,2,3] , size = 3
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
188 # index = 3
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
189 # size = 3-1 = 2
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
190 # index -> 0
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
191 if ( $self->_index() ge $size - 1 ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
192 $self->_index(0);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
193 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
194 else {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
195 $self->_index( $self->_index() + 1 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
196 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
197 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
198 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
199
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
200
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
201 sub reset_index {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
202 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
203 $self->_index(0);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
204 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
205
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
206
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
207 sub get_value {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
208 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
209 if ( defined $self->value() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
210 if ( $self->multiple ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
211 my @data = @{ $self->value() };
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
212 return $data[ $self->_index() ];
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
213 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
214 else {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
215 return $self->value();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
216 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
217 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
218 return;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
219 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
220 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
221
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
222
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
223 sub get_default {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
224 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
225 if ( defined $self->default() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
226 if ( $self->multiple ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
227 my @data = @{ $self->default() };
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
228 return $data[ $self->_index() ];
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
229 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
230 else {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
231 return $self->default();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
232 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
233 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
234 return;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
235 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
236 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
237
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
238
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
239
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
240 sub validate {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
241 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
242 if ( $self->multiple() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
243 my $errors = 0;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
244 if( ref($self->value()) ne 'ARRAY' ){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
245 carp "Author specified a non-array default value for " . $self->name() . ", which allows multiple values. Script author should modify the default value to be an ArrayRef.";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
246 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
247 for my $val ( @{ $self->value() } ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
248 if($self->validate_individual($val) == 0){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
249 $errors++;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
250 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
251 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
252 # Must cast to number otherwise it returns "" which is bad since I use
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
253 # 1/0 as T/F (true = good, false = bad)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
254 return 0+($errors == 0);
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
255 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
256 else {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
257 return 0+$self->validate_individual($self->value());
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
258 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
259 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
260
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
261
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
262 sub get_repeat_idx_name {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
263 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
264 return 'item';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
265 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
266
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
267
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
268 sub get_repeat_name {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
269 my ($self) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
270 if($self->multiple()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
271 return sprintf('repeat_%s', $self->get_galaxy_cli_identifier());
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
272 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
273 confess "Tried to get repeat name for non-multiple item";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
274 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
275 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
276
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
277
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
278 sub handle_possible_galaxy_input_repeat_start {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
279 my ($self, $xml_writer ) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
280 if ( $self->multiple() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
281 my $title = $self->get_galaxy_cli_identifier();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
282 $title =~ s/_/ /g;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
283 # Convert To Title Case (http://www.davekb.com/browse_programming_tips:perl_title_case:txt)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
284 $title =~ s/(\w+)/\u\L$1/g;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
285 $xml_writer->startTag(
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
286 'repeat',
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
287 'name' => $self->get_repeat_name(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
288 'title' => $title,
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
289 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
290 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
291 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
292
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
293
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
294 sub handle_possible_galaxy_input_repeat_end {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
295 my ($self, $xml_writer ) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
296 if ( $self->multiple() ) {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
297 $xml_writer->endTag('repeat');
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
298 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
299 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
300
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
301
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
302
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
303 sub handle_possible_galaxy_command_repeat_start {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
304 my ( $self ) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
305 if($self->multiple()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
306 return sprintf("#for \$%s in \$%s:\n",
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
307 $self->get_repeat_idx_name(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
308 $self->get_repeat_name()
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
309 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
310 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
311 return '';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
312 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
313 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
314
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
315
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
316 sub handle_possible_galaxy_command_repeat_end {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
317 my ( $self ) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
318 if($self->multiple()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
319 return "#end for\n";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
320 }else{
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
321 return '';
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
322 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
323 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
324
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
325 sub get_default_input_parameters {
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
326 my ( $self, $type ) = @_;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
327 my %params = (
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
328 name => $self->get_galaxy_cli_identifier(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
329 optional => $self->is_optional_galaxy(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
330 label => $self->get_galaxy_cli_identifier(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
331 help => $self->description(),
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
332 type => $type,
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
333 );
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
334
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
335 # Multiple values would return ARRAY(0xAAAAAAA) locations, so we have to
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
336 # handle those semi-intelligently until galaxy can handle default values
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
337 # for repeats
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
338 if($self->multiple() && defined $self->default()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
339 if(ref($self->default()) ne 'ARRAY'){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
340 carp "Author specified a non-array default value for " . $self->name() . ", which allows multiple values. Script author should modify the default value to be an ArrayRef.";
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
341 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
342 $params{value} = ${$self->default}[0];
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
343 }elsif(!$self->multiple() && defined $self->default()){
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
344 $params{value} = $self->default();
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
345 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
346
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
347 return %params;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
348 }
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
349
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
350 no Moose::Role;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
351
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
352 1;
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
353
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
354 __END__
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
355
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
356 =pod
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
357
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
358 =encoding UTF-8
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
359
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
360 =head1 NAME
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
361
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
362 CPT::Parameter
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
363
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
364 =head1 VERSION
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
365
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
366 version 1.99.4
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
367
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
368 =head2 galaxy_command
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
369
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
370 $file_param->galaxy_command(); # where $file_param is a CPT::Parameter::*
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
371
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
372 Returns the portion of the command used in the <command/> block in galaxy XML files
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
373
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
374 =head2 getOptionsArray
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
375
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
376 When called on a CPT::Parameter::* object, it will collapse the object into a GetOpt::Long compatible array
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
377
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
378 =head2 getopt_identifier
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
379
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
380 Used for backwards compatability with existing defaults => { 'file|f=s' => "Blah" } format
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
381
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
382 =head2 get_galaxy_identifier
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
383
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
384 Returns the identifier associated with a given variable. This identifier is what the Cheetah template knows the variable as (given the correct context).
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
385
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
386 For non-multiple variables it should be the name of the variable.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
387
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
388 For multiple variables it will reference the repeat item name and then the variable name (e.g., C< $item.label >)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
389
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
390 =head2 get_galaxy_cli_identifier
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
391
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
392 Returns the command line identifier (i.e., the command line flag) associated
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
393 with a given parameter. For a `--format` flag, this would return "format".
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
394 This should work out of the box, as CLI parameters have the same name as we
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
395 specify them with (even if they're repeated)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
396
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
397 =head2 is_optional
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
398
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
399 If required, it is NOT optional; If not reqiured, it IS optional
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
400
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
401 =head2 is_optional_galaxy
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
402
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
403 Returns is_optional() as "True" or "False" for convenience and reduced code duplication
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
404
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
405 =head2 update_index
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
406
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
407 Convenience method to increment the index. This wraps around.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
408
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
409 =head2 reset_index
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
410
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
411 convenience method to zero the index (i.e., the next get_value request will start at the beginning again)
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
412
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
413 =head2 get_value
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
414
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
415 Returns the value in the current index.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
416
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
417 =head2 get_default
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
418
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
419 Returns the default in the current index. Something to note, please bear in
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
420 mind this you are trying to access an array based on an index which wraps
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
421 according to value() not according to default(). This means you may not reach
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
422 the end of default/reach over the end of default depending on how many values
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
423 the user actually passes
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
424
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
425 =head2 validate
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
426
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
427 Validation logic was eventually moved out here, as the logic for validaton is
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
428 identical everywhere, and requires slightly different behaviour based on
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
429 wheterh or not it's a single/multiple valued item.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
430
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
431 =head2 get_repeat_idx_name
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
432
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
433 Function to obtain the name of the item as it is called inside the repeat. This
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
434 is necessary to know which variable we are referring to within a loop.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
435
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
436 =head2 get_repeat_name
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
437
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
438 Function to obtain the name of the repeat. It is necessary that this is used
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
439 identically in the command section as well as in the input section.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
440
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
441 =head2 handle_possible_galaxy_input_repeat_start
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
442
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
443 If the feature is repeated, this should automatically handle the start of that
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
444 repeat
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
445
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
446 =head2 handle_possible_galaxy_input_repeat_end
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
447
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
448 If the feature is repeated, this should automatically handle the end of that
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
449 repeat
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
450
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
451 =head2 handle_possible_galaxy_command_repeat_start
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
452
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
453 If the feature is repeated, this should automatically handle the start of that
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
454 repeat with a
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
455
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
456 #for $item in $repeat_name:
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
457
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
458 =head2 handle_possible_galaxy_command_repeat_end
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
459
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
460 If the feature is repeated, this should automatically handle the end of that
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
461 repeat with
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
462
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
463 #end for
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
464
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
465 =head1 AUTHOR
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
466
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
467 Eric Rasche <rasche.eric@yandex.ru>
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
468
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
469 =head1 COPYRIGHT AND LICENSE
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
470
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
471 This software is Copyright (c) 2014 by Eric Rasche.
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
472
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
473 This is free software, licensed under:
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
474
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
475 The GNU General Public License, Version 3, June 2007
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
476
b8b8b52904a5 Uploaded
cpt
parents:
diff changeset
477 =cut