AnnotatedGene.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 4 / 4 Conditioncond 61.1% 11 / 18 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 12 / 12 Podpod 100% 6 / 6 totaltotal 83.1% 84 / 101 CC 9 SCAR 13.9
CC
9
Cov
90%
__init
8.2
_handleMissingArgument
2.1
BEGIN
1.0
CRAP 4.0
« Utils/File.pm ↑ Summary TermFinder/Native.pm »
1 package GO::AnnotatedGene;
2  
3  
4 # File : AnnotatedGene.pm
5 # Author : Gavin Sherlock
6 # Date Begun : March 9th 2003
7  
8 # $Id: AnnotatedGene.pm,v 1.2 2003/11/26 19:23:52 sherlock Exp $
9  
10 # License information (the MIT license)
11  
12 # Copyright (c) 2003 Gavin Sherlock; Stanford University
13  
14 # Permission is hereby granted, free of charge, to any person
15 # obtaining a copy of this software and associated documentation files
16 # (the "Software"), to deal in the Software without restriction,
17 # including without limitation the rights to use, copy, modify, merge,
18 # publish, distribute, sublicense, and/or sell copies of the Software,
19 # and to permit persons to whom the Software is furnished to do so,
20 # subject to the following conditions:
21  
22 # The above copyright notice and this permission notice shall be
23 # included in all copies or substantial portions of the Software.
24  
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 # SOFTWARE.
33  
34 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use diagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 =pod
39  
40 =head1 NAME - I<will> provide an object to hold info about a gene with GO annotation
41  
42 GO::AnnotatedGene
43  
44 =head1 DESCRIPTION
45  
46 The GO::AnnotatedGene package allows creation of objects that contains
47 the details of a gene as determined from a gene_associations file.
48 Typically these objects will contain the following information:
49  
50 Column Cardinality Contents
51 ------ ----------- -------------------------------------------------------------
52 1 1 Database identifier of the annotated gene
53 2 1 Standard name of the annotated gene
54 9 0,1 Name of the product of the annotated gene
55 10 0,n Alias(es) of the annotated gene
56 11 1 type of the annotated gene (one of gene, transcript, protein)
57  
58  
59 Further details can be found at:
60  
61 http://www.geneontology.org/doc/GO.annotation.html#file
62  
63 It is expected that AnnotatedGene objects will typically be created by
64 concrete subclasses of AnnotationProvider
65  
66 =head1 TODO
67  
68 A lot....
69  
70 =cut
71  
72 1 ▶use vars qw ($PACKAGE $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 1 $PACKAGE = "GO::AnnotatedGene";
75 1 $VERSION = "0.11";
76  
77 # CLASS Attributes
78 #
79 # These should be considered as constants, and are initialized here
80  
81 1 my $kDatabaseId = $PACKAGE.'::__databaseId';
82 1 my $kStandardName = $PACKAGE.'::__standardName';
83 1 my $kType = $PACKAGE.'::__type';
84 1 my $kProductName = $PACKAGE.'::__productName';
85 1 my $kAliases = $PACKAGE.'::__aliases';
86  
87 =pod
88  
89 =head1 Constructor
90  
91 =cut
92  
93 ############################################################################
94 5 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
95 ############################################################################
96 =pod
97  
98 =head2 new
99  
100 This is the constructor for a GO::AnnotatedGene object
101  
102 It expects to receive the following named arguments:
103  
104 databaseId : The databaseId of the annotated gene
105 standardName : The standardName of the annotated gene
106 type : The type of the annotated gene (one of gene, transcript, protein)
107  
108 In addition, the following optional arguments may also be provided:
109  
110 productName : The name of the product of the annotated gene
111 aliases : A reference to an array of aliases
112  
113 Usage:
114  
115 my $annotatedGene = GO::AnnotatedGene->new(databaseId => $databaseId,
116 standardName => $standardName,
117 type => $type,
118 productName => $productName,
119 aliases => $aliases);
120  
121 =cut
122  
123 5 my $self = {};
124  
125 5 my $class = shift;
126  
127 5 bless $self, $class;
128  
129 5 $self->__init(@_);
130  
131 2 return $self;
132  
133 }
134  
135 ############################################################################
136 5 ▶sub __init{
Subroutine __init: called CC=8 SCAR=21.1
137 ############################################################################
138 # This private method initializes the object, dependent on what arguments
139 # have been received.
140 #
141  
142 5 my ($self, %args) = @_;
143  
144 # check required arguments
145  
146 5 ▶ my $databaseId = $args{'databaseId'} || $self->_handleMissingArgument(argument => 'databaseId');
Condition66%2/3
$args{'databaseId'} || $self->_handleMissingArgument('argument', 'databaseId')
l!l&&r!l&&!r
410
MC/DC0%0/2
$args{'databaseId'} || $self->_handleMissingArgument('argument', 'databaseId')
$args{'databaseId'} $self->_handleMissingArgument('argument', 'databaseId')
Truth table33%1/3
A || B
A= $args{'databaseId'}B= $self->_handleMissingArgument('argument', 'databaseId')
ABresult
1X1
011
000
147 4 ▶ my $standardName = $args{'standardName'} || $self->_handleMissingArgument(argument => 'standardName');
Condition66%2/3
$args{'standardName'} || $self->_handleMissingArgument('argument', 'standardName')
l!l&&r!l&&!r
310
MC/DC0%0/2
$args{'standardName'} || $self->_handleMissingArgument('argument', 'standardName')
$args{'standardName'} $self->_handleMissingArgument('argument', 'standardName')
Truth table33%1/3
A || B
A= $args{'standardName'}B= $self->_handleMissingArgument('argument', 'standardName')
ABresult
1X1
011
000
148 3 ▶ my $type = $args{'type'} || $self->_handleMissingArgument(argument => 'type');
Condition66%2/3
$args{'type'} || $self->_handleMissingArgument('argument', 'type')
l!l&&r!l&&!r
201
MC/DC0%0/2
$args{'type'} || $self->_handleMissingArgument('argument', 'type')
$args{'type'} $self->_handleMissingArgument('argument', 'type')
Truth table33%1/3
A || B
A= $args{'type'}B= $self->_handleMissingArgument('argument', 'type')
ABresult
1X1
011
000
149  
150 # store them
151  
152 2 $self->{$kDatabaseId} = $databaseId;
153 2 $self->{$kStandardName} = $standardName;
154 2 $self->{$kType} = $type;
155
156 # now check and store optional arguments
157  
158 2 ▶ if (exists ($args{'productName'}) && defined ($args{'productName'})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'productName'} and defined $args{'productName'}) { } 1 1 2
Condition66%2/3
exists $args{"productName"} and defined $args{"productName"}
!ll&&!rl&&r
101
MC/DC50%1/2
exists $args{"productName"} and defined $args{"productName"}
exists $args{"productName"} defined $args{"productName"}
Truth table66%2/3
A and B
A= exists $args{"productName"}B= defined $args{"productName"}
ABresult
0X0
100
111
159  
160 1 $self->{$kProductName} = $args{'productName'};
161  
162 }else{
163  
164 1 $self->{$kProductName} = undef;
165  
166 }
167  
168 2 ▶ if (exists ($args{'aliases'}) && defined ($args{'aliases'})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'aliases'} and defined $args{'aliases'}) { } 1 1 2
Condition66%2/3
exists $args{"aliases"} and defined $args{"aliases"}
!ll&&!rl&&r
101
MC/DC50%1/2
exists $args{"aliases"} and defined $args{"aliases"}
exists $args{"aliases"} defined $args{"aliases"}
Truth table66%2/3
A and B
A= exists $args{"aliases"}B= defined $args{"aliases"}
ABresult
0X0
100
111
169  
170 1 $self->{$kAliases} = $args{'aliases'};
171  
172 }else{
173  
174 1 $self->{$kAliases} = []; # default to an empty list
175  
176 }
177  
178 }
179  
180 =pod
181  
182 =head1 Public Instance Methods
183  
184 =cut
185  
186 ############################################################################
187 1 ▶sub databaseId{
Subroutine databaseId: called CC=1 SCAR=0.0
Pod documented
188 ############################################################################
189 =pod
190  
191 =head2 databaseId
192  
193 This public instance method returns the databaseId.
194  
195 Usage :
196  
197 my $databaseId = $annotatedGene->databaseId;
198  
199 =cut
200  
201 1 return $_[0]->{$kDatabaseId};
202  
203 }
204  
205 ############################################################################
206 1 ▶sub standardName{
Subroutine standardName: called CC=1 SCAR=0.0
Pod documented
207 ############################################################################
208 =pod
209  
210 =head2 standardName
211  
212 This public instance method returns the standardName.
213  
214 Usage:
215  
216 my $standardName = $annotatedGene->standardName;
217  
218 =cut
219  
220 1 return $_[0]->{$kStandardName};
221  
222 }
223  
224 ############################################################################
225 1 ▶sub type{
Subroutine type: called CC=1 SCAR=0.0
Pod documented
226 ############################################################################
227 =pod
228  
229 =head2 type
230  
231 This public instance method returns the type of the annotated gene.
232  
233 Usage:
234  
235 my $type = $annotatedGene->type;
236  
237 =cut
238  
239 1 return $_[0]->{$kType};
240  
241 }
242  
243 ############################################################################
244 2 ▶sub productName{
Subroutine productName: called CC=1 SCAR=0.0
Pod documented
245 ############################################################################
246 =pod
247  
248  
249 =head2 productName
250  
251 This public instance method returns the product name of the annotated
252 gene, if one exists. Otherwise it returns undef.
253  
254 Usage:
255  
256 my $productName = $annotatedGene->productName;
257  
258 =cut
259  
260 2 return $_[0]->{$kProductName};
261  
262 }
263  
264 ############################################################################
265 3 ▶sub aliases{
Subroutine aliases: called CC=1 SCAR=0.0
Pod documented
266 ############################################################################
267 =pod
268  
269 =head2 aliases
270  
271 This public instance method returns an array of aliases for the
272 annotated gene. If no aliases exist, then an empty array will be
273 returned.
274  
275 Usage:
276  
277 my @aliases = $annotatedGene->aliases;
278  
279 =cut
280  
281 3 return @{$_[0]->{$kAliases}};
282  
283 }
284  
285 =pod
286  
287 =head1 Protected Methods
288  
289 =cut
290  
291 # need to make this code common to all objects, or to
292 # start using something like Params-Validate
293  
294 ############################################################################
295 3 ▶sub _handleMissingArgument{
Subroutine _handleMissingArgument: called CC=2 SCAR=7.2
296 ############################################################################
297 =pod
298  
299 =head2 _handleMissingArgument
300  
301 This protected method simply provides a simple way for concrete
302 subclasses to deal with missing arguments from method calls. It will
303 die with an appropriate error message.
304  
305 Usage:
306  
307 $self->_handleMissingArgument(argument=>'blah');
308  
309 =cut
310 ##############################################################################
311  
312 3 my ($self, %args) = @_;
313  
314 3 ▶ my $arg = $args{'argument'} || $self->_handleMissingArgument(argument=>'argument');
Condition33%1/3
$args{'argument'} || $self->_handleMissingArgument('argument', 'argument')
l!l&&r!l&&!r
300
MC/DC0%0/2
$args{'argument'} || $self->_handleMissingArgument('argument', 'argument')
$args{'argument'} $self->_handleMissingArgument('argument', 'argument')
Truth table33%1/3
A || B
A= $args{'argument'}B= $self->_handleMissingArgument('argument', 'argument')
ABresult
1X1
011
000
315  
316 3 my $receiver = (caller(1))[3];
317 3 my $caller = (caller(2))[3];
318  
319 3 die "The method $caller did not provide a value for the '$arg' argument for the $receiver method";
320  
321 }
322  
323  
324  
325 1 1; # to keep Perl happy
326  
327 =pod
328  
329 =head1 AUTHOR
330  
331 Gavin Sherlock, sherlock@genome.stanford.edu
332  
333 =cut
« Utils/File.pm ↑ Summary TermFinder/Native.pm »