diff --git a/workflows/gobrowser.py b/workflows/gobrowser.py index f2e7652..df5751a 100644 --- a/workflows/gobrowser.py +++ b/workflows/gobrowser.py @@ -297,6 +297,42 @@ class GOWeightDialog(gtk.Dialog): options['rank_threshold'] = self._rank_spin.get_value() +class DistanceToSelectionFunction(workflow.Function): + def __init__(self): + workflow.Function.__init__(self, 'dist-to-sel', 'Dist. to Selection') + self.options = DistanceToSelectionOptions() + + def run(self, similarities, selection): + self.show_gui(similarities, self.options) + + retval = [] + + dims = similarities.get_dim_name() + if dims[0] != "_%s" %dims[1] and dims[1] != "_%s" %dims[0]: + logger.log('warning', 'Are you sure this is a similarity matrix?') + + dim = dims[0] + print "dim", dim + + print "selection", selection[dim] + print "indices", similarities.get_indices(dim, selection[dim]) + indices = similarities.get_indices(dim, selection[dim]) + m = apply_along_axis(max, 1, similarities.asarray().take(indices, 1)) + retval.append(dataset.Dataset(m, [(dim, similarities[dim]), + ("_dummy", '0')])) + + return retval + + def show_gui(self, similarities, options, edit=True): + dialog = DistanceToSelectionOptionsDialog([similarities], self.options) + response = dialog.run() + dialog.hide() + if response == gtk.RESPONSE_OK: + dialog.set_output() + return dialog.get_options() + else: + return options + class GOWeightFunction(workflow.Function): def __init__(self): workflow.Function.__init__(self, 'load-go-ann', 'GO Influence') @@ -334,6 +370,11 @@ class GOWeightFunction(workflow.Function): return options +class DistanceToSelectionOptionsDialog(workflow.OptionsDialog): + def __init__(self, data, options): + workflow.OptionsDialog.__init__(self, data, options, ['X']) + + class TTestOptionsDialog(workflow.OptionsDialog): def __init__(self, data, options): @@ -373,13 +414,13 @@ class TTestFunction(workflow.Function): print "Out data:", self.options['out_data'] tds = dataset.Dataset(tscores[0], [('gene_id', x['gene_id']), - ('t', ['0'])], + ('_t', ['0'])], name='t-values') if 't-value' in self.options['out_data']: retval.append(tds) pds = dataset.Dataset(tscores[1], [('gene_id', x['gene_id']), - ('p', ['0'])], + ('_p', ['0'])], name='p-values') if 'p-value' in self.options['out_data']: retval.append(pds) @@ -387,6 +428,14 @@ class TTestFunction(workflow.Function): if ProbabilityHistogramPlot in self.options['out_plots']: retval.append(ProbabilityHistogramPlot(pds)) + if VolcanoPlot in self.options['out_plots']: + fc = apply_along_axis(mean, 0, ns) / apply_along_axis(mean, 0, cs) + fcds = dataset.Dataset(fc, [('gene_id', x['gene_id']), + ('_dummy', ['0'])], + name="Fold change") + + retval.append(VolcanoPlot(fcds, pds, 'gene_id')) + return retval def show_gui(self, x, categories): @@ -404,13 +453,20 @@ class TTestOptions(workflow.Options): def __init__(self): workflow.Options.__init__(self) - self['all_plots'] = [(ProbabilityHistogramPlot, 'Histogram', True)] + self['all_plots'] = [(ProbabilityHistogramPlot, 'Histogram', True), + (VolcanoPlot, 'Histogram', True)] self['all_data'] = [('t-value', 't-values', True), ('p-value', 'Probabilities', True), ('categories', 'Categories', False)] self['out_data'] = ['t-value', 'p-value'] +class DistanceToSelectionOptions(workflow.Options): + def __init__(self): + workflow.Options.__init__(self) + self['all_data'] = [('mindist', 'Minimum distance', True)] + + class GOWeightOptions(workflow.Options): def __init__(self): workflow.Options.__init__(self) @@ -420,6 +476,13 @@ class GOWeightOptions(workflow.Options): class ProbabilityHistogramPlot(plots.HistogramPlot): def __init__(self, ds): - plots.HistogramPlot.__init__(self, ds, name="Confidence") + plots.HistogramPlot.__init__(self, ds, name="Confidence", bins=50) +class VolcanoPlot(plots.ScatterPlot): + def __init__(self, fold_ds, p_ds, dim, **kw): + plots.ScatterPlot.__init__(self, fold_ds, p_ds, 'gene_id', '_dummy', + '0', '0', + name="Volcano plot", + sel_dim_2='_p', **kw) +