draw_figure.pl
use GD;
use integer;
$imagefile = "blast_figure.png";
$seq_length = "505";
$data_file = "blast_parse_1_out.txt";
$div = 1;
$image_width = 1400;
$image_height = 350;
$seq_width = 10;
$margin_left = 20;
$margin_top = 50;
$subjectStartField = 8;
$subjectEndField = 9;
$hitNameField = 5;
$img = new GD::Image($image_width, $image_height);
$white = $img->colorAllocate(255,255,255);
$black = $img->colorAllocate(0,0,0);
$green = $img->colorAllocate(0, 255, 0);
$blue = $img->colorAllocate(0, 0, 255);
$red = $img->colorAllocate(255, 0, 0);
open(DATA, "$data_file") || die "Cannot open $data_file for reading: $!\n";
@data = <DATA>;
$data[2] =~ s/DATA FOR QUERY//;
chomp ($seqName = $data[2]);
$title = "Top 10 BLAST hits for $seqName";
$img->string(gdMediumBoldFont, $margin_left, 5, $title, $black);
$x1 = $margin_left;
$x2 = $x1 + ($seq_length / $div);
$y1 = $margin_top;
$y2 = $y1 + $seq_width;
$img->filledRectangle($x1, $y1, $x2, $y2, $red);
for ($i = 1; $i < $seq_length; $i+= 100)
{
$x1 = $margin_left + (($i - 1) / $div);
$img->string(gdMediumBoldFont, $x1, 20, $i, $red);
$img->line($x1, 35, $x1, 60, $blue);
}
for ($i = 5; $i < $
{
@fields = split (/\t/, $data[$i]);
$start = $fields[$subjectStartField];
$end = $fields[$subjectEndField];
$hit = $fields[$hitNameField];
$x1 = $margin_left + ($start / $div);
$x2 = $margin_left + ($end / $div);
$y1 = $margin_top + $seq_width + ($i - 4) * 20;
$y2 = $y1 + 5;
$img->filledRectangle($x1, $y1, $x2, $y2, $green);
$img->string(gdTinyFont, $x1, $y2 + 1, "$hit", $black);
}
open(OUT, ">$imagefile") || die "Cannot write to $imagefile: $!\n";
print OUT $img->png;
close OUT;
print "All done - figure is $imagefile\n";