[Bio] / FigWebServices / genomebrowser.cgi Repository:
ViewVC logotype

View of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (annotate)
Wed Feb 2 21:02:32 2005 UTC (15 years, 2 months ago) by redwards
Branch: MAIN
genomebrowser.cgi is the first script to use raedraw and to make comparisons of genomes.
In the first version it only draws sims between multiple genomes. In subsequent versions I will extend
it to include all tag value pairs.

# -*- perl -*-

=pod

=head1

A genome browser to view different things in genomes

=cut

use strict;
use FIG;
use HTML;
use raedraw;
use CGI;
my $cgi=new CGI;
my $fig;
eval {
    $fig = new FIG;
};  

if ($@ ne "")
{
    my $err = $@;
    
    my(@html);
    
    push(@html, $cgi->p("Error connecting to SEED database."));
    if ($err =~ /Could not connect to DBI:.*could not connect to server/)
    {
        push(@html, $cgi->p("Could not connect to relational database of type $FIG_Config::dbms named $FIG_Config::db on port $FIG_Config::dbport."));
    }   
    else
    {
        push(@html, $cgi->pre($err));
    }   
    &HTML::show_page($cgi, \@html, 1);
    exit;
} 


$ENV{"PATH"} = "$FIG_Config::bin:$FIG_Config::ext_bin:" . $ENV{"PATH"};

my $html = [];
my $user = $cgi->param('user');
my $err;

if ($cgi->param('genome')) {
 # draw the image

 my %imagefns;
 foreach my $kw 
  (qw[width margin top_marg bottom_marg box_height rows box_no_score box_score show_function tick_mark_height genome_lines abrrev stopshort])
 {
  $imagefns{"-".$kw}=$cgi->param($kw);
 }

 $cgi->param('genome') =~ /\((\d+\.\d+)\)/; $imagefns{'-genome'}=$1;
 # this should be an array!!!

 foreach my $ct ($cgi->param('compare_to')) {
  $ct =~ /\((\d+\.\d+)\)/; 
  push @{$imagefns{'-compare_to'}}, $1;
  print STDERR "Added $1\n";
 }
 

 my $image=raedraw->new(%imagefns);
 my $filename = "$FIG_Config::temp/genomebrowser_$$.svg";
 my $url = &FIG::temp_url . "/genomebrowser_$$.svg";
		 
 
 $image->write_image($filename);

 push @$html, $cgi->div({class=>"image"}, $cgi->object({class=>"genomebrowser", data=>"$url", width=>"100%", height=>"100%",
         standby=>"Loading genome browser image, please be patient"}, 
	 "There should have been an SVG graphic comparing the genomes that you have chosen here, however, you probably need to download ",
	 "the SVG viewer from <a href=\"http://www.adobe.com/svg/viewer/install/main.html\">Adobe</a> (yes, it is free)."),"\n",);
}




else {
 unshift @$html, "<TITLE>The SEED - PIR comparison page</TITLE>\n";
 &show_initial($fig,$cgi,$html);
}

push @$html, $cgi->div({class=>"errors", style=>"font-size: smaller"}, @$err);
&HTML::show_page($cgi,$html,1);
exit;





