[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Sat Oct 25 19:20:47 EDT 2003
mwilkinson
Sat Oct 25 18:20:47 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv1757/Perl/MOBY
Modified Files:
CommonSubs.html CommonSubs.pm
Added Files:
CrossReference.html CrossReference.pm
Log Message:
added a new CrossReference object, able to represent either the old 0.5 Object style cross-references, or the new Xref style cross-references. Added method to CommonSubs to extract the cross-references from an Article. Updated all documentation.
moby-live/Perl/MOBY CrossReference.html,NONE,1.1 CrossReference.pm,NONE,1.1 CommonSubs.html,1.4,1.5 CommonSubs.pm,1.17,1.18
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.html 2003/09/22 16:27:46 1.4
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.html 2003/10/25 22:20:47 1.5
@@ -32,7 +32,8 @@
<li><a href="#iscollectionarticle">isCollectionArticle</a></li>
<li><a href="#getnodecontentwitharticle">getNodeContentWithArticle</a></li>
<li><a href="#validatenamespaces">validateNamespaces</a></li>
- <li><a href="#extractresponsearticles">extractResponseArticles</a></li>
+ <li><a href="#getresponsearticles_(a.k.a._extractresponsearticles)">getResponseArticles (a.k.a. extractResponseArticles)</a></li>
+ <li><a href="#getcrossreferences">getCrossReferences</a></li>
</ul>
</ul>
@@ -237,7 +238,8 @@
$tagname - the tagname (effectively from the Object type ontology)
$articleName - the articleName that we are searching for
- returns : an array of the stringified contents of each child node of the matching node
+ returns : an array of the stringified text content for each
+ node that matched the tagname/articleName specified.
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:
@@ -263,8 +265,8 @@
foreach (@queries){
my @inputs = @{$_}; #(may be more than one Simple/Collection input per query)
foreach my $input(@inputs){
- @sequence = getNodeContentWithArticle($_, "String", "SequenceString");
- print "Sequence was ".(join "", @sequence)."\n"; # join all lines of string
+ @sequences = getNodeContentWithArticle($_, "String", "SequenceString");
+ print "matching node contents were ".(join "\n\n", @sequences)."\n"; # join all lines of string
}
}</pre>
<p>
@@ -279,15 +281,40 @@
presumptive namespaces; undef for each namespace that was invalid</pre>
<p>
</p>
-<h2><a name="extractresponsearticles">extractResponseArticles</a></h2>
+<h2><a name="getresponsearticles_(a.k.a._extractresponsearticles)">getResponseArticles (a.k.a. extractResponseArticles)</a></h2>
<pre>
- name : extractResponseArticles
+ name : getResponseArticles
function : get the DOM nodes corresponding to individual
Simple or Collection outputs from a MOBY Response
- usage : ($collections, $simples) = extractResponseArticles($node)
+ usage : ($collections, $simples) = getResponseArticles($node)
args : $node - either raw XML or an XML::DOM::Document to be searched
returns : an array-ref of Collection article XML::DOM::Node's
an array-ref of Simple article XML::DOM::Node's</pre>
+<p>
+</p>
+<h2><a name="getcrossreferences">getCrossReferences</a></h2>
+<pre>
+ name : getCrossReferences
+ function : to get the cross-references for a Simple article
+ usage : @xrefs = getCrossReferences($XML)
+ args : $XML is either a SIMPLE article (<Simple>...</Simple>)
+ or an object (the payload of a Simple article), and
+ may be either raw XML or an XML::DOM node.
+ returns : an array of MOBY::CrossReference objects
+ example :</pre>
+<pre>
+ my (($colls, $simps) = getResponseArticles($query); # returns DOM nodes
+ foreach (@{$simps}){
+ my @xrefs = getCrossReferences($_);
+ foreach my $xref(@xrefs){
+ print "Cross-ref type: ",$xref->type,"\n";
+ print "namespace: ",$xref->namespace,"\n";
+ print "id: ",$xref->id,"\n";
+ if ($xref->type eq "Xref"){
+ print "Cross-ref relationship: ", $xref->xref_type,"\n";
+ }
+ }
+ }</pre>
</body>
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm 2003/10/20 14:23:54 1.17
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm 2003/10/25 22:20:47 1.18
@@ -62,6 +62,7 @@
package MOBY::CommonSubs;
require Exporter;
use XML::DOM;
+use MOBY::CrossReference;
@ISA = qw(Exporter);
@EXPORT_OK = qw(
@@ -77,6 +78,8 @@
isSimpleArticle
isCollectionArticle
extractResponseArticles
+ getResponseArticles
+ getCrossReferences
);
%EXPORT_TAGS =(all => [qw(
getSimpleArticleIDs
@@ -91,6 +94,8 @@
isSimpleArticle
isCollectionArticle
extractResponseArticles
+ getResponseArticles
+ getCrossReferences
)]);
@@ -397,12 +402,10 @@
my @queries;
for (0..$x->getLength-1){ # there may be more than one queryInput per message
- # but there *should* only be *one* child node per queryInput, Simple or Collection!
- my @this_query;
- foreach $child($x->item($_)->getChildNodes){ # still, iterate over them just in case (though the meaning is ambiguous if there is more than one)
+ my @this_query;
+ foreach $child($x->item($_)->getChildNodes){ # there may be more than one Simple/Collection per input; iterate over them
next unless $child->getNodeType == ELEMENT_NODE; # ignore whitespace
push @this_query, $child; # take the child elements, which are <Simple/> or <Collection/>
- last; # ENFORCE CORRECT XML!! Only one input article per query!!
}
push @queries, \@this_query;
}
@@ -567,18 +570,20 @@
}
-=head2 extractResponseArticles
+=head2 getResponseArticles (a.k.a. extractResponseArticles)
- name : extractResponseArticles
+ name : getResponseArticles
function : get the DOM nodes corresponding to individual
Simple or Collection outputs from a MOBY Response
- usage : ($collections, $simples) = extractResponseArticles($node)
+ usage : ($collections, $simples) = getResponseArticles($node)
args : $node - either raw XML or an XML::DOM::Document to be searched
returns : an array-ref of Collection article XML::DOM::Node's
an array-ref of Simple article XML::DOM::Node's
=cut
+*getResponseArticles = \&extractResponseArticles;
+*getResponseArticles = \&extractResponseArticles;
sub extractResponseArticles {
my ($result) = @_;
@@ -627,4 +632,115 @@
}
}
return (\@collections, \@objects);
+}
+
+
+
+=head2 getCrossReferences
+
+ name : getCrossReferences
+ function : to get the cross-references for a Simple article
+ usage : @xrefs = getCrossReferences($XML)
+ args : $XML is either a SIMPLE article (<Simple>...</Simple>)
+ or an object (the payload of a Simple article), and
+ may be either raw XML or an XML::DOM node.
+ returns : an array of MOBY::CrossReference objects
+ example :
+
+ my (($colls, $simps) = getResponseArticles($query); # returns DOM nodes
+ foreach (@{$simps}){
+ my @xrefs = getCrossReferences($_);
+ foreach my $xref(@xrefs){
+ print "Cross-ref type: ",$xref->type,"\n";
+ print "namespace: ",$xref->namespace,"\n";
+ print "id: ",$xref->id,"\n";
+ if ($xref->type eq "Xref"){
+ print "Cross-ref relationship: ", $xref->xref_type,"\n";
+ }
+ }
+ }
+
+=cut
+
+
+sub getCrossReferences {
+
+ my ($XML) = @_;
+ unless (ref($XML) =~ /XML::DOM/){
+ my $parser = new XML::DOM::Parser;
+ my $doc = $parser->parse($XML);
+ $XML = $doc->getDocumentElement();
+ }
+ my @xrefs; my @XREFS;
+ my @simples;
+ return @XREFS if $XML->getTagName eq "Collection";
+ if ($XML->getTagName eq "Simple"){
+ foreach my $child ($XML->getChildNodes){
+ next unless $child->getNodeType == ELEMENT_NODE;
+ $XML = $child;
+ last; # enforce proper MOBY message structure
+ }
+ }
+ foreach ($XML->getChildNodes){
+ next unless $_->getNodeType == ELEMENT_NODE;
+ next unless $_->getTagName eq "CrossReference";
+ foreach my $xref($_->getChildNodes){
+ next unless $xref->getNodeType == ELEMENT_NODE;
+ next unless ($xref->getTagName eq "Xref" || $xref->getTagName eq 'Object');
+ push @xrefs, $xref;
+ }
+ }
+ foreach (@xrefs){
+ $x = &_makeXrefType($_) if $_->getTagName eq "Xref";
+ $x = &_makeObjectType($_) if $_->getTagName eq "Object";
+ push @XREFS, $x if $x;
+ }
+ return @XREFS;
+}
+
+sub _makeXrefType {
+ my ($xref) = @_;
+ my $ns = $xref->getAttributeNode('namespace');
+ $ns = $xref->getAttributeNode('moby:namespace') unless $ns;
+ return undef unless $ns;
+ my $id = $xref->getAttributeNode('id');
+ $id = $xref->getAttributeNode('moby:id') unless $ns;
+ return undef unless $id;
+ my $xr = $xref->getAttributeNode('xref_type');
+ $xr = $xref->getAttributeNode('moby:namespace') unless $ns;
+ return undef unless $xr;
+ my $ec = $xref->getAttributeNode('evidence_code');
+ $ec = $xref->getAttributeNode('moby:namespace') unless $ns;
+ return undef unless $ec;
+ my $au = $xref->getAttributeNode('authURI');
+ $au = $xref->getAttributeNode('moby:authURI') unless $au;
+ return undef unless $au;
+ my $sn = $xref->getAttributeNode('serviceName');
+ $sn = $xref->getAttributeNode('moby:serviceName') unless $sn;
+ return undef unless $sn;
+ my $XREF = MOBY::CrossReference->new(
+ type => "xref",
+ namespace => $ns->getValue,
+ id => $id->getValue,
+ authURI => $au->getValue,
+ serviceName => $sn->getValue,
+ evidence_code => $ec->getValue,
+ xref_type => $xr->getValue
+ );
+ return $XREF;
+}
+
+sub _makeObjectType {
+ my ($xref) = @_;
+ my $ns = $xref->getAttributeNode('namespace');
+ $ns = $xref->getAttributeNode('moby:namespace') unless $ns;
+ return undef unless $ns;
+ my $id = $xref->getAttributeNode('id');
+ $id = $xref->getAttributeNode('moby:id') unless $ns;
+ return undef unless $id;
+ my $XREF = MOBY::CrossReference->new(
+ type => "object",
+ namespace => $ns->getValue,
+ id => $id->getValue,
+ );
}
\ No newline at end of file
More information about the MOBY-guts
mailing list