diff -r 350ab6479c5c lib/galaxy/web/controllers/dataset.py --- a/lib/galaxy/web/controllers/dataset.py Thu Nov 18 19:49:01 2010 -0500 +++ b/lib/galaxy/web/controllers/dataset.py Mon Nov 22 10:20:02 2010 +0000 @@ -375,7 +375,11 @@ raise paste.httpexceptions.HTTPNotFound( "File Not Found (%s)." % data.file_name ) max_peek_size = 1000000 # 1 MB - if not preview or isinstance(data.datatype, datatypes.images.Image) or os.stat( data.file_name ).st_size < max_peek_size: + if preview and isinstance(data.datatype, datatypes.tabular.Tabular): + #Show pretty table + trans.response.set_content_type( "text/html" ) + return tabular_to_html( data ) + elif not preview or isinstance(data.datatype, datatypes.images.Image) or os.stat( data.file_name ).st_size < max_peek_size: return open( data.file_name ) else: trans.response.set_content_type( "text/html" ) @@ -824,3 +828,33 @@ status = SUCCESS message = done_msg return status, message + + +#TODO - Move this somewhere more sensible +def tabular_to_html( data ): + """Returns HTML table as a string.""" + #TODO - Share code with the tabular "peek view"? + #TODO - Column names e.g. Chrom, Start, End, Strand, Name in interval data + #TODO - Add a warning if this is only the start of the file + #TODO - Add CSS reference, perhaps some id attributes to help with styling? + answer = [""] + in_table = False + handle = open(data.file_name) + for line in handle: + #TODO - Escape any problem characters for HTML like & and < or > + if line.startswith("#") and "\t" not in line: + if in_table: + in_table = False + answer.append("") + answer.append("

%s

" % line.rstrip()) + else: + if not in_table: + answer.append("") + in_table = True + cols = line.rstrip().split("\t") + answer.append("" % "
%s
".join(cols)) + handle.close() + if in_table: + answer.append("
") + answer.append("") + return "".join(answer)