Archive Ensembl HomeArchive Ensembl Home
BaseAlignFeatureAdaptor.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::DBSQL::BaseAlignFeatureAdaptor - Abstract Base class for
00024 AlignFeatureAdaptors
00025 
00026 =head1 SYNOPSIS
00027 
00028 Abstract class, should not be instantiated.  Implementation of abstract
00029 methods must be performed by subclasses.
00030 
00031 =head1 DESCRIPTION
00032 
00033 This is a base adaptor for the align feature adaptors
00034 DnaAlignFeatureAdaptor and ProteinAlignFeatureAdaptor.
00035 
00036 =head1 METHODS
00037 
00038 =cut
00039 
00040 package Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
00041 use vars qw(@ISA @EXPORT);
00042 use strict;
00043 
00044 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
00045 
00046 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
00047 
00048 @EXPORT = (@{$DBI::EXPORT_TAGS{'sql_types'}});
00049 
00050 =head2 fetch_all_by_Slice_and_hcoverage
00051 
00052   Arg [1]    : Bio::EnsEMBL::Slice $slice
00053                The slice from which to obtain align features.
00054   Arg [2]    : (optional) float $hcoverage 
00055                A lower bound for the hcoverage of feats to obtain.
00056   Arg [3]    : (optional) string $logic_name
00057                The logic name of the type of features to obtain.
00058   Example    : @feats = @{
00059                 $adaptor->fetch_all_by_Slice_and_hcoverage( $slice,
00060                   50.0 ) };
00061   Description: Returns a listref of features created from the
00062                database which are on the Slice $slice and with a
00063                hcoverage greater than $hcoverage.  If logic name
00064                is defined, only features with an analysis of type
00065                $logic_name will be returned.
00066   Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
00067                in Slice coordinates
00068   Exceptions : none
00069   Caller     : general
00070   Status     : At Risk
00071 
00072 =cut
00073 
00074 sub fetch_all_by_Slice_and_hcoverage {
00075   my ( $self, $slice, $hcoverage, $logic_name ) = @_;
00076 
00077   my $constraint;
00078   if ( defined($hcoverage) ) {
00079     $constraint = "hcoverage > $hcoverage";
00080   }
00081 
00082   return
00083     $self->fetch_all_by_Slice_constraint( $slice, $constraint,
00084                                           $logic_name );
00085 }
00086 
00087 =head2 fetch_all_by_Slice_and_external_db
00088 
00089   Arg [1]    : Bio::EnsEMBL::Slice $slice
00090                The slice from which to obtain align features.
00091   Arg [2]    : String $external_db_name
00092                Name of the external DB to which the align features
00093                should be restricted.
00094   Arg [3]    : (optional) string $logic_name
00095                The logic name of the type of features to obtain.
00096   Example    : @feats = @{
00097                   $adaptor->fetch_all_by_Slice_and_external_db( $slice,
00098                     'EMBL' ) };
00099   Description: Returns a listref of features created from the
00100                database which are on the Slice $slice and associated
00101                with external DB $external_db_name.  If logic name
00102                is defined, only features with an analysis of type
00103                $logic_name will be returned.
00104   Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
00105                in Slice coordinates
00106   Exceptions : thrown if $external_db_name is not defined or if
00107                the subclass does not return a table alias for the
00108                external_db table from _tables()
00109   Caller     : general
00110   Status     : At Risk
00111 
00112 =cut
00113 
00114 sub fetch_all_by_Slice_and_external_db {
00115   my ( $self, $slice, $external_db_name, $logic_name ) = @_;
00116 
00117   if ( !defined($external_db_name) ) {
00118     throw("Need name of external DB to restrict to");
00119   }
00120 
00121   my @join_tables = $self->_tables();
00122 
00123   my $edb_alias;
00124   foreach my $join_table (@join_tables) {
00125     my ( $table, $table_alias ) = @{$join_table};
00126     if ( $table eq 'external_db' ) {
00127       $edb_alias = $table_alias;
00128       last;
00129     }
00130   }
00131 
00132   if ( !defined($edb_alias) ) {
00133     throw("Can not find alias for external_db table");
00134   }
00135 
00136   my $constraint = sprintf( "%s.db_name = %s",
00137                             $edb_alias,
00138                             $self->dbc()->db_handle()
00139                               ->quote( $external_db_name, SQL_VARCHAR )
00140   );
00141 
00142   return
00143     $self->fetch_all_by_Slice_constraint( $slice, $constraint,
00144                                           $logic_name );
00145 } ## end sub fetch_all_by_Slice_and_external_db
00146 
00147 =head2 fetch_all_by_Slice_and_pid
00148 
00149   Arg [1]    : Bio::EnsEMBL::Slice $slice
00150                The slice from which to obtain align features.
00151   Arg [2]    : (optional) float $pid 
00152                A lower bound for the percentage identity of features
00153                to obtain.
00154   Arg [3]    : (optional) string $logic_name
00155                The logic name of the type of features to obtain.
00156   Example    : @feats =
00157                  @{ $adaptor->fetch_all_by_Slice_and_pid( $slice, 50.0 ) };
00158   Description: Returns a listref of features created from the
00159                database which are on the Slice $slice and with a
00160                percentage identity greater than $pid.  If logic name
00161                is defined, only features with an analysis of type
00162                $logic_name will be returned.
00163   Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
00164                in Slice coordinates
00165   Exceptions : none
00166   Caller     : general
00167   Status     : Stable
00168 
00169 =cut
00170 
00171 sub fetch_all_by_Slice_and_pid {
00172   my ( $self, $slice, $pid, $logic_name ) = @_;
00173 
00174   #  #get the primary table alias
00175   #  my @tabs = $self->_tables;
00176   #  my $alias = $tabs[0]->[1];
00177 
00178   #  if(defined $pid) {
00179   #    $constraint = "${alias}.perc_ident > $pid";
00180   #  }
00181 
00182   my $constraint;
00183   if ( defined($pid) ) {
00184     $constraint = sprintf( "perc_ident > %s",
00185                            $self->dbc()->db_handle()
00186                              ->quote( $pid, SQL_FLOAT ) );
00187   }
00188 
00189   return
00190     $self->fetch_all_by_Slice_constraint( $slice, $constraint,
00191                                           $logic_name );
00192 }
00193 
00194 
00195 =head2 fetch_all_by_hit_name
00196 
00197   Arg [1]    : string $hit_name
00198                The hit_name of the features to obtain
00199   Arg [2]    : (optional) string $logic_name
00200                The analysis logic name of the type of features to
00201                obtain.
00202   Example    : @feats =
00203                  @{ $adaptor->fetch_all_by_hit_name( $name,
00204                    $logic_name ); }
00205   Description: Returns a listref of features created from the
00206                database which correspond to the given hit_name.  If
00207                logic name is defined, only features with an analysis
00208                of type $logic_name will be returned.
00209   Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
00210   Exceptions : thrown if hit_name is not defined
00211   Caller     : general
00212   Status     : Stable
00213 
00214 =cut
00215 
00216 sub fetch_all_by_hit_name {
00217   my ( $self, $hit_name, $logic_name ) = @_;
00218 
00219   if ( !defined($hit_name) ) {
00220     throw("hit_name argument is required");
00221   }
00222 
00223   # Construct a constraint like 't1.hit_name = "123"'
00224   my @tabs = $self->_tables();
00225   my ( $name, $syn ) = @{ $tabs[0] };
00226 
00227   my $constraint = sprintf( "%s.hit_name = %s",
00228            $syn,
00229            $self->dbc()->db_handle()->quote( $hit_name, SQL_VARCHAR ) );
00230 
00231   if ( defined($logic_name) ) {
00232     # Add the $logic_name constraint
00233     $constraint =
00234       $self->_logic_name_to_constraint( $constraint, $logic_name );
00235   }
00236 
00237   return $self->generic_fetch($constraint);
00238 }
00239 
00240 
00241 =head2 fetch_all_by_hit_name_unversioned
00242 
00243   Arg [1]    : string $hit_name
00244                The beginning of the hit_name of the features to
00245                obtain, e.g. AA768786 would retrieve AA768786.1,
00246                AA768786.2 etc.
00247   Arg [2]    : (optional) string $logic_name
00248                The analysis logic name of the type of features to
00249                obtain.
00250   Example    : @feats =
00251                   @{ $adaptor->fetch_all_by_hit_name( $name,
00252                     $logic_name ) };
00253   Description: Returns a listref of features created from the
00254                database which start with the given hit_name.  If
00255                logic name is defined, only features with an analysis
00256                of type $logic_name will be returned.
00257   Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
00258   Exceptions : thrown if hit_name is not defined
00259   Caller     : general
00260   Status     : At risk
00261 
00262 =cut
00263 
00264 sub fetch_all_by_hit_name_unversioned {
00265   my ( $self, $hit_name, $logic_name ) = @_;
00266 
00267   if ( !defined($hit_name) ) {
00268     throw("hit_name argument is required");
00269   }
00270 
00271   #construct a constraint like 't1.hit_name = "123"'
00272   my @tabs = $self->_tables;
00273   my ( $name, $syn ) = @{ $tabs[0] };
00274 
00275   my $constraint = sprintf( "%s.hit_name LIKE %s",
00276     $syn,
00277     $self->dbc()->db_handle()->quote( $hit_name . '.%', SQL_VARCHAR ) );
00278 
00279   if ( defined($logic_name) ) {
00280     # Add the $logic_name constraint
00281     $constraint =
00282       $self->_logic_name_to_constraint( $constraint, $logic_name );
00283   }
00284 
00285   return $self->generic_fetch($constraint);
00286 }
00287 
00288 
00289 
00290 =head2 fetch_all_by_RawContig_and_pid
00291 
00292   Description: DEPRECATED use fetch_all_by_Slice_and_pid instead
00293 
00294 =cut
00295 
00296 sub fetch_all_by_RawContig_and_pid {
00297   my($self, $contig, $pid, $logic_name) = @_;
00298 
00299   my $constraint;
00300 
00301   #get the primary table alias
00302   my @tabs = $self->_tables;
00303   my $alias = $tabs[0]->[1];
00304 
00305   if(defined $pid) {
00306     $constraint = "${alias}.perc_ident > $pid";
00307   }
00308 
00309   return $self->fetch_all_by_RawContig_constraint($contig, 
00310                           $constraint, 
00311                           $logic_name);
00312 }
00313 
00314 
00315 
00316 
00317 ##implemented by subclasses:
00318 # store
00319 # _tables
00320 # _columns
00321 # _obj_from_hashref
00322 
00323 
00324 
00325 1;