Friday, October 14, 2011

Perl script for convert table.txt file to html

#!/usr/bin/perl
#Script: htmlize.pl
use CGI qw/:standard :html3 -noDebug/;

# FOR THE PURPOSES OF THE ONLINE PRESENTATION, WE ARE HARD-CODING
# THE LOCATION OF THE FILE HERE.  COMMENT THE NEXT LINE OUT TO USE
# THE PROGRAM FROM THE COMMAND LINE.

open (IN,"table.txt") or die "Cant Open $!";
print start_html('Young Gene Duplicates in Human');

# get the caption
chomp($caption = <IN>);

# get the column headers
chomp($colhead = <IN>);
@col_head = split("\t",$colhead);

# Get the data into an array. 
# The first item in each array is the header, the rest is
# the data cells
while (<IN>) {
     chomp;
     ($rowhead,@data) = split("\t");
     push(@rows,th($rowhead).td(\@data));
}
close IN;

# Print out the table
print img{src=>'1_ENSG00000033011_ENSG00000189366.png',align=>'center'};

print hr;

print table({-border=>''},
          caption($caption),
          TR([th(\@col_head),@rows])
      );

print end_html;

No comments:

Post a Comment