[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Thu Jun 19 00:47:35 UTC 2003


mwilkinson
Wed Jun 18 20:47:35 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv12376/Perl/MOBY

Modified Files:
	Central.html Central.pm OntologyServer.pm 
Log Message:
Doh\!  I didn't read the API properly when I wrote the code.  The API didn't make sense anyway, so I took the liberty of fixing the API call to make it sensible, and then coded to that.  This new version should fulfil what was intended in the API.  the 'expand' function is not yet implemented

moby-live/Perl/MOBY Central.html,1.4,1.5 Central.pm,1.78,1.79 OntologyServer.pm,1.16,1.17
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Perl/MOBY/Central.html	2003/06/18 22:57:01	1.4
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.html	2003/06/19 00:47:35	1.5
@@ -684,14 +684,24 @@
  Usage     :    $ns = $MOBY->Relationships()
  Function  :    get the fist level of relationships for the given term
  Returns   :    output XML (see below)
- Args      :    Input XML (see below)
+ Args      :    Input XML (see below).  relationshipTypes are optional.
+                If included, it will limit the response to only those
+                relationship types, otherwise you get all by default.
+                NOTE:  the expandRelationships flag in the official API is not yet implemented.</pre>
+<pre>
  input XML :
         &lt;Relationships&gt;
            &lt;objectType&gt;$term&lt;/objectType&gt;
+           &lt;relationshipType&gt;$relationship_term&lt;/relationshipType&gt;
+           ... more relationship types
+           ...
         &lt;/Relationships&gt;
  OR
         &lt;Relationships&gt;
            &lt;serviceType&gt;$term&lt;/serviceType&gt;
+           &lt;relationshipType&gt;$relationship_term&lt;/relationshipType&gt;
+           ... more relationship types
+           ...
         &lt;/Relationships&gt;</pre>
 <pre>
  outputXML :

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/06/18 22:57:01	1.78
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm	2003/06/19 00:47:35	1.79
@@ -2275,14 +2275,24 @@
  Usage     :	$ns = $MOBY->Relationships()
  Function  :	get the fist level of relationships for the given term
  Returns   :	output XML (see below)
- Args      :	Input XML (see below)
+ Args      :	Input XML (see below).  relationshipTypes are optional.
+                If included, it will limit the response to only those
+                relationship types, otherwise you get all by default.
+                NOTE:  the expandRelationships flag in the official API is not yet implemented.
+
  input XML :
 	<Relationships>
 	   <objectType>$term</objectType>
+	   <relationshipType>$relationship_term</relationshipType>
+	   ... more relationship types
+	   ...
 	</Relationships>
  OR
 	<Relationships>
 	   <serviceType>$term</serviceType>
+	   <relationshipType>$relationship_term</relationshipType>
+	   ... more relationship types
+	   ...
 	</Relationships>
 
 
@@ -2318,6 +2328,17 @@
 	my $ontology;
 	my $Parser = new XML::DOM::Parser;
 	my $doc = $Parser->parse($payload);
+	my $x = $doc->getElementsByTagName("relationshipType");
+	my $l = $x->getLength;  # might be a Collection object with multiple simples...
+	my @reltypes;
+	for (my $n=0; $n < $l; ++$n){
+		my @child = $x->item($n)->getChildNodes;
+		foreach (@child){
+			next unless ($_->getNodeType == TEXT_NODE);
+			my $name = $_->toString; chomp $name;
+			push @reltypes, $name;
+		}
+	}
 	my $term =  &_nodeTextContent($doc, "objectType");
 	$ontology = "object" if $term;  # pick up the ontology "object" that we used here if we got an object term
 	$term ||= &_nodeTextContent($doc, "serviceType");  # if we didn't get anything using objectType try serviceType
@@ -2327,10 +2348,15 @@
 	my %rels = %{$OS->Relationships(term => $term)};
 
 	my $response="<Relationships>\n";
-	while (my ($rel, $lsids) = each %rels){
-		$response .="<Relationship relationshipType='$rel'>\n";
-		foreach (@{$lsids}){
-			$response .="<${ontology}Type>$_</${ontology}Type>\n";
+	my $OSrel = MOBY::OntologyServer->new(ontology => 'relationship');
+	foreach (@reltypes){
+		my $rellsid = $OSrel->getRelationshipURI($ontology, $_);
+		next unless $rellsid;
+		my $lsids = $rels{$rellsid};
+		next unless $lsids->[0];
+		$response .="<Relationship relationshipType='$rellsid'>\n";
+		foreach my $lsid(@{$lsids}){
+			$response .="<${ontology}Type>$lsid</${ontology}Type>\n";
 		}
 		$response .= "</Relationship>\n";
 	}

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm	2003/06/18 22:57:01	1.16
+++ /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm	2003/06/19 00:47:35	1.17
@@ -783,6 +783,18 @@
     return $id;
 }
 
+
+=head2 getNamespaceURI
+
+=cut
+
+sub getRelationshipURI {
+    my ($self, $ontology, $term) = @_;
+    return $term if $term =~ /urn\:lsid/;
+    my ($id) = $self->dbh->selectrow_array(q{select relationship_lsid from relationship where relationship_type = ? and ontology = ?},undef,$term, $ontology);
+    return $id;
+}
+
 =head2 getRelationshipTypes
 
 =cut




More information about the MOBY-guts mailing list