[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Mon May 3 15:07:51 UTC 2004


mwilkinson
Mon May  3 11:07:51 EDT 2004
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv11683/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
more documentation and tools for dealing with secondary inputs

moby-live/Perl/MOBY CommonSubs.pm,1.47,1.48
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2004/04/29 22:37:57	1.47
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2004/05/03 15:07:51	1.48
@@ -30,9 +30,9 @@
         # Each element of the array is a queryInput block, or a mobyData block
         # the arrayref has the following structure:
         # [SIMPLE, $queryID, $simple]
-        # the first element is a constant "SIMPLE" or "COLLECTION"
+        # the first element is an exported constant SIMPLE, COLLECTION, SECONDARY
         # the second element is the queryID (required for enumerating the responses)
-        # the third element is the XML::DOM for the Simple or Collection block    
+        # the third element is the XML::DOM for the Simple, Collection, or Parameter block    
     my (@inputs)= genericServiceInputParser($data); 
         # or fail properly with an empty response
     return SOAP::Data->type('base64' => responseHeader("my.authURI.com") . responseFooter()) unless (scalar(@inputs));
@@ -163,7 +163,11 @@
 use MOBY::Client::OntologyServer;
 use strict;
 use warnings;
-
+use MOBY::Client::SimpleArticle;
+use MOBY::Client::CollectionArticle;
+use MOBY::Client::SecondaryArticle;
+            
+            
 use constant COLLECTION => 1;
 use constant SIMPLE => 2;
 use constant SECONDARY => 3;
@@ -191,6 +195,7 @@
     validateThisNamespace
     isSimpleArticle
     isCollectionArticle
+    isSecondaryArticle
     extractResponseArticles
     getResponseArticles
     getCrossReferences
@@ -223,6 +228,7 @@
     validateThisNamespace
     isSimpleArticle
     isCollectionArticle
+    isSecondaryArticle
     extractResponseArticles
     getResponseArticles
     getCrossReferences
@@ -244,19 +250,18 @@
 
  name     : genericServiceInputParser
  function : For the MOST SIMPLE SERVICES that take single Simple or Collection inputs
-            and no Secondaries this routine takes the MOBY message and
+            and no Secondaries/Parameters this routine takes the MOBY message and
             breaks the objects out of it in a useful way
  usage    : my @inputs = genericServiceInputParser($MOBY_mssage));
  args     : $message - this is the SOAP payload; i.e. the XML document containing the MOBY message
  returns  : @inputs - the structure of @inputs is a list of listrefs.
             Each listref has three components:
-                1. COLLECTION|SIMPLE|SECONDARY (i.e. constants 1, 2, 3)
-                2. queryID (undef for Secondary parameters)
+                1. COLLECTION|SIMPLE (i.e. constants 1, 2)
+                2. queryID
                 3. $data - the data takes several forms
                          a. $article XML::DOM node for Simples
                             <mobyData...>...</mobyData>
                          b. \@article XML:DOM nodes for Collections
-                         c. $secondary XML::DOM node
 
 =cut
 
@@ -276,7 +281,7 @@
                 push @inputs, [COLLECTION,$queryID, \@simples];
             } elsif (isSimpleArticle($article)){
                 push @inputs, [SIMPLE,$queryID,$article];
-            } elsif (isSecondaryArticle($article)){
+            } elsif (isSecondaryArticle($article)){  # should never happen in a generic service parser!
                 push @inputs, [SECONDARY,$queryID,$article];
             }
         }
@@ -290,7 +295,7 @@
 =head2 complexServiceInputParser
 
  name     : complexServiceInputParser
- function : For more complex services taht have multiple articles for each input
+ function : For more complex services that have multiple articles for each input
             and/or accept parameters, this routine will take a MOBY message and
             extract the Simple/Collection/Parameter objects out of it in a
             useful way.
@@ -317,14 +322,14 @@
             will become:
             (note that SIMPLE, COLLECTION, and SECONDARY are exported constants from this module)
             
