diff options
author | Sam Ockman | 2012-06-05 00:24:44 -0400 |
---|---|---|
committer | Sam Ockman | 2012-06-05 00:24:44 -0400 |
commit | 8ac39ead1014953c634e85d0ce340497ecfe2934 (patch) | |
tree | f69bef8650f64bdfa5093c39fe7dc6a8b5ffac82 /wqflask/utility/AJAX_table.py | |
parent | 8abd879e71f492ce61e0b8d3eab53fcb43c34681 (diff) | |
download | genenetwork2-8ac39ead1014953c634e85d0ce340497ecfe2934.tar.gz |
Ran reindent.py recursively on wqflask directory
Diffstat (limited to 'wqflask/utility/AJAX_table.py')
-rwxr-xr-x | wqflask/utility/AJAX_table.py | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/wqflask/utility/AJAX_table.py b/wqflask/utility/AJAX_table.py index 963a530e..083d1c0d 100755 --- a/wqflask/utility/AJAX_table.py +++ b/wqflask/utility/AJAX_table.py @@ -39,115 +39,115 @@ import webqtlUtil class AJAX_table: - def __init__(self, fd): - file = fd.formdata.getfirst("file", "") - sort = fd.formdata.getfirst("sort", "") - order = fd.formdata.getfirst("order", "up") - cmd = fd.formdata.getfirst("cmd", "") - tableID = fd.formdata.getfirst("tableID", "") - addIndex = fd.formdata.getfirst("addIndex", "1") - hiddenColumnsString = fd.formdata.getfirst("hiddenColumns", "") - hiddenColumns = hiddenColumnsString.split(',') - - try: - fp = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'rb') - tblobj = cPickle.load(fp) - fp.close() - - if cmd == 'addCorr': - dbId = int(fd.formdata.getfirst("db")) - dbFullName = fd.formdata.getfirst("dbname") - trait = fd.formdata.getfirst("trait") - form = fd.formdata.getfirst("form") - ids = fd.formdata.getfirst("ids") - vals = fd.formdata.getfirst("vals") - ids = eval(ids) - nnCorr = len(ids) - vals = eval(vals) - - workbook = xl.Writer('%s.xls' % (webqtlConfig.TMPDIR+file)) - worksheet = workbook.add_worksheet() - - con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) - cursor = con.cursor() - - cursor.execute("Select name, ShortName from ProbeSetFreeze where Id = %s", dbId) - dbName, dbShortName = cursor.fetchone() - - tblobj['header'][0].append( - THCell(HT.TD(dbShortName, Class="fs11 ffl b1 cw cbrb"), - text="%s" % dbShortName, idx=tblobj['header'][0][-1].idx + 1), - ) - - headingStyle = workbook.add_format(align = 'center', bold = 1, border = 1, size=13, fg_color = 0x1E, color="white") - for i, item in enumerate(tblobj['header'][0]): - if (i > 0): - worksheet.write([8, i-1], item.text, headingStyle) - worksheet.set_column([i-1, i-1], 2*len(item.text)) - - for i, row in enumerate(tblobj['body']): - ProbeSetId = row[1].text - #XZ, 03/02/2009: Xiaodong changed Data to ProbeSetData - cursor.execute(""" - Select ProbeSetData.StrainId, ProbeSetData.Value - From ProbeSetData, ProbeSetXRef, ProbeSet - where ProbeSetXRef.ProbeSetFreezeId = %d AND - ProbeSetXRef.DataId = ProbeSetData.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSet.Name = '%s' - """ % (dbId, ProbeSetId)) - results = cursor.fetchall() - vdict = {} - for item in results: - vdict[item[0]] = item[1] - newvals = [] - for id in ids: - if vdict.has_key(id): - newvals.append(vdict[id]) - else: - newvals.append(None) - corr,nOverlap= webqtlUtil.calCorrelation(newvals,vals,nnCorr) - repr = '%0.4f' % corr - row.append( - TDCell(HT.TD(HT.Href(text=repr, url="javascript:showCorrPlotThird('%s', '%s', '%s')" % (form, dbName, ProbeSetId), Class="fs11 fwn ffl"), " / ", nOverlap, Class="fs11 fwn ffl b1 c222", align="middle"),repr,abs(corr)) - ) - - last_row=0 - for j, item in enumerate(tblobj['body'][i]): - if (j > 0): - worksheet.write([9+i, j-1], item.text) - last_row = 9+i - last_row += 1 - - titleStyle = workbook.add_format(align = 'left', bold = 0, size=14, border = 1, border_color="gray") - ##Write title Info - # Modified by Hongqiang Li - worksheet.write([0, 0], "Citations: Please see %s/reference.html" % webqtlConfig.PORTADDR, titleStyle) - worksheet.write([1, 0], "Trait : %s" % trait, titleStyle) - worksheet.write([2, 0], "Database : %s" % dbFullName, titleStyle) - worksheet.write([3, 0], "Date : %s" % time.strftime("%B %d, %Y", time.gmtime()), titleStyle) - worksheet.write([4, 0], "Time : %s GMT" % time.strftime("%H:%M ", time.gmtime()), titleStyle) - worksheet.write([5, 0], "Status of data ownership: Possibly unpublished data; please see %s/statusandContact.html for details on sources, ownership, and usage of these data." % webqtlConfig.PORTADDR, titleStyle) - #Write footer info - worksheet.write([1 + last_row, 0], "Funding for The GeneNetwork: NIAAA (U01AA13499, U24AA13513), NIDA, NIMH, and NIAAA (P20-DA21131), NCI MMHCC (U01CA105417), and NCRR (U01NR 105417)", titleStyle) - worksheet.write([2 + last_row, 0], "PLEASE RETAIN DATA SOURCE INFORMATION WHENEVER POSSIBLE", titleStyle) - - cursor.close() - workbook.close() - - objfile = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'wb') - cPickle.dump(tblobj, objfile) - objfile.close() - else: - pass - - self.value = str(webqtlUtil.genTableObj(tblobj=tblobj, file=file, sortby=(sort, order), tableID = tableID, addIndex = addIndex, hiddenColumns = hiddenColumns)) - - except: - self.value = "<span class='fs16 fwb cr ffl'>The table is no longer available on this server</span>" - - def __str__(self): - return self.value - - def write(self): - return str(self) + def __init__(self, fd): + file = fd.formdata.getfirst("file", "") + sort = fd.formdata.getfirst("sort", "") + order = fd.formdata.getfirst("order", "up") + cmd = fd.formdata.getfirst("cmd", "") + tableID = fd.formdata.getfirst("tableID", "") + addIndex = fd.formdata.getfirst("addIndex", "1") + hiddenColumnsString = fd.formdata.getfirst("hiddenColumns", "") + hiddenColumns = hiddenColumnsString.split(',') + + try: + fp = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'rb') + tblobj = cPickle.load(fp) + fp.close() + + if cmd == 'addCorr': + dbId = int(fd.formdata.getfirst("db")) + dbFullName = fd.formdata.getfirst("dbname") + trait = fd.formdata.getfirst("trait") + form = fd.formdata.getfirst("form") + ids = fd.formdata.getfirst("ids") + vals = fd.formdata.getfirst("vals") + ids = eval(ids) + nnCorr = len(ids) + vals = eval(vals) + + workbook = xl.Writer('%s.xls' % (webqtlConfig.TMPDIR+file)) + worksheet = workbook.add_worksheet() + + con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD) + cursor = con.cursor() + + cursor.execute("Select name, ShortName from ProbeSetFreeze where Id = %s", dbId) + dbName, dbShortName = cursor.fetchone() + + tblobj['header'][0].append( + THCell(HT.TD(dbShortName, Class="fs11 ffl b1 cw cbrb"), + text="%s" % dbShortName, idx=tblobj['header'][0][-1].idx + 1), + ) + + headingStyle = workbook.add_format(align = 'center', bold = 1, border = 1, size=13, fg_color = 0x1E, color="white") + for i, item in enumerate(tblobj['header'][0]): + if (i > 0): + worksheet.write([8, i-1], item.text, headingStyle) + worksheet.set_column([i-1, i-1], 2*len(item.text)) + + for i, row in enumerate(tblobj['body']): + ProbeSetId = row[1].text + #XZ, 03/02/2009: Xiaodong changed Data to ProbeSetData + cursor.execute(""" + Select ProbeSetData.StrainId, ProbeSetData.Value + From ProbeSetData, ProbeSetXRef, ProbeSet + where ProbeSetXRef.ProbeSetFreezeId = %d AND + ProbeSetXRef.DataId = ProbeSetData.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSet.Name = '%s' + """ % (dbId, ProbeSetId)) + results = cursor.fetchall() + vdict = {} + for item in results: + vdict[item[0]] = item[1] + newvals = [] + for id in ids: + if vdict.has_key(id): + newvals.append(vdict[id]) + else: + newvals.append(None) + corr,nOverlap= webqtlUtil.calCorrelation(newvals,vals,nnCorr) + repr = '%0.4f' % corr + row.append( + TDCell(HT.TD(HT.Href(text=repr, url="javascript:showCorrPlotThird('%s', '%s', '%s')" % (form, dbName, ProbeSetId), Class="fs11 fwn ffl"), " / ", nOverlap, Class="fs11 fwn ffl b1 c222", align="middle"),repr,abs(corr)) + ) + + last_row=0 + for j, item in enumerate(tblobj['body'][i]): + if (j > 0): + worksheet.write([9+i, j-1], item.text) + last_row = 9+i + last_row += 1 + + titleStyle = workbook.add_format(align = 'left', bold = 0, size=14, border = 1, border_color="gray") + ##Write title Info + # Modified by Hongqiang Li + worksheet.write([0, 0], "Citations: Please see %s/reference.html" % webqtlConfig.PORTADDR, titleStyle) + worksheet.write([1, 0], "Trait : %s" % trait, titleStyle) + worksheet.write([2, 0], "Database : %s" % dbFullName, titleStyle) + worksheet.write([3, 0], "Date : %s" % time.strftime("%B %d, %Y", time.gmtime()), titleStyle) + worksheet.write([4, 0], "Time : %s GMT" % time.strftime("%H:%M ", time.gmtime()), titleStyle) + worksheet.write([5, 0], "Status of data ownership: Possibly unpublished data; please see %s/statusandContact.html for details on sources, ownership, and usage of these data." % webqtlConfig.PORTADDR, titleStyle) + #Write footer info + worksheet.write([1 + last_row, 0], "Funding for The GeneNetwork: NIAAA (U01AA13499, U24AA13513), NIDA, NIMH, and NIAAA (P20-DA21131), NCI MMHCC (U01CA105417), and NCRR (U01NR 105417)", titleStyle) + worksheet.write([2 + last_row, 0], "PLEASE RETAIN DATA SOURCE INFORMATION WHENEVER POSSIBLE", titleStyle) + + cursor.close() + workbook.close() + + objfile = open(os.path.join(webqtlConfig.TMPDIR, file + '.obj'), 'wb') + cPickle.dump(tblobj, objfile) + objfile.close() + else: + pass + + self.value = str(webqtlUtil.genTableObj(tblobj=tblobj, file=file, sortby=(sort, order), tableID = tableID, addIndex = addIndex, hiddenColumns = hiddenColumns)) + + except: + self.value = "<span class='fs16 fwb cr ffl'>The table is no longer available on this server</span>" + + def __str__(self): + return self.value + + def write(self): + return str(self) |