BaseAlignFeatureAdaptor.pm 5.36 KB
Newer Older
1
#
2
# EnsEMBL module for Bio::EnsEMBL::BaseFeatureAdaptor
3
#
4
# Copyright (c) 2003 EnsEMBL
5
6
7
8
9
10
11
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

12
13
Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor - Abstract Base class for
AlignFeatureAdaptors
14
15
16

=head1 SYNOPSIS

17
Abstract class - should not be instantiated.  Implementation of
18
19
20
21
22
23
24
25
abstract methods must be performed by subclasses.

=head1 DESCRIPTION

This is a base adaptor for align adaptors.  Since DnaAlignFeatureAdaptor and
PepAlignFeatureAdaptor had almost the same functionality it made sense to 
streamline by creating this superclass.

26
=head1 CONTACT
27

28
Post questions/comments to the ensembl developer list: ensembl-dev@ebi.ac.uk
29

Graham McVicker's avatar
Graham McVicker committed
30
=head1 METHODS
31
32
33
34

=cut

package Bio::EnsEMBL::DBSQL::BaseAlignFeatureAdaptor;
35
use vars qw(@ISA @EXPORT);
36
37
use strict;

38
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
39

40
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
41

42
@EXPORT = (@{$DBI::EXPORT_TAGS{'sql_types'}});
43

44
=head2 fetch_all_by_Slice_and_pid
45

46
47
48
49
  Arg [1]    : Bio::EnsEMBL::Slice $slice
               The slice from which to obtain align features.
  Arg [2]    : (optional) float $pid 
               a lower bound for the percentage identity of feats to obtain
50
51
  Arg [3]    : (optional) string $logic_name
               the logic name of the type of features to obtain
52
  Example    : @feats = $adaptor->fetch_all_by_Slice_and_pid($slice, 50.0);
53
  Description: Returns a listref of features created from the database which
54
               are on the Slice $slice and with a percentage identity
55
               greater than $pid.  If logic name is defined, only features
56
57
58
               with an analysis of type $logic_name will be returned.
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures in Slice coordinates
  Exceptions : thrown if pid is not defined
59
  Caller     : general
60
  Status     : Stable
61
62
63

=cut

64
65
sub fetch_all_by_Slice_and_pid {
  my ($self,$slice,$pid, $logic_name) = @_;
66
67
  my $constraint;

68

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

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

77
78
79
  if(defined $pid){
    $constraint = "perc_ident > $pid";
  }
80

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


86
87
88
89
=head2 fetch_all_by_hit_name

  Arg [1]    : string $hit_name
               the hit_name of the features to obtain
Glenn Proctor's avatar
Glenn Proctor committed
90
  Arg [2]    : (optional) string $logic_name
91
92
93
94
95
96
97
98
99
               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.
  Returntype : listref of Bio::EnsEMBL::BaseAlignFeatures
  Exceptions : thrown if hit_name is not defined
  Caller     : general
100
  Status     : Stable
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

=cut

sub fetch_all_by_hit_name{
  my( $self, $hit_name, $logic_name ) = @_;
  throw("hit_name argument is required") if(! $hit_name);

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

  if( $logic_name ){
    # Add the $logic_name constraint
    $constraint = $self->_logic_name_to_constraint($constraint, $logic_name);
  }
  return $self->generic_fetch($constraint);
}


121
122
123
124
125
126
127
128
129
=head2 fetch_all_by_hit_name_unversioned

  Arg [1]    : string $hit_name
               the beginning of the hit_name of the features to obtain
               e.g. AA768786 would retrieve AA768786.1, AA768786.2 etc
  Arg [2]    : (optional) string $logic_name
               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
Glenn Proctor's avatar
Glenn Proctor committed
130
               which start with the  given hit_name. If logic name
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
               is defined, only features with an analysis of type
               $logic_name will be returned.
  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 {
  my( $self, $hit_name, $logic_name ) = @_;
  throw("hit_name argument is required") if(! $hit_name);

  #construct a constraint like 't1.hit_name = "123"'
  my @tabs = $self->_tables;
  my ($name, $syn) = @{$tabs[0]};
147
  my $constraint = ( "${syn}.hit_name LIKE '$hit_name.%'" );
148
149
150
151
152
153
154
155
156

  if( $logic_name ){
    # Add the $logic_name constraint
    $constraint = $self->_logic_name_to_constraint($constraint, $logic_name);
  }
  return $self->generic_fetch($constraint);
}


157

158
=head2 fetch_all_by_RawContig_and_pid
159

160
  Description: DEPRECATED use fetch_all_by_Slice_and_pid instead
161
162
163

=cut

164
165
sub fetch_all_by_RawContig_and_pid {
  my($self, $contig, $pid, $logic_name) = @_;
166

167
  my $constraint;
168
169
170
171
172
173
174
175
176

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

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

177
178
179
180
  return $self->fetch_all_by_RawContig_constraint($contig, 
						  $constraint, 
						  $logic_name);
}
181
182
183
184




185
186
##implemented by subclasses:
# store
187
# _tables
188
189
# _columns
# _obj_from_hashref
190
191


192

193
1;