From 4d7119460292ed3c2a123d6a2f568611dc12beee Mon Sep 17 00:00:00 2001 From: aparton Date: Fri, 13 Sep 2019 11:49:51 +0100 Subject: [PATCH 1/4] Return subseq from correct side of seq when on reverse strand using a fasta file --- .../Bio/EnsEMBL/Variation/Utils/FastaSequence.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm index 075bf38c97..c35ae8afe9 100644 --- a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm +++ b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm @@ -361,9 +361,18 @@ sub _new_slice_seq { 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; $strand = defined($strand) ? $strand * $self->strand : $self->strand; + + if($strand == 1) { + $start = $start ? ($self->start + $start) - 1 : $self->start; + $end = $end ? ($self->start + $end) - 1 : $self->end; + } + else{ + my $old_end = $end; + $end = $end ? ($self->end - $start) + 1 : $self->end; + $start = $start ? ($self->end - $old_end) + 1 : $self->start; + } + my $sr_name = $self->seq_region_name; # indels From 5933790bd9735016367b7ee4834614d6a4f52cc7 Mon Sep 17 00:00:00 2001 From: aparton Date: Fri, 13 Sep 2019 13:44:33 +0100 Subject: [PATCH 2/4] Call the strand in the right place --- modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm index c35ae8afe9..43e52f1e73 100644 --- a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm +++ b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm @@ -363,14 +363,14 @@ sub _new_slice_seq { $strand = defined($strand) ? $strand * $self->strand : $self->strand; - if($strand == 1) { + if($self->strand == 1) { $start = $start ? ($self->start + $start) - 1 : $self->start; $end = $end ? ($self->start + $end) - 1 : $self->end; } else{ - my $old_end = $end; + my $input_end = $end; $end = $end ? ($self->end - $start) + 1 : $self->end; - $start = $start ? ($self->end - $old_end) + 1 : $self->start; + $start = $start ? ($self->end - $input_end) + 1 : $self->start; } my $sr_name = $self->seq_region_name; From c7dc1eb1d40cb6c3541525d9fe6184143aea4392 Mon Sep 17 00:00:00 2001 From: aparton Date: Fri, 13 Sep 2019 14:39:01 +0100 Subject: [PATCH 3/4] Add test for slices on reverse strand --- modules/t/fastaSequence.t | 8 ++++++++ 1 file changed, 8 insertions(+) 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); From f68290dcf8ff20384fa409869f3ff4123ed7f763 Mon Sep 17 00:00:00 2001 From: Andrew Parton Date: Thu, 20 Feb 2020 17:02:12 +0000 Subject: [PATCH 4/4] Use correct coordinates when falling back to database for patch sequence --- modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm index 43e52f1e73..55e14d685c 100644 --- a/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm +++ b/modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm @@ -360,7 +360,10 @@ sub _new_slice_seq { return sub { my ($self, $start, $end, $strand, $preserve_masking) = @_; my ($seq, $length) = ('', 0); - + + my $orig_start = $start; + my $orig_end = $end; + $strand = defined($strand) ? $strand * $self->strand : $self->strand; if($self->strand == 1) { @@ -405,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(); } }