mainly play in plots
This commit is contained in:
parent
1d48bd85c5
commit
a8937ededb
2
fluent
2
fluent
|
@ -130,3 +130,5 @@ if __name__ == '__main__':
|
||||||
app.show()
|
app.show()
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#import logger
|
import logger
|
||||||
from scipy import array,take,asarray,shape
|
from scipy import array,take,asarray,shape
|
||||||
import project
|
import project
|
||||||
#from sets import Set as set
|
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,15 +29,21 @@ class Dataset:
|
||||||
enum_ids = {}
|
enum_ids = {}
|
||||||
if dim_name not in project.c_p.dim_names:
|
if dim_name not in project.c_p.dim_names:
|
||||||
dim_name = project.c_p.suggest_dim_name(dim_name)
|
dim_name = project.c_p.suggest_dim_name(dim_name)
|
||||||
if not ids:
|
if not ids:
|
||||||
ids = self._create_identifiers(axis)
|
ids = self._create_identifiers(axis)
|
||||||
for num,name in enumerate(ids):
|
for num,name in enumerate(ids):
|
||||||
enum_ids[name] = num
|
enum_ids[name] = num
|
||||||
self.ids[dim_name] = enum_ids
|
self.ids[dim_name] = enum_ids
|
||||||
self._ids_set = self._ids_set.union(set(ids))
|
self._ids_set = self._ids_set.union(set(ids))
|
||||||
self._dim_num[dim_name] = axis
|
self._dim_num[dim_name] = axis
|
||||||
self._dim_names.append(dim_name)
|
self._dim_names.append(dim_name)
|
||||||
for df,d in izip(def_list,self.dims):
|
#if dim_name in project.c_p.dim_names:
|
||||||
|
# if ids:
|
||||||
|
# # check that identifers are same as before
|
||||||
|
# raise NotImplementedError
|
||||||
|
# else:
|
||||||
|
|
||||||
|
for df,d in izip(def_list,self.dims): #check that data and labels match
|
||||||
df=df[1]
|
df=df[1]
|
||||||
if len(df)!=d and df:
|
if len(df)!=d and df:
|
||||||
raise ValueError,"dim size and identifyer mismatch"
|
raise ValueError,"dim size and identifyer mismatch"
|
||||||
|
@ -70,6 +75,10 @@ class Dataset:
|
||||||
n_dim = self.dims[axis]
|
n_dim = self.dims[axis]
|
||||||
return [str(axis) + '_' + str(i) for i in range(n_dim)]
|
return [str(axis) + '_' + str(i) for i in range(n_dim)]
|
||||||
|
|
||||||
|
def index_to_id(self,dim_name,index):
|
||||||
|
dim_ids = self.ids[dim_name]
|
||||||
|
return [id for id,ind in dim_ids.items() if ind in index]
|
||||||
|
|
||||||
class Selection:
|
class Selection:
|
||||||
"""Handles selected identifiers along each dimension of a dataset"""
|
"""Handles selected identifiers along each dimension of a dataset"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import pygtk
|
import pygtk
|
||||||
import gtk
|
import gtk
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import project
|
||||||
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
||||||
from matplotlib.axes import Subplot
|
from matplotlib.axes import Subplot
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
|
@ -12,6 +13,7 @@ from matplotlib.widgets import RectangleSelector
|
||||||
|
|
||||||
import scipy
|
import scipy
|
||||||
import logger
|
import logger
|
||||||
|
import project
|
||||||
|
|
||||||
class MainView (gtk.Notebook):
|
class MainView (gtk.Notebook):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -167,6 +169,8 @@ class Plot (gtk.Frame):
|
||||||
gtk.Frame.__init__(self)
|
gtk.Frame.__init__(self)
|
||||||
self.mark_active(False)
|
self.mark_active(False)
|
||||||
self.connect('button_press_event', self.on_button_press)
|
self.connect('button_press_event', self.on_button_press)
|
||||||
|
self.sel_obj = None
|
||||||
|
project.c_p.attach(self)
|
||||||
|
|
||||||
def on_button_press(self, *rest):
|
def on_button_press(self, *rest):
|
||||||
logger.log('debug', 'button pressed in plot')
|
logger.log('debug', 'button pressed in plot')
|
||||||
|
@ -181,6 +185,9 @@ class Plot (gtk.Frame):
|
||||||
else:
|
else:
|
||||||
self.set_shadow_type(gtk.SHADOW_OUT)
|
self.set_shadow_type(gtk.SHADOW_OUT)
|
||||||
|
|
||||||
|
def update_selection(self,project):
|
||||||
|
self.selection_object = project.get_selection()
|
||||||
|
|
||||||
class EmptyView (Plot):
|
class EmptyView (Plot):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Plot.__init__(self)
|
Plot.__init__(self)
|
||||||
|
@ -228,18 +235,20 @@ class ScatterPlot (Plot):
|
||||||
Plot.__init__(self)
|
Plot.__init__(self)
|
||||||
fig = Figure(figsize=(5,4), dpi=72)
|
fig = Figure(figsize=(5,4), dpi=72)
|
||||||
self.ax = ax = fig.add_subplot(111)
|
self.ax = ax = fig.add_subplot(111)
|
||||||
N = 200
|
self.x_dataset = project.c_p.datasets[0]
|
||||||
self.a = a = scipy.randn(N)
|
x = self.x_dataset._data
|
||||||
self.b = b = scipy.randn(N)
|
self.a = a = x[:,0]
|
||||||
|
self.b = b = x[:,1]
|
||||||
ax.plot(a,b,'og')
|
ax.plot(a,b,'og')
|
||||||
self.canvas = FigureCanvas(fig)
|
self.canvas = FigureCanvas(fig)
|
||||||
self.add(self.canvas)
|
self.add(self.canvas)
|
||||||
|
rectprops = dict(facecolor='blue', edgecolor = 'black',
|
||||||
|
alpha=0.2, fill=True)
|
||||||
sel = RectangleSelector(ax, self.line_select_callback,
|
sel = RectangleSelector(ax, self.line_select_callback,
|
||||||
drawtype='box',useblit=True)
|
drawtype='box',useblit=True,rectprops=rectprops)
|
||||||
|
|
||||||
self.canvas.show()
|
self.canvas.show()
|
||||||
|
|
||||||
|
|
||||||
def line_select_callback(self,event1, event2):
|
def line_select_callback(self,event1, event2):
|
||||||
'event1 and event2 are the press and release events'
|
'event1 and event2 are the press and release events'
|
||||||
x1, y1 = event1.xdata, event1.ydata
|
x1, y1 = event1.xdata, event1.ydata
|
||||||
|
@ -250,11 +259,17 @@ class ScatterPlot (Plot):
|
||||||
ydata = self.b
|
ydata = self.b
|
||||||
xdata = self.a
|
xdata = self.a
|
||||||
index =scipy.nonzero((xdata<x2) & (xdata>x1) & (ydata<y1) & (ydata>y2))
|
index =scipy.nonzero((xdata<x2) & (xdata>x1) & (ydata<y1) & (ydata>y2))
|
||||||
xdata_new = scipy.take(xdata,index)
|
if len(index)==0:
|
||||||
ydata_new = scipy.take(ydata,index)
|
logger.log('debug','No points selected!')
|
||||||
#self.ax.plot(xdata,ydata,'og')
|
else:
|
||||||
self.ax.plot(xdata_new,ydata_new,'or')
|
logger.log('debug','Selected:\n%s'%index)
|
||||||
self.canvas.draw()
|
ids = self.x_dataset.index_to_id('samples',index)
|
||||||
|
logger.log('debug','Selected identifiers:\n%s'%ids)
|
||||||
|
xdata_new = scipy.take(xdata,index)
|
||||||
|
ydata_new = scipy.take(ydata,index)
|
||||||
|
# self.ax.plot(xdata,ydata,'og')
|
||||||
|
self.ax.plot(xdata_new,ydata_new,'or')
|
||||||
|
self.canvas.draw()
|
||||||
|
|
||||||
def get_toolbar(self, window):
|
def get_toolbar(self, window):
|
||||||
self.toolbar = NavigationToolbar(self.canvas, window)
|
self.toolbar = NavigationToolbar(self.canvas, window)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import dataset
|
import dataset
|
||||||
|
import scipy
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
def __init__(self,name="Testing"):
|
def __init__(self,name="Testing"):
|
||||||
|
@ -27,9 +28,10 @@ class Project:
|
||||||
if modifier != observer:
|
if modifier != observer:
|
||||||
observer.update(self)
|
observer.update(self)
|
||||||
|
|
||||||
def set_selection(self,dim_name,selection):
|
def set_selection(self,sel_obj,dim_name,selection):
|
||||||
"""Sets selection and notifies observers"""
|
"""Sets selection and notifies observers"""
|
||||||
current_selection = set(selection)
|
current_selection = set(selection)
|
||||||
|
sel_obj.current_selection[dim_name] = current_selection
|
||||||
self.current_selection[dim_name] = current_selection
|
self.current_selection[dim_name] = current_selection
|
||||||
self.notify()
|
self.notify()
|
||||||
|
|
||||||
|
@ -52,3 +54,18 @@ class Project:
|
||||||
|
|
||||||
# FIXME: Singleton project should be removed.
|
# FIXME: Singleton project should be removed.
|
||||||
c_p = Project()
|
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(2,2)
|
||||||
|
def_list = [ ['samples',['1','2']], ['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()
|
||||||
|
|
||||||
|
|
Reference in New Issue