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;
67 Arg [1] : list of args @args
68 Superclass constructor arguments
70 Description: Constructor which just initializes
internal cache structures
73 Caller : implementing subclass constructors
82 my $class = ref($proto) || $proto;
83 my $self = $class->SUPER::new(@_);
97 $sth->bind_columns( \( $id, $desc ) );
99 while ( $sth->fetch() ) {
100 $desc_to_id{$desc} = $id;
112 # Description: PROTECTED implementation of superclass abstract method
113 # returns the names, aliases of the tables to use for queries
114 # Returntype : list of listrefs of strings
121 return ([
'unmapped_object',
'uo'],
122 [
'unmapped_reason',
'ur']);
129 # Description: PROTECTED implementation of superclass abstract method
130 # returns a list of columns to use for queries
131 # Returntype : list of strings
139 return qw(uo.unmapped_object_id uo.type uo.analysis_id uo.external_db_id
140 uo.identifier uo.unmapped_reason_id uo.query_score uo.target_score
141 uo.ensembl_id uo.ensembl_object_type
142 ur.summary_description ur.full_description);
147 'unmapped_object',
"uo.unmapped_reason_id = ur.unmapped_reason_id"
154 Example : @unmapped_object_ids = @{$unmapped_object_adaptor->list_dbIDs()};
155 Description: Gets an array of
internal ids
for all unmapped_objects in the current db
156 Returntype : list of ints
166 return $self->_list_dbIDs(
"unmapped_object");
169 =head2 list_unmapped_reasons
172 Example : @unmapped_object_reason+ids =
173 @{$unmapped_object_adaptor->list_unmapped_reasons()};
174 Description: Gets an array of
internal ids
for all unmapped_objects in the current db
175 Returntype : list of ints
182 sub list_unmapped_reasons {
185 return $self->_list_dbIDs(
"unmapped_reason");
191 # Arg [1] : StatementHandle $sth
193 # Description: PROTECTED implementation of abstract superclass method.
194 # responsible for the creation of UnmappedObjects
195 # Returntype : listref of Bio::EnsEMBL::UnmappedObjects
201 my ($self, $sth) = @_;
203 my($unmapped_object_id, $type, $analysis_id, $external_db_id, $identifier,
204 $unmapped_reason_id, $query_score, $target_score, $ensembl_id,
205 $ensembl_object_type, $summary, $full_desc);
207 $sth->bind_columns(\$unmapped_object_id,\$type, \$analysis_id,
208 \$external_db_id, \$identifier, \$unmapped_reason_id,
209 \$query_score, \$target_score, \$ensembl_id,
210 \$ensembl_object_type, \$summary, \$full_desc);
212 my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
215 while($sth->fetch()) {
216 my $analysis = $analysis_adaptor->fetch_by_dbID($analysis_id);
218 #print "$identifier\n";
221 $self->_create_feature(
222 'Bio::EnsEMBL::UnmappedObject', {
223 -unmapped_object_id => $unmapped_object_id,
224 -unmapped_reason_id => $unmapped_reason_id,
226 -analysis => $analysis,
227 -external_db_id => $external_db_id,
228 -identifier => $identifier,
229 -query_score => $query_score,
230 -target_score => $target_score,
231 -ensembl_id => $ensembl_id,
232 -ensembl_object_type => $ensembl_object_type,
233 -summary => $summary,
234 -full_desc => $full_desc,
246 Arg [1] : list of Bio::EnsEMBL::UnmappedObjects @uo
247 the unmapped objects to store in the database
248 Example : $ou_adaptor->store(@uo);
249 Description: Stores a list of unmapped objects in the database
251 Exceptions : thrown
if no Analysis, or no list of objects to store.
258 my ($self,@uos) = @_;
260 if( scalar(@uos) == 0 ) {
261 throw(
"Must call store with list of UnmappedObjects");
265 my $db = $self->db();
266 my $analysis_adaptor = $db->get_AnalysisAdaptor();
268 my $sth_reason = $self->prepare
269 (
"INSERT INTO unmapped_reason (summary_description, full_description)".
272 my $sth_unmapped_object = $self->prepare
273 (
"INSERT INTO unmapped_object (type, analysis_id, external_db_id,
274 identifier, unmapped_reason_id, query_score, target_score,
275 ensembl_id, ensembl_object_type)".
276 " VALUES (?,?,?,?,?,?,?,?,?)");
278 my $sth_fetch_reason =
288 FEATURE:
foreach my $uo ( @uos ) {
290 if( !ref $uo || !$uo->isa(
"Bio::EnsEMBL::UnmappedObject") ) {
291 throw(
"UnmappedObject must be an Ensembl UnmappedObject, " .
292 "not a [".ref($uo).
"]");
294 if($uo->is_stored($db)){
298 my $analysis = $uo->analysis();
299 throw(
"UnmappedObject must have an analysis object.".$uo->analysis.
"\n")
if(!defined($analysis));
302 if($analysis->is_stored($db)) {
303 $analysis_id = $analysis->dbID();
306 $analysis_id = $db->get_AnalysisAdaptor->store($analysis);
311 # Check if unmapped reason is cached
312 # Check if it has been added since the cache was created
315 if(!defined($desc_to_id{$uo->{
'description'}})){
316 $sth_reason->bind_param(1,$uo->{
'summary'},SQL_VARCHAR);
317 $sth_reason->bind_param(2,$uo->{
'description'},SQL_VARCHAR);
319 if(! eval{ $sth_reason->execute(); 1 }){
320 # DBI Trace possible here?
323 $msg .=
"INSERT INTO unmapped_reason (summary_description, full_description) VALUES (";
324 $msg .= $uo->{
'summary'} .
','. $uo->{
'description'}.
')';
325 # Temporary fix for naughty cross-dependency regulation code.
327 warning(
"Query: \n$msg");
328 print STDERR
"UnmappedObject: \n";
329 print STDERR Dumper $uo;
331 $sth_fetch_reason->execute($uo->{
'description'});
333 my $unmapped_reasons = $sth_fetch_reason->fetchrow_arrayref();
334 if(! defined($unmapped_reasons)){
335 my $msg = $uo->{
'description'}.
" unable to store. Check MySQL schema, maybe PK not big enough?";
338 if(scalar @$unmapped_reasons != 1){
339 throw(
"Multiple results for this description");
341 $uo->{
'unmapped_reason_id'} = $unmapped_reasons->[0];
345 # print 'Last mohican: '.$self->last_insert_id ."\n";
346 $uo->{
'unmapped_reason_id'} = $self->last_insert_id;
350 $uo->{
'unmapped_reason_id'} = $desc_to_id{$uo->{
'description'}};
352 $sth_unmapped_object->bind_param(1,$uo->{
'type'},SQL_VARCHAR);
353 $sth_unmapped_object->bind_param(2,$uo->analysis->dbID,SQL_INTEGER);
354 $sth_unmapped_object->bind_param(3,$uo->{
'external_db_id'},SQL_INTEGER);
355 $sth_unmapped_object->bind_param(4,$uo->{
'identifier'},SQL_VARCHAR);
356 $sth_unmapped_object->bind_param(5,$uo->{
'unmapped_reason_id'},SQL_VARCHAR);
357 $sth_unmapped_object->bind_param(6,$uo->{
'query_score'},SQL_DOUBLE);
358 $sth_unmapped_object->bind_param(7,$uo->{
'target_score'},SQL_DOUBLE);
359 $sth_unmapped_object->bind_param(8,$uo->{
'ensembl_id'},SQL_INTEGER);
360 $sth_unmapped_object->bind_param(9,$uo->{
'ensembl_object_type'},SQL_VARCHAR);
361 $sth_unmapped_object->execute();
362 $uo->dbID($self->last_insert_id(
'unmapped_object_id', undef,
'unmapped_object'));
364 $sth_reason->finish();
369 =head2 fetch_all_by_type
371 Arg [1] :
string type. The type of unmapped objects
372 Example : @unmapped_object = @{$uoa->fetch_all_by_type(
'xref')};
373 Description : Retrieves all the unmapped
object for a particular
374 type. e.g.
'xref',
'cDNA',
'marker'
382 sub fetch_all_by_type {
383 my ($self, $type) = @_;
386 throw(
"type argument is required");
388 $self->bind_param_generic_fetch($type,SQL_VARCHAR);
389 $self->generic_fetch(
"uo.type = ?");
393 =head2 fetch_all_by_analysis
395 Arg [1] :
Bio:EnsEMBL::Analysis
object
396 Arg [2] : (optional)
string database name
397 Example : @unmapped_object = @{$uoa->fetch_all_by_analysis($analysis)};
398 Description : Retrieves all the unmapped
object for a particular
399 analysis type with the the option of a particular
402 Exceptions : thorws
if first argument is not an anaylisi
object
408 sub fetch_all_by_analysis {
409 my ($self, $analysis,$dbname) = @_;
412 throw(
"analysis argument is required");
414 $self->bind_param_generic_fetch($analysis->dbID,SQL_INTEGER);
415 my $constraint =
"uo.analysis_id = ?";
416 if(defined($dbname)){
418 my $sth = $self->prepare(
'select external_db_id from external_db where db_name like "'.
421 $sth->bind_columns(\$db_id);
423 if(!defined($db_id) or $db_id == 0){
424 throw(
"$dbname could not be found in the external database table\n");
426 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
427 $constraint .=
" AND uo.external_db_id = ?";
429 $self->generic_fetch($constraint);
433 =head2 fetch_by_identifier
435 Arg [1] :
string type. The type of unmapped objects
436 Arg [2] : (optional)
string database name
437 Example : @unmapped_object = @{$uoa->fetch_by_identifier(
'Q123345')};
438 Description : Retrieves the unmapped
object for a particular
447 sub fetch_by_identifier {
448 my ($self, $identifier, $dbname) = @_;
450 unless($identifier) {
451 throw(
"identifier argument is required");
453 $self->bind_param_generic_fetch($identifier,SQL_VARCHAR);
454 my $constraint =
'uo.identifier like ?';
456 if(defined($dbname)){
458 my $sth = $self->prepare(
'select external_db_id from external_db where db_name like "'.
461 $sth->bind_columns(\$db_id);
463 if(!defined($db_id) or $db_id == 0){
464 throw(
"$dbname could not be found in the external database table\n");
466 $self->bind_param_generic_fetch($db_id,SQL_INTEGER);
467 $constraint .=
" AND uo.external_db_id = ?";
469 return $self->generic_fetch($constraint);
472 =head2 fetch_all_by_object_type_id
474 Arg [1] :
string - The
object type of the ensembl
object e.g. Gene
475 Arg [2] :
int - The
internal dbID of the ensembl
object
476 Example : my @unmapped_objects = @{$uoa->fetch_all_by_object_type_id(
'Gene', 12341)};
477 Description : Retrieves the unmapped objects
for a particular ensembl
object
478 This is a base method which should be called by wrapper methods
479 defining the correct
object type e.g. $uoa->fetch_all_by_Gene($gene)
481 Exceptions : Throws
if arguments are not defined
487 sub fetch_all_by_object_type_id {
488 my ($self, $object_type, $dbid) = @_;
490 if(! ($object_type && $dbid)){
491 throw(
"object_type and dbid arguments required");
494 $self->bind_param_generic_fetch($object_type, SQL_VARCHAR);
495 $self->bind_param_generic_fetch($dbid, SQL_INTEGER);
497 my $constraint =
'uo.ensembl_object_type=? and uo.ensembl_id=?';
499 return $self->generic_fetch($constraint);