Skip to content

Commit

Permalink
Merge pull request #431 from ens-lgil/bugfix/missing_ref_allele_97
Browse files Browse the repository at this point in the history
Fix issue when the reference allele is missing in the variant allele …
  • Loading branch information
ima23 committed Aug 6, 2019
2 parents e9e14e5 + 205ae98 commit 26a059c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ language: perl
os:
- linux

dist:
- trusty

perl:
- '5.14'
- '5.26'
Expand Down
19 changes: 10 additions & 9 deletions modules/Bio/EnsEMBL/Variation/Utils/Sequence.pm
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ sub get_hgvs_alleles{
$ref_allele = $string;
}
}

# no change
elsif ($description =~ m/\=/i) {
($ref_allele) = $description =~ m/([A-Z]*)\=$/i;
Expand Down Expand Up @@ -1055,26 +1054,28 @@ sub get_matched_variant_alleles {

# convert allele_string key
foreach my $var($a, $b) {
if(my $as = $var->{allele_string}) {
my @alleles = split('/', $as);
if($var->{allele_string} && $var->{allele_string} !~ /^\/.+$/) {
my @alleles = split('/', $var->{allele_string});
$var->{ref} ||= shift @alleles;
$var->{alts} = \@alleles unless exists($var->{alts});
}
}

# check ref
throw("Missing ref key in first variant") unless exists($a->{ref});
throw("Missing ref key in second variant") unless exists($b->{ref});
warning("Missing ref key in first variant") unless exists($a->{ref});
warning("Missing ref key in second variant") unless exists($b->{ref});

# check alts
$a->{alts} ||= [$a->{alt}] if defined($a->{alt});
$b->{alts} ||= [$b->{alt}] if defined($b->{alt});
throw("Missing alt or alts key in first variant") unless exists($a->{alts});
throw("Missing alt or alts key in second variant") unless exists($b->{alts});
warning("Missing alt or alts key in first variant") unless exists($a->{alts});
warning("Missing alt or alts key in second variant") unless exists($b->{alts});

# check pos
throw("Missing pos key in first variant") unless $a->{pos};
throw("Missing pos key in second variant") unless $b->{pos};
warning("Missing pos key in first variant") unless $a->{pos};
warning("Missing pos key in second variant") unless $b->{pos};

return [] if (!exists($a->{ref}) || !exists($b->{ref}) || !exists($a->{alts}) || !exists($b->{alts}) || !$a->{pos} || !$b->{pos});

# munge in strand
$a->{strand} = 1 unless exists($a->{strand});
Expand Down
25 changes: 19 additions & 6 deletions modules/t/sequence_utils.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use warnings;

use Test::More;
use Test::Exception;
use Test::Warnings qw(warning :no_end_test);
use Bio::EnsEMBL::Test::MultiTestDB;

BEGIN {
Expand Down Expand Up @@ -124,14 +125,26 @@ throws_ok {get_matched_variant_alleles({})} qr/undef/, 'get_matched_variant_alle
throws_ok {get_matched_variant_alleles([])} qr/expected.+HASH/, 'get_matched_variant_alleles - wrong ref type a';
throws_ok {get_matched_variant_alleles({}, [])} qr/expected.+HASH/, 'get_matched_variant_alleles - wrong ref type b';

throws_ok {get_matched_variant_alleles({}, {})} qr/Missing ref key.+first/, 'get_matched_variant_alleles - missing ref field a';
throws_ok {get_matched_variant_alleles({ref => 'A'}, {})} qr/Missing ref key.+second/, 'get_matched_variant_alleles - missing ref field b';
like(
(warning { get_matched_variant_alleles({}, {}) })->[0], qr/Missing ref key.+first/, 'get_matched_variant_alleles - missing ref field a'
);
like(
(warning { get_matched_variant_alleles({ref => 'A'}, {}) })->[0], qr/Missing ref key.+second/, 'get_matched_variant_alleles - missing ref field b'
);

throws_ok {get_matched_variant_alleles({ref => 'A'}, {ref => 'A'})} qr/Missing alt.+first/, 'get_matched_variant_alleles - missing alts field a';
throws_ok {get_matched_variant_alleles({ref => 'A', alts => ['B']}, {ref => 'A'})} qr/Missing alt.+second/, 'get_matched_variant_alleles - missing alts field b';
like(
(warning { get_matched_variant_alleles({ref => 'A'}, {ref => 'A'}) })->[0], qr/Missing alt.+first/, 'get_matched_variant_alleles - missing alts field a'
);
like(
(warning { get_matched_variant_alleles({ref => 'A', alts => ['B']}, {ref => 'A'}) })->[0], qr/Missing alt.+second/, 'get_matched_variant_alleles - missing alts field b'
);

throws_ok {get_matched_variant_alleles({ref => 'A', alts => ['B']}, {ref => 'A', alts => ['B']})} qr/Missing pos key.+first/, 'get_matched_variant_alleles - missing pos field a';
throws_ok {get_matched_variant_alleles({ref => 'A', alts => ['B'], pos => 1}, {ref => 'A', alts => ['B']})} qr/Missing pos key.+second/, 'get_matched_variant_alleles - missing pos field b';
like(
warning { get_matched_variant_alleles({ref => 'A', alts => ['B']}, {ref => 'A', alts => ['B'], pos => 2}) }, qr/Missing pos key.+first/, 'get_matched_variant_alleles - missing pos field a'
);
like(
warning { get_matched_variant_alleles({ref => 'A', alts => ['B'], pos => 1}, {ref => 'A', alts => ['B']}) }, qr/Missing pos key.+second/, 'get_matched_variant_alleles - missing pos field b'
);

# define tests
# {
Expand Down

0 comments on commit 26a059c

Please sign in to comment.