/usr/bin/vcf-tstv is in vcftools 0.1.11+dfsg-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 | #!/usr/bin/env perl
#
# Author: petr.danecek@sanger
#
use strict;
use warnings;
use Carp;
my $opts = parse_params();
calc_tstv();
exit;
#--------------------------------
sub error
{
my (@msg) = @_;
if ( scalar @msg ) { confess @msg; }
print
"Usage: cat file.vcf | vcf-tstv\n",
"Options:\n",
" -h, -?, --help This help message.\n",
"\n";
exit -1;
}
sub parse_params
{
my $opts = {};
while (defined(my $arg=shift(@ARGV)))
{
if ( $arg eq '-?' || $arg eq '-h' || $arg eq '--help' ) { error(); }
error("Unknown parameter \"$arg\". Run -h for help.\n");
}
return $opts;
}
sub calc_tstv
{
my $stats;
my $n=0;
my $multiallelic=0;
while (my $line=<STDIN>)
{
if ( substr($line,0,1) eq '#' ) { next; }
$n++;
my $i=-1; for (1..3) { $i=index($line,"\t",$i+1); }
my $j = index($line,"\t",$i+1);
my $ref = substr($line,$i+1,$j-$i-1);
if ( length($ref)>1 ) { next; }
$i = index($line,"\t",$j+1);
my $alt = substr($line,$j+1,$i-$j-1);
if ( $alt eq '.' ) { next; }
$i = index($alt,',');
if ( $i!=-1 ) { $alt = substr($alt,0,$i); } # only first ALT is counted
if ( length($alt)>1 ) { next; }
if ( $i!=-1 ) { $multiallelic++ }
$$stats{$ref.$alt}++;
}
my $ts = 0;
for my $mut (qw(AG GA CT TC))
{
if ( exists($$stats{$mut}) ) { $ts += $$stats{$mut}; }
}
my $tv = 0;
for my $mut (qw(AC CA GT TG AT TA CG GC))
{
if ( exists($$stats{$mut}) ) { $tv += $$stats{$mut}; }
}
my $ratio = $tv ? $ts/$tv : 0;
printf "%.2f\t%d\t(ts=%d tv=%d total=%d skipped=%d multiallelic=%d)\n", $ratio,$ts+$tv, $ts,$tv,$n,$n-$ts-$tv,$multiallelic;
}
|