Bio/Ontology/GOterm.pm

filter: Statementstmt 94.4% 68 / 72 Branchbran 64.2% 9 / 14 Conditioncond 46.1% 6 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 81.8% 104 / 127 CC 14 SCAR 12.9
CC
14
Cov
84%
to_string
7.3
_check_go_id
4.5
_array_to_string
4.1
CRAP 3.7
« Bio/Tools/pICalculator.pm ↑ Summary Bio/Factory/ObjectFactory.pm »
1 #
2 # BioPerl module for Bio::Ontology::GOterm
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  
25 =head1 NAME
26  
27 Bio::Ontology::GOterm - representation of GO terms
28  
29 =head1 SYNOPSIS
30  
31 $term = Bio::Ontology::GOterm->new
32 ( -go_id => "GO:0016847",
33 -name => "1-aminocyclopropane-1-carboxylate synthase",
34 -definition => "Catalysis of ...",
35 -is_obsolete => 0,
36 -comment => "" );
37  
38 $term->add_definition_references( @refs );
39 $term->add_secondary_GO_ids( @ids );
40 $term->add_aliases( @aliases );
41  
42 foreach my $dr ( $term->each_definition_reference() ) {
43 print $dr, "\n";
44 }
45  
46 # etc.
47  
48 =head1 DESCRIPTION
49  
50 This is "dumb" class for GO terms (it provides no functionality
51 related to graphs). Implements Bio::Ontology::TermI.
52  
53 =head1 FEEDBACK
54  
55 =head2 Mailing Lists
56  
57 User feedback is an integral part of the evolution of this and other
58 Bioperl modules. Send your comments and suggestions preferably to one
59 of the Bioperl mailing lists. Your participation is much appreciated.
60  
61 bioperl-l@bioperl.org - General discussion
62 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
63  
64 =head2 Support
65  
66 Please direct usage questions or support issues to the mailing list:
67  
68 I<bioperl-l@bioperl.org>
69  
70 rather than to the module maintainer directly. Many experienced and
71 reponsive experts will be able look at the problem and quickly
72 address it. Please include a thorough description of the problem
73 with code and data examples if at all possible.
74  
75 =head2 Reporting Bugs
76  
77 Report bugs to the Bioperl bug tracking system to help us keep track
78 the bugs and their resolution. Bug reports can be submitted via the web:
79  
80 https://github.com/bioperl/bioperl-live/issues
81  
82 =head1 AUTHOR
83  
84 Christian M. Zmasek
85  
86 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
87  
88 WWW: http://monochrome-effect.net/
89  
90 Address:
91  
92 Genomics Institute of the Novartis Research Foundation
93 10675 John Jay Hopkins Drive
94 San Diego, CA 92121
95  
96 =head1 APPENDIX
97  
98 The rest of the documentation details each of the object
99 methods.
100  
101 =cut
102  
103  
104 # Let the code begin...
105  
106 package Bio::Ontology::GOterm;
107 7 $Bio::Ontology::GOterm::VERSION = '1.7.8';
108 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 7 ▶use constant GOID_DEFAULT => "GO:0000000";
Subroutine BEGIN: called CC=1 SCAR=0.0
111 7 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 7 ▶use constant FALSE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 7 ▶use base qw(Bio::Ontology::Term);
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 =head2 new
117  
118 Title : new
119 Usage : $term = Bio::Ontology::GOterm->new(
120 -go_id => "GO:0016847",
121 -name => "1-aminocyclopropane-1-carboxylate synthase",
122 -definition => "Catalysis of ...",
123 -is_obsolete => 0,
124 -comment => "" );
125 Function: Creates a new Bio::Ontology::GOterm.
126 Returns : A new Bio::Ontology::GOterm object.
127 Args : -go_id => the goid of this GO term [GO:nnnnnnn]
128 or [nnnnnnn] (nnnnnnn is a zero-padded
129 integer of seven digits)
130 -name => the name of this GO term [scalar]
131 -definition => the definition of this GO term [scalar]
132 -ontology => the ontology for this term (a
133 Bio::Ontology::OntologyI compliant object)
134 -version => version information [scalar]
135 -is_obsolete => the obsoleteness of this GO term [0 or 1]
136 -comment => a comment [scalar]
137  
138 =cut
139  
140 233 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
141  
142 233 my( $class,@args ) = @_;
143
144 233 my $self = $class->SUPER::new( @args );
145
146 233 my ( $GO_id )
147 = $self->_rearrange( [ qw( GO_ID ) ], @args );
148
149 233 ▶ $GO_id && $self->GO_id( $GO_id );
Branch: 1 branch
BranchTrueFalseTotal
$GO_id and $self->GO_id($GO_id) 1 232 233
150
151
152 233 return $self;
153
154 } # new
155  
156  
157 =head2 init
158  
159 Title : init()
160 Usage : $term->init();
161 Function: Initializes this GOterm to all "" and empty lists.
162 Returns :
163 Args :
164  
165 =cut
166  
167 235 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
168  
169 235 my $self = shift;
170  
171 # first call the inherited version to properly chain up the hierarchy
172 235 $self->SUPER::init(@_);
173  
174 # then only initialize what we implement ourselves here
175 #$self->GO_id( GOID_DEFAULT );
176
177 } # init
178  
179  
180 =head2 GO_id
181  
182 Title : GO_id
183 Usage : $term->GO_id( "GO:0003947" );
184 or
185 print $term->GO_id();
186 Function: Set/get for the goid of this GO term.
187  
188 This is essentially an alias to identifier(), with added
189 format checking.
190  
191 Returns : The goid [GO:nnnnnnn].
192 Args : The goid [GO:nnnnnnn] or [nnnnnnn] (nnnnnnn is a
193 zero-padded integer of seven digits) (optional).
194  
195 =cut
196  
197 157 ▶sub GO_id {
Subroutine GO_id: called CC=2 SCAR=6.9
Pod documented
198 157 my $self = shift;
199 157 my $value;
200  
201 157 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 154 157
202 3 $value = $self->_check_go_id( shift );
203 3 unshift(@_, $value);
204 }
205  
206 157 return $self->identifier( @_ );
207  
208 } # GO_id
209  
210  
211 =head2 get_secondary_GO_ids
212  
213 Title : get_secondary_GO_ids
214 Usage : @ids = $term->get_secondary_GO_ids();
215 Function: Returns a list of secondary goids of this Term.
216  
217 This is aliased to remove_secondary_ids().
218  
219 Returns : A list of secondary goids [array of [GO:nnnnnnn]]
220 (nnnnnnn is a zero-padded integer of seven digits).
221 Args :
222  
223 =cut
224  
225 7 ▶sub get_secondary_GO_ids {
Subroutine get_secondary_GO_ids: called CC=1 SCAR=0.0
Pod documented
226 7 return shift->get_secondary_ids(@_);
227 } # get_secondary_GO_ids
228  
229  
230 =head2 add_secondary_GO_id
231  
232 Title : add_secondary_GO_id
233 Usage : $term->add_secondary_GO_id( @ids );
234 or
235 $term->add_secondary_GO_id( $id );
236 Function: Pushes one or more secondary goids into
237 the list of secondary goids.
238  
239 This is aliased to remove_secondary_ids().
240  
241 Returns :
242 Args : One secondary goid [GO:nnnnnnn or nnnnnnn] or a list
243 of secondary goids [array of [GO:nnnnnnn or nnnnnnn]]
244 (nnnnnnn is a zero-padded integer of seven digits).
245  
246 =cut
247  
248 2 ▶sub add_secondary_GO_id {
Subroutine add_secondary_GO_id: called CC=1 SCAR=0.0
Pod documented
249 2 return shift->add_secondary_id(@_);
250 } # add_secondary_GO_id
251  
252  
253 =head2 remove_secondary_GO_ids
254  
255 Title : remove_secondary_GO_ids()
256 Usage : $term->remove_secondary_GO_ids();
257 Function: Deletes (and returns) the secondary goids of this Term.
258  
259 This is aliased to remove_secondary_ids().
260  
261 Returns : A list of secondary goids [array of [GO:nnnnnnn]]
262 (nnnnnnn is a zero-padded integer of seven digits).
263 Args :
264  
265 =cut
266  
267 2 ▶sub remove_secondary_GO_ids {
Subroutine remove_secondary_GO_ids: called CC=1 SCAR=0.0
Pod documented
268 2 return shift->remove_secondary_ids(@_);
269 } # remove_secondary_GO_ids
270  
271  
272 =head2 to_string
273  
274 Title : to_string()
275 Usage : print $term->to_string();
276 Function: to_string method for GO terms.
277 Returns : A string representation of this GOterm.
278 Args :
279  
280 =cut
281  
282 1 ▶sub to_string {
Subroutine to_string: called CC=7 SCAR=19.9
Pod documented
283 1 my( $self ) = @_;
284  
285 1 my $s = "";
286  
287 1 $s .= "-- GO id:\n";
288 1 ▶ $s .= ($self->GO_id() || '')."\n";
Condition50%1/2
$self->GO_id || ''
l!l
01
MC/DC0%0/1
$self->GO_id || ''
$self->GO_id
Truth table50%1/2
A
A= $self->GO_id
Aresult
11
00
289 1 $s .= "-- Name:\n";
290 1 ▶ $s .= ($self->name() || '') ."\n";
Condition50%1/2
$self->name || ''
l!l
01
MC/DC0%0/1
$self->name || ''
$self->name
Truth table50%1/2
A
A= $self->name
Aresult
11
00
291 1 $s .= "-- Definition:\n";
292 1 ▶ $s .= ($self->definition() || '') ."\n";
Condition50%1/2
$self->definition || ''
l!l
01
MC/DC0%0/1
$self->definition || ''
$self->definition
Truth table50%1/2
A
A= $self->definition
Aresult
11
00
293 1 $s .= "-- Category:\n";
294 1 ▶ if ( defined( $self->ontology() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->ontology) { } 0 1 1
295 0 $s .= $self->ontology()->name()."\n";
296 }
297 else {
298 1 $s .= "\n";
299 }
300 1 $s .= "-- Version:\n";
301 1 ▶ $s .= ($self->version() || '') ."\n";
Condition50%1/2
$self->version || ''
l!l
01
MC/DC0%0/1
$self->version || ''
$self->version
Truth table50%1/2
A
A= $self->version
Aresult
11
00
302 1 $s .= "-- Is obsolete:\n";
303 1 $s .= $self->is_obsolete()."\n";
304 1 $s .= "-- Comment:\n";
305 1 ▶ $s .= ($self->comment() || '') ."\n";
Condition50%1/2
$self->comment || ''
l!l
01
MC/DC0%0/1
$self->comment || ''
$self->comment
Truth table50%1/2
A
A= $self->comment
Aresult
11
00
306 1 $s .= "-- Definition references:\n";
307 1 $s .= $self->_array_to_string( $self->get_dbxrefs() )."\n";
308 1 $s .= "-- Secondary GO ids:\n";
309 1 $s .= $self->_array_to_string( $self->get_secondary_GO_ids() )."\n";
310 1 $s .= "-- Aliases:\n";
311 1 $s .= $self->_array_to_string( $self->get_synonyms() );
312
313 1 return $s;
314
315 } # to_string
316  
317  
318  
319  
320 # Title : _check_go_id
321 # Function: Checks whether the argument is [GO:nnnnnnn].
322 # If "GO:" is not present, it adds it.
323 # Returns : The canonical GO id.
324 # Args : The value to be checked.
325 3 ▶sub _check_go_id {
Subroutine _check_go_id: called CC=4 SCAR=15.0
326 3 my ( $self, $value ) = @_;
327 3 ▶ unless ( $value =~ /^(GO:)?\d{7}$/ || $value eq GOID_DEFAULT ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^(GO:)?\d{7}$/ or $value eq "GO:0000000") 0 3 3
Condition33%1/3
$value =~ /^(GO:)?\d{7}$/ or $value eq "GO:0000000"
l!l&&r!l&&!r
300
MC/DC0%0/2
$value =~ /^(GO:)?\d{7}$/ or $value eq "GO:0000000"
$value =~ /^(GO:)?\d{7}$/ $value eq "GO:0000000"
Truth table33%1/3
A or B
A= $value =~ /^(GO:)?\d{7}$/B= $value eq "GO:0000000"
ABresult
1X1
011
000
328 0 $self->throw( "Found [" . $value
329 . "] where [GO:nnnnnnn] or [nnnnnnn] expected" );
330 }
331 3 ▶ unless ( $value =~ /^GO:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^GO:/) 1 2 3
332 1 $value = "GO:".$value;
333 }
334 3 return $value;
335 } # _check_go_id
336  
337  
338  
339 # Title : _array_to_string
340 # Function:
341 # Returns :
342 # Args :
343 3 ▶sub _array_to_string {
Subroutine _array_to_string: called CC=3 SCAR=14.2
344 3 my( $self, @value ) = @_;
345  
346 3 my $s = "";
347
348 3 ▶ for ( my $i = 0; $i < scalar( @value ); ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @value) 0 3 3
349 0 ▶ if ( ! ref( $value[ $i ] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value[$i]) 0 0 0
350 0 $s .= "#" . $i . "\n-- " . $value[ $i ] . "\n";
351 }
352 }
353
354 3 return $s;
355
356 } # _array_to_string
357  
358 #################################################################
359 # aliases or forwards to maintain backward compatibility
360 #################################################################
361  
362 7 *each_secondary_GO_id = \&get_secondary_GO_ids;
363 7 *add_secondary_GO_ids = \&add_secondary_GO_id;
364  
365 7 1;
« Bio/Tools/pICalculator.pm ↑ Summary Bio/Factory/ObjectFactory.pm »