3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
20 package XrefMapper::DirectXrefs;
36 my($class, $mapper) = @_;
40 $self->
core($mapper->core);
41 $self->xref($mapper->xref);
42 $self->verbose($mapper->verbose);
51 INSERT IGNORE INTO identity_xref (object_xref_id, query_identity, target_identity)
54 my $sth = $dbi->prepare($sql);
62 # Now process the direct xrefs and add data to the object xrefs remember dependent xrefs.
65 my $dbi = $self->xref->
dbc;
67 # First get the sths needed for the processing of the direct xrefs;
68 my $ins_ox_sql = (<<
"IOS");
69 INSERT INTO object_xref (ensembl_id, xref_id, ensembl_object_type, linkage_type)
72 my $ins_ox_sth = $dbi->prepare($ins_ox_sql);
73 my $get_object_xref_id_sth = $self->get_ox_id_sth($dbi);
75 # Direct xrefs can be considered to be 100% matching
77 my $ins_ix_sth = $self->get_ins_ix_sth($dbi);
79 my $stable_sql=(<<
"SQL");
80 SELECT so.name, dx.general_xref_id, s.internal_id, dx.ensembl_stable_id , dx.linkage_xref
81 FROM source so, xref x, TYPE_direct_xref dx left join TYPE_stable_id s on s.stable_id = dx.ensembl_stable_id
82 WHERE x.xref_id = dx.general_xref_id and x.source_id = so.source_id
87 # We want to process the errors ourselves as for greater control
88 # If we get a error adding an object xref then it is already there
89 # This is not a problem. But we want to know how amny of these there were.
91 local $ins_ox_sth->{RaiseError} = 0; # want to see duplicates and not add de
92 local $ins_ox_sth->{PrintError} = 0;
96 foreach my $table (qw(gene
transcript translation)){
97 my ($dbname, $xref_id, $internal_id, $stable_id, $linkage_type);
98 my $sql = $stable_sql;
99 $sql =~ s/TYPE/$table/g;
100 my $sth = $dbi->prepare($sql);
102 $sth->bind_columns(\$dbname, \$xref_id, \$internal_id, \$stable_id, \$linkage_type);
104 my $duplicate_direct_count = 0;
105 my $duplicate_dependent_count = 0;
107 if(!defined($internal_id)){ # not found either it is an
internal id already or stable_id no longer exists
108 if($stable_id =~ /^\d+$/){
109 $internal_id = $stable_id;
112 if((!defined($err_count{$dbname})) or ($err_count{$dbname} < 10)){
113 print
"Could not find stable id $stable_id in table to get the internal id hence ignoring!!! (for $dbname)\n" if($self->verbose);
115 $err_count{$dbname}++;
122 if($internal_id == 0){
123 die
"Problem could not find stable id $stable_id and got past the first check for $dbname\n";
125 $ins_ox_sth->execute($internal_id, $xref_id, $table,
'DIRECT');
126 $get_object_xref_id_sth->execute($internal_id, $xref_id, $table,
'DIRECT');
127 $object_xref_id = ($get_object_xref_id_sth->fetchrow_array())[0];
128 if($ins_ox_sth->err){
129 $duplicate_direct_count++;
133 $ins_ix_sth->execute($object_xref_id);
134 push @master_xref_ids, $xref_id;
136 $self->process_dependents({master_xrefs => \@master_xref_ids,
137 dup_count => \$duplicate_dependent_count,
139 internal_id => $internal_id,
145 if($duplicate_direct_count or $duplicate_dependent_count){
146 print
"duplicate entrys ignored for $duplicate_direct_count direct xrefs and $duplicate_dependent_count dependent xrefs\n" if($self->verbose);
149 foreach my $key ( keys %err_count){
150 print STDERR
"*WARNING*: ".$err_count{$key}.
" direct xrefs for database ".$key.
" could not be added as their stable_ids could not be found\n";
153 my $sth = $dbi->prepare(
"insert into process_status (status, date) values('direct_xrefs_parsed',now())");
165 my $dep_sql = (<<
"DSS");
166 SELECT dependent_xref_id, linkage_annotation
168 WHERE master_xref_id = ?
170 my $sth = $dbi->prepare($dep_sql);
181 INSERT INTO object_xref (ensembl_id, xref_id, ensembl_object_type, linkage_type, master_xref_id)
182 VALUES (?, ?, ?, ?, ?)
184 my $sth = $dbi->prepare($sql);
193 select object_xref_id from object_xref where ensembl_id = ? and xref_id = ? and ensembl_object_type = ? and linkage_type = ?
195 my $sth = $dbi->prepare($sql);
199 sub get_ox_id_master_sth {
204 select object_xref_id from object_xref where ensembl_id = ? and xref_id = ? and ensembl_object_type = ? and linkage_type = ? and master_xref_id = ?
206 my $sth = $dbi->prepare($sql);
211 sub process_dependents {
212 my ($self, $arg_ref) = @_;
214 my $dbi = $arg_ref->{dbi};
215 my $master_xref_ids = $arg_ref->{master_xrefs};
216 my $duplicate_dep_count = $arg_ref->{dup_count};
217 my $table = $arg_ref->{table};
218 my $internal_id = $arg_ref->{internal_id};
220 my $dep_sth = $self->get_dep_sth($dbi);
221 my $ins_ox_sth2 = $self->get_add_dep_ox($dbi);
222 my $ins_ix_sth = $self->get_ins_ix_sth($dbi);
223 my $get_object_xref_id_sth = $self->get_ox_id_master_sth($dbi);
226 local $ins_ox_sth2->{RaiseError} = 0; # want to see duplicates and not die automatically
227 local $ins_ox_sth2->{PrintError} = 0;
230 while(my $master_xref_id = pop(@$master_xref_ids)){
231 my ($dep_xref_id, $link);
232 $dep_sth->execute($master_xref_id);
233 $dep_sth->bind_columns(\$dep_xref_id, \$link);
234 while($dep_sth->fetch){
235 $ins_ox_sth2->execute($internal_id, $dep_xref_id, $table,
'DEPENDENT', $master_xref_id);
236 $get_object_xref_id_sth->execute($internal_id, $dep_xref_id, $table,
'DEPENDENT', $master_xref_id);
237 $object_xref_id = ($get_object_xref_id_sth->fetchrow_array())[0];
238 if($ins_ox_sth2->err){
239 my $err = $ins_ox_sth2->errstr;
240 if($err =~ /Duplicate/){
241 $$duplicate_dep_count++;
245 die
"Problem loading error is $err\n";
248 $ins_ix_sth->execute($object_xref_id);
249 push @$master_xref_ids, $dep_xref_id; # get the dependent, dependents just in
case