Commit b3266ec0 authored by cvs2git's avatar cvs2git
Browse files

This commit was manufactured by cvs2svn to create branch

'ensembl_simple_schema_01'.

Sprout from master 1999-11-23 14:04:04 UTC Ewan Birney <birney@sanger.ac.uk> 'reverted sql'
Delete:
    modules/GeneDraw/DrawingRoutines.pm
    modules/GeneDraw/GenDraw.pm
    modules/GeneDraw/ImageMap.pm
    modules/GeneDraw/contig_drawer.pl
parent bd1207fb
=head1 NAME
DrawingRoutines.pm
=head1 SYNOPSIS
&DrawingRoutines::draw__s2_band($im_fh,$x_start,$y_start,$x_end,$y_end,$black,$black,$name,$url,$img_map_fh);
&DrawingRoutines::draw_a_rectangle($im_fh,$x_start,$y_start,$x_end,$y_end,$lightgrey,$black,$name,$url,$img_map_fh);
&DrawingRoutines::draw_a_centromere_p($im_fh,$x_start,$y_start,$x_end,$y_end,$darkgrey,$black,$name,$url,$img_map_fh);
&DrawingRoutines::draw_a_centromere_q($im_fh,$x_start,$y_start,$x_end,$y_end,$darkgrey,$black,$name,$url,$img_map_fh);
=head1 DESCRIPTION
DrawingRoutines contains basic routines for drawing triangles and rectangles. DrawingRoutines consists of the following modules:
draw_s2_band : draws two rectangles
draw_a_rectangle : draws a filled rectangle
draw_a_centromere_p : draws a triangle pointing down
draw_a_centromere_q : draws a triangle pointing up
=head1 AUTHOR
Arek Kasprzyk
arek@ebi.ac.uk
=cut
package DrawingRoutines;
use strict;
use GD;
=head1 Methods
Methods available in the DrawingRoutines package:
=head2 draw_a_rectangle
Title : draw a rectangle
Usage : &DrawingRoutines::draw_a_rectangle($im_fh,$x_start,$y_start,$x_end,$y_end,$lightgrey,$black,$name,$url,$img_map_fh);
Function: draws a rectangle
Example :
Returns :
=cut
sub draw_a_rectangle {
my($im_fh,$x_start,$y_start,$x_end,$y_end,$colour,$font_colour,$name,$url,$img_map_fh)=@_;
$im_fh->filledRectangle($x_start,$y_start,$x_end,$y_end,$colour);
}
=head2 draw_a_s2_band
Title : draw a s2 band
Usage : &DrawingRoutines::draw__s2_band($im_fh,$x_start,$y_start,$x_end,$y_end,$black,$black,$name,$url,$img_map_fh);
Function: draws two rectangles
Example :
Returns :
=cut
sub draw__s2_band {
my($im_fh,$x_start,$y_start,$x_end,$y_end,$colour,$font_colour,$name,$url,$img_map_fh)=@_;
$im_fh->filledRectangle($x_start,$y_start+($y_end-$y_start)/5,$x_end,$y_start+(($y_end-$y_start)/5)*2,$colour);
$im_fh->filledRectangle($x_start,$y_start+(($y_end-$y_start)/5)*3,$x_end,$y_start+(($y_end-$y_start)/5)*4,$colour);
}
=head2 draw_a_centromere_P
Title : draw a centromere_p
Usage :&DrawingRoutines::draw_a_centromere_p($im_fh,$x_start,$y_start,$x_end,$y_end,$darkgrey,$black,$name,$url,$img_map_fh);
Function: draws a triangle pointing down
Example :
Returns :
=cut
sub draw_a_centromere_p {
my($im_fh,$x_start,$y_start,$x_end,$y_end,$colour,$font_colour,$name,$url,$img_map_fh)=@_;
my $poly = new GD::Polygon;
$poly->addPt($x_start,$y_start);
$poly->addPt($x_end,$y_start);
$poly->addPt(($x_end-$x_start)*0.5+$x_start,$y_end);
$im_fh->filledPolygon($poly,$colour);
}
=head2 draw_a_centromere_q
Title : draw a centromere_q
Usage :&DrawingRoutines::draw_a_centromere_q($im_fh,$x_start,$y_start,$x_end,$y_end,$darkgrey,$black,$name,$url,$img_map_fh);
Function: draws a triangle pointing up
Example :
Returns :
=cut
sub draw_a_centromere_q {
my($im_fh,$x_start,$y_start,$x_end,$y_end,$colour,$font_colour,$name,$url,$img_map_fh)=@_;
my $poly = new GD::Polygon;
$poly->addPt($x_start,$y_end);
$poly->addPt($x_end,$y_end);
$poly->addPt(($x_end-$x_start)*0.5+$x_start,$y_start);
$im_fh->filledPolygon($poly,$colour);
}
1;
package GenDraw;
use strict;
use GD;
use Bio::EnsEMBL::DBSQL::Obj;
use ImageMap;
use DrawingRoutines;
sub build_image
{
my($bases_per_pixel,$contig_name)=@_;
my $GAP=50;
my $x_img_len=600;
my $repeats = &GenDraw::adjust_image_size($bases_per_pixel,$x_img_len,$contig_name);
my $y_img_len=$repeats*$GAP;
my $margin=30;
my $im = new GD::Image($x_img_len+2*$margin,$y_img_len);
return my @param= ($im,$GAP,$x_img_len,$margin);
}
sub adjust_image_size
{
my ($bases_per_pixel,$x_img_len,$contig_name)=@_;
my $dbuser = 'ensembl';
my $dbname = 'ensdev';
my $host = 'sol28';
my $dbpass = undef;
my $db = Bio::EnsEMBL::DBSQL::Obj->new( -user => $dbuser, -db => $dbname ,
-host => $host, -password => $dbpass );
my $contig = $db->get_Contig($contig_name);
my $seq = $contig->seq();
my $repeats =$seq->seq_len/($x_img_len*$bases_per_pixel)+2;
return $repeats;
}
sub draw_genes
{
my ($im_fh,$contig_name,$bases_per_pixel,$img_map_fh) = @_;
# get image parameters
my @parms=&build_image($bases_per_pixel,$contig_name);
my $GAP=@parms[1];
my $x_img_len=@parms[2];
my $margin=@parms[3];
# set colours
my $white = $im_fh->colorAllocate(255,255,255);
my $grey = $im_fh->colorAllocate(192,192,192);# background
my $lightgrey=$im_fh->colorAllocate(140,140,140);
my $darkgrey= $im_fh->colorAllocate(80,80,80);
my $white = $im_fh->colorAllocate(255,255,255);
my $black = $im_fh->colorAllocate(0,0,0);
my $red = $im_fh->colorAllocate(255,0,0);
my $blue = $im_fh->colorAllocate(0,0,255);
# create a db object
my $dbuser = 'ensembl';
my $dbname = 'ensdev';
my $host = 'sol28';
my $dbpass = undef;
my $db = Bio::EnsEMBL::DBSQL::Obj->new( -user => $dbuser, -db => $dbname ,
-host => $host, -password => $dbpass );
# set the the vertical distance between each drawn object and the sequence
my $center= ($GAP)/2;
my $gap=0.1*$GAP;
my $adjusted_gap=0;
my $y_cent_seq=$center;
my $n=2;
my $y_cent_exon=$center+$n*$gap;
my $y_cent_baseno=$center-6*$gap;
my $y_cent_contig_name=-6*$gap;
# set width of each object
my $seq_width=0.01*$GAP;
my $exon_width=0.2*$GAP;
my $gene_width=0.01*$GAP;
my $y_start_seq=$y_cent_seq-0.5*$seq_width;
my $y_start_exon=$y_cent_exon-0.5*$exon_width;
my $y_start_baseno=$y_cent_baseno;
my $y_end_seq=$y_start_seq+$seq_width;
my $y_end_exon=$y_start_exon+$exon_width;
# bases count parameters
my $no_of_bases=0;
my $last_no_of_bases=0;
my $first_no_of_bases=0;
my $remaining_bases=0;
# x coordinate parameters
my $x_start=$margin;
my $x_end=$margin;
my $x_exon_start=0;
my $x_exon_end=0;
my $keep_gene_start=0;
my $keep_gene_end=0;
# drawing parameters
my $gene_status=0;
my $drawing_status=1;
my $drawing_counter=0;
my $factor=1/$bases_per_pixel;
#
# contig object drawer
#
# start of an image map
&ImageMap::print_map_start($img_map_fh);
# create contig object and get seq
my $contig = $db->get_Contig($contig_name);
my $seq = $contig->seq();
$remaining_bases=$seq->seq_len;
# print contig id
$im_fh->string(gdMediumBoldFont,$x_img_len/2-50 ,20,$contig->id,$black);
# adjust drawing parameters according to scale
while ($drawing_status==1)
{
if ($remaining_bases>=$x_img_len*$bases_per_pixel)
{
$no_of_bases = $x_img_len*$bases_per_pixel;
$x_end=$x_img_len+$margin;
$drawing_counter++;
$first_no_of_bases=$last_no_of_bases+1;
$last_no_of_bases=$no_of_bases +$last_no_of_bases;
$remaining_bases=$seq->seq_len-$last_no_of_bases;
}
else
{
$drawing_status=0;
$x_end=$margin+$remaining_bases*$factor;
$no_of_bases = $remaining_bases;
$drawing_counter++;
$first_no_of_bases=$last_no_of_bases+1;
$last_no_of_bases=$no_of_bases +$last_no_of_bases;
}
#
# loop through all genes/transcripts/exons
#
foreach my $gene ( $contig->get_all_Genes ) { $gene_status=1;
foreach my $trans ( $gene->each_Transcript() ) {
foreach my $exon ( $trans->each_Exon() ) {
#
# draw exons
#
# adjust the gap according to strand
if($exon->strand == 1 && $adjusted_gap == 0){$adjusted_gap=-2*$n*$gap;}
if($exon->strand == -1 && $adjusted_gap<0){$adjusted_gap=0;}
# calculate x exon coordinates
$x_exon_start=$margin+($exon->start)*$factor-($drawing_counter-1)*$x_img_len;
$x_exon_end=$margin+($exon->end)*$factor-($drawing_counter-1)*$x_img_len;
# don't go beyond the margin
if ($x_exon_start <$margin){$x_exon_start=$margin;}
if ($x_exon_end >$x_img_len+$margin){$x_exon_end=$x_img_len+$margin;}
# calculate y exon coordinates
my $y_ex_start= ($y_start_exon+$adjusted_gap)+$drawing_counter*$GAP;
my $y_ex_end= ($y_end_exon+$adjusted_gap)+$drawing_counter*$GAP;
# and finally draw exons
&DrawingRoutines::draw_a_rectangle($im_fh,$x_exon_start,$y_ex_start,$x_exon_end,$y_ex_end,$black);
# prepare for drawing a gene ...
# find the coordinates of the first and the last gene exon
# if it's a first exon of a gene
if ($gene_status==1){
$keep_gene_start=$x_exon_start;
$keep_gene_end=$x_exon_end;
$gene_status=2;
}
# if it's a subsequent exon
if ($gene_status==2){
if($keep_gene_end<$x_exon_end){$keep_gene_end=$x_exon_end;}
if($keep_gene_start>$x_exon_end){$keep_gene_start=$x_exon_start;}
}
}
# calculate gene image map coordinates
my $y_ex_img_start= ($y_start_exon+$adjusted_gap)+$drawing_counter*$GAP;
my $y_ex_img_end= ($y_end_exon+$adjusted_gap)+$drawing_counter*$GAP;
# calculate gene coordinates
my $x_start=$keep_gene_start;
my $x_end=$keep_gene_end;
my $y_gene_line_start=($y_cent_exon-0.5*$gene_width+$adjusted_gap)+$drawing_counter*$GAP;
my $y_gene_line_end = ($y_cent_exon+0.5*$gene_width+$adjusted_gap)+$drawing_counter*$GAP;
# draw genes
&DrawingRoutines::draw_a_rectangle($im_fh,$x_start,$y_gene_line_start,$x_end,$y_gene_line_end,$black);
# draw gene image map
&ImageMap::print_map($im_fh,$x_start,$y_ex_img_start,$x_end,$y_ex_img_end,$gene->id,"GETgene?",$img_map_fh);
}
}
# draw seqeunce
&DrawingRoutines::draw_a_rectangle($im_fh,$x_start,$y_start_seq +$drawing_counter*$GAP,$x_end,$y_end_seq+$drawing_counter*$GAP,$red);
# print no of bases
$im_fh->string(gdSmallFont,$x_start,$y_start_baseno+$drawing_counter*$GAP,$first_no_of_bases,$black);
$im_fh->string(gdSmallFont,$x_img_len+$margin-30,$y_start_baseno+$drawing_counter*$GAP,$last_no_of_bases,$black);
print $last_no_of_bases," bp ... done\n";
}
# end of an image map
&ImageMap::print_map_end($img_map_fh);
}
1;
=head1 NAME
ImageMap.pm
=head1 SYNOPSIS
&ImageMap::print_map_start(\*HTML);
&ImageMap::print_map($im_fh,$x_start,$y_start,$x_end,$y_end,$name,$url,$img_map_fh);
&ImageMap::print_map_end(\*HTML);
=head1 DESCRIPTION
ImageMap contains routines that print an image map. ImageMap.pm consists of the following modules:
print_map_start : prints the beginning of an image map
print_map : prints an image map
print_map_end : prints the end of an image map
=head1 AUTHOR
Arek Kasprzyk
arek@ebi.ac.uk
=cut
package ImageMap;
use strict;
=head1 Methods
Methods available in the ImageMap package:
=head2 print_map_start
Title : print map start
Usage : &ImageMap::print_map_start(\*HTML)
Function: prints start of an image map
Example :
Returns :
=cut
sub print_map_start{
my ($img_map_fh)=@_;
print $img_map_fh "<IMG SRC=\"output.gif\" BORDER=\"0\" USEMAP=\"#Ngs22\"><BR>\n";
print $img_map_fh "<MAP Name=\"Ngs22\">\n";
}
=head2 print_map
Title : print map
Usage : &ImageMap::print_map($im_fh,$x_start,$y_start,$x_end,$y_end,$name,$url,$img_map_fh);
Function: prints an image map
Example :
Returns :
=cut
sub print_map{
my($im_fh,$x_start,$y_start,$x_end,$y_end,$name,$url,$img_map_fh)=@_;
print $img_map_fh "<AREA Shape=\"Rect\" coords = \"",$x_start," ", $y_start," ",$x_end," ",$y_end," \" HREF=\"",$url,$name,"\">","\n";
}
=head2 print_map_end
Title : print map end
Usage : &ImageMap::print_map_end(\*HTML)
Function: prints end of an image map
Example :
Returns :
=cut
sub print_map_end{
my ($img_map_fh)=@_;
print $img_map_fh "</MAP>\n";
}
1;
use strict;
use GD;
use ImageMap;
use DrawingRoutines;
use GenDraw;
# read in arguments
my $contig_name = shift @ARGV;
my $bases_per_pixel = shift @ARGV;
if( !$contig_name || !$bases_per_pixel ){die"\n","***** USAGE: contig_drawer.pl contig_name (e.g.AC000001.00010) bases_per_pixel (e.g. 100)*****","\n","\n";}
# open output HTML file
open(HTML,">output.html");
# build image
my @parms=&GenDraw::build_image($bases_per_pixel,$contig_name);
my $im=shift @parms;
# draw genes
&GenDraw::draw_genes($im,$contig_name,$bases_per_pixel,\*HTML);
# draw image
open(GIF,">output.gif");
print GIF $im->gif;
close(GIF);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment