empty_field validator for multi-select column parameter
Hi all, I have a tool where for one parameter I want the user to pick one or more columns from a tabular file. Other tools do this too, e.g. filters/uniq.xml (the Statistics "Count" tool) uses: <inputs> <param name="input" type="data" format="tabular" label="from query" help="Query missing? See TIP below"/> <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns" /> ... </inputs> I would like extend this by adding a validator to prevent the user trying to run my tool with no columns (in fact, I think this would be a good idea for filters/uniq.xml as well - currently the error is only spotted when the tool is run). There is a list of validators given on the wiki page, http://bitbucket.org/galaxy/galaxy-central/wiki/ToolConfigSyntax I expected to be able to use the empty_field validator, but that doesn't work - is this a bug?: <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns"> <validator type="empty_field" message="Pick at least one column"/> </param> I found a workaround, based on the fact that no columns is passed to the command line tools as the string 'None', using the expression validator: <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns"> <validator type="expression" message="Pick at least one column">str(value)!='None'</validator> </param> Peter
On Tue, Nov 23, 2010 at 11:19 AM, Peter <peter@maubp.freeserve.co.uk> wrote:
Hi all,
I have a tool where for one parameter I want the user to pick one or more columns from a tabular file. Other tools do this too, e.g. filters/uniq.xml (the Statistics "Count" tool) uses:
<inputs> <param name="input" type="data" format="tabular" label="from query" help="Query missing? See TIP below"/> <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns" /> ... </inputs>
I would like extend this by adding a validator to prevent the user trying to run my tool with no columns (in fact, I think this would be a good idea for filters/uniq.xml as well - currently the error is only spotted when the tool is run).
There is a list of validators given on the wiki page, http://bitbucket.org/galaxy/galaxy-central/wiki/ToolConfigSyntax
I expected to be able to use the empty_field validator, but that doesn't work - is this a bug?:
<param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns"> <validator type="empty_field" message="Pick at least one column"/> </param>
If this is a bug, the following seems to fix it: diff -r 91b1759c7c18 lib/galaxy/tools/parameters/validation.py --- a/lib/galaxy/tools/parameters/validation.py Mon Nov 22 17:38:52 2010 +0000 +++ b/lib/galaxy/tools/parameters/validation.py Tue Nov 23 11:25:31 2010 +0000 @@ -226,7 +226,7 @@ def from_element( cls, param, elem ): return cls( elem.get( 'message', None ) ) def validate( self, value, history=None ): - if value == '': + if value == '' or value is None: if self.message is None: self.message = "Field requires a value" raise ValueError( self.message ) Alternatively, from looking at the comments in the code I saw the no_options validator is to check for an empty select list, and that works. Maybe these two validators could be combined into one since they are almost identical? In the meantime, would someone like to commit the following enhancement to the count tool to validate the column argument before running the tool? --- a/tools/filters/uniq.xml Mon Nov 22 17:38:52 2010 +0000 +++ b/tools/filters/uniq.xml Tue Nov 23 11:31:35 2010 +0000 @@ -3,7 +3,9 @@ <command interpreter="python">uniq.py -i $input -o $out_file1 -c "$column" -d $delim</command> <inputs> <param name="input" type="data" format="tabular" label="from query" help="Query missing? See TIP below"/> - <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns" /> + <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Count occurrences of values in column(s)" help="Multi-select list - hold the appropriate key while clicking to select multiple columns"> + <validator type="no_options" message="Pick at least one column" /> + </param> <param name="delim" type="select" label="Delimited by"> <option value="T">Tab</option> <option value="Sp">Whitespace</option> Regards, Peter
participants (1)
-
Peter