3 # BioPerl module for Bio::DB::BioSQL::Pg::TermAdaptorDriver
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Hilmar Lapp <hlapp at gmx.net>
9 # Copyright Hilmar Lapp
13 # (c) Hilmar Lapp, hlapp at gmx.net, 2003.
14 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2003.
16 # You may distribute this module under the same terms as perl itself.
17 # Refer to the Perl Artistic License (see the license accompanying this
18 # software package, or see http://www.perl.com/language/misc/Artistic.html)
19 # for the terms under which you may use, modify, and redistribute this module.
21 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 # POD documentation - main docs before the code
30 Bio::DB::BioSQL::Pg::TermAdaptorDriver - DESCRIPTION of Object
34 Give standard usage here
38 Describe the object here
44 User feedback is an integral part of the evolution of this and other
45 Bioperl modules. Send your comments and suggestions preferably to
46 the Bioperl mailing list. Your participation is much appreciated.
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53 Please direct usage questions or support issues to the mailing list:
55 I<bioperl-l@bioperl.org>
57 rather than to the module maintainer directly. Many experienced and
58 reponsive experts will be able look at the problem and quickly
59 address it. Please include a thorough description of the problem
60 with code and data examples if at all possible.
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 of the bugs and their resolution. Bug reports can be submitted via
68 http://redmine.open-bio.org/projects/bioperl/
70 =head1 AUTHOR - Hilmar Lapp
72 Email hlapp at gmx.net
76 Additional contributors names and emails here
80 The rest of the documentation details each of the object methods.
81 Internal methods are usually preceded with a _
86 # Let the code begin...
89 package Bio
::DB
::BioSQL
::Pg
::TermAdaptorDriver
;
93 use Bio::DB::BioSQL::Pg::BasePersistenceAdaptorDriver;
95 @ISA = qw(Bio::DB::BioSQL::Pg::BasePersistenceAdaptorDriver);
98 =head2 remove_synonyms
100 Title : remove_synonyms
102 Function: Removes all synonyms for an ontology term.
104 Returns : TRUE on success, and FALSE otherwise.
105 Args : The calling persistence adaptor.
107 The persistent term object for which to remove the synonyms
108 (a Bio::DB::PersistentObjectI compliant object with defined
115 my ($self,$adp,$obj) = @_;
117 # delete statement cached?
118 my $cachekey = "DELETE SYNONYMS";
119 my $sth = $adp->sth($cachekey);
120 # if not we need to build it
122 # we need table name and foreign key
123 my $table = $self->table_name("TermSynonym");
124 my $fkname = $self->foreign_key_name($obj->obj);
125 # build, prepare, and cache the SQL statement
126 $sth = $self->_build_sth($adp, $cachekey,
127 "DELETE FROM $table WHERE $fkname = ?");
129 # bind parameters and execute insert
130 my $dbgmsg = "executing with values (".
131 $obj->primary_key().") (FK to ".ref($obj->obj).")";
132 $adp->debug("$cachekey: $dbgmsg\n");
133 my $rv = $sth->execute($obj->primary_key());
135 $self->warn("failed to remove term synonyms (".ref($adp)
136 .") with values (".$obj->primary_key()
137 .") (FK to ".ref($obj->obj)."):\n".$sth->errstr());
144 Title : store_synonym
146 Function: Stores a synonym for an ontology term.
148 Returns : TRUE on success, and FALSE otherwise.
149 Args : The calling persistence adaptor.
151 The persistent term object for which to store the synonym
152 (a Bio::DB::PersistentObjectI compliant object with defined
155 The synonym to store (a scalar).
161 my ($self,$adp,$obj,$syn) = @_;
163 # insert and look-up statements cached?
164 my $icachekey = "INSERT SYNONYM";
165 my $isth = $adp->sth($icachekey);
166 # if not we need to build them
168 # we need table name, foreign key, and slot map
169 my $table = $self->table_name("TermSynonym");
170 my $fkname = $self->foreign_key_name($obj->obj);
171 my $colmap = $self->slot_attribute_map($table);
172 # build, prepare, and cache the SQL statements
173 $isth = $self->_build_sth($adp, $icachekey,
174 "INSERT INTO $table (".
175 join(", ", $colmap->{'synonym'}, $fkname).
178 # bind parameters and execute insert
179 my $dbgmsg = "executing with values ($syn, ".
180 $obj->primary_key().") (synonym, FK to ".ref($obj->obj).")";
181 $adp->debug("$icachekey: $dbgmsg\n");
182 my $rv = $isth->execute($syn, $obj->primary_key());
183 # in PostgreSQL, the UK failure is caught through a rule already,
184 # so if $rv evaluates to FALSE it must be the statement being bad
186 $self->warn("failed to store term synonym (".ref($adp)
187 .") with values ($syn) (FK ".$obj->primary_key()
188 ." to ".ref($obj->obj)."):\n"
195 my ($self,$adp,$cachekey,$sql) = @_;
197 $adp->debug("$cachekey: preparing: $sql\n");
198 my $sth = $adp->dbh->prepare($sql);
199 $self->throw("failed to prepare \"$sql\": ".$adp->dbh->errstr)
201 $adp->sth($cachekey,$sth);
209 Function: Retrieves the synonyms for an ontology term and adds them
212 Returns : TRUE on success, and FALSE otherwise.
213 Args : The calling persistence adaptor.
215 The persistent term object for which to retrieve the
216 synonyms (a Bio::DB::PersistentObjectI compliant object
217 with defined primary key).
223 my ($self,$adp,$obj) = @_;
225 # insert and look-up statements cached?
226 my $cachekey = "SELECT SYNONYMS";
227 my $sth = $adp->sth($cachekey);
228 # if not we need to build it
230 # we need table name, foreign key, and slot map
231 my $table = $self->table_name("TermSynonym");
232 my $fkname = $self->foreign_key_name($obj->obj);
233 my $colmap = $self->slot_attribute_map($table);
234 # build, prepare, and cache the SQL statement
235 $sth = $self->_build_sth($adp, $cachekey,
236 "SELECT ".$colmap->{'synonym'}.
237 " FROM $table WHERE $fkname = ?");
239 # bind parameters and execute select
240 my $dbgmsg = "executing with values (".
241 $obj->primary_key().") (FK to ".ref($obj->obj).")";
242 $adp->debug("$cachekey: $dbgmsg\n");
243 my $rv = $sth->execute($obj->primary_key());
244 $self->warn("failed to execute $cachekey: ".$sth->errstr) unless $rv;
245 while(my $row = $sth->fetchrow_arrayref()) {
246 $obj->add_synonym($row->[0]);