#!perl
use warnings;
use strict;
use SVG;
use File::Basename qw(basename);
die "perl $0 <sample.list> <pathway.sorted> <outprefix>
Note: support 24 colors to sample~
" if @ARGV != 3;
my (@file, @pwtmp, @pw2sp);
my $i = 0;
open PW, $ARGV[1] or die $!;
while(<PW>)
{
chomp;
my @tmp = split / /;
$pwtmp[$i]{$tmp[0]} = 1;
$i ++;
}
my $f = 0;
open SP, $ARGV[0] or die $!;
while(<SP>)
{
chomp;
my @ft = split;
my $name = basename($ft[0]);
my ($id) = $ft[0] =~ /^([^.]+)/;
push @file, $ft[1];
open FA, $ft[0] or die $!;
<FA>;
for(my $n = 0; $n < @pwtmp; $n ++)
{
$pw2sp[$f][$n] = 1;
}
while(my $line = <FA>)
{
chomp($line);
my @tmp = split / /, $line;
for(my $j = 0; $j < @pwtmp; $j ++)
{
if(exists $pwtmp[$j]{$tmp[0]})
{
$pw2sp[$f][$j] = $tmp[4];
last;
}
}
}
$f ++;
}
my $fn = @file;
my $pwn = @pwtmp;
my $svg = SVG->new(width => ($fn * 50 + 1100), height => ($pwn * 50 + 300));
$svg->rect(x => 55, y => 55, width => (($fn + 1) * 50 + 10), height => (($pwn + 1) * 50 + 10), fill => "white", stroke => "grey", 'stroke-width' => 8);
for(my $j = 0; $j < @pwtmp; $j ++)
{
my $n = $j + 1;
$svg->line(x1 => 60, y1 => (60 + $n * 50), x2 => (60 + ($fn+1) * 50), y2 => (60 + $n * 50), stroke => "orange", 'stroke-width' => 3);
foreach my $pc(keys %{$pwtmp[$j]})
{
$svg->text(x => (($fn + 1) * 50 + 70), y => 65 + $n * 50, style => {'font' => 'Times new roman', 'font-size' => 30, 'font-weight' => 'bold'})->cdata($pc);
}
}
my @color = ('red', 'green', 'blue', 'yellow', 'cyan', 'purple', 'sandybrown', 'navy', 'violet', 'darksalmon', 'bisque', 'fuchsia', 'lightcoral', 'goldenrod', 'silver', 'brown', 'lawngreen', 'skyblue', 'indigo', 'forestgreen', 'lightseagreen', 'aqua', 'lime');
#my @color = ('red', 'red', 'green', 'green', 'blue', 'blue', 'yellow', 'yellow');
my $column = 0;
my $row = 0;
for(my $j = 0; $j < @file; $j ++)
{
my $n = $j + 1;
my $rx = 75 + $n * 50 + int(length($file[$j]) / 2) * 14;
my $ry = 80 + ($pwn + 1) * 50 + length($file[$j]) * 12;
$svg->line(x1 => (60 + $n * 50), y1 => 60, x2 => (60 + $n * 50), y2 => (60 + ($pwn + 1) * 50), stroke => "orange", 'stroke-width' => 3);
$svg->text(x => (60 + $n * 50), y => (80 + ($pwn + 1) * 50), style => {'font' => 'Times new roman', 'font-size' => 25, 'font-weight' => 'bold'}, 'transform' => "rotate(⑷5, $rx, $ry)")->cdata($file[$j]);
for(my $k = 0; $k < @{$pw2sp[$j]}; $k ++)
{
if($pw2sp[$j][$k] >= 0.05)
{
$svg->circle(cx => (60 + $n * 50), cy => (60 + ($k+1) * 50), r => 1, fill => $color[$j], stroke => 'black');
}elsif($pw2sp[$j][$k] < 0.05 and $pw2sp[$j][$k] >= 0.01){
$svg->circle(cx => (60 + $n * 50), cy => (60 + ($k+1) * 50), r => 20, fill => $color[$j], stroke => 'black');
}else{
$svg->circle(cx => (60 + $n * 50), cy => (60 + ($k+1) * 50), r => 45, fill => $color[$j], stroke => 'black');
}
}
if(($n / 6) =~ /./)
{
$svg->circle(cx => (250 + (@file + 1) * 50 + $column * 100), cy => (75 + ($pwn + 1) * 50 + $row * 75), r => 20, fill => "$color[$j]", stroke => 'black');
$svg->text(x => (250 + (@file + 1) * 50 + $column * 100), y => (110 + ($pwn + 1) * 50 + $row * 75), style => {'font' => 'Times new roman', 'font-size'=> 15,'font-weight' => 'bold'})->cdata($file[$j]);
$column ++;
}else{
$svg->circle(cx => (250 + (@file + 1) * 50 + $column * 100), cy => (75 + ($pwn + 1) * 50 + $row * 75), r => 20, fill => "$color[$j]", stroke => 'black');
$svg->text(x => (250 + (@file + 1) * 50 + $column * 100), y => (110 + ($pwn + 1) * 50 + $row * 75), style => {'font' => 'Times new roman', 'font-size'=> 15,'font-weight' => 'bold'})->cdata($file[$j]);
$row ++;
$column = 0;
}
}
$svg->circle(cx => (100 + (@file + 1) * 50), cy => (75 + ($pwn + 1) * 50), r => 20, fill => 'sandybrown', stroke => 'black');
$svg->circle(cx => (100 + (@file + 1) * 50), cy => (150 + ($pwn + 1) * 50), r => 45, fill => 'sandybrown', stroke => 'black');
$svg->text(x => (122 + (@file + 1) * 50), y => (75 + ($pwn + 1) * 50), style => {'font' => 'Times new roman', 'font-size'=> 15,'font-weight' => 'bold'})->cdata("FDR < 0.05");
$svg->text(x => (147 + (@file + 1) * 50), y => (150 + ($pwn + 1) * 50), style => {'font' => 'Times new roman', 'font-size'=> 15,'font-weight' => 'bold'})->cdata("FDR < 0.01");
open OUT, "> $ARGV[2].svg" or die $!;
print OUT $svg->xmlify;