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

3
  Copyright (c) 1999-2010 The European Bioinformatics Institute and
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

    http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <ensembl-dev@ebi.ac.uk>.

  Questions may also be sent to the Ensembl help desk at
  <helpdesk@ensembl.org>.

=cut
20
21
22

=head1 NAME

23
24
Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor - Abstract Base class for
AlignFeatureAdaptors
25
26
27

=head1 SYNOPSIS

28
29
Abstract class, should not be instantiated.  Implementation of abstract
methods must be performed by subclasses.
30
31
32

=head1 DESCRIPTION

33
This is a base adaptor for the align feature adaptors
34
DnaAlignFeatureAdaptor and ProteinAlignFeatureAdaptor.
35

Graham McVicker's avatar
Graham McVicker committed
36
=head1 METHODS
37
38
39
40

=cut

package Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
41
use vars qw(@ISA @EXPORT);
42
43
use strict;

44
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
45

46
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
47

48
@EXPORT = (@{$DBI::EXPORT_TAGS{'sql_types'}});
49

50
51
52
53
54
=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 
55
               A lower bound for the hcoverage of feats to obtain.
56
  Arg [3]    : (optional) string $logic_name
57
58
59
60
61
62
63
64
65
66
               The logic name of the type of features to obtain.
  Example    : @feats =
                $adaptor->fetch_all_by_Slice_and_hcoverage( $slice, 50.0 );
  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
67
  Exceptions : none
68
69
70
71
72
73
  Caller     : general
  Status     : At Risk

=cut

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

76
77
  my $constraint;
  if ( defined($hcoverage) ) {
78
79
80
    $constraint = "hcoverage > $hcoverage";
  }

81
82
83
  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
84
85
}

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
=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.
  Example    : @feats =
                $adaptor->fetch_all_by_Slice_and_external_db( $slice, 'EMBL' );
  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",
135
136
137
138
                            $edb_alias,
                            $self->dbc()->db_handle()
                              ->quote( $external_db_name, SQL_VARCHAR )
  );
139
140
141
142
143

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

145
=head2 fetch_all_by_Slice_and_pid
146

147
148
149
  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice from which to obtain align features.
  Arg [2]    : (optional) float $pid 
150
151
               A lower bound for the percentage identity of features
               to obtain.
152
  Arg [3]    : (optional) string $logic_name
153
154
155
156
157
158
159
160
161
               The logic name of the type of features to obtain.
  Example    : @feats = $adaptor->fetch_all_by_Slice_and_pid( $slice, 50.0 );
  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
162
  Exceptions : none
163
  Caller     : general
164
  Status     : Stable
165
166
167

=cut

168
sub fetch_all_by_Slice_and_pid {
169
  my ( $self, $slice, $pid, $logic_name ) = @_;
170

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

175
176
177
  #  if(defined $pid) {
  #    $constraint = "${alias}.perc_ident > $pid";
  #  }
178

179
180
  my $constraint;
  if ( defined($pid) ) {
181
182
183
    $constraint = sprintf( "perc_ident > %s",
                           $self->dbc()->db_handle()
                             ->quote( $pid, SQL_FLOAT ) );
184
  }
185

186
187
188
  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
189
}
190
191


192
193
194
=head2 fetch_all_by_hit_name

  Arg [1]    : string $hit_name
195
               The hit_name of the features to obtain
Glenn Proctor's avatar
Glenn Proctor committed
196
  Arg [2]    : (optional) string $logic_name
197
198
199
200
201
202
203
204
               The analysis logic name of the type of features to
               obtain.
  Example    : @feats =
                $adaptor->fetch_all_by_hit_name( $name, $logic_name );
  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.
205
206
207
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
  Exceptions : thrown if hit_name is not defined
  Caller     : general
208
  Status     : Stable
209
210
211

=cut

212
213
214
215
216
217
sub fetch_all_by_hit_name {
  my ( $self, $hit_name, $logic_name ) = @_;

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

219
220
221
  # Construct a constraint like 't1.hit_name = "123"'
  my @tabs = $self->_tables();
  my ( $name, $syn ) = @{ $tabs[0] };
222

223
  my $constraint = sprintf( "%s.hit_name = %s",
224
225
           $syn,
           $self->dbc()->db_handle()->quote( $hit_name, SQL_VARCHAR ) );
226
227

  if ( defined($logic_name) ) {
228
    # Add the $logic_name constraint
229
230
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
231
  }
232

233
234
235
236
  return $self->generic_fetch($constraint);
}


237
238
239
=head2 fetch_all_by_hit_name_unversioned

  Arg [1]    : string $hit_name
240
241
242
               The beginning of the hit_name of the features to
               obtain, e.g. AA768786 would retrieve AA768786.1,
               AA768786.2 etc.
243
  Arg [2]    : (optional) string $logic_name
244
245
246
247
248
249
250
251
               The analysis logic name of the type of features to
               obtain.
  Example    : @feats =
                $adaptor->fetch_all_by_hit_name( $name, $logic_name );
  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.
252
253
254
255
256
257
258
259
  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 {
260
261
262
263
264
  my ( $self, $hit_name, $logic_name ) = @_;

  if ( !defined($hit_name) ) {
    throw("hit_name argument is required");
  }
265
266
267

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

270
  my $constraint = sprintf( "%s.hit_name LIKE %s",
271
272
    $syn,
    $self->dbc()->db_handle()->quote( $hit_name . '.%', SQL_VARCHAR ) );
273
274

  if ( defined($logic_name) ) {
275
    # Add the $logic_name constraint
276
277
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
278
  }
279

280
281
282
283
  return $self->generic_fetch($constraint);
}


284

285
=head2 fetch_all_by_RawContig_and_pid
286

287
  Description: DEPRECATED use fetch_all_by_Slice_and_pid instead
288
289
290

=cut

291
292
sub fetch_all_by_RawContig_and_pid {
  my($self, $contig, $pid, $logic_name) = @_;
293

294
  my $constraint;
295
296
297
298
299
300
301
302
303

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

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

304
305
306
307
  return $self->fetch_all_by_RawContig_constraint($contig, 
						  $constraint, 
						  $logic_name);
}
308
309
310
311




312
313
##implemented by subclasses:
# store
314
# _tables
315
316
# _columns
# _obj_from_hashref
317
318


319

320
1;