Added pickling as a quick and dirty way of loading and saving data in einars workflow.
This commit is contained in:
parent
d123f0e1c1
commit
5a2a1afe91
|
@ -8,6 +8,7 @@ import dataset
|
|||
#import gostat
|
||||
import rpy
|
||||
from scipy import array,randn
|
||||
import cPickle
|
||||
|
||||
class EinarsWorkflow (Workflow):
|
||||
|
||||
|
@ -19,6 +20,7 @@ class EinarsWorkflow (Workflow):
|
|||
load.add_function(Function('load', 'Load Microarrays'))
|
||||
load.add_function(CelFileImportFunction())
|
||||
load.add_function(TestDataFunction())
|
||||
load.add_function(DatasetLoadFunction())
|
||||
self.add_stage(load)
|
||||
|
||||
preproc = Stage('preprocess', 'Preprocessing')
|
||||
|
@ -34,6 +36,10 @@ class EinarsWorkflow (Workflow):
|
|||
regression.add_function(Function('pls', 'PLS'))
|
||||
self.add_stage(regression)
|
||||
|
||||
save = Stage('save', 'Save Data')
|
||||
save.add_function(DatasetSaveFunction())
|
||||
self.add_stage(save)
|
||||
|
||||
logger.log('debug', '\tEinar\'s workflow is now active')
|
||||
|
||||
class LoadAnnotationsFunction(Function):
|
||||
|
@ -102,6 +108,64 @@ class TestDataFunction(Function):
|
|||
return [X, plots.SinePlot(None)]
|
||||
|
||||
|
||||
class DatasetLoadFunction(Function):
|
||||
"""Loader for previously pickled Datasets."""
|
||||
def __init__(self):
|
||||
Function.__init__(self, 'load_data', 'Load Pickled Dataset')
|
||||
|
||||
def run(self, data):
|
||||
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
||||
pkl_filter = gtk.FileFilter()
|
||||
pkl_filter.set_name("Python pickled data files (*.pkl)")
|
||||
pkl_filter.add_pattern("*.[pP][kK][lL]")
|
||||
all_filter = gtk.FileFilter()
|
||||
all_filter.set_name("All Files (*.*)")
|
||||
all_filter.add_pattern("*")
|
||||
chooser.add_filter(pkl_filter)
|
||||
chooser.add_filter(all_filter)
|
||||
|
||||
try:
|
||||
if chooser.run() == gtk.RESPONSE_OK:
|
||||
return [cPickle.load(open(chooser.get_filename()))]
|
||||
finally:
|
||||
chooser.destroy()
|
||||
|
||||
|
||||
class DatasetSaveFunction(Function):
|
||||
"""QND way to save data to file for later import to this program."""
|
||||
def __init__(self):
|
||||
Function.__init__(self, 'save_data', 'Save Pickled Dataset')
|
||||
|
||||
def run(self, data):
|
||||
if not data:
|
||||
logger.log("notice", "No data to save.")
|
||||
return
|
||||
|
||||
chooser = gtk.FileChooserDialog(title="Save pickled data...", parent=None,
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
|
||||
pkl_filter = gtk.FileFilter()
|
||||
pkl_filter.set_name("Python pickled data files (*.pkl)")
|
||||
pkl_filter.add_pattern("*.[pP][kK][lL]")
|
||||
all_filter = gtk.FileFilter()
|
||||
all_filter.set_name("All Files (*.*)")
|
||||
all_filter.add_pattern("*")
|
||||
chooser.add_filter(pkl_filter)
|
||||
chooser.add_filter(all_filter)
|
||||
chooser.set_current_name(data.get_name() + ".pkl")
|
||||
|
||||
try:
|
||||
if chooser.run() == gtk.RESPONSE_OK:
|
||||
cPickle.dump(data, open(chooser.get_filename(), "w"))
|
||||
logger.log("notice", "Saved data to %r." % chooser.get_filename())
|
||||
finally:
|
||||
chooser.destroy()
|
||||
|
||||
|
||||
class CelFileImportFunction(Function):
|
||||
"""Loads AffyMetrix .CEL-files into matrix."""
|
||||
def __init__(self):
|
||||
|
|
Reference in New Issue