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
This commit is contained in:
Greg Von Kuster
2008-03-18 20:48:19 +00:00
parent 365a87fd90
commit a5544c752b
3 changed files with 130 additions and 30 deletions
+67 -9
View File
@@ -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 = ['<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>' )
out.append( '</table>' )
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...
+26
View File
@@ -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 = ['<table cellspacing="0" cellpadding="3">']
try:
out.append('<tr><th>')
for species in dataset.metadata.species:
out.append( '%s,&nbsp;' % species )
out.append( '</th></tr>' )
data = dataset.peek
lines = data.splitlines()
for line in lines:
line = line.strip()
if not line:
continue
out.append( '<tr><td>%s</td></tr>' % line )
out.append( '</table>' )
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
+37 -21
View File
@@ -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 = ['<table cellspacing="0" cellpadding="3">']
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('<tr>')
for index, elem in enumerate(elems):
out.append("<th>%s</th>" % (index+1))
out.append('</tr>')
while len(comments)>0:
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:
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)
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 = ['<table cellspacing="0" cellpadding="3">']
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( '<tr>' )
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( "<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 )
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 )
except Exception, exc: