[MOBY-l] First (?) MOBY 0.5 service up and running
Mark Wilkinson
markw at illuminae.com
Wed Jun 11 21:05:12 UTC 2003
Hi MOBYers and I3Cers,
I set up a simple service at mobycentral.cbr.nrc.ca that takes base
objects with GO accessions and returns the GO term/definition.
Attached are:
RegisterGOService.pl - shows how to use the Perl interface to register
objects, namespaces, and services. How to discover services. How to
use the MOBY::Client::Service and ServiceInstance modules to connect to
and execute the service (for the moment we are still coding XML by
hand...)
Services.cgi - this is the cgi program at mobycentral that is serving
the service.
BasicLocalServices.pm - this contains the subroutine that is executed in
order to do the ID -> GO_Term transformation.
*** Please do a CVS update before running the script ***
I'm off for the weekend! Back Monday. Let me know if this works for
you,
Cheers all!
Mark
--
Mark Wilkinson <markw at illuminae.com>
Illuminae
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RegisterGoService.pl
Type: text/x-perl
Size: 1926 bytes
Desc: not available
URL: <http://lists.open-bio.org/pipermail/moby-l/attachments/20030611/f02d768f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Services.cgi
Type: text/x-perl
Size: 598 bytes
Desc: not available
URL: <http://lists.open-bio.org/pipermail/moby-l/attachments/20030611/f02d768f/attachment-0001.bin>
-------------- next part --------------
package Services::BasicLocalServices;
use lib "/var/www/cgi-bin";
use strict;
use MIME::Base64;
use XML::DOM;
use vars qw(@ISA);
@ISA = qw(SOAP::Server::Parameters); # uncomment this line if you want access to the SOM as the
# last parameter passed to thh subroutine
sub getGoTerm {
my $SOM = pop;
my ($self, $data) = @_;
my $response; my @objects;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parse($data);
my $moby = $doc->getDocumentElement();
my $x = $moby->getElementsByTagName('queryInput');
unless ($x->item(0)){
$x = $moby->getElementsByTagName('moby:queryInput');
}
my @accessions;
if ($x->item(0)){
my @child = $x->item(0)->getChildNodes;
my $content;
foreach (@child){
$content .= $_->toString;
unless ($content =~ /namespace\s*=\s*['"]GO\/Accession.*?id\s*=\s*['"](GO:\d\d\d\d\d\d\d)/s){
push @accessions, undef;
next;
} else {
push @accessions, $1;
}
}
}
use DBI;
use DBD::mysql;
my $dbh = _dbAccess('go');
die "can't connecvt to database\n" unless $dbh;
my $sth = $dbh->prepare(q{select name, term_definition from term, term_definition where term.id = term_definition.term_id and acc=?});
foreach (@accessions){
$sth->execute($_);
my ($term, $def) = $sth->fetchrow_array;
if ($term){
$response .= simpleResponse("
<moby:GO_Term namespace='GO/Accession' id='$_'>
<moby:String namespace='' id='' articleName='Term'>$term</String>
<moby:String namespace='' id='' articleName='Definition'>$def</String>
</moby:GO_term>")
} else {
$response .= simpleResponse("")
}
}
$response = responseHeader() . $response . responseFooter();
my $SOAPResponse = SOAP::Data->type('base64' => $response);
return $SOAPResponse
}
sub responseHeader {
return "<?xml version='1.0' encoding='UTF-8'?>
<moby:MOBY xmlns:moby='http://www.biomoby.org/moby'>
<moby:Response moby:authority='http://www.illuminae.com'>
";
}
sub responseFooter {
return "
</moby:Response>
</moby:MOBY>\n"
}
sub simpleResponse {
my ($data, $articleName) = @_; # articleName optional
if ($articleName) {
return "
<moby:queryResponse>
<Simple articleName='$articleName'>
$data
</Simple>
</moby:queryResponse>
";
} else {
return "
<moby:queryResponse>
<Simple>
$data
</Simple>
</moby:queryResponse>
";
}
}
sub _dbAccess {
my ($dbname) = @_;
return undef unless $dbname;
my $url = $ENV{MOBY_CENTRAL_URL}; chomp $url;
my $username = $ENV{MOBY_CENTRAL_DBUSER}; chomp $username;
my $password = $ENV{MOBY_CENTRAL_DBPASS}; chomp $password;
my $port = $ENV{MOBY_CENTRAL_DBPORT}; chomp $port;
my ($dsn) = "DBI:mysql:$dbname:$url:$port";
my $dbh = DBI->connect($dsn, $username, $password, {RaiseError => 1}) or die "can't connect to database";
return ($dbh);
}
1;
More information about the moby-l
mailing list