[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Sep 12 23:41:44 EDT 2003


mwilkinson
Fri Sep 12 22:41:44 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv21515/Perl/scripts/Services

Modified Files:
	LocalServices.pm 
Log Message:
added new service and a few new utility subroutines to the CommonSubs module

moby-live/Perl/scripts/Services LocalServices.pm,1.33,1.34
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/09/12 14:19:56	1.33
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm	2003/09/13 02:41:44	1.34
@@ -171,15 +171,17 @@
 	my $req = new HTTP::Request GET => 'http://www.godatabase.org/dev/database/server.cfg';
 	my $res = $ua->request($req);
 	my $host; my $dbname;
-	if ($res->is_success) {
-		my $resp =  $res->content;
-		if ($resp =~ /(\w+)\@(\S+)/){
-			$host = $2;
-			$dbname= $1;
-		} else {
-			return SOAP::Data->type('base64' => responseHeader() . responseFooter());  # base 64 encode it (optional)
-		}
-	}
+	$host = "sin.lbl.gov";
+	$dbname = "go";
+#	if ($res->is_success) {
+	#	my $resp =  $res->content;
+	#	if ($resp =~ /(\w+)\@(\S+)/){
+	#		$host = $2;
+	#		$dbname= $1;
+	#	} else {
+	#		return SOAP::Data->type('base64' => responseHeader() . responseFooter());  # base 64 encode it (optional)
+	#	}
+	#}
 	my %connect_hash;
 	$connect_hash{-dbname}=$dbname;
 	$connect_hash{-dbhost}=$host;
@@ -430,11 +432,9 @@
     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 ($GB_Acc_LSID, $GB_gi_LSID) = validateNamespaces('NCBI_Acc', 'NCBI_gi');
+	unless ($GB_Acc_LSID && $GB_gi_LSID){  # unless we could get the known namespace LSID's we should bail because somethign is very very wrong!
 		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)
 	}
@@ -512,6 +512,75 @@
     return $SOAPResponse;	
 }
 
+
+sub GenbankRecordRetrieve {
+	use Bio::SeqIO;
+	use IO::String;
+    my $SOM = pop;  
+    my ($self, $data) = @_;
+    my $response; # prepare a variable to hold the responses
+
+	# Step 1 - validate the namespaces you plan to accept as input
+	my ($GB_Acc_LSID, $GB_gi_LSID, $EMBL_LSID) = validateNamespaces('NCBI_Acc', 'NCBI_gi', 'EMBL');
+	unless ($GB_Acc_LSID && $GB_gi_LSID && $EMBL_LSID){  # unless we could get the known namespace LSID's we should bail because somethign is very very wrong!
+		print STDERR "the namespace NCBI_Acc, NCBI_gi, or EMBL_LSID that we are expecting does not exist in the MOBY namespace ontology\n";
+		return SOAP::Data->type('base64' => responseHeader() . responseFooter());  # base 64 encode it (optional)
+	}
+
+	# Step 2 - get your input objects
+	# in this case, we have registered as accepting
+	# only simple inputs (not collections), therefore
+	# we can insist on that constraint.
+	my @inputs = getInputArticles($data); # returns ([SimpleDOM], [SimpleDOM],...), each represents a unique query input
+	foreach my $node(@inputs){
+		# do a bit of simple validation
+		# the next 12 lines or so are ~cut-n-paste for every service
+		unless (isSimpleArticle($node)){ 		# we only allow Simple inputs to this service, ignore anything else
+			$response .= simpleResponse("");	# because we have to send one response per input, send a blank if it fails
+			next;
+		}
+		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) || $namespace_LSID eq $EMBL_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, send a blank if there is no id (?!?)
+			next;
+		}
+
+		# Now, do the analysis
+		use Bio::DB::GenBank;
+		use Bio::DB::EMBL;
+		my $gb = new Bio::DB::GenBank(-retrievaltype => 'io_string');  # now that we have a namespace and ID, we are ready to retrieve
+		my $emb = new Bio::DB::EMBL(-retrievaltype => 'io_string');
+		my $seq;
+		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
+		} elsif ($namespace_LSID  eq $EMBL_LSID) { # if the namespace is a genbank gi
+			$seq = $gb->get_Seq_by_acc($ID);  # get the sequence object for the gi
+		} else {
+			$response .= simpleResponse("");  # if it is neither,then send a blank as required by the API
+			next;
+		}
+
+		my $string;
+		my $stringio = IO::String->new($string);
+		my $out = Bio::SeqIO->new('-fh' => $stringio,
+							   '-format' => 'genbank');
+		# output goes into $string
+		$out->write_seq($seq);
+		$response .= simpleResponse("<moby:genbank-flatfile namespace='$namespace_LSID' id='$ID'><![CDATA[$string]]></moby:genbank-flatfile>"); # append this queryResponse to the list
+	}
+    my $fullresponse =  responseHeader() . $response . responseFooter();  # add the headers and footers around all queryResponses
+    my $SOAPResponse = SOAP::Data->type('base64' => $fullresponse);  # base 64 encode it (optional)
+    return $SOAPResponse;	# and yer done!
+}
+
+
 #################################################
 #################################################
 ####   DragonDB Subroutines #####################



More information about the MOBY-guts mailing list