File Coverage

blib/lib/OBO/Core/Instance.pm
Criterion Covered Total %
statement 204 221 92.3
branch 79 108 73.1
condition 31 54 57.4
subroutine 37 37 100.0
pod 29 30 96.6
total 380 450 84.4


line stmt bran cond sub pod time code
1             # $Id: Instance.pm 2011-06-06 erick.antezana $
2             #
3             # Module : Instance.pm
4             # Purpose : Capture instances in an Ontology.
5             # License : Copyright (c) 2006-2015 by Erick Antezana. All rights reserved.
6             # This program is free software; you can redistribute it and/or
7             # modify it under the same terms as Perl itself.
8             # Contact : Erick Antezana
9             #
10             package OBO::Core::Instance;
11              
12 10     10   12828 use OBO::Core::Relationship;
  10         25  
  10         301  
13 10     10   3268 use OBO::Core::Synonym;
  10         22  
  10         264  
14 10     10   3351 use OBO::Util::SynonymSet;
  10         27  
  10         266  
15              
16 10     10   54 use Carp;
  10         18  
  10         552  
17 10     10   44 use strict;
  10         17  
  10         36144  
18              
19             sub new {
20 42     42 0 177 my $class = shift;
21 42         76 my $self = {};
22              
23 42         93 $self->{ID} = undef; # required, scalar (1)
24 42         73 $self->{IS_ANONYMOUS} = undef; # [1|0], 0 by default
25 42         70 $self->{NAME} = undef; # not required since OBO spec 1.4, scalar (0..1)
26 42         163 $self->{NAMESPACE_SET} = OBO::Util::Set->new(); # set (0..N)
27 42         130 $self->{ALT_ID} = OBO::Util::Set->new(); # set (0..N)
28 42         72 $self->{BUILTIN} = undef; # [1|0], 0 by default
29 42         70 $self->{COMMENT} = undef; # scalar (0..1)
30 42         125 $self->{SUBSET_SET} = OBO::Util::Set->new(); # set of scalars (0..N)
31 42         155 $self->{SYNONYM_SET} = OBO::Util::SynonymSet->new(); # set of synonyms (0..N)
32 42         173 $self->{XREF_SET} = OBO::Util::DbxrefSet->new(); # set of dbxref's (0..N)
33 42         129 $self->{PROPERTY_VALUE} = OBO::Util::ObjectSet->new(); # set of objects: rel's Instance->Instance or Instance->Datatype (0..N)
34 42         74 $self->{INSTANCE_OF} = undef; # OBO::Core::Term (0..1)
35 42         125 $self->{INTERSECTION_OF} = OBO::Util::Set->new(); # (0..N)
36 42         123 $self->{UNION_OF} = OBO::Util::Set->new(); # (0..N)
37 42         124 $self->{DISJOINT_FROM} = OBO::Util::Set->new(); # (0..N)
38 42         175 $self->{CREATED_BY} = undef; # scalar (0..1)
39 42         69 $self->{CREATION_DATE} = undef; # scalar (0..1)
40 42         68 $self->{MODIFIED_BY} = undef; # scalar (0..1)
41 42         69 $self->{MODIFICATION_DATE} = undef; # scalar (0..1)
42 42         67 $self->{IS_OBSOLETE} = undef; # [1|0], 0 by default
43 42         125 $self->{REPLACED_BY} = OBO::Util::Set->new(); # set of scalars (0..N)
44 42         128 $self->{CONSIDER} = OBO::Util::Set->new(); # set of scalars (0..N)
45              
46 42         74 bless ($self, $class);
47 42         102 return $self;
48             }
49              
50             =head2 id
51              
52             Usage - print $instance->id() or $instance->id($id)
53             Returns - the instance ID (string)
54             Args - the instance ID (string)
55             Function - gets/sets the ID of this instance
56            
57             =cut
58              
59             sub id {
60 585 100   585 1 2352 if (defined $_[1]) { $_[0]->{ID} = $_[1] }
  43         108  
61 585         2265 return $_[0]->{ID};
62             }
63              
64             =head2 idspace
65              
66             Usage - print $instance->idspace()
67             Returns - the idspace of this instance; otherwise, 'NN'
68             Args - none
69             Function - gets the idspace of this instance # TODO Does this method still makes sense?
70            
71             =cut
72              
73             sub idspace {
74 4 100   4 1 71 $_[0]->{ID} =~ /([A-Za-z_]+):/ if ($_[0]->{ID});
75 4   100     35 return $1 || 'NN';
76             }
77              
78             =head2 subnamespace
79              
80             Usage - print $instance->subnamespace()
81             Returns - the subnamespace of this instance (character); otherwise, 'X'
82             Args - none
83             Function - gets the subnamespace of this instance
84            
85             =cut
86              
87             sub subnamespace {
88 2 100   2 1 10 $_[0]->{ID} =~ /:([A-Z][a-z]?)/ if ($_[0]->{ID});
89 2   100     19 return $1 || 'X';
90             }
91              
92             =head2 code
93              
94             Usage - print $instance->code()
95             Returns - the code of this instance (character); otherwise, '0000000'
96             Args - none
97             Function - gets the code of this instance
98            
99             =cut
100              
101             sub code {
102 2 100   2 1 8 $_[0]->{ID} =~ /:[A-Z]?[a-z]?(.*)/ if ($_[0]->{ID});
103 2   100     15 return $1 || '0000000';
104             }
105              
106             =head2 name
107              
108             Usage - print $instance->name() or $instance->name($name)
109             Returns - the name (string) of this instance
110             Args - the name (string) of this instance
111             Function - gets/sets the name of this instance
112            
113             =cut
114              
115             sub name {
116 163 100   163 1 429 if ($_[1]) { $_[0]->{NAME} = $_[1] }
  28         67  
117 163         856 return $_[0]->{NAME};
118             }
119              
120             =head2 is_anonymous
121              
122             Usage - print $instance->is_anonymous() or $instance->is_anonymous("1")
123             Returns - either 1 (true) or 0 (false)
124             Args - either 1 (true) or 0 (false)
125             Function - tells whether this instance is anonymous or not.
126            
127             =cut
128              
129             sub is_anonymous {
130 11 50 66 11 1 35 if (defined $_[1] && ($_[1] == 1 || $_[1] == 0)) { $_[0]->{IS_ANONYMOUS} = $_[1] }
  2   66     4  
131 11 100 66     63 return ($_[0]->{IS_ANONYMOUS} && $_[0]->{IS_ANONYMOUS} == 1)?1:0;
132             }
133              
134             =head2 alt_id
135              
136             Usage - $instance->alt_id() or $instance->alt_id($id1, $id2, $id3, ...)
137             Returns - a set (OBO::Util::Set) with the alternate id(s) of this instance
138             Args - the alternate id(s) (string) of this instance
139             Function - gets/sets the alternate id(s) of this instance
140            
141             =cut
142              
143             sub alt_id {
144 13     13 1 19 my $self = shift;
145 13 100       41 if (scalar(@_) > 1) {
    100          
146 1         6 $self->{ALT_ID}->add_all(@_);
147             } elsif (scalar(@_) == 1) {
148 1         4 $self->{ALT_ID}->add(shift);
149             }
150 13         46 return $self->{ALT_ID};
151             }
152              
153             =head2 namespace
154              
155             Usage - $instance->namespace() or $instance->namespace($ns1, $ns2, $ns3, ...)
156             Returns - an array with the namespace(s) to which this instance belongs
157             Args - the namespace(s) to which this instance belongs
158             Function - gets/sets the namespace(s) to which this instance belongs
159            
160             =cut
161              
162             sub namespace {
163 5     5 1 7 my $self = shift;
164 5 50       25 if (scalar(@_) > 1) {
    100          
165 0         0 $self->{NAMESPACE_SET}->add_all(@_);
166             } elsif (scalar(@_) == 1) {
167 1         4 $self->{NAMESPACE_SET}->add(shift);
168             }
169 5         42 return $self->{NAMESPACE_SET}->get_set();
170             }
171              
172             =head2 comment
173              
174             Usage - print $instance->comment() or $instance->comment("This is a comment")
175             Returns - the comment (string) of this instance
176             Args - the comment (string) of this instance
177             Function - gets/sets the comment of this instance
178            
179             =cut
180              
181             sub comment {
182 4 50   4 1 9 if (defined $_[1]) { $_[0]->{COMMENT} = $_[1] }
  0         0  
183 4         13 return $_[0]->{COMMENT};
184             }
185              
186             =head2 subset
187              
188             Usage - $instance->subset() or $instance->subset($ss_name1, $ss_name2, $ss_name3, ...)
189             Returns - an array with the subset name(s) to which this instance belongs
190             Args - the subset name(s) (string) to which this instance belongs
191             Function - gets/sets the subset name(s) to which this instance belongs
192            
193             =cut
194              
195             sub subset {
196 21     21 1 41 my $self = shift;
197 21 100       71 if (scalar(@_) > 1) {
    100          
198 1         4 $self->{SUBSET_SET}->add_all(@_);
199             } elsif (scalar(@_) == 1) {
200 3         11 $self->{SUBSET_SET}->add(shift);
201             }
202 21         72 return $self->{SUBSET_SET}->get_set();
203             }
204              
205             =head2 synonym_set
206              
207             Usage - $instance->synonym_set() or $instance->synonym_set($synonym1, $synonym2, $synonym3, ...)
208             Returns - an array with the synonym(s) of this instance
209             Args - the synonym(s) (OBO::Core::Synonym) of this instance
210             Function - gets/sets the synonym(s) of this instance
211            
212             =cut
213              
214             sub synonym_set {
215 49     49 1 86 my $self = shift;
216 49         103 foreach my $synonym (@_) {
217 11         25 my $s_name = $self->name();
218 11 50       29 if (!defined($s_name)) {
219 0         0 croak 'The name of this instance (', $self->id(), ') is undefined. Add it before adding its synonyms.';
220             }
221            
222 11         14 my $syn_found = 0;
223             # update the scope of a synonym
224 11         43 foreach my $s_text ($self->{SYNONYM_SET}->get_set()) {
225 10 100       32 if ($s_text->def()->text() eq $synonym->def()->text()) { # if that SYNONYM is already in the set
226 3         9 $s_text->def()->dbxref_set($synonym->def()->dbxref_set); # then update its DBXREFs!
227 3         9 $s_text->scope($synonym->scope); # then update its SCOPE!
228 3         8 $s_text->synonym_type_name($synonym->synonym_type_name); # and update its SYNONYM_TYPE_NAME!
229 3         4 $syn_found = 1;
230 3         4 last;
231             }
232             }
233            
234             # do not add 'EXACT' synonyms with the same 'name':
235 11 50 66     67 if (!$syn_found && !($synonym->scope() eq 'EXACT' && $synonym->def()->text() eq $s_name)) {
      66        
236 8         34 $self->{SYNONYM_SET}->add($synonym)
237             }
238             }
239 49         166 return $self->{SYNONYM_SET}->get_set();
240             }
241              
242             =head2 synonym_as_string
243              
244             Usage - print $instance->synonym_as_string() or $instance->synonym_as_string('this is a synonym text', '[APO:ea]', 'EXACT', 'UK_SPELLING')
245             Returns - an array with the synonym(s) of this instance
246             Args - the synonym text (string), the dbxrefs (string), synonym scope (string) of this instance, and optionally the synonym type name (string)
247             Function - gets/sets the synonym(s) of this instance
248            
249             =cut
250              
251             sub synonym_as_string {
252 16 50 66 16 1 81 if ($_[1] && $_[2] && $_[3]) {
      33        
253 8         34 my $synonym = OBO::Core::Synonym->new();
254 8         30 $synonym->def_as_string($_[1], $_[2]);
255 8         34 $synonym->scope($_[3]);
256 8         33 $synonym->synonym_type_name($_[4]); # optional argument
257 8         31 $_[0]->synonym_set($synonym);
258             }
259            
260 29         62 my @sorted_syns = map { $_->[0] } # restore original values
261 13         34 sort { $a->[1] cmp $b->[1] } # sort
262 29         85 map { [$_, lc($_->def_as_string())] } # transform: value, sortkey
263 16         59 $_[0]->{SYNONYM_SET}->get_set();
264              
265 16         42 my @result;
266             my $s_as_string;
267 16         29 foreach my $synonym (@sorted_syns) {
268 29         81 my $syn_scope = $synonym->scope();
269 29 50       63 if ($syn_scope) {
270 29         72 my $syn_type_name = $synonym->synonym_type_name();
271 29 100       59 if ($syn_type_name) {
272 3         8 $s_as_string = ' '.$syn_scope.' '.$syn_type_name;
273             } else {
274 26         49 $s_as_string = ' '.$syn_scope;
275             }
276             } else {
277             # This case should never happen since the SCOPE is mandatory!
278 0         0 warn "The scope of this synonym is not defined: ", $synonym->def()->text();
279             }
280            
281 29         73 push @result, $synonym->def_as_string().$s_as_string;
282             }
283 16         132 return @result;
284             }
285              
286             =head2 xref_set
287              
288             Usage - $instance->xref_set() or $instance->xref_set($dbxref_set)
289             Returns - a Dbxref set (OBO::Util::DbxrefSet) with the analogous xref(s) of this instance in another vocabulary
290             Args - a set of analogous xref(s) (OBO::Util::DbxrefSet) of this instance in another vocabulary
291             Function - gets/sets the analogous xref(s) set of this instance in another vocabulary
292            
293             =cut
294              
295             sub xref_set {
296 20 100   20 1 70 $_[0]->{XREF_SET} = $_[1] if ($_[1]);
297 20         90 return $_[0]->{XREF_SET};
298             }
299              
300             =head2 xref_set_as_string
301              
302             Usage - $instance->xref_set_as_string() or $instance->xref_set_as_string("[Reactome:20610, EC:2.3.2.12]")
303             Returns - the dbxref set with the analogous xref(s) of this instance; [] if the set is empty
304             Args - the dbxref set with the analogous xref(s) of this instance
305             Function - gets/sets the dbxref set with the analogous xref(s) of this instance
306             Remark - make sure that colons (,) are scaped (\,) when necessary
307            
308             =cut
309              
310             sub xref_set_as_string {
311 16     16 1 110 my $xref_as_string = $_[1];
312 16 100       47 if ($xref_as_string) {
313 5         13 my $xref_set = $_[0]->{XREF_SET};
314            
315 5         22 my ($e, $entry) = __dbxref($xref_set, $xref_as_string);
316 5 50       19 if ($e == -1) {
317 0         0 croak "ERROR: Check the 'dbxref' field of '", $entry, "' (term ID = ", $_[0]->id(), ")." ;
318             }
319            
320 5         16 $_[0]->{XREF_SET} = $xref_set; # We are overwriting the existing set; otherwise, add the new elements to the existing set!
321             }
322 16         85 my @result = $_[0]->xref_set()->get_set();
323             }
324              
325             =head2 property_value
326              
327             Usage - $instance->property_value() or $instance->property_value($p_value1, $p_value2, $p_value3, ...)
328             Returns - an array with the property value(s) of this instance
329             Args - the relationship(s) (OBO::Core::Relationship) of this instance with its property value(s)
330             Function - gets/sets the property_value(s) of this instance
331             Remark - WARNING: this code might change!
332              
333             =cut
334              
335             sub property_value {
336             # TODO WARNING: this code might change!
337 15     15 1 36 my ($self, @co) = @_;
338            
339 15         27 foreach my $i (@co) {
340 9         33 $self->{PROPERTY_VALUE}->add($i);
341             }
342 15         84 return $self->{PROPERTY_VALUE};
343             }
344              
345             =head2 instance_of
346              
347             Usage - $instance->instance_of() or $instance->instance_of($term)
348             Returns - a term (OBO::Core::Term) of which this object is instance of
349             Args - a term (OBO::Core::Term) of which this object is instance of
350             Function - gets/sets the term (class) of this instance
351            
352             =cut
353              
354             sub instance_of {
355 46 100   46 1 136 if ($_[1]) {
356 27         109 my $r = OBO::Core::Relationship->new();
357 27         89 my $tid = $_[1]->id();
358 27         43 my $rt = 'instance_of';
359 27         69 my $iid = $_[0]->id();
360 27         97 my $id = $iid.'_'.$rt.'_'.$tid;
361              
362 27         94 $r->id($id);
363 27         83 $r->type($rt);
364 27         93 $r->link($_[0], $_[1]); # $_[0] --> $r --> $_[1] == Instance --> rel --> Term
365 27         51 $_[0]->{INSTANCE_OF} = $r; # only one term (class) per instance
366            
367             # make the term aware of its instance
368 27         97 $_[1]->class_of()->add($_[0]);
369             }
370 46 100       217 return ($_[0]->{INSTANCE_OF})?$_[0]->{INSTANCE_OF}->head():undef;
371             }
372              
373             =head2 is_instance_of
374              
375             Usage - $instance->is_instance_of($term)
376             Returns - either 1 (true) or 0 (false)
377             Args - a term (OBO::Core::Term) of which this object might be instance of
378             Function - tells whether this object is instance of $term
379            
380             =cut
381              
382             sub is_instance_of {
383 16   66 16 1 132 return ($_[1] && $_[0]->{INSTANCE_OF} && $_[1]->id() eq $_[0]->{INSTANCE_OF}->head()->id());
384             }
385              
386             =head2 intersection_of
387            
388             Usage - $instance->intersection_of() or $instance->intersection_of($t1, $t2, $r1, ...)
389             Returns - an array with the instances/relations which define this instance
390             Args - a set (strings) of instances/relations which define this instance
391             Function - gets/sets the set of instances/relatonships defining this instance
392            
393             =cut
394              
395             sub intersection_of {
396 4     4 1 6 my $self = shift;
397 4 50       15 if (scalar(@_) > 1) {
    50          
398 0         0 $self->{INTERSECTION_OF}->add_all(@_);
399             } elsif (scalar(@_) == 1) {
400 0         0 $self->{INTERSECTION_OF}->add(shift);
401             }
402 4         14 return $self->{INTERSECTION_OF}->get_set();
403             }
404              
405             =head2 union_of
406            
407             Usage - $instance->union_of() or $instance->union_of($t1, $t2, $r1, ...)
408             Returns - an array with the instances/relations which define this instance
409             Args - a set (strings) of instances/relations which define this instance
410             Function - gets/sets the set of instances/relatonships defining this instance
411            
412             =cut
413            
414             sub union_of {
415 4     4 1 6 my $self = shift;
416 4 50       14 if (scalar(@_) > 1) {
    50          
417 0         0 $self->{UNION_OF}->add_all(@_);
418             } elsif (scalar(@_) == 1) {
419 0         0 $self->{UNION_OF}->add(shift);
420             }
421 4         14 return $self->{UNION_OF}->get_set();
422             }
423              
424             =head2 disjoint_from
425              
426             Usage - $instance->disjoint_from() or $instance->disjoint_from($disjoint_instance_id1, $disjoint_instance_id2, $disjoint_instance_id3, ...)
427             Returns - the disjoint instance id(s) (string(s)) from this one
428             Args - the instance id(s) (string) that is (are) disjoint from this one
429             Function - gets/sets the disjoint instance(s) from this one
430            
431             =cut
432              
433             sub disjoint_from {
434 6     6 1 11 my $self = shift;
435 6 100       20 if (scalar(@_) > 1) {
    50          
436 1         6 $self->{DISJOINT_FROM}->add_all(@_);
437             } elsif (scalar(@_) == 1) {
438 0         0 $self->{DISJOINT_FROM}->add(shift);
439             }
440 6         22 return $self->{DISJOINT_FROM}->get_set();
441             }
442              
443             =head2 created_by
444              
445             Usage - print $instance->created_by() or $instance->created_by("erick_antezana")
446             Returns - name (string) of the creator of the instance, may be a short username, initials or ID
447             Args - name (string) of the creator of the instance, may be a short username, initials or ID
448             Function - gets/sets the name of the creator of the instance
449            
450             =cut
451              
452             sub created_by {
453 6 100   6 1 16 $_[0]->{CREATED_BY} = $_[1] if ($_[1]);
454 6         21 return $_[0]->{CREATED_BY};
455             }
456              
457             =head2 creation_date
458              
459             Usage - print $instance->creation_date() or $instance->creation_date("2010-04-13T01:32:36Z")
460             Returns - date (string) of creation of the instance specified in ISO 8601 format
461             Args - date (string) of creation of the instance specified in ISO 8601 format
462             Function - gets/sets the date of creation of the instance
463            
464             =cut
465              
466             sub creation_date {
467 6 100   6 1 16 $_[0]->{CREATION_DATE} = $_[1] if ($_[1]);
468 6         19 return $_[0]->{CREATION_DATE};
469             }
470              
471             =head2 modified_by
472              
473             Usage - print $instance->modified_by() or $instance->modified_by("erick_antezana")
474             Returns - name (string) of the modificator of the instance, may be a short username, initials or ID
475             Args - name (string) of the modificator of the instance, may be a short username, initials or ID
476             Function - gets/sets the name of the modificator of the instance
477            
478             =cut
479              
480             sub modified_by {
481 6 100   6 1 16 $_[0]->{MODIFIED_BY} = $_[1] if ($_[1]);
482 6         17 return $_[0]->{MODIFIED_BY};
483             }
484              
485             =head2 modification_date
486              
487             Usage - print $instance->modification_date() or $instance->modification_date("2010-04-13T01:32:36Z")
488             Returns - date (string) of modification of the instance specified in ISO 8601 format
489             Args - date (string) of modification of the instance specified in ISO 8601 format
490             Function - gets/sets the date of modification of the instance
491            
492             =cut
493              
494             sub modification_date {
495 6 100   6 1 15 $_[0]->{MODIFICATION_DATE} = $_[1] if ($_[1]);
496 6         19 return $_[0]->{MODIFICATION_DATE};
497             }
498              
499             =head2 is_obsolete
500              
501             Usage - print $instance->is_obsolete()
502             Returns - either 1 (true) or 0 (false)
503             Args - either 1 (true) or 0 (false)
504             Function - tells whether the instance is obsolete or not. 'false' by default.
505            
506             =cut
507              
508             sub is_obsolete {
509 11 50 66 11 1 37 if (defined $_[1] && ($_[1] == 1 || $_[1] == 0)) { $_[0]->{IS_OBSOLETE} = $_[1] }
  2   66     4  
510 11 100 66     66 return ($_[0]->{IS_OBSOLETE} && $_[0]->{IS_OBSOLETE} == 1)?1:0;
511             }
512              
513             =head2 replaced_by
514              
515             Usage - $instance->replaced_by() or $instance->replaced_by($id1, $id2, $id3, ...)
516             Returns - a set (OBO::Util::Set) with the id(s) of the replacing instance(s)
517             Args - the the id(s) of the replacing instance(s) (string)
518             Function - gets/sets the the id(s) of the replacing instance(s)
519            
520             =cut
521              
522             sub replaced_by {
523 4     4 1 5 my $self = shift;
524 4 50       14 if (scalar(@_) > 1) {
    50          
525 0         0 $self->{REPLACED_BY}->add_all(@_);
526             } elsif (scalar(@_) == 1) {
527 0         0 $self->{REPLACED_BY}->add(shift);
528             }
529 4         14 return $self->{REPLACED_BY};
530             }
531              
532             =head2 consider
533              
534             Usage - $instance->consider() or $instance->consider($id1, $id2, $id3, ...)
535             Returns - a set (OBO::Util::Set) with the appropiate substitute(s) for an obsolete instance
536             Args - the appropiate substitute(s) for an obsolete instance (string)
537             Function - gets/sets the appropiate substitute(s) for this obsolete instance
538            
539             =cut
540              
541             sub consider {
542 4     4 1 6 my $self = shift;
543 4 50       13 if (scalar(@_) > 1) {
    50          
544 0         0 $self->{CONSIDER}->add_all(@_);
545             } elsif (scalar(@_) == 1) {
546 0         0 $self->{CONSIDER}->add(shift);
547             }
548 4         13 return $self->{CONSIDER};
549             }
550              
551             =head2 builtin
552              
553             Usage - $instance->builtin() or $instance->builtin(1) or $instance->builtin(0)
554             Returns - tells if this instance is builtin to the OBO format; false by default
555             Args - 1 (true) or 0 (false)
556             Function - gets/sets the value indicating whether this instance is builtin to the OBO format
557            
558             =cut
559              
560             sub builtin {
561 4 0 0 4 1 11 if (defined $_[1] && ($_[1] == 1 || $_[1] == 0)) { $_[0]->{BUILTIN} = $_[1] }
  0   33     0  
562 4 50 33     21 return ($_[0]->{BUILTIN} && $_[0]->{BUILTIN} == 1)?1:0;
563             }
564              
565             =head2 equals
566              
567             Usage - print $instance->equals($another_instance)
568             Returns - either 1 (true) or 0 (false)
569             Args - the instance (OBO::Core::Instance) to compare with
570             Function - tells whether this instance is equal to the parameter
571            
572             =cut
573              
574             sub equals {
575 13     13 1 28 my ($self, $target) = @_;
576 13 50 33     49 if ($_[1] && eval { $_[1]->isa('OBO::Core::Instance') }) {
  13         142  
577 13 50 33     140 return (defined $_[1] && $_[0]->{'ID'} eq $_[1]->{'ID'})?1:0;
578             } else {
579 0         0 croak "An unrecognized object type (not a OBO::Core::Instance) was found: '", $_[1], "'";
580             }
581             }
582              
583             sub __dbxref () {
584 5 50   5   18 caller eq __PACKAGE__ or croak "You cannot call this (__dbxref) prived method!";
585             #
586             # $_[0] ==> set
587             # $_[1] ==> dbxref string
588             #
589 5         10 my $dbxref_set = $_[0];
590 5         10 my $dbxref_as_string = $_[1];
591            
592 5         21 $dbxref_as_string =~ s/^\[//;
593 5         19 $dbxref_as_string =~ s/\]$//;
594 5         11 $dbxref_as_string =~ s/\\,/;;;;/g; # trick to keep the comma's
595 5         11 $dbxref_as_string =~ s/\\"/;;;;;/g; # trick to keep the double quote's
596            
597 5         19 my @lineas = $dbxref_as_string =~ /\"([^\"]*)\"/g; # get the double-quoted pieces
598 5         14 foreach my $l (@lineas) {
599 1         2 my $cp = $l;
600 1         2 $l =~ s/,/;;;;/g; # trick to keep the comma's
601 1         17 $dbxref_as_string =~ s/\Q$cp\E/$l/;
602             }
603            
604 5         18 my @dbxrefs = split (',', $dbxref_as_string);
605            
606 5         22 my $r_db_acc = qr/([ \*\.\w-]*):([ '\#~\w:\\\+\?\{\}\$\/\(\)\[\]\.=&!%_-]*)/o;
607 5         17 my $r_desc = qr/\s+\"([^\"]*)\"/o;
608 5         14 my $r_mod = qr/\s+(\{[\w ]+=[\w ]+\})/o;
609            
610 5         13 foreach my $entry (@dbxrefs) {
611 7         15 my ($match, $db, $acc, $desc, $mod) = undef;
612 7         29 my $dbxref = OBO::Core::Dbxref->new();
613 7 100       1798 if ($entry =~ m/$r_db_acc$r_desc$r_mod?/) {
    50          
614 1         4 $db = __unescape($1);
615 1         3 $acc = __unescape($2);
616 1         3 $desc = __unescape($3);
617 1 50       6 $mod = __unescape($4) if ($4);
618             } elsif ($entry =~ m/$r_db_acc$r_desc?$r_mod?/) {
619 6         21 $db = __unescape($1);
620 6         17 $acc = __unescape($2);
621 6 50       26 $desc = __unescape($3) if ($3);
622 6 50       20 $mod = __unescape($4) if ($4);
623             } else {
624 0         0 return (-1, $entry);
625             }
626            
627             # set the dbxref:
628 7         140 $dbxref->name($db.':'.$acc);
629 7 100       28 $dbxref->description($desc) if (defined $desc);
630 7 100       18 $dbxref->modifier($mod) if (defined $mod);
631 7         29 $dbxref_set->add($dbxref);
632             }
633 5         26 return 1;
634             }
635              
636             sub __unescape {
637 16 50   16   46 caller eq __PACKAGE__ or die;
638 16         39 my $match = $_[0];
639 16         28 $match =~ s/;;;;;/\\"/g;
640 16         25 $match =~ s/;;;;/\\,/g;
641 16         38 return $match;
642             }
643              
644             1;
645              
646             __END__