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 $ditagadaptor = $db->get_DitagAdaptor();
38 my @ditags = @{ $ditagadaptor->fetch_by_type(
"ZZ11") };
48 package Bio::EnsEMBL::Map::DBSQL::DitagAdaptor;
60 =head2 fetch_all_by_name
63 Example : $tag = $ditag_adaptor->fetch_by_name(
"U3");
64 Description: Retrieves ditags from the database
using the name
70 sub fetch_all_by_name {
71 my ($self, $tagname) = @_;
74 throw "must be called with a name of a ditag.";
76 my $sth = $self->prepare(
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence
79 $sth->execute($tagname);
80 my $result = $self->_fetch($sth);
90 Example : @all_tags = @{$ditag_adaptor->fetch_by_dbID(1003)};
91 Description: Retrieve ditags with a certain
id from the database
98 my ($self, $tagid) = @_;
101 throw "must be called with the type of a ditag.";
103 my $sth = $self->prepare(
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence
105 WHERE d.ditag_id = ?");
106 $sth->execute($tagid);
107 my $result = $self->_fetch($sth);
113 =head2 fetch_all_by_type
116 Example : @all_tags = @{$ditag_adaptor->fetch_by_type(
"SME005")};
117 Description: Retrieves all ditags of a certain type from the database
123 sub fetch_all_by_type {
124 my ($self, $tagtype) = @_;
127 throw "must be called with the type of a ditag.";
129 my $sth = $self->prepare(
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence
132 $sth->execute($tagtype);
133 my $result = $self->_fetch($sth);
139 =head2 fetch_by_name_and_type
143 Example : $tag = $ditag_adaptor->fetch_by_name_and_type(
"U3",
"SME005");
144 Description: Retrieves ditags from the database
using name/type combination
145 which should be non-ambiguous
151 sub fetch_by_name_and_type {
152 my ($self, $tagname, $tagtype) = @_;
154 if(!$tagname or !$tagtype){
155 throw "must be called with a name and type of a ditag.";
157 my $sth = $self->prepare(
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence
159 WHERE d.name = ? and d.type = ?");
160 $sth->execute($tagname, $tagtype);
161 my $result = $self->_fetch($sth);
170 Example : @all_tags = @{$ditag_adaptor->fetch_all};
171 Description: Retrieves all ditags from the database
180 my $sth = $self->prepare(
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence
183 my $result = $self->_fetch($sth);
189 =head2 fetch_all_with_limit
194 Description: fetch_by_type with row limit and offset
200 sub fetch_all_with_limit {
201 my ($self, $tagtype, $limit, $offset) = @_;
204 my $sql =
"SELECT d.ditag_id, d.name, d.type, d.tag_count, d.sequence ".
206 "WHERE d.type = ? LIMIT ? OFFSET ?;";
207 my $sth = $self->db->dbc->prepare($sql);
208 $sth->execute($tagtype, $limit, $offset);
209 my $result = $self->_fetch($sth);
217 Arg [1] : statement handler
object
218 Description:
generic sql-fetch
function for the ditag fetch methods
225 my ($self, $sth) = @_;
227 my($tag_id, $name, $type, $count, $sequence);
230 $sth->bind_columns(\$tag_id, \$name, \$type, \$count, \$sequence);
236 -tag_count => $count,
237 -sequence => $sequence,
249 Example : $ditag_adaptor->store(\@ditags);
250 Description: Stores a single ditag or
251 a list of ditags in
this database.
258 my ($self, $ditags) = @_;
260 if(ref $ditags eq
'ARRAY'){
261 if(scalar(@$ditags) == 0){
262 throw(
"Must call store with ditag or list ref of ditags");
267 push @ditags, $ditags;
271 throw(
"Must call store with ditag or list ref of ditags not ".$ditags);
274 my $db = $self->db() or
throw "Couldn t get database connection.";
277 foreach my $ditag (@$ditags) {
279 if ( !ref $ditag || !$ditag->isa(
"Bio::EnsEMBL::Map::Ditag") ) {
280 throw(
"Object must be an Ensembl Ditag, " .
"not a [" . ref($ditag) .
"]" );
283 if ( $ditag->is_stored($db) ) {
284 warning(
"Ditag [" . $ditag->dbID .
"] is already stored in this database." );
288 #check if tag with same name/type already exists
289 my $sth = $self->prepare(
"SELECT COUNT(*) FROM ditag
290 WHERE name = ? AND type = ?" );
291 $sth->execute($ditag->name, $ditag->type);
292 if($sth->fetchrow() > 0){
293 warning(
"Ditag with name/type ".$ditag->name.
" / ".$ditag->type.
294 " is already stored in this database.\n".
295 "Use update_ditag() instead.");
299 if ( $ditag->dbID ) {
300 my $sth = $self->prepare(
"INSERT INTO ditag( ditag_id , name, type, tag_count, sequence ) ".
301 "VALUES( ?,?,?,?,? )" );
302 $sth->bind_param(1,$ditag->dbID,SQL_INTEGER);
303 $sth->bind_param(2,$ditag->name,SQL_VARCHAR);
304 $sth->bind_param(3,$ditag->type,SQL_VARCHAR);
305 $sth->bind_param(4,$ditag->tag_count,SQL_VARCHAR);
306 $sth->bind_param(5,$ditag->sequence,SQL_VARCHAR);
309 my $sth = $self->prepare(
"INSERT INTO ditag( name, type, tag_count, sequence ) ".
310 "VALUES( ?,?,?,? )" );
311 $sth->bind_param(1,$ditag->name,SQL_VARCHAR);
312 $sth->bind_param(2,$ditag->type,SQL_VARCHAR);
313 $sth->bind_param(3,$ditag->tag_count,SQL_VARCHAR);
314 $sth->bind_param(4,$ditag->sequence,SQL_VARCHAR);
316 my $dbID = $self->last_insert_id(
'ditag_id', undef,
'ditag');
318 $ditag->adaptor($self);
326 =head2 print_creation
328 Arg [1] : ditag probe name
330 Arg [3] : ditag count
331 Arg [4] : ditag sequence
332 Arg [5] : (optional) ditag dbID
333 Description: convenience method to produce SQL insert statements
334 to speed up the creation of
new ditags
340 my ($self, $probe_name, $type, $count, $sequence, $dbid) = @_;
343 $string =
"INSERT INTO ditag( ditag_id, name, type, tag_count, sequence ) ".
344 "VALUES($dbid, '".$probe_name.
"', '".$type.
"', ".$count.
"'".$sequence.
"');\n";
347 $string =
"INSERT INTO ditag( name, type, tag_count, sequence ) ".
348 "VALUES('".$probe_name.
"', '".$type.
"', ".$count.
", '".$sequence.
"');\n";
357 Arg [1] : ditag to update
358 Description: update an existing ditag with
new values
359 Returntype :
true on success
364 my ($self, $ditag) = @_;
366 my $sth = $self->prepare(
"UPDATE ditag SET name=?, type=?, tag_count=?, sequence=? where ditag_id=?;" );
367 my $result =$sth->execute(
382 Example : my @feature_ids = @{$da->list_dbIDs()};
383 Description: Gets an array of
internal IDs
for all Ditag objects in
384 the current database.
385 Returntype : List of ints
391 my ($self, $ordered) = @_;
393 return $self->_list_dbIDs(
'ditag');