[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Tue Dec 9 22:24:03 UTC 2003
mwilkinson
Tue Dec 9 17:24:03 EST 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv28763/Perl/scripts/Services
Modified Files:
LocalServices.pm
Log Message:
updating my GO services to be 0.6 compliant and a bit more readable
moby-live/Perl/scripts/Services LocalServices.pm,1.37,1.38
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm 2003/12/09 21:06:51 1.37
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm 2003/12/09 22:24:03 1.38
@@ -10,6 +10,7 @@
use SOAP::Lite;
use DBI;
use DBD::mysql;
+use GO::AppHandle;
use MIME::Base64;
use XML::DOM;
use MOBY::Client::OntologyServer;
@@ -24,85 +25,60 @@
#getNodeContentWithArticle
use vars qw(@ISA);
- at ISA = qw(SOAP::Server::Parameters); # uncomment this line if you want access to the SOM as the
- # last parameter passed to the subroutine
sub getGoTerm {
my ($caller, $message) = @_;
my $MOBY_RESPONSE;
- my (@inputs)= genericServiceInputParser($message, []); # ([SIMPLE, $queryID, $simple],...)
+ my (@inputs)= genericServiceInputParser($message); # ([SIMPLE, $queryID, $simple],...)
return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
- my @validNS = validateNamespaces(); # ONLY do this if you are intending to be namespace aware!
+ my @validNS = validateNamespaces("GO"); # ONLY do this if you are intending to be namespace aware!
+
+ my $dbh = _dbAccess('go');
+ die "can't connect to GO 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=?});
- my @accessions;
foreach (@inputs){
my ($articleType, $ID, $input) = @{$_};
unless ($articleType == SIMPLE){
- $MOBY_RESPONSE .= simpleResponse("", "", $ID) ;
+ $MOBY_RESPONSE .= simpleResponse("", "Collection_Article_Not_allowed_as_input", $ID);
next;
} else {
my $ns = getSimpleArticleNamespaceURI($input);
- ((push @accessions, undef) && (next)) unless validateThisNamespace($ns, @validNS);
- push @accessions, defined(getSimpleArticleIDs($ns, [$input]))?getSimpleArticleIDs($ns,[$input]):1;
+ (($MOBY_RESPONSE .= simpleResponse("", "Invalid_Namespace", $ID)) && (next)) unless validateThisNamespace($ns, @validNS); # only do this if you are truly validating namespaces
+ my $accession = defined(getSimpleArticleIDs($ns, [$input]))?getSimpleArticleIDs($ns,[$input]):undef;
+ unless (defined($accession)){
+ $MOBY_RESPONSE .= simpleResponse("", "Invalid_Accession", $ID);
+ next;
+ }
+ unless ($accession =~/^GO:/){
+ $accession = "GO:$accession"; # we still haven't decided on whether id's should include the prefix...
+ }
+ $sth->execute($accession);
+ my ($term, $def) = $sth->fetchrow_array;
+ if ($term){
+ $MOBY_RESPONSE .= simpleResponse("
+ <moby:GO_Term namespace='GO' id='$accession'>
+ <moby:String namespace='' id='' articleName='Term'>$term</moby:String>
+ <moby:String namespace='' id='' articleName='Definition'>$def</moby:String>
+ </moby:GO_Term>", "GO_Term_From_ID", $ID)
+ } else {
+ $MOBY_RESPONSE .= simpleResponse("", "NO_Term_Found", $ID)
+ }
}
}
- my $dbh = _dbAccess('go');
- die "can't connect to GO 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 my $acc(@accessions){
- unless ($acc =~/^GO:/){
- $acc = "GO:$acc"; # we still haven't decided on whether id's should include the prefix...
- }
- $sth->execute($acc);
- my ($term, $def) = $sth->fetchrow_array;
- if ($term){
- $MOBY_RESPONSE .= simpleResponse("
- <moby:GO_Term namespace='GO' id='$acc'>
- <moby:String namespace='' id='' articleName='Term'>$term</moby:String>
- <moby:String namespace='' id='' articleName='Definition'>$def</moby:String>
- </moby:GO_Term>")
- } else {
- $MOBY_RESPONSE .= simpleResponse("")
- }
- }
return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);
}
-
sub getGoTermAssociations {
+ my ($caller, $message) = @_;
+ my $MOBY_RESPONSE;
+ my (@inputs)= genericServiceInputParser($message); # ([SIMPLE, $queryID, $simple],...)
+ return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
- my $SOM = pop;
- my ($self, $data) = @_;
- my $response = "";
- my @accessions;
- # first, get the valid URI for the namespace that we accept
- my $OS = MOBY::Client::OntologyServer->new;
- my ($s, $m, $VALID_NAMESPACE) = $OS->namespaceExists(term => 'GO');
- unless ($VALID_NAMESPACE){ # unless we could get the known namespace LSID's we should bail because somethign is very very wrong!
- print STDERR "the namespace GO does not exist in the MOBY namespace ontology\n";
- return SOAP::Data->type('base64' => responseHeader() . responseFooter()); # base 64 encode it (optional)
- }
-
- # now start analyzing the input data
- my @input_nodes = getInputArticles($data);
- foreach (@input_nodes){
- my ($input) = @{$_}; # this service only allows one input per query, so take the first
- my $ns = getSimpleArticleNamespaceURI($input);
- push @accessions, undef unless $ns eq $VALID_NAMESPACE; # if we have been sent an invalid namespace, then stack an undef as a response
- my ($id) = getSimpleArticleIDs($ns, [$input]);
- if (defined $id){
- push @accessions, $id;
- } else {
- push @accessions, undef;
- }
- }
-
- use DBI;
- use DBD::mysql;
my $dbh = _dbAccess('go');
- die "can't connecvt to database\n" unless $dbh;
+ die "can't connect to database\n" unless $dbh;
my $sth = $dbh->prepare("
select
gp.symbol,
@@ -125,27 +101,39 @@
and a.is_not = 0
and t.id = d.term_id
order by species_id");
-
- foreach my $acc(@accessions){
- unless ($acc =~/^GO:/){
- $acc = "GO:$acc"; # we still haven't decided on whether id's should include the prefix...
- }
- my @simples;
- $sth->execute($acc);
- while (my ($symb, $sp, $namsp, $type, $name, $def) = $sth->fetchrow_array){
- my $response_data .= "<Object namespace='$namsp' id='$symb'>\n";
- $response_data .= " <CrossReference>\n";
- $response_data .= " <Invocation namespace='GO' id='$acc'/>\n";
- $response_data .= " <Object namespace='taxon' id='$sp'/>\n";
- $response_data .= " </CrossReference>\n";
- $response_data .= "</Object>\n";
- push @simples, $response_data;
+
+ my @validNS = validateNamespaces("GO"); # ONLY do this if you are intending to be namespace aware!
+
+ foreach (@inputs){
+ my ($articleType, $ID, $input) = @{$_};
+ unless ($articleType == SIMPLE){
+ $MOBY_RESPONSE .= collectionResponse([], "Collection_Article_Input_Invalid", $ID) ;
+ next;
+ } else {
+ my $ns = getSimpleArticleNamespaceURI($input);
+ (($MOBY_RESPONSE .= $MOBY_RESPONSE .= collectionResponse([], "Invalid_Namespace", $ID)) && (next)) unless validateThisNamespace($ns, @validNS); # only do this if you are truly validating namespaces
+ my $acc, defined(getSimpleArticleIDs($ns, [$input]))?getSimpleArticleIDs($ns,[$input]):undef;
+ unless (defined($acc)){
+ $MOBY_RESPONSE .= collectionResponse([], "Invalid_Accession", $ID);
+ next;
+ }
+ unless ($acc =~/^GO:/){
+ $acc = "GO:$acc"; # we still haven't decided on whether id's should include the prefix...
+ }
+ my @simples;
+ $sth->execute($acc);
+ while (my ($symb, $sp, $namsp, $type, $name, $def) = $sth->fetchrow_array){
+ my $response_data .= "<Object namespace='$namsp' id='$symb'>\n";
+ $response_data .= " <CrossReference>\n";
+ $response_data .= " <Object namespace='taxon' id='$sp'/>\n";
+ $response_data .= " </CrossReference>\n";
+ $response_data .= "</Object>\n";
+ push @simples, $response_data;
+ }
+ $MOBY_RESPONSE .= collectionResponse(\@simples,"Known_GO_Term_Associations",$ID); # after all images have been collected, create the collection
}
- $response .= collectionResponse(\@simples); # after all images have been collected, create the collection
}
- $response = responseHeader() . $response . responseFooter();
- my $SOAPResponse = SOAP::Data->type('base64' => $response);
- return $SOAPResponse
+ return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);
}
@@ -153,67 +141,51 @@
sub RetrieveGOFromKeywords {
my $SOM = pop;
my ($self, $query) = @_;
- use GO::AppHandle;
-
- my $ua = new LWP::UserAgent;
- my $req = new HTTP::Request GET => 'http://www.godatabase.org/dev/database/server.cfg';
- my $res = $ua->request($req);
+ # INITIALIZE CONNECTION TO GO DB
my $host; my $dbname;
$host = "sin.lbl.gov";
$dbname = "go";
-# if ($res->is_success) {
- # my $resp = $res->content;
- # if ($resp =~ /(\w+)\@(\S+)/){
- # $host = $2;
- # $dbname= $1;
- # } else {
- # return SOAP::Data->type('base64' => responseHeader() . responseFooter()); # base 64 encode it (optional)
- # }
- #}
my %connect_hash;
$connect_hash{-dbname}=$dbname;
$connect_hash{-dbhost}=$host;
-
my $GO_API = GO::AppHandle->connect(%connect_hash);
unless ($GO_API){
return SOAP::Data->type('base64' => responseHeader() . responseFooter()); # base 64 encode it (optional)
}
+ # DB is now initialized
- # first, get the valid URI for the namespace that we accept
- my $OS = MOBY::Client::OntologyServer->new;
- my ($s, $m, $VALID_NAMESPACE) = $OS->namespaceExists(term => 'Global_Keyword');
- unless ($VALID_NAMESPACE){ # unless we could get the known namespace LSID's we should bail because somethign is very very wrong!
- print STDERR "the namespace Global_Keyword does not exist in the MOBY namespace ontology\n";
- return SOAP::Data->type('base64' => responseHeader() . responseFooter()); # base 64 encode it (optional)
- }
+ my $MOBY_RESPONSE;
+ my (@inputs)= genericServiceInputParser($query); # ([SIMPLE, $queryID, $simple],...)
+ return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
- # now start analyzing the input data
- my @input_nodes = getInputArticles($query); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
- my $response;
- foreach (@input_nodes){
- my $input = $_->[0]; # we only allow one input object per query
- my ($kw) = getSimpleArticleIDs($VALID_NAMESPACE, [$input]);
- ($kw) = (($kw =~ /^\s*(.*)\s*$/) && ($1));
- my @terms = @{$GO_API->get_terms({search=>"$kw"})};
- next unless($terms[0]);
- my @simples;
- foreach my $term(@terms){
- my $acc = $term->public_acc;
- my $def = $term->definition;
- my $name = $term->name;
- push @simples, "<moby:GO_Term namespace='GO' id='$acc'>
- <CrossReference>
- <Invocation namespace='$VALID_NAMESPACE' id='$kw'/>
- </CrossReference>
- <moby:String namespace='' id='' articleName='Term'>$name</moby:String>
- <moby:String namespace='' id='' articleName='Definition'>$def</moby:String>
- </moby:GO_Term>";
+ my @validNS = validateNamespaces("Global_Keyword"); # ONLY do this if you are intending to be namespace aware!
+ foreach (@inputs){
+ my ($articleType, $ID, $input) = @{$_};
+ unless ($articleType == SIMPLE){
+ $MOBY_RESPONSE .= collectionResponse([], "Collection_Input_Invalid", $ID) ;
+ next;
+ } else {
+ my $ns = getSimpleArticleNamespaceURI($input);
+ (($MOBY_RESPONSE .= collectionResponse([], "Invalid_Namespace", $ID)) && (next)) unless validateThisNamespace($ns, @validNS); # only do this if you are truly validating namespaces
+ my $kw = defined(getSimpleArticleIDs($ns, [$input]))?getSimpleArticleIDs($ns,[$input]):undef;
+ ($MOBY_RESPONSE .= collectionResponse([], "No_Keyword", $ID) && (next)) unless defined $kw;
+ ($kw) = (($kw =~ /^\s*(.*)\s*$/) && ($1));
+ my @terms = @{$GO_API->get_terms({search=>"$kw"})};
+ next unless($terms[0]);
+ my @simples;
+ foreach my $term(@terms){
+ my $acc = $term->public_acc;
+ my $def = $term->definition;
+ my $name = $term->name;
+ push @simples, "<moby:GO_Term namespace='GO' id='$acc'>
+ <moby:String namespace='' id='' articleName='Term'>$name</moby:String>
+ <moby:String namespace='' id='' articleName='Definition'>$def</moby:String>
+ </moby:GO_Term>";
+ }
+ $MOBY_RESPONSE .= collectionResponse(\@simples, "GO_terms_from_keywords", $ID);
}
- $response .= collectionResponse(\@simples);
- }
- $response = responseHeader() . $response . responseFooter();
- my $SOAPResponse = SOAP::Data->type('base64' => $response);
- return $SOAPResponse
+ }
+ return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);
}
More information about the MOBY-guts
mailing list