From 56a6028547830e40c25fdfd54c075f907d3f6671 Mon Sep 17 00:00:00 2001 From: reidarst Date: Wed, 3 May 2006 11:52:54 +0000 Subject: [PATCH] Validation on number of inputs added --- system/navigator.py | 27 +++++++-------------------- system/project.py | 2 +- system/workflow.py | 32 +++++++++++++++++++++++++++----- workflows/affy_workflow.py | 10 +++++----- workflows/go_workflow.py | 16 ++++++++-------- workflows/pca_workflow.py | 8 ++++---- 6 files changed, 52 insertions(+), 43 deletions(-) diff --git a/system/navigator.py b/system/navigator.py index e37e2a7..0a823d2 100644 --- a/system/navigator.py +++ b/system/navigator.py @@ -21,9 +21,10 @@ class NavigatorView (gtk.TreeView): # Selection Mode self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.get_selection().set_select_function(self.is_selectable) + self.get_selection().connect('changed',self.selection_changed_handler) # Setting up TextRenderers etc - self.connect('cursor_changed', self.cursor_changed_handler) + # self.connect('cursor_changed', self.cursor_changed_handler) self.connect('row_activated', self.row_activated_handler) textrenderer = gtk.CellRendererText() @@ -68,11 +69,8 @@ class NavigatorView (gtk.TreeView): return True # selection changed, setting current_data ojbects - def cursor_changed_handler(self, widget): - - - - selection = widget.get_selection() + def selection_changed_handler(self, selection): + model, paths = selection.get_selected_rows() objs = [self.data_tree.get_value(self.data_tree.get_iter(path),2) for path in paths] @@ -80,22 +78,11 @@ class NavigatorView (gtk.TreeView): if objs and isinstance(objs[0], dataset.Dataset): logger.log('debug', 'Selecting dataset') self.project.set_current_data(objs) + else: + logger.log('debug', 'Deselecting dataset') + self.project.set_current_data([]) - # current object hasn't been added to selection yet, so we're adding it in - cur_path, column = widget.get_cursor() - - obj = model.get_value(model.get_iter(cur_path),2) - objs = [model.get_value(model.get_iter(path), 2) for path in paths] - - if (not obj in objs) and isinstance(obj, dataset.Dataset): - objs += obj - - if objs: - if isinstance(objs[0], dataset.Dataset): - logger.log('debug', 'Selecting dataset') - self.project.set_current_data(objs) - # TreeView changed. Set correct focus and colours def row_changed_handler(self, treestore, pos, iter): obj = treestore.get_value(iter,2) diff --git a/system/project.py b/system/project.py index 452af37..0738054 100644 --- a/system/project.py +++ b/system/project.py @@ -13,7 +13,7 @@ class Project: self.name = name self.dim_names = [] self._selection_observers = [] - self.current_data = None + self.current_data = [] self.datasets = [] self.sel_obj = dataset.Selection() diff --git a/system/workflow.py b/system/workflow.py index d65b1e7..37f3182 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -114,12 +114,19 @@ class Function: self.id = id self.name = name - def valid_input(input): - return True + # ,ust return a Validation object + def validate_input(input): + return Validation(True,"Validation Not Implemented") - def run(self, data): + def run(self): pass +class Validation: + def __init__(self,result, reason): + self.succeeded = result + self.reason = reason + + class WorkflowView (gtk.VBox): def __init__(self, wf): @@ -162,10 +169,25 @@ class WorkflowView (gtk.VBox): project = self.workflow.app.project parent_data = project.current_data - new_data = function.run(project.current_data) + validation = function.validate_input() + + if not validation.succeeded: + logger.log('warning','Invalid Inputdata: ' + str(reason)) + return + + argcount =function.run.func_code.co_argcount - 1 + + if argcount != len(parent_data): + logger.log('warning','Method requires ' + str(argcount) + ' Data. ' + str(len(parent_data)) + ' selected') + return + if not project.current_data: + new_data = function.run() + else: + new_data = function.run(*project.current_data) + if new_data != None: project.add_data(parent_data, new_data, function.name) - + logger.log('debug', 'Function ended: %s' % function.name) def button_click_handler(self, button): diff --git a/workflows/affy_workflow.py b/workflows/affy_workflow.py index 1bebb40..cc2d642 100644 --- a/workflows/affy_workflow.py +++ b/workflows/affy_workflow.py @@ -31,7 +31,7 @@ class TestDataFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'test_data', 'Generate Test Data') - def run(self, data): + def run(self): logger.log('notice', 'Injecting foo test data') x = randn(20,30) X = dataset.Dataset(x) @@ -43,7 +43,7 @@ class DatasetLoadFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'load_data', 'Load Pickled Dataset') - def run(self, data): + def run(self): chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, @@ -69,7 +69,7 @@ class DatasetSaveFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset') - def run(self, data): + def run(self): if not data: logger.log("notice", "No data to save.") return @@ -103,7 +103,7 @@ class CelFileImportFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'cel_import', 'Import Affy') - def run(self, (data,)): + def run(self,data): import rpy chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, @@ -152,7 +152,7 @@ class PCAFunction(workflow.Function): workflow.Function.__init__(self, 'pca', 'PCA') self._workflow = wf - def run(self, (data,)): + def run(self,data): import rpy dim_2, dim_1 = data.get_dim_names() diff --git a/workflows/go_workflow.py b/workflows/go_workflow.py index dcfa0e1..4a893c6 100644 --- a/workflows/go_workflow.py +++ b/workflows/go_workflow.py @@ -65,7 +65,7 @@ class LoadAnnotationsFunction(workflow.Function): logger.log('notice', 'Reading file: %s' % dialog.get_filename()) self.load_file(dialog.get_filename()) - def run(self, data): + def run(self): btns = ('Open', gtk.RESPONSE_OK, \ 'Cancel', gtk.RESPONSE_CANCEL) dialog = gtk.FileChooserDialog('Open GO Annotation File', @@ -81,7 +81,7 @@ class GODistanceFunction(workflow.Function): workflow.Function.__init__(self, 'go_diatance', 'GO Distances') self.output = None - def run(self, (data,)): + def run(self, data): logger.log('debug', 'datatype: %s' % type(data)) if not type(data) == Annotations: return None @@ -98,7 +98,7 @@ class TestDataFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'test_data', 'Generate Test Data') - def run(self, data): + def run(self): logger.log('notice', 'Injecting foo test data') x = randn(20,30) X = dataset.Dataset(x) @@ -108,7 +108,7 @@ class DatasetLog(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'log', 'Log') - def run(self, (data,)): + def run(self, data): logger.log('notice', 'Taking the log of dataset %s' % data.get_name()) d = data.asarray() d = log(d) @@ -121,7 +121,7 @@ class DatasetLoadFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'load_data', 'Load Pickled Dataset') - def run(self, data): + def run(self): chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, @@ -147,7 +147,7 @@ class DatasetSaveFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset') - def run(self, data): + def run(self): if not data: logger.log("notice", "No data to save.") return @@ -180,7 +180,7 @@ class CelFileImportFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'cel_import', 'Import Affy') - def run(self, (data,)): + def run(self, data): import rpy chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, @@ -229,7 +229,7 @@ class PCAFunction(workflow.Function): workflow.Function.__init__(self, 'pca', 'PCA') self._workflow = wf - def run(self, (data,)): + def run(self, data): import rpy dim_2, dim_1 = data.get_dim_names() diff --git a/workflows/pca_workflow.py b/workflows/pca_workflow.py index e5409f0..4f83a74 100644 --- a/workflows/pca_workflow.py +++ b/workflows/pca_workflow.py @@ -49,7 +49,7 @@ class LoadAnnotationsFunction(Function): logger.log('notice', 'Reading file: %s' % dialog.get_filename()) self.load_affy_file(dialog.get_filename()) - def run(self, (data,)): + def run(self,data): btns = ('Open', gtk.RESPONSE_OK, \ 'Cancel', gtk.RESPONSE_CANCEL) dialog = gtk.FileChooserDialog('Open Affy Annotation File', @@ -81,7 +81,7 @@ class PCAFunction(Function): self.output = None self.workflow = workflow - def run(self, (data,)): + def run(self,data): logger.log('debug', 'datatype: %s' % type(data)) if not isinstance(data,dataset.Dataset): return None @@ -226,7 +226,7 @@ class LoadMoothaData(Function): def __init__(self): Function.__init__(self, 'load', 'Load diabetes data') - def run(self,(data,)): + def run(self,data): data_file = open('full_data.pickle','r') data = pickle.load(data_file) data_file.close() @@ -250,7 +250,7 @@ class Log2Function(Function): def __init__(self): Function.__init__(self, 'log', 'Log2') - def run(self,(data,)): + def run(self,data): x = log2(data._array) #pull out identifiers ids = []