From 7017833f42499ef37a0010a8840b69f364b6f83c Mon Sep 17 00:00:00 2001 From: Carl Eberhard Date: Thu, 28 Aug 2014 09:44:56 -0400 Subject: [PATCH] Vis registry: add two tests (has_attribute, not_eq); add see also for test types in visualization.dtd; correct applicability tests for trackster and circster using not_eq on datatype.track_type --- .../visualizations/circster/config/circster.xml | 4 ++-- .../trackster/config/trackster.xml | 4 ++-- config/plugins/visualizations/visualization.dtd | 3 ++- lib/galaxy/visualization/registry.py | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/config/plugins/visualizations/circster/config/circster.xml b/config/plugins/visualizations/circster/config/circster.xml index d5d11596b98..c572ea29323 100644 --- a/config/plugins/visualizations/circster/config/circster.xml +++ b/config/plugins/visualizations/circster/config/circster.xml @@ -4,13 +4,13 @@ HistoryDatasetAssociation - data.Data + None dataset_id hda_ldda LibraryDatasetDatasetAssociation - data.Data + None dataset_id hda_ldda diff --git a/config/plugins/visualizations/trackster/config/trackster.xml b/config/plugins/visualizations/trackster/config/trackster.xml index 385e9b415ab..bba0900d04d 100644 --- a/config/plugins/visualizations/trackster/config/trackster.xml +++ b/config/plugins/visualizations/trackster/config/trackster.xml @@ -5,14 +5,14 @@ HistoryDatasetAssociation - data.Data + None dataset_id hda_ldda dbkey LibraryDatasetDatasetAssociation - data.Data + None dataset_id hda_ldda diff --git a/config/plugins/visualizations/visualization.dtd b/config/plugins/visualizations/visualization.dtd index 7fe9d9a0868..18337596252 100644 --- a/config/plugins/visualizations/visualization.dtd +++ b/config/plugins/visualizations/visualization.dtd @@ -33,7 +33,8 @@ Currently, all tests are OR'd and there is no logical grouping. Tests are run in order. (text): the text of this element is what the given target will be compared to (REQUIRED) type: what type of test to run (e.g. when the target is an HDA the test will often be of type 'isinstance' - and test whether the HDA's datatype isinstace of a class) + and test whether the HDA's datatype isinstace of a class). + See lib/galaxy/visualizations/registry.py, DataSourceParser.parse_tests for test type options. DEFAULT: string comparison. test_attr: what attribute of the target object should be used in the test. For instance, 'datatype' will attempt to get the HDA.datatype from a target HDA. If the given object doesn't have diff --git a/lib/galaxy/visualization/registry.py b/lib/galaxy/visualization/registry.py index beec9c28b70..da59db12298 100644 --- a/lib/galaxy/visualization/registry.py +++ b/lib/galaxy/visualization/registry.py @@ -203,6 +203,7 @@ class VisualizationsRegistry( pluginframework.PageServingPluginManager ): #log.debug( '\t passed model_class' ) # tests are optional - default is the above class test +#TODO: not true: must have test currently tests = data_source[ 'tests' ] if tests and not self.is_object_applicable( trans, target_object, tests ): continue @@ -228,14 +229,14 @@ class VisualizationsRegistry( pluginframework.PageServingPluginManager ): Run a visualization's data_source tests to find out if it can be applied to the target_object. """ - #log.debug( 'is_object_applicable( self, trans, %s, %s )', target_object, data_source_tests ) + log.debug( 'is_object_applicable( self, trans, %s, %s )', target_object, data_source_tests ) for test in data_source_tests: test_type = test[ 'type' ] result_type = test[ 'result_type' ] test_result = test[ 'result' ] test_fn = test[ 'fn' ] - #log.debug( '%s %s: %s, %s, %s, %s', str( target_object ), 'is_object_applicable', - # test_type, result_type, test_result, test_fn ) + log.debug( '%s %s: %s, %s, %s, %s', str( target_object ), 'is_object_applicable', + test_type, result_type, test_result, test_fn ) if test_type == 'isinstance': # parse test_result based on result_type (curr: only datatype has to do this) @@ -253,7 +254,7 @@ class VisualizationsRegistry( pluginframework.PageServingPluginManager ): #NOTE: tests are OR'd, if any test passes - the visualization can be applied if test_fn( target_object, test_result ): - #log.debug( '\t test passed' ) + log.debug( '\t test passed' ) return True return False @@ -407,6 +408,7 @@ class VisualizationsConfigParser( object ): # allow manually turning off a vis by checking for a disabled property if 'disabled' in xml_tree.attrib: +#TODO: differentiate between disabled and failed to parse, log.warn only on failure, log.info otherwise return None # a text display name for end user links @@ -627,6 +629,13 @@ class DataSourceParser( object ): test_fn = lambda o, result: ( hasattr( getter( o ), 'has_dataprovider' ) and getter( o ).has_dataprovider( result ) ) + elif test_type == 'has_attribute': + # does the object itself have attr in 'result' (no equivalence checking) + test_fn = lambda o, result: hasattr( getter( o ), result ) + + elif test_type == 'not_eq': + test_fn = lambda o, result: str( getter( o ) ) != result + else: # default to simple (string) equilavance (coercing the test_attr to a string) test_fn = lambda o, result: str( getter( o ) ) == result