ensembl-hive  2.7.0
BaseAlignFeatureAdaptor.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 =cut
19 
20 
21 =head1 CONTACT
22 
23  Please email comments or questions to the public Ensembl
24  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25 
26  Questions may also be sent to the Ensembl help desk at
27  <http://www.ensembl.org/Help/Contact>.
28 
29 =cut
30 
31 =head1 NAME
32 
33 Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor - Abstract Base class for
34 AlignFeatureAdaptors
35 
36 =head1 SYNOPSIS
37 
38 Abstract class, should not be instantiated. Implementation of abstract
39 methods must be performed by subclasses.
40 
41 =head1 DESCRIPTION
42 
43 This is a base adaptor for the align feature adaptors
45 
46 =head1 METHODS
47 
48 =cut
49 
50 package Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
51 use vars qw(@ISA @EXPORT);
52 use strict;
53 
55 
57 
58 @EXPORT = (@{$DBI::EXPORT_TAGS{'sql_types'}});
59 
60 =head2 fetch_all_by_Slice_and_hcoverage
61 
62  Arg [1] : Bio::EnsEMBL::Slice $slice
63  The slice from which to obtain align features.
64  Arg [2] : (optional) float $hcoverage
65  A lower bound for the hcoverage of feats to obtain.
66  Arg [3] : (optional) string $logic_name
67  The logic name of the type of features to obtain.
68  Example : @feats = @{
69  $adaptor->fetch_all_by_Slice_and_hcoverage( $slice,
70  50.0 ) };
71  Description: Returns a listref of features created from the
72  database which are on the Slice $slice and with a
73  hcoverage greater than $hcoverage. If logic name
74  is defined, only features with an analysis of type
75  $logic_name will be returned.
76  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
77  in Slice coordinates
78  Exceptions : none
79  Caller : general
80  Status : At Risk
81 
82 =cut
83 
84 sub fetch_all_by_Slice_and_hcoverage {
85  my ( $self, $slice, $hcoverage, $logic_name ) = @_;
86 
87  my $constraint;
88  if ( defined($hcoverage) ) {
89  $constraint = "hcoverage > $hcoverage";
90  }
91 
92  return
93  $self->fetch_all_by_Slice_constraint( $slice, $constraint,
94  $logic_name );
95 }
96 
97 =head2 fetch_all_by_Slice_and_external_db
98 
99  Arg [1] : Bio::EnsEMBL::Slice $slice
100  The slice from which to obtain align features.
101  Arg [2] : String $external_db_name
102  Name of the external DB to which the align features
103  should be restricted.
104  Arg [3] : (optional) string $logic_name
105  The logic name of the type of features to obtain.
106  Example : @feats = @{
107  $adaptor->fetch_all_by_Slice_and_external_db( $slice,
108  'EMBL' ) };
109  Description: Returns a listref of features created from the
110  database which are on the Slice $slice and associated
111  with external DB $external_db_name. If logic name
112  is defined, only features with an analysis of type
113  $logic_name will be returned.
114  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
115  in Slice coordinates
116  Exceptions : thrown if $external_db_name is not defined or if
117  the subclass does not return a table alias for the
118  external_db table from _tables()
119  Caller : general
120  Status : At Risk
121 
122 =cut
123 
124 sub fetch_all_by_Slice_and_external_db {
125  my ( $self, $slice, $external_db_name, $logic_name ) = @_;
126 
127  if ( !defined($external_db_name) ) {
128  throw("Need name of external DB to restrict to");
129  }
130 
131  my @join_tables = $self->_tables();
132 
133  my $edb_alias;
134  foreach my $join_table (@join_tables) {
135  my ( $table, $table_alias ) = @{$join_table};
136  if ( $table eq 'external_db' ) {
137  $edb_alias = $table_alias;
138  last;
139  }
140  }
141 
142  if ( !defined($edb_alias) ) {
143  throw("Can not find alias for external_db table");
144  }
145 
146  my $constraint = sprintf( "%s.db_name = %s",
147  $edb_alias,
148  $self->dbc()->db_handle()
149  ->quote( $external_db_name, SQL_VARCHAR )
150  );
151 
152  return
153  $self->fetch_all_by_Slice_constraint( $slice, $constraint,
154  $logic_name );
155 } ## end sub fetch_all_by_Slice_and_external_db
156 
157 =head2 fetch_all_by_Slice_and_pid
158 
159  Arg [1] : Bio::EnsEMBL::Slice $slice
160  The slice from which to obtain align features.
161  Arg [2] : (optional) float $pid
162  A lower bound for the percentage identity of features
163  to obtain.
164  Arg [3] : (optional) string $logic_name
165  The logic name of the type of features to obtain.
166  Example : @feats =
167  @{ $adaptor->fetch_all_by_Slice_and_pid( $slice, 50.0 ) };
168  Description: Returns a listref of features created from the
169  database which are on the Slice $slice and with a
170  percentage identity greater than $pid. If logic name
171  is defined, only features with an analysis of type
172  $logic_name will be returned.
173  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
174  in Slice coordinates
175  Exceptions : none
176  Caller : general
177  Status : Stable
178 
179 =cut
180 
181 sub fetch_all_by_Slice_and_pid {
182  my ( $self, $slice, $pid, $logic_name ) = @_;
183 
184  # #get the primary table alias
185  # my @tabs = $self->_tables;
186  # my $alias = $tabs[0]->[1];
187 
188  # if(defined $pid) {
189  # $constraint = "${alias}.perc_ident > $pid";
190  # }
191 
192  my $constraint;
193  if ( defined($pid) ) {
194  $constraint = sprintf( "perc_ident > %s",
195  $self->dbc()->db_handle()
196  ->quote( $pid, SQL_FLOAT ) );
197  }
198 
199  return
200  $self->fetch_all_by_Slice_constraint( $slice, $constraint,
201  $logic_name );
202 }
203 
204 
205 =head2 fetch_all_by_hit_name
206 
207  Arg [1] : string $hit_name
208  The hit_name of the features to obtain
209  Arg [2] : (optional) string $logic_name
210  The analysis logic name of the type of features to
211  obtain.
212  Example : @feats =
213  @{ $adaptor->fetch_all_by_hit_name( 'AK078491.1',
214  'vertrna' ); }
215  Description: Returns a listref of features created from the
216  database which correspond to the given hit_name. If
217  logic name is defined, only features with an analysis
218  of type $logic_name will be returned.
219  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
220  Exceptions : thrown if hit_name is not defined
221  Caller : general
222  Status : Stable
223 
224 =cut
225 
226 sub fetch_all_by_hit_name {
227  my ( $self, $hit_name, $logic_name ) = @_;
228 
229  if ( !defined($hit_name) ) {
230  throw("hit_name argument is required");
231  }
232 
233  # Construct a constraint like 't1.hit_name = "123"'
234  my @tabs = $self->_tables();
235  my ( $name, $syn ) = @{ $tabs[0] };
236 
237  my $constraint = sprintf( "%s.hit_name = %s",
238  $syn,
239  $self->dbc()->db_handle()->quote( $hit_name, SQL_VARCHAR ) );
240 
241  if ( defined($logic_name) ) {
242  # Add the $logic_name constraint
243  $constraint =
244  $self->_logic_name_to_constraint( $constraint, $logic_name );
245  }
246 
247  return $self->generic_fetch($constraint);
248 }
249 
250 
251 =head2 fetch_all_by_hit_name_unversioned
252 
253  Arg [1] : string $hit_name
254  The beginning of the hit_name of the features to
255  obtain, e.g. AA768786 would retrieve AA768786.1,
256  AA768786.2 etc.
257  Arg [2] : (optional) string $logic_name
258  The analysis logic name of the type of features to
259  obtain.
260  Example : @feats =
261  @{ $adaptor->fetch_all_by_hit_name( $name,
262  $logic_name ) };
263  Description: Returns a listref of features created from the
264  database which start with the given hit_name. If
265  logic name is defined, only features with an analysis
266  of type $logic_name will be returned.
267  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
268  Exceptions : thrown if hit_name is not defined
269  Caller : general
270  Status : At risk
271 
272 =cut
273 
274 sub fetch_all_by_hit_name_unversioned {
275  my ( $self, $hit_name, $logic_name ) = @_;
276 
277  if ( !defined($hit_name) ) {
278  throw("hit_name argument is required");
279  }
280  $hit_name =~ s/_/\\_/;
281 
282  #construct a constraint like 't1.hit_name = "123"'
283  my @tabs = $self->_tables;
284  my ( $name, $syn ) = @{ $tabs[0] };
285 
286  my $constraint = sprintf( "%s.hit_name LIKE %s",
287  $syn,
288  $self->dbc()->db_handle()->quote( $hit_name . '.%', SQL_VARCHAR ) );
289 
290  if ( defined($logic_name) ) {
291  # Add the $logic_name constraint
292  $constraint =
293  $self->_logic_name_to_constraint( $constraint, $logic_name );
294  }
295 
296  return $self->generic_fetch($constraint);
297 }
298 
299 
300 ##implemented by subclasses:
301 # store
302 # _tables
303 # _columns
304 # _obj_from_hashref
305 
306 
307 
308 1;
Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor
Definition: ProteinAlignFeatureAdaptor.pm:18
Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor
Definition: BaseFeatureAdaptor.pm:24
Bio::EnsEMBL::Slice
Definition: Slice.pm:50
Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor
Definition: DnaAlignFeatureAdaptor.pm:25
Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor
Definition: BaseAlignFeatureAdaptor.pm:18