From f1d7725c5f7529c5f587bab4ea89d3467b903ddb Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Wed, 12 Sep 2012 18:22:45 -0500 Subject: Worked towards correctly passing form data to correlation page and addressed various bugs that arose while doing so --- misc/byobu_commands.txt | 6 - misc/find.txt | 1 - misc/notes.txt | 41 +++++++ misc/python_stuff.txt | 1 - misc/runserver.txt | 1 - misc/virtual_env.txt | 1 - wqflask/base/webqtlFormData.py | 121 +++++++++++---------- wqflask/wqflask/correlation/CorrelationPage.py | 82 +++++++------- .../new/javascript/trait_data_and_analysis.coffee | 12 +- .../new/javascript/trait_data_and_analysis.js | 9 +- 10 files changed, 160 insertions(+), 115 deletions(-) delete mode 100644 misc/byobu_commands.txt delete mode 100644 misc/find.txt create mode 100644 misc/notes.txt delete mode 100644 misc/python_stuff.txt delete mode 100644 misc/runserver.txt delete mode 100644 misc/virtual_env.txt diff --git a/misc/byobu_commands.txt b/misc/byobu_commands.txt deleted file mode 100644 index 48e85396..00000000 --- a/misc/byobu_commands.txt +++ /dev/null @@ -1,6 +0,0 @@ -byobu -RD -control-a then :multiuser on -control-a then :acladd sam - -type: screen -list for sessions -screen -r zas1024/25679.byobu diff --git a/misc/find.txt b/misc/find.txt deleted file mode 100644 index 5c792d80..00000000 --- a/misc/find.txt +++ /dev/null @@ -1 +0,0 @@ -find | grep _____ diff --git a/misc/notes.txt b/misc/notes.txt new file mode 100644 index 00000000..be023c1d --- /dev/null +++ b/misc/notes.txt @@ -0,0 +1,41 @@ +To get server running: + +Start up virtual environment: +source ~/ve27/bin/activate + +To set WQFLASK_SETTINGS environment variable: +export WQFLASK_SETTINGS=~/gene/wqflask/cfg/zach_settings.py (or wherever file is located) + +To search for commands in history if necessary: +history | grep "(whatever is being searched for)" + +Run server: +python runserver.py + +=========================================== + +Start screen session +byobu -RD (to start) +control-a then :multiuser on +control-a then :acladd sam + +type: screen -list for sessions +screen -r zas1024/25679.byobu + +or if only one: + +screen -r zas1024/ + +=========================================== + +Coffeescript Stuff: + +coffee -c (filename) +coffee -c -w (to watch for changes and recompile) +coffee --help (for information about setting options) + +=========================================== + +Python stuff: + +Classes should always inherit "object" \ No newline at end of file diff --git a/misc/python_stuff.txt b/misc/python_stuff.txt deleted file mode 100644 index f36fe338..00000000 --- a/misc/python_stuff.txt +++ /dev/null @@ -1 +0,0 @@ -Classes should always inherit "object" \ No newline at end of file diff --git a/misc/runserver.txt b/misc/runserver.txt deleted file mode 100644 index 71e3dfd7..00000000 --- a/misc/runserver.txt +++ /dev/null @@ -1 +0,0 @@ -python runserver.py diff --git a/misc/virtual_env.txt b/misc/virtual_env.txt deleted file mode 100644 index 7a8f20be..00000000 --- a/misc/virtual_env.txt +++ /dev/null @@ -1 +0,0 @@ -source ~/ve27/bin/activate diff --git a/wqflask/base/webqtlFormData.py b/wqflask/base/webqtlFormData.py index a9e3b7d4..177c72a2 100755 --- a/wqflask/base/webqtlFormData.py +++ b/wqflask/base/webqtlFormData.py @@ -60,17 +60,12 @@ class webqtlFormData: print("in webqtlFormData start_vars are:", pf(start_vars)) for item in webqtlFormData.attrs: self.__dict__[item] = None - #self.__dict__.update(start_vars) + for item in start_vars: self.__dict__[item] = start_vars[item] - print(" Now self.dict is:", pf(self.__dict__)) - #for item in self.attrs: - # if getattr(self, item, None): - # print("Setting item %s to None" % (item,)) - # self.attrs[item] = None - # else: - # self.attrs[item] = self.attrs[item].strip() + #print(" Now self.dict is:", pf(self.__dict__)) + #Todo: This can't be good below...rework try: self.remote_ip = req.connection.remote_ip except: @@ -151,23 +146,32 @@ class webqtlFormData: def readGenotype(self): - 'read genotype from .geno file' + '''read genotype from .geno file''' if self.RISet == 'BXD300': self.RISet = 'BXD' - else: - pass - assert self.RISet + + assert self.RISet, "self.RISet needs to be set" + #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')) + + full_filename = os.path.join(webqtlConfig.GENODIR, self.RISet + '.geno') + + # reaper barfs on unicode filenames, so here we ensure it's a string + full_filename = str(full_filename) + self.genotype_1.read(full_filename) + + print("Got to after read") + try: # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.RISet] - except: + except KeyError: _f1 = _f12 = _mat = _pat = None - self.genotype_2 =self.genotype_1 + 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) @@ -177,78 +181,83 @@ class webqtlFormData: else: self.incparentsf1 = 0 self.genotype = self.genotype_1 + self.strainlist = list(self.genotype.prgy) - self.f1list = self.parlist = [] + 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' + def readData(self, strainlist, incf1=None): + '''read user input data or from trait data and analysis form''' + + if incf1 == None: + incf1 = [] if not self.genotype: self.readGenotype() - if not strainlst: + if not strainlist: if incf1: - strainlst = self.f1list + self.strainlist + strainlist = self.f1list + self.strainlist else: - strainlst = self.strainlist + strainlist = self.strainlist + #print("before traitfiledata self.traitfile is:", pf(self.traitfile)) - 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') + traitfiledata = getattr(self, "traitfile", None) + traitpastedata = getattr(self, "traitpaste", None) + variancefiledata = getattr(self, "variancefile", None) + variancepastedata = getattr(self, "variancepaste", None) + Nfiledata = getattr(self, "Nfile", None) + #### Todo: Rewrite below when we get to someone submitting their own trait ##### if traitfiledata: - tt = string.split(traitfiledata) - vals = map(webqtlUtil.StringAsFloat, tt) + tt = traitfiledata.split() + values = map(webqtlUtil.StringAsFloat, tt) elif traitpastedata: - tt = string.split(traitpastedata) - vals = map(webqtlUtil.StringAsFloat, tt) + tt = traitpastedata.split() + values = 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 + values = map(self.FormDataAsFloat, strainlist) + if len(values) < len(strainlist): + values += [None] * (len(strainlist) - len(values)) + elif len(values) > len(strainlist): + values = values[:len(strainlist)] + if variancefiledata: - tt = string.split(variancefiledata) - vars = map(webqtlUtil.StringAsFloat, tt) + tt = variancefiledata.split() + variances = map(webqtlUtil.StringAsFloat, tt) elif variancepastedata: - tt = string.split(variancepastedata) - vars = map(webqtlUtil.StringAsFloat, tt) + tt = variancepastedata.split() + variances = map(webqtlUtil.StringAsFloat, tt) else: - vars = map(self.FormVarianceAsFloat, strainlst) + variances = map(self.FormVarianceAsFloat, strainlist) - if len(vars) < len(strainlst): - vars += [None]*(len(strainlst) - len(vars)) - elif len(vars) > len(strainlst): - vars = vars[:len(strainlst)] - else: - pass + if len(variances) < len(strainlist): + variances += [None]*(len(strainlist) - len(variances)) + elif len(variances) > len(strainlist): + variances = variances[:len(strainlist)] if Nfiledata: tt = string.split(Nfiledata) nstrains = map(webqtlUtil.IntAsFloat, tt) - if len(nstrains) < len(strainlst): - nstrains += [None]*(len(strainlst) - len(nstrains)) + if len(nstrains) < len(strainlist): + nstrains += [None]*(len(strainlist) - len(nstrains)) else: - nstrains = map(self.FormNAsFloat, strainlst) + nstrains = map(self.FormNAsFloat, strainlist) - ##vals, vars, nstrains is obsolete + ##values, variances, 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]) + for i, _strain in enumerate(strainlist): + if values[i] != None: + self.allTraitData[_strain] = webqtlCaseData(values[i], variances[i], nstrains[i]) diff --git a/wqflask/wqflask/correlation/CorrelationPage.py b/wqflask/wqflask/correlation/CorrelationPage.py index 9caf6595..62e4c4ab 100644 --- a/wqflask/wqflask/correlation/CorrelationPage.py +++ b/wqflask/wqflask/correlation/CorrelationPage.py @@ -177,42 +177,37 @@ def get_custom_trait(form_data, cursor): #XZ, 09/18/2008: get the information such as value, variance of the input strain names from the form. -def get_sample_data(form_data): - if form_data.allstrainlist: - mdpchoice = form_data.formdata.getvalue('MDPChoice') - #XZ, in HTML source code, it is "BXD Only" or "BXH only", and so on +def get_sample_data(fd): + print("fd is:", pf(fd.__dict__)) + if fd.allstrainlist: + mdpchoice = fd.MDPChoice + #XZ, in HTML source code, it is "BXD Only", "BXH Only", and so on if mdpchoice == "1": - strainlist = form_data.f1list + form_data.strainlist - #XZ, in HTML source code, it is "MDP Only" + strainlist = fd.f1list + fd.strainlist + #XZ, in HTML source code, it is "Non-BXD Only", "Non-BXD Only", etc elif mdpchoice == "2": strainlist = [] - strainlist2 = form_data.f1list + form_data.strainlist - for strain in form_data.allstrainlist: + strainlist2 = fd.f1list + fd.strainlist + for strain in fd.allstrainlist: if strain not in strainlist2: strainlist.append(strain) #So called MDP Panel if strainlist: - strainlist = form_data.f1list+form_data.parlist+strainlist + strainlist = fd.f1list + fd.parlist+strainlist #XZ, in HTML source code, it is "All Cases" else: - strainlist = form_data.allstrainlist - #XZ, 09/18/2008: put the trait data into dictionary form_data.allTraitData - form_data.readData(form_data.allstrainlist) + strainlist = fd.allstrainlist + #XZ, 09/18/2008: put the trait data into dictionary fd.allTraitData + fd.readData(fd.allstrainlist) else: mdpchoice = None - strainlist = form_data.strainlist - #XZ, 09/18/2008: put the trait data into dictionary form_data.allTraitData - form_data.readData() + strainlist = fd.strainlist + #XZ, 09/18/2008: put the trait data into dictionary fd.allTraitData + fd.readData() return strainlist -def get_mdp_choice(form_data): - if form_data.allstrainlist: - return form_data.formdata.getvalue("MDPChoice") - else: - return None - def get_species(fd, cursor): #XZ, 3/16/2010: variable RISet must be pass by the form @@ -277,7 +272,7 @@ class CorrelationPage(templatePage): RANK_ORDERS = {"1": 0, "2": 1, "3": 0, "4": 0, "5": 1} - def error(self, message, error="Error", heading = None): + def error(self, message, *args, **kw): heading = heading or self.PAGE_HEADING return templatePage.error(heading = heading, detail = [message], error=error) @@ -295,23 +290,30 @@ class CorrelationPage(templatePage): fd.readGenotype() sample_list = get_sample_data(fd) - mdp_choice = get_mdp_choice(fd) # No idea what this is yet + + # Whether the user chose BXD Only, Non-BXD Only, or All Strains + # (replace BXD with whatever the group/inbredset name is) + # "mdp" stands for "mouse diversity panel" This is outdated; it now represents any + # cases/strains from the non-primary group + mdp_choice = fd.MDPChoice if fd.allstrainlist else None + self.species = get_species(fd, self.cursor) #XZ, 09/18/2008: get all information about the user selected database. - target_db_name = fd.formdata.getvalue('database') - self.target_db_name = target_db_name + #target_db_name = fd.corr_dataset + self.target_db_name = fd.corr_dataset - try: - self.db = webqtlDataset(target_db_name, self.cursor) - except: - detail = ["The database you just requested has not been established yet."] - self.error(detail) - return + #try: + #print("target_db_name is:", target_db_name) + self.db = webqtlDataset(self.target_db_name, self.cursor) + #except: + # detail = ["The database you just requested has not been established yet."] + # self.error(detail) + # return # Auth if needed try: - auth_user_for_db(self.db, self.cursor, target_db_name, self.privilege, self.userName) + auth_user_for_db(self.db, self.cursor, self.target_db_name, self.privilege, self.userName) except AuthException, e: detail = [e.message] return self.error(detail) @@ -322,7 +324,7 @@ class CorrelationPage(templatePage): #CF - If less than a minimum number of strains/cases in common, don't calculate anything if len(self.sample_names) < self.corrMinInformative: detail = ['Fewer than %d strain data were entered for %s data set. No calculation of correlation has been attempted.' % (self.corrMinInformative, fd.RISet)] - self.error(heading=PAGE_HEADING,detail=detail) + self.error(heading=None, detail=detail) self.method = get_correlation_method_key(fd) @@ -330,15 +332,16 @@ class CorrelationPage(templatePage): rankOrder = self.RANK_ORDERS[self.method] # CF - Number of results returned - self.returnNumber = int(fd.formdata.getvalue('criteria')) + self.returnNumber = int(fd.criteria) self.record_count = 0 myTrait = get_custom_trait(fd, self.cursor) - # We will not get Literature Correlations if there is no GeneId because there is nothing to look against - self.gene_id = int(fd.formdata.getvalue('GeneId') or 0) + # We will not get Literature Correlations if there is no GeneId because there is nothing + # to look against + self.gene_id = int(fd.GeneId) # We will not get Tissue Correlations if there is no gene symbol because there is nothing to look against self.trait_symbol = myTrait.symbol @@ -359,7 +362,8 @@ class CorrelationPage(templatePage): TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') mainfmName = webqtlUtil.genRandStr("fm_") - form = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name= mainfmName, submit=HT.Input(type='hidden')) + form = HT.Form(cgi = os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), + enctype='multipart/form-data', name= mainfmName, submit=HT.Input(type='hidden')) hddn = {'FormID': 'showDatabase', 'ProbeSetID': '_', 'database': self.target_db_name, @@ -369,9 +373,9 @@ class CorrelationPage(templatePage): 'identification': fd.identification} if myTrait: - hddn['fullname']=fd.formdata.getvalue('fullname') + hddn['fullname'] = fd.fullname if mdp_choice: - hddn['MDPChoice']=mdp_choice + hddn['MDPChoice']= mdp_choice #XZ, 09/18/2008: pass the trait data to next page by hidden parameters. diff --git a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee index 3ea90b9c..7bfa6d01 100644 --- a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee +++ b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee @@ -170,10 +170,14 @@ $ -> console.log("in beginning of on_corr_submit") values = $('#trait_data_form').serialize() console.log("in on_corr_submit, values are:", values) - $.ajax "/corr_compute", - type: 'GET' - dataType: 'html' - data: values + + params = $.param(values) + window.location.href = "/corr_compute?" + params + + #$.ajax "/corr_compute", + # type: 'GET' + # dataType: 'html' + # data: values $('#corr_compute').click(on_corr_submit) diff --git a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js index 0de0297b..e1f870d9 100644 --- a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js +++ b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js @@ -200,15 +200,12 @@ }; $('select[name=corr_method]').change(on_corr_method_change); on_corr_submit = function() { - var values; + var params, values; console.log("in beginning of on_corr_submit"); values = $('#trait_data_form').serialize(); console.log("in on_corr_submit, values are:", values); - return $.ajax("/corr_compute", { - type: 'GET', - dataType: 'html', - data: values - }); + params = $.param(values); + return window.location.href = "/corr_compute?" + params; }; $('#corr_compute').click(on_corr_submit); /* -- cgit v1.2.3