modified: n.fq
[GalaxyCodeBases.git] / tools / svg / synteny / draw_synteny_OO.pl
blob70f07eba9ae1c3c01443fa8b93cda1db005a2a6f
1 #!/bin/env perl
3 =head1 Name
5 draw_synteny_OO.pl -- draw synteny figure between two sequences (OO version)
7 =head1 Description
9 draw linear figures for synteny analysis with nucmer result,
10 also add gene and TE elements to svg figure.
12 =head1 Version
14 Author: Hu Xuesong, huxuesong@genomics.org.cn
15 Version: 1.0, Date: 2009-12-14
17 =head1 Usage
19 perl draw_synteny_parallel_melon4.pl [options]
20 --width <int> set the image width (1200)
21 --height <int> set the image height (720)
22 --chr <file> set the chromosome length file
23 --list <file> set the pairwise relation list file
24 // --scale <int> set the unit for big scales
25 // --resolution <float> set the figure resolution, default 100000
26 --synteny_heigth <int> set the height of each unit of synteny figure, default=60
27 --gene1 <file> draw exon-intron structure for one gene set
28 --gene2 <file> draw exon-intron structure for another gene set
29 --TE1 <file> draw colorful blocks for one TE set
30 --TE2 <file> draw colorful blocks for another TE set
31 --contig1 <file> draw contigs for one scaffold set
32 --contig2 <file> draw contigs for another scaffold set
33 --outdir <str> set the output directory
34 --verbose output verbose information to screen
35 --help output help information to screen
37 =head1 Exmple
39 perl draw_synteny_OO.pl --synteny_heigth 150 --scale 10000 --resolution 100 -chr ./melon_cucumber_chrs.list --list ./melo_4BACs.delta.filter.coords.list --gene1 ./melo_4BACs.gbk.noTE.gff -TE1 ./melo_4BACs.fa.TE.gff --gene2 ./cucumber.3scaffs.gene.gff.need.noTE.gff --TE2 ./cucumber.scaffs.TE.gff
41 =cut
43 use strict;
44 use warnings;
45 use Getopt::Long;
46 use FindBin qw($Bin $Script);
47 use File::Basename qw(basename dirname);
48 use Data::Dumper;
49 use lib "$Bin/../lib";
50 use lib 'U:\dev\sda\5\develop\ActivePerl510\Perl64\site\lib\\';
51 use SVG;
52 use FontSize;
54 #my $figure_resolution; ##one point stands for 10000 bp
55 #my $big_scale;
56 my ($synteny_heigth);
57 my ($Gene1_file,$TE1_file,$Gene2_file,$TE2_file,$contig1_file,$contig2_file,$depth_file,$img_width,$img_height);
58 my ($pairwise_file,$chr_len_file1);
59 my ($Verbose,$Help,$Outdir);
60 GetOptions(
61 "width:i"=>\$img_width,
62 "height:i"=>\$img_height,
63 "chr:s"=>\$chr_len_file1,
64 "list:s"=>\$pairwise_file,
65 # "scale:i"=>\$big_scale,
66 # "resolution:f"=>\$figure_resolution,
67 "synteny_heigth:i"=>\$synteny_heigth,
68 "gene1:s"=>\$Gene1_file,
69 "gene2:s"=>\$Gene2_file,
70 "TE1:s"=>\$TE1_file,
71 "TE2:s"=>\$TE2_file,
72 "contig1:s"=>\$contig1_file,
73 "contig2:s"=>\$contig2_file,
74 "outdir:s"=>\$Outdir,
75 "verbose"=>\$Verbose,
76 "help"=>\$Help
78 $img_width ||=1200;
79 $img_height ||=720;
80 #$figure_resolution ||= 100000;
81 #$big_scale ||= 10000000;
82 $synteny_heigth ||= 60;
83 $Outdir ||= ".";
84 die `pod2text $0` if (!$chr_len_file1 || !$pairwise_file || $Help);
86 #Contig_4 1 97799 scaffold375 1 34612 -
87 #Contig_4 1 97799 scaffold2282 377 67038 +
88 sub read_chromosome_file($$) {
89 my $chromosome_file=shift;
90 my $chromosome_p=shift;
91 open CHR,$chromosome_file or die "[x]$!";
92 while(<CHR>) {
93 chomp;
94 next if $_=~/^chr_id\t/;
95 s/^\s+//;
96 next if(!$_);
97 my @t = split /\s+/;
98 push @{$chromosome_p->{$t[0]}}, \@t;
100 close CHR;
103 #Contig_1_4 Contig_1 - 79705 59416 scaffold629_4 scaffold629 + 2529462 2550090
104 #Contig_2_5 Contig_2 + 1 6619 scaffold421_5 scaffold421 + 290060 296703
105 sub read_pairwise_file {
106 my $pairwise_file = shift;
107 my $synteny_p = shift;
108 open IN, $pairwise_file || die "[x]Fail open $pairwise_file !";
109 while (<IN>) {
110 chomp;
111 my ($gene1,$chr1,$strand1,$start1,$end1,$gene2,$chr2,$strand2,$start2,$end2) = split /\s+/;
112 push @$synteny_p,[$gene1,$start1,$end1,$strand1,$gene2,$start2,$end2,$strand2,$chr1,$chr2];
114 close IN;
117 #Contig_8 BGI mRNA 10453 11903 . + . ID=Apl_00006;
118 #Contig_8 BGI CDS 10453 10464 . + 0 Parent=Apl_00006;
119 #Contig_8 BGI CDS 11887 11903 . + 0 Parent=Apl_00006;
120 sub read_gene_gff($$) {
121 my $file=shift;
122 my $ref=shift;
123 open (IN,$file) || die ("[x]Fail open $file !\n");
124 while (<IN>) {
125 chomp;
126 s/^\s+//;
127 next if(/^\#/);
128 my @t = split(/\t/);
129 my $tname = $t[0];
130 my $qname;
131 if ($t[2] eq 'mRNA' || $t[2] eq 'CDS'|| $t[2] eq 'CDs') {
132 $qname = $1 if($t[8] =~ /^GenePrediction\s+(\S+)/ || $t[8] =~ /^ID=(\S+?);/ || $t[8] =~ /^Parent=(\S+?);/);
134 if ($t[2] eq 'match' || $t[2] eq 'HSP') {
135 $qname = $1 if($t[8] =~ /Target\s+\"(\S+)\"/);
137 if ($t[2] eq 'mRNA' || $t[2] eq 'match') {
138 my $start = $t[3];
139 my $end = $t[4];
140 my $strand = $t[6];
141 $ref->{$tname}{$qname}{strand} = $strand;
142 $ref->{$tname}{$qname}{start} = $start;
143 $ref->{$tname}{$qname}{end} = $end;
145 if ($t[2] eq 'CDS' || $t[2] eq 'HSP'|| $t[2] eq 'CDs') {
146 # print "$tname\t$qname\n";
147 push @{$ref->{$tname}{$qname}{exon}}, [$t[3],$t[4]] if(exists $ref->{$tname}{$qname});
150 close(IN);
152 foreach my $scaff (sort keys %$ref) {
153 my $scaff_p = $ref->{$scaff};
154 # print Dumper ($ref->{$scaff});
155 foreach my $gene (sort keys %$scaff_p) {
156 # print Dumper ($ref->{$scaff});
157 my $gene_p = $scaff_p->{$gene};
158 my @exon = @{$gene_p->{exon}};
159 @exon = reverse @exon if($exon[0][0] > $exon[-1][0]);
160 my @new;
161 foreach my $p (@exon) {
162 push @new,$p->[0],$p->[1];
164 $ref->{$scaff}{$gene}{exon} = \@new;
169 ##gff-version 3
170 #scaffold375 RepeatMasker Transposon 1 3000 1611 + . ID=TE055206;Target=CR1-Y2_Aves 340 1177;Class=LINE/CR1;PercDiv=29.0;PercDel=2.9;PercIns=0.2;
171 sub read_TE_gff($$) {
172 my $file=shift;
173 my $ref=shift;
174 open (IN,$file) || die ("[x]Fail open $file !\n");
175 while (<IN>) {
176 chomp;
177 s/^\s+//;
178 next if(/^\#/);
179 my @t = split(/\t/);
180 my $tname = $t[0];
181 my $qname = $1 if($t[8] =~ /^ID=([^;]+);*/);
182 my $type = $1 if($t[8] =~ /Class=([^\/;]+)/);
183 my $start = $t[3];
184 my $end = $t[4];
185 my $strand = $t[6];
186 $ref->{$tname}{$qname} = [$start,$end,$strand,$type];
188 close(IN);
191 #Contig_4 1 7836
192 #Contig_4 8956 26732
193 sub read_contig_list($$) {
194 my $file=shift;
195 my $hash_p=shift;
196 open IN,$file or die "[x]Fail open $file !\n";
197 while(<IN>) {
198 chomp;
199 my @ary=split /\t/;
200 push @{$hash_p->{$ary[0]}},[$ary[1],$ary[2]];
202 close IN;
210 my $pairwise_file_base = basename($pairwise_file);
211 $Outdir =~ s/\/$//;
212 mkdir $Outdir unless (-d $Outdir);
214 my %Chr1;
215 my @Synteny;
217 #$figure_resolution = 1 / $figure_resolution;
219 my (%SVG,@Show);
220 my @Order=('Ruler1','mRNA1','TE1','Name1','Bar1','Synteny',
221 'Bar2','Name2','TE2','mRNA2','Ruler2');
222 our %Heights=(
223 Ruler1 => 20,
224 Ruler2 => 20,
225 mRNA1 => 15,
226 mRNA2 => 15,
227 TE1 => 15,
228 TE2 => 15,
229 Name1 => 10,
230 Name2 => 10,
231 Bar1 => 15,
232 Bar2 => 15,
233 Synteny => $synteny_heigth
235 my $Y_junt=10;
236 my %toShow=(
237 Ruler1 => 1,
238 Ruler2 => 1,
239 Name1 => 1,
240 Name2 => 1,
241 Bar1 => 1,
242 Bar2 => 1,
243 Synteny => 1,
246 ##read data into memory
247 read_chromosome_file($chr_len_file1,\%Chr1);
248 read_pairwise_file($pairwise_file,\@Synteny);
250 my (%Gene1,%Gene2,%TE1,%TE2,%contig1,%contig2,%depth);
251 read_gene_gff($Gene1_file,\%Gene1) if(defined $Gene1_file);
252 read_gene_gff($Gene2_file,\%Gene2) if(defined $Gene2_file);
253 read_TE_gff($TE1_file,\%TE1) if(defined $TE1_file);
254 read_TE_gff($TE2_file,\%TE2) if(defined $TE2_file);
255 read_contig_list($contig1_file,\%contig1) if(defined $contig1_file);
256 read_contig_list($contig2_file,\%contig2) if(defined $contig2_file);
257 ##figure parameters setting
258 our $font = FontSize->new();
259 our $font_family = "Arial";
260 #my $font_size = 24; # stringHeight = int($size*0.72); => font_size = stringHeight / 0.72
261 our $x_margin = 20;
262 my $y_margin = 20;
263 my $Seq2_junt=1000;
265 my %Synteny_length_bp;
266 for my $key (keys %Chr1) {
267 my ($Seq1_name,$Seq1_start,$Seq1_end) = @{${$Chr1{$key}}[0]};
268 my $Seq2_lenA = 0;
269 my $Seq1_len = $Seq1_end - $Seq1_start +1;
270 for (@{$Chr1{$key}}) {
271 my ($Seq1_name,$Seq1_start,$Seq1_end,$Seq2_name,$Seq2_start,$Seq2_end,$Reverse) = @$_;
272 #$Seq1_lenA = $Seq1_end - $Seq1_start;
273 $Seq2_lenA += $Seq2_junt if $Seq2_lenA;
274 $Seq2_lenA += $Seq2_end - $Seq2_start +1;
276 $Synteny_length_bp{$key} = ($Seq1_len >= $Seq2_lenA) ? $Seq1_len : $Seq2_lenA;
277 my $X_start=0;
279 # Ruler1
280 #plot_ruler("svg",$svg,"Y",$backbone2_height + 100 + $y_margin, "X_start",$synteny_Xstart+$X_start,"X_end",$synteny_Xstart+$X_start+$Seq2_len* $figure_resolution,"bp_start",$Seq2_start,"bp_end",$Seq2_end,"scaletype","Kb","scaletypepos","right","scalestart","auto","rulerstyle",2,"bigscalesize",$big_scale);
281 push @{$SVG{$key}{'Ruler1'}},[0,$Seq1_start,$Seq1_len];
283 if(defined $contig1_file && exists $contig1{$Seq1_name}) {
284 $toShow{'Bar1'}=1;
285 for (@{$contig1{$Seq1_name}}) {
286 my ($start,$end)=@$_;
287 my $str='1: '.$Seq1_name;
288 push @{$SVG{$key}{'Bar1'}},[$str,$start-$Seq1_start+1,$end-$start+1,'black'];#($str,$margin+$start,$len,$color)
292 $SVG{$key}{'Name1'}=[[$Seq1_name,0,$Seq1_len]];
293 if (defined $TE1_file && exists $TE1{$Seq1_name}) {
294 $toShow{'TE1'}=1;
295 my $Seq1_p = $TE1{$Seq1_name};
296 foreach my $TE1_id (sort keys %$Seq1_p) {
297 my $TE1_p = $Seq1_p->{$TE1_id}; ##$ref->{$tname}{$qname} = [$start,$end,$strand,$type];
298 my ($start,$end,$strand,$type) = @$TE1_p;
299 my $str=join(': ',$type,$TE1_id);
300 push @{$SVG{$key}{'TE1'}},[$str,$start-$Seq1_start+1,$end-$start+1];#($str,$margin+$start,$len)
304 if (defined $Gene1_file && exists $Gene1{$Seq1_name}) {
305 $toShow{'mRNA1'}=1;
306 my $Seq1_p = $Gene1{$Seq1_name};
307 foreach my $gene1_id (keys %$Seq1_p) {
308 my @StartEndStrandFull=($Seq1_p->{$gene1_id}{start}-$Seq1_start+1,$Seq1_p->{$gene1_id}{end}-$Seq1_start+1,$Seq1_p->{$gene1_id}{strand},1);
309 #next if ($StartEndStrand[0] > $Seq1_end or $StartEndStrand[1] < $Seq1_start);
310 if ($StartEndStrandFull[0] < $Seq1_start-$Seq2_junt/2) {
311 $StartEndStrandFull[3]=0;
312 $StartEndStrandFull[0]=$Seq1_start-$Seq2_junt/2;
314 if ($StartEndStrandFull[1] > $Seq1_end+$Seq2_junt/2) {
315 $StartEndStrandFull[3]=0;
316 $StartEndStrandFull[1]=$Seq1_end+$Seq2_junt/2;
318 my @exon = @{$Seq1_p->{$gene1_id}{exon}};
319 #my $gene1_strand = $Seq1_p->{$gene1_id}{strand};
320 my @X_exon;
321 #push @X_exon,$_-$Seq1_start+1 for (@exon);
322 for (@exon) {
323 my $pos=$_-$Seq1_start+1;
324 $pos=-$Seq2_junt/2 if $pos<-$Seq2_junt/2;
325 $pos=$Seq1_end+$Seq2_junt/2 if $pos>$Seq1_end+$Seq2_junt/2;
326 push @X_exon,$pos;
328 push @{$SVG{$key}{'mRNA1'}},[$gene1_id,\@StartEndStrandFull,\@X_exon];
332 my $count2=0;
333 for (@{$Chr1{$key}}) {
334 ++$count2;
335 my ($Seq1_name,$Seq1_start,$Seq1_end,$Seq2_name,$Seq2_start,$Seq2_end,$Reverse) = @$_;
336 #my $Seq1_len = $Seq1_end - $Seq1_start +1;
337 my $Seq2_len = $Seq2_end - $Seq2_start +1;
338 push @{$SVG{$key}{'Ruler2'}},[$X_start,$Seq2_start,$Seq2_len];
339 #$SVG{$key}{'Name1'}=[[$Seq1_name,0,$Seq1_len]];
340 push @{$SVG{$key}{'Name2'}},[$Seq2_name,$X_start,$Seq2_len];
342 # »¹Ã»¿¼ÂǸºÁ´¡­¡­
343 if(defined $contig2_file && exists $contig2{$Seq2_name}) {
344 $toShow{'Bar2'}=1;
345 for (@{$contig2{$Seq2_name}}) {
346 my ($start,$end)=@$_;
347 my $str="$count2: $Seq2_name";
348 push @{$SVG{$key}{'Bar2'}},[$str,$X_start+$start-$Seq2_start+1,$end-$start+1,'black'];#($str,$margin+$start,$len,$color)
352 if (defined $TE2_file && exists $TE2{$Seq2_name}) {
353 $toShow{'TE2'}=1;
354 my $Seq2_p = $TE2{$Seq2_name};
355 foreach my $TE2_id (sort keys %$Seq2_p) {
356 my $TE2_p = $Seq2_p->{$TE2_id}; ##$ref->{$tname}{$qname} = [$start,$end,$strand,$type];
357 my ($start,$end,$strand,$type) = @$TE2_p;
358 next if ($end<$Seq2_start or $start>$Seq2_end);
359 my $str=join(': ',$type,$TE2_id);
360 my $len=$end-$start+1;
361 if ($Reverse eq "-") {
362 $start = $Seq2_end - $end +1;
364 my $begin=$start-$Seq2_start+1;
365 if ($begin<-$Seq2_junt/3) {
366 $len += $begin+$Seq2_junt/3;
367 $begin=-$Seq2_junt/3;
369 push @{$SVG{$key}{'TE2'}},[$str,$X_start+$begin,$len];
375 $X_start += $Seq2_len + $Seq2_junt;
379 our $WidthPoint;
380 our $HeightPoint;
381 for (@Order) {
382 if (defined $toShow{$_}) {
383 push @Show,$_;
384 $HeightPoint += $Heights{$_} + $Y_junt;
387 $HeightPoint -= $Y_junt;
388 $HeightPoint = ($img_height-2*$y_margin)/$HeightPoint;
389 our ($Y_start,$svg);
390 #our $MaxLenBP;
391 my $Ln10=2.30258509299405;
392 my $Lg2=0.301029995663981;
393 my $Lg5=0.698970004336019;
394 our $OTF; # One,Two,Five
395 our ($cStepN,$cStepKMGT,$cStepKMGTn); # cent. step
397 for my $key (keys %SVG) {
398 my $MaxLenBP = $Synteny_length_bp{$key};
399 my $LG_MaxLenBP = log($MaxLenBP)/$Ln10;
400 $WidthPoint = ($img_width-2*$x_margin)/$MaxLenBP;
401 # for Ruler
402 my $LG_Main=int($LG_MaxLenBP);
403 my $LG_suf=$LG_MaxLenBP-$LG_Main;
404 $cStepN=$LG_Main-1;
405 if ($LG_suf==0) { $OTF=1; }
406 elsif ($LG_suf<=$Lg2) { $OTF=2; }
407 elsif ($LG_suf<=$Lg5) { $OTF=5; }
408 elsif ($LG_suf<=1) { $OTF=10;$cStepN=$LG_Main; }
409 else { $OTF=20;$cStepN=$LG_Main; } # impossible
410 =pod
411 if ($cStepN>=24) {$cStepKMGT='Y';$cStepKMGTn=1000000000000000000000000;}
412 elsif ($cStepN>=21) {$cStepKMGT='Z';$cStepKMGTn=1000000000000000000000;}
413 elsif ($cStepN>=18) {$cStepKMGT='E';$cStepKMGTn=1000000000000000000;}
414 elsif ($cStepN>=15) {$cStepKMGT='P';$cStepKMGTn=1000000000000000;}
416 =cut No Genome can larger than 1P. Human only 3G.
417 if ($cStepN>=12) {$cStepKMGT='T';$cStepKMGTn=1000000000000;}
418 elsif ($cStepN>=9) {$cStepKMGT='G';$cStepKMGTn=1000000000;}
419 elsif ($cStepN>=6) {$cStepKMGT='M';$cStepKMGTn=1000000;}
420 elsif ($cStepN>=3) {$cStepKMGT='K';$cStepKMGTn=1000;}
421 else {$cStepKMGT='';$cStepKMGTn=1;}
422 $cStepN=$OTF*10^($LG_Main-2);
424 $svg = SVG->new('width',$img_width,'height',$img_height);
425 $svg->rect('x',0,'y',$img_height/2,'height',$y_margin,'width',$img_width,'fill','black');
426 $svg->rect('x',$x_margin,'y',$y_margin,'height',$img_height-2*$y_margin,'width',$img_width-2*$x_margin,'stroke','black','fill','rgb(196,196,196)');
427 $Y_start=$y_margin;
428 open OUT, ">$Outdir/$key.synteny.svg" || die "[x]Fail create $!";
429 for my $ss (@Show) {
430 no strict 'refs';
431 $ss =~ /^([^\d]+)(\d)$/;
432 my $Func='SVG_'.$1;
433 my $OE=($2==2);
434 &$Func($ss,$_,$OE) for (@{$SVG{$key}{$ss}});
435 $Y_start += ($Y_junt + $Heights{$ss})*$HeightPoint;
437 $svg->rect('x',0,'y',0,'height',$img_height,'width',$x_margin/2,'fill','white');
438 $svg->rect('x',$img_width-$x_margin/2,'y',0,'height',$img_height,'width',$x_margin/2,'fill','white');
439 print OUT $svg->xmlify();
440 close OUT;
442 print "$WidthPoint,$HeightPoint,$svg\n";
443 sub SVG_Name($$$) {
444 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');
445 my ($str,$margin,$len)=@{$_[1]};
446 my $height=$Heights{$_[0]}*$HeightPoint;#*.8;
447 #my $OE=$_[2];
448 my $Y0=$Y_start+$_[2]*$Heights{$_[0]}*$HeightPoint;#*.8;
449 my $font_size = int($height / .72);
450 my $name_width = $font->stringWidth($font_family,$font_size,$str);
451 #$name_width=0;
452 my $x=$x_margin+(($len+$margin+$margin)*$WidthPoint-$name_width)/2;
453 $svg->text('x',$x,'y',$Y0+$height*(!$_[2]),'-cdata',$str,'font-family',$font_family,'font-size',$font_size);
454 #$svg->line('x1',$x_margin,'y1',$Y_start,'x2',$x+$name_width/2,'y2',$Y0,'stroke','#000000','stroke-width',1);
455 print "$_[0],$str,$margin,$len\t$Y_start\t$name_width,$font_size\n";
458 sub SVG_Ruler($$) {
459 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');
460 ### Use $WidthPoint; $MaxLenBP; $cStepN,$cStepKMGT,$cStepKMGTn
461 my ($margin,$start,$len)=@{$_[1]};
462 my $height=$Heights{$_[0]}*$HeightPoint;
463 my $g = $svg->group();
464 my $y=$Y_start+$height/2;
465 my $x1=$x_margin+($start+$margin)*$WidthPoint;
466 $g->line('x1',$x1,'y1',$y,'x2',$x1+$len*$WidthPoint,'y2',$y,'stroke','black','stroke-width',$height/16);
467 my $PosBP=$start;
468 my $h=$height/8;
469 while ($PosBP<=$len) {
470 my $x=$x_margin+($PosBP+$margin)*$WidthPoint;
471 $g->line('x1',$x,'y1',$y,'x2',$x,'y2',$y+$h,'stroke','red','stroke-width',$height/16);
473 $PosBP += $cStepN*100;
476 sub SVG_mRNA($$) {
477 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');
478 #[$gene1_id,\@StartEndStrand,\@X_exon];
479 my ($str,$SESFrefA,$EXONrefA)=@{$_[1]};
480 my $height=$Heights{$_[0]}*$HeightPoint;
481 my $M_Height=$Heights{$_[0]}*.824;
482 $M_Height = $Y_junt if $M_Height > $Y_junt;
483 $M_Height *= .75;
484 my $font_size = int($M_Height*$HeightPoint / .72);
485 my $M_str=($$SESFrefA[3] == 1)?'M':'m';
486 my $M_width = $font->stringWidth($font_family,$font_size,$M_str);
487 my $Y0=$Y_start+( (!$_[2])*$Heights{$_[0]} + $M_Height*2*(.5-$_[2]) )*$HeightPoint;
488 my $g = $svg->group('id'=>$str,'onclick',"alert('$str')");
489 # Bone Line
490 my $y=$Y_start+$height/2;
491 my $x1=$x_margin+$$SESFrefA[0]*$WidthPoint;
492 my $x2=$x_margin+$$SESFrefA[1]*$WidthPoint;
493 $g->line('x1',$x1,'y1',$y,'x2',$x2,'y2',$y,'stroke','rgb(0,96,196)','stroke-width',$height/4);
494 # Exon Boxes
495 while (@$EXONrefA > 1) {
496 my $x1=shift @$EXONrefA;
497 my $x2=shift @$EXONrefA;
498 my $w=$x2-$x1;
499 $x1 *= $WidthPoint; $w *= $WidthPoint;
500 $w=1 if $w<1;
501 $x1 += $x_margin;
502 $g->rect('x',$x1, 'y',$Y_start,'width',$w,'height',$height,'fill','rgb(0,96,96)');
505 my $A_PointX;
506 if ($$SESFrefA[2] eq '+') {
507 $A_PointX=$x2;
508 $A_PointX=$img_width-$x_margin/2 if $A_PointX>$img_width-$x_margin/2;
509 $A_PointX -= $M_width;
510 } else {
511 $A_PointX=$x1;
512 $A_PointX=$x_margin/2 if $A_PointX<$x_margin/2;
514 $g->text('x',$A_PointX,'y',$Y0,'-cdata',$M_str,'font-family',$font_family,'font-size',$font_size);
516 sub SVG_TE($$) {
517 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');
518 my ($str,$start_margin,$len)=@{$_[1]};
519 my $height=$Heights{$_[0]}*$HeightPoint;
520 my $x=$x_margin+$start_margin*$WidthPoint;
521 my $w=$len*$WidthPoint;
522 $w=1 if $w<1;
523 $svg->rect('x',$x, 'y',$Y_start,'width',$w,'height',$height,'fill','red','onclick',"alert('$str')");
525 sub SVG_Bar($$) {
526 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');
527 #($str,$margin+$start,$len,$color)
528 my ($str,$start_margin,$len,$color)=@{$_[1]};
529 my $height=$Heights{$_[0]}*$HeightPoint;
530 my $x=$x_margin+$start_margin*$WidthPoint;
531 my $w=$len*$WidthPoint;
532 $w=1 if $w<1;
533 $svg->rect('x',$x, 'y',$Y_start,'width',$w,'height',$height,'fill',$color,'onclick',"alert('$str')");
535 sub SVG_Synteny($$) {
536 $svg->rect('x',$x_margin, 'y',$Y_start,'width',$img_width-2*$x_margin,'height',$Heights{$_[0]}*$HeightPoint,'fill','none','stroke','blue');