Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return subseq from correct side of seq when on reverse strand using a… #454

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions modules/Bio/EnsEMBL/Variation/Utils/FastaSequence.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down
8 changes: 8 additions & 0 deletions modules/t/fastaSequence.t
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down