BaseAlignFeatureAdaptor.pm 9.77 KB
Newer Older
1
=head1 LICENSE
2

3
Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4

5 6 7 8 9 10 11 12 13 14 15 16 17
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut
18 19 20 21 22


=head1 CONTACT

  Please email comments or questions to the public Ensembl
Magali Ruffier's avatar
Magali Ruffier committed
23
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
24 25

  Questions may also be sent to the Ensembl help desk at
Magali Ruffier's avatar
Magali Ruffier committed
26
  <http://www.ensembl.org/Help/Contact>.
27 28

=cut
29 30 31

=head1 NAME

32 33
Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor - Abstract Base class for
AlignFeatureAdaptors
34 35 36

=head1 SYNOPSIS

37 38
Abstract class, should not be instantiated.  Implementation of abstract
methods must be performed by subclasses.
39 40 41

=head1 DESCRIPTION

42
This is a base adaptor for the align feature adaptors
43
DnaAlignFeatureAdaptor and ProteinAlignFeatureAdaptor.
44

Graham McVicker's avatar
Graham McVicker committed
45
=head1 METHODS
46 47 48 49

=cut

package Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
50
use vars qw(@ISA @EXPORT);
51 52
use strict;

53
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
54

55
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
56

57
@EXPORT = (@{$DBI::EXPORT_TAGS{'sql_types'}});
58

59 60 61 62 63
=head2 fetch_all_by_Slice_and_hcoverage

  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice from which to obtain align features.
  Arg [2]    : (optional) float $hcoverage 
64
               A lower bound for the hcoverage of feats to obtain.
65
  Arg [3]    : (optional) string $logic_name
66
               The logic name of the type of features to obtain.
67 68 69
  Example    : @feats = @{
                $adaptor->fetch_all_by_Slice_and_hcoverage( $slice,
                  50.0 ) };
70 71 72 73 74 75 76
  Description: Returns a listref of features created from the
               database which are on the Slice $slice and with a
               hcoverage greater than $hcoverage.  If logic name
               is defined, only features with an analysis of type
               $logic_name will be returned.
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
               in Slice coordinates
77
  Exceptions : none
78 79 80 81 82 83
  Caller     : general
  Status     : At Risk

=cut

sub fetch_all_by_Slice_and_hcoverage {
84
  my ( $self, $slice, $hcoverage, $logic_name ) = @_;
85

86 87
  my $constraint;
  if ( defined($hcoverage) ) {
88 89 90
    $constraint = "hcoverage > $hcoverage";
  }

91 92 93
  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
94 95
}

96 97 98 99 100 101 102 103 104
=head2 fetch_all_by_Slice_and_external_db

  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice from which to obtain align features.
  Arg [2]    : String $external_db_name
               Name of the external DB to which the align features
               should be restricted.
  Arg [3]    : (optional) string $logic_name
               The logic name of the type of features to obtain.
105 106 107
  Example    : @feats = @{
                  $adaptor->fetch_all_by_Slice_and_external_db( $slice,
                    'EMBL' ) };
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  Description: Returns a listref of features created from the
               database which are on the Slice $slice and associated
               with external DB $external_db_name.  If logic name
               is defined, only features with an analysis of type
               $logic_name will be returned.
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
               in Slice coordinates
  Exceptions : thrown if $external_db_name is not defined or if
               the subclass does not return a table alias for the
               external_db table from _tables()
  Caller     : general
  Status     : At Risk

=cut

sub fetch_all_by_Slice_and_external_db {
  my ( $self, $slice, $external_db_name, $logic_name ) = @_;

  if ( !defined($external_db_name) ) {
    throw("Need name of external DB to restrict to");
  }

  my @join_tables = $self->_tables();

  my $edb_alias;
  foreach my $join_table (@join_tables) {
    my ( $table, $table_alias ) = @{$join_table};
    if ( $table eq 'external_db' ) {
      $edb_alias = $table_alias;
      last;
    }
  }

  if ( !defined($edb_alias) ) {
    throw("Can not find alias for external_db table");
  }

  my $constraint = sprintf( "%s.db_name = %s",
146 147 148 149
                            $edb_alias,
                            $self->dbc()->db_handle()
                              ->quote( $external_db_name, SQL_VARCHAR )
  );
150 151 152 153 154

  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
} ## end sub fetch_all_by_Slice_and_external_db
155

156
=head2 fetch_all_by_Slice_and_pid
157

158 159 160
  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice from which to obtain align features.
  Arg [2]    : (optional) float $pid 
161 162
               A lower bound for the percentage identity of features
               to obtain.
163
  Arg [3]    : (optional) string $logic_name
164
               The logic name of the type of features to obtain.
165 166
  Example    : @feats =
                 @{ $adaptor->fetch_all_by_Slice_and_pid( $slice, 50.0 ) };
167 168 169 170 171 172 173
  Description: Returns a listref of features created from the
               database which are on the Slice $slice and with a
               percentage identity greater than $pid.  If logic name
               is defined, only features with an analysis of type
               $logic_name will be returned.
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
               in Slice coordinates
