ensembl-hive  2.7.0
SeqRegionSynonymAdaptor.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 INTO
29 =cut
30 
31 package Bio::EnsEMBL::DBSQL::SeqRegionSynonymAdaptor;
32 use vars qw(@ISA);
33 use strict;
34 
35 
37 use Bio::EnsEMBL::Utils::Exception qw(throw);
39 
40 @ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');
41 
42 
43 sub get_synonyms {
44  my ($self, $seq_id) = @_;
45  $self->bind_param_generic_fetch($seq_id, SQL_INTEGER);
46  return $self->generic_fetch(qq{srs.seq_region_id = ?});
47 }
48 
49 sub store {
50  my $self = shift;
51  my $syn = shift;
52 
53  return if($syn->is_stored($self->db));
54 
55  if(!defined($syn->seq_region_id)){
56  throw("seq_region_id is needed to store a seq_region_synoym");
57  }
58 
59  my $insert_ignore = $self->insert_ignore_clause();
60  my $sth = $self->prepare("${insert_ignore} INTO seq_region_synonym (seq_region_id, synonym, external_db_id) VALUES (?, ?, ?)");
61  $sth->bind_param(1, $syn->seq_region_id, SQL_INTEGER);
62  $sth->bind_param(2, $syn->name , SQL_VARCHAR);
63  $sth->bind_param(3, $syn->external_db_id, SQL_INTEGER);
64  $sth->execute;
65  $syn->{'dbID'} = $self->last_insert_id('seq_region_synonym_id', undef, 'seq_region_synonym');
66  $sth->finish;
67 }
68 
69 sub _tables {
70  return (['seq_region_synonym', 'srs'], ['external_db','exdb']);
71 }
72 
73 sub _columns {
74  return qw(srs.seq_region_synonym_id srs.seq_region_id srs.synonym srs.external_db_id exdb.db_name exdb.db_display_name);
75 }
76 
77 sub _left_join{
78  return (['external_db',"exdb.external_db_id = srs.external_db_id"]);
79 }
80 
81 sub _objs_from_sth {
82  my ($self, $sth) = @_;
83 
84  my @results;
85  my ($seq_id, $dbid, $alt_name, $ex_db, $dbname, $db_display_name);
86  $sth->bind_columns(\$dbid, \$seq_id, \$alt_name, \$ex_db, \$dbname, \$db_display_name);
87 
88  push @results, Bio::EnsEMBL::SeqRegionSynonym->new(
89  -adaptor => $self,
90  -synonym => $alt_name,
91  -dbID => $dbid,
92  -external_db_id => $ex_db,
93  -seq_region_id => $seq_id,
94  -dbname => $dbname,
95  -db_display_name => $db_display_name,
96  ) while $sth->fetch();
97 
98  $sth->finish;
99 
100  return \@results;
101 }
102 
103 sub _final_clause {
104  return ' ORDER BY srs.seq_region_synonym_id'
105 }
106 
107 1;
Bio::EnsEMBL::SeqRegionSynonym
Definition: SeqRegionSynonym.pm:16
Bio::EnsEMBL::DBSQL::BaseAdaptor
Definition: BaseAdaptor.pm:71
Bio::EnsEMBL::SeqRegionSynonym::new
public Bio::EnsEMBL::SeqRegionSynonym new()
Bio::EnsEMBL::Utils::Exception
Definition: Exception.pm:68