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

Andy Yates's avatar
Andy Yates committed
3
  Copyright (c) 1999-2012 The European Bioinformatics Institute and
4
5
6
7
8
9
10
11
12
13
  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
14
  developers list at <dev@ensembl.org>.
15
16
17
18
19

  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
               The logic name of the type of features to obtain.
58
59
60
  Example    : @feats = @{
                $adaptor->fetch_all_by_Slice_and_hcoverage( $slice,
                  50.0 ) };
61
62
63
64
65
66
67
  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
68
  Exceptions : none
69
70
71
72
73
74
  Caller     : general
  Status     : At Risk

=cut

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

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

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

87
88
89
90
91
92
93
94
95
=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.
96
97
98
  Example    : @feats = @{
                  $adaptor->fetch_all_by_Slice_and_external_db( $slice,
                    'EMBL' ) };
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
135
136
  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",
137
138
139
140
                            $edb_alias,
                            $self->dbc()->db_handle()
                              ->quote( $external_db_name, SQL_VARCHAR )
  );
141
142
143
144
145

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

147
=head2 fetch_all_by_Slice_and_pid
148

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

=cut

171
sub fetch_all_by_Slice_and_pid {
172
  my ( $self, $slice, $pid, $logic_name ) = @_;
173

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

178
179
180
  #  if(defined $pid) {
  #    $constraint = "${alias}.perc_ident > $pid";
  #  }
181

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

189
190
191
  return
    $self->fetch_all_by_Slice_constraint( $slice, $constraint,
                                          $logic_name );
192
}
193
194


195
196
197
=head2 fetch_all_by_hit_name

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

=cut

216
217
218
219
220
221
sub fetch_all_by_hit_name {
  my ( $self, $hit_name, $logic_name ) = @_;

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

223
224
225
  # Construct a constraint like 't1.hit_name = "123"'
  my @tabs = $self->_tables();
  my ( $name, $syn ) = @{ $tabs[0] };
226

227
  my $constraint = sprintf( "%s.hit_name = %s",
228
229
           $syn,
           $self->dbc()->db_handle()->quote( $hit_name, SQL_VARCHAR ) );
230
231

  if ( defined($logic_name) ) {
232
    # Add the $logic_name constraint
233
234
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
235
  }
236

237
238
239
240
  return $self->generic_fetch($constraint);
}


241
242
243
=head2 fetch_all_by_hit_name_unversioned

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

  if ( !defined($hit_name) ) {
    throw("hit_name argument is required");
  }
270
  $hit_name =~ s/_/\\_/;
271
272
273

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

276
  my $constraint = sprintf( "%s.hit_name LIKE %s",
277
278
    $syn,
    $self->dbc()->db_handle()->quote( $hit_name . '.%', SQL_VARCHAR ) );
279
280

  if ( defined($logic_name) ) {
281
    # Add the $logic_name constraint
282
283
    $constraint =
      $self->_logic_name_to_constraint( $constraint, $logic_name );
284
  }
285

286
287
288
289
  return $self->generic_fetch($constraint);
}


290

291
=head2 fetch_all_by_RawContig_and_pid
292

293
  Description: DEPRECATED use fetch_all_by_Slice_and_pid instead
294
295
296

=cut

297
298
sub fetch_all_by_RawContig_and_pid {
  my($self, $contig, $pid, $logic_name) = @_;
299

300
  my $constraint;
301
302
303
304
305
306
307
308
309

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

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

310
311
312
313
  return $self->fetch_all_by_RawContig_constraint($contig, 
						  $constraint, 
						  $logic_name);
}
314
315
316
317




318
319
##implemented by subclasses:
# store
320
# _tables
321
322
# _columns
# _obj_from_hashref
323
324


325

326
1;