diff options
author | zsloan | 2020-08-25 15:53:29 -0500 |
---|---|---|
committer | GitHub | 2020-08-25 15:53:29 -0500 |
commit | 726179fc7f772246c4017fde4526f46bd1125270 (patch) | |
tree | fc311c5df3caf3e57c150e04fe8fddbbec4e2e89 /wqflask | |
parent | 82d169adce491011ae65839515cfb6b5400155fe (diff) | |
parent | d18f24281a30759f4fbafe3e50d383438f38e2de (diff) | |
download | genenetwork2-726179fc7f772246c4017fde4526f46bd1125270.tar.gz |
Merge pull request #425 from BonfaceKilz/refactor/extract-htmlgen-methods-to-wrapper-class
Refactor/extract htmlgen methods to wrapper class
Diffstat (limited to 'wqflask')
5 files changed, 364 insertions, 93 deletions
diff --git a/wqflask/tests/wqflask/api/test_gen_menu.py b/wqflask/tests/wqflask/api/test_gen_menu.py index 79c77fec..239484aa 100644 --- a/wqflask/tests/wqflask/api/test_gen_menu.py +++ b/wqflask/tests/wqflask/api/test_gen_menu.py @@ -255,9 +255,9 @@ class TestGenMenu(unittest.TestCase): ('Mouse Tissue'), ('Human Tissue'), ('Rat Tissue') ) self.assertEqual(build_types('mouse', 'random group'), - [['M', 'M', 'Molecular Trait Datasets'], - ['H', 'H', 'Molecular Trait Datasets'], - ['R', 'R', 'Molecular Trait Datasets']]) + [['M', 'M', 'Molecular Traits'], + ['H', 'H', 'Molecular Traits'], + ['R', 'R', 'Molecular Traits']]) db_mock.db.execute.assert_called_once_with( "SELECT DISTINCT Tissue.Name " + "FROM ProbeFreeze, ProbeSetFreeze, InbredSet, " + diff --git a/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py b/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py new file mode 100644 index 00000000..6f791df1 --- /dev/null +++ b/wqflask/tests/wqflask/marker_regression/test_display_mapping_results.py @@ -0,0 +1,151 @@ +import unittest + +from htmlgen import HTMLgen2 as HT +from wqflask.marker_regression.display_mapping_results import ( + DisplayMappingResults, + HtmlGenWrapper +) + + +class TestDisplayMappingResults(unittest.TestCase): + """Basic Methods to test Mapping Results""" + def test_pil_colors(self): + """Test that colors use PILLOW color format""" + self.assertEqual(DisplayMappingResults.CLICKABLE_WEBQTL_REGION_COLOR, + (245, 211, 211)) + + +class TestHtmlGenWrapper(unittest.TestCase): + """Test Wrapper around HTMLGen""" + def test_create_image(self): + """Test HT.Image method""" + self.assertEqual( + str(HtmlGenWrapper.create_image_tag(src="test.png", + alt="random", + border="0", + width="10", + height="13", + usemap="#webqtlmap")), + ("""<IMG src="test.png" height="13" width="10" """ + """alt="random" border="0" """ + """usemap="#webqtlmap">""") + ) + + def test_create_form(self): + """Test HT.Form method""" + test_form = HtmlGenWrapper.create_form_tag( + cgi="/testing/", + enctype='multipart/form-data', + name="formName", + submit=HT.Input(type='hidden') + ) + test_image = HtmlGenWrapper.create_image_tag( + src="test.png", + alt="random", + border="0", + width="10", + height="13", + usemap="#webqtlmap" + ) + self.assertEqual( + str(test_form).replace("\n", ""), + ("""<FORM METHOD="POST" ACTION="/testing/" """ + """ENCTYPE="multipart/form-data" """ + """NAME="formName"><INPUT TYPE="hidden" """ + """NAME="Default_Name"></FORM>""")) + hddn = { + 'FormID': 'showDatabase', + 'ProbeSetID': '_', + 'database': "TestGeno", + 'CellID': '_', + 'RISet': "Test", + 'incparentsf1': 'ON' + } + for key in hddn.keys(): + test_form.append(HT.Input(name=key, value=hddn[key], + type='hidden')) + test_form.append(test_image) + self.assertEqual(str(test_form).replace("\n", ""), ( + """<FORM METHOD="POST" ACTION="/testing/" """ + """ENCTYPE="multipart/form-data" NAME="formName">""" + """<INPUT TYPE="hidden" NAME="database" VALUE="TestGeno">""" + """<INPUT TYPE="hidden" NAME="incparentsf1" VALUE="ON">""" + """<INPUT TYPE="hidden" NAME="FormID" VALUE="showDatabase">""" + """<INPUT TYPE="hidden" NAME="ProbeSetID" VALUE="_">""" + """<INPUT TYPE="hidden" NAME="RISet" VALUE="Test">""" + """<INPUT TYPE="hidden" NAME="CellID" VALUE="_">""" + """<IMG src="test.png" height="13" width="10" alt="random" """ + """border="0" usemap="#webqtlmap">""" + """<INPUT TYPE="hidden" NAME="Default_Name"></FORM>""")) + + def test_create_paragraph(self): + """Test HT.Paragraph method""" + test_p_element = HtmlGenWrapper.create_p_tag(id="smallSize") + par_text = ( + "Mapping using genotype data as " + "a trait will result in infinity LRS at one locus. " + "In order to display the result properly, all LRSs " + "higher than 100 are capped at 100." + ) + self.assertEqual( + str(test_p_element), + """<P id="smallSize"></P>""" + ) + test_p_element.append(HT.BR()) + test_p_element.append(par_text) + self.assertEqual( + str(test_p_element), + """<P id="smallSize"><BR>{}</P>""".format(par_text) + ) + + def test_create_br_tag(self): + """Test HT.BR() method""" + self.assertEqual(str(HtmlGenWrapper.create_br_tag()), + "<BR>") + + def test_create_input_tag(self): + """Test HT.Input method""" + self.assertEqual( + str(HtmlGenWrapper.create_input_tag( + type="hidden", + name="name", + value="key", + Class="trait trait_")).replace("\n", ""), + ("""<INPUT TYPE="hidden" NAME="name" """ + """class="trait trait_" VALUE="key">""")) + + def test_create_map_tag(self): + """Test HT.Map method""" + self.assertEqual(str(HtmlGenWrapper.create_map_tag( + name="WebqTLImageMap")).replace("\n", ""), + """<MAP NAME="WebqTLImageMap"></MAP>""") + gifmap = HtmlGenWrapper.create_map_tag(areas=[]) + gifmap.areas.append(HT.Area(shape="rect", + coords='1 2 3', href='#area1')) + gifmap.areas.append(HT.Area(shape="rect", + coords='1 2 3', href='#area2')) + self.assertEqual( + str(gifmap).replace("\n", ""), + ("""<MAP NAME="">""" + """<AREA coords="1 2 3" """ + """href="#area1" shape="rect">""" + """<AREA coords="1 2 3" href="#area2" shape="rect">""" + """</MAP>""")) + + def test_create_area_tag(self): + """Test HT.Area method""" + self.assertEqual( + str(HtmlGenWrapper.create_area_tag( + shape="rect", + coords="1 2", + href="http://test.com", + title="Some Title")).replace("\n", ""), + ("""<AREA coords="1 2" href="http://test.com" """ + """shape="rect" title="Some Title">""")) + + def test_create_link_tag(self): + """Test HT.HREF method""" + self.assertEqual( + str(HtmlGenWrapper.create_link_tag( + "www.test.com", "test", target="_blank")).replace("\n", ""), + """<A HREF="www.test.com" TARGET="_blank">test</A>""") diff --git a/wqflask/tests/wqflask/marker_regression/test_display_marking_results.py b/wqflask/tests/wqflask/marker_regression/test_display_marking_results.py deleted file mode 100644 index 67da508b..00000000 --- a/wqflask/tests/wqflask/marker_regression/test_display_marking_results.py +++ /dev/null @@ -1,9 +0,0 @@ -import unittest - -from wqflask.marker_regression.display_mapping_results import DisplayMappingResults - -class TestDisplayMappingResults(unittest.TestCase): - def test_pil_colors(self): - """Test that colors use PILLOW color format""" - self.assertEqual(DisplayMappingResults.CLICKABLE_WEBQTL_REGION_COLOR, - (245, 211, 211)) diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py index d4373412..b9b71129 100644 --- a/wqflask/utility/Plot.py +++ b/wqflask/utility/Plot.py @@ -26,16 +26,12 @@ from __future__ import print_function -from PIL import (Image, ImageColor, ImageDraw, ImageFont) -from pprint import pformat as pf +from PIL import ImageColor +from PIL import ImageDraw +from PIL import ImageFont from math import * -import random -import sys, os -from numarray import linear_algebra as la -from numarray import ones, array, dot, swapaxes -import webqtlUtil import corestats from base import webqtlConfig from utility.pillow_utils import draw_rotated_text diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 3943a401..a92adb90 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -24,13 +24,13 @@ # # Last updated by Zach 12/14/2010 -import datetime import string from math import * -from PIL import (Image,ImageDraw,ImageFont,ImageColor) -import sys,os -import cPickle -import httplib +from PIL import Image +from PIL import ImageDraw +from PIL import ImageFont +from PIL import ImageColor +import os import json from flask import Flask, g @@ -40,15 +40,14 @@ from htmlgen import HTMLgen2 as HT from base import webqtlConfig from base.GeneralObject import GeneralObject from utility import webqtlUtil -from utility import helper_functions from utility import Plot from utility.benchmark import Bench from wqflask.interval_analyst import GeneUtil -from base.webqtlConfig import GENERATED_TEXT_DIR, GENERATED_IMAGE_DIR +from base.webqtlConfig import GENERATED_IMAGE_DIR from utility.pillow_utils import draw_rotated_text, draw_open_polygon import utility.logger -logger = utility.logger.getLogger(__name__ ) +logger = utility.logger.getLogger(__name__) RED = ImageColor.getrgb("red") BLUE = ImageColor.getrgb("blue") @@ -80,22 +79,53 @@ ARIAL_FILE = "./wqflask/static/fonts/arial.ttf" assert(os.path.isfile(VERDANA_FILE)) -# ---- END: FONT FILES ---- # -######################################### -# Inteval Mapping Plot Page -######################################### +class HtmlGenWrapper: + """Wrapper Methods for HTML gen""" + @staticmethod + def create_image_tag(**kwargs): + return HT.Image(**kwargs) + + @staticmethod + def create_form_tag(**kwargs): + return HT.Form(**kwargs) + + @staticmethod + def create_p_tag(**kwargs): + return HT.Paragraph(**kwargs) + + @staticmethod + def create_br_tag(): + return HT.BR() + + @staticmethod + def create_input_tag(**kwargs): + return HT.Input(**kwargs) + + @staticmethod + def create_area_tag(**kwargs): + return HT.Area(**kwargs) + + @staticmethod + def create_link_tag(href, content, **kwargs): + return HT.Href(href, content, **kwargs) + + @staticmethod + def create_map_tag(**kwargs): + return HT.Map(**kwargs) + + class DisplayMappingResults(object): + """Inteval Mapping Plot Page""" cMGraphInterval = 5 GRAPH_MIN_WIDTH = 900 - GRAPH_MAX_WIDTH = 10000 # Don't set this too high + GRAPH_MAX_WIDTH = 10000 # Don't set this too high GRAPH_DEFAULT_WIDTH = 1280 MULT_GRAPH_DEFAULT_WIDTH = 2000 MULT_GRAPH_MIN_WIDTH = 1400 MULT_GRAPH_DEFAULT_WIDTH = 1600 GRAPH_DEFAULT_HEIGHT = 600 - # Display order: # UCSC BAND ========= # ENSEMBL BAND -=-=-= @@ -106,22 +136,27 @@ class DisplayMappingResults(object): BAND_HEIGHT = 10 BAND_HEIGHT = 10 - NUM_GENE_ROWS = 10 - EACH_GENE_HEIGHT = 6 # number of pixels tall, for each gene to display + NUM_GENE_ROWS = 10 + EACH_GENE_HEIGHT = 6 # number of pixels tall, for each gene to display EACH_GENE_ARROW_WIDTH = 5 EACH_GENE_ARROW_SPACING = 14 DRAW_DETAIL_MB = 4 DRAW_UTR_LABELS_MB = 4 - qmarkImg = HT.Image('/images/qmarkBoxBlue.gif', width=10, height=13, border=0, alt='Glossary') - # Note that "qmark.gif" is a similar, smaller, rounded-edges question mark. It doesn't look - # like the ones on the image, though, which is why we don't use it here. + qmarkImg = HtmlGenWrapper.create_image_tag( + src='/images/qmarkBoxBlue.gif', + width="10", height="13", border="0", alt='Glossary' + ) + + # Note that "qmark.gif" is a similar, smaller, rounded-edges + # question mark. It doesn't look like the ones on the image, + # though, which is why we don't use it here. HELP_WINDOW_NAME = 'helpWind' - ## BEGIN HaplotypeAnalyst + # BEGIN HaplotypeAnalyst NR_INDIVIDUALS = 0 - ## END HaplotypeAnalyst + # END HaplotypeAnalyst ALEX_DEBUG_BOOL_PRINT_GENE_LIST = 1 @@ -129,13 +164,13 @@ class DisplayMappingResults(object): LODFACTOR = 4.61 - SNP_COLOR = ORANGE # Color for the SNP "seismograph" + SNP_COLOR = ORANGE # Color for the SNP "seismograph" TRANSCRIPT_LOCATION_COLOR = MEDIUMPURPLE BOOTSTRAP_BOX_COLOR = YELLOW - LRS_COLOR = ImageColor.getrgb("#0000FF") - SIGNIFICANT_COLOR = ImageColor.getrgb("#EBC7C7") - SUGGESTIVE_COLOR = GAINSBORO + LRS_COLOR = ImageColor.getrgb("#0000FF") + SIGNIFICANT_COLOR = ImageColor.getrgb("#EBC7C7") + SUGGESTIVE_COLOR = GAINSBORO SIGNIFICANT_WIDTH = 5 SUGGESTIVE_WIDTH = 5 ADDITIVE_COLOR_POSITIVE = GREEN @@ -143,33 +178,33 @@ class DisplayMappingResults(object): DOMINANCE_COLOR_POSITIVE = DARKVIOLET DOMINANCE_COLOR_NEGATIVE = RED - ## BEGIN HaplotypeAnalyst + # BEGIN HaplotypeAnalyst HAPLOTYPE_POSITIVE = GREEN HAPLOTYPE_NEGATIVE = RED HAPLOTYPE_HETEROZYGOUS = BLUE HAPLOTYPE_RECOMBINATION = DARKGRAY - ## END HaplotypeAnalyst + # END HaplotypeAnalyst TOP_RIGHT_INFO_COLOR = BLACK - CLICKABLE_WEBQTL_REGION_COLOR = ImageColor.getrgb("#F5D3D3") + CLICKABLE_WEBQTL_REGION_COLOR = ImageColor.getrgb("#F5D3D3") CLICKABLE_WEBQTL_REGION_OUTLINE_COLOR = ImageColor.getrgb("#FCE9E9") - CLICKABLE_WEBQTL_TEXT_COLOR = ImageColor.getrgb("#912828") + CLICKABLE_WEBQTL_TEXT_COLOR = ImageColor.getrgb("#912828") - CLICKABLE_PHENOGEN_REGION_COLOR = ImageColor.getrgb("#A2FB94") + CLICKABLE_PHENOGEN_REGION_COLOR = ImageColor.getrgb("#A2FB94") CLICKABLE_PHENOGEN_REGION_OUTLINE_COLOR = ImageColor.getrgb("#CEFEC7") - CLICKABLE_PHENOGEN_TEXT_COLOR = ImageColor.getrgb("#1FD504") + CLICKABLE_PHENOGEN_TEXT_COLOR = ImageColor.getrgb("#1FD504") - CLICKABLE_UCSC_REGION_COLOR = ImageColor.getrgb("#DDDDEE") + CLICKABLE_UCSC_REGION_COLOR = ImageColor.getrgb("#DDDDEE") CLICKABLE_UCSC_REGION_OUTLINE_COLOR = ImageColor.getrgb("#EDEDFF") - CLICKABLE_UCSC_TEXT_COLOR = ImageColor.getrgb("#333366") + CLICKABLE_UCSC_TEXT_COLOR = ImageColor.getrgb("#333366") - CLICKABLE_ENSEMBL_REGION_COLOR = ImageColor.getrgb("#EEEEDD") + CLICKABLE_ENSEMBL_REGION_COLOR = ImageColor.getrgb("#EEEEDD") CLICKABLE_ENSEMBL_REGION_OUTLINE_COLOR = ImageColor.getrgb("#FEFEEE") - CLICKABLE_ENSEMBL_TEXT_COLOR = ImageColor.getrgb("#555500") + CLICKABLE_ENSEMBL_TEXT_COLOR = ImageColor.getrgb("#555500") GRAPH_BACK_LIGHT_COLOR = ImageColor.getrgb("#FBFBFF") - GRAPH_BACK_DARK_COLOR = ImageColor.getrgb("#F1F1F9") + GRAPH_BACK_DARK_COLOR = ImageColor.getrgb("#F1F1F9") HELP_PAGE_REF = '/glossary.html' @@ -196,7 +231,8 @@ class DisplayMappingResults(object): self.temp_trait = "True" self.group = start_vars['group'] - #Needing for form submission when doing single chr mapping or remapping after changing options + # Needing for form submission when doing single chr + # mapping or remapping after changing options self.samples = start_vars['samples'] self.vals = start_vars['vals'] self.transform = start_vars['transform'] @@ -207,9 +243,9 @@ class DisplayMappingResults(object): self.mapmodel_rqtl_geno = start_vars['model'] self.pair_scan = start_vars['pair_scan'] - #if self.mapping_method != "gemma" and self.mapping_method != "plink": self.js_data = start_vars['js_data'] - self.trimmed_markers = start_vars['trimmed_markers'] #Top markers to display in table + # Top markers to display in table + self.trimmed_markers = start_vars['trimmed_markers'] if self.dataset.group.species == "rat": self._ucscDb = "rn6" @@ -221,7 +257,7 @@ class DisplayMappingResults(object): ##################################### # Options ##################################### - #Mapping options + # Mapping options if start_vars['mapping_scale'] != "": self.plotScale = start_vars['mapping_scale'] else: @@ -510,7 +546,11 @@ class DisplayMappingResults(object): "{}.png".format( os.path.join(webqtlConfig.GENERATED_IMAGE_DIR, self.filename)), format='png') - intImg=HT.Image('/image/'+self.filename+'.png', border=0, usemap='#WebQTLImageMap') + intImg = HtmlGenWrapper.create_image_tag( + src="/image/{}.png".format(self.filename), + border="0", usemap='#WebQTLImageMap' + ) + self.intImg = intImg #Scales plot differently for high resolution if self.draw2X: @@ -527,11 +567,16 @@ class DisplayMappingResults(object): ################################################################ #this form is used for opening Locus page or trait page, only available for genetic mapping if showLocusForm: - showLocusForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', - name=showLocusForm, submit=HT.Input(type='hidden')) + showLocusForm = HtmlGenWrapper.create_form_tag( + cgi=os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), + enctype='multipart/form-data', + name=showLocusForm, + submit=HtmlGenWrapper.create_input_tag(type='hidden')) + hddn = {'FormID':'showDatabase', 'ProbeSetID':'_','database':fd.RISet+"Geno",'CellID':'_', 'RISet':fd.RISet, 'incparentsf1':'ON'} for key in hddn.keys(): - showLocusForm.append(HT.Input(name=key, value=hddn[key], type='hidden')) + showLocusForm.append(HtmlGenWrapper.create_input_tag( + name=key, value=hddn[key], type='hidden')) showLocusForm.append(intImg) else: showLocusForm = intImg @@ -542,10 +587,12 @@ class DisplayMappingResults(object): ################################################################ # footnote goes here ################################################################ - btminfo = HT.Paragraph(Id="smallsize") #Small('More information about this graph is available here.') + # Small('More information about this graph is available here.') + btminfo = HtmlGenWrapper.create_p_tag(id="smallsize") if self.traitList and self.traitList[0].dataset and self.traitList[0].dataset.type == 'Geno': - btminfo.append(HT.BR(), 'Mapping using genotype data as a trait will result in infinity LRS at one locus. In order to display the result properly, all LRSs higher than 100 are capped at 100.') + btminfo.append(HtmlGenWrapper.create_br_tag()) + btminfo.append('Mapping using genotype data as a trait will result in infinity LRS at one locus. In order to display the result properly, all LRSs higher than 100 are capped at 100.') def plotIntMapping(self, canvas, offset= (80, 120, 20, 100), zoom = 1, startMb = None, endMb = None, showLocusForm = ""): im_drawer = ImageDraw.Draw(canvas) @@ -601,8 +648,8 @@ class DisplayMappingResults(object): if zoom == 2: drawAreaHeight -= 60 - #Image map - gifmap = HT.Map(name = "WebQTLImageMap") + # Image map + gifmap = HtmlGenWrapper.create_map_tag(name="WebQTLImageMap") newoffset = (xLeftOffset, xRightOffset, yTopOffset, yBottomOffset) # Draw the alternating-color background first and get plotXScale @@ -950,8 +997,8 @@ class DisplayMappingResults(object): if thisTrait.db: COORDS = "%d,%d,%d,%d" %(rectWidth+2+rightShift,yPaddingTop+kstep*15,rectWidth+2+rightShift+nameWidth,yPaddingTop+10+kstep*15,) HREF= "javascript:showDatabase3('%s','%s','%s','');" % (showLocusForm, thisTrait.db.name, thisTrait.name) - Areas = HT.Area(shape='rect',coords=COORDS,href=HREF) - gifmap.areas.append(Areas) + Areas = HtmlGenWrapper.create_area_tag(shape='rect',coords=COORDS,href=HREF) + gifmap.areas.append(Areas) ### TODO def drawLegendPanel(self, canvas, offset= (40, 120, 80, 10), zoom = 1): im_drawer = ImageDraw.Draw(canvas) @@ -1353,7 +1400,13 @@ class DisplayMappingResults(object): COORDS = "%d, %d, %d, %d" %(geneStartPix, geneYLocation, geneEndPix, (geneYLocation + self.EACH_GENE_HEIGHT)) # NL: 06-02-2011 Rob required to display NCBI info in a new window - gifmap.areas.append(HT.Area(shape='rect',coords=COORDS,href=HREF, title=TITLE,target="_blank")) + gifmap.areas.append( + HtmlGenWrapper.create_area_tag( + shape='rect', + coords=COORDS, + href=HREF, + title=TITLE, + target="_blank")) ## BEGIN HaplotypeAnalyst def drawHaplotypeBand(self, canvas, gifmap, plotXScale, offset= (40, 120, 80, 10), zoom = 1, startMb = None, endMb = None): @@ -1521,7 +1574,12 @@ class DisplayMappingResults(object): COORDS = "%d, %d, %d, %d" %(geneStartPix, geneYLocation+ind*self.EACH_GENE_HEIGHT, geneEndPix+1, (geneYLocation + ind*self.EACH_GENE_HEIGHT)) TITLE = "Strain: %s, marker (%s) \n Position %2.3f Mb." % (samplelist[k], _chr[j].name, float(txStart)) HREF = '' - gifmap.areas.append(HT.Area(shape='rect',coords=COORDS,href=HREF, title=TITLE)) + gifmap.areas.append( + HtmlGenWrapper.create_area_tag( + shape='rect', + coords=COORDS, + href=HREF, + title=TITLE)) # if there are no more markers in a chromosome, the plotRight value calculated above will be before the plotWidth # resulting in some empty space on the right side of the plot area. This draws an "unknown" bar from plotRight to the edge. @@ -1640,7 +1698,12 @@ class DisplayMappingResults(object): WEBQTL_HREF = "javascript:rangeView('%s', %f, %f)" % (self.selectedChr - 1, max(0, (calBase-webqtlZoomWidth))/1000000.0, (calBase+webqtlZoomWidth)/1000000.0) WEBQTL_TITLE = "Click to view this section of the genome in WebQTL" - gifmap.areas.append(HT.Area(shape='rect',coords=WEBQTL_COORDS,href=WEBQTL_HREF, title=WEBQTL_TITLE)) + gifmap.areas.append( + HtmlGenWrapper.create_area_tag( + shape='rect', + coords=WEBQTL_COORDS, + href=WEBQTL_HREF, + title=WEBQTL_TITLE)) im_drawer.rectangle( xy=((xBrowse1, paddingTop), (xBrowse2, (paddingTop + self.BAND_HEIGHT))), @@ -1657,7 +1720,12 @@ class DisplayMappingResults(object): else: PHENOGEN_HREF = "https://phenogen.org/gene.jsp?speciesCB=Mm&auto=Y&geneTxt=chr%s:%d-%d&genomeVer=mm10" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) PHENOGEN_TITLE = "Click to view this section of the genome in PhenoGen" - gifmap.areas.append(HT.Area(shape='rect',coords=PHENOGEN_COORDS,href=PHENOGEN_HREF, title=PHENOGEN_TITLE)) + gifmap.areas.append( + HtmlGenWrapper.create_area_tag( + shape='rect', + coords=PHENOGEN_COORDS, + href=PHENOGEN_HREF, + title=PHENOGEN_TITLE)) im_drawer.rectangle( xy=((xBrowse1, phenogenPaddingTop), (xBrowse2, (phenogenPaddingTop+self.BAND_HEIGHT))), @@ -1673,7 +1741,12 @@ class DisplayMappingResults(object): else: UCSC_HREF = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=%s&position=chr%s:%d-%d" % (self._ucscDb, self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) UCSC_TITLE = "Click to view this section of the genome in the UCSC Genome Browser" - gifmap.areas.append(HT.Area(shape='rect',coords=UCSC_COORDS,href=UCSC_HREF, title=UCSC_TITLE)) + gifmap.areas.append( + HtmlGenWrapper.create_area_tag( + shape='rect', + coords=UCSC_COORDS, + href=UCSC_HREF, + title=UCSC_TITLE)) im_drawer.rectangle( xy=((xBrowse1, ucscPaddingTop), (xBrowse2, (ucscPaddingTop+self.BAND_HEIGHT))), @@ -1690,7 +1763,11 @@ class DisplayMappingResults(object): else: ENSEMBL_HREF = "http://www.ensembl.org/Rattus_norvegicus/contigview?chr=%s&start=%d&end=%d" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) ENSEMBL_TITLE = "Click to view this section of the genome in the Ensembl Genome Browser" - gifmap.areas.append(HT.Area(shape='rect',coords=ENSEMBL_COORDS,href=ENSEMBL_HREF, title=ENSEMBL_TITLE)) + gifmap.areas.append(HtmlGenWrapper.create_area_tag( + shape='rect', + coords=ENSEMBL_COORDS, + href=ENSEMBL_HREF, + title=ENSEMBL_TITLE)) im_drawer.rectangle( xy=((xBrowse1, ensemblPaddingTop), (xBrowse2, (ensemblPaddingTop+self.BAND_HEIGHT))), @@ -1922,9 +1999,14 @@ class DisplayMappingResults(object): outline=rectColor,fill=rectColor,width = 0) COORDS="%d,%d,%d,%d"%(xLeftOffset+offsetA-LRectHeight, yZero+40+Zorder*(LRectWidth+3),\ xLeftOffset+offsetA,yZero+40+Zorder*(LRectWidth+3)+LRectWidth) - HREF="/show_trait?trait_id=%s&dataset=%s" % (Lname, self.dataset.group.name+"Geno") + HREF = "/show_trait?trait_id=%s&dataset=%s" % (Lname, self.dataset.group.name+"Geno") #HREF="javascript:showDatabase3('%s','%s','%s','');" % (showLocusForm,fd.RISet+"Geno", Lname) - Areas=HT.Area(shape='rect', coords=COORDS, href=HREF, target="_blank", title="Locus : " + Lname) + Areas = HtmlGenWrapper.create_area_tag( + shape='rect', + coords=COORDS, + href=HREF, + target="_blank", + title="Locus : {}".format(Lname)) gifmap.areas.append(Areas) ##piddle bug if j == 0: @@ -2133,8 +2215,14 @@ class DisplayMappingResults(object): else: sugg_title = "Suggestive LOD = %0.2f" % (self.suggestive/4.61) sig_title = "Significant LOD = %0.2f" % (self.significant/4.61) - Areas1 = HT.Area(shape='rect',coords=sugg_coords,title=sugg_title) - Areas2 = HT.Area(shape='rect',coords=sig_coords,title=sig_title) + Areas1 = HtmlGenWrapper.create_area_tag( + shape='rect', + coords=sugg_coords, + title=sugg_title) + Areas2 = HtmlGenWrapper.create_area_tag( + shape='rect', + coords=sig_coords, + title=sig_title) gifmap.areas.append(Areas1) gifmap.areas.append(Areas2) @@ -2586,7 +2674,10 @@ class DisplayMappingResults(object): #add by NL 09-03-2010 HREF = "javascript:chrView(%d,%s);" % (i,self.ChrLengthMbList) #HREF = "javascript:changeView(%d,%s);" % (i,self.ChrLengthMbList) - Areas = HT.Area(shape='rect', coords=COORDS, href=HREF) + Areas = HtmlGenWrapper.create_area_tag( + shape='rect', + coords=COORDS, + href=HREF) gifmap.areas.append(Areas) startPosX += (self.ChrLengthDistList[i]+self.GraphInterval)*plotXScale @@ -2672,7 +2763,11 @@ class DisplayMappingResults(object): tableIterationsCnt = tableIterationsCnt + 1 this_row = [] #container for the cells of each row - selectCheck = HT.Input(type="checkbox", name="selectCheck", value=theGO["GeneSymbol"], Class="checkbox trait_checkbox") #checkbox for each row + selectCheck = HtmlGenWrapper.create_input_tag( + type="checkbox", + name="selectCheck", + value=theGO["GeneSymbol"], + Class="checkbox trait_checkbox") # checkbox for each row geneLength = (theGO["TxEnd"] - theGO["TxStart"])*1000.0 tenPercentLength = geneLength*0.0001 @@ -2730,41 +2825,77 @@ class DisplayMappingResults(object): this_row = [selectCheck.__str__(), str(tableIterationsCnt), - HT.Href(geneIdString, theGO["GeneSymbol"], target="_blank").__str__(), - HT.Href(mouseStartString, "%0.6f" % txStart, target="_blank").__str__(), - HT.Href("javascript:rangeView('%s', %f, %f)" % (str(chr_as_int), txStart-tenPercentLength, txEnd+tenPercentLength), "%0.3f" % geneLength).__str__(), + str(HtmlGenWrapper.create_link_tag( + geneIdString, + theGO["GeneSymbol"], + target="_blank") + ), + str(HtmlGenWrapper.create_link_tag( + mouseStartString, + "{:.6f}".format(txStart), + target="_blank") + ), + str(HtmlGenWrapper.create_link_tag( + "javascript:rangeView('{}', {:f}, {:f})".format( + str(chr_as_int), + txStart-tenPercentLength, + txEnd+tenPercentLength), + "{:.3f}".format(geneLength))), snpString, snpDensityStr, avgExpr, humanChr, - HT.Href(humanStartString, humanStartDisplay, target="_blank").__str__(), + str(HtmlGenWrapper.create_link_tag( + humanStartString, + humanStartDisplay, + target="_blank")), literatureCorrelationString, geneDescription] else: this_row = [selectCheck.__str__(), str(tableIterationsCnt), - HT.Href(geneIdString, theGO["GeneSymbol"], target="_blank").__str__(), - HT.Href(mouseStartString, "%0.6f" % txStart, target="_blank").__str__(), - HT.Href("javascript:rangeView('%s', %f, %f)" % (str(chr_as_int), txStart-tenPercentLength, txEnd+tenPercentLength), "%0.3f" % geneLength).__str__(), + str(HtmlGenWrapper.create_link_tag( + geneIdString, theGO["GeneSymbol"], + target="_blank")), + str(HtmlGenWrapper.create_link_tag( + mouseStartString, + "{:.6f}".format(txStart), + target="_blank")), + str(HtmlGenWrapper.create_link_tag( + "javascript:rangeView('{}', {:f}, {:f})".format( + str(chr_as_int), + txStart-tenPercentLength, + txEnd+tenPercentLength), + "{:.3f}".format(geneLength))), snpString, snpDensityStr, avgExpr, humanChr, - HT.Href(humanStartString, humanStartDisplay, target="_blank").__str__(), + str(HtmlGenWrapper.create_link_tag( + humanStartString, + humanStartDisplay, + target="_blank")), geneDescription] gene_table_body.append(this_row) elif self.dataset.group.species == 'rat': for gIndex, theGO in enumerate(geneCol): - this_row = [] #container for the cells of each row - selectCheck = HT.Input(type="checkbox", name="selectCheck", Class="checkbox trait_checkbox").__str__() #checkbox for each row + this_row = [] # container for the cells of each row + selectCheck = str(HtmlGenWrapper.create_input_tag( + type="checkbox", + name="selectCheck", + Class="checkbox trait_checkbox")) # checkbox for each row #ZS: May want to get this working again later #webqtlSearch = HT.Href(os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE)+"?cmd=sch&gene=%s&alias=1&species=rat" % theGO["GeneSymbol"], ">>", target="_blank").__str__() if theGO["GeneID"] != "": - geneSymbolNCBI = HT.Href("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=Graphics&list_uids=%s" % theGO["GeneID"], theGO["GeneSymbol"], Class="normalsize", target="_blank").__str__() + geneSymbolNCBI = str(HtmlGenWrapper.create_link_tag( + "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=Graphics&list_uids={}".format(theGO["GeneID"]), + theGO["GeneSymbol"], + Class="normalsize", + target="_blank")) else: geneSymbolNCBI = theGO["GeneSymbol"] @@ -2804,7 +2935,9 @@ class DisplayMappingResults(object): str(gIndex+1), geneSymbolNCBI, "%0.6f" % theGO["TxStart"], - HT.Href(geneLengthURL, "%0.3f" % (geneLength*1000.0)).__str__(), + str(HtmlGenWrapper.create_link_tag( + geneLengthURL, + "{:.3f}".format(geneLength*1000.0))), avgExprVal, mouseChr, mouseTxStart, |