Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Validation on number of inputs added

This commit is contained in:
Reidar Strand Hagen 2006-05-03 11:52:54 +00:00
parent a613f0a3fa
commit 56a6028547
6 changed files with 52 additions and 43 deletions

View File

@ -21,9 +21,10 @@ class NavigatorView (gtk.TreeView):
# Selection Mode # Selection Mode
self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
self.get_selection().set_select_function(self.is_selectable) self.get_selection().set_select_function(self.is_selectable)
self.get_selection().connect('changed',self.selection_changed_handler)
# Setting up TextRenderers etc # 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) self.connect('row_activated', self.row_activated_handler)
textrenderer = gtk.CellRendererText() textrenderer = gtk.CellRendererText()
@ -68,11 +69,8 @@ class NavigatorView (gtk.TreeView):
return True return True
# selection changed, setting current_data ojbects # selection changed, setting current_data ojbects
def cursor_changed_handler(self, widget): def selection_changed_handler(self, selection):
selection = widget.get_selection()
model, paths = selection.get_selected_rows() model, paths = selection.get_selected_rows()
objs = [self.data_tree.get_value(self.data_tree.get_iter(path),2) for path in paths] 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): if objs and isinstance(objs[0], dataset.Dataset):
logger.log('debug', 'Selecting dataset') logger.log('debug', 'Selecting dataset')
self.project.set_current_data(objs) 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 # TreeView changed. Set correct focus and colours
def row_changed_handler(self, treestore, pos, iter): def row_changed_handler(self, treestore, pos, iter):
obj = treestore.get_value(iter,2) obj = treestore.get_value(iter,2)

View File

@ -13,7 +13,7 @@ class Project:
self.name = name self.name = name
self.dim_names = [] self.dim_names = []
self._selection_observers = [] self._selection_observers = []
self.current_data = None self.current_data = []
self.datasets = [] self.datasets = []
self.sel_obj = dataset.Selection() self.sel_obj = dataset.Selection()

View File

@ -114,12 +114,19 @@ class Function:
self.id = id self.id = id
self.name = name self.name = name
def valid_input(input): # ,ust return a Validation object
return True def validate_input(input):
return Validation(True,"Validation Not Implemented")
def run(self, data): def run(self):
pass pass
class Validation:
def __init__(self,result, reason):
self.succeeded = result
self.reason = reason
class WorkflowView (gtk.VBox): class WorkflowView (gtk.VBox):
def __init__(self, wf): def __init__(self, wf):
@ -162,10 +169,25 @@ class WorkflowView (gtk.VBox):
project = self.workflow.app.project project = self.workflow.app.project
parent_data = project.current_data 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: if new_data != None:
project.add_data(parent_data, new_data, function.name) project.add_data(parent_data, new_data, function.name)
logger.log('debug', 'Function ended: %s' % function.name) logger.log('debug', 'Function ended: %s' % function.name)
def button_click_handler(self, button): def button_click_handler(self, button):

View File

@ -31,7 +31,7 @@ class TestDataFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'test_data', 'Generate Test Data') workflow.Function.__init__(self, 'test_data', 'Generate Test Data')
def run(self, data): def run(self):
logger.log('notice', 'Injecting foo test data') logger.log('notice', 'Injecting foo test data')
x = randn(20,30) x = randn(20,30)
X = dataset.Dataset(x) X = dataset.Dataset(x)
@ -43,7 +43,7 @@ class DatasetLoadFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'load_data', 'Load Pickled Dataset') 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, chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN, action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
@ -69,7 +69,7 @@ class DatasetSaveFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset') workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset')
def run(self, data): def run(self):
if not data: if not data:
logger.log("notice", "No data to save.") logger.log("notice", "No data to save.")
return return
@ -103,7 +103,7 @@ class CelFileImportFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'cel_import', 'Import Affy') workflow.Function.__init__(self, 'cel_import', 'Import Affy')
def run(self, (data,)): def run(self,data):
import rpy import rpy
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN, action=gtk.FILE_CHOOSER_ACTION_OPEN,
@ -152,7 +152,7 @@ class PCAFunction(workflow.Function):
workflow.Function.__init__(self, 'pca', 'PCA') workflow.Function.__init__(self, 'pca', 'PCA')
self._workflow = wf self._workflow = wf
def run(self, (data,)): def run(self,data):
import rpy import rpy
dim_2, dim_1 = data.get_dim_names() dim_2, dim_1 = data.get_dim_names()

View File

