ensembl-hive  2.7.0
MySQLChecksum.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 package XrefMapper::Methods::MySQLChecksum;
21 
22 use strict;
23 use warnings;
25 
27 
28 use Bio::EnsEMBL::Utils::Exception qw(throw);
29 
30 my $CHECKSUM_SQL = <<SQL;
31 select accession
32 from checksum_xref
33 where checksum =?
34 and source_id=?
35 SQL
36 
37 sub perform_mapping {
38  my ($self, $sequences, $source_id, $object_type, $db_url) = @_;
39 
40  my @final_results;
41  my $dbc;
42  if (defined $db_url) {
43  my ($dbconn_part, $driver, $user, $pass, $host, $port, $dbname, $table_name, $tparam_name, $tparam_value, $conn_param_string) =
44  $db_url =~ m{^((\w*)://(?:(\w+)(?:\:([^/\@]*))?\@)?(?:([\w\-\.]+)(?:\:(\d*))?)?/([\w\-\.]*))(?:/(\w+)(?:\?(\w+)=([\w\[\]\{\}]*))?)?((?:;(\w+)=(\w+))*)$};
46  -dbname => $dbname,
47  -user => $user,
48  -pass => $pass,
49  -host => $host,
50  -port => $port);
51  } else {
52  $dbc = $self->mapper()->xref()->dbc();
53  }
54 
55  $dbc->sql_helper()->batch(-SQL => $CHECKSUM_SQL, -CALLBACK => sub {
56  my ($sth) = @_;
57  foreach my $sequence (@{$sequences}) {
58  my $checksum = uc($self->md5_checksum($sequence));
59  $sth->execute($checksum, $source_id);
60  my $upi;
61  while(my $row = $sth->fetchrow_arrayref()) {
62  my ($local_upi) = @{$row};
63  if(defined $upi) {
64  throw sprintf('The sequence %s had a checksum of %s but this resulted in more than one UPI: [%s, %s]', $sequence->id(), $checksum, $upi, $local_upi);
65  }
66  $upi = $local_upi;
67  }
68  if(defined $upi){
69  push(@final_results, { id => $sequence->id(), upi => $upi, object_type => $object_type });
70  }
71  }
72  return;
73  });
74 
75  return \@final_results;
76 }
accession
public accession()
XrefMapper::Methods::ChecksumBasic
Definition: ChecksumBasic.pm:7
Bio::EnsEMBL::Utils::SqlHelper::batch
public Int batch()
Bio::EnsEMBL::DBSQL::DBConnection
Definition: DBConnection.pm:42
Bio::EnsEMBL::DBSQL::DBConnection::sql_helper
public Bio::EnsEMBL::Utils::SqlHelper sql_helper()
Bio::EnsEMBL::Utils::Exception
Definition: Exception.pm:68