[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Thu Jul 10 19:51:24 UTC 2003
mwilkinson
Thu Jul 10 15:51:24 EDT 2003
Update of /home/repository/moby/moby-live/Perl/scripts/Services
In directory pub.open-bio.org:/tmp/cvs-serv6028/Perl/scripts/Services
Modified Files:
LocalServices.pm
Log Message:
first steps towards an independent set of modules to deal with the ontology server. the server itself is currently running as a littl CGI script on mobycentral. These things are still in their infancy and subject to major change, so don't build code that depends on them or you will wish you had not...
moby-live/Perl/scripts/Services LocalServices.pm,1.10,1.11
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm 2003/07/10 04:05:04 1.10
+++ /home/repository/moby/moby-live/Perl/scripts/Services/LocalServices.pm 2003/07/10 19:51:24 1.11
@@ -194,6 +194,77 @@
#=================================================
#=================================================
+sub GenbankCompleteSequenceRetrieve {
+
+# this service is registered as consuming NCBI_Acc OR NCBI_gi
+# and producing GenericSequence objects. However, it will
+# actually produce DNA, RNA or PRotein objects, as appropriate
+# and will produce a cross-reference block as well
+ my $SOM = pop;
+ my ($self, $data) = @_;
+ my $response; my @gis;
+
+ 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 $ID = $IDs[0]; # there is only one, so this is safe
+ unless (defined $ID){
+ $response .= simpleResponse("");
+ next;
+ }
+ use Bio::DB::GenBank;
+ my $gb = new Bio::DB::GenBank;
+ 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
+ } else {
+ $response .= simpleResponse("");
+ next;
+ }
+
+ my $length;my $sequence;
+ if ($seq){
+ $length = $seq->length;$sequence = $seq->seq; # if it exists, get the length and sequence
+ } else {
+ $response .= simpleResponse("");
+ next;
+ }
+ my $gi = $seq->prinary_id;
+ my $acc = $seq->accession; # e.g. A123434
+ my $kw = $seq->species->binomial; # e.g. mus musculus
+ my $moltype = $seq->alphabet; # 'dna', 'rna', 'protein'
+ my $taxon = $seq->species->ncbi_taxid; # e.g. 1234
+
+ my $ObjectType="GenericSequence"; # set it as the generic as default
+ if ($moltype eq 'dna'){$ObjectType = "DNASequence"} # set to DNA
+ elsif ($moltype eq 'rna'){$ObjectType = "RNASequence"} # set to RNA
+ elsif ($moltype eq 'protein'){$ObjectType = "AminoAcidSequence"} # set to Protein
+
+ if ($length){ # and construct the response
+ my $tempresponse .= "
+ <moby:$ObjectType namespace='$namespace' 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'/>"}
+ $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("");
+ }
+ }
+ my $fullresponse = responseHeader() . $response . responseFooter(); # add the headers and footers
+ my $SOAPResponse = SOAP::Data->type('base64' => $fullresponse); # base 64 encode it (optional)
+ return $SOAPResponse;
+}
+
sub _getIDs {
my ($self, $desired_namespace, $input_nodes) = @_;
@@ -237,6 +308,23 @@
return @accessions;
}
+sub _getNamespace {
+ my ($self, $input_node) = @_;
+ return undef unless $input_node;
+
+ #$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
+ }
+ return $ns->getValue; # if we have a namespace, then get its value
+ }
+}
+
sub responseHeader {
return "<?xml version='1.0' encoding='UTF-8'?>
<moby:MOBY xmlns:moby='http://www.biomoby.org/moby'>
More information about the MOBY-guts
mailing list