174
  Exceptions : none
175
  Caller     : general
176
  Status     : Stable
177 178 179

=cut

180
sub fetch_all_by_Slice_and_pid {
181
  my ( $self, $slice, $pid, $logic_name ) = @_;
182

183 184 185
  #  #get the primary table alias
  #  my @tabs = $self->_tables;
  #  my $alias = $tabs[0]->[1];
186

187 188 189
  #  if(defined $pid) {
  #    $constraint = "${alias}.perc_ident > $pid";
  #  }
190

191 192
  my $constraint;
  if ( defined($pid) ) {
193 194 195
    $constraint = sprintf( "perc_ident > %s",
                           $self->dbc()->db_handle()
                             ->quote( $pid, SQL_FLOAT ) );
196
  }
197

198 199 200
  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
201
}
202 203


204 205 206
=head2 fetch_all_by_hit_name

  Arg [1]    : string $hit_name
207
               The hit_name of the features to obtain
Glenn Proctor's avatar
Glenn Proctor committed
208
  Arg [2]    : (optional) string $logic_name
209 210 211
               The analysis logic name of the type of features to
               obtain.
  Example    : @feats =
212 213
                 @{ $adaptor->fetch_all_by_hit_name( 'AK078491.1',
                   'vertrna' ); }
214 215 216 217
  Description: Returns a listref of features created from the
               database which correspond to the given hit_name.  If
               logic name is defined, only features with an analysis
               of type $logic_name will be returned.
218 219 220
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
  Exceptions : thrown if hit_name is not defined
  Caller     : general
221
  Status     : Stable
222 223 224

=cut

225 226 227 228 229 230
sub fetch_all_by_hit_name {
  my ( $self, $hit_name, $logic_name ) = @_;

  if ( !defined($hit_name) ) {
    throw("hit_name argument is required");
  }
231

232 233 234
  # Construct a constraint like 't1.hit_name = "123"'
  my @tabs = $self->_tables();
  my ( $name, $syn ) = @{ $tabs[0] };
235

236
  my $constraint = sprintf( "%s.hit_name = %s",
237 238
           $syn,
           $self->dbc()->db_handle()->quote( $hit_name, SQL_VARCHAR ) );
239 240

  if ( defined($logic_name) ) {
241
    # Add the $logic_name constraint
242 243
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
244
  }
245

246 247 248 249
  return $self->generic_fetch($constraint);
}


250 251 252
=head2 fetch_all_by_hit_name_unversioned

  Arg [1]    : string $hit_name
253 254 255
               The beginning of the hit_name of the features to
               obtain, e.g. AA768786 would retrieve AA768786.1,
               AA768786.2 etc.
256
  Arg [2]    : (optional) string $logic_name
257 258 259
               The analysis logic name of the type of features to
               obtain.
  Example    : @feats =
260 261
                  @{ $adaptor->fetch_all_by_hit_name( $name,
                    $logic_name ) };
262 263 264 265
  Description: Returns a listref of features created from the
               database which start with the given hit_name.  If
               logic name is defined, only features with an analysis
               of type $logic_name will be returned.
266 267 268 269 270 271 272 273
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
  Exceptions : thrown if hit_name is not defined
  Caller     : general
  Status     : At risk

=cut

sub fetch_all_by_hit_name_unversioned {
274 275 276 277 278
  my ( $self, $hit_name, $logic_name ) = @_;

  if ( !defined($hit_name) ) {
    throw("hit_name argument is required");
  }
279
  $hit_name =~ s/_/\\_/;
280 281 282

  #construct a constraint like 't1.hit_name = "123"'
  my @tabs = $self->_tables;
283
  my ( $name, $syn ) = @{ $tabs[0] };
284

285
  my $constraint = sprintf( "%s.hit_name LIKE %s",
286 287
    $syn,
    $self->dbc()->db_handle()->quote( $hit_name . '.%', SQL_VARCHAR ) );
288 289

  if ( defined($logic_name) ) {
290
    # Add the $logic_name constraint
291 292
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
293
  }
294

295 296 297 298
  return $self->generic_fetch($constraint);
}


299

300
=head2 fetch_all_by_RawContig_and_pid
301

302
  Description: DEPRECATED use fetch_all_by_Slice_and_pid instead
303 304 305

=cut

306 307
sub fetch_all_by_RawContig_and_pid {
  my($self, $contig, $pid, $logic_name) = @_;
308

309
  my $constraint;
310 311 312 313 314 315 316 317 318

  #get the primary table alias
  my @tabs = $self->_tables;
  my $alias = $tabs[0]->[1];

  if(defined $pid) {
    $constraint = "${alias}.perc_ident > $pid";
  }

319 320 321 322
  return $self->fetch_all_by_RawContig_constraint($contig, 
						  $constraint, 
						  $logic_name);
}
323 324 325 326




327 328
##implemented by subclasses:
# store
329
# _tables
330 331
# _columns
# _obj_from_hashref
332 333


334

335
1;