File Coverage

blib/lib/OBO/APO/APO_ID.pm
Criterion Covered Total %
statement 40 40 100.0
branch 5 6 83.3
condition 6 12 50.0
subroutine 9 9 100.0
pod 5 6 83.3
total 65 73 89.0


line stmt bran cond sub pod time code
1             # $Id: APO_ID.pm 2010-09-29 erick.antezana $
2             #
3             # Module : APO_ID.pm
4             # Purpose : A APO_ID.
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              
11             package OBO::APO::APO_ID;
12              
13             =head1 NAME
14              
15             OBO::APO::APO_ID - A module for describing Application Ontology (APO) identifiers. Its idspace, subnamespace and localID are stored.
16              
17             =head1 SYNOPSIS
18              
19             use OBO::APO::APO_ID;
20              
21             $id = APO_ID->new();
22              
23             $id->idspace("APO");
24              
25             $id->subnamespace("X");
26              
27             $id->localID("0000001");
28              
29             $idspace = $id->idspace();
30              
31             $subnamespace = $id->subnamespace();
32              
33             $localID = $id->localID();
34              
35             print $id->id_as_string();
36              
37             $id->id_as_string("APO:P1234567");
38              
39             =head1 DESCRIPTION
40              
41             The OBO::APO::APO_ID class implements an Application Ontology identifier.
42              
43             A APO ID holds: IDSPACE, SUBNAMESPACE and a NUMBER in the following form:
44              
45             APO:[A-Z][a-z]?nnnnnnn
46              
47             For instance: APO:Pa1234567
48              
49             The SUBNAMESPACE may be one of the following:
50            
51             C Cellular component
52             F Molecular Function
53             P Biological Process
54             B Protein
55             G Gene
56             I Interaction
57             R Reference
58             T Taxon
59             N Instance
60             U Upper Level Ontology (APO)
61             L Relationship type (e.g. is_a)
62             Y Interaction type
63             Z Unknown
64            
65             plus an extra (optional) qualifier could be added to explicitly capture the organism:
66              
67             a Arabidopsis thaliana
68             h Homo sapiens
69             y Saccharomyces cerevisiae
70             s Schizosaccharomyces pombe
71             c Caenorhabditis elegans
72             d Drosophila melanogaster
73             m Mus musculus
74              
75             =head1 AUTHOR
76              
77             Erick Antezana, Eerick.antezana -@- gmail.comE
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             Copyright (c) 2006-2015 by Erick Antezana. All rights reserved.
82              
83             This library is free software; you can redistribute it and/or modify
84             it under the same terms as Perl itself, either Perl version 5.8.7 or,
85             at your option, any later version of Perl 5 you may have available.
86              
87             =cut
88              
89             our @ISA = qw(OBO::XO::OBO_ID);
90 3     3   39859 use OBO::XO::OBO_ID;
  3         7  
  3         102  
91 3     3   17 use strict;
  3         6  
  3         71  
92 3     3   16 use Carp;
  3         5  
  3         1758  
93            
94             sub new {
95 27     27 0 449 my $class = shift;
96 27         41 my $self = {};
97              
98 27         65 $self->{IDSPACE} = undef; # string
99 27         56 $self->{SUBNAMESPACE} = undef; # subnamespace
100 27         69 $self->{LOCALID} = undef; # 7 digits
101              
102 27         43 bless ($self, $class);
103 27         71 return $self;
104             }
105              
106             =head2 subnamespace
107              
108             Usage - print $id->subnamespace() or $id->subnamespace($name)
109             Returns - the subnamespace (string)
110             Args - the subnamespace (string)
111             Function - gets/sets the subnamespace
112            
113             =cut
114              
115             sub subnamespace {
116 2     2 1 13 my ($self, $sns) = @_;
117 2 50       8 if ($sns) { $self->{SUBNAMESPACE} = $sns }
  2         5  
118 2         5 return $self->{SUBNAMESPACE};
119             }
120              
121             =head2 id_as_string
122              
123             Usage - print $id->id_as_string() or $id->id_as_string("APO:X0000001")
124             Returns - the id as string (scalar)
125             Args - the id as string
126             Function - gets/sets the id as string
127            
128             =cut
129              
130             sub id_as_string () {
131 125     125 1 194 my ($self, $id_as_string) = @_;
132 125 100 66     818 if ( defined $id_as_string && $id_as_string =~ /(APO):([A-Z][a-z]?)([0-9]{7})/ ) {
    100 66        
      33        
133 23         65 $self->{IDSPACE} = $1;
134 23         47 $self->{SUBNAMESPACE} = $2;
135 23         146 $self->{LOCALID} = substr($3 + 10000000, 1, 7); # trick: forehead zeros
136             } elsif ($self->{IDSPACE} && $self->{SUBNAMESPACE} && $self->{LOCALID}) {
137 101         391 return $self->{IDSPACE}.':'.$self->{SUBNAMESPACE}.$self->{LOCALID};
138             }
139             }
140             *id = \&id_as_string;
141              
142             =head2 equals
143              
144             Usage - print $id->equals($id)
145             Returns - 1 (true) or 0 (false)
146             Args - the other ID (OBO::APO::APO_ID)
147             Function - tells if two IDs are equal
148            
149             =cut
150              
151             sub equals () {
152 1     1 1 6 my ($self, $target) = @_;
153             return (($self->{IDSPACE} eq $target->{IDSPACE}) &&
154             ($self->{SUBNAMESPACE} eq $target->{SUBNAMESPACE}) &&
155 1   33     25 ($self->{LOCALID} == $target->{LOCALID}));
156             }
157              
158             =head2 next_id
159              
160             Usage - $id->next_id()
161             Returns - the next ID (OBO::APO::APO_ID)
162             Args - none
163             Function - returns the next ID, which is new
164            
165             =cut
166              
167             sub next_id () {
168 1     1 1 4 my $self = shift;
169 1         5 my $next_id = OBO::APO::APO_ID->new();
170 1         4 $next_id->{IDSPACE} = $self->{IDSPACE};
171 1         3 $next_id->{SUBNAMESPACE} = $self->{SUBNAMESPACE};
172 1         5 $next_id->{LOCALID} = substr(10000001 + $self->{LOCALID}, 1, 7); # trick: forehead zeros
173 1         5 return $next_id;
174             }
175              
176             =head2 previous_id
177              
178             Usage - $id->previous_id()
179             Returns - the previous ID (OBO::APO::APO_ID)
180             Args - none
181             Function - returns the previous ID, which is new
182            
183             =cut
184              
185             sub previous_id () {
186 1     1 1 3 my $self = shift;
187 1         4 my $previous_id = OBO::APO::APO_ID->new ();
188 1         3 $previous_id->{IDSPACE} = $self->{IDSPACE};
189 1         3 $previous_id->{SUBNAMESPACE} = $self->{SUBNAMESPACE};
190 1         6 $previous_id->{LOCALID} = substr((10000000 + $self->{LOCALID}) - 1, 1, 7); # trick: forehead zeros
191 1         6 return $previous_id;
192             }
193              
194             1;