From f44a9e0425cf9d364604c62893100c0cdb0a6f8f Mon Sep 17 00:00:00 2001 From: Sam Ockman Date: Sun, 3 Jun 2012 04:08:57 -0400 Subject: Added files --- .../basicStatistics/updatedBasicStatisticsPage.py | 150 +++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100755 wqflask/basicStatistics/updatedBasicStatisticsPage.py (limited to 'wqflask/basicStatistics/updatedBasicStatisticsPage.py') diff --git a/wqflask/basicStatistics/updatedBasicStatisticsPage.py b/wqflask/basicStatistics/updatedBasicStatisticsPage.py new file mode 100755 index 00000000..ab7ed07d --- /dev/null +++ b/wqflask/basicStatistics/updatedBasicStatisticsPage.py @@ -0,0 +1,150 @@ +from htmlgen import HTMLgen2 as HT + +from base.templatePage import templatePage +from dbFunction import webqtlDatabaseFunction +import BasicStatisticsFunctions + +#Window generated from the Trait Data and Analysis page (DataEditingPage.py) with updated stats figures; takes the page's values that can bed edited by the user +class updatedBasicStatisticsPage(templatePage): + + plotMinInformative = 4 + + def __init__(self, fd): + + templatePage.__init__(self, fd) + + if not fd.genotype: + fd.readGenotype() + this_strainlist = fd.strainlist + + if fd.allstrainlist: + this_strainlist = fd.allstrainlist + + fd.readData(this_strainlist) + + specialStrains = [] #This appears to be the "other/non-RISet strainlist" without parents/f1 strains; not sure what to name it + setStrains = [] + for item in this_strainlist: + if item not in fd.strainlist and item.find('F1') < 0: + specialStrains.append(item) + else: + continue + + specialStrains.sort() + if specialStrains: + specialStrains = fd.f1list+fd.parlist+specialStrains + + self.dict['title'] = 'Basic Statistics' + TD_LR = HT.TD(valign="top",width="100%",bgcolor="#fafafa") + + stats_row = HT.TR() + stats_cell = HT.TD() + stats_script = HT.Script(language="Javascript") + + #Get strain names, values, and variances + strain_names = fd.formdata.getvalue('strainNames').split(',') + strain_vals = fd.formdata.getvalue('strainVals').split(',') + strain_vars = fd.formdata.getvalue('strainVars').split(',') + + vals = [] + if (len(strain_names) > 0): + if (len(strain_names) > 3): + #Need to create "vals" object + for i in range(len(strain_names)): + try: + this_strain_val = float(strain_vals[i]) + except: + continue + try: + this_strain_var = float(strain_vars[i]) + except: + this_strain_var = None + + thisValFull = [strain_names[i], this_strain_val, this_strain_var] + vals.append(thisValFull) + + stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-2", Class="stats_tab"), + HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), + HT.Href(text="Box Plot", url="#statstabs-5", Class="stats_tab")] + stats_tabs = HT.List(stats_tab_list) + + stats_container = HT.Div(id="stats_tabs", Class="ui-tabs") + stats_container.append(stats_tabs) + + stats_script_text = """$(function() { $("#stats_tabs").tabs();});""" #Javascript enabling tabs + + table_div = HT.Div(id="statstabs-1", style="height:320px;width:740px;overflow:scroll;") + table_container = HT.Paragraph() + + statsTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + this_trait_type = fd.formdata.getvalue('trait_type', None) + this_cellid = fd.formdata.getvalue('cellid', None) + statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=this_trait_type, cellid=this_cellid) + statsTable.append(HT.TR(HT.TD(statsTableCell))) + + table_container.append(statsTable) + table_div.append(table_container) + stats_container.append(table_div) + + normalplot_div = HT.Div(id="statstabs-2", style="height:540px;width:740px;overflow:scroll;") + normalplot_container = HT.Paragraph() + normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + plotTitle = fd.formdata.getvalue("normalPlotTitle","") + normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, RISet=fd.RISet, title=plotTitle, specialStrains=specialStrains) + normalplot.append(HT.TR(HT.TD(normalplot_img))) + normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ + normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), + "More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", + target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) + normalplot_container.append(normalplot) + normalplot_div.append(normalplot_container) + stats_container.append(normalplot_div) + + barName_div = HT.Div(id="statstabs-3", style="height:540px;width:740px;overflow:scroll;") + barName_container = HT.Paragraph() + barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="name") + barName.append(HT.TR(HT.TD(barName_img))) + barName_container.append(barName) + barName_div.append(barName_container) + stats_container.append(barName_div) + + barRank_div = HT.Div(id="statstabs-4", style="height:540px;width:740px;overflow:scroll;") + barRank_container = HT.Paragraph() + barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="rank") + barRank.append(HT.TR(HT.TD(barRank_img))) + barRank_container.append(barRank) + barRank_div.append(barRank_container) + stats_container.append(barRank_div) + + boxplot_div = HT.Div(id="statstabs-5", style="height:540px;width:740px;overflow:scroll;") + boxplot_container = HT.Paragraph() + boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) + boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) + boxplot_container.append(boxplot) + boxplot_div.append(boxplot_container) + stats_container.append(boxplot_div) + + stats_cell.append(stats_container) + stats_script.append(stats_script_text) + + submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + stats_row.append(stats_cell) + + submitTable.append(stats_row) + submitTable.append(stats_script) + + TD_LR.append(submitTable) + self.dict['body'] = str(TD_LR) + else: + heading = "Basic Statistics" + detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] + self.error(heading=heading,detail=detail) + return + else: + heading = "Basic Statistics" + detail = ['Empty data set, please check your data.'] + self.error(heading=heading,detail=detail) + return \ No newline at end of file -- cgit v1.2.3 From 8ac39ead1014953c634e85d0ce340497ecfe2934 Mon Sep 17 00:00:00 2001 From: Sam Ockman Date: Tue, 5 Jun 2012 00:24:44 -0400 Subject: Ran reindent.py recursively on wqflask directory --- .gitignore | 2 + wqflask/base/GeneralObject.py | 77 +- wqflask/base/admin.py | 32 +- wqflask/base/cgiData.py | 60 +- wqflask/base/cookieData.py | 27 +- wqflask/base/header.py | 2 +- wqflask/base/indexBody.py | 414 +-- wqflask/base/myCookie.py | 38 +- wqflask/base/sessionData.py | 27 +- wqflask/base/template.py | 74 +- wqflask/base/templatePage.py | 318 +- wqflask/base/webqtlCaseData.py | 43 +- wqflask/base/webqtlDataset.py | 249 +- wqflask/base/webqtlFormData.py | 516 +-- wqflask/base/webqtlTrait.py | 1152 +++--- .../basicStatistics/BasicStatisticsFunctions.py | 280 +- .../basicStatistics/BasicStatisticsPage_alpha.py | 602 ++-- .../basicStatistics/updatedBasicStatisticsPage.py | 284 +- wqflask/dbFunction/webqtlDatabaseFunction.py | 293 +- wqflask/utility/AJAX_table.py | 224 +- wqflask/utility/Plot.py | 2304 ++++++------ wqflask/utility/TDCell.py | 15 +- wqflask/utility/THCell.py | 16 +- wqflask/utility/svg.py | 133 +- wqflask/utility/webqtlUtil.py | 1459 ++++---- wqflask/wqflask/show_trait/DataEditingPage.py | 3810 ++++++++++---------- wqflask/wqflask/show_trait/show_trait_page.py | 290 +- 27 files changed, 6353 insertions(+), 6388 deletions(-) (limited to 'wqflask/basicStatistics/updatedBasicStatisticsPage.py') diff --git a/.gitignore b/.gitignore index 8bc78454..fc051245 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ # gitignore *.pyc *.orig +*.bak *~ + diff --git a/wqflask/base/GeneralObject.py b/wqflask/base/GeneralObject.py index 311c9e22..53d1357b 100755 --- a/wqflask/base/GeneralObject.py +++ b/wqflask/base/GeneralObject.py @@ -25,47 +25,44 @@ # Last updated by GeneNetwork Core Team 2010/10/20 class GeneralObject: - """ - Base class to define an Object. - a = [Spam(1, 4), Spam(9, 3), Spam(4,6)] - a.sort(lambda x, y: cmp(x.eggs, y.eggs)) - """ + """ + Base class to define an Object. + a = [Spam(1, 4), Spam(9, 3), Spam(4,6)] + a.sort(lambda x, y: cmp(x.eggs, y.eggs)) + """ - def __init__(self, *args, **kw): - self.contents = list(args) - for name, value in kw.items(): - setattr(self, name, value) - - def __setitem__(self, key, value): - setattr(self, key, value) - - def __getitem__(self, key): - return getattr(self, key) - - def __getattr__(self, key): - if key in self.__dict__.keys(): - return self.__dict__[key] - else: - return eval("self.__dict__.%s" % key) - - def __len__(self): - return len(self.__dict__) - 1 - - def __str__(self): - s = '' - for key in self.__dict__.keys(): - if key != 'contents': - s += '%s = %s\n' % (key,self.__dict__[key]) - return s - - def __repr__(self): - s = '' - for key in self.__dict__.keys(): - s += '%s = %s\n' % (key,self.__dict__[key]) - return s - - def __cmp__(self,other): - return len(self.__dict__.keys()).__cmp__(len(other.__dict__.keys())) + def __init__(self, *args, **kw): + self.contents = list(args) + for name, value in kw.items(): + setattr(self, name, value) + def __setitem__(self, key, value): + setattr(self, key, value) + def __getitem__(self, key): + return getattr(self, key) + def __getattr__(self, key): + if key in self.__dict__.keys(): + return self.__dict__[key] + else: + return eval("self.__dict__.%s" % key) + + def __len__(self): + return len(self.__dict__) - 1 + + def __str__(self): + s = '' + for key in self.__dict__.keys(): + if key != 'contents': + s += '%s = %s\n' % (key,self.__dict__[key]) + return s + + def __repr__(self): + s = '' + for key in self.__dict__.keys(): + s += '%s = %s\n' % (key,self.__dict__[key]) + return s + + def __cmp__(self,other): + return len(self.__dict__.keys()).__cmp__(len(other.__dict__.keys())) diff --git a/wqflask/base/admin.py b/wqflask/base/admin.py index a04df2da..1ba75117 100755 --- a/wqflask/base/admin.py +++ b/wqflask/base/admin.py @@ -35,18 +35,18 @@ ADMIN_search_dbs = { - 'rat': {'PERITONEAL FAT': ['FT_2A_0605_Rz'], + 'rat': {'PERITONEAL FAT': ['FT_2A_0605_Rz'], 'KIDNEY': ['KI_2A_0405_Rz'], 'ADRENAL GLAND': ['HXB_Adrenal_1208'], 'HEART': ['HXB_Heart_1208'] }, - 'mouse': {'CEREBELLUM': ['CB_M_0305_R'], + 'mouse': {'CEREBELLUM': ['CB_M_0305_R'], 'STRIATUM': ['SA_M2_0905_R', 'SA_M2_0405_RC', 'UTHSC_1107_RankInv', 'Striatum_Exon_0209'], - 'HIPPOCAMPUS': ['HC_M2_0606_R', 'UMUTAffyExon_0209_RMA'], - 'WHOLE BRAIN': ['BR_M2_1106_R', 'IBR_M_0106_R', 'BRF2_M_0805_R', 'UCLA_BHF2_BRAIN_0605'], - 'LIVER': ['LV_G_0106_B', 'UCLA_BHF2_LIVER_0605'], - 'EYE': ['Eye_M2_0908_R'], - 'HEMATOPOIETIC STEM CELLS': ['HC_U_0304_R'], + 'HIPPOCAMPUS': ['HC_M2_0606_R', 'UMUTAffyExon_0209_RMA'], + 'WHOLE BRAIN': ['BR_M2_1106_R', 'IBR_M_0106_R', 'BRF2_M_0805_R', 'UCLA_BHF2_BRAIN_0605'], + 'LIVER': ['LV_G_0106_B', 'UCLA_BHF2_LIVER_0605'], + 'EYE': ['Eye_M2_0908_R'], + 'HEMATOPOIETIC STEM CELLS': ['HC_U_0304_R'], 'KIDNEY': ['MA_M2_0806_R'], 'MAMMARY TUMORS': ['MA_M_0704_R', 'NCI_Agil_Mam_Tum_RMA_0409'], 'PREFRONTAL CORTEX': ['VCUSal_1206_R'], @@ -65,14 +65,14 @@ ADMIN_search_dbs = { ###LIST of tissue alias -ADMIN_tissue_alias = {'CEREBELLUM': ['Cb'], - 'STRIATUM': ['Str'], - 'HIPPOCAMPUS': ['Hip'], - 'WHOLE BRAIN': ['Brn'], - 'LIVER': ['Liv'], - 'EYE': ['Eye'], - 'PERITONEAL FAT': ['Fat'], - 'HEMATOPOIETIC STEM CELLS': ['Hsc'], +ADMIN_tissue_alias = {'CEREBELLUM': ['Cb'], + 'STRIATUM': ['Str'], + 'HIPPOCAMPUS': ['Hip'], + 'WHOLE BRAIN': ['Brn'], + 'LIVER': ['Liv'], + 'EYE': ['Eye'], + 'PERITONEAL FAT': ['Fat'], + 'HEMATOPOIETIC STEM CELLS': ['Hsc'], 'KIDNEY': ['Kid'], 'ADRENAL GLAND': ['Adr'], 'HEART': ['Hea'], @@ -84,5 +84,3 @@ ADMIN_tissue_alias = {'CEREBELLUM': ['Cb'], 'ADIPOSE': ['Wfat'], 'RETINA': ['Ret'] } - - diff --git a/wqflask/base/cgiData.py b/wqflask/base/cgiData.py index 57416060..155b3ec3 100755 --- a/wqflask/base/cgiData.py +++ b/wqflask/base/cgiData.py @@ -30,41 +30,37 @@ ######################################### class cgiData(dict): - '''convert Field storage object to Dict object - Filed storage object cannot be properly dumped - ''' + '''convert Field storage object to Dict object + Filed storage object cannot be properly dumped + ''' - def __init__(self, field_storage=None): + def __init__(self, field_storage=None): - if not field_storage: - field_storage={} - - for key in field_storage.keys(): - temp = field_storage.getlist(key) - if len(temp) > 1: - temp = map(self.toValue, temp) - elif len(temp) == 1: - temp = self.toValue(temp[0]) - else: - temp = None - self[key]= temp - - def toValue(self, obj): - '''fieldstorge returns different type of objects, \ - need to convert to string or None''' - try: - return obj.value - except: - return "" - - def getvalue(self, k, default= None): - try: - return self[k] - except: - return default - - getfirst = getvalue + if not field_storage: + field_storage={} + for key in field_storage.keys(): + temp = field_storage.getlist(key) + if len(temp) > 1: + temp = map(self.toValue, temp) + elif len(temp) == 1: + temp = self.toValue(temp[0]) + else: + temp = None + self[key]= temp + def toValue(self, obj): + '''fieldstorge returns different type of objects, \ + need to convert to string or None''' + try: + return obj.value + except: + return "" + def getvalue(self, k, default= None): + try: + return self[k] + except: + return default + getfirst = getvalue diff --git a/wqflask/base/cookieData.py b/wqflask/base/cookieData.py index 4b7c9046..eeb7c0cf 100755 --- a/wqflask/base/cookieData.py +++ b/wqflask/base/cookieData.py @@ -30,23 +30,20 @@ ######################################### class cookieData(dict): - 'convert mod python Cookie object to Dict object' + 'convert mod python Cookie object to Dict object' - def __init__(self, cookies=None): + def __init__(self, cookies=None): - if not cookies: - cookies={} - - for key in cookies.keys(): - self[key.lower()]= cookies[key].value - - def getvalue(self, k, default= None): - try: - return self[k.lower()] - except: - return default - - getfirst = getvalue + if not cookies: + cookies={} + for key in cookies.keys(): + self[key.lower()]= cookies[key].value + def getvalue(self, k, default= None): + try: + return self[k.lower()] + except: + return default + getfirst = getvalue diff --git a/wqflask/base/header.py b/wqflask/base/header.py index b6136b51..ec15e174 100755 --- a/wqflask/base/header.py +++ b/wqflask/base/header.py @@ -3,4 +3,4 @@ import webqtlConfig header_string = open(webqtlConfig.HTMLPATH + 'header.html', 'r').read() header_string = header_string.replace("\\'", "'") header_string = header_string.replace('%"','%%"') -header_string = header_string.replace('', '%s') \ No newline at end of file +header_string = header_string.replace('', '%s') diff --git a/wqflask/base/indexBody.py b/wqflask/base/indexBody.py index aa67dffa..a5bc4c17 100755 --- a/wqflask/base/indexBody.py +++ b/wqflask/base/indexBody.py @@ -1,174 +1,174 @@ index_body_string = """ -

Select and Search -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +

Select and Search + + +

- Species: - - - -
- Group: - - - -
- Type: - - - -
- Database: - - - - -
- - -

    Databases marked with ** suffix are not public yet. -
    Access requires user login.

-
- Get Any: - - - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - + - + + - - + + - + - - + + - - - - + + + - -
+ Species: + + + +
+ Group: + + + +
+ Type: + + + +
+ Database: + + + + +
+ + +

    Databases marked with ** suffix are not public yet. +
    Access requires user login.

+
+ Get Any: + + + + +
- +
+ - -

    Enter terms, genes, ID numbers in the Get Any field. -
    Use * or ? wildcards (Cyp*a?, synap*). -
    Use Combined for terms such as tyrosine kinase.

+
+

    Enter terms, genes, ID numbers in the Get Any field. +
    Use * or ? wildcards (Cyp*a?, synap*). +
    Use Combined for terms such as tyrosine kinase.

-
- Combined: -
+ Combined: + - + - - -
+ + +
- - -      -      - +
+ + +      +      + -
- - - -
- + + + + + + + + @@ -185,7 +185,7 @@ Quick HELP Examples and User's Guide

-  You can also use advanced commands. Copy these simple examples +  You can also use advanced commands. Copy these simple examples
  into the Get Any or Combined search fields: + - + -

Websites Affiliated with GeneNetwork

-

-

-

-

____________________________ - -

Getting Started   

-
    -
  1. Select Species (or select All) -
  2. Select Group (a specific sample) -
  3. Select Type of data: - -
  4. Select a Database -
  5. Enter search terms in the Get Any or Combined field: words, genes, ID numbers, probes, advanced search commands -
  6. Click on the Search button -
  7. Optional: Use the Make Default button to save your preferences -
- -

____________________________ +

Websites Affiliated with GeneNetwork

+

+

+

+

____________________________ + +

Getting Started   

+
    +
  1. Select Species (or select All) +
  2. Select Group (a specific sample) +
  3. Select Type of data: + +
  4. Select a Database +
  5. Enter search terms in the Get Any or Combined field: words, genes, ID numbers, probes, advanced search commands +
  6. Click on the Search button +
  7. Optional: Use the Make Default button to save your preferences +
+ +

____________________________

How to Use GeneNetwork -

-

Take a 20-40 minute GeneNetwork Tour that includes screen shots and typical steps in the analysis.

-
-
-

For information about resources and methods, select the INFO buttons.

+
+

Take a 20-40 minute GeneNetwork Tour that includes screen shots and typical steps in the analysis.

+
+
+

For information about resources and methods, select the INFO buttons.

+ + - -

Try the Workstation site to explore data and features that are being implemented.

-

Review the Conditions and Contacts pages for information on the status of data sets and advice on their use and citation.

+

Review the Conditions and Contacts pages for information on the status of data sets and advice on their use and citation.

+ +
-
- -

Mirror and Development Sites

+

Mirror and Development Sites

- + -

History and Archive +

History and Archive -

-

GeneNetwork's Time Machine links to earlier versions that correspond to specific publication dates.

+
+

GeneNetwork's Time Machine links to earlier versions that correspond to specific publication dates.

-
+

- + """ diff --git a/wqflask/base/myCookie.py b/wqflask/base/myCookie.py index db5320df..add7e6ea 100755 --- a/wqflask/base/myCookie.py +++ b/wqflask/base/myCookie.py @@ -25,31 +25,27 @@ # Last updated by GeneNetwork Core Team 2010/10/20 ######################################### -## python cookie and mod python cookie are +## python cookie and mod python cookie are ## not compatible ######################################### class myCookie(dict): - 'define my own cookie' - - def __init__(self, name="", value="", expire = None, path="/"): - self['name']= name - self['value']= value - self['expire']= expire - self['path']= path - - def __getattr__(self, key): - if key in self.keys(): - return self[key] - else: - return None - - def __nonzero__ (self): - if self['name']: - return 1 - else: - return 0 - + 'define my own cookie' + def __init__(self, name="", value="", expire = None, path="/"): + self['name']= name + self['value']= value + self['expire']= expire + self['path']= path + def __getattr__(self, key): + if key in self.keys(): + return self[key] + else: + return None + def __nonzero__ (self): + if self['name']: + return 1 + else: + return 0 diff --git a/wqflask/base/sessionData.py b/wqflask/base/sessionData.py index 01555f87..4b23060f 100755 --- a/wqflask/base/sessionData.py +++ b/wqflask/base/sessionData.py @@ -30,24 +30,21 @@ ######################################### class sessionData(dict): - 'convert mod python Session object to Dict object' + 'convert mod python Session object to Dict object' - def __init__(self, mod_python_session=None): - - if not mod_python_session: - mod_python_session = {} + def __init__(self, mod_python_session=None): - for key in mod_python_session.keys(): - self[key]= mod_python_session[key] - - - def getvalue(self, k, default= None): - try: - return self[k] - except: - return default + if not mod_python_session: + mod_python_session = {} - getfirst = getvalue + for key in mod_python_session.keys(): + self[key]= mod_python_session[key] + def getvalue(self, k, default= None): + try: + return self[k] + except: + return default + getfirst = getvalue diff --git a/wqflask/base/template.py b/wqflask/base/template.py index 85bd86df..aa8f90dc 100755 --- a/wqflask/base/template.py +++ b/wqflask/base/template.py @@ -68,32 +68,32 @@ template = """ %s - - - - %s - - + + + + %s + + - - - - - + + + + + - - - - + + + +
- - - %s - -
-
+ + + %s + +
+
- %s
-
+ %s
+
@@ -103,20 +103,20 @@ template = """ diff --git a/wqflask/base/templatePage.py b/wqflask/base/templatePage.py index 821c6181..7ef58a72 100755 --- a/wqflask/base/templatePage.py +++ b/wqflask/base/templatePage.py @@ -61,162 +61,162 @@ from utility import webqtlUtil class templatePage: - contents = ['title','basehref','js1','js2', 'layer', 'header', 'body', 'footer'] - - # you can pass in another template here if you want - def __init__(self, fd=None, template=template.template): - - # initiate dictionary - self.starttime = time.time() - self.dict = {} - self.template = template - - for item in self.contents: - self.dict[item] = "" - - self.dict['basehref'] = "" #webqtlConfig.BASEHREF - self.cursor = None - - self.cookie = [] #XZ: list to hold cookies (myCookie object) being changed - self.content_type = 'text/html' - self.content_disposition = '' - self.redirection = '' - self.debug = '' - self.attachment = '' - - #XZ: Holding data (new data or existing data being changed) that should be saved to session. The data must be picklable!!! - self.session_data_changed = {} - - self.userName = 'Guest' - self.privilege = 'guest' - - # Commenting this out for flask - we'll have to reimplement later - Sam - #if fd.input_session_data.has_key('user'): - # self.userName = fd.input_session_data['user'] - #if fd.input_session_data.has_key('privilege'): - # self.privilege = fd.input_session_data['privilege'] - - def __str__(self): - - #XZ: default setting - thisUserName = self.userName - thisPrivilege = self.privilege - #XZ: user may just go through login or logoff page - if self.session_data_changed.has_key('user'): - thisUserName = self.session_data_changed['user'] - if self.session_data_changed.has_key('privilege'): - thisPrivilege = self.session_data_changed['privilege'] - - if thisUserName == 'Guest': - userInfo = 'Welcome! Login' - else: - userInfo = 'Hi, %s! Logout' % thisUserName - - reload(header) - self.dict['header'] = header.header_string % userInfo - - serverInfo = "It took %2.3f second(s) for %s to generate this page" % (time.time()-self.starttime, socket.getfqdn()) - reload(footer) - self.dict['footer'] = footer.footer_string % serverInfo - - slist = [] - for item in self.contents: - slist.append(self.dict[item]) - return self.template % tuple(slist) - - - def __del__(self): - if self.cursor: - self.cursor.close() - - def write(self): - 'return string representation of this object' - - if self.cursor: - self.cursor.close() - - return str(self) - - def writeFile(self, filename): - 'save string representation of this object into a file' - if self.cursor: - self.cursor.close() - - try: - 'it could take a long time to generate the file, save to .tmp first' - fp = open(os.path.join(webqtlConfig.TMPDIR, filename+'.tmp'), 'wb') - fp.write(str(self)) - fp.close() - path_tmp = os.path.join(webqtlConfig.TMPDIR, filename+'.tmp') - path_html = os.path.join(webqtlConfig.TMPDIR, filename) - shutil.move(path_tmp,path_html) - except: - pass - - def openMysql(self): - try: - self.con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, \ - user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) - self.cursor = self.con.cursor() - return 1 - except: - heading = "Connect MySQL Server" - detail = ["Can't connect to MySQL server on '"+ webqtlConfig.MYSQL_SERVER+"':100061. \ - The server may be down at this time"] - self.error(heading=heading,detail=detail,error="Error 2003") - return 0 - - def updMysql(self): - try: - self.con = MySQLdb.Connect(db=webqtlConfig.DB_UPDNAME,host=webqtlConfig.MYSQL_UPDSERVER, \ - user=webqtlConfig.DB_UPDUSER,passwd=webqtlConfig.DB_UPDPASSWD) - self.cursor = self.con.cursor() - return 1 - except: - heading = "Connect MySQL Server" - detail = ["update: Can't connect to MySQL server on '"+ webqtlConfig.MYSQL_UPDSERVER+"':100061. \ - The server may be down at this time "] - self.error(heading=heading,detail=detail,error="Error 2003") - return 0 - - def error(self,heading="",intro=[],detail=[],title="Error",error="Error"): - 'generating a WebQTL style error page' - Heading = HT.Paragraph(heading) - Heading.__setattr__("class","title") - - Intro = HT.Blockquote() - if intro: - for item in intro: - Intro.append(item) - else: - Intro.append(HT.Strong('Sorry!'),' Error occurred while processing\ - your request.', HT.P(),'The nature of the error generated is as\ - follows:') - - Detail = HT.Blockquote() - Detail.append(HT.Span("%s : " % error,Class="fwb cr")) - if detail: - Detail2 = HT.Blockquote() - for item in detail: - Detail2.append(item) - Detail.append(HT.Italic(Detail2)) - - #Detail.__setattr__("class","subtitle") - TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee',valign="top") - TD_LR.append(Heading,Intro,Detail) - self.dict['body'] = str(TD_LR) - self.dict['title'] = title - - def session(self,mytitle="",myHeading=""): - 'generate a auto-refreshing temporary html file(waiting page)' - self.filename = webqtlUtil.generate_session() - self.dict['title'] = mytitle - self.dict['basehref'] = webqtlConfig.REFRESHSTR % (webqtlConfig.CGIDIR, self.filename) + "" #webqtlConfig.BASEHREF - - TD_LR = HT.TD(align="center", valign="middle", height=200,width="100%", bgColor='#eeeeee') - Heading = HT.Paragraph(myHeading, Class="fwb fs16 cr") - # NL, 07/27/2010. variable 'PROGRESSBAR' has been moved from templatePage.py to webqtlUtil.py; - TD_LR.append(Heading, HT.BR(), webqtlUtil.PROGRESSBAR) - self.dict['body'] = TD_LR - self.writeFile(self.filename + '.html') - return self.filename + contents = ['title','basehref','js1','js2', 'layer', 'header', 'body', 'footer'] + + # you can pass in another template here if you want + def __init__(self, fd=None, template=template.template): + + # initiate dictionary + self.starttime = time.time() + self.dict = {} + self.template = template + + for item in self.contents: + self.dict[item] = "" + + self.dict['basehref'] = "" #webqtlConfig.BASEHREF + self.cursor = None + + self.cookie = [] #XZ: list to hold cookies (myCookie object) being changed + self.content_type = 'text/html' + self.content_disposition = '' + self.redirection = '' + self.debug = '' + self.attachment = '' + + #XZ: Holding data (new data or existing data being changed) that should be saved to session. The data must be picklable!!! + self.session_data_changed = {} + + self.userName = 'Guest' + self.privilege = 'guest' + + # Commenting this out for flask - we'll have to reimplement later - Sam + #if fd.input_session_data.has_key('user'): + # self.userName = fd.input_session_data['user'] + #if fd.input_session_data.has_key('privilege'): + # self.privilege = fd.input_session_data['privilege'] + + def __str__(self): + + #XZ: default setting + thisUserName = self.userName + thisPrivilege = self.privilege + #XZ: user may just go through login or logoff page + if self.session_data_changed.has_key('user'): + thisUserName = self.session_data_changed['user'] + if self.session_data_changed.has_key('privilege'): + thisPrivilege = self.session_data_changed['privilege'] + + if thisUserName == 'Guest': + userInfo = 'Welcome! Login' + else: + userInfo = 'Hi, %s! Logout' % thisUserName + + reload(header) + self.dict['header'] = header.header_string % userInfo + + serverInfo = "It took %2.3f second(s) for %s to generate this page" % (time.time()-self.starttime, socket.getfqdn()) + reload(footer) + self.dict['footer'] = footer.footer_string % serverInfo + + slist = [] + for item in self.contents: + slist.append(self.dict[item]) + return self.template % tuple(slist) + + + def __del__(self): + if self.cursor: + self.cursor.close() + + def write(self): + 'return string representation of this object' + + if self.cursor: + self.cursor.close() + + return str(self) + + def writeFile(self, filename): + 'save string representation of this object into a file' + if self.cursor: + self.cursor.close() + + try: + 'it could take a long time to generate the file, save to .tmp first' + fp = open(os.path.join(webqtlConfig.TMPDIR, filename+'.tmp'), 'wb') + fp.write(str(self)) + fp.close() + path_tmp = os.path.join(webqtlConfig.TMPDIR, filename+'.tmp') + path_html = os.path.join(webqtlConfig.TMPDIR, filename) + shutil.move(path_tmp,path_html) + except: + pass + + def openMysql(self): + try: + self.con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, \ + user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) + self.cursor = self.con.cursor() + return 1 + except: + heading = "Connect MySQL Server" + detail = ["Can't connect to MySQL server on '"+ webqtlConfig.MYSQL_SERVER+"':100061. \ + The server may be down at this time"] + self.error(heading=heading,detail=detail,error="Error 2003") + return 0 + + def updMysql(self): + try: + self.con = MySQLdb.Connect(db=webqtlConfig.DB_UPDNAME,host=webqtlConfig.MYSQL_UPDSERVER, \ + user=webqtlConfig.DB_UPDUSER,passwd=webqtlConfig.DB_UPDPASSWD) + self.cursor = self.con.cursor() + return 1 + except: + heading = "Connect MySQL Server" + detail = ["update: Can't connect to MySQL server on '"+ webqtlConfig.MYSQL_UPDSERVER+"':100061. \ + The server may be down at this time "] + self.error(heading=heading,detail=detail,error="Error 2003") + return 0 + + def error(self,heading="",intro=[],detail=[],title="Error",error="Error"): + 'generating a WebQTL style error page' + Heading = HT.Paragraph(heading) + Heading.__setattr__("class","title") + + Intro = HT.Blockquote() + if intro: + for item in intro: + Intro.append(item) + else: + Intro.append(HT.Strong('Sorry!'),' Error occurred while processing\ + your request.', HT.P(),'The nature of the error generated is as\ + follows:') + + Detail = HT.Blockquote() + Detail.append(HT.Span("%s : " % error,Class="fwb cr")) + if detail: + Detail2 = HT.Blockquote() + for item in detail: + Detail2.append(item) + Detail.append(HT.Italic(Detail2)) + + #Detail.__setattr__("class","subtitle") + TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee',valign="top") + TD_LR.append(Heading,Intro,Detail) + self.dict['body'] = str(TD_LR) + self.dict['title'] = title + + def session(self,mytitle="",myHeading=""): + 'generate a auto-refreshing temporary html file(waiting page)' + self.filename = webqtlUtil.generate_session() + self.dict['title'] = mytitle + self.dict['basehref'] = webqtlConfig.REFRESHSTR % (webqtlConfig.CGIDIR, self.filename) + "" #webqtlConfig.BASEHREF + + TD_LR = HT.TD(align="center", valign="middle", height=200,width="100%", bgColor='#eeeeee') + Heading = HT.Paragraph(myHeading, Class="fwb fs16 cr") + # NL, 07/27/2010. variable 'PROGRESSBAR' has been moved from templatePage.py to webqtlUtil.py; + TD_LR.append(Heading, HT.BR(), webqtlUtil.PROGRESSBAR) + self.dict['body'] = TD_LR + self.writeFile(self.filename + '.html') + return self.filename diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py index 4df32ca4..f68354be 100755 --- a/wqflask/base/webqtlCaseData.py +++ b/wqflask/base/webqtlCaseData.py @@ -25,30 +25,27 @@ # Last updated by GeneNetwork Core Team 2010/10/20 class webqtlCaseData: - """ - one case data in one trait - """ + """ + one case data in one trait + """ - val = None #Trait Value - var = None #Trait Variance - N = None #Number of individuals - - def __init__(self, val=val, var=var, N=N): - self.val = val - self.var = var - self.N = N - - def __str__(self): - str = "" - if self.val != None: - str += "value=%2.3f" % self.val - if self.var != None: - str += " variance=%2.3f" % self.var - if self.N != None: - str += " ndata=%d" % self.N - return str - - __repr__ = __str__ + val = None #Trait Value + var = None #Trait Variance + N = None #Number of individuals + def __init__(self, val=val, var=var, N=N): + self.val = val + self.var = var + self.N = N + def __str__(self): + str = "" + if self.val != None: + str += "value=%2.3f" % self.val + if self.var != None: + str += " variance=%2.3f" % self.var + if self.N != None: + str += " ndata=%d" % self.N + return str + __repr__ = __str__ diff --git a/wqflask/base/webqtlDataset.py b/wqflask/base/webqtlDataset.py index da1b8601..f8491bb1 100755 --- a/wqflask/base/webqtlDataset.py +++ b/wqflask/base/webqtlDataset.py @@ -31,130 +31,125 @@ import webqtlConfig class webqtlDataset: - """ - Database class defines a database in webqtl, can be either Microarray, - Published phenotype, genotype, or user input database(temp) - """ - - def __init__(self, dbName, cursor=None): - - assert dbName - self.id = 0 - self.name = '' - self.type = '' - self.riset = '' - self.cursor = cursor - - #temporary storage - if dbName.find('Temp') >= 0: - self.searchfield = ['name','description'] - self.disfield = ['name','description'] - self.type = 'Temp' - self.id = 1 - self.fullname = 'Temporary Storage' - self.shortname = 'Temp' - elif dbName.find('Publish') >= 0: - self.searchfield = ['name','post_publication_description','abstract','title','authors'] - self.disfield = ['name','pubmed_id', - 'pre_publication_description', 'post_publication_description', 'original_description', - 'pre_publication_abbreviation', 'post_publication_abbreviation', - 'lab_code', 'submitter', 'owner', 'authorized_users', - 'authors','title','abstract', 'journal','volume','pages','month', - 'year','sequence', 'units', 'comments'] - self.type = 'Publish' - elif dbName.find('Geno') >= 0: - self.searchfield = ['name','chr'] - self.disfield = ['name','chr','mb', 'source2', 'sequence'] - self.type = 'Geno' - else: #ProbeSet - self.searchfield = ['name','description','probe_target_description', - 'symbol','alias','genbankid','unigeneid','omim', - 'refseq_transcriptid','probe_set_specificity', 'probe_set_blat_score'] - self.disfield = ['name','symbol','description','probe_target_description', - 'chr','mb','alias','geneid','genbankid', 'unigeneid', 'omim', - 'refseq_transcriptid','blatseq','targetseq','chipid', 'comments', - 'strand_probe','strand_gene','probe_set_target_region', - 'probe_set_specificity', 'probe_set_blat_score','probe_set_blat_mb_start', - 'probe_set_blat_mb_end', 'probe_set_strand', - 'probe_set_note_by_rw', 'flag'] - self.type = 'ProbeSet' - self.name = dbName - if self.cursor and self.id == 0: - self.retrieveName() - - def __str__(self): - return self.name - - __repr__ = __str__ - - - def getRISet(self): - assert self.cursor - if self.type == 'Publish': - query = ''' - SELECT - InbredSet.Name, InbredSet.Id - FROM - InbredSet, PublishFreeze - WHERE - PublishFreeze.InbredSetId = InbredSet.Id AND - PublishFreeze.Name = "%s" - ''' % self.name - elif self.type == 'Geno': - query = ''' - SELECT - InbredSet.Name, InbredSet.Id - FROM - InbredSet, GenoFreeze - WHERE - GenoFreeze.InbredSetId = InbredSet.Id AND - GenoFreeze.Name = "%s" - ''' % self.name - elif self.type == 'ProbeSet': - query = ''' - SELECT - InbredSet.Name, InbredSet.Id - FROM - InbredSet, ProbeSetFreeze, ProbeFreeze - WHERE - ProbeFreeze.InbredSetId = InbredSet.Id AND - ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND - ProbeSetFreeze.Name = "%s" - ''' % self.name - else: - return "" - self.cursor.execute(query) - RISet, RIID = self.cursor.fetchone() - if RISet == 'BXD300': - RISet = "BXD" - self.riset = RISet - self.risetid = RIID - return RISet - - - def retrieveName(self): - assert self.id == 0 and self.cursor - query = ''' - SELECT - Id, Name, FullName, ShortName - FROM - %sFreeze - WHERE - public > %d AND - (Name = "%s" OR FullName = "%s" OR ShortName = "%s") - '''% (self.type, webqtlConfig.PUBLICTHRESH, self.name, self.name, self.name) - try: - self.cursor.execute(query) - self.id,self.name,self.fullname,self.shortname=self.cursor.fetchone() - except: - raise KeyError, `self.name`+' doesn\'t exist.' - - - def genHTML(self, Class='c0dd'): - return HT.Href(text = HT.Span('%s Database' % self.fullname, Class= "fwb " + Class), - url= webqtlConfig.INFOPAGEHREF % self.name,target="_blank") - - - - - + """ + Database class defines a database in webqtl, can be either Microarray, + Published phenotype, genotype, or user input database(temp) + """ + + def __init__(self, dbName, cursor=None): + + assert dbName + self.id = 0 + self.name = '' + self.type = '' + self.riset = '' + self.cursor = cursor + + #temporary storage + if dbName.find('Temp') >= 0: + self.searchfield = ['name','description'] + self.disfield = ['name','description'] + self.type = 'Temp' + self.id = 1 + self.fullname = 'Temporary Storage' + self.shortname = 'Temp' + elif dbName.find('Publish') >= 0: + self.searchfield = ['name','post_publication_description','abstract','title','authors'] + self.disfield = ['name','pubmed_id', + 'pre_publication_description', 'post_publication_description', 'original_description', + 'pre_publication_abbreviation', 'post_publication_abbreviation', + 'lab_code', 'submitter', 'owner', 'authorized_users', + 'authors','title','abstract', 'journal','volume','pages','month', + 'year','sequence', 'units', 'comments'] + self.type = 'Publish' + elif dbName.find('Geno') >= 0: + self.searchfield = ['name','chr'] + self.disfield = ['name','chr','mb', 'source2', 'sequence'] + self.type = 'Geno' + else: #ProbeSet + self.searchfield = ['name','description','probe_target_description', + 'symbol','alias','genbankid','unigeneid','omim', + 'refseq_transcriptid','probe_set_specificity', 'probe_set_blat_score'] + self.disfield = ['name','symbol','description','probe_target_description', + 'chr','mb','alias','geneid','genbankid', 'unigeneid', 'omim', + 'refseq_transcriptid','blatseq','targetseq','chipid', 'comments', + 'strand_probe','strand_gene','probe_set_target_region', + 'probe_set_specificity', 'probe_set_blat_score','probe_set_blat_mb_start', + 'probe_set_blat_mb_end', 'probe_set_strand', + 'probe_set_note_by_rw', 'flag'] + self.type = 'ProbeSet' + self.name = dbName + if self.cursor and self.id == 0: + self.retrieveName() + + def __str__(self): + return self.name + + __repr__ = __str__ + + + def getRISet(self): + assert self.cursor + if self.type == 'Publish': + query = ''' + SELECT + InbredSet.Name, InbredSet.Id + FROM + InbredSet, PublishFreeze + WHERE + PublishFreeze.InbredSetId = InbredSet.Id AND + PublishFreeze.Name = "%s" + ''' % self.name + elif self.type == 'Geno': + query = ''' + SELECT + InbredSet.Name, InbredSet.Id + FROM + InbredSet, GenoFreeze + WHERE + GenoFreeze.InbredSetId = InbredSet.Id AND + GenoFreeze.Name = "%s" + ''' % self.name + elif self.type == 'ProbeSet': + query = ''' + SELECT + InbredSet.Name, InbredSet.Id + FROM + InbredSet, ProbeSetFreeze, ProbeFreeze + WHERE + ProbeFreeze.InbredSetId = InbredSet.Id AND + ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND + ProbeSetFreeze.Name = "%s" + ''' % self.name + else: + return "" + self.cursor.execute(query) + RISet, RIID = self.cursor.fetchone() + if RISet == 'BXD300': + RISet = "BXD" + self.riset = RISet + self.risetid = RIID + return RISet + + + def retrieveName(self): + assert self.id == 0 and self.cursor + query = ''' + SELECT + Id, Name, FullName, ShortName + FROM + %sFreeze + WHERE + public > %d AND + (Name = "%s" OR FullName = "%s" OR ShortName = "%s") + '''% (self.type, webqtlConfig.PUBLICTHRESH, self.name, self.name, self.name) + try: + self.cursor.execute(query) + self.id,self.name,self.fullname,self.shortname=self.cursor.fetchone() + except: + raise KeyError, `self.name`+' doesn\'t exist.' + + + def genHTML(self, Class='c0dd'): + return HT.Href(text = HT.Span('%s Database' % self.fullname, Class= "fwb " + Class), + url= webqtlConfig.INFOPAGEHREF % self.name,target="_blank") diff --git a/wqflask/base/webqtlFormData.py b/wqflask/base/webqtlFormData.py index c94dbe53..06faacc0 100755 --- a/wqflask/base/webqtlFormData.py +++ b/wqflask/base/webqtlFormData.py @@ -40,261 +40,261 @@ from utility import webqtlUtil class webqtlFormData: - 'Represents data from a WebQTL form page, needed to generate the next page' - attrs = ('formID','RISet','genotype','strainlist','allstrainlist', - 'suggestive','significance','submitID','identification', 'enablevariance', - 'nperm','nboot','email','incparentsf1','genotype_1','genotype_2','traitInfo') - - #XZ: Attention! All attribute values must be picklable! - - def __init__(self, start_vars = None, req = None, mod_python_session=None, FieldStorage_formdata=None): - - self.__dict__.update(start_vars) - - for item in self.attrs: - setattr(self,item, None) - - try: - self.remote_ip = req.connection.remote_ip - except: - self.remote_ip = '1.2.3.4' - - if req and req.headers_in.has_key('referer'): - self.refURL = req.headers_in['referer'] - else: - self.refURL = None - - # For now let's just comment all this out - Sam - - #self.cookies = cookieData.cookieData(Cookie.get_cookies(req)) #XZ: dictionary type. To hold values transfered from mod_python Cookie. - # - ##XZ: dictionary type. To hold values transfered from mod_python Session object. We assume that it is always picklable. - #self.input_session_data = sessionData.sessionData( mod_python_session ) - # - ##XZ: FieldStorage_formdata may contain item that can't be pickled. Must convert to picklable data. - #self.formdata = cgiData( FieldStorage_formdata ) - # - ##get Form ID - #self.formID = self.formdata.getfirst('FormID') - # - ##get rest of the attributes - #if self.formID: - # for item in self.attrs: - # value = self.formdata.getfirst(item) - # if value != None: - # setattr(self,item,string.strip(value)) - - self.ppolar = "" - self.mpolar = "" - if self.RISet: - try: - # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; - f1, f12, self.mpolar, self.ppolar = webqtlUtil.ParInfo[self.RISet] - except: - f1 = f12 = self.mpolar = self.ppolar = None - - try: - self.nperm = int(self.nperm) - self.nboot = int(self.nboot) - except: - self.nperm = 2000 #XZ: Rob asked to change the default value to 2000 - self.nboot = 2000 #XZ: Rob asked to change the default value to 2000 - - if self.allstrainlist: - self.allstrainlist = map(string.strip, string.split(self.allstrainlist)) - #self.readGenotype() - #self.readData() - - if self.RISet == 'BXD300': - self.RISet = 'BXD' - else: - pass - - def __getitem__(self, key): - return self.__dict__[key] - - def get(self, key, default=None): - if key in self.__dict__: - return self.__dict__[key] - else: - return default - - def __str__(self): - rstr = '' - for item in self.attrs: - if item != 'genotype': - rstr += '%s:%s\n' % (item,str(getattr(self,item))) - return rstr - - - def readGenotype(self): - 'read genotype from .geno file' - if self.RISet == 'BXD300': - self.RISet = 'BXD' - else: - pass - assert self.RISet - #genotype_1 is Dataset Object without parents and f1 - #genotype_2 is Dataset Object with parents and f1 (not for intercross) - self.genotype_1 = reaper.Dataset() - self.genotype_1.read(os.path.join(webqtlConfig.GENODIR, self.RISet + '.geno')) - try: - # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; - _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.RISet] - except: - _f1 = _f12 = _mat = _pat = None - - self.genotype_2 =self.genotype_1 - if self.genotype_1.type == "riset" and _mat and _pat: - self.genotype_2 = self.genotype_1.add(Mat=_mat, Pat=_pat) #, F1=_f1) - - #determine default genotype object - if self.incparentsf1 and self.genotype_1.type != "intercross": - self.genotype = self.genotype_2 - else: - self.incparentsf1 = 0 - self.genotype = self.genotype_1 - self.strainlist = list(self.genotype.prgy) - self.f1list = self.parlist = [] - if _f1 and _f12: - self.f1list = [_f1, _f12] - if _mat and _pat: - self.parlist = [_mat, _pat] - - def readData(self, strainlst=[], incf1=[]): - 'read user input data or from trait data and analysis form' - - if not self.genotype: - self.readGenotype() - if not strainlst: - if incf1: - strainlst = self.f1list + self.strainlist - else: - strainlst = self.strainlist - - - traitfiledata = self.formdata.getfirst('traitfile') - traitpastedata = self.formdata.getfirst('traitpaste') - variancefiledata = self.formdata.getfirst('variancefile') - variancepastedata = self.formdata.getfirst('variancepaste') - Nfiledata = self.formdata.getfirst('Nfile') - - - if traitfiledata: - tt = string.split(traitfiledata) - vals = map(webqtlUtil.StringAsFloat, tt) - elif traitpastedata: - tt = string.split(traitpastedata) - vals = map(webqtlUtil.StringAsFloat, tt) - else: - vals = map(self.FormDataAsFloat, strainlst) - - if len(vals) < len(strainlst): - vals += [None]*(len(strainlst) - len(vals)) - elif len(vals) > len(strainlst): - vals = vals[:len(strainlst)] - else: - pass - - - if variancefiledata: - tt = string.split(variancefiledata) - vars = map(webqtlUtil.StringAsFloat, tt) - elif variancepastedata: - tt = string.split(variancepastedata) - vars = map(webqtlUtil.StringAsFloat, tt) - else: - vars = map(self.FormVarianceAsFloat, strainlst) - - if len(vars) < len(strainlst): - vars += [None]*(len(strainlst) - len(vars)) - elif len(vars) > len(strainlst): - vars = vars[:len(strainlst)] - else: - pass - - if Nfiledata: - tt = string.split(Nfiledata) - nstrains = map(webqtlUtil.IntAsFloat, tt) - if len(nstrains) < len(strainlst): - nstrains += [None]*(len(strainlst) - len(nstrains)) - else: - nstrains = map(self.FormNAsFloat, strainlst) - - ##vals, vars, nstrains is obsolete - self.allTraitData = {} - for i, _strain in enumerate(strainlst): - if vals[i] != None: - self.allTraitData[_strain] = webqtlCaseData(vals[i], vars[i], nstrains[i]) - - - - def informativeStrains(self, strainlst=[], incVars = 0): - '''if readData was called, use this to output the informative strains - (strain with values)''' - if not strainlst: - strainlst = self.strainlist - strains = [] - vals = [] - vars = [] - for _strain in strainlst: - if self.allTraitData.has_key(_strain): - _val, _var = self.allTraitData[_strain].val, self.allTraitData[_strain].var - if _val != None: - if incVars: - if _var != None: - strains.append(_strain) - vals.append(_val) - vars.append(_var) - else: - strains.append(_strain) - vals.append(_val) - vars.append(None) - return strains, vals, vars, len(strains) - - - - def FormDataAsFloat(self, key): - try: - return float(self.formdata.getfirst(key)) - except: - return None - - - def FormVarianceAsFloat(self, key): - try: - return float(self.formdata.getfirst('V' + key)) - except: - return None - - def FormNAsFloat(self, key): - try: - return int(self.formdata.getfirst('N' + key)) - except: - return None - - def Sample(self): - 'Create some dummy data for testing' - self.RISet = 'BXD' - self.incparentsf1 = 'on' - #self.display = 9.2 - #self.significance = 16.1 - self.readGenotype() - self.identification = 'BXD : Coat color example by Lu Lu, et al' - #self.readGenotype() - #self.genotype.ReadMM('AXBXAforQTL') - #self.strainlist = map((lambda x, y='': '%s%s' % (y,x)), self.genotype.prgy) - #self.strainlist.sort() - self.allTraitData = {'BXD29': webqtlCaseData(3), 'BXD28': webqtlCaseData(2), - 'BXD25': webqtlCaseData(2), 'BXD24': webqtlCaseData(2), 'BXD27': webqtlCaseData(2), - 'BXD21': webqtlCaseData(1), 'BXD20': webqtlCaseData(4), 'BXD23': webqtlCaseData(4), - 'BXD22': webqtlCaseData(3), 'BXD14': webqtlCaseData(4), 'BXD15': webqtlCaseData(2), - 'BXD16': webqtlCaseData(3), 'BXD11': webqtlCaseData(4), 'BXD12': webqtlCaseData(3), - 'BXD13': webqtlCaseData(2), 'BXD18': webqtlCaseData(3), 'BXD19': webqtlCaseData(3), - 'BXD38': webqtlCaseData(3), 'BXD39': webqtlCaseData(3), 'BXD36': webqtlCaseData(2), - 'BXD34': webqtlCaseData(4), 'BXD35': webqtlCaseData(4), 'BXD32': webqtlCaseData(4), - 'BXD33': webqtlCaseData(3), 'BXD30': webqtlCaseData(1), 'BXD31': webqtlCaseData(4), - 'DBA/2J': webqtlCaseData(1), 'BXD8': webqtlCaseData(3), 'BXD9': webqtlCaseData(1), - 'BXD6': webqtlCaseData(3), 'BXD5': webqtlCaseData(3), 'BXD2': webqtlCaseData(4), - 'BXD1': webqtlCaseData(1), 'C57BL/6J': webqtlCaseData(4), 'B6D2F1': webqtlCaseData(4), - 'BXD42': webqtlCaseData(4), 'BXD40': webqtlCaseData(3)} + 'Represents data from a WebQTL form page, needed to generate the next page' + attrs = ('formID','RISet','genotype','strainlist','allstrainlist', + 'suggestive','significance','submitID','identification', 'enablevariance', + 'nperm','nboot','email','incparentsf1','genotype_1','genotype_2','traitInfo') + + #XZ: Attention! All attribute values must be picklable! + + def __init__(self, start_vars = None, req = None, mod_python_session=None, FieldStorage_formdata=None): + + self.__dict__.update(start_vars) + + for item in self.attrs: + setattr(self,item, None) + + try: + self.remote_ip = req.connection.remote_ip + except: + self.remote_ip = '1.2.3.4' + + if req and req.headers_in.has_key('referer'): + self.refURL = req.headers_in['referer'] + else: + self.refURL = None + + # For now let's just comment all this out - Sam + + #self.cookies = cookieData.cookieData(Cookie.get_cookies(req)) #XZ: dictionary type. To hold values transfered from mod_python Cookie. + # + ##XZ: dictionary type. To hold values transfered from mod_python Session object. We assume that it is always picklable. + #self.input_session_data = sessionData.sessionData( mod_python_session ) + # + ##XZ: FieldStorage_formdata may contain item that can't be pickled. Must convert to picklable data. + #self.formdata = cgiData( FieldStorage_formdata ) + # + ##get Form ID + #self.formID = self.formdata.getfirst('FormID') + # + ##get rest of the attributes + #if self.formID: + # for item in self.attrs: + # value = self.formdata.getfirst(item) + # if value != None: + # setattr(self,item,string.strip(value)) + + self.ppolar = "" + self.mpolar = "" + if self.RISet: + try: + # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; + f1, f12, self.mpolar, self.ppolar = webqtlUtil.ParInfo[self.RISet] + except: + f1 = f12 = self.mpolar = self.ppolar = None + + try: + self.nperm = int(self.nperm) + self.nboot = int(self.nboot) + except: + self.nperm = 2000 #XZ: Rob asked to change the default value to 2000 + self.nboot = 2000 #XZ: Rob asked to change the default value to 2000 + + if self.allstrainlist: + self.allstrainlist = map(string.strip, string.split(self.allstrainlist)) + #self.readGenotype() + #self.readData() + + if self.RISet == 'BXD300': + self.RISet = 'BXD' + else: + pass + + def __getitem__(self, key): + return self.__dict__[key] + + def get(self, key, default=None): + if key in self.__dict__: + return self.__dict__[key] + else: + return default + + def __str__(self): + rstr = '' + for item in self.attrs: + if item != 'genotype': + rstr += '%s:%s\n' % (item,str(getattr(self,item))) + return rstr + + + def readGenotype(self): + 'read genotype from .geno file' + if self.RISet == 'BXD300': + self.RISet = 'BXD' + else: + pass + assert self.RISet + #genotype_1 is Dataset Object without parents and f1 + #genotype_2 is Dataset Object with parents and f1 (not for intercross) + self.genotype_1 = reaper.Dataset() + self.genotype_1.read(os.path.join(webqtlConfig.GENODIR, self.RISet + '.geno')) + try: + # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; + _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.RISet] + except: + _f1 = _f12 = _mat = _pat = None + + self.genotype_2 =self.genotype_1 + if self.genotype_1.type == "riset" and _mat and _pat: + self.genotype_2 = self.genotype_1.add(Mat=_mat, Pat=_pat) #, F1=_f1) + + #determine default genotype object + if self.incparentsf1 and self.genotype_1.type != "intercross": + self.genotype = self.genotype_2 + else: + self.incparentsf1 = 0 + self.genotype = self.genotype_1 + self.strainlist = list(self.genotype.prgy) + self.f1list = self.parlist = [] + if _f1 and _f12: + self.f1list = [_f1, _f12] + if _mat and _pat: + self.parlist = [_mat, _pat] + + def readData(self, strainlst=[], incf1=[]): + 'read user input data or from trait data and analysis form' + + if not self.genotype: + self.readGenotype() + if not strainlst: + if incf1: + strainlst = self.f1list + self.strainlist + else: + strainlst = self.strainlist + + + traitfiledata = self.formdata.getfirst('traitfile') + traitpastedata = self.formdata.getfirst('traitpaste') + variancefiledata = self.formdata.getfirst('variancefile') + variancepastedata = self.formdata.getfirst('variancepaste') + Nfiledata = self.formdata.getfirst('Nfile') + + + if traitfiledata: + tt = string.split(traitfiledata) + vals = map(webqtlUtil.StringAsFloat, tt) + elif traitpastedata: + tt = string.split(traitpastedata) + vals = map(webqtlUtil.StringAsFloat, tt) + else: + vals = map(self.FormDataAsFloat, strainlst) + + if len(vals) < len(strainlst): + vals += [None]*(len(strainlst) - len(vals)) + elif len(vals) > len(strainlst): + vals = vals[:len(strainlst)] + else: + pass + + + if variancefiledata: + tt = string.split(variancefiledata) + vars = map(webqtlUtil.StringAsFloat, tt) + elif variancepastedata: + tt = string.split(variancepastedata) + vars = map(webqtlUtil.StringAsFloat, tt) + else: + vars = map(self.FormVarianceAsFloat, strainlst) + + if len(vars) < len(strainlst): + vars += [None]*(len(strainlst) - len(vars)) + elif len(vars) > len(strainlst): + vars = vars[:len(strainlst)] + else: + pass + + if Nfiledata: + tt = string.split(Nfiledata) + nstrains = map(webqtlUtil.IntAsFloat, tt) + if len(nstrains) < len(strainlst): + nstrains += [None]*(len(strainlst) - len(nstrains)) + else: + nstrains = map(self.FormNAsFloat, strainlst) + + ##vals, vars, nstrains is obsolete + self.allTraitData = {} + for i, _strain in enumerate(strainlst): + if vals[i] != None: + self.allTraitData[_strain] = webqtlCaseData(vals[i], vars[i], nstrains[i]) + + + + def informativeStrains(self, strainlst=[], incVars = 0): + '''if readData was called, use this to output the informative strains + (strain with values)''' + if not strainlst: + strainlst = self.strainlist + strains = [] + vals = [] + vars = [] + for _strain in strainlst: + if self.allTraitData.has_key(_strain): + _val, _var = self.allTraitData[_strain].val, self.allTraitData[_strain].var + if _val != None: + if incVars: + if _var != None: + strains.append(_strain) + vals.append(_val) + vars.append(_var) + else: + strains.append(_strain) + vals.append(_val) + vars.append(None) + return strains, vals, vars, len(strains) + + + + def FormDataAsFloat(self, key): + try: + return float(self.formdata.getfirst(key)) + except: + return None + + + def FormVarianceAsFloat(self, key): + try: + return float(self.formdata.getfirst('V' + key)) + except: + return None + + def FormNAsFloat(self, key): + try: + return int(self.formdata.getfirst('N' + key)) + except: + return None + + def Sample(self): + 'Create some dummy data for testing' + self.RISet = 'BXD' + self.incparentsf1 = 'on' + #self.display = 9.2 + #self.significance = 16.1 + self.readGenotype() + self.identification = 'BXD : Coat color example by Lu Lu, et al' + #self.readGenotype() + #self.genotype.ReadMM('AXBXAforQTL') + #self.strainlist = map((lambda x, y='': '%s%s' % (y,x)), self.genotype.prgy) + #self.strainlist.sort() + self.allTraitData = {'BXD29': webqtlCaseData(3), 'BXD28': webqtlCaseData(2), + 'BXD25': webqtlCaseData(2), 'BXD24': webqtlCaseData(2), 'BXD27': webqtlCaseData(2), + 'BXD21': webqtlCaseData(1), 'BXD20': webqtlCaseData(4), 'BXD23': webqtlCaseData(4), + 'BXD22': webqtlCaseData(3), 'BXD14': webqtlCaseData(4), 'BXD15': webqtlCaseData(2), + 'BXD16': webqtlCaseData(3), 'BXD11': webqtlCaseData(4), 'BXD12': webqtlCaseData(3), + 'BXD13': webqtlCaseData(2), 'BXD18': webqtlCaseData(3), 'BXD19': webqtlCaseData(3), + 'BXD38': webqtlCaseData(3), 'BXD39': webqtlCaseData(3), 'BXD36': webqtlCaseData(2), + 'BXD34': webqtlCaseData(4), 'BXD35': webqtlCaseData(4), 'BXD32': webqtlCaseData(4), + 'BXD33': webqtlCaseData(3), 'BXD30': webqtlCaseData(1), 'BXD31': webqtlCaseData(4), + 'DBA/2J': webqtlCaseData(1), 'BXD8': webqtlCaseData(3), 'BXD9': webqtlCaseData(1), + 'BXD6': webqtlCaseData(3), 'BXD5': webqtlCaseData(3), 'BXD2': webqtlCaseData(4), + 'BXD1': webqtlCaseData(1), 'C57BL/6J': webqtlCaseData(4), 'B6D2F1': webqtlCaseData(4), + 'BXD42': webqtlCaseData(4), 'BXD40': webqtlCaseData(3)} diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py index 88226894..812d112a 100755 --- a/wqflask/base/webqtlTrait.py +++ b/wqflask/base/webqtlTrait.py @@ -14,579 +14,579 @@ from pprint import pformat as pf class webqtlTrait: - """ - Trait class defines a trait in webqtl, can be either Microarray, - Published phenotype, genotype, or user input trait - - """ - - def __init__(self, cursor = None, **kw): - print("in webqtlTrait") - self.cursor = cursor - self.db = None # database object - self.name = '' # Trait ID, ProbeSet ID, Published ID, etc. - self.cellid = '' - self.identification = 'un-named trait' - self.riset = '' - self.haveinfo = 0 - self.sequence = '' # Blat sequence, available for ProbeSet - self.data = {} - print("foo") - print("kw in webqtlTrait are:", pf(kw)) - print("printed\n\n") - for name, value in kw.items(): - if self.__dict__.has_key(name): - setattr(self, name, value) - elif name == 'fullname': - name2 = value.split("::") - if len(name2) == 2: - self.db, self.name = name2 - elif len(name2) == 3: - self.db, self.name, self.cellid = name2 - else: - raise KeyError, repr(value) + ' parameter format error.' - else: - raise KeyError, repr(name) + ' not a valid parameter for this class.' - - if self.db and isinstance(self.db, basestring): - assert self.cursor, "Don't have a cursor" - self.db = webqtlDataset(self.db, self.cursor) - - #if self.db == None, not from a database - print("self.db is:", self.db, type(self.db)) - if self.db: - if self.db.type == "Temp": - self.cursor.execute(''' - SELECT - InbredSet.Name - FROM - InbredSet, Temp - WHERE - Temp.InbredSetId = InbredSet.Id AND - Temp.Name = "%s" - ''', self.name) - self.riset = self.cursor.fetchone()[0] - else: - self.riset = self.db.getRISet() - - # - # In ProbeSet, there are maybe several annotations match one sequence - # so we need use sequence(BlatSeq) as the identification, when we update - # one annotation, we update the others who match the sequence also. - # - # Hongqiang Li, 3/3/2008 - # - - #XZ, 05/08/2009: This block is not neccessary. We can add 'BlatSeq' into disfield. - # The variable self.sequence should be changed to self.BlatSeq - # It also should be changed in other places where it are used. - - if self.db: - if self.db.type == 'ProbeSet': - print("Doing ProbeSet Query") - query = ''' - SELECT - ProbeSet.BlatSeq - FROM - ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE - ProbeSet.Id=ProbeSetXRef.ProbeSetId and - ProbeSetFreeze.Id = ProbeSetXRef.ProbeSetFreezeId and - ProbeSet.Name = %s and - ProbeSetFreeze.Name = %s - ''', (self.name, self.db.name) - print("query is:", query) - self.cursor.execute(*query) - self.sequence = self.cursor.fetchone()[0] - print("self.sequence is:", self.sequence) - - - def getName(self): - str = "" - if self.db and self.name: - str = "%s::%s" % (self.db, self.name) - if self.cellid: - str += "::" + self.cellid - else: - str = self.description - return str - - # - # when user enter a trait or GN generate a trait, user want show the name - # not the name that generated by GN randomly, the two follow function are - # used to give the real name and the database. displayName() will show the - # database also, getGivenName() just show the name. - # For other trait, displayName() as same as getName(), getGivenName() as - # same as self.name - # - # Hongqiang 11/29/07 - # - def getGivenName(self): - str = self.name - if self.db and self.name: - if self.db.type=='Temp': - self.cursor.execute('SELECT description FROM Temp WHERE Name=%s', self.name) - desc = self.cursor.fetchone()[0] - if desc.__contains__('PCA'): - desc = desc[desc.rindex(':')+1:].strip() - else: - desc = desc[:desc.index('entered')].strip() - str = desc - return str - - def displayName(self): - str = "" - if self.db and self.name: - if self.db.type=='Temp': - desc = self.description - if desc.__contains__('PCA'): - desc = desc[desc.rindex(':')+1:].strip() - else: - desc = desc[:desc.index('entered')].strip() - str = "%s::%s" % (self.db, desc) - else: - str = "%s::%s" % (self.db, self.name) - if self.cellid: - str += "::" + self.cellid - else: - str = self.description - - return str - - - #def __str__(self): - # #return "%s %s" % (self.getName(), self.riset) - # return self.getName() - __str__ = getName - __repr__ = __str__ - - def exportData(self, strainlist, type="val"): - """ - export data according to strainlist - mostly used in calculating correlation - """ - result = [] - for strain in strainlist: - if self.data.has_key(strain): - if type=='val': - result.append(self.data[strain].val) - elif type=='var': - result.append(self.data[strain].var) - elif type=='N': - result.append(self.data[strain].N) - else: - raise KeyError, `type`+' type is incorrect.' - else: - result.append(None) - return result - - def exportInformative(self, incVar=0): - """ - export informative strain - mostly used in qtl regression - """ - strains = [] - vals = [] - vars = [] - for strain, value in self.data.items(): - if value.val != None: - if not incVar or value.var != None: - strains.append(strain) - vals.append(value.val) - vars.append(value.var) - return strains, vals, vars - - - # - # In ProbeSet, there are maybe several annotations match one sequence - # so we need use sequence(BlatSeq) as the identification, when we update - # one annotation, we update the others who match the sequence also. - # - # Hongqiang Li, 3/3/2008 - # - def getSequence(self): - assert self.cursor - if self.db.type == 'ProbeSet': - self.cursor.execute(''' - SELECT - ProbeSet.BlatSeq - FROM - ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE - ProbeSet.Id=ProbeSetXRef.ProbeSetId and - ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and - ProbeSet.Name = %s - ProbeSetFreeze.Name = %s - ''', self.name, self.db.name) - #self.cursor.execute(query) - results = self.fetchone() - - return results[0] - - - - def retrieveData(self, strainlist=[]): - assert self.db and self.cursor - - if self.db.type == 'Temp': - query = ''' - SELECT - Strain.Name, TempData.value, TempData.SE, TempData.NStrain, TempData.Id - FROM - TempData, Temp, Strain - WHERE - TempData.StrainId = Strain.Id AND - TempData.Id = Temp.DataId AND - Temp.name = '%s' - Order BY - Strain.Name - ''' % self.name - #XZ, 03/02/2009: Xiaodong changed Data to PublishData, SE to PublishSE - elif self.db.type == 'Publish': - query = ''' - SELECT - Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id - FROM - (PublishData, Strain, PublishXRef, PublishFreeze) - left join PublishSE on - (PublishSE.DataId = PublishData.Id AND PublishSE.StrainId = PublishData.StrainId) - left join NStrain on - (NStrain.DataId = PublishData.Id AND - NStrain.StrainId = PublishData.StrainId) - WHERE - PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND - PublishData.Id = PublishXRef.DataId AND PublishXRef.Id = %s AND - PublishFreeze.Id = %d AND PublishData.StrainId = Strain.Id - Order BY - Strain.Name - ''' % (self.name, self.db.id) - - #XZ, 03/02/2009: Xiaodong changed Data to ProbeData, SE to ProbeSE - elif self.cellid: - #Probe Data - query = ''' - SELECT - Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id - FROM - (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef, - Strain, Probe, ProbeSet) - left join ProbeSE on - (ProbeSE.DataId = ProbeData.Id AND ProbeSE.StrainId = ProbeData.StrainId) - WHERE - Probe.Name = '%s' AND ProbeSet.Name = '%s' AND - Probe.ProbeSetId = ProbeSet.Id AND - ProbeXRef.ProbeId = Probe.Id AND - ProbeXRef.ProbeFreezeId = ProbeFreeze.Id AND - ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeXRef.DataId = ProbeData.Id AND - ProbeData.StrainId = Strain.Id - Order BY - Strain.Name - ''' % (self.cellid, self.name, self.db.name) - #XZ, 03/02/2009: Xiaodong added this block for ProbeSetData and ProbeSetSE - elif self.db.type == 'ProbeSet': - #ProbeSet Data - query = ''' - SELECT - Strain.Name, ProbeSetData.value, ProbeSetSE.error, ProbeSetData.Id - FROM - (ProbeSetData, ProbeSetFreeze, Strain, ProbeSet, ProbeSetXRef) - left join ProbeSetSE on - (ProbeSetSE.DataId = ProbeSetData.Id AND ProbeSetSE.StrainId = ProbeSetData.StrainId) - WHERE - ProbeSet.Name = '%s' AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSetXRef.DataId = ProbeSetData.Id AND - ProbeSetData.StrainId = Strain.Id - Order BY - Strain.Name - ''' % (self.name, self.db.name) - #XZ, 03/02/2009: Xiaodong changeded Data to GenoData, SE to GenoSE - else: - #Geno Data - #XZ: The SpeciesId is not necessary, but it's nice to keep it to speed up database search. - query = ''' - SELECT - Strain.Name, GenoData.value, GenoSE.error, GenoData.Id - FROM - (GenoData, GenoFreeze, Strain, Geno, GenoXRef) - left join GenoSE on - (GenoSE.DataId = GenoData.Id AND GenoSE.StrainId = GenoData.StrainId) - WHERE - Geno.SpeciesId = %s AND Geno.Name = '%s' AND GenoXRef.GenoId = Geno.Id AND - GenoXRef.GenoFreezeId = GenoFreeze.Id AND - GenoFreeze.Name = '%s' AND - GenoXRef.DataId = GenoData.Id AND - GenoData.StrainId = Strain.Id - Order BY - Strain.Name - ''' % (webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.db.riset), self.name, self.db.name) - - - self.cursor.execute(query) - results = self.cursor.fetchall() - self.data.clear() - if results: - self.mysqlid = results[0][-1] - if strainlist: - for item in results: - if item[0] in strainlist: - val = item[1] - if val != None: - var = item[2] - ndata = None - if self.db.type in ('Publish', 'Temp'): - ndata = item[3] - self.data[item[0]] = webqtlCaseData(val, var, ndata) - #end for - else: - for item in results: - val = item[1] - if val != None: - var = item[2] - ndata = None - if self.db.type in ('Publish', 'Temp'): - ndata = item[3] - self.data[item[0]] = webqtlCaseData(val, var, ndata) - #end for - #end if - else: - pass - - def keys(self): - return self.__dict__.keys() - - def has_key(self, key): - return self.__dict__.has_key(key) - - def items(self): - return self.__dict__.items() - - def retrieveInfo(self, QTL = None): - assert self.db and self.cursor - if self.db.type == 'Publish': - #self.db.DisField = ['Name','PubMed_ID','Phenotype','Abbreviation','Authors','Title',\ - # 'Abstract', 'Journal','Volume','Pages','Month','Year','Sequence',\ - # 'Units', 'comments'] - query = ''' - SELECT - PublishXRef.Id, Publication.PubMed_ID, - Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description, - Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation, - Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users, - Publication.Authors, Publication.Title, Publication.Abstract, - Publication.Journal, Publication.Volume, Publication.Pages, - Publication.Month, Publication.Year, PublishXRef.Sequence, - Phenotype.Units, PublishXRef.comments - FROM - PublishXRef, Publication, Phenotype, PublishFreeze - WHERE - PublishXRef.Id = %s AND - Phenotype.Id = PublishXRef.PhenotypeId AND - Publication.Id = PublishXRef.PublicationId AND - PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND - PublishFreeze.Id =%s - ''' % (self.name, self.db.id) - #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name - #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. - elif self.db.type == 'ProbeSet': - disfieldString = string.join(self.db.disfield,',ProbeSet.') - disfieldString = 'ProbeSet.' + disfieldString - query = """ - SELECT %s - FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE - ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSet.Name = '%s' - """ % (disfieldString, self.db.name, self.name) - #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name - # to avoid the problem of same marker name from different species. - elif self.db.type == 'Geno': - disfieldString = string.join(self.db.disfield,',Geno.') - disfieldString = 'Geno.' + disfieldString - query = """ - SELECT %s - FROM Geno, GenoFreeze, GenoXRef - WHERE - GenoXRef.GenoFreezeId = GenoFreeze.Id AND - GenoXRef.GenoId = Geno.Id AND - GenoFreeze.Name = '%s' AND - Geno.Name = '%s' - """ % (disfieldString, self.db.name, self.name) - else: #Temp type - query = 'SELECT %s FROM %s WHERE Name = "%s"' % \ - (string.join(self.db.disfield,','), self.db.type, self.name) - - - self.cursor.execute(query) - traitInfo = self.cursor.fetchone() - if traitInfo: - self.haveinfo = 1 - - #XZ: assign SQL query result to trait attributes. - for i, field in enumerate(self.db.disfield): - setattr(self, field, traitInfo[i]) - - if self.db.type == 'Publish': - self.confidential = 0 - if self.pre_publication_description and not self.pubmed_id: - self.confidential = 1 - - self.homologeneid = None - if self.db.type == 'ProbeSet' and self.riset and self.geneid: - #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. - #XZ: So I have to test if geneid is number before execute the query. - #XZ: The geneid values in database should be cleaned up. - try: - junk = float(self.geneid) - geneidIsNumber = 1 - except: - geneidIsNumber = 0 - - if geneidIsNumber: - query = """ - SELECT - HomologeneId - FROM - Homologene, Species, InbredSet - WHERE - Homologene.GeneId =%s AND - InbredSet.Name = '%s' AND - InbredSet.SpeciesId = Species.Id AND - Species.TaxonomyId = Homologene.TaxonomyId - """ % (self.geneid, self.riset) - self.cursor.execute(query) - result = self.cursor.fetchone() - else: - result = None - - if result: - self.homologeneid = result[0] - - if QTL: - if self.db.type == 'ProbeSet' and not self.cellid: - query = ''' - SELECT - ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean - FROM - ProbeSetXRef, ProbeSet - WHERE - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSet.Name = "%s" AND - ProbeSetXRef.ProbeSetFreezeId =%s - ''' % (self.name, self.db.id) - self.cursor.execute(query) - traitQTL = self.cursor.fetchone() - if traitQTL: - self.locus, self.lrs, self.pvalue, self.mean = traitQTL - else: - self.locus = self.lrs = self.pvalue = self.mean = "" - if self.db.type == 'Publish': - query = ''' - SELECT - PublishXRef.Locus, PublishXRef.LRS - FROM - PublishXRef, PublishFreeze - WHERE - PublishXRef.Id = %s AND - PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND - PublishFreeze.Id =%s - ''' % (self.name, self.db.id) - self.cursor.execute(query) - traitQTL = self.cursor.fetchone() - if traitQTL: - self.locus, self.lrs = traitQTL - else: - self.locus = self.lrs = "" - else: - raise KeyError, `self.name`+' information is not found in the database.' - - def genHTML(self, formName = "", dispFromDatabase=0, privilege="guest", userName="Guest", authorized_users=""): - if not self.haveinfo: - self.retrieveInfo() - - if self.db.type == 'Publish': - PubMedLink = "" - if self.pubmed_id: - PubMedLink = HT.Href(text="PubMed %d : " % self.pubmed_id, - target = "_blank", url = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id) - else: - PubMedLink = HT.Span("Unpublished : ", Class="fs15") - - if formName: - setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" % - (formName, self.db.name, self.name), Class = "fs14") - else: - setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" % - (self.db.name,self.name), Class = "fs14") - - if self.confidential and not webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=privilege, userName=userName, authorized_users=authorized_users): - setDescription2.append('RecordID/%s - %s' % (self.name, self.pre_publication_description)) - else: - setDescription2.append('RecordID/%s - %s' % (self.name, self.post_publication_description)) - - #XZ 03/26/2011: Xiaodong comment out the following two lins as Rob asked. Need to check with Rob why in PublishXRef table, there are few row whose Sequence > 1. - #if self.sequence > 1: - # setDescription2.append(' btach %d' % self.sequence) - if self.authors: - a1 = string.split(self.authors,',')[0] - while a1[0] == '"' or a1[0] == "'" : - a1 = a1[1:] - setDescription2.append(' by ') - setDescription2.append(HT.Italic('%s, and colleagues' % a1)) - setDescription = HT.Span(PubMedLink, setDescription2) - - elif self.db.type == 'Temp': - setDescription = HT.Href(text="%s" % (self.description),url="javascript:showDatabase2\ - ('%s','%s','')" % (self.db.name,self.name), Class = "fs14") - setDescription = HT.Span(setDescription) - - elif self.db.type == 'Geno': # Genome DB only available for single search - if formName: - setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ - '%2.3f' % self.mb),url="javascript:showDatabase3('%s','%s','%s','')" % \ - (formName, self.db.name, self.name), Class = "fs14") - else: - setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ - '%2.3f' % self.mb),url="javascript:showDatabase2('%s','%s','')" % \ - (self.db.name,self.name), Class = "fs14") - - setDescription = HT.Span(setDescription) - - else: - if self.cellid: - if formName: - setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name, self.cellid),url=\ - "javascript:showDatabase3('%s','%s','%s','%s')" % (formName, self.db.name,self.name,self.cellid), \ - Class = "fs14") - else: - setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name,self.cellid),url=\ - "javascript:showDatabase2('%s','%s','%s')" % (self.db.name,self.name,self.cellid), \ - Class = "fs14") - else: - if formName: - setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase3('%s','%s','%s','')" % (formName, self.db.name,self.name), \ - Class = "fs14") - else: - setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase2('%s','%s','')" % (self.db.name,self.name), \ - Class = "fs14") - if self.symbol and self.chr and self.mb: - setDescription.append(' [') - setDescription.append(HT.Italic('%s' % self.symbol,Class="cdg fwb")) - setDescription.append(' on Chr %s @ %s Mb]' % (self.chr,self.mb)) - if self.description: - setDescription.append(': %s' % self.description) - if self.probe_target_description: - setDescription.append('; %s' % self.probe_target_description) - setDescription = HT.Span(setDescription) - - if self.db.type != 'Temp' and dispFromDatabase: - setDescription.append( ' --- FROM : ') - setDescription.append(self.db.genHTML(Class='cori')) - return setDescription + """ + Trait class defines a trait in webqtl, can be either Microarray, + Published phenotype, genotype, or user input trait + + """ + + def __init__(self, cursor = None, **kw): + print("in webqtlTrait") + self.cursor = cursor + self.db = None # database object + self.name = '' # Trait ID, ProbeSet ID, Published ID, etc. + self.cellid = '' + self.identification = 'un-named trait' + self.riset = '' + self.haveinfo = 0 + self.sequence = '' # Blat sequence, available for ProbeSet + self.data = {} + print("foo") + print("kw in webqtlTrait are:", pf(kw)) + print("printed\n\n") + for name, value in kw.items(): + if self.__dict__.has_key(name): + setattr(self, name, value) + elif name == 'fullname': + name2 = value.split("::") + if len(name2) == 2: + self.db, self.name = name2 + elif len(name2) == 3: + self.db, self.name, self.cellid = name2 + else: + raise KeyError, repr(value) + ' parameter format error.' + else: + raise KeyError, repr(name) + ' not a valid parameter for this class.' + + if self.db and isinstance(self.db, basestring): + assert self.cursor, "Don't have a cursor" + self.db = webqtlDataset(self.db, self.cursor) + + #if self.db == None, not from a database + print("self.db is:", self.db, type(self.db)) + if self.db: + if self.db.type == "Temp": + self.cursor.execute(''' + SELECT + InbredSet.Name + FROM + InbredSet, Temp + WHERE + Temp.InbredSetId = InbredSet.Id AND + Temp.Name = "%s" + ''', self.name) + self.riset = self.cursor.fetchone()[0] + else: + self.riset = self.db.getRISet() + + # + # In ProbeSet, there are maybe several annotations match one sequence + # so we need use sequence(BlatSeq) as the identification, when we update + # one annotation, we update the others who match the sequence also. + # + # Hongqiang Li, 3/3/2008 + # + + #XZ, 05/08/2009: This block is not neccessary. We can add 'BlatSeq' into disfield. + # The variable self.sequence should be changed to self.BlatSeq + # It also should be changed in other places where it are used. + + if self.db: + if self.db.type == 'ProbeSet': + print("Doing ProbeSet Query") + query = ''' + SELECT + ProbeSet.BlatSeq + FROM + ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE + ProbeSet.Id=ProbeSetXRef.ProbeSetId and + ProbeSetFreeze.Id = ProbeSetXRef.ProbeSetFreezeId and + ProbeSet.Name = %s and + ProbeSetFreeze.Name = %s + ''', (self.name, self.db.name) + print("query is:", query) + self.cursor.execute(*query) + self.sequence = self.cursor.fetchone()[0] + print("self.sequence is:", self.sequence) + + + def getName(self): + str = "" + if self.db and self.name: + str = "%s::%s" % (self.db, self.name) + if self.cellid: + str += "::" + self.cellid + else: + str = self.description + return str + + # + # when user enter a trait or GN generate a trait, user want show the name + # not the name that generated by GN randomly, the two follow function are + # used to give the real name and the database. displayName() will show the + # database also, getGivenName() just show the name. + # For other trait, displayName() as same as getName(), getGivenName() as + # same as self.name + # + # Hongqiang 11/29/07 + # + def getGivenName(self): + str = self.name + if self.db and self.name: + if self.db.type=='Temp': + self.cursor.execute('SELECT description FROM Temp WHERE Name=%s', self.name) + desc = self.cursor.fetchone()[0] + if desc.__contains__('PCA'): + desc = desc[desc.rindex(':')+1:].strip() + else: + desc = desc[:desc.index('entered')].strip() + str = desc + return str + + def displayName(self): + str = "" + if self.db and self.name: + if self.db.type=='Temp': + desc = self.description + if desc.__contains__('PCA'): + desc = desc[desc.rindex(':')+1:].strip() + else: + desc = desc[:desc.index('entered')].strip() + str = "%s::%s" % (self.db, desc) + else: + str = "%s::%s" % (self.db, self.name) + if self.cellid: + str += "::" + self.cellid + else: + str = self.description + + return str + + + #def __str__(self): + # #return "%s %s" % (self.getName(), self.riset) + # return self.getName() + __str__ = getName + __repr__ = __str__ + + def exportData(self, strainlist, type="val"): + """ + export data according to strainlist + mostly used in calculating correlation + """ + result = [] + for strain in strainlist: + if self.data.has_key(strain): + if type=='val': + result.append(self.data[strain].val) + elif type=='var': + result.append(self.data[strain].var) + elif type=='N': + result.append(self.data[strain].N) + else: + raise KeyError, `type`+' type is incorrect.' + else: + result.append(None) + return result + + def exportInformative(self, incVar=0): + """ + export informative strain + mostly used in qtl regression + """ + strains = [] + vals = [] + vars = [] + for strain, value in self.data.items(): + if value.val != None: + if not incVar or value.var != None: + strains.append(strain) + vals.append(value.val) + vars.append(value.var) + return strains, vals, vars + + + # + # In ProbeSet, there are maybe several annotations match one sequence + # so we need use sequence(BlatSeq) as the identification, when we update + # one annotation, we update the others who match the sequence also. + # + # Hongqiang Li, 3/3/2008 + # + def getSequence(self): + assert self.cursor + if self.db.type == 'ProbeSet': + self.cursor.execute(''' + SELECT + ProbeSet.BlatSeq + FROM + ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE + ProbeSet.Id=ProbeSetXRef.ProbeSetId and + ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and + ProbeSet.Name = %s + ProbeSetFreeze.Name = %s + ''', self.name, self.db.name) + #self.cursor.execute(query) + results = self.fetchone() + + return results[0] + + + + def retrieveData(self, strainlist=[]): + assert self.db and self.cursor + + if self.db.type == 'Temp': + query = ''' + SELECT + Strain.Name, TempData.value, TempData.SE, TempData.NStrain, TempData.Id + FROM + TempData, Temp, Strain + WHERE + TempData.StrainId = Strain.Id AND + TempData.Id = Temp.DataId AND + Temp.name = '%s' + Order BY + Strain.Name + ''' % self.name + #XZ, 03/02/2009: Xiaodong changed Data to PublishData, SE to PublishSE + elif self.db.type == 'Publish': + query = ''' + SELECT + Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id + FROM + (PublishData, Strain, PublishXRef, PublishFreeze) + left join PublishSE on + (PublishSE.DataId = PublishData.Id AND PublishSE.StrainId = PublishData.StrainId) + left join NStrain on + (NStrain.DataId = PublishData.Id AND + NStrain.StrainId = PublishData.StrainId) + WHERE + PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishData.Id = PublishXRef.DataId AND PublishXRef.Id = %s AND + PublishFreeze.Id = %d AND PublishData.StrainId = Strain.Id + Order BY + Strain.Name + ''' % (self.name, self.db.id) + + #XZ, 03/02/2009: Xiaodong changed Data to ProbeData, SE to ProbeSE + elif self.cellid: + #Probe Data + query = ''' + SELECT + Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id + FROM + (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef, + Strain, Probe, ProbeSet) + left join ProbeSE on + (ProbeSE.DataId = ProbeData.Id AND ProbeSE.StrainId = ProbeData.StrainId) + WHERE + Probe.Name = '%s' AND ProbeSet.Name = '%s' AND + Probe.ProbeSetId = ProbeSet.Id AND + ProbeXRef.ProbeId = Probe.Id AND + ProbeXRef.ProbeFreezeId = ProbeFreeze.Id AND + ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeXRef.DataId = ProbeData.Id AND + ProbeData.StrainId = Strain.Id + Order BY + Strain.Name + ''' % (self.cellid, self.name, self.db.name) + #XZ, 03/02/2009: Xiaodong added this block for ProbeSetData and ProbeSetSE + elif self.db.type == 'ProbeSet': + #ProbeSet Data + query = ''' + SELECT + Strain.Name, ProbeSetData.value, ProbeSetSE.error, ProbeSetData.Id + FROM + (ProbeSetData, ProbeSetFreeze, Strain, ProbeSet, ProbeSetXRef) + left join ProbeSetSE on + (ProbeSetSE.DataId = ProbeSetData.Id AND ProbeSetSE.StrainId = ProbeSetData.StrainId) + WHERE + ProbeSet.Name = '%s' AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeSetXRef.DataId = ProbeSetData.Id AND + ProbeSetData.StrainId = Strain.Id + Order BY + Strain.Name + ''' % (self.name, self.db.name) + #XZ, 03/02/2009: Xiaodong changeded Data to GenoData, SE to GenoSE + else: + #Geno Data + #XZ: The SpeciesId is not necessary, but it's nice to keep it to speed up database search. + query = ''' + SELECT + Strain.Name, GenoData.value, GenoSE.error, GenoData.Id + FROM + (GenoData, GenoFreeze, Strain, Geno, GenoXRef) + left join GenoSE on + (GenoSE.DataId = GenoData.Id AND GenoSE.StrainId = GenoData.StrainId) + WHERE + Geno.SpeciesId = %s AND Geno.Name = '%s' AND GenoXRef.GenoId = Geno.Id AND + GenoXRef.GenoFreezeId = GenoFreeze.Id AND + GenoFreeze.Name = '%s' AND + GenoXRef.DataId = GenoData.Id AND + GenoData.StrainId = Strain.Id + Order BY + Strain.Name + ''' % (webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.db.riset), self.name, self.db.name) + + + self.cursor.execute(query) + results = self.cursor.fetchall() + self.data.clear() + if results: + self.mysqlid = results[0][-1] + if strainlist: + for item in results: + if item[0] in strainlist: + val = item[1] + if val != None: + var = item[2] + ndata = None + if self.db.type in ('Publish', 'Temp'): + ndata = item[3] + self.data[item[0]] = webqtlCaseData(val, var, ndata) + #end for + else: + for item in results: + val = item[1] + if val != None: + var = item[2] + ndata = None + if self.db.type in ('Publish', 'Temp'): + ndata = item[3] + self.data[item[0]] = webqtlCaseData(val, var, ndata) + #end for + #end if + else: + pass + + def keys(self): + return self.__dict__.keys() + + def has_key(self, key): + return self.__dict__.has_key(key) + + def items(self): + return self.__dict__.items() + + def retrieveInfo(self, QTL = None): + assert self.db and self.cursor + if self.db.type == 'Publish': + #self.db.DisField = ['Name','PubMed_ID','Phenotype','Abbreviation','Authors','Title',\ + # 'Abstract', 'Journal','Volume','Pages','Month','Year','Sequence',\ + # 'Units', 'comments'] + query = ''' + SELECT + PublishXRef.Id, Publication.PubMed_ID, + Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description, + Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation, + Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users, + Publication.Authors, Publication.Title, Publication.Abstract, + Publication.Journal, Publication.Volume, Publication.Pages, + Publication.Month, Publication.Year, PublishXRef.Sequence, + Phenotype.Units, PublishXRef.comments + FROM + PublishXRef, Publication, Phenotype, PublishFreeze + WHERE + PublishXRef.Id = %s AND + Phenotype.Id = PublishXRef.PhenotypeId AND + Publication.Id = PublishXRef.PublicationId AND + PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishFreeze.Id =%s + ''' % (self.name, self.db.id) + #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name + #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. + elif self.db.type == 'ProbeSet': + disfieldString = string.join(self.db.disfield,',ProbeSet.') + disfieldString = 'ProbeSet.' + disfieldString + query = """ + SELECT %s + FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE + ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeSet.Name = '%s' + """ % (disfieldString, self.db.name, self.name) + #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name + # to avoid the problem of same marker name from different species. + elif self.db.type == 'Geno': + disfieldString = string.join(self.db.disfield,',Geno.') + disfieldString = 'Geno.' + disfieldString + query = """ + SELECT %s + FROM Geno, GenoFreeze, GenoXRef + WHERE + GenoXRef.GenoFreezeId = GenoFreeze.Id AND + GenoXRef.GenoId = Geno.Id AND + GenoFreeze.Name = '%s' AND + Geno.Name = '%s' + """ % (disfieldString, self.db.name, self.name) + else: #Temp type + query = 'SELECT %s FROM %s WHERE Name = "%s"' % \ + (string.join(self.db.disfield,','), self.db.type, self.name) + + + self.cursor.execute(query) + traitInfo = self.cursor.fetchone() + if traitInfo: + self.haveinfo = 1 + + #XZ: assign SQL query result to trait attributes. + for i, field in enumerate(self.db.disfield): + setattr(self, field, traitInfo[i]) + + if self.db.type == 'Publish': + self.confidential = 0 + if self.pre_publication_description and not self.pubmed_id: + self.confidential = 1 + + self.homologeneid = None + if self.db.type == 'ProbeSet' and self.riset and self.geneid: + #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. + #XZ: So I have to test if geneid is number before execute the query. + #XZ: The geneid values in database should be cleaned up. + try: + junk = float(self.geneid) + geneidIsNumber = 1 + except: + geneidIsNumber = 0 + + if geneidIsNumber: + query = """ + SELECT + HomologeneId + FROM + Homologene, Species, InbredSet + WHERE + Homologene.GeneId =%s AND + InbredSet.Name = '%s' AND + InbredSet.SpeciesId = Species.Id AND + Species.TaxonomyId = Homologene.TaxonomyId + """ % (self.geneid, self.riset) + self.cursor.execute(query) + result = self.cursor.fetchone() + else: + result = None + + if result: + self.homologeneid = result[0] + + if QTL: + if self.db.type == 'ProbeSet' and not self.cellid: + query = ''' + SELECT + ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean + FROM + ProbeSetXRef, ProbeSet + WHERE + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSet.Name = "%s" AND + ProbeSetXRef.ProbeSetFreezeId =%s + ''' % (self.name, self.db.id) + self.cursor.execute(query) + traitQTL = self.cursor.fetchone() + if traitQTL: + self.locus, self.lrs, self.pvalue, self.mean = traitQTL + else: + self.locus = self.lrs = self.pvalue = self.mean = "" + if self.db.type == 'Publish': + query = ''' + SELECT + PublishXRef.Locus, PublishXRef.LRS + FROM + PublishXRef, PublishFreeze + WHERE + PublishXRef.Id = %s AND + PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishFreeze.Id =%s + ''' % (self.name, self.db.id) + self.cursor.execute(query) + traitQTL = self.cursor.fetchone() + if traitQTL: + self.locus, self.lrs = traitQTL + else: + self.locus = self.lrs = "" + else: + raise KeyError, `self.name`+' information is not found in the database.' + + def genHTML(self, formName = "", dispFromDatabase=0, privilege="guest", userName="Guest", authorized_users=""): + if not self.haveinfo: + self.retrieveInfo() + + if self.db.type == 'Publish': + PubMedLink = "" + if self.pubmed_id: + PubMedLink = HT.Href(text="PubMed %d : " % self.pubmed_id, + target = "_blank", url = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id) + else: + PubMedLink = HT.Span("Unpublished : ", Class="fs15") + + if formName: + setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" % + (formName, self.db.name, self.name), Class = "fs14") + else: + setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" % + (self.db.name,self.name), Class = "fs14") + + if self.confidential and not webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=privilege, userName=userName, authorized_users=authorized_users): + setDescription2.append('RecordID/%s - %s' % (self.name, self.pre_publication_description)) + else: + setDescription2.append('RecordID/%s - %s' % (self.name, self.post_publication_description)) + + #XZ 03/26/2011: Xiaodong comment out the following two lins as Rob asked. Need to check with Rob why in PublishXRef table, there are few row whose Sequence > 1. + #if self.sequence > 1: + # setDescription2.append(' btach %d' % self.sequence) + if self.authors: + a1 = string.split(self.authors,',')[0] + while a1[0] == '"' or a1[0] == "'" : + a1 = a1[1:] + setDescription2.append(' by ') + setDescription2.append(HT.Italic('%s, and colleagues' % a1)) + setDescription = HT.Span(PubMedLink, setDescription2) + + elif self.db.type == 'Temp': + setDescription = HT.Href(text="%s" % (self.description),url="javascript:showDatabase2\ + ('%s','%s','')" % (self.db.name,self.name), Class = "fs14") + setDescription = HT.Span(setDescription) + + elif self.db.type == 'Geno': # Genome DB only available for single search + if formName: + setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ + '%2.3f' % self.mb),url="javascript:showDatabase3('%s','%s','%s','')" % \ + (formName, self.db.name, self.name), Class = "fs14") + else: + setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ + '%2.3f' % self.mb),url="javascript:showDatabase2('%s','%s','')" % \ + (self.db.name,self.name), Class = "fs14") + + setDescription = HT.Span(setDescription) + + else: + if self.cellid: + if formName: + setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name, self.cellid),url=\ + "javascript:showDatabase3('%s','%s','%s','%s')" % (formName, self.db.name,self.name,self.cellid), \ + Class = "fs14") + else: + setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name,self.cellid),url=\ + "javascript:showDatabase2('%s','%s','%s')" % (self.db.name,self.name,self.cellid), \ + Class = "fs14") + else: + if formName: + setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ + "javascript:showDatabase3('%s','%s','%s','')" % (formName, self.db.name,self.name), \ + Class = "fs14") + else: + setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ + "javascript:showDatabase2('%s','%s','')" % (self.db.name,self.name), \ + Class = "fs14") + if self.symbol and self.chr and self.mb: + setDescription.append(' [') + setDescription.append(HT.Italic('%s' % self.symbol,Class="cdg fwb")) + setDescription.append(' on Chr %s @ %s Mb]' % (self.chr,self.mb)) + if self.description: + setDescription.append(': %s' % self.description) + if self.probe_target_description: + setDescription.append('; %s' % self.probe_target_description) + setDescription = HT.Span(setDescription) + + if self.db.type != 'Temp' and dispFromDatabase: + setDescription.append( ' --- FROM : ') + setDescription.append(self.db.genHTML(Class='cori')) + return setDescription diff --git a/wqflask/basicStatistics/BasicStatisticsFunctions.py b/wqflask/basicStatistics/BasicStatisticsFunctions.py index 5cbbb145..285addae 100755 --- a/wqflask/basicStatistics/BasicStatisticsFunctions.py +++ b/wqflask/basicStatistics/BasicStatisticsFunctions.py @@ -13,162 +13,162 @@ from dbFunction import webqtlDatabaseFunction def basicStatsTable(vals, trait_type=None, cellid=None, heritability=None): - 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 - - 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")) - - #XZ, 04/01/2009: don't try to get H2 value for probe. - if cellid: - pass - else: - 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 - # Lei Yan - # 2008/12/19 - - return tbl + 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 + + 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")) + + #XZ, 04/01/2009: don't try to get H2 value for probe. + if cellid: + pass + else: + 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 + # Lei Yan + # 2008/12/19 + + return tbl def plotNormalProbability(vals=None, RISet='', title=None, showstrains=0, specialStrains=[None], size=(750,500)): - dataXZ = vals[:] - dataXZ.sort(webqtlUtil.cmpOrder) - dataLabel = [] - dataX = map(lambda X: X[1], dataXZ) + dataXZ = vals[:] + dataXZ.sort(webqtlUtil.cmpOrder) + dataLabel = [] + dataX = map(lambda X: X[1], dataXZ) - showLabel = showstrains - if len(dataXZ) > 50: - showLabel = 0 - for item in dataXZ: - strainName = webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=item[0]) - dataLabel.append(strainName) + showLabel = showstrains + if len(dataXZ) > 50: + showLabel = 0 + for item in dataXZ: + strainName = webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=item[0]) + dataLabel.append(strainName) - dataY=Plot.U(len(dataX)) - dataZ=map(Plot.inverseCumul,dataY) - c = pid.PILCanvas(size=(750,500)) - Plot.plotXY(c, dataZ, dataX, dataLabel = dataLabel, XLabel='Expected Z score', connectdot=0, YLabel='Trait value', title=title, specialCases=specialStrains, showLabel = showLabel) + dataY=Plot.U(len(dataX)) + dataZ=map(Plot.inverseCumul,dataY) + c = pid.PILCanvas(size=(750,500)) + Plot.plotXY(c, dataZ, dataX, dataLabel = dataLabel, XLabel='Expected Z score', connectdot=0, YLabel='Trait value', title=title, specialCases=specialStrains, showLabel = showLabel) - filename= webqtlUtil.genRandStr("nP_") - c.save(webqtlConfig.IMGDIR+filename, format='gif') + filename= webqtlUtil.genRandStr("nP_") + c.save(webqtlConfig.IMGDIR+filename, format='gif') - img=HT.Image('/image/'+filename+'.gif',border=0) + img=HT.Image('/image/'+filename+'.gif',border=0) - return img + return img def plotBoxPlot(vals): - valsOnly = [] - dataXZ = vals[:] - for i in range(len(dataXZ)): - valsOnly.append(dataXZ[i][1]) + valsOnly = [] + dataXZ = vals[:] + for i in range(len(dataXZ)): + valsOnly.append(dataXZ[i][1]) - plotHeight = 320 - plotWidth = 220 - xLeftOffset = 60 - xRightOffset = 40 - yTopOffset = 40 - yBottomOffset = 60 + plotHeight = 320 + plotWidth = 220 + xLeftOffset = 60 + xRightOffset = 40 + yTopOffset = 40 + yBottomOffset = 60 - canvasHeight = plotHeight + yTopOffset + yBottomOffset - canvasWidth = plotWidth + xLeftOffset + xRightOffset - canvas = pid.PILCanvas(size=(canvasWidth,canvasHeight)) - XXX = [('', valsOnly[:])] + canvasHeight = plotHeight + yTopOffset + yBottomOffset + canvasWidth = plotWidth + xLeftOffset + xRightOffset + canvas = pid.PILCanvas(size=(canvasWidth,canvasHeight)) + XXX = [('', valsOnly[:])] - Plot.plotBoxPlot(canvas, XXX, offset=(xLeftOffset, xRightOffset, yTopOffset, yBottomOffset), XLabel= "Trait") - filename= webqtlUtil.genRandStr("Box_") - canvas.save(webqtlConfig.IMGDIR+filename, format='gif') - img=HT.Image('/image/'+filename+'.gif',border=0) + Plot.plotBoxPlot(canvas, XXX, offset=(xLeftOffset, xRightOffset, yTopOffset, yBottomOffset), XLabel= "Trait") + filename= webqtlUtil.genRandStr("Box_") + canvas.save(webqtlConfig.IMGDIR+filename, format='gif') + img=HT.Image('/image/'+filename+'.gif',border=0) - plotLink = HT.Span("More about ", HT.Href(text="Box Plots", url="http://davidmlane.com/hyperstat/A37797.html", target="_blank", Class="fs13")) + plotLink = HT.Span("More about ", HT.Href(text="Box Plots", url="http://davidmlane.com/hyperstat/A37797.html", target="_blank", Class="fs13")) - return img, plotLink + return img, plotLink def plotBarGraph(identification='', RISet='', vals=None, type="name"): - this_identification = "unnamed trait" - if identification: - this_identification = identification - - if type=="rank": - dataXZ = vals[:] - dataXZ.sort(webqtlUtil.cmpOrder) - title='%s' % this_identification - else: - dataXZ = vals[:] - title='%s' % this_identification - - tvals = [] - tnames = [] - tvars = [] - for i in range(len(dataXZ)): - tvals.append(dataXZ[i][1]) - tnames.append(webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=dataXZ[i][0])) - tvars.append(dataXZ[i][2]) - nnStrain = len(tnames) - - sLabel = 1 - - ###determine bar width and space width - if nnStrain < 20: - sw = 4 - elif nnStrain < 40: - sw = 3 - else: - sw = 2 - - ### 700 is the default plot width minus Xoffsets for 40 strains - defaultWidth = 650 - if nnStrain > 40: - defaultWidth += (nnStrain-40)*10 - defaultOffset = 100 - bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) - if bw < 10: - bw = 10 - - plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset - plotHeight = 500 - #print [plotWidth, plotHeight, bw, sw, nnStrain] - c = pid.PILCanvas(size=(plotWidth,plotHeight)) - Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title=title, sLabel = sLabel, barSpace = sw) - - filename= webqtlUtil.genRandStr("Bar_") - c.save(webqtlConfig.IMGDIR+filename, format='gif') - img=HT.Image('/image/'+filename+'.gif',border=0) - - return img + this_identification = "unnamed trait" + if identification: + this_identification = identification + + if type=="rank": + dataXZ = vals[:] + dataXZ.sort(webqtlUtil.cmpOrder) + title='%s' % this_identification + else: + dataXZ = vals[:] + title='%s' % this_identification + + tvals = [] + tnames = [] + tvars = [] + for i in range(len(dataXZ)): + tvals.append(dataXZ[i][1]) + tnames.append(webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=dataXZ[i][0])) + tvars.append(dataXZ[i][2]) + nnStrain = len(tnames) + + sLabel = 1 + + ###determine bar width and space width + if nnStrain < 20: + sw = 4 + elif nnStrain < 40: + sw = 3 + else: + sw = 2 + + ### 700 is the default plot width minus Xoffsets for 40 strains + defaultWidth = 650 + if nnStrain > 40: + defaultWidth += (nnStrain-40)*10 + defaultOffset = 100 + bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) + if bw < 10: + bw = 10 + + plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset + plotHeight = 500 + #print [plotWidth, plotHeight, bw, sw, nnStrain] + c = pid.PILCanvas(size=(plotWidth,plotHeight)) + Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title=title, sLabel = sLabel, barSpace = sw) + + filename= webqtlUtil.genRandStr("Bar_") + c.save(webqtlConfig.IMGDIR+filename, format='gif') + img=HT.Image('/image/'+filename+'.gif',border=0) + + return img diff --git a/wqflask/basicStatistics/BasicStatisticsPage_alpha.py b/wqflask/basicStatistics/BasicStatisticsPage_alpha.py index 4ba9d54a..365143db 100755 --- a/wqflask/basicStatistics/BasicStatisticsPage_alpha.py +++ b/wqflask/basicStatistics/BasicStatisticsPage_alpha.py @@ -43,306 +43,302 @@ from dbFunction import webqtlDatabaseFunction class BasicStatisticsPage_alpha(templatePage): - plotMinInformative = 4 - - def __init__(self, fd): - - templatePage.__init__(self, fd) - - if not fd.genotype: - fd.readGenotype() - strainlist2 = fd.strainlist - - if fd.allstrainlist: - strainlist2 = fd.allstrainlist - - fd.readData(strainlist2) - - specialStrains = [] - setStrains = [] - for item in strainlist2: - if item not in fd.strainlist and item.find('F1') < 0: - specialStrains.append(item) - else: - setStrains.append(item) - specialStrains.sort() - #So called MDP Panel - if specialStrains: - specialStrains = fd.f1list+fd.parlist+specialStrains - - self.plotType = fd.formdata.getvalue('ptype', '0') - plotStrains = strainlist2 - if specialStrains: - if self.plotType == '1': - plotStrains = setStrains - if self.plotType == '2': - plotStrains = specialStrains - - self.dict['title'] = 'Basic Statistics' - if not self.openMysql(): - return - - self.showstrains = 1 - self.identification = "unnamed trait" - - self.fullname = fd.formdata.getvalue('fullname', '') - if self.fullname: - self.Trait = webqtlTrait(fullname=self.fullname, cursor=self.cursor) - self.Trait.retrieveInfo() - else: - self.Trait = None - - if fd.identification: - self.identification = fd.identification - self.dict['title'] = self.identification + ' / '+self.dict['title'] - TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') - - ##should not display Variance, but cannot convert Variance to SE - #print plotStrains, fd.allTraitData.keys() - if len(fd.allTraitData) > 0: - vals=[] - InformData = [] - for _strain in plotStrains: - if fd.allTraitData.has_key(_strain): - _val, _var = fd.allTraitData[_strain].val, fd.allTraitData[_strain].var - if _val != None: - vals.append([_strain, _val, _var]) - InformData.append(_val) - - if len(vals) >= self.plotMinInformative: - supertable2 = HT.TableLite(border=0, cellspacing=0, cellpadding=5,width="800") - - staIntro1 = HT.Paragraph("The table and plots below list the basic statistical analysis result of trait",HT.Strong(" %s" % self.identification)) - - ##### - #anova - ##### - traitmean, traitmedian, traitvar, traitstdev, traitsem, N = reaper.anova(InformData) - TDStatis = HT.TD(width="360", valign="top") - tbl2 = HT.TableLite(cellpadding=5, cellspacing=0, Class="collap") - dataXZ = vals[:] - dataXZ.sort(self.cmpValue) - tbl2.append(HT.TR(HT.TD("Statistic",align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 200), - HT.TD("Value", align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 140))) - tbl2.append(HT.TR(HT.TD("N of Cases",align="center", Class="fs13 b1 cbw c222"), - HT.TD(N,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("Mean",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.3f" % traitmean,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("Median",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.3f" % traitmedian,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - #tbl2.append(HT.TR(HT.TD("Variance",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - # HT.TD("%2.3f" % traitvar,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("SEM",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.3f" % traitsem,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("SD",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.3f" % traitstdev,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("Minimum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%s" % dataXZ[0][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD("Maximum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%s" % dataXZ[-1][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - if self.Trait and self.Trait.db.type == 'ProbeSet': - #IRQuest = HT.Href(text="Interquartile Range", url=webqtlConfig.glossaryfile +"#Interquartile",target="_blank", Class="fs14") - #IRQuest.append(HT.BR()) - #IRQuest.append(" (fold difference)") - tbl2.append(HT.TR(HT.TD("Range (log2)",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.3f" % (dataXZ[-1][1]-dataXZ[0][1]),nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD(HT.Span("Range (fold)"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"), - HT.TD("%2.2f" % pow(2.0,(dataXZ[-1][1]-dataXZ[0][1])), nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - tbl2.append(HT.TR(HT.TD(HT.Span("Quartile Range",HT.BR()," (fold difference)"),align="center", 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",align="center", Class="fs13 b1 cbw c222"))) - - # (Lei Yan) - # 2008/12/19 - self.Trait.retrieveData() - #XZ, 04/01/2009: don't try to get H2 value for probe. - if self.Trait.cellid: - pass - else: - self.cursor.execute("SELECT DataId, h2 from ProbeSetXRef WHERE DataId = %d" % self.Trait.mysqlid) - dataid, heritability = self.cursor.fetchone() - if heritability: - tbl2.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: - tbl2.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("NaN", nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) - - # Lei Yan - # 2008/12/19 - - TDStatis.append(tbl2) - - plotHeight = 220 - plotWidth = 120 - xLeftOffset = 60 - xRightOffset = 25 - yTopOffset = 20 - yBottomOffset = 53 - - canvasHeight = plotHeight + yTopOffset + yBottomOffset - canvasWidth = plotWidth + xLeftOffset + xRightOffset - canvas = pid.PILCanvas(size=(canvasWidth,canvasHeight)) - XXX = [('', InformData[:])] - - Plot.plotBoxPlot(canvas, XXX, offset=(xLeftOffset, xRightOffset, yTopOffset, yBottomOffset), XLabel= "Trait") - filename= webqtlUtil.genRandStr("Box_") - canvas.save(webqtlConfig.IMGDIR+filename, format='gif') - img=HT.Image('/image/'+filename+'.gif',border=0) - - #supertable2.append(HT.TR(HT.TD(staIntro1, colspan=3 ))) - tb = HT.TableLite(border=0, cellspacing=0, cellpadding=0) - tb.append(HT.TR(HT.TD(img, align="left", style="border: 1px solid #999999; padding:0px;"))) - supertable2.append(HT.TR(TDStatis, HT.TD(tb))) - - dataXZ = vals[:] - tvals = [] - tnames = [] - tvars = [] - for i in range(len(dataXZ)): - tvals.append(dataXZ[i][1]) - tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) - tvars.append(dataXZ[i][2]) - nnStrain = len(tnames) - - sLabel = 1 - - ###determine bar width and space width - if nnStrain < 20: - sw = 4 - elif nnStrain < 40: - sw = 3 - else: - sw = 2 - - ### 700 is the default plot width minus Xoffsets for 40 strains - defaultWidth = 650 - if nnStrain > 40: - defaultWidth += (nnStrain-40)*10 - defaultOffset = 100 - bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) - if bw < 10: - bw = 10 - - plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset - plotHeight = 500 - #print [plotWidth, plotHeight, bw, sw, nnStrain] - c = pid.PILCanvas(size=(plotWidth,plotHeight)) - Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (sorted by name)' % self.identification, sLabel = sLabel, barSpace = sw) - - filename= webqtlUtil.genRandStr("Bar_") - c.save(webqtlConfig.IMGDIR+filename, format='gif') - img0=HT.Image('/image/'+filename+'.gif',border=0) - - dataXZ = vals[:] - dataXZ.sort(self.cmpValue) - tvals = [] - tnames = [] - tvars = [] - for i in range(len(dataXZ)): - tvals.append(dataXZ[i][1]) - tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) - tvars.append(dataXZ[i][2]) - - c = pid.PILCanvas(size=(plotWidth,plotHeight)) - Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (ranked)' % self.identification, sLabel = sLabel, barSpace = sw) - - filename= webqtlUtil.genRandStr("Bar_") - c.save(webqtlConfig.IMGDIR+filename, format='gif') - img1=HT.Image('/image/'+filename+'.gif',border=0) - - # Lei Yan - # 05/18/2009 - # report - - title = HT.Paragraph('REPORT on the variation of Shh (or PCA Composite Trait XXXX) (sonic hedgehog) in the (insert Data set name) of (insert Species informal name, e.g., Mouse, Rat, Human, Barley, Arabidopsis)', Class="title") - header = HT.Paragraph('''This report was generated by GeneNetwork on May 11, 2009, at 11.20 AM using the Basic Statistics module (v 1.0) and data from the Hippocampus Consortium M430v2 (Jun06) PDNN data set. For more details and updates on this data set please link to URL:get Basic Statistics''') - hr = HT.HR() - p1 = HT.Paragraph('''Trait values for Shh were taken from the (insert Database name, Hippocampus Consortium M430v2 (Jun06) PDNN). GeneNetwork contains data for NN (e.g., 99) cases. In general, data are averages for each case. A summary of mean, median, and the range of these data are provided in Table 1 and in the box plot (Figure 1). Data for individual cases are provided in Figure 2A and 2B, often with error bars (SEM). ''') - p2 = HT.Paragraph('''Trait values for Shh range 5.1-fold: from a low of 8.2 (please round value) in 129S1/SvImJ to a high of 10.6 (please round value) in BXD9. The interquartile range (the difference between values closest to the 25% and 75% levels) is a more modest 1.8-fold. The mean value is XX. ''') - t1 = HT.Paragraph('''Table 1. Summary of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''') - f1 = HT.Paragraph('''Figure 1. ''') - f1.append(HT.Href(text="Box plot", url="http://davidmlane.com/hyperstat/A37797.html", target="_blank", Class="fs14")) - f1.append(HT.Text(''' of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''')) - f2A = HT.Paragraph('''Figure 2A: Bar chart of Shh data ordered by case from the Hippocampus Consortium M430v2 (june06) PDNN data set''') - f2B = HT.Paragraph('''Figure 2B: Bar chart of Shh values ordered by from the Hippocampus Consortium M430v2 (june06) PDNN data set''') - TD_LR.append(HT.Blockquote(title, HT.P(), header, hr, p1, HT.P(), p2, HT.P(), supertable2, t1, f1, HT.P(), img0, f2A, HT.P(), img1, f2B)) - self.dict['body'] = str(TD_LR) - else: - heading = "Basic Statistics" - detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] - self.error(heading=heading,detail=detail) - return - else: - heading = "Basic Statistics" - detail = ['Empty data set, please check your data.'] - self.error(heading=heading,detail=detail) - return - - def traitInfo(self, fd, specialStrains = None): - species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) - heading2 = HT.Paragraph(HT.Strong('Population: '), "%s %s" % (species.title(), fd.RISet) , HT.BR()) - if self.Trait: - trait_url = HT.Href(text=self.Trait.name, url = os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + \ - "?FormID=showDatabase&incparentsf1=1&database=%s&ProbeSetID=%s" % (self.Trait.db.name, self.Trait.name), \ - target='_blank', Class="fs13 fwn") - heading2.append(HT.Strong("Database: "), - HT.Href(text=self.Trait.db.fullname, url = webqtlConfig.INFOPAGEHREF % self.Trait.db.name , - target='_blank',Class="fs13 fwn"),HT.BR()) - if self.Trait.db.type == 'ProbeSet': - heading2.append(HT.Strong('Trait ID: '), trait_url, HT.BR(), - HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.symbol,id="green"),HT.BR()) - if self.Trait.chr and self.Trait.mb: - heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb)) - elif self.Trait.db.type == 'Geno': - heading2.append(HT.Strong('Locus : '), trait_url, HT.BR()) - #heading2.append(HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.Symbol,id="green"),HT.BR()) - if self.Trait.chr and self.Trait.mb: - heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb)) - elif self.Trait.db.type == 'Publish': - heading2.append(HT.Strong('Record ID: '), trait_url, HT.BR()) - heading2.append(HT.Strong('Phenotype: '), self.Trait.phenotype, HT.BR()) - heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR()) - elif self.Trait.db.type == 'Temp': - heading2.append(HT.Strong('Description: '), self.Trait.description, HT.BR()) - #heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR()) - else: - pass - else: - heading2.append(HT.Strong("Trait Name: "), fd.identification) - - if specialStrains: - mdpform = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='MDP_Form',submit=HT.Input(type='hidden')) - mdphddn = {'FormID':'dataEditing', 'submitID':'basicStatistics','RISet':fd.RISet, "allstrainlist":string.join(fd.allstrainlist, " "), "ptype":self.plotType, 'identification':fd.identification, "incparentsf1":1} - if self.fullname: mdphddn['fullname'] = self.fullname - webqtlUtil.exportData(mdphddn, fd.allTraitData) - for key in mdphddn.keys(): - mdpform.append(HT.Input(name=key, value=mdphddn[key], type='hidden')) - btn0 = HT.Input(type='button' ,name='',value='All Cases',onClick="this.form.ptype.value=0;submit();", Class="button") - btn1 = HT.Input(type='button' ,name='',value='%s Only' % fd.RISet,onClick="this.form.ptype.value=1;submit();", Class="button") - btn2 = HT.Input(type='button' ,name='',value='MDP Only', onClick="this.form.ptype.value=2;submit();", Class="button") - mdpform.append(btn0) - mdpform.append(btn1) - mdpform.append(btn2) - heading2.append(HT.P(), mdpform) - - return HT.Span(heading2) - - def calSD(self,var): - try: - return sqrt(abs(var)) - except: - return None - - - def cmpValue(self,A,B): - try: - if A[1] < B[1]: - return -1 - elif A[1] == B[1]: - return 0 - else: - return 1 - except: - return 0 - - - - + plotMinInformative = 4 + + def __init__(self, fd): + + templatePage.__init__(self, fd) + + if not fd.genotype: + fd.readGenotype() + strainlist2 = fd.strainlist + + if fd.allstrainlist: + strainlist2 = fd.allstrainlist + + fd.readData(strainlist2) + + specialStrains = [] + setStrains = [] + for item in strainlist2: + if item not in fd.strainlist and item.find('F1') < 0: + specialStrains.append(item) + else: + setStrains.append(item) + specialStrains.sort() + #So called MDP Panel + if specialStrains: + specialStrains = fd.f1list+fd.parlist+specialStrains + + self.plotType = fd.formdata.getvalue('ptype', '0') + plotStrains = strainlist2 + if specialStrains: + if self.plotType == '1': + plotStrains = setStrains + if self.plotType == '2': + plotStrains = specialStrains + + self.dict['title'] = 'Basic Statistics' + if not self.openMysql(): + return + + self.showstrains = 1 + self.identification = "unnamed trait" + + self.fullname = fd.formdata.getvalue('fullname', '') + if self.fullname: + self.Trait = webqtlTrait(fullname=self.fullname, cursor=self.cursor) + self.Trait.retrieveInfo() + else: + self.Trait = None + + if fd.identification: + self.identification = fd.identification + self.dict['title'] = self.identification + ' / '+self.dict['title'] + TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') + + ##should not display Variance, but cannot convert Variance to SE + #print plotStrains, fd.allTraitData.keys() + if len(fd.allTraitData) > 0: + vals=[] + InformData = [] + for _strain in plotStrains: + if fd.allTraitData.has_key(_strain): + _val, _var = fd.allTraitData[_strain].val, fd.allTraitData[_strain].var + if _val != None: + vals.append([_strain, _val, _var]) + InformData.append(_val) + + if len(vals) >= self.plotMinInformative: + supertable2 = HT.TableLite(border=0, cellspacing=0, cellpadding=5,width="800") + + staIntro1 = HT.Paragraph("The table and plots below list the basic statistical analysis result of trait",HT.Strong(" %s" % self.identification)) + + ##### + #anova + ##### + traitmean, traitmedian, traitvar, traitstdev, traitsem, N = reaper.anova(InformData) + TDStatis = HT.TD(width="360", valign="top") + tbl2 = HT.TableLite(cellpadding=5, cellspacing=0, Class="collap") + dataXZ = vals[:] + dataXZ.sort(self.cmpValue) + tbl2.append(HT.TR(HT.TD("Statistic",align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 200), + HT.TD("Value", align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 140))) + tbl2.append(HT.TR(HT.TD("N of Cases",align="center", Class="fs13 b1 cbw c222"), + HT.TD(N,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("Mean",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.3f" % traitmean,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("Median",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.3f" % traitmedian,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + #tbl2.append(HT.TR(HT.TD("Variance",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + # HT.TD("%2.3f" % traitvar,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("SEM",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.3f" % traitsem,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("SD",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.3f" % traitstdev,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("Minimum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%s" % dataXZ[0][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD("Maximum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%s" % dataXZ[-1][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + if self.Trait and self.Trait.db.type == 'ProbeSet': + #IRQuest = HT.Href(text="Interquartile Range", url=webqtlConfig.glossaryfile +"#Interquartile",target="_blank", Class="fs14") + #IRQuest.append(HT.BR()) + #IRQuest.append(" (fold difference)") + tbl2.append(HT.TR(HT.TD("Range (log2)",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.3f" % (dataXZ[-1][1]-dataXZ[0][1]),nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD(HT.Span("Range (fold)"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"), + HT.TD("%2.2f" % pow(2.0,(dataXZ[-1][1]-dataXZ[0][1])), nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + tbl2.append(HT.TR(HT.TD(HT.Span("Quartile Range",HT.BR()," (fold difference)"),align="center", 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",align="center", Class="fs13 b1 cbw c222"))) + + # (Lei Yan) + # 2008/12/19 + self.Trait.retrieveData() + #XZ, 04/01/2009: don't try to get H2 value for probe. + if self.Trait.cellid: + pass + else: + self.cursor.execute("SELECT DataId, h2 from ProbeSetXRef WHERE DataId = %d" % self.Trait.mysqlid) + dataid, heritability = self.cursor.fetchone() + if heritability: + tbl2.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: + tbl2.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("NaN", nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) + + # Lei Yan + # 2008/12/19 + + TDStatis.append(tbl2) + + plotHeight = 220 + plotWidth = 120 + xLeftOffset = 60 + xRightOffset = 25 + yTopOffset = 20 + yBottomOffset = 53 + + canvasHeight = plotHeight + yTopOffset + yBottomOffset + canvasWidth = plotWidth + xLeftOffset + xRightOffset + canvas = pid.PILCanvas(size=(canvasWidth,canvasHeight)) + XXX = [('', InformData[:])] + + Plot.plotBoxPlot(canvas, XXX, offset=(xLeftOffset, xRightOffset, yTopOffset, yBottomOffset), XLabel= "Trait") + filename= webqtlUtil.genRandStr("Box_") + canvas.save(webqtlConfig.IMGDIR+filename, format='gif') + img=HT.Image('/image/'+filename+'.gif',border=0) + + #supertable2.append(HT.TR(HT.TD(staIntro1, colspan=3 ))) + tb = HT.TableLite(border=0, cellspacing=0, cellpadding=0) + tb.append(HT.TR(HT.TD(img, align="left", style="border: 1px solid #999999; padding:0px;"))) + supertable2.append(HT.TR(TDStatis, HT.TD(tb))) + + dataXZ = vals[:] + tvals = [] + tnames = [] + tvars = [] + for i in range(len(dataXZ)): + tvals.append(dataXZ[i][1]) + tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) + tvars.append(dataXZ[i][2]) + nnStrain = len(tnames) + + sLabel = 1 + + ###determine bar width and space width + if nnStrain < 20: + sw = 4 + elif nnStrain < 40: + sw = 3 + else: + sw = 2 + + ### 700 is the default plot width minus Xoffsets for 40 strains + defaultWidth = 650 + if nnStrain > 40: + defaultWidth += (nnStrain-40)*10 + defaultOffset = 100 + bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) + if bw < 10: + bw = 10 + + plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset + plotHeight = 500 + #print [plotWidth, plotHeight, bw, sw, nnStrain] + c = pid.PILCanvas(size=(plotWidth,plotHeight)) + Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (sorted by name)' % self.identification, sLabel = sLabel, barSpace = sw) + + filename= webqtlUtil.genRandStr("Bar_") + c.save(webqtlConfig.IMGDIR+filename, format='gif') + img0=HT.Image('/image/'+filename+'.gif',border=0) + + dataXZ = vals[:] + dataXZ.sort(self.cmpValue) + tvals = [] + tnames = [] + tvars = [] + for i in range(len(dataXZ)): + tvals.append(dataXZ[i][1]) + tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) + tvars.append(dataXZ[i][2]) + + c = pid.PILCanvas(size=(plotWidth,plotHeight)) + Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (ranked)' % self.identification, sLabel = sLabel, barSpace = sw) + + filename= webqtlUtil.genRandStr("Bar_") + c.save(webqtlConfig.IMGDIR+filename, format='gif') + img1=HT.Image('/image/'+filename+'.gif',border=0) + + # Lei Yan + # 05/18/2009 + # report + + title = HT.Paragraph('REPORT on the variation of Shh (or PCA Composite Trait XXXX) (sonic hedgehog) in the (insert Data set name) of (insert Species informal name, e.g., Mouse, Rat, Human, Barley, Arabidopsis)', Class="title") + header = HT.Paragraph('''This report was generated by GeneNetwork on May 11, 2009, at 11.20 AM using the Basic Statistics module (v 1.0) and data from the Hippocampus Consortium M430v2 (Jun06) PDNN data set. For more details and updates on this data set please link to URL:get Basic Statistics''') + hr = HT.HR() + p1 = HT.Paragraph('''Trait values for Shh were taken from the (insert Database name, Hippocampus Consortium M430v2 (Jun06) PDNN). GeneNetwork contains data for NN (e.g., 99) cases. In general, data are averages for each case. A summary of mean, median, and the range of these data are provided in Table 1 and in the box plot (Figure 1). Data for individual cases are provided in Figure 2A and 2B, often with error bars (SEM). ''') + p2 = HT.Paragraph('''Trait values for Shh range 5.1-fold: from a low of 8.2 (please round value) in 129S1/SvImJ to a high of 10.6 (please round value) in BXD9. The interquartile range (the difference between values closest to the 25% and 75% levels) is a more modest 1.8-fold. The mean value is XX. ''') + t1 = HT.Paragraph('''Table 1. Summary of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''') + f1 = HT.Paragraph('''Figure 1. ''') + f1.append(HT.Href(text="Box plot", url="http://davidmlane.com/hyperstat/A37797.html", target="_blank", Class="fs14")) + f1.append(HT.Text(''' of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''')) + f2A = HT.Paragraph('''Figure 2A: Bar chart of Shh data ordered by case from the Hippocampus Consortium M430v2 (june06) PDNN data set''') + f2B = HT.Paragraph('''Figure 2B: Bar chart of Shh values ordered by from the Hippocampus Consortium M430v2 (june06) PDNN data set''') + TD_LR.append(HT.Blockquote(title, HT.P(), header, hr, p1, HT.P(), p2, HT.P(), supertable2, t1, f1, HT.P(), img0, f2A, HT.P(), img1, f2B)) + self.dict['body'] = str(TD_LR) + else: + heading = "Basic Statistics" + detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] + self.error(heading=heading,detail=detail) + return + else: + heading = "Basic Statistics" + detail = ['Empty data set, please check your data.'] + self.error(heading=heading,detail=detail) + return + + def traitInfo(self, fd, specialStrains = None): + species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) + heading2 = HT.Paragraph(HT.Strong('Population: '), "%s %s" % (species.title(), fd.RISet) , HT.BR()) + if self.Trait: + trait_url = HT.Href(text=self.Trait.name, url = os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + \ + "?FormID=showDatabase&incparentsf1=1&database=%s&ProbeSetID=%s" % (self.Trait.db.name, self.Trait.name), \ + target='_blank', Class="fs13 fwn") + heading2.append(HT.Strong("Database: "), + HT.Href(text=self.Trait.db.fullname, url = webqtlConfig.INFOPAGEHREF % self.Trait.db.name , + target='_blank',Class="fs13 fwn"),HT.BR()) + if self.Trait.db.type == 'ProbeSet': + heading2.append(HT.Strong('Trait ID: '), trait_url, HT.BR(), + HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.symbol,id="green"),HT.BR()) + if self.Trait.chr and self.Trait.mb: + heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb)) + elif self.Trait.db.type == 'Geno': + heading2.append(HT.Strong('Locus : '), trait_url, HT.BR()) + #heading2.append(HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.Symbol,id="green"),HT.BR()) + if self.Trait.chr and self.Trait.mb: + heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb)) + elif self.Trait.db.type == 'Publish': + heading2.append(HT.Strong('Record ID: '), trait_url, HT.BR()) + heading2.append(HT.Strong('Phenotype: '), self.Trait.phenotype, HT.BR()) + heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR()) + elif self.Trait.db.type == 'Temp': + heading2.append(HT.Strong('Description: '), self.Trait.description, HT.BR()) + #heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR()) + else: + pass + else: + heading2.append(HT.Strong("Trait Name: "), fd.identification) + + if specialStrains: + mdpform = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='MDP_Form',submit=HT.Input(type='hidden')) + mdphddn = {'FormID':'dataEditing', 'submitID':'basicStatistics','RISet':fd.RISet, "allstrainlist":string.join(fd.allstrainlist, " "), "ptype":self.plotType, 'identification':fd.identification, "incparentsf1":1} + if self.fullname: mdphddn['fullname'] = self.fullname + webqtlUtil.exportData(mdphddn, fd.allTraitData) + for key in mdphddn.keys(): + mdpform.append(HT.Input(name=key, value=mdphddn[key], type='hidden')) + btn0 = HT.Input(type='button' ,name='',value='All Cases',onClick="this.form.ptype.value=0;submit();", Class="button") + btn1 = HT.Input(type='button' ,name='',value='%s Only' % fd.RISet,onClick="this.form.ptype.value=1;submit();", Class="button") + btn2 = HT.Input(type='button' ,name='',value='MDP Only', onClick="this.form.ptype.value=2;submit();", Class="button") + mdpform.append(btn0) + mdpform.append(btn1) + mdpform.append(btn2) + heading2.append(HT.P(), mdpform) + + return HT.Span(heading2) + + def calSD(self,var): + try: + return sqrt(abs(var)) + except: + return None + + + def cmpValue(self,A,B): + try: + if A[1] < B[1]: + return -1 + elif A[1] == B[1]: + return 0 + else: + return 1 + except: + return 0 diff --git a/wqflask/basicStatistics/updatedBasicStatisticsPage.py b/wqflask/basicStatistics/updatedBasicStatisticsPage.py index ab7ed07d..3f30619d 100755 --- a/wqflask/basicStatistics/updatedBasicStatisticsPage.py +++ b/wqflask/basicStatistics/updatedBasicStatisticsPage.py @@ -6,145 +6,145 @@ import BasicStatisticsFunctions #Window generated from the Trait Data and Analysis page (DataEditingPage.py) with updated stats figures; takes the page's values that can bed edited by the user class updatedBasicStatisticsPage(templatePage): - - plotMinInformative = 4 - - def __init__(self, fd): - - templatePage.__init__(self, fd) - - if not fd.genotype: - fd.readGenotype() - this_strainlist = fd.strainlist - - if fd.allstrainlist: - this_strainlist = fd.allstrainlist - - fd.readData(this_strainlist) - - specialStrains = [] #This appears to be the "other/non-RISet strainlist" without parents/f1 strains; not sure what to name it - setStrains = [] - for item in this_strainlist: - if item not in fd.strainlist and item.find('F1') < 0: - specialStrains.append(item) - else: - continue - - specialStrains.sort() - if specialStrains: - specialStrains = fd.f1list+fd.parlist+specialStrains - - self.dict['title'] = 'Basic Statistics' - TD_LR = HT.TD(valign="top",width="100%",bgcolor="#fafafa") - - stats_row = HT.TR() - stats_cell = HT.TD() - stats_script = HT.Script(language="Javascript") - - #Get strain names, values, and variances - strain_names = fd.formdata.getvalue('strainNames').split(',') - strain_vals = fd.formdata.getvalue('strainVals').split(',') - strain_vars = fd.formdata.getvalue('strainVars').split(',') - - vals = [] - if (len(strain_names) > 0): - if (len(strain_names) > 3): - #Need to create "vals" object - for i in range(len(strain_names)): - try: - this_strain_val = float(strain_vals[i]) - except: - continue - try: - this_strain_var = float(strain_vars[i]) - except: - this_strain_var = None - - thisValFull = [strain_names[i], this_strain_val, this_strain_var] - vals.append(thisValFull) - - stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-2", Class="stats_tab"), - HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), - HT.Href(text="Box Plot", url="#statstabs-5", Class="stats_tab")] - stats_tabs = HT.List(stats_tab_list) - - stats_container = HT.Div(id="stats_tabs", Class="ui-tabs") - stats_container.append(stats_tabs) - - stats_script_text = """$(function() { $("#stats_tabs").tabs();});""" #Javascript enabling tabs - - table_div = HT.Div(id="statstabs-1", style="height:320px;width:740px;overflow:scroll;") - table_container = HT.Paragraph() - - statsTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - this_trait_type = fd.formdata.getvalue('trait_type', None) - this_cellid = fd.formdata.getvalue('cellid', None) - statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=this_trait_type, cellid=this_cellid) - statsTable.append(HT.TR(HT.TD(statsTableCell))) - - table_container.append(statsTable) - table_div.append(table_container) - stats_container.append(table_div) - - normalplot_div = HT.Div(id="statstabs-2", style="height:540px;width:740px;overflow:scroll;") - normalplot_container = HT.Paragraph() - normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - plotTitle = fd.formdata.getvalue("normalPlotTitle","") - normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, RISet=fd.RISet, title=plotTitle, specialStrains=specialStrains) - normalplot.append(HT.TR(HT.TD(normalplot_img))) - normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ - normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), - "More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", - target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) - normalplot_container.append(normalplot) - normalplot_div.append(normalplot_container) - stats_container.append(normalplot_div) - - barName_div = HT.Div(id="statstabs-3", style="height:540px;width:740px;overflow:scroll;") - barName_container = HT.Paragraph() - barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="name") - barName.append(HT.TR(HT.TD(barName_img))) - barName_container.append(barName) - barName_div.append(barName_container) - stats_container.append(barName_div) - - barRank_div = HT.Div(id="statstabs-4", style="height:540px;width:740px;overflow:scroll;") - barRank_container = HT.Paragraph() - barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="rank") - barRank.append(HT.TR(HT.TD(barRank_img))) - barRank_container.append(barRank) - barRank_div.append(barRank_container) - stats_container.append(barRank_div) - - boxplot_div = HT.Div(id="statstabs-5", style="height:540px;width:740px;overflow:scroll;") - boxplot_container = HT.Paragraph() - boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) - boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) - boxplot_container.append(boxplot) - boxplot_div.append(boxplot_container) - stats_container.append(boxplot_div) - - stats_cell.append(stats_container) - stats_script.append(stats_script_text) - - submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - stats_row.append(stats_cell) - - submitTable.append(stats_row) - submitTable.append(stats_script) - - TD_LR.append(submitTable) - self.dict['body'] = str(TD_LR) - else: - heading = "Basic Statistics" - detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] - self.error(heading=heading,detail=detail) - return - else: - heading = "Basic Statistics" - detail = ['Empty data set, please check your data.'] - self.error(heading=heading,detail=detail) - return \ No newline at end of file + + plotMinInformative = 4 + + def __init__(self, fd): + + templatePage.__init__(self, fd) + + if not fd.genotype: + fd.readGenotype() + this_strainlist = fd.strainlist + + if fd.allstrainlist: + this_strainlist = fd.allstrainlist + + fd.readData(this_strainlist) + + specialStrains = [] #This appears to be the "other/non-RISet strainlist" without parents/f1 strains; not sure what to name it + setStrains = [] + for item in this_strainlist: + if item not in fd.strainlist and item.find('F1') < 0: + specialStrains.append(item) + else: + continue + + specialStrains.sort() + if specialStrains: + specialStrains = fd.f1list+fd.parlist+specialStrains + + self.dict['title'] = 'Basic Statistics' + TD_LR = HT.TD(valign="top",width="100%",bgcolor="#fafafa") + + stats_row = HT.TR() + stats_cell = HT.TD() + stats_script = HT.Script(language="Javascript") + + #Get strain names, values, and variances + strain_names = fd.formdata.getvalue('strainNames').split(',') + strain_vals = fd.formdata.getvalue('strainVals').split(',') + strain_vars = fd.formdata.getvalue('strainVars').split(',') + + vals = [] + if (len(strain_names) > 0): + if (len(strain_names) > 3): + #Need to create "vals" object + for i in range(len(strain_names)): + try: + this_strain_val = float(strain_vals[i]) + except: + continue + try: + this_strain_var = float(strain_vars[i]) + except: + this_strain_var = None + + thisValFull = [strain_names[i], this_strain_val, this_strain_var] + vals.append(thisValFull) + + stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-2", Class="stats_tab"), + HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), + HT.Href(text="Box Plot", url="#statstabs-5", Class="stats_tab")] + stats_tabs = HT.List(stats_tab_list) + + stats_container = HT.Div(id="stats_tabs", Class="ui-tabs") + stats_container.append(stats_tabs) + + stats_script_text = """$(function() { $("#stats_tabs").tabs();});""" #Javascript enabling tabs + + table_div = HT.Div(id="statstabs-1", style="height:320px;width:740px;overflow:scroll;") + table_container = HT.Paragraph() + + statsTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + this_trait_type = fd.formdata.getvalue('trait_type', None) + this_cellid = fd.formdata.getvalue('cellid', None) + statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=this_trait_type, cellid=this_cellid) + statsTable.append(HT.TR(HT.TD(statsTableCell))) + + table_container.append(statsTable) + table_div.append(table_container) + stats_container.append(table_div) + + normalplot_div = HT.Div(id="statstabs-2", style="height:540px;width:740px;overflow:scroll;") + normalplot_container = HT.Paragraph() + normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + plotTitle = fd.formdata.getvalue("normalPlotTitle","") + normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, RISet=fd.RISet, title=plotTitle, specialStrains=specialStrains) + normalplot.append(HT.TR(HT.TD(normalplot_img))) + normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ + normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), + "More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", + target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) + normalplot_container.append(normalplot) + normalplot_div.append(normalplot_container) + stats_container.append(normalplot_div) + + barName_div = HT.Div(id="statstabs-3", style="height:540px;width:740px;overflow:scroll;") + barName_container = HT.Paragraph() + barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="name") + barName.append(HT.TR(HT.TD(barName_img))) + barName_container.append(barName) + barName_div.append(barName_container) + stats_container.append(barName_div) + + barRank_div = HT.Div(id="statstabs-4", style="height:540px;width:740px;overflow:scroll;") + barRank_container = HT.Paragraph() + barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="rank") + barRank.append(HT.TR(HT.TD(barRank_img))) + barRank_container.append(barRank) + barRank_div.append(barRank_container) + stats_container.append(barRank_div) + + boxplot_div = HT.Div(id="statstabs-5", style="height:540px;width:740px;overflow:scroll;") + boxplot_container = HT.Paragraph() + boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) + boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) + boxplot_container.append(boxplot) + boxplot_div.append(boxplot_container) + stats_container.append(boxplot_div) + + stats_cell.append(stats_container) + stats_script.append(stats_script_text) + + submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + stats_row.append(stats_cell) + + submitTable.append(stats_row) + submitTable.append(stats_script) + + TD_LR.append(submitTable) + self.dict['body'] = str(TD_LR) + else: + heading = "Basic Statistics" + detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] + self.error(heading=heading,detail=detail) + return + else: + heading = "Basic Statistics" + detail = ['Empty data set, please check your data.'] + self.error(heading=heading,detail=detail) + return diff --git a/wqflask/dbFunction/webqtlDatabaseFunction.py b/wqflask/dbFunction/webqtlDatabaseFunction.py index 772e0526..7e33da3f 100755 --- a/wqflask/dbFunction/webqtlDatabaseFunction.py +++ b/wqflask/dbFunction/webqtlDatabaseFunction.py @@ -26,7 +26,7 @@ #webqtlDatabaseFunction.py # -#This file consists of various database related functions; the names are generally self-explanatory. +#This file consists of various database related functions; the names are generally self-explanatory. import MySQLdb import string @@ -49,63 +49,63 @@ def getCursor(): ########################################################################### #input: cursor, groupName (string) #output: mappingMethodId (int) info, value will be Null or else -#function: retrieve mappingMethodId info from InbredSet table -########################################################################### +#function: retrieve mappingMethodId info from InbredSet table +########################################################################### def getMappingMethod(cursor=None, groupName=None): - cursor.execute("select MappingMethodId from InbredSet where Name= '%s'" % groupName) - mappingMethodId = cursor.fetchone()[0] - return mappingMethodId + cursor.execute("select MappingMethodId from InbredSet where Name= '%s'" % groupName) + mappingMethodId = cursor.fetchone()[0] + return mappingMethodId ########################################################################### #input: cursor, inbredSetId (int), strainId (int) -#output: isMappingId (bull) info, value will be 0,1,2 or else, 0 or Null means -# "can not do mapping", >0 means "can do mapping", >1 means "there exsists +#output: isMappingId (bull) info, value will be 0,1,2 or else, 0 or Null means +# "can not do mapping", >0 means "can do mapping", >1 means "there exsists # redundant data, user needs to choose one to do mapping function" -#function: retrieve isMappingId info from StrainXRef table -########################################################################### - -def isMapping(cursor=None, inbredSetId=None, strainId=None): - cursor.execute("select IsMapping from StrainXRef where InbredSetId='%d' and StrainId = '%d'" %(inbredSetId, strainId)) - isMappingId = cursor.fetchone()[0] - return isMappingId +#function: retrieve isMappingId info from StrainXRef table +########################################################################### + +def isMapping(cursor=None, inbredSetId=None, strainId=None): + cursor.execute("select IsMapping from StrainXRef where InbredSetId='%d' and StrainId = '%d'" %(inbredSetId, strainId)) + isMappingId = cursor.fetchone()[0] + return isMappingId ########################################################################### #input: cursor, groupName (string) #output: all species data info (array), value will be Null or else -#function: retrieve all species info from Species table -########################################################################### +#function: retrieve all species info from Species table +########################################################################### def getAllSpecies(cursor=None): - cursor.execute("select Id, Name, MenuName, FullName, TaxonomyId,OrderId from Species Order by OrderId") - allSpecies = cursor.fetchall() - return allSpecies + cursor.execute("select Id, Name, MenuName, FullName, TaxonomyId,OrderId from Species Order by OrderId") + allSpecies = cursor.fetchall() + return allSpecies ########################################################################### #input: cursor, RISet (string) #output: specie's name (string), value will be None or else -#function: retrieve specie's name info based on RISet -########################################################################### +#function: retrieve specie's name info based on RISet +########################################################################### def retrieveSpecies(cursor=None, RISet=None): - try: - cursor.execute("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % RISet) - return cursor.fetchone()[0] - except: - return None + try: + cursor.execute("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % RISet) + return cursor.fetchone()[0] + except: + return None ########################################################################### #input: cursor, RISet (string) #output: specie's Id (string), value will be None or else -#function: retrieve specie's Id info based on RISet -########################################################################### - +#function: retrieve specie's Id info based on RISet +########################################################################### + def retrieveSpeciesId(cursor=None, RISet=None): - try: - cursor.execute("select SpeciesId from InbredSet where Name = '%s'" % RISet) - return cursor.fetchone()[0] - except: - return None + try: + cursor.execute("select SpeciesId from InbredSet where Name = '%s'" % RISet) + return cursor.fetchone()[0] + except: + return None ########################################################################### # input: cursor @@ -118,24 +118,24 @@ def retrieveSpeciesId(cursor=None, RISet=None): ########################################################################### def getTissueDataSet(cursor=None): - tissProbeSetFreezeIdList=[] - nameList =[] - fullNameList = [] - - query = "select Id,Name,FullName from TissueProbeSetFreeze; " - try: - cursor.execute(query) - result = cursor.fetchall() - - for row in result: - tissProbeSetFreezeIdList.append(row[0]) - nameList.append(row[1]) - fullNameList.append(row[2]) - except: - return None - - return tissProbeSetFreezeIdList,nameList,fullNameList - + tissProbeSetFreezeIdList=[] + nameList =[] + fullNameList = [] + + query = "select Id,Name,FullName from TissueProbeSetFreeze; " + try: + cursor.execute(query) + result = cursor.fetchall() + + for row in result: + tissProbeSetFreezeIdList.append(row[0]) + nameList.append(row[1]) + fullNameList.append(row[2]) + except: + return None + + return tissProbeSetFreezeIdList,nameList,fullNameList + ########################################################################### # input: cursor,GeneSymbol (string), and TissueProbeSetFreezeId (string) # output: geneId (string), dataId (string) @@ -143,42 +143,42 @@ def getTissueDataSet(cursor=None): ########################################################################### def getGeneIdDataIdForTissueBySymbol(cursor=None, GeneSymbol=None, TissueProbeSetFreezeId= 0): - query ="select GeneId, DataId from TissueProbeSetXRef where Symbol = '%s' and TissueProbeSetFreezeId=%s order by Mean desc" %(GeneSymbol,TissueProbeSetFreezeId) - try: - cursor.execute(query) - result = cursor.fetchone() - geneId = result[0] - dataId = result[1] - except: - geneId = 0 - dataId = 0 - - return geneId,dataId + query ="select GeneId, DataId from TissueProbeSetXRef where Symbol = '%s' and TissueProbeSetFreezeId=%s order by Mean desc" %(GeneSymbol,TissueProbeSetFreezeId) + try: + cursor.execute(query) + result = cursor.fetchone() + geneId = result[0] + dataId = result[1] + except: + geneId = 0 + dataId = 0 + + return geneId,dataId ########################################################################### # input: cursor, TissueProbeSetFreezeId (int) # output: chipId (int) -# function: retrieve chipId from TissueProbeFreeze table +# function: retrieve chipId from TissueProbeFreeze table ########################################################################### def getChipIdByTissueProbeSetFreezeId(cursor=None, TissueProbeSetFreezeId=None): - query = "select TissueProbeFreezeId from TissueProbeSetFreeze where Id =%s" % TissueProbeSetFreezeId - try: - cursor.execute(query) - result = cursor.fetchone() - TissueProbeFreezeId = result[0] - except: - TissueProbeFreezeId =0 - - query1 = "select ChipId from TissueProbeFreeze where Id =%s" % TissueProbeFreezeId - try: - cursor.execute(query1) - result1 = cursor.fetchone() - chipId = result1[0] - except: - chipId =0 - - return chipId + query = "select TissueProbeFreezeId from TissueProbeSetFreeze where Id =%s" % TissueProbeSetFreezeId + try: + cursor.execute(query) + result = cursor.fetchone() + TissueProbeFreezeId = result[0] + except: + TissueProbeFreezeId =0 + + query1 = "select ChipId from TissueProbeFreeze where Id =%s" % TissueProbeFreezeId + try: + cursor.execute(query1) + result1 = cursor.fetchone() + chipId = result1[0] + except: + chipId =0 + + return chipId ########################################################################### # input: cursor, TissueProbeSetFreezeId (int) @@ -186,80 +186,79 @@ def getChipIdByTissueProbeSetFreezeId(cursor=None, TissueProbeSetFreezeId=None): # function: retrieve how many tissue used in the specific dataset based on TissueProbeSetFreezeId ########################################################################### def getTissueCountByTissueProbeSetFreezeId(cursor=None, TissueProbeSetFreezeId=None): - query1 ="select DataId from TissueProbeSetXRef where TissueProbeSetFreezeId =%s limit 1" % TissueProbeSetFreezeId - try: - cursor.execute(query1) - result1 = cursor.fetchone() - DataId = result1[0] - - query2 =" select count(*) from TissueProbeSetData where Id=%s" % DataId - try: - cursor.execute(query2) - result2 = cursor.fetchone() - TissueCount = result2[0] - except: - TissueCount =0 - except: - TissueCount =0 - - return TissueCount - + query1 ="select DataId from TissueProbeSetXRef where TissueProbeSetFreezeId =%s limit 1" % TissueProbeSetFreezeId + try: + cursor.execute(query1) + result1 = cursor.fetchone() + DataId = result1[0] + + query2 =" select count(*) from TissueProbeSetData where Id=%s" % DataId + try: + cursor.execute(query2) + result2 = cursor.fetchone() + TissueCount = result2[0] + except: + TissueCount =0 + except: + TissueCount =0 + + return TissueCount + ########################################################################### # input: cursor, TissueProbeSetFreezeId (int) # output: DatasetName(string),DatasetFullName(string) # function: retrieve DatasetName, DatasetFullName based on TissueProbeSetFreezeId ########################################################################### def getDatasetNamesByTissueProbeSetFreezeId(cursor=None, TissueProbeSetFreezeId=None): - query ="select Name, FullName from TissueProbeSetFreeze where Id=%s" % TissueProbeSetFreezeId - try: - cursor.execute(query) - result = cursor.fetchone() - DatasetName = result[0] - DatasetFullName =result[1] - except: - DatasetName =None - DatasetFullName =None - - return DatasetName, DatasetFullName - + query ="select Name, FullName from TissueProbeSetFreeze where Id=%s" % TissueProbeSetFreezeId + try: + cursor.execute(query) + result = cursor.fetchone() + DatasetName = result[0] + DatasetFullName =result[1] + except: + DatasetName =None + DatasetFullName =None + + return DatasetName, DatasetFullName + ########################################################################### # input: cursor, geneIdLst (list) # output: geneIdSymbolPair(dict),key is geneId, value is geneSymbol # function: retrieve GeneId, GeneSymbol based on geneId List -########################################################################### +########################################################################### def getGeneIdSymbolPairByGeneId(cursor=None, geneIdLst =None): - geneIdSymbolPair={} - for geneId in geneIdLst: - geneIdSymbolPair[geneId]=None - - query ="select GeneId,GeneSymbol from GeneList where GeneId in (%s)" % string.join(geneIdLst, ", ") - try: - cursor.execute(query) - results = cursor.fetchall() - for item in results: - geneId =item[0] - geneSymbol =item[1] - geneIdSymbolPair[geneId]=geneSymbol - except: - geneIdSymbolPair=None - - return geneIdSymbolPair - - + geneIdSymbolPair={} + for geneId in geneIdLst: + geneIdSymbolPair[geneId]=None + + query ="select GeneId,GeneSymbol from GeneList where GeneId in (%s)" % string.join(geneIdLst, ", ") + try: + cursor.execute(query) + results = cursor.fetchall() + for item in results: + geneId =item[0] + geneSymbol =item[1] + geneIdSymbolPair[geneId]=geneSymbol + except: + geneIdSymbolPair=None + + return geneIdSymbolPair + + def updateTissueProbesetXRefByProbesetId(cursor=None, probesetId=None): - query ="select Symbol,GeneId,Chr,Mb,description, Probe_Target_Description from ProbeSet where Id =%s"%probesetId - try: - cursor.execute(query) - result =cursor.fetchone() - - updateQuery =''' - Update TissueProbeSetXRef - Set Symbol='%s',GeneId='%s', Chr='%s', Mb='%s', description ='%s',Probe_Target_Description='%s' - where ProbesetId=%s - '''%(result[0],result[1],result[2],result[3],result[4],result[5],probesetId) - - cursor.execute(updateQuery) - - except: - return None - \ No newline at end of file + query ="select Symbol,GeneId,Chr,Mb,description, Probe_Target_Description from ProbeSet where Id =%s"%probesetId + try: + cursor.execute(query) + result =cursor.fetchone() + + updateQuery =''' + Update TissueProbeSetXRef + Set Symbol='%s',GeneId='%s', Chr='%s', Mb='%s', description ='%s',Probe_Target_Description='%s' + where ProbesetId=%s + '''%(result[0],result[1],result[2],result[3],result[4],result[5],probesetId) + + cursor.execute(updateQuery) + + except: + return None diff --git a/wqflask/utility/AJAX_table.py b/wqflask/utility/AJAX_table.py index 963a530e..083d1c0d 100755 --- a/wqflask/utility/AJAX_table.py +++ b/wqflask/utility/AJAX_table.py @@ -39,115 +39,115 @@ import webqtlUtil class AJAX_table: - def __init__(self, fd): - file = fd.formdata.getfirst("file", "") - sort = fd.formdata.getfirst("sort", "") - order = fd.formdata.getfirst("order", "up") - cmd = fd.formdata.getfirst("cmd", "") - tableID = fd.formdata.getfirst("tableID", "") - addIndex = fd.formdata.getfirst("addIndex", "1") - hiddenColumnsString = fd.formdata.getfirst("hiddenColumns", "") - hiddenColumns = hiddenColumnsString.split(',') - - try: - fp = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'rb') - tblobj = cPickle.load(fp) - fp.close() - - if cmd == 'addCorr': - dbId = int(fd.formdata.getfirst("db")) - dbFullName = fd.formdata.getfirst("dbname") - trait = fd.formdata.getfirst("trait") - form = fd.formdata.getfirst("form") - ids = fd.formdata.getfirst("ids") - vals = fd.formdata.getfirst("vals") - ids = eval(ids) - nnCorr = len(ids) - vals = eval(vals) - - workbook = xl.Writer('%s.xls' % (webqtlConfig.TMPDIR+file)) - worksheet = workbook.add_worksheet() - - con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) - cursor = con.cursor() - - cursor.execute("Select name, ShortName from ProbeSetFreeze where Id = %s", dbId) - dbName, dbShortName = cursor.fetchone() - - tblobj['header'][0].append( - THCell(HT.TD(dbShortName, Class="fs11 ffl b1 cw cbrb"), - text="%s" % dbShortName, idx=tblobj['header'][0][-1].idx + 1), - ) - - headingStyle = workbook.add_format(align = 'center', bold = 1, border = 1, size=13, fg_color = 0x1E, color="white") - for i, item in enumerate(tblobj['header'][0]): - if (i > 0): - worksheet.write([8, i-1], item.text, headingStyle) - worksheet.set_column([i-1, i-1], 2*len(item.text)) - - for i, row in enumerate(tblobj['body']): - ProbeSetId = row[1].text - #XZ, 03/02/2009: Xiaodong changed Data to ProbeSetData - cursor.execute(""" - Select ProbeSetData.StrainId, ProbeSetData.Value - From ProbeSetData, ProbeSetXRef, ProbeSet - where ProbeSetXRef.ProbeSetFreezeId = %d AND - ProbeSetXRef.DataId = ProbeSetData.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSet.Name = '%s' - """ % (dbId, ProbeSetId)) - results = cursor.fetchall() - vdict = {} - for item in results: - vdict[item[0]] = item[1] - newvals = [] - for id in ids: - if vdict.has_key(id): - newvals.append(vdict[id]) - else: - newvals.append(None) - corr,nOverlap= webqtlUtil.calCorrelation(newvals,vals,nnCorr) - repr = '%0.4f' % corr - row.append( - TDCell(HT.TD(HT.Href(text=repr, url="javascript:showCorrPlotThird('%s', '%s', '%s')" % (form, dbName, ProbeSetId), Class="fs11 fwn ffl"), " / ", nOverlap, Class="fs11 fwn ffl b1 c222", align="middle"),repr,abs(corr)) - ) - - last_row=0 - for j, item in enumerate(tblobj['body'][i]): - if (j > 0): - worksheet.write([9+i, j-1], item.text) - last_row = 9+i - last_row += 1 - - titleStyle = workbook.add_format(align = 'left', bold = 0, size=14, border = 1, border_color="gray") - ##Write title Info - # Modified by Hongqiang Li - worksheet.write([0, 0], "Citations: Please see %s/reference.html" % webqtlConfig.PORTADDR, titleStyle) - worksheet.write([1, 0], "Trait : %s" % trait, titleStyle) - worksheet.write([2, 0], "Database : %s" % dbFullName, titleStyle) - worksheet.write([3, 0], "Date : %s" % time.strftime("%B %d, %Y", time.gmtime()), titleStyle) - worksheet.write([4, 0], "Time : %s GMT" % time.strftime("%H:%M ", time.gmtime()), titleStyle) - worksheet.write([5, 0], "Status of data ownership: Possibly unpublished data; please see %s/statusandContact.html for details on sources, ownership, and usage of these data." % webqtlConfig.PORTADDR, titleStyle) - #Write footer info - worksheet.write([1 + last_row, 0], "Funding for The GeneNetwork: NIAAA (U01AA13499, U24AA13513), NIDA, NIMH, and NIAAA (P20-DA21131), NCI MMHCC (U01CA105417), and NCRR (U01NR 105417)", titleStyle) - worksheet.write([2 + last_row, 0], "PLEASE RETAIN DATA SOURCE INFORMATION WHENEVER POSSIBLE", titleStyle) - - cursor.close() - workbook.close() - - objfile = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'wb') - cPickle.dump(tblobj, objfile) - objfile.close() - else: - pass - - self.value = str(webqtlUtil.genTableObj(tblobj=tblobj, file=file, sortby=(sort, order), tableID = tableID, addIndex = addIndex, hiddenColumns = hiddenColumns)) - - except: - self.value = "The table is no longer available on this server" - - def __str__(self): - return self.value - - def write(self): - return str(self) + def __init__(self, fd): + file = fd.formdata.getfirst("file", "") + sort = fd.formdata.getfirst("sort", "") + order = fd.formdata.getfirst("order", "up") + cmd = fd.formdata.getfirst("cmd", "") + tableID = fd.formdata.getfirst("tableID", "") + addIndex = fd.formdata.getfirst("addIndex", "1") + hiddenColumnsString = fd.formdata.getfirst("hiddenColumns", "") + hiddenColumns = hiddenColumnsString.split(',') + + try: + fp = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'rb') + tblobj = cPickle.load(fp) + fp.close() + + if cmd == 'addCorr': + dbId = int(fd.formdata.getfirst("db")) + dbFullName = fd.formdata.getfirst("dbname") + trait = fd.formdata.getfirst("trait") + form = fd.formdata.getfirst("form") + ids = fd.formdata.getfirst("ids") + vals = fd.formdata.getfirst("vals") + ids = eval(ids) + nnCorr = len(ids) + vals = eval(vals) + + workbook = xl.Writer('%s.xls' % (webqtlConfig.TMPDIR+file)) + worksheet = workbook.add_worksheet() + + con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) + cursor = con.cursor() + + cursor.execute("Select name, ShortName from ProbeSetFreeze where Id = %s", dbId) + dbName, dbShortName = cursor.fetchone() + + tblobj['header'][0].append( + THCell(HT.TD(dbShortName, Class="fs11 ffl b1 cw cbrb"), + text="%s" % dbShortName, idx=tblobj['header'][0][-1].idx + 1), + ) + + headingStyle = workbook.add_format(align = 'center', bold = 1, border = 1, size=13, fg_color = 0x1E, color="white") + for i, item in enumerate(tblobj['header'][0]): + if (i > 0): + worksheet.write([8, i-1], item.text, headingStyle) + worksheet.set_column([i-1, i-1], 2*len(item.text)) + + for i, row in enumerate(tblobj['body']): + ProbeSetId = row[1].text + #XZ, 03/02/2009: Xiaodong changed Data to ProbeSetData + cursor.execute(""" + Select ProbeSetData.StrainId, ProbeSetData.Value + From ProbeSetData, ProbeSetXRef, ProbeSet + where ProbeSetXRef.ProbeSetFreezeId = %d AND + ProbeSetXRef.DataId = ProbeSetData.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSet.Name = '%s' + """ % (dbId, ProbeSetId)) + results = cursor.fetchall() + vdict = {} + for item in results: + vdict[item[0]] = item[1] + newvals = [] + for id in ids: + if vdict.has_key(id): + newvals.append(vdict[id]) + else: + newvals.append(None) + corr,nOverlap= webqtlUtil.calCorrelation(newvals,vals,nnCorr) + repr = '%0.4f' % corr + row.append( + TDCell(HT.TD(HT.Href(text=repr, url="javascript:showCorrPlotThird('%s', '%s', '%s')" % (form, dbName, ProbeSetId), Class="fs11 fwn ffl"), " / ", nOverlap, Class="fs11 fwn ffl b1 c222", align="middle"),repr,abs(corr)) + ) + + last_row=0 + for j, item in enumerate(tblobj['body'][i]): + if (j > 0): + worksheet.write([9+i, j-1], item.text) + last_row = 9+i + last_row += 1 + + titleStyle = workbook.add_format(align = 'left', bold = 0, size=14, border = 1, border_color="gray") + ##Write title Info + # Modified by Hongqiang Li + worksheet.write([0, 0], "Citations: Please see %s/reference.html" % webqtlConfig.PORTADDR, titleStyle) + worksheet.write([1, 0], "Trait : %s" % trait, titleStyle) + worksheet.write([2, 0], "Database : %s" % dbFullName, titleStyle) + worksheet.write([3, 0], "Date : %s" % time.strftime("%B %d, %Y", time.gmtime()), titleStyle) + worksheet.write([4, 0], "Time : %s GMT" % time.strftime("%H:%M ", time.gmtime()), titleStyle) + worksheet.write([5, 0], "Status of data ownership: Possibly unpublished data; please see %s/statusandContact.html for details on sources, ownership, and usage of these data." % webqtlConfig.PORTADDR, titleStyle) + #Write footer info + worksheet.write([1 + last_row, 0], "Funding for The GeneNetwork: NIAAA (U01AA13499, U24AA13513), NIDA, NIMH, and NIAAA (P20-DA21131), NCI MMHCC (U01CA105417), and NCRR (U01NR 105417)", titleStyle) + worksheet.write([2 + last_row, 0], "PLEASE RETAIN DATA SOURCE INFORMATION WHENEVER POSSIBLE", titleStyle) + + cursor.close() + workbook.close() + + objfile = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'wb') + cPickle.dump(tblobj, objfile) + objfile.close() + else: + pass + + self.value = str(webqtlUtil.genTableObj(tblobj=tblobj, file=file, sortby=(sort, order), tableID = tableID, addIndex = addIndex, hiddenColumns = hiddenColumns)) + + except: + self.value = "The table is no longer available on this server" + + def __str__(self): + return self.value + + def write(self): + return str(self) diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py index e00b8e9e..04fe85bf 100755 --- a/wqflask/utility/Plot.py +++ b/wqflask/utility/Plot.py @@ -39,1245 +39,1245 @@ from base import webqtlConfig def cformat(d, rank=0): - 'custom string format' - strD = "%2.6f" % d - - if rank == 0: - while strD[-1] in ('0','.'): - if strD[-1] == '0' and strD[-2] == '.' and len(strD) <= 4: - break - elif strD[-1] == '.': - strD = strD[:-1] - break - else: - strD = strD[:-1] - - else: - strD = strD.split(".")[0] - - if strD == '-0.0': - strD = '0.0' - return strD + 'custom string format' + strD = "%2.6f" % d + + if rank == 0: + while strD[-1] in ('0','.'): + if strD[-1] == '0' and strD[-2] == '.' and len(strD) <= 4: + break + elif strD[-1] == '.': + strD = strD[:-1] + break + else: + strD = strD[:-1] + + else: + strD = strD.split(".")[0] + + if strD == '-0.0': + strD = '0.0' + return strD def frange(start, end=None, inc=1.0): - "A faster range-like function that does accept float increments..." - if end == None: - end = start + 0.0 - start = 0.0 - else: - start += 0.0 # force it to be a float - count = int((end - start) / inc) - if start + count * inc != end: - # Need to adjust the count. AFAICT, it always comes up one short. - count += 1 - L = [start] * count - for i in xrange(1, count): - L[i] = start + i * inc - return L + "A faster range-like function that does accept float increments..." + if end == None: + end = start + 0.0 + start = 0.0 + else: + start += 0.0 # force it to be a float + count = int((end - start) / inc) + if start + count * inc != end: + # Need to adjust the count. AFAICT, it always comes up one short. + count += 1 + L = [start] * count + for i in xrange(1, count): + L[i] = start + i * inc + return L def gammln(xx): - cof=[76.18009173,-86.50532033,24.01409822,-1.231739516,0.120858003e-2,-0.536382e-5] - x=xx-1.0 - tmp=x+5.5 - tmp -=(x+0.5)*log(tmp) - ser=1.0 - for item in cof: - x+=1.0 - ser+=item/x + cof=[76.18009173,-86.50532033,24.01409822,-1.231739516,0.120858003e-2,-0.536382e-5] + x=xx-1.0 + tmp=x+5.5 + tmp -=(x+0.5)*log(tmp) + ser=1.0 + for item in cof: + x+=1.0 + ser+=item/x - return -tmp+log(2.50662827465*ser) + return -tmp+log(2.50662827465*ser) def gser(a,x): - gln=gammln(a) - ITMAX=100 - EPS=3.0e-7 - - if x<=0.0: - gamser=0.0 - return [gamser,gln] - else: - ap=a - sum=1.0/a - dele=sum - for i in range(1,ITMAX+1): - ap+=1.0 - dele*=x/ap - sum+=dele - if abs(dele)=0.0: - return ans - else: - return 2.0-ans + z=abs(x) + t=1.0/(1.0+0.5*z) + ans=t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+t*(-0.82215223+t*0.17087277))))))))) + if x>=0.0: + return ans + else: + return 2.0-ans def calMeanVar(data): - n=len(data) - if n<2: - return None - else: - sum=reduce(lambda x,y:x+y,data,0.0) - mean=sum/n - z=data[:] - for i in range(n): - z[i]=z[i]-mean - variance=reduce(lambda x,y:x+y*y,z,0.0) - variance /= n-1 - variance =sqrt(variance) - for i in range(n): - z[i]=z[i]/variance - return z + n=len(data) + if n<2: + return None + else: + sum=reduce(lambda x,y:x+y,data,0.0) + mean=sum/n + z=data[:] + for i in range(n): + z[i]=z[i]-mean + variance=reduce(lambda x,y:x+y*y,z,0.0) + variance /= n-1 + variance =sqrt(variance) + for i in range(n): + z[i]=z[i]/variance + return z def inverseCumul(p): - #Coefficients in rational approximations. - a = [-3.969683028665376e+01,2.209460984245205e+02,-2.759285104469687e+02,1.383577518672690e+02,-3.066479806614716e+01,2.506628277459239e+00] + #Coefficients in rational approximations. + a = [-3.969683028665376e+01,2.209460984245205e+02,-2.759285104469687e+02,1.383577518672690e+02,-3.066479806614716e+01,2.506628277459239e+00] - b = [-5.447609879822406e+01,1.615858368580409e+02,-1.556989798598866e+02,6.680131188771972e+01,-1.328068155288572e+01] + b = [-5.447609879822406e+01,1.615858368580409e+02,-1.556989798598866e+02,6.680131188771972e+01,-1.328068155288572e+01] - c = [-7.784894002430293e-03,-3.223964580411365e-01,-2.400758277161838e+00,-2.549732539343734e+00,4.374664141464968e+00,2.938163982698783e+00] + c = [-7.784894002430293e-03,-3.223964580411365e-01,-2.400758277161838e+00,-2.549732539343734e+00,4.374664141464968e+00,2.938163982698783e+00] - d = [7.784695709041462e-03,3.224671290700398e-01,2.445134137142996e+00,3.754408661907416e+00] + d = [7.784695709041462e-03,3.224671290700398e-01,2.445134137142996e+00,3.754408661907416e+00] - #Define break-points. + #Define break-points. - p_low = 0.02425 - p_high = 1 - p_low + p_low = 0.02425 + p_high = 1 - p_low - #Rational approximation for lower region. + #Rational approximation for lower region. - if p > 0 and p < p_low: - q = sqrt(-2*log(p)) - x = (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1) + if p > 0 and p < p_low: + q = sqrt(-2*log(p)) + x = (((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) / ((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1) - #Rational approximation for central region. + #Rational approximation for central region. - elif p>= p_low and p <= p_high: - q = p - 0.5 - r = q*q - x = (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q /(((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1) + elif p>= p_low and p <= p_high: + q = p - 0.5 + r = q*q + x = (((((a[0]*r+a[1])*r+a[2])*r+a[3])*r+a[4])*r+a[5])*q /(((((b[0]*r+b[1])*r+b[2])*r+b[3])*r+b[4])*r+1) - #Rational approximation for upper region. + #Rational approximation for upper region. - elif p>p_high and p < 1: - q = sqrt(-2*log(1-p)) - x = -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1) + elif p>p_high and p < 1: + q = sqrt(-2*log(1-p)) + x = -(((((c[0]*q+c[1])*q+c[2])*q+c[3])*q+c[4])*q+c[5]) /((((d[0]*q+d[1])*q+d[2])*q+d[3])*q+1) - else: - return None + else: + return None - if p>0 and p < 1: - e = 0.5 * erfcc(-x/sqrt(2)) - p - u = e * sqrt(2*pi) * exp(x*x/2) - x = x - u/(1 + x*u/2) - return x - else: - return None + if p>0 and p < 1: + e = 0.5 * erfcc(-x/sqrt(2)) - p + u = e * sqrt(2*pi) * exp(x*x/2) + x = x - u/(1 + x*u/2) + return x + else: + return None def gmean(lst): - N = len(lst) - if N == 0: - return 0 - else: - return (reduce(lambda x,y: x+y, lst, 0.0))/N + N = len(lst) + if N == 0: + return 0 + else: + return (reduce(lambda x,y: x+y, lst, 0.0))/N def gmedian(lst2): - lst = lst2[:] - N = len(lst) - if N == 0: - return 0 - else: - lst.sort() - if N % 2 == 0: - return (lst[N/2]+lst[(N-2)/2])/2.0 - else: - return lst[(N-1)/2] + lst = lst2[:] + N = len(lst) + if N == 0: + return 0 + else: + lst.sort() + if N % 2 == 0: + return (lst[N/2]+lst[(N-2)/2])/2.0 + else: + return lst[(N-1)/2] def gpercentile(lst2, np): - lst = lst2[:] - N = len(lst) - if N == 0 or np > 100 or np < 0: - return None - else: - lst.sort() - pNadd1 = (np/100.0)*N - k = int(pNadd1) - d = pNadd1 - k - if k == 0: - return lst[0] - elif k >= N-1: - return lst[N-1] - else: - return lst[k-1] + d*(lst[k] - lst[k-1]) + lst = lst2[:] + N = len(lst) + if N == 0 or np > 100 or np < 0: + return None + else: + lst.sort() + pNadd1 = (np/100.0)*N + k = int(pNadd1) + d = pNadd1 - k + if k == 0: + return lst[0] + elif k >= N-1: + return lst[N-1] + else: + return lst[k-1] + d*(lst[k] - lst[k-1]) def findOutliers(vals): - valsOnly = [] - dataXZ = vals[:] - for i in range(len(dataXZ)): - valsOnly.append(dataXZ[i][1]) - - data = [('', valsOnly[:])] - - for item in data: - itemvalue = item[1] - nValue = len(itemvalue) - catValue = [] - - for item2 in itemvalue: - try: - tstrain, tvalue = item2 - except: - tvalue = item2 - if nValue <= 4: - continue - else: - catValue.append(tvalue) - - if catValue != []: - lowHinge = gpercentile(catValue, 25) - upHinge = gpercentile(catValue, 75) - Hstep = 1.5*(upHinge - lowHinge) - - outlier = [] - extreme = [] - - upperBound = upHinge + Hstep - lowerBound = lowHinge - Hstep - - for item in catValue: - if item >= upHinge + 2*Hstep: - extreme.append(item) - elif item >= upHinge + Hstep: - outlier.append(item) - else: - pass - - for item in catValue: - if item <= lowHinge - 2*Hstep: - extreme.append(item) - elif item <= lowHinge - Hstep: - outlier.append(item) - else: - pass - else: - upperBound = 1000 - lowerBound = -1000 - - return upperBound, lowerBound + valsOnly = [] + dataXZ = vals[:] + for i in range(len(dataXZ)): + valsOnly.append(dataXZ[i][1]) + + data = [('', valsOnly[:])] + + for item in data: + itemvalue = item[1] + nValue = len(itemvalue) + catValue = [] + + for item2 in itemvalue: + try: + tstrain, tvalue = item2 + except: + tvalue = item2 + if nValue <= 4: + continue + else: + catValue.append(tvalue) + + if catValue != []: + lowHinge = gpercentile(catValue, 25) + upHinge = gpercentile(catValue, 75) + Hstep = 1.5*(upHinge - lowHinge) + + outlier = [] + extreme = [] + + upperBound = upHinge + Hstep + lowerBound = lowHinge - Hstep + + for item in catValue: + if item >= upHinge + 2*Hstep: + extreme.append(item) + elif item >= upHinge + Hstep: + outlier.append(item) + else: + pass + + for item in catValue: + if item <= lowHinge - 2*Hstep: + extreme.append(item) + elif item <= lowHinge - Hstep: + outlier.append(item) + else: + pass + else: + upperBound = 1000 + lowerBound = -1000 + + return upperBound, lowerBound def plotBoxPlot(canvas, data, offset= (40, 40, 40, 40), XLabel="Category", YLabel="Value"): - xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset - plotWidth = canvas.size[0] - xLeftOffset - xRightOffset - plotHeight = canvas.size[1] - yTopOffset - yBottomOffset - iValues = [] - for item in data: - for item2 in item[1]: - try: - iValues.append(item2[1]) - except: - iValues.append(item2) - - #draw frame - max_Y = max(iValues) - min_Y = min(iValues) - scaleY = detScale(min_Y, max_Y) - Yll = scaleY[0] - Yur = scaleY[1] - nStep = scaleY[2] - stepY = (Yur - Yll)/nStep - stepYPixel = plotHeight/(nStep) - canvas.drawRect(plotWidth+xLeftOffset, plotHeight + yTopOffset, xLeftOffset, yTopOffset) - - ##draw Y Scale - YYY = Yll - YCoord = plotHeight + yTopOffset - scaleFont=pid.Font(ttf="cour",size=11,bold=1) - for i in range(nStep+1): - strY = cformat(d=YYY, rank=0) - YCoord = max(YCoord, yTopOffset) - canvas.drawLine(xLeftOffset,YCoord,xLeftOffset-5,YCoord) - canvas.drawString(strY, xLeftOffset -30,YCoord +5,font=scaleFont) - YYY += stepY - YCoord -= stepYPixel - - ##draw X Scale - stepX = plotWidth/len(data) - XCoord = xLeftOffset + 0.5*stepX - YCoord = plotHeight + yTopOffset - scaleFont = pid.Font(ttf="tahoma",size=12,bold=0) - labelFont = pid.Font(ttf="tahoma",size=13,bold=0) - for item in data: - itemname, itemvalue = item - canvas.drawLine(XCoord, YCoord,XCoord, YCoord+5, color=pid.black) - canvas.drawString(itemname, XCoord - canvas.stringWidth(itemname,font=labelFont)/2.0,\ - YCoord +20,font=labelFont) - - nValue = len(itemvalue) - catValue = [] - for item2 in itemvalue: - try: - tstrain, tvalue = item2 - except: - tvalue = item2 - if nValue <= 4: - canvas.drawCross(XCoord, plotHeight + yTopOffset - (tvalue-Yll)*plotHeight/(Yur - Yll), color=pid.red,size=5) - else: - catValue.append(tvalue) - if catValue != []: - catMean = gmean(catValue) - catMedian = gmedian(catValue) - lowHinge = gpercentile(catValue, 25) - upHinge = gpercentile(catValue, 75) - Hstep = 1.5*(upHinge - lowHinge) - - outlier = [] - extrem = [] - - upperAdj = None - for item in catValue: - if item >= upHinge + 2*Hstep: - extrem.append(item) - elif item >= upHinge + Hstep: - outlier.append(item) - elif item > upHinge and item < upHinge + Hstep: - if upperAdj == None or item > upperAdj: - upperAdj = item - else: - pass - lowerAdj = None - for item in catValue: - if item <= lowHinge - 2*Hstep: - extrem.append(item) - elif item <= lowHinge - Hstep: - outlier.append(item) - if item < lowHinge and item > lowHinge - Hstep: - if lowerAdj == None or item < lowerAdj: - lowerAdj = item - else: - pass - canvas.drawRect(XCoord-20, plotHeight + yTopOffset - (lowHinge-Yll)*plotHeight/(Yur - Yll), \ - XCoord+20, plotHeight + yTopOffset - (upHinge-Yll)*plotHeight/(Yur - Yll)) - canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (catMedian-Yll)*plotHeight/(Yur - Yll), \ - XCoord+20, plotHeight + yTopOffset - (catMedian-Yll)*plotHeight/(Yur - Yll)) - if upperAdj != None: - canvas.drawLine(XCoord, plotHeight + yTopOffset - (upHinge-Yll)*plotHeight/(Yur - Yll), \ - XCoord, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll)) - canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll), \ - XCoord+20, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll)) - if lowerAdj != None: - canvas.drawLine(XCoord, plotHeight + yTopOffset - (lowHinge-Yll)*plotHeight/(Yur - Yll), \ - XCoord, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll)) - canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll), \ - XCoord+20, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll)) - - outlierFont = pid.Font(ttf="cour",size=12,bold=0) - if outlier != []: - for item in outlier: - yc = plotHeight + yTopOffset - (item-Yll)*plotHeight/(Yur - Yll) - #canvas.drawEllipse(XCoord-3, yc-3, XCoord+3, yc+3) - canvas.drawString('o', XCoord-3, yc+5, font=outlierFont, color=pid.orange) - if extrem != []: - for item in extrem: - yc = plotHeight + yTopOffset - (item-Yll)*plotHeight/(Yur - Yll) - #canvas.drawEllipse(XCoord-3, yc-3, XCoord+3, yc+3) - canvas.drawString('*', XCoord-3, yc+6, font=outlierFont, color=pid.red) - - canvas.drawCross(XCoord, plotHeight + yTopOffset - (catMean-Yll)*plotHeight/(Yur - Yll), \ - color=pid.blue,size=3) - #print (catMean, catMedian, cat25per, cat75per) - pass - - XCoord += stepX - - labelFont=pid.Font(ttf="verdana",size=18,bold=0) - canvas.drawString(XLabel, xLeftOffset + (plotWidth -canvas.stringWidth(XLabel,font=labelFont))/2.0, \ - YCoord +40, font=labelFont) - canvas.drawString(YLabel,xLeftOffset-40, YCoord-(plotHeight -canvas.stringWidth(YLabel,font=labelFont))/2.0,\ - font=labelFont, angle =90) + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + iValues = [] + for item in data: + for item2 in item[1]: + try: + iValues.append(item2[1]) + except: + iValues.append(item2) + + #draw frame + max_Y = max(iValues) + min_Y = min(iValues) + scaleY = detScale(min_Y, max_Y) + Yll = scaleY[0] + Yur = scaleY[1] + nStep = scaleY[2] + stepY = (Yur - Yll)/nStep + stepYPixel = plotHeight/(nStep) + canvas.drawRect(plotWidth+xLeftOffset, plotHeight + yTopOffset, xLeftOffset, yTopOffset) + + ##draw Y Scale + YYY = Yll + YCoord = plotHeight + yTopOffset + scaleFont=pid.Font(ttf="cour",size=11,bold=1) + for i in range(nStep+1): + strY = cformat(d=YYY, rank=0) + YCoord = max(YCoord, yTopOffset) + canvas.drawLine(xLeftOffset,YCoord,xLeftOffset-5,YCoord) + canvas.drawString(strY, xLeftOffset -30,YCoord +5,font=scaleFont) + YYY += stepY + YCoord -= stepYPixel + + ##draw X Scale + stepX = plotWidth/len(data) + XCoord = xLeftOffset + 0.5*stepX + YCoord = plotHeight + yTopOffset + scaleFont = pid.Font(ttf="tahoma",size=12,bold=0) + labelFont = pid.Font(ttf="tahoma",size=13,bold=0) + for item in data: + itemname, itemvalue = item + canvas.drawLine(XCoord, YCoord,XCoord, YCoord+5, color=pid.black) + canvas.drawString(itemname, XCoord - canvas.stringWidth(itemname,font=labelFont)/2.0,\ + YCoord +20,font=labelFont) + + nValue = len(itemvalue) + catValue = [] + for item2 in itemvalue: + try: + tstrain, tvalue = item2 + except: + tvalue = item2 + if nValue <= 4: + canvas.drawCross(XCoord, plotHeight + yTopOffset - (tvalue-Yll)*plotHeight/(Yur - Yll), color=pid.red,size=5) + else: + catValue.append(tvalue) + if catValue != []: + catMean = gmean(catValue) + catMedian = gmedian(catValue) + lowHinge = gpercentile(catValue, 25) + upHinge = gpercentile(catValue, 75) + Hstep = 1.5*(upHinge - lowHinge) + + outlier = [] + extrem = [] + + upperAdj = None + for item in catValue: + if item >= upHinge + 2*Hstep: + extrem.append(item) + elif item >= upHinge + Hstep: + outlier.append(item) + elif item > upHinge and item < upHinge + Hstep: + if upperAdj == None or item > upperAdj: + upperAdj = item + else: + pass + lowerAdj = None + for item in catValue: + if item <= lowHinge - 2*Hstep: + extrem.append(item) + elif item <= lowHinge - Hstep: + outlier.append(item) + if item < lowHinge and item > lowHinge - Hstep: + if lowerAdj == None or item < lowerAdj: + lowerAdj = item + else: + pass + canvas.drawRect(XCoord-20, plotHeight + yTopOffset - (lowHinge-Yll)*plotHeight/(Yur - Yll), \ + XCoord+20, plotHeight + yTopOffset - (upHinge-Yll)*plotHeight/(Yur - Yll)) + canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (catMedian-Yll)*plotHeight/(Yur - Yll), \ + XCoord+20, plotHeight + yTopOffset - (catMedian-Yll)*plotHeight/(Yur - Yll)) + if upperAdj != None: + canvas.drawLine(XCoord, plotHeight + yTopOffset - (upHinge-Yll)*plotHeight/(Yur - Yll), \ + XCoord, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll)) + canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll), \ + XCoord+20, plotHeight + yTopOffset - (upperAdj-Yll)*plotHeight/(Yur - Yll)) + if lowerAdj != None: + canvas.drawLine(XCoord, plotHeight + yTopOffset - (lowHinge-Yll)*plotHeight/(Yur - Yll), \ + XCoord, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll)) + canvas.drawLine(XCoord-20, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll), \ + XCoord+20, plotHeight + yTopOffset - (lowerAdj-Yll)*plotHeight/(Yur - Yll)) + + outlierFont = pid.Font(ttf="cour",size=12,bold=0) + if outlier != []: + for item in outlier: + yc = plotHeight + yTopOffset - (item-Yll)*plotHeight/(Yur - Yll) + #canvas.drawEllipse(XCoord-3, yc-3, XCoord+3, yc+3) + canvas.drawString('o', XCoord-3, yc+5, font=outlierFont, color=pid.orange) + if extrem != []: + for item in extrem: + yc = plotHeight + yTopOffset - (item-Yll)*plotHeight/(Yur - Yll) + #canvas.drawEllipse(XCoord-3, yc-3, XCoord+3, yc+3) + canvas.drawString('*', XCoord-3, yc+6, font=outlierFont, color=pid.red) + + canvas.drawCross(XCoord, plotHeight + yTopOffset - (catMean-Yll)*plotHeight/(Yur - Yll), \ + color=pid.blue,size=3) + #print (catMean, catMedian, cat25per, cat75per) + pass + + XCoord += stepX + + labelFont=pid.Font(ttf="verdana",size=18,bold=0) + canvas.drawString(XLabel, xLeftOffset + (plotWidth -canvas.stringWidth(XLabel,font=labelFont))/2.0, \ + YCoord +40, font=labelFont) + canvas.drawString(YLabel,xLeftOffset-40, YCoord-(plotHeight -canvas.stringWidth(YLabel,font=labelFont))/2.0,\ + font=labelFont, angle =90) def plotSecurity(canvas, text="12345"): - if not text: - return - - plotWidth = canvas.size[0] - plotHeight = canvas.size[1] - if plotHeight<=0 or plotWidth<=0: - return - - bgColor = pid.Color(0.6+0.4*random.random(), 0.6+0.4*random.random(), 0.6+0.4*random.random()) - canvas.drawRect(0,0,plotWidth,plotHeight, edgeColor=bgColor, fillColor=bgColor) - - for i in range(30): - randomColor = pid.Color(0.6+0.4*random.random(), 0.6+0.4*random.random(), 0.6+0.4*random.random()) - scaleFont=pid.Font(ttf="cour",size=random.choice(range(20, 50))) - canvas.drawString(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), - int(random.random()*plotWidth), int(random.random()*plotHeight), font=scaleFont, - color=randomColor, angle=random.choice(range(-45, 50))) - - step = (plotWidth-20)/len(text) - startX = 20 - for item in text: - randomColor = pid.Color(0.6*random.random(),0.6*random.random(), 0.6*random.random()) - scaleFont=pid.Font(ttf="verdana",size=random.choice(range(50, 60)),bold=1) - canvas.drawString(item, startX, plotHeight/2-10, font=scaleFont, - color=randomColor, angle=random.choice(range(-45, 50))) - startX += step + if not text: + return + + plotWidth = canvas.size[0] + plotHeight = canvas.size[1] + if plotHeight<=0 or plotWidth<=0: + return + + bgColor = pid.Color(0.6+0.4*random.random(), 0.6+0.4*random.random(), 0.6+0.4*random.random()) + canvas.drawRect(0,0,plotWidth,plotHeight, edgeColor=bgColor, fillColor=bgColor) + + for i in range(30): + randomColor = pid.Color(0.6+0.4*random.random(), 0.6+0.4*random.random(), 0.6+0.4*random.random()) + scaleFont=pid.Font(ttf="cour",size=random.choice(range(20, 50))) + canvas.drawString(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), + int(random.random()*plotWidth), int(random.random()*plotHeight), font=scaleFont, + color=randomColor, angle=random.choice(range(-45, 50))) + + step = (plotWidth-20)/len(text) + startX = 20 + for item in text: + randomColor = pid.Color(0.6*random.random(),0.6*random.random(), 0.6*random.random()) + scaleFont=pid.Font(ttf="verdana",size=random.choice(range(50, 60)),bold=1) + canvas.drawString(item, startX, plotHeight/2-10, font=scaleFont, + color=randomColor, angle=random.choice(range(-45, 50))) + startX += step # parameter: data is either object returned by reaper permutation function (called by MarkerRegressionPage.py) # or the first object returned by direct (pair-scan) permu function (called by DirectPlotPage.py) def plotBar(canvas, data, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, offset= (60, 20, 40, 40), zoom = 1): - xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset - - plotWidth = canvas.size[0] - xLeftOffset - xRightOffset - plotHeight = canvas.size[1] - yTopOffset - yBottomOffset - if plotHeight<=0 or plotWidth<=0: - return - - if len(data) < 2: - return - - max_D = max(data) - min_D = min(data) - #add by NL 06-20-2011: fix the error: when max_D is infinite, log function in detScale will go wrong - if max_D == float('inf') or max_D>webqtlConfig.MAXLRS: - max_D=webqtlConfig.MAXLRS #maximum LRS value - - xLow, xTop, stepX = detScale(min_D, max_D) - - #reduce data - step = ceil((xTop-xLow)/50.0) - j = xLow - dataXY = [] - Count = [] - while j <= xTop: - dataXY.append(j) - Count.append(0) - j += step - - for i, item in enumerate(data): - if item == float('inf') or item>webqtlConfig.MAXLRS: - item = webqtlConfig.MAXLRS #maximum LRS value - j = int((item-xLow)/step) - Count[j] += 1 - - yLow, yTop, stepY=detScale(0,max(Count)) - - #draw data - xScale = plotWidth/(xTop-xLow) - yScale = plotHeight/(yTop-yLow) - barWidth = xScale*step - - for i, count in enumerate(Count): - if count: - xc = (dataXY[i]-xLow)*xScale+xLeftOffset - yc =-(count-yLow)*yScale+yTopOffset+plotHeight - canvas.drawRect(xc+2,yc,xc+barWidth-2,yTopOffset+plotHeight,edgeColor=barColor,fillColor=barColor) - - #draw drawing region - canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) - - #draw scale - scaleFont=pid.Font(ttf="cour",size=11,bold=1) - x=xLow - for i in range(stepX+1): - xc=xLeftOffset+(x-xLow)*xScale - canvas.drawLine(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, color=axesColor) - strX = cformat(d=x, rank=0) - canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+14,font=scaleFont) - x+= (xTop - xLow)/stepX - - y=yLow - for i in range(stepY+1): - yc=yTopOffset+plotHeight-(y-yLow)*yScale - canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) - strY = "%d" %y - canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) - y+= (yTop - yLow)/stepY - - #draw label - labelFont=pid.Font(ttf="tahoma",size=17,bold=0) - if XLabel: - canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, - yTopOffset+plotHeight+yBottomOffset-10,font=labelFont,color=labelColor) - - if YLabel: - canvas.drawString(YLabel, 19, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, - font=labelFont,color=labelColor,angle=90) - - labelFont=pid.Font(ttf="verdana",size=16,bold=0) - if title: - canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, - 20,font=labelFont,color=labelColor) + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + + if len(data) < 2: + return + + max_D = max(data) + min_D = min(data) + #add by NL 06-20-2011: fix the error: when max_D is infinite, log function in detScale will go wrong + if max_D == float('inf') or max_D>webqtlConfig.MAXLRS: + max_D=webqtlConfig.MAXLRS #maximum LRS value + + xLow, xTop, stepX = detScale(min_D, max_D) + + #reduce data + step = ceil((xTop-xLow)/50.0) + j = xLow + dataXY = [] + Count = [] + while j <= xTop: + dataXY.append(j) + Count.append(0) + j += step + + for i, item in enumerate(data): + if item == float('inf') or item>webqtlConfig.MAXLRS: + item = webqtlConfig.MAXLRS #maximum LRS value + j = int((item-xLow)/step) + Count[j] += 1 + + yLow, yTop, stepY=detScale(0,max(Count)) + + #draw data + xScale = plotWidth/(xTop-xLow) + yScale = plotHeight/(yTop-yLow) + barWidth = xScale*step + + for i, count in enumerate(Count): + if count: + xc = (dataXY[i]-xLow)*xScale+xLeftOffset + yc =-(count-yLow)*yScale+yTopOffset+plotHeight + canvas.drawRect(xc+2,yc,xc+barWidth-2,yTopOffset+plotHeight,edgeColor=barColor,fillColor=barColor) + + #draw drawing region + canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) + + #draw scale + scaleFont=pid.Font(ttf="cour",size=11,bold=1) + x=xLow + for i in range(stepX+1): + xc=xLeftOffset+(x-xLow)*xScale + canvas.drawLine(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, color=axesColor) + strX = cformat(d=x, rank=0) + canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+14,font=scaleFont) + x+= (xTop - xLow)/stepX + + y=yLow + for i in range(stepY+1): + yc=yTopOffset+plotHeight-(y-yLow)*yScale + canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) + strY = "%d" %y + canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) + y+= (yTop - yLow)/stepY + + #draw label + labelFont=pid.Font(ttf="tahoma",size=17,bold=0) + if XLabel: + canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, + yTopOffset+plotHeight+yBottomOffset-10,font=labelFont,color=labelColor) + + if YLabel: + canvas.drawString(YLabel, 19, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, + font=labelFont,color=labelColor,angle=90) + + labelFont=pid.Font(ttf="verdana",size=16,bold=0) + if title: + canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, + 20,font=labelFont,color=labelColor) def plotBarText(canvas, data, label, variance=None, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, sLabel = None, offset= (80, 20, 40, 100), barSpace = 2, zoom = 1): - xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset - plotWidth = canvas.size[0] - xLeftOffset - xRightOffset - plotHeight = canvas.size[1] - yTopOffset - yBottomOffset - if plotHeight<=0 or plotWidth<=0: - return - - NNN = len(data) - if NNN < 2 or NNN != len(label): - return - if variance and len(variance)!=NNN: - variance = [] - - Y2 = data[:] - if variance: - for i in range(NNN): - if variance[i]: - Y2 += [data[i]-variance[i]] - - #Y axis - YLow, YTop, stepY = detScale(min(Y2), max(Y2)) - YScale = plotHeight/(YTop - YLow) - - if YLow < 0 and YTop > 0: - drawZero = 1 - else: - drawZero = 0 - - #X axis - X = range(NNN) - Xll= 0 - Xur= NNN-1 - - - if drawZero: - YZero = yTopOffset+plotHeight-YScale*(0-YLow) - canvas.drawLine(xLeftOffset, YZero, xLeftOffset+plotWidth, YZero) - else: - YZero = yTopOffset+plotHeight - #draw data - spaceWidth = barSpace - if spaceWidth < 1: - spaceWidth = 1 - barWidth = int((plotWidth - (NNN-1.0)*spaceWidth)/NNN) - - xc= xLeftOffset - scaleFont=pid.Font(ttf="verdana",size=11,bold=0) - for i in range(NNN): - yc = yTopOffset+plotHeight-(data[i]-YLow)*YScale - canvas.drawRect(xc,YZero,xc+barWidth-1, yc, edgeColor=barColor,fillColor=barColor) - if variance and variance[i]: - varlen = variance[i]*YScale - if yc-varlen < yTopOffset: - topYd = yTopOffset - else: - topYd = yc-varlen - canvas.drawLine(xc+barWidth/2-2,yc-varlen,xc+barWidth/2+2,yc-varlen,color=pid.red) - canvas.drawLine(xc+barWidth/2,yc+varlen,xc+barWidth/2,topYd,color=pid.red) - canvas.drawLine(xc+barWidth/2-2,yc+varlen,xc+barWidth/2+2,yc+varlen,color=pid.red) - strX = label[i] - canvas.drawString(strX,xc+barWidth/2.0+2,yTopOffset+plotHeight+2+canvas.stringWidth(strX,font=scaleFont),font=scaleFont,angle=90) - xc += barWidth + spaceWidth - - #draw drawing region - canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) - - #draw Y scale - scaleFont=pid.Font(ttf="cour",size=16,bold=1) - y=YLow - for i in range(stepY+1): - yc=yTopOffset+plotHeight-(y-YLow)*YScale - canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) - strY = cformat(d=y, rank=0) - canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) - y+= (YTop - YLow)/stepY - - #draw label - labelFont=pid.Font(ttf="verdana",size=17,bold=0) - if XLabel: - canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0,yTopOffset+plotHeight+65,font=labelFont,color=labelColor) - - if YLabel: - canvas.drawString(YLabel,xLeftOffset-50, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0,font=labelFont,color=labelColor,angle=90) - - labelFont=pid.Font(ttf="verdana",size=18,bold=0) - if title: - canvas.drawString(title,xLeftOffset,yTopOffset-15,font=labelFont,color=labelColor) - - return + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + + NNN = len(data) + if NNN < 2 or NNN != len(label): + return + if variance and len(variance)!=NNN: + variance = [] + + Y2 = data[:] + if variance: + for i in range(NNN): + if variance[i]: + Y2 += [data[i]-variance[i]] + + #Y axis + YLow, YTop, stepY = detScale(min(Y2), max(Y2)) + YScale = plotHeight/(YTop - YLow) + + if YLow < 0 and YTop > 0: + drawZero = 1 + else: + drawZero = 0 + + #X axis + X = range(NNN) + Xll= 0 + Xur= NNN-1 + + + if drawZero: + YZero = yTopOffset+plotHeight-YScale*(0-YLow) + canvas.drawLine(xLeftOffset, YZero, xLeftOffset+plotWidth, YZero) + else: + YZero = yTopOffset+plotHeight + #draw data + spaceWidth = barSpace + if spaceWidth < 1: + spaceWidth = 1 + barWidth = int((plotWidth - (NNN-1.0)*spaceWidth)/NNN) + + xc= xLeftOffset + scaleFont=pid.Font(ttf="verdana",size=11,bold=0) + for i in range(NNN): + yc = yTopOffset+plotHeight-(data[i]-YLow)*YScale + canvas.drawRect(xc,YZero,xc+barWidth-1, yc, edgeColor=barColor,fillColor=barColor) + if variance and variance[i]: + varlen = variance[i]*YScale + if yc-varlen < yTopOffset: + topYd = yTopOffset + else: + topYd = yc-varlen + canvas.drawLine(xc+barWidth/2-2,yc-varlen,xc+barWidth/2+2,yc-varlen,color=pid.red) + canvas.drawLine(xc+barWidth/2,yc+varlen,xc+barWidth/2,topYd,color=pid.red) + canvas.drawLine(xc+barWidth/2-2,yc+varlen,xc+barWidth/2+2,yc+varlen,color=pid.red) + strX = label[i] + canvas.drawString(strX,xc+barWidth/2.0+2,yTopOffset+plotHeight+2+canvas.stringWidth(strX,font=scaleFont),font=scaleFont,angle=90) + xc += barWidth + spaceWidth + + #draw drawing region + canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) + + #draw Y scale + scaleFont=pid.Font(ttf="cour",size=16,bold=1) + y=YLow + for i in range(stepY+1): + yc=yTopOffset+plotHeight-(y-YLow)*YScale + canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) + strY = cformat(d=y, rank=0) + canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) + y+= (YTop - YLow)/stepY + + #draw label + labelFont=pid.Font(ttf="verdana",size=17,bold=0) + if XLabel: + canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0,yTopOffset+plotHeight+65,font=labelFont,color=labelColor) + + if YLabel: + canvas.drawString(YLabel,xLeftOffset-50, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0,font=labelFont,color=labelColor,angle=90) + + labelFont=pid.Font(ttf="verdana",size=18,bold=0) + if title: + canvas.drawString(title,xLeftOffset,yTopOffset-15,font=labelFont,color=labelColor) + + return def plotXY(canvas, dataX, dataY, rank=0, dataLabel=[], plotColor = pid.black, axesColor=pid.black, labelColor=pid.black, lineSize="thin", lineColor=pid.grey, idFont="arial", idColor=pid.blue, idSize="14", symbolColor=pid.black, symbolType="circle", filled="yes", symbolSize="tiny", XLabel=None, YLabel=None, title=None, fitcurve=None, connectdot=1, displayR=None, loadingPlot = 0, offset= (80, 20, 40, 60), zoom = 1, specialCases=[], showLabel = 1, bufferSpace = 15): - 'displayR : correlation scatter plot, loadings : loading plot' - - dataXRanked, dataYRanked = webqtlUtil.calRank(dataX, dataY, len(dataX)) - - #get ID font size - idFontSize = int(idSize) - - #If filled is yes, set fill color - if filled == "yes": - fillColor = symbolColor - else: - fillColor = None - - if symbolSize == "large": - sizeModifier = 7 - fontModifier = 12 - elif symbolSize == "medium": - sizeModifier = 5 - fontModifier = 8 - elif symbolSize == "small": - sizeModifier = 3 - fontModifier = 3 - else: - sizeModifier = 1 - fontModifier = -1 - - if rank == 0: # Pearson correlation - bufferSpace = 0 - dataXPrimary = dataX - dataYPrimary = dataY - dataXAlt = dataXRanked #Values used just for printing the other corr type to the graph image - dataYAlt = dataYRanked #Values used just for printing the other corr type to the graph image - else: # Spearman correlation: Switching Ranked and Unranked X and Y values - dataXPrimary = dataXRanked - dataYPrimary = dataYRanked - dataXAlt = dataX #Values used just for printing the other corr type to the graph image - dataYAlt = dataY #Values used just for printing the other corr type to the graph image - - xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset - plotWidth = canvas.size[0] - xLeftOffset - xRightOffset - plotHeight = canvas.size[1] - yTopOffset - yBottomOffset - if plotHeight<=0 or plotWidth<=0: - return - if len(dataXPrimary) < 1 or len(dataXPrimary) != len(dataYPrimary) or (dataLabel and len(dataXPrimary) != len(dataLabel)): - return - - max_X=max(dataXPrimary) - min_X=min(dataXPrimary) - max_Y=max(dataYPrimary) - min_Y=min(dataYPrimary) - - #for some reason I forgot why I need to do this - if loadingPlot: - min_X = min(-0.1,min_X) - max_X = max(0.1,max_X) - min_Y = min(-0.1,min_Y) - max_Y = max(0.1,max_Y) - - xLow, xTop, stepX=detScale(min_X,max_X) - yLow, yTop, stepY=detScale(min_Y,max_Y) - xScale = plotWidth/(xTop-xLow) - yScale = plotHeight/(yTop-yLow) - - #draw drawing region - canvas.drawRect(xLeftOffset-bufferSpace, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight+bufferSpace) - canvas.drawRect(xLeftOffset-bufferSpace+1, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight+bufferSpace-1) - - #calculate data points - data = map(lambda X, Y: (X, Y), dataXPrimary, dataYPrimary) - xCoord = map(lambda X, Y: ((X-xLow)*xScale + xLeftOffset, yTopOffset+plotHeight-(Y-yLow)*yScale), dataXPrimary, dataYPrimary) - - labelFont=pid.Font(ttf=idFont,size=idFontSize,bold=0) - - if loadingPlot: - xZero = -xLow*xScale+xLeftOffset - yZero = yTopOffset+plotHeight+yLow*yScale - for point in xCoord: - canvas.drawLine(xZero,yZero,point[0],point[1],color=pid.red) - else: - if connectdot: - canvas.drawPolygon(xCoord,edgeColor=plotColor,closed=0) - else: - pass - - symbolFont = pid.Font(ttf="fnt_bs", size=12+fontModifier,bold=0) - - for i, item in enumerate(xCoord): - if dataLabel and dataLabel[i] in specialCases: - canvas.drawRect(item[0]-3, item[1]-3, item[0]+3, item[1]+3, edgeColor=pid.green) - #canvas.drawCross(item[0],item[1],color=pid.blue,size=5) - else: - if symbolType == "vertRect": - canvas.drawRect(x1=item[0]-sizeModifier+2,y1=item[1]-sizeModifier-2, x2=item[0]+sizeModifier-1,y2=item[1]+sizeModifier+2, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) - elif (symbolType == "circle" and filled != "yes"): - canvas.drawString(":", item[0]-canvas.stringWidth(":",font=symbolFont)/2+1,item[1]+2,color=symbolColor, font=symbolFont) - elif (symbolType == "circle" and filled == "yes"): - canvas.drawString("5", item[0]-canvas.stringWidth("5",font=symbolFont)/2+1,item[1]+2,color=symbolColor, font=symbolFont) - elif symbolType == "horiRect": - canvas.drawRect(x1=item[0]-sizeModifier-1,y1=item[1]-sizeModifier+3, x2=item[0]+sizeModifier+3,y2=item[1]+sizeModifier-2, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) - elif (symbolType == "square"): - canvas.drawRect(x1=item[0]-sizeModifier+1,y1=item[1]-sizeModifier-4, x2=item[0]+sizeModifier+2,y2=item[1]+sizeModifier-3, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) - elif (symbolType == "diamond" and filled != "yes"): - canvas.drawString(",", item[0]-canvas.stringWidth(",",font=symbolFont)/2+2, item[1]+6, font=symbolFont, color=symbolColor) - elif (symbolType == "diamond" and filled == "yes"): - canvas.drawString("D", item[0]-canvas.stringWidth("D",font=symbolFont)/2+2, item[1]+6, font=symbolFont, color=symbolColor) - elif symbolType == "4-star": - canvas.drawString("l", item[0]-canvas.stringWidth("l",font=symbolFont)/2+1, item[1]+3, font=symbolFont, color=symbolColor) - elif symbolType == "3-star": - canvas.drawString("k", item[0]-canvas.stringWidth("k",font=symbolFont)/2+1, item[1]+3, font=symbolFont, color=symbolColor) - else: - canvas.drawCross(item[0],item[1]-2,color=symbolColor, size=sizeModifier+2) - - if showLabel and dataLabel: - if (symbolType == "vertRect" or symbolType == "diamond"): - labelGap = 15 - elif (symbolType == "4-star" or symbolType == "3-star"): - labelGap = 12 - else: - labelGap = 11 - canvas.drawString(dataLabel[i], item[0]- canvas.stringWidth(dataLabel[i], - font=labelFont)/2 + 1, item[1]+(labelGap+sizeModifier+(idFontSize-12)), font=labelFont, color=idColor) - - #draw scale - scaleFont=pid.Font(ttf="cour",size=16,bold=1) - - - x=xLow - for i in range(stepX+1): - xc=xLeftOffset+(x-xLow)*xScale - if ((x == 0) & (rank == 1)): - pass - else: - canvas.drawLine(xc,yTopOffset+plotHeight + bufferSpace,xc,yTopOffset+plotHeight+5 + bufferSpace, color=axesColor) - strX = cformat(d=x, rank=rank) - if ((strX == "0") & (rank == 1)): - pass - else: - canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+20 + bufferSpace,font=scaleFont) - x+= (xTop - xLow)/stepX - - y=yLow - for i in range(stepY+1): - yc=yTopOffset+plotHeight-(y-yLow)*yScale - if ((y == 0) & (rank == 1)): - pass - else: - canvas.drawLine(xLeftOffset - bufferSpace,yc,xLeftOffset-5 - bufferSpace,yc, color=axesColor) - strY = cformat(d=y, rank=rank) - if ((strY == "0") & (rank == 1)): - pass - else: - canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)- 10 - bufferSpace,yc+4,font=scaleFont) - y+= (yTop - yLow)/stepY - - #draw label - - labelFont=pid.Font(ttf="verdana",size=canvas.size[0]/45,bold=0) - titleFont=pid.Font(ttf="verdana",size=canvas.size[0]/40,bold=0) - - if (rank == 1 and not title): - canvas.drawString("Spearman Rank Correlation", xLeftOffset-canvas.size[0]*.025+(plotWidth-canvas.stringWidth("Spearman Rank Correlation",font=titleFont))/2.0, - 25,font=titleFont,color=labelColor) - elif (rank == 0 and not title): - canvas.drawString("Pearson Correlation", xLeftOffset-canvas.size[0]*.025+(plotWidth-canvas.stringWidth("Pearson Correlation",font=titleFont))/2.0, - 25,font=titleFont,color=labelColor) - - if XLabel: - canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, - yTopOffset+plotHeight+yBottomOffset-25,font=labelFont,color=labelColor) - - if YLabel: - canvas.drawString(YLabel, xLeftOffset-65, yTopOffset+plotHeight- (plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, - font=labelFont,color=labelColor,angle=90) - - labelFont=pid.Font(ttf="verdana",size=20,bold=0) - if title: - canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, - 20,font=labelFont,color=labelColor) - - if fitcurve: - import sys - sys.argv = [ "mod_python" ] - #from numarray import linear_algebra as la - #from numarray import ones, array, dot, swapaxes - fitYY = array(dataYPrimary) - fitXX = array([ones(len(dataXPrimary)),dataXPrimary]) - AA = dot(fitXX,swapaxes(fitXX,0,1)) - BB = dot(fitXX,fitYY) - bb = la.linear_least_squares(AA,BB)[0] - - xc1 = xLeftOffset - yc1 = yTopOffset+plotHeight-(bb[0]+bb[1]*xLow-yLow)*yScale - if yc1 > yTopOffset+plotHeight: - yc1 = yTopOffset+plotHeight - xc1 = (yLow-bb[0])/bb[1] - xc1=(xc1-xLow)*xScale+xLeftOffset - elif yc1 < yTopOffset: - yc1 = yTopOffset - xc1 = (yTop-bb[0])/bb[1] - xc1=(xc1-xLow)*xScale+xLeftOffset - else: - pass - - xc2 = xLeftOffset + plotWidth - yc2 = yTopOffset+plotHeight-(bb[0]+bb[1]*xTop-yLow)*yScale - if yc2 > yTopOffset+plotHeight: - yc2 = yTopOffset+plotHeight - xc2 = (yLow-bb[0])/bb[1] - xc2=(xc2-xLow)*xScale+xLeftOffset - elif yc2 < yTopOffset: - yc2 = yTopOffset - xc2 = (yTop-bb[0])/bb[1] - xc2=(xc2-xLow)*xScale+xLeftOffset - else: - pass - - canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace,xc2,yc2,color=lineColor) - if lineSize == "medium": - canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace+1,xc2,yc2+1,color=lineColor) - if lineSize == "thick": - canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace+1,xc2,yc2+1,color=lineColor) - canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace-1,xc2,yc2-1,color=lineColor) - - - if displayR: - labelFont=pid.Font(ttf="trebuc",size=canvas.size[0]/60,bold=0) - NNN = len(dataX) - corr = webqtlUtil.calCorrelation(dataXPrimary,dataYPrimary,NNN)[0] - - if NNN < 3: - corrPValue = 1.0 - else: - if abs(corr) >= 1.0: - corrPValue = 0.0 - else: - ZValue = 0.5*log((1.0+corr)/(1.0-corr)) - ZValue = ZValue*sqrt(NNN-3) - corrPValue = 2.0*(1.0 - reaper.normp(abs(ZValue))) - - NStr = "N = %d" % NNN - strLenN = canvas.stringWidth(NStr,font=labelFont) - - if rank == 1: - if corrPValue < 0.0000000000000001: - corrStr = "Rho = %1.3f P < 1.00 E-16" % (corr) - else: - corrStr = "Rho = %1.3f P = %3.2E" % (corr, corrPValue) - else: - if corrPValue < 0.0000000000000001: - corrStr = "r = %1.3f P < 1.00 E-16" % (corr) - else: - corrStr = "r = %1.3f P = %3.2E" % (corr, corrPValue) - strLen = canvas.stringWidth(corrStr,font=labelFont) - - canvas.drawString(NStr,xLeftOffset,yTopOffset-10,font=labelFont,color=labelColor) - canvas.drawString(corrStr,xLeftOffset+plotWidth-strLen,yTopOffset-10,font=labelFont,color=labelColor) - - return xCoord + 'displayR : correlation scatter plot, loadings : loading plot' + + dataXRanked, dataYRanked = webqtlUtil.calRank(dataX, dataY, len(dataX)) + + #get ID font size + idFontSize = int(idSize) + + #If filled is yes, set fill color + if filled == "yes": + fillColor = symbolColor + else: + fillColor = None + + if symbolSize == "large": + sizeModifier = 7 + fontModifier = 12 + elif symbolSize == "medium": + sizeModifier = 5 + fontModifier = 8 + elif symbolSize == "small": + sizeModifier = 3 + fontModifier = 3 + else: + sizeModifier = 1 + fontModifier = -1 + + if rank == 0: # Pearson correlation + bufferSpace = 0 + dataXPrimary = dataX + dataYPrimary = dataY + dataXAlt = dataXRanked #Values used just for printing the other corr type to the graph image + dataYAlt = dataYRanked #Values used just for printing the other corr type to the graph image + else: # Spearman correlation: Switching Ranked and Unranked X and Y values + dataXPrimary = dataXRanked + dataYPrimary = dataYRanked + dataXAlt = dataX #Values used just for printing the other corr type to the graph image + dataYAlt = dataY #Values used just for printing the other corr type to the graph image + + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + if len(dataXPrimary) < 1 or len(dataXPrimary) != len(dataYPrimary) or (dataLabel and len(dataXPrimary) != len(dataLabel)): + return + + max_X=max(dataXPrimary) + min_X=min(dataXPrimary) + max_Y=max(dataYPrimary) + min_Y=min(dataYPrimary) + + #for some reason I forgot why I need to do this + if loadingPlot: + min_X = min(-0.1,min_X) + max_X = max(0.1,max_X) + min_Y = min(-0.1,min_Y) + max_Y = max(0.1,max_Y) + + xLow, xTop, stepX=detScale(min_X,max_X) + yLow, yTop, stepY=detScale(min_Y,max_Y) + xScale = plotWidth/(xTop-xLow) + yScale = plotHeight/(yTop-yLow) + + #draw drawing region + canvas.drawRect(xLeftOffset-bufferSpace, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight+bufferSpace) + canvas.drawRect(xLeftOffset-bufferSpace+1, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight+bufferSpace-1) + + #calculate data points + data = map(lambda X, Y: (X, Y), dataXPrimary, dataYPrimary) + xCoord = map(lambda X, Y: ((X-xLow)*xScale + xLeftOffset, yTopOffset+plotHeight-(Y-yLow)*yScale), dataXPrimary, dataYPrimary) + + labelFont=pid.Font(ttf=idFont,size=idFontSize,bold=0) + + if loadingPlot: + xZero = -xLow*xScale+xLeftOffset + yZero = yTopOffset+plotHeight+yLow*yScale + for point in xCoord: + canvas.drawLine(xZero,yZero,point[0],point[1],color=pid.red) + else: + if connectdot: + canvas.drawPolygon(xCoord,edgeColor=plotColor,closed=0) + else: + pass + + symbolFont = pid.Font(ttf="fnt_bs", size=12+fontModifier,bold=0) + + for i, item in enumerate(xCoord): + if dataLabel and dataLabel[i] in specialCases: + canvas.drawRect(item[0]-3, item[1]-3, item[0]+3, item[1]+3, edgeColor=pid.green) + #canvas.drawCross(item[0],item[1],color=pid.blue,size=5) + else: + if symbolType == "vertRect": + canvas.drawRect(x1=item[0]-sizeModifier+2,y1=item[1]-sizeModifier-2, x2=item[0]+sizeModifier-1,y2=item[1]+sizeModifier+2, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) + elif (symbolType == "circle" and filled != "yes"): + canvas.drawString(":", item[0]-canvas.stringWidth(":",font=symbolFont)/2+1,item[1]+2,color=symbolColor, font=symbolFont) + elif (symbolType == "circle" and filled == "yes"): + canvas.drawString("5", item[0]-canvas.stringWidth("5",font=symbolFont)/2+1,item[1]+2,color=symbolColor, font=symbolFont) + elif symbolType == "horiRect": + canvas.drawRect(x1=item[0]-sizeModifier-1,y1=item[1]-sizeModifier+3, x2=item[0]+sizeModifier+3,y2=item[1]+sizeModifier-2, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) + elif (symbolType == "square"): + canvas.drawRect(x1=item[0]-sizeModifier+1,y1=item[1]-sizeModifier-4, x2=item[0]+sizeModifier+2,y2=item[1]+sizeModifier-3, edgeColor=symbolColor, edgeWidth=1, fillColor=fillColor) + elif (symbolType == "diamond" and filled != "yes"): + canvas.drawString(",", item[0]-canvas.stringWidth(",",font=symbolFont)/2+2, item[1]+6, font=symbolFont, color=symbolColor) + elif (symbolType == "diamond" and filled == "yes"): + canvas.drawString("D", item[0]-canvas.stringWidth("D",font=symbolFont)/2+2, item[1]+6, font=symbolFont, color=symbolColor) + elif symbolType == "4-star": + canvas.drawString("l", item[0]-canvas.stringWidth("l",font=symbolFont)/2+1, item[1]+3, font=symbolFont, color=symbolColor) + elif symbolType == "3-star": + canvas.drawString("k", item[0]-canvas.stringWidth("k",font=symbolFont)/2+1, item[1]+3, font=symbolFont, color=symbolColor) + else: + canvas.drawCross(item[0],item[1]-2,color=symbolColor, size=sizeModifier+2) + + if showLabel and dataLabel: + if (symbolType == "vertRect" or symbolType == "diamond"): + labelGap = 15 + elif (symbolType == "4-star" or symbolType == "3-star"): + labelGap = 12 + else: + labelGap = 11 + canvas.drawString(dataLabel[i], item[0]- canvas.stringWidth(dataLabel[i], + font=labelFont)/2 + 1, item[1]+(labelGap+sizeModifier+(idFontSize-12)), font=labelFont, color=idColor) + + #draw scale + scaleFont=pid.Font(ttf="cour",size=16,bold=1) + + + x=xLow + for i in range(stepX+1): + xc=xLeftOffset+(x-xLow)*xScale + if ((x == 0) & (rank == 1)): + pass + else: + canvas.drawLine(xc,yTopOffset+plotHeight + bufferSpace,xc,yTopOffset+plotHeight+5 + bufferSpace, color=axesColor) + strX = cformat(d=x, rank=rank) + if ((strX == "0") & (rank == 1)): + pass + else: + canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+20 + bufferSpace,font=scaleFont) + x+= (xTop - xLow)/stepX + + y=yLow + for i in range(stepY+1): + yc=yTopOffset+plotHeight-(y-yLow)*yScale + if ((y == 0) & (rank == 1)): + pass + else: + canvas.drawLine(xLeftOffset - bufferSpace,yc,xLeftOffset-5 - bufferSpace,yc, color=axesColor) + strY = cformat(d=y, rank=rank) + if ((strY == "0") & (rank == 1)): + pass + else: + canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)- 10 - bufferSpace,yc+4,font=scaleFont) + y+= (yTop - yLow)/stepY + + #draw label + + labelFont=pid.Font(ttf="verdana",size=canvas.size[0]/45,bold=0) + titleFont=pid.Font(ttf="verdana",size=canvas.size[0]/40,bold=0) + + if (rank == 1 and not title): + canvas.drawString("Spearman Rank Correlation", xLeftOffset-canvas.size[0]*.025+(plotWidth-canvas.stringWidth("Spearman Rank Correlation",font=titleFont))/2.0, + 25,font=titleFont,color=labelColor) + elif (rank == 0 and not title): + canvas.drawString("Pearson Correlation", xLeftOffset-canvas.size[0]*.025+(plotWidth-canvas.stringWidth("Pearson Correlation",font=titleFont))/2.0, + 25,font=titleFont,color=labelColor) + + if XLabel: + canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, + yTopOffset+plotHeight+yBottomOffset-25,font=labelFont,color=labelColor) + + if YLabel: + canvas.drawString(YLabel, xLeftOffset-65, yTopOffset+plotHeight- (plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, + font=labelFont,color=labelColor,angle=90) + + labelFont=pid.Font(ttf="verdana",size=20,bold=0) + if title: + canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, + 20,font=labelFont,color=labelColor) + + if fitcurve: + import sys + sys.argv = [ "mod_python" ] + #from numarray import linear_algebra as la + #from numarray import ones, array, dot, swapaxes + fitYY = array(dataYPrimary) + fitXX = array([ones(len(dataXPrimary)),dataXPrimary]) + AA = dot(fitXX,swapaxes(fitXX,0,1)) + BB = dot(fitXX,fitYY) + bb = la.linear_least_squares(AA,BB)[0] + + xc1 = xLeftOffset + yc1 = yTopOffset+plotHeight-(bb[0]+bb[1]*xLow-yLow)*yScale + if yc1 > yTopOffset+plotHeight: + yc1 = yTopOffset+plotHeight + xc1 = (yLow-bb[0])/bb[1] + xc1=(xc1-xLow)*xScale+xLeftOffset + elif yc1 < yTopOffset: + yc1 = yTopOffset + xc1 = (yTop-bb[0])/bb[1] + xc1=(xc1-xLow)*xScale+xLeftOffset + else: + pass + + xc2 = xLeftOffset + plotWidth + yc2 = yTopOffset+plotHeight-(bb[0]+bb[1]*xTop-yLow)*yScale + if yc2 > yTopOffset+plotHeight: + yc2 = yTopOffset+plotHeight + xc2 = (yLow-bb[0])/bb[1] + xc2=(xc2-xLow)*xScale+xLeftOffset + elif yc2 < yTopOffset: + yc2 = yTopOffset + xc2 = (yTop-bb[0])/bb[1] + xc2=(xc2-xLow)*xScale+xLeftOffset + else: + pass + + canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace,xc2,yc2,color=lineColor) + if lineSize == "medium": + canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace+1,xc2,yc2+1,color=lineColor) + if lineSize == "thick": + canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace+1,xc2,yc2+1,color=lineColor) + canvas.drawLine(xc1 - bufferSpace,yc1 + bufferSpace-1,xc2,yc2-1,color=lineColor) + + + if displayR: + labelFont=pid.Font(ttf="trebuc",size=canvas.size[0]/60,bold=0) + NNN = len(dataX) + corr = webqtlUtil.calCorrelation(dataXPrimary,dataYPrimary,NNN)[0] + + if NNN < 3: + corrPValue = 1.0 + else: + if abs(corr) >= 1.0: + corrPValue = 0.0 + else: + ZValue = 0.5*log((1.0+corr)/(1.0-corr)) + ZValue = ZValue*sqrt(NNN-3) + corrPValue = 2.0*(1.0 - reaper.normp(abs(ZValue))) + + NStr = "N = %d" % NNN + strLenN = canvas.stringWidth(NStr,font=labelFont) + + if rank == 1: + if corrPValue < 0.0000000000000001: + corrStr = "Rho = %1.3f P < 1.00 E-16" % (corr) + else: + corrStr = "Rho = %1.3f P = %3.2E" % (corr, corrPValue) + else: + if corrPValue < 0.0000000000000001: + corrStr = "r = %1.3f P < 1.00 E-16" % (corr) + else: + corrStr = "r = %1.3f P = %3.2E" % (corr, corrPValue) + strLen = canvas.stringWidth(corrStr,font=labelFont) + + canvas.drawString(NStr,xLeftOffset,yTopOffset-10,font=labelFont,color=labelColor) + canvas.drawString(corrStr,xLeftOffset+plotWidth-strLen,yTopOffset-10,font=labelFont,color=labelColor) + + return xCoord def plotXYSVG(drawSpace, dataX, dataY, rank=0, dataLabel=[], plotColor = "black", axesColor="black", labelColor="black", symbolColor="red", XLabel=None, YLabel=None, title=None, fitcurve=None, connectdot=1, displayR=None, loadingPlot = 0, offset= (80, 20, 40, 60), zoom = 1, specialCases=[], showLabel = 1): - 'displayR : correlation scatter plot, loadings : loading plot' - - dataXRanked, dataYRanked = webqtlUtil.calRank(dataX, dataY, len(dataX)) - - # Switching Ranked and Unranked X and Y values if a Spearman Rank Correlation - if rank == 0: - dataXPrimary = dataX - dataYPrimary = dataY - dataXAlt = dataXRanked - dataYAlt = dataYRanked - - else: - dataXPrimary = dataXRanked - dataYPrimary = dataYRanked - dataXAlt = dataX - dataYAlt = dataY - - - - xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset - plotWidth = drawSpace.attributes['width'] - xLeftOffset - xRightOffset - plotHeight = drawSpace.attributes['height'] - yTopOffset - yBottomOffset - if plotHeight<=0 or plotWidth<=0: - return - if len(dataXPrimary) < 1 or len(dataXPrimary) != len(dataYPrimary) or (dataLabel and len(dataXPrimary) != len(dataLabel)): - return - - max_X=max(dataXPrimary) - min_X=min(dataXPrimary) - max_Y=max(dataYPrimary) - min_Y=min(dataYPrimary) - - #for some reason I forgot why I need to do this - if loadingPlot: - min_X = min(-0.1,min_X) - max_X = max(0.1,max_X) - min_Y = min(-0.1,min_Y) - max_Y = max(0.1,max_Y) - - xLow, xTop, stepX=detScale(min_X,max_X) - yLow, yTop, stepY=detScale(min_Y,max_Y) - xScale = plotWidth/(xTop-xLow) - yScale = plotHeight/(yTop-yLow) - - #draw drawing region - r = svg.rect(xLeftOffset, yTopOffset, plotWidth, plotHeight, 'none', axesColor, 1) - drawSpace.addElement(r) - - #calculate data points - data = map(lambda X, Y: (X, Y), dataXPrimary, dataYPrimary) - xCoord = map(lambda X, Y: ((X-xLow)*xScale + xLeftOffset, yTopOffset+plotHeight-(Y-yLow)*yScale), dataXPrimary, dataYPrimary) - labelFontF = "verdana" - labelFontS = 11 - - if loadingPlot: - xZero = -xLow*xScale+xLeftOffset - yZero = yTopOffset+plotHeight+yLow*yScale - for point in xCoord: - drawSpace.addElement(svg.line(xZero,yZero,point[0],point[1], "red", 1)) - else: - if connectdot: - pass - #drawSpace.drawPolygon(xCoord,edgeColor=plotColor,closed=0) - else: - pass - - for i, item in enumerate(xCoord): - if dataLabel and dataLabel[i] in specialCases: - drawSpace.addElement(svg.rect(item[0]-3, item[1]-3, 6, 6, "none", "green", 0.5)) - #drawSpace.drawCross(item[0],item[1],color=pid.blue,size=5) - else: - drawSpace.addElement(svg.line(item[0],item[1]+5,item[0],item[1]-5,symbolColor,1)) - drawSpace.addElement(svg.line(item[0]+5,item[1],item[0]-5,item[1],symbolColor,1)) - if showLabel and dataLabel: - pass - drawSpace.addElement(svg.text(item[0], item[1]+14, dataLabel[i], labelFontS, - labelFontF, text_anchor="middle", style="stroke:blue;stroke-width:0.5;")) - #canvas.drawString(, item[0]- canvas.stringWidth(dataLabel[i], - # font=labelFont)/2, item[1]+14, font=labelFont, color=pid.blue) - - #draw scale - #scaleFont=pid.Font(ttf="cour",size=14,bold=1) - x=xLow - for i in range(stepX+1): - xc=xLeftOffset+(x-xLow)*xScale - drawSpace.addElement(svg.line(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, axesColor, 1)) - strX = cformat(d=x, rank=rank) - drawSpace.addElement(svg.text(xc,yTopOffset+plotHeight+20,strX,13, "courier", text_anchor="middle")) - x+= (xTop - xLow)/stepX - - y=yLow - for i in range(stepY+1): - yc=yTopOffset+plotHeight-(y-yLow)*yScale - drawSpace.addElement(svg.line(xLeftOffset,yc,xLeftOffset-5,yc, axesColor, 1)) - strY = cformat(d=y, rank=rank) - drawSpace.addElement(svg.text(xLeftOffset-10,yc+5,strY,13, "courier", text_anchor="end")) - y+= (yTop - yLow)/stepY - - #draw label - labelFontF = "verdana" - labelFontS = 17 - if XLabel: - drawSpace.addElement(svg.text(xLeftOffset+plotWidth/2.0, - yTopOffset+plotHeight+yBottomOffset-10,XLabel, - labelFontS, labelFontF, text_anchor="middle")) - - if YLabel: - drawSpace.addElement(svg.text(xLeftOffset-50, - yTopOffset+plotHeight/2,YLabel, - labelFontS, labelFontF, text_anchor="middle", style="writing-mode:tb-rl", transform="rotate(270 %d %d)" % (xLeftOffset-50, yTopOffset+plotHeight/2))) - #drawSpace.drawString(YLabel, xLeftOffset-50, yTopOffset+plotHeight- (plotHeight-drawSpace.stringWidth(YLabel,font=labelFont))/2.0, - # font=labelFont,color=labelColor,angle=90) - - - if fitcurve: - sys.argv = [ "mod_python" ] - #from numarray import linear_algebra as la - #from numarray import ones, array, dot, swapaxes - fitYY = array(dataYPrimary) - fitXX = array([ones(len(dataXPrimary)),dataXPrimary]) - AA = dot(fitXX,swapaxes(fitXX,0,1)) - BB = dot(fitXX,fitYY) - bb = la.linear_least_squares(AA,BB)[0] - - xc1 = xLeftOffset - yc1 = yTopOffset+plotHeight-(bb[0]+bb[1]*xLow-yLow)*yScale - if yc1 > yTopOffset+plotHeight: - yc1 = yTopOffset+plotHeight - xc1 = (yLow-bb[0])/bb[1] - xc1=(xc1-xLow)*xScale+xLeftOffset - elif yc1 < yTopOffset: - yc1 = yTopOffset - xc1 = (yTop-bb[0])/bb[1] - xc1=(xc1-xLow)*xScale+xLeftOffset - else: - pass - - xc2 = xLeftOffset + plotWidth - yc2 = yTopOffset+plotHeight-(bb[0]+bb[1]*xTop-yLow)*yScale - if yc2 > yTopOffset+plotHeight: - yc2 = yTopOffset+plotHeight - xc2 = (yLow-bb[0])/bb[1] - xc2=(xc2-xLow)*xScale+xLeftOffset - elif yc2 < yTopOffset: - yc2 = yTopOffset - xc2 = (yTop-bb[0])/bb[1] - xc2=(xc2-xLow)*xScale+xLeftOffset - else: - pass - - drawSpace.addElement(svg.line(xc1,yc1,xc2,yc2,"green", 1)) - - if displayR: - labelFontF = "trebuc" - labelFontS = 14 - NNN = len(dataX) - - corr = webqtlUtil.calCorrelation(dataXPrimary,dataYPrimary,NNN)[0] - - if NNN < 3: - corrPValue = 1.0 - else: - if abs(corr) >= 1.0: - corrPValue = 0.0 - else: - ZValue = 0.5*log((1.0+corr)/(1.0-corr)) - ZValue = ZValue*sqrt(NNN-3) - corrPValue = 2.0*(1.0 - reaper.normp(abs(ZValue))) - - NStr = "N of Cases=%d" % NNN - - if rank == 1: - corrStr = "Spearman's r=%1.3f P=%3.2E" % (corr, corrPValue) - else: - corrStr = "Pearson's r=%1.3f P=%3.2E" % (corr, corrPValue) - - drawSpace.addElement(svg.text(xLeftOffset,yTopOffset-10,NStr, - labelFontS, labelFontF, text_anchor="start")) - drawSpace.addElement(svg.text(xLeftOffset+plotWidth,yTopOffset-25,corrStr, - labelFontS, labelFontF, text_anchor="end")) - """ - """ - return + 'displayR : correlation scatter plot, loadings : loading plot' + + dataXRanked, dataYRanked = webqtlUtil.calRank(dataX, dataY, len(dataX)) + + # Switching Ranked and Unranked X and Y values if a Spearman Rank Correlation + if rank == 0: + dataXPrimary = dataX + dataYPrimary = dataY + dataXAlt = dataXRanked + dataYAlt = dataYRanked + + else: + dataXPrimary = dataXRanked + dataYPrimary = dataYRanked + dataXAlt = dataX + dataYAlt = dataY + + + + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + plotWidth = drawSpace.attributes['width'] - xLeftOffset - xRightOffset + plotHeight = drawSpace.attributes['height'] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + if len(dataXPrimary) < 1 or len(dataXPrimary) != len(dataYPrimary) or (dataLabel and len(dataXPrimary) != len(dataLabel)): + return + + max_X=max(dataXPrimary) + min_X=min(dataXPrimary) + max_Y=max(dataYPrimary) + min_Y=min(dataYPrimary) + + #for some reason I forgot why I need to do this + if loadingPlot: + min_X = min(-0.1,min_X) + max_X = max(0.1,max_X) + min_Y = min(-0.1,min_Y) + max_Y = max(0.1,max_Y) + + xLow, xTop, stepX=detScale(min_X,max_X) + yLow, yTop, stepY=detScale(min_Y,max_Y) + xScale = plotWidth/(xTop-xLow) + yScale = plotHeight/(yTop-yLow) + + #draw drawing region + r = svg.rect(xLeftOffset, yTopOffset, plotWidth, plotHeight, 'none', axesColor, 1) + drawSpace.addElement(r) + + #calculate data points + data = map(lambda X, Y: (X, Y), dataXPrimary, dataYPrimary) + xCoord = map(lambda X, Y: ((X-xLow)*xScale + xLeftOffset, yTopOffset+plotHeight-(Y-yLow)*yScale), dataXPrimary, dataYPrimary) + labelFontF = "verdana" + labelFontS = 11 + + if loadingPlot: + xZero = -xLow*xScale+xLeftOffset + yZero = yTopOffset+plotHeight+yLow*yScale + for point in xCoord: + drawSpace.addElement(svg.line(xZero,yZero,point[0],point[1], "red", 1)) + else: + if connectdot: + pass + #drawSpace.drawPolygon(xCoord,edgeColor=plotColor,closed=0) + else: + pass + + for i, item in enumerate(xCoord): + if dataLabel and dataLabel[i] in specialCases: + drawSpace.addElement(svg.rect(item[0]-3, item[1]-3, 6, 6, "none", "green", 0.5)) + #drawSpace.drawCross(item[0],item[1],color=pid.blue,size=5) + else: + drawSpace.addElement(svg.line(item[0],item[1]+5,item[0],item[1]-5,symbolColor,1)) + drawSpace.addElement(svg.line(item[0]+5,item[1],item[0]-5,item[1],symbolColor,1)) + if showLabel and dataLabel: + pass + drawSpace.addElement(svg.text(item[0], item[1]+14, dataLabel[i], labelFontS, + labelFontF, text_anchor="middle", style="stroke:blue;stroke-width:0.5;")) + #canvas.drawString(, item[0]- canvas.stringWidth(dataLabel[i], + # font=labelFont)/2, item[1]+14, font=labelFont, color=pid.blue) + + #draw scale + #scaleFont=pid.Font(ttf="cour",size=14,bold=1) + x=xLow + for i in range(stepX+1): + xc=xLeftOffset+(x-xLow)*xScale + drawSpace.addElement(svg.line(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, axesColor, 1)) + strX = cformat(d=x, rank=rank) + drawSpace.addElement(svg.text(xc,yTopOffset+plotHeight+20,strX,13, "courier", text_anchor="middle")) + x+= (xTop - xLow)/stepX + + y=yLow + for i in range(stepY+1): + yc=yTopOffset+plotHeight-(y-yLow)*yScale + drawSpace.addElement(svg.line(xLeftOffset,yc,xLeftOffset-5,yc, axesColor, 1)) + strY = cformat(d=y, rank=rank) + drawSpace.addElement(svg.text(xLeftOffset-10,yc+5,strY,13, "courier", text_anchor="end")) + y+= (yTop - yLow)/stepY + + #draw label + labelFontF = "verdana" + labelFontS = 17 + if XLabel: + drawSpace.addElement(svg.text(xLeftOffset+plotWidth/2.0, + yTopOffset+plotHeight+yBottomOffset-10,XLabel, + labelFontS, labelFontF, text_anchor="middle")) + + if YLabel: + drawSpace.addElement(svg.text(xLeftOffset-50, + yTopOffset+plotHeight/2,YLabel, + labelFontS, labelFontF, text_anchor="middle", style="writing-mode:tb-rl", transform="rotate(270 %d %d)" % (xLeftOffset-50, yTopOffset+plotHeight/2))) + #drawSpace.drawString(YLabel, xLeftOffset-50, yTopOffset+plotHeight- (plotHeight-drawSpace.stringWidth(YLabel,font=labelFont))/2.0, + # font=labelFont,color=labelColor,angle=90) + + + if fitcurve: + sys.argv = [ "mod_python" ] + #from numarray import linear_algebra as la + #from numarray import ones, array, dot, swapaxes + fitYY = array(dataYPrimary) + fitXX = array([ones(len(dataXPrimary)),dataXPrimary]) + AA = dot(fitXX,swapaxes(fitXX,0,1)) + BB = dot(fitXX,fitYY) + bb = la.linear_least_squares(AA,BB)[0] + + xc1 = xLeftOffset + yc1 = yTopOffset+plotHeight-(bb[0]+bb[1]*xLow-yLow)*yScale + if yc1 > yTopOffset+plotHeight: + yc1 = yTopOffset+plotHeight + xc1 = (yLow-bb[0])/bb[1] + xc1=(xc1-xLow)*xScale+xLeftOffset + elif yc1 < yTopOffset: + yc1 = yTopOffset + xc1 = (yTop-bb[0])/bb[1] + xc1=(xc1-xLow)*xScale+xLeftOffset + else: + pass + + xc2 = xLeftOffset + plotWidth + yc2 = yTopOffset+plotHeight-(bb[0]+bb[1]*xTop-yLow)*yScale + if yc2 > yTopOffset+plotHeight: + yc2 = yTopOffset+plotHeight + xc2 = (yLow-bb[0])/bb[1] + xc2=(xc2-xLow)*xScale+xLeftOffset + elif yc2 < yTopOffset: + yc2 = yTopOffset + xc2 = (yTop-bb[0])/bb[1] + xc2=(xc2-xLow)*xScale+xLeftOffset + else: + pass + + drawSpace.addElement(svg.line(xc1,yc1,xc2,yc2,"green", 1)) + + if displayR: + labelFontF = "trebuc" + labelFontS = 14 + NNN = len(dataX) + + corr = webqtlUtil.calCorrelation(dataXPrimary,dataYPrimary,NNN)[0] + + if NNN < 3: + corrPValue = 1.0 + else: + if abs(corr) >= 1.0: + corrPValue = 0.0 + else: + ZValue = 0.5*log((1.0+corr)/(1.0-corr)) + ZValue = ZValue*sqrt(NNN-3) + corrPValue = 2.0*(1.0 - reaper.normp(abs(ZValue))) + + NStr = "N of Cases=%d" % NNN + + if rank == 1: + corrStr = "Spearman's r=%1.3f P=%3.2E" % (corr, corrPValue) + else: + corrStr = "Pearson's r=%1.3f P=%3.2E" % (corr, corrPValue) + + drawSpace.addElement(svg.text(xLeftOffset,yTopOffset-10,NStr, + labelFontS, labelFontF, text_anchor="start")) + drawSpace.addElement(svg.text(xLeftOffset+plotWidth,yTopOffset-25,corrStr, + labelFontS, labelFontF, text_anchor="end")) + """ + """ + return # This function determines the scale of the plot def detScaleOld(min,max): - if min>=max: - return None - elif min == -1.0 and max == 1.0: - return [-1.2,1.2,12] - else: - a=max-min - b=floor(log10(a)) - c=pow(10.0,b) - if a < c*5.0: - c/=2.0 - #print a,b,c - low=c*floor(min/c) - high=c*ceil(max/c) - return [low,high,round((high-low)/c)] + if min>=max: + return None + elif min == -1.0 and max == 1.0: + return [-1.2,1.2,12] + else: + a=max-min + b=floor(log10(a)) + c=pow(10.0,b) + if a < c*5.0: + c/=2.0 + #print a,b,c + low=c*floor(min/c) + high=c*ceil(max/c) + return [low,high,round((high-low)/c)] def detScale(min=0,max=0,bufferSpace=3): - if min>=max: - return None - elif min == -1.0 and max == 1.0: - return [-1.2,1.2,12] - else: - a=max-min - if max != 0: - max += 0.1*a - if min != 0: - if min > 0 and min < 0.1*a: - min = 0.0 - else: - min -= 0.1*a - a=max-min - b=floor(log10(a)) - c=pow(10.0,b) - low=c*floor(min/c) - high=c*ceil(max/c) - n = round((high-low)/c) - div = 2.0 - while n < 5 or n > 15: - if n < 5: - c /= div - else: - c *= div - if div == 2.0: - div =5.0 - else: - div =2.0 - low=c*floor(min/c) - high=c*ceil(max/c) - n = round((high-low)/c) - - return [low,high,n] + if min>=max: + return None + elif min == -1.0 and max == 1.0: + return [-1.2,1.2,12] + else: + a=max-min + if max != 0: + max += 0.1*a + if min != 0: + if min > 0 and min < 0.1*a: + min = 0.0 + else: + min -= 0.1*a + a=max-min + b=floor(log10(a)) + c=pow(10.0,b) + low=c*floor(min/c) + high=c*ceil(max/c) + n = round((high-low)/c) + div = 2.0 + while n < 5 or n > 15: + if n < 5: + c /= div + else: + c *= div + if div == 2.0: + div =5.0 + else: + div =2.0 + low=c*floor(min/c) + high=c*ceil(max/c) + n = round((high-low)/c) + + return [low,high,n] def colorSpectrumOld(n): - if n == 1: - return [pid.Color(1,0,0)] - elif n == 2: - return [pid.Color(1,0,0),pid.Color(0,0,1)] - elif n == 3: - return [pid.Color(1,0,0),pid.Color(0,1,0),pid.Color(0,0,1)] - else: - step = 2.0/(n-1) - red = 1.0 - green = 0.0 - blue = 0.0 - colors = [pid.Color(red,green,blue)] - i = 1 - greenpeak = 0 - while i < n: - if red >= step: - red -= step - green += step - if green >= 1.0: - greenpeak = 1 - blue += green -1.0 - green = 1.0 - else: - red = 0.0 - if greenpeak: - green -= step - blue += step - else: - green += step - if green >= 1.0: - greenpeak = 1 - blue += green -1.0 - green = 2.0 -green - elif green < 0.0: - green = 0.0 - else: - pass - colors.append(pid.Color(red,green,blue)) - i += 1 - return colors + if n == 1: + return [pid.Color(1,0,0)] + elif n == 2: + return [pid.Color(1,0,0),pid.Color(0,0,1)] + elif n == 3: + return [pid.Color(1,0,0),pid.Color(0,1,0),pid.Color(0,0,1)] + else: + step = 2.0/(n-1) + red = 1.0 + green = 0.0 + blue = 0.0 + colors = [pid.Color(red,green,blue)] + i = 1 + greenpeak = 0 + while i < n: + if red >= step: + red -= step + green += step + if green >= 1.0: + greenpeak = 1 + blue += green -1.0 + green = 1.0 + else: + red = 0.0 + if greenpeak: + green -= step + blue += step + else: + green += step + if green >= 1.0: + greenpeak = 1 + blue += green -1.0 + green = 2.0 -green + elif green < 0.0: + green = 0.0 + else: + pass + colors.append(pid.Color(red,green,blue)) + i += 1 + return colors def bluefunc(x): - return 1.0 / (1.0 + exp(-10*(x-0.6))) + return 1.0 / (1.0 + exp(-10*(x-0.6))) def redfunc(x): - return 1.0 / (1.0 + exp(10*(x-0.5))) + return 1.0 / (1.0 + exp(10*(x-0.5))) def greenfunc(x): - return 1 - pow(redfunc(x+0.2),2) - bluefunc(x-0.3) + return 1 - pow(redfunc(x+0.2),2) - bluefunc(x-0.3) def colorSpectrum(n=100): - multiple = 10 - if n == 1: - return [pid.Color(1,0,0)] - elif n == 2: - return [pid.Color(1,0,0),pid.Color(0,0,1)] - elif n == 3: - return [pid.Color(1,0,0),pid.Color(0,1,0),pid.Color(0,0,1)] - N = n*multiple - out = [None]*N; - for i in range(N): - x = float(i)/N - out[i] = pid.Color(redfunc(x), greenfunc(x), bluefunc(x)); - out2 = [out[0]] - step = N/float(n-1) - j = 0 - for i in range(n-2): - j += step - out2.append(out[int(j)]) - out2.append(out[-1]) - return out2 + multiple = 10 + if n == 1: + return [pid.Color(1,0,0)] + elif n == 2: + return [pid.Color(1,0,0),pid.Color(0,0,1)] + elif n == 3: + return [pid.Color(1,0,0),pid.Color(0,1,0),pid.Color(0,0,1)] + N = n*multiple + out = [None]*N; + for i in range(N): + x = float(i)/N + out[i] = pid.Color(redfunc(x), greenfunc(x), bluefunc(x)); + out2 = [out[0]] + step = N/float(n-1) + j = 0 + for i in range(n-2): + j += step + out2.append(out[int(j)]) + out2.append(out[-1]) + return out2 def colorSpectrumSVG(n=100): - multiple = 10 - if n == 1: - return ["rgb(255,0,0)"] - elif n == 2: - return ["rgb(255,0,0)","rgb(0,0,255)"] - elif n == 3: - return ["rgb(255,0,0)","rgb(0,255,0)","rgb(0,0,255)"] - N = n*multiple - out = [None]*N; - for i in range(N): - x = float(i)/N - out[i] = "rgb(%d, %d, %d)" % (redfunc(x)*255, greenfunc(x)*255, bluefunc(x)*255); - out2 = [out[0]] - step = N/float(n-1) - j = 0 - for i in range(n-2): - j += step - out2.append(out[int(j)]) - out2.append(out[-1]) - return out2 + multiple = 10 + if n == 1: + return ["rgb(255,0,0)"] + elif n == 2: + return ["rgb(255,0,0)","rgb(0,0,255)"] + elif n == 3: + return ["rgb(255,0,0)","rgb(0,255,0)","rgb(0,0,255)"] + N = n*multiple + out = [None]*N; + for i in range(N): + x = float(i)/N + out[i] = "rgb(%d, %d, %d)" % (redfunc(x)*255, greenfunc(x)*255, bluefunc(x)*255); + out2 = [out[0]] + step = N/float(n-1) + j = 0 + for i in range(n-2): + j += step + out2.append(out[int(j)]) + out2.append(out[-1]) + return out2 def BWSpectrum(n=100): - multiple = 10 - if n == 1: - return [pid.Color(0,0,0)] - elif n == 2: - return [pid.Color(0,0,0),pid.Color(1,1,1)] - elif n == 3: - return [pid.Color(0,0,0),pid.Color(0.5,0.5,0.5),pid.Color(1,1,1)] - - step = 1.0/n - x = 0.0 - out = [] - for i in range(n): - out.append(pid.Color(x,x,x)); - x += step - return out + multiple = 10 + if n == 1: + return [pid.Color(0,0,0)] + elif n == 2: + return [pid.Color(0,0,0),pid.Color(1,1,1)] + elif n == 3: + return [pid.Color(0,0,0),pid.Color(0.5,0.5,0.5),pid.Color(1,1,1)] + + step = 1.0/n + x = 0.0 + out = [] + for i in range(n): + out.append(pid.Color(x,x,x)); + x += step + return out diff --git a/wqflask/utility/TDCell.py b/wqflask/utility/TDCell.py index 76b9c5db..8de8e050 100755 --- a/wqflask/utility/TDCell.py +++ b/wqflask/utility/TDCell.py @@ -30,13 +30,12 @@ # ########################################################## - + class TDCell: - def __init__(self, html="", text="", val=0.0): - self.html = html #html, for web page - self.text = text #text value, for output to a text file - self.val = val #sort by value - - def __str__(self): - return self.text + def __init__(self, html="", text="", val=0.0): + self.html = html #html, for web page + self.text = text #text value, for output to a text file + self.val = val #sort by value + def __str__(self): + return self.text diff --git a/wqflask/utility/THCell.py b/wqflask/utility/THCell.py index a96b9e49..dde221b5 100755 --- a/wqflask/utility/THCell.py +++ b/wqflask/utility/THCell.py @@ -32,13 +32,11 @@ class THCell: - def __init__(self, html="", text="", sort=1, idx=-1): - self.html = html #html, for web page - self.text = text #Column text value - self.sort = sort #0: not sortable, 1: yes - self.idx = idx #sort by value - - def __str__(self): - return self.text - + def __init__(self, html="", text="", sort=1, idx=-1): + self.html = html #html, for web page + self.text = text #Column text value + self.sort = sort #0: not sortable, 1: yes + self.idx = idx #sort by value + def __str__(self): + return self.text diff --git a/wqflask/utility/svg.py b/wqflask/utility/svg.py index e49a6c3c..512bc9e6 100755 --- a/wqflask/utility/svg.py +++ b/wqflask/utility/svg.py @@ -74,7 +74,7 @@ by using easy to use classes and methods usualy you start by creating a drawing d.setSVG(s) #and finaly you xmlify the drawing d.toXml() - + this results in the svg source of the drawing, which consists of a circle on a white background. Its as easy as that;) @@ -112,7 +112,7 @@ if sys.version_info[1]<2: True=1 False=0 file=open - + sys.setrecursionlimit=50 #The recursion limit is set conservative so mistakes like s=svg() s.addElement(s) #won't eat up too much processor time. @@ -167,7 +167,7 @@ def _xypointlist(a): def _viewboxlist(a): """formats a tuple""" s='' - for e in a: + for e in a: s+=str(e)+' ' return s @@ -178,7 +178,7 @@ def _pointlist(a): class pathdata: """class used to create a pathdata object which can be used for a path. although most methods are pretty straightforward it might be useful to look at the SVG specification.""" - #I didn't test the methods below. + #I didn't test the methods below. def __init__(self,x=None,y=None): self.path=[] if x is not None and y is not None: @@ -242,10 +242,10 @@ class pathdata: self.path.append('a'+str(rx)+','+str(ry)+' '+str(xrot)+' '+str(laf)+' '+str(sf)+' '+str(x)+' '+str(y)) def __repr__(self): return ' '.join(self.path) - - + + class SVGelement: """SVGelement(type,attributes,elements,text,namespace,**args) Creates a arbitrary svg element and is intended to be subclassed not used on its own. @@ -296,7 +296,7 @@ class SVGelement: if self.cdata: f.write('\n'+'\t'*(level+1)+'\n') if self.text: if type(self.text)==type(''): #If the text is only text @@ -305,13 +305,13 @@ class SVGelement: f.write(str(self.text)) if self.elements: f.write('\t'*level+'\n') - elif self.text: + elif self.text: f.write('\n') elif self.cdata: f.write('\t'*level+'\n') else: f.write('/>\n') - + class tspan(SVGelement): """ts=tspan(text='',**args) @@ -330,12 +330,12 @@ class tspan(SVGelement): def __repr__(self): s="None: self.attributes['stroke-width']=stroke_width - + class ellipse(SVGelement): """e=ellipse(rx,ry,x,y,fill,stroke,stroke_width,**args) @@ -440,8 +440,8 @@ class ellipse(SVGelement): self.attributes['stroke']=stroke if stroke_width<>None: self.attributes['stroke-width']=stroke_width - - + + class circle(SVGelement): """c=circle(x,y,radius,fill,stroke,stroke_width,**args) @@ -464,7 +464,7 @@ class circle(SVGelement): class point(circle): """p=point(x,y,color) - + A point is defined as a circle with a size 1 radius. It may be more efficient to use a very small rectangle if you use many points because a circle is difficult to render. """ @@ -473,7 +473,7 @@ class point(circle): class line(SVGelement): """l=line(x1,y1,x2,y2,stroke,stroke_width,**args) - + A line is defined by a begin x,y pair and an end x,y pair """ def __init__(self,x1=None,y1=None,x2=None,y2=None,stroke=None,stroke_width=None,**args): @@ -490,10 +490,10 @@ class line(SVGelement): self.attributes['stroke-width']=stroke_width if stroke<>None: self.attributes['stroke']=stroke - + class polyline(SVGelement): """pl=polyline([[x1,y1],[x2,y2],...],fill,stroke,stroke_width,**args) - + a polyline is defined by a list of xy pairs """ def __init__(self,points,fill=None,stroke=None,stroke_width=None,**args): @@ -507,7 +507,7 @@ class polyline(SVGelement): class polygon(SVGelement): """pl=polyline([[x1,y1],[x2,y2],...],fill,stroke,stroke_width,**args) - + a polygon is defined by a list of xy pairs """ def __init__(self,points,fill=None,stroke=None,stroke_width=None,**args): @@ -534,11 +534,11 @@ class path(SVGelement): self.attributes['stroke-width']=stroke_width if id<>None: self.attributes['id']=id - - + + class text(SVGelement): """t=text(x,y,text,font_size,font_family,**args) - + a text element can bge used for displaying text on the screen """ def __init__(self,x=None,y=None,text=None,font_size=None,font_family=None,text_anchor=None,**args): @@ -560,7 +560,7 @@ class text(SVGelement): class textpath(SVGelement): """tp=textpath(text,link,**args) - a textpath places a text on a path which is referenced by a link. + a textpath places a text on a path which is referenced by a link. """ def __init__(self,link,text=None,**args): SVGelement.__init__(self,'textPath',{'xlink:href':link},**args) @@ -589,7 +589,7 @@ class pattern(SVGelement): class title(SVGelement): """t=title(text,**args) - + a title is a text element. The text is displayed in the title bar add at least one to the root svg element """ @@ -600,7 +600,7 @@ class title(SVGelement): class description(SVGelement): """d=description(text,**args) - + a description can be added to any element and is used for a tooltip Add this element before adding other elements. """ @@ -648,7 +648,7 @@ class radialgradient(SVGelement): self.attributes['fy']=fy if id<>None: self.attributes['id']=id - + class stop(SVGelement): """st=stop(offset,stop_color,**args) @@ -658,7 +658,7 @@ class stop(SVGelement): SVGelement.__init__(self,'stop',{'offset':offset},**args) if stop_color<>None: self.attributes['stop-color']=stop_color - + class style(SVGelement): """st=style(type,cdata=None,**args) @@ -666,8 +666,8 @@ class style(SVGelement): """ def __init__(self,type,cdata=None,**args): SVGelement.__init__(self,'style',{'type':type},cdata=cdata, **args) - - + + class image(SVGelement): """im=image(url,width,height,x,y,**args) @@ -686,7 +686,7 @@ class image(SVGelement): self.attributes['x']=x if y<>None: self.attributes['y']=y - + class cursor(SVGelement): """c=cursor(url,**args) @@ -695,10 +695,10 @@ class cursor(SVGelement): def __init__(self,url,**args): SVGelement.__init__(self,'cursor',{'xlink:href':url},**args) - + class marker(SVGelement): """m=marker(id,viewbox,refX,refY,markerWidth,markerHeight,**args) - + defines a marker which can be used as an endpoint for a line or other pathtypes add an element to it which should be used as a marker. """ @@ -716,10 +716,10 @@ class marker(SVGelement): self.attributes['markerWidth']=markerWidth if markerHeight<>None: self.attributes['markerHeight']=markerHeight - + class group(SVGelement): """g=group(id,**args) - + a group is defined by an id and is used to contain elements g.addElement(SVGelement) """ @@ -736,14 +736,14 @@ class symbol(SVGelement): display it by referencing its id. sy.addElement(SVGelement) """ - + def __init__(self,id=None,viewBox=None,**args): SVGelement.__init__(self,'symbol',**args) if id<>None: self.attributes['id']=id if viewBox<>None: self.attributes['viewBox']=_viewboxlist(viewBox) - + class defs(SVGelement): """d=defs(**args) @@ -762,10 +762,10 @@ class switch(SVGelement): def __init__(self,**args): SVGelement.__init__(self,'switch',**args) - + class use(SVGelement): """u=use(link,x,y,width,height,**args) - + references a symbol by linking to its id and its position, height and width """ def __init__(self,link,x=None,y=None,width=None,height=None,**args): @@ -779,8 +779,8 @@ class use(SVGelement): self.attributes['width']=width if height<>None: self.attributes['height']=height - - + + class link(SVGelement): """a=link(url,**args) @@ -789,7 +789,7 @@ class link(SVGelement): """ def __init__(self,link='',**args): SVGelement.__init__(self,'a',{'xlink:href':link},**args) - + class view(SVGelement): """v=view(id,**args) @@ -807,11 +807,11 @@ class script(SVGelement): """ def __init__(self,type,cdata=None,**args): SVGelement.__init__(self,'script',{'type':type},cdata=cdata,**args) - + class animate(SVGelement): """an=animate(attribute,from,to,during,**args) - animates an attribute. + animates an attribute. """ def __init__(self,attribute,fr=None,to=None,dur=None,**args): SVGelement.__init__(self,'animate',{'attributeName':attribute},**args) @@ -821,7 +821,7 @@ class animate(SVGelement): self.attributes['to']=to if dur<>None: self.attributes['dur']=dur - + class animateMotion(SVGelement): """an=animateMotion(pathdata,dur,**args) @@ -836,7 +836,7 @@ class animateMotion(SVGelement): class animateTransform(SVGelement): """antr=animateTransform(type,from,to,dur,**args) - + transform an element from and to a value. """ def __init__(self,type=None,fr=None,to=None,dur=None,**args): @@ -864,10 +864,10 @@ class animateColor(SVGelement): if to<>None: self.attributes['to']=to if dur<>None: - self.attributes['dur']=dur + self.attributes['dur']=dur class set(SVGelement): """st=set(attribute,to,during,**args) - + sets an attribute to a value for a """ def __init__(self,attribute,to=None,dur=None,**args): @@ -878,10 +878,10 @@ class set(SVGelement): self.attributes['dur']=dur - + class svg(SVGelement): """s=svg(viewbox,width,height,**args) - + a svg or element is the root of a drawing add all elements to a svg element. You can have different svg elements in one svg file s.addElement(SVGelement) @@ -903,7 +903,7 @@ class svg(SVGelement): if height<>None: self.attributes['height']=height self.namespace="http://www.w3.org/2000/svg" - + class drawing: """d=drawing() @@ -921,17 +921,17 @@ class drawing: def setSVG(self,svg): self.svg=svg #Voeg een element toe aan de grafiek toe. - if use_dom_implementation==0: + if use_dom_implementation==0: def toXml(self, filename='',compress=False): import cStringIO xml=cStringIO.StringIO() xml.write("\n") xml.write("\n" % (item, self.entity[item])) - xml.write("]") + xml.write(" [\n") + for item in self.entity.keys(): + xml.write("\n" % (item, self.entity[item])) + xml.write("]") xml.write(">\n") self.svg.toXml(0,xml) if not filename: @@ -964,7 +964,7 @@ class drawing: compresses if filename ends with svgz or if compress is true """ doctype = implementation.createDocumentType('svg',"-//W3C//DTD SVG 1.0//EN""",'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd ') - + global root #root is defined global so it can be used by the appender. Its also possible to use it as an arugument but #that is a bit messy. @@ -1034,12 +1034,12 @@ class drawing: print "SVG well formed" if __name__=='__main__': - + d=drawing() s=svg((0,0,100,100)) r=rect(-100,-100,300,300,'cyan') s.addElement(r) - + t=title('SVGdraw Demo') s.addElement(t) g=group('animations') @@ -1064,6 +1064,5 @@ if __name__=='__main__': c=circle(i,j,1,'red','black',.5) s.addElement(c) d.setSVG(s) - - print d.toXml() + print d.toXml() diff --git a/wqflask/utility/webqtlUtil.py b/wqflask/utility/webqtlUtil.py index 6af7f846..6409e781 100755 --- a/wqflask/utility/webqtlUtil.py +++ b/wqflask/utility/webqtlUtil.py @@ -90,741 +90,741 @@ PROGRESSBAR = HT.Image('/images/waitAnima2.gif', alt='checkblue',align="middle", ######################################### def decodeEscape(str): - a = str - pattern = re.compile('(%[0-9A-Fa-f][0-9A-Fa-f])') - match = pattern.findall(a) - matched = [] - for item in match: - if item not in matched: - a = a.replace(item, '%c' % eval("0x"+item[-2:])) - matched.append(item) - return a - + a = str + pattern = re.compile('(%[0-9A-Fa-f][0-9A-Fa-f])') + match = pattern.findall(a) + matched = [] + for item in match: + if item not in matched: + a = a.replace(item, '%c' % eval("0x"+item[-2:])) + matched.append(item) + return a + def exportData(hddn, tdata, NP = None): - for key in tdata.keys(): - _val, _var, _N = tdata[key].val, tdata[key].var, tdata[key].N - if _val != None: - hddn[key] = _val - if _var != None: - hddn['V'+key] = _var - if NP and _N != None: - hddn['N'+key] = _N - + for key in tdata.keys(): + _val, _var, _N = tdata[key].val, tdata[key].var, tdata[key].N + if _val != None: + hddn[key] = _val + if _var != None: + hddn['V'+key] = _var + if NP and _N != None: + hddn['N'+key] = _N + def genShortStrainName(RISet='', input_strainName=''): - #aliasStrainDict = {'C57BL/6J':'B6','DBA/2J':'D2'} - strainName = input_strainName - if RISet != 'AXBXA': - if RISet == 'BXD300': - this_RISet = 'BXD' - elif RISet == 'BDF2-2005': - this_RISet = 'CASE05_' - else: - this_RISet = RISet - strainName = string.replace(strainName,this_RISet,'') - strainName = string.replace(strainName,'CASE','') - try: - strainName = "%02d" % int(strainName) - except: - pass - else: - strainName = string.replace(strainName,'AXB','A') - strainName = string.replace(strainName,'BXA','B') - try: - strainName = strainName[0] + "%02d" % int(strainName[1:]) - except: - pass - return strainName + #aliasStrainDict = {'C57BL/6J':'B6','DBA/2J':'D2'} + strainName = input_strainName + if RISet != 'AXBXA': + if RISet == 'BXD300': + this_RISet = 'BXD' + elif RISet == 'BDF2-2005': + this_RISet = 'CASE05_' + else: + this_RISet = RISet + strainName = string.replace(strainName,this_RISet,'') + strainName = string.replace(strainName,'CASE','') + try: + strainName = "%02d" % int(strainName) + except: + pass + else: + strainName = string.replace(strainName,'AXB','A') + strainName = string.replace(strainName,'BXA','B') + try: + strainName = strainName[0] + "%02d" % int(strainName[1:]) + except: + pass + return strainName def toInt(in_str): - "Converts an arbitrary string to an unsigned integer" - start = -1 - end = -1 - for i, char in enumerate(in_str): - if char >= '0' and char <= '9': - if start < 0: - start = i - end = i+1 - else: - if start >= 0: - break - if start < end: - return int(in_str[start:end]) - else: - return -1 + "Converts an arbitrary string to an unsigned integer" + start = -1 + end = -1 + for i, char in enumerate(in_str): + if char >= '0' and char <= '9': + if start < 0: + start = i + end = i+1 + else: + if start >= 0: + break + if start < end: + return int(in_str[start:end]) + else: + return -1 def transpose(m): - 'transpose a matrix' - n = len(m) - return [[m[j][i] for i in range(len(m[0])) for j in range(n)][k*n:k*n+n] for k in range(len(m[0]))] + 'transpose a matrix' + n = len(m) + return [[m[j][i] for i in range(len(m[0])) for j in range(n)][k*n:k*n+n] for k in range(len(m[0]))] def asymTranspose(m): - 'transpose a matrix' - t = max(map(len, m)) - n = len(m) - m2 = [["-"]]*n - for i in range(n): - m2[i] = m[i] + [""]*(t- len(m[i])) - return [[m2[j][i] for i in range(len(m2[0])) for j in range(n)][k*n:k*n+n] for k in range(len(m2[0]))] + 'transpose a matrix' + t = max(map(len, m)) + n = len(m) + m2 = [["-"]]*n + for i in range(n): + m2[i] = m[i] + [""]*(t- len(m[i])) + return [[m2[j][i] for i in range(len(m2[0])) for j in range(n)][k*n:k*n+n] for k in range(len(m2[0]))] def genRandStr(prefix = "", length=8, chars=string.letters+string.digits): - from random import choice - _str = prefix[:] - for i in range(length): - _str += choice(chars) - return _str + from random import choice + _str = prefix[:] + for i in range(length): + _str += choice(chars) + return _str def generate_session(): - import sha - return sha.new(str(time.time())).hexdigest() + import sha + return sha.new(str(time.time())).hexdigest() def cvt2Dict(x): - tmp = {} - for key in x.keys(): - tmp[key] = x[key] - return tmp + tmp = {} + for key in x.keys(): + tmp[key] = x[key] + return tmp def dump_session(session_obj, filename): - "It seems mod python can only cPickle most basic data type" - import cPickle - session_file = open(filename, 'wb') - #try: - # pass - #except: - # pass - cPickle.dump(session_obj, session_file) - session_file.close() - + "It seems mod python can only cPickle most basic data type" + import cPickle + session_file = open(filename, 'wb') + #try: + # pass + #except: + # pass + cPickle.dump(session_obj, session_file) + session_file.close() + def StringAsFloat(str): - 'Converts string to float but catches any exception and returns None' - try: - return float(str) - except: - return None - + 'Converts string to float but catches any exception and returns None' + try: + return float(str) + except: + return None + def IntAsFloat(str): - 'Converts string to Int but catches any exception and returns None' - try: - return int(str) - except: - return None - + 'Converts string to Int but catches any exception and returns None' + try: + return int(str) + except: + return None + def FloatAsFloat(flt): - 'Converts float to string but catches any exception and returns None' - try: - return float("%2.3f" % flt) - except: - return None + 'Converts float to string but catches any exception and returns None' + try: + return float("%2.3f" % flt) + except: + return None def RemoveZero(flt): - 'Converts string to float but catches any exception and returns None' - try: - if abs(flt) < 1e-6: - return None - else: - return flt - except: - return None + 'Converts string to float but catches any exception and returns None' + try: + if abs(flt) < 1e-6: + return None + else: + return flt + except: + return None def SciFloat(d): - 'Converts string to float but catches any exception and returns None' + 'Converts string to float but catches any exception and returns None' - try: - if abs(d) <= 1.0e-4: - return "%1.2e" % d - else: - return "%1.5f" % d - except: - return None + try: + if abs(d) <= 1.0e-4: + return "%1.2e" % d + else: + return "%1.5f" % d + except: + return None ###To be removed def FloatList2String(lst): - 'Converts float list to string but catches any exception and returns None' - tt='' - try: - for item in lst: - if item == None: - tt += 'X ' - else: - tt += '%f ' % item - return tt - except: - return "" + 'Converts float list to string but catches any exception and returns None' + tt='' + try: + for item in lst: + if item == None: + tt += 'X ' + else: + tt += '%f ' % item + return tt + except: + return "" def ListNotNull(lst): - 'Determine if the elements in a list are all null' - for item in lst: - if item is not None: - return 1 - return None - + 'Determine if the elements in a list are all null' + for item in lst: + if item is not None: + return 1 + return None + ###To be removed def FileDataProcess(str): - 'Remove the description text from the input file if theres any' - i=0 - while i'\x20': - break - else: - i+=1 - str=str[i:] - str=string.join(string.split(str,'\000'),'') - i=string.find(str,"*****") - if i>-1: - return str[i+5:] - else: - return str + 'Remove the description text from the input file if theres any' + i=0 + while i'\x20': + break + else: + i+=1 + str=str[i:] + str=string.join(string.split(str,'\000'),'') + i=string.find(str,"*****") + if i>-1: + return str[i+5:] + else: + return str def rank(a,lst,offset=0): - """Calculate the integer rank of a number in an array, can be used to calculate p-value""" - n = len(lst) - if n == 2: - if a lst[1]: - return offset + 2 - else: - return offset +1 - elif n == 1: - if a lst[1]: + return offset + 2 + else: + return offset +1 + elif n == 1: + if a B.LRS: - return 1 - elif A.LRS == B.LRS: - return 0 - else: - return -1 - except: - return 0 - - + try: + if A.LRS > B.LRS: + return 1 + elif A.LRS == B.LRS: + return 0 + else: + return -1 + except: + return 0 + + def cmpScanResult2(A,B): - try: - if A.LRS < B.LRS: - return 1 - elif A.LRS == B.LRS: - return 0 - else: - return -1 - except: - return 0 + try: + if A.LRS < B.LRS: + return 1 + elif A.LRS == B.LRS: + return 0 + else: + return -1 + except: + return 0 def cmpOrder(A,B): - try: - if A[1] < B[1]: - return -1 - elif A[1] == B[1]: - return 0 - else: - return 1 - except: - return 0 + try: + if A[1] < B[1]: + return -1 + elif A[1] == B[1]: + return 0 + else: + return 1 + except: + return 0 def cmpOrder2(A,B): - try: - if A[-1] < B[-1]: - return -1 - elif A[-1] == B[-1]: - return 0 - else: - return 1 - except: - return 0 + try: + if A[-1] < B[-1]: + return -1 + elif A[-1] == B[-1]: + return 0 + else: + return 1 + except: + return 0 def calRank(xVals, yVals, N): ### Zach Sloan, February 4 2010 - """ - Returns a ranked set of X and Y values. These are used when generating - a Spearman scatterplot. Bear in mind that this sets values equal to each - other as the same rank. - """ - XX = [] - YY = [] - X = [0]*len(xVals) - Y = [0]*len(yVals) - j = 0 - - for i in range(len(xVals)): - - if xVals[i] != None and yVals[i] != None: - XX.append((j, xVals[i])) - YY.append((j, yVals[i])) - j = j + 1 - - NN = len(XX) - - XX.sort(cmpOrder2) - YY.sort(cmpOrder2) - - j = 1 - rank = 0.0 - - while j < NN: - - if XX[j][1] != XX[j-1][1]: - X[XX[j-1][0]] = j - j = j+1 - - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (XX[jt][1] != XX[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - X[XX[ji][0]] = rank - if (jt == NN-1): - if (XX[jt][1] == XX[j-1][1]): - X[XX[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if X[XX[NN-1][0]] == 0: - X[XX[NN-1][0]] = NN - - j = 1 - rank = 0.0 - - while j < NN: - - if YY[j][1] != YY[j-1][1]: - Y[YY[j-1][0]] = j - j = j+1 - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (YY[jt][1] != YY[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - Y[YY[ji][0]] = rank - if (jt == NN-1): - if (YY[jt][1] == YY[j-1][1]): - Y[YY[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if Y[YY[NN-1][0]] == 0: - Y[YY[NN-1][0]] = NN - - return (X,Y) + """ + Returns a ranked set of X and Y values. These are used when generating + a Spearman scatterplot. Bear in mind that this sets values equal to each + other as the same rank. + """ + XX = [] + YY = [] + X = [0]*len(xVals) + Y = [0]*len(yVals) + j = 0 + + for i in range(len(xVals)): + + if xVals[i] != None and yVals[i] != None: + XX.append((j, xVals[i])) + YY.append((j, yVals[i])) + j = j + 1 + + NN = len(XX) + + XX.sort(cmpOrder2) + YY.sort(cmpOrder2) + + j = 1 + rank = 0.0 + + while j < NN: + + if XX[j][1] != XX[j-1][1]: + X[XX[j-1][0]] = j + j = j+1 + + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (XX[jt][1] != XX[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + X[XX[ji][0]] = rank + if (jt == NN-1): + if (XX[jt][1] == XX[j-1][1]): + X[XX[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if X[XX[NN-1][0]] == 0: + X[XX[NN-1][0]] = NN + + j = 1 + rank = 0.0 + + while j < NN: + + if YY[j][1] != YY[j-1][1]: + Y[YY[j-1][0]] = j + j = j+1 + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (YY[jt][1] != YY[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + Y[YY[ji][0]] = rank + if (jt == NN-1): + if (YY[jt][1] == YY[j-1][1]): + Y[YY[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if Y[YY[NN-1][0]] == 0: + Y[YY[NN-1][0]] = NN + + return (X,Y) def calCorrelationRank(xVals,yVals,N): - """ - Calculated Spearman Ranked Correlation. The algorithm works - by setting all tied ranks to the average of those ranks (for - example, if ranks 5-10 all have the same value, each will be set - to rank 7.5). - """ - - XX = [] - YY = [] - j = 0 - - for i in range(len(xVals)): - if xVals[i]!= None and yVals[i]!= None: - XX.append((j,xVals[i])) - YY.append((j,yVals[i])) - j = j+1 - - NN = len(XX) - if NN <6: - return (0.0,NN) - XX.sort(cmpOrder2) - YY.sort(cmpOrder2) - X = [0]*NN - Y = [0]*NN - - j = 1 - rank = 0.0 - t = 0.0 - sx = 0.0 - - while j < NN: - - if XX[j][1] != XX[j-1][1]: - X[XX[j-1][0]] = j - j = j+1 - - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (XX[jt][1] != XX[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - X[XX[ji][0]] = rank - t = jt-j - sx = sx + (t*t*t-t) - if (jt == NN-1): - if (XX[jt][1] == XX[j-1][1]): - X[XX[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if X[XX[NN-1][0]] == 0: - X[XX[NN-1][0]] = NN - - j = 1 - rank = 0.0 - t = 0.0 - sy = 0.0 - - while j < NN: - - if YY[j][1] != YY[j-1][1]: - Y[YY[j-1][0]] = j - j = j+1 - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (YY[jt][1] != YY[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - Y[YY[ji][0]] = rank - t = jt - j - sy = sy + (t*t*t-t) - if (jt == NN-1): - if (YY[jt][1] == YY[j-1][1]): - Y[YY[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if Y[YY[NN-1][0]] == 0: - Y[YY[NN-1][0]] = NN - - D = 0.0 - - for i in range(NN): - D += (X[i]-Y[i])*(X[i]-Y[i]) - - fac = (1.0 -sx/(NN*NN*NN-NN))*(1.0-sy/(NN*NN*NN-NN)) - - return ((1-(6.0/(NN*NN*NN-NN))*(D+(sx+sy)/12.0))/math.sqrt(fac),NN) - - + """ + Calculated Spearman Ranked Correlation. The algorithm works + by setting all tied ranks to the average of those ranks (for + example, if ranks 5-10 all have the same value, each will be set + to rank 7.5). + """ + + XX = [] + YY = [] + j = 0 + + for i in range(len(xVals)): + if xVals[i]!= None and yVals[i]!= None: + XX.append((j,xVals[i])) + YY.append((j,yVals[i])) + j = j+1 + + NN = len(XX) + if NN <6: + return (0.0,NN) + XX.sort(cmpOrder2) + YY.sort(cmpOrder2) + X = [0]*NN + Y = [0]*NN + + j = 1 + rank = 0.0 + t = 0.0 + sx = 0.0 + + while j < NN: + + if XX[j][1] != XX[j-1][1]: + X[XX[j-1][0]] = j + j = j+1 + + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (XX[jt][1] != XX[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + X[XX[ji][0]] = rank + t = jt-j + sx = sx + (t*t*t-t) + if (jt == NN-1): + if (XX[jt][1] == XX[j-1][1]): + X[XX[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if X[XX[NN-1][0]] == 0: + X[XX[NN-1][0]] = NN + + j = 1 + rank = 0.0 + t = 0.0 + sy = 0.0 + + while j < NN: + + if YY[j][1] != YY[j-1][1]: + Y[YY[j-1][0]] = j + j = j+1 + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (YY[jt][1] != YY[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + Y[YY[ji][0]] = rank + t = jt - j + sy = sy + (t*t*t-t) + if (jt == NN-1): + if (YY[jt][1] == YY[j-1][1]): + Y[YY[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if Y[YY[NN-1][0]] == 0: + Y[YY[NN-1][0]] = NN + + D = 0.0 + + for i in range(NN): + D += (X[i]-Y[i])*(X[i]-Y[i]) + + fac = (1.0 -sx/(NN*NN*NN-NN))*(1.0-sy/(NN*NN*NN-NN)) + + return ((1-(6.0/(NN*NN*NN-NN))*(D+(sx+sy)/12.0))/math.sqrt(fac),NN) + + def calCorrelationRankText(dbdata,userdata,N): ### dcrowell = David Crowell, July 2008 - """Calculates correlation ranks with data formatted from the text file. - dbdata, userdata are lists of strings. N is an int. Returns a float. - Used by correlationPage""" - XX = [] - YY = [] - j = 0 - for i in range(N): - if (dbdata[i]!= None and userdata[i]!=None) and (dbdata[i]!= 'None' and userdata[i]!='None'): - XX.append((j,float(dbdata[i]))) - YY.append((j,float(userdata[i]))) - j += 1 - NN = len(XX) - if NN <6: - return (0.0,NN) - XX.sort(cmpOrder2) - YY.sort(cmpOrder2) - X = [0]*NN - Y = [0]*NN - - j = 1 - rank = 0.0 - t = 0.0 - sx = 0.0 - - while j < NN: - - if XX[j][1] != XX[j-1][1]: - X[XX[j-1][0]] = j - j = j+1 - - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (XX[jt][1] != XX[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - X[XX[ji][0]] = rank - t = jt-j - sx = sx + (t*t*t-t) - if (jt == NN-1): - if (XX[jt][1] == XX[j-1][1]): - X[XX[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if X[XX[NN-1][0]] == 0: - X[XX[NN-1][0]] = NN - - j = 1 - rank = 0.0 - t = 0.0 - sy = 0.0 - - while j < NN: - - if YY[j][1] != YY[j-1][1]: - Y[YY[j-1][0]] = j - j = j+1 - else: - jt = j+1 - ji = j - for jt in range(j+1, NN): - if (YY[jt][1] != YY[j-1][1]): - break - rank = 0.5*(j+jt) - for ji in range(j-1, jt): - Y[YY[ji][0]] = rank - t = jt - j - sy = sy + (t*t*t-t) - if (jt == NN-1): - if (YY[jt][1] == YY[j-1][1]): - Y[YY[NN-1][0]] = rank - j = jt+1 - - if j == NN: - if Y[YY[NN-1][0]] == 0: - Y[YY[NN-1][0]] = NN - - D = 0.0 - - for i in range(NN): - D += (X[i]-Y[i])*(X[i]-Y[i]) - - fac = (1.0 -sx/(NN*NN*NN-NN))*(1.0-sy/(NN*NN*NN-NN)) - - return ((1-(6.0/(NN*NN*NN-NN))*(D+(sx+sy)/12.0))/math.sqrt(fac),NN) + """Calculates correlation ranks with data formatted from the text file. + dbdata, userdata are lists of strings. N is an int. Returns a float. + Used by correlationPage""" + XX = [] + YY = [] + j = 0 + for i in range(N): + if (dbdata[i]!= None and userdata[i]!=None) and (dbdata[i]!= 'None' and userdata[i]!='None'): + XX.append((j,float(dbdata[i]))) + YY.append((j,float(userdata[i]))) + j += 1 + NN = len(XX) + if NN <6: + return (0.0,NN) + XX.sort(cmpOrder2) + YY.sort(cmpOrder2) + X = [0]*NN + Y = [0]*NN + + j = 1 + rank = 0.0 + t = 0.0 + sx = 0.0 + + while j < NN: + + if XX[j][1] != XX[j-1][1]: + X[XX[j-1][0]] = j + j = j+1 + + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (XX[jt][1] != XX[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + X[XX[ji][0]] = rank + t = jt-j + sx = sx + (t*t*t-t) + if (jt == NN-1): + if (XX[jt][1] == XX[j-1][1]): + X[XX[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if X[XX[NN-1][0]] == 0: + X[XX[NN-1][0]] = NN + + j = 1 + rank = 0.0 + t = 0.0 + sy = 0.0 + + while j < NN: + + if YY[j][1] != YY[j-1][1]: + Y[YY[j-1][0]] = j + j = j+1 + else: + jt = j+1 + ji = j + for jt in range(j+1, NN): + if (YY[jt][1] != YY[j-1][1]): + break + rank = 0.5*(j+jt) + for ji in range(j-1, jt): + Y[YY[ji][0]] = rank + t = jt - j + sy = sy + (t*t*t-t) + if (jt == NN-1): + if (YY[jt][1] == YY[j-1][1]): + Y[YY[NN-1][0]] = rank + j = jt+1 + + if j == NN: + if Y[YY[NN-1][0]] == 0: + Y[YY[NN-1][0]] = NN + + D = 0.0 + + for i in range(NN): + D += (X[i]-Y[i])*(X[i]-Y[i]) + + fac = (1.0 -sx/(NN*NN*NN-NN))*(1.0-sy/(NN*NN*NN-NN)) + + return ((1-(6.0/(NN*NN*NN-NN))*(D+(sx+sy)/12.0))/math.sqrt(fac),NN) def calCorrelation(dbdata,userdata,N): - X = [] - Y = [] - for i in range(N): - if dbdata[i]!= None and userdata[i]!= None: - X.append(dbdata[i]) - Y.append(userdata[i]) - NN = len(X) - if NN <6: - return (0.0,NN) - sx = reduce(lambda x,y:x+y,X,0.0) - sy = reduce(lambda x,y:x+y,Y,0.0) - meanx = sx/NN - meany = sy/NN - xyd = 0.0 - sxd = 0.0 - syd = 0.0 - for i in range(NN): - xyd += (X[i] - meanx)*(Y[i]-meany) - sxd += (X[i] - meanx)*(X[i] - meanx) - syd += (Y[i] - meany)*(Y[i] - meany) - try: - corr = xyd/(sqrt(sxd)*sqrt(syd)) - except: - corr = 0 - return (corr,NN) + X = [] + Y = [] + for i in range(N): + if dbdata[i]!= None and userdata[i]!= None: + X.append(dbdata[i]) + Y.append(userdata[i]) + NN = len(X) + if NN <6: + return (0.0,NN) + sx = reduce(lambda x,y:x+y,X,0.0) + sy = reduce(lambda x,y:x+y,Y,0.0) + meanx = sx/NN + meany = sy/NN + xyd = 0.0 + sxd = 0.0 + syd = 0.0 + for i in range(NN): + xyd += (X[i] - meanx)*(Y[i]-meany) + sxd += (X[i] - meanx)*(X[i] - meanx) + syd += (Y[i] - meany)*(Y[i] - meany) + try: + corr = xyd/(sqrt(sxd)*sqrt(syd)) + except: + corr = 0 + return (corr,NN) def calCorrelationText(dbdata,userdata,N): ### dcrowell July 2008 - """Calculates correlation coefficients with values formatted from text files. dbdata, userdata are lists of strings. N is an int. Returns a float - Used by correlationPage""" - X = [] - Y = [] - for i in range(N): - #if (dbdata[i]!= None and userdata[i]!= None) and (dbdata[i]!= 'None' and userdata[i]!= 'None'): - # X.append(float(dbdata[i])) - # Y.append(float(userdata[i])) - if dbdata[i] == None or dbdata[i] == 'None' or userdata[i] == None or userdata[i] == 'None': - continue - else: - X.append(float(dbdata[i])) - Y.append(float(userdata[i])) - NN = len(X) - if NN <6: - return (0.0,NN) - sx = sum(X) - sy = sum(Y) - meanx = sx/float(NN) - meany = sy/float(NN) - xyd = 0.0 - sxd = 0.0 - syd = 0.0 - for i in range(NN): - x1 = X[i]-meanx - y1 = Y[i]-meany - xyd += x1*y1 - sxd += x1**2 - syd += y1**2 - try: - corr = xyd/(sqrt(sxd)*sqrt(syd)) - except: - corr = 0 - return (corr,NN) + """Calculates correlation coefficients with values formatted from text files. dbdata, userdata are lists of strings. N is an int. Returns a float + Used by correlationPage""" + X = [] + Y = [] + for i in range(N): + #if (dbdata[i]!= None and userdata[i]!= None) and (dbdata[i]!= 'None' and userdata[i]!= 'None'): + # X.append(float(dbdata[i])) + # Y.append(float(userdata[i])) + if dbdata[i] == None or dbdata[i] == 'None' or userdata[i] == None or userdata[i] == 'None': + continue + else: + X.append(float(dbdata[i])) + Y.append(float(userdata[i])) + NN = len(X) + if NN <6: + return (0.0,NN) + sx = sum(X) + sy = sum(Y) + meanx = sx/float(NN) + meany = sy/float(NN) + xyd = 0.0 + sxd = 0.0 + syd = 0.0 + for i in range(NN): + x1 = X[i]-meanx + y1 = Y[i]-meany + xyd += x1*y1 + sxd += x1**2 + syd += y1**2 + try: + corr = xyd/(sqrt(sxd)*sqrt(syd)) + except: + corr = 0 + return (corr,NN) def readLineCSV(line): ### dcrowell July 2008 - """Parses a CSV string of text and returns a list containing each element as a string. - Used by correlationPage""" - returnList = line.split('","') - returnList[-1]=returnList[-1][:-2] - returnList[0]=returnList[0][1:] - return returnList + """Parses a CSV string of text and returns a list containing each element as a string. + Used by correlationPage""" + returnList = line.split('","') + returnList[-1]=returnList[-1][:-2] + returnList[0]=returnList[0][1:] + return returnList def cmpCorr(A,B): - try: - if abs(A[1]) < abs(B[1]): - return 1 - elif abs(A[1]) == abs(B[1]): - return 0 - else: - return -1 - except: - return 0 + try: + if abs(A[1]) < abs(B[1]): + return 1 + elif abs(A[1]) == abs(B[1]): + return 0 + else: + return -1 + except: + return 0 def cmpLitCorr(A,B): - try: - if abs(A[3]) < abs(B[3]): return 1 - elif abs(A[3]) == abs(B[3]): - if abs(A[1]) < abs(B[1]): return 1 - elif abs(A[1]) == abs(B[1]): return 0 - else: return -1 - else: return -1 - except: - return 0 + try: + if abs(A[3]) < abs(B[3]): return 1 + elif abs(A[3]) == abs(B[3]): + if abs(A[1]) < abs(B[1]): return 1 + elif abs(A[1]) == abs(B[1]): return 0 + else: return -1 + else: return -1 + except: + return 0 def cmpPValue(A,B): - try: - if A.corrPValue < B.corrPValue: - return -1 - elif A.corrPValue == B.corrPValue: - if abs(A.corr) > abs(B.corr): - return -1 - elif abs(A.corr) < abs(B.corr): - return 1 - else: - return 0 - else: - return 1 - except: - return 0 + try: + if A.corrPValue < B.corrPValue: + return -1 + elif A.corrPValue == B.corrPValue: + if abs(A.corr) > abs(B.corr): + return -1 + elif abs(A.corr) < abs(B.corr): + return 1 + else: + return 0 + else: + return 1 + except: + return 0 def cmpEigenValue(A,B): - try: - if A[0] > B[0]: - return -1 - elif A[0] == B[0]: - return 0 - else: - return 1 - except: - return 0 + try: + if A[0] > B[0]: + return -1 + elif A[0] == B[0]: + return 0 + else: + return 1 + except: + return 0 def cmpLRSFull(A,B): - try: - if A[0] < B[0]: - return -1 - elif A[0] == B[0]: - return 0 - else: - return 1 - except: - return 0 + try: + if A[0] < B[0]: + return -1 + elif A[0] == B[0]: + return 0 + else: + return 1 + except: + return 0 def cmpLRSInteract(A,B): - try: - if A[1] < B[1]: - return -1 - elif A[1] == B[1]: - return 0 - else: - return 1 - except: - return 0 - - + try: + if A[1] < B[1]: + return -1 + elif A[1] == B[1]: + return 0 + else: + return 1 + except: + return 0 + + def cmpPos(A,B): - try: - try: - AChr = int(A.chr) - except: - AChr = 20 - try: - BChr = int(B.chr) - except: - BChr = 20 - if AChr > BChr: - return 1 - elif AChr == BChr: - if A.mb > B.mb: - return 1 - if A.mb == B.mb: - return 0 - else: - return -1 - else: - return -1 - except: - return 0 - + try: + try: + AChr = int(A.chr) + except: + AChr = 20 + try: + BChr = int(B.chr) + except: + BChr = 20 + if AChr > BChr: + return 1 + elif AChr == BChr: + if A.mb > B.mb: + return 1 + if A.mb == B.mb: + return 0 + else: + return -1 + else: + return -1 + except: + return 0 + def cmpGenoPos(A,B): - try: - A1 = A.chr - B1 = B.chr - try: - A1 = int(A1) - except: - A1 = 25 - try: - B1 = int(B1) - except: - B1 = 25 - if A1 > B1: - return 1 - elif A1 == B1: - if A.mb > B.mb: - return 1 - if A.mb == B.mb: - return 0 - else: - return -1 - else: - return -1 - except: - return 0 + try: + A1 = A.chr + B1 = B.chr + try: + A1 = int(A1) + except: + A1 = 25 + try: + B1 = int(B1) + except: + B1 = 25 + if A1 > B1: + return 1 + elif A1 == B1: + if A.mb > B.mb: + return 1 + if A.mb == B.mb: + return 0 + else: + return -1 + else: + return -1 + except: + return 0 #XZhou: Must use "BINARY" to enable case sensitive comparison. def authUser(name,password,db, encrypt=None): - try: - if encrypt: - query = 'SELECT privilege, id,name,password, grpName FROM User WHERE name= BINARY \'%s\' and password= BINARY \'%s\'' % (name,password) - else: - query = 'SELECT privilege, id,name,password, grpName FROM User WHERE name= BINARY \'%s\' and password= BINARY SHA(\'%s\')' % (name,password) - db.execute(query) - records = db.fetchone() - if not records: - raise ValueError - return records#(privilege,id,name,password,grpName) - except: - return (None, None, None, None, None) + try: + if encrypt: + query = 'SELECT privilege, id,name,password, grpName FROM User WHERE name= BINARY \'%s\' and password= BINARY \'%s\'' % (name,password) + else: + query = 'SELECT privilege, id,name,password, grpName FROM User WHERE name= BINARY \'%s\' and password= BINARY SHA(\'%s\')' % (name,password) + db.execute(query) + records = db.fetchone() + if not records: + raise ValueError + return records#(privilege,id,name,password,grpName) + except: + return (None, None, None, None, None) def hasAccessToConfidentialPhenotypeTrait(privilege, userName, authorized_users): @@ -840,9 +840,9 @@ def hasAccessToConfidentialPhenotypeTrait(privilege, userName, authorized_users) class VisualizeException(Exception): def __init__(self, message): - self.message = message + self.message = message def __str__(self): - return self.message + return self.message # safeConvert : (string -> A) -> A -> A # to convert a string to type A, using the supplied default value @@ -852,12 +852,12 @@ def safeConvert(f, value, default): return f(value) except: return default - + # safeFloat : string -> float -> float # to convert a string to a float safely def safeFloat(value, default): return safeConvert(float, value, default) - + # safeInt: string -> int -> int # to convert a string to an int safely def safeInt(value, default): @@ -878,7 +878,7 @@ def yesNoToInt(value): if value == "yes": return 1 elif value == "no": - return 0 + return 0 else: return None @@ -890,79 +890,79 @@ def intToYesNo(value): elif value == 0: return "no" else: - return None - + return None + def formatField(name): - name = name.replace("_", " ") - name = name.title() - #name = name.replace("Mb Mm6", "Mb"); - return name.replace("Id", "ID") + name = name.replace("_", " ") + name = name.title() + #name = name.replace("Mb Mm6", "Mb"); + return name.replace("Id", "ID") #XZ, 03/27/2009: This function is very specific. #It is used by AJAX_table.py, correlationPage.py and dataPage.py def genTableObj(tblobj=None, file="", sortby = ("", ""), tableID = "sortable", addIndex = "1", hiddenColumns=[]): - header = tblobj['header'] - body = tblobj['body'] - field, order = sortby - - #ZAS 9/12/2011 - The hiddenColumns array needs to be converted into a string so they can be placed into the javascript of each up/down button - hiddenColumnsString = ",".join(hiddenColumns) - - tbl = HT.TableLite(Class="collap b2", cellspacing=1, cellpadding=5) - - hiddenColumnIdx = [] #indices of columns to hide - idx = -1 - last_idx = 0 #ZS: This is the index of the last item in the regular table header (without any extra parameters). It is used to determine the index of each extra parameter. - for row in header: - hr = HT.TR() - for i, item in enumerate(row): - if (item.text == '') or (item.text not in hiddenColumns): - if item.sort and item.text: - down = HT.Href("javascript:xmlhttpPost('%smain.py?FormID=AJAX_table', '%s', 'sort=%s&order=down&file=%s&tableID=%s&addIndex=%s&hiddenColumns=%s')" % (webqtlConfig.CGIDIR, tableID, item.text, file, tableID, addIndex, hiddenColumnsString),IMGDESC) - up = HT.Href("javascript:xmlhttpPost('%smain.py?FormID=AJAX_table', '%s', 'sort=%s&order=up&file=%s&tableID=%s&addIndex=%s&hiddenColumns=%s')" % (webqtlConfig.CGIDIR, tableID, item.text, file, tableID, addIndex, hiddenColumnsString),IMGASC) - if item.text == field: - idx = item.idx - last_idx = idx - if order == 'up': - up = IMGASCON - elif order == 'down': - down = IMGDESCON - item.html.append(HT.Div(up, down, style="float: bottom;")) - hr.append(item.html) - else: - hiddenColumnIdx.append(i) - tbl.append(hr) - - for i, row in enumerate(body): - for j, item in enumerate(row): - if order == 'down': - if (item.val == '' or item.val == 'x' or item.val == 'None'): - item.val = 0 - if order == 'up': - if (item.val == '' or item.val == 'x' or item.val == 'None'): - item.val = 'zzzzz' - - if idx >= 0: - if order == 'down': - body.sort(lambda A, B: cmp(B[idx].val, A[idx].val), key=natsort_key) - elif order == 'up': - body.sort(lambda A, B: cmp(A[idx].val, B[idx].val), key=natsort_key) - else: - pass - - for i, row in enumerate(body): - hr = HT.TR(Id = row[0].text) - for j, item in enumerate(row): - if (j not in hiddenColumnIdx): - if j == 0: - if addIndex == "1": - item.html.contents = [i+1] + item.html.contents - hr.append(item.html) - tbl.append(hr) - - return tbl + header = tblobj['header'] + body = tblobj['body'] + field, order = sortby + + #ZAS 9/12/2011 - The hiddenColumns array needs to be converted into a string so they can be placed into the javascript of each up/down button + hiddenColumnsString = ",".join(hiddenColumns) + + tbl = HT.TableLite(Class="collap b2", cellspacing=1, cellpadding=5) + + hiddenColumnIdx = [] #indices of columns to hide + idx = -1 + last_idx = 0 #ZS: This is the index of the last item in the regular table header (without any extra parameters). It is used to determine the index of each extra parameter. + for row in header: + hr = HT.TR() + for i, item in enumerate(row): + if (item.text == '') or (item.text not in hiddenColumns): + if item.sort and item.text: + down = HT.Href("javascript:xmlhttpPost('%smain.py?FormID=AJAX_table', '%s', 'sort=%s&order=down&file=%s&tableID=%s&addIndex=%s&hiddenColumns=%s')" % (webqtlConfig.CGIDIR, tableID, item.text, file, tableID, addIndex, hiddenColumnsString),IMGDESC) + up = HT.Href("javascript:xmlhttpPost('%smain.py?FormID=AJAX_table', '%s', 'sort=%s&order=up&file=%s&tableID=%s&addIndex=%s&hiddenColumns=%s')" % (webqtlConfig.CGIDIR, tableID, item.text, file, tableID, addIndex, hiddenColumnsString),IMGASC) + if item.text == field: + idx = item.idx + last_idx = idx + if order == 'up': + up = IMGASCON + elif order == 'down': + down = IMGDESCON + item.html.append(HT.Div(up, down, style="float: bottom;")) + hr.append(item.html) + else: + hiddenColumnIdx.append(i) + tbl.append(hr) + + for i, row in enumerate(body): + for j, item in enumerate(row): + if order == 'down': + if (item.val == '' or item.val == 'x' or item.val == 'None'): + item.val = 0 + if order == 'up': + if (item.val == '' or item.val == 'x' or item.val == 'None'): + item.val = 'zzzzz' + + if idx >= 0: + if order == 'down': + body.sort(lambda A, B: cmp(B[idx].val, A[idx].val), key=natsort_key) + elif order == 'up': + body.sort(lambda A, B: cmp(A[idx].val, B[idx].val), key=natsort_key) + else: + pass + + for i, row in enumerate(body): + hr = HT.TR(Id = row[0].text) + for j, item in enumerate(row): + if (j not in hiddenColumnIdx): + if j == 0: + if addIndex == "1": + item.html.contents = [i+1] + item.html.contents + hr.append(item.html) + tbl.append(hr) + + return tbl def natsort_key(string): r = [] @@ -974,4 +974,3 @@ def natsort_key(string): except: r.append(c) return r - diff --git a/wqflask/wqflask/show_trait/DataEditingPage.py b/wqflask/wqflask/show_trait/DataEditingPage.py index b50428fc..6d709012 100755 --- a/wqflask/wqflask/show_trait/DataEditingPage.py +++ b/wqflask/wqflask/show_trait/DataEditingPage.py @@ -18,1908 +18,1908 @@ from basicStatistics import BasicStatisticsFunctions ######################################### class DataEditingPage(templatePage): - def __init__(self, fd, thisTrait=None): - - templatePage.__init__(self, fd) - - self.dict['title'] = 'Data Editing' - TD_LR = HT.TD(valign="top",width="100%",bgcolor="#fafafa") - - if not self.openMysql(): - return - if not fd.genotype: - fd.readData(incf1=1) - - ############################# - # determine data editing page format - ############################# - varianceDataPage = 0 - if fd.formID == 'varianceChoice': - varianceDataPage = 1 - - if varianceDataPage: - fmID='dataEditing' - nCols = 6 - else: - if fd.enablevariance: - fmID='pre_dataEditing' - nCols = 4 - else: - fmID='dataEditing' - nCols = 4 - - ############################# - ## titles, etc. - ############################# - - #titleTop = HT.Div() - # - #title1 = HT.Paragraph("  Details and Links", style="border-radius: 5px;", Id="title1", Class="sectionheader") - #title1Body = HT.Paragraph(Id="sectionbody1") - # - #if fd.enablevariance and not varianceDataPage: - # title2 = HT.Paragraph("  Submit Variance", style="border-radius: 5px;", Id="title2", Class="sectionheader") - #else: - # title2 = HT.Paragraph("  Basic Statistics", style="border-radius: 5px;", Id="title2", Class="sectionheader") - #title2Body = HT.Paragraph(Id="sectionbody2") - # - #title3 = HT.Paragraph("  Calculate Correlations", style="border-radius: 5px;", Id="title3", Class="sectionheader") - #title3Body = HT.Paragraph(Id="sectionbody3") - # - #title4 = HT.Paragraph("  Mapping Tools", style="border-radius: 5px;", Id="title4", Class="sectionheader") - #title4Body = HT.Paragraph(Id="sectionbody4") - # - #title5 = HT.Paragraph("  Review and Edit Data", style="border-radius: 5px;", Id="title5", Class="sectionheader") - #title5Body = HT.Paragraph(Id="sectionbody5") - - ############################# - ## Hidden field - ############################# - - # Some fields, like method, are defaulted to None; otherwise in IE the field can't be changed using jquery - hddn = { - 'FormID':fmID, - 'RISet':fd.RISet, - 'submitID':'', - 'scale':'physic', - 'additiveCheck':'ON', - 'showSNP':'ON', - 'showGenes':'ON', - 'method':None, - 'parentsf14regression':'OFF', - 'stats_method':'1', - 'chromosomes':'-1', - 'topten':'', - 'viewLegend':'ON', - 'intervalAnalystCheck':'ON', - 'valsHidden':'OFF', - 'database':'', - 'criteria':None, - 'MDPChoice':None, - 'bootCheck':None, - 'permCheck':None, - 'applyVarianceSE':None, - 'strainNames':'_', - 'strainVals':'_', - 'strainVars':'_', - 'otherStrainNames':'_', - 'otherStrainVals':'_', - 'otherStrainVars':'_', - 'extra_attributes':'_', - 'other_extra_attributes':'_' - } - - if fd.enablevariance: - hddn['enablevariance']='ON' - if fd.incparentsf1: - hddn['incparentsf1']='ON' - - if thisTrait: - hddn['fullname'] = str(thisTrait) - try: - hddn['normalPlotTitle'] = thisTrait.symbol - hddn['normalPlotTitle'] += ": " - hddn['normalPlotTitle'] += thisTrait.name - except: - hddn['normalPlotTitle'] = str(thisTrait.name) - hddn['fromDataEditingPage'] = 1 - if thisTrait.db and thisTrait.db.type and thisTrait.db.type == 'ProbeSet': - hddn['trait_type'] = thisTrait.db.type - if thisTrait.cellid: - hddn['cellid'] = thisTrait.cellid - else: - self.cursor.execute("SELECT h2 from ProbeSetXRef WHERE DataId = %d" % thisTrait.mysqlid) - heritability = self.cursor.fetchone() - hddn['heritability'] = heritability - - hddn['attribute_names'] = "" - - hddn['mappingMethodId'] = webqtlDatabaseFunction.getMappingMethod (cursor=self.cursor, groupName=fd.RISet) - - ############################# - ## Display Trait Information - ############################# - - #headSpan = self.dispHeader(fd,thisTrait) #Draw header - # - #titleTop.append(headSpan) - - if fd.identification: - hddn['identification'] = fd.identification - - else: - hddn['identification'] = "Un-named trait" #If no identification, set identification to un-named - - self.dispTraitInformation(fd, "", hddn, thisTrait) #Display trait information + function buttons - - ############################# - ## Generate form and buttons - ############################# - - mainForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), - name='dataInput', submit=HT.Input(type='hidden')) - - next=HT.Input(type='submit', name='submit',value='Next',Class="button") - reset=HT.Input(type='Reset',name='',value=' Reset ',Class="button") - correlationMenus = [] - - if thisTrait == None: - thisTrait = webqtlTrait(data=fd.allTraitData, db=None) - - # Variance submit page only - if fd.enablevariance and not varianceDataPage: - title2Body.append("Click the next button to go to the variance submission form.", - HT.Center(next,reset)) - else: - self.dispBasicStatistics(fd, title2Body, thisTrait) - self.dispCorrelationTools(fd, title3Body, thisTrait) - self.dispMappingTools(fd, title4Body, thisTrait) - - ############################# - ## Trait Value Table - ############################# - - self.dispTraitValues(fd, title5Body, varianceDataPage, nCols, mainForm, thisTrait) - - if fd.allstrainlist: - hddn['allstrainlist'] = string.join(fd.allstrainlist, ' ') - for key in hddn.keys(): - mainForm.append(HT.Input(name=key, value=hddn[key], type='hidden')) - - if fd.enablevariance and not varianceDataPage: - #pre dataediting page, need to submit variance - mainForm.append(titleTop, title1,title1Body,title2,title2Body,title3,title3Body,title4,title4Body,title5,title5Body) - else: - mainForm.append(titleTop, title1,title1Body,title2,title2Body,title3,title3Body,title4,title4Body,title5,title5Body) - TD_LR.append(HT.Paragraph(mainForm)) - self.dict['body'] = str(TD_LR) - - ########################################## - ## Function to display header - ########################################## - def dispHeader(self, fd, thisTrait): - headSpan = HT.Div(style="font-size:14px;") - - #If trait, use trait name; otherwise, use identification value - if thisTrait: - if thisTrait.cellid: - headSpan.append(HT.Strong('Trait Data and Analysis ', style='font-size:16px;'),' for Probe ID ', thisTrait.cellid) - else: - headSpan.append(HT.Strong('Trait Data and Analysis ', style='font-size:16px;'),' for Record ID ', thisTrait.name) - else: - if fd.identification: - headSpan.append(HT.Strong('Trait ID ', style='font-size:16px;'),fd.identification) - else: - headSpan.append(HT.Strong('Un-named Trait', style='font-size:16px;')) - - return headSpan - - ########################################## - ## Function to display trait infos - ########################################## - def dispTraitInformation(self, fd, title1Body, hddn, thisTrait): - - _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) - - #tbl = HT.TableLite(cellpadding=2, Class="collap", style="margin-left:20px;", width="840", valign="top", id="target1") - - #reset=HT.Input(type='Reset',name='',value=' Reset ',Class="button") - - #XZ, August 02, 2011: The display of icons is decided by the trait type (if trait exists), along with user log-in status. Note that the new submitted trait might not be trait object. - addSelectionButton = "" - verifyButton = "" - rnaseqButton = "" - geneWikiButton = "" - probeButton = "" - similarButton = "" - snpBrowserButton = "" - updateButton = "" - - addSelectionText = "" - verifyText = "" - rnaseqText = "" - geneWikiText = "" - probeText = "" - similarText = "" - snpBrowserText = "" - updateText = "" - - if webqtlConfig.USERDICT[self.privilege] >= webqtlConfig.USERDICT['user']: - - if thisTrait==None or thisTrait.db.type=='Temp': - updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'addPublish');") - updateButton_img = HT.Image("/images/edit_icon.jpg", name="addnew", alt="Add To Publish", title="Add To Publish", style="border:none;") - updateButton.append(updateButton_img) - updateText = "Edit" - elif thisTrait.db.type != 'Temp': - if thisTrait.db.type == 'Publish' and thisTrait.confidential: #XZ: confidential phenotype trait - if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=thisTrait.authorized_users): - updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") - updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") - updateButton.append(updateButton_img) - updateText = "Edit" - else: - updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") - updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") - updateButton.append(updateButton_img) - updateText = "Edit" - else: - pass - - self.cursor.execute('SELECT Name FROM InbredSet WHERE Name="%s"' % fd.RISet) - if thisTrait: - addSelectionButton = HT.Href(url="#redirect", onClick="addRmvSelection('%s', document.getElementsByName('%s')[0], 'addToSelection');" % (fd.RISet, 'dataInput')) - addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="addselect", alt="Add To Collection", title="Add To Collection", style="border:none;") - #addSelectionButton.append(addSelectionButton_img) - addSelectionText = "Add" - elif self.cursor.fetchall(): - addSelectionButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('%s')[0], 'addRecord');" % ('dataInput')) - addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="", alt="Add To Collection", title="Add To Collection", style="border:none;") - #addSelectionButton.append(addSelectionButton_img) - addSelectionText = "Add" - else: - pass - - - # Microarray database information to display - if thisTrait and thisTrait.db and thisTrait.db.type == 'ProbeSet': #before, this line was only reached if thisTrait != 0, but now we need to check - try: - hddn['GeneId'] = int(string.strip(thisTrait.geneid)) - except: - pass - - #Info2Disp = HT.Paragraph() - - #XZ: Gene Symbol - if thisTrait.symbol: - #XZ: Show SNP Browser only for mouse - if _Species == 'mouse': - self.cursor.execute("select geneSymbol from GeneList where geneSymbol = %s", thisTrait.symbol) - geneName = self.cursor.fetchone() - if geneName: - snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + "&geneName=%s" % geneName[0] - else: - if thisTrait.chr and thisTrait.mb: - snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + \ - "&chr=%s&start=%2.6f&end=%2.6f" % (thisTrait.chr, thisTrait.mb-0.002, thisTrait.mb+0.002) - else: - snpurl = "" - - if snpurl: - snpBrowserButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % snpurl) - snpBrowserButton_img = HT.Image("/images/snp_icon.jpg", name="snpbrowser", alt=" View SNPs and Indels ", title=" View SNPs and Indels ", style="border:none;") - snpBrowserButton.append(snpBrowserButton_img) - snpBrowserText = "SNPs" - - #XZ: Show GeneWiki for all species - geneWikiButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + "?FormID=geneWiki&symbol=%s" % thisTrait.symbol)) - geneWikiButton_img = HT.Image("/images/genewiki_icon.jpg", name="genewiki", alt=" Write or review comments about this gene ", title=" Write or review comments about this gene ", style="border:none;") - geneWikiButton.append(geneWikiButton_img) - geneWikiText = 'GeneWiki' - - #XZ: display similar traits in other selected datasets - if thisTrait and thisTrait.db and thisTrait.db.type=="ProbeSet" and thisTrait.symbol: - if _Species in ("mouse", "rat", "human"): - similarUrl = "%s?cmd=sch&gene=%s&alias=1&species=%s" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), thisTrait.symbol, _Species) - similarButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % similarUrl) - similarButton_img = HT.Image("/images/find_icon.jpg", name="similar", alt=" Find similar expression data ", title=" Find similar expression data ", style="border:none;") - similarButton.append(similarButton_img) - similarText = "Find" - else: - pass - tbl.append(HT.TR( - HT.TD('Gene Symbol: ', Class="fwb fs13", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span('%s' % thisTrait.symbol, valign="top", Class="fs13 fsI"), valign="top", width=740) - )) - else: - tbl.append(HT.TR( - HT.TD('Gene Symbol: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span('Not available', Class="fs13 fsI"), valign="top") - )) - - #XZ: Gene Alias - if thisTrait.alias: - alias = string.replace(thisTrait.alias, ";", " ") - alias = string.join(string.split(alias), ", ") - tbl.append(HT.TR( - HT.TD('Aliases: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(alias, Class="fs13 fsI"), valign="top") - )) - - #XZ: Description - if thisTrait.description: - tSpan = HT.Span(thisTrait.description, Class="fs13") - if thisTrait.probe_target_description: - tSpan.append('; ', thisTrait.probe_target_description) - else: - tSpan = HT.Span('Not available', Class="fs13") - tbl.append(HT.TR( - HT.TD('Description: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top") - )) - - #XZ: Location - - #XZ: deal with Chr and Mb - if thisTrait.chr and thisTrait.mb: - tSpan = HT.Span('Chr %s @ %s Mb' % (thisTrait.chr,thisTrait.mb),Class="fs13") - elif (thisTrait.chr): - tSpan = HT.Span('Chr %s @ Unknown position' % (thisTrait.chr), Class="fs13") - else: - tSpan = HT.Span('Not available', Class="fs13") - - #XZ: deal with direction - if thisTrait.strand_probe == '+': - tSpan.append(' on the plus strand ') - elif thisTrait.strand_probe == '-': - tSpan.append(' on the minus strand ') - else: - pass - - tbl.append(HT.TR( - HT.TD('Location: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top") - )) - - ##display Verify Location button - try: - blatsequence = thisTrait.blatseq - if not blatsequence: - #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. - self.cursor.execute("""SELECT Probe.Sequence, Probe.Name - FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSet.Name = '%s' AND - Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""" % (thisTrait.db.name, thisTrait.name) ) - seqs = self.cursor.fetchall() - if not seqs: - raise ValueError - else: - blatsequence = '' - for seqt in seqs: - if int(seqt[1][-1]) % 2 == 1: - blatsequence += string.strip(seqt[0]) - - #--------Hongqiang add this part in order to not only blat ProbeSet, but also blat Probe - blatsequence = '%3E'+thisTrait.name+'%0A'+blatsequence+'%0A' - #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. - self.cursor.execute("""SELECT Probe.Sequence, Probe.Name - FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSet.Name = '%s' AND - Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""" % (thisTrait.db.name, thisTrait.name) ) - - seqs = self.cursor.fetchall() - for seqt in seqs: - if int(seqt[1][-1]) %2 == 1: - blatsequence += '%3EProbe_'+string.strip(seqt[1])+'%0A'+string.strip(seqt[0])+'%0A' - #-------- - #XZ, 07/16/2009: targetsequence is not used, so I comment out this block - #targetsequence = thisTrait.targetseq - #if targetsequence==None: - # targetsequence = "" - - #XZ: Pay attention to the parameter of version (rn, mm, hg). They need to be changed if necessary. - if _Species == "rat": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', blatsequence) - UTHSC_BLAT_URL = "" - elif _Species == "mouse": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', blatsequence) - UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', blatsequence) - elif _Species == "human": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) - UTHSC_BLAT_URL = "" - else: - UCSC_BLAT_URL = "" - UTHSC_BLAT_URL = "" - - if UCSC_BLAT_URL: - verifyButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UCSC_BLAT_URL) - verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", - title=" Check probe locations at UCSC ", style="border:none;") - verifyButton.append(verifyButtonImg) - verifyText = 'Verify' - if UTHSC_BLAT_URL: - rnaseqButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UTHSC_BLAT_URL) - rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", - title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") - rnaseqButton.append(rnaseqButtonImg) - rnaseqText = 'RNA-seq' - tSpan.append(HT.BR()) - except: - pass - - #Display probe information (if any) - if thisTrait.db.name.find('Liver') >= 0 and thisTrait.db.name.find('F2') < 0: - pass - else: - #query database for number of probes associated with trait; if count > 0, set probe tool button and text - self.cursor.execute("""SELECT count(*) - FROM Probe, ProbeSet - WHERE ProbeSet.Name = '%s' AND Probe.ProbeSetId = ProbeSet.Id""" % (thisTrait.name)) - - probeResult = self.cursor.fetchone() - if probeResult[0] > 0: - probeurl = "%s?FormID=showProbeInfo&database=%s&ProbeSetID=%s&CellID=%s&RISet=%s&incparentsf1=ON" \ - % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), thisTrait.db, thisTrait.name, thisTrait.cellid, fd.RISet) - probeButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % probeurl) - probeButton_img = HT.Image("/images/probe_icon.jpg", name="probe", alt=" Check sequence of probes ", title=" Check sequence of probes ", style="border:none;") - probeButton.append(probeButton_img) - probeText = "Probes" - - tSpan = HT.Span(Class="fs13") - - #XZ: deal with blat score and blat specificity. - if thisTrait.probe_set_specificity or thisTrait.probe_set_blat_score: - if thisTrait.probe_set_specificity: - tSpan.append(HT.Href(url="/blatInfo.html", target="_blank", title="Values higher than 2 for the specificity are good", text="BLAT specificity", Class="non_bold"),": %.1f" % float(thisTrait.probe_set_specificity), " "*3) - if thisTrait.probe_set_blat_score: - tSpan.append("Score: %s" % int(thisTrait.probe_set_blat_score), " "*2) - - onClick="openNewWin('/blatInfo.html')" - - tbl.append(HT.TR( - HT.TD('Target Score: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top") - )) - - tSpan = HT.Span(Class="fs13") - tSpan.append(str(_Species).capitalize(), ", ", fd.RISet) - - tbl.append(HT.TR( - HT.TD('Species and Group: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top") - )) - - if thisTrait.cellid: - self.cursor.execute(""" - select ProbeFreeze.Name from ProbeFreeze, ProbeSetFreeze - where - ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND - ProbeSetFreeze.Id = %d""" % thisTrait.db.id) - probeDBName = self.cursor.fetchone()[0] - tbl.append(HT.TR( - HT.TD('Database: ', Class="fs13 fwb", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span('%s' % probeDBName, Class="non_bold"), valign="top") - )) - else: - tbl.append(HT.TR( - HT.TD('Database: ', Class="fs13 fwb", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(HT.Href(text=thisTrait.db.fullname, url = webqtlConfig.INFOPAGEHREF % thisTrait.db.name, - target='_blank', Class="fs13 fwn non_bold"), valign="top") - )) - - #XZ: ID links - if thisTrait.genbankid or thisTrait.geneid or thisTrait.unigeneid or thisTrait.omim or thisTrait.homologeneid: - idStyle = "background:#dddddd;padding:2" - tSpan = HT.Span(Class="fs13") - if thisTrait.geneid: - gurl = HT.Href(text= 'Gene', target='_blank',\ - url=webqtlConfig.NCBI_LOCUSID % thisTrait.geneid, Class="fs14 fwn", title="Info from NCBI Entrez Gene") - tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if thisTrait.omim: - gurl = HT.Href(text= 'OMIM', target='_blank', \ - url= webqtlConfig.OMIM_ID % thisTrait.omim,Class="fs14 fwn", title="Summary from On Mendelian Inheritance in Man") - tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if thisTrait.unigeneid: - try: - gurl = HT.Href(text= 'UniGene',target='_blank',\ - url= webqtlConfig.UNIGEN_ID % tuple(string.split(thisTrait.unigeneid,'.')[:2]),Class="fs14 fwn", title="UniGene ID") - tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - except: - pass - if thisTrait.genbankid: - thisTrait.genbankid = '|'.join(thisTrait.genbankid.split('|')[0:10]) - if thisTrait.genbankid[-1]=='|': - thisTrait.genbankid=thisTrait.genbankid[0:-1] - gurl = HT.Href(text= 'GenBank', target='_blank', \ - url= webqtlConfig.GENBANK_ID % thisTrait.genbankid,Class="fs14 fwn", title="Find the original GenBank sequence used to design the probes") - tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if thisTrait.homologeneid: - hurl = HT.Href(text= 'HomoloGene', target='_blank',\ - url=webqtlConfig.HOMOLOGENE_ID % thisTrait.homologeneid, Class="fs14 fwn", title="Find similar genes in other species") - tSpan.append(HT.Span(hurl, style=idStyle), " "*2) - - tbl.append( - HT.TR(HT.TD(colspan=3,height=6)), - HT.TR( - HT.TD('Resource Links: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top") - )) - - #XZ: Resource Links: - if thisTrait.symbol: - linkStyle = "background:#dddddd;padding:2" - tSpan = HT.Span(style="font-family:verdana,serif;font-size:13px") - - #XZ,12/26/2008: Gene symbol may contain single quotation mark. - #For example, Affymetrix, mouse430v2, 1440338_at, the symbol is 2'-Pde (geneid 211948) - #I debug this by using double quotation marks. - if _Species == "rat": - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #symatlas_species = "Rattus norvegicus" - - #self.cursor.execute("SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = '%s'" % thisTrait.symbol) - self.cursor.execute('SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = "%s"' % thisTrait.symbol) - try: - kgId, chr, txst, txen = self.cursor.fetchall()[0] - if chr and txst and txen and kgId: - txst = int(txst*1000000) - txen = int(txen*1000000) - tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ - title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('rn3',kgId,chr,txst,txen),Class="fs14 fwn"), style=linkStyle) - , " "*2) - except: - pass - if _Species == "mouse": - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #symatlas_species = "Mus musculus" - - #self.cursor.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = '%s'" % thisTrait.symbol) - self.cursor.execute('SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = "%s"' % thisTrait.symbol) - try: - chr, txst, txen = self.cursor.fetchall()[0] - if chr and txst and txen and thisTrait.refseq_transcriptid : - txst = int(txst*1000000) - txen = int(txen*1000000) - tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ - title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('mm9',thisTrait.refseq_transcriptid,chr,txst,txen), - Class="fs14 fwn"), style=linkStyle) - , " "*2) - except: - pass - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #tSpan.append(HT.Span(HT.Href(text= 'SymAtlas',target="mainFrame",\ - # url="http://symatlas.gnf.org/SymAtlas/bioentry?querytext=%s&query=14&species=%s&type=Expression" \ - # % (thisTrait.symbol,symatlas_species),Class="fs14 fwn", \ - # title="Expression across many tissues and cell types"), style=linkStyle), " "*2) - if thisTrait.geneid and (_Species == "mouse" or _Species == "rat" or _Species == "human"): - tSpan.append(HT.Span(HT.Href(text= 'BioGPS',target="mainFrame",\ - url="http://biogps.gnf.org/?org=%s#goto=genereport&id=%s" \ - % (_Species, thisTrait.geneid),Class="fs14 fwn", \ - title="Expression across many tissues and cell types"), style=linkStyle), " "*2) - tSpan.append(HT.Span(HT.Href(text= 'STRING',target="mainFrame",\ - url="http://string.embl.de/newstring_cgi/show_link_summary.pl?identifier=%s" \ - % thisTrait.symbol,Class="fs14 fwn", \ - title="Protein interactions: known and inferred"), style=linkStyle), " "*2) - if thisTrait.symbol: - #ZS: The "species scientific" converts the plain English species names we're using to their scientific names, which are needed for PANTHER's input - #We should probably use the scientific name along with the English name (if not instead of) elsewhere as well, given potential non-English speaking users - if _Species == "mouse": - species_scientific = "Mus%20musculus" - elif _Species == "rat": - species_scientific = "Rattus%20norvegicus" - elif _Species == "human": - species_scientific = "Homo%20sapiens" - elif _Species == "drosophila": - species_scientific = "Drosophila%20melanogaster" - else: - species_scientific = "all" - - species_scientific - tSpan.append(HT.Span(HT.Href(text= 'PANTHER',target="mainFrame", \ - url="http://www.pantherdb.org/genes/geneList.do?searchType=basic&fieldName=all&organism=%s&listType=1&fieldValue=%s" \ - % (species_scientific, thisTrait.symbol),Class="fs14 fwn", \ - title="Gene and protein data resources from Celera-ABI"), style=linkStyle), " "*2) - else: - pass - #tSpan.append(HT.Span(HT.Href(text= 'BIND',target="mainFrame",\ - # url="http://bind.ca/?textquery=%s" \ - # % thisTrait.symbol,Class="fs14 fwn", \ - # title="Protein interactions"), style=linkStyle), " "*2) - if thisTrait.geneid and (_Species == "mouse" or _Species == "rat" or _Species == "human"): - tSpan.append(HT.Span(HT.Href(text= 'Gemma',target="mainFrame",\ - url="http://www.chibi.ubc.ca/Gemma/gene/showGene.html?ncbiid=%s" \ - % thisTrait.geneid, Class="fs14 fwn", \ - title="Meta-analysis of gene expression data"), style=linkStyle), " "*2) - tSpan.append(HT.Span(HT.Href(text= 'SynDB',target="mainFrame",\ - url="http://lily.uthsc.edu:8080/20091027_GNInterfaces/20091027_redirectSynDB.jsp?query=%s" \ - % thisTrait.symbol, Class="fs14 fwn", \ - title="Brain synapse database"), style=linkStyle), " "*2) - if _Species == "mouse": - tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - url="http://mouse.brain-map.org/brain/%s.html" \ - % thisTrait.symbol, Class="fs14 fwn", \ - title="Allen Brain Atlas"), style=linkStyle), " "*2) - - if thisTrait.geneid: - #if _Species == "mouse": - # tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - # url="http://www.brain-map.org/search.do?queryText=egeneid=%s" \ - # % thisTrait.geneid, Class="fs14 fwn", \ - # title="Allen Brain Atlas"), style=linkStyle), " "*2) - if _Species == "human": - tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - url="http://humancortex.alleninstitute.org/has/human/imageseries/search/1.html?searchSym=t&searchAlt=t&searchName=t&gene_term=&entrez_term=%s" \ - % thisTrait.geneid, Class="fs14 fwn", \ - title="Allen Brain Atlas"), style=linkStyle), " "*2) - tbl.append( - HT.TR(HT.TD(colspan=3,height=6)), - HT.TR( - HT.TD(' '), - HT.TD(width=10, valign="top"), - HT.TD(tSpan, valign="top"))) - - menuTable = HT.TableLite(cellpadding=2, Class="collap", width="620", id="target1") - menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(similarButton, align="center"),HT.TD(verifyButton, align="center"),HT.TD(geneWikiButton, align="center"),HT.TD(snpBrowserButton, align="center"),HT.TD(rnaseqButton, align="center"),HT.TD(probeButton, align="center"),HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(similarText, align="center"),HT.TD(verifyText, align="center"),HT.TD(geneWikiText, align="center"),HT.TD(snpBrowserText, align="center"),HT.TD(rnaseqText, align="center"),HT.TD(probeText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - - - #for zhou mi's cliques, need to be removed - #if self.database[:6] == 'BXDMic' and self.ProbeSetID in cliqueID: - # Info2Disp.append(HT.Strong('Clique Search: '),HT.Href(text='Search',\ - # url ="http://compbio1.utmem.edu/clique_go/results.php?pid=%s&pval_1=0&pval_2=0.001" \ - # % self.ProbeSetID,target='_blank',Class="normalsize"),HT.BR()) - - #linkTable.append(HT.TR(linkTD)) - #Info2Disp.append(linkTable) - title1Body.append(tbl, HT.BR(), menuTable) - - elif thisTrait and thisTrait.db and thisTrait.db.type =='Publish': #Check if trait is phenotype - - if thisTrait.confidential: - tbl.append(HT.TR( - HT.TD('Pre-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.pre_publication_description, Class="fs13"), valign="top", width=740) - )) - if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=thisTrait.authorized_users): - tbl.append(HT.TR( - HT.TD('Post-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.post_publication_description, Class="fs13"), valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Pre-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.pre_publication_abbreviation, Class="fs13"), valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Post-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.post_publication_abbreviation, Class="fs13"), valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Lab code: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.lab_code, Class="fs13"), valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Owner: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.owner, Class="fs13"), valign="top", width=740) - )) - else: - tbl.append(HT.TR( - HT.TD('Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.post_publication_description, Class="fs13"), valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Authors: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.authors, Class="fs13"), - valign="top", width=740) - )) - tbl.append(HT.TR( - HT.TD('Title: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(thisTrait.title, Class="fs13"), - valign="top", width=740) - )) - if thisTrait.journal: - journal = thisTrait.journal - if thisTrait.year: - journal = thisTrait.journal + " (%s)" % thisTrait.year - - tbl.append(HT.TR( - HT.TD('Journal: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(journal, Class="fs13"), - valign="top", width=740) - )) - PubMedLink = "" - if thisTrait.pubmed_id: - PubMedLink = webqtlConfig.PUBMEDLINK_URL % thisTrait.pubmed_id - if PubMedLink: - tbl.append(HT.TR( - HT.TD('Link: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(HT.Href(url=PubMedLink, text="PubMed",target='_blank',Class="fs14 fwn"), - style = "background:#cddcff;padding:2"), valign="top", width=740) - )) - - menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1") - menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - - title1Body.append(tbl, HT.BR(), menuTable) - - elif thisTrait and thisTrait.db and thisTrait.db.type == 'Geno': #Check if trait is genotype - - GenoInfo = HT.Paragraph() - if thisTrait.chr and thisTrait.mb: - location = ' Chr %s @ %s Mb' % (thisTrait.chr,thisTrait.mb) - else: - location = "not available" - - if thisTrait.sequence and len(thisTrait.sequence) > 100: - if _Species == "rat": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', thisTrait.sequence) - UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('rat', 'rn3', thisTrait.sequence) - elif _Species == "mouse": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', thisTrait.sequence) - UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', thisTrait.sequence) - elif _Species == "human": - UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) - UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('human', 'hg19', thisTrait.sequence) - else: - UCSC_BLAT_URL = "" - UTHSC_BLAT_URL = "" - if UCSC_BLAT_URL: - #verifyButton = HT.Href(url="#", onClick="openNewWin('%s')" % UCSC_BLAT_URL) - verifyButton = HT.Href(url="#") - verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", title=" Check probe locations at UCSC ", style="border:none;") - verifyButton.append(verifyButtonImg) - verifyText = "Verify" - rnaseqButton = HT.Href(url="#", onClick="openNewWin('%s')" % UTHSC_BLAT_URL) - rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") - rnaseqButton.append(rnaseqButtonImg) - rnaseqText = "RNA-seq" - - tbl.append(HT.TR( - HT.TD('Location: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span(location, Class="fs13"), valign="top", width=740) - ), - HT.TR( - HT.TD('SNP Search: ', Class="fs13 fwb", - valign="top", nowrap="on", width=90), - HT.TD(width=10, valign="top"), - HT.TD(HT.Href("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=snp&cmd=search&term=%s" % thisTrait.name, 'NCBI',Class="fs13"), - valign="top", width=740) - )) - - menuTable = HT.TableLite(cellpadding=2, Class="collap", width="275", id="target1") - menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(verifyButton, align="center"),HT.TD(rnaseqButton, align="center"), HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(verifyText, align="center"),HT.TD(rnaseqText, align="center"), HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - - title1Body.append(tbl, HT.BR(), menuTable) - - elif (thisTrait == None or thisTrait.db.type == 'Temp'): #if temporary trait (user-submitted trait or PCA trait) - - TempInfo = HT.Paragraph() - if thisTrait != None: - if thisTrait.description: - tbl.append(HT.TR(HT.TD(HT.Strong('Description: '),' %s ' % thisTrait.description,HT.BR()), colspan=3, height=15)) - else: - tbl.append(HT.TR(HT.TD(HT.Strong('Description: '),'not available',HT.BR(),HT.BR()), colspan=3, height=15)) - - if (updateText == "Edit"): - menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1") - else: - menuTable = HT.TableLite(cellpadding=2, Class="collap", width="80", id="target1") - - menuTable.append(HT.TR(HT.TD(addSelectionButton, align="right"),HT.TD(updateButton, align="right"), colspan=3, height=50, style="vertical-align:bottom;") ) - menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) - - title1Body.append(tbl, HT.BR(), menuTable) - - else: - pass - - - ########################################## - ## Function to display analysis tools - ########################################## - def dispBasicStatistics(self, fd, title2Body, thisTrait): - - #XZ, June 22, 2011: The definition and usage of primary_strains, other_strains, specialStrains, all_strains are not clear and hard to understand. But since they are only used in this function for draw graph purpose, they will not hurt the business logic outside. As of June 21, 2011, this function seems work fine, so no hurry to clean up. These parameters and code in this function should be cleaned along with fd.f1list, fd.parlist, fd.strainlist later. - stats_row = HT.TR() - stats_cell = HT.TD() - - if fd.genotype.type == "riset": - strainlist = fd.f1list + fd.strainlist - else: - strainlist = fd.f1list + fd.parlist + fd.strainlist - - other_strains = [] #XZ: strain that is not of primary group - specialStrains = [] #XZ: This might be replaced by other_strains / ZS: It is just other strains without parent/f1 strains. - all_strains = [] - primary_strains = [] #XZ: strain of primary group, e.g., BXD, LXS - - MDP_menu = HT.Select(name='stats_mdp', Class='stats_mdp') - - for strain in thisTrait.data.keys(): - strainName = strain.replace("_2nd_", "") - if strain not in strainlist: - if (thisTrait.data[strainName].val != None): - if strain.find('F1') < 0: - specialStrains.append(strain) - if (thisTrait.data[strainName].val != None) and (strain not in (fd.f1list + fd.parlist)): - other_strains.append(strain) #XZ: at current stage, other_strains doesn't include parent strains and F1 strains of primary group - else: - if (thisTrait.data[strainName].val != None) and (strain not in (fd.f1list + fd.parlist)): - primary_strains.append(strain) #XZ: at current stage, the primary_strains is the same as fd.strainlist / ZS: I tried defining primary_strains as fd.strainlist instead, but in some cases it ended up including the parent strains (1436869_at BXD) - - if len(other_strains) > 3: - other_strains.sort(key=webqtlUtil.natsort_key) - primary_strains.sort(key=webqtlUtil.natsort_key) - primary_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_strains #XZ: note that fd.f1list and fd.parlist are added. - all_strains = primary_strains + other_strains - other_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + other_strains #XZ: note that fd.f1list and fd.parlist are added. - MDP_menu.append(('All Cases','0')) - MDP_menu.append(('%s Only' % fd.RISet,'1')) - MDP_menu.append(('Non-%s Only' % fd.RISet,'2')) - stats_row.append("Include: ", MDP_menu, HT.BR(), HT.BR()) - else: - if (len(other_strains) > 0) and (len(primary_strains) + len(other_strains) > 3): - MDP_menu.append(('All Cases','0')) - MDP_menu.append(('%s Only' % fd.RISet,'1')) - MDP_menu.append(('Non-%s Only' % fd.RISet,'2')) - stats_row.append("Include: ", MDP_menu, " "*3) - all_strains = primary_strains - all_strains.sort(key=webqtlUtil.natsort_key) - all_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + all_strains - primary_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_strains - else: - all_strains = strainlist - - other_strains.sort(key=webqtlUtil.natsort_key) - all_strains = all_strains + other_strains - pass - - update_button = HT.Input(type='button',value=' Update Figures ', Class="button update") #This is used to reload the page and update the Basic Statistics figures with user-edited data - stats_row.append(update_button, HT.BR(), HT.BR()) - - if (len(other_strains)) > 0 and (len(primary_strains) + len(other_strains) > 4): - #One set of vals for all, selected strain only, and non-selected only - vals1 = [] - vals2 = [] - vals3 = [] - - #Using all strains/cases for values - for i, strainNameOrig in enumerate(all_strains): - strainName = strainNameOrig.replace("_2nd_", "") - - try: - thisval = thisTrait.data[strainName].val - thisvar = thisTrait.data[strainName].var - thisValFull = [strainName,thisval,thisvar] - except: - continue - - vals1.append(thisValFull) - - #Using just the RISet strain - for i, strainNameOrig in enumerate(primary_strains): - strainName = strainNameOrig.replace("_2nd_", "") - - try: - thisval = thisTrait.data[strainName].val - thisvar = thisTrait.data[strainName].var - thisValFull = [strainName,thisval,thisvar] - except: - continue - - vals2.append(thisValFull) - - #Using all non-RISet strains only - for i, strainNameOrig in enumerate(other_strains): - strainName = strainNameOrig.replace("_2nd_", "") - - try: - thisval = thisTrait.data[strainName].val - thisvar = thisTrait.data[strainName].var - thisValFull = [strainName,thisval,thisvar] - except: - continue - - vals3.append(thisValFull) - - vals_set = [vals1,vals2,vals3] - - else: - vals = [] - - #Using all strains/cases for values - for i, strainNameOrig in enumerate(all_strains): - strainName = strainNameOrig.replace("_2nd_", "") - - try: - thisval = thisTrait.data[strainName].val - thisvar = thisTrait.data[strainName].var - thisValFull = [strainName,thisval,thisvar] - except: - continue - - vals.append(thisValFull) - - vals_set = [vals] - - stats_script = HT.Script(language="Javascript") #script needed for tabs - - for i, vals in enumerate(vals_set): - if i == 0 and len(vals) < 4: - stats_container = HT.Div(id="stats_tabs", style="padding:10px;", Class="ui-tabs") #Needed for tabs; notice the "stats_script_text" below referring to this element - stats_container.append(HT.Div(HT.Italic("Fewer than 4 case data were entered. No statistical analysis has been attempted."))) - stats_script_text = """$(function() { $("#stats_tabs").tabs();});""" - stats_cell.append(stats_container) - break - elif (i == 1 and len(primary_strains) < 4): - stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") - stats_container.append(HT.Div(HT.Italic("Fewer than 4 " + fd.RISet + " case data were entered. No statistical analysis has been attempted."))) - elif (i == 2 and len(other_strains) < 4): - stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") - stats_container.append(HT.Div(HT.Italic("Fewer than 4 non-" + fd.RISet + " case data were entered. No statistical analysis has been attempted."))) - stats_script_text = """$(function() { $("#stats_tabs0").tabs(); $("#stats_tabs1").tabs(); $("#stats_tabs2").tabs();});""" - else: - stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") - stats_script_text = """$(function() { $("#stats_tabs0").tabs(); $("#stats_tabs1").tabs(); $("#stats_tabs2").tabs();});""" - if len(vals) > 4: - stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-5", Class="stats_tab"), - HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), - HT.Href(text="Box Plot", url="#statstabs-2", Class="stats_tab")] - stats_tabs = HT.List(stats_tab_list) - stats_container.append(stats_tabs) - - table_div = HT.Div(id="statstabs-1") - table_container = HT.Paragraph() - - statsTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - - if thisTrait.db: - if thisTrait.cellid: - statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=thisTrait.db.type, cellid=thisTrait.cellid) - else: - statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=thisTrait.db.type) - else: - statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals) - - statsTable.append(HT.TR(HT.TD(statsTableCell))) - - table_container.append(statsTable) - table_div.append(table_container) - stats_container.append(table_div) - - normalplot_div = HT.Div(id="statstabs-5") - normalplot_container = HT.Paragraph() - normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - - try: - plotTitle = thisTrait.symbol - plotTitle += ": " - plotTitle += thisTrait.name - except: - plotTitle = str(thisTrait.name) - - normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, RISet=fd.RISet, title=plotTitle, specialStrains=specialStrains) - normalplot.append(HT.TR(HT.TD(normalplot_img))) - normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ - normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), - "More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", - target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) - normalplot_container.append(normalplot) - normalplot_div.append(normalplot_container) - stats_container.append(normalplot_div) - - boxplot_div = HT.Div(id="statstabs-2") - boxplot_container = HT.Paragraph() - boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) - boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) - boxplot_container.append(boxplot) - boxplot_div.append(boxplot_container) - stats_container.append(boxplot_div) - - - barName_div = HT.Div(id="statstabs-3") - barName_container = HT.Paragraph() - barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="name") - barName.append(HT.TR(HT.TD(barName_img))) - barName_container.append(barName) - barName_div.append(barName_container) - stats_container.append(barName_div) - - barRank_div = HT.Div(id="statstabs-4") - barRank_container = HT.Paragraph() - barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="rank") - barRank.append(HT.TR(HT.TD(barRank_img))) - barRank_container.append(barRank) - barRank_div.append(barRank_container) - stats_container.append(barRank_div) - - stats_cell.append(stats_container) - - stats_script.append(stats_script_text) - - submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target2") - stats_row.append(stats_cell) - - submitTable.append(stats_row) - submitTable.append(stats_script) - - title2Body.append(submitTable) - - - def dispCorrelationTools(self, fd, title3Body, thisTrait): - - _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) - - RISetgp = fd.RISet - if RISetgp[:3] == 'BXD': - RISetgp = 'BXD' - - if RISetgp: - sample_correlation = HT.Input(type='button',name='sample_corr', value=' Compute ', Class="button sample_corr") - lit_correlation = HT.Input(type='button',name='lit_corr', value=' Compute ', Class="button lit_corr") - tissue_correlation = HT.Input(type='button',name='tiss_corr', value=' Compute ', Class="button tiss_corr") - methodText = HT.Span("Calculate:", Class="ffl fwb fs12") - - databaseText = HT.Span("Database:", Class="ffl fwb fs12") - databaseMenu1 = HT.Select(name='database1') - databaseMenu2 = HT.Select(name='database2') - databaseMenu3 = HT.Select(name='database3') - - nmenu = 0 - self.cursor.execute('SELECT PublishFreeze.FullName,PublishFreeze.Name FROM \ - PublishFreeze,InbredSet WHERE PublishFreeze.InbredSetId = InbredSet.Id \ - and InbredSet.Name = "%s" and PublishFreeze.public > %d' % \ - (RISetgp,webqtlConfig.PUBLICTHRESH)) - for item in self.cursor.fetchall(): - databaseMenu1.append(item) - databaseMenu2.append(item) - databaseMenu3.append(item) - nmenu += 1 - self.cursor.execute('SELECT GenoFreeze.FullName,GenoFreeze.Name FROM GenoFreeze,\ - InbredSet WHERE GenoFreeze.InbredSetId = InbredSet.Id and InbredSet.Name = \ - "%s" and GenoFreeze.public > %d' % (RISetgp,webqtlConfig.PUBLICTHRESH)) - for item in self.cursor.fetchall(): - databaseMenu1.append(item) - databaseMenu2.append(item) - databaseMenu3.append(item) - nmenu += 1 - #03/09/2009: Xiaodong changed the SQL query to order by Name as requested by Rob. - self.cursor.execute('SELECT Id, Name FROM Tissue order by Name') - for item in self.cursor.fetchall(): - TId, TName = item - databaseMenuSub = HT.Optgroup(label = '%s ------' % TName) - self.cursor.execute('SELECT ProbeSetFreeze.FullName,ProbeSetFreeze.Name FROM ProbeSetFreeze, ProbeFreeze, \ - InbredSet WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and ProbeFreeze.TissueId = %d and \ - ProbeSetFreeze.public > %d and ProbeFreeze.InbredSetId = InbredSet.Id and InbredSet.Name like "%s%%" \ - order by ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId ' % (TId,webqtlConfig.PUBLICTHRESH, RISetgp)) - for item2 in self.cursor.fetchall(): - databaseMenuSub.append(item2) - nmenu += 1 - databaseMenu1.append(databaseMenuSub) - databaseMenu2.append(databaseMenuSub) - databaseMenu3.append(databaseMenuSub) - if nmenu: - if thisTrait and thisTrait.db != None: - databaseMenu1.selected.append(thisTrait.db.fullname) - databaseMenu2.selected.append(thisTrait.db.fullname) - databaseMenu3.selected.append(thisTrait.db.fullname) - - criteriaText = HT.Span("Return:", Class="ffl fwb fs12") - - criteriaMenu1 = HT.Select(name='criteria1', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") - criteriaMenu1.append(('top 100','100')) - criteriaMenu1.append(('top 200','200')) - criteriaMenu1.append(('top 500','500')) - criteriaMenu1.append(('top 1000','1000')) - criteriaMenu1.append(('top 2000','2000')) - criteriaMenu1.append(('top 5000','5000')) - criteriaMenu1.append(('top 10000','10000')) - criteriaMenu1.append(('top 15000','15000')) - criteriaMenu1.append(('top 20000','20000')) - - criteriaMenu2 = HT.Select(name='criteria2', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") - criteriaMenu2.append(('top 100','100')) - criteriaMenu2.append(('top 200','200')) - criteriaMenu2.append(('top 500','500')) - criteriaMenu2.append(('top 1000','1000')) - criteriaMenu2.append(('top 2000','2000')) - criteriaMenu2.append(('top 5000','5000')) - criteriaMenu2.append(('top 10000','10000')) - criteriaMenu2.append(('top 15000','15000')) - criteriaMenu2.append(('top 20000','20000')) - - criteriaMenu3 = HT.Select(name='criteria3', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") - criteriaMenu3.append(('top 100','100')) - criteriaMenu3.append(('top 200','200')) - criteriaMenu3.append(('top 500','500')) - criteriaMenu3.append(('top 1000','1000')) - criteriaMenu3.append(('top 2000','2000')) - criteriaMenu3.append(('top 5000','5000')) - criteriaMenu3.append(('top 10000','10000')) - criteriaMenu3.append(('top 15000','15000')) - criteriaMenu3.append(('top 20000','20000')) - - - self.MDPRow1 = HT.TR(Class='mdp1') - self.MDPRow2 = HT.TR(Class='mdp2') - self.MDPRow3 = HT.TR(Class='mdp3') - - correlationMenus1 = HT.TableLite( - HT.TR(HT.TD(databaseText), HT.TD(databaseMenu1, colspan="3")), - HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu1)), - self.MDPRow1, cellspacing=0, width="619px", cellpadding=2) - correlationMenus1.append(HT.Input(name='orderBy', value='2', type='hidden')) # to replace the orderBy menu - correlationMenus2 = HT.TableLite( - HT.TR(HT.TD(databaseText), HT.TD(databaseMenu2, colspan="3")), - HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu2)), - self.MDPRow2, cellspacing=0, width="619px", cellpadding=2) - correlationMenus2.append(HT.Input(name='orderBy', value='2', type='hidden')) - correlationMenus3 = HT.TableLite( - HT.TR(HT.TD(databaseText), HT.TD(databaseMenu3, colspan="3")), - HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu3)), - self.MDPRow3, cellspacing=0, width="619px", cellpadding=2) - correlationMenus3.append(HT.Input(name='orderBy', value='2', type='hidden')) - - else: - correlationMenus = "" - - - corr_row = HT.TR() - corr_container = HT.Div(id="corr_tabs", Class="ui-tabs") - - if (thisTrait.db != None and thisTrait.db.type =='ProbeSet'): - corr_tab_list = [HT.Href(text='Sample r', url="#corrtabs-1"), HT.Href(text='Literature r', url="#corrtabs-2"), HT.Href(text='Tissue r', url="#corrtabs-3")] - else: - corr_tab_list = [HT.Href(text='Sample r', url="#corrtabs-1")] - - corr_tabs = HT.List(corr_tab_list) - corr_container.append(corr_tabs) - - if correlationMenus1 or correlationMenus2 or correlationMenus3: - sample_div = HT.Div(id="corrtabs-1") - sample_container = HT.Span() - - sample_type = HT.Input(type="radio", name="sample_method", value="1", checked="checked") - sample_type2 = HT.Input(type="radio", name="sample_method", value="2") - - sampleTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - sampleTD = HT.TD(correlationMenus1, HT.BR(), - "Pearson", sample_type, " "*3, "Spearman Rank", sample_type2, HT.BR(), HT.BR(), - sample_correlation, HT.BR(), HT.BR()) - - sampleTD.append(HT.Span("The ",HT.Href(url="/correlationAnnotation.html#sample_r", target="_blank", text="Sample Correlation")," is computed between trait data and", - " any ",HT.BR()," other traits in the sample database selected above. Use ", - HT.Href(url="/glossary.html#Correlations", target="_blank", text="Spearman Rank"), - HT.BR(),"when the sample size is small (<20) or when there are influential \ - outliers.", HT.BR(),Class="fs12")) - - sampleTable.append(sampleTD) - - sample_container.append(sampleTable) - sample_div.append(sample_container) - corr_container.append(sample_div) - - literature_div = HT.Div(id="corrtabs-2") - literature_container = HT.Span() - - literatureTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - literatureTD = HT.TD(correlationMenus2,HT.BR(),lit_correlation, HT.BR(), HT.BR()) - literatureTD.append(HT.Span("The ", HT.Href(url="/correlationAnnotation.html", target="_blank",text="Literature Correlation"), " (Lit r) between this gene and all other genes is computed",HT.BR(), - "using the ", HT.Href(url="https://grits.eecs.utk.edu/sgo/sgo.html", target="_blank", text="Semantic Gene Organizer"), - " and human, rat, and mouse data from PubMed. ", HT.BR(),"Values are ranked by Lit r, \ - but Sample r and Tissue r are also displayed.", HT.BR(), HT.BR(), - HT.Href(url="/glossary.html#Literature", target="_blank", text="More on using Lit r"), Class="fs12")) - literatureTable.append(literatureTD) - - literature_container.append(literatureTable) - literature_div.append(literature_container) - - if thisTrait.db != None: - if (thisTrait.db.type =='ProbeSet'): - corr_container.append(literature_div) - - tissue_div = HT.Div(id="corrtabs-3") - tissue_container = HT.Span() - - tissue_type = HT.Input(type="radio", name="tissue_method", value="4", checked="checked") - tissue_type2 = HT.Input(type="radio", name="tissue_method", value="5") - - tissueTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - tissueTD = HT.TD(correlationMenus3,HT.BR(), - "Pearson", tissue_type, " "*3, "Spearman Rank", tissue_type2, HT.BR(), HT.BR(), - tissue_correlation, HT.BR(), HT.BR()) - tissueTD.append(HT.Span("The ", HT.Href(url="/webqtl/main.py?FormID=tissueCorrelation", target="_blank", text="Tissue Correlation"), - " (Tissue r) estimates the similarity of expression of two genes",HT.BR()," or \ - transcripts across different cells, tissues, or organs (",HT.Href(url="/correlationAnnotation.html#tissue_r", target="_blank", text="glossary"),"). \ - Tissue correlations",HT.BR()," are generated by analyzing expression in multiple samples usually taken from \ - single cases.",HT.BR(),HT.Bold("Pearson")," and ",HT.Bold("Spearman Rank")," correlations have been computed for all pairs \ - of genes",HT.BR()," using data from mouse samples.", - HT.BR(), Class="fs12")) - tissueTable.append(tissueTD) - - tissue_container.append(tissueTable) - tissue_div.append(tissue_container) - if thisTrait.db != None: - if (thisTrait.db.type =='ProbeSet'): - corr_container.append(tissue_div) - - corr_row.append(HT.TD(corr_container)) - - corr_script = HT.Script(language="Javascript") - corr_script_text = """$(function() { $("#corr_tabs").tabs(); });""" - corr_script.append(corr_script_text) - - submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target4") - submitTable.append(corr_row) - submitTable.append(corr_script) - - title3Body.append(submitTable) - - - def dispMappingTools(self, fd, title4Body, thisTrait): - - _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) - - RISetgp = fd.RISet - if RISetgp[:3] == 'BXD': - RISetgp = 'BXD' - - #check boxes - one for regular interval mapping, the other for composite - permCheck1= HT.Input(type='checkbox', Class='checkbox', name='permCheck1',checked="on") - bootCheck1= HT.Input(type='checkbox', Class='checkbox', name='bootCheck1',checked=0) - permCheck2= HT.Input(type='checkbox', Class='checkbox', name='permCheck2',checked="on") - bootCheck2= HT.Input(type='checkbox', Class='checkbox', name='bootCheck2',checked=0) - optionbox1 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression1',checked=0) - optionbox2 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression2',checked=0) - optionbox3 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression3',checked=0) - applyVariance1 = HT.Input(name='applyVarianceSE1',type='checkbox', Class='checkbox') - applyVariance2 = HT.Input(name='applyVarianceSE2',type='checkbox', Class='checkbox') - - IntervalMappingButton=HT.Input(type='button' ,name='interval',value=' Compute ', Class="button") - CompositeMappingButton=HT.Input(type='button' ,name='composite',value=' Compute ', Class="button") - MarkerRegressionButton=HT.Input(type='button',name='marker', value=' Compute ', Class="button") - - chrText = HT.Span("Chromosome:", Class="ffl fwb fs12") - - # updated by NL 5-28-2010 - # Interval Mapping - chrMenu = HT.Select(name='chromosomes1') - chrMenu.append(tuple(["All",-1])) - for i in range(len(fd.genotype)): - if len(fd.genotype[i]) > 1: - chrMenu.append(tuple([fd.genotype[i].name,i])) - - #Menu for Composite Interval Mapping - chrMenu2 = HT.Select(name='chromosomes2') - chrMenu2.append(tuple(["All",-1])) - for i in range(len(fd.genotype)): - if len(fd.genotype[i]) > 1: - chrMenu2.append(tuple([fd.genotype[i].name,i])) - - if fd.genotype.Mbmap: - scaleText = HT.Span("Mapping Scale:", Class="ffl fwb fs12") - scaleMenu1 = HT.Select(name='scale1', onChange="checkUncheck(window.document.dataInput.scale1.value, window.document.dataInput.permCheck1, window.document.dataInput.bootCheck1)") - scaleMenu1.append(("Megabase",'physic')) - scaleMenu1.append(("Centimorgan",'morgan')) - scaleMenu2 = HT.Select(name='scale2', onChange="checkUncheck(window.document.dataInput.scale2.value, window.document.dataInput.permCheck2, window.document.dataInput.bootCheck2)") - scaleMenu2.append(("Megabase",'physic')) - scaleMenu2.append(("Centimorgan",'morgan')) - - controlText = HT.Span("Control Locus:", Class="ffl fwb fs12") - controlMenu = HT.Input(type="text", name="controlLocus", Class="controlLocus") - - if fd.genotype.Mbmap: - intMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), - HT.TR(HT.TD(scaleText), HT.TD(scaleMenu1)), - cellspacing=0, width="263px", cellpadding=2) - compMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), - HT.TR(HT.TD(scaleText), HT.TD(scaleMenu2)), - HT.TR(HT.TD(controlText), HT.TD(controlMenu)), - cellspacing=0, width="325px", cellpadding=2) - else: - intMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), - cellspacing=0, width="263px", cellpadding=2) - compMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), - HT.TR(HT.TD(controlText), HT.TD(controlMenu)), - cellspacing=0, width="325px", cellpadding=2) - - directPlotButton = "" - directPlotButton = HT.Input(type='button',name='', value=' Compute ',\ - onClick="dataEditingFunc(this.form,'directPlot');",Class="button") - directPlotSortText = HT.Span(HT.Bold("Sort by: "), Class="ffl fwb fs12") - directPlotSortMenu = HT.Select(name='graphSort') - directPlotSortMenu.append(('LRS Full',0)) - directPlotSortMenu.append(('LRS Interact',1)) - directPlotPermuText = HT.Span("Permutation Test (n=500)", Class="ffl fs12") - directPlotPermu = HT.Input(type='checkbox', Class='checkbox',name='directPermuCheckbox', checked="on") - pairScanReturnText = HT.Span(HT.Bold("Return: "), Class="ffl fwb fs12") - pairScanReturnMenu = HT.Select(name='pairScanReturn') - pairScanReturnMenu.append(('top 50','50')) - pairScanReturnMenu.append(('top 100','100')) - pairScanReturnMenu.append(('top 200','200')) - pairScanReturnMenu.append(('top 500','500')) - - pairScanMenus = HT.TableLite( - HT.TR(HT.TD(directPlotSortText), HT.TD(directPlotSortMenu)), - HT.TR(HT.TD(pairScanReturnText), HT.TD(pairScanReturnMenu)), - cellspacing=0, width="232px", cellpadding=2) - - markerSuggestiveText = HT.Span(HT.Bold("Display LRS greater than:"), Class="ffl fwb fs12") - markerSuggestive = HT.Input(name='suggestive', size=5, maxlength=8) - displayAllText = HT.Span(" Display all LRS ", Class="ffl fs12") - displayAll = HT.Input(name='displayAllLRS', type="checkbox", Class='checkbox') - useParentsText = HT.Span(" Use Parents ", Class="ffl fs12") - useParents = optionbox2 - applyVarianceText = HT.Span(" Use Weighted ", Class="ffl fs12") - - markerMenu = HT.TableLite( - HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive)), - HT.TR(HT.TD(displayAll,displayAllText)), - HT.TR(HT.TD(useParents,useParentsText)), - HT.TR(HT.TD(applyVariance2,applyVarianceText)), - cellspacing=0, width="263px", cellpadding=2) - - - mapping_row = HT.TR() - mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") - - mapping_tab_list = [HT.Href(text="Interval", url="#mappingtabs-1"), HT.Href(text="Marker Regression", url="#mappingtabs-2"), HT.Href(text="Composite", url="#mappingtabs-3"), HT.Href(text="Pair-Scan", url="#mappingtabs-4")] - mapping_tabs = HT.List(mapping_tab_list) - mapping_container.append(mapping_tabs) - - interval_div = HT.Div(id="mappingtabs-1") - interval_container = HT.Span() - - intervalTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - intTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - intTD.append(intMappingMenu,HT.BR()) - - intTD.append(permCheck1,'Permutation Test (n=2000)',HT.BR(), - bootCheck1,'Bootstrap Test (n=2000)', HT.BR(), optionbox1, 'Use Parents', HT.BR(), - applyVariance1,'Use Weighted', HT.BR(), HT.BR(),IntervalMappingButton, HT.BR(), HT.BR()) - intervalTable.append(HT.TR(intTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#intmap', target='_blank', text='Interval Mapping'), - ' computes linkage maps for the entire genome or single',HT.BR(),' chromosomes.', - ' The ',HT.Href(url='/glossary.html#permutation', target='_blank', text='Permutation Test'),' estimates suggestive and significant ',HT.BR(),' linkage scores. \ - The ',HT.Href(url='/glossary.html#bootstrap', target='_blank', text='Bootstrap Test'), ' estimates the precision of the QTL location.' - ,Class="fs12"), HT.BR(), valign="top"))) - - interval_container.append(intervalTable) - interval_div.append(interval_container) - mapping_container.append(interval_div) - - # Marker Regression - - marker_div = HT.Div(id="mappingtabs-2") - marker_container = HT.Span() - - markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - markerTD.append(markerMenu,HT.BR()) - - markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) - - markerTable.append(HT.TR(markerTD),HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#',target='_blank',text='Marker regression'), - ' computes and displays LRS values for individual markers.',HT.BR(), - 'This function also lists additive effects (phenotype units per allele) and', HT.BR(), - 'dominance deviations for some datasets.', HT.BR(),Class="fs12"), HT.BR(), valign="top"))) - - marker_container.append(markerTable) - marker_div.append(marker_container) - mapping_container.append(marker_div) - - # Composite interval mapping - composite_div = HT.Div(id="mappingtabs-3") - composite_container = HT.Span() - - compositeTable = HT.TableLite(cellspacing=0, cellpadding=3, width="100%") - compTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - compTD.append(compMappingMenu,HT.BR()) - - compTD.append(permCheck2, 'Permutation Test (n=2000)',HT.BR(), - bootCheck2,'Bootstrap Test (n=2000)', HT.BR(), - optionbox3, 'Use Parents', HT.BR(), HT.BR(), CompositeMappingButton, HT.BR(), HT.BR()) - compositeTable.append(HT.TR(compTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Composite',target='_blank',text='Composite Interval Mapping'), - " allows you to control for a single marker as",HT.BR()," a cofactor. ", - "To find a control marker, run the ",HT.Bold("Marker Regression")," function."), - HT.BR(), valign="top"))) - - composite_container.append(compositeTable) - composite_div.append(composite_container) - mapping_container.append(composite_div) - - # Pair Scan - - pairscan_div = HT.Div(id="mappingtabs-4") - pairscan_container = HT.Span() - - pairScanTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - pairScanTD = HT.TD(NOWRAP='ON', Class="fs12 fwn") - pairScanTD.append(pairScanMenus,HT.BR()) - pairScanTD.append(directPlotPermu, directPlotPermuText, HT.BR(), HT.BR(), - directPlotButton,HT.BR(),HT.BR()) - pairScanTable.append(HT.TR(pairScanTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Pair_Scan', target="_blank", text='Pair-Scan'), - ' searches for pairs of chromosomal regions that are',HT.BR(), - 'involved in two-locus epistatic interactions.'), HT.BR(), valign="top"))) - - pairscan_container.append(pairScanTable) - pairscan_div.append(pairscan_container) - mapping_container.append(pairscan_div) - - mapping_row.append(HT.TD(mapping_container)) - - # Treat Interval Mapping and Marker Regression and Pair Scan as a group for displaying - #disable Interval Mapping and Marker Regression and Pair Scan for human and the dataset doesn't have genotype file - mappingMethodId = webqtlDatabaseFunction.getMappingMethod(cursor=self.cursor, groupName=RISetgp) - - mapping_script = HT.Script(language="Javascript") - mapping_script_text = """$(function() { $("#mapping_tabs").tabs(); });""" - mapping_script.append(mapping_script_text) - - submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target2") - - if mappingMethodId != None: - if int(mappingMethodId) == 1: - submitTable.append(mapping_row) - submitTable.append(mapping_script) - elif int(mappingMethodId) == 4: - # NL; 09-26-2011 testing for Human Genome Association function - mapping_row=HT.TR() - mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") - - mapping_tab_list = [HT.Href(text="Genome Association", url="#mappingtabs-1")] - mapping_tabs = HT.List(mapping_tab_list) - mapping_container.append(mapping_tabs) - - # Genome Association - markerSuggestiveText = HT.Span(HT.Bold("P Value:"), Class="ffl fwb fs12") - - markerSuggestive = HT.Input(name='pValue', value='0.001', size=10, maxlength=20,onClick="this.value='';",onBlur="if(this.value==''){this.value='0.001'};") - markerMenu = HT.TableLite(HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive),HT.TD(HT.Italic('   (e.g. 0.001 or 1e-3 or 1E-3 or 3)'))),cellspacing=0, width="400px", cellpadding=2) - MarkerRegressionButton=HT.Input(type='button',name='computePlink', value='  Compute Using PLINK  ', onClick= "validatePvalue(this.form);", Class="button") - - marker_div = HT.Div(id="mappingtabs-1") - marker_container = HT.Span() - markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - markerTD.append(markerMenu,HT.BR()) - markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) - markerTable.append(HT.TR(markerTD)) - - marker_container.append(markerTable) - marker_div.append(marker_container) - - mapping_container.append(marker_div) - mapping_row.append(HT.TD(mapping_container)) - submitTable.append(mapping_row) - submitTable.append(mapping_script) - else: - submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("mappingMethodId %s has not been implemented for this dataset yet." % mappingMethodId), id="mapping_tabs", Class="ui-tabs")))) - submitTable.append(mapping_script) - - else: - submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("Mapping options are disabled for data not matched with genotypes."), id="mapping_tabs", Class="ui-tabs")))) - submitTable.append(mapping_script) - - title4Body.append(submitTable) - - - def natural_sort(strain_list): - - sorted = [] - for strain in strain_list: - try: - strain = int(strain) - try: sorted[-1] = sorted[-1] * 10 + strain - except: sorted.append(strain) - except: - sorted.append(strain) - return sorted - - ########################################## - ## Function to display trait tables - ########################################## - def dispTraitValues(self, fd , title5Body, varianceDataPage, nCols, mainForm, thisTrait): - traitTableOptions = HT.Div(style="border: 3px solid #EEEEEE; -moz-border-radius: 10px; -webkit-border-radius: 10px; width: 625px; padding: 5px 5px 10px 8px; font-size: 12px; background: #DDDDDD;") - resetButton = HT.Input(type='button',name='resetButton',value=' Reset ',Class="button") - blockSamplesField = HT.Input(type="text",style="background-color:white;border: 1px solid black;font-size: 14px;", name="removeField") - blockSamplesButton = HT.Input(type='button',value=' Block ', name='blockSamples', Class="button") - showHideNoValue = HT.Input(type='button', name='showHideNoValue', value=' Hide No Value ',Class='button') - blockMenuSpan = HT.Span(Id="blockMenuSpan") - blockMenu = HT.Select(name='block_method') - - if fd.genotype.type == "riset": - allstrainlist_neworder = fd.f1list + fd.strainlist - else: - allstrainlist_neworder = fd.f1list + fd.parlist + fd.strainlist - - attribute_ids = [] - attribute_names = [] - try: - #ZS: Id values for this trait's extra attributes; used to create "Exclude" dropdown and query for attribute values and create - self.cursor.execute("""SELECT CaseAttribute.Id, CaseAttribute.Name - FROM CaseAttribute, CaseAttributeXRef - WHERE CaseAttributeXRef.ProbeSetFreezeId = '%s' AND - CaseAttribute.Id = CaseAttributeXRef.CaseAttributeId - group by CaseAttributeXRef.CaseAttributeId""" % (str(thisTrait.db.id))) - - exclude_menu = HT.Select(name="exclude_menu") - dropdown_menus = [] #ZS: list of dropdown menus with the distinct values of each attribute (contained in DIVs so the style parameter can be edited and they can be hidden) - - for attribute in self.cursor.fetchall(): - attribute_ids.append(attribute[0]) - attribute_names.append(attribute[1]) - for this_attr_name in attribute_names: - exclude_menu.append((this_attr_name.capitalize(), this_attr_name)) - self.cursor.execute("""SELECT DISTINCT CaseAttributeXRef.Value - FROM CaseAttribute, CaseAttributeXRef - WHERE CaseAttribute.Name = '%s' AND - CaseAttributeXRef.CaseAttributeId = CaseAttribute.Id""" % (this_attr_name)) - try: - distinct_values = self.cursor.fetchall() - attr_value_menu_div = HT.Div(style="display:none;", Class="attribute_values") #container used to show/hide dropdown menus - attr_value_menu = HT.Select(name=this_attr_name) - attr_value_menu.append(("None", "show_all")) - for value in distinct_values: - attr_value_menu.append((str(value[0]), value[0])) - attr_value_menu_div.append(attr_value_menu) - dropdown_menus.append(attr_value_menu_div) - except: - pass - except: - pass - - other_strains = [] - for strain in thisTrait.data.keys(): - if strain not in allstrainlist_neworder: - other_strains.append(strain) - - if other_strains: - blockMenu.append(('%s Only' % fd.RISet,'1')) - blockMenu.append(('Non-%s Only' % fd.RISet,'0')) - blockMenuSpan.append(blockMenu) - else: - pass - - showHideOutliers = HT.Input(type='button', name='showHideOutliers', value=' Hide Outliers ', Class='button') - showHideMenuOptions = HT.Span(Id="showHideOptions", style="line-height:225%;") - if other_strains: - showHideMenuOptions.append(HT.Bold("  Block samples by index:    "), blockSamplesField, "   ", blockMenuSpan, "   ", blockSamplesButton, HT.BR()) - else: - showHideMenuOptions.append(HT.Bold("  Block samples by index:    "), blockSamplesField, "   ", blockSamplesButton, HT.BR()) - - exportButton = HT.Input(type='button', name='export', value=' Export ', Class='button') - if len(attribute_names) > 0: - excludeButton = HT.Input(type='button', name='excludeGroup', value=' Block ', Class='button') - showHideMenuOptions.append(HT.Bold("  Block samples by group:"), " "*5, exclude_menu, " "*5) - for menu in dropdown_menus: - showHideMenuOptions.append(menu) - showHideMenuOptions.append(" "*5, excludeButton, HT.BR()) - showHideMenuOptions.append(HT.Bold("  Options:"), " "*5, showHideNoValue, " "*5, showHideOutliers, " "*5, resetButton, " "*5, exportButton) - - traitTableOptions.append(showHideMenuOptions,HT.BR(),HT.BR()) - traitTableOptions.append(HT.Span("  Outliers highlighted in ", HT.Bold(" yellow ", style="background-color:yellow;"), " can be hidden using the ", - HT.Strong(" Hide Outliers "), " button,",HT.BR(),"  and samples with no value (x) can be hidden by clicking ", - HT.Strong(" Hide No Value "), "."), HT.BR()) - - - dispintro = HT.Paragraph("Edit or delete values in the Trait Data boxes, and use the ", HT.Strong("Reset"), " option as needed.",Class="fs12", style="margin-left:20px;") - - table = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target5") #Everything needs to be inside this table object in order for the toggle to work - container = HT.Div() #This will contain everything and be put into a cell of the table defined above - - container.append(dispintro, traitTableOptions, HT.BR()) - - primary_table = HT.TableLite(cellspacing=0, cellpadding=0, Id="sortable1", Class="tablesorter") - primary_header = self.getTableHeader(fd=fd, thisTrait=thisTrait, nCols=nCols, attribute_names=attribute_names) #Generate header for primary table object - - other_strainsExist = False - for strain in thisTrait.data.keys(): - if strain not in allstrainlist_neworder: - other_strainsExist = True - break - - primary_body = self.addTrait2Table(fd=fd, varianceDataPage=varianceDataPage, strainlist=allstrainlist_neworder, mainForm=mainForm, thisTrait=thisTrait, other_strainsExist=other_strainsExist, attribute_ids=attribute_ids, attribute_names=attribute_names, strains='primary') - - primary_table.append(primary_header) - for i in range(len(primary_body)): - primary_table.append(primary_body[i]) - - other_strains = [] - for strain in thisTrait.data.keys(): - if strain not in allstrainlist_neworder: - allstrainlist_neworder.append(strain) - other_strains.append(strain) - - if other_strains: - other_table = HT.TableLite(cellspacing=0, cellpadding=0, Id="sortable2", Class="tablesorter") #Table object with other (for example, non-BXD / MDP) traits - other_header = self.getTableHeader(fd=fd, thisTrait=thisTrait, nCols=nCols, attribute_names=attribute_names) #Generate header for other table object; same function is used as the one used for the primary table, since the header is the same - other_strains.sort() #Sort other strains - other_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + other_strains #Append F1 and parent strains to the beginning of the sorted list of other strains - - MDPText = HT.Span("Samples:", Class="ffl fwb fs12") - MDPMenu1 = HT.Select(name='MDPChoice1') - MDPMenu2 = HT.Select(name='MDPChoice2') - MDPMenu3 = HT.Select(name='MDPChoice3') - MDPMenu1.append(('%s Only' % fd.RISet,'1')) - MDPMenu2.append(('%s Only' % fd.RISet,'1')) - MDPMenu3.append(('%s Only' % fd.RISet,'1')) - MDPMenu1.append(('Non-%s Only' % fd.RISet,'2')) - MDPMenu2.append(('Non-%s Only' % fd.RISet,'2')) - MDPMenu3.append(('Non-%s Only' % fd.RISet,'2')) - MDPMenu1.append(('All Cases','0')) - MDPMenu2.append(('All Cases','0')) - MDPMenu3.append(('All Cases','0')) - self.MDPRow1.append(HT.TD(MDPText),HT.TD(MDPMenu1)) - self.MDPRow2.append(HT.TD(MDPText),HT.TD(MDPMenu2)) - self.MDPRow3.append(HT.TD(MDPText),HT.TD(MDPMenu3)) - - other_body = self.addTrait2Table(fd=fd, varianceDataPage=varianceDataPage, strainlist=other_strains, mainForm=mainForm, thisTrait=thisTrait, attribute_ids=attribute_ids, attribute_names=attribute_names, strains='other') - - other_table.append(other_header) - for i in range(len(other_body)): - other_table.append(other_body[i]) - else: - pass - - if other_strains or (fd.f1list and thisTrait.data.has_key(fd.f1list[0])) \ - or (fd.f1list and thisTrait.data.has_key(fd.f1list[1])): - fd.allstrainlist = allstrainlist_neworder - - if nCols == 6 and fd.varianceDispName != 'Variance': - mainForm.append(HT.Input(name='isSE', value="yes", type='hidden')) - - primary_div = HT.Div(primary_table, Id="primary") #Container for table with primary (for example, BXD) strain values - container.append(primary_div) - - if other_strains: - other_div = HT.Div(other_table, Id="other") #Container for table with other (for example, Non-BXD/MDP) strain values - container.append(HT.Div(' ', height=30)) - container.append(other_div) - - table.append(HT.TR(HT.TD(container))) - title5Body.append(table) - - def addTrait2Table(self, fd, varianceDataPage, strainlist, mainForm, thisTrait, other_strainsExist=None, attribute_ids=[], attribute_names=[], strains='primary'): - #XZ, Aug 23, 2010: I commented the code related to the display of animal case - #strainInfo = thisTrait.has_key('strainInfo') and thisTrait.strainInfo - - table_body = [] - vals = [] - - for i, strainNameOrig in enumerate(strainlist): - strainName = strainNameOrig.replace("_2nd_", "") - - try: - thisval = thisTrait.data[strainName].val - thisvar = thisTrait.data[strainName].var - thisValFull = [strainName,thisval,thisvar] - except: - continue - - vals.append(thisValFull) - - upperBound, lowerBound = Plot.findOutliers(vals) # ZS: Values greater than upperBound or less than lowerBound are considered outliers. - - for i, strainNameOrig in enumerate(strainlist): - - trId = strainNameOrig - selectCheck = HT.Input(type="checkbox", name="selectCheck", value=trId, Class="checkbox", onClick="highlight(this)") - - strainName = strainNameOrig.replace("_2nd_", "") - strainNameAdd = '' - if fd.RISet == 'AXBXA' and strainName in ('AXB18/19/20','AXB13/14','BXA8/17'): - strainNameAdd = HT.Href(url='/mouseCross.html#AXB/BXA', text=HT.Sup('#'), Class='fs12', target="_blank") - - try: - thisval, thisvar, thisNP = thisTrait.data[strainName].val, thisTrait.data[strainName].var, thisTrait.data[strainName].N - if thisNP: - mainForm.append(HT.Input(name='N'+strainName, value=thisNP, type='hidden')) - else: - pass - except: - thisval = thisvar = 'x' - - try: - traitVal = thisval - dispVal = "%2.3f" % thisval - except: - traitVal = '' - dispVal = 'x' - - strainNameDisp = HT.Span(strainName, Class='fs14 fwn ffl') - - if varianceDataPage: - try: - traitVar = thisvar - dispVar = "%2.3f" % thisvar - except: - traitVar = '' - dispVar = 'x' - - if thisval == 'x': - traitVar = '' #ZS: Used to be 0, but it doesn't seem like a good idea for values of 0 to *always* be at the bottom when you sort; it makes more sense to put "nothing" - - className = 'fs13 b1 c222 ' - valueClassName = 'fs13 b1 c222 valueField ' - rowClassName = 'novalue ' - else: - if (thisval >= upperBound) or (thisval <= lowerBound): - className = 'fs13 b1 c222 outlier ' - valueClassName = 'fs13 b1 c222 valueField ' - rowClassName = 'outlier' - else: - className = 'fs13 b1 c222 ' - valueClassName = 'fs13 b1 c222 valueField ' - rowClassName = ' ' - - if varianceDataPage: - varClassName = valueClassName + str(traitVar) - valueClassName += str(traitVal) - - if strainNameOrig == strainName: - if other_strainsExist and strainNameOrig in (fd.parlist + fd.f1list): - ######################################################################################################################################################## - # ZS: Append value and variance to the value and variance input fields' list of classes; this is so the javascript can update the value when the user - # changes it. The updated value is then used when the table is sorted (tablesorter.js). This needs to be done because the "value" attribute is immutable. - ######################################################################################################################################################### - - valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right; background-color:#FFFFFF;", value=dispVal, - onChange= "javascript:this.form['_2nd_%s'].value=this.form['%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=valueClassName) - if varianceDataPage: - seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, - onChange= "javascript:this.form['V_2nd_%s'].value=this.form['V%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=varClassName) - else: - valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right; background-color:#FFFFFF;", value=dispVal, Class=valueClassName) - if varianceDataPage: - seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, Class=varClassName) - else: - valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVal, - onChange= "javascript:this.form['%s'].value=this.form['%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=valueClassName) - if varianceDataPage: - seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, - onChange= "javascript:this.form['V%s'].value=this.form['V%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=varClassName) - - if (strains == 'primary'): - table_row = HT.TR(Id="Primary_"+str(i+1), Class=rowClassName) - else: - table_row = HT.TR(Id="Other_"+str(i+1), Class=rowClassName) - - if varianceDataPage: - table_row.append(HT.TD(str(i+1), selectCheck, width=45, align='right', Class=className)) - table_row.append(HT.TD(strainNameDisp, strainNameAdd, align='right', width=100, Class=className)) - table_row.append(HT.TD(valueField, width=70, align='right', Id="value_"+str(i)+"_"+strains, Class=className)) - table_row.append(HT.TD("±", width=20, align='center', Class=className)) - table_row.append(HT.TD(seField, width=80, align='right', Id="SE_"+str(i)+"_"+strains, Class=className)) - else: - table_row.append(HT.TD(str(i+1), selectCheck, width=45, align='right', Class=className)) - table_row.append(HT.TD(strainNameDisp, strainNameAdd, align='right', width=100, Class=className)) - table_row.append(HT.TD(valueField, width=70, align='right', Id="value_"+str(i)+"_"+strains, Class=className)) - - if thisTrait and thisTrait.db and thisTrait.db.type =='ProbeSet': - if len(attribute_ids) > 0: - - #ZS: Get StrainId value for the next query - self.cursor.execute("""SELECT Strain.Id - FROM Strain, StrainXRef, InbredSet - WHERE Strain.Name = '%s' and - StrainXRef.StrainId = Strain.Id and - InbredSet.Id = StrainXRef.InbredSetId and - InbredSet.Name = '%s'""" % (strainName, fd.RISet)) - - strain_id = self.cursor.fetchone()[0] - - attr_counter = 1 # This is needed so the javascript can know which attribute type to associate this value with for the exported excel sheet (each attribute type being a column). - for attribute_id in attribute_ids: - - #ZS: Add extra case attribute values (if any) - self.cursor.execute("""SELECT Value - FROM CaseAttributeXRef - WHERE ProbeSetFreezeId = '%s' AND - StrainId = '%s' AND - CaseAttributeId = '%s' - group by CaseAttributeXRef.CaseAttributeId""" % (thisTrait.db.id, strain_id, str(attribute_id))) - - attributeValue = self.cursor.fetchone()[0] #Trait-specific attributes, if any - - #ZS: If it's an int, turn it into one for sorting (for example, 101 would be lower than 80 if they're strings instead of ints) - try: - attributeValue = int(attributeValue) - except: - pass - - span_Id = strains+"_attribute"+str(attr_counter)+"_sample"+str(i+1) - attr_container = HT.Span(attributeValue, Id=span_Id) - attr_className = str(attributeValue) + " " + className - table_row.append(HT.TD(attr_container, align='right', Class=attr_className)) - attr_counter += 1 - - table_body.append(table_row) - return table_body - - def getTableHeader(self, fd, thisTrait, nCols, attribute_names): - - table_header = HT.TR() - - col_class = "fs13 fwb ff1 b1 cw cbrb" - - if nCols == 6: - try: - if fd.varianceDispName: - pass - except: - fd.varianceDispName = 'Variance' - - table_header.append(HT.TH('Index', align='right', width=60, Class=col_class), - HT.TH('Sample', align='right', width=100, Class=col_class), - HT.TH('Value', align='right', width=70, Class=col_class), - HT.TH(' ', width=20, Class=col_class), - HT.TH(fd.varianceDispName, align='right', width=80, Class=col_class)) - - elif nCols == 4: - table_header.append(HT.TH('Index', align='right', width=60, Class=col_class), - HT.TH('Sample', align='right', width=100, Class=col_class), - HT.TH('Value', align='right', width=70, Class=col_class)) - - else: - pass - - if len(attribute_names) > 0: - i=0 - for attribute in attribute_names: - char_count = len(attribute) - cell_width = char_count * 14 - table_header.append(HT.TH(attribute, align='right', width=cell_width, Class="attribute_name " + col_class)) - i+=1 - - return table_header - - - def getSortByValue(self): - - sortby = ("", "") - - return sortby + def __init__(self, fd, thisTrait=None): + + templatePage.__init__(self, fd) + + self.dict['title'] = 'Data Editing' + TD_LR = HT.TD(valign="top",width="100%",bgcolor="#fafafa") + + if not self.openMysql(): + return + if not fd.genotype: + fd.readData(incf1=1) + + ############################# + # determine data editing page format + ############################# + varianceDataPage = 0 + if fd.formID == 'varianceChoice': + varianceDataPage = 1 + + if varianceDataPage: + fmID='dataEditing' + nCols = 6 + else: + if fd.enablevariance: + fmID='pre_dataEditing' + nCols = 4 + else: + fmID='dataEditing' + nCols = 4 + + ############################# + ## titles, etc. + ############################# + + #titleTop = HT.Div() + # + #title1 = HT.Paragraph("  Details and Links", style="border-radius: 5px;", Id="title1", Class="sectionheader") + #title1Body = HT.Paragraph(Id="sectionbody1") + # + #if fd.enablevariance and not varianceDataPage: + # title2 = HT.Paragraph("  Submit Variance", style="border-radius: 5px;", Id="title2", Class="sectionheader") + #else: + # title2 = HT.Paragraph("  Basic Statistics", style="border-radius: 5px;", Id="title2", Class="sectionheader") + #title2Body = HT.Paragraph(Id="sectionbody2") + # + #title3 = HT.Paragraph("  Calculate Correlations", style="border-radius: 5px;", Id="title3", Class="sectionheader") + #title3Body = HT.Paragraph(Id="sectionbody3") + # + #title4 = HT.Paragraph("  Mapping Tools", style="border-radius: 5px;", Id="title4", Class="sectionheader") + #title4Body = HT.Paragraph(Id="sectionbody4") + # + #title5 = HT.Paragraph("  Review and Edit Data", style="border-radius: 5px;", Id="title5", Class="sectionheader") + #title5Body = HT.Paragraph(Id="sectionbody5") + + ############################# + ## Hidden field + ############################# + + # Some fields, like method, are defaulted to None; otherwise in IE the field can't be changed using jquery + hddn = { + 'FormID':fmID, + 'RISet':fd.RISet, + 'submitID':'', + 'scale':'physic', + 'additiveCheck':'ON', + 'showSNP':'ON', + 'showGenes':'ON', + 'method':None, + 'parentsf14regression':'OFF', + 'stats_method':'1', + 'chromosomes':'-1', + 'topten':'', + 'viewLegend':'ON', + 'intervalAnalystCheck':'ON', + 'valsHidden':'OFF', + 'database':'', + 'criteria':None, + 'MDPChoice':None, + 'bootCheck':None, + 'permCheck':None, + 'applyVarianceSE':None, + 'strainNames':'_', + 'strainVals':'_', + 'strainVars':'_', + 'otherStrainNames':'_', + 'otherStrainVals':'_', + 'otherStrainVars':'_', + 'extra_attributes':'_', + 'other_extra_attributes':'_' + } + + if fd.enablevariance: + hddn['enablevariance']='ON' + if fd.incparentsf1: + hddn['incparentsf1']='ON' + + if thisTrait: + hddn['fullname'] = str(thisTrait) + try: + hddn['normalPlotTitle'] = thisTrait.symbol + hddn['normalPlotTitle'] += ": " + hddn['normalPlotTitle'] += thisTrait.name + except: + hddn['normalPlotTitle'] = str(thisTrait.name) + hddn['fromDataEditingPage'] = 1 + if thisTrait.db and thisTrait.db.type and thisTrait.db.type == 'ProbeSet': + hddn['trait_type'] = thisTrait.db.type + if thisTrait.cellid: + hddn['cellid'] = thisTrait.cellid + else: + self.cursor.execute("SELECT h2 from ProbeSetXRef WHERE DataId = %d" % thisTrait.mysqlid) + heritability = self.cursor.fetchone() + hddn['heritability'] = heritability + + hddn['attribute_names'] = "" + + hddn['mappingMethodId'] = webqtlDatabaseFunction.getMappingMethod (cursor=self.cursor, groupName=fd.RISet) + + ############################# + ## Display Trait Information + ############################# + + #headSpan = self.dispHeader(fd,thisTrait) #Draw header + # + #titleTop.append(headSpan) + + if fd.identification: + hddn['identification'] = fd.identification + + else: + hddn['identification'] = "Un-named trait" #If no identification, set identification to un-named + + self.dispTraitInformation(fd, "", hddn, thisTrait) #Display trait information + function buttons + + ############################# + ## Generate form and buttons + ############################# + + mainForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), + name='dataInput', submit=HT.Input(type='hidden')) + + next=HT.Input(type='submit', name='submit',value='Next',Class="button") + reset=HT.Input(type='Reset',name='',value=' Reset ',Class="button") + correlationMenus = [] + + if thisTrait == None: + thisTrait = webqtlTrait(data=fd.allTraitData, db=None) + + # Variance submit page only + if fd.enablevariance and not varianceDataPage: + title2Body.append("Click the next button to go to the variance submission form.", + HT.Center(next,reset)) + else: + self.dispBasicStatistics(fd, title2Body, thisTrait) + self.dispCorrelationTools(fd, title3Body, thisTrait) + self.dispMappingTools(fd, title4Body, thisTrait) + + ############################# + ## Trait Value Table + ############################# + + self.dispTraitValues(fd, title5Body, varianceDataPage, nCols, mainForm, thisTrait) + + if fd.allstrainlist: + hddn['allstrainlist'] = string.join(fd.allstrainlist, ' ') + for key in hddn.keys(): + mainForm.append(HT.Input(name=key, value=hddn[key], type='hidden')) + + if fd.enablevariance and not varianceDataPage: + #pre dataediting page, need to submit variance + mainForm.append(titleTop, title1,title1Body,title2,title2Body,title3,title3Body,title4,title4Body,title5,title5Body) + else: + mainForm.append(titleTop, title1,title1Body,title2,title2Body,title3,title3Body,title4,title4Body,title5,title5Body) + TD_LR.append(HT.Paragraph(mainForm)) + self.dict['body'] = str(TD_LR) + + ########################################## + ## Function to display header + ########################################## + def dispHeader(self, fd, thisTrait): + headSpan = HT.Div(style="font-size:14px;") + + #If trait, use trait name; otherwise, use identification value + if thisTrait: + if thisTrait.cellid: + headSpan.append(HT.Strong('Trait Data and Analysis ', style='font-size:16px;'),' for Probe ID ', thisTrait.cellid) + else: + headSpan.append(HT.Strong('Trait Data and Analysis ', style='font-size:16px;'),' for Record ID ', thisTrait.name) + else: + if fd.identification: + headSpan.append(HT.Strong('Trait ID ', style='font-size:16px;'),fd.identification) + else: + headSpan.append(HT.Strong('Un-named Trait', style='font-size:16px;')) + + return headSpan + + ########################################## + ## Function to display trait infos + ########################################## + def dispTraitInformation(self, fd, title1Body, hddn, thisTrait): + + _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) + + #tbl = HT.TableLite(cellpadding=2, Class="collap", style="margin-left:20px;", width="840", valign="top", id="target1") + + #reset=HT.Input(type='Reset',name='',value=' Reset ',Class="button") + + #XZ, August 02, 2011: The display of icons is decided by the trait type (if trait exists), along with user log-in status. Note that the new submitted trait might not be trait object. + addSelectionButton = "" + verifyButton = "" + rnaseqButton = "" + geneWikiButton = "" + probeButton = "" + similarButton = "" + snpBrowserButton = "" + updateButton = "" + + addSelectionText = "" + verifyText = "" + rnaseqText = "" + geneWikiText = "" + probeText = "" + similarText = "" + snpBrowserText = "" + updateText = "" + + if webqtlConfig.USERDICT[self.privilege] >= webqtlConfig.USERDICT['user']: + + if thisTrait==None or thisTrait.db.type=='Temp': + updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'addPublish');") + updateButton_img = HT.Image("/images/edit_icon.jpg", name="addnew", alt="Add To Publish", title="Add To Publish", style="border:none;") + updateButton.append(updateButton_img) + updateText = "Edit" + elif thisTrait.db.type != 'Temp': + if thisTrait.db.type == 'Publish' and thisTrait.confidential: #XZ: confidential phenotype trait + if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=thisTrait.authorized_users): + updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") + updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") + updateButton.append(updateButton_img) + updateText = "Edit" + else: + updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") + updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") + updateButton.append(updateButton_img) + updateText = "Edit" + else: + pass + + self.cursor.execute('SELECT Name FROM InbredSet WHERE Name="%s"' % fd.RISet) + if thisTrait: + addSelectionButton = HT.Href(url="#redirect", onClick="addRmvSelection('%s', document.getElementsByName('%s')[0], 'addToSelection');" % (fd.RISet, 'dataInput')) + addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="addselect", alt="Add To Collection", title="Add To Collection", style="border:none;") + #addSelectionButton.append(addSelectionButton_img) + addSelectionText = "Add" + elif self.cursor.fetchall(): + addSelectionButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('%s')[0], 'addRecord');" % ('dataInput')) + addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="", alt="Add To Collection", title="Add To Collection", style="border:none;") + #addSelectionButton.append(addSelectionButton_img) + addSelectionText = "Add" + else: + pass + + + # Microarray database information to display + if thisTrait and thisTrait.db and thisTrait.db.type == 'ProbeSet': #before, this line was only reached if thisTrait != 0, but now we need to check + try: + hddn['GeneId'] = int(string.strip(thisTrait.geneid)) + except: + pass + + #Info2Disp = HT.Paragraph() + + #XZ: Gene Symbol + if thisTrait.symbol: + #XZ: Show SNP Browser only for mouse + if _Species == 'mouse': + self.cursor.execute("select geneSymbol from GeneList where geneSymbol = %s", thisTrait.symbol) + geneName = self.cursor.fetchone() + if geneName: + snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + "&geneName=%s" % geneName[0] + else: + if thisTrait.chr and thisTrait.mb: + snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + \ + "&chr=%s&start=%2.6f&end=%2.6f" % (thisTrait.chr, thisTrait.mb-0.002, thisTrait.mb+0.002) + else: + snpurl = "" + + if snpurl: + snpBrowserButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % snpurl) + snpBrowserButton_img = HT.Image("/images/snp_icon.jpg", name="snpbrowser", alt=" View SNPs and Indels ", title=" View SNPs and Indels ", style="border:none;") + snpBrowserButton.append(snpBrowserButton_img) + snpBrowserText = "SNPs" + + #XZ: Show GeneWiki for all species + geneWikiButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + "?FormID=geneWiki&symbol=%s" % thisTrait.symbol)) + geneWikiButton_img = HT.Image("/images/genewiki_icon.jpg", name="genewiki", alt=" Write or review comments about this gene ", title=" Write or review comments about this gene ", style="border:none;") + geneWikiButton.append(geneWikiButton_img) + geneWikiText = 'GeneWiki' + + #XZ: display similar traits in other selected datasets + if thisTrait and thisTrait.db and thisTrait.db.type=="ProbeSet" and thisTrait.symbol: + if _Species in ("mouse", "rat", "human"): + similarUrl = "%s?cmd=sch&gene=%s&alias=1&species=%s" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), thisTrait.symbol, _Species) + similarButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % similarUrl) + similarButton_img = HT.Image("/images/find_icon.jpg", name="similar", alt=" Find similar expression data ", title=" Find similar expression data ", style="border:none;") + similarButton.append(similarButton_img) + similarText = "Find" + else: + pass + tbl.append(HT.TR( + HT.TD('Gene Symbol: ', Class="fwb fs13", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span('%s' % thisTrait.symbol, valign="top", Class="fs13 fsI"), valign="top", width=740) + )) + else: + tbl.append(HT.TR( + HT.TD('Gene Symbol: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span('Not available', Class="fs13 fsI"), valign="top") + )) + + #XZ: Gene Alias + if thisTrait.alias: + alias = string.replace(thisTrait.alias, ";", " ") + alias = string.join(string.split(alias), ", ") + tbl.append(HT.TR( + HT.TD('Aliases: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(alias, Class="fs13 fsI"), valign="top") + )) + + #XZ: Description + if thisTrait.description: + tSpan = HT.Span(thisTrait.description, Class="fs13") + if thisTrait.probe_target_description: + tSpan.append('; ', thisTrait.probe_target_description) + else: + tSpan = HT.Span('Not available', Class="fs13") + tbl.append(HT.TR( + HT.TD('Description: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top") + )) + + #XZ: Location + + #XZ: deal with Chr and Mb + if thisTrait.chr and thisTrait.mb: + tSpan = HT.Span('Chr %s @ %s Mb' % (thisTrait.chr,thisTrait.mb),Class="fs13") + elif (thisTrait.chr): + tSpan = HT.Span('Chr %s @ Unknown position' % (thisTrait.chr), Class="fs13") + else: + tSpan = HT.Span('Not available', Class="fs13") + + #XZ: deal with direction + if thisTrait.strand_probe == '+': + tSpan.append(' on the plus strand ') + elif thisTrait.strand_probe == '-': + tSpan.append(' on the minus strand ') + else: + pass + + tbl.append(HT.TR( + HT.TD('Location: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top") + )) + + ##display Verify Location button + try: + blatsequence = thisTrait.blatseq + if not blatsequence: + #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. + self.cursor.execute("""SELECT Probe.Sequence, Probe.Name + FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeSet.Name = '%s' AND + Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""" % (thisTrait.db.name, thisTrait.name) ) + seqs = self.cursor.fetchall() + if not seqs: + raise ValueError + else: + blatsequence = '' + for seqt in seqs: + if int(seqt[1][-1]) % 2 == 1: + blatsequence += string.strip(seqt[0]) + + #--------Hongqiang add this part in order to not only blat ProbeSet, but also blat Probe + blatsequence = '%3E'+thisTrait.name+'%0A'+blatsequence+'%0A' + #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. + self.cursor.execute("""SELECT Probe.Sequence, Probe.Name + FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeSet.Name = '%s' AND + Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""" % (thisTrait.db.name, thisTrait.name) ) + + seqs = self.cursor.fetchall() + for seqt in seqs: + if int(seqt[1][-1]) %2 == 1: + blatsequence += '%3EProbe_'+string.strip(seqt[1])+'%0A'+string.strip(seqt[0])+'%0A' + #-------- + #XZ, 07/16/2009: targetsequence is not used, so I comment out this block + #targetsequence = thisTrait.targetseq + #if targetsequence==None: + # targetsequence = "" + + #XZ: Pay attention to the parameter of version (rn, mm, hg). They need to be changed if necessary. + if _Species == "rat": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', blatsequence) + UTHSC_BLAT_URL = "" + elif _Species == "mouse": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', blatsequence) + UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', blatsequence) + elif _Species == "human": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) + UTHSC_BLAT_URL = "" + else: + UCSC_BLAT_URL = "" + UTHSC_BLAT_URL = "" + + if UCSC_BLAT_URL: + verifyButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UCSC_BLAT_URL) + verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", + title=" Check probe locations at UCSC ", style="border:none;") + verifyButton.append(verifyButtonImg) + verifyText = 'Verify' + if UTHSC_BLAT_URL: + rnaseqButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UTHSC_BLAT_URL) + rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", + title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") + rnaseqButton.append(rnaseqButtonImg) + rnaseqText = 'RNA-seq' + tSpan.append(HT.BR()) + except: + pass + + #Display probe information (if any) + if thisTrait.db.name.find('Liver') >= 0 and thisTrait.db.name.find('F2') < 0: + pass + else: + #query database for number of probes associated with trait; if count > 0, set probe tool button and text + self.cursor.execute("""SELECT count(*) + FROM Probe, ProbeSet + WHERE ProbeSet.Name = '%s' AND Probe.ProbeSetId = ProbeSet.Id""" % (thisTrait.name)) + + probeResult = self.cursor.fetchone() + if probeResult[0] > 0: + probeurl = "%s?FormID=showProbeInfo&database=%s&ProbeSetID=%s&CellID=%s&RISet=%s&incparentsf1=ON" \ + % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), thisTrait.db, thisTrait.name, thisTrait.cellid, fd.RISet) + probeButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % probeurl) + probeButton_img = HT.Image("/images/probe_icon.jpg", name="probe", alt=" Check sequence of probes ", title=" Check sequence of probes ", style="border:none;") + probeButton.append(probeButton_img) + probeText = "Probes" + + tSpan = HT.Span(Class="fs13") + + #XZ: deal with blat score and blat specificity. + if thisTrait.probe_set_specificity or thisTrait.probe_set_blat_score: + if thisTrait.probe_set_specificity: + tSpan.append(HT.Href(url="/blatInfo.html", target="_blank", title="Values higher than 2 for the specificity are good", text="BLAT specificity", Class="non_bold"),": %.1f" % float(thisTrait.probe_set_specificity), " "*3) + if thisTrait.probe_set_blat_score: + tSpan.append("Score: %s" % int(thisTrait.probe_set_blat_score), " "*2) + + onClick="openNewWin('/blatInfo.html')" + + tbl.append(HT.TR( + HT.TD('Target Score: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top") + )) + + tSpan = HT.Span(Class="fs13") + tSpan.append(str(_Species).capitalize(), ", ", fd.RISet) + + tbl.append(HT.TR( + HT.TD('Species and Group: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top") + )) + + if thisTrait.cellid: + self.cursor.execute(""" + select ProbeFreeze.Name from ProbeFreeze, ProbeSetFreeze + where + ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND + ProbeSetFreeze.Id = %d""" % thisTrait.db.id) + probeDBName = self.cursor.fetchone()[0] + tbl.append(HT.TR( + HT.TD('Database: ', Class="fs13 fwb", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span('%s' % probeDBName, Class="non_bold"), valign="top") + )) + else: + tbl.append(HT.TR( + HT.TD('Database: ', Class="fs13 fwb", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(HT.Href(text=thisTrait.db.fullname, url = webqtlConfig.INFOPAGEHREF % thisTrait.db.name, + target='_blank', Class="fs13 fwn non_bold"), valign="top") + )) + + #XZ: ID links + if thisTrait.genbankid or thisTrait.geneid or thisTrait.unigeneid or thisTrait.omim or thisTrait.homologeneid: + idStyle = "background:#dddddd;padding:2" + tSpan = HT.Span(Class="fs13") + if thisTrait.geneid: + gurl = HT.Href(text= 'Gene', target='_blank',\ + url=webqtlConfig.NCBI_LOCUSID % thisTrait.geneid, Class="fs14 fwn", title="Info from NCBI Entrez Gene") + tSpan.append(HT.Span(gurl, style=idStyle), " "*2) + if thisTrait.omim: + gurl = HT.Href(text= 'OMIM', target='_blank', \ + url= webqtlConfig.OMIM_ID % thisTrait.omim,Class="fs14 fwn", title="Summary from On Mendelian Inheritance in Man") + tSpan.append(HT.Span(gurl, style=idStyle), " "*2) + if thisTrait.unigeneid: + try: + gurl = HT.Href(text= 'UniGene',target='_blank',\ + url= webqtlConfig.UNIGEN_ID % tuple(string.split(thisTrait.unigeneid,'.')[:2]),Class="fs14 fwn", title="UniGene ID") + tSpan.append(HT.Span(gurl, style=idStyle), " "*2) + except: + pass + if thisTrait.genbankid: + thisTrait.genbankid = '|'.join(thisTrait.genbankid.split('|')[0:10]) + if thisTrait.genbankid[-1]=='|': + thisTrait.genbankid=thisTrait.genbankid[0:-1] + gurl = HT.Href(text= 'GenBank', target='_blank', \ + url= webqtlConfig.GENBANK_ID % thisTrait.genbankid,Class="fs14 fwn", title="Find the original GenBank sequence used to design the probes") + tSpan.append(HT.Span(gurl, style=idStyle), " "*2) + if thisTrait.homologeneid: + hurl = HT.Href(text= 'HomoloGene', target='_blank',\ + url=webqtlConfig.HOMOLOGENE_ID % thisTrait.homologeneid, Class="fs14 fwn", title="Find similar genes in other species") + tSpan.append(HT.Span(hurl, style=idStyle), " "*2) + + tbl.append( + HT.TR(HT.TD(colspan=3,height=6)), + HT.TR( + HT.TD('Resource Links: ', Class="fwb fs13", valign="top", nowrap="on"), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top") + )) + + #XZ: Resource Links: + if thisTrait.symbol: + linkStyle = "background:#dddddd;padding:2" + tSpan = HT.Span(style="font-family:verdana,serif;font-size:13px") + + #XZ,12/26/2008: Gene symbol may contain single quotation mark. + #For example, Affymetrix, mouse430v2, 1440338_at, the symbol is 2'-Pde (geneid 211948) + #I debug this by using double quotation marks. + if _Species == "rat": + + #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more + #symatlas_species = "Rattus norvegicus" + + #self.cursor.execute("SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = '%s'" % thisTrait.symbol) + self.cursor.execute('SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = "%s"' % thisTrait.symbol) + try: + kgId, chr, txst, txen = self.cursor.fetchall()[0] + if chr and txst and txen and kgId: + txst = int(txst*1000000) + txen = int(txen*1000000) + tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ + title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('rn3',kgId,chr,txst,txen),Class="fs14 fwn"), style=linkStyle) + , " "*2) + except: + pass + if _Species == "mouse": + + #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more + #symatlas_species = "Mus musculus" + + #self.cursor.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = '%s'" % thisTrait.symbol) + self.cursor.execute('SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = "%s"' % thisTrait.symbol) + try: + chr, txst, txen = self.cursor.fetchall()[0] + if chr and txst and txen and thisTrait.refseq_transcriptid : + txst = int(txst*1000000) + txen = int(txen*1000000) + tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ + title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('mm9',thisTrait.refseq_transcriptid,chr,txst,txen), + Class="fs14 fwn"), style=linkStyle) + , " "*2) + except: + pass + + #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more + #tSpan.append(HT.Span(HT.Href(text= 'SymAtlas',target="mainFrame",\ + # url="http://symatlas.gnf.org/SymAtlas/bioentry?querytext=%s&query=14&species=%s&type=Expression" \ + # % (thisTrait.symbol,symatlas_species),Class="fs14 fwn", \ + # title="Expression across many tissues and cell types"), style=linkStyle), " "*2) + if thisTrait.geneid and (_Species == "mouse" or _Species == "rat" or _Species == "human"): + tSpan.append(HT.Span(HT.Href(text= 'BioGPS',target="mainFrame",\ + url="http://biogps.gnf.org/?org=%s#goto=genereport&id=%s" \ + % (_Species, thisTrait.geneid),Class="fs14 fwn", \ + title="Expression across many tissues and cell types"), style=linkStyle), " "*2) + tSpan.append(HT.Span(HT.Href(text= 'STRING',target="mainFrame",\ + url="http://string.embl.de/newstring_cgi/show_link_summary.pl?identifier=%s" \ + % thisTrait.symbol,Class="fs14 fwn", \ + title="Protein interactions: known and inferred"), style=linkStyle), " "*2) + if thisTrait.symbol: + #ZS: The "species scientific" converts the plain English species names we're using to their scientific names, which are needed for PANTHER's input + #We should probably use the scientific name along with the English name (if not instead of) elsewhere as well, given potential non-English speaking users + if _Species == "mouse": + species_scientific = "Mus%20musculus" + elif _Species == "rat": + species_scientific = "Rattus%20norvegicus" + elif _Species == "human": + species_scientific = "Homo%20sapiens" + elif _Species == "drosophila": + species_scientific = "Drosophila%20melanogaster" + else: + species_scientific = "all" + + species_scientific + tSpan.append(HT.Span(HT.Href(text= 'PANTHER',target="mainFrame", \ + url="http://www.pantherdb.org/genes/geneList.do?searchType=basic&fieldName=all&organism=%s&listType=1&fieldValue=%s" \ + % (species_scientific, thisTrait.symbol),Class="fs14 fwn", \ + title="Gene and protein data resources from Celera-ABI"), style=linkStyle), " "*2) + else: + pass + #tSpan.append(HT.Span(HT.Href(text= 'BIND',target="mainFrame",\ + # url="http://bind.ca/?textquery=%s" \ + # % thisTrait.symbol,Class="fs14 fwn", \ + # title="Protein interactions"), style=linkStyle), " "*2) + if thisTrait.geneid and (_Species == "mouse" or _Species == "rat" or _Species == "human"): + tSpan.append(HT.Span(HT.Href(text= 'Gemma',target="mainFrame",\ + url="http://www.chibi.ubc.ca/Gemma/gene/showGene.html?ncbiid=%s" \ + % thisTrait.geneid, Class="fs14 fwn", \ + title="Meta-analysis of gene expression data"), style=linkStyle), " "*2) + tSpan.append(HT.Span(HT.Href(text= 'SynDB',target="mainFrame",\ + url="http://lily.uthsc.edu:8080/20091027_GNInterfaces/20091027_redirectSynDB.jsp?query=%s" \ + % thisTrait.symbol, Class="fs14 fwn", \ + title="Brain synapse database"), style=linkStyle), " "*2) + if _Species == "mouse": + tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ + url="http://mouse.brain-map.org/brain/%s.html" \ + % thisTrait.symbol, Class="fs14 fwn", \ + title="Allen Brain Atlas"), style=linkStyle), " "*2) + + if thisTrait.geneid: + #if _Species == "mouse": + # tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ + # url="http://www.brain-map.org/search.do?queryText=egeneid=%s" \ + # % thisTrait.geneid, Class="fs14 fwn", \ + # title="Allen Brain Atlas"), style=linkStyle), " "*2) + if _Species == "human": + tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ + url="http://humancortex.alleninstitute.org/has/human/imageseries/search/1.html?searchSym=t&searchAlt=t&searchName=t&gene_term=&entrez_term=%s" \ + % thisTrait.geneid, Class="fs14 fwn", \ + title="Allen Brain Atlas"), style=linkStyle), " "*2) + tbl.append( + HT.TR(HT.TD(colspan=3,height=6)), + HT.TR( + HT.TD(' '), + HT.TD(width=10, valign="top"), + HT.TD(tSpan, valign="top"))) + + menuTable = HT.TableLite(cellpadding=2, Class="collap", width="620", id="target1") + menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(similarButton, align="center"),HT.TD(verifyButton, align="center"),HT.TD(geneWikiButton, align="center"),HT.TD(snpBrowserButton, align="center"),HT.TD(rnaseqButton, align="center"),HT.TD(probeButton, align="center"),HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(similarText, align="center"),HT.TD(verifyText, align="center"),HT.TD(geneWikiText, align="center"),HT.TD(snpBrowserText, align="center"),HT.TD(rnaseqText, align="center"),HT.TD(probeText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + + + #for zhou mi's cliques, need to be removed + #if self.database[:6] == 'BXDMic' and self.ProbeSetID in cliqueID: + # Info2Disp.append(HT.Strong('Clique Search: '),HT.Href(text='Search',\ + # url ="http://compbio1.utmem.edu/clique_go/results.php?pid=%s&pval_1=0&pval_2=0.001" \ + # % self.ProbeSetID,target='_blank',Class="normalsize"),HT.BR()) + + #linkTable.append(HT.TR(linkTD)) + #Info2Disp.append(linkTable) + title1Body.append(tbl, HT.BR(), menuTable) + + elif thisTrait and thisTrait.db and thisTrait.db.type =='Publish': #Check if trait is phenotype + + if thisTrait.confidential: + tbl.append(HT.TR( + HT.TD('Pre-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.pre_publication_description, Class="fs13"), valign="top", width=740) + )) + if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=thisTrait.authorized_users): + tbl.append(HT.TR( + HT.TD('Post-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.post_publication_description, Class="fs13"), valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Pre-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.pre_publication_abbreviation, Class="fs13"), valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Post-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.post_publication_abbreviation, Class="fs13"), valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Lab code: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.lab_code, Class="fs13"), valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Owner: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.owner, Class="fs13"), valign="top", width=740) + )) + else: + tbl.append(HT.TR( + HT.TD('Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.post_publication_description, Class="fs13"), valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Authors: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.authors, Class="fs13"), + valign="top", width=740) + )) + tbl.append(HT.TR( + HT.TD('Title: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(thisTrait.title, Class="fs13"), + valign="top", width=740) + )) + if thisTrait.journal: + journal = thisTrait.journal + if thisTrait.year: + journal = thisTrait.journal + " (%s)" % thisTrait.year + + tbl.append(HT.TR( + HT.TD('Journal: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(journal, Class="fs13"), + valign="top", width=740) + )) + PubMedLink = "" + if thisTrait.pubmed_id: + PubMedLink = webqtlConfig.PUBMEDLINK_URL % thisTrait.pubmed_id + if PubMedLink: + tbl.append(HT.TR( + HT.TD('Link: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(HT.Href(url=PubMedLink, text="PubMed",target='_blank',Class="fs14 fwn"), + style = "background:#cddcff;padding:2"), valign="top", width=740) + )) + + menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1") + menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + + title1Body.append(tbl, HT.BR(), menuTable) + + elif thisTrait and thisTrait.db and thisTrait.db.type == 'Geno': #Check if trait is genotype + + GenoInfo = HT.Paragraph() + if thisTrait.chr and thisTrait.mb: + location = ' Chr %s @ %s Mb' % (thisTrait.chr,thisTrait.mb) + else: + location = "not available" + + if thisTrait.sequence and len(thisTrait.sequence) > 100: + if _Species == "rat": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', thisTrait.sequence) + UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('rat', 'rn3', thisTrait.sequence) + elif _Species == "mouse": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', thisTrait.sequence) + UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', thisTrait.sequence) + elif _Species == "human": + UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) + UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('human', 'hg19', thisTrait.sequence) + else: + UCSC_BLAT_URL = "" + UTHSC_BLAT_URL = "" + if UCSC_BLAT_URL: + #verifyButton = HT.Href(url="#", onClick="openNewWin('%s')" % UCSC_BLAT_URL) + verifyButton = HT.Href(url="#") + verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", title=" Check probe locations at UCSC ", style="border:none;") + verifyButton.append(verifyButtonImg) + verifyText = "Verify" + rnaseqButton = HT.Href(url="#", onClick="openNewWin('%s')" % UTHSC_BLAT_URL) + rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") + rnaseqButton.append(rnaseqButtonImg) + rnaseqText = "RNA-seq" + + tbl.append(HT.TR( + HT.TD('Location: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Span(location, Class="fs13"), valign="top", width=740) + ), + HT.TR( + HT.TD('SNP Search: ', Class="fs13 fwb", + valign="top", nowrap="on", width=90), + HT.TD(width=10, valign="top"), + HT.TD(HT.Href("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=snp&cmd=search&term=%s" % thisTrait.name, 'NCBI',Class="fs13"), + valign="top", width=740) + )) + + menuTable = HT.TableLite(cellpadding=2, Class="collap", width="275", id="target1") + menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(verifyButton, align="center"),HT.TD(rnaseqButton, align="center"), HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(verifyText, align="center"),HT.TD(rnaseqText, align="center"), HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + + title1Body.append(tbl, HT.BR(), menuTable) + + elif (thisTrait == None or thisTrait.db.type == 'Temp'): #if temporary trait (user-submitted trait or PCA trait) + + TempInfo = HT.Paragraph() + if thisTrait != None: + if thisTrait.description: + tbl.append(HT.TR(HT.TD(HT.Strong('Description: '),' %s ' % thisTrait.description,HT.BR()), colspan=3, height=15)) + else: + tbl.append(HT.TR(HT.TD(HT.Strong('Description: '),'not available',HT.BR(),HT.BR()), colspan=3, height=15)) + + if (updateText == "Edit"): + menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1") + else: + menuTable = HT.TableLite(cellpadding=2, Class="collap", width="80", id="target1") + + menuTable.append(HT.TR(HT.TD(addSelectionButton, align="right"),HT.TD(updateButton, align="right"), colspan=3, height=50, style="vertical-align:bottom;") ) + menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;")) + + title1Body.append(tbl, HT.BR(), menuTable) + + else: + pass + + + ########################################## + ## Function to display analysis tools + ########################################## + def dispBasicStatistics(self, fd, title2Body, thisTrait): + + #XZ, June 22, 2011: The definition and usage of primary_strains, other_strains, specialStrains, all_strains are not clear and hard to understand. But since they are only used in this function for draw graph purpose, they will not hurt the business logic outside. As of June 21, 2011, this function seems work fine, so no hurry to clean up. These parameters and code in this function should be cleaned along with fd.f1list, fd.parlist, fd.strainlist later. + stats_row = HT.TR() + stats_cell = HT.TD() + + if fd.genotype.type == "riset": + strainlist = fd.f1list + fd.strainlist + else: + strainlist = fd.f1list + fd.parlist + fd.strainlist + + other_strains = [] #XZ: strain that is not of primary group + specialStrains = [] #XZ: This might be replaced by other_strains / ZS: It is just other strains without parent/f1 strains. + all_strains = [] + primary_strains = [] #XZ: strain of primary group, e.g., BXD, LXS + + MDP_menu = HT.Select(name='stats_mdp', Class='stats_mdp') + + for strain in thisTrait.data.keys(): + strainName = strain.replace("_2nd_", "") + if strain not in strainlist: + if (thisTrait.data[strainName].val != None): + if strain.find('F1') < 0: + specialStrains.append(strain) + if (thisTrait.data[strainName].val != None) and (strain not in (fd.f1list + fd.parlist)): + other_strains.append(strain) #XZ: at current stage, other_strains doesn't include parent strains and F1 strains of primary group + else: + if (thisTrait.data[strainName].val != None) and (strain not in (fd.f1list + fd.parlist)): + primary_strains.append(strain) #XZ: at current stage, the primary_strains is the same as fd.strainlist / ZS: I tried defining primary_strains as fd.strainlist instead, but in some cases it ended up including the parent strains (1436869_at BXD) + + if len(other_strains) > 3: + other_strains.sort(key=webqtlUtil.natsort_key) + primary_strains.sort(key=webqtlUtil.natsort_key) + primary_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_strains #XZ: note that fd.f1list and fd.parlist are added. + all_strains = primary_strains + other_strains + other_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + other_strains #XZ: note that fd.f1list and fd.parlist are added. + MDP_menu.append(('All Cases','0')) + MDP_menu.append(('%s Only' % fd.RISet,'1')) + MDP_menu.append(('Non-%s Only' % fd.RISet,'2')) + stats_row.append("Include: ", MDP_menu, HT.BR(), HT.BR()) + else: + if (len(other_strains) > 0) and (len(primary_strains) + len(other_strains) > 3): + MDP_menu.append(('All Cases','0')) + MDP_menu.append(('%s Only' % fd.RISet,'1')) + MDP_menu.append(('Non-%s Only' % fd.RISet,'2')) + stats_row.append("Include: ", MDP_menu, " "*3) + all_strains = primary_strains + all_strains.sort(key=webqtlUtil.natsort_key) + all_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + all_strains + primary_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_strains + else: + all_strains = strainlist + + other_strains.sort(key=webqtlUtil.natsort_key) + all_strains = all_strains + other_strains + pass + + update_button = HT.Input(type='button',value=' Update Figures ', Class="button update") #This is used to reload the page and update the Basic Statistics figures with user-edited data + stats_row.append(update_button, HT.BR(), HT.BR()) + + if (len(other_strains)) > 0 and (len(primary_strains) + len(other_strains) > 4): + #One set of vals for all, selected strain only, and non-selected only + vals1 = [] + vals2 = [] + vals3 = [] + + #Using all strains/cases for values + for i, strainNameOrig in enumerate(all_strains): + strainName = strainNameOrig.replace("_2nd_", "") + + try: + thisval = thisTrait.data[strainName].val + thisvar = thisTrait.data[strainName].var + thisValFull = [strainName,thisval,thisvar] + except: + continue + + vals1.append(thisValFull) + + #Using just the RISet strain + for i, strainNameOrig in enumerate(primary_strains): + strainName = strainNameOrig.replace("_2nd_", "") + + try: + thisval = thisTrait.data[strainName].val + thisvar = thisTrait.data[strainName].var + thisValFull = [strainName,thisval,thisvar] + except: + continue + + vals2.append(thisValFull) + + #Using all non-RISet strains only + for i, strainNameOrig in enumerate(other_strains): + strainName = strainNameOrig.replace("_2nd_", "") + + try: + thisval = thisTrait.data[strainName].val + thisvar = thisTrait.data[strainName].var + thisValFull = [strainName,thisval,thisvar] + except: + continue + + vals3.append(thisValFull) + + vals_set = [vals1,vals2,vals3] + + else: + vals = [] + + #Using all strains/cases for values + for i, strainNameOrig in enumerate(all_strains): + strainName = strainNameOrig.replace("_2nd_", "") + + try: + thisval = thisTrait.data[strainName].val + thisvar = thisTrait.data[strainName].var + thisValFull = [strainName,thisval,thisvar] + except: + continue + + vals.append(thisValFull) + + vals_set = [vals] + + stats_script = HT.Script(language="Javascript") #script needed for tabs + + for i, vals in enumerate(vals_set): + if i == 0 and len(vals) < 4: + stats_container = HT.Div(id="stats_tabs", style="padding:10px;", Class="ui-tabs") #Needed for tabs; notice the "stats_script_text" below referring to this element + stats_container.append(HT.Div(HT.Italic("Fewer than 4 case data were entered. No statistical analysis has been attempted."))) + stats_script_text = """$(function() { $("#stats_tabs").tabs();});""" + stats_cell.append(stats_container) + break + elif (i == 1 and len(primary_strains) < 4): + stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") + stats_container.append(HT.Div(HT.Italic("Fewer than 4 " + fd.RISet + " case data were entered. No statistical analysis has been attempted."))) + elif (i == 2 and len(other_strains) < 4): + stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") + stats_container.append(HT.Div(HT.Italic("Fewer than 4 non-" + fd.RISet + " case data were entered. No statistical analysis has been attempted."))) + stats_script_text = """$(function() { $("#stats_tabs0").tabs(); $("#stats_tabs1").tabs(); $("#stats_tabs2").tabs();});""" + else: + stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") + stats_script_text = """$(function() { $("#stats_tabs0").tabs(); $("#stats_tabs1").tabs(); $("#stats_tabs2").tabs();});""" + if len(vals) > 4: + stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-5", Class="stats_tab"), + HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), + HT.Href(text="Box Plot", url="#statstabs-2", Class="stats_tab")] + stats_tabs = HT.List(stats_tab_list) + stats_container.append(stats_tabs) + + table_div = HT.Div(id="statstabs-1") + table_container = HT.Paragraph() + + statsTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + + if thisTrait.db: + if thisTrait.cellid: + statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=thisTrait.db.type, cellid=thisTrait.cellid) + else: + statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=thisTrait.db.type) + else: + statsTableCell = BasicStatisticsFunctions.basicStatsTable(vals=vals) + + statsTable.append(HT.TR(HT.TD(statsTableCell))) + + table_container.append(statsTable) + table_div.append(table_container) + stats_container.append(table_div) + + normalplot_div = HT.Div(id="statstabs-5") + normalplot_container = HT.Paragraph() + normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + + try: + plotTitle = thisTrait.symbol + plotTitle += ": " + plotTitle += thisTrait.name + except: + plotTitle = str(thisTrait.name) + + normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, RISet=fd.RISet, title=plotTitle, specialStrains=specialStrains) + normalplot.append(HT.TR(HT.TD(normalplot_img))) + normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ + normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), + "More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", + target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) + normalplot_container.append(normalplot) + normalplot_div.append(normalplot_container) + stats_container.append(normalplot_div) + + boxplot_div = HT.Div(id="statstabs-2") + boxplot_container = HT.Paragraph() + boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) + boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) + boxplot_container.append(boxplot) + boxplot_div.append(boxplot_container) + stats_container.append(boxplot_div) + + + barName_div = HT.Div(id="statstabs-3") + barName_container = HT.Paragraph() + barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="name") + barName.append(HT.TR(HT.TD(barName_img))) + barName_container.append(barName) + barName_div.append(barName_container) + stats_container.append(barName_div) + + barRank_div = HT.Div(id="statstabs-4") + barRank_container = HT.Paragraph() + barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, RISet=fd.RISet, vals=vals, type="rank") + barRank.append(HT.TR(HT.TD(barRank_img))) + barRank_container.append(barRank) + barRank_div.append(barRank_container) + stats_container.append(barRank_div) + + stats_cell.append(stats_container) + + stats_script.append(stats_script_text) + + submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target2") + stats_row.append(stats_cell) + + submitTable.append(stats_row) + submitTable.append(stats_script) + + title2Body.append(submitTable) + + + def dispCorrelationTools(self, fd, title3Body, thisTrait): + + _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) + + RISetgp = fd.RISet + if RISetgp[:3] == 'BXD': + RISetgp = 'BXD' + + if RISetgp: + sample_correlation = HT.Input(type='button',name='sample_corr', value=' Compute ', Class="button sample_corr") + lit_correlation = HT.Input(type='button',name='lit_corr', value=' Compute ', Class="button lit_corr") + tissue_correlation = HT.Input(type='button',name='tiss_corr', value=' Compute ', Class="button tiss_corr") + methodText = HT.Span("Calculate:", Class="ffl fwb fs12") + + databaseText = HT.Span("Database:", Class="ffl fwb fs12") + databaseMenu1 = HT.Select(name='database1') + databaseMenu2 = HT.Select(name='database2') + databaseMenu3 = HT.Select(name='database3') + + nmenu = 0 + self.cursor.execute('SELECT PublishFreeze.FullName,PublishFreeze.Name FROM \ + PublishFreeze,InbredSet WHERE PublishFreeze.InbredSetId = InbredSet.Id \ + and InbredSet.Name = "%s" and PublishFreeze.public > %d' % \ + (RISetgp,webqtlConfig.PUBLICTHRESH)) + for item in self.cursor.fetchall(): + databaseMenu1.append(item) + databaseMenu2.append(item) + databaseMenu3.append(item) + nmenu += 1 + self.cursor.execute('SELECT GenoFreeze.FullName,GenoFreeze.Name FROM GenoFreeze,\ + InbredSet WHERE GenoFreeze.InbredSetId = InbredSet.Id and InbredSet.Name = \ + "%s" and GenoFreeze.public > %d' % (RISetgp,webqtlConfig.PUBLICTHRESH)) + for item in self.cursor.fetchall(): + databaseMenu1.append(item) + databaseMenu2.append(item) + databaseMenu3.append(item) + nmenu += 1 + #03/09/2009: Xiaodong changed the SQL query to order by Name as requested by Rob. + self.cursor.execute('SELECT Id, Name FROM Tissue order by Name') + for item in self.cursor.fetchall(): + TId, TName = item + databaseMenuSub = HT.Optgroup(label = '%s ------' % TName) + self.cursor.execute('SELECT ProbeSetFreeze.FullName,ProbeSetFreeze.Name FROM ProbeSetFreeze, ProbeFreeze, \ + InbredSet WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and ProbeFreeze.TissueId = %d and \ + ProbeSetFreeze.public > %d and ProbeFreeze.InbredSetId = InbredSet.Id and InbredSet.Name like "%s%%" \ + order by ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId ' % (TId,webqtlConfig.PUBLICTHRESH, RISetgp)) + for item2 in self.cursor.fetchall(): + databaseMenuSub.append(item2) + nmenu += 1 + databaseMenu1.append(databaseMenuSub) + databaseMenu2.append(databaseMenuSub) + databaseMenu3.append(databaseMenuSub) + if nmenu: + if thisTrait and thisTrait.db != None: + databaseMenu1.selected.append(thisTrait.db.fullname) + databaseMenu2.selected.append(thisTrait.db.fullname) + databaseMenu3.selected.append(thisTrait.db.fullname) + + criteriaText = HT.Span("Return:", Class="ffl fwb fs12") + + criteriaMenu1 = HT.Select(name='criteria1', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") + criteriaMenu1.append(('top 100','100')) + criteriaMenu1.append(('top 200','200')) + criteriaMenu1.append(('top 500','500')) + criteriaMenu1.append(('top 1000','1000')) + criteriaMenu1.append(('top 2000','2000')) + criteriaMenu1.append(('top 5000','5000')) + criteriaMenu1.append(('top 10000','10000')) + criteriaMenu1.append(('top 15000','15000')) + criteriaMenu1.append(('top 20000','20000')) + + criteriaMenu2 = HT.Select(name='criteria2', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") + criteriaMenu2.append(('top 100','100')) + criteriaMenu2.append(('top 200','200')) + criteriaMenu2.append(('top 500','500')) + criteriaMenu2.append(('top 1000','1000')) + criteriaMenu2.append(('top 2000','2000')) + criteriaMenu2.append(('top 5000','5000')) + criteriaMenu2.append(('top 10000','10000')) + criteriaMenu2.append(('top 15000','15000')) + criteriaMenu2.append(('top 20000','20000')) + + criteriaMenu3 = HT.Select(name='criteria3', selected='500', onMouseOver="if (NS4 || IE4) activateEl('criterias', event);") + criteriaMenu3.append(('top 100','100')) + criteriaMenu3.append(('top 200','200')) + criteriaMenu3.append(('top 500','500')) + criteriaMenu3.append(('top 1000','1000')) + criteriaMenu3.append(('top 2000','2000')) + criteriaMenu3.append(('top 5000','5000')) + criteriaMenu3.append(('top 10000','10000')) + criteriaMenu3.append(('top 15000','15000')) + criteriaMenu3.append(('top 20000','20000')) + + + self.MDPRow1 = HT.TR(Class='mdp1') + self.MDPRow2 = HT.TR(Class='mdp2') + self.MDPRow3 = HT.TR(Class='mdp3') + + correlationMenus1 = HT.TableLite( + HT.TR(HT.TD(databaseText), HT.TD(databaseMenu1, colspan="3")), + HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu1)), + self.MDPRow1, cellspacing=0, width="619px", cellpadding=2) + correlationMenus1.append(HT.Input(name='orderBy', value='2', type='hidden')) # to replace the orderBy menu + correlationMenus2 = HT.TableLite( + HT.TR(HT.TD(databaseText), HT.TD(databaseMenu2, colspan="3")), + HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu2)), + self.MDPRow2, cellspacing=0, width="619px", cellpadding=2) + correlationMenus2.append(HT.Input(name='orderBy', value='2', type='hidden')) + correlationMenus3 = HT.TableLite( + HT.TR(HT.TD(databaseText), HT.TD(databaseMenu3, colspan="3")), + HT.TR(HT.TD(criteriaText), HT.TD(criteriaMenu3)), + self.MDPRow3, cellspacing=0, width="619px", cellpadding=2) + correlationMenus3.append(HT.Input(name='orderBy', value='2', type='hidden')) + + else: + correlationMenus = "" + + + corr_row = HT.TR() + corr_container = HT.Div(id="corr_tabs", Class="ui-tabs") + + if (thisTrait.db != None and thisTrait.db.type =='ProbeSet'): + corr_tab_list = [HT.Href(text='Sample r', url="#corrtabs-1"), HT.Href(text='Literature r', url="#corrtabs-2"), HT.Href(text='Tissue r', url="#corrtabs-3")] + else: + corr_tab_list = [HT.Href(text='Sample r', url="#corrtabs-1")] + + corr_tabs = HT.List(corr_tab_list) + corr_container.append(corr_tabs) + + if correlationMenus1 or correlationMenus2 or correlationMenus3: + sample_div = HT.Div(id="corrtabs-1") + sample_container = HT.Span() + + sample_type = HT.Input(type="radio", name="sample_method", value="1", checked="checked") + sample_type2 = HT.Input(type="radio", name="sample_method", value="2") + + sampleTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + sampleTD = HT.TD(correlationMenus1, HT.BR(), + "Pearson", sample_type, " "*3, "Spearman Rank", sample_type2, HT.BR(), HT.BR(), + sample_correlation, HT.BR(), HT.BR()) + + sampleTD.append(HT.Span("The ",HT.Href(url="/correlationAnnotation.html#sample_r", target="_blank", text="Sample Correlation")," is computed between trait data and", + " any ",HT.BR()," other traits in the sample database selected above. Use ", + HT.Href(url="/glossary.html#Correlations", target="_blank", text="Spearman Rank"), + HT.BR(),"when the sample size is small (<20) or when there are influential \ + outliers.", HT.BR(),Class="fs12")) + + sampleTable.append(sampleTD) + + sample_container.append(sampleTable) + sample_div.append(sample_container) + corr_container.append(sample_div) + + literature_div = HT.Div(id="corrtabs-2") + literature_container = HT.Span() + + literatureTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + literatureTD = HT.TD(correlationMenus2,HT.BR(),lit_correlation, HT.BR(), HT.BR()) + literatureTD.append(HT.Span("The ", HT.Href(url="/correlationAnnotation.html", target="_blank",text="Literature Correlation"), " (Lit r) between this gene and all other genes is computed",HT.BR(), + "using the ", HT.Href(url="https://grits.eecs.utk.edu/sgo/sgo.html", target="_blank", text="Semantic Gene Organizer"), + " and human, rat, and mouse data from PubMed. ", HT.BR(),"Values are ranked by Lit r, \ + but Sample r and Tissue r are also displayed.", HT.BR(), HT.BR(), + HT.Href(url="/glossary.html#Literature", target="_blank", text="More on using Lit r"), Class="fs12")) + literatureTable.append(literatureTD) + + literature_container.append(literatureTable) + literature_div.append(literature_container) + + if thisTrait.db != None: + if (thisTrait.db.type =='ProbeSet'): + corr_container.append(literature_div) + + tissue_div = HT.Div(id="corrtabs-3") + tissue_container = HT.Span() + + tissue_type = HT.Input(type="radio", name="tissue_method", value="4", checked="checked") + tissue_type2 = HT.Input(type="radio", name="tissue_method", value="5") + + tissueTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + tissueTD = HT.TD(correlationMenus3,HT.BR(), + "Pearson", tissue_type, " "*3, "Spearman Rank", tissue_type2, HT.BR(), HT.BR(), + tissue_correlation, HT.BR(), HT.BR()) + tissueTD.append(HT.Span("The ", HT.Href(url="/webqtl/main.py?FormID=tissueCorrelation", target="_blank", text="Tissue Correlation"), + " (Tissue r) estimates the similarity of expression of two genes",HT.BR()," or \ + transcripts across different cells, tissues, or organs (",HT.Href(url="/correlationAnnotation.html#tissue_r", target="_blank", text="glossary"),"). \ + Tissue correlations",HT.BR()," are generated by analyzing expression in multiple samples usually taken from \ + single cases.",HT.BR(),HT.Bold("Pearson")," and ",HT.Bold("Spearman Rank")," correlations have been computed for all pairs \ + of genes",HT.BR()," using data from mouse samples.", + HT.BR(), Class="fs12")) + tissueTable.append(tissueTD) + + tissue_container.append(tissueTable) + tissue_div.append(tissue_container) + if thisTrait.db != None: + if (thisTrait.db.type =='ProbeSet'): + corr_container.append(tissue_div) + + corr_row.append(HT.TD(corr_container)) + + corr_script = HT.Script(language="Javascript") + corr_script_text = """$(function() { $("#corr_tabs").tabs(); });""" + corr_script.append(corr_script_text) + + submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target4") + submitTable.append(corr_row) + submitTable.append(corr_script) + + title3Body.append(submitTable) + + + def dispMappingTools(self, fd, title4Body, thisTrait): + + _Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet) + + RISetgp = fd.RISet + if RISetgp[:3] == 'BXD': + RISetgp = 'BXD' + + #check boxes - one for regular interval mapping, the other for composite + permCheck1= HT.Input(type='checkbox', Class='checkbox', name='permCheck1',checked="on") + bootCheck1= HT.Input(type='checkbox', Class='checkbox', name='bootCheck1',checked=0) + permCheck2= HT.Input(type='checkbox', Class='checkbox', name='permCheck2',checked="on") + bootCheck2= HT.Input(type='checkbox', Class='checkbox', name='bootCheck2',checked=0) + optionbox1 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression1',checked=0) + optionbox2 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression2',checked=0) + optionbox3 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression3',checked=0) + applyVariance1 = HT.Input(name='applyVarianceSE1',type='checkbox', Class='checkbox') + applyVariance2 = HT.Input(name='applyVarianceSE2',type='checkbox', Class='checkbox') + + IntervalMappingButton=HT.Input(type='button' ,name='interval',value=' Compute ', Class="button") + CompositeMappingButton=HT.Input(type='button' ,name='composite',value=' Compute ', Class="button") + MarkerRegressionButton=HT.Input(type='button',name='marker', value=' Compute ', Class="button") + + chrText = HT.Span("Chromosome:", Class="ffl fwb fs12") + + # updated by NL 5-28-2010 + # Interval Mapping + chrMenu = HT.Select(name='chromosomes1') + chrMenu.append(tuple(["All",-1])) + for i in range(len(fd.genotype)): + if len(fd.genotype[i]) > 1: + chrMenu.append(tuple([fd.genotype[i].name,i])) + + #Menu for Composite Interval Mapping + chrMenu2 = HT.Select(name='chromosomes2') + chrMenu2.append(tuple(["All",-1])) + for i in range(len(fd.genotype)): + if len(fd.genotype[i]) > 1: + chrMenu2.append(tuple([fd.genotype[i].name,i])) + + if fd.genotype.Mbmap: + scaleText = HT.Span("Mapping Scale:", Class="ffl fwb fs12") + scaleMenu1 = HT.Select(name='scale1', onChange="checkUncheck(window.document.dataInput.scale1.value, window.document.dataInput.permCheck1, window.document.dataInput.bootCheck1)") + scaleMenu1.append(("Megabase",'physic')) + scaleMenu1.append(("Centimorgan",'morgan')) + scaleMenu2 = HT.Select(name='scale2', onChange="checkUncheck(window.document.dataInput.scale2.value, window.document.dataInput.permCheck2, window.document.dataInput.bootCheck2)") + scaleMenu2.append(("Megabase",'physic')) + scaleMenu2.append(("Centimorgan",'morgan')) + + controlText = HT.Span("Control Locus:", Class="ffl fwb fs12") + controlMenu = HT.Input(type="text", name="controlLocus", Class="controlLocus") + + if fd.genotype.Mbmap: + intMappingMenu = HT.TableLite( + HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), + HT.TR(HT.TD(scaleText), HT.TD(scaleMenu1)), + cellspacing=0, width="263px", cellpadding=2) + compMappingMenu = HT.TableLite( + HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), + HT.TR(HT.TD(scaleText), HT.TD(scaleMenu2)), + HT.TR(HT.TD(controlText), HT.TD(controlMenu)), + cellspacing=0, width="325px", cellpadding=2) + else: + intMappingMenu = HT.TableLite( + HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), + cellspacing=0, width="263px", cellpadding=2) + compMappingMenu = HT.TableLite( + HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), + HT.TR(HT.TD(controlText), HT.TD(controlMenu)), + cellspacing=0, width="325px", cellpadding=2) + + directPlotButton = "" + directPlotButton = HT.Input(type='button',name='', value=' Compute ',\ + onClick="dataEditingFunc(this.form,'directPlot');",Class="button") + directPlotSortText = HT.Span(HT.Bold("Sort by: "), Class="ffl fwb fs12") + directPlotSortMenu = HT.Select(name='graphSort') + directPlotSortMenu.append(('LRS Full',0)) + directPlotSortMenu.append(('LRS Interact',1)) + directPlotPermuText = HT.Span("Permutation Test (n=500)", Class="ffl fs12") + directPlotPermu = HT.Input(type='checkbox', Class='checkbox',name='directPermuCheckbox', checked="on") + pairScanReturnText = HT.Span(HT.Bold("Return: "), Class="ffl fwb fs12") + pairScanReturnMenu = HT.Select(name='pairScanReturn') + pairScanReturnMenu.append(('top 50','50')) + pairScanReturnMenu.append(('top 100','100')) + pairScanReturnMenu.append(('top 200','200')) + pairScanReturnMenu.append(('top 500','500')) + + pairScanMenus = HT.TableLite( + HT.TR(HT.TD(directPlotSortText), HT.TD(directPlotSortMenu)), + HT.TR(HT.TD(pairScanReturnText), HT.TD(pairScanReturnMenu)), + cellspacing=0, width="232px", cellpadding=2) + + markerSuggestiveText = HT.Span(HT.Bold("Display LRS greater than:"), Class="ffl fwb fs12") + markerSuggestive = HT.Input(name='suggestive', size=5, maxlength=8) + displayAllText = HT.Span(" Display all LRS ", Class="ffl fs12") + displayAll = HT.Input(name='displayAllLRS', type="checkbox", Class='checkbox') + useParentsText = HT.Span(" Use Parents ", Class="ffl fs12") + useParents = optionbox2 + applyVarianceText = HT.Span(" Use Weighted ", Class="ffl fs12") + + markerMenu = HT.TableLite( + HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive)), + HT.TR(HT.TD(displayAll,displayAllText)), + HT.TR(HT.TD(useParents,useParentsText)), + HT.TR(HT.TD(applyVariance2,applyVarianceText)), + cellspacing=0, width="263px", cellpadding=2) + + + mapping_row = HT.TR() + mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") + + mapping_tab_list = [HT.Href(text="Interval", url="#mappingtabs-1"), HT.Href(text="Marker Regression", url="#mappingtabs-2"), HT.Href(text="Composite", url="#mappingtabs-3"), HT.Href(text="Pair-Scan", url="#mappingtabs-4")] + mapping_tabs = HT.List(mapping_tab_list) + mapping_container.append(mapping_tabs) + + interval_div = HT.Div(id="mappingtabs-1") + interval_container = HT.Span() + + intervalTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + intTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") + intTD.append(intMappingMenu,HT.BR()) + + intTD.append(permCheck1,'Permutation Test (n=2000)',HT.BR(), + bootCheck1,'Bootstrap Test (n=2000)', HT.BR(), optionbox1, 'Use Parents', HT.BR(), + applyVariance1,'Use Weighted', HT.BR(), HT.BR(),IntervalMappingButton, HT.BR(), HT.BR()) + intervalTable.append(HT.TR(intTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#intmap', target='_blank', text='Interval Mapping'), + ' computes linkage maps for the entire genome or single',HT.BR(),' chromosomes.', + ' The ',HT.Href(url='/glossary.html#permutation', target='_blank', text='Permutation Test'),' estimates suggestive and significant ',HT.BR(),' linkage scores. \ + The ',HT.Href(url='/glossary.html#bootstrap', target='_blank', text='Bootstrap Test'), ' estimates the precision of the QTL location.' + ,Class="fs12"), HT.BR(), valign="top"))) + + interval_container.append(intervalTable) + interval_div.append(interval_container) + mapping_container.append(interval_div) + + # Marker Regression + + marker_div = HT.Div(id="mappingtabs-2") + marker_container = HT.Span() + + markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") + markerTD.append(markerMenu,HT.BR()) + + markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) + + markerTable.append(HT.TR(markerTD),HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#',target='_blank',text='Marker regression'), + ' computes and displays LRS values for individual markers.',HT.BR(), + 'This function also lists additive effects (phenotype units per allele) and', HT.BR(), + 'dominance deviations for some datasets.', HT.BR(),Class="fs12"), HT.BR(), valign="top"))) + + marker_container.append(markerTable) + marker_div.append(marker_container) + mapping_container.append(marker_div) + + # Composite interval mapping + composite_div = HT.Div(id="mappingtabs-3") + composite_container = HT.Span() + + compositeTable = HT.TableLite(cellspacing=0, cellpadding=3, width="100%") + compTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") + compTD.append(compMappingMenu,HT.BR()) + + compTD.append(permCheck2, 'Permutation Test (n=2000)',HT.BR(), + bootCheck2,'Bootstrap Test (n=2000)', HT.BR(), + optionbox3, 'Use Parents', HT.BR(), HT.BR(), CompositeMappingButton, HT.BR(), HT.BR()) + compositeTable.append(HT.TR(compTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Composite',target='_blank',text='Composite Interval Mapping'), + " allows you to control for a single marker as",HT.BR()," a cofactor. ", + "To find a control marker, run the ",HT.Bold("Marker Regression")," function."), + HT.BR(), valign="top"))) + + composite_container.append(compositeTable) + composite_div.append(composite_container) + mapping_container.append(composite_div) + + # Pair Scan + + pairscan_div = HT.Div(id="mappingtabs-4") + pairscan_container = HT.Span() + + pairScanTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + pairScanTD = HT.TD(NOWRAP='ON', Class="fs12 fwn") + pairScanTD.append(pairScanMenus,HT.BR()) + pairScanTD.append(directPlotPermu, directPlotPermuText, HT.BR(), HT.BR(), + directPlotButton,HT.BR(),HT.BR()) + pairScanTable.append(HT.TR(pairScanTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Pair_Scan', target="_blank", text='Pair-Scan'), + ' searches for pairs of chromosomal regions that are',HT.BR(), + 'involved in two-locus epistatic interactions.'), HT.BR(), valign="top"))) + + pairscan_container.append(pairScanTable) + pairscan_div.append(pairscan_container) + mapping_container.append(pairscan_div) + + mapping_row.append(HT.TD(mapping_container)) + + # Treat Interval Mapping and Marker Regression and Pair Scan as a group for displaying + #disable Interval Mapping and Marker Regression and Pair Scan for human and the dataset doesn't have genotype file + mappingMethodId = webqtlDatabaseFunction.getMappingMethod(cursor=self.cursor, groupName=RISetgp) + + mapping_script = HT.Script(language="Javascript") + mapping_script_text = """$(function() { $("#mapping_tabs").tabs(); });""" + mapping_script.append(mapping_script_text) + + submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target2") + + if mappingMethodId != None: + if int(mappingMethodId) == 1: + submitTable.append(mapping_row) + submitTable.append(mapping_script) + elif int(mappingMethodId) == 4: + # NL; 09-26-2011 testing for Human Genome Association function + mapping_row=HT.TR() + mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") + + mapping_tab_list = [HT.Href(text="Genome Association", url="#mappingtabs-1")] + mapping_tabs = HT.List(mapping_tab_list) + mapping_container.append(mapping_tabs) + + # Genome Association + markerSuggestiveText = HT.Span(HT.Bold("P Value:"), Class="ffl fwb fs12") + + markerSuggestive = HT.Input(name='pValue', value='0.001', size=10, maxlength=20,onClick="this.value='';",onBlur="if(this.value==''){this.value='0.001'};") + markerMenu = HT.TableLite(HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive),HT.TD(HT.Italic('   (e.g. 0.001 or 1e-3 or 1E-3 or 3)'))),cellspacing=0, width="400px", cellpadding=2) + MarkerRegressionButton=HT.Input(type='button',name='computePlink', value='  Compute Using PLINK  ', onClick= "validatePvalue(this.form);", Class="button") + + marker_div = HT.Div(id="mappingtabs-1") + marker_container = HT.Span() + markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") + markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") + markerTD.append(markerMenu,HT.BR()) + markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) + markerTable.append(HT.TR(markerTD)) + + marker_container.append(markerTable) + marker_div.append(marker_container) + + mapping_container.append(marker_div) + mapping_row.append(HT.TD(mapping_container)) + submitTable.append(mapping_row) + submitTable.append(mapping_script) + else: + submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("mappingMethodId %s has not been implemented for this dataset yet." % mappingMethodId), id="mapping_tabs", Class="ui-tabs")))) + submitTable.append(mapping_script) + + else: + submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("Mapping options are disabled for data not matched with genotypes."), id="mapping_tabs", Class="ui-tabs")))) + submitTable.append(mapping_script) + + title4Body.append(submitTable) + + + def natural_sort(strain_list): + + sorted = [] + for strain in strain_list: + try: + strain = int(strain) + try: sorted[-1] = sorted[-1] * 10 + strain + except: sorted.append(strain) + except: + sorted.append(strain) + return sorted + + ########################################## + ## Function to display trait tables + ########################################## + def dispTraitValues(self, fd , title5Body, varianceDataPage, nCols, mainForm, thisTrait): + traitTableOptions = HT.Div(style="border: 3px solid #EEEEEE; -moz-border-radius: 10px; -webkit-border-radius: 10px; width: 625px; padding: 5px 5px 10px 8px; font-size: 12px; background: #DDDDDD;") + resetButton = HT.Input(type='button',name='resetButton',value=' Reset ',Class="button") + blockSamplesField = HT.Input(type="text",style="background-color:white;border: 1px solid black;font-size: 14px;", name="removeField") + blockSamplesButton = HT.Input(type='button',value=' Block ', name='blockSamples', Class="button") + showHideNoValue = HT.Input(type='button', name='showHideNoValue', value=' Hide No Value ',Class='button') + blockMenuSpan = HT.Span(Id="blockMenuSpan") + blockMenu = HT.Select(name='block_method') + + if fd.genotype.type == "riset": + allstrainlist_neworder = fd.f1list + fd.strainlist + else: + allstrainlist_neworder = fd.f1list + fd.parlist + fd.strainlist + + attribute_ids = [] + attribute_names = [] + try: + #ZS: Id values for this trait's extra attributes; used to create "Exclude" dropdown and query for attribute values and create + self.cursor.execute("""SELECT CaseAttribute.Id, CaseAttribute.Name + FROM CaseAttribute, CaseAttributeXRef + WHERE CaseAttributeXRef.ProbeSetFreezeId = '%s' AND + CaseAttribute.Id = CaseAttributeXRef.CaseAttributeId + group by CaseAttributeXRef.CaseAttributeId""" % (str(thisTrait.db.id))) + + exclude_menu = HT.Select(name="exclude_menu") + dropdown_menus = [] #ZS: list of dropdown menus with the distinct values of each attribute (contained in DIVs so the style parameter can be edited and they can be hidden) + + for attribute in self.cursor.fetchall(): + attribute_ids.append(attribute[0]) + attribute_names.append(attribute[1]) + for this_attr_name in attribute_names: + exclude_menu.append((this_attr_name.capitalize(), this_attr_name)) + self.cursor.execute("""SELECT DISTINCT CaseAttributeXRef.Value + FROM CaseAttribute, CaseAttributeXRef + WHERE CaseAttribute.Name = '%s' AND + CaseAttributeXRef.CaseAttributeId = CaseAttribute.Id""" % (this_attr_name)) + try: + distinct_values = self.cursor.fetchall() + attr_value_menu_div = HT.Div(style="display:none;", Class="attribute_values") #container used to show/hide dropdown menus + attr_value_menu = HT.Select(name=this_attr_name) + attr_value_menu.append(("None", "show_all")) + for value in distinct_values: + attr_value_menu.append((str(value[0]), value[0])) + attr_value_menu_div.append(attr_value_menu) + dropdown_menus.append(attr_value_menu_div) + except: + pass + except: + pass + + other_strains = [] + for strain in thisTrait.data.keys(): + if strain not in allstrainlist_neworder: + other_strains.append(strain) + + if other_strains: + blockMenu.append(('%s Only' % fd.RISet,'1')) + blockMenu.append(('Non-%s Only' % fd.RISet,'0')) + blockMenuSpan.append(blockMenu) + else: + pass + + showHideOutliers = HT.Input(type='button', name='showHideOutliers', value=' Hide Outliers ', Class='button') + showHideMenuOptions = HT.Span(Id="showHideOptions", style="line-height:225%;") + if other_strains: + showHideMenuOptions.append(HT.Bold("  Block samples by index:    "), blockSamplesField, "   ", blockMenuSpan, "   ", blockSamplesButton, HT.BR()) + else: + showHideMenuOptions.append(HT.Bold("  Block samples by index:    "), blockSamplesField, "   ", blockSamplesButton, HT.BR()) + + exportButton = HT.Input(type='button', name='export', value=' Export ', Class='button') + if len(attribute_names) > 0: + excludeButton = HT.Input(type='button', name='excludeGroup', value=' Block ', Class='button') + showHideMenuOptions.append(HT.Bold("  Block samples by group:"), " "*5, exclude_menu, " "*5) + for menu in dropdown_menus: + showHideMenuOptions.append(menu) + showHideMenuOptions.append(" "*5, excludeButton, HT.BR()) + showHideMenuOptions.append(HT.Bold("  Options:"), " "*5, showHideNoValue, " "*5, showHideOutliers, " "*5, resetButton, " "*5, exportButton) + + traitTableOptions.append(showHideMenuOptions,HT.BR(),HT.BR()) + traitTableOptions.append(HT.Span("  Outliers highlighted in ", HT.Bold(" yellow ", style="background-color:yellow;"), " can be hidden using the ", + HT.Strong(" Hide Outliers "), " button,",HT.BR(),"  and samples with no value (x) can be hidden by clicking ", + HT.Strong(" Hide No Value "), "."), HT.BR()) + + + dispintro = HT.Paragraph("Edit or delete values in the Trait Data boxes, and use the ", HT.Strong("Reset"), " option as needed.",Class="fs12", style="margin-left:20px;") + + table = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target5") #Everything needs to be inside this table object in order for the toggle to work + container = HT.Div() #This will contain everything and be put into a cell of the table defined above + + container.append(dispintro, traitTableOptions, HT.BR()) + + primary_table = HT.TableLite(cellspacing=0, cellpadding=0, Id="sortable1", Class="tablesorter") + primary_header = self.getTableHeader(fd=fd, thisTrait=thisTrait, nCols=nCols, attribute_names=attribute_names) #Generate header for primary table object + + other_strainsExist = False + for strain in thisTrait.data.keys(): + if strain not in allstrainlist_neworder: + other_strainsExist = True + break + + primary_body = self.addTrait2Table(fd=fd, varianceDataPage=varianceDataPage, strainlist=allstrainlist_neworder, mainForm=mainForm, thisTrait=thisTrait, other_strainsExist=other_strainsExist, attribute_ids=attribute_ids, attribute_names=attribute_names, strains='primary') + + primary_table.append(primary_header) + for i in range(len(primary_body)): + primary_table.append(primary_body[i]) + + other_strains = [] + for strain in thisTrait.data.keys(): + if strain not in allstrainlist_neworder: + allstrainlist_neworder.append(strain) + other_strains.append(strain) + + if other_strains: + other_table = HT.TableLite(cellspacing=0, cellpadding=0, Id="sortable2", Class="tablesorter") #Table object with other (for example, non-BXD / MDP) traits + other_header = self.getTableHeader(fd=fd, thisTrait=thisTrait, nCols=nCols, attribute_names=attribute_names) #Generate header for other table object; same function is used as the one used for the primary table, since the header is the same + other_strains.sort() #Sort other strains + other_strains = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + other_strains #Append F1 and parent strains to the beginning of the sorted list of other strains + + MDPText = HT.Span("Samples:", Class="ffl fwb fs12") + MDPMenu1 = HT.Select(name='MDPChoice1') + MDPMenu2 = HT.Select(name='MDPChoice2') + MDPMenu3 = HT.Select(name='MDPChoice3') + MDPMenu1.append(('%s Only' % fd.RISet,'1')) + MDPMenu2.append(('%s Only' % fd.RISet,'1')) + MDPMenu3.append(('%s Only' % fd.RISet,'1')) + MDPMenu1.append(('Non-%s Only' % fd.RISet,'2')) + MDPMenu2.append(('Non-%s Only' % fd.RISet,'2')) + MDPMenu3.append(('Non-%s Only' % fd.RISet,'2')) + MDPMenu1.append(('All Cases','0')) + MDPMenu2.append(('All Cases','0')) + MDPMenu3.append(('All Cases','0')) + self.MDPRow1.append(HT.TD(MDPText),HT.TD(MDPMenu1)) + self.MDPRow2.append(HT.TD(MDPText),HT.TD(MDPMenu2)) + self.MDPRow3.append(HT.TD(MDPText),HT.TD(MDPMenu3)) + + other_body = self.addTrait2Table(fd=fd, varianceDataPage=varianceDataPage, strainlist=other_strains, mainForm=mainForm, thisTrait=thisTrait, attribute_ids=attribute_ids, attribute_names=attribute_names, strains='other') + + other_table.append(other_header) + for i in range(len(other_body)): + other_table.append(other_body[i]) + else: + pass + + if other_strains or (fd.f1list and thisTrait.data.has_key(fd.f1list[0])) \ + or (fd.f1list and thisTrait.data.has_key(fd.f1list[1])): + fd.allstrainlist = allstrainlist_neworder + + if nCols == 6 and fd.varianceDispName != 'Variance': + mainForm.append(HT.Input(name='isSE', value="yes", type='hidden')) + + primary_div = HT.Div(primary_table, Id="primary") #Container for table with primary (for example, BXD) strain values + container.append(primary_div) + + if other_strains: + other_div = HT.Div(other_table, Id="other") #Container for table with other (for example, Non-BXD/MDP) strain values + container.append(HT.Div(' ', height=30)) + container.append(other_div) + + table.append(HT.TR(HT.TD(container))) + title5Body.append(table) + + def addTrait2Table(self, fd, varianceDataPage, strainlist, mainForm, thisTrait, other_strainsExist=None, attribute_ids=[], attribute_names=[], strains='primary'): + #XZ, Aug 23, 2010: I commented the code related to the display of animal case + #strainInfo = thisTrait.has_key('strainInfo') and thisTrait.strainInfo + + table_body = [] + vals = [] + + for i, strainNameOrig in enumerate(strainlist): + strainName = strainNameOrig.replace("_2nd_", "") + + try: + thisval = thisTrait.data[strainName].val + thisvar = thisTrait.data[strainName].var + thisValFull = [strainName,thisval,thisvar] + except: + continue + + vals.append(thisValFull) + + upperBound, lowerBound = Plot.findOutliers(vals) # ZS: Values greater than upperBound or less than lowerBound are considered outliers. + + for i, strainNameOrig in enumerate(strainlist): + + trId = strainNameOrig + selectCheck = HT.Input(type="checkbox", name="selectCheck", value=trId, Class="checkbox", onClick="highlight(this)") + + strainName = strainNameOrig.replace("_2nd_", "") + strainNameAdd = '' + if fd.RISet == 'AXBXA' and strainName in ('AXB18/19/20','AXB13/14','BXA8/17'): + strainNameAdd = HT.Href(url='/mouseCross.html#AXB/BXA', text=HT.Sup('#'), Class='fs12', target="_blank") + + try: + thisval, thisvar, thisNP = thisTrait.data[strainName].val, thisTrait.data[strainName].var, thisTrait.data[strainName].N + if thisNP: + mainForm.append(HT.Input(name='N'+strainName, value=thisNP, type='hidden')) + else: + pass + except: + thisval = thisvar = 'x' + + try: + traitVal = thisval + dispVal = "%2.3f" % thisval + except: + traitVal = '' + dispVal = 'x' + + strainNameDisp = HT.Span(strainName, Class='fs14 fwn ffl') + + if varianceDataPage: + try: + traitVar = thisvar + dispVar = "%2.3f" % thisvar + except: + traitVar = '' + dispVar = 'x' + + if thisval == 'x': + traitVar = '' #ZS: Used to be 0, but it doesn't seem like a good idea for values of 0 to *always* be at the bottom when you sort; it makes more sense to put "nothing" + + className = 'fs13 b1 c222 ' + valueClassName = 'fs13 b1 c222 valueField ' + rowClassName = 'novalue ' + else: + if (thisval >= upperBound) or (thisval <= lowerBound): + className = 'fs13 b1 c222 outlier ' + valueClassName = 'fs13 b1 c222 valueField ' + rowClassName = 'outlier' + else: + className = 'fs13 b1 c222 ' + valueClassName = 'fs13 b1 c222 valueField ' + rowClassName = ' ' + + if varianceDataPage: + varClassName = valueClassName + str(traitVar) + valueClassName += str(traitVal) + + if strainNameOrig == strainName: + if other_strainsExist and strainNameOrig in (fd.parlist + fd.f1list): + ######################################################################################################################################################## + # ZS: Append value and variance to the value and variance input fields' list of classes; this is so the javascript can update the value when the user + # changes it. The updated value is then used when the table is sorted (tablesorter.js). This needs to be done because the "value" attribute is immutable. + ######################################################################################################################################################### + + valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right; background-color:#FFFFFF;", value=dispVal, + onChange= "javascript:this.form['_2nd_%s'].value=this.form['%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=valueClassName) + if varianceDataPage: + seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, + onChange= "javascript:this.form['V_2nd_%s'].value=this.form['V%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=varClassName) + else: + valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right; background-color:#FFFFFF;", value=dispVal, Class=valueClassName) + if varianceDataPage: + seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, Class=varClassName) + else: + valueField = HT.Input(name=strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVal, + onChange= "javascript:this.form['%s'].value=this.form['%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=valueClassName) + if varianceDataPage: + seField = HT.Input(name='V'+strainNameOrig, size=8, maxlength=8, style="text-align:right", value=dispVar, + onChange= "javascript:this.form['V%s'].value=this.form['V%s'].value;" % (strainNameOrig.replace("/", ""), strainNameOrig.replace("/", "")), Class=varClassName) + + if (strains == 'primary'): + table_row = HT.TR(Id="Primary_"+str(i+1), Class=rowClassName) + else: + table_row = HT.TR(Id="Other_"+str(i+1), Class=rowClassName) + + if varianceDataPage: + table_row.append(HT.TD(str(i+1), selectCheck, width=45, align='right', Class=className)) + table_row.append(HT.TD(strainNameDisp, strainNameAdd, align='right', width=100, Class=className)) + table_row.append(HT.TD(valueField, width=70, align='right', Id="value_"+str(i)+"_"+strains, Class=className)) + table_row.append(HT.TD("±", width=20, align='center', Class=className)) + table_row.append(HT.TD(seField, width=80, align='right', Id="SE_"+str(i)+"_"+strains, Class=className)) + else: + table_row.append(HT.TD(str(i+1), selectCheck, width=45, align='right', Class=className)) + table_row.append(HT.TD(strainNameDisp, strainNameAdd, align='right', width=100, Class=className)) + table_row.append(HT.TD(valueField, width=70, align='right', Id="value_"+str(i)+"_"+strains, Class=className)) + + if thisTrait and thisTrait.db and thisTrait.db.type =='ProbeSet': + if len(attribute_ids) > 0: + + #ZS: Get StrainId value for the next query + self.cursor.execute("""SELECT Strain.Id + FROM Strain, StrainXRef, InbredSet + WHERE Strain.Name = '%s' and + StrainXRef.StrainId = Strain.Id and + InbredSet.Id = StrainXRef.InbredSetId and + InbredSet.Name = '%s'""" % (strainName, fd.RISet)) + + strain_id = self.cursor.fetchone()[0] + + attr_counter = 1 # This is needed so the javascript can know which attribute type to associate this value with for the exported excel sheet (each attribute type being a column). + for attribute_id in attribute_ids: + + #ZS: Add extra case attribute values (if any) + self.cursor.execute("""SELECT Value + FROM CaseAttributeXRef + WHERE ProbeSetFreezeId = '%s' AND + StrainId = '%s' AND + CaseAttributeId = '%s' + group by CaseAttributeXRef.CaseAttributeId""" % (thisTrait.db.id, strain_id, str(attribute_id))) + + attributeValue = self.cursor.fetchone()[0] #Trait-specific attributes, if any + + #ZS: If it's an int, turn it into one for sorting (for example, 101 would be lower than 80 if they're strings instead of ints) + try: + attributeValue = int(attributeValue) + except: + pass + + span_Id = strains+"_attribute"+str(attr_counter)+"_sample"+str(i+1) + attr_container = HT.Span(attributeValue, Id=span_Id) + attr_className = str(attributeValue) + " " + className + table_row.append(HT.TD(attr_container, align='right', Class=attr_className)) + attr_counter += 1 + + table_body.append(table_row) + return table_body + + def getTableHeader(self, fd, thisTrait, nCols, attribute_names): + + table_header = HT.TR() + + col_class = "fs13 fwb ff1 b1 cw cbrb" + + if nCols == 6: + try: + if fd.varianceDispName: + pass + except: + fd.varianceDispName = 'Variance' + + table_header.append(HT.TH('Index', align='right', width=60, Class=col_class), + HT.TH('Sample', align='right', width=100, Class=col_class), + HT.TH('Value', align='right', width=70, Class=col_class), + HT.TH(' ', width=20, Class=col_class), + HT.TH(fd.varianceDispName, align='right', width=80, Class=col_class)) + + elif nCols == 4: + table_header.append(HT.TH('Index', align='right', width=60, Class=col_class), + HT.TH('Sample', align='right', width=100, Class=col_class), + HT.TH('Value', align='right', width=70, Class=col_class)) + + else: + pass + + if len(attribute_names) > 0: + i=0 + for attribute in attribute_names: + char_count = len(attribute) + cell_width = char_count * 14 + table_header.append(HT.TH(attribute, align='right', width=cell_width, Class="attribute_name " + col_class)) + i+=1 + + return table_header + + + def getSortByValue(self): + + sortby = ("", "") + + return sortby diff --git a/wqflask/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py index a63071c3..57c68a1c 100644 --- a/wqflask/wqflask/show_trait/show_trait_page.py +++ b/wqflask/wqflask/show_trait/show_trait_page.py @@ -40,148 +40,148 @@ from DataEditingPage import DataEditingPage class ShowTraitPage(DataEditingPage): - def __init__(self, fd, traitInfos = None): - - #templatePage.__init__(self, fd) - - if not self.openMysql(): - return - - #TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') - print("j2") - # When is traitInfos used? - if traitInfos: - print("j2.2") - database, ProbeSetID, CellID = traitInfos - else: - print("j2.3") - print("fd is:", fd) - database = fd['database'][0] - ProbeSetID = fd['ProbeSetID'][0] - print("j2.4") - CellID = fd.get('CellID') - print("j2.6") - - # We're no longer wrapping this in an exception. If we fail, let's fail hard - # Log it and fix it - #try: - print("j3") - thisTrait = webqtlTrait(db=database, name=ProbeSetID, cellid= CellID, cursor=self.cursor) - #except: - # heading = "Trait Data and Analysis Form" - # detail = ["The trait isn't available currently."] - # self.error(heading=heading,detail=detail,error="Error") - # return - print("j4") - if thisTrait.db.type == "ProbeSet": - - self.cursor.execute('''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers - FROM ProbeSetFreeze WHERE Name = "%s"''' % database) - - indId, indName, indFullName, confidential, AuthorisedUsers = self.cursor.fetchall()[0] - - if confidential == 1: - access_to_confidential_dataset = 0 - - #for the dataset that confidentiality is 1 - #1. 'admin' and 'root' can see all of the dataset - #2. 'user' can see the dataset that AuthorisedUsers contains his id(stored in the Id field of User table) - if webqtlConfig.USERDICT[self.privilege] > webqtlConfig.USERDICT['user']: - access_to_confidential_dataset = 1 - else: - AuthorisedUsersList=AuthorisedUsers.split(',') - if AuthorisedUsersList.__contains__(self.userName): - access_to_confidential_dataset = 1 - - if not access_to_confidential_dataset: - #Error, Confidential Database - heading = "Show Database" - detail = ["The %s database you selected is not open to the public \ - at this time, please go back and select other database." % indFullName] - self.error(heading=heading,detail=detail,error="Confidential Database") - return - print("environ:", request.environ) - - # Becuase of proxying remote_addr is probably localhost, so we first try for - # HTTP_X_FORWARDED_FOR - user_ip = request.environ.get('HTTP_X_FORWARDED_FOR') or request.remote_addr # in old app was fd.remote_ip - print("user_ip is:", user_ip) - query = "SELECT count(id) FROM AccessLog WHERE ip_address = %s and \ - UNIX_TIMESTAMP()-UNIX_TIMESTAMP(accesstime)<86400" - self.cursor.execute(query,user_ip) - daycount = self.cursor.fetchall() - if daycount: - daycount = daycount[0][0] - if daycount > webqtlConfig.DAILYMAXIMUM: - heading = "Retrieve Data" - detail = ['For security reasons, the maximum access to a database is \ - %d times per day per ip address. You have reached the limit, please \ - try it again tomorrow.' % webqtlConfig.DAILYMAXIMUM] - self.error(heading=heading,detail=detail) - return - else: - pass - else: - pass - - if thisTrait.db.type != 'ProbeSet' and thisTrait.cellid: - heading = "Retrieve Data" - detail = ['The Record you requested doesn\'t exist!'] - self.error(heading=heading,detail=detail) - return - - #XZ: Aug 23, 2010: I commented out this block because this feature is not used anymore - # check if animal information are available - """ - self.cursor.execute(''' - SELECT - SampleXRef.ProbeFreezeId - FROM - SampleXRef, ProbeSetFreeze - WHERE - SampleXRef.ProbeFreezeId = ProbeSetFreeze.ProbeFreezeId AND - ProbeSetFreeze.Name = "%s" - ''' % thisTrait.db.name) - - sampleId = self.cursor.fetchall() - if sampleId: - thisTrait.strainInfo = 1 - else: - thisTrait.strainInfo = None - """ - - ##identification, etc. - fd.identification = '%s : %s' % (thisTrait.db.shortname,ProbeSetID) - thisTrait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ - &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database, ProbeSetID, fd['RISet']) - - if CellID: - fd.identification = '%s/%s'%(fd.identification, CellID) - thisTrait.returnURL = '%s&CellID=%s' % (thisTrait.returnURL, CellID) - - #retrieve trait information - try: - thisTrait.retrieveInfo() - thisTrait.retrieveData() - self.updMysql() - self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)", user_ip) - self.openMysql() - except Exception as why: - print("Got an exception:", why) - heading = "Retrieve Data" - detail = ["The information you requested is not avaiable at this time."] - self.error(heading=heading, detail=detail) - return - - ##read genotype file - fd.RISet = thisTrait.riset - fd.readGenotype() - - if webqtlUtil.ListNotNull(map(lambda x:x.var, thisTrait.data.values())): - fd.displayVariance = 1 - fd.varianceDispName = 'SE' - fd.formID = 'varianceChoice' - - #self.dict['body']= thisTrait - DataEditingPage.__init__(self, fd, thisTrait) - #self.dict['title'] = '%s: Display Trait' % fd.identification + def __init__(self, fd, traitInfos = None): + + #templatePage.__init__(self, fd) + + if not self.openMysql(): + return + + #TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') + print("j2") + # When is traitInfos used? + if traitInfos: + print("j2.2") + database, ProbeSetID, CellID = traitInfos + else: + print("j2.3") + print("fd is:", fd) + database = fd['database'][0] + ProbeSetID = fd['ProbeSetID'][0] + print("j2.4") + CellID = fd.get('CellID') + print("j2.6") + + # We're no longer wrapping this in an exception. If we fail, let's fail hard + # Log it and fix it + #try: + print("j3") + thisTrait = webqtlTrait(db=database, name=ProbeSetID, cellid= CellID, cursor=self.cursor) + #except: + # heading = "Trait Data and Analysis Form" + # detail = ["The trait isn't available currently."] + # self.error(heading=heading,detail=detail,error="Error") + # return + print("j4") + if thisTrait.db.type == "ProbeSet": + + self.cursor.execute('''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers + FROM ProbeSetFreeze WHERE Name = "%s"''' % database) + + indId, indName, indFullName, confidential, AuthorisedUsers = self.cursor.fetchall()[0] + + if confidential == 1: + access_to_confidential_dataset = 0 + + #for the dataset that confidentiality is 1 + #1. 'admin' and 'root' can see all of the dataset + #2. 'user' can see the dataset that AuthorisedUsers contains his id(stored in the Id field of User table) + if webqtlConfig.USERDICT[self.privilege] > webqtlConfig.USERDICT['user']: + access_to_confidential_dataset = 1 + else: + AuthorisedUsersList=AuthorisedUsers.split(',') + if AuthorisedUsersList.__contains__(self.userName): + access_to_confidential_dataset = 1 + + if not access_to_confidential_dataset: + #Error, Confidential Database + heading = "Show Database" + detail = ["The %s database you selected is not open to the public \ + at this time, please go back and select other database." % indFullName] + self.error(heading=heading,detail=detail,error="Confidential Database") + return + print("environ:", request.environ) + + # Becuase of proxying remote_addr is probably localhost, so we first try for + # HTTP_X_FORWARDED_FOR + user_ip = request.environ.get('HTTP_X_FORWARDED_FOR') or request.remote_addr # in old app was fd.remote_ip + print("user_ip is:", user_ip) + query = "SELECT count(id) FROM AccessLog WHERE ip_address = %s and \ + UNIX_TIMESTAMP()-UNIX_TIMESTAMP(accesstime)<86400" + self.cursor.execute(query,user_ip) + daycount = self.cursor.fetchall() + if daycount: + daycount = daycount[0][0] + if daycount > webqtlConfig.DAILYMAXIMUM: + heading = "Retrieve Data" + detail = ['For security reasons, the maximum access to a database is \ + %d times per day per ip address. You have reached the limit, please \ + try it again tomorrow.' % webqtlConfig.DAILYMAXIMUM] + self.error(heading=heading,detail=detail) + return + else: + pass + else: + pass + + if thisTrait.db.type != 'ProbeSet' and thisTrait.cellid: + heading = "Retrieve Data" + detail = ['The Record you requested doesn\'t exist!'] + self.error(heading=heading,detail=detail) + return + + #XZ: Aug 23, 2010: I commented out this block because this feature is not used anymore + # check if animal information are available + """ + self.cursor.execute(''' + SELECT + SampleXRef.ProbeFreezeId + FROM + SampleXRef, ProbeSetFreeze + WHERE + SampleXRef.ProbeFreezeId = ProbeSetFreeze.ProbeFreezeId AND + ProbeSetFreeze.Name = "%s" + ''' % thisTrait.db.name) + + sampleId = self.cursor.fetchall() + if sampleId: + thisTrait.strainInfo = 1 + else: + thisTrait.strainInfo = None + """ + + ##identification, etc. + fd.identification = '%s : %s' % (thisTrait.db.shortname,ProbeSetID) + thisTrait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ + &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database, ProbeSetID, fd['RISet']) + + if CellID: + fd.identification = '%s/%s'%(fd.identification, CellID) + thisTrait.returnURL = '%s&CellID=%s' % (thisTrait.returnURL, CellID) + + #retrieve trait information + try: + thisTrait.retrieveInfo() + thisTrait.retrieveData() + self.updMysql() + self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)", user_ip) + self.openMysql() + except Exception as why: + print("Got an exception:", why) + heading = "Retrieve Data" + detail = ["The information you requested is not avaiable at this time."] + self.error(heading=heading, detail=detail) + return + + ##read genotype file + fd.RISet = thisTrait.riset + fd.readGenotype() + + if webqtlUtil.ListNotNull(map(lambda x:x.var, thisTrait.data.values())): + fd.displayVariance = 1 + fd.varianceDispName = 'SE' + fd.formID = 'varianceChoice' + + #self.dict['body']= thisTrait + DataEditingPage.__init__(self, fd, thisTrait) + #self.dict['title'] = '%s: Display Trait' % fd.identification -- cgit v1.2.3