EnsEMBL/DBSQL/ExonAdaptor.pm untested

filter: Statementstmt 0.0% 0 / 262 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 45 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 442 CC 53 SCAR 58.9
CC
53
Cov
0%
_objs_from_sth
812.0
store
156.0
remove
56.0
CRAP 361.6
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::ExonAdaptor - An adaptor responsible for the retrieval and
34 storage of exon objects
35  
36 =head1 SYNOPSIS
37  
38 my $exon_adaptor = $registry->get_adaptor( 'Human', 'Core', 'Exon' );
39  
40 my $exon = $exon_adaptor->fetch_by_dbID($dbID);
41  
42 =head1 DESCRIPTION
43  
44 The ExonAdaptor is responsible for retrieving and storing Exon objects
45 from an Ensembl database. Most of the ExonAdaptor functionality is
46 inherited from the B<Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor> class.
47  
48 =head1 METHODS
49  
50 =cut
51  
52 package Bio::EnsEMBL::DBSQL::ExonAdaptor;
53 $Bio::EnsEMBL::DBSQL::ExonAdaptor::VERSION = '114.0.0_50'; # TRIAL
54 $Bio::EnsEMBL::DBSQL::ExonAdaptor::VERSION = '114.0.050';
55 use strict;
56  
57 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
58 use Bio::EnsEMBL::Exon;
59 use Bio::EnsEMBL::Utils::Exception qw( warning throw );
60
61 use vars qw( @ISA );
62 @ISA = qw( Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor );
63  
64  
65 #_tables
66 #
67 # Arg [1] : none
68 # Example : none
69 # Description: PROTECTED implementation of superclass abstract method
70 # returns the names, aliases of the tables to use for queries
71 # Returntype : list of listrefs of strings
72 # Exceptions : none
73 # Caller : internal
74  
75 sub _tables {
76 my $self = shift;
77  
78 # Allow the table definition to be overridden by certain methods.
79 if ( defined( $self->{'tables'} ) ) {
80 return @{ $self->{'tables'} };
81 }
82  
83 return ( [ 'exon', 'e' ] );
84 }
85  
86  
87 # _columns
88 #
89 # Arg [1] : none
90 # Example : none
91 # Description: PROTECTED implementation of superclass abstract method
92 # returns a list of columns to use for queries
93 # Returntype : list of strings
94 # Exceptions : none
95 # Caller : internal
96  
97 sub _columns {
98 my $self = shift;
99  
100 my $created_date =
101 $self->db->dbc->from_date_to_seconds("created_date");
102 my $modified_date =
103 $self->db->dbc->from_date_to_seconds("modified_date");
104  
105 return (
106 'e.exon_id', 'e.seq_region_id', 'e.seq_region_start',
107 'e.seq_region_end', 'e.seq_region_strand', 'e.phase',
108 'e.end_phase', 'e.is_current', 'e.is_constitutive',
109 'e.stable_id', 'e.version', $created_date,
110 $modified_date
111 );
112 }
113  
114  
115  
116 # _final_clause
117 #
118 # Arg [1] : none
119 # Example : none
120 # Description: PROTECTED implementation of superclass abstract method
121 # returns a default end for the SQL-query (ORDER BY)
122 # Returntype : string
123 # Exceptions : none
124 # Caller : internal
125  
126 sub _final_clause {
127 my $self = shift;
128 return $self->{'final_clause'} || '';
129 }
130  
131  
132 sub fetch_all {
133 my ($self) = @_;
134  
135 my $constraint = 'e.is_current = 1';
136 my @exons = @{ $self->generic_fetch($constraint) };
137 return \@exons ;
138 }
139  
140 =head2 fetch_by_stable_id
141  
142 Arg [1] : string $stable_id
143 the stable id of the exon to retrieve
144 Example : $exon = $exon_adaptor->fetch_by_stable_id('ENSE0000988221');
145 Description: Retrieves an Exon from the database via its stable id
146 Returntype : Bio::EnsEMBL::Exon in native coordinates.
147 Exceptions : none
148 Caller : general
149 Status : Stable
150  
151 =cut
152  
153 sub fetch_by_stable_id {
154 my ($self, $stable_id) = @_;
155  
156 my $constraint = "e.stable_id = ? AND e.is_current = 1";
157  
158 $self->bind_param_generic_fetch($stable_id,SQL_VARCHAR);
159 my ($exon) = @{ $self->generic_fetch($constraint) };
160  
161 # If we didn't get anything back, desperately try to see if there's
162 # a version number in the stable_id
163 if(!defined($exon) && (my $vindex = rindex($stable_id, '.'))) {
164 $exon = $self->fetch_by_stable_id_version(substr($stable_id,0,$vindex),
165 substr($stable_id,$vindex+1));
166 }
167  
168 return $exon;
169 }
170  
171  
172 =head2 fetch_by_stable_id_version
173  
174 Arg [1] : String $id
175 The stable ID of the exon to retrieve
176 Arg [2] : Integer $version
177 The version of the stable_id to retrieve
178 Example : $exon = $exon_adaptor->fetch_by_stable_id('ENSE0000988221', 3);
179 Description: Retrieves an exon object from the database via its stable id and version.
180 The exon will be retrieved in its native coordinate system (i.e.
181 in the coordinate system it is stored in the database). It may
182 be converted to a different coordinate system through a call to
183 transform() or transfer(). If the exon is not found
184 undef is returned instead.
185 Returntype : Bio::EnsEMBL::Exon or undef
186 Exceptions : if we cant get the exon in given coord system
187 Caller : general
188 Status : Stable
189  
190 =cut
191  
192 sub fetch_by_stable_id_version {
193 my ($self, $stable_id, $version) = @_;
194  
195 # Enforce that version be numeric
196 return unless($version =~ /^\d+$/);
197  
198 my $constraint = "e.stable_id = ? AND e.version = ? AND e.is_current = 1";
199 $self->bind_param_generic_fetch($stable_id, SQL_VARCHAR);
200 $self->bind_param_generic_fetch($version, SQL_INTEGER);
201 my ($exon) = @{$self->generic_fetch($constraint)};
202  
203 return $exon;
204 }
205  
206 =head2 fetch_all_versions_by_stable_id
207  
208 Arg [1] : String $stable_id
209 The stable ID of the exon to retrieve
210 Example : my $exon = $exon_adaptor->fetch_all_version_by_stable_id
211 ('ENSE00000309301');
212 Description : Similar to fetch_by_stable_id, but retrieves all versions of an
213 exon stored in the database.
214 Returntype : listref of Bio::EnsEMBL::Exon objects
215 Exceptions : if we cant get the gene in given coord system
216 Caller : general
217 Status : At Risk
218  
219 =cut
220  
221 sub fetch_all_versions_by_stable_id {
222 my ($self, $stable_id) = @_;
223  
224 my $constraint = "e.stable_id = ?";
225  
226 $self->bind_param_generic_fetch($stable_id,SQL_VARCHAR);
227  
228 return $self->generic_fetch($constraint);
229 }
230  
231  
232 =head2 fetch_all_by_Transcript
233  
234 Arg [1] : Bio::EnsEMBL::Transcript $transcript
235 Example : none
236 Description: Retrieves all Exons for the Transcript in 5-3 order
237 Returntype : listref Bio::EnsEMBL::Exon on Transcript slice
238 Exceptions : throws if transcript has no slice
239 Caller : Transcript->get_all_Exons()
240 Status : Stable
241  
242 =cut
243  
244 sub fetch_all_by_Transcript {
245 my ( $self, $transcript ) = @_;
246  
247 my $tslice = $transcript->slice();
248 my $slice;
249  
250 if ( !defined($tslice) ) {
251 throw("Transcript must have attached slice to retrieve exons.");
252 }
253  
254 # use a small slice the same size as the transcript
255 if ( !$tslice->is_circular() ) {
256 $slice =
257 $self->db()->get_SliceAdaptor()->fetch_by_Feature($transcript);
258 } else {
259 # Circular.
260 $slice = $tslice;
261 }
262  
263 # Override the tables definition to provide an additional join to the
264 # exon_transcript table. For efficiency we cannot afford to have this
265 # in as a left join every time.
266 my @tables = $self->_tables();
267  
268 # Be extra cautious so that we do not add 'exon_transcript' twice.
269 my $found = 0;
270 foreach my $table (@tables) {
271 if ( $table->[0] eq 'exon_transcript' ) {
272 $found = 1;
273 last;
274 }
275 }
276 if ( !$found ) {
277 push @tables, [ 'exon_transcript', 'et' ];
278 }
279  
280 $self->{'tables'} = \@tables;
281 $self->{'final_clause'} = "ORDER BY et.transcript_id, et.rank";
282  
283 my $constraint =
284 "et.transcript_id = "
285 . $transcript->dbID()
286 . " AND e.exon_id = et.exon_id";
287  
288 # fetch all of the exons
289 my $exons = $self->fetch_all_by_Slice_constraint($slice, $constraint);
290  
291 # un-override the table definition
292 delete( $self->{'tables'} );
293 delete( $self->{'final_clause'} );
294  
295 # remap exon coordinates if necessary
296 if($slice->name() ne $tslice->name()) {
297 my @out;
298 foreach my $ex (@$exons) {
299 push @out, $ex->transfer($tslice);
300 }
301 $exons = \@out;
302 }
303  
304 return $exons;
305 }
306  
307  
308 =head2 store
309  
310 Arg [1] : Bio::EnsEMBL::Exon $exon
311 the exon to store in this database
312 Example : $exon_adaptor->store($exon);
313 Description: Stores an exon in the database
314 Returntype : none
315 Exceptions : thrown if exon (or component exons) do not have a contig_id
316 or if $exon->start, $exon->end, $exon->strand, or $exon->phase
317 are not defined or if $exon is not a Bio::EnsEMBL::Exon
318 Caller : general
319 Status : Stable
320  
321 =cut
322  
323 sub store {
324 my ($self, $exon) = @_;
325  
326 if( ! $exon->isa('Bio::EnsEMBL::Exon') ) {
327 throw("$exon is not a EnsEMBL exon - not storing.");
328 }
329  
330 my $db = $self->db();
331  
332 if($exon->is_stored($db)) {
333 return $exon->dbID();
334 }
335  
336 if( ! $exon->start || ! $exon->end ||
337 ! $exon->strand || ! defined $exon->phase ) {
338 throw("Exon does not have all attributes to store");
339 }
340  
341 # Default to is_current = 1 if this attribute is not set
342 my $is_current = $exon->is_current();
343 if ( !defined($is_current) ) { $is_current = 1 }
344  
345 # Default to is_constitutive = 0 if this attribute is not set
346 my $is_constitutive = $exon->is_constitutive();
347 if ( !defined($is_constitutive) ) { $is_constitutive = 0 }
348  
349 my $exon_sql = q{
350 INSERT into exon ( seq_region_id, seq_region_start,
351 seq_region_end, seq_region_strand, phase,
352 end_phase, is_current, is_constitutive
353 };
354 if ( defined($exon->stable_id) ) {
355 my $created = $self->db->dbc->from_seconds_to_date($exon->created_date());
356 my $modified = $self->db->dbc->from_seconds_to_date($exon->modified_date());
357  
358 $exon_sql .= sprintf ", stable_id, version%s%s) VALUES ( ?,?,?,?,?,?,?,?,?,?%s%s)", $created?", created_date":'', $modified?", modified_date":'', $created?",$created":'', $modified?",$modified":'';
359
360 } else {
361 $exon_sql .= q{
362 ) VALUES ( ?,?,?,?,?,?,?,?)
363 };
364 }
365  
366  
367 my $exonst = $self->prepare($exon_sql);
368  
369 my $exonId = undef;
370  
371 my $original = $exon;
372 my $seq_region_id;
373 ($exon, $seq_region_id) = $self->_pre_store($exon);
374  
375 #store the exon
376 $exonst->bind_param( 1, $seq_region_id, SQL_INTEGER );
377 $exonst->bind_param( 2, $exon->start, SQL_INTEGER );
378 $exonst->bind_param( 3, $exon->end, SQL_INTEGER );
379 $exonst->bind_param( 4, $exon->strand, SQL_TINYINT );
380 $exonst->bind_param( 5, $exon->phase, SQL_TINYINT );
381 $exonst->bind_param( 6, $exon->end_phase, SQL_TINYINT );
382 $exonst->bind_param( 7, $is_current, SQL_TINYINT );
383 $exonst->bind_param( 8, $is_constitutive, SQL_TINYINT );
384  
385 if ( defined($exon->stable_id) ) {
386  
387 $exonst->bind_param( 9, $exon->stable_id, SQL_VARCHAR );
388 $exonst->bind_param( 10, $exon->version, SQL_INTEGER );
389 }
390  
391 $exonst->execute();
392 $exonId = $self->last_insert_id('exon_id', undef, 'exon');
393  
394 # Now the supporting evidence
395 my $esf_adaptor = $db->get_SupportingFeatureAdaptor;
396 $esf_adaptor->store($exonId, $exon->get_all_supporting_features);
397  
398 #
399 # Finally, update the dbID and adaptor of the exon (and any component exons)
400 # to point to the new database
401 #
402  
403 $original->adaptor($self);
404 $original->dbID($exonId);
405  
406 return $exonId;
407 }
408  
409  
410 =head2 remove
411  
412 Arg [1] : Bio::EnsEMBL::Exon $exon
413 the exon to remove from the database
414 Example : $exon_adaptor->remove($exon);
415 Description: Removes an exon from the database. This method is generally
416 called by the TranscriptAdaptor::store method. Database
417 integrity will not be maintained if this method is simply
418 called on its own without taking into account transcripts which
419 may refer to the exon being removed.
420 Returntype : none
421 Exceptions : none
422 Caller : general
423 Status : Stable
424  
425 =cut
426  
427 sub remove {
428 my $self = shift;
429 my $exon = shift;
430  
431 if(!ref($exon) || !$exon->isa('Bio::EnsEMBL::Exon')) {
432 throw('Bio::EnsEMBL::Exon argument expected.');
433 }
434  
435 if(!$exon->is_stored($self->db())) {
436 warning("Cannot remove exon " .$exon->dbID.
437 "Is not stored in this database.");
438 return;
439 }
440  
441 # sanity check: make sure nobdody tries to slip past a prediction exon
442 # which inherits from exon but actually uses different tables
443 if($exon->isa('Bio::EnsEMBL::PredictionExon')) {
444 throw("ExonAdaptor can only remove Exons not PredictionExons.");
445 }
446  
447 # Remove the supporting features of this exon
448  
449 my $prot_adp = $self->db->get_ProteinAlignFeatureAdaptor;
450 my $dna_adp = $self->db->get_DnaAlignFeatureAdaptor;
451  
452 my $sth = $self->prepare("SELECT feature_type, feature_id " .
453 "FROM supporting_feature " .
454 "WHERE exon_id = ?");
455 $sth->bind_param(1, $exon->dbID, SQL_INTEGER);
456 $sth->execute();
457  
458 # statements to check for shared align_features
459 my $sth1 = $self->prepare("SELECT count(*) FROM supporting_feature " .
460 "WHERE feature_type = ? AND feature_id = ?");
461 my $sth2 = $self->prepare("SELECT count(*) " .
462 "FROM transcript_supporting_feature " .
463 "WHERE feature_type = ? AND feature_id = ?");
464  
465 SUPPORTING_FEATURE:
466 while(my ($type, $feature_id) = $sth->fetchrow()){
467
468 # only remove align_feature if this is the last reference to it
469 $sth1->bind_param(1, $type, SQL_VARCHAR);
470 $sth1->bind_param(2, $feature_id, SQL_INTEGER);
471 $sth1->execute;
472 $sth2->bind_param(1, $type, SQL_VARCHAR);
473 $sth2->bind_param(2, $feature_id, SQL_INTEGER);
474 $sth2->execute;
475 my ($count1) = $sth1->fetchrow;
476 my ($count2) = $sth2->fetchrow;
477 if ($count1 + $count2 > 1) {
478 #warn "shared feature, not removing $type|$feature_id\n";
479 next SUPPORTING_FEATURE;
480 }
481
482 #warn "removing $type|$feature_id\n";
483
484 if($type eq 'protein_align_feature'){
485 my $f = $prot_adp->fetch_by_dbID($feature_id);
486 $prot_adp->remove($f);
487 }
488 elsif($type eq 'dna_align_feature'){
489 my $f = $dna_adp->fetch_by_dbID($feature_id);
490 $dna_adp->remove($f);
491 }
492 else {
493 warning("Unknown supporting feature type $type. Not removing feature.");
494 }
495 }
496 $sth->finish();
497 $sth1->finish();
498 $sth2->finish();
499  
500 # delete the association to supporting features
501  
502 $sth = $self->prepare("DELETE FROM supporting_feature WHERE exon_id = ?");
503 $sth->bind_param(1, $exon->dbID, SQL_INTEGER);
504 $sth->execute();
505 $sth->finish();
506  
507  
508 # delete the exon
509  
510 $sth = $self->prepare( "DELETE FROM exon WHERE exon_id = ?" );
511 $sth->bind_param(1, $exon->dbID, SQL_INTEGER);
512 $sth->execute();
513 $sth->finish();
514  
515 $exon->dbID(undef);
516 $exon->adaptor(undef);
517  
518 return;
519 }
520  
521  
522 =head2 list_dbIDs
523  
524 Arg [1] : none
525 Example : @exon_ids = @{$exon_adaptor->list_dbIDs()};
526 Description: Gets an array of internal ids for all exons in the current db
527 Arg[1] : <optional> int. not 0 for the ids to be sorted by the seq_region.
528 Returntype : list of ints
529 Exceptions : none
530 Caller : ?
531 Status : Stable
532  
533 =cut
534  
535 sub list_dbIDs {
536 my ($self, $ordered) = @_;
537  
538 return $self->_list_dbIDs("exon",undef, $ordered);
539 }
540  
541  
542 =head2 list_stable_ids
543  
544 Arg [1] : none
545 Example : @stable_exon_ids = @{$exon_adaptor->list_stable_dbIDs()};
546 Description: Gets an array of stable ids for all exons in the current db
547 Returntype : list of ints
548 Exceptions : none
549 Caller : ?
550 Status : Stable
551  
552 =cut
553  
554 sub list_stable_ids {
555 my ($self) = @_;
556  
557 return $self->_list_dbIDs("exon", "stable_id");
558 }
559  
560 #_objs_from_sth
561 #
562 # Arg [1] : StatementHandle $sth
563 # Example : none
564 # Description: PROTECTED implementation of abstract superclass method.
565 # responsible for the creation of Exons
566 # Returntype : listref of Bio::EnsEMBL::Exons in target coordinate system
567 # Exceptions : none
568 # Caller : internal
569  
570 sub _objs_from_sth {
571 my ( $self, $sth, $mapper, $dest_slice ) = @_;
572  
573 #
574 # This code is ugly because an attempt has been made to remove as many
575 # function calls as possible for speed purposes. Thus many caches and
576 # a fair bit of gymnastics is used.
577 #
578  
579 my $sa = $self->db()->get_SliceAdaptor();
580  
581 my @exons;
582 my %slice_hash;
583 my %sr_name_hash;
584 my %sr_cs_hash;
585  
586 my ( $exon_id, $seq_region_id, $seq_region_start,
587 $seq_region_end, $seq_region_strand, $phase,
588 $end_phase, $is_current, $is_constitutive,
589 $stable_id, $version, $created_date,
590 $modified_date );
591  
592 $sth->bind_columns( \( $exon_id, $seq_region_id, $seq_region_start,
593 $seq_region_end, $seq_region_strand, $phase,
594 $end_phase, $is_current, $is_constitutive,
595 $stable_id, $version, $created_date,
596 $modified_date ) );
597  
598 my $dest_slice_start;
599 my $dest_slice_end;
600 my $dest_slice_strand;
601 my $dest_slice_length;
602 my $dest_slice_cs;
603 my $dest_slice_sr_name;
604 my $dest_slice_sr_id;
605 my $asma;
606  
607 if ($dest_slice) {
608 $dest_slice_start = $dest_slice->start();
609 $dest_slice_end = $dest_slice->end();
610 $dest_slice_strand = $dest_slice->strand();
611 $dest_slice_length = $dest_slice->length();
612 $dest_slice_cs = $dest_slice->coord_system();
613 $dest_slice_sr_name = $dest_slice->seq_region_name();
614 $dest_slice_sr_id = $dest_slice->get_seq_region_id();
615 $asma = $self->db->get_AssemblyMapperAdaptor();
616 }
617  
618 FEATURE: while($sth->fetch()) {
619  
620 #need to get the internal_seq_region, if present
621 $seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
622 my $slice = $slice_hash{"ID:".$seq_region_id};
623  
624 if (!$slice) {
625 $slice = $sa->fetch_by_seq_region_id($seq_region_id);
626 $slice_hash{"ID:".$seq_region_id} = $slice;
627 $sr_name_hash{$seq_region_id} = $slice->seq_region_name();
628 $sr_cs_hash{$seq_region_id} = $slice->coord_system();
629 }
630  
631 #obtain a mapper if none was defined, but a dest_seq_region was
632 if(!$mapper && $dest_slice && !$dest_slice_cs->equals($slice->coord_system)) {
633 $mapper = $asma->fetch_by_CoordSystems($dest_slice_cs, $slice->coord_system);
634 }
635  
636 my $sr_name = $sr_name_hash{$seq_region_id};
637 my $sr_cs = $sr_cs_hash{$seq_region_id};
638  
639 #
640 # remap the feature coordinates to another coord system
641 # if a mapper was provided
642 #
643  
644 if ($mapper) {
645  
646 if (defined $dest_slice && $mapper->isa('Bio::EnsEMBL::ChainedAssemblyMapper') ) {
647 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
648 $mapper->map($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs, 1, $dest_slice);
649  
650 } else {
651 ($seq_region_id, $seq_region_start, $seq_region_end, $seq_region_strand) =
652 $mapper->fastmap($sr_name, $seq_region_start, $seq_region_end, $seq_region_strand, $sr_cs);
653 }
654  
655 #skip features that map to gaps or coord system boundaries
656 next FEATURE if (!defined($seq_region_id));
657  
658 #get a slice in the coord system we just mapped to
659 $slice = $slice_hash{"ID:".$seq_region_id} ||= $sa->fetch_by_seq_region_id($seq_region_id);
660 }
661  
662 #
663 # If a destination slice was provided convert the coords.
664 #
665 if (defined($dest_slice)) {
666 my $seq_region_len = $dest_slice->seq_region_length();
667  
668 if ( $dest_slice_strand == 1 ) {
669 $seq_region_start = $seq_region_start - $dest_slice_start + 1;
670 $seq_region_end = $seq_region_end - $dest_slice_start + 1;
671  
672 if ( $dest_slice->is_circular ) {
673 # Handle circular chromosomes.
674  
675 if ( $seq_region_start > $seq_region_end ) {
676 # Looking at a feature overlapping the chromosome origin.
677  
678 if ( $seq_region_end > $dest_slice_start ) {
679 # Looking at the region in the beginning of the chromosome
680 $seq_region_start -= $seq_region_len;
681 }
682 if ( $seq_region_end < 0 ) {
683 $seq_region_end += $seq_region_len;
684 }
685 } else {
686 if ($dest_slice_start > $dest_slice_end && $seq_region_end < 0) {
687 # Looking at the region overlapping the chromosome
688 # origin and a feature which is at the beginning of the
689 # chromosome.
690 $seq_region_start += $seq_region_len;
691 $seq_region_end += $seq_region_len;
692 }
693 }
694 }
695 } else {
696  
697 my $start = $dest_slice_end - $seq_region_end + 1;
698 my $end = $dest_slice_end - $seq_region_start + 1;
699  
700 if ($dest_slice->is_circular()) {
701  
702 if ($dest_slice_start > $dest_slice_end) {
703 # slice spans origin or replication
704  
705 if ($seq_region_start >= $dest_slice_start) {
706 $end += $seq_region_len;
707 $start += $seq_region_len if $seq_region_end > $dest_slice_start;
708  
709 } elsif ($seq_region_start <= $dest_slice_end) {
710 # do nothing
711 } elsif ($seq_region_end >= $dest_slice_start) {
712 $start += $seq_region_len;
713 $end += $seq_region_len;
714  
715 } elsif ($seq_region_end <= $dest_slice_end) {
716 $end += $seq_region_len if $end < 0;
717  
718 } elsif ($seq_region_start > $seq_region_end) {
719 $end += $seq_region_len;
720 }
721  
722 } else {
723  
724 if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) {
725 # do nothing
726 } elsif ($seq_region_start > $seq_region_end) {
727 if ($seq_region_start <= $dest_slice_end) {
728 $start -= $seq_region_len;
729 } elsif ($seq_region_end >= $dest_slice_start) {
730 $end += $seq_region_len;
731 }
732 }
733 }
734 }
735  
736 $seq_region_start = $start;
737 $seq_region_end = $end;
738 $seq_region_strand *= -1;
739  
740 } ## end else [ if ( $dest_slice_strand...)]
741  
742 # Throw away features off the end of the requested slice or on
743 # different seq_region.
744 if ($seq_region_end < 1
745 || $seq_region_start > $dest_slice_length
746 || ($dest_slice_sr_id != $seq_region_id)) {
747 next FEATURE;
748 }
749 $slice = $dest_slice;
750 }
751  
752 # Finally, create the new exon.
753 push( @exons,
754 $self->_create_feature_fast(
755 'Bio::EnsEMBL::Exon', {
756 'start' => $seq_region_start,
757 'end' => $seq_region_end,
758 'strand' => $seq_region_strand,
759 'adaptor' => $self,
760 'slice' => $slice,
761 'dbID' => $exon_id,
762 'stable_id' => $stable_id,
763 'version' => $version,
764 'created_date' => $created_date || undef,
765 'modified_date' => $modified_date || undef,
766 'phase' => $phase,
767 'end_phase' => $end_phase,
768 'is_current' => $is_current,
769 'is_constitutive' => $is_constitutive } )
770 );
771  
772 } ## end while ( $sth->fetch() )
773  
774 return \@exons;
775 } ## end sub _objs_from_sth
776  
777  
778 1;
779  
780