From a5544c752bf1fcafed178a6ae987398ea9890b57 Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Tue, 18 Mar 2008 20:48:19 +0000 Subject: [PATCH] Improvements in rendering HTML for history items: - Interval data will display chrom, start, end, strand, name metadat column settings - Maf will display species metadata settings - Wiggle will render correct column headings - it never has previously - skipchars consists of a list of string to use to determine comment lines in the peek data rather than a singel skipchar --- lib/galaxy/datatypes/interval.py | 76 ++++++++++++++++++++++++++++---- lib/galaxy/datatypes/sequence.py | 26 +++++++++++ lib/galaxy/datatypes/tabular.py | 58 +++++++++++++++--------- 3 files changed, 130 insertions(+), 30 deletions(-) diff --git a/lib/galaxy/datatypes/interval.py b/lib/galaxy/datatypes/interval.py index e0bca39c4b2..2b77b6e4cbe 100644 --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -107,7 +107,7 @@ class Interval( Tabular ): int( elems[3] ) except: dataset.metadata.nameCol = 4 - if len( elems ) < 6: + if len( elems ) < 6 or elems[5] not in data.valid_strand: dataset.metadata.strandCol = 0 else: dataset.metadata.strandCol = 6 @@ -169,6 +169,64 @@ class Interval( Tabular ): os.close(fd) return open(temp_name) + def make_html_table( self, dataset, skipchars=[] ): + """Create HTML table, used for displaying peek""" + out = [''] + first = True + comments = [] + try: + data = dataset.peek + lines = data.splitlines() + for line in lines: + line = line.strip() + if not line: + continue + comment = False + for skipchar in skipchars: + if line.startswith( skipchar ): + comments.append( line ) + comment = True + break + if comment: + continue + elems = line.split( '\t' ) + if first: # Generate column header + first = False + out.append('') + for index, elem in enumerate( elems ): + if index+1 == dataset.metadata.chromCol: + out.append( '' % ( index+1 ) ) + elif index+1 == dataset.metadata.startCol: + out.append( '' % ( index+1 ) ) + elif index+1 == dataset.metadata.endCol: + out.append( '' % ( index+1 ) ) + elif dataset.metadata.strandCol and ( index+1 == dataset.metadata.strandCol ): + out.append( '' % ( index+1 ) ) + elif dataset.metadata.nameCol and ( index+1 == dataset.metadata.nameCol ): + out.append( '' % ( index+1 ) ) + else: + out.append( '' % ( index+1 ) ) + out.append('') + while len( comments ) > 0: # Keep comments + out.append( '' ) + out.append( '' ) # body + for elem in elems: + elem = escape( elem ) + out.append( '' % elem ) + out.append( '' ) + # Peek may consis only of comments + while len( comments ) > 0: + out.append( '' ) + out.append( '
%s.Chrom%s.Start%s.End%s.Strand%s.Name%s
' ) + out.append( escape( comments.pop( 0 ) ) ) + out.append( '
%s
' ) + out.append( escape( comments.pop(0) ) ) + out.append( '
' ) + out = ''.join( out ) + except Exception, exc: + out = "Can't create peek %s" % str( exc ) + return out + def ucsc_links( self, dataset, type, app, base_url ): ret_val = [] if dataset.has_data: @@ -424,8 +482,8 @@ class Gff( Tabular ): pass Tabular.set_meta( self, dataset, skip=i ) - def make_html_table(self, data): - return Tabular.make_html_table(self, data, skipchar='#') + def make_html_table( self, dataset ): + return Tabular.make_html_table( self, dataset, skipchars=['#'] ) def as_gbrowse_display_file( self, dataset, **kwd ): """Returns file contents that can be displayed in GBrowse apps.""" @@ -625,8 +683,8 @@ class Wiggle( Tabular ): MetadataElement( name="columns", default=3, desc="Number of columns", readonly=True, visible=False ) - def make_html_table(self, data): - return Tabular.make_html_table(self, data, skipchar='#') + def make_html_table( self, dataset ): + return Tabular.make_html_table( self, dataset, skipchars=['track', '#'] ) def set_meta( self, dataset, **kwd ): i = 0 @@ -686,8 +744,8 @@ class CustomTrack ( Tabular ): def set_meta( self, dataset, **kwd ): Tabular.set_meta( self, dataset, skip=1 ) - def make_html_table(self, dataset): - return Tabular.make_html_table(self, dataset, skipchar='track') + def make_html_table( self, dataset ): + return Tabular.make_html_table( self, dataset, skipchars=['track', '#'] ) def get_estimated_display_viewport( self, dataset ): try: @@ -783,8 +841,8 @@ class GBrowseTrack ( Tabular ): def set_meta( self, dataset, **kwd ): Tabular.set_meta( self, dataset, skip=1 ) - def make_html_table(self, dataset): - return Tabular.make_html_table(self, dataset, skipchar='track') + def make_html_table( self, dataset ): + return Tabular.make_html_table( self, dataset, skipchars=['track', '#'] ) def get_estimated_display_viewport( self, dataset ): #TODO: fix me... diff --git a/lib/galaxy/datatypes/sequence.py b/lib/galaxy/datatypes/sequence.py index d276b99961c..5d9cf7df819 100644 --- a/lib/galaxy/datatypes/sequence.py +++ b/lib/galaxy/datatypes/sequence.py @@ -4,6 +4,7 @@ Image classes import data import logging +from cgi import escape from galaxy.datatypes.metadata import MetadataElement from galaxy.datatypes import metadata from galaxy import util @@ -129,6 +130,31 @@ class Maf( Alignment ): return True return False + def display_peek( self, dataset ): + """Returns formated html of peek""" + return self.make_html_table( dataset ) + + def make_html_table( self, dataset, skipchars=[] ): + """Create HTML table, used for displaying peek""" + out = [''] + try: + out.append('' ) + data = dataset.peek + lines = data.splitlines() + for line in lines: + line = line.strip() + if not line: + continue + out.append( '' % line ) + out.append( '
') + for species in dataset.metadata.species: + out.append( '%s, ' % species ) + out.append( '
%s
' ) + out = "".join( out ) + except Exception, exc: + out = "Can't create peek %s" % exc + return out + def sniff( self, filename ): """ Determines wether the file is in maf format diff --git a/lib/galaxy/datatypes/tabular.py b/lib/galaxy/datatypes/tabular.py index 0e04a289898..3e64fc206e3 100644 --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -85,39 +85,47 @@ class Tabular( data.Text ): if i > 100: break # Hopefully we never get here... dataset.metadata.column_types = column_types - def make_html_table(self, data, skipchar=None): + def make_html_table( self, dataset, skipchars=[] ): """Create HTML table, used for displaying peek""" out = [''] first = True comments = [] try: + data = dataset.peek lines = data.splitlines() for line in lines: - if skipchar and line.startswith(skipchar): - comments.append(line.strip()) - continue line = line.strip() if not line: continue + comment = False + for skipchar in skipchars: + if line.startswith( skipchar ): + comments.append( line ) + comment = True + break + if comment: + continue elems = line.split("\t") - - if first: #generate header + if first: # Generate column header first = False out.append('') for index, elem in enumerate(elems): out.append("" % (index+1)) out.append('') - - while len(comments)>0: + while len(comments)>0: # Keep comments out.append('') - - out.append('') # body - for elem in elems: + out.append('') + for elem in elems: # body elem = escape(elem) out.append("" % elem) out.append('') + # Peek may consis only of comments + while len( comments ) > 0: + out.append( '' ) out.append('
%s
') out.append(escape(comments.pop(0))) out.append('
%s
' ) + out.append( escape( comments.pop(0) ) ) + out.append( '
') out = "".join(out) except Exception, exc: @@ -126,8 +134,7 @@ class Tabular( data.Text ): def display_peek( self, dataset ): """Returns formated html of peek""" - m_peek = self.make_html_table( dataset.peek ) - return m_peek + return self.make_html_table( dataset ) class Taxonomy( Tabular ): def __init__(self, **kwd): @@ -139,23 +146,28 @@ class Taxonomy( Tabular ): 'Tribe', 'Subtribe', 'Genus', 'Subgenus', 'Species', 'Subspecies' ] - def make_html_table( self, data, skipchar=None ): + def make_html_table( self, dataset, skipchars=[] ): """Create HTML table, used for displaying peek""" out = [''] first = True comments = [] try: + data = dataset.peek lines = data.splitlines() for line in lines: - line = line.rstrip( '\r\n' ) + line = line.strip() if not line: continue - if skipchar and line.startswith( skipchar ): - comments.append( line ) + comment = False + for skipchar in skipchars: + if line.startswith( skipchar ): + comments.append( line ) + comment = True + break + if comment: continue - elems = line.split( '\t' ) - if first: #generate header + if first: # Generate column header first = False out.append( '' ) for index, name in enumerate( self.column_names ): @@ -166,17 +178,21 @@ class Taxonomy( Tabular ): for index in range( len( self.column_names ), len( elems ) ): out.append( "" % ( index+1 ) ) out.append( '' ) - + # Keep comments while len( comments ) > 0: out.append( '' ) - out.append( '' ) # body for elem in elems: elem = escape( elem ) out.append( "" % elem ) out.append( '' ) + # Peek may consis only of comments + while len( comments ) > 0: + out.append( '' ) out.append( '
%s
' ) out.append( escape( comments.pop( 0 ) ) ) out.append( '
%s
' ) + out.append( escape( comments.pop(0) ) ) + out.append( '
' ) out = "".join( out ) except Exception, exc: