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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
38 my $msa = $registry->get_adaptor(
'Human',
'Core',
'MiscSet' );
40 my $misc_set = $msa->fetch_by_dbID(1234);
42 $misc_set = $msa->fetch_by_code(
'clone');
46 This
class provides database interactivity for
MiscSet objects.
47 MiscSets are used to classify MiscFeatures into groups.
53 package Bio::EnsEMBL::DBSQL::MiscSetAdaptor;
72 caches the contents of the
MiscSet table.
84 my $self = $class->SUPER::new(@_);
86 $self->{
'_id_cache'} = {};
87 $self->{
'_code_cache'} = {};
89 # cache the entire contents of the misc set table
90 # the table is small and it removes the need to repeatedly query the
91 # table or join to the table
104 Example :
foreach my $ms (@{$msa->fetch_all()}) {
105 print $ms->code(),
' ', $ms->name(),
"\n";
107 Description: Retrieves every MiscSet defined in the DB.
108 NOTE: In a multi-species database,
this method will
109 return all the entries matching the search criteria, not
110 just the ones associated with the current species.
111 Returntype : listref of Bio::EnsEMBL::MiscSets
121 my $sth = $self->prepare
122 (
'SELECT misc_set_id, code, name, description, max_length FROM misc_set');
126 my ($dbID, $code, $name, $desc, $max_len);
127 $sth->bind_columns(\$dbID, \$code, \$name, \$desc, \$max_len);
131 while($sth->fetch()) {
137 -DESCRIPTION => $desc,
138 -LONGEST_FEATURE => $max_len);
140 $self->{
'_id_cache'}->{$dbID} = $ms;
141 $self->{
'_code_cache'}->{lc($code)} = $ms;
155 The
internal identifier of the misc set to retrieve
156 Example : my $ms = $msa->fetch_by_dbID($dbID);
157 Description: Retrieves a misc set via its
internal identifier
169 if(!$self->{
'_id_cache'}->{$dbID}) {
170 # on a cache miss reread the whole table and reload the cache
174 return $self->{
'_id_cache'}->{$dbID};
181 Arg [1] :
string $code
182 The unique code of the MiscSet to retrieve
183 Example : my $ms = $msa->fetch_by_code(
'clone');
184 Description: Retrieves a MiscSet via its code
196 if(!$self->{
'_code_cache'}->{lc($code)}) {
197 # on cache miss, reread whole table and reload cache
201 return $self->{
'_code_cache'}->{lc($code)};
208 Arg [1] : list of MiscSets @mist_sets
209 Example : $misc_set_adaptor->store(@misc_sets);
210 Description: Stores a list of MiscSets in the database, and sets the
211 dbID and adaptor attributes of the stored sets.
213 Exceptions :
throw on incorrect arguments
214 warning
if a feature is already stored in
this database
215 Caller : MiscFeatureAdaptor::store
224 # we use 'insert ignore' so that inserts can occur safely on the farm
225 # otherwise 2 processes could try to insert at the same time and one
228 my $insert_ignore = $self->insert_ignore_clause();
229 my $sth = $self->prepare(
230 qq{${insert_ignore} INTO misc_set (
235 ) VALUES (?, ?, ?, ?)
238 my $db = $self->db();
241 foreach my $ms (@misc_sets) {
242 if(!ref($ms) || !$ms->isa(
'Bio::EnsEMBL::MiscSet')) {
243 throw(
"List of MiscSet arguments expected.");
246 if($ms->is_stored($db)) {
247 warning(
"MiscSet [".$ms->dbID.
"] is already stored in this database.");
251 $sth->bind_param(1,$ms->code,SQL_VARCHAR);
252 $sth->bind_param(2,$ms->name,SQL_VARCHAR);
253 $sth->bind_param(3,$ms->description,SQL_LONGVARCHAR);
254 $sth->bind_param(4,$ms->longest_feature,SQL_INTEGER);
256 my $num_inserted = $sth->execute();
260 if($num_inserted == 0) {
261 # insert failed because set with this code already exists
262 my $sth2 = $self->prepare(
"SELECT misc_set_id from misc_set " .
264 $sth2->bind_param(1,$ms->code,SQL_VARCHAR);
267 ($dbID) = $sth2->fetchrow_array();
269 if($sth2->rows() != 1) {
270 throw(
"Could not retrieve or store MiscSet, code=[".$ms->code.
"]\n".
271 "Wrong database user/permissions?");
274 $dbID = $self->last_insert_id(
'misc_set_id', undef,
'misc_set');
280 # update the internal caches
281 $self->{
'_id_cache'}->{$dbID} = $ms;
282 $self->{
'_code_cache'}->{lc($ms->code())} = $ms;
291 Example : $adaptor->update($miscset)
292 Description: Updates
this misc_set in the database
293 Returntype :
int 1
if update is performed, undef
if it is not
294 Exceptions :
throw if arg is not an misc_set
object
304 if (!ref($m) || !$m->isa(
'Bio::EnsEMBL::MiscSet')) {
305 throw(
"Expected Bio::EnsEMBL::MiscSet argument.");
308 if(!$m->is_stored($self->db())) {
312 my $sth = $self->prepare(
"UPDATE misc_set ".
313 "SET code =?, name =?, description = ?, max_length = ? ".
314 "WHERE misc_set_id = ?");
316 $sth->bind_param(1,$m->code,SQL_VARCHAR);
317 $sth->bind_param(2,$m->name,SQL_VARCHAR);
318 $sth->bind_param(3,$m->description,SQL_VARCHAR);
319 $sth->bind_param(4,$m->longest_feature,SQL_INTEGER);
320 $sth->bind_param(5,$m->dbID,SQL_INTEGER);
325 # update the internal caches
326 $self->{
'_id_cache'}->{$m->
dbID} = $m;
327 $self->{
'_code_cache'}->{lc($m->code())} = $m;