ensembl-hive  2.7.0
WormbaseCElegansBase.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 use strict;
20 use warnings;
21 package XrefParser::WormbaseCElegansBase;
22 
23 sub swap_dependency {
24  my ($self, $source_ids, $dbi, $xref, @source_ids_skip) = @_;
25  $source_ids = [$source_ids] unless ref $source_ids eq 'ARRAY';
26 
27  my @matching_source_id_dependents;
28  my @other_dependents;
29  for my $dependent_xref (@{$xref->{DEPENDENT_XREFS} || []}){
30  my $source_id_here = $dependent_xref->{SOURCE_ID};
31  if(grep {$_ == $source_id_here } @$source_ids
32  and $self->get_xref($dependent_xref->{ACCESSION}, $dependent_xref->{SOURCE_ID}, $xref->{SPECIES_ID})){
33  $dependent_xref->{SPECIES_ID} = $xref->{SPECIES_ID};
34  push @matching_source_id_dependents, $dependent_xref;
35  } elsif (grep {$_ == $source_id_here} @source_ids_skip){
36  #skip
37  } else {
38  push @other_dependents, $dependent_xref;
39  }
40  }
41  my @result;
42  for my $matching_source_id_dependent (@matching_source_id_dependents) {
43  my $source_id = $matching_source_id_dependent->{SOURCE_ID};
44  my $xref_as_dependent_here = {
45  %$xref, INFO_TYPE => "DEPENDENT",
46  LINKAGE_SOURCE_ID => $source_id,
47  DEPENDENT_XREFS => undef,
48  };
49  my @dependents_here = ({
50  %$xref, INFO_TYPE => "DEPENDENT",
51  LINKAGE_SOURCE_ID => $source_id,
52  DEPENDENT_XREFS => undef,
53  });
54  for my $d (@other_dependents){
55  push @dependents_here, {
56  %$d, INFO_TYPE => "DEPENDENT", LINKAGE_SOURCE_ID => $source_id,
57  };
58  }
59  push @result, {
60  %$matching_source_id_dependent,
61  LABEL=>undef, INFO_TYPE => "MISC",
62  DEPENDENT_XREFS =>\@dependents_here,
63  };
64  }
65 
66  return @result;
67 }
68 1;