124 lines
3.4 KiB
Python
124 lines
3.4 KiB
Python
|
|
||
|
import gtk
|
||
|
import logger
|
||
|
|
||
|
class Workflow:
|
||
|
"""Defines a workflow that contains a set of analysis stages.
|
||
|
|
||
|
A Workflow is a set of analysis stages for a certain type of analysis.
|
||
|
Each stage contains some possible operations to do accomplish that
|
||
|
task.
|
||
|
"""
|
||
|
|
||
|
def __init__(self, app):
|
||
|
self.name = ''
|
||
|
self.stages = []
|
||
|
self.stages_by_id = {}
|
||
|
self.app = app
|
||
|
|
||
|
def add_stage(self, stage):
|
||
|
self.stages.append(stage)
|
||
|
self.stages_by_id[stage.id] = stage
|
||
|
|
||
|
def print_tree(self):
|
||
|
print self.name
|
||
|
for stage in self.stages:
|
||
|
print ' %s' % stage.name
|
||
|
for fun in stage.functions:
|
||
|
print ' %s' % fun.name
|
||
|
|
||
|
class Stage:
|
||
|
"""A stage is a part of the data analysis process.
|
||
|
|
||
|
Each stage contains a set of functions that can be used to
|
||
|
accomplish the task. A typical early stage is 'preprocessing', which
|
||
|
can be done in several ways, each represented by a function.
|
||
|
"""
|
||
|
|
||
|
def __init__(self, id, name):
|
||
|
self.id = id
|
||
|
self.name = name
|
||
|
self.functions = []
|
||
|
self.functions_by_id = {}
|
||
|
|
||
|
def add_function(self, fun):
|
||
|
self.functions.append(fun)
|
||
|
self.functions_by_id[fun.id] = fun
|
||
|
|
||
|
class Function:
|
||
|
"""A Function object encapsulates a function on a data set.
|
||
|
|
||
|
Each Function instance encapsulates some function that can be applied
|
||
|
to one or more types of data.
|
||
|
"""
|
||
|
|
||
|
def __init__(self, id, name):
|
||
|
self.id = id
|
||
|
self.name = name
|
||
|
|
||
|
def valid_input(input):
|
||
|
return True
|
||
|
|
||
|
def run(self, data):
|
||
|
pass
|
||
|
|
||
|
def foo():
|
||
|
print "foo"
|
||
|
|
||
|
class EinarsWorkflow (Workflow):
|
||
|
|
||
|
def __init__(self, app):
|
||
|
Workflow.__init__(self, app)
|
||
|
self.name = 'Einar\'s Workflow'
|
||
|
|
||
|
load = Stage('load', 'Load Data')
|
||
|
load.add_function(Function('load', 'Load Microarrays'))
|
||
|
self.add_stage(load)
|
||
|
|
||
|
preproc = Stage('preprocess', 'Preprocessing')
|
||
|
preproc.add_function(Function('rma', 'RMA'))
|
||
|
self.add_stage(preproc)
|
||
|
|
||
|
go = Stage('go', 'Gene Ontology Data')
|
||
|
go.add_function(Function('godist', 'GO Distances'))
|
||
|
self.add_stage(go)
|
||
|
|
||
|
regression = Stage('regression', 'Regression')
|
||
|
regression.add_function(Function('pls', 'PLS'))
|
||
|
self.add_stage(regression)
|
||
|
|
||
|
logger.log('debug', 'Einar\'s workflow is now active')
|
||
|
|
||
|
class WorkflowView (gtk.VBox):
|
||
|
|
||
|
def __init__(self, wf):
|
||
|
gtk.VBox.__init__(self)
|
||
|
self.workflow = wf
|
||
|
|
||
|
# Add stage in the process
|
||
|
for stage in wf.stages:
|
||
|
exp = gtk.Expander(stage.name)
|
||
|
btn_box = gtk.VBox()
|
||
|
btn_box.show()
|
||
|
exp.add(btn_box)
|
||
|
|
||
|
# Add functions in each stage
|
||
|
for fun in stage.functions:
|
||
|
btn = gtk.Button(fun.name)
|
||
|
btn.connect('clicked', self.button_click_handler)
|
||
|
# btn.connect('clicked', lambda(w): logger.log('notice', fun.name))
|
||
|
btn.function = fun
|
||
|
|
||
|
btn_box.add(btn)
|
||
|
btn.show()
|
||
|
|
||
|
exp.show()
|
||
|
self.pack_start(exp, expand=False, fill=False)
|
||
|
|
||
|
def button_click_handler(self, button):
|
||
|
function = button.function
|
||
|
logger.log('debug', 'Starting function: %s' % function.name)
|
||
|
function.run(self.workflow.app.current_data)
|
||
|
logger.log('debug', 'Function ended: %s' % function.name)
|
||
|
|