Bio-Pipeline-Comparison
view release on metacpan or search on metacpan
lib/Bio/Pipeline/Comparison/Report/ParseVCFCompare.pm view on Meta::CPAN
my ($self) = @_;
$self->_number_of_variants($self->observed_variant_filename);
}
sub _number_of_variants
{
my ($self,$filename) = @_;
my $number_of_variants = 0;
for my $row_results (@{$self->_raw_venn_diagram_results})
{
my $number_of_files_with_overlap = @{$row_results->{files_to_percentage}};
if($number_of_files_with_overlap > 0)
{
for(my $i = 0; $i < $number_of_files_with_overlap; $i++ )
{
if(defined($row_results->{files_to_percentage}->[$1]->{file_name})
&& $row_results->{files_to_percentage}->[$1]->{file_name} eq $filename)
{
$number_of_variants +=$row_results->{number_of_sites};
last;
}
}
}
}
return $number_of_variants;
}
sub _number_of_uniques_for_filename
{
my ($self, $filename) = @_;
for my $row_results (@{$self->_raw_venn_diagram_results})
{
if(@{$row_results->{files_to_percentage}} == 1
&& defined($row_results->{files_to_percentage}->[0]->{file_name})
&& $row_results->{files_to_percentage}->[0]->{file_name} eq $filename)
{
return $row_results->{number_of_sites};
}
}
return 0;
}
sub _build__vcf_compare_fh
{
lib/Bio/Pipeline/Comparison/Report/ParseVCFCompare.pm view on Meta::CPAN
my $vd_regex = $self->_venn_diagram_regex;
my $fh = $self->_vcf_compare_fh;
seek($fh, 0, 0);
while(<$fh>)
{
my $line = $_;
if( $line =~ m/$vd_regex/)
{
my %vd_results;
$vd_results{number_of_sites} = $1;
$vd_results{files_to_percentage} = [ {file_name => $2, percentage => $3} ];
if(defined($4) && defined($5) && defined($6))
{
push(@{$vd_results{files_to_percentage}}, {file_name => $5, percentage => $6} );
}
push(@vd_rows,\%vd_results);
}
}
return \@vd_rows;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
t/Bio/Pipeline/Comparison/Report/ParseVCFCompare.t view on Meta::CPAN
}
ok((my $obj = Bio::Pipeline::Comparison::Report::ParseVCFCompare->new(
known_variant_filename => 't/data/no_overlap/known_no_overlap.vcf.gz',
observed_variant_filename => 't/data/no_overlap/observed_no_overlap.vcf.gz',
'vcf_compare_exec' => abs_path('bin/vcf-compare')
)
), 'Initialise no overlap');
my @expected_no_overlap = (
{
'files_to_percentage' => [
{
'percentage' => '100.0',
'file_name' => 't/data/no_overlap/observed_no_overlap.vcf.gz'
}
],
'number_of_sites' => '5'
},
{
'files_to_percentage' => [
{
'file_name' => 't/data/no_overlap/known_no_overlap.vcf.gz',
'percentage' => '100.0',
}
],
'number_of_sites' => '5'
}
);
is_deeply($obj->_raw_venn_diagram_results, \@expected_no_overlap, 'Results from no overlap' );
is($obj->number_of_false_positives, 5 ,'no overlap fp');
is($obj->number_of_false_negatives, 5 ,'no overlap fn');
ok((my $obj_perfect = Bio::Pipeline::Comparison::Report::ParseVCFCompare->new(
known_variant_filename => 't/data/perfect/known_perfect.vcf.gz',
observed_variant_filename => 't/data/perfect/observed_perfect.vcf.gz',
'vcf_compare_exec' => abs_path('bin/vcf-compare')
)
), 'Initialise all variants the same');
my @expected_perfect = (
{
'files_to_percentage' => [
{
'file_name' => 't/data/perfect/known_perfect.vcf.gz',
'percentage' => '100.0'
},
{
'file_name' => 't/data/perfect/observed_perfect.vcf.gz',
'percentage' => '100.0'
}
],
'number_of_sites' => '5'
}
);
is_deeply($obj_perfect->_raw_venn_diagram_results, \@expected_perfect, 'Results from perfect results' );
is($obj_perfect->number_of_false_positives, 0 ,'perfect fp');
is($obj_perfect->number_of_false_negatives, 0 ,'perfect fn');
ok((my $obj_fn = Bio::Pipeline::Comparison::Report::ParseVCFCompare->new(
known_variant_filename => 't/data/false_negatives/known_false_negatives.vcf.gz',
observed_variant_filename => 't/data/false_negatives/observed_false_negatives.vcf.gz',
'vcf_compare_exec' => abs_path('bin/vcf-compare')
)
), 'Initialise variants with false negatives');
my @expected_fn =
(
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_negatives/known_false_negatives.vcf.gz',
'percentage' => '40.0'
}
],
'number_of_sites' => '2'
},
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_negatives/known_false_negatives.vcf.gz',
'percentage' => '60.0'
},
{
'file_name' => 't/data/false_negatives/observed_false_negatives.vcf.gz',
'percentage' => '100.0'
}
],
'number_of_sites' => '3'
}
);
is_deeply($obj_fn->_raw_venn_diagram_results, \@expected_fn, 'Results from false negatives' );
is($obj_fn->number_of_false_positives, 0 ,'only false negatives fp');
is($obj_fn->number_of_false_negatives, 2 ,'only false negatives fn');
ok((my $obj_fp = Bio::Pipeline::Comparison::Report::ParseVCFCompare->new(
known_variant_filename => 't/data/false_positives/known_false_positives.vcf.gz',
observed_variant_filename => 't/data/false_positives/observed_false_positives.vcf.gz',
'vcf_compare_exec' => abs_path('bin/vcf-compare')
)
), 'Initialise variants with false positives');
my @expected_fp =
(
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_positives/observed_false_positives.vcf.gz',
'percentage' => '16.7'
}
],
'number_of_sites' => '1'
},
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_positives/known_false_positives.vcf.gz',
'percentage' => '100.0'
},
{
'file_name' => 't/data/false_positives/observed_false_positives.vcf.gz',
'percentage' => '83.3'
}
],
'number_of_sites' => '5'
}
);
is_deeply($obj_fp->_raw_venn_diagram_results, \@expected_fp, 'Results from false positives' );
is($obj_fp->number_of_false_positives, 1 ,'only false positives fp');
is($obj_fp->number_of_false_negatives, 0 ,'only false positives fn');
t/Bio/Pipeline/Comparison/Report/ParseVCFCompare.t view on Meta::CPAN
ok((my $obj_fp_and_fn = Bio::Pipeline::Comparison::Report::ParseVCFCompare->new(
known_variant_filename => 't/data/false_positives_and_negatives/known_false_positives_and_negatives.vcf.gz',
observed_variant_filename => 't/data/false_positives_and_negatives/observed_false_positives_and_negatives.vcf.gz',
'vcf_compare_exec' => abs_path('bin/vcf-compare')
)
), 'Initialise variants with false positives and false negatives');
my @expected_fp_and_fn =
(
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_positives_and_negatives/observed_false_positives_and_negatives.vcf.gz',
'percentage' => '25.0'
}
],
'number_of_sites' => '1'
},
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_positives_and_negatives/known_false_positives_and_negatives.vcf.gz',
'percentage' => '25.0'
}
],
'number_of_sites' => '1'
},
{
'files_to_percentage' => [
{
'file_name' => 't/data/false_positives_and_negatives/known_false_positives_and_negatives.vcf.gz',
'percentage' => '75.0'
},
{
'file_name' => 't/data/false_positives_and_negatives/observed_false_positives_and_negatives.vcf.gz',
'percentage' => '75.0'
}
],
'number_of_sites' => '3'
}
);
is_deeply($obj_fp_and_fn->_raw_venn_diagram_results, \@expected_fp_and_fn, 'Results from false positives and false negatives' );
is($obj_fp_and_fn->number_of_false_positives, 1 ,'false positives and false negatives fp');
is($obj_fp_and_fn->number_of_false_negatives, 1 ,'false positives and false negatives fn');
( run in 0.319 second using v1.01-cache-2.11-cpan-709fd43a63f )