diff --git a/modules/Bio/EnsEMBL/DBSQL/AssemblyExceptionFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/AssemblyExceptionFeatureAdaptor.pm index 8261d4dad203c6ab6853001da245765e780537bb..636c3b17f48999137f33ddd85d210b2356be7917 100644 --- a/modules/Bio/EnsEMBL/DBSQL/AssemblyExceptionFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/AssemblyExceptionFeatureAdaptor.pm @@ -324,14 +324,108 @@ sub _remap { # create new copies of successfully mapped feaatures with shifted start, # end and strand my ($new_start, $new_end); - if($slice_strand == -1) { - $new_start = $slice_end - $end + 1; - $new_end = $slice_end - $start + 1; - } else { - $new_start = $start - $slice_start + 1; - $new_end = $end - $slice_start + 1; - } + # if($slice_strand == -1) { + # $new_start = $slice_end - $end + 1; + # $new_end = $slice_end - $start + 1; + # } else { + # $new_start = $start - $slice_start + 1; + # $new_end = $end - $slice_start + 1; + # } + my $seq_region_len = $slice->seq_region_length(); + + if ($slice_strand == 1) { # Positive strand + + $new_start = $start - $slice_start + 1; + $new_end = $end - $slice_start + 1; + + if ($slice->is_circular()) { + # Handle circular chromosomes. + + if ($new_start > $new_end) { + # Looking at a feature overlapping the chromsome origin. + + if ($new_end > $slice_start) { + + # Looking at the region in the beginning of the + # chromosome. + $new_start -= $seq_region_len; + } + + if ($new_end < 0) { + $new_end += $seq_region_len; + } + + } else { + + if ( $slice_start > $slice_end + && $new_end < 0) { + # Looking at the region overlapping the chromosome + # origin and a feature which is at the beginning of the + # chromosome. + $new_start += $seq_region_len; + $new_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $new_start = $slice_end - $end + 1; + my $new_end = $slice_end - $start + 1; + + if ($slice->is_circular()) { + + if ($slice_start > $slice_end) { + # slice spans origin or replication + + if ($start >= $slice_start) { + $new_end += $seq_region_len; + $new_start += $seq_region_len + if $end > $slice_start; + + } elsif ($start <= $slice_end) { + # do nothing + } elsif ($end >= $slice_start) { + $new_start += $seq_region_len; + $new_end += $seq_region_len; + + } elsif ($end <= $slice_end) { + + $new_end += $seq_region_len + if $new_end < 0; + + } elsif ($start > $end) { + + $new_end += $seq_region_len; + + } else { + + } + + } else { + + if ($start <= $slice_end and $end >= $slice_start) { + # do nothing + } elsif ($start > $end) { + if ($start <= $slice_end) { + + $new_start -= $seq_region_len; + + } elsif ($end >= $slice_start) { + $new_end += $seq_region_len; + + } else { + + } + } + } + + } + + } ## end else [ if ($dest_slice_strand...)] + push @out, Bio::EnsEMBL::AssemblyExceptionFeature->new( '-dbID' => $f->dbID, '-start' => $new_start, diff --git a/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm index 9f5cbb116c19922a06864fac7c529c1cf9ccc209..1c2839612ec9b5f7a164bb07fb8443babb1d4323 100644 --- a/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm @@ -501,25 +501,112 @@ FEATURE: # If a destination slice was provided, convert the coords. If the # dest_slice starts at 1 and is forward strand, nothing needs doing. if ( defined($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; - } 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 = -$seq_region_strand; - } + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + + $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()) { + # Handle cicular chromosomes. + + 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 -= $seq_region_len; + } + + if ($seq_region_end < 0) { + $seq_region_end += $seq_region_len; + } + + } 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 += $seq_region_len; + $seq_region_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $start = $dest_slice_end - $seq_region_end + 1; + my $end = $dest_slice_end - $seq_region_start + 1; + + if ($dest_slice->is_circular()) { + + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + + if ($seq_region_start >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $dest_slice_start; - # Throw away features off the end of the requested slice. - if ( $seq_region_end < 1 - || $seq_region_start > $dest_slice_length - || ( $dest_slice_seq_region_id ne $seq_region_id ) ) + } elsif ($seq_region_start <= $dest_slice_end) { + # do nothing + } elsif ($seq_region_end >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $dest_slice_end) { + + $end += $seq_region_len + if $end < 0; + + } elsif ($seq_region_start > $seq_region_end) { + + $end += $seq_region_len; + + } else { + + } + + } else { + + if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $dest_slice_end) { + + $start -= $seq_region_len; + + } elsif ($seq_region_end >= $dest_slice_start) { + $end += $seq_region_len; + + } else { + + } + } + } + + } + + $seq_region_start = $start; + $seq_region_end = $end; + $seq_region_strand *= -1; + + } ## 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_seq_region_id ne $seq_region_id ) ) { next FEATURE; } - } + $slice = $dest_slice; } diff --git a/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm index 216829a42d4115942f82a147a9ba733bf0b7f8ba..09c27241fbcf692c86572331304fa5dfb664b404 100644 --- a/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/MiscFeatureAdaptor.pm @@ -469,20 +469,106 @@ 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 ($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; - } 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; - } - } + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + + $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()) { + # Handle cicular chromosomes. + + 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 -= $seq_region_len; + } + + if ($seq_region_end < 0) { + $seq_region_end += $seq_region_len; + } + + } 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 += $seq_region_len; + $seq_region_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $start = $dest_slice_end - $seq_region_end + 1; + my $end = $dest_slice_end - $seq_region_start + 1; + + if ($dest_slice->is_circular()) { + + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + + if ($seq_region_start >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $dest_slice_start; + + } elsif ($seq_region_start <= $dest_slice_end) { + # do nothing + } elsif ($seq_region_end >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $dest_slice_end) { + + $end += $seq_region_len + if $end < 0; + + } elsif ($seq_region_start > $seq_region_end) { + + $end += $seq_region_len; + + } else { + + } + + } else { + + if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $dest_slice_end) { + + $start -= $seq_region_len; + + } elsif ($seq_region_end >= $dest_slice_start) { + $end += $seq_region_len; + + } else { + + } + } + } + + } + + $seq_region_start = $start; + $seq_region_end = $end; + $seq_region_strand *= -1; + + } ## 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 )) { @@ -490,6 +576,7 @@ sub _objs_from_sth { $throw_away = $misc_feature_id; next FEATURE; } + $slice = $dest_slice; } diff --git a/modules/Bio/EnsEMBL/DBSQL/PredictionTranscriptAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/PredictionTranscriptAdaptor.pm index 492509618243667bf78e371c0f42826198a3479f..fc31865db88f3f2acfa53944185a7d311e314221 100644 --- a/modules/Bio/EnsEMBL/DBSQL/PredictionTranscriptAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/PredictionTranscriptAdaptor.pm @@ -383,20 +383,105 @@ 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($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; - } 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; + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + + $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()) { + # Handle cicular chromosomes. + + 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 -= $seq_region_len; + } + + if ($seq_region_end < 0) { + $seq_region_end += $seq_region_len; + } + + } 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 += $seq_region_len; + $seq_region_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $start = $dest_slice_end - $seq_region_end + 1; + my $end = $dest_slice_end - $seq_region_start + 1; + + if ($dest_slice->is_circular()) { + + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + + if ($seq_region_start >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $dest_slice_start; + + } elsif ($seq_region_start <= $dest_slice_end) { + # do nothing + } elsif ($seq_region_end >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $dest_slice_end) { + + $end += $seq_region_len + if $end < 0; + + } elsif ($seq_region_start > $seq_region_end) { + + $end += $seq_region_len; + + } else { + + } + + } else { + + if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $dest_slice_end) { + + $start -= $seq_region_len; + + } elsif ($seq_region_end >= $dest_slice_start) { + $end += $seq_region_len; + + } else { + + } + } + } + } - } + + $seq_region_start = $start; + $seq_region_end = $end; + $seq_region_strand *= -1; + + } ## 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 || @@ -404,7 +489,6 @@ sub _objs_from_sth { next FEATURE; } - $slice = $dest_slice; } diff --git a/modules/Bio/EnsEMBL/DBSQL/ProteinAlignFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/ProteinAlignFeatureAdaptor.pm index fa25b1c3d3982c9588188fe8140a528b8bed17f0..dc0802dc229e075a79760be83d2939f3326f9e67 100644 --- a/modules/Bio/EnsEMBL/DBSQL/ProteinAlignFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/ProteinAlignFeatureAdaptor.pm @@ -287,26 +287,112 @@ 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($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; - } 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; - } - } + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + + $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()) { + # Handle cicular chromosomes. + + 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 -= $seq_region_len; + } + + if ($seq_region_end < 0) { + $seq_region_end += $seq_region_len; + } + + } 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 += $seq_region_len; + $seq_region_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $start = $dest_slice_end - $seq_region_end + 1; + my $end = $dest_slice_end - $seq_region_start + 1; + + if ($dest_slice->is_circular()) { + + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + + if ($seq_region_start >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $dest_slice_start; + + } elsif ($seq_region_start <= $dest_slice_end) { + # do nothing + } elsif ($seq_region_end >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $dest_slice_end) { + + $end += $seq_region_len + if $end < 0; + + } elsif ($seq_region_start > $seq_region_end) { + + $end += $seq_region_len; + + } else { + + } + + } else { + + if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $dest_slice_end) { + + $start -= $seq_region_len; + + } elsif ($seq_region_end >= $dest_slice_start) { + $end += $seq_region_len; + + } else { + + } + } + } + + } + + $seq_region_start = $start; + $seq_region_end = $end; + $seq_region_strand *= -1; + + } ## 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 )) { next FEATURE; } + $slice = $dest_slice; } diff --git a/modules/Bio/EnsEMBL/Map/DBSQL/DitagFeatureAdaptor.pm b/modules/Bio/EnsEMBL/Map/DBSQL/DitagFeatureAdaptor.pm index 33e8fb51523a361abcbc7366a324e940728cc9e4..148ddc9456d17b56c3af9d1715c13c4142f98800 100644 --- a/modules/Bio/EnsEMBL/Map/DBSQL/DitagFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/Map/DBSQL/DitagFeatureAdaptor.pm @@ -300,14 +300,71 @@ sub fetch_pairs_by_Slice { $sth->execute(); $sth->bind_columns( \$tag_id, \$pair_id, \$seq_region_id, \$start, \$end, \$strand, \$analysis_id ,\$tag_count); while ( $sth->fetch ) { - #convert into relative slice coordinates - if($slice->strand == 1) { + # convert into relative slice coordinates + my $seq_region_len = $slice->seq_region_length(); + + if ($slice->strand == 1) { # Positive strand $start = $start - $slice->start + 1; - $end = $end - $slice->start + 1; - } - else{ - $start = $slice->end - $end + 1; - $end = $slice->end - $start + 1; + $end = $end - $slice->start + 1; + + if ($slice->is_circular()) { # Handle circular chromosomes + if ($start > $end) { # Looking at a feature overlapping the chromsome origin + if ($end > $slice->start) { + # Looking at the region in the beginning of the chromosome + $start -= $seq_region_len; + } + + if ($end < 0) { + $end += $seq_region_len; + } + } else { + if ($slice->start > $slice->end && $end < 0) { + # Looking at the region overlapping the chromosome origin and + # a feature which is at the beginning of the chromosome + $start += $seq_region_len; + $end += $seq_region_len; + } + } + } # end if ($dest_slice->is_circular...) + + } else { # Negative strand + my ($seq_region_start, $seq_region_end) = ($start, $end); + $start = $slice->end - $seq_region_end + 1; + $end = $slice->end - $seq_region_start + 1; + + if ($slice->is_circular()) { + if ($slice->start > $slice->end) { # slice spans origin or replication + if ($seq_region_start >= $slice->start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $slice->start; + + } elsif ($seq_region_start <= $slice->end) { + # do nothing + } elsif ($seq_region_end >= $slice->start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $slice->end) { + $end += $seq_region_len + if $end < 0; + } elsif ($seq_region_start > $seq_region_end) { + $end += $seq_region_len; + } else { } + + } else { + if ($seq_region_start <= $slice->end and $seq_region_end >= $slice->start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $slice->end) { + $start -= $seq_region_len; + } elsif ($seq_region_end >= $slice->start) { + $end += $seq_region_len; + } else { } + } + } + } + $strand *= -1; } @@ -375,8 +432,75 @@ sub _fetch { $seqend = $dest_slice_end - $tmp_seq_region_start + 1; $strand *= -1; } - $slice = $dest_slice; } + + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + $seqstart = $seqstart - $dest_slice_start + 1; + $seqend = $seqend - $dest_slice_start + 1; + + if ($dest_slice->is_circular()) { # Handle cicular chromosomes + if ($seqstart > $seqend) { # Looking at a feature overlapping the chromsome origin + if ($seqend > $dest_slice_start) { + # Looking at the region in the beginning of the chromosome. + $seqstart -= $seq_region_len; + } + + if ($seqend < 0) { + $seqend += $seq_region_len; + } + } else { + if ($dest_slice_start > $dest_slice_end && $seqend < 0) { + # Looking at the region overlapping the chromosome origin and + # a feature which is at the beginning of the chromosome. + $seqstart += $seq_region_len; + $seqend += $seq_region_len; + } + } + } + } else { # Negative strand + my $start = $dest_slice_end - $seqend + 1; + my $end = $dest_slice_end - $seqstart + 1; + + if ($dest_slice->is_circular()) { + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + if ($seqstart >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seqend > $dest_slice_start; + + } elsif ($seqstart <= $dest_slice_end) { + # do nothing + } elsif ($seqend >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + } elsif ($seqend <= $dest_slice_end) { + $end += $seq_region_len + if $end < 0; + } elsif ($seqstart > $seqend) { + $end += $seq_region_len; + } else { } + } else { + if ($seqstart <= $dest_slice_end and $seqend >= $dest_slice_start) { + # do nothing + } elsif ($seqstart > $seqend) { + if ($seqstart <= $dest_slice_end) { + $start -= $seq_region_len; + } elsif ($seqend >= $dest_slice_start) { + $end += $seq_region_len; + } else { } + } + } + } + + $seqstart = $start; + $seqend = $end; + $strand *= -1; + } + + $slice = $dest_slice; } push @ditag_features, diff --git a/modules/Bio/EnsEMBL/Map/DBSQL/MarkerFeatureAdaptor.pm b/modules/Bio/EnsEMBL/Map/DBSQL/MarkerFeatureAdaptor.pm index d8698cd55d174ff923f675760feda5297eb851df..b02a36959fb832271ae3f399ad226c41dc1e9f23 100644 --- a/modules/Bio/EnsEMBL/Map/DBSQL/MarkerFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/Map/DBSQL/MarkerFeatureAdaptor.pm @@ -298,21 +298,108 @@ sub _objs_from_sth { # If the dest_slice starts at 1 and is foward strand, nothing needs doing # 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; - } 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; - } + my $seq_region_len = $dest_slice->seq_region_length(); + + if ($dest_slice_strand == 1) { # Positive strand + + $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()) { + # Handle cicular chromosomes. + + 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 -= $seq_region_len; + } + + if ($seq_region_end < 0) { + $seq_region_end += $seq_region_len; + } + + } 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 += $seq_region_len; + $seq_region_end += $seq_region_len; + } + } + + } ## end if ($dest_slice->is_circular...) + + } else { # Negative strand + + my $start = $dest_slice_end - $seq_region_end + 1; + my $end = $dest_slice_end - $seq_region_start + 1; + + if ($dest_slice->is_circular()) { + + if ($dest_slice_start > $dest_slice_end) { + # slice spans origin or replication + + if ($seq_region_start >= $dest_slice_start) { + $end += $seq_region_len; + $start += $seq_region_len + if $seq_region_end > $dest_slice_start; + + } elsif ($seq_region_start <= $dest_slice_end) { + # do nothing + } elsif ($seq_region_end >= $dest_slice_start) { + $start += $seq_region_len; + $end += $seq_region_len; + + } elsif ($seq_region_end <= $dest_slice_end) { + + $end += $seq_region_len + if $end < 0; + + } elsif ($seq_region_start > $seq_region_end) { + + $end += $seq_region_len; + + } else { + + } + + } else { + + if ($seq_region_start <= $dest_slice_end and $seq_region_end >= $dest_slice_start) { + # do nothing + } elsif ($seq_region_start > $seq_region_end) { + if ($seq_region_start <= $dest_slice_end) { + + $start -= $seq_region_len; + + } elsif ($seq_region_end >= $dest_slice_start) { + $end += $seq_region_len; + + } else { + + } + } + } - #throw away features off the end of the requested slice - if($seq_region_end < 1 || $seq_region_start > $dest_slice_length) { - next FEATURE; } + + $seq_region_start = $start; + $seq_region_end = $end; + + } ## 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) { + next FEATURE; } + $slice = $dest_slice; }