From 527bb0459cf488e5021696e326dc10d28ecdd74c Mon Sep 17 00:00:00 2001
From: Sam Ockman
Date: Thu, 24 May 2012 02:18:20 -0400
Subject: Trying to get stuff working under new structure
---
wqflask/base/GeneralObject.py | 71 +++++
wqflask/base/JinjaPage.py | 28 ++
wqflask/base/__init__.py | 0
wqflask/base/admin.py | 88 ++++++
wqflask/base/cgiData.py | 70 +++++
wqflask/base/cookieData.py | 52 ++++
wqflask/base/footer.py | 6 +
wqflask/base/header.py | 6 +
wqflask/base/indexBody.py | 290 +++++++++++++++++++
wqflask/base/myCookie.py | 55 ++++
wqflask/base/sessionData.py | 53 ++++
wqflask/base/template.py | 123 ++++++++
wqflask/base/templatePage.py | 222 +++++++++++++++
wqflask/base/webqtlCaseData.py | 54 ++++
wqflask/base/webqtlConfig.py | 73 +++++
wqflask/base/webqtlConfigLocal.py | 19 ++
wqflask/base/webqtlDataset.py | 160 +++++++++++
wqflask/base/webqtlFormData.py | 289 +++++++++++++++++++
wqflask/base/webqtlTrait.py | 581 ++++++++++++++++++++++++++++++++++++++
19 files changed, 2240 insertions(+)
create mode 100755 wqflask/base/GeneralObject.py
create mode 100644 wqflask/base/JinjaPage.py
create mode 100755 wqflask/base/__init__.py
create mode 100755 wqflask/base/admin.py
create mode 100755 wqflask/base/cgiData.py
create mode 100755 wqflask/base/cookieData.py
create mode 100755 wqflask/base/footer.py
create mode 100755 wqflask/base/header.py
create mode 100755 wqflask/base/indexBody.py
create mode 100755 wqflask/base/myCookie.py
create mode 100755 wqflask/base/sessionData.py
create mode 100755 wqflask/base/template.py
create mode 100755 wqflask/base/templatePage.py
create mode 100755 wqflask/base/webqtlCaseData.py
create mode 100755 wqflask/base/webqtlConfig.py
create mode 100755 wqflask/base/webqtlConfigLocal.py
create mode 100755 wqflask/base/webqtlDataset.py
create mode 100755 wqflask/base/webqtlFormData.py
create mode 100755 wqflask/base/webqtlTrait.py
(limited to 'wqflask/base')
diff --git a/wqflask/base/GeneralObject.py b/wqflask/base/GeneralObject.py
new file mode 100755
index 00000000..311c9e22
--- /dev/null
+++ b/wqflask/base/GeneralObject.py
@@ -0,0 +1,71 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# 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))
+ """
+
+ 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/JinjaPage.py b/wqflask/base/JinjaPage.py
new file mode 100644
index 00000000..07e485b1
--- /dev/null
+++ b/wqflask/base/JinjaPage.py
@@ -0,0 +1,28 @@
+import logging
+logging.basicConfig(filename="/tmp/gn_log", level=logging.INFO)
+_log = logging.getLogger("search")
+
+from pprint import pformat as pf
+
+import templatePage
+
+from utility import formatting
+
+import jinja2
+JinjaEnv = jinja2.Environment(loader=jinja2.FileSystemLoader('/gnshare/gn/web/webqtl/templates'))
+JinjaEnv.globals['numify'] = formatting.numify
+
+
+class JinjaPage(templatePage.templatePage):
+ """Class derived from our regular templatePage, but uses Jinja2 instead.
+
+ When converting pages from Python generated templates, change the base class from templatePage
+ to JinjaPage
+
+ """
+
+
+ def write(self):
+ """We override the base template write so we can use Jinja2."""
+ _log.info(pf(self.__dict__))
+ return self.jtemplate.render(**self.__dict__)
diff --git a/wqflask/base/__init__.py b/wqflask/base/__init__.py
new file mode 100755
index 00000000..e69de29b
diff --git a/wqflask/base/admin.py b/wqflask/base/admin.py
new file mode 100755
index 00000000..a04df2da
--- /dev/null
+++ b/wqflask/base/admin.py
@@ -0,0 +1,88 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+
+
+
+
+#XZ, 04/02/2009: we should put this into database.
+
+
+###LIST of databases used into gene name query
+
+
+ADMIN_search_dbs = {
+ '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'],
+ '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'],
+ 'KIDNEY': ['MA_M2_0806_R'],
+ 'MAMMARY TUMORS': ['MA_M_0704_R', 'NCI_Agil_Mam_Tum_RMA_0409'],
+ 'PREFRONTAL CORTEX': ['VCUSal_1206_R'],
+ 'SPLEEN': ['IoP_SPL_RMA_0509'],
+ 'NUCLEUS ACCUMBENS': ['VCUSalo_1007_R'],
+ 'NEOCORTEX': ['HQFNeoc_0208_RankInv'],
+ 'ADIPOSE': ['UCLA_BHF2_ADIPOSE_0605'],
+ 'RETINA': ['Illum_Retina_BXD_RankInv0410']
+ },
+ 'human': {
+ 'LYMPHOBLAST B CELL': ['Human_1008', 'UT_CEPH_RankInv0909'],
+ 'WHOLE BRAIN': ['GSE5281_F_RMA0709', 'GSE15222_F_RI_0409']
+ }
+ }
+
+
+###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'],
+ 'KIDNEY': ['Kid'],
+ 'ADRENAL GLAND': ['Adr'],
+ 'HEART': ['Hea'],
+ 'MAMMARY TUMORS': ['Mam'],
+ 'PREFRONTAL CORTEX': ['Pfc'],
+ 'SPLEEN': ['Spl'],
+ 'NUCLEUS ACCUMBENS': ['Nac'],
+ 'NEOCORTEX': ['Ctx'],
+ 'ADIPOSE': ['Wfat'],
+ 'RETINA': ['Ret']
+ }
+
+
diff --git a/wqflask/base/cgiData.py b/wqflask/base/cgiData.py
new file mode 100755
index 00000000..57416060
--- /dev/null
+++ b/wqflask/base/cgiData.py
@@ -0,0 +1,70 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+#########################################
+#convert Field storage object to Dict object
+#in order to be able to saved into a session file
+#########################################
+
+class cgiData(dict):
+ '''convert Field storage object to Dict object
+ Filed storage object cannot be properly dumped
+ '''
+
+ 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
+
+
+
+
diff --git a/wqflask/base/cookieData.py b/wqflask/base/cookieData.py
new file mode 100755
index 00000000..4b7c9046
--- /dev/null
+++ b/wqflask/base/cookieData.py
@@ -0,0 +1,52 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+#########################################
+#convert mod_python object to Dict object
+#in order to be able to be pickled
+#########################################
+
+class cookieData(dict):
+ 'convert mod python Cookie object to Dict object'
+
+ 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
+
+
+
diff --git a/wqflask/base/footer.py b/wqflask/base/footer.py
new file mode 100755
index 00000000..6f92fdf8
--- /dev/null
+++ b/wqflask/base/footer.py
@@ -0,0 +1,6 @@
+import webqtlConfig
+
+footer_html = open(webqtlConfig.HTMLPATH + 'footer.html', 'r').read()
+footer = footer_html.replace('%"','%%"')
+
+footer_string = footer.replace('', '%s')
diff --git a/wqflask/base/header.py b/wqflask/base/header.py
new file mode 100755
index 00000000..b6136b51
--- /dev/null
+++ b/wqflask/base/header.py
@@ -0,0 +1,6 @@
+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
diff --git a/wqflask/base/indexBody.py b/wqflask/base/indexBody.py
new file mode 100755
index 00000000..aa67dffa
--- /dev/null
+++ b/wqflask/base/indexBody.py
@@ -0,0 +1,290 @@
+index_body_string = """
+
+
+
+ You can also use advanced commands. Copy these simple examples
+ into the Get Any or Combined search fields:
+
+
+
POSITION=(chr1 25 30) finds genes, markers, or transcripts on chromosome 1 between 25 and 30 Mb.
+
+
MEAN=(15 16) LRS=(23 46) in the Combined field finds highly expressed genes (15 to 16 log2 units) AND with peak LRS linkage between 23 and 46.
+
+
+
RIF=mitochondrial searches RNA databases for GeneRIF links.
+
+
WIKI=nicotine searches GeneWiki for genes that you or other users have annotated with the word nicotine.
+
+
GO:0045202 searches for synapse-associated genes listed in the Gene Ontology.
+
+
+
GO:0045202 LRS=(9 99 Chr4 122 155) cisLRS=(9 999 10) in Combined finds synapse-associated genes with cis eQTL on Chr 4 from 122 and 155 Mb with LRS scores between 9 and 999.
+
+
RIF=diabetes LRS=(9 999 Chr2 100 105) transLRS=(9 999 10) in Combined finds diabetes-associated transcripts with peak trans eQTLs on Chr 2 between 100 and 105 Mb with LRS scores between 9 and 999.
+
+
+
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
new file mode 100755
index 00000000..db5320df
--- /dev/null
+++ b/wqflask/base/myCookie.py
@@ -0,0 +1,55 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+#########################################
+## 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
+
+
+
+
diff --git a/wqflask/base/sessionData.py b/wqflask/base/sessionData.py
new file mode 100755
index 00000000..01555f87
--- /dev/null
+++ b/wqflask/base/sessionData.py
@@ -0,0 +1,53 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+#########################################
+#convert mod_python object to Dict object
+#in order to be able to be pickled
+#########################################
+
+class sessionData(dict):
+ 'convert mod python Session object to Dict object'
+
+ def __init__(self, mod_python_session=None):
+
+ if not mod_python_session:
+ mod_python_session = {}
+
+ 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
new file mode 100755
index 00000000..85bd86df
--- /dev/null
+++ b/wqflask/base/template.py
@@ -0,0 +1,123 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+template = """
+
+
+
+
+%s
+
+
+
+
+
+
+
+%s
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+%s
+
+
+
+
+%s
+
+
+
+
+ %s
+
+
+
+
+
+
+
+
+ %s
+
+
+
+
+
+
+
+
+
+
%s
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+"""
diff --git a/wqflask/base/templatePage.py b/wqflask/base/templatePage.py
new file mode 100755
index 00000000..4dece24a
--- /dev/null
+++ b/wqflask/base/templatePage.py
@@ -0,0 +1,222 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+#templatePage.py
+#
+#--Genenetwork generates a lot of pages; this file is the generic version of them, defining routines they all use.
+#
+#Classes:
+#templatePage
+#
+#Functions (of templatePage):
+#__init__(...) -- class constructor, allows a more specific template to be used in addition to templatePage
+#__str__(self) -- returns the object's elements as a tuple
+#__del__(self) -- closes the current connection to MySQL, if there is one
+#write -- explained below
+#writefile -- explained below
+#openMysql(self) -- opens a MySQL connection and stores the resulting cursor in the object's cursor variable
+#updMysql(self) -- same as openMysql
+#error -- explained below
+#session -- explained below
+
+
+import socket
+import time
+import shutil
+import MySQLdb
+import os
+
+from htmlgen import HTMLgen2 as HT
+
+import template
+import webqtlConfig
+import header
+import footer
+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'
+ 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
new file mode 100755
index 00000000..4df32ca4
--- /dev/null
+++ b/wqflask/base/webqtlCaseData.py
@@ -0,0 +1,54 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+class webqtlCaseData:
+ """
+ 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__
+
+
+
diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py
new file mode 100755
index 00000000..755595e0
--- /dev/null
+++ b/wqflask/base/webqtlConfig.py
@@ -0,0 +1,73 @@
+from webqtlConfigLocal import *
+#########################################'
+# Environment Variables - public
+#########################################
+
+#Debug Level
+#1 for debug, mod python will reload import each time
+DEBUG = 1
+
+#USER privilege
+USERDICT = {'guest':1,'user':2, 'admin':3, 'root':4}
+
+#minimum number of informative strains
+KMININFORMATIVE = 5
+
+#maximum number of traits for interval mapping
+MULTIPLEMAPPINGLIMIT = 11
+
+#maximum number of traits for correlation
+MAXCORR = 100
+
+#Daily download limit from one IP
+DAILYMAXIMUM = 1000
+
+#maximum LRS value
+MAXLRS = 460.0
+
+#temporary data life span
+MAXLIFE = 86400
+
+#MINIMUM Database public value
+PUBLICTHRESH = 0
+
+#NBCI address
+NCBI_LOCUSID = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=Graphics&list_uids=%s"
+UCSC_REFSEQ = "http://genome.cse.ucsc.edu/cgi-bin/hgGene?db=%s&hgg_gene=%s&hgg_chrom=chr%s&hgg_start=%s&hgg_end=%s"
+GENBANK_ID = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=Nucleotide&cmd=search&doptcmdl=DocSum&term=%s"
+OMIM_ID = "http://www.ncbi.nlm.nih.gov/omim/%s"
+UNIGEN_ID = "http://www.ncbi.nlm.nih.gov/UniGene/clust.cgi?ORG=%s&CID=%s"
+HOMOLOGENE_ID = "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=homologene&Cmd=DetailsSearch&Term=%s"
+PUBMEDLINK_URL = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids=%s&dopt=Abstract"
+UCSC_POS = "http://genome.ucsc.edu/cgi-bin/hgTracks?clade=mammal&org=%s&db=%s&position=chr%s:%s-%s&pix=800&Submit=submit"
+UCSC_BLAT = 'http://genome.ucsc.edu/cgi-bin/hgBlat?org=%s&db=%s&type=0&sort=0&output=0&userSeq=%s'
+UTHSC_BLAT = 'http://ucscbrowser.genenetwork.org/cgi-bin/hgBlat?org=%s&db=%s&type=0&sort=0&output=0&userSeq=%s'
+UCSC_GENOME = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=%s&position=chr%s:%d-%d&hgt.customText=http://web2qtl.utmem.edu:88/snp/chr%s"
+ENSEMBLE_BLAT = 'http://www.ensembl.org/Mus_musculus/featureview?type=AffyProbe&id=%s'
+DBSNP = 'http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=%s'
+UCSC_RUDI_TRACK_URL = " http://genome.cse.ucsc.edu/cgi-bin/hgTracks?org=%s&db=%s&hgt.customText=http://gbic.biol.rug.nl/~ralberts/tracks/%s/%s"
+GENOMEBROWSER_URL="http://ucscbrowser.genenetwork.org/cgi-bin/hgTracks?clade=mammal&org=Mouse&db=mm9&position=%s&hgt.suggest=&pix=800&Submit=submit"
+ENSEMBLETRANSCRIPT_URL="http://useast.ensembl.org/Mus_musculus/Lucene/Details?species=Mus_musculus;idx=Transcript;end=1;q=%s"
+
+SECUREDIR = GNROOT + 'secure/'
+COMMON_LIB = GNROOT + 'support/admin'
+HTMLPATH = GNROOT + 'web/'
+IMGDIR = HTMLPATH +'image/'
+IMAGESPATH = HTMLPATH + 'images/'
+UPLOADPATH = IMAGESPATH + 'upload/'
+TMPDIR = '/tmp/'
+GENODIR = HTMLPATH + 'genotypes/'
+GENO_ARCHIVE_DIR = GENODIR + 'archive/'
+TEXTDIR = HTMLPATH + 'ProbeSetFreeze_DataMatrix/'
+CMDLINEDIR = HTMLPATH + 'webqtl/cmdLine/'
+ChangableHtmlPath = GNROOT + 'web/'
+
+SITENAME = 'GN'
+PORTADDR = "http://132.192.47.32"
+BASEHREF = ''
+INFOPAGEHREF = '/dbdoc/%s.html'
+GLOSSARYFILE = "/glossary.html"
+CGIDIR = '/webqtl/' #XZ: The variable name 'CGIDIR' should be changed to 'PYTHONDIR'
+SCRIPTFILE = 'main.py'
+REFRESHSTR = ''
+REFRESHDIR = '%s' + SCRIPTFILE +'?sid=%s'
diff --git a/wqflask/base/webqtlConfigLocal.py b/wqflask/base/webqtlConfigLocal.py
new file mode 100755
index 00000000..35da73c2
--- /dev/null
+++ b/wqflask/base/webqtlConfigLocal.py
@@ -0,0 +1,19 @@
+#########################################'
+# Environment Variables - private
+#########################################
+
+MYSQL_SERVER = 'localhost'
+DB_NAME = 'db_webqtl'
+DB_USER = 'webqtlupd'
+DB_PASSWD = 'zhou&yan@ut'
+
+MYSQL_UPDSERVER = 'localhost'
+DB_UPDNAME = 'db_webqtl'
+DB_UPDUSER = 'webqtlupd'
+DB_UPDPASSWD = 'zhou&yan@ut'
+
+GNROOT = '/gnshare/gn/'
+PythonPath = '/usr/bin/python'
+PIDDLE_FONT_PATH = '/usr/lib/python2.4/site-packages/piddle/truetypefonts/'
+
+TEXTUI=1 # XZ: This is to protect GN production server. If set to 0, no text UI is allowed.
diff --git a/wqflask/base/webqtlDataset.py b/wqflask/base/webqtlDataset.py
new file mode 100755
index 00000000..da1b8601
--- /dev/null
+++ b/wqflask/base/webqtlDataset.py
@@ -0,0 +1,160 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+from htmlgen import HTMLgen2 as HT
+
+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")
+
+
+
+
+
diff --git a/wqflask/base/webqtlFormData.py b/wqflask/base/webqtlFormData.py
new file mode 100755
index 00000000..84e41cae
--- /dev/null
+++ b/wqflask/base/webqtlFormData.py
@@ -0,0 +1,289 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+from mod_python import Cookie
+import string
+import os
+
+import reaper
+
+import webqtlConfig
+import cookieData
+import sessionData
+from cgiData import cgiData
+from webqtlCaseData import webqtlCaseData
+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, req = None, mod_python_session=None, FieldStorage_formdata=None):
+
+ 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
+
+
+ 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 __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
new file mode 100755
index 00000000..f5051e45
--- /dev/null
+++ b/wqflask/base/webqtlTrait.py
@@ -0,0 +1,581 @@
+import string
+
+from htmlgen import HTMLgen2 as HT
+
+import webqtlConfig
+from webqtlCaseData import webqtlCaseData
+from webqtlDataset import webqtlDataset
+from dbFunction import webqtlDatabaseFunction
+from utility import webqtlUtil
+
+
+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):
+ 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 = {}
+ 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, `value` + ' parameter format error.'
+ else:
+ raise KeyError, `name`+' not a valid parameter for this class.'
+
+ if self.db and type(self.db) == type("1"):
+ assert self.cursor
+ self.db = webqtlDataset(self.db, self.cursor)
+
+ #if self.db == None, not from a database
+ 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':
+ 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)
+ self.cursor.execute(query)
+ self.sequence = self.cursor.fetchone()[0]
+
+
+ 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':
+ query = '''
+ 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
+
+
--
cgit v1.2.3
From c1432f41d243047e767a4ec1dc423b9fd0055e0f Mon Sep 17 00:00:00 2001
From: Sam Ockman
Date: Sun, 3 Jun 2012 04:08:15 -0400
Subject: Cleaning up trait stuff in flask
---
wqflask/base/webqtlTrait.py | 228 ++++++++++++++------------
wqflask/wqflask/show_trait/show_trait_page.py | 42 +++--
2 files changed, 145 insertions(+), 125 deletions(-)
(limited to 'wqflask/base')
diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py
index f5051e45..c3c0cded 100755
--- a/wqflask/base/webqtlTrait.py
+++ b/wqflask/base/webqtlTrait.py
@@ -1,3 +1,5 @@
+from __future__ import division, print_function
+
import string
from htmlgen import HTMLgen2 as HT
@@ -8,14 +10,18 @@ from webqtlDataset import webqtlDataset
from dbFunction import webqtlDatabaseFunction
from utility import webqtlUtil
+from pprint import pformat as pf
+
class webqtlTrait:
"""
- Trait class defines a trait in webqtl, can be either Microarray,
+ 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.
@@ -25,6 +31,9 @@ class webqtlTrait:
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)
@@ -35,28 +44,29 @@ class webqtlTrait:
elif len(name2) == 3:
self.db, self.name, self.cellid = name2
else:
- raise KeyError, `value` + ' parameter format error.'
+ raise KeyError, repr(value) + ' parameter format error.'
else:
- raise KeyError, `name`+' not a valid parameter for this class.'
-
- if self.db and type(self.db) == type("1"):
- assert self.cursor
+ 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
+ SELECT
+ InbredSet.Name
+ FROM
+ InbredSet, Temp
+ WHERE
+ Temp.InbredSetId = InbredSet.Id AND
Temp.Name = "%s"
- ''' % self.name)
+ ''', self.name)
self.riset = self.cursor.fetchone()[0]
- else:
+ else:
self.riset = self.db.getRISet()
#
@@ -73,8 +83,9 @@ class webqtlTrait:
if self.db:
if self.db.type == 'ProbeSet':
+ print("Doing ProbeSet Query")
query = '''
- SELECT
+ SELECT
ProbeSet.BlatSeq
FROM
ProbeSet, ProbeSetFreeze, ProbeSetXRef
@@ -84,10 +95,11 @@ class webqtlTrait:
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]
-
+
def getName(self):
str = ""
if self.db and self.name:
@@ -98,12 +110,12 @@ class webqtlTrait:
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
+ # 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
@@ -137,10 +149,10 @@ class webqtlTrait:
str += "::" + self.cellid
else:
str = self.description
-
+
return str
-
+
#def __str__(self):
# #return "%s %s" % (self.getName(), self.riset)
# return self.getName()
@@ -166,7 +178,7 @@ class webqtlTrait:
else:
result.append(None)
return result
-
+
def exportInformative(self, incVar=0):
"""
export informative strain
@@ -195,7 +207,7 @@ class webqtlTrait:
assert self.cursor
if self.db.type == 'ProbeSet':
query = '''
- SELECT
+ SELECT
ProbeSet.BlatSeq
FROM
ProbeSet, ProbeSetFreeze, ProbeSetXRef
@@ -209,40 +221,40 @@ class webqtlTrait:
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
+ 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':
+ elif self.db.type == 'Publish':
query = '''
- SELECT
- Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id
- FROM
+ SELECT
+ Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id
+ FROM
(PublishData, Strain, PublishXRef, PublishFreeze)
- left join PublishSE on
+ 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
+ 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
@@ -252,21 +264,21 @@ class webqtlTrait:
elif self.cellid:
#Probe Data
query = '''
- SELECT
- Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id
- FROM
- (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef,
+ SELECT
+ Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id
+ FROM
+ (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef,
Strain, Probe, ProbeSet)
- left join ProbeSE on
+ 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
+ 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
@@ -295,23 +307,23 @@ class webqtlTrait:
#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
+ 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
+ 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
+ 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()
@@ -328,7 +340,7 @@ class webqtlTrait:
ndata = item[3]
self.data[item[0]] = webqtlCaseData(val, var, ndata)
#end for
- else:
+ else:
for item in results:
val = item[1]
if val != None:
@@ -341,16 +353,16 @@ class webqtlTrait:
#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':
@@ -358,22 +370,22 @@ class webqtlTrait:
# '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,
+ 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
+ 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
@@ -382,7 +394,7 @@ class webqtlTrait:
disfieldString = string.join(self.db.disfield,',ProbeSet.')
disfieldString = 'ProbeSet.' + disfieldString
query = """
- SELECT %s
+ SELECT %s
FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef
WHERE
ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND
@@ -396,7 +408,7 @@ class webqtlTrait:
disfieldString = string.join(self.db.disfield,',Geno.')
disfieldString = 'Geno.' + disfieldString
query = """
- SELECT %s
+ SELECT %s
FROM Geno, GenoFreeze, GenoXRef
WHERE
GenoXRef.GenoFreezeId = GenoFreeze.Id AND
@@ -408,7 +420,7 @@ class webqtlTrait:
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:
@@ -457,12 +469,12 @@ class webqtlTrait:
if QTL:
if self.db.type == 'ProbeSet' and not self.cellid:
query = '''
- SELECT
- ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean
- FROM
+ SELECT
+ ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean
+ FROM
ProbeSetXRef, ProbeSet
- WHERE
- ProbeSetXRef.ProbeSetId = ProbeSet.Id AND
+ WHERE
+ ProbeSetXRef.ProbeSetId = ProbeSet.Id AND
ProbeSet.Name = "%s" AND
ProbeSetXRef.ProbeSetFreezeId =%s
''' % (self.name, self.db.id)
@@ -491,11 +503,11 @@ class webqtlTrait:
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:
@@ -503,14 +515,14 @@ class webqtlTrait:
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','')" %
+ 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','')" %
+ 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:
@@ -526,12 +538,12 @@ class webqtlTrait:
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,\
@@ -541,16 +553,16 @@ class webqtlTrait:
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:
+ 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:
+ 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")
@@ -572,10 +584,8 @@ class webqtlTrait:
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/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py
index 03f8b9b3..c7d6618e 100644
--- a/wqflask/wqflask/show_trait/show_trait_page.py
+++ b/wqflask/wqflask/show_trait/show_trait_page.py
@@ -36,29 +36,39 @@ from DataEditingPage import DataEditingPage
class ShowTraitPage(DataEditingPage):
- def __init__(self, fd, traitInfos = []):
+ def __init__(self, fd, traitInfos = None):
- templatePage.__init__(self, fd)
+ #templatePage.__init__(self, fd)
if not self.openMysql():
return
- TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')
-
+ #TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')
+ print("j2")
+ # When is traitInfos used?
if traitInfos:
- database,ProbeSetID,CellID = traitInfos
+ print("j2.2")
+ database, ProbeSetID, CellID = traitInfos
else:
- database = fd.formdata.getfirst('database')
- ProbeSetID = fd.formdata.getfirst('ProbeSetID')
- CellID = fd.formdata.getfirst('CellID')
- try:
- 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("j2.3")
+ print("fd is:", fd)
+ database = fd['database']
+ ProbeSetID = fd['ProbeSetID']
+ 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
--
cgit v1.2.3
From 3d6be932e5185e4dd7170b3ea740591de01341a0 Mon Sep 17 00:00:00 2001
From: Sam Ockman
Date: Sun, 3 Jun 2012 05:47:07 -0400
Subject: Before changing fd for trait analysis into a webQTLFormData object
---
wqflask/base/webqtlTrait.py | 17 +++++++++--------
wqflask/wqflask/show_trait/show_trait_page.py | 21 +++++++++++++++------
2 files changed, 24 insertions(+), 14 deletions(-)
(limited to 'wqflask/base')
diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py
index c3c0cded..88226894 100755
--- a/wqflask/base/webqtlTrait.py
+++ b/wqflask/base/webqtlTrait.py
@@ -92,12 +92,13 @@ class webqtlTrait:
WHERE
ProbeSet.Id=ProbeSetXRef.ProbeSetId and
ProbeSetFreeze.Id = ProbeSetXRef.ProbeSetFreezeId and
- ProbeSet.Name = "%s" and
- ProbeSetFreeze.Name = "%s"
- ''' % (self.name, self.db.name)
+ ProbeSet.Name = %s and
+ ProbeSetFreeze.Name = %s
+ ''', (self.name, self.db.name)
print("query is:", query)
- self.cursor.execute(query)
+ self.cursor.execute(*query)
self.sequence = self.cursor.fetchone()[0]
+ print("self.sequence is:", self.sequence)
def getName(self):
@@ -124,7 +125,7 @@ class webqtlTrait:
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)
+ 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()
@@ -206,7 +207,7 @@ class webqtlTrait:
def getSequence(self):
assert self.cursor
if self.db.type == 'ProbeSet':
- query = '''
+ self.cursor.execute('''
SELECT
ProbeSet.BlatSeq
FROM
@@ -216,8 +217,8 @@ class webqtlTrait:
ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and
ProbeSet.Name = %s
ProbeSetFreeze.Name = %s
- ''' , (self.name, self.db.name)
- self.cursor.execute(query)
+ ''', self.name, self.db.name)
+ #self.cursor.execute(query)
results = self.fetchone()
return results[0]
diff --git a/wqflask/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py
index c7d6618e..a34c20cf 100644
--- a/wqflask/wqflask/show_trait/show_trait_page.py
+++ b/wqflask/wqflask/show_trait/show_trait_page.py
@@ -24,6 +24,10 @@
#
# Last updated by GeneNetwork Core Team 2010/10/20
+from __future__ import division, print_function
+
+from flask import request
+
from htmlgen import HTMLgen2 as HT
from base import webqtlConfig
@@ -96,8 +100,12 @@ class ShowTraitPage(DataEditingPage):
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)
- user_ip = fd.remote_ip
+ # 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)
@@ -143,9 +151,9 @@ class ShowTraitPage(DataEditingPage):
"""
##identification, etc.
- fd.identification = '%s : %s'%(thisTrait.db.shortname,ProbeSetID)
+ 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)
+ &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database, ProbeSetID, fd['RISet'])
if CellID:
fd.identification = '%s/%s'%(fd.identification, CellID)
@@ -156,12 +164,13 @@ class ShowTraitPage(DataEditingPage):
thisTrait.retrieveInfo()
thisTrait.retrieveData()
self.updMysql()
- self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)" ,user_ip)
+ self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)", user_ip)
self.openMysql()
- except:
+ 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)
+ self.error(heading=heading, detail=detail)
return
##read genotype file
--
cgit v1.2.3
From b2240d137c4d81110994bc8e2e9004bd7a01fe5b Mon Sep 17 00:00:00 2001
From: Sam Ockman
Date: Sun, 3 Jun 2012 06:20:36 -0400
Subject: Now using modified webqtlformdata for trait analysis
---
wqflask/base/webqtlFormData.py | 119 ++++++++++++++------------
wqflask/wqflask/show_trait/show_trait_page.py | 4 +-
wqflask/wqflask/views.py | 6 +-
3 files changed, 72 insertions(+), 57 deletions(-)
(limited to 'wqflask/base')
diff --git a/wqflask/base/webqtlFormData.py b/wqflask/base/webqtlFormData.py
index 84e41cae..c94dbe53 100755
--- a/wqflask/base/webqtlFormData.py
+++ b/wqflask/base/webqtlFormData.py
@@ -24,7 +24,7 @@
#
# Last updated by GeneNetwork Core Team 2010/10/20
-from mod_python import Cookie
+#from mod_python import Cookie
import string
import os
@@ -47,7 +47,9 @@ class webqtlFormData:
#XZ: Attention! All attribute values must be picklable!
- def __init__(self, req = None, mod_python_session=None, FieldStorage_formdata=None):
+ 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)
@@ -62,34 +64,35 @@ class webqtlFormData:
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')
+ #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))
- #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;
+ # 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)
@@ -101,12 +104,21 @@ class webqtlFormData:
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:
@@ -114,7 +126,7 @@ class webqtlFormData:
rstr += '%s:%s\n' % (item,str(getattr(self,item)))
return rstr
-
+
def readGenotype(self):
'read genotype from .geno file'
if self.RISet == 'BXD300':
@@ -127,15 +139,15 @@ class webqtlFormData:
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;
+ # 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
@@ -148,7 +160,7 @@ class webqtlFormData:
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'
@@ -158,16 +170,16 @@ class webqtlFormData:
if incf1:
strainlst = self.f1list + self.strainlist
else:
- strainlst = self.strainlist
-
-
+ 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)
@@ -183,8 +195,8 @@ class webqtlFormData:
vals = vals[:len(strainlst)]
else:
pass
-
-
+
+
if variancefiledata:
tt = string.split(variancefiledata)
vars = map(webqtlUtil.StringAsFloat, tt)
@@ -200,7 +212,7 @@ class webqtlFormData:
vars = vars[:len(strainlst)]
else:
pass
-
+
if Nfiledata:
tt = string.split(Nfiledata)
nstrains = map(webqtlUtil.IntAsFloat, tt)
@@ -208,14 +220,14 @@ class webqtlFormData:
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
@@ -241,26 +253,26 @@ class webqtlFormData:
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'
@@ -273,17 +285,16 @@ class webqtlFormData:
#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),
+ 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/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py
index a34c20cf..d4019fd5 100644
--- a/wqflask/wqflask/show_trait/show_trait_page.py
+++ b/wqflask/wqflask/show_trait/show_trait_page.py
@@ -56,8 +56,8 @@ class ShowTraitPage(DataEditingPage):
else:
print("j2.3")
print("fd is:", fd)
- database = fd['database']
- ProbeSetID = fd['ProbeSetID']
+ database = fd['database'][0]
+ ProbeSetID = fd['ProbeSetID'][0]
print("j2.4")
CellID = fd.get('CellID')
print("j2.6")
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 611cc05b..3457f0ff 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -7,6 +7,8 @@ from flask import render_template, request
from wqflask import search_results
from wqflask.show_trait import show_trait_page
+from base import webqtlFormData
+
from pprint import pformat as pf
@app.route("/")
@@ -21,5 +23,7 @@ def search():
@app.route("/showDatabaseBXD")
def showDatabaseBXD():
- template_vars = show_trait_page.ShowTraitPage(request.args)
+ # Here it's currently too complicated not to use an fd that is a webqtlFormData
+ fd = webqtlFormData.webqtlFormData(request.args)
+ template_vars = show_trait_page.ShowTraitPage(fd)
return render_template("trait_data_and_analysis.html")
--
cgit v1.2.3
From cad0bdf26b325c7d5fa1757e44db8721a9d86cca Mon Sep 17 00:00:00 2001
From: Sam Ockman
Date: Mon, 4 Jun 2012 22:45:24 -0400
Subject: Checkpoint along modifying for data trait and analysis
---
wqflask/base/templatePage.py | 44 ++++++++--------
wqflask/wqflask/show_trait/DataEditingPage.py | 73 ++++++++++++++++++---------
wqflask/wqflask/show_trait/show_trait_page.py | 4 +-
3 files changed, 74 insertions(+), 47 deletions(-)
(limited to 'wqflask/base')
diff --git a/wqflask/base/templatePage.py b/wqflask/base/templatePage.py
index 4dece24a..821c6181 100755
--- a/wqflask/base/templatePage.py
+++ b/wqflask/base/templatePage.py
@@ -70,13 +70,13 @@ class templatePage:
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 = ''
@@ -89,11 +89,13 @@ class templatePage:
self.userName = 'Guest'
self.privilege = 'guest'
- 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']
-
+
+ # 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
@@ -126,20 +128,20 @@ class templatePage:
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)
-
+ 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')
@@ -147,9 +149,9 @@ class templatePage:
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)
+ shutil.move(path_tmp,path_html)
except:
- pass
+ pass
def openMysql(self):
try:
@@ -176,12 +178,12 @@ class templatePage:
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:
@@ -190,7 +192,7 @@ class templatePage:
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:
@@ -198,7 +200,7 @@ class templatePage:
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)
@@ -210,13 +212,11 @@ class templatePage:
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;
+ # 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/wqflask/show_trait/DataEditingPage.py b/wqflask/wqflask/show_trait/DataEditingPage.py
index c2e1c37f..1186fa03 100755
--- a/wqflask/wqflask/show_trait/DataEditingPage.py
+++ b/wqflask/wqflask/show_trait/DataEditingPage.py
@@ -52,35 +52,62 @@ class DataEditingPage(templatePage):
## 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")
+ #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':'_'}
+ 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'
diff --git a/wqflask/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py
index d4019fd5..a63071c3 100644
--- a/wqflask/wqflask/show_trait/show_trait_page.py
+++ b/wqflask/wqflask/show_trait/show_trait_page.py
@@ -182,6 +182,6 @@ class ShowTraitPage(DataEditingPage):
fd.varianceDispName = 'SE'
fd.formID = 'varianceChoice'
- self.dict['body']= thisTrait
+ #self.dict['body']= thisTrait
DataEditingPage.__init__(self, fd, thisTrait)
- self.dict['title'] = '%s: Display Trait' % fd.identification
+ #self.dict['title'] = '%s: Display Trait' % fd.identification
--
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/base')
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
-
+
@@ -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:
@@ -206,85 +206,85 @@ Quick HELP Examples and
RIF=diabetes LRS=(9 999 Chr2 100 105) transLRS=(9 999 10) in Combined finds diabetes-associated transcripts with peak trans eQTLs on Chr 2 between 100 and 105 Mb with LRS scores between 9 and 999.
-