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

View of /FigWebServices/genomebrowser.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (annotate)
Wed Oct 18 21:44:58 2006 UTC (13 years ago) by redwards
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.7: +1 -1 lines
minor change to allow proper genome selection

# -*- perl -*-
#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


=pod

=head1

A genome browser to view different things in genomes

=cut

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser); # this makes debugging a lot easier by throwing errors out to the browser
use FIG;
use HTML;
use raedraw;
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;


foreach (@ARGV) {
 my ($k, $v)=split /\=/;
 if ($k eq "compare_to") {my @arr=split /\,/, $v; $v=\@arr}
 $cgi->param(-name=>$k, -value=>$v);
}

if ($cgi->param('genome')) {
 # draw the image
 unshift @$html, "<TITLE>The SEED - Genome Browser </TITLE>\n";

 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 abbrev stopshort 
  maxn maxp bluescale stopshort user])
 {
  $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;
 }
 if ($cgi->param('subsystems')) {push @{$imagefns{'-compare_to'}}, "subsystems"}
 if ($cgi->param('pirsf')) {push @{$imagefns{'-compare_to'}}, ['tagvalue', 'pirsf']} 
 #
 # remember that we also need to pass in scalefactor here if we have one. This should be a tuple of 'pirsf' and the factor

 if ($ARGV[0]) {
  print STDERR "These are the compare to's: \n", join "\n", @{$imagefns{'-compare_to'}}, '';
 }

 my $image=raedraw->new(%imagefns);

 
 my $filename = "$FIG_Config::temp/genomebrowser_$$.svg";
 my $url = &FIG::temp_url . "/genomebrowser_$$.svg";
		 
 
 my ($width, $height)=$image->write_image($filename);


 push @$html, $cgi->div({class=>"image"}, $cgi->object({class=>"genomebrowser", data=>"$url", width=>"$width", height=>"$height",
         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 - Genome Browser </TITLE>\n";
 &show_initial($fig,$cgi,$html);
}

push @$err, "Computing this image took " . int((time-$^T)/0.6)/100 . " minutes\n";
push @$html, $cgi->div({class=>"errors", style=>"font-size: smaller"}, $cgi->h3("Errors/Diagnoses we caught:"), @$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		=> [10,   'split the image into rows'],
   show_function=> [3,   'show function every n pegs'],
   tick_mark_height=> [3, 'height of the tick marks on the genome line'],
   maxn		=> [5, "Max sims"],
   maxp		=> [1e-5, "Max E-val"],
   stopshort	=> [500, "Stop after drawing this many pegs"],
 );

 my %checkbox=(
   box_no_score => [0, "draw boxes around empty cells"],
   box_score	=> [1, "draw boxes around cells with content"],
   bluescale    => [1, "make the darkest color blue (if checked) or red (if not checked)"],
   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));
 
 push @$html, $cgi->h3("Subsystems"),  $cgi->table($cgi->Tr(
  $cgi->td([$cgi->checkbox(-name=>'subsystems', -label=>'') . " &nbsp; highlight PEGs in subsystems"])));

 # now add the table for tag value pairs:
 push @$html, $cgi->h3("Tag value pairs"), $cgi->table($cgi->Tr(
 	$cgi->td([$cgi->checkbox(-name=>'pirsf', -label=>'') . " &nbsp; PIR superfamilies", ''])));
 
 push @$html, $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