ExternalFeatureFactoryI.pm 8.42 KB
Newer Older
1
=head1 LICENSE
2

3
Copyright [1999-2013] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4

5 6 7 8 9 10 11 12 13 14 15 16 17
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut
18

19 20 21 22

=head1 CONTACT

  Please email comments or questions to the public Ensembl
Magali Ruffier's avatar
Magali Ruffier committed
23
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
24 25

  Questions may also be sent to the Ensembl help desk at
Magali Ruffier's avatar
Magali Ruffier committed
26
  <http://www.ensembl.org/Help/Contact>.
27

28 29 30
=cut

=head1 NAME
31

32 33 34 35
Bio::EnsEMBL::DB::ExternalFeatureFactoryI -
Legacy Abstract interface for External Feature
Factories. Bio::EnsEMBL::External::ExternalFeatureAdaptor should be used
instead if possible.
36 37 38

=head1 SYNOPSIS

39
  $external_ff = new ImplementingExternalFeatureFactoryClass;
40

41 42 43 44 45
  $database_adaptor = new Bio::EnsEMBL::DBSQL::DBAdaptor(
    -host   => 'blah',
    -dbname => 'other',
    -pass   => 'pass'
  );
46

47 48
  # alternatively, you can add external databases to an obj once made
  $database_adaptor->add_ExternalFeatureFactory($external_ff);
49

50 51 52 53
  # now the ExternalFeatureFactory has been added, Ensembl RawContigs
  # and Slices will now have ExternalFeatures on them
  $contig =
    $db_adaptor->get_RawContigAdaptor->fetch_by_name('AC00056.00001');
54
  @external = @{ $contig->get_all_ExternalFeatures() };
55

56 57 58 59
  # this works on Slices as well
  $slice =
    $db_adaptor->get_SliceAdaptor->fetch_by_chr_start_end( '12', 10000,
    30000 );
60
  @external = @{ $slice->get_all_ExternalFeatures() };
61 62 63

=head1 DESCRIPTION

64 65 66 67 68
This is a legacy class.  It is included only for backwards
compatibility with ExternalFeatureFactories which are presumably
still used to place data into ensembl.  It is recommended that if
you wish to create EnsEMBL features externally that you use the
Bio::EnsEMBL::External::ExternalFeatureAdaptor instead.
69

70 71 72 73 74 75 76
This object defines the abstract interface for External Database access
inside Ensembl. The aim is that one can attach an External Database
which will generate Sequence Features and these Sequence Features will
be accessible along side all the internal Ensembl sequence features, for
drawing, EMBL dumping etc. In particular, the external database does not
have to worry about the transformation of the Sequence Feature objects
into VirtualContigs.
77 78

Sequence Features have to be defined in one of two coordinate systems:
79 80 81
Original EMBL/GenBank coordinates of a particular sequnence version or
the Ensembl contig coordinates. This means you have to calculate your
sequence features in one these two coordinate systems
82 83 84

The methods that have to be implemented are:

85 86
  get_External_SeqFeatures_contig( $ensembl_contig_identifier,
    $sequence_version, $start, $end );
87

88 89
  get_External_SeqFeatures_clone( $embl_accession_number,
    $sequence_version, $start, $end );
90 91 92

The semantics of this method is as follows:

93 94 95
  $ensembl_contig_identifier - the ensembl contig id (external id).
  $sequence_version - embl/genbank sequence version
  $embl_accession_number - the embl/genbank accession number
96 97 98

The $start/$end can be ignored, but methods can take advantage of it.
This is so that ensembl can ask for features only on a region of DNA,
99 100
and if desired, the external database can respond with features only in
this region, rather than the entire sequence.
101

102 103 104
The hope is that the second method could potentially have a very complex
set of mappings of other embl_accession numbers to one embl_accession
number and provide the complex mapping.
105

106
The methods should return Sequence Features with the following spec:
107

108
  a) must implement the Bio::SeqFeatureI interface.
109

110
  b) must accept "set" calls on 
111

112
  start,end,strand
113

114
  to provide coordinate transformation of the feature.
115

116 117 118 119 120 121 122
  c) must be unique in-memory objects, ie, the implementation is not
  allowed to cache the sequence feature in its entirity. Two separate
  calls to get_External_SeqFeatures_contig must be able to separately
  set start,end,strand information without clobbering each other. The
  other information, if so wished, can be cached by each SeqFeature
  holding onto another object, but this is left to the implementor to
  decide on the correct strategy.
123

124
  d) must return an unique identifier when called with method id.
