1 new changeset in galaxy-central: http://bitbucket.org/galaxy/galaxy-central/changeset/150069a23aad/ changeset: 150069a23aad user: dan date: 2011-10-19 16:14:51 summary: Add dataset_metadata_in_data_table validator. Mimics behavior of dataset_metadata_in_file, but uses data tables. affected #: 1 file (-1 bytes) --- a/lib/galaxy/tools/parameters/validation.py Tue Oct 18 16:57:45 2011 -0400 +++ b/lib/galaxy/tools/parameters/validation.py Wed Oct 19 10:14:51 2011 -0400 @@ -189,7 +189,7 @@ class UnspecifiedBuildValidator( Validator ): """ - Validator that checks for missing metadata + Validator that checks for dbkey not equal to '?' """ def __init__( self, message=None ): if message is None: @@ -268,6 +268,45 @@ return raise ValueError( self.message ) +class MetadataInDataTableColumnValidator( Validator ): + """ + Validator that checks if the value for a dataset's metadata item exists in a file. + """ + @classmethod + def from_element( cls, param, elem ): + table_name = elem.get( "table_name", None ) + assert table_name, 'You must specify a table_name.' + tool_data_table = param.tool.app.tool_data_tables[ table_name ] + metadata_name = elem.get( "metadata_name", None ) + if metadata_name: + metadata_name = metadata_name.strip() + metadata_column = elem.get( "metadata_column", 0 ) + try: + metadata_column = int( metadata_column ) + except: + pass + message = elem.get( "message", "Value for metadata %s was not found in %s." % ( metadata_name, table_name ) ) + line_startswith = elem.get( "line_startswith", None ) + if line_startswith: + line_startswith = line_startswith.strip() + return cls( tool_data_table, metadata_name, metadata_column, message, line_startswith ) + def __init__( self, tool_data_table, metadata_name, metadata_column, message="Value for metadata not found.", line_startswith=None ): + self.metadata_name = metadata_name + self.message = message + self.valid_values = [] + if isinstance( metadata_column, basestring ): + metadata_column = tool_data_table.columns[ metadata_column ] + for fields in tool_data_table.get_fields(): + if metadata_column < len( fields ): + self.valid_values.append( fields[ metadata_column ] ) + def validate( self, value, history = None ): + if not value: return + if hasattr( value, "metadata" ): + if value.metadata.spec[self.metadata_name].param.to_string( value.metadata.get( self.metadata_name ) ) in self.valid_values: + return + raise ValueError( self.message ) + + validator_types = dict( expression=ExpressionValidator, regex=RegexValidator, in_range=InRangeValidator, @@ -277,6 +316,7 @@ no_options=NoOptionsValidator, empty_field=EmptyTextfieldValidator, dataset_metadata_in_file=MetadataInFileColumnValidator, + dataset_metadata_in_data_table=MetadataInDataTableColumnValidator, dataset_ok_validator=DatasetOkValidator ) def get_suite(): Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.