ensembl-hive  2.8.1
OntologyXref.pm
Go to the documentation of this file.
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 
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 
76 use strict;
77 use warnings;
78 
79 use base qw( Bio::EnsEMBL::DBEntry );
80 
82 
83 =head2 get_OntologyTerm
84 
85  Example : $ontology_xref->get_OntologyTerm();
86  Description: Queries the OntologyTermAdaptor for a term which is the same
87  as the primary id of this object. This method requires a
88  OntologyDBAdaptor to be available in the Bio::EnsEMBL::Registry.
89  If you have loaded data from an Ensembl release using
91  work.
92  Returntype : Bio::EnsEMBL::OntologyTerm
93  Exceptions : None
94  Caller : general
95  Status : Experimantal
96 
97 =cut
98 
99 
100 sub get_OntologyTerm {
101  my ($self) = @_;
102  my $dbas = Bio::EnsEMBL::Registry->get_all_DBAdaptors(-GROUP => 'ontology');
103  foreach my $ontology_dba (@{$dbas}) {
104  my $ota = $ontology_dba->get_OntologyTermAdaptor();
105  my $term = $ota->fetch_by_accession($self->primary_id());
106  return $term if $term;
107  }
108  return;
109 }
110 
111 =head2 add_linkage_type
112 
113  Arg [1] : string $value
114  allowed values:
115  'IC', 'IDA', 'IEA', 'IEP', 'IGI', 'IMP', 'IPI',
116  'ISS', NAS', 'ND', 'TAS', 'NR', 'RCA'
117  Arg [2] : (optional) Bio::EnsEMBL::DBEntry $source
118  Example : $ontology_xref->add_linkage_type('IGI');
119  Description: Associates a linkage type and source DBEntry with
120  this ontology_xref
121  Returntype : integer; number of linkages
122  Exceptions : thrown if $linkage_type argument not supplied or
123  the optional DBEntry is not a DBEntry object.
124  Caller : DBEntryAdaptor
125  Status : Experimantal
126 
127 =cut
128 
129 sub add_linkage_type {
130  my ( $self, $lt, $source_dbentry ) = @_;
131 
132  if ( !defined($lt) ) {
133  $self->throw("linkage type argument required");
134  }
135 
136  if ( defined($source_dbentry)
137  && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
138  {
139  $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
140  }
141 
142  $self->{'linkage_types'} ||= [];
143 
144  push @{ $self->{'linkage_types'} },
145  [ $lt, ( $source_dbentry || () ) ];
146 }
147 
148 
149 =head2 get_all_linkage_info
150 
151  Arg [1] : none
152  Example :
153 
154  foreach ( @{ $ontology_xref->get_all_linkage_info() } ) {
155  print "evidence: $_->[0] via $_->[1]->display_id";
156  }
157 
158  Description: Retrieves a list of evidence-tag/source-DBEntry pairs
159  associated with this ontology_xref
160  Returntype : listref of listrefs
161  Exceptions : none
162  Caller : geneview? general.
163  Status : Experimental
164 
165 =cut
166 
167 sub get_all_linkage_info {
168  my ($self) = @_;
169 
170  return $self->{'linkage_types'} || [];
171 }
172 
173 
174 =head2 get_all_linkage_types
175 
176  Arg [1] : none
177  Example :
178 
179  print( join( ' ', @{ $ontology_xref->get_all_linkage_types() } ),
180  "\n" );
181 
182  Description: Retrieves a unique list of evidence tags associated with
183  this ontology_xref
184  Returntype : none
185  Exceptions : none
186  Caller : geneview? general
187  Status : Stable
188 
189 =cut
190 
191 sub get_all_linkage_types {
192  my ($self) = @_;
193 
194  my %seen;
195  return [ grep { !$seen{$_}++ }
196  map { $_->[0] } @{ $self->{'linkage_types'} } ];
197 
198  #return [ map{ $_->[0]} @{ $self->{'linkage_types'} || [] } ];
199 }
200 
201 
202 =head2 flush_linkage_types
203 
204  Arg [1] : none
205  Example : $ontology_xref->flush_linkage_types();
206  Description: Removes any associated evidence tags
207  Returntype : none
208  Exceptions : none
209  Caller : general
210  Status : Stable
211 
212 =cut
213 
214 sub flush_linkage_types {
215  my ($self) = @_;
216 
217  $self->{'linkage_types'} = [];
218 }
219 
220 
221 =head2 add_associated_xref
222 
223  Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
224  or an Array of Bio::EnsEMBL::DBEntry for compound annotations
225  Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
226  Arg [3] : string $condition_type or an Array of string $condition_types
227  matching the order of Arg[1] for compound queries.
228  Arg [4] : (optional) Integer $group id for compound annotations.
229  Arg [5] : (optional) Integer $rank order for a term within a compound annotation.
230  Example : $ontology_xref->add_associated_xref(
231  $associated_xref,
232  $source_dbentry,
233  'with',
234  42,
235  5);
236  Description: Associates a linkage type and source DBEntry with
237  this ontology_xref
238  Returntype : none
239  Exceptions : thrown if $linkage_type argument not supplied or
240  the optional DBEntry is not a DBEntry object.
241  Caller : DBEntryAdaptor
242  Status : Experimantal
243 
244 =cut
245 
246 sub add_associated_xref {
247  my ( $self, $associated_xref, $source_dbentry, $condition_type, $group, $rank ) = @_;
248  if ( ref($associated_xref) eq 'ARRAY' )
249  {
250  foreach my $e ( @{ $associated_xref } ) {
251  if ( !$e->isa('Bio::EnsEMBL::DBEntry') ) {
252  $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an
253  Array of Bio::EnsEMBL::DBEntry objects.");
254  }
255  }
256  } elsif ( defined($associated_xref)
257  && !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
258  {
259  $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
260  of Bio::EnsEMBL::DBEntry objects.");
261  }
262 
263  if ( defined($source_dbentry)
264  && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
265  {
266  $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
267  }
268 
269  if ( !defined $condition_type ) {
270  $self->throw("condition must be a string");
271  }
272 
273  if (!defined $group) {
274  $group = 1 + scalar keys %{ $self->{'associated_xref'} };
275  }
276 
277  if (!defined $rank) {
278  #$rank = 0;
279  $rank = 1 + scalar keys %{ $self->{'associated_xref'}->{ $group } };
280  }
281 
282  $self->{'associated_xref'} ||= {};
283 
284  $self->{'associated_xref'}->{ $group }->{$rank} =
285  [ $associated_xref, $source_dbentry, $condition_type ];
286 }
287 
288 
289 =head2 add_linked_associated_xref
290 
291  Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
292  or an Array of Bio::EnsEMBL::DBEntry for compound annotations
293  Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
294  Arg [3] : string $condition_type or an Array of string $condition_types
295  matching the order of Arg[1] for compound queries.
296  Arg [4] : Integer $group id.
297  Arg [5] : Integer $rank id.
298  Example : $ontology_xref->add_associated_xref(
299  $associated_xref,
300  $source_dbentry,
301  'with',
302  42,
303  5);
304  Description: Associates a linkage type and source DBEntry with this
305  ontology_xref that have come from the same annotation source
306  Returntype : none
307  Exceptions : thrown if $linkage_type argument not supplied or
308  the optional DBEntry is not a DBEntry object.
309  Caller : DBEntryAdaptor
310  Status : Experimantal
311 
312 =cut
313 
314 sub add_linked_associated_xref {
315  my ( $self, $associated_xref, $source_dbentry, $condition_type, $associate_group_id, $associate_group_rank ) = @_;
316 
317  if ( !defined($associated_xref) )
318  {
319  $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
320  of Bio::EnsEMBL::DBEntry objects.");
321  }
322 
323  if ( defined($associated_xref)
324  && !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
325  {
326  $self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
327  of Bio::EnsEMBL::DBEntry objects.");
328  }
329 
330  if ( defined($source_dbentry)
331  && !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
332  {
333  $self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
334  }
335 
336  if ( !defined $condition_type ) {
337  $self->throw("condition must be a string");
338  }
339 
340  if ( !defined $associate_group_id )
341  {
342  $self->throw("$associate_group_id must be an integer");
343  }
344 
345  if ( !defined $associate_group_rank )
346  {
347  $self->throw("$associate_group_rank must be an integer");
348  }
349 
350 # print "\t" . $associate_group_id;
351 # print "\t" . $associate_group_rank;
352 # print "\t|" . defined($associated_xref) . '|';
353 # #print "\t" . defined($associated_xref->primary_id);
354 # print "\t" . $associated_xref->primary_id;# . ' (' . $associated_xref->display_id . ')';
355 # print "\t" . $source_dbentry->primary_id;
356 # print "\t" . $condition_type . "\n";
357 
358  my $associated_xref_array = {};
359  my $matching_link = 0;
360 
361  my $load_postion = 0;
362  if ( !defined $self->{'associated_xref'} ) {
363  $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
364  $associated_xref,
365  $source_dbentry,
366  $condition_type
367  ];
368  $load_postion = 1;
369  } else {
370  $associated_xref_array = $self->{'associated_xref'};
371 
372  if (!defined $associated_xref_array->{$associate_group_id} ) {
373  $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
374  $associated_xref,
375  $source_dbentry,
376  $condition_type
377  ];
378  $load_postion = 2;
379  } else {
380  my $already_loaded = 0;
381  foreach my $rank ( keys %{$associated_xref_array->{$associate_group_id}} ) {
382  my @ax_gr_set = @{ $associated_xref_array->{$associate_group_id}->{$rank} };
383  if (
384  $ax_gr_set[0]->primary_id eq $associated_xref->primary_id &&
385  $ax_gr_set[1]->primary_id eq $source_dbentry->primary_id &&
386  $ax_gr_set[2] eq $condition_type
387  ) {
388  $already_loaded = 1;
389  $load_postion = 4;
390  #last;
391  }
392  }
393  if ( !$already_loaded ) {
394  if (!defined $associated_xref_array->{$associate_group_id}->{$associate_group_rank} ) {
395  $associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
396  $associated_xref,
397  $source_dbentry,
398  $condition_type
399  ];
400  $load_postion = 5;
401  } else {
402  $associated_xref_array->{$associate_group_id}->{scalar keys %{ $associated_xref_array->{$associate_group_id} }} = [
403  $associated_xref,
404  $source_dbentry,
405  $condition_type
406  ];
407  $load_postion = 3;
408  }
409  }
410  }
411  }
412  $self->{'associated_xref'} = $associated_xref_array;
413 # print "\t\tLoaded at " . $load_postion . "\n";
414 # if ($associate_group_id == 28792 || $associate_group_id == 28793) {
415 # print Data::Dumper->Dumper([$self->{'associated_xref'}]);
416 # }
417 }
418 
419 
420 =head2 get_all_associated_xrefs
421 
422  Arg [1] : none
423  Example :
424 
425  foreach ( @{ $ontology_xref->get_all_associated_xref() } ) {
426  print "evidence: $_->[0] via $_->[1]->display_id";
427  }
428 
429  Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
430  sets associated with this ontology_xref
431  Returntype : listref of listrefs
432  Exceptions : none
433  Caller : geneview? general.
434  Status : Experimental
435 
436 =cut
437 
438 sub get_all_associated_xrefs {
439  my ($self) = @_;
440 
441  return $self->{'associated_xref'} || {};
442 }
443 
444 =head2 get_extensions
445  Arg [1] : none
446  Example :
447 
448  use Data::Dumper;
449  print Dumper @{ $ontology_xref->get_extensions_for_web() }
450 
451  Returns :
452  $VAR1 = {
453  'source' => '<a href="<Link to CiteXplore>">11937031</a>',
454  'evidence' => 'IDA',
455  'description' => '<strong>has_direct_input</strong>
456  <a href="http://www.pombase.org/gene/SPBC32F12.09">
457  SPBC32F12.09
458  </a>'
459  };
460 
461  Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
462  sets associated with this ontology_xref and formats them ready
463  for web display in a group per row fashion.
464  The accessions for ontologies are linkable. Extra links need to
465  be added for each distinct database that is reference.
466  Returntype : listref of hashrefs
467  Exceptions : none
468  Caller :
469  Status : Experimental
470 =cut
471 sub get_extensions {
472  my ($self) = @_;
473 
474  if ( !defined $self->{'associated_xref'} ) {
475  return [];
476  }
477 
478  my @annotExtRows = ();
479 
480  my %external_urls = (
481  'GO' => 'http://www.ebi.ac.uk/ego/GTerm?id=',
482  'GO_REF' => 'http://www.geneontology.org/cgi-bin/references.cgi#',
483  'SO' => 'http://www.sequenceontology.org/miso/current_cvs/term/',
484  #'MOD' => 'href=mod',
485  'PomBase' => 'http://www.pombase.org/gene/',
486  'PomBase_Systematic_ID' => 'http://www.pombase.org/gene/',
487  'PUBMED' => 'http://europepmc.org/abstract/MED/'
488  );
489 
490  foreach my $groupId (keys %{ $self->{'associated_xref'} } ) {
491  my $description = '';
492  my $evidence = '';
493  my $source = '';
494 
495  foreach my $rank ( keys %{ $self->{'associated_xref'}->{$groupId} } ) {
496  if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[2]
497  eq 'evidence' ) {
498  if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
499  $evidence = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
500  . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
501  . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
502  . '</a>';
503  } else {
504  $evidence = $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
505  }
506  } else {
507  if (length $description > 0) {
508  $description .= ', ';
509  }
510  $description .= '<strong>' . $self->{'associated_xref'}->{$groupId}->{$rank}->[2] . '</strong> ';
511 
512  if (exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
513  $description .= '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
514  . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
515  . $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
516  . '</a>';
517  } else {
518  $description .= $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
519  }
520 
521 
522  }
523 
524  if ( !undef $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]} ) {
525  if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname} ) {
526  $source = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname}
527  . $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->primary_id . '">';
528  if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname ne 'GO_REF' ) {
529  $source .= 'PMC:';
530  }
531  $source .= $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id . '</a>';
532  } elsif ($self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id eq 'PMPB:0') {
533  $source = '';
534  } else {
535  $source = $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id;
536  }
537  }
538  }
539 
540  if ($evidence ne '' and $description ne '') {
541  my %row = ('description' => $description,
542  'evidence' => $evidence,
543  'source' => $source);
544  push @annotExtRows, (\%row);
545  }
546  }
547 
548  return \@annotExtRows;
549 }
550 
551 1;
EnsEMBL
Definition: Filter.pm:1
Bio::EnsEMBL::Registry
Definition: Registry.pm:113
Bio::EnsEMBL::OntologyXref
Definition: OntologyXref.pm:41
Bio::EnsEMBL::Registry::load_registry_from_db
public Int load_registry_from_db()
Bio::EnsEMBL::DBEntry
Definition: DBEntry.pm:12
Bio::EnsEMBL::DBEntry::dbname
public String dbname()
Bio::EnsEMBL::Registry::get_all_DBAdaptors
public List get_all_DBAdaptors()
Bio::EnsEMBL::OntologyTerm
Definition: OntologyTerm.pm:10