2020-11-26

#! usr/bin/env perl -w
use SVG;
use FontSize;
use strict;

my $hap1_len = shift;
my $hap2_len = shift;
my $hap1_bed = shift;
my $hap2_bed = shift;
open hap1,"<$hap1_len" or die $!;
open hap2,"<$hap2_len" or die $!;
open hapbed1,"<$hap1_bed" or die $!;
open hapbed2,"<$hap2_bed" or die $!;
my $LINE1;
my $LINE2;
my $svg=SVG->new('width',1800,'height',600);
my $inside1;
my $y1;
my $width1;
my $inside2;
my $x2;
my $y2;
my $width2;
my $name;
my $y_extra;
my $ration=1/400000;
while ($LINE1 = <hap1>) {
        chomp($LINE1);
        my @line1=split (/\s+/,$LINE1);
        foreach $inside1 (@line1){
                if ($inside1=~/chr(\d+)/){
                        $y1=85+50*(10-$1);
                        $width1=($line1[2])*$ration;
                        $name="chr$1";
                        $y_extra=105+50*(10-$1);
                        $svg->text('x',925,'y',$y_extra,'-cdata',$name,'fill','black','front-size',200,'text-anchor','middle');
                        $svg->rect('x',950,'y',$y1,'width',$width1,'height',30,'stroke','black','fill','white');
                }
                else{
                        next;
                }
         }
}
while ($LINE2 = <hap2>){
        chomp ($LINE2);
        my @line2=split(/\s+/,$LINE2);
        foreach $inside2 (@line2){
                if ($inside2=~/chr(\d+)/){
                        $x2 = 850-($line2[2])*$ration;
$y2 = 85+50*(10-$1);
                        $width2=($line2[2])*$ration;
                        $svg->rect('x',$x2,'y',$y2,'width',$width2,'height',30,'stroke','black','fill','white');

                }
                else{
                        next;
                }
        }
}
my $LINE3;
my $LINE4;
my $inside3;
my $x3;
my $y3;
my $width3;
my $color;
my $inside4;
my $x4;
my $y4;
my $width4;

while ($LINE3 = <hapbed1>){
        chomp($LINE3);
        my @line3=split (/\s+/,$LINE3);
foreach $inside3 (@line3){
                 if ($inside3=~/chr(\d+)/){
                         $x3=950+($line3[1])*$ration;
                         $y3=85+50*(10-$1);
                         $width3=($line3[2]-$line3[1])*$ration;
                                if ($line3[3]=~/B73_only/){
                                        $color='#87CEEB';
                                }
                                else{
                                        $color='#FFE384';
                                }

                         $svg->rect('x',$x3,'y',$y3,'width',$width3,'height',30,'stroke','white','fill',$color);
                 }
                 else{
                         next;
                 }
          }
}
while ($LINE4=<hapbed2>){
        chomp($LINE4);
        my @line4=split(/\s+/,$LINE4);
foreach $inside4 (@line4){
                if ($inside4=~/chr(\d+)/){
                        $x4=850-($line4[2])*$ration;
                        $y4=85+50*(10-$1);
                        $width4=($line4[2]-$line4[1])*$ration;
                                  if ($line4[3]=~/B73_only/){
                                          $color='#87CEEB';
                                  }
                                  else{
                                          $color='#FFE384';
                                  }

                           $svg->rect('x',$x4,'y',$y4,'width',$width4,'height',30,'stroke','white','fill',$color);
                   }
                   else{
                           next;
                   }
                }
}
close hap1;
close hap2;
close hapbed1;
close hapbed2;
$svg->line('x1',950,'y1',575,'x2',950+306000000*$ration,'y2',575,'stroke','black','stroke-width',1);
$svg->line('x1',850,'y1',575,'x2',850-306000000*$ration,'y2',575,'stroke','black','stroke-width',1);
my @num=(1..4);
my $x5;
my $x6;
my $i;
my $name1;
my $numb;
foreach $i (@num){
        $x5=950+($i-1)*100000000*$ration;
        $x6=850-($i-1)*100000000*$ration;
        $numb=($i-1)*100;
        $name1="$numb";
        $svg->line('x1',$x5,'y1',575,'x2',$x5,'y2',580,'stroke','black','stroke-width',1);
        $svg->line('x1',$x6,'y1',575,'x2',$x6,'y2',580,'stroke','black','stroke-width',1);
        $svg->text('x',$x5+21,'y',598,'-cdata',$name1,'fill','black','front-size',50,'text-anchor','middle');
        $svg->text('x',$x6+21,'y',598,'-cdata',$name1,'fill','black','front-size',50,'text-anchor','middle');

}

$svg->text('x',1755,'y',598,'-cdata','Mb','fill','black','front-size',50,'text-anchor','middle');
$svg->text('x',75,'y',598,'-cdata','Mb','fill','black','front-size',50,'text-anchor','middle');


print $svg->xmlify();

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页