changeset 0:a5814dd5a11a default tip

Uploaded
author ondovb
date Fri, 23 Sep 2011 17:06:15 -0400
parents
children
files tabular2HTML.pl tabular2HTML.xml
diffstat 2 files changed, 223 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tabular2HTML.pl	Fri Sep 23 17:06:15 2011 -0400
@@ -0,0 +1,69 @@
+
+use strict;
+
+my ($table, $input, $output, @spans) = @ARGV;
+
+# positions that should have dark right borders
+#
+my %dark;
+
+foreach my $span ( @spans )
+{
+	if ( $span > 1 )
+	{
+		# only initialize if there are any spans more than 1
+		
+		pop @spans;
+		my $i;
+		
+		foreach my $span ( @spans )
+		{
+	    	$i += $span;
+		    $dark{$i - 1} = 1;
+		}
+		
+		last;
+    }
+}
+
+open TABLE, ">>$table" or die $!;
+open INPUT, "<$input" or die $!;
+
+my $parity;
+
+while ( my $line = <INPUT> )
+{
+	chomp $line;
+	
+	my @vals = split /\t/, $line;
+	
+	$parity = ( $parity eq 'odd' ? 'even' : 'odd' );
+	
+	print TABLE "<tr class='$parity'>";
+	
+    for( my $i = 0; $i < @vals; $i++ )
+    {
+		my $val = $vals[$i];
+		my $class;
+	
+		if ( $dark{$i} )
+		{
+			$class = ' class="darkRight"';
+		}
+	
+		$val =~ s/</&lt;/;
+		$val =~ s/>/&gt;/;
+	
+		print TABLE "<td$class>$val</td>";
+	}
+	
+	print TABLE "</tr>\n";
+}
+
+close INPUT;
+
+print TABLE "</table></body></html>\n";
+
+close TABLE;
+
+`mv $table $output`;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tabular2HTML.xml	Fri Sep 23 17:06:15 2011 -0400
@@ -0,0 +1,154 @@
+<tool id="tabular2HTML" name="Tabular-to-HTML" version="1.0.0">
+    <description>for easier table viewing</description>
+    <command interpreter="perl">
+        tabular2HTML.pl
+			$tableHeader
+			$input
+			$output
+			#if $headerSource.source == 'explicit':
+	            #for $header in $headerSource.headers
+    	            #if len($header.subheaders) > 0
+        	            ${len($header.subheaders)}
+            	    #else
+                	    1
+	                #end if
+    	        #end for
+			#end if
+    </command>
+    <inputs>
+        <param name="input" type="data" format="tabular" label="Tabular data"/>
+    	<conditional name="headerSource">
+	    	<param name="source" type="select" label="Header">
+	    		<option value="numbers">Column numbers</option>
+	    		<option value="names">Column names (if available)</option>
+	    		<option value="explicit">Specify headers and subheaders</option>
+	    		<option value="none">None</option>
+	    	</param>
+	    	<when value="numbers">
+	    	</when>
+	    	<when value="names">
+	 		</when>
+	    	<when value="explicit">
+    		    <repeat name="headers" title="Header">
+        		    <param name="name" type="text" label="Name">
+            		    <sanitizer>
+                		    <valid initial="string.printable">
+                    		    <remove value="&lt;"/>
+                        		<remove value="&gt;"/>
+		                    </valid>
+							<mapping initial="none">
+								<add source="&lt;" target="&amp;lt;"/>
+								<add source="&gt;" target="&amp;gt;"/>
+							</mapping>
+						</sanitizer>
+					</param>
+					<repeat name="subheaders" title="Subheader">
+						<param name="name" type="text" label="Name"/>
+					</repeat>
+				</repeat>
+			</when>
+			<when value="none">
+			</when>
+		</conditional>
+	</inputs>
+	<outputs>
+		<data format="html" name="output"/>
+	</outputs>
+	<configfiles>
+		<configfile name="tableHeader">
+			&lt;html&gt;&lt;head&gt;&lt;style type="text/css"&gt;
+			table,td,th
+			{
+				border: 1px solid #dddddd;
+				border-collapse: collapse;
+				padding: 4px;
+				font-size: 10pt;
+			}
+			th{border-width:2px; background-color: #888888; color: #ffffff}
+			tr.odd {background-color: #f2fff2}
+			tr.even {background-color: #f2f2ff}
+			td.darkRight {border-right: 2px solid #888888}
+			&lt;/style&gt;&lt;/head&gt;&lt;body&gt;
+			&lt;table style="border-collapse:collapse"&gt;
+			#if $headerSource.source == 'numbers':
+				&lt;tr&gt;
+            	#for $i in range(int($input.metadata.columns)):
+            		&lt;th&gt;${i + 1}&lt;/th&gt;
+            	#end for
+				&lt;/tr&gt;
+			#elif $headerSource.source == 'names' and hasattr($input.datatype, 'column_names'):
+				&lt;tr&gt;
+				#for $columnName in $input.datatype.column_names:
+					&lt;th&gt;$columnName&lt;/th&gt;
+				#end for
+				&lt;/tr&gt;
+            #elif $headerSource.source == 'explicit':
+				&lt;tr&gt;
+				#for $header in $headerSource.headers:
+					&lt;th
+					#if len($header.subheaders) > 0:
+						colspan="${len($header.subheaders)}"
+					#else
+						rowspan="2"
+					#end if
+					&gt;
+					$header.name
+					&lt;/th&gt;
+				#end for
+				&lt;tr&gt;
+				#for $header in $headerSource.headers:
+					#for $subheader in $header.subheaders:
+						&lt;th&gt;
+						${subheader.name}
+						&lt;/th&gt;
+					#end for
+				#end for
+				&lt;/tr&gt;
+            #end if
+        </configfile>
+    </configfiles>
+    <help>
+**===What it does===**
+
+Wraps tabular data in an HTML table for easier viewing.
+
+------
+
+**===Headers===**
+
+**Column numbers** - The header will show the order of the columns.
+
+**Column names** - The header will show column names if the data file is a
+specific type of tabular file that has column names in
+Galaxy (such as *sam* or *taxonomy*). Otherwise, no header will be shown.
+
+**Specify headers and subheaders** - This allows custom headers, which can span
+multiple columns if subheaders are included. For example, the tabular file::
+
+  1      2    3      4
+  read1  100  12345  50
+  read2  150  56789  60
+
+...with the headers and subheaders::
+
+  Query
+    ID
+    length
+  Hit
+    gi
+    score
+
+...would create an html table with the format:
+
++----------------+---------------+
+|     Query      |      Hit      |
++-------+--------+-------+-------+
+|  ID   | length |   gi  | score |
++=======+========+=======+=======+
+| read1 |  100   | 12345 |  50   |
++-------+--------+-------+-------+
+| read2 |  150   | 56789 |  60   |
++-------+--------+-------+-------+
+
+    </help>
+</tool>