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
37 my $density_type_adaptor =
38 $registry->get_adaptor(
'Human',
'Core',
'DensityType' );
40 my @density_types = @{ $density_type_adaptor->
fetch_all() };
42 my $dt = $density_type_adaptor->fetch_by_dbID(12);
52 package Bio::EnsEMBL::DBSQL::DensityTypeAdaptor;
69 Example : #use
this instead of the constructor directly:
70 my $dta = $db_adaptor->get_DensityTypeAdaptor();
82 my $self = $class->SUPER::new(@_);
84 $self->{
'dbID_cache'} = {};
92 # Description: PROTECTED implementation of superclass abstract method.
93 # Returns the names, aliases of the tables to use for queries.
94 # Returntype : list of listrefs of strings
100 return ([
'density_type',
'dt']);
107 # Description: PROTECTED implementation of superclass abstract method.
108 # Returns a list of columns to use for queries.
109 # Returntype : list of strings
115 return (
'dt.density_type_id',
'dt.analysis_id',
'dt.block_size',
'dt.region_features',
'dt.value_type');
124 Example : my @density_types = @{$density_type_adaptor->fetch_all};
125 Description: Retrieves every density type in the database.
126 NOTE: In a multi-species database,
this method will
127 return all the entries, not just the ones associated with
131 Caller : general,
new
141 my $sth = $self->prepare(
"SELECT density_type_id, analysis_id, block_size,".
142 " value_type, region_features " .
143 "FROM density_type");
147 my($dbID, $analysis_id, $blk_size, $vtype, $region_features );
148 $sth->bind_columns(\$dbID, \$analysis_id, \$blk_size, \$vtype, \$region_features );
150 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
152 while($sth->fetch()) {
153 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
158 -ANALYSIS => $analysis,
159 -BLOCK_SIZE => $blk_size,
160 -REGION_FEATURES => $region_features,
161 -VALUE_TYPE => $vtype);
163 $self->{
'dbID_cache'}->{$dbID} = $dt;
176 Example : my $dt = $density_type_adaptor->fetch_by_dbID($dbID);
177 Description: Retrieves a density type
object via its
internal identifier
179 Exceptions :
throw if dbID argument not defined
189 if(!defined($dbID)) {
190 throw(
"dbID argument must be defined");
193 if($self->{
'dbID_cache'}->{$dbID}) {
194 return $self->{
'dbID_cache'}->{$dbID};
197 # go back to database and refill caches
200 return $self->{
'dbID_cache'}->{$dbID};
204 =head2 fetch_all_by_logic_name
206 Arg [1] :
string $logic_name
207 Example : my @dts = @{$dtype_adaptor->fetch_all(
'repeat_coverage')};
208 Description: Retrieves all density types with a given logic name.
209 NOTE: In a multi-species database,
this method will
210 return all the entries matching the search criteria, not
211 just the ones associated with the current species.
212 Returntype : reference to list of Bio::EnsEMBL::DensityTypes
213 Exceptions : thrown
if logic_name argument is not provided
219 sub fetch_all_by_logic_name {
221 my $logic_name = shift;
223 if(!defined($logic_name)) {
224 throw(
"logic_name argument is required.");
227 my $analysis_adaptor = $self->db()->get_AnalysisAdaptor();
228 my $analysis = $analysis_adaptor->fetch_by_logic_name($logic_name);
230 return []
if(!$analysis);
232 my $sth = $self->prepare(
"SELECT density_type_id, block_size,".
233 " value_type, region_features " .
234 "FROM density_type " .
235 "WHERE analysis_id = ?");
236 $sth->bind_param(1,$analysis->dbID,SQL_INTEGER);
239 my($dbID, $blk_size, $vtype, $region_features );
240 $sth->bind_columns(\$dbID, \$blk_size, \$vtype, \$region_features);
244 while($sth->fetch()) {
248 -ANALYSIS => $analysis,
249 -BLOCK_SIZE => $blk_size,
250 -REGION_FEATURES => $region_features,
251 -VALUE_TYPE => $vtype);
253 $self->{
'dbID_cache'}->{$dbID} = $dt;
265 the density types to store in the database
266 Example : $density_type->store(@density_types);
267 Description: Stores a list of density type objects in the database
269 Exceptions : thrown
if @dt is not defined
279 if( scalar(@dt) == 0 ) {
280 throw(
"Must call store with list of Density Types");
283 my $insert_ignore = $self->insert_ignore_clause();
284 my $sth = $self->prepare
285 (
"${insert_ignore} INTO density_type (analysis_id,".
286 "block_size, value_type, region_features ) ".
287 "VALUES (?, ?, ?, ?)");
289 my $db = $self->db();
290 my $analysis_adaptor = $db->get_AnalysisAdaptor();
292 FEATURE:
foreach my $dt ( @dt ) {
293 if( !ref $dt || !$dt->isa(
"Bio::EnsEMBL::DensityType") ) {
294 throw(
"Density Type must be an Ensembl DensityType, " .
295 "not a [".ref($dt).
"]");
298 if($dt->is_stored($db)) {
302 if(!defined($dt->analysis())) {
303 throw(
"An analysis must be attached to the density type to be stored.");
306 #store the analysis if it has not been stored yet
307 if(!$dt->analysis->is_stored($db)) {
308 $analysis_adaptor->store($dt->analysis());
313 my $region_features = $dt->region_features();
314 $region_features |= 0;
316 $sth->bind_param(1,$dt->analysis->dbID,SQL_INTEGER);
317 $sth->bind_param(2,$block_size,SQL_INTEGER);
318 $sth->bind_param(3,$dt->value_type,SQL_VARCHAR);
319 $sth->bind_param(4,$region_features, SQL_VARCHAR);
320 my $inserted = $sth->execute();
324 # $inserted can be 0E0 which is true but equal to 0
325 if(!$inserted || $inserted == 0) {
326 # insert failed, presumably because was already stored in database
328 my @dts=@{$self->fetch_all_by_logic_name($dt->analysis()->logic_name())};
329 my ($stored_dt) = grep {$_->block_size() == $dt->block_size()} @dts;
331 throw(
"Could not retrieve or store DensityType from database.\n" .
332 "Incorrect db permissions or missing density_type table?\n");
334 $dbID = $stored_dt->dbID();
336 $dbID = $self->last_insert_id(
'density_type_id', undef,
'density_type');
339 # next two lines are to set the density type as stored
343 $self->{
'dbID_cache'}->{$dbID} = $dt;