ensembl-hive  2.8.1
ExternalFeatureFactoryI.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 
34 Legacy Abstract interface for External Feature
35 Factories. Bio::EnsEMBL::External::ExternalFeatureAdaptor should be used
36 instead if possible.
37 
38 =head1 SYNOPSIS
39 
40  $external_ff = new ImplementingExternalFeatureFactoryClass;
41 
42  $database_adaptor = new Bio::EnsEMBL::DBSQL::DBAdaptor(
43  -host => 'blah',
44  -dbname => 'other',
45  -pass => 'pass'
46  );
47 
48  # alternatively, you can add external databases to an obj once made
49  $database_adaptor->add_ExternalFeatureFactory($external_ff);
50 
51  # now the ExternalFeatureFactory has been added, Ensembl RawContigs
52  # and Slices will now have ExternalFeatures on them
53  $contig =
54  $db_adaptor->get_RawContigAdaptor->fetch_by_name('AC00056.00001');
55  @external = @{ $contig->get_all_ExternalFeatures() };
56 
57  # this works on Slices as well
58  $slice =
59  $db_adaptor->get_SliceAdaptor->fetch_by_chr_start_end( '12', 10000,
60  30000 );
61  @external = @{ $slice->get_all_ExternalFeatures() };
62 
63 =head1 DESCRIPTION
64 
65 This is a legacy class. It is included only for backwards
66 compatibility with ExternalFeatureFactories which are presumably
67 still used to place data into ensembl. It is recommended that if
68 you wish to create EnsEMBL features externally that you use the
70 
71 This object defines the abstract interface for External Database access
72 inside Ensembl. The aim is that one can attach an External Database
73 which will generate Sequence Features and these Sequence Features will
74 be accessible along side all the internal Ensembl sequence features, for
75 drawing, EMBL dumping etc. In particular, the external database does not
76 have to worry about the transformation of the Sequence Feature objects
77 into VirtualContigs.
78 
79 Sequence Features have to be defined in one of two coordinate systems:
80 Original EMBL/GenBank coordinates of a particular sequnence version or
81 the Ensembl contig coordinates. This means you have to calculate your
82 sequence features in one these two coordinate systems
83 
84 The methods that have to be implemented are:
85 
86  get_External_SeqFeatures_contig( $ensembl_contig_identifier,
87  $sequence_version, $start, $end );
88 
89  get_External_SeqFeatures_clone( $embl_accession_number,
90  $sequence_version, $start, $end );
91 
92 The semantics of this method is as follows:
93 
94  $ensembl_contig_identifier - the ensembl contig id (external id).
95  $sequence_version - embl/genbank sequence version
96  $embl_accession_number - the embl/genbank accession number
97 
98 The $start/$end can be ignored, but methods can take advantage of it.
99 This is so that ensembl can ask for features only on a region of DNA,
100 and if desired, the external database can respond with features only in
101 this region, rather than the entire sequence.
102 
103 The hope is that the second method could potentially have a very complex
104 set of mappings of other embl_accession numbers to one embl_accession
105 number and provide the complex mapping.
106 
107 The methods should return Sequence Features with the following spec:
108 
109  a) must implement the Bio::SeqFeatureI interface.
110 
111  b) must accept "set" calls on
112 
113  start,end,strand
114 
115  to provide coordinate transformation of the feature.
116 
117  c) must be unique in-memory objects, ie, the implementation is not
118  allowed to cache the sequence feature in its entirity. Two separate
119  calls to get_External_SeqFeatures_contig must be able to separately
120  set start,end,strand information without clobbering each other. The
121  other information, if so wished, can be cached by each SeqFeature
122  holding onto another object, but this is left to the implementor to
123  decide on the correct strategy.
124 
125  d) must return an unique identifier when called with method id.
126 
127 You must implement both functions. In most cases, one function will
128 always return an empty list, whereas the other function will actually
129 query the external database.
130 
131 The second way of accessing the External Database from Ensembl is using
132 unique internal identifiers in that database. The method is:
133 
134  get_SeqFeature_by_id($id);
135 
136 It should return exactly one Sequence Feature object of the same type as
137 above.
138 
139 =head1 METHODS
140 
141 =cut
142 
144 
145 use strict;
146 use warnings;
147 
149 use vars qw(@ISA);
150 
151 @ISA = ( 'Bio::EnsEMBL::External::ExternalFeatureAdaptor' );
152 
153 
154 =head2 coordinate_systems
155 
156  Arg [1] : none
157  Example : none
158  Description: This method is present to make the ExternalFeatureFactory
159  interface behave as an ExternalFeatureAdaptor. It is for
160  backwards compatibility.
161  Returntype : none
162  Exceptions : none
163  Caller : internal
164 
165 =cut
166 
167 sub coordinate_systems {
168  my $self = shift;
169  return qw(CONTIG);
170 }
171 
172 
173 =head2 fetch_all_by_contig_name
174 
175  Arg [1] : none
176  Example : none
177  Description: This method is present to make the ExternalFeatureFactory
178  interface behave as an ExternalFeatureAdaptor. It is for
179  backwards compatibility.
180  Returntype : none
181  Exceptions : none
182  Caller : internal
183 
184 =cut
185 
186 sub fetch_all_by_contig_name {
187  my ($self, $contig_name) = @_;
188 
189  unless($self->db) {
190  $self->throw('DB attribute not set. This value must be set for the ' .
191  'ExternalFeatureFactory to function correctly');
192  }
193 
194  my @features = ();
195 
196  my $ctg = $self->db->get_RawContigAdaptor->fetch_by_name($contig_name);
197  my $clone = $ctg->clone;
198  my $version = $clone->version;
199  my $ctg_length = $ctg->length;
200 
201  #get contig features
202  push @features, $self->get_Ensembl_SeqFeatures_contig($ctg->name,
203  $version,
204  1,
205  $ctg_length);
206 
207  #get clone features
208  my $clone_start = $ctg->embl_offset;
209  my $clone_end = $clone_start + $ctg_length - 1;
210  my @clone_features = $self->get_Ensembl_SeqFeatures_clone($clone->id,
211  $version,
212  $clone_start,
213  $clone_end);
214 
215  #change clone coordinates to contig coordinates
216  my ($start, $end);
217  foreach my $f (@clone_features) {
218  $start = $f->start - $clone_start + 1;
219  $end = $f->end - $clone_start + 1;
220 
221  #skip features outside the contig
222  next if($end < 1 || $start > $ctg_length);
223 
224  $f->start($start);
225  $f->end($end);
226 
227  push @features, $f;
228  }
229 
230  return \@features;
231 }
232 
233 =head2 get_Ensembl_SeqFeatures_contig
234 
235  Title : get_Ensembl_SeqFeatures_contig (Abstract)
236  Usage :
237  Function:
238  Example :
239  Returns :
240  Args :
241 
242 
243 =cut
244 
245 sub get_Ensembl_SeqFeatures_contig{
246  my ($self) = @_;
247 
248  $self->warn("Abstract method get_External_SeqFeatures_contig " .
249  "encountered in base class. Implementation failed to complete it");
250 
251 }
252 
253 =head2 get_Ensembl_SeqFeatures_clone
254 
255  Title : get_Ensembl_SeqFeatures_clone (Abstract)
256  Usage :
257  Function:
258  Example :
259  Returns :
260  Args :
261 
262 
263 =cut
264 
265 sub get_Ensembl_SeqFeatures_clone{
266  my ($self) = @_;
267 
268  $self->warn("Abstract method get_Ensembl_SeqFeatures_clone " .
269  "encountered in base class. Implementation failed to complete it");
270 
271 }
272 
273 =head2 get_Ensembl_Genes_clone
274 
275  Title : get_Ensembl_Genes_clone
276  Function: returns Gene objects in clone coordinates from a gene id
277  Returns : An array of Gene objects
278  Args : clone id
279 
280 =cut
281 
282 sub get_Ensembl_Genes_clone {
283  my $self = @_;
284 
285  return;
286 }
287 
288 =head2 get_SeqFeature_by_id
289 
290  Title : get_SeqFeature_by_id (Abstract)
291  Usage :
292  Function: Return SeqFeature object for any valid unique id
293  Example :
294  Returns :
295  Args : id as determined by the External Database
296 
297 
298 =cut
299 
300 
301 sub get_SeqFeature_by_id {
302  my ($self) = @_;
303  $self->warn("Abstract method get_SeqFeature_by_id encountered " .
304  "in base class. Implementation failed to complete it");
305 }
306 
307 
308 1;
309 
310 
311 
312 
313 
314 
315 
EnsEMBL
Definition: Filter.pm:1
Bio::EnsEMBL::DBSQL::DBAdaptor
Definition: DBAdaptor.pm:40
Bio::EnsEMBL::SeqFeature
Definition: SeqFeature.pm:30
Bio::EnsEMBL::DB::ExternalFeatureFactoryI::get_Ensembl_SeqFeatures_contig
public get_Ensembl_SeqFeatures_contig()
Bio::EnsEMBL::DB::ExternalFeatureFactoryI::get_SeqFeature_by_id
public get_SeqFeature_by_id()
Bio::EnsEMBL::Feature
Definition: Feature.pm:47
accession
public accession()
Bio::EnsEMBL::Gene
Definition: Gene.pm:37
Bio::EnsEMBL::DB::ExternalFeatureFactoryI
Definition: ExternalFeatureFactoryI.pm:109
about
public about()
Bio::EnsEMBL::DB::ExternalFeatureFactoryI::get_Ensembl_SeqFeatures_clone
public get_Ensembl_SeqFeatures_clone()
Bio::EnsEMBL::External::ExternalFeatureAdaptor
Definition: ExternalFeatureAdaptor.pm:85
Bio
Definition: AltAlleleGroup.pm:4