mainly overhaul of observers, and removal of project singleton
This commit is contained in:
parent
f45c9c6bf7
commit
6a4ae8ecf1
21
fluent
21
fluent
|
@ -14,10 +14,12 @@ import gnome.ui
|
|||
import pango
|
||||
import project
|
||||
import workflow
|
||||
import dataset
|
||||
import logger
|
||||
import plots
|
||||
import navigator
|
||||
import go_workflow
|
||||
import scipy
|
||||
|
||||
PROGRAM_NAME = 'fluent'
|
||||
VERSION = '0.1.0'
|
||||
|
@ -29,11 +31,22 @@ class FluentApp:
|
|||
|
||||
def __init__(self):
|
||||
# Application variables
|
||||
self.navigator = navigator.NavigatorStore()
|
||||
self.current_data = None
|
||||
|
||||
self.project = project.Project()
|
||||
|
||||
# add test data ##################
|
||||
x = scipy.rand(200,3)
|
||||
def_list = [ ['samples',[]], ['genes',['a','b','c']] ]
|
||||
test_data1 = dataset.Dataset(x,def_list)
|
||||
self.project.add_dataset(test_data1)
|
||||
#y = scipy.rand(200,2)
|
||||
#def_list = [ ['samples',[]], ['yclasses',['C','N']] ]
|
||||
#test_data2 = dataset.Dataset(y,def_list)
|
||||
|
||||
####################
|
||||
|
||||
|
||||
self.navigator = navigator.NavigatorStore(self.project)
|
||||
self.current_data = None
|
||||
gtk.glade.set_custom_handler(self.custom_object_factory)
|
||||
self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'appwindow')
|
||||
self.workflow = go_workflow.EinarsWorkflow(self)
|
||||
|
@ -59,7 +72,7 @@ class FluentApp:
|
|||
self.small_view.show()
|
||||
return self.small_view
|
||||
|
||||
def create_large_view(self, str1, str2, int1, int2):
|
||||
def create_large_view(self, str1, str2, int1, int2,project):
|
||||
self.large_view = plots.LargeView()
|
||||
self.large_view.show()
|
||||
return self.large_view
|
||||
|
|
|
@ -22,10 +22,11 @@ class Dataset:
|
|||
raise ValueError,"array dims and identifyer mismatch"
|
||||
for axis,(dim_name,ids) in enumerate(def_list):
|
||||
enum_ids = {}
|
||||
if dim_name not in project.c_p.dim_names:
|
||||
dim_name = project.c_p.suggest_dim_name(dim_name)
|
||||
if not ids:
|
||||
ids = self._create_identifiers(axis)
|
||||
#if dim_name not in project.c_p.dim_names:
|
||||
# dim_name = project.c_p.suggest_dim_name(dim_name)
|
||||
if not ids:
|
||||
logger.log('debug','Creating identifiers along: '+dim_name)
|
||||
ids = self._create_identifiers(axis)
|
||||
for num,name in enumerate(ids):
|
||||
enum_ids[name] = num
|
||||
self.ids[dim_name] = enum_ids
|
||||
|
@ -70,6 +71,7 @@ class Dataset:
|
|||
dim_ids = self.ids[dim_name]
|
||||
if type(index)==int:
|
||||
index = [index]
|
||||
|
||||
return set([id for id,ind in dim_ids.items() if ind in index])
|
||||
|
||||
def extract_index_from_id(self,dim_name,id):
|
||||
|
|
|
@ -5,22 +5,20 @@ import plots
|
|||
import logger
|
||||
|
||||
class NavigatorStore (gtk.TreeStore):
|
||||
def __init__(self):
|
||||
def __init__(self,project):
|
||||
gtk.TreeStore.__init__(self, gobject.TYPE_STRING, plots.Plot)
|
||||
|
||||
self.project = project
|
||||
iter = self.append(None)
|
||||
self.set_value(iter, 0, ('Sine Plot'))
|
||||
self.set_value(iter, 1, (plots.SinePlot()))
|
||||
self.set_value(iter, 1, (plots.SinePlot(project)))
|
||||
|
||||
iter = self.append(None)
|
||||
self.set_value(iter, 0, ('Scatter Plot'))
|
||||
self.set_value(iter, 1, (plots.ScatterPlot()))
|
||||
self.set_value(iter, 1, (plots.ScatterPlot(project)))
|
||||
|
||||
iter = self.append(None)
|
||||
self.set_value(iter, 0, ('Scatter Plot 2'))
|
||||
self.set_value(iter, 1, (plots.ScatterPlot()))
|
||||
|
||||
|
||||
self.set_value(iter, 1, (plots.ScatterPlot(project)))
|
||||
|
||||
def plot_at(self, path):
|
||||
iter = self.get_iter(path)
|
||||
|
|
|
@ -163,12 +163,14 @@ class LargeView (gtk.Frame):
|
|||
|
||||
class Plot (gtk.Frame):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self,project):
|
||||
gtk.Frame.__init__(self)
|
||||
self.project = project
|
||||
self.mark_active(False)
|
||||
self.connect('button_press_event', self.on_button_press)
|
||||
self.sel_obj = None
|
||||
project.c_p.attach(self)
|
||||
if project!=None: #its not an Emptyview
|
||||
project.attach(self,'selection_update')
|
||||
|
||||
def on_button_press(self, *rest):
|
||||
logger.log('debug', 'button pressed in plot')
|
||||
|
@ -183,12 +185,12 @@ class Plot (gtk.Frame):
|
|||
else:
|
||||
self.set_shadow_type(gtk.SHADOW_OUT)
|
||||
|
||||
def update_selection(self,project):
|
||||
def update(self,project,key):
|
||||
pass
|
||||
|
||||
class EmptyView (Plot):
|
||||
def __init__(self):
|
||||
Plot.__init__(self)
|
||||
Plot.__init__(self,None)
|
||||
|
||||
label = gtk.Label('No view')
|
||||
ebox = gtk.EventBox()
|
||||
|
@ -210,10 +212,10 @@ class EmptyView (Plot):
|
|||
self.ebox.hide()
|
||||
Plot.hide(self)
|
||||
|
||||
class SinePlot (Plot):
|
||||
class SinePlot(Plot):
|
||||
|
||||
def __init__(self):
|
||||
Plot.__init__(self)
|
||||
def __init__(self,project):
|
||||
Plot.__init__(self,project)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
ax = fig.add_subplot(111)
|
||||
t = arange(0.0,3.0,0.01)
|
||||
|
@ -228,15 +230,14 @@ class SinePlot (Plot):
|
|||
self.toolbar.set_property('show-arrow', False)
|
||||
return self.toolbar
|
||||
|
||||
class ScatterPlot (Plot):
|
||||
def __init__(self):
|
||||
Plot.__init__(self)
|
||||
class ScatterPlot(Plot):
|
||||
def __init__(self,project):
|
||||
Plot.__init__(self,project)
|
||||
fig = Figure(figsize=(5,4), dpi=72)
|
||||
self.ax = ax = fig.add_subplot(111)
|
||||
|
||||
# testing testing
|
||||
self.c_p = project.c_p
|
||||
self.x_dataset = self.c_p.datasets[0]
|
||||
self.x_dataset = project.datasets[0]
|
||||
x = self.x_dataset._data
|
||||
self.xaxis_data = xaxis_data = x[:,0] + scipy.randn(scipy.shape(x)[0])
|
||||
self.yaxis_data = yaxis_data = x[:,1]
|
||||
|
@ -286,15 +287,16 @@ class ScatterPlot (Plot):
|
|||
logger.log('debug','Selected:\n%s'%index)
|
||||
ids = self.x_dataset.extract_id_from_index('samples',index)
|
||||
#update selection object
|
||||
self.c_p.set_selection(self.current_dim,ids)
|
||||
self.project.set_selection(self.current_dim,ids)
|
||||
logger.log('debug','Selected identifiers:\n%s'%ids)
|
||||
|
||||
def update_selection(self,project):
|
||||
def update(self,project,key):
|
||||
curr_sel = project.get_selection() # get selection object
|
||||
ids = curr_sel[self.current_dim] # current identifiers
|
||||
index = self.x_dataset.extract_index_from_id(self.current_dim,ids) #conversion to index
|
||||
xdata_new = scipy.take(self.xaxis_data,index) #take data
|
||||
ydata_new = scipy.take(self.yaxis_data,index)
|
||||
self.ax.plot(self.xaxis_data,self.yaxis_data,'ob')
|
||||
self.ax.plot(xdata_new,ydata_new,'or')
|
||||
self.canvas.draw()
|
||||
|
||||
|
|
|
@ -5,33 +5,35 @@ class Project:
|
|||
def __init__(self,name="Testing"):
|
||||
self.name = name
|
||||
self.dim_names = []
|
||||
self._selection_observers = []
|
||||
self._observers = {}
|
||||
self.current_data=None
|
||||
self.datasets=[]
|
||||
self.sel_obj = dataset.Selection()
|
||||
|
||||
def attach(self, observer):
|
||||
def attach(self,observer,key):
|
||||
"""Attach observer for selection updates"""
|
||||
if not observer in self._selection_observers:
|
||||
self._selection_observers.append(observer)
|
||||
if not self._observers.has_key(key):
|
||||
self._observers[key]=[]
|
||||
if not observer in self._observers[key]:
|
||||
self._observers[key].append(observer)
|
||||
|
||||
def detach(self, observer):
|
||||
def detach(self,observer,key):
|
||||
"""Detach observer for selection updates"""
|
||||
try:
|
||||
self.selection_observers.remove(observer)
|
||||
self._observers[key].remove(observer)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def notify(self, modifier=None):
|
||||
"""Notifies observers that selection is updated"""
|
||||
for observer in self._selection_observers:
|
||||
def notify(self,key,modifier=None):
|
||||
"""Notifies observers"""
|
||||
for observer in self._observers[key]:
|
||||
if modifier != observer:
|
||||
observer.update_selection(self)
|
||||
observer.update(self,key)
|
||||
|
||||
def set_selection(self,dim_name,selection):
|
||||
"""Sets selection and notifies observers"""
|
||||
"""Sets a current selection and notify observers"""
|
||||
self.sel_obj.current_selection[dim_name] = set(selection)
|
||||
self.notify()
|
||||
self.notify('selection_update')
|
||||
|
||||
def get_selection(self):
|
||||
"""Returns the current selection object"""
|
||||
|
@ -50,18 +52,6 @@ class Project:
|
|||
dim_name = dim_name + "_t"
|
||||
return dim_name
|
||||
|
||||
# FIXME: Singleton project should be removed.
|
||||
c_p = Project()
|
||||
|
||||
#add test data
|
||||
x = scipy.rand(2000,3)
|
||||
def_list = [ ['samples',[]], ['genes',['a','b','c']] ]
|
||||
test_data = dataset.Dataset(x,def_list)
|
||||
c_p.add_dataset(test_data)
|
||||
|
||||
y = scipy.rand(2000,2)
|
||||
def_list = [ ['samples',[]], ['yclasses',['C','N']] ]
|
||||
test_data = dataset.Dataset(y,def_list)
|
||||
c_p.add_dataset(test_data)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import gtk
|
|||
import logger
|
||||
from annotations import Annotations
|
||||
from workflow import *
|
||||
import geneontology
|
||||
import gostat
|
||||
#import geneontology
|
||||
#import gostat
|
||||
from scipy import array
|
||||
|
||||
class EinarsWorkflow (Workflow):
|
||||
|
|
Reference in New Issue