Archive Ensembl HomeArchive Ensembl Home
UnmappedObject.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio:EnsEMBL::UnmappedObject - A object representing why a particular entity
00024 was NOT mapped to the ensembl.
00025 
00026 =head1 SYNOPSIS
00027 
00028   use Bio::EnsEMBL::UnmappedObject;
00029 
00030   my $uo = Bio::EnsEMBL::UnmappedObject->new(
00031     -type           => 'xref',
00032     -analysis       => $analysis,
00033     -external_db_id => 4100,
00034     -identifier     => "Q12345",
00035     -query_score    => 45.5,
00036     -target_score   => 29.2,
00037     -ensembl_id     => 122346,
00038     -ensembl_type   => "Translation",
00039     -summary        => "match failed for exonerate",
00040     -full_desc      => "match failed for the xref exonerate run "
00041       . "as match was below threshold of 90"
00042   );
00043 
00044 =head1 DESCRIPTION
00045 
00046 UnmappedObjects represent entities NOT mapped to ensembl. Therefore this
00047 should help users to find out why certain accessions etc can not be
00048 found.
00049 
00050 =head1 METHODS
00051 
00052 =cut
00053 
00054 
00055 
00056 package Bio::EnsEMBL::UnmappedObject;
00057 
00058 use strict;
00059 use warnings;
00060 
00061 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00062 use Bio::EnsEMBL::Utils::Exception qw(throw);
00063 use Bio::EnsEMBL::Storable;
00064 
00065 use vars qw(@ISA);
00066 
00067 @ISA = qw(Bio::EnsEMBL::Storable);
00068 
00069 
00070 =head2 new
00071 
00072   Arg [TYPE]           : the type of mapping i.e. 'xref','cDNA' 
00073   Arg [ANALYSIS]       : Analysis object. 
00074   Arg [EXTERNAL_DB_ID] : id for the external db id this identifier is from
00075   Arg [IDENTIFIER]     : name of the identifier i.e. accession
00076   Arg [QUERY_SCORE]    : (optional) The query score
00077   Arg [TARGET_SCORE]   : (optional) The target score
00078   Arg [SUMMARY]        : The summary reason for not mapping.
00079   Arg [FULL_DESC]      : The Full description of why it did not map.
00080   Arg [ENSEMBL_ID]     : (optional) internal ensembl id for the best match
00081   Arg [ENSEMBL_OBJECT_TYPE] : (optional) the type of object for the best match
00082   Example              : see SYNOPSIS
00083   Returntype           : Bio::EnsEMBL::UnmappedObject
00084   Exceptions           : If any of the none optional args are missing
00085   Caller               : general
00086   Status               : At Risk
00087 
00088 =cut
00089 
00090 sub new {
00091   my $caller = shift;
00092 
00093   #allow constructor to be called as class or object method
00094   my $class = ref($caller) || $caller;
00095 
00096 
00097 
00098   my ($dbID, $unmapped_reason_id, $type, $analysis, $ex_db_id, $identifier, 
00099       $query_score, $target_score, $summary, $full_desc,
00100       $ensembl_id, $ensembl_object_type, $adaptor ) = 
00101     rearrange([qw(UNMAPPED_OBJECT_ID UNMAPPED_REASON_ID TYPE ANALYSIS 
00102           EXTERNAL_DB_ID IDENTIFIER QUERY_SCORE TARGET_SCORE 
00103           SUMMARY FULL_DESC ENSEMBL_ID ENSEMBL_OBJECT_TYPE ADAPTOR)], @_);
00104 
00105   my $self = $class->SUPER::new(@_);
00106   if(defined($analysis)) {
00107     if(!ref($analysis) || !$analysis->isa('Bio::EnsEMBL::Analysis')) {
00108       throw('-ANALYSIS argument must be a Bio::EnsEMBL::Analysis not '.
00109             $analysis);
00110     }
00111   }
00112   else{
00113     throw('-ANALYSIS argument must be given');
00114   }
00115   $self->{'analysis'} = $analysis;
00116   $self->{'dbID'} = $dbID if (defined($dbID));
00117   $self->{'description'} = $full_desc   || throw('FULL_DESC must be given');
00118   $self->{'summary'} = $summary         || throw('SUMMARY must be given');
00119   $self->{'type'} = $type               || throw('TYPE must be given');
00120   $self->{'external_db_id'} = $ex_db_id;
00121 
00122   if (lc($type) eq "xref") {
00123     throw('EXTERNAL_DB_ID must be given') if ! defined $ex_db_id;
00124   }
00125 
00126   $self->{'identifier'} = $identifier   || throw('IDENTIFIER must be given');
00127   $self->{'query_score'} = $query_score  if(defined($query_score));
00128   $self->{'target_score'} = $target_score  if(defined($target_score));
00129   $self->{'ensembl_id'} = $ensembl_id  if(defined($ensembl_id));
00130   $self->{'ensembl_object_type'} = $ensembl_object_type  
00131     if(defined($ensembl_object_type));
00132   $self->{'unmapped_reason_id'} = $unmapped_reason_id 
00133     if(defined($unmapped_reason_id));
00134   $self->adaptor($adaptor)  if(defined($adaptor));
00135   return $self;
00136 }
00137 
00138 =head2 new_fast
00139 
00140   Arg [...]  : none
00141   Example    : $feature = Bio::EnsEMBL::UnmappedObject->new_fast();
00142   Description: Creates a new Unmapped Object.
00143   Returntype : Bio::EnsEMBL::UnmappedObject
00144   Exceptions : none
00145   Caller     : general
00146   Status     : At Risk
00147 
00148 =cut
00149 
00150 sub new_fast{
00151   my $caller = shift;
00152 
00153   #allow constructor to be called as class or object method
00154   my $class = ref($caller) || $caller;
00155 
00156   my $self = $class->SUPER::new(@_);
00157 
00158   return $self;
00159 }
00160 
00161 =head2 description
00162 
00163   Arg [1]     : (optional) * to be set to
00164   Example     : print $unmappedObject->description."\n";
00165   Description : Basic getter/setter for description
00166   ReturnType  : String
00167   Exceptions  : none
00168   Caller      : general
00169   Status      : At Risk
00170 
00171 =cut
00172 
00173 sub description{
00174   my $self = shift;
00175 
00176   if(@_) {
00177     my $des = shift;
00178     $self->{'description'} = $des;
00179   }
00180 
00181   return $self->{'description'};
00182 }
00183 
00184 =head2 summary
00185 
00186   Arg [1]     : (optional) summary to be set to
00187   Example     : print $unmappedObject->summary."\n";
00188   Description : Basic getter/setter for summary
00189   ReturnType  : String
00190   Exceptions  : none
00191   Caller      : general
00192   Status      : At Risk
00193 
00194 =cut
00195 
00196 sub summary{
00197   my $self = shift;
00198 
00199   if(@_) {
00200     my $des = shift;
00201     $self->{'summary'} = $des;
00202   }
00203 
00204   return $self->{'summary'};
00205 }
00206 
00207 =head2 type
00208 
00209   Arg [1]     : (optional) type to be set to
00210   Example     : print $unmappedObject->type."\n";
00211   Description : Basic getter/setter for type
00212   ReturnType  : String
00213   Exceptions  : none
00214   Caller      : general
00215   Status      : At Risk
00216 
00217 =cut
00218 
00219 sub type{
00220   my $self = shift;
00221 
00222   if(@_) {
00223     my $arg = shift;
00224     $self->{'type'} = $arg;
00225   }
00226 
00227   return $self->{'type'};
00228 }
00229 
00230 =head2 ensembl_object_type
00231 
00232   Arg [1]     : (optional) ensembl object type to be set to
00233   Example     : print $unmappedObject->ensembl_object_type."\n";
00234   Description : Basic getter/setter for ensembl object type
00235   ReturnType  : String
00236   Exceptions  : none
00237   Caller      : general
00238   Status      : At Risk
00239 
00240 =cut
00241 
00242 sub ensembl_object_type{
00243   my $self = shift;
00244 
00245   if(@_) {
00246     my $arg = shift;
00247     $self->{'ensembl_object_type'} = $arg;
00248   }
00249 
00250   return $self->{'ensembl_object_type'};
00251 }
00252 
00253 =head2 ensembl_id
00254 
00255   Arg [1]     : (optional) ensembl id to be set to
00256   Example     : print $unmappedObject->ensembl_id."\n";
00257   Description : Basic getter/setter for ensembl id
00258   ReturnType  : String
00259   Exceptions  : none
00260   Caller      : general
00261   Status      : At Risk
00262 
00263 =cut
00264 
00265 sub ensembl_id{
00266   my $self = shift;
00267 
00268   if(@_) {
00269     my $arg = shift;
00270     $self->{'ensembl_id'} = $arg;
00271   }
00272 
00273   return $self->{'ensembl_id'};
00274 }
00275 
00276 =head2 external_db_id
00277 
00278   Arg [1]     : (optional) external_db_id to be set to
00279   Example     : print $unmappedObject->external_db_id."\n";
00280   Description : Basic getter/setter for external_db_id
00281   ReturnType  : int
00282   Exceptions  : none
00283   Caller      : general
00284   Status      : At Risk
00285 
00286 =cut
00287 
00288 sub external_db_id{
00289   my $self = shift;
00290 
00291   if(@_) {
00292     my $arg = shift;
00293     $self->{'external_db_id'} = $arg;
00294   }
00295   
00296   return $self->{'external_db_id'};
00297 }
00298 
00299 =head2 external_db_name
00300 
00301   Example     : print $unmappedObject->external_db_name()."\n";
00302   Description : Basic getter for external_db_name
00303   ReturnType  : int
00304   Exceptions  : none
00305   Caller      : general
00306   Status      : At Risk
00307 
00308 =cut
00309 
00310 sub external_db_name{
00311   my $self = shift;
00312 
00313   my $handle = $self->adaptor;
00314   if(defined($handle) and defined($self->{'external_db_id'})){
00315     my $sth = $handle->prepare("select db_name from external_db where external_db_id = ".$self->{'external_db_id'});
00316     $sth->execute();
00317     my $name;
00318     $sth->bind_columns(\$name);
00319     $sth->fetch();
00320     return $name;
00321   }
00322   return "";
00323 }
00324 
00325 
00326 sub stable_id{
00327   my ($self) = shift;
00328   
00329   my $handle = $self->adaptor;
00330   if(defined($handle)){
00331     my $sql = "select stable_id from ".lc($self->{'ensembl_object_type'})." where ".
00332       lc($self->{'ensembl_object_type'})."_id = ".
00333     $self->{'ensembl_id'};
00334     my $sth = $handle->prepare($sql);
00335     $sth->execute();
00336     my $name;
00337     $sth->bind_columns(\$name);
00338     $sth->fetch();
00339     return $name;
00340   }
00341   return "";
00342 }
00343                          
00344  #  my $adaptor;
00345 #  if($self->{'ensembl_object_type'} eq  "Transcript"){
00346 #    $adaptor= $self->adaptor->db->get_TranscriptAdaptor();
00347 #  }
00348 #  elsif($self->{'ensembl_object_type'} eq  "Translation"){
00349 #    $adaptor= $self->adaptor->db->get_TranslationAdaptor();
00350 #  }
00351 #  elsif($self->{'ensembl_object_type'} eq  "Gene"){
00352 #    $adaptor= $self->adaptor->db->get_GeneAdaptor();
00353 #  } 
00354 #  else{
00355 #    return undef;
00356 #  }
00357 #  my $object = $adaptor->fetch_by_dbID($self->{'ensembl_id'});
00358 #  if(defined($object)){
00359 #    return $object->stable_id;
00360 #  }
00361 #  else{
00362 #    return undef;
00363 #  }
00364 #}
00365 
00366  
00367 =head2 identifier
00368 
00369   Arg [1]     : (optional) identifier to be set to
00370   Example     : print $unmappedObject->identifier."\n";
00371   Description : Basic getter/setter for identifier
00372   ReturnType  : String
00373   Exceptions  : none
00374   Caller      : general
00375   Status      : At Risk
00376 
00377 =cut
00378 
00379 sub identifier{
00380   my $self = shift;
00381 
00382   if(@_) {
00383     my $arg = shift;
00384     $self->{'identifier'} = $arg;
00385   }
00386 
00387   return $self->{'identifier'};
00388 }
00389 
00390 =head2 query_score
00391 
00392   Arg [1]     : (optional) query_score to be set to
00393   Example     : print $unmappedObject->query_score."\n";
00394   Description : Basic getter/setter for query_score
00395   ReturnType  : float
00396   Exceptions  : none
00397   Caller      : general
00398   Status      : At Risk
00399 
00400 =cut
00401 
00402 sub query_score{
00403   my $self = shift;
00404 
00405   if(@_) {
00406     my $arg = shift;
00407     $self->{'query_score'} = $arg;
00408   }
00409 
00410   return $self->{'query_score'};
00411 }
00412 
00413 =head2 target_score
00414 
00415   Arg [1]     : (optional) target_score to be set to
00416   Example     : print $unmappedObject->target_score."\n";
00417   Description : Basic getter/setter for target_score
00418   ReturnType  : float
00419   Exceptions  : none
00420   Caller      : general
00421   Status      : At Risk
00422 
00423 =cut
00424 
00425 sub target_score{
00426   my $self = shift;
00427 
00428   if(@_) {
00429     my $arg = shift;
00430     $self->{'target_score'} = $arg;
00431   }
00432 
00433   return $self->{'target_score'};
00434 }
00435 
00436 =head2 unmapped_reason_id
00437 
00438   Arg [1]     : (optional) unmapped_reason_id to be set to
00439   Example     : print $unmappedObject->unmapped_reason_id."\n";
00440   Description : Basic getter/setter for unmapped_reason_id
00441   ReturnType  : int
00442   Exceptions  : none
00443   Caller      : general
00444   Status      : At Risk
00445 
00446 =cut
00447 
00448 sub unmapped_reason_id{
00449   my $self = shift;
00450 
00451   if(@_) {
00452     my $arg = shift;
00453     $self->{'unmapped_reason_id'} = $arg;
00454   }
00455 
00456   return $self->{'unmapped_reason_id'};
00457 }
00458 
00459 =head2 analysis
00460 
00461   Arg [1]     : (optional) analysis to be set to
00462   Example     : print $unmappedObject->analysis->logic_name."\n";
00463   Description : Basic getter/setter for analysis
00464   ReturnType  : Bio::EnsEMBL::Analysis
00465   Exceptions  : none
00466   Caller      : general
00467   Status      : At Risk
00468 
00469 =cut
00470 
00471 sub analysis {
00472   my $self = shift;
00473 
00474   if(@_) {
00475     my $an = shift;
00476     if(defined($an) && (!ref($an) || !$an->isa('Bio::EnsEMBL::Analysis'))) {
00477       throw('analysis argument must be a Bio::EnsEMBL::Analysis');
00478     }
00479     $self->{'analysis'} = $an;
00480   }
00481 
00482   return $self->{'analysis'};
00483 }
00484 
00485 1;