From 11040a4616cbffc667b9ae5dc88d814702e6a6ef Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Wed, 19 Mar 2008 14:33:43 +0000 Subject: [PATCH] Next pass at improving make_html_table, using metadata to generate column headers now. --- lib/galaxy/datatypes/data.py | 33 +++++++++++ lib/galaxy/datatypes/interval.py | 66 ++++++--------------- lib/galaxy/datatypes/sequence.py | 2 +- lib/galaxy/datatypes/tabular.py | 98 ++++++-------------------------- 4 files changed, 69 insertions(+), 130 deletions(-) diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index 4807b76c6e8..d982485c1c8 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -102,6 +102,39 @@ class Data( object ): """Set the peek and blurb text""" dataset.peek = '' dataset.blurb = 'data' + def make_html_peek_rows( self, dataset, skipchars=[] ): + out = [""] + comments = [] + 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' ) + while len( comments ) > 0: # Keep comments + out.append( '' ) + out.append( escape( comments.pop(0) ) ) + out.append( '' ) + out.append( '' ) + for elem in elems: # valid data + elem = escape( elem ) + out.append( '%s' % elem ) + out.append( '' ) + # Peek may consist only of comments + while len( comments ) > 0: + out.append( '' ) + out.append( escape( comments.pop(0) ) ) + out.append( '' ) + return "".join( out ) def display_peek(self, dataset): """Returns formated html of peek""" try: diff --git a/lib/galaxy/datatypes/interval.py b/lib/galaxy/datatypes/interval.py index 2b77b6e4cbe..1bd2b7f712d 100644 --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -172,57 +172,27 @@ class Interval( Tabular ): 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( '' ) + # Generate column header + out.append('') + for i in range( 1, dataset.metadata.columns+1 ): + if i == dataset.metadata.chromCol: + out.append( '' % i ) + elif i == dataset.metadata.startCol: + out.append( '' % i ) + elif i == dataset.metadata.endCol: + out.append( '' % i ) + elif dataset.metadata.strandCol and i == dataset.metadata.strandCol: + out.append( '' % i ) + elif dataset.metadata.nameCol and i == dataset.metadata.nameCol: + out.append( '' % i ) + else: + out.append( '' % i ) + out.append('') + out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) 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( '
%s.Chrom%s.Start%s.End%s.Strand%s.Name%s
' ) - out = ''.join( out ) + out = "".join( out ) except Exception, exc: out = "Can't create peek %s" % str( exc ) return out diff --git a/lib/galaxy/datatypes/sequence.py b/lib/galaxy/datatypes/sequence.py index 5d9cf7df819..8835539bcf5 100644 --- a/lib/galaxy/datatypes/sequence.py +++ b/lib/galaxy/datatypes/sequence.py @@ -148,7 +148,7 @@ class Maf( Alignment ): line = line.strip() if not line: continue - out.append( '%s' % line ) + out.append( '%s' % escape( line ) ) out.append( '' ) out = "".join( out ) except Exception, exc: diff --git a/lib/galaxy/datatypes/tabular.py b/lib/galaxy/datatypes/tabular.py index 3e64fc206e3..7c8c8af362c 100644 --- a/lib/galaxy/datatypes/tabular.py +++ b/lib/galaxy/datatypes/tabular.py @@ -88,48 +88,16 @@ class Tabular( data.Text ): 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): - out.append("" % (index+1)) - out.append('') - while len(comments)>0: # Keep comments - out.append('') - 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) + # Generate column header + for i in range( 1, dataset.metadata.columns+1 ): + out.append( '%s' % str( i ) ) + out.append( '' ) + out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) + out.append( '' ) + out = "".join( out ) except Exception, exc: - out = "Can't create peek %s" % exc + out = "Can't create peek %s" % str( exc ) return out def display_peek( self, dataset ): @@ -149,50 +117,18 @@ class Taxonomy( Tabular ): 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, name in enumerate( self.column_names ): - out.append( "" % ( str( index+1 ), name ) ) - # This data type requires at least 24 columns in the data - num_col_headers = len( elems ) - len( self.column_names ) - if num_col_headers > 0: - 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 ) + # Generate column header + out.append( '' ) + for i, name in enumerate( self.column_names ): + out.append( '' % ( 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( '' % str( i+1 ) ) out.append( '' ) - # Peek may consis only of comments - while len( comments ) > 0: - out.append( '' ) + out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) ) out.append( '
%s.%s%s
' ) - out.append( escape( comments.pop( 0 ) ) ) - out.append( '
%s
%s.%s%s
' ) - out.append( escape( comments.pop(0) ) ) - out.append( '
' ) out = "".join( out ) except Exception, exc: