/usr/bin/vcf-validator is in vcftools 0.1.15-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #!/usr/bin/env perl
#
# Author: petr.danecek@sanger
#
use strict;
use warnings;
use Carp;
use Vcf;
use IPC::Open3 'open3';
use IO::Select;
my $opts = parse_params();
do_validation($opts);
exit;
#--------------------------------
sub error
{
my (@msg) = @_;
if ( scalar @msg )
{
croak @msg;
}
die
"Usage: vcf-validator [OPTIONS] file.vcf.gz\n",
"Options:\n",
" -d, --duplicates Warn about duplicate positions.\n",
" -u, --unique-messages Output all messages only once.\n",
" -h, -?, --help This help message.\n",
"\n";
}
sub parse_params
{
my $opts = { unique=>0, duplicates=>0 };
while (my $arg=shift(@ARGV))
{
if ( $arg eq '-d' || $arg eq '--duplicates' ) { $$opts{duplicates}=1; next; }
if ( $arg eq '-u' || $arg eq '--unique-messages' ) { $$opts{unique}=1; next; }
if ( $arg eq '-?' || $arg eq '-h' || $arg eq '--help' ) { error(); }
if ( (-e $arg or $arg=~m{^(?:ftp|http)://}) && !exists($$opts{file}) ) { $$opts{file}=$arg; next; }
error("Unknown parameter or non-existent file: \"$arg\". Run -h for help.\n");
}
return $opts;
}
sub do_validation
{
my ($opts) = @_;
my %opts = $$opts{file} ? (file=>$$opts{file}) : (fh=>\*STDIN);
if ( !$$opts{unique} )
{
my $vcf = Vcf->new(%opts, warn_duplicates=>$$opts{duplicates});
$vcf->run_validation();
return;
}
my ($kid_in,$kid_out,$kid_err);
my $pid = open3($kid_in,$kid_out,$kid_err,'-');
if ( !defined $pid ) { error("Cannot fork: $!"); }
if ($pid)
{
$$opts{known_lines} = [];
my $sel = new IO::Select;
$sel->add($kid_out,$kid_err);
while(my @ready = $sel->can_read)
{
foreach my $fh (@ready)
{
my $line = <$fh>;
if (not defined $line)
{
$sel->remove($fh);
next;
}
print_or_discard_line($opts,$line);
}
}
print_summary($opts);
}
else
{
my $vcf = Vcf->new(%opts, warn_duplicates=>$$opts{duplicates});
$vcf->run_validation();
return;
}
}
sub print_or_discard_line
{
my ($opts,$line) = @_;
my @items = split(/\s+/,$line);
my $nitems = scalar @items;
for my $known (@{$$opts{known_lines}})
{
if ( @items != @{$$known{line}} ) { next; }
my $nmatches = 0;
for (my $i=0; $i<$nitems; $i++)
{
if ( $items[$i] eq $$known{line}[$i] ) { $nmatches++ }
}
if ( $nitems-$nmatches<3 )
{
$$known{n}++;
return;
}
}
push @{$$opts{known_lines}}, { line=>\@items, n=>1 };
print $line;
}
sub print_summary
{
my ($opts) = @_;
my $n = 0;
for my $error (@{$$opts{known_lines}})
{
$n += $$error{n};
}
print "\n\n------------------------\n";
print "Summary:\n";
printf "\t%d errors total \n\n", $n;
$n = 0;
for my $error (sort {$$b{n}<=>$$a{n}} @{$$opts{known_lines}})
{
if ( $n++ > 50 ) { print "\n\nand more...\n"; last; }
printf "\t%d\t..\t%s\n", $$error{n},join(' ',@{$$error{line}});
}
}
|