-            $inputs->{1} = [ [SIMPLE, $DOM_name1],
-                             [SECONDARY, $DOM_cutoff]
+            $inputs->{1} = [ [SIMPLE, $DOM_name1], # the <Simple> block
+                             [SECONDARY, $DOM_cutoff]  # $DOM_cutoff= <Parameter> block
                            ]
 
             Please see the XML::DOM pod documentation for information about how
             to parse XML DOM objects.
-            
-            
+
+
             Collections --------------------
             
             With inputs that have collections these are presented as a
@@ -347,8 +352,8 @@
 
             will become
             
-            $inputs->{1} = [ [COLLECTION, [$DOM, $DOM] ],
-                             [SECONDARY, $DOM_cutoff]
+            $inputs->{1} = [ [COLLECTION, [$DOM, $DOM] ], # $DOM is the <Simple> Block!
+                             [SECONDARY, $DOM_cutoff]  # $DOM_cutoff = <Parameter> Block
                            ]
 
             Please see the XML::DOM pod documentation for information about how
@@ -891,7 +896,7 @@
         } elsif ($child->getTagName =~ /Collection/){
             $object = MOBY::Client::CollectionArticle->new(XML_DOM => $child);
         } elsif ($child->getTagName =~ /Parameter/){
-            $object = MOBY::Client::CollectionArticle->new(XML_DOM => $child);
+            $object = MOBY::Client::SecondaryArticle->new(XML_DOM => $child);
         }
         next unless $object;
         push @articles, $object;   # take the child elements, which are <Simple/> or <Collection/>
@@ -1097,15 +1102,20 @@
 =head2 getNodeContentWithArticle
 
  name     : getNodeContentWithArticle
- function : get the stringified content of a node that has the correct element and article name
+ function : a very flexible way to get the stringified content of a node
+            that has the correct element and article name
+            or get the value of a Parameter element.
  usage    : @strings = getNodeContentWithArticle($node, $tagname, $articleName)
  args     : (in order)
-            $node        - the XML::DOM node we are searching
-            $tagname     - the tagname (effectively from the Object type ontology)
+            $node        - an XML::DOM node, or straight XML.  It may even
+                           be the entire mobyData block.
+            $tagname     - the tagname (effectively from the Object type ontology),
+                           or "Parameter" if you are trying to get secondaries
             $articleName - the articleName that we are searching for
             
  returns  : an array of the stringified text content for each
             node that matched the tagname/articleName specified.
+            note that each line of content is an element of the string.
  notes    : This was written for the purpose of getting the values of
             String, Integer, Float, Date_Time, and other such primitives.
             For example, in the following XML:
@@ -1126,16 +1136,50 @@
              
             would be analysed as follows:
               
-              my ($query) = @_;  # get the incoming MOBY query XML
-              my @queries = getInputArticles($query);  # returns DOM nodes
-              foreach (@queries){
-                 my @inputs = @{$_}; #(may be more than one Simple/Collection input per query)
-                 foreach my $input(@inputs){
-                     @sequences = getNodeContentWithArticle($_, "String", "SequenceString");
-                     print "matching node contents were ".(join "\n\n", @sequences)."\n"; # join all lines of string
-                 }   
-              }
+              # get $input - e.g. from genericServiceInputParser or complexServiceInputParser
+              @sequences = getNodeContentWithArticle($input, "String", "SequenceString");
 
+            For Parameters, such as the following
+             ...
+             ...
+             <moby:mobyContent>
+                <moby:mobyData>
+                    <Simple>
+                      <Sequence namespace=blah id=blah>
+                           <Integer namespace='' id='' articleName="Length">3</Integer>
+                           <String namespace='' id='' articleName="SequenceString">ATG</String>
+                      </Sequence>
+                    </Simple>
+                    <Parameter articleName='cutoff'>
+                        <Value>24</Value>
+                    </Parameter>
+                </moby:mobyData>
+             </moby:mobyContent>
+             ...
+             ...
+            
+            You would parse it as follows:
+            
+              # get $input - e.g. from genericServiceInputParser or complexServiceInputParser
+              @sequences = getNodeContentWithArticle($input, "String", "SequenceString");
+              @cutoffs = getNodeContentWithArticle($input, "Parameter", "cutoff");
+
+
+ EXAMPLE  :
+           my $inputs = complexServiceInputParser($MOBY_mssage));
+               # $inputs->{$queryID} = [ [TYPE, $DOM], [TYPE, $DOM], [TYPE, $DOM] ]
+           my (@enumerated) = keys %{$inputs};
+           foreach $no (@enumerated){
+             my @articles = @{$inputs->{$no}};
+             foreach my $article(@articles){
+                my ($type, $DOM) = @{$article};
+                if ($type == SECONDARY){
+                    $cutoff = getNodeContentsWithArticle($DOM, "Parameter", "cutoff");
+                } else {
+                   $sequences = getNodeContentWithArticle($DOM, "String", "SequenceString");
+                }
+             }
+           }
 
 =cut
 
@@ -1157,19 +1201,38 @@
     unless ($nodes->item(0)){
         $nodes = $node->getElementsByTagName("moby:$element");
     }
+
 	for (0..$nodes->getLength-1){
         my $child = $nodes->item($_);
-		if (
+        if (
             (($child->getAttribute("articleName")) && (($child->getAttribute("articleName") eq $articleName)))
             || (($child->getAttribute("moby:articleName")) && (($child->getAttribute("moby:articleName") eq $articleName)))){
-			# now we have a valid child, get the content... stringified... regardless of what it is
-			my $resp;
-			foreach ($child->getChildNodes){
-                next unless $_->getNodeType == TEXT_NODE;
-				$resp .= $_->toString;
-			}
-			push @contents, $resp;
-		}
+            # now we have a valid child, get the content... stringified... regardless of what it is
+            
+            if (isSecondaryArticle($child)){
+                my $resp;
+                my $valuenodes = $child->getElementsByTagName('Value');
+                unless ($valuenodes->item(0)){
+                    $valuenodes = $child->getElementsByTagName("moby:Value");
+                }
+                for (0..$valuenodes->getLength-1){
+                    my $valuenode = $valuenodes->item($_);
+                    foreach my $amount ($valuenode->getChildNodes){
+                        next unless $amount->getNodeType == TEXT_NODE;
+                        $resp .= $amount->toString;
+                    }
+                }
+                push @contents, $resp;
+                
+            } else {
+                my $resp;
+                foreach ($child->getChildNodes){
+                    next unless $_->getNodeType == TEXT_NODE;
+                    $resp .= $_->toString;
+                }
+                push @contents, $resp;
+            }
+        }
 	}
 	return @contents;
 }




More information about the MOBY-guts mailing list