125 126 127 128 129

You must implement both functions. In most cases, one function will
always return an empty list, whereas the other function will actually
query the external database.

130 131
The second way of accessing the External Database from Ensembl is using
unique internal identifiers in that database. The method is:
132

133
  get_SeqFeature_by_id($id);
134

135 136
It should return exactly one Sequence Feature object of the same type as
above.
137

138
=head1 METHODS
139

140
=cut
141

142
package Bio::EnsEMBL::DB::ExternalFeatureFactoryI;
143 144 145 146

use strict;
use warnings;

147 148
use Bio::EnsEMBL::External::ExternalFeatureAdaptor;
use vars qw(@ISA);
149

150
@ISA = ( 'Bio::EnsEMBL::External::ExternalFeatureAdaptor' );
151 152


153 154 155 156 157 158 159 160 161 162
=head2 coordinate_systems

  Arg [1]    : none
  Example    : none
  Description: This method is present to make the ExternalFeatureFactory 
               interface behave as an ExternalFeatureAdaptor. It is for
               backwards compatibility.
  Returntype : none
  Exceptions : none
  Caller     : internal
163 164 165

=cut

166 167 168 169
sub coordinate_systems {
  my $self = shift;
  return qw(CONTIG);
}
170 171


172
=head2 fetch_all_by_contig_name
173

174 175 176 177 178 179 180 181
  Arg [1]    : none
  Example    : none
  Description: This method is present to make the ExternalFeatureFactory 
               interface behave as an ExternalFeatureAdaptor. It is for
               backwards compatibility.
  Returntype : none
  Exceptions : none
  Caller     : internal
182

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
=cut

sub fetch_all_by_contig_name {
   my ($self, $contig_name) = @_;

   unless($self->db) {
     $self->throw('DB attribute not set.  This value must be set for the ' .
		  'ExternalFeatureFactory to function correctly');
   }

   my @features = ();

   my $ctg = $self->db->get_RawContigAdaptor->fetch_by_name($contig_name);
   my $clone = $ctg->clone;
   my $version = $clone->version;
   my $ctg_length = $ctg->length;
   
   #get contig features
   push @features, $self->get_Ensembl_SeqFeatures_contig($ctg->name, 
							 $version, 
							 1,
							 $ctg_length);

   #get clone features
   my $clone_start = $ctg->embl_offset;
   my $clone_end   = $clone_start + $ctg_length - 1;
   my @clone_features = $self->get_Ensembl_SeqFeatures_clone($clone->id,
							     $version,
							     $clone_start,
							     $clone_end);

   #change clone coordinates to contig coordinates
   my ($start, $end); 
   foreach my $f (@clone_features) {
     $start = $f->start - $clone_start + 1;
     $end   = $f->end   - $clone_start + 1;

     #skip features outside the contig
     next if($end < 1 || $start > $ctg_length);

     $f->start($start);
     $f->end($end);

     push @features, $f;
   }

   return \@features;
}
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314

=head2 get_Ensembl_SeqFeatures_contig

 Title   : get_Ensembl_SeqFeatures_contig (Abstract)
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub get_Ensembl_SeqFeatures_contig{
   my ($self) = @_;

   $self->warn("Abstract method get_External_SeqFeatures_contig " .
	    "encountered in base class. Implementation failed to complete it");

}

=head2 get_Ensembl_SeqFeatures_clone

 Title   : get_Ensembl_SeqFeatures_clone (Abstract)
 Usage   :
 Function:
 Example :
 Returns : 
 Args    :


=cut

sub get_Ensembl_SeqFeatures_clone{
   my ($self) = @_;
   
   $self->warn("Abstract method get_Ensembl_SeqFeatures_clone " .
	    "encountered in base class. Implementation failed to complete it");

}

=head2 get_Ensembl_Genes_clone

 Title   : get_Ensembl_Genes_clone
 Function: returns Gene objects in clone coordinates from a gene id
 Returns : An array of Gene objects
 Args    : clone id

=cut

sub get_Ensembl_Genes_clone {
    my $self = @_;

    return;
}

=head2 get_SeqFeature_by_id

 Title   : get_SeqFeature_by_id (Abstract)
 Usage   : 
 Function: Return SeqFeature object for any valid unique id  
 Example :
 Returns : 
 Args    : id as determined by the External Database


=cut

       
sub get_SeqFeature_by_id {
   my ($self) = @_;
   $self->warn("Abstract method get_SeqFeature_by_id  encountered " .
	       "in base class. Implementation failed to complete it");
}


1;