70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
import dataset
|
|
import scipy
|
|
|
|
class Project:
|
|
def __init__(self,name="Testing"):
|
|
self.name = name
|
|
self.dim_names = []
|
|
self._selection_observers = []
|
|
self.current_data=[]
|
|
self.datasets=[]
|
|
self.sel_obj = dataset.Selection()
|
|
|
|
def attach(self, observer):
|
|
"""Attach observer for selection updates"""
|
|
if not observer in self._selection_observers:
|
|
self._selection_observers.append(observer)
|
|
|
|
def detach(self, observer):
|
|
"""Detach observer for selection updates"""
|
|
try:
|
|
self.selection_observers.remove(observer)
|
|
except ValueError:
|
|
pass
|
|
|
|
def notify(self, modifier=None):
|
|
"""Notifies observers that selection is updated"""
|
|
for observer in self._selection_observers:
|
|
if modifier != observer:
|
|
observer.update_selection(self)
|
|
|
|
def set_selection(self,dim_name,selection):
|
|
"""Sets selection and notifies observers"""
|
|
self.sel_obj.current_selection[dim_name] = set(selection)
|
|
self.notify()
|
|
|
|
def get_selection(self):
|
|
"""Returns the current selection object"""
|
|
return self.sel_obj.current_selection
|
|
|
|
def add_dataset(self,dataset):
|
|
"""Appends a new Dataset to the project."""
|
|
self.datasets.append(dataset)
|
|
for dim_name in dataset.ids.keys():
|
|
if dim_name not in self.dim_names:
|
|
self.dim_names.append(dim_name)
|
|
|
|
def suggest_dim_name(self,dim_name):
|
|
"""Creates an arbitrary unique name for a new dimension."""
|
|
while dim_name in self.dim_names:
|
|
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)
|
|
|
|
#add selection object
|
|
c_p.sel_obj = dataset.Selection()
|
|
|