[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Wed Dec 10 22:22:03 UTC 2003


mwilkinson
Wed Dec 10 17:22:03 EST 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv32614/Perl/scripts/Services

Modified Files:
	LocalServices.pm 
Log Message:
minor changes to make some CommonSubs more friendly.  Also added a new service which is the beginning of me weaning myself off of GenBank because genbank is broken almost every time I need to use it.  The new service uses SeqHound to make the data lookups, so it is always 24 hours behind the real genbank, but thats not bad.  The new service consumes NCBI_Acc, NCBI_gi, PIR, Swissprot, EMBL, or PDB identifiers and returns the genbank record as a flatfile

moby-live/Perl/scripts/Services LocalServices.pm,1.40,1.41
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/12/09 22:56:19	1.40
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/12/10 22:22:03	1.41
@@ -7,6 +7,7 @@
 use lib "/export/home/root/BIOPERL/perl-api";
 
 use strict;
+use SeqHound;
 use SOAP::Lite;
 use DBI;
 use DBD::mysql;
@@ -23,6 +24,7 @@
 #responseFooter
 #getInputArticles
 #getNodeContentWithArticle
+my $debug = 1;
 
 use vars qw(@ISA);
 
@@ -201,49 +203,126 @@
 #  =        having a single service for each     =
 #  =        namespace                            =
 #  ===============================================
-sub GenbankAccVirtualSequenceRetrieve {
-    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 => '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)
-	}
+sub _generic_service_template {
+    my ($caller, $data) = @_;
+    my $MOBY_RESPONSE;
+    my (@inputs)= genericServiceInputParser($data); # ([SIMPLE, $queryID, $simple],...)
+    return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
 
-	# 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
+    my @validNS = validateNamespaces("NCBI_Acc");  # ONLY do this if you are intending to be namespace aware!
+
+    foreach (@inputs){
+        my ($articleType, $qID, $input) = @{$_};
+        unless ($articleType == SIMPLE){
+            $MOBY_RESPONSE .= simpleResponse("", "", $qID) ;
+            next;
+        } else {
+            my $namespace = getSimpleArticleNamespaceURI($input);
+			my ($identifier) = getSimpleArticleIDs($input);  # note array output!
+			# do your thing here!
+        }
+    }
+    return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);    
+}
+
+sub MOBYSHoundGetGenBankff {
+    my ($caller, $data) = @_;
+	my $MOBY_RESPONSE;
+	
+	my $aa = SHoundInit("TRUE", "MOBY_SHoundGetGenBankff_Service"); # initialize SeqHound
+	$aa = SHoundIsInited(); # confirm initialization
+    return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter) unless $aa eq "TRUE";    
+
+    my (@inputs)= genericServiceInputParser($data); # ([SIMPLE, $queryID, $simple],...)
+    return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
+
+	my %validNS;
+	foreach (qw(NCBI_Acc NCBI_gi PIR Swiss-Prot EMBL PDB)){
+		my ($valid) = validateNamespaces($_);  # we are going to ignore anything that is invalid		
+		$validNS{$_} = $valid;
 	}
