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

View of /FigWebServices/genome_object.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Fri Jul 11 19:15:39 2014 UTC (5 years, 6 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912
Changes since 1.1: +108 -19 lines
RAST fixes.

#
# Copyright (c) 2003-2014 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.
#

our $have_rast;
eval {
    require DBMaster;
    require RAST_submission;
    require FIGV;
    $have_rast = 1;
};

use FIG_Config;
#$have_rast = 0 unless ($FIG_Config::rast_jobs && -d $FIG_Config::rast_jobs);

use JSON::XS;
use FIG;
my $fig = new FIG;

use CGI;
our $cgi = new CGI;

if (0)
{
    print $cgi->header;
    my @params = $cgi->param;
    print "<pre>\n";
    foreach $_ (@params)
    {
	print "$_\t:",join(",",$cgi->param($_)),":\n";
    }
    exit;
}

#
# Check if we're in RAST.
#
my $job = $cgi->param("rast_job");

my $genome;
my $gobj;

if ($have_rast && $job ne '')
{
    my $rast_user = $cgi->param('username');
    my $rast_password = $cgi->param('password');

    if ($rast_user eq '')
    {
	&myerror($cgi, '500 missing username', 'RAST username is missing');
    }

    #
    # Connect to the authentication database.
    #

    my $dbmaster;
    eval {
      $dbmaster = DBMaster->new(-database => $FIG_Config::webapplication_db || "WebAppBackend",
				-host     => $FIG_Config::webapplication_host || "localhost",
				-user     => $FIG_Config::webapplication_user || "root",
				-password => $FIG_Config::webapplication_password || "");
    };

    #
    # And evaluate username and password.
    #

    my $user_obj = $dbmaster->User->init( { login => $rast_user });
    if (!ref($user_obj) || !$user_obj->active)
    {
	&myerror($cgi, '500 invalid login', 'Invalid RAST login');
    }

    if (crypt($rast_password, $user_obj->password) ne $user_obj->password)
    {
	&myerror($cgi, '500 invalid login', 'Invalid RAST login');
    }
    warn "Authenticated $rast_user\n";

    # Connect to the RAST job cache
    my $rast_dbmaster = DBMaster->new(-backend => 'MySQL',
				      -database  => $FIG_Config::rast_jobcache_db,
				      -host     => $FIG_Config::rast_jobcache_host,
				      -user     => $FIG_Config::rast_jobcache_user,
				      -password => $FIG_Config::rast_jobcache_password );
    
    my $rast_obj = RAST_submission->new($rast_dbmaster, $dbmaster, $user_obj);

    my $job_obj = $rast_obj->rast_dbmaster->Job->init({ id => $job });
	

    if (!$rast_obj->user_may_access_job($job_obj))
    {
	&myerror($cgi, '500 access denied', 'Access denied.');
    }

    my $jdir = "$FIG_Config::rast_jobs/$job";
    open(G, "<", "$jdir/GENOME_ID") or &myerror($cgi, '500 error', 'cannot open genome');
    $genome = <G>;
    chomp $genome;

    my $gdir = "$jdir/rp/$genome";
    my $figv = FIGV->new($gdir, undef, $fig);
    $gobj = &FIG::genome_id_to_genome_object($figv, $genome);

    if ($gobj)
    {
	&GenomeTypeObject::set_metadata($gobj,{source => "RAST job $job"});
    }
}
else
{
    $genome = $cgi->param('genome');
    if (! $genome)
    {
	&myerror($cgi, '500 error', "no genome specified");
    }

    $gobj = $fig->genome_id_to_genome_object($genome);
}

my $pretty = $cgi->param('pretty') ? 1 : 0;
$gobj or &myerror($cgi, '500 error', "genome retrieval failed");
print $cgi->header(-content_type => 'application/json');
my $json = JSON::XS->new->pretty($pretty);
print $json->encode($gobj);

exit;

sub myerror
{
    my($cgi, $stat, $msg) = @_;
    print $cgi->header(-status =>  $stat);
    print "$msg\n";
    exit;
}





MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3