diff --git a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm index 075bf38c97..55e14d685c 100644 --- a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm +++ b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm @@ -360,10 +360,22 @@ sub _new_slice_seq { return sub { my ($self, $start, $end, $strand, $preserve_masking) = @_; my ($seq, $length) = ('', 0); - - $start = $start ? ($self->start + $start) - 1 : $self->start; - $end = $end ? ($self->start + $end) - 1 : $self->end; + + my $orig_start = $start; + my $orig_end = $end; + $strand = defined($strand) ? $strand * $self->strand : $self->strand; + + if($self->strand == 1) { + $start = $start ? ($self->start + $start) - 1 : $self->start; + $end = $end ? ($self->start + $end) - 1 : $self->end; + } + else{ + my $input_end = $end; + $end = $end ? ($self->end - $start) + 1 : $self->end; + $start = $start ? ($self->end - $input_end) + 1 : $self->start; + } + my $sr_name = $self->seq_region_name; # indels @@ -396,7 +408,7 @@ sub _new_slice_seq { print STDERR "USING DATABASE\n" if $DEBUG; return scalar(@_) > 1 ? - $self->_fasta_old_db_subseq($start, $end, $strand) : + $self->_fasta_old_db_subseq($orig_start, $orig_end, $strand) : $self->_fasta_old_db_seq(); } } diff --git a/modules/t/fastaSequence.t b/modules/t/fastaSequence.t index 8a86158107..38c1cf9384 100644 --- a/modules/t/fastaSequence.t +++ b/modules/t/fastaSequence.t @@ -114,6 +114,14 @@ is($slice1->subseq(3, 5, -1), 'CCA', 'subseq rev'); is($slice1->subseq(5, 4), '', 'subseq e > s'); is($slice1->subseq(-1, 5), 'CGCATGG', "subseq overlap 5'"); +# test subseq on transcript feature slice on reverse strand +my $stable_id = 'ENST00000346798'; +my $transcript_adaptor = $cdb->get_TranscriptAdaptor(); +my $transcript = $transcript_adaptor->fetch_by_stable_id($stable_id); +my $transcript_slice = $transcript->feature_Slice; +is($transcript_slice->subseq(1, 2), 'CA', 'subseq on slice on reverse strand'); + + # test going off ends $slice1 = $sa->fetch_by_region('chromosome', 21, 1, 10);