Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added LinePlot used by Affy importer.

This commit is contained in:
Truls Alexander Tangstad 2006-04-27 11:03:11 +00:00
parent c95c18eb14
commit 969006015a
2 changed files with 58 additions and 2 deletions

View File

@ -9,6 +9,7 @@ from matplotlib.axes import Subplot
from matplotlib.figure import Figure from matplotlib.figure import Figure
from matplotlib.numerix import arange, sin, pi from matplotlib.numerix import arange, sin, pi
from matplotlib.widgets import RectangleSelector from matplotlib.widgets import RectangleSelector
from matplotlib import cm
from system import logger from system import logger
@ -59,6 +60,7 @@ class Plot (gtk.Frame):
self.sel_obj = None self.sel_obj = None
self.active = False self.active = False
self.title = title self.title = title
self.project = None
def get_title(self): def get_title(self):
return self.title return self.title
@ -344,6 +346,58 @@ class SinePlot(Plot):
return self._toolbar return self._toolbar
class LinePlot(Plot):
def __init__(self, dataset, name="Line plot"):
Plot.__init__(self, name)
fig = Figure(figsize=(5,4), dpi=72)
self.canvas = FigureCanvas(fig)
self.ax = ax = fig.add_subplot(111)
self._dataset = dataset
import rpy
silent_eval = rpy.with_mode(rpy.NO_CONVERSION, rpy.r)
rpy.with_mode(rpy.NO_CONVERSION, rpy.r.assign)("m", dataset.get_matrix())
ymin, ymax = rpy.r("range(m)*1.1")
self._ymin, self._ymax = ymin, ymax
silent_eval("res <- apply(m, 2, density, from=%s, to=%s)" % (ymin, ymax))
silent_eval("k <- sapply(1:length(res), function(id) rev(res[[id]]$y))")
self._bg_matrix = bg_matrix = rpy.r("k")
rpy.r.rm(["k", "res", "m"])
self.update(None)
self.add(self.canvas)
self.canvas.show()
# We use a regular toolbar as we don't need selections
self._toolbar = NavigationToolbar2(self.canvas, None)
self._toolbar.set_property('show-arrow', False)
def get_toolbar(self):
self.canvas.draw()
return self._toolbar
def update(self, key):
self.ax.clear()
rows, cols = self._bg_matrix.shape
self.ax.imshow(self._bg_matrix, cmap=cm.gray, extent=(0.5, cols+0.5, self._ymin, self._ymax))
if self.project:
curr_sel = self.project.get_selection() # get selection object
ids = curr_sel['ids'] # current identifiers
index = [ind for id,ind in self._dataset['ids'].items() if id in ids] #conversion to index
for i in index:
line = self._dataset.get_matrix()[i]
self.ax.plot(range(1, len(line)+1), line)
self.ax.set_xlim((0.5, cols+0.5))
self.ax.set_ylim((self._ymin, self._ymax))
self.canvas.draw()
class ScatterPlot(Plot): class ScatterPlot(Plot):
def __init__(self, dataset,id_dim, sel_dim,id_1,id_2): def __init__(self, dataset,id_dim, sel_dim,id_1,id_2):
Plot.__init__(self, 'Scatter plot') Plot.__init__(self, 'Scatter plot')

View File

@ -216,7 +216,9 @@ class CelFileImportFunction(workflow.Function):
rpy.r.rm(["E", "m"]) rpy.r.rm(["E", "m"])
if m: if m:
return [dataset.Dataset(m, (('ids', rownames), ('filename', colnames)), name="AffyMatrix Data")] data = dataset.Dataset(m, (('ids', rownames), ('filename', colnames)), name="AffyMatrix Data")
plot = plots.LinePlot(data, "Gene profiles")
return [data, plot]
else: else:
logger.log("notice", "No data loaded from importer.") logger.log("notice", "No data loaded from importer.")
finally: finally: