From a7d05a47da592e76fd88ed699f034e13e2dba08e Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 8 Feb 2017 20:31:03 +0000 Subject: [PATCH] Prevent make_html_table() datatype methods from raising Exceptions This was preventing the browse of a data library which contained a purged dataset of gg datatype. Also fix import order and Python3 compatibility. --- .ci/flake8_lint_include_list.txt | 2 + .ci/py3_sources.txt | 2 + lib/galaxy/datatypes/genetics.py | 64 +++++++++++++++--------------- lib/galaxy/datatypes/interval.py | 46 +++++++++++---------- lib/galaxy/datatypes/proteomics.py | 8 ++-- lib/galaxy/datatypes/tabular.py | 8 ++-- 6 files changed, 68 insertions(+), 62 deletions(-) diff --git a/.ci/flake8_lint_include_list.txt b/.ci/flake8_lint_include_list.txt index 3bd4c942944..c8faba1b706 100644 --- a/.ci/flake8_lint_include_list.txt +++ b/.ci/flake8_lint_include_list.txt @@ -53,8 +53,10 @@ lib/galaxy/datatypes/dataproviders/__init__.py lib/galaxy/datatypes/data.py lib/galaxy/datatypes/display_applications/__init__.py lib/galaxy/datatypes/display_applications/util.py +lib/galaxy/datatypes/genetics.py lib/galaxy/datatypes/images.py lib/galaxy/datatypes/__init__.py +lib/galaxy/datatypes/interval.py lib/galaxy/datatypes/metadata.py lib/galaxy/datatypes/msa.py lib/galaxy/datatypes/ngsindex.py diff --git a/.ci/py3_sources.txt b/.ci/py3_sources.txt index 68fd3d55315..a17447b9d75 100644 --- a/.ci/py3_sources.txt +++ b/.ci/py3_sources.txt @@ -13,7 +13,9 @@ lib/galaxy/datatypes/constructive_solid_geometry.py lib/galaxy/datatypes/converters/ lib/galaxy/datatypes/dataproviders/ lib/galaxy/datatypes/data.py +lib/galaxy/datatypes/genetics.py lib/galaxy/datatypes/images.py +lib/galaxy/datatypes/interval.py lib/galaxy/datatypes/msa.py lib/galaxy/datatypes/ngsindex.py lib/galaxy/datatypes/proteomics.py diff --git a/lib/galaxy/datatypes/genetics.py b/lib/galaxy/datatypes/genetics.py index 24900beebe7..ee5b5980739 100644 --- a/lib/galaxy/datatypes/genetics.py +++ b/lib/galaxy/datatypes/genetics.py @@ -11,18 +11,18 @@ subsequent row values are all numeric ! Will fail if any non numeric (eg '+' or ross lazarus for rgenetics august 20 2007 """ - import logging import os import re import sys -import urllib from cgi import escape +from six.moves.urllib.parse import quote_plus + from galaxy.datatypes import metadata -from galaxy.datatypes.text import Html from galaxy.datatypes.metadata import MetadataElement from galaxy.datatypes.tabular import Tabular +from galaxy.datatypes.text import Html from galaxy.util import nice_size from galaxy.web import url_for @@ -95,9 +95,9 @@ class GenomeGraphs( Tabular ): action='display_at', filename='ucsc_' + site_name ) display_url = "%s%s/display_as?id=%i&display_app=%s&authz_method=display_at" % (base_url, url_for( controller='root' ), dataset.id, type) - display_url = urllib.quote_plus( display_url ) - # was display_url = urllib.quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) - # redirect_url = urllib.quote_plus( "%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" % (site_url, dataset.dbkey, chrom, start, stop) ) + display_url = quote_plus( display_url ) + # was display_url = quote_plus( "%s/display_as?id=%i&display_app=%s" % (base_url, dataset.id, type) ) + # redirect_url = quote_plus( "%sdb=%s&position=%s:%s-%s&hgt.customText=%%s" % (site_url, dataset.dbkey, chrom, start, stop) ) sl = ["%sdb=%s" % (site_url, dataset.dbkey ), ] # sl.append("&hgt.customText=%s") sl.append("&hgGenome_dataSetName=%s&hgGenome_dataSetDescription=%s" % (dataset.name, 'GalaxyGG_data')) @@ -106,7 +106,7 @@ class GenomeGraphs( Tabular ): sl.append("&hgGenome_doSubmitUpload=submit") sl.append("&hgGenome_maxGapToFill=25000000&hgGenome_uploadFile=%s" % display_url) s = ''.join(sl) - s = urllib.quote_plus(s) + s = quote_plus(s) redirect_url = s link = '%s?redirect_url=%s&display_url=%s' % ( internal_url, redirect_url, display_url ) ret_val.append( (site_name, link) ) @@ -117,17 +117,17 @@ class GenomeGraphs( Tabular ): Create HTML table, used for displaying peek """ out = [''] - f = open(dataset.file_name, 'r') - d = f.readlines()[:5] - if len(d) == 0: - out = "Cannot find anything to parse in %s" % dataset.name - return out - hasheader = 0 - try: - ['%f' % x for x in d[0][1:]] # first is name - see if starts all numerics - except: - hasheader = 1 try: + with open(dataset.file_name, 'r') as f: + d = f.readlines()[:5] + if len(d) == 0: + out = "Cannot find anything to parse in %s" % dataset.name + return out + hasheader = 0 + try: + ['%f' % x for x in d[0][1:]] # first is name - see if starts all numerics + except: + hasheader = 1 # Generate column header out.append( '' ) if hasheader: @@ -150,16 +150,16 @@ class GenomeGraphs( Tabular ): Validate a gg file - all numeric after header row """ errors = list() - infile = open(dataset.file_name, "r") - infile.next() # header - for i, row in enumerate(infile): - ll = row.strip().split('\t')[1:] # first is alpha feature identifier - badvals = [] - for j, x in enumerate(ll): - try: - x = float(x) - except: - badvals.append('col%d:%s' % (j + 1, x)) + with open(dataset.file_name, "r") as infile: + next(infile) # header + for i, row in enumerate(infile): + ll = row.strip().split('\t')[1:] # first is alpha feature identifier + badvals = [] + for j, x in enumerate(ll): + try: + x = float(x) + except: + badvals.append('col%d:%s' % (j + 1, x)) if len(badvals) > 0: errors.append('row %d, %s' % (' '.join(badvals))) return errors @@ -219,7 +219,7 @@ class rgTabList(Tabular): def display_peek( self, dataset ): """Returns formated html of peek""" - return Tabular.make_html_table( self, dataset, column_names=self.column_names ) + return self.make_html_table( dataset, column_names=self.column_names ) def get_mime(self): """Returns the mime type of the datatype""" @@ -246,8 +246,8 @@ class rgSampleList(rgTabList): # this is what Plink wants as at 2009 def sniff(self, filename): - infile = open(filename, "r") - header = infile.next() # header + with open(filename, "r") as infile: + header = next(infile) # header if header[0] == 'FID' and header[1] == 'IID': return True else: @@ -287,7 +287,7 @@ class Rgenetics(Html): def generate_primary_file( self, dataset=None ): rval = ['Rgenetics Galaxy Composite Dataset

'] rval.append('

This composite dataset is composed of the following files: