Skip to content

Commit

Permalink
Fix check and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dglemos committed Sep 22, 2023
1 parent 4b70a58 commit b552c4c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
30 changes: 22 additions & 8 deletions modules/Bio/EnsEMBL/VEP/Parser/VCF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,10 @@ sub create_individual_VariationFeatures {

# Compare sample names
if(lc($self->{individual}->[0]) ne 'all') {
my $samples = join(",", sort @{$parser->get_samples});
my $input_samples = join(",", sort @{$include});
my $found = _find_in_array($parser->get_samples, $include);

if($samples ne $input_samples) {
die("ERROR: Sample IDs given ($input_samples) do not match samples from VCF ($samples)\n");
if(!$found) {
die("ERROR: Sample IDs given (", join(",", @{$include}), ") do not match samples from VCF (", join(",", @{$parser->get_samples}), ")\n");
}
}

Expand Down Expand Up @@ -698,11 +697,10 @@ sub create_individuals_zyg_VariationFeature {

# Compare sample names
if(lc($self->{individual_zyg}->[0]) ne 'all') {
my $samples = join(",", sort @{$parser->get_samples});
my $input_samples = join(",", sort @{$include});
my $found = _find_in_array($parser->get_samples, $include);

if($samples ne $input_samples) {
die("ERROR: Sample IDs given ($input_samples) do not match samples from VCF ($samples)\n");
if(!$found) {
die("ERROR: Sample IDs given (", join(",", @{$include}), ") do not match samples from VCF (", join(",", @{$parser->get_samples}), ")\n");
}
}

Expand Down Expand Up @@ -743,4 +741,20 @@ sub create_individuals_zyg_VariationFeature {
return \@return;
}

sub _find_in_array {
my $all_samples = shift;
my $samples = shift;

my %all = map { $_ => 1 } @{$all_samples};
my %input_samples = map { $_ => 1 } @{$samples};

foreach my $sample (keys %input_samples) {
if(!$all{$sample}) {
return 0;
}
}

return 1;
}

1;
28 changes: 28 additions & 0 deletions t/OutputFactory.t
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,34 @@ my $genotype = join ',', sort(@{$result->{ZYG}});
is($genotype, 'barry:HOM,dave:HET,jeff:HOMREF', 'VariationFeature_to_output_hash - individual_zyg');
delete($of->{individual_zyg});

### individual_zyg wrong sample name
dies_ok { get_annotated_buffer({
input_file => $test_cfg->create_input_file([
['##fileformat=VCFv4.1'],
[qw(#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT dave barry jeff)],
[qw(21 25607429 indtest A G . . . GT 0|1 1/1 0/0)],
]),
individual_zyg => 'john',
});
} 'VariationFeature_to_output_hash - individual_zyg wrong sample name';

### individual_zyg correct sample name
$ib = get_annotated_buffer({
input_file => $test_cfg->create_input_file([
['##fileformat=VCFv4.1'],
[qw(#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT dave barry jeff)],
[qw(21 25607429 indtest A G . . . GT 0|1 1/1 0/0)],
]),
individual_zyg => 'dave,barry',
});

$of->{individual_zyg} = ['dave,barry'];
my $result = $of->VariationFeature_to_output_hash($ib->buffer->[0]);
my $genotype = join ',', sort(@{$result->{ZYG}});

is($genotype, 'barry:HOM,dave:HET', 'VariationFeature_to_output_hash - individual_zyg correct sample name');
delete($of->{individual_zyg});


# done
done_testing();
Expand Down

0 comments on commit b552c4c

Please sign in to comment.