mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Next pass at improving make_html_table, using metadata to generate column headers now.
This commit is contained in:
@@ -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( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop(0) ) )
|
||||
out.append( '</td></tr>' )
|
||||
out.append( '<tr>' )
|
||||
for elem in elems: # valid data
|
||||
elem = escape( elem )
|
||||
out.append( '<td>%s</td>' % elem )
|
||||
out.append( '</tr>' )
|
||||
# Peek may consist only of comments
|
||||
while len( comments ) > 0:
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop(0) ) )
|
||||
out.append( '</td></tr>' )
|
||||
return "".join( out )
|
||||
def display_peek(self, dataset):
|
||||
"""Returns formated html of peek"""
|
||||
try:
|
||||
|
||||
@@ -172,57 +172,27 @@ class Interval( Tabular ):
|
||||
def make_html_table( self, dataset, skipchars=[] ):
|
||||
"""Create HTML table, used for displaying peek"""
|
||||
out = ['<table cellspacing="0" cellpadding="3">']
|
||||
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('<tr>')
|
||||
for index, elem in enumerate( elems ):
|
||||
if index+1 == dataset.metadata.chromCol:
|
||||
out.append( '<th>%s.Chrom</th>' % ( index+1 ) )
|
||||
elif index+1 == dataset.metadata.startCol:
|
||||
out.append( '<th>%s.Start</th>' % ( index+1 ) )
|
||||
elif index+1 == dataset.metadata.endCol:
|
||||
out.append( '<th>%s.End</th>' % ( index+1 ) )
|
||||
elif dataset.metadata.strandCol and ( index+1 == dataset.metadata.strandCol ):
|
||||
out.append( '<th>%s.Strand</th>' % ( index+1 ) )
|
||||
elif dataset.metadata.nameCol and ( index+1 == dataset.metadata.nameCol ):
|
||||
out.append( '<th>%s.Name</th>' % ( index+1 ) )
|
||||
else:
|
||||
out.append( '<th>%s</th>' % ( index+1 ) )
|
||||
out.append('</tr>')
|
||||
while len( comments ) > 0: # Keep comments
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop( 0 ) ) )
|
||||
out.append( '</td></tr>' )
|
||||
out.append( '<tr>' ) # body
|
||||
for elem in elems:
|
||||
elem = escape( elem )
|
||||
out.append( '<td>%s</td>' % elem )
|
||||
out.append( '</tr>' )
|
||||
# Peek may consis only of comments
|
||||
while len( comments ) > 0:
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop(0) ) )
|
||||
out.append( '</td></tr>' )
|
||||
# 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 )
|
||||
out = "".join( out )
|
||||
except Exception, exc:
|
||||
out = "Can't create peek %s" % str( exc )
|
||||
return out
|
||||
|
||||
@@ -148,7 +148,7 @@ class Maf( Alignment ):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
out.append( '<tr><td>%s</td></tr>' % line )
|
||||
out.append( '<tr><td>%s</td></tr>' % escape( line ) )
|
||||
out.append( '</table>' )
|
||||
out = "".join( out )
|
||||
except Exception, exc:
|
||||
|
||||
@@ -88,48 +88,16 @@ class Tabular( data.Text ):
|
||||
def make_html_table( self, dataset, skipchars=[] ):
|
||||
"""Create HTML table, used for displaying peek"""
|
||||
out = ['<table cellspacing="0" cellpadding="3">']
|
||||
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('<tr>')
|
||||
for index, elem in enumerate(elems):
|
||||
out.append("<th>%s</th>" % (index+1))
|
||||
out.append('</tr>')
|
||||
while len(comments)>0: # Keep comments
|
||||
out.append('<tr><td colspan="100%">')
|
||||
out.append(escape(comments.pop(0)))
|
||||
out.append('</td></tr>')
|
||||
out.append('<tr>')
|
||||
for elem in elems: # body
|
||||
elem = escape(elem)
|
||||
out.append("<td>%s</td>" % elem)
|
||||
out.append('</tr>')
|
||||
# Peek may consis only of comments
|
||||
while len( comments ) > 0:
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop(0) ) )
|
||||
out.append( '</td></tr>' )
|
||||
out.append('</table>')
|
||||
out = "".join(out)
|
||||
# Generate column header
|
||||
for i in range( 1, dataset.metadata.columns+1 ):
|
||||
out.append( '<th>%s</th>' % str( 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" % 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 = ['<table cellspacing="0" cellpadding="3">']
|
||||
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( '<tr>' )
|
||||
for index, name in enumerate( self.column_names ):
|
||||
out.append( "<th>%s.%s</th>" % ( 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( "<th>%s</th>" % ( index+1 ) )
|
||||
out.append( '</tr>' )
|
||||
# Keep comments
|
||||
while len( comments ) > 0:
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop( 0 ) ) )
|
||||
out.append( '</td></tr>' )
|
||||
out.append( '<tr>' ) # body
|
||||
for elem in elems:
|
||||
elem = escape( elem )
|
||||
out.append( "<td>%s</td>" % elem )
|
||||
# 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>' )
|
||||
# Peek may consis only of comments
|
||||
while len( comments ) > 0:
|
||||
out.append( '<tr><td colspan="100%">' )
|
||||
out.append( escape( comments.pop(0) ) )
|
||||
out.append( '</td></tr>' )
|
||||
out.append( self.make_html_peek_rows( dataset, skipchars=skipchars ) )
|
||||
out.append( '</table>' )
|
||||
out = "".join( out )
|
||||
except Exception, exc:
|
||||
|
||||
Reference in New Issue
Block a user