[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Thu Jul 10 20:43:09 UTC 2003


mwilkinson
Thu Jul 10 16:43:09 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv6261/scripts/Services

Modified Files:
	LocalServices.pm 
Log Message:
All sorts of changes to make the LSID vs. common name flexibility bulletproof (so long as you are working within a moby: namespace).

moby-live/Perl/scripts/Services LocalServices.pm,1.11,1.12
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/10 19:51:24	1.11
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/07/10 20:43:09	1.12
@@ -2,9 +2,13 @@
 
 use lib "/var/www/cgi-bin";
 use lib "/usr/local/apache/cgi-bin/bioperl/core";
+use lib "/usr/local/apache/cgi-bin/MOBY05/";
+
 use strict;
 use MIME::Base64;
 use XML::DOM;
+use MOBY::Client::OntologyServer;
+
 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
@@ -203,25 +207,36 @@
     my $SOM = pop;  
     my ($self, $data) = @_;
     my $response; my @gis;
+	my $OS = MOBY::Client::OntologyServer->new;
 
+	my ($s, $m, $GB_Acc_LSID) = $OS->namespaceExists(term => "NCBI_Acc");
+	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;	
+	}
+	
 	my @input_nodes = $self->_getSimpleChildNodes($data);
 	foreach my $node(@input_nodes){
-		my $namespace = $self->_getNamespaceURI($node);
-		my @IDs= $self->_getIDs($namespace, [$node]);  # send the node to get the id
+		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
-		unless (defined $ID){
-			$response .= simpleResponse("");
+		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;
 		}
+
 		use Bio::DB::GenBank;
-		my $gb = new Bio::DB::GenBank;
+		my $gb = new Bio::DB::GenBank;  # now that we have a namespace and ID, we are ready to retrieve
 		my $seq;
-		if ($namespace =~ /NCBI_Acc/){
-			$seq = $gb->get_Seq_by_acc($ID);  # get the sequence object for each gi
-		} elsif ($namespace =~ /NCBI_gi/) {
-			$seq = $gb->get_Seq_by_gi($ID);  # get the sequence object for each gi
+		if ($namespace_LSID eq $GB_Acc_LSID){  # if the namespace is a genbank Accession thebn
+			$seq = $gb->get_Seq_by_acc($ID);  # get the sequence object for the accession
+		} elsif ($namespace_LSID  eq $GB_gi_LSID) { # if the namespace is a genbank gi
+			$seq = $gb->get_Seq_by_gi($ID);  # get the sequence object for the gi
 		} else {
-			$response .= simpleResponse("");
+			$response .= simpleResponse("");  # if it is neither,then send a blank as required by the API
 			next;
 		}
 			
@@ -229,10 +244,10 @@
 		if ($seq){
 			$length = $seq->length;$sequence = $seq->seq;  # if it exists, get the length and sequence
 		} else {
-			$response .= simpleResponse("");
+			$response .= simpleResponse("");  # if we got nada, then send a blank as required
 			next;
 		}
-		my $gi = $seq->prinary_id;		
+		my $gi = $seq->prinary_id;		  # e.g. 163483
 		my $acc = $seq->accession;        # e.g. A123434
 		my $kw = $seq->species->binomial; # e.g. mus musculus
 		my $moltype = $seq->alphabet;     #  'dna', 'rna', 'protein'
@@ -243,21 +258,21 @@
 		elsif ($moltype eq 'rna'){$ObjectType = "RNASequence"} # set to RNA
 		elsif ($moltype eq 'protein'){$ObjectType = "AminoAcidSequence"}  # set to Protein
 		
-		if ($length){  # and construct the response
+		if ($length){  # and construct the response; luckily, all of these objects have exactly the same structure :-)
 			my $tempresponse .= "
-		<moby:$ObjectType namespace='$namespace' id='$ID'>
+		<moby:$ObjectType namespace='$namespace_LSID' id='$ID'>
 			<CrossReference>";
 			if ($taxon){ $response .="<Object namespace='taxon' id='$taxon'/>"}
 			if ($kw){$response .="<Object namespace='Global_Keyword' id='$kw'/>"}
-			if ($acc && !($namespace =~ /NCBI_Acc/)){$response .="<Object namespace='NCBI_Acc' id='$acc'/>"}
-			if ($gi && !($namespace =~ /NCBI_gi/)){$response .="<Object namespace='NCBI_gi' id='$gi'/>"}
+			if ($acc && !($namespace_LSID eq $GB_Acc_LSID)){$response .="<Object namespace='NCBI_Acc' id='$acc'/>"}
+			if ($gi && !($namespace_LSID eq $GB_gi_LSID)){$response .="<Object namespace='NCBI_gi' id='$gi'/>"}
 			$response .="</CrossReference>
 			<moby:Int namespace='' id='' articleName='Length'>$length</moby:Int>
 			<moby:String namespace='' id='' articleName='SequenceString'>$sequence</moby:String>
 		</moby:GenericSequence>";
 			$response .= simpleResponse($tempresponse);
 		} else {
-			$response .= simpleResponse("");
+			$response .= simpleResponse("");  # if we failed to get a sequence length, then something weird happened, so just ignore it
 		}
 	}
     my $fullresponse =  responseHeader() . $response . responseFooter();  # add the headers and footers
@@ -271,8 +286,11 @@
 	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>"
@@ -286,6 +304,8 @@
 				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;
@@ -308,9 +328,12 @@
 	return @accessions;
 }
 
-sub _getNamespace {
+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;
@@ -321,7 +344,9 @@
 		unless ($ns){   # if we don't get it at all, then move on to the next input
 			return undef
 		}
-		return $ns->getValue;   # if we have a namespace, then get its value
+		my ($s, $m, $lsid) = $OS->namespaceExists(term => $ns->getValue);   # if we have a namespace, then get its value
+		return undef unless $s;
+		return $lsid
 	}
 }
 




More information about the MOBY-guts mailing list