From 824f954474a33f58c74eab4d1a0affbd6c4f4325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Fri, 13 Aug 2010 16:20:51 +0000 Subject: [PATCH] Make _objs_from_sth() aware of circular chromosomes. Patch from EG. --- .../Bio/EnsEMBL/DBSQL/TranscriptAdaptor.pm | 80 +++++++++++++++---- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/TranscriptAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/TranscriptAdaptor.pm index 4cbba25717..18ede60db1 100644 --- a/modules/Bio/EnsEMBL/DBSQL/TranscriptAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/TranscriptAdaptor.pm @@ -312,8 +312,12 @@ sub fetch_all_by_Gene { throw("Gene must have attached slice to retrieve transcripts."); } - if ($gene->start() < 1 || $gene->end() > $gslice->length()) { - $slice = $self->db->get_SliceAdaptor->fetch_by_Feature($gene); + if ( $gene->start() < 1 || $gene->end() > $gslice->length() ) { + if ( $gslice->is_circular() ) { + $slice = $gslice; + } else { + $slice = $self->db->get_SliceAdaptor->fetch_by_Feature($gene); + } } else { $slice = $gslice; } @@ -1486,31 +1490,79 @@ sub _objs_from_sth { } # - # If a destination slice was provided convert the coords - # If the dest_slice starts at 1 and is foward strand, nothing needs doing + # If a destination slice was provided convert the coords. # - if ($dest_slice) { - if ( $dest_slice_start != 1 || $dest_slice_strand != 1 ) { - if ( $dest_slice_strand == 1 ) { - $seq_region_start = $seq_region_start - $dest_slice_start + 1; - $seq_region_end = $seq_region_end - $dest_slice_start + 1; + if (defined($dest_slice)) { + if ( $dest_slice_strand == 1 ) { + $seq_region_start = $seq_region_start - $dest_slice_start + 1; + $seq_region_end = $seq_region_end - $dest_slice_start + 1; + + if ( $dest_slice->is_circular ) { + if ( $seq_region_start > $seq_region_end ) { + # Looking at a feature overlapping the chromsome origin. + if ( $seq_region_end > $dest_slice_start ) { + # Looking at the region in the beginning of the chromosome + $seq_region_start -= $dest_slice->seq_region_length(); + } + if ( $seq_region_end < 0 ) { + $seq_region_end += $dest_slice->seq_region_length(); + } + } else { + if ( $dest_slice_start > $dest_slice_end + && $seq_region_end < 0 ) + { + # Looking at the region overlapping the chromosome + # origin and a feature which is at the beginning of the + # chromosome. + $seq_region_start += $dest_slice->seq_region_length(); + $seq_region_end += $dest_slice->seq_region_length(); + } + } + } + } else { + if ( $dest_slice->is_circular() + && $seq_region_start > $seq_region_end ) + { + if ( $seq_region_end > $dest_slice_start ) { + # Looking at the region in the beginning of the chromosome. + $seq_region_start = $dest_slice_end - $seq_region_end + 1; + $seq_region_end = + $seq_region_end - + $dest_slice->seq_region_length() - + $dest_slice_start + 1; + } else { + my $tmp_seq_region_start = $seq_region_start; + $seq_region_start = + $dest_slice_end - + $seq_region_end - + $dest_slice->seq_region_length() + 1; + $seq_region_end = + $dest_slice_end - $tmp_seq_region_start + 1; + } + } else { my $tmp_seq_region_start = $seq_region_start; $seq_region_start = $dest_slice_end - $seq_region_end + 1; $seq_region_end = $dest_slice_end - $tmp_seq_region_start + 1; - $seq_region_strand *= -1; } - } + + $seq_region_strand = -$seq_region_strand; + } ## end else [ if ( $dest_slice_strand...)] # Throw away features off the end of the requested slice - if ( $seq_region_end < 1 - || $seq_region_start > $dest_slice_length - || ( $dest_slice_sr_id ne $seq_region_id ) ) + if ( $seq_region_end < 1 + || $seq_region_start > $dest_slice_length + || ( $dest_slice_sr_id ne $seq_region_id ) ) { next FEATURE; } $slice = $dest_slice; + } else { + $slice = + $sa->fetch_by_seq_region_id( $seq_region_id, $seq_region_start, + $seq_region_end, $seq_region_strand + ); } my $display_xref; -- GitLab