commit/galaxy-central: richard_burhans: consolidated make_html_table for tabular datatypes
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/0abcd5c667ac/ changeset: 0abcd5c667ac user: richard_burhans date: 2011-11-01 20:52:53 summary: consolidated make_html_table for tabular datatypes affected #: 3 files diff -r 33e2ae31dddd0f494841aaa7f408aac9312b031b -r 0abcd5c667ac1f6199baa9df20d9c8847d7b8908 lib/galaxy/datatypes/genetics.py --- a/lib/galaxy/datatypes/genetics.py +++ b/lib/galaxy/datatypes/genetics.py @@ -192,27 +192,9 @@ Tabular.__init__( self, **kwd ) self.column_names = [] - def make_html_table( self, dataset, skipchars=[] ): - """ - Create HTML table, used for displaying peek - """ - out = ['<table cellspacing="0" cellpadding="3">'] - comments = [] - try: - # Generate column header - out.append( '<tr>' ) - for i, name in enumerate( self.column_names ): - out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) ) - if dataset.metadata.columns - len( self.column_names ) > 0: - for i in range( len( self.column_names ), dataset.metadata.columns ): - out.append( '<th>%s</th>' % str( i+1 ) ) - out.append( '</tr>' ) - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % exc - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_names=self.column_names ) def get_mime(self): """Returns the mime type of the datatype""" diff -r 33e2ae31dddd0f494841aaa7f408aac9312b031b -r 0abcd5c667ac1f6199baa9df20d9c8847d7b8908 lib/galaxy/datatypes/interval.py --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -219,33 +219,9 @@ os.write(fd, '%s\n' % '\t'.join(tmp) ) os.close(fd) return open(temp_name) - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - comments = [] - try: - # Generate column header - out.append('<tr>') - for i in range( 1, dataset.metadata.columns+1 ): - if i == dataset.metadata.chromCol: - out.append( '<th>%s.Chrom</th>' % i ) - elif i == dataset.metadata.startCol: - out.append( '<th>%s.Start</th>' % i ) - elif i == dataset.metadata.endCol: - out.append( '<th>%s.End</th>' % i ) - elif dataset.metadata.strandCol and i == dataset.metadata.strandCol: - out.append( '<th>%s.Strand</th>' % i ) - elif dataset.metadata.nameCol and i == dataset.metadata.nameCol: - out.append( '<th>%s.Name</th>' % i ) - else: - out.append( '<th>%s</th>' % i ) - out.append('</tr>') - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % str( exc ) - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_parameter_alias={'chromCol':'Chrom', 'startCol':'Start', 'endCol':'End', 'strandCol':'Strand', 'nameCol':'Name'} ) def ucsc_links( self, dataset, type, app, base_url ): """ Generate links to UCSC genome browser sites based on the dbkey @@ -617,21 +593,9 @@ except: pass Tabular.set_meta( self, dataset, overwrite = overwrite, skip = i ) - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - comments = [] - try: - # Generate column header - out.append( '<tr>' ) - for i, name in enumerate( self.column_names ): - out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) ) - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % exc - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_names=self.column_names ) def get_estimated_display_viewport( self, dataset ): """ Return a chrom, start, stop tuple for viewing a file. There are slight differences between gff 2 and gff 3 @@ -1081,7 +1045,8 @@ link = self._get_remote_call_url( redirect_url, site_name, dataset, type, app, base_url ) ret_val.append( ( site_name, link ) ) return ret_val - def make_html_table( self, dataset ): + def display_peek( self, dataset ): + """Returns formated html of peek""" return Tabular.make_html_table( self, dataset, skipchars=['track', '#'] ) def set_meta( self, dataset, overwrite = True, **kwd ): max_data_lines = None diff -r 33e2ae31dddd0f494841aaa7f408aac9312b031b -r 0abcd5c667ac1f6199baa9df20d9c8847d7b8908 lib/galaxy/datatypes/tabular.py --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -168,24 +168,46 @@ """Create HTML table, used for displaying peek""" out = ['<table cellspacing="0" cellpadding="3">'] try: - out.append( self.make_html_peek_header( dataset, kwargs ) ) - out.append( self.make_html_peek_rows( dataset, kwargs ) ) + out.append( self.make_html_peek_header( dataset, **kwargs ) ) + out.append( self.make_html_peek_rows( dataset, **kwargs ) ) out.append( '</table>' ) out = "".join( out ) except Exception, exc: out = "Can't create peek %s" % str( exc ) return out - def make_html_peek_header( self, dataset, skipchars=[] ): + def make_html_peek_header( self, dataset, skipchars=[], column_names=[], column_number_format='%s', column_parameter_alias={}, **kwargs ): out = [] try: + column_headers = [None] * dataset.metadata.columns + + # fill in empty headers with data from column_names + for i in range( min( dataset.metadata.columns, len( column_names ) ) ): + if column_headers[i] is None and column_names[i] is not None: + column_headers[i] = column_names[i] + + # fill in empty headers from ColumnParameters set in the metadata + for name, spec in dataset.metadata.spec.items(): + if isinstance( spec.param, metadata.ColumnParameter ): + try: + i = int( getattr( dataset.metadata, name ) ) - 1 + except: + i = -1 + if 0 <= i < dataset.metadata.columns and column_headers[i] is None: + column_headers[i] = column_parameter_alias.get(name, name) + out.append( '<tr>' ) - for i in range( 1, dataset.metadata.columns+1 ): - out.append( '<th>%s</th>' % str( i ) ) + for i, header in enumerate( column_headers ): + out.append( '<th>' ) + if header is None: + out.append( column_number_format % str( i + 1 ) ) + else: + out.append( '%s.%s' % ( str( i + 1 ), escape( header ) ) ) + out.append( '</th>' ) out.append( '</tr>' ) except Exception, exc: raise Exception, "Can't create peek header %s" % str( exc ) return "".join( out ) - def make_html_peek_rows( self, dataset, skipchars=[] ): + def make_html_peek_rows( self, dataset, skipchars=[], **kwargs ): out = [] try: if not dataset.peek: @@ -235,26 +257,9 @@ 'Superorder', 'Order', 'Suborder', 'Superfamily', 'Family', 'Subfamily', 'Tribe', 'Subtribe', 'Genus', 'Subgenus', 'Species', 'Subspecies' ] - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - comments = [] - try: - # Generate column header - out.append( '<tr>' ) - for i, name in enumerate( self.column_names ): - out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) ) - # This data type requires at least 24 columns in the data - if dataset.metadata.columns - len( self.column_names ) > 0: - for i in range( len( self.column_names ), dataset.metadata.columns ): - out.append( '<th>%s</th>' % str( i+1 ) ) - out.append( '</tr>' ) - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % exc - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_names=self.column_names ) class Sam( Tabular ): file_ext = 'sam' @@ -264,25 +269,10 @@ self.column_names = ['QNAME', 'FLAG', 'RNAME', 'POS', 'MAPQ', 'CIGAR', 'MRNM', 'MPOS', 'ISIZE', 'SEQ', 'QUAL', 'OPT' ] - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - try: - # Generate column header - out.append( '<tr>' ) - for i, name in enumerate( self.column_names ): - out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) ) - # This data type requires at least 11 columns in the data - if dataset.metadata.columns - len( self.column_names ) > 0: - for i in range( len( self.column_names ), dataset.metadata.columns ): - out.append( '<th>%s</th>' % str( i+1 ) ) - out.append( '</tr>' ) - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % exc - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_names=self.column_names ) + def sniff( self, filename ): """ Determines whether the file is in SAM format @@ -376,29 +366,9 @@ def init_meta( self, dataset, copy_from=None ): Tabular.init_meta( self, dataset, copy_from=copy_from ) - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - comments = [] - try: - # Generate column header - out.append('<tr>') - for i in range( 1, dataset.metadata.columns+1 ): - if i == dataset.metadata.chromCol: - out.append( '<th>%s.Chrom</th>' % i ) - elif i == dataset.metadata.startCol: - out.append( '<th>%s.Start</th>' % i ) - elif i == dataset.metadata.baseCol: - out.append( '<th>%s.Base</th>' % i ) - else: - out.append( '<th>%s</th>' % i ) - out.append('</tr>') - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % str( exc ) - return out + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_parameter_alias={'chromCol':'Chrom', 'startCol':'Start', 'baseCol':'Base'} ) def repair_methods( self, dataset ): """Return options for removing errors along with a description""" @@ -464,21 +434,9 @@ def sniff( self, filename ): headers = get_headers( filename, '\n', count=1 ) return headers[0][0].startswith("##fileformat=VCF") + def display_peek( self, dataset ): + """Returns formated html of peek""" + return Tabular.make_html_table( self, dataset, column_names=self.column_names ) - def make_html_table( self, dataset, skipchars=[] ): - """Create HTML table, used for displaying peek""" - out = ['<table cellspacing="0" cellpadding="3">'] - try: - # Generate column header - out.append( '<tr>' ) - for i, name in enumerate( self.column_names ): - out.append( '<th>%s.%s</th>' % ( str( i+1 ), name ) ) - out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) - out.append( '</table>' ) - out = "".join( out ) - except Exception, exc: - out = "Can't create peek %s" % exc - return out - def get_track_type( self ): return "VcfTrack", {"data": "tabix", "index": "summary_tree"} Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket