aboutsummaryrefslogtreecommitdiff
path: root/wqflask/basicStatistics
diff options
context:
space:
mode:
authorSam Ockman2012-06-09 06:23:48 -0400
committerSam Ockman2012-06-09 06:23:48 -0400
commit7085c3644adc569e7ce297b60f8666e5830339ea (patch)
tree9532cf895628e3ead9f15cc534395a23d56d8743 /wqflask/basicStatistics
parentf3733aa972a3b1ab2eb1ab9d02d859eb75cebbb9 (diff)
downloadgenenetwork2-7085c3644adc569e7ce297b60f8666e5830339ea.tar.gz
Trying to get the stats to work
Diffstat (limited to 'wqflask/basicStatistics')
-rwxr-xr-xwqflask/basicStatistics/BasicStatisticsFunctions.py109
1 files changed, 69 insertions, 40 deletions
diff --git a/wqflask/basicStatistics/BasicStatisticsFunctions.py b/wqflask/basicStatistics/BasicStatisticsFunctions.py
index 285addae..d2584bdd 100755
--- a/wqflask/basicStatistics/BasicStatisticsFunctions.py
+++ b/wqflask/basicStatistics/BasicStatisticsFunctions.py
@@ -1,9 +1,15 @@
+from __future__ import print_function
+
#import string
from math import *
#import piddle as pid
#import os
-#import reaper
+from pprint import pformat as pf
+
+from corestats import Stats
+
+import reaper
from htmlgen import HTMLgen2 as HT
#from utility import Plot
@@ -12,58 +18,81 @@ from base import webqtlConfig
from dbFunction import webqtlDatabaseFunction
def basicStatsTable(vals, trait_type=None, cellid=None, heritability=None):
-
+ st = {} # This is the dictionary where we'll put everything for the template
valsOnly = []
dataXZ = vals[:]
for i in range(len(dataXZ)):
valsOnly.append(dataXZ[i][1])
- traitmean, traitmedian, traitvar, traitstdev, traitsem, N = reaper.anova(valsOnly) #ZS: Should convert this from reaper to R in the future
+ (st['traitmean'],
+ st['traitmedian'],
+ st['traitvar'],
+ st['traitstdev'],
+ st['traitsem'],
+ st['N']) = reaper.anova(valsOnly) #ZS: Should convert this from reaper to R in the future
+
+ #tbl = HT.TableLite(cellpadding=20, cellspacing=0)
+ #dataXZ = vals[:]
+ dataXZ = sorted(vals, webqtlUtil.cmpOrder)
+
+ print("data for stats is:", pf(dataXZ))
+ for num, item in enumerate(dataXZ):
+ print(" %i - %s" % (num, item))
+ print(" length:", len(dataXZ))
+
+ st['min'] = dataXZ[0][1]
+ st['max'] = dataXZ[-1][1]
+
+ numbers = [x[1] for x in dataXZ]
+ stats = Stats(numbers)
+
+ at75 = stats.percentile(75)
+ at25 = stats.percentile(25)
+ print("Interquartile:", at75 - at25)
+
+ #tbl.append(HT.TR(HT.TD("Statistic",align="left", Class="fs14 fwb ffl b1 cw cbrb", width = 180),
+ # HT.TD("Value", align="right", Class="fs14 fwb ffl b1 cw cbrb", width = 60)))
+ #tbl.append(HT.TR(HT.TD("N of Samples",align="left", Class="fs13 b1 cbw c222"),
+ # HT.TD(N,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Mean",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.3f" % traitmean,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Median",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.3f" % traitmedian,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ ##tbl.append(HT.TR(HT.TD("Variance",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ ## HT.TD("%2.3f" % traitvar,nowrap="yes",align="left", Class="fs13 b1 cbw c222")))
+ #tbl.append(HT.TR(HT.TD("Standard Error (SE)",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.3f" % traitsem,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Standard Deviation (SD)", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.3f" % traitstdev,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Minimum", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%s" % dataXZ[0][1],nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Maximum", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%s" % dataXZ[-1][1],nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+
+
- tbl = HT.TableLite(cellpadding=20, cellspacing=0)
- dataXZ = vals[:]
- dataXZ.sort(webqtlUtil.cmpOrder)
- tbl.append(HT.TR(HT.TD("Statistic",align="left", Class="fs14 fwb ffl b1 cw cbrb", width = 180),
- HT.TD("Value", align="right", Class="fs14 fwb ffl b1 cw cbrb", width = 60)))
- tbl.append(HT.TR(HT.TD("N of Samples",align="left", Class="fs13 b1 cbw c222"),
- HT.TD(N,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD("Mean",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.3f" % traitmean,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD("Median",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.3f" % traitmedian,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- #tbl.append(HT.TR(HT.TD("Variance",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- # HT.TD("%2.3f" % traitvar,nowrap="yes",align="left", Class="fs13 b1 cbw c222")))
- tbl.append(HT.TR(HT.TD("Standard Error (SE)",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.3f" % traitsem,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD("Standard Deviation (SD)", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.3f" % traitstdev,nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD("Minimum", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%s" % dataXZ[0][1],nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD("Maximum", align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%s" % dataXZ[-1][1],nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
if (trait_type != None and trait_type == 'ProbeSet'):
- #IRQuest = HT.Href(text="Interquartile Range", url=webqtlConfig.glossaryfile +"#Interquartile",target="_blank", Class="fs14")
- #IRQuest.append(HT.BR())
- #IRQuest.append(" (fold difference)")
- tbl.append(HT.TR(HT.TD("Range (log2)",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.3f" % (dataXZ[-1][1]-dataXZ[0][1]),nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD(HT.Span("Range (fold)"),align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.2f" % pow(2.0,(dataXZ[-1][1]-dataXZ[0][1])), nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
- tbl.append(HT.TR(HT.TD(HT.Span(HT.Href(url="/glossary.html#Interquartile", target="_blank", text="Interquartile Range", Class="non_bold")), align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
- HT.TD("%2.2f" % pow(2.0,(dataXZ[int((N-1)*3.0/4.0)][1]-dataXZ[int((N-1)/4.0)][1])), nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD("Range (log2)",align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.3f" % (dataXZ[-1][1]-dataXZ[0][1]),nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD(HT.Span("Range (fold)"),align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.2f" % pow(2.0,(dataXZ[-1][1]-dataXZ[0][1])), nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ #tbl.append(HT.TR(HT.TD(HT.Span(HT.Href(url="/glossary.html#Interquartile", target="_blank", text="Interquartile Range", Class="non_bold")), align="left", Class="fs13 b1 cbw c222",nowrap="yes"),
+ # HT.TD("%2.2f" % pow(2.0,(dataXZ[int((N-1)*3.0/4.0)][1]-dataXZ[int((N-1)/4.0)][1])), nowrap="yes", Class="fs13 b1 cbw c222"), align="right"))
+ st['range_log2'] = dataXZ[-1][1]-dataXZ[0][1]
+ st['range_fold'] = pow(2.0, (dataXZ[-1][1]-dataXZ[0][1]))
+ st['interquartile'] = pow(2.0, (dataXZ[int((st['N']-1)*3.0/4.0)][1]-dataXZ[int((st['N']-1)/4.0)][1]))
#XZ, 04/01/2009: don't try to get H2 value for probe.
- if cellid:
- pass
- else:
+ if not cellid:
if heritability:
- tbl.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("%s" % heritability, nowrap="yes",align="center", Class="fs13 b1 cbw c222")))
- else:
- pass
+ # This field needs to still be put into the Jinja2 template
+ st['heritability'] = heritability
+ #tbl.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("%s" % heritability, nowrap="yes",align="center", Class="fs13 b1 cbw c222")))
+
# Lei Yan
# 2008/12/19
- return tbl
+ return st
def plotNormalProbability(vals=None, RISet='', title=None, showstrains=0, specialStrains=[None], size=(750,500)):