Bio/Ontology/RelationshipType.pm

filter: Statementstmt 84.4% 87 / 103 Branchbran 48.2% 27 / 56 Conditioncond 43.4% 20 / 46 MC/DCmcdc 15.3% 4 / 26 Subroutinesub 90.9% 20 / 22 Podpod 100% 11 / 11 totaltotal 64.0% 169 / 264 CC 44 SCAR 21.2
CC
44
Cov
65%
veto_change
30.0
version
20.0
ontology
9.8
CRAP 8.3
« Bio/Tools/FootPrinter.pm ↑ Summary Bio/Matrix/PSM/IO/meme.pm »
1 #
2 # BioPerl module for Bio::Ontology::RelationshipType
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Christian M. Zmasek <czmasek-at-burnham.org> or <cmzmasek@yahoo.com>
7 #
8 # (c) Christian M. Zmasek, czmasek-at-burnham.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
10 #
11 # You may distribute this module under the same terms as perl itself.
12 # Refer to the Perl Artistic License (see the license accompanying this
13 # software package, or see http://www.perl.com/language/misc/Artistic.html)
14 # for the terms under which you may use, modify, and redistribute this module.
15 #
16 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #
20 # You may distribute this module under the same terms as perl itself
21  
22 # POD documentation - main docs before the code
23  
24 =head1 NAME
25  
26 Bio::Ontology::RelationshipType - a relationship type for an ontology
27  
28 =head1 SYNOPSIS
29  
30 #
31  
32 =head1 DESCRIPTION
33  
34 This class can be used to model various types of relationships
35 (such as "IS_A", "PART_OF", "CONTAINS", "FOUND_IN", "RELATED_TO").
36  
37 This class extends L<Bio::Ontology::Term>, so it essentially is-a
38 L<Bio::Ontology::TermI>. In addition, all methods are overridden such
39 as to make the object immutable.
40  
41 =head1 FEEDBACK
42  
43 =head2 Mailing Lists
44  
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to the
47 Bioperl mailing lists Your participation is much appreciated.
48  
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
51  
52 =head2 Support
53  
54 Please direct usage questions or support issues to the mailing list:
55  
56 I<bioperl-l@bioperl.org>
57  
58 rather than to the module maintainer directly. Many experienced and
59 reponsive experts will be able look at the problem and quickly
60 address it. Please include a thorough description of the problem
61 with code and data examples if at all possible.
62  
63 =head2 Reporting Bugs
64  
65 Report bugs to the Bioperl bug tracking system to help us keep track
66 the bugs and their resolution. Bug reports can be submitted via
67 the web:
68  
69 https://github.com/bioperl/bioperl-live/issues
70  
71 =head1 AUTHOR
72  
73 Christian M. Zmasek
74  
75 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
76  
77 WWW: http://monochrome-effect.net/
78  
79 Address:
80  
81 Genomics Institute of the Novartis Research Foundation
82 10675 John Jay Hopkins Drive
83 San Diego, CA 92121
84  
85 =head1 APPENDIX
86  
87 The rest of the documentation details each of the object
88 methods. Internal methods are usually preceded with a _
89  
90 =cut
91  
92  
93 # Let the code begin...
94  
95 package Bio::Ontology::RelationshipType;
96 16 $Bio::Ontology::RelationshipType::VERSION = '1.7.8';
97 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99  
100 16 ▶use constant PART_OF => "PART_OF";
Subroutine BEGIN: called CC=1 SCAR=0.0
101 16 ▶use constant RELATED_TO => "RELATED_TO";
Subroutine BEGIN: called CC=1 SCAR=0.0
102 16 ▶use constant IS_A => "IS_A";
Subroutine BEGIN: called CC=1 SCAR=0.0
103 16 ▶use constant CONTAINS => "CONTAINS";
Subroutine BEGIN: called CC=1 SCAR=0.0
104 16 ▶use constant FOUND_IN => "FOUND_IN";
Subroutine BEGIN: called CC=1 SCAR=0.0
105 16 ▶use constant REGULATES => "REGULATES";
Subroutine BEGIN: called CC=1 SCAR=0.0
106 16 ▶use constant POSITIVELY_REGULATES => "POSITIVELY_REGULATES";
Subroutine BEGIN: called CC=1 SCAR=0.0
107 16 ▶use constant NEGATIVELY_REGULATES => "NEGATIVELY_REGULATES";
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109  
110 16 ▶use base qw(Bio::Ontology::Term);
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112  
113 #
114 # cache for terms
115 #
116 16 my %term_name_map = ();
117  
118  
119 =head2 get_instance
120  
121 Title : get_instance
122 Usage : $IS_A = Bio::Ontology::RelationshipType->get_instance( "IS_A" );
123 $PART_OF = Bio::Ontology::RelationshipType->get_instance( "PART_OF" );
124 $RELATED_TO = Bio::Ontology::RelationshipType->get_instance( "RELATED_TO" );
125 $CONTAINS = Bio::Ontology::RelationshipType->get_instance( "CONTAINS" );
126 $FOUND_IN = Bio::Ontology::RelationshipType->get_instance( "FOUND_IN" );
127 Function: Factory method to create instances of RelationshipType
128 Returns : [Bio::Ontology::RelationshipType]
129 Args : "IS_A" or "PART_OF" or "CONTAINS" or "FOUND_IN" or
130 "RELATED_TO" [scalar]
131 the ontology [Bio::Ontology::OntologyI] (optional)
132  
133 =cut
134  
135 73 ▶sub get_instance {
Subroutine get_instance: called CC=8 SCAR=20.9
Pod documented
136 73 my ( $class, $name, $ont ) = @_;
137  
138 73 ▶ $class->throw("must provide predicate name") unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 73 73
139  
140 # is one in the cache?
141 73 my $reltype = $term_name_map{$name};
142  
143 73 ▶ if($reltype &&
Branch: 1 branch
BranchTrueFalseTotal
if ($reltype and $ont && $reltype->ontology && $ont->name eq $reltype->ontology->name || !($reltype->ontology || $ont)) 16 57 73
Condition86%13/15
$reltype and $ont && $reltype->ontology && $ont->name eq $reltype->ontology->name || !($reltype->ontology || $ont)
!ll&&!rl&&r
372016
$ont and $reltype->ontology and $ont->name eq $reltype->ontology->name or not $reltype->ontology || $ont
l!l&&r!l&&!r
21420
$ont and $reltype->ontology and $ont->name eq $reltype->ontology->name
!ll&&!rl&&r
3222
$ont and $reltype->ontology
!ll&&!rl&&r
3204
$reltype->ontology || $ont
l!l&&r!l&&!r
20014
MC/DC66%4/6
$reltype and $ont && $reltype->ontology && $ont->name eq $reltype->ontology->name || !($reltype->ontology || $ont)
$reltype $ont $reltype->ontology $ont->name eq $reltype->ontology->name $reltype->ontology $ont
Truth table45%5/11
A and B and C and D or not(E || F)
A= $reltypeB= $ontC= $reltype->ontologyD= $ont->name eq $reltype->ontology->nameE= $reltype->ontologyF= $ont
ABCDEFresult
0XXXXX0
10XX1X0
10XX010
110X1X0
110X010
11101X0
1110010
1111XX1
10XX001
110X001
1110001
144 # check whether ontologies match
145 (($ont && $reltype->ontology() &&
146 ($ont->name() eq $reltype->ontology->name())) ||
147 (! ($reltype->ontology() || $ont)))) {
148 # we're done, return cached type
149 16 return $reltype;
150 }
151 # valid relationship type?
152  
153 #
154 #see the cell ontology. this code is too strict, even for dag-edit files. -allen
155 #
156 # if ( ! (($name eq IS_A) || ($name eq PART_OF) ||
157 # ($name eq CONTAINS) || ( $name eq FOUND_IN ))) {
158 # my $msg = "Found unknown type of relationship: [" . $name . "]\n";
159 # $msg .= "Known types are: [" . IS_A . "], [" . PART_OF . "], [" . CONTAINS . "], [" . FOUND_IN . "]";
160 # $class->throw( $msg );
161 # }
162 # if we get here we need to create the rel.type
163 57 $reltype = $class->new(-name => $name,
164 -ontology => $ont);
165 # cache it (FIXME possibly overrides one from another ontology)
166 57 $term_name_map{$name} = $reltype;
167 57 return $reltype;
168 } # get_instance
169  
170  
171 =head2 init
172  
173 Title : init()
174 Usage : $type->init();
175 Function: Initializes this to all undef and empty lists.
176 Returns :
177 Args :
178  
179 =cut
180  
181 57 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
182 57 my $self = shift;
183  
184 57 $self->SUPER::init();
185  
186 # at this point we don't really need to do anything special for us
187 } # init
188  
189  
190 =head2 equals
191  
192 Title : equals
193 Usage : if ( $type->equals( $other_type ) ) { ...
194 Function: Compares this type to another one, based on string "eq" of
195 the "identifier" field, if at least one of the two types has
196 the identifier set, or string eq of the name otherwise.
197 Returns : true or false
198 Args : [Bio::Ontology::RelationshipType]
199  
200 =cut
201  
202 176 ▶sub equals {
Subroutine equals: called CC=5 SCAR=20.9
Pod documented
203 176 my( $self, $type ) = @_;
204  
205 176 $self->_check_class( $type, "Bio::Ontology::RelationshipType" );
206  
207 176 ▶ if ( $self->identifier() xor $type->identifier() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->identifier xor $type->identifier) 0 176 176
Condition25%1/4
$self->identifier xor $type->identifier
l&&rl&&!r!l&&r!l&&!r
000176
MC/DC0%0/2
$self->identifier xor $type->identifier
$self->identifier $type->identifier
Truth table25%1/4
A xor B
A= $self->identifierB= $type->identifier
ABresult
110
101
011
000
208 0 $self->warn("comparing relationship types when only ".
209 "one has an identifier will always return false" );
210 }
211  
212 return
213 176 ▶ ($self->identifier() || $type->identifier()) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->identifier || $type->identifier ? : 0 176 176
Condition33%1/3
$self->identifier or $type->identifier
l!l&&r!l&&!r
00176
MC/DC0%0/2
$self->identifier or $type->identifier
$self->identifier $type->identifier
Truth table33%1/3
A or B
A= $self->identifierB= $type->identifier
ABresult
1X1
011
000
214 $self->identifier() eq $type->identifier() :
215 $self->name() eq $type->name();
216
217 } # equals
218  
219  
220 =head2 identifier
221  
222 Title : identifier
223 Usage : $term->identifier( "IS_A" );
224 or
225 print $term->identifier();
226 Function: Set/get for the immutable identifier of this Type.
227 Returns : The identifier [scalar].
228 Args : The identifier [scalar] (optional).
229  
230 =cut
231  
232 766 ▶sub identifier {
Subroutine identifier: called CC=4 SCAR=14.3
Pod documented
233 766 my $self = shift;
234 766 my $ret = $self->SUPER::identifier();
235 766 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 709 766
236 57 ▶ $self->throw($self->veto_change("identifier",$ret,$_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret ne $_[0] 0 57 57
Condition33%1/3
$ret and $ret ne $_[0]
!ll&&!rl&&r
5700
MC/DC0%0/2
$ret and $ret ne $_[0]
$ret $ret ne $_[0]
Truth table33%1/3
A and B
A= $retB= $ret ne $_[0]
ABresult
0X0
100
111
237 if $ret && ($ret ne $_[0]);
238 57 $ret = $self->SUPER::identifier(@_);
239 }
240 766 return $ret;
241 } # identifier
242  
243  
244 =head2 name
245  
246 Title : name
247 Usage : $term->name( "is a type" );
248 or
249 print $term->name();
250 Function: Set/get for the immutable name of this Type.
251 Returns : The name [scalar].
252 Args : The name [scalar] (optional).
253  
254 =cut
255  
256 577 ▶sub name {
Subroutine name: called CC=4 SCAR=14.3
Pod documented
257 577 my $self = shift;
258 577 my $ret = $self->SUPER::name();
259 577 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 114 463 577
260 114 ▶ $self->throw($self->veto_change("name",$ret,$_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret ne $_[0] 0 114 114
Condition33%1/3
$ret and $ret ne $_[0]
!ll&&!rl&&r
11400
MC/DC0%0/2
$ret and $ret ne $_[0]
$ret $ret ne $_[0]
Truth table33%1/3
A and B
A= $retB= $ret ne $_[0]
ABresult
0X0
100
111
261 if $ret && ($ret ne $_[0]);
262 114 $ret = $self->SUPER::name(@_);
263 }
264 577 return $ret;
265 } # name
266  
267  
268  
269  
270  
271 =head2 definition
272  
273 Title : definition
274 Usage : $term->definition( "" );
275 or
276 print $term->definition();
277 Function: Set/get for the immutable definition of this Type.
278 Returns : The definition [scalar].
279 Args : The definition [scalar] (optional).
280  
281 =cut
282  
283 61 ▶sub definition {
Subroutine definition: called CC=6 SCAR=18.6
Pod documented
284 61 my $self = shift;
285 61 my $ret = $self->SUPER::definition();
286 61 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 4 61
287 57 ▶ $self->veto_change("definition",$ret,$_[0])
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret ne $_[0] 0 57 57
Condition33%1/3
$ret and $ret ne $_[0]
!ll&&!rl&&r
5700
MC/DC0%0/2
$ret and $ret ne $_[0]
$ret $ret ne $_[0]
Truth table33%1/3
A and B
A= $retB= $ret ne $_[0]
ABresult
0X0
100
111
288 if $ret && ($ret ne $_[0]);
289 57 $ret = $self->SUPER::definition(@_);
290 }
291 # let's be nice and return something readable here
292 61 ▶ return $ret if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 61 61
293 61 ▶ return $self->name()." relationship predicate (type)" if $self->name();
Branch: 1 branch
BranchTrueFalseTotal
if $self->name 4 57 61
294 } # definition
295  
296  
297  
298 =head2 ontology
299  
300 Title : ontology
301 Usage : $term->ontology( $top );
302 or
303 $top = $term->ontology();
304 Function: Set/get for the ontology this relationship type lives in.
305 Returns : The ontology [Bio::Ontology::OntologyI].
306 Args : On set, the ontology [Bio::Ontology::OntologyI] (optional).
307  
308 =cut
309  
310 191 ▶sub ontology {
Subroutine ontology: called CC=6 SCAR=22.9
Pod documented
311 191 my $self = shift;
312 191 my $ret = $self->SUPER::ontology();
313 191 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 104 87 191
314 104 my $ont = shift;
315 104 ▶ if($ret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 104 104
316 0 ▶ $self->throw($self->veto_change("ontology",$ret->name,
Branch: 2 branches
BranchTrueFalseTotal
unless $ont and $ont->name eq $ret->name 0 0 0
$ont ? : 0 0 0
Condition0%0/3
$ont and $ont->name eq $ret->name
!ll&&!rl&&r
000
MC/DC0%0/2
$ont and $ont->name eq $ret->name
$ont $ont->name eq $ret->name
Truth table0%0/3
A and B
A= $ontB= $ont->name eq $ret->name
ABresult
0X0
100
111
317 $ont ? $ont->name : $ont))
318 unless $ont && ($ont->name() eq $ret->name());
319 }
320 104 $ret = $self->SUPER::ontology($ont,@_);
321 }
322 191 return $ret;
323 } # category
324  
325  
326  
327 =head2 version
328  
329 Title : version
330 Usage : $term->version( "1.00" );
331 or
332 print $term->version();
333 Function: Set/get for immutable version information.
334 Returns : The version [scalar].
335 Args : The version [scalar] (optional).
336  
337 =cut
338  
339 0 ▶sub version {
Subroutine version: not called CC=4 SCAR=30.0
Pod documented
340 0 my $self = shift;
341 0 my $ret = $self->SUPER::version();
342 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
343 0 ▶ $self->throw($self->veto_change("version",$ret,$_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret ne $_[0] 0 0 0
Condition0%0/3
$ret and $ret ne $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$ret and $ret ne $_[0]
$ret $ret ne $_[0]
Truth table0%0/3
A and B
A= $retB= $ret ne $_[0]
ABresult
0X0
100
111
344 if $ret && ($ret ne $_[0]);
345 0 $ret = $self->SUPER::version(@_);
346 }
347 0 return $ret;
348 } # version
349  
350  
351  
352 =head2 is_obsolete
353  
354 Title : is_obsolete
355 Usage : $term->is_obsolete( 1 );
356 or
357 if ( $term->is_obsolete() )
358 Function: Set/get for the immutable obsoleteness of this Type.
359 Returns : the obsoleteness [0 or 1].
360 Args : the obsoleteness [0 or 1] (optional).
361  
362 =cut
363  
364 57 ▶sub is_obsolete {
Subroutine is_obsolete: called CC=4 SCAR=15.0
Pod documented
365 57 my $self = shift;
366 57 my $ret = $self->SUPER::is_obsolete();
367 57 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 0 57
368 57 ▶ $self->throw($self->veto_change("is_obsolete",$ret,$_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret != $_[0] 0 57 57
Condition33%1/3
$ret and $ret != $_[0]
!ll&&!rl&&r
5700
MC/DC0%0/2
$ret and $ret != $_[0]
$ret $ret != $_[0]
Truth table33%1/3
A and B
A= $retB= $ret != $_[0]
ABresult
0X0
100
111
369 if $ret && ($ret != $_[0]);
370 57 $ret = $self->SUPER::is_obsolete(@_);
371 }
372 57 return $ret;
373 } # is_obsolete
374  
375  
376 =head2 comment
377  
378 Title : comment
379 Usage : $term->comment( "..." );
380 or
381 print $term->comment();
382 Function: Set/get for an arbitrary immutable comment about this Type.
383 Returns : A comment.
384 Args : A comment (optional).
385  
386 =cut
387  
388 57 ▶sub comment {
Subroutine comment: called CC=4 SCAR=15.0
Pod documented
389 57 my $self = shift;
390 57 my $ret = $self->SUPER::comment();
391 57 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 57 0 57
392 57 ▶ $self->throw($self->veto_change("comment",$ret,$_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $ret and $ret ne $_[0] 0 57 57
Condition33%1/3
$ret and $ret ne $_[0]
!ll&&!rl&&r
5700
MC/DC0%0/2
$ret and $ret ne $_[0]
$ret $ret ne $_[0]
Truth table33%1/3
A and B
A= $retB= $ret ne $_[0]
ABresult
0X0
100
111
393 if $ret && ($ret ne $_[0]);
394 57 $ret = $self->SUPER::comment(@_);
395 }
396 57 return $ret;
397 } # comment
398  
399 =head1 Private methods
400  
401 May be overridden in a derived class, but should never be called from
402 outside.
403  
404 =cut
405  
406 176 ▶sub _check_class {
Subroutine _check_class: called CC=4 SCAR=18.9
407 176 my ( $self, $value, $expected_class ) = @_;
408  
409 176 ▶ if ( ! defined( $value ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $value) { } 0 176 176
elsif (not ref $value) { } 0 176 176
elsif (not $value->isa($expected_class)) { } 0 176 176
410 0 $self->throw( "Found [undef] where [$expected_class] expected" );
411 }
412 elsif ( ! ref( $value ) ) {
413 0 $self->throw( "Found [scalar] where [$expected_class] expected" );
414 }
415 elsif ( ! $value->isa( $expected_class ) ) {
416 0 $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
417 }
418  
419 } # _check_type
420  
421 =head2 veto_change
422  
423 Title : veto_change
424 Usage :
425 Function: Called if an attribute is changed. Setting an attribute is
426 considered a change if it had a value before and the attempt
427 to set it would change the value.
428  
429 This method returns the message to be printed in the exception.
430  
431 Example :
432 Returns : A string
433 Args : The name of the attribute that was attempted to change.
434 Optionally, the old value and the new value for reporting
435 purposes only.
436  
437 =cut
438  
439 0 ▶sub veto_change{
Subroutine veto_change: not called CC=5 SCAR=34.0
Pod documented
440 0 my ($self,$attr,$old,$new) = @_;
441  
442 0 ▶ my $changetype = $old ? ($new ? "change" : "unset") : "change";
Branch: 2 branches
BranchTrueFalseTotal
$old ? : 0 0 0
$new ? : 0 0 0
443 0 my $msg = "attempt to $changetype attribute $attr in ".ref($self).
444 ", which is immutable";
445 0 ▶ $msg .= " (\"$old\" to \"$new\")" if $old && $new;
Branch: 1 branch
BranchTrueFalseTotal
if $old and $new 0 0 0
Condition0%0/3
$old and $new
!ll&&!rl&&r
000
MC/DC0%0/2
$old and $new
$old $new
Truth table0%0/3
A and B
A= $oldB= $new
ABresult
0X0
100
111
446 0 return $msg;
447 }
448  
449 16 1;
« Bio/Tools/FootPrinter.pm ↑ Summary Bio/Matrix/PSM/IO/meme.pm »