-	@accessions = getSimpleArticleIDs($VALID_NAMESPACE, \@inputs);
-	foreach my $acc (@accessions){
-		unless (defined $acc){
-			$response .= simpleResponse("");
-			next;
+
+    foreach (@inputs){
+        my ($articleType, $qID, $input) = @{$_};
+        unless (($articleType == SIMPLE) && (defined($input))){  # we only accept simple inputs to this service
+            $MOBY_RESPONSE .= simpleResponse("", "", $qID) ;  # send back a blank response for this queryID
+            next;
+        } else {
+			my $ns = getSimpleArticleNamespaceURI($input);
+			(($MOBY_RESPONSE .= simpleResponse("", "Invalid_Namespace", $qID)) && next) unless validateThisNamespace($ns, values(%validNS));  # return blank if they have sent us a namespace we don't understand
+			my ($identifier) = getSimpleArticleIDs($input);
+            (($MOBY_RESPONSE .= simpleResponse("", "No_Identifier_provided", $qID)) && next) unless $identifier;
+			if ($ns eq $validNS{'NCBI_gi'}){  # gi numbers are used natively by SeqHound
+				my $gb = SHoundGetGenBankff($identifier);
+	            (($MOBY_RESPONSE .= simpleResponse("", "No_genbank_record_found", $qID)) && next) unless $gb;
+				$MOBY_RESPONSE .= "<genbank-flatfile namespace='NCBI_gi' id='$identifier'><![CDATA[$gb]]></genbank-flatfile>";
+			} elsif ($ns eq $validNS{'NCBI_Acc'}){  # THIS ONE DOESN'T WORK YET????
+				my $gi = SHoundFindAcc($identifier);
+				(($MOBY_RESPONSE .= simpleResponse("", "No_gi_found_for_accession", $qID)) && next) unless $gi;
+				my $gb = SHoundGetGenBankff($gi);
+	            (($MOBY_RESPONSE .= simpleResponse("", "No_genbank_record_found", $qID)) && next) unless $gb;
+				$MOBY_RESPONSE .= "<genbank-flatfile namespace='NCBI_gi' id='$gi'>
+					<CrossReferences>
+						<Object namespace='$ns' id='$identifier'/>
+					</CrossReferences>
+					<![CDATA[$gb]]></genbank-flatfile>";
+			} else {
+				my $gi = SHoundFindName($identifier);
+				(($MOBY_RESPONSE .= simpleResponse("", "No_gi_found_for_accession", $qID)) && next) unless $gi;
+				my $gb = SHoundGetGenBankff($gi);
+	            (($MOBY_RESPONSE .= simpleResponse("", "No_genbank_record_found", $qID)) && next) unless $gb;
+				$MOBY_RESPONSE .= "<genbank-flatfile namespace='NCBI_gi' id='$gi'>
+					<CrossReferences>
+						<Object namespace='$ns' id='$identifier'/>
+					</CrossReferences>
+					<![CDATA[$gb]]></genbank-flatfile>";
+			}
 		}
-		use Bio::DB::GenBank;
-		my $gb = new Bio::DB::GenBank(-retrievaltype => 'io_string');
-		my $seq = $gb->get_Seq_by_acc($acc);
-		my $length;
-		if ($seq){$length = $seq->length;}
-		if ($length){
-			$response .= simpleResponse("
-		<moby:VirtualSequence namespace='NCBI_Acc' id='$acc'>
-			<moby:Integer namespace='' id='' articleName='Length'>$length</moby:Integer>
-		</moby:VirtualSequence>");
-		} else {
-			$response .= simpleResponse("");
+    }
+	$aa = SHoundFini();
+	print STDERR responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter;
+    return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);    
+}
+
+sub GenbankAccVirtualSequenceRetrieve {
+    my ($self, $data) = @_;
+
+    my $MOBY_RESPONSE;
+    my (@inputs)= genericServiceInputParser($data); # ([SIMPLE, $queryID, $simple],...)
+    return SOAP::Data->type('base64' => responseHeader() . responseFooter()) unless (scalar(@inputs));
+
+    my @validNS = validateNamespaces("NCBI_Acc");  # ONLY do this if you are intending to be namespace aware!
+
+    foreach (@inputs){
+        my ($articleType, $qID, $input) = @{$_};
+        unless ($articleType == SIMPLE){
+            $MOBY_RESPONSE .= simpleResponse("", "", $qID) ;
+            next;
+        } else {
+			(($MOBY_RESPONSE .= simpleResponse("", "no_input_object", $qID)) && (next)) unless (defined $input);
+			my $ns = getSimpleArticleNamespaceURI($input);
+			(($MOBY_RESPONSE .= simpleResponse([], "Invalid_Namespace", $qID)) && (next)) unless validateThisNamespace($ns, @validNS);  # only do this if you are truly validating namespaces
+			my ($acc) = defined(getSimpleArticleIDs($ns, [$input]))?getSimpleArticleIDs($ns,[$input]):undef;
+            ($MOBY_RESPONSE .= collectionResponse([], "No_Accession_provided", $qID) && (next)) unless defined $acc;
+			use Bio::DB::GenBank;
+			my $gb = new Bio::DB::GenBank(-retrievaltype => 'io_string');
+			my $seq = $gb->get_Seq_by_acc($acc);
+			my $length;
+			if ($seq){$length = $seq->length;}
+			if ($length){
+				$MOBY_RESPONSE .= simpleResponse("
+			<moby:VirtualSequence namespace='NCBI_Acc' id='$acc'>
+				<moby:Integer namespace='' id='' articleName='Length'>$length</moby:Integer>
+			</moby:VirtualSequence>", "", $qID);
+			} else {
+				$MOBY_RESPONSE .= simpleResponse("", "sequence_has_no_length", $qID);
+			}
 		}
 	}
-		
-    $response =  responseHeader() . $response . responseFooter();
-    my $SOAPResponse = SOAP::Data->type('base64' => $response);
-    return $SOAPResponse
+    return SOAP::Data->type('base64' => responseHeader("illuminae.com") . $MOBY_RESPONSE . responseFooter);    
 }
+
 sub GenbankAccSequenceRetrieve {
     my ($self, $data) = @_;
     my $response; my @accessions;




More information about the MOBY-guts mailing list