/usr/bin/fill-aa is in vcftools 0.1.12+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 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #!/usr/bin/env perl
#
# Notes:
# * The AA files can be downloaded from ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/pilot_data/technical/reference/ancestral_alignments
# * The program runs samtools, therefore the AA files must be gzipped (not b2zipped).
#
# support: pd3@sanger
use strict;
use warnings;
use Carp;
use Vcf;
use FindBin;
use lib "$FindBin::Bin";
use FaSlice;
my $opts = parse_params();
fill_aa($opts,$$opts{aa_file});
exit;
#--------------------------------
sub error
{
my (@msg) = @_;
if ( scalar @msg ) { confess @msg; }
die
"About: This script fills ancestral alleles into INFO column of VCF files. It depends on samtools,\n",
" therefore the fasta sequence must be gzipped (not bgzipped!) and indexed by samtools faidx.\n",
" The AA files can be downloaded from\n",
" ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/pilot_data/technical/reference/ancestral_alignments\n",
" and processed as shown in the example below. This is because the sequences in the original files\n",
" are named as 'ANCESTOR_for_chromosome:NCBI36:1:1:247249719', but the underlying FaSplice.pm\n",
" requires names as 'chr1' or '1'.\n",
"Usage: fill-aa [OPTIONS] < in.vcf >out.vcf\n",
"Options:\n",
" -a, --ancestral-allele <prefix> Prefix to ancestral allele chromosome files.\n",
" -t, --type <list> Variant types to process: all,indel,ref,snp. [all]\n",
" -h, -?, --help This help message.\n",
"Example:\n",
" # Get the files ready: compress by gzip and index by samtools faidx. Either repeat the\n",
" # following command for each file manually\n",
" bzcat human_ancestor_1.fa.bz2 | sed 's,^>.*,>1,' | gzip -c > human_ancestor_1.fa.gz\n",
" samtools faidx human_ancestor_1.fa.gz\n",
" \n",
" # .. or use this loop (tested in bash shell)\n",
" ls human_ancestor_*.fa.bz2 | while read IN; do\n",
" OUT=`echo \$IN | sed 's,bz2\$,gz,'`\n",
" CHR=`echo \$IN | sed 's,human_ancestor_,, ; s,.fa.bz2,,'`\n",
" bzcat \$IN | sed \"s,^>.*,>\$CHR,\" | gzip -c > \$OUT\n",
" samtools faidx \$OUT\n",
" done\n",
" \n",
" # After this has been done, the following command should return 'TACGTGGcTGCTCTCACACAT'\n",
" samtools faidx human_ancestor_1.fa.gz 1:1000000-1000020\n",
" \n",
" # Now the files are ready to use with fill-aa. Note that the VCF file\n",
" # should be sorted (see vcf-sort), otherwise the performance would be seriously\n",
" # affected.\n",
" cat file.vcf | fill-aa -a human_ancestor_ 2>test.err | gzip -c >out.vcf.gz \n",
"\n";
}
sub parse_params
{
my $opts = {};
while (my $arg=shift(@ARGV))
{
if ( $arg eq '-a' || $arg eq '--ancestral-allele' ) { $$opts{aa_file} = shift(@ARGV); next }
if ( $arg eq '-t' || $arg eq '--type' )
{
my %known = ( snp=>'s', indel=>'i', all=>'a', ref=>'r' );
my $types = shift(@ARGV);
for my $t (split(/,/,$types))
{
if ( !(exists($known{$t})) ) { error("Unknown type [$t] with -t [$types]\n"); }
$$opts{types}{$known{$t}} = 1;
}
if ( exists($$opts{types}{a}) )
{
$$opts{types}{s} = 1;
$$opts{types}{i} = 1;
$$opts{types}{r} = 1;
}
next;
}
if ( $arg eq '-?' || $arg eq '-h' || $arg eq '--help' ) { error(); }
error("Unknown parameter \"$arg\". Run -h for help.\n");
}
if ( !exists($$opts{aa_file}) ) { error("Missing the -a option.\n") }
return $opts;
}
sub fill_aa
{
my ($opts,$aa_fname) = @_;
my $n_unknown = 0;
my $n_filled_sites = 0;
my $n_filled_bases = 0;
my $vcf = Vcf->new(fh=>\*STDIN, assume_uppercase=>1);
$vcf->parse_header();
$vcf->add_header_line({key=>'INFO',ID=>'AA',Number=>1,Type=>'String',
Description=>'Ancestral Allele, ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/pilot_data/technical/reference/ancestral_alignments/README'});
print $vcf->format_header();
my %chr2fa = ();
my $nskipped = 0;
while (my $line = $vcf->next_line() )
{
my $rec = $vcf->next_data_array($line);
my $chr = $$rec[0];
my $pos = $$rec[1];
my $ref = $$rec[3];
if ( !exists($chr2fa{$chr}) )
{
my $fname = $aa_fname;
if ( ! -e $fname )
{
if ( -e "$fname$chr.fa.gz" ) { $fname = "$fname$chr.fa.gz"; }
else { error(qq[Neither "$fname" nor "$fname$chr.fa.gz" exists.\n]); }
}
$chr2fa{$chr} = FaSlice->new(file=>$fname, size=>100_000);
}
my $fa = $chr2fa{$chr};
my $ref_len = length($ref);
if ( exists($$opts{types}) && !exists($$opts{types}{a}) )
{
my $ok = 0;
for my $alt (split(/,/,$$rec[4]))
{
my ($type,$len,$ht) = $vcf->event_type($ref,$alt);
if ( exists($$opts{types}{$type}) ) { $ok=1; last; }
}
if ( !$ok )
{
print $line;
$nskipped++;
next;
}
}
my $aa = $ref_len==1 ? $fa->get_base($chr,$pos) : $fa->get_slice($chr,$pos,$pos+$ref_len-1);
if ( $aa )
{
$$rec[7] = $vcf->add_info_field($$rec[7],'AA'=>$aa);
$n_filled_sites++;
$n_filled_bases+=$ref_len;
}
else
{
$$rec[7] = $vcf->add_info_field($$rec[7],'AA'=>'.');
$n_unknown++;
}
print join("\t",@$rec),"\n";
}
print STDERR
"AA sites filled .. $n_filled_sites\n",
"AA bases filled .. $n_filled_bases\n",
"No AAs .. $n_unknown\n",
"Lines skipped .. $nskipped\n";
}
|