#!/usr/bin/perl use GD; #use strict; my @x1; my @y1; my $max1; my $max2; my $min1; my $min2; my $i; open(FILE1,"fwd.stb"); while() { my @value = split(/\s+/,$_); $x1[$i] = $value[0]-7; $y1[$i] = $value[1]; if($i != 0 && $y1[$i] > $max1) { $max1 = $y1[$i]; } if($i != 0 && $y1[$i] < $min1) { $min1 = $y1[$i]; } if($i == 0) { $min1 = $max1 = $y1[$i]; } $i++; } my $lines = $i; # Define constants my $X1start = 50+20; # X-axis my $Y1start = 300; # X-axis my $X1end = 450+$lines-400; # X-axis my $Y1end = 300; # X-axis my $X2start = 50+20; my $Y2start = 100; my $X2end = 50+20; my $Y2end = 300; # create a new image my $im = new GD::Image($X1end+50,$Y2end+100); # allocate some colors my $white = $im->colorAllocate(255,255,255); my $green = $im->colorAllocate(0,255,0); my $black = $im->colorAllocate(0,0,0); my $red = $im->colorAllocate(255,0,0); my $blue = $im->colorAllocate(0,0,255); # set the caption for the graph $im->string(gdLargeFont,int($lines/2)-50,20,"ENERGY GRAPH",$black); # draw the y-axis & x-axis $im->line($X2start,$Y2start,$X2end,$Y2end,$black); $im->line($X1start,$Y1start,$X1end,$Y1end,$black); # set the caption for x-axis and y-axis $im->string(gdLargeFont,int($lines/2)-50,335,"NUCLEOTIDE POSITION",$black); $im->stringUp(gdLargeFont,5,260,"FREE ENERGY(delta G)",$black); $im->string(gdSmallFont,int($lines/2)+100,20," Genomic Sequence -------",$red); $im->string(gdSmallFont,int($lines/2)+100,40," Shuffled Sequence -------",$blue); open(FILE2,"total_shuffle.stb"); $i = 0; my @x2; my @Y2; my $min; my $max; while() { my @value = split(/\s+/,$_); $x2[$i] = $value[0]-7; $y2[$i] = $value[1]; if($i != 0 && $y2[$i] > $max2)if($i != 0 && $y2[$i] > $max2) { $max2 = $y2[$i]; } if($i != 0 && $y2[$i] < $min2) { $min2 = $y2[$i]; } if($i == 0) { $min2 = $max2 = $y2[$i]; } $i++; } if($min1 <= $min2) { $min = $min1; } else { $min = $min2; } if($max1 >= $max2) { $max = $max1; } else { $max = $max2; } @y = @y1; @x = @x1; graph(); @y = @y2; @x = @x2;my $png_data = $im->png; open (DISPLAY,"| display -") || die; #open (DISPLAY,">image.jpg") || die; binmode DISPLAY; print DISPLAY $png_data; close DISPLAY; sub graph { # set min and max energy my $minEnergy = $min; my $maxEnergy = $max; # set the length of x-axis and y-axis my $xLen = $X1end-$X1start; my $yLen = $Y2end-$Y2start; # Scaling the values $Yscale = $yLen/(abs($minEnergy)-abs($maxEnergy)); $scale = ($minEnergy-$maxEnergy)/5; $incEnergy = $maxEnergy; while($incEnergy > $minEnergy) ##### Prob loop#### { $x1 = $X1start-2; $y1 = int(((abs($incEnergy)-abs($maxEnergy))*$Yscale)+$Y2start); $x2 = $X1start+2; $im->line($x1,$y1,$x2,$y1,$black); $displayEnergy = sprintf("%2.1f",$incEnergy); $im->string(gdSmallFont,$x1-35,$y1-10,$displayEnergy,$black); $incEnergy = $incEnergy+$scale; } # set the length of nucleotide $len = @x; # mark 10 points on the position axis $posSkip = int(@x/10); # If the length of the fragment is lesser than the x-axis $skipPixel = $xLen/$len; for($i=0;$i<$len-1;$i++) { $x1 = int(($i*$skipPixel)+$X1start); $y1 = int(((abs($y[$i])-abs($maxEnergy))*$Yscale)+$Y2start); $x2 = int((($i+1)*$skipPixel)+$X1start); $y2 = int(((abs($y[$i+1])-abs($maxEnergy))*$Yscale)+$Y2start); if($call == 0) { $im->line($x1,$y1,$x2,$y2,$red); } else { $im->line($x1,$y1,$x2,$y2,$blue); } $count++; if($count == $posSkip) { $x1 = int(($i*$skipPixel)+$X1start); $y1 = $Y1end-2; $x2 = int(($i*$skipPixel)+$X1start); $y2 = $Y1end+2; if($call == 0) { $im->line($x1,$y1,$x2,$y2,$black); $im->string(gdSmallFont,$x1,$y1+10,$i+1,$black); } $count = 0; } } $call++; }