This file is indexed.

/usr/bin/vcf-sort 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
#!/usr/bin/env perl
#
# Author: petr.danecek@sanger
#

use strict;
use warnings;
use Carp;

my $opts = parse_params();
sort_vcf($opts);

exit;

#--------------------------------

sub error
{
    my (@msg) = @_;
    if ( scalar @msg )
    {
        croak @msg;
    }
    die
        "Usage: vcf-sort > out.vcf\n",
        "       cat file.vcf | vcf-sort > out.vcf\n",
        "Options:\n",
        "   -c, --chromosomal-order       Use natural ordering (1,2,10,MT,X) rather then the default (1,10,2,MT,X). This requires\n",
        "                                     new version of the unix \"sort\" command which supports the --version-sort option.\n",
        "   -p, --parallel <int>          Change the number of sorts run concurrently to <int>\n",
        "   -t, --temporary-directory     Use a directory other than /tmp as the temporary directory for sorting.\n",
        "   -h, -?, --help                This help message.\n",
        "\n";
}

sub parse_params
{
    my $opts = {};
    while (my $arg=shift(@ARGV))
    {
        if ( $arg eq '-p' || $arg eq '--parallel-sort' ) { $$opts{parallel_sort}=shift(@ARGV); next; }
        if ( $arg eq '-c' || $arg eq '--chromosomal-order' ) { $$opts{chromosomal_order}=1; next; }
        if ( $arg eq '-?' || $arg eq '-h' || $arg eq '--help' ) { error(); }
        if ( $arg eq '-t' || $arg eq '--temporary-directory' ) { $$opts{temp_dir}=shift(@ARGV); next; }
        if ( -e $arg ) { $$opts{file}=$arg; next }
        error("Unknown parameter \"$arg\". Run -h for help.\n");
    }
    return $opts;
}

sub sort_vcf
{
    my ($opts) = @_;
    
    my $fh;
    if ( exists($$opts{file}) )
    {
        if ( $$opts{file}=~/\.gz$/i )
        {
            open($fh,"gunzip -c $$opts{file} |") or error("$$opts{file}: $!");
        }
        else
        {
            open($fh,'<',$$opts{file}) or error("$$opts{file}: $!");
        }
    }
    else { $fh = *STDIN; }

    my $sort_opts = check_sort_options($opts);
    my $cmd;
    
    if ( exists($$opts{temp_dir}) )
    {
		$cmd = "sort $sort_opts -T $$opts{temp_dir} -k2,2n";    
    }
    else
    {
    	$cmd = "sort $sort_opts -k2,2n";
    }
    print STDERR "$cmd\n";
    open(my $sort_fh,"| $cmd") or error("$cmd: $!");

    my $unflushed = select(STDOUT); 
    $| = 1; 
    while (my $line=<$fh>)
    {
        if ( $line=~/^#/ ) { print $line; next; }
        print $sort_fh $line;
        last;
    }
    select($unflushed);
    while (my $line=<$fh>)
    {
        print $sort_fh $line;
    }
}

sub check_sort_options
{
    my ($opts) = @_;

    my $sort_opts = join('',`sort --help`);
    my $has_version_sort = ( $sort_opts=~/\s+--version-sort\s+/ ) ? 1 : 0;
    my $has_parallel_sort = ( $sort_opts=~/\s+--parallel=/ ) ? 1 : 0;

    if ( $$opts{chromosomal_order} && !$has_version_sort ) 
    {
        error("Old version of sort command installed, please run without the -c option.\n");
    }
    if ( $$opts{parallel_sort} && !$has_version_sort ) 
    {
        error("Old version of sort command installed, please run without the -p option.\n");
    }
    $sort_opts  = ( $$opts{chromosomal_order} && $has_version_sort ) ? '-k1,1V' : '-k1,1d';
    if ( $$opts{parallel_sort} && $has_parallel_sort ) { $sort_opts .= " --parallel $$opts{parallel_sort}"; }
    
    return $sort_opts;
}