# Create a genotype matrix from VCF file using bcftools

I have a vcf file that contains SNPs from chromosome 2 for 2000 samples. I want to create a genotype matrix from this vcf file.

The file is in zipped format as well so that I can use bcftools. I want to filter snips with

• MAF>= 1%
• more than 2 alleles.

I'm not quite sure why I have to filter for more than 2 alleles, is it common to do this if I'm trying to perform PCA analysis?

The instruction I'm using right now is:

bcftools query -e'AF<0.01' -e'AF>0.99' chr2.vcf.gz | \
sed 's/0|0/0/g' | sed 's/0|1/1/g' | sed 's/1|0/1/g' | sed 's/1|1/2/g' | \
grep -v "|" > extract.tab

• How do I only extract the multi-allelic cases?

I have a way to do it using bcftools view -m2 chr2.vcf.gz but the results seem fishy.

• How do I correct this?
• What do you mean 'the results seem fishy'? Can you post a small sample input and output. Apr 5 '20 at 7:33