#!C:\Perl\bin # Test Widget to try and draw circular genome # by Mark # # Created 08.19.03 # Revised 08.20.03 # # ver. 0.02 use Cwd; use DBI; use Digest::MD5 qw(md5_hex); use LWP::Simple; use Text::Wrap; use lib 'lib'; use lib 'vg/lib'; use lib '../lib'; use Tk; use Tk::LabEntry; use Tk::Dialog; use Tk::DialogBox; use Tk::TableMatrix; use Tk::ProgressBar; use Tk::ROText; use Tk::Optionmenu; use Win32; use Win32::Process; use Import::Genbank qw(gbk_org_info gbk_write_orfs); use Functions qw( mysystem ); use Globals; use strict; use warnings; # DEBUG! # use RG::Fasta; use RG::DB::Protein; use RG::DB::Org; use RG::DB::Contig; use RG::GUI::Orfscan; use RG::GUI::ProteinInspector; use RG::DNA; use RG::Block; use RG::ButtonBar; use RG::Canvas; use RG::ContigAsm; use RG::ContigAsmP; use RG::ContigAsmS; use RG::ContigAsmY; use RG::Ephemera; use RG::FileIO; use RG::Menubar; use RG::Organism; use RG::PropTable; use RG::ScatterPlot; use Tk::MyBalloon; #use Math; our($dbh,$sth,%myorfs,@orfids); # Define database connection $dbh = DBI->connect('dbi:mysql:genomatik','genomatik','3369',{ RaiseError => 1,AutoCommit => 1 }); # grab protein positions for halodurans, org_id 106 $sth = $dbh->prepare ("select text_id,gene_name,protein5, protein3 from protein where org_id=64 order by protein5 desc") or die "Can't prepare SQL statement ", $dbh->errstr(),"\n"; $sth->execute() or die "Can't execute SQL statement: ", $sth->errstr(), "\n"; my $count=0; while (my($text_id,$gene_name,$protein5,$protein3) = $sth->fetchrow_array()) { $myorfs{$count}= [$text_id,$gene_name,$protein5,$protein3]; $count++; } @orfids = keys(%myorfs); my $orfcount = $#orfids+1; print" There are $orfcount orfs in halodurans\n"; my $mw = MainWindow->new(); $mw ->title("Circular Genome View"); my $canvas = $mw->Canvas(-height=>600, -width=> 600, -background=> 'white')->pack(); # Create area to display ORF ID's my $message; my $orf_label = $mw->Label(-textvariable=> \$message, -borderwidth=> 2, -relief=> 'groove')->pack(-fill => 'x',-side=>'bottom'); my ($x1,$y1,$x2,$y2,$x_offset,$y_offset,$circumference,$pi,$genome_length,$radius); my @colors = qw/grey purple pink blue turquoise green chartreuse yellow gold orange/; # Mathmatical Basis # # For a circle with central angle A, arc length S and circumference C, # S/C = A/360 degrees. Therefore A = 360(S/2*pi*radius) # # Since we draw the longest arc (last orf) first, we just draw a full circle. After that, # the calculated central_angle is added to drawn_angle. As we draw the other orfs, the arc that is drawn # is 360 - drawn_angle. The central_angle is added to drawn_angle so that the next one will be placed # correctly. $pi = 3.1417; $x_offset = 25; $y_offset = 25; $x1 = $x_offset; $y1 = $y_offset; $x2 = $x_offset + 650; $y2 = $y_offset + 650; $circumference = 2 * ($x2 - $x1) * $pi; # define circumference $radius = $circumference/2; # define radius my @orf_keys = keys %myorfs; my $drawn_angle=0; my ($remaining_angle,$actual_angle); $genome_length=0; foreach my $key(@orf_keys) { my $distance = $myorfs{$key}[3] - $myorfs{$key}[2]; # calc orf length $genome_length = $genome_length + $distance; # calc total genome length } print "circum = $circumference\ngenome length= $genome_length\n"; foreach my $key(@orf_keys) { my $color = int($key % 10); my $orig_dist = $myorfs{$key}[3] - $myorfs{$key}[2]; # calc original orf length my $orf_pct = $orig_dist/$genome_length; # convert orf length to pct of genome length my $graph_arc_length = $circumference * $orf_pct; # calc equivalent arc length corresponding to same pct of circumference my $central_angle = 360 * ($graph_arc_length / $circumference); #(2 * $pi * $radius)); # calc central angle for that arc if ($drawn_angle == 0) { $canvas->createArc($x1,$y1,$x2,$y2, -width=> 10, -fill=> $colors[$color],-outline=> $colors[$color],-style=> 'arc', -start=>90, -extent=> -359.99); &bind_message($canvas,"Edg-1"); # Display gene name when mouse is over it. $drawn_angle = $central_angle; } elsif($drawn_angle < 359) { $actual_angle = 360 - $drawn_angle; $canvas->createArc($x1,$y1,$x2,$y2, -width=> 10, -fill=> $colors[$color],-outline=> $colors[$color],-style=> 'arc', -start=>90, -extent=> -$actual_angle); $drawn_angle = $drawn_angle + $central_angle; } } # Graph Label $canvas->createText($x_offset+375, $y_offset+375, -fill => 'black', -text => 'Halodurans Genome'); $canvas->createText($x_offset+375, $y_offset+390, -fill => 'black', -text => "$genome_length bp"); #$canvas->configure(-scrollregion=> [$canvas->bbox("all")]); $mw->deiconify(); $mw->raise(); MainLoop; # Displays value of $message in lower box when mouse is over item, goes back to null when mouse leaves. sub bind_message { my($widget, $msg) = @_; $widget->Tk::bind('', [ sub { $message = $_[1]; }, $msg ]); $widget->Tk::bind('', sub { $message = ""; }); }