[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Mon Jul 14 19:35:05 UTC 2003


mwilkinson
Mon Jul 14 15:35:05 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv1668/Perl/scripts/Services

Modified Files:
	LocalServices.pm 
Log Message:
still porting my LocalServices to use the new CommonSubs module subroutines

moby-live/Perl/scripts/Services LocalServices.pm,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/14 16:34:43	1.15
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/14 19:35:05	1.16
@@ -9,21 +9,33 @@
 use MIME::Base64;
 use XML::DOM;
 use MOBY::Client::OntologyServer;
-use MOBY::CommonSubs qw(:all);
+use MOBY::CommonSubs qw(:all);  # this provides the
+# subroutines:
+#getSimpleArticleIDs
+#getSimpleArticleNamespaceURI
+#simpleResponse
+#responseHeader
+#responseFooter
+#getInputArticles
+#getNodeContentWithArticle
 
 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
+                                       # last parameter passed to the subroutine
 
 sub getGoTerm {
 
     my $SOM = pop;  
     my ($self, $data) = @_;
-    my $response; my @accessions;
+    my $response = "";
+	my @accessions;
 	# first, get the valid URI for the namespace that we accept
 	my $OS = MOBY::Client::OntologyServer->new;
-	my $VALID_NAMESPACE = $OS->namespaceExists(term => 'GO');
-	$VALID_NAMESPACE || die "Expected Namespace 'GO' does not exist in the MOBY namespace ontology!";
+	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);
@@ -82,8 +94,21 @@
     my ($self, $data) = @_;
     my $response; my @accessions;
 
-	my @input_nodes = $self->_getSimpleChildNodes($data);
-	@accessions = $self->_getIDs("NCBI_Acc", \@input_nodes);
+	# 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 => 'NCBI_Acc');
+	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 NCBI_Acc 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); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
+	my @inputs;
+	foreach (@input_nodes){
+		push @inputs, $_->[0];  # we only allow one input object per query
+	}
+	@accessions = getSimpleArticleIDs($VALID_NAMESPACE, \@inputs);
 	foreach my $acc (@accessions){
 		unless (defined $acc){
 			$response .= simpleResponse("");
@@ -113,8 +138,21 @@
     my ($self, $data) = @_;
     my $response; my @accessions;
 
-	my @input_nodes = $self->_getSimpleChildNodes($data);
-	@accessions = $self->_getIDs("NCBI_Acc", \@input_nodes);
+	# 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 => 'NCBI_Acc');
+	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 NCBI_Acc 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); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
+	my @inputs;
+	foreach (@input_nodes){
+		push @inputs, $_->[0];  # we only allow one input object per query
+	}
+	@accessions = getSimpleArticleIDs($VALID_NAMESPACE, \@inputs);
 	foreach my $acc(@accessions){
 		unless (defined $acc){
 			$response .= simpleResponse("");
@@ -145,8 +183,21 @@
     my ($self, $data) = @_;
     my $response; my @accessions;
 
-	my @input_nodes = $self->_getSimpleChildNodes($data);
-	@accessions = $self->_getIDs("NCBI_gi", \@input_nodes);
+	# 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 => 'NCBI_gi');
+	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 NCBI_gi 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); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
+	my @inputs;
+	foreach (@input_nodes){
+		push @inputs, $_->[0];  # we only allow one input object per query
+	}
+	@accessions = getSimpleArticleIDs($VALID_NAMESPACE, \@inputs);
 	foreach my $acc(@accessions){
 		unless (defined $acc){
 			$response .= simpleResponse("");
@@ -171,13 +222,27 @@
     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->_getIDs("NCBI_gi", \@input_nodes);
+	# 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 => 'NCBI_gi');
+	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 NCBI_gi 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); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
+	my @inputs;
+	foreach (@input_nodes){
+		push @inputs, $_->[0];  # we only allow one input object per query
+	}
+	@accessions = getSimpleArticleIDs($VALID_NAMESPACE, \@inputs);
 	foreach my $acc(@accessions){
 		unless (defined $acc){
 			$response .= simpleResponse("");
@@ -220,17 +285,25 @@
 	my ($s2, $m2, $GB_gi_LSID) = $OS->namespaceExists(term => "NCBI_gi");
 
 	unless ($s && $s2){  # unless we could get the known namespace LSID's we should bail because somethign is very very wrong!
-		my $fullresponse =  responseHeader() . responseFooter();  # add the headers and footers
-		my $SOAPResponse = SOAP::Data->type('base64' => $fullresponse);  # base 64 encode it (optional)
-		return $SOAPResponse;	
+		print STDERR "the namespace NCBI_Acc or NCBI_gi does not exist in the MOBY namespace ontology\n";
+		return SOAP::Data->type('base64' => responseHeader() . responseFooter());  # base 64 encode it (optional)
 	}
 	
-	my @input_nodes = $self->_getSimpleChildNodes($data);
-	foreach my $node(@input_nodes){
+	# now start analyzing the input data
+	my @input_nodes = getInputArticles($data); # returns ([obj1, obj2], [obj3, obj4], [obj5], [obj6],...)
+	my @inputs;
+	foreach (@input_nodes){
+		push @inputs, $_->[0];  # we only allow one input object per query
+	}
+	foreach my $node(@inputs){
  
-		my $namespace_LSID = $self->_getNamespaceURI($node);  # get the LSID of the namespace for this input object
-		my @IDs= $self->_getIDs($namespace_LSID, [$node]);  # get the ID within this namespace
-		my $ID = $IDs[0];  # there is only one, so this is safe
+		my $namespace_LSID = getSimpleArticleNamespaceURI($node);  # get the LSID of the namespace for this input object
+		unless (($namespace_LSID eq $GB_Acc_LSID) || ($namespace_LSID eq $GB_gi_LSID)){ # validate the namespace
+			$response .= simpleResponse("");  # because we have to send one response per input, send a blank if bad namespace
+			next;
+		}
+			
+		my ($ID)= getSimpleArticleIDs($namespace_LSID, [$node]);  # get the ID within this namespace
 		unless (defined $ID){  # send a blank if we failed to get an id, 
 			$response .= simpleResponse("");  # because we have to send one response per input
 			next;
@@ -289,135 +362,6 @@
     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 $OS = MOBY::Client::OntologyServer->new;
-	my ($s, $m);
-	($s, $m, $desired_namespace) = $OS->namespaceExists(term => $desired_namespace); # returns (success, message, lsid)
-	return undef unless $s;  # bail if not successful
-
-	my @accessions;	
-	foreach my $in(@input_nodes){
-		#$in = "<Simple><Object namespace='' id=''/></Simple>"
-		my @simples = $in->getChildNodes;
-		foreach (@simples){ # $_ = <Object namespace='' id=''/>
-			next unless $_->getNodeType == ELEMENT_NODE;
-			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
-			($s, $m, $ns) = $OS->namespaceExists(term => $ns);
-			
-			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 _getNamespaceURI {
-	# pass me a <SIMPLE> input node and I will give you the lsid of the namespace of that input object
-
-	my ($self, $input_node) = @_;
-	return undef unless $input_node;
-	my $OS = MOBY::Client::OntologyServer->new;
-	
-	#$input_node = "<Simple><Object namespace='' id=''/></Simple>"
-	my @simples = $input_node->getChildNodes;
-	foreach (@simples){ # $_ = <Object namespace='' id=''/>   # should be just one, so I will return at will from this routine
-		next unless $_->getNodeType == ELEMENT_NODE;
-		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
-			return undef
-		}
-		my ($s, $m, $lsid) = $OS->namespaceExists(term => $ns->getValue);   # if we have a namespace, then get its value
-		return undef unless $s;
-		return $lsid
-	}
-}
-
-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>
-        ";
-    } elsif($data) {
-        return "
-        <moby:queryResponse>
-            <Simple>
-                $data
-            </Simple>
-        </moby:queryResponse>
-        ";
-    } else {
-	return "
-        <moby:queryResponse>
-        </moby:queryResponse>
-	";
-	}
-}
-
-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