line |
bran |
sub |
pod |
code |
1
|
|
|
|
package Sanger::CGP::Vagrent::Data::AnnotationGroup; |
2
|
|
|
|
|
3
|
|
|
|
##########LICENCE########## |
4
|
|
|
|
# Copyright (c) 2014 Genome Research Ltd. |
5
|
|
|
|
# |
6
|
|
|
|
# Author: Cancer Genome Project cgpit@sanger.ac.uk |
7
|
|
|
|
# |
8
|
|
|
|
# This file is part of VAGrENT. |
9
|
|
|
|
# |
10
|
|
|
|
# VAGrENT is free software: you can redistribute it and/or modify it under |
11
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free |
12
|
|
|
|
# Software Foundation; either version 3 of the License, or (at your option) any |
13
|
|
|
|
# later version. |
14
|
|
|
|
# |
15
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
16
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
18
|
|
|
|
# details. |
19
|
|
|
|
# |
20
|
|
|
|
# You should have received a copy of the GNU Affero General Public License |
21
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
|
##########LICENCE########## |
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
4
|
|
use strict; |
26
|
|
4
|
|
use Data::Dumper; |
27
|
|
4
|
|
use List::Util qw(first); |
28
|
|
4
|
|
use Carp; |
29
|
|
|
|
|
30
|
|
4
|
|
use Log::Log4perl; |
31
|
|
4
|
|
use Sanger::CGP::Vagrent qw($VERSION); |
32
|
|
4
|
|
use Sanger::CGP::Vagrent::Data::Transcript; |
33
|
|
|
|
|
34
|
|
4
|
|
use base qw(Sanger::CGP::Vagrent); |
35
|
|
|
|
|
36
|
|
|
|
my $log = Log::Log4perl->get_logger(__PACKAGE__); |
37
|
|
|
|
1; |
38
|
|
|
|
|
39
|
|
|
|
sub new { |
40
|
|
818
|
1
|
my $proto = shift; |
41
|
|
|
|
my $class = ref($proto) || $proto; |
42
|
|
|
|
my $self = {}; |
43
|
|
|
|
bless($self, $class); |
44
|
|
|
|
$self->_init(@_); |
45
|
|
|
|
return $self; |
46
|
|
|
|
} |
47
|
|
|
|
|
48
|
|
|
|
sub _init { |
49
|
|
818
|
|
my $self = shift; |
50
|
|
|
|
my %vars = @_; |
51
|
|
|
|
foreach my $k(keys(%vars)){ |
52
|
100
|
|
|
if($k eq 'label'){ |
|
100
|
|
|
|
|
100
|
|
|
|
|
50
|
|
|
|
53
|
|
|
|
$self->{_label} = $vars{label}; |
54
|
|
|
|
} elsif($k eq 'accession'){ |
55
|
|
|
|
$self->{_accession} = $vars{accession}; |
56
|
|
|
|
} elsif($k eq 'type'){ |
57
|
|
|
|
my $good = undef; |
58
|
|
|
|
foreach my $type(Sanger::CGP::Vagrent::Data::Transcript->getAllGeneTypes){ |
59
|
100
|
|
|
if($vars{type} eq $type){ |
60
|
|
|
|
$good = $vars{type}; |
61
|
|
|
|
last; |
62
|
|
|
|
} |
63
|
|
|
|
} |
64
|
50
|
|
|
if(defined($good)){ |
65
|
|
|
|
$self->{_type} = $good; |
66
|
|
|
|
} else { |
67
|
|
|
|
croak('recieved unknown gene type: '.$vars{type}); |
68
|
|
|
|
} |
69
|
|
|
|
} elsif($k eq 'ccds'){ |
70
|
|
|
|
$self->{_ccds} = $vars{ccds}; |
71
|
|
|
|
} |
72
|
|
|
|
} |
73
|
|
|
|
} |
74
|
|
|
|
|
75
|
|
|
|
sub addAnnotation { |
76
|
|
1700
|
1
|
my ($self,$a) = @_; |
77
|
50
|
|
|
unless(defined($a)){ |
78
|
|
|
|
$log->error('cannot add an undef Annotation object to an annotation group'); |
79
|
|
|
|
return; |
80
|
|
|
|
} |
81
|
50
|
|
|
unless($a->isa('Sanger::CGP::Vagrent::Data::Annotation')){ |
82
|
|
|
|
$log->error('can only add Annotation objects to an annotation group'); |
83
|
|
|
|
return; |
84
|
|
|
|
} |
85
|
100
|
|
|
if(exists($self->{_anno}) && defined($self->{_anno}) && scalar(@{$self->{_anno}}) > 0){ |
86
|
|
|
|
my $good = 1; |
87
|
|
|
|
foreach my $ca(@{$self->{_anno}}){ |
88
|
50
|
|
|
if($ca->getContext eq $a->getContext){ |
89
|
|
|
|
$good = 0; |
90
|
|
|
|
$log->error('cant add more that one annotation of the same context to the same group'); |
91
|
|
|
|
last; |
92
|
|
|
|
} |
93
|
|
|
|
} |
94
|
50
|
|
|
if($good){ |
95
|
|
|
|
push(@{$self->{_anno}},$a); |
96
|
|
|
|
} |
97
|
|
|
|
} else { |
98
|
|
|
|
push(@{$self->{_anno}},$a); |
99
|
|
|
|
} |
100
|
|
|
|
} |
101
|
|
|
|
|
102
|
|
|
|
sub getAllAnnotations { |
103
|
|
818
|
1
|
my $self = shift; |
104
|
50
|
|
|
if(defined($self->{_anno})){ |
105
|
|
|
|
return $self->{_anno}; |
106
|
|
|
|
} else { |
107
|
|
|
|
return undef; |
108
|
|
|
|
} |
109
|
|
|
|
} |
110
|
|
|
|
|
111
|
|
|
|
sub getAnnotationByContext { |
112
|
|
4154
|
1
|
my ($self,$ctx) = @_; |
113
|
|
|
|
foreach my $a(@{$self->{_anno}}){ |
114
|
100
|
|
|
return $a if($a->getContext eq $ctx); |
115
|
|
|
|
} |
116
|
|
|
|
return undef; |
117
|
|
|
|
} |
118
|
|
|
|
|
119
|
|
|
|
sub getLabel { |
120
|
|
818
|
1
|
return shift->{_label}; |
121
|
|
|
|
} |
122
|
|
|
|
|
123
|
|
|
|
sub getCCDS { |
124
|
|
818
|
1
|
return shift->{_ccds}; |
125
|
|
|
|
} |
126
|
|
|
|
|
127
|
|
|
|
sub getAccession { |
128
|
|
818
|
1
|
return shift->{_accession}; |
129
|
|
|
|
} |
130
|
|
|
|
|
131
|
|
|
|
sub getType { |
132
|
|
1636
|
1
|
return shift->{_type}; |
133
|
|
|
|
} |
134
|
|
|
|
|
135
|
|
|
|
sub addClassification { |
136
|
|
818
|
1
|
my ($self,@classes) = @_; |
137
|
|
|
|
foreach my $c (@classes){ |
138
|
50
|
|
|
if(defined($c)){ |
139
|
100
|
|
|
if(defined($self->getClassifications)){ |
140
|
50
|
2309
|
|
push(@{$self->{_class}},$c) unless(first {$_ eq $c} $self->getClassifications); |
141
|
|
|
|
} else { |
142
|
|
|
|
push(@{$self->{_class}},$c); |
143
|
|
|
|
} |
144
|
|
|
|
} |
145
|
|
|
|
} |
146
|
|
|
|
} |
147
|
|
|
|
|
148
|
|
|
|
sub getClassifications { |
149
|
|
6066
|
1
|
my ($self,$class) = @_; |
150
|
100
|
|
|
return @{$self->{_class}} if(exists $self->{_class} && defined $self->{_class}); |
151
|
|
|
|
return undef; |
152
|
|
|
|
} |
153
|
|
|
|
|
154
|
|
|
|
sub hasClassification { |
155
|
|
0
|
1
|
my ($self,$class) = @_; |
156
|
0
|
|
|
if(exists $self->{_class} && defined($self->{_class})){ |
157
|
0
|
0
|
|
if(first {$_ eq $class} @{$self->{_class}}){ |
158
|
|
|
|
return 1; |
159
|
|
|
|
} else { |
160
|
|
|
|
return 0; |
161
|
|
|
|
} |
162
|
|
|
|
} |
163
|
|
|
|
return 0; |
164
|
|
|
|
} |
165
|
|
|
|
|
166
|
|
|
|
sub addBookmark { |
167
|
|
0
|
1
|
my ($self,$marker) = @_; |
168
|
0
|
|
|
unless($marker->isa('Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker')){ |
169
|
|
|
|
my $msg = 'can only use Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker objects to mark an annotation group'; |
170
|
|
|
|
$log->error($msg); |
171
|
|
|
|
warn $msg; |
172
|
|
|
|
return; |
173
|
|
|
|
} |
174
|
|
|
|
$self->{_bookmarks}->{ref($marker)} = 1; |
175
|
|
|
|
} |
176
|
|
|
|
|
177
|
|
|
|
sub hasBookmark { |
178
|
|
0
|
1
|
my ($self,$marker) = @_; |
179
|
0
|
|
|
if(defined $marker){ |
180
|
0
|
|
|
unless($marker->isa('Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker')){ |
181
|
|
|
|
my $msg = 'can only use Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker objects to look for bookmarks'; |
182
|
|
|
|
$log->error($msg); |
183
|
|
|
|
warn $msg; |
184
|
|
|
|
return; |
185
|
|
|
|
} |
186
|
0
|
|
|
if(exists $self->{_bookmarks} && exists $self->{_bookmarks}->{ref($marker)} && $self->{_bookmarks}->{ref($marker)} == 1){ |
187
|
|
|
|
return 1; |
188
|
|
|
|
} |
189
|
|
|
|
} else { |
190
|
0
|
|
|
if(exists $self->{_bookmarks} && defined $self->{_bookmarks}){ |
191
|
|
|
|
return 1; |
192
|
|
|
|
} |
193
|
|
|
|
} |
194
|
|
|
|
return 0; |
195
|
|
|
|
} |
196
|
|
|
|
|
197
|
|
|
|
__END__ |
198
|
|
|
|
|
199
|
|
|
|
=head1 NAME |
200
|
|
|
|
|
201
|
|
|
|
Sanger::CGP::Vagrent::Data::AnnotationGroup - Object holding data about the effect of a single |
202
|
|
|
|
variation on a transcript. |
203
|
|
|
|
|
204
|
|
|
|
=head1 DESCRIPTION |
205
|
|
|
|
|
206
|
|
|
|
This holds information about a variation within a transcript along with a collection of |
207
|
|
|
|
L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> objects detailing the descriptions of that variation in |
208
|
|
|
|
different sequence contexts. |
209
|
|
|
|
|
210
|
|
|
|
=head1 METHODS |
211
|
|
|
|
|
212
|
|
|
|
=head2 Constructor |
213
|
|
|
|
|
214
|
|
|
|
=head3 new |
215
|
|
|
|
|
216
|
|
|
|
=over |
217
|
|
|
|
|
218
|
|
|
|
=item Usage : |
219
|
|
|
|
|
220
|
|
|
|
my $annoGrp = Sanger::CGP::Vagrent::Data::AnnotationGroup->new(%params); |
221
|
|
|
|
|
222
|
|
|
|
=item Function : |
223
|
|
|
|
|
224
|
|
|
|
Builds a new Sanger::CGP::Vagrent::Data::AnnotationGroup object |
225
|
|
|
|
|
226
|
|
|
|
=item Returns : |
227
|
|
|
|
|
228
|
|
|
|
L<Sanger::CGP::Vagrent::Data::AnnotationGroup|Sanger::CGP::Vagrent::Data::AnnotationGroup> object initialized with parameter values |
229
|
|
|
|
|
230
|
|
|
|
=item Params : |
231
|
|
|
|
|
232
|
|
|
|
accession => Accession for the transcript |
233
|
|
|
|
type => Gene type (defined by type constants in L<Sanger::CGP::Vagrent::Data::Transcript|Sanger::CGP::Vagrent::Data::Transcript>) |
234
|
|
|
|
label => text label for the transcript, typically the gene name |
235
|
|
|
|
ccds => CCDS reference number if the transcript has one |
236
|
|
|
|
|
237
|
|
|
|
=back |
238
|
|
|
|
|
239
|
|
|
|
=head2 Attributes |
240
|
|
|
|
|
241
|
|
|
|
=head3 addAnnotation |
242
|
|
|
|
|
243
|
|
|
|
=over |
244
|
|
|
|
|
245
|
|
|
|
=item Usage : |
246
|
|
|
|
|
247
|
|
|
|
$annoGrp->addAnnotation($anno); |
248
|
|
|
|
|
249
|
|
|
|
=item Function : |
250
|
|
|
|
|
251
|
|
|
|
Validates and adds a L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> object to the group. |
252
|
|
|
|
Only one annotation of each context can be added to a group |
253
|
|
|
|
|
254
|
|
|
|
=item Params : |
255
|
|
|
|
|
256
|
|
|
|
A L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> object |
257
|
|
|
|
|
258
|
|
|
|
=item Returns : |
259
|
|
|
|
|
260
|
|
|
|
None |
261
|
|
|
|
|
262
|
|
|
|
=back |
263
|
|
|
|
|
264
|
|
|
|
=head3 getAllAnnotations |
265
|
|
|
|
|
266
|
|
|
|
=over |
267
|
|
|
|
|
268
|
|
|
|
=item Usage : |
269
|
|
|
|
|
270
|
|
|
|
my $annoListRef = $annoGrp->getAllAnnotations; |
271
|
|
|
|
|
272
|
|
|
|
=item Function : |
273
|
|
|
|
|
274
|
|
|
|
Retrieves all annotations in the group |
275
|
|
|
|
|
276
|
|
|
|
=item Returns : |
277
|
|
|
|
|
278
|
|
|
|
Array ref of L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> objects, or undef |
279
|
|
|
|
|
280
|
|
|
|
=back |
281
|
|
|
|
|
282
|
|
|
|
=head3 getAnnotationByContext |
283
|
|
|
|
|
284
|
|
|
|
=over |
285
|
|
|
|
|
286
|
|
|
|
=item Usage : |
287
|
|
|
|
|
288
|
|
|
|
my $cdsAnno = $annoGrp->getAnnotationByContext(Sanger::CGP::Vagrent::Data::Annotation::getCDSAnnotationContext); |
289
|
|
|
|
|
290
|
|
|
|
=item Function : |
291
|
|
|
|
|
292
|
|
|
|
Retrieves annotation for the specified context |
293
|
|
|
|
|
294
|
|
|
|
=item Params : |
295
|
|
|
|
|
296
|
|
|
|
String - A context constant from L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> |
297
|
|
|
|
|
298
|
|
|
|
=item Returns : |
299
|
|
|
|
|
300
|
|
|
|
A L<Sanger::CGP::Vagrent::Data::Annotation|Sanger::CGP::Vagrent::Data::Annotation> object, or undef |
301
|
|
|
|
|
302
|
|
|
|
=back |
303
|
|
|
|
|
304
|
|
|
|
=head3 getLabel |
305
|
|
|
|
|
306
|
|
|
|
=over |
307
|
|
|
|
|
308
|
|
|
|
=item Usage : |
309
|
|
|
|
|
310
|
|
|
|
my $label = $grp->getLabel; |
311
|
|
|
|
|
312
|
|
|
|
=item Function : |
313
|
|
|
|
|
314
|
|
|
|
The label for the transcript (Gene name or similar) |
315
|
|
|
|
|
316
|
|
|
|
=item Returns : |
317
|
|
|
|
|
318
|
|
|
|
String or undef |
319
|
|
|
|
|
320
|
|
|
|
=back |
321
|
|
|
|
|
322
|
|
|
|
=head3 getCCDS |
323
|
|
|
|
|
324
|
|
|
|
=over |
325
|
|
|
|
|
326
|
|
|
|
=item Usage : |
327
|
|
|
|
|
328
|
|
|
|
my $ccds = $grp->getCCDS; |
329
|
|
|
|
|
330
|
|
|
|
=item Function : |
331
|
|
|
|
|
332
|
|
|
|
The CCDS reference number for the transcript |
333
|
|
|
|
|
334
|
|
|
|
=item Returns : |
335
|
|
|
|
|
336
|
|
|
|
String or undef |
337
|
|
|
|
|
338
|
|
|
|
=back |
339
|
|
|
|
|
340
|
|
|
|
=head3 getAccession |
341
|
|
|
|
|
342
|
|
|
|
=over |
343
|
|
|
|
|
344
|
|
|
|
=item Usage : |
345
|
|
|
|
|
346
|
|
|
|
my $acc = $grp->getAccession; |
347
|
|
|
|
|
348
|
|
|
|
=item Function : |
349
|
|
|
|
|
350
|
|
|
|
The accession number for the transcript |
351
|
|
|
|
|
352
|
|
|
|
=item Returns : |
353
|
|
|
|
|
354
|
|
|
|
String or undef |
355
|
|
|
|
|
356
|
|
|
|
=back |
357
|
|
|
|
|
358
|
|
|
|
=head3 getType |
359
|
|
|
|
|
360
|
|
|
|
=over |
361
|
|
|
|
|
362
|
|
|
|
=item Usage : |
363
|
|
|
|
|
364
|
|
|
|
my $type = $grp->getType; |
365
|
|
|
|
|
366
|
|
|
|
=item Function : |
367
|
|
|
|
|
368
|
|
|
|
Gene type (defined by type constants in L<Sanger::CGP::Vagrent::Data::Transcript|Sanger::CGP::Vagrent::Data::Transcript>) |
369
|
|
|
|
|
370
|
|
|
|
=item Returns : |
371
|
|
|
|
|
372
|
|
|
|
String - A type constant from L<Sanger::CGP::Vagrent::Data::Transcript|Sanger::CGP::Vagrent::Data::Transcript> |
373
|
|
|
|
|
374
|
|
|
|
=back |
375
|
|
|
|
|
376
|
|
|
|
=head3 addClassification |
377
|
|
|
|
|
378
|
|
|
|
=over |
379
|
|
|
|
|
380
|
|
|
|
=item Usage : |
381
|
|
|
|
|
382
|
|
|
|
$grp->addClassification($class1,$class2); |
383
|
|
|
|
|
384
|
|
|
|
=item Function |
385
|
|
|
|
|
386
|
|
|
|
Appends one or more classification terms to the annotation group |
387
|
|
|
|
|
388
|
|
|
|
=item Params |
389
|
|
|
|
|
390
|
|
|
|
An array of classification terms (Strings) |
391
|
|
|
|
|
392
|
|
|
|
=item Returns |
393
|
|
|
|
|
394
|
|
|
|
None |
395
|
|
|
|
|
396
|
|
|
|
=back |
397
|
|
|
|
|
398
|
|
|
|
=head3 getClassifications |
399
|
|
|
|
|
400
|
|
|
|
=over |
401
|
|
|
|
|
402
|
|
|
|
=item Usage : |
403
|
|
|
|
|
404
|
|
|
|
my @classes = $grp->getClassifications; |
405
|
|
|
|
|
406
|
|
|
|
=item Function |
407
|
|
|
|
|
408
|
|
|
|
Returns the stored classification terms |
409
|
|
|
|
|
410
|
|
|
|
=item Returns |
411
|
|
|
|
|
412
|
|
|
|
Array of Strings, or undef if none |
413
|
|
|
|
|
414
|
|
|
|
=back |
415
|
|
|
|
|
416
|
|
|
|
=head3 addBookmark |
417
|
|
|
|
|
418
|
|
|
|
=over |
419
|
|
|
|
|
420
|
|
|
|
=item Usage : |
421
|
|
|
|
|
422
|
|
|
|
$g->addBookmark($bookmarker); |
423
|
|
|
|
|
424
|
|
|
|
=item Function |
425
|
|
|
|
|
426
|
|
|
|
Adds a bookmark to the annotation group of a type defined by the supplied bookmarker |
427
|
|
|
|
|
428
|
|
|
|
=item Params |
429
|
|
|
|
|
430
|
|
|
|
A L<Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker|Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker> implementing object |
431
|
|
|
|
|
432
|
|
|
|
=item Returns |
433
|
|
|
|
|
434
|
|
|
|
None |
435
|
|
|
|
|
436
|
|
|
|
=back |
437
|
|
|
|
|
438
|
|
|
|
=head2 Functions |
439
|
|
|
|
|
440
|
|
|
|
=head3 hasClassification |
441
|
|
|
|
|
442
|
|
|
|
=over |
443
|
|
|
|
|
444
|
|
|
|
=item Usage : |
445
|
|
|
|
|
446
|
|
|
|
if($grp->hasClassification($checkClass)){ |
447
|
|
|
|
..... |
448
|
|
|
|
} |
449
|
|
|
|
|
450
|
|
|
|
=item Function |
451
|
|
|
|
|
452
|
|
|
|
Checks an annotation to see if it already contains the specified class |
453
|
|
|
|
|
454
|
|
|
|
=item Returns |
455
|
|
|
|
|
456
|
|
|
|
Boolean, 1 or 0 |
457
|
|
|
|
|
458
|
|
|
|
=back |
459
|
|
|
|
|
460
|
|
|
|
=head3 hasBookmark |
461
|
|
|
|
|
462
|
|
|
|
=over |
463
|
|
|
|
|
464
|
|
|
|
=item Usage : |
465
|
|
|
|
|
466
|
|
|
|
$g->hasBookmark; |
467
|
|
|
|
$g->hasBookmark($bookmarker); |
468
|
|
|
|
|
469
|
|
|
|
=item Function |
470
|
|
|
|
|
471
|
|
|
|
Returns true if the Annotation group has a bookmark, if a Bookmarker object is |
472
|
|
|
|
supplied it only returns true if that specific bookmark type is present |
473
|
|
|
|
|
474
|
|
|
|
=item Params |
475
|
|
|
|
|
476
|
|
|
|
(Optional) A L<Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker|Sanger::CGP::Vagrent::Bookmarkers::AbstractBookmarker> implementing object |
477
|
|
|
|
|
478
|
|
|
|
=item Returns |
479
|
|
|
|
|
480
|
|
|
|
Boolean, 1 or 0 |
481
|
|
|
|
|
482
|
|
|
|
=back |