Archive Ensembl HomeArchive Ensembl Home
SeqRegionSynonymAdaptor.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 INTO 
00019 =cut
00020 
00021 package Bio::EnsEMBL::DBSQL::SeqRegionSynonymAdaptor;
00022 use vars qw(@ISA);
00023 use strict;
00024 
00025 
00026 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
00027 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning stack_trace_dump);
00028 use Bio::EnsEMBL::SeqRegionSynonym;
00029 
00030 @ISA = ('Bio::EnsEMBL::DBSQL::BaseAdaptor');
00031 
00032 
00033 sub get_synonyms{
00034   my $self = shift;
00035   my $seq_id = shift;
00036   
00037   my @results;
00038 
00039   my $sth = $self->prepare("select seq_region_synonym_id, synonym, external_db_id from seq_region_synonym where seq_region_id = ?");
00040   $sth->bind_param(1, $seq_id, SQL_INTEGER);
00041   $sth->execute();
00042   my $dbid;
00043   my $alt_name;
00044   my $ex_db;
00045   $sth->bind_columns(\$dbid, \$alt_name, \$ex_db);
00046   while($sth->fetch()){
00047     push @results, Bio::EnsEMBL::SeqRegionSynonym->new(-adaptor => $self,
00048                                                        -synonym => $alt_name,
00049                                -dbID => $dbid,
00050                                                        -external_db_id => $ex_db,
00051                                                        -seq_region_id => $seq_id);
00052   }
00053   $sth->finish;
00054 
00055   return \@results;
00056 }
00057 
00058 sub store {
00059   my $self = shift;
00060   my $syn = shift;
00061 
00062   return if($syn->is_stored($self->db));
00063 
00064   if(!defined($syn->seq_region_id)){
00065     throw("seq_region_id is needed to store a seq_region_synoym");
00066   }
00067 
00068   my $sth = $self->prepare("INSERT IGNORE INTO seq_region_synonym (seq_region_id, synonym, external_db_id) VALUES (?, ?, ?)");
00069   $sth->bind_param(1, $syn->seq_region_id,  SQL_INTEGER);
00070   $sth->bind_param(2, $syn->name         ,  SQL_VARCHAR);
00071   $sth->bind_param(3, $syn->external_db_id, SQL_INTEGER);
00072   $sth->execute;
00073   $syn->{'dbID'} = $sth->{'mysql_insertid'};
00074   $sth->finish;
00075 }
00076 
00077 
00078 
00079 1;