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 $uoa = $database_adaptor->get_UnmappedObjectAdaptor();
43 Unmapped ObjectAdaptor - An adaptor responsible
for the creation,
44 editing, retrieval of Unmapped Objects. These being the Objects that
45 where not mapped in a specific process i.e. xref, cDNA, Markers.
51 package Bio::EnsEMBL::DBSQL::UnmappedObjectAdaptor;
68 Arg [1] : list of args @args
69 Superclass constructor arguments
71 Description: Constructor which just initializes
internal cache structures
74 Caller : implementing subclass constructors
83 my $class = ref($proto) || $proto;
84 my $self = $class->SUPER::new(@_);
98 $sth->bind_columns( \( $id, $desc ) );
100 while ( $sth->fetch() ) {
101 $desc_to_id{$desc} = $id;
113 # Description: PROTECTED implementation of superclass abstract method
114 # returns the names, aliases of the tables to use for queries
115 # Returntype : list of listrefs of strings
122 return ([
'unmapped_object',
'uo'],
123 [
'unmapped_reason',
'ur']);
130 # Description: PROTECTED implementation of superclass abstract method
131 # returns a list of columns to use for queries
132 # Returntype : list of strings
140 return qw(uo.unmapped_object_id uo.type uo.analysis_id uo.external_db_id
141 uo.identifier uo.unmapped_reason_id uo.query_score uo.target_score
142 uo.ensembl_id uo.ensembl_object_type
143 ur.summary_description ur.full_description);
148 'unmapped_object',
"uo.unmapped_reason_id = ur.unmapped_reason_id"
155 Example : @unmapped_object_ids = @{$unmapped_object_adaptor->list_dbIDs()};
156 Description: Gets an array of
internal ids
for all unmapped_objects in the current db
157 Returntype : list of ints
167 return $self->_list_dbIDs(
"unmapped_object");
170 =head2 list_unmapped_reasons
173 Example : @unmapped_object_reason+ids =
174 @{$unmapped_object_adaptor->list_unmapped_reasons()};
175 Description: Gets an array of
internal ids
for all unmapped_objects in the current db
176 Returntype : list of ints
183 sub list_unmapped_reasons {
186 return $self->_list_dbIDs(
"unmapped_reason");
192 # Arg [1] : StatementHandle $sth
194 # Description: PROTECTED implementation of abstract superclass method.
195 # responsible for the creation of UnmappedObjects
196 # Returntype : listref of Bio::EnsEMBL::UnmappedObjects
202 my ($self, $sth) = @_;
204 my($unmapped_object_id, $type, $analysis_id, $external_db_id, $identifier,
205 $unmapped_reason_id, $query_score, $target_score, $ensembl_id,
206 $ensembl_object_type, $summary, $full_desc);
208 $sth->bind_columns(\$unmapped_object_id,\$type, \$analysis_id,
209 \$external_db_id, \$identifier, \$unmapped_reason_id,
210 \$query_score, \$target_score, \$ensembl_id,
211 \$ensembl_object_type, \$summary, \$full_desc);
213 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
216 while($sth->fetch()) {
217 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
219 #print "$identifier\n";
222 $self->_create_feature(
223 'Bio::EnsEMBL::UnmappedObject', {
224 -unmapped_object_id => $unmapped_object_id,
225 -unmapped_reason_id => $unmapped_reason_id,
227 -analysis => $analysis,
228 -external_db_id => $external_db_id,
229 -identifier => $identifier,
230 -query_score => $query_score,
231 -target_score => $target_score,
232 -ensembl_id => $ensembl_id,
233 -ensembl_object_type => $ensembl_object_type,
234 -summary => $summary,
235 -full_desc => $full_desc,
247 Arg [1] : list of Bio::EnsEMBL::UnmappedObjects @uo
248 the unmapped objects to store in the database
249 Example : $ou_adaptor->store(@uo);
250 Description: Stores a list of unmapped objects in the database
252 Exceptions : thrown
if no Analysis, or no list of objects to store.
259 my ($self,@uos) = @_;
261 if( scalar(@uos) == 0 ) {
262 throw(
"Must call store with list of UnmappedObjects");
266 my $db = $self->db();
267 my $analysis_adaptor = $db->get_AnalysisAdaptor();
269 my $sth_reason = $self->prepare
270 (
"INSERT INTO unmapped_reason (summary_description, full_description)".
273 my $sth_unmapped_object = $self->prepare
274 (
"INSERT INTO unmapped_object (type, analysis_id, external_db_id,
275 identifier, unmapped_reason_id, query_score, target_score,
276 ensembl_id, ensembl_object_type)".
277 " VALUES (?,?,?,?,?,?,?,?,?)");
279 my $sth_fetch_reason =
289 FEATURE:
foreach my $uo ( @uos ) {
291 if( !ref $uo || !$uo->isa(
"Bio::EnsEMBL::UnmappedObject") ) {
292 throw(
"UnmappedObject must be an Ensembl UnmappedObject, " .
293 "not a [".ref($uo).
"]");
295 if($uo->is_stored($db)){
299 my $analysis = $uo->analysis();
300 throw(
"UnmappedObject must have an analysis object.".$uo->analysis.
"\n")
if(!defined($analysis));
303 if($analysis->is_stored($db)) {
304 $analysis_id = $analysis->dbID();
307 $analysis_id = $db->get_AnalysisAdaptor->store($analysis);
312 # Check if unmapped reason is cached
313 # Check if it has been added since the cache was created
316 if(!defined($desc_to_id{$uo->{
'description'}})){
317 $sth_reason->bind_param(1,$uo->{
'summary'},SQL_VARCHAR);
318 $sth_reason->bind_param(2,$uo->{
'description'},SQL_VARCHAR);
320 if(! eval{ $sth_reason->execute(); 1 }){
321 # DBI Trace possible here?
324 $msg .=
"INSERT INTO unmapped_reason (summary_description, full_description) VALUES (";
325 $msg .= $uo->{
'summary'} .
','. $uo->{
'description'}.
')';
326 # Temporary fix for naughty cross-dependency regulation code.
328 warning(
"Query: \n$msg");
329 print STDERR
"UnmappedObject: \n";
330 print STDERR Dumper $uo;
332 $sth_fetch_reason->execute($uo->{
'description'});
334 my $unmapped_reasons = $sth_fetch_reason->fetchrow_arrayref();
335 if(! defined($unmapped_reasons)){
336 my $msg = $uo->{
'description'}.
" unable to store. Check MySQL schema, maybe PK not big enough?";
339 if(scalar @$unmapped_reasons != 1){
340 throw(
"Multiple results for this description");
342 $uo->{
'unmapped_reason_id'} = $unmapped_reasons->[0];
346 # print 'Last mohican: '.$self->last_insert_id ."\n";
347 $uo->{
'unmapped_reason_id'} = $self->last_insert_id;
351 $uo->{
'unmapped_reason_id'} = $desc_to_id{$uo->{
'description'}};
353 $sth_unmapped_object->bind_param(1,$uo->{
'type'},SQL_VARCHAR);
354 $sth_unmapped_object->bind_param(2,$uo->analysis->dbID,SQL_INTEGER);
355 $sth_unmapped_object->bind_param(3,$uo->{
'external_db_id'},SQL_INTEGER);
356 $sth_unmapped_object->bind_param(4,$uo->{
'identifier'},SQL_VARCHAR);
357 $sth_unmapped_object->bind_param(5,$uo->{
'unmapped_reason_id'},SQL_VARCHAR);
358 $sth_unmapped_object->bind_param(6,$uo->{
'query_score'},SQL_DOUBLE);
359 $sth_unmapped_object->bind_param(7,$uo->{
'target_score'},SQL_DOUBLE);
360 $sth_unmapped_object->bind_param(8,$uo->{
'ensembl_id'},SQL_INTEGER);
361 $sth_unmapped_object->bind_param(9,$uo->{
'ensembl_object_type'},SQL_VARCHAR);
362 $sth_unmapped_object->execute();
363 $uo->dbID($self->last_insert_id(
'unmapped_object_id', undef,
'unmapped_object'));
365 $sth_reason->finish();
370 =head2 fetch_all_by_type
372 Arg [1] :
string type. The type of unmapped objects
373 Example : @unmapped_object = @{$uoa->fetch_all_by_type(
'xref')};
374 Description : Retrieves all the unmapped
object for a particular
375 type. e.g.
'xref',
'cDNA',
'marker'
383 sub fetch_all_by_type {
384 my ($self, $type) = @_;
387 throw(
"type argument is required");
389 $self->bind_param_generic_fetch($type,SQL_VARCHAR);
390 $self->generic_fetch(
"uo.type = ?");
394 =head2 fetch_all_by_analysis
396 Arg [1] :
Bio:EnsEMBL::Analysis
object
397 Arg [2] : (optional)
string database name
398 Example : @unmapped_object = @{$uoa->fetch_all_by_analysis($analysis)};
399 Description : Retrieves all the unmapped
object for a particular
400 analysis type with the the option of a particular
403 Exceptions : thorws
if first argument is not an anaylisi
object
409 sub fetch_all_by_analysis {
410 my ($self, $analysis,$dbname) = @_;
413 throw(
"analysis argument is required");
415 $self->bind_param_generic_fetch($analysis->dbID,SQL_INTEGER);
416 my $constraint =
"uo.analysis_id = ?";
417 if(defined($dbname)){
419 my $sth = $self->prepare(
'select external_db_id from external_db where db_name like "'.
422 $sth->bind_columns(\$db_id);
424 if(!defined($db_id) or $db_id == 0){
425 throw(
"$dbname could not be found in the external database table\n");
427 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
428 $constraint .=
" AND uo.external_db_id = ?";
430 $self->generic_fetch($constraint);
434 =head2 fetch_by_identifier
436 Arg [1] :
string type. The type of unmapped objects
437 Arg [2] : (optional)
string database name
438 Example : @unmapped_object = @{$uoa->fetch_by_identifier(
'Q123345')};
439 Description : Retrieves the unmapped
object for a particular
448 sub fetch_by_identifier {
449 my ($self, $identifier, $dbname) = @_;
451 unless($identifier) {
452 throw(
"identifier argument is required");
454 $self->bind_param_generic_fetch($identifier,SQL_VARCHAR);
455 my $constraint =
'uo.identifier like ?';
457 if(defined($dbname)){
459 my $sth = $self->prepare(
'select external_db_id from external_db where db_name like "'.
462 $sth->bind_columns(\$db_id);
464 if(!defined($db_id) or $db_id == 0){
465 throw(
"$dbname could not be found in the external database table\n");
467 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
468 $constraint .=
" AND uo.external_db_id = ?";
470 return $self->generic_fetch($constraint);
473 =head2 fetch_all_by_object_type_id
475 Arg [1] :
string - The
object type of the ensembl
object e.g. Gene
476 Arg [2] :
int - The
internal dbID of the ensembl
object
477 Example : my @unmapped_objects = @{$uoa->fetch_all_by_object_type_id(
'Gene', 12341)};
478 Description : Retrieves the unmapped objects
for a particular ensembl
object
479 This is a base method which should be called by wrapper methods
480 defining the correct
object type e.g. $uoa->fetch_all_by_Gene($gene)
482 Exceptions : Throws
if arguments are not defined
488 sub fetch_all_by_object_type_id {
489 my ($self, $object_type, $dbid) = @_;
491 if(! ($object_type && $dbid)){
492 throw(
"object_type and dbid arguments required");
495 $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
496 $self->bind_param_generic_fetch($dbid, SQL_INTEGER);
498 my $constraint =
'uo.ensembl_object_type=? and uo.ensembl_id=?';
500 return $self->generic_fetch($constraint);