Mercurial > repos > ondovb > tabular2html
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/</</; + $val =~ s/>/>/; + + 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="<"/> + <remove value=">"/> + </valid> + <mapping initial="none"> + <add source="<" target="&lt;"/> + <add source=">" target="&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"> + <html><head><style type="text/css"> + 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} + </style></head><body> + <table style="border-collapse:collapse"> + #if $headerSource.source == 'numbers': + <tr> + #for $i in range(int($input.metadata.columns)): + <th>${i + 1}</th> + #end for + </tr> + #elif $headerSource.source == 'names' and hasattr($input.datatype, 'column_names'): + <tr> + #for $columnName in $input.datatype.column_names: + <th>$columnName</th> + #end for + </tr> + #elif $headerSource.source == 'explicit': + <tr> + #for $header in $headerSource.headers: + <th + #if len($header.subheaders) > 0: + colspan="${len($header.subheaders)}" + #else + rowspan="2" + #end if + > + $header.name + </th> + #end for + <tr> + #for $header in $headerSource.headers: + #for $subheader in $header.subheaders: + <th> + ${subheader.name} + </th> + #end for + #end for + </tr> + #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>