sub show_initial {
 my ($fig,$cgi,$html)=@_;
 # generate a blank page
 # we want a list of all functions that have >= 1 peg unless we want all
 
 push (@$html, $cgi->start_form(-action => "genomebrowser.cgi"),
  $cgi->h2("Please choose some factors for your image"),
  "First, please enter a username: ", $cgi->textfield(-name=>"user"), $cgi->p,
  $cgi->h2("Please choose a <strong>single</strong> genome as the baseline:"), $cgi->p,
  &genome_lists("domain1", "complete1", "genome", 0), $cgi->p,
  $cgi->h2("Please choose one or more genomes as the comparators:"), $cgi->p,
  &genome_lists("domain2", "complete2", "compare_to", 'true'), $cgi->p,
  $cgi->submit(-label=>"Draw Genomes"), $cgi->reset);
 

 my %options=(
   width	=> [800, 'width'],
   margin	=> [100, 'margin'],
   top_marg	=> [20,  'top margin'],
   bottom_marg	=> [20,  'bottom margin'],
   box_height	=> [10,  'height of the boxes around the pegs'],
   rows		=> [2,   'rows to split the image into'],
   show_function=> [3,   'show function every n pegs'],
   tick_mark_height=> [3, 'height of the tick marks on the genome line'],
 );

 my %checkbox=(
   box_no_score => [0, "draw boxes around empty cells"],
   box_score	=> [1, "draw boxes around cells with content"],
   genome_lines	=> [1, "draw lines where the genomes are"],
   abbrev	=> [1, "abbreviate genome names"],
 );
  
 my $advanced;
 foreach my $opt (sort {$a cmp $b} keys %options) {
  $advanced .= "\n" . $cgi->Tr($cgi->td([$options{$opt}->[1]. ":", $cgi->textfield(-name=>$opt, -default=>$options{$opt}->[0], -size=>4)]));
 }
 foreach my $opt (sort {$a cmp $b} keys %checkbox) {
  $advanced .= "\n" . $cgi->Tr($cgi->td([$checkbox{$opt}->[1], $cgi->checkbox(-name=>$opt, -label=>'', -checked=>$checkbox{$opt}->[0])]));
 }
  
 push @$html, "\n" , $cgi->p, $cgi->div({class=>"advanced"}, 
  $cgi->table($advanced), $cgi->submit(-label=>"Draw Genomes"), $cgi->reset, $cgi->end_form);
}











# generate the genome lists as needed.

sub genome_lists {
 my ($domain,$complete, $listname, $multiple)=@_;
 
    #############
    # 
    # Stolen from index.cgi
    # 
    # 
    
    my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );

    #
    #  Canonical names must match the keywords used in the DBMS.  They are
    #  defined in compute_genome_counts.pl
    #
    my %canonical = (
        'All'                   =>  undef,
        'Archaea'               => 'Archaea',
        'Bacteria'              => 'Bacteria',
        'Eucarya'               => 'Eukaryota',
        'Viruses'               => 'Virus',
        'Environmental samples' => 'Environmental Sample'
        );
    
    my $req_dom = $cgi->param( $domain ) || 'All';
    my @domains = $cgi->radio_group( -name     => $domain,
                                     -default  => $req_dom,
                                     -override => 1,
                                     -values   => [ @display ]
                                   );

    my $n_domain = 0;
    my %dom_num = map { ( $_, $n_domain++ ) } @display;
    my $req_dom_num = $dom_num{ $req_dom } || 0;

    #
    #  Viruses and Environmental samples must have completeness = All (that is
    #  how they are in the database).  Otherwise, default is Only "complete".
    #
    my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All'
                 : $cgi->param( 'complete' ) || 'Only "complete"';
    my @complete = $cgi->radio_group( -name     => $complete,
                                      -default  => $req_comp,
                                      -override => 1,
                                      -values   => [ 'All', 'Only "complete"' ]
                        );
    #
    #  Use $fig->genomes( complete, restricted, domain ) to get org list:
    #
    my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
   
    my @orgs = sort map { my $org = $_; my $gs = $fig->genus_species($org); my $gc=scalar $fig->all_contigs($org); "$gs ($org) [$gc contigs]" }
               $fig->genomes( $complete, undef, $canonical{ $req_dom } );
    
    my $n_genomes = @orgs;

    return        "<TABLE>\n",
                  "   <TR>\n",
                  "      <TD>",
	          $cgi->scrolling_list( -name     => $listname,
                                        -size     => 10,
					-multiple => $multiple,
                                        -values   => \@orgs,
                                      ),
                  $cgi->br,
                  "$n_genomes genomes shown ",
                  $cgi->submit( 'Update List' ), $cgi->reset,
                  "</TD>",
                  "      <TD>",
                  join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n",
                  join( "<br>", "<b>Completeness?</b>", @complete), "\n",
                  "</TD>",
                  "   </TR>\n",
                  "</TABLE>\n",
	          $cgi->br, 

}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3