# Masking sites in a vcf file

I need to mask all sites in a vcf file flagged by the 1000 Genomes Project as being unfit for population genetic analyses. The sites for all chromosomes are available at:

From above mentioned link you can get both bed files and Fasta files.

I wanted to mask all sites using VCFtools but VCFtools is not longer being updated and therefore, can't me used on the my vcf file because you can only VCFtools upto VCF file format v.2. And file format for my file is v.3. Can someone suggest another tool that I can use. Insights will be appreciated.

If you are familiar with Python, check out the pyvcf.VcfFrame.filter_bed() method I wrote:

from fuc import pyvcf
vf = pyvcf.VcfFrame.from_file('your_vcf.vcf')
filtered_vf = vf.filter_bed('your_bed.bed', opposite=True)
filtered_vf.to_file('filtered.vcf')


I've tried many ways to do this with bcftools but don't think it's possible to exclude a bed file. What you want is

bedtools intersect -v -a sample.vcf -b mask.bed -wa -header

The -v option gives you only the parts of file a that are not in file b. -wa only keeps entries from file a, and -header preserves the header from file a.

Have a look at BCFtools, which I think does most of the stuff that VCFtools does. I notice there's a --mask option in BCFtools consensus, which may do what you want:

-m, --mask FILE
BED file or TAB file with regions to be replaced with N
(the default) or as specified by the next --mask-with
option. See discussion of --regions-file in Common
Options for file format details

• So just to make sure that I am using the correct command. It'll be: bcftools consensus --mask A.fa A.vcf.gz > masked_file.vcf. Is this correct?
– John
Jun 1 at 8:32
• @John Sorry, I don't know anything more than what I've read; I have no experience with using masking in BCFtools or VCFtools. Try it and see if it works!
– gringer
Jun 1 at 13:30