[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Thu Jul 10 02:16:17 UTC 2003


mwilkinson
Wed Jul  9 22:16:17 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv1466/Perl/scripts/Services

Modified Files:
	LocalServices.pm 
Log Message:
added four new example services to the LocalServices module.  These are all registered and running.

moby-live/Perl/scripts/Services LocalServices.pm,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/01 16:36:43	1.5
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/10 02:16:17	1.6
@@ -1,6 +1,7 @@
 package Services::LocalServices;
 
 use lib "/var/www/cgi-bin";
+use lib "/usr/local/apache/cgi-bin/bioperl/core";
 use strict;
 use MIME::Base64;
 use XML::DOM;
@@ -12,31 +13,20 @@
 
     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 $response; my @accessions;
 
-    my $x = $moby->getElementsByTagName('queryInput');
-    unless ($x->item(0)){
-		$x = $moby->getElementsByTagName('moby:queryInput');
+	my @input_nodes = $self->_getSimpleChildNodes($data);
+	foreach (@input_nodes){
+		my $content .= $_->toString;
+		unless (($content =~ /namespace\s*=\s*['"]GO.*?id\s*=\s*['"](GO:\d\d\d\d\d\d\d)/s) ||  # this would be  a lot easier to track if I used a real XML parser
+				($content =~ /namespace\s*=\s*['"]GO.*?id\s*=\s*['"](\d+)/s) ){  # we don't know yet what a GO id should look like "GO:0001823" or "0001823"
+			push @accessions, undef;  # we must return a respnse node for *every* input node, even if it is invalid
+									# and the response nodes must appear in the same order
+		} else {
+			push @accessions, $1;
+		}
     }
 
-    my @accessions;
-    for (0..$x->getLength-1){
-        my @child = $x->item($_)->getChildNodes;
-        my $content;
-        foreach (@child){
-            $content .= $_->toString;
-            unless ($content =~ /namespace\s*=\s*['"]GO.*?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');
@@ -62,7 +52,169 @@
     return $SOAPResponse
     
 }
-    
+
+#  ===============================================
+#  =    Genbank Retrieval Scripts                =
+#  =                                             =
+#  = Note:  The two VirtualSequenceRetrieve's    =
+#  =        and two SequenceRetrieves below could=
+#  =        have been registered as two services =
+#  =        instead of four, by simply           =
+#  =        registering each under two different =
+#  =        namespaces (Acc and gi) instead of   =
+#  =        having a single service for each     =
+#  =        namespace                            =
+#  ===============================================
+sub GenbankAccVirtualSequenceRetrieve {
+    my $SOM = pop;  
+    my ($self, $data) = @_;
+    my $response; my @accessions;
+
+	my @input_nodes = $self->_getSimpleChildNodes($data);
+	@accessions = $self->_getIDs("NCBI_Acc", \@input_nodes);
+	foreach (@accessions){
+		use Bio::DB::GenBank;
+		my $gb = new Bio::DB::GenBank;
+		my $seq = $gb->get_Seq_by_acc($_);
+		my $length;
+		if ($seq){$length = $seq->length;}
+		if ($length){
+			$response .= simpleResponse("
+		<moby:VirtualSequence namespace='NCBI_Acc' id='$_'>
+			<moby:Int namespace='' id='' articleName='Length'>$length</moby:Int>
+		</moby:VirtualSequence>");
+		} else {
+			$response .= simpleResponse("");
+		}
+	}
+		
+    $response =  responseHeader() . $response . responseFooter();
+    my $SOAPResponse = SOAP::Data->type('base64' => $response);
+    return $SOAPResponse
+}
+sub GenbankAccSequenceRetrieve {
+    my $SOM = pop;  
+    my ($self, $data) = @_;
+    my $response; my @accessions;
+
+	my @input_nodes = $self->_getSimpleChildNodes($data);
+	@accessions = $self->_getIDs("NCBI_Acc", \@input_nodes);
+	foreach (@accessions){
+		use Bio::DB::GenBank;
+		my $gb = new Bio::DB::GenBank;
+		my $seq = $gb->get_Seq_by_acc($_);
+		my $length;my $sequence;
+		if ($seq){$length = $seq->length;$sequence = $seq->seq}
+		if ($length){
+			$response .= simpleResponse("
+		<moby:GenericSequence namespace='NCBI_Acc' id='$_'>
+			<moby:Int namespace='' id='' articleName='Length'>$length</moby:Int>
+			<moby:String namespace='' id='' articleName='SequenceString'>$sequence</moby:Int>
+		</moby:GenericSequence>");
+		} else {
+			$response .= simpleResponse("");
+		}
+	}
+	
+    $response =  responseHeader() . $response . responseFooter();
+    my $SOAPResponse = SOAP::Data->type('base64' => $response);
+    return $SOAPResponse   
+}
+sub GenbankGIVirtualSequenceRetrieve {
+    my $SOM = pop;  
+    my ($self, $data) = @_;
+    my $response; my @accessions;
+
+	my @input_nodes = $self->_getSimpleChildNodes($data);
+	@accessions = $self->_getIDs("NCBI_gi", \@input_nodes);
+	foreach (@accessions){
+		use Bio::DB::GenBank;
+		my $gb = new Bio::DB::GenBank;
+		my $seq = $gb->get_Seq_by_gi($_);
+		my $length;
+		if ($seq){$length = $seq->length;}
+		if ($length){
+			$response .= simpleResponse("
+		<moby:VirtualSequence namespace='NCBI_gi' id='$_'>
+			<moby:Int namespace='' id='' articleName='Length'>$length</moby:Int>
+		</moby:VirtualSequence>");
+		} else {
+			$response .= simpleResponse("");
+		}
+	}
+	
+    $response =  responseHeader() . $response . responseFooter();
+    my $SOAPResponse = SOAP::Data->type('base64' => $response);
+    return $SOAPResponse   
+}
+sub GenbankGISequenceRetrieve {
+    my $SOM = pop;  
+    my ($self, $data) = @_;
+    my $response; my @accessions;
+
+	my @input_nodes = $self->_getSimpleChildNodes($data);
+	@accessions = $self->_getGenbankGI("NCBI_gi", \@input_nodes);
+	foreach (@accessions){
+		use Bio::DB::GenBank;
+		my $gb = new Bio::DB::GenBank;
+		my $seq = $gb->get_Seq_by_gi($_);  # get the sequence object for each gi
+		my $length;my $sequence;
+		if ($seq){$length = $seq->length;$sequence = $seq->seq}  # if it exists, get the length and sequence
+		if ($length){  # and construct the response
+			$response .= simpleResponse("
+		<moby:GenericSequence namespace='NCBI_gi' id='$_'>
+			<moby:Int namespace='' id='' articleName='Length'>$length</moby:Int>
+			<moby:String namespace='' id='' articleName='SequenceString'>$sequence</moby:Int>
+		</moby:GenericSequence>");
+		} else {
+			$response .= simpleResponse("");
+		}
+	}
+    $response =  responseHeader() . $response . responseFooter();
+    my $SOAPResponse = SOAP::Data->type('base64' => $response);
+    return $SOAPResponse;
+}
+#=================================================
+#=================================================
+#=================================================
+
+
+sub _getIDs {
+	my ($self, $desired_namespace, $input_nodes) = @_;
+	return undef unless $input_nodes;
+	return undef unless scalar @{$input_nodes};
+	my @input_nodes = @{$input_nodes};
+	
+	my @accessions;	
+	foreach (@input_nodes){
+		my $ns = $_->getAttributeNode('namespace');  # get the namespace DOM node
+		$ns = $_->getAttributeNode('moby::namespace') unless ($ns);  # perhaps it is namespaced...
+		unless ($ns){   # if we don't get it at all, then move on to the next input
+			push @accessions, undef;  # but push an undef onto teh stack in order
+			next;
+		}
+		$ns = $ns->getValue;   # if we have a namespace, then get its value
+		unless ($ns eq $desired_namespace){  # we are registering as working in a particular namespace, so check this
+			push @accessions, undef;  # and push undef onto the stack if it isn't 
+			next;
+		}
+		# Now do the same thing for ID's
+		my $id = $_->getAttributeNode('id');
+		$id = $_->getAttributeNode('moby::id') unless ($id);
+		unless ($id){
+			push @accessions, undef;
+			next;
+		}
+		$id = $id->getValue;
+		unless (defined $id){  # it has to have a hope in hell of retrieving something...
+			push @accessions, undef;  # otherwise push undef onto the stack if it isn't 
+			next;
+		}
+		push @accessions, $id;
+	}
+	return @accessions;
+}
+
 sub responseHeader {
     return "<?xml version='1.0' encoding='UTF-8'?>
       <moby:MOBY xmlns:moby='http://www.biomoby.org/moby'>
@@ -102,6 +254,26 @@
 	}
 }
 
+sub _getSimpleChildNodes {
+
+	my ($self, $XML) = @_;
+    my $parser = new XML::DOM::Parser;
+    my $doc = $parser->parse($XML);
+    my $moby = $doc->getDocumentElement();
+
+    my $x = $moby->getElementsByTagName('queryInput');  # get teh queryInput block
+    unless ($x->item(0)){
+		$x = $moby->getElementsByTagName('moby:queryInput');
+    }
+
+    my @nodes;
+    for (0..$x->getLength-1){
+		# there *should* only be one node per queryInput in a Simple article, but... yeah...
+        push @nodes, $x->item($_)->getChildNodes;   # anyway, take all of the children, which are input objects
+	}
+	return @nodes;  # return them in the order that they were discovered.
+}
+
 sub _dbAccess {
     my ($dbname) = @_;
     return undef unless $dbname;




More information about the MOBY-guts mailing list