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

Update NearestExonJB #771

Open
wants to merge 7 commits into
base: postreleasefix/114
Choose a base branch
from
Open
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
75 changes: 69 additions & 6 deletions NearestExonJB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ limitations under the License.

This is a plugin for the Ensembl Variant Effect Predictor (VEP) that
finds the nearest exon junction boundary to a coding sequence variant. More than
one boundary may be reported if the boundaries are equidistant.
one boundary may be reported if the boundaries are equidistant or if using option
--intronic.

The plugin will report the Ensembl identifier of the exon, the distance to the
exon boundary, the boundary type (start or end of exon) and the total
Expand All @@ -44,9 +45,16 @@ limitations under the License.

max_range : maximum search range in bp (default: 10000)

intronic : set to 1 to check nearest exons for intronic variants (default: 0)
returns the nearest exon upstream and downstream without considering
the max_range.


Parameters are passed e.g.:

--plugin NearestExonJB,max_range=50000
--plugin NearestExonJB,max_range=50000,intronic=1
--plugin NearestExonJB,intronic=1

=cut

Expand All @@ -63,6 +71,7 @@ my $char_sep = "|";

my %CONFIG = (
max_range => 10000,
intronic => 0
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting we change the get_header_info since we support intron_variants now

sub new {
Expand Down Expand Up @@ -106,9 +115,39 @@ sub run {
my $loc_string = sprintf("%s:%s-%i-%i", $trv->transcript_stable_id, $vf->{chr} || $vf->seq_region_name, $vf->{start}, $vf->{end});

if(!exists($self->{_cache}) || !exists($self->{_cache}->{$loc_string})) {
my $exons = $trv->_overlapped_exons;
my $exons = $trv->_overlapped_exons; # intronic variants do not overlap any exon
my %dists;
my $min = $CONFIG{max_range};

# For option --intronic, fetch the list of exons with different method
# Do not take into account the max_range
if(scalar @{$exons} == 0 && $CONFIG{intronic} == 1) {
my $intron_numbers = $trv->intron_number();
my $consequences = join(",", map { $_->SO_term } @{$tva->get_all_OverlapConsequences});

if(defined $intron_numbers && $consequences =~ /intron/) {
$exons = $trv->_sorted_exons;
my ($intron_number, $total_number) = split(/\//, $intron_numbers);

# Get the number of exons before and after the intron
my $exon_before = $intron_number;
my $exon_after = $intron_number + 1;

my @exons_tmp;
# Reverse strand we get the exons from the end of the list
if($tva->transcript->strand < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting that we just directly modify the $exons like this

if ($tva->transcript->strand < 0) {
@$exons = ($exons->[-$intron_number], $exons->[-($intron_number + 1)]);
}
else {
@$exons = ($exons->[$intron_number - 1], $exons->[$intron_number]);  
}

push(@exons_tmp, $exons->[-$exon_before]);
push(@exons_tmp, $exons->[-$exon_after]);
}
else {
push(@exons_tmp, $exons->[$exon_before -1]);
push(@exons_tmp, $exons->[$exon_after -1]);
}

$exons = \@exons_tmp;
}
}

foreach my $exon (@$exons) {
my $startD = abs ($vf->start - $exon->seq_region_start);
my $endD = abs ($vf->end - $exon->seq_region_end);
Expand All @@ -128,9 +167,34 @@ sub run {
}

my @finalRes;
foreach my $exon (keys %dists){
if (exists $dists{$exon}{$min}) {
push(@finalRes, $exon.$char_sep.$min.$char_sep.$dists{$exon}{$min}.$char_sep.$dists{$exon}{len})
# For option --intronic, return the closest exons (upstream/dowsntream) from the intron
if(scalar @{$exons} == 2 && $CONFIG{intronic} == 1) {
foreach my $exon (keys %dists) {
my $inner_hash = $dists{$exon};
my $length_value;
my $type;
my $distance_value;

for my $internal_key (keys %{$inner_hash}) {
if($internal_key eq "len") {
$length_value = $inner_hash->{$internal_key};
}
else {
$type = $inner_hash->{$internal_key};
$distance_value = $internal_key;
}
}

my $string = $exon . $char_sep . $distance_value . $char_sep . $type . $char_sep . $length_value;
push(@finalRes, $string);
}
}
else {
# This is the default behaviour of the plugin
foreach my $exon (keys %dists){
if (exists $dists{$exon}{$min}) {
push(@finalRes, $exon.$char_sep.$min.$char_sep.$dists{$exon}{$min}.$char_sep.$dists{$exon}{len})
}
}
}

Expand All @@ -140,4 +204,3 @@ sub run {
}

1;