@ -65,7 +65,7 @@ class LoadAnnotationsFunction(workflow.Function):
logger.log('notice', 'Reading file: %s' % dialog.get_filename()) logger.log('notice', 'Reading file: %s' % dialog.get_filename())
self.load_file(dialog.get_filename()) self.load_file(dialog.get_filename())
def run(self, data): def run(self):
btns = ('Open', gtk.RESPONSE_OK, \ btns = ('Open', gtk.RESPONSE_OK, \
'Cancel', gtk.RESPONSE_CANCEL) 'Cancel', gtk.RESPONSE_CANCEL)
dialog = gtk.FileChooserDialog('Open GO Annotation File', dialog = gtk.FileChooserDialog('Open GO Annotation File',
@ -81,7 +81,7 @@ class GODistanceFunction(workflow.Function):
workflow.Function.__init__(self, 'go_diatance', 'GO Distances') workflow.Function.__init__(self, 'go_diatance', 'GO Distances')
self.output = None self.output = None
def run(self, (data,)): def run(self, data):
logger.log('debug', 'datatype: %s' % type(data)) logger.log('debug', 'datatype: %s' % type(data))
if not type(data) == Annotations: if not type(data) == Annotations:
return None return None
@ -98,7 +98,7 @@ class TestDataFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'test_data', 'Generate Test Data') workflow.Function.__init__(self, 'test_data', 'Generate Test Data')
def run(self, data): def run(self):
logger.log('notice', 'Injecting foo test data') logger.log('notice', 'Injecting foo test data')
x = randn(20,30) x = randn(20,30)
X = dataset.Dataset(x) X = dataset.Dataset(x)
@ -108,7 +108,7 @@ class DatasetLog(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'log', 'Log') 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()) logger.log('notice', 'Taking the log of dataset %s' % data.get_name())
d = data.asarray() d = data.asarray()
d = log(d) d = log(d)
@ -121,7 +121,7 @@ class DatasetLoadFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'load_data', 'Load Pickled Dataset') 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, chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN, action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
@ -147,7 +147,7 @@ class DatasetSaveFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset') workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset')
def run(self, data): def run(self):
if not data: if not data:
logger.log("notice", "No data to save.") logger.log("notice", "No data to save.")
return return
@ -180,7 +180,7 @@ class CelFileImportFunction(workflow.Function):
def __init__(self): def __init__(self):
workflow.Function.__init__(self, 'cel_import', 'Import Affy') workflow.Function.__init__(self, 'cel_import', 'Import Affy')
def run(self, (data,)): def run(self, data):
import rpy import rpy
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None, chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN, action=gtk.FILE_CHOOSER_ACTION_OPEN,
@ -229,7 +229,7 @@ class PCAFunction(workflow.Function):
workflow.Function.__init__(self, 'pca', 'PCA') workflow.Function.__init__(self, 'pca', 'PCA')
self._workflow = wf self._workflow = wf
def run(self, (data,)): def run(self, data):
import rpy import rpy
dim_2, dim_1 = data.get_dim_names() dim_2, dim_1 = data.get_dim_names()

View File

@ -49,7 +49,7 @@ class LoadAnnotationsFunction(Function):
logger.log('notice', 'Reading file: %s' % dialog.get_filename()) logger.log('notice', 'Reading file: %s' % dialog.get_filename())
self.load_affy_file(dialog.get_filename()) self.load_affy_file(dialog.get_filename())
def run(self, (data,)): def run(self,data):
btns = ('Open', gtk.RESPONSE_OK, \ btns = ('Open', gtk.RESPONSE_OK, \
'Cancel', gtk.RESPONSE_CANCEL) 'Cancel', gtk.RESPONSE_CANCEL)
dialog = gtk.FileChooserDialog('Open Affy Annotation File', dialog = gtk.FileChooserDialog('Open Affy Annotation File',
@ -81,7 +81,7 @@ class PCAFunction(Function):
self.output = None self.output = None
self.workflow = workflow self.workflow = workflow
def run(self, (data,)): def run(self,data):
logger.log('debug', 'datatype: %s' % type(data)) logger.log('debug', 'datatype: %s' % type(data))
if not isinstance(data,dataset.Dataset): if not isinstance(data,dataset.Dataset):
return None return None
@ -226,7 +226,7 @@ class LoadMoothaData(Function):
def __init__(self): def __init__(self):
Function.__init__(self, 'load', 'Load diabetes data') Function.__init__(self, 'load', 'Load diabetes data')
def run(self,(data,)): def run(self,data):
data_file = open('full_data.pickle','r') data_file = open('full_data.pickle','r')
data = pickle.load(data_file) data = pickle.load(data_file)
data_file.close() data_file.close()
@ -250,7 +250,7 @@ class Log2Function(Function):
def __init__(self): def __init__(self):
Function.__init__(self, 'log', 'Log2') Function.__init__(self, 'log', 'Log2')
def run(self,(data,)): def run(self,data):
x = log2(data._array) x = log2(data._array)
#pull out identifiers #pull out identifiers
ids = [] ids = []