T-test now works, and outputs a histogram as well as t-values and p-values.

This commit is contained in:
Einar Ryeng 2007-07-03 16:25:38 +00:00
parent 99987999db
commit d29013a863
3 changed files with 66 additions and 6 deletions

View File

@ -241,8 +241,8 @@ class Options(dict):
"""
def __init__(self, *args,**kw):
dict.__init__(self, *args, **kw)
self['out_plots'] = None
self['out_data'] = None
self['out_plots'] = []
self['out_data'] = []
self['all_plots'] = []
self['all_data'] = []

View File

@ -2,7 +2,8 @@
import gtk
from fluents import dataset, logger, plots, workflow, fluents, project
import geneontology
from scipy import array, randn, log, ones, zeros
#from scipy import array, randn, log, ones, zeros
from scipy import *
import networkx
import re
@ -339,6 +340,19 @@ class TTestOptionsDialog(workflow.OptionsDialog):
workflow.OptionsDialog.__init__(self, data, options,
['X', 'Categories'])
vb = gtk.VBox()
l = gtk.Label("Limit")
adj = gtk.Adjustment(0, 0.0, 1.0, 0.01, 1.0, 1.0)
sb = gtk.SpinButton(adj, 0.0, 2)
l.show()
sb.show()
vb.add(l)
vb.add(sb)
vb.show()
self.nb.insert_page(vb, gtk.Label("Limit"), -1)
class TTestFunction(workflow.Function):
def __init__(self):
workflow.Function.__init__(self, 't-test', 't-test')
@ -347,16 +361,55 @@ class TTestFunction(workflow.Function):
def run(self, x, categories):
self.show_gui(x, categories)
retval = []
m = x.asarray()
c = categories.asarray()
# Nonsmokers and current smokers
ns = m.take(nonzero(c[:,0]), 0)[0]
cs = m.take(nonzero(c[:,2]), 0)[0]
tscores = stats.ttest_ind(ns, cs)
print "Out data:", self.options['out_data']
tds = dataset.Dataset(tscores[0], [('gene_id', x['gene_id']),
('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'])],
name='p-values')
if 'p-value' in self.options['out_data']:
retval.append(pds)
if ProbabilityHistogramPlot in self.options['out_plots']:
retval.append(ProbabilityHistogramPlot(pds))
return retval
def show_gui(self, x, categories):
dlg = TTestOptionsDialog([x, categories], self.options)
dlg.run()
dialog = TTestOptionsDialog([x, categories], self.options)
response = dialog.run()
dialog.hide()
if response == gtk.RESPONSE_OK:
dialog.set_output()
return dialog.get_options()
else:
return options
class TTestOptions(workflow.Options):
def __init__(self):
workflow.Options.__init__(self)
self['all_plots'] = [(ProbabilityHistogramPlot, '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 GOWeightOptions(workflow.Options):
def __init__(self):
@ -364,3 +417,9 @@ class GOWeightOptions(workflow.Options):
self['similarity_threshold'] = 0.0
self['rank_threshold'] = 0.0
class ProbabilityHistogramPlot(plots.HistogramPlot):
def __init__(self, ds):
plots.HistogramPlot.__init__(self, ds, name="Confidence")

View File

@ -52,6 +52,7 @@ class SmallTestWorkflow(workflow.Workflow):
go = workflow.Stage('go', 'Gene Ontology')
go.add_function(gobrowser.LoadGOFunction())
go.add_function(gobrowser.GOWeightFunction())
go.add_function(gobrowser.TTestFunction())
self.add_stage(go)
# EXTRA PLOTS