Added LinePlot used by Affy importer.
This commit is contained in:
parent
c95c18eb14
commit
969006015a
|
@ -9,6 +9,7 @@ from matplotlib.axes import Subplot
|
|||
from matplotlib.figure import Figure
|
||||
from matplotlib.numerix import arange, sin, pi
|
||||
from matplotlib.widgets import RectangleSelector
|
||||
from matplotlib import cm
|
||||
from system import logger
|
||||
|
||||
|
||||
|
@ -59,6 +60,7 @@ class Plot (gtk.Frame):
|
|||
self.sel_obj = None
|
||||
self.active = False
|
||||
self.title = title
|
||||
self.project = None
|
||||
|
||||
def get_title(self):
|
||||
return self.title
|
||||
|
@ -344,6 +346,58 @@ class SinePlot(Plot):
|
|||
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):
|
||||
def __init__(self, dataset,id_dim, sel_dim,id_1,id_2):
|
||||
Plot.__init__(self, 'Scatter plot')
|
||||
|
|
|
@ -216,7 +216,9 @@ class CelFileImportFunction(workflow.Function):
|
|||
rpy.r.rm(["E", "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:
|
||||
logger.log("notice", "No data loaded from importer.")
|
||||
finally:
|
||||
|
@ -250,6 +252,6 @@ class PCAFunction(workflow.Function):
|
|||
|
||||
loading_plot1 = plots.ScatterPlot(P,'ids','component','1','2')
|
||||
loading_plot2 = plots.ScatterPlot(P,'ids','component','3','4')
|
||||
score_plot = plots.ScatterPlot(T,'filename','component','1','2')
|
||||
score_plot = plots.ScatterPlot(T,'filename','component','1','2')
|
||||
|
||||
return [T, P, loading_plot1, loading_plot2, score_plot]
|
||||
|
|
Reference in New Issue