EnsEMBL/OntologyXref.pm untested

filter: Statementstmt 0.0% 0 / 141 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 35 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 260 CC 32 SCAR 45.0
CC
32
Cov
0%
add_linked_associated_xref
156.0
get_extensions
132.0
add_associated_xref
72.0
CRAP 90.1
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::OntologyXref
34  
35 =head1 DESCRIPTION
36  
37 This class extends the DBEntry in order to associate Evidence Tags
38 to the relationship between EnsEMBL objects and ontology accessions
39 (primarily GO accessions).
40  
41 The relationship to GO that is stored in the database is actually
42 derived through the relationship of EnsEMBL peptides to SwissProt
43 peptides, i.e. the relationship is derived like this:
44  
45 ENSP -> SWISSPROT -> GO
46  
47 And the evidence tag describes the relationship between the SwissProt
48 Peptide and the GO entry.
49  
50 In reality, however, we store this in the database like this:
51  
52 ENSP -> SWISSPROT
53 ENSP -> GO
54  
55 and the evidence tag hangs off of the relationship between the ENSP and
56 the GO identifier. Some ENSPs are associated with multiple closely
57 related Swissprot entries which may both be associated with the same GO
58 identifier but with different evidence tags. For this reason a single
59 'OntologyXref' can have multiple evidence tags.
60  
61 =head1 SYNOPSIS
62  
63 my $ontology_xref = Bio::EnsEMBL::OntologyXref->new();
64 $ontology_xref->add_linkage_type('IEA');
65  
66 foreach my $evtag ( @{ $ontology_xref->get_all_linkage_types() } ) {
67 print "$evtag\n";
68 }
69  
70 =head1 METHODS
71  
72 =cut
73  
74 package Bio::EnsEMBL::OntologyXref;
75 $Bio::EnsEMBL::OntologyXref::VERSION = '114.0.0_50'; # TRIAL
76 $Bio::EnsEMBL::OntologyXref::VERSION = '114.0.050';
77 use strict;
78 use warnings;
79  
80 use base qw( Bio::EnsEMBL::DBEntry );
81  
82 require Bio::EnsEMBL::Registry;
83  
84 =head2 get_OntologyTerm
85  
86 Example : $ontology_xref->get_OntologyTerm();
87 Description: Queries the OntologyTermAdaptor for a term which is the same
88 as the primary id of this object. This method requires a
89 OntologyDBAdaptor to be available in the Bio::EnsEMBL::Registry.
90 If you have loaded data from an Ensembl release using
91 Bio::EnsEMBL::Registry->load_registry_from_db() then this should
92 work.
93 Returntype : Bio::EnsEMBL::OntologyTerm
94 Exceptions : None
95 Caller : general
96 Status : Experimantal
97  
98 =cut
99  
100  
101 sub get_OntologyTerm {
102 my ($self) = @_;
103 my $dbas = Bio::EnsEMBL::Registry->get_all_DBAdaptors(-GROUP => 'ontology');
104 foreach my $ontology_dba (@{$dbas}) {
105 my $ota = $ontology_dba->get_OntologyTermAdaptor();
106 my $term = $ota->fetch_by_accession($self->primary_id());
107 return $term if $term;
108 }
109 return;
110 }
111  
112 =head2 add_linkage_type
113  
114 Arg [1] : string $value
115 allowed values:
116 'IC', 'IDA', 'IEA', 'IEP', 'IGI', 'IMP', 'IPI',
117 'ISS', NAS', 'ND', 'TAS', 'NR', 'RCA'
118 Arg [2] : (optional) Bio::EnsEMBL::DBEntry $source
119 Example : $ontology_xref->add_linkage_type('IGI');
120 Description: Associates a linkage type and source DBEntry with
121 this ontology_xref
122 Returntype : integer; number of linkages
123 Exceptions : thrown if $linkage_type argument not supplied or
124 the optional DBEntry is not a DBEntry object.
125 Caller : DBEntryAdaptor
126 Status : Experimantal
127  
128 =cut
129  
130 sub add_linkage_type {
131 my ( $self, $lt, $source_dbentry ) = @_;
132  
133 if ( !defined($lt) ) {
134 $self->throw("linkage type argument required");
135 }
136  
137 if ( defined($source_dbentry)
138 && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
139 {
140 $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
141 }
142  
143 $self->{'linkage_types'} ||= [];
144  
145 push @{ $self->{'linkage_types'} },
146 [ $lt, ( $source_dbentry || () ) ];
147 }
148  
149  
150 =head2 get_all_linkage_info
151  
152 Arg [1] : none
153 Example :
154  
155 foreach ( @{ $ontology_xref->get_all_linkage_info() } ) {
156 print "evidence: $_->[0] via $_->[1]->display_id";
157 }
158  
159 Description: Retrieves a list of evidence-tag/source-DBEntry pairs
160 associated with this ontology_xref
161 Returntype : listref of listrefs
162 Exceptions : none
163 Caller : geneview? general.
164 Status : Experimental
165  
166 =cut
167  
168 sub get_all_linkage_info {
169 my ($self) = @_;
170  
171 return $self->{'linkage_types'} || [];
172 }
173  
174  
175 =head2 get_all_linkage_types
176  
177 Arg [1] : none
178 Example :
179  
180 print( join( ' ', @{ $ontology_xref->get_all_linkage_types() } ),
181 "\n" );
182  
183 Description: Retrieves a unique list of evidence tags associated with
184 this ontology_xref
185 Returntype : none
186 Exceptions : none
187 Caller : geneview? general
188 Status : Stable
189  
190 =cut
191  
192 sub get_all_linkage_types {
193 my ($self) = @_;
194  
195 my %seen;
196 return [ grep { !$seen{$_}++ }
197 map { $_->[0] } @{ $self->{'linkage_types'} } ];
198  
199 #return [ map{ $_->[0]} @{ $self->{'linkage_types'} || [] } ];
200 }
201  
202  
203 =head2 flush_linkage_types
204  
205 Arg [1] : none
206 Example : $ontology_xref->flush_linkage_types();
207 Description: Removes any associated evidence tags
208 Returntype : none
209 Exceptions : none
210 Caller : general
211 Status : Stable
212  
213 =cut
214  
215 sub flush_linkage_types {
216 my ($self) = @_;
217  
218 $self->{'linkage_types'} = [];
219 }
220  
221  
222 =head2 add_associated_xref
223  
224 Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
225 or an Array of Bio::EnsEMBL::DBEntry for compound annotations
226 Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
227 Arg [3] : string $condition_type or an Array of string $condition_types
228 matching the order of Arg[1] for compound queries.
229 Arg [4] : (optional) Integer $group id for compound annotations.
230 Arg [5] : (optional) Integer $rank order for a term within a compound annotation.
231 Example : $ontology_xref->add_associated_xref(
232 $associated_xref,
233 $source_dbentry,
234 'with',
235 42,
236 5);
237 Description: Associates a linkage type and source DBEntry with
238 this ontology_xref
239 Returntype : none
240 Exceptions : thrown if $linkage_type argument not supplied or
241 the optional DBEntry is not a DBEntry object.
242 Caller : DBEntryAdaptor
243 Status : Experimantal
244  
245 =cut
246  
247 sub add_associated_xref {
248 my ( $self, $associated_xref, $source_dbentry, $condition_type, $group, $rank ) = @_;
249 if ( ref($associated_xref) eq 'ARRAY' )
250 {
251 foreach my $e ( @{ $associated_xref } ) {
252 if ( !$e->isa('Bio::EnsEMBL::DBEntry') ) {
253 $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an
254 Array of Bio::EnsEMBL::DBEntry objects.");
255 }
256 }
257 } elsif ( defined($associated_xref)
258 && !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
259 {
260 $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
261 of Bio::EnsEMBL::DBEntry objects.");
262 }
263
264 if ( defined($source_dbentry)
265 && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
266 {
267 $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
268 }
269
270 if ( !defined $condition_type ) {
271 $self->throw("condition must be a string");
272 }
273
274 if (!defined $group) {
275 $group = 1 + scalar keys %{ $self->{'associated_xref'} };
276 }
277
278 if (!defined $rank) {
279 #$rank = 0;
280 $rank = 1 + scalar keys %{ $self->{'associated_xref'}->{ $group } };
281 }
282  
283 $self->{'associated_xref'} ||= {};
284  
285 $self->{'associated_xref'}->{ $group }->{$rank} =
286 [ $associated_xref, $source_dbentry, $condition_type ];
287 }
288  
289  
290 =head2 add_linked_associated_xref
291  
292 Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
293 or an Array of Bio::EnsEMBL::DBEntry for compound annotations
294 Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
295 Arg [3] : string $condition_type or an Array of string $condition_types
296 matching the order of Arg[1] for compound queries.
297 Arg [4] : Integer $group id.
298 Arg [5] : Integer $rank id.
299 Example : $ontology_xref->add_associated_xref(
300 $associated_xref,
301 $source_dbentry,
302 'with',
303 42,
304 5);
305 Description: Associates a linkage type and source DBEntry with this
306 ontology_xref that have come from the same annotation source
307 Returntype : none
308 Exceptions : thrown if $linkage_type argument not supplied or
309 the optional DBEntry is not a DBEntry object.
310 Caller : DBEntryAdaptor
311 Status : Experimantal
312  
313 =cut
314  
315 sub add_linked_associated_xref {
316 my ( $self, $associated_xref, $source_dbentry, $condition_type, $associate_group_id, $associate_group_rank ) = @_;
317
318 if ( !defined($associated_xref) )
319 {
320 $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
321 of Bio::EnsEMBL::DBEntry objects.");
322 }
323
324 if ( defined($associated_xref)
325 && !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
326 {
327 $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
328 of Bio::EnsEMBL::DBEntry objects.");
329 }
330
331 if ( defined($source_dbentry)
332 && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
333 {
334 $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
335 }
336
337 if ( !defined $condition_type ) {
338 $self->throw("condition must be a string");
339 }
340
341 if ( !defined $associate_group_id )
342 {
343 $self->throw("$associate_group_id must be an integer");
344 }
345
346 if ( !defined $associate_group_rank )
347 {
348 $self->throw("$associate_group_rank must be an integer");
349 }
350
351 # print "\t" . $associate_group_id;
352 # print "\t" . $associate_group_rank;
353 # print "\t|" . defined($associated_xref) . '|';
354 # #print "\t" . defined($associated_xref->primary_id);
355 # print "\t" . $associated_xref->primary_id;# . ' (' . $associated_xref->display_id . ')';
356 # print "\t" . $source_dbentry->primary_id;
357 # print "\t" . $condition_type . "\n";
358
359 my $associated_xref_array = {};
360 my $matching_link = 0;
361
362 my $load_postion = 0;
363 if ( !defined $self->{'associated_xref'} ) {
364 $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
365 $associated_xref,
366 $source_dbentry,
367 $condition_type
368 ];
369 $load_postion = 1;
370 } else {
371 $associated_xref_array = $self->{'associated_xref'};
372
373 if (!defined $associated_xref_array->{$associate_group_id} ) {
374 $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
375 $associated_xref,
376 $source_dbentry,
377 $condition_type
378 ];
379 $load_postion = 2;
380 } else {
381 my $already_loaded = 0;
382 foreach my $rank ( keys %{$associated_xref_array->{$associate_group_id}} ) {
383 my @ax_gr_set = @{ $associated_xref_array->{$associate_group_id}->{$rank} };
384 if (
385 $ax_gr_set[0]->primary_id eq $associated_xref->primary_id &&
386 $ax_gr_set[1]->primary_id eq $source_dbentry->primary_id &&
387 $ax_gr_set[2] eq $condition_type
388 ) {
389 $already_loaded = 1;
390 $load_postion = 4;
391 #last;
392 }
393 }
394 if ( !$already_loaded ) {
395 if (!defined $associated_xref_array->{$associate_group_id}->{$associate_group_rank} ) {
396 $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
397 $associated_xref,
398 $source_dbentry,
399 $condition_type
400 ];
401 $load_postion = 5;
402 } else {
403 $associated_xref_array->{$associate_group_id}->{scalar keys %{ $associated_xref_array->{$associate_group_id} }} = [
404 $associated_xref,
405 $source_dbentry,
406 $condition_type
407 ];
408 $load_postion = 3;
409 }
410 }
411 }
412 }
413 $self->{'associated_xref'} = $associated_xref_array;
414 # print "\t\tLoaded at " . $load_postion . "\n";
415 # if ($associate_group_id == 28792 || $associate_group_id == 28793) {
416 # print Data::Dumper->Dumper([$self->{'associated_xref'}]);
417 # }
418 }
419  
420  
421 =head2 get_all_associated_xrefs
422  
423 Arg [1] : none
424 Example :
425  
426 foreach ( @{ $ontology_xref->get_all_associated_xref() } ) {
427 print "evidence: $_->[0] via $_->[1]->display_id";
428 }
429  
430 Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
431 sets associated with this ontology_xref
432 Returntype : listref of listrefs
433 Exceptions : none
434 Caller : geneview? general.
435 Status : Experimental
436  
437 =cut
438  
439 sub get_all_associated_xrefs {
440 my ($self) = @_;
441  
442 return $self->{'associated_xref'} || {};
443 }
444  
445 =head2 get_extensions
446 Arg [1] : none
447 Example :
448  
449 use Data::Dumper;
450 print Dumper @{ $ontology_xref->get_extensions_for_web() }
451
452 Returns :
453 $VAR1 = {
454 'source' => '<a href="<Link to CiteXplore>">11937031</a>',
455 'evidence' => 'IDA',
456 'description' => '<strong>has_direct_input</strong>
457 <a href="http://www.pombase.org/gene/SPBC32F12.09">
458 SPBC32F12.09
459 </a>'
460 };
461  
462 Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
463 sets associated with this ontology_xref and formats them ready
464 for web display in a group per row fashion.
465 The accessions for ontologies are linkable. Extra links need to
466 be added for each distinct database that is reference.
467 Returntype : listref of hashrefs
468 Exceptions : none
469 Caller :
470 Status : Experimental
471 =cut
472 sub get_extensions {
473 my ($self) = @_;
474
475 if ( !defined $self->{'associated_xref'} ) {
476 return [];
477 }
478
479 my @annotExtRows = ();
480
481 my %external_urls = (
482 'GO' => 'http://www.ebi.ac.uk/ego/GTerm?id=',
483 'GO_REF' => 'http://www.geneontology.org/cgi-bin/references.cgi#',
484 'SO' => 'http://www.sequenceontology.org/miso/current_cvs/term/',
485 #'MOD' => 'href=mod',
486 'PomBase' => 'http://www.pombase.org/gene/',
487 'PomBase_Systematic_ID' => 'http://www.pombase.org/gene/',
488 'PUBMED' => 'http://europepmc.org/abstract/MED/'
489 );
490
491 foreach my $groupId (keys %{ $self->{'associated_xref'} } ) {
492 my $description = '';
493 my $evidence = '';
494 my $source = '';
495
496 foreach my $rank ( keys %{ $self->{'associated_xref'}->{$groupId} } ) {
497 if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[2]
498 eq 'evidence' ) {
499 if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
500 $evidence = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
501 . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
502 . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
503 . '</a>';
504 } else {
505 $evidence = $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
506 }
507 } else {
508 if (length $description > 0) {
509 $description .= ', ';
510 }
511 $description .= '<strong>' . $self->{'associated_xref'}->{$groupId}->{$rank}->[2] . '</strong> ';
512
513 if (exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
514 $description .= '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
515 . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
516 . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
517 . '</a>';
518 } else {
519 $description .= $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
520 }
521
522
523 }
524
525 if ( !undef $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]} ) {
526 if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname} ) {
527 $source = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname}
528 . $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->primary_id . '">';
529 if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname ne 'GO_REF' ) {
530 $source .= 'PMC:';
531 }
532 $source .= $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id . '</a>';
533 } elsif ($self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id eq 'PMPB:0') {
534 $source = '';
535 } else {
536 $source = $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id;
537 }
538 }
539 }
540
541 if ($evidence ne '' and $description ne '') {
542 my %row = ('description' => $description,
543 'evidence' => $evidence,
544 'source' => $source);
545 push @annotExtRows, (\%row);
546 }
547 }
548
549 return \@annotExtRows;
550 }
551  
552 1;