This is a test version of Biostars. For the public version, visit https://www.biostars.org.
best way of filtering a VCF file using a list of SNP IDs and ref/alt alleles

Hi,

I need to filter a VCF file keeping only those SNPs that match with a separate list containing 3 columns: their ID, their reference allele and their alternate allele.

I am very new to this kind of procedure so I am trying to understand the most effective strategy to work on this.

I have been suggested to use VCFtools or BCFtools, but I am not sure I can select variants also on the basis of their ref/alt alleles. Is it possible to do this just using the command line?

Thank you

vcf bcftools

2 answers

If your separate list with IDs is formatted the same way as the VCF, then a simple grep should work:

grep -f ID.list full.vcf > filtered.vcf

Edit: Just realized that this command will remove the headers. Quickest solution is to add a line at the top of the ID.list that has the '#' character.

hey, this works but it takes a very long time. What I did instead was adding reference and alternate allele letters to SNP id column and then use VCFtools to make selection.

gatk https://software.broadinstitute.org/gatk/gatkdocs/org_broadinstitute_gatk_tools_walkers_variantutils_SelectVariants.php

Select IDs in fileKeep and exclude IDs in fileExclude:

 java -jar GenomeAnalysisTK.jar \
   -R ref.fasta \
   -T SelectVariants \
   --variant input.vcf \
   -o output.vcf \
   -IDs fileKeep \
   -excludeIDs fileExclude

Log in to answer this question.