#!/usr/bin/perl
use SVG;
use FontSize;
use strict;
use Getopt::Long;
my $coords=shift;
open IN,"< $coords" or die $!;
my %data;
my %count;
my ($min, $max)=(1000000000,0);
my @color=('purple','blue','yellow','green','blue','red','black');
while(<IN>){
chomp;
my @line=split(/\s+/,$_);
$min=$min<$line[0]?$min:$line[0];
$max=$max>$line[1]?$max:$line[1];
push @{$data{$line[12]}},[$line[0],$line[1],$line[3],$line[4]];
}
close IN;
my $width=1200;
my $height=1200;
my $x_ratio=1000/($max-$min+1);
my $svg = SVG->new('width',$width,'height',$height);
$svg->line('x1',100,'y1',100,'x2',100,'y2',1100,'stroke','black','stroke-width',1);
$svg->line('x1',100,'y1',100,'x2',1100,'y2',100,'stroke','black','stroke-width',1);
$svg->line('x1',1100,'y1',100,'x2',1100,'y2',1100,'stroke','black','stroke-width',1);
$svg->line('x1',100,'y1',1100,'x2',1100,'y2',1100,'stroke','black','stroke-width',1);
my $yshift=1100;
my $color_index=0;
foreach my $scaf (keys %data){
my @array=sort {$a->[2]<=>$b->[2]} @{$data{$scaf}};
# my ($ymin,$ymax)=($array[0][0],$array[0][0]);
my @tmp=($array[0][2],$array[0][3],$array[-1][2],$array[-1][3]);
my($ymin,$ymax)=(1000000000,0);
for(my $x=0;$x<@tmp;$x++){
$ymin=$ymin<$tmp[$x]?$ymin:$tmp[$x];
$ymax=$ymax>$tmp[$x]?$ymax:$tmp[$x];
}
my $sub_color=$color[$color_index];
for(my $i=0;$i<@array;$i++){
my $x1=100+($array[$i][0]-$min+1)*$x_ratio;
my $x2=100+($array[$i][1]-$min+1)*$x_ratio;
my $y1=$yshift-($array[$i][2]-$ymin+1)*$x_ratio;
my $y2=$yshift-($array[$i][3]-$ymin+1)*$x_ratio;
$svg->line('x1',$x1,'y1',$y1,'x2',$x2,'y2',$y2,'stroke',$sub_color,'stroke-width',1);
}
$yshift-=($ymax-$ymin+1)*$x_ratio;
$color_index++;
$svg->line('x1',100,'y1',$yshift,'x2',1100,'y2',$yshift,'stroke','black','stroke-width',1);
}
print $svg->xmlify();
2021-01-17
最新推荐文章于 2024-04-17 00:15:12 发布