Chart-HeatMap-Simple/0000775000076400007640000000000010564217603014175 5ustar jinkeejinkeeChart-HeatMap-Simple/README0000664000076400007640000000111710564217575015065 0ustar jinkeejinkeeHeatMap-Simple version 0.01 =========================== INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: PostScript::Simple COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2007 by Thuan-Jin Kee This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. Chart-HeatMap-Simple/Makefile.PL0000664000076400007640000000107610564217223016151 0ustar jinkeejinkeeuse 5.008008; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Chart::HeatMap::Simple', VERSION_FROM => 'lib/Chart/HeatMap/Simple.pm', # finds $VERSION PREREQ_PM => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Chart/HeatMap/Simple.pm', # retrieve abstract from module AUTHOR => 'Thuan-Jin Kee ') : ()), ); Chart-HeatMap-Simple/lib/0000775000076400007640000000000010564217223014741 5ustar jinkeejinkeeChart-HeatMap-Simple/lib/Chart/0000775000076400007640000000000010564217223016002 5ustar jinkeejinkeeChart-HeatMap-Simple/lib/Chart/HeatMap/0000775000076400007640000000000010564217441017323 5ustar jinkeejinkeeChart-HeatMap-Simple/lib/Chart/HeatMap/Simple.pm0000664000076400007640000001324110564217441021113 0ustar jinkeejinkeepackage Chart::HeatMap::Simple; use 5.008008; use strict; use warnings; use PostScript::Simple; require Exporter; use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); #our %EXPORT_TAGS = ( 'all' => [ qw( # #) ] ); #our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = ( 'new', 'render_heatmap', 'compare_to_first_column' ); our $VERSION = '0.02'; # Preloaded methods go here. # Autoload methods go after =cut, and are processed by the autosplit program. my $compare_to_first_column = sub { my $self = shift; my $raw_array = $self->{_input_array}; my $processed_array; if (1==$self->{_headings}){ my $headings = shift @$raw_array; push @$processed_array,$headings; } for my $line (@$raw_array){ my @result_row; if (1==$self->{_row_names}){ my $label = shift @$line; push @result_row, $label; } push @result_row, colourdiff($line); push @$processed_array, \@result_row; } return $processed_array; }; sub new { my $class = shift; my %params = @_; my $self ={ _headings=> 1, _row_names=> 1, _input_array=>undef, _origin_x=>0.5, _origin_y=>10, _label_x=>1.5, _step=>0.25, _colour_distribution_function=>$compare_to_first_column, }; #print $self->{_colour_distribution_function}; foreach my $key (sort keys %params){ $self->{$key}=$params{$key}; } bless $self,$class; return $self; } sub render_heatmap{ my ($self) = shift; my $p = new PostScript::Simple(papersize => "A4", colour => 1, eps => 0, units => "in"); $p->newpage; #my $raw_array = $self->{_input_array}; my $final_function = $self->{_colour_distribution_function}; my $input_array = &$final_function($self); my $heading_array = shift @$input_array; if(1==$self->{_headings}){ # print "making headings"; my $xpos = $self->{_origin_x} + $self->{_label_x}; my $ypos = $self->{_origin_y}; my $first_col_heading = shift @$heading_array; $p->setcolour("black"); $p->setfont("Times-Roman", 20); $p->text($self->{_origin_x},$ypos, $first_col_heading); for my $i (@$heading_array){ $p->setcolour("black"); $p->setfont("Times-Roman", 20); $p->text({rotate=>90},$xpos,$ypos, $i); $xpos = $xpos + $self->{_step}; } } # print "going over array"; my $xpos = $self->{_origin_x} + $self->{_label_x}; my $ypos = $self->{_origin_y}; for my $line (@$input_array){ if(1==$self->{_row_names}){ $xpos = $self->{_origin_x} + $self->{_label_x}; $ypos -= $self->{_step}; my $line_label = shift @$line; $p->setcolour("black"); $p->setfont("Times-Roman", 20); $p->text( $self->{_origin_x}, $ypos, $line_label ); } # my $outarrayline = colourdiff($line); my $outarrayline = $line; for my $colourbox (@$outarrayline){ # $p->setcolour(colour_from_number($colourbox)); #SCAFFOLDING # for my $scaffold (@$colourbox){my ($r, $g, $b)=@$scaffold;print "($r, $g, $b)";} # print "Next"; #SCAFFOLDING for my $colour (@$colourbox){ my ($r,$g,$b) = @$colour; $p->setcolour($r,$g,$b); # $p->setcolour(0,0,0); $p->box( {filled=>1}, ($xpos - $self->{_step}), ($ypos + $self->{_step}), $xpos, $ypos, ); $xpos += $self->{_step}; } } } #http://www.unix.org.ua/orelly/perl/prog/ch03_102.htm $p->output(">-"); } sub colour_from_number{ my $number = shift; # my $p = shift; if (0>$number){ # $p->setcolour(0,0,$number); return (0,0,abs ($number)); } elsif (0<$number){ # $p->setcolour($number,0,0); return ($number,0,0); }else{ # $p->setcolour(0,0,0); return (0,0,0); } } sub colourdiff{ my $i = shift; # my @outarray; my @outarrayline; my @sorted = sort{abs($a)<=>abs($b)} @$i; my $greatest = abs($sorted[$#sorted]); # print $greatest ,"\n"; for my $j (@$i){ # print "$j = ", (($j-@$i[0])/$greatest * 255); my @value = colour_from_number((($j-@$i[0])/$greatest * 255)); # push @outarrayline, (($j-@$i[0])/$greatest * 255); # push @outarrayline, \@value; push @outarrayline, \@value; # print $j; } return \@outarrayline; } 1; __END__ =head1 NAME Chart::HeatMap::Simple - Perl extension for producing a simple heatmap graph =head1 SYNOPSIS use Chart::HeatMap::Simple; my @array; while (){ my @line = split (/[,\t]/,$_); push @array, \@line; } my $HeatMap = new Chart::HeatMap::Simple(_input_array=>\@array); $HeatMap->render_heatmap(); =head1 DESCRIPTION Chart::HeatMap::Simple is an easy way to produce heatmaps from arbitary 2D arrays. It uses only one dependency PostScript::Simple and features a programmer replacable colour distribution. =head2 EXPORT new render_heatmap compare_to_first_column =head1 SEE ALSO =head1 AUTHOR Thuan-Jin Kee, Ejin.kee@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright (C) 2007 by Thuan-Jin Kee This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. =cut Chart-HeatMap-Simple/MANIFEST0000664000076400007640000000013110564217223015317 0ustar jinkeejinkeeChanges Makefile.PL MANIFEST README t/Chart-HeatMap-Simple.t lib/Chart/HeatMap/Simple.pm Chart-HeatMap-Simple/Changes0000664000076400007640000000026410564217223015470 0ustar jinkeejinkeeRevision history for Perl extension Chart::HeatMap::Simple. 0.01 Tue Feb 13 13:12:35 2007 - original version; created by h2xs 1.23 with options -XA -n Chart::HeatMap::Simple Chart-HeatMap-Simple/t/0000775000076400007640000000000010564217223014436 5ustar jinkeejinkeeChart-HeatMap-Simple/t/Chart-HeatMap-Simple.t0000664000076400007640000000075410564217223020436 0ustar jinkeejinkee# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Chart-HeatMap-Simple.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Chart::HeatMap::Simple') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script.