[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Tue Jun 10 22:30:11 UTC 2003


mwilkinson
Tue Jun 10 18:30:11 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY/Services
In directory pub.open-bio.org:/tmp/cvs-serv1638/Services

Modified Files:
	BasicLocalServices.pm 
Log Message:
but in the discovery of services by output fixed.  Added an (as yet untested) example of a MOBY Service that takes GO Accessions and returns GO Term objects.  I am testing it on my local server right now and will deploy it publicly and  make a comment about it on-list if it works

moby-live/Perl/MOBY/Services BasicLocalServices.pm,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Services/BasicLocalServices.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY/Services/BasicLocalServices.pm	2003/02/19 23:14:47	1.1
+++ /home/repository/moby/moby-live/Perl/MOBY/Services/BasicLocalServices.pm	2003/06/10 22:30:11	1.2
@@ -8,28 +8,105 @@
 @ISA = qw(SOAP::Server::Parameters);   # uncomment this line if you want access to the SOM as the
                                        # last parameter passed to thh subroutine
 
-sub ExampleService {
+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();
-        foreach my $node ($moby->getChildNodes()) {
-                next unless $node->getNodeType == ELEMENT_NODE;
-                push(@objects,$node->toString());
+    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');
+    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;
+            }
         }
-        
-        foreach (@objects){
-                $response .= "$_\n";
+	}
+    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("")
         }
-        my $responseFull = "<MOBY AuthURI='http://illuminae.com'>\n".$response."</MOBY>\n";
-        my $SOAPResponse = SOAP::Data->type('base64' => $responseFull);
-        
-    return  $SOAPResponse;
+    }
+ 
+    $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'>
+        ";
 }
 
-1;
+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-guts mailing list