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;
68 Example : #use
this instead of the constructor directly:
69 my $dta = $db_adaptor->get_DensityTypeAdaptor();
81 my $self = $class->SUPER::new(@_);
83 $self->{
'dbID_cache'} = {};
91 # Description: PROTECTED implementation of superclass abstract method.
92 # Returns the names, aliases of the tables to use for queries.
93 # Returntype : list of listrefs of strings
99 return ([
'density_type',
'dt']);
106 # Description: PROTECTED implementation of superclass abstract method.
107 # Returns a list of columns to use for queries.
108 # Returntype : list of strings
114 return (
'dt.density_type_id',
'dt.analysis_id',
'dt.block_size',
'dt.region_features',
'dt.value_type');
123 Example : my @density_types = @{$density_type_adaptor->fetch_all};
124 Description: Retrieves every density type in the database.
125 NOTE: In a multi-species database,
this method will
126 return all the entries, not just the ones associated with
130 Caller : general,
new
140 my $sth = $self->prepare(
"SELECT density_type_id, analysis_id, block_size,".
141 " value_type, region_features " .
142 "FROM density_type");
146 my($dbID, $analysis_id, $blk_size, $vtype, $region_features );
147 $sth->bind_columns(\$dbID, \$analysis_id, \$blk_size, \$vtype, \$region_features );
149 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
151 while($sth->fetch()) {
152 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
157 -ANALYSIS => $analysis,
158 -BLOCK_SIZE => $blk_size,
159 -REGION_FEATURES => $region_features,
160 -VALUE_TYPE => $vtype);
162 $self->{
'dbID_cache'}->{$dbID} = $dt;
175 Example : my $dt = $density_type_adaptor->fetch_by_dbID($dbID);
176 Description: Retrieves a density type
object via its
internal identifier
178 Exceptions :
throw if dbID argument not defined
188 if(!defined($dbID)) {
189 throw(
"dbID argument must be defined");
192 if($self->{
'dbID_cache'}->{$dbID}) {
193 return $self->{
'dbID_cache'}->{$dbID};
196 # go back to database and refill caches
199 return $self->{
'dbID_cache'}->{$dbID};
203 =head2 fetch_all_by_logic_name
205 Arg [1] :
string $logic_name
206 Example : my @dts = @{$dtype_adaptor->fetch_all(
'repeat_coverage')};
207 Description: Retrieves all density types with a given logic name.
208 NOTE: In a multi-species database,
this method will
209 return all the entries matching the search criteria, not
210 just the ones associated with the current species.
211 Returntype : reference to list of Bio::EnsEMBL::DensityTypes
212 Exceptions : thrown
if logic_name argument is not provided
218 sub fetch_all_by_logic_name {
220 my $logic_name = shift;
222 if(!defined($logic_name)) {
223 throw(
"logic_name argument is required.");
226 my $analysis_adaptor = $self->db()->get_AnalysisAdaptor();
227 my $analysis = $analysis_adaptor->fetch_by_logic_name($logic_name);
229 return []
if(!$analysis);
231 my $sth = $self->prepare(
"SELECT density_type_id, block_size,".
232 " value_type, region_features " .
233 "FROM density_type " .
234 "WHERE analysis_id = ?");
235 $sth->bind_param(1,$analysis->dbID,SQL_INTEGER);
238 my($dbID, $blk_size, $vtype, $region_features );
239 $sth->bind_columns(\$dbID, \$blk_size, \$vtype, \$region_features);
243 while($sth->fetch()) {
247 -ANALYSIS => $analysis,
248 -BLOCK_SIZE => $blk_size,
249 -REGION_FEATURES => $region_features,
250 -VALUE_TYPE => $vtype);
252 $self->{
'dbID_cache'}->{$dbID} = $dt;
264 the density types to store in the database
265 Example : $density_type->store(@density_types);
266 Description: Stores a list of density type objects in the database
268 Exceptions : thrown
if @dt is not defined
278 if( scalar(@dt) == 0 ) {
279 throw(
"Must call store with list of Density Types");
282 my $insert_ignore = $self->insert_ignore_clause();
283 my $sth = $self->prepare
284 (
"${insert_ignore} INTO density_type (analysis_id,".
285 "block_size, value_type, region_features ) ".
286 "VALUES (?, ?, ?, ?)");
288 my $db = $self->db();
289 my $analysis_adaptor = $db->get_AnalysisAdaptor();
291 FEATURE:
foreach my $dt ( @dt ) {
292 if( !ref $dt || !$dt->isa(
"Bio::EnsEMBL::DensityType") ) {
293 throw(
"Density Type must be an Ensembl DensityType, " .
294 "not a [".ref($dt).
"]");
297 if($dt->is_stored($db)) {
301 if(!defined($dt->analysis())) {
302 throw(
"An analysis must be attached to the density type to be stored.");
305 #store the analysis if it has not been stored yet
306 if(!$dt->analysis->is_stored($db)) {
307 $analysis_adaptor->store($dt->analysis());
312 my $region_features = $dt->region_features();
313 $region_features |= 0;
315 $sth->bind_param(1,$dt->analysis->dbID,SQL_INTEGER);
316 $sth->bind_param(2,$block_size,SQL_INTEGER);
317 $sth->bind_param(3,$dt->value_type,SQL_VARCHAR);
318 $sth->bind_param(4,$region_features, SQL_VARCHAR);
319 my $inserted = $sth->execute();
323 # $inserted can be 0E0 which is true but equal to 0
324 if(!$inserted || $inserted == 0) {
325 # insert failed, presumably because was already stored in database
327 my @dts=@{$self->fetch_all_by_logic_name($dt->analysis()->logic_name())};
328 my ($stored_dt) = grep {$_->block_size() == $dt->block_size()} @dts;
330 throw(
"Could not retrieve or store DensityType from database.\n" .
331 "Incorrect db permissions or missing density_type table?\n");
333 $dbID = $stored_dt->dbID();
335 $dbID = $self->last_insert_id(
'density_type_id', undef,
'density_type');
338 # next two lines are to set the density type as stored
342 $self->{
'dbID_cache'}->{$dbID} = $dt;