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

View of /FigWebServices/rest_mgrast.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (annotate)
Thu Feb 25 01:11:53 2010 UTC (9 years, 11 months ago) by redwards
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_dev_06072011, rast_rel_2010_0526, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, 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_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, mgrast_dev_04052011, mgrast_dev_02222011
Changes since 1.1: +9 -20 lines
updating rtmg

#__perl__

# NOTE THAT use strict will break this!!
use lib '/home/redwards/perl/lib/perl5/site_perl/5.8.7/i686-linux/';
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use JSON::XS;

use ANNOserver;
$|=1;

=pod 

=head1 rest_mgrast.cgi

YAWS - Yet another web service!

Why: We're using rpc encoding which is basically URL encoding. In this, I call something like 

http://bioseed.mcs.anl.gov/~redwards/FIG/rest_seed.cgi/multiply/2/3/4/5 

and get a response. Why do we need another web service? Mainly because of the Google work. Google pretty much exclusively deals with http requests, and eschews SOAP and other encodings as being too complex. 

The data returned is all in JSON format (http://www.json.org/) which is the Javascript object notation format. JSON is a really light weight markup language that cna handle complex objects quite easily. 

I am also aiming for lightweight code. In this case, we're not going to instantiate anything until we need it. Hopefully.

=cut

# a really simple RESTful web service that returns seed data

my $cgi=new CGI qw/:standard/;
my $json= new JSON::XS;

print $cgi->header('text/plain');

# get the query with path so we get the RESTful information
my $abs = $cgi->url(-absolute=>1); # this will be the cgi-bin/rest.cgi stuff
my $rest = $cgi->url(-path_info=>1);
$rest =~ s/^.*$abs\///;
my @rest=split m#/#, $rest;

my $method = shift @rest;

# there is no good way of passing a null value!!
map {undef $rest[$_] if ($rest[$_] eq "undef" || $rest[$_] eq "null")} (0..$#rest);

my $result =  $json->encode({result => &{$method}(@rest) });

print $result, "\n";



=pod

=head1 multiply.

This is a really simple method that just multiplies two numbers! It's great for testing things out

=cut

sub multiply {
        
	my $x = 1;
        map {$x = $x * $_} @_;
        return $x;
}

=head1 annotate

This takes a dna sequence and returns the bare bones annotation. This is for first pass, kind of what's there look.

=cut

sub annotate {
	my %sequences = @_;
	my $sequences; 
	map {push @$sequences, [$_, "no comment", $sequences{$_}]} keys %sequences;

    	# Create a FIGfam server object.
    	my $ffServer = ANNOserver->new();
    	# Pass the input file to the FIGfam server to get assignments.
	my $reliability = 2;
	my $maxGap = 1000;
	my $kmer = 8;
	my $resultH = $ffServer->assign_functions_to_dna({-input=>$sequences, -minHits=>$reliability, -maxGap=>$maxGap, -kmer=>$kmer});

# Loop through the results. We send good results to the standard output,
# and failures to the standard error file.
	my $allresults;
	while (my $result = $resultH->get_next()) {push @$allresults, $result; print STDERR Dumper("ROB", $result)}
	return $allresults;

};



=head1 annotate_fasta_file

This takes a LOCAL fasta file and returns the bare bones annotation. This is for first pass, kind of what's there look. Italso takes an optional reliability. If not provided, defaults to 2.

=cut

sub annotate_fasta_file {
	my ($file, $reliability, $kmer, $maxGap) = @_;
	if (!defined $reliability) {$reliability = 2}
	if (!defined $maxGap) {$maxGap = 600}
	if (!defined $kmer) {$kmer = 8}
	use raelib;
	use FIG_Config;
	$file = $FIG_Config::temp . "/" . $file;
	unless (-e $file) {return "$file not found";}
	##return ("using $file");
	my $fa=raelib->read_fasta($file);
	map {push @$sequences, [$_, "no comment", $fa->{$_}]} keys %$fa;

    	# Create a FIGfam server object.
    	my $ffServer = ANNOserver->new();
    	# Pass the input file to the FIGfam server to get assignments.
	my $maxGap = 1000;
	my $resultH = $ffServer->assign_functions_to_dna({-input=>$sequences, -minHits=>$reliability, -maxGap=>$maxGap, -kmer=>$kmer});

	my $allresults=[];
	while (my $result = $resultH->get_next()) { push @{$allresults}, $result }
	unlink $file;
	return $allresults;
};




MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3