From fc4e62f799adf109fda33f87fe7a9065f03694a3 Mon Sep 17 00:00:00 2001 From: flatberg Date: Fri, 21 Apr 2006 09:23:05 +0000 Subject: [PATCH] current datset selection fix --- fluent | 2 +- system/navigator.py | 26 ++++++++++++++++++-------- system/project.py | 2 ++ workflows/pca_workflow.py | 21 +++++++++++++++------ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/fluent b/fluent index 1753c2f..f233911 100755 --- a/fluent +++ b/fluent @@ -77,7 +77,7 @@ class FluentApp: def create_navigator_view(self, str1, str2, int1, int2): tree = self.project.data_tree - self.navigator_view = navigator.NavigatorView(tree, self) + self.navigator_view = navigator.NavigatorView(self.project, self) self.navigator_view.show() return self.navigator_view diff --git a/system/navigator.py b/system/navigator.py index b26163d..e268916 100644 --- a/system/navigator.py +++ b/system/navigator.py @@ -3,12 +3,16 @@ import gtk import gobject import plots import logger +import dataset +import project class NavigatorView (gtk.TreeView): - def __init__(self, nav, app): - gtk.TreeView.__init__(self, nav) - self.navigator = nav + def __init__(self, project, app): + self.project = project + self.data_tree = project.data_tree self.app = app + + gtk.TreeView.__init__(self, self.data_tree) self.set_headers_visible(False) self.connect('row-activated', self.row_activated_handler) @@ -20,8 +24,14 @@ class NavigatorView (gtk.TreeView): logger.log('debug', 'Initializing naviagor window') def row_activated_handler(self, widget, path, column): - - iter = self.navigator.get_iter(path) - object = self.navigator.get_value(iter, 2) - logger.log('notice', 'Button pressed') - self.app.change_plot(object) + iter = self.data_tree.get_iter(path) + obj = self.data_tree.get_value(iter, 2) + if isinstance(obj, plots.Plot): + logger.log('debug', 'Activating plot') + self.app.change_plot(obj) + elif isinstance(obj, dataset.Dataset): + logger.log('debug', 'Selecting dataset') + self.project.set_current_data(obj) + else: + t = type(obj) + logger.log('debug', 'Datatype was %s. Don\'t know what to do.' % t) diff --git a/system/project.py b/system/project.py index 0b834c1..0ac43a9 100644 --- a/system/project.py +++ b/system/project.py @@ -87,3 +87,5 @@ class Project: object.show() return object + def set_current_data(self, obj): + self.current_data = obj diff --git a/workflows/pca_workflow.py b/workflows/pca_workflow.py index d61c056..9033bf9 100644 --- a/workflows/pca_workflow.py +++ b/workflows/pca_workflow.py @@ -1,9 +1,10 @@ import gtk import logger from workflow import * -from scipy import array +from scipy import array,zeros from data import read_affy_annot,read_mootha,data_dict_to_matrix import plots +import dataset class PCAWorkflow(Workflow): @@ -12,7 +13,7 @@ class PCAWorkflow(Workflow): self.name = 'PCAs Workflow' load = Stage('load', 'Load Data') - load.add_function(Function('load_mootha', 'Load')) + load.add_function(LoadMoothaData()) self.add_stage(load) preproc = Stage('preprocess', 'Preprocessing') @@ -113,6 +114,7 @@ class LoadMoothaData(Function): f = open(filename) logger.log('notice', 'Loading expression file: %s' % filename) self.file = f + self.filename = filename def on_response(self, dialog, response): if response == gtk.RESPONSE_OK: @@ -122,16 +124,23 @@ class LoadMoothaData(Function): def run(self, data): btns = ('Open', gtk.RESPONSE_OK, \ 'Cancel', gtk.RESPONSE_CANCEL) - dialog = gtk.FileChooserDialog('Open Affy Annotation File', + dialog = gtk.FileChooserDialog('Open diabetes expression File', buttons=btns) dialog.connect('response', self.on_response) dialog.run() dialog.destroy() ### Reading and parsing here - d,sample_names = read_mootha(self.file) - x,gene_ids = data_dict_to_matrix(d) + d,sample_names = read_mootha() + n_samps = len(sample_names) + n_genes = len(d.keys()) + typecode = 'f' + x = zeros((n_samps,n_genes),typecode) + gene_ids = [] + for i,(id,desc) in enumerate(d.items()): + gene_ids.append(id) + x[:,i] = desc[0].astype(typecode) gene_def = ['genes',gene_ids] sample_def = ['samples', sample_names] X = dataset.Dataset(x,[sample_def,gene_def]) # samples x genes - return X + return [X]