[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Sat Dec 27 20:11:49 UTC 2003


mwilkinson
Sat Dec 27 15:11:49 EST 2003
Update of /home/repository/moby/moby-live/Perl/MOBY/Client
In directory pub.open-bio.org:/tmp/cvs-serv29963/Perl/MOBY/Client

Modified Files:
	Central.pm Central.html 
Log Message:
Gbrowse client modifications and additions.  Caching is clearly an issue for speed purposes so there are some nice caching routines now in MOBY::Client::Central, as well as accessor methods to play with the cache.

moby-live/Perl/MOBY/Client Central.pm,1.67,1.68 Central.html,1.14,1.15
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm	2003/12/27 17:41:32	1.67
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/Central.pm	2003/12/27 20:11:48	1.68
@@ -1377,8 +1377,8 @@
  Function  :	a pre-canned use of the Relationships function
                 to quickly get an answer to whether class1 ISA class2
  Returns   :    Boolean
- Args      :	$class1  - an Object ontology term
-                $class2 - an Object ontology term
+ Args      :	$class1  - an Object ontology term or LSID
+                $class2 - an Object ontology term or LSID
 
 =cut
 
@@ -1386,27 +1386,17 @@
 sub ISA {
 	my ($self, $class1, $class2) = @_;
 	return 1 if (($class1 eq $class2) || ("moby:$class1" eq $class2) || ($class1 eq "moby:$class2"));
-	my $OS = MOBY::Client::OntologyServer->new;
-	my ($lsid1, $lsid2);
-	unless ($lsid1 = $self->{LSID_CACHE}->{$class1}){
-		my ($s, $d, $lsid) = $OS->objectExists(term => $class1);
-		$self->LSID_CACHE($class1, $lsid);
-		$lsid1 = $lsid;
-		return 0 unless $s;
-	}
-	unless ($lsid2 = $self->{LSID_CACHE}->{$class2}){
-		my ($s, $d, $lsid) = $OS->objectExists(term => $class2);
-		$self->LSID_CACHE($class2, $lsid);
-		$lsid2 = $lsid;
-		return 0 unless $s;
-	}
+	my $lsid1 = $self->ObjLSID($class1);
+	my $lsid2 = $self->ObjLSID($class2);
+	return 0 unless $lsid1 && $lsid2;
 	my @lsids;
-	unless ($self->ISA_CACHE($lsid1) && (@lsids = @{$self->{"ISA_CACHE"}->{"$lsid1"}})){
+	unless (@lsids = $self->ISA_CACHE($lsid1)){
 		my $resp = $self->Relationships(objectType => $lsid1, expandRelationship => 1, Relationships => ['ISA']);
 		my $lsids = $resp->{'urn:lsid:biomoby.org:objectrelation:isa'};
 		@lsids = @$lsids;
+		$self->ISA_CACHE($lsid1, [@lsids]);
+		$self->ISA_CACHE($class1, [@lsids]);
 	}
-	$self->ISA_CACHE($lsid1, [@lsids]);
 	foreach (@lsids){
 		return 1 if $_ eq $lsid2;
 	}
@@ -1509,6 +1499,29 @@
     return \@Services;
 }
 
+#        my ($e, $m, $lsid) = $OS->objectExists(term => $_);
+
+=head2 ObjLSID
+
+=cut
+
+sub ObjLSID {
+	my ($self, $term) = @_;
+	return undef unless $term;
+	if (my $lsid = $self->LSID_CACHE($term)){
+		return $lsid;
+	} else {
+		my $os = MOBY::Client::OntologyServer->new;
+		my ($s, $m, $lsid) = $os->objectExists(term => $term);
+		if ($lsid){
+			$self->LSID_CACHE($term, $lsid);  # link both the term
+			$self->LSID_CACHE($lsid, $lsid);  # and the lsid to itself
+			return $lsid
+		} else {
+			return undef
+		}
+	}
+}
 
 =head2 LSID_CACHE
 
@@ -1537,29 +1550,32 @@
 
 =head2 ISA_CACHE
 
- Title     :	ISA_CACHE
- Usage     :	$lsid = $MOBY->ISA_CACHE($term, \@isas)
- Function  :	get/set the ISA relationships in the cache
- Returns   :	listref of ISA relationships.  The resulting
-                list is IN ORDER from term to root.
- Args      :	the term for which you have/want the ISA parentage,
-                and optionally the parentage listref to set.
+ Title     : ISA_CACHE
+ Usage     : @lsids = $MOBY->ISA_CACHE($lsid, \@isas)
+ Function  : get/set the ISA relationships in the cache
+ Returns   : list of ISA relationships.  The ISA list
+             is IN ORDER from, excluding the term itself, to
+             root Object. Base Object returns an empty list.
+ Args      : The LSID for which you have/want the ISA parentage,
+             and optionally the parentage listref to set.
+ Note      : WHAT COMES BACK ARE LSIDs!!!   
 
 =cut
 
 sub ISA_CACHE {
-	my ($self, $term, $isas) = @_;
-	return [] if $isas && !(ref($isas)=~/ARRAY/);
+	my ($self, $desiredterm, $isas) = @_;
+	my $term = $desiredterm;
+	return (undef) if $isas && !(ref($isas)=~/ARRAY/);
 	if ($term && $isas){
-		while (scalar(@$isas)){
+		$self->{ISA_CACHE}->{$desiredterm} = [@$isas];
+		while (my $term = shift(@$isas)){
 			$self->{ISA_CACHE}->{$term} = [@$isas];
-			$term = shift(@$isas);
 		}
-		return $self->{ISA_CACHE}->{$term};
-	} elsif ($term){
-		return $self->{ISA_CACHE}->{$term};
+		return @{$self->{ISA_CACHE}->{$desiredterm}};
+	} elsif ($term && $self->{ISA_CACHE}->{$desiredterm}){
+		return @{$self->{ISA_CACHE}->{$desiredterm}};
 	} else {
-		return []
+		return ();
 	}
 }
 

===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Client/Central.html,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- /home/repository/moby/moby-live/Perl/MOBY/Client/Central.html	2003/12/27 17:41:32	1.14
+++ /home/repository/moby/moby-live/Perl/MOBY/Client/Central.html	2003/12/27 20:11:49	1.15
@@ -41,6 +41,7 @@
 		<li><a href="#relationships">Relationships</a></li>
 		<li><a href="#isa">ISA</a></li>
 		<li><a href="#dump">DUMP</a></li>
+		<li><a href="#objlsid">ObjLSID</a></li>
 		<li><a href="#lsid_cache">LSID_CACHE</a></li>
 		<li><a href="#isa_cache">ISA_CACHE</a></li>
 	</ul>
@@ -421,8 +422,8 @@
  Function  :    a pre-canned use of the Relationships function
                 to quickly get an answer to whether class1 ISA class2
  Returns   :    Boolean
- Args      :    $class1  - an Object ontology term
-                $class2 - an Object ontology term</pre>
+ Args      :    $class1  - an Object ontology term or LSID
+                $class2 - an Object ontology term or LSID</pre>
 <p>
 </p>
 <h2><a name="dump">DUMP</a></h2>
@@ -434,6 +435,9 @@
  Args      :    $reg - name of MOBY Central you want to use if not default</pre>
 <p>
 </p>
+<h2><a name="objlsid">ObjLSID</a></h2>
+<p>
+</p>
 <h2><a name="lsid_cache">LSID_CACHE</a></h2>
 <pre>
  Title     :    LSID_CACHE
@@ -446,13 +450,15 @@
 </p>
 <h2><a name="isa_cache">ISA_CACHE</a></h2>
 <pre>
- Title     :    ISA_CACHE
- Usage     :    $lsid = $MOBY-&gt;ISA_CACHE($term, \@isas)
- Function  :    get/set the ISA relationships in the cache
- Returns   :    listref of ISA relationships.  The resulting
-                list is IN ORDER from term to root.
- Args      :    the term for which you have/want the ISA parentage,
-                and optionally the parentage listref to set.</pre>
+ Title     : ISA_CACHE
+ Usage     : @lsids = $MOBY-&gt;ISA_CACHE($lsid, \@isas)
+ Function  : get/set the ISA relationships in the cache
+ Returns   : list of ISA relationships.  The ISA list
+             is IN ORDER from, excluding the term itself, to
+             root Object. Base Object returns an empty list.
+ Args      : The LSID for which you have/want the ISA parentage,
+             and optionally the parentage listref to set.
+ Note      : WHAT COMES BACK ARE LSIDs!!!</pre>
 
 </body>
 




More information about the MOBY-guts mailing list