This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Removing SNPs from .bed file?

I have a list of imputed SNPs in a binary file (.bed, .bim, .fam) and I would like to perform some QC before proceeding with further analysis. I need to remove a list of SNPs based on low MAF and poor imputation quality (I have this list). Is it possible to remove this list from the .bed file to create a new binary fileset that no longer contains these variants?

snp

2 answers

Use PLINK (either 1.07 or 1.90).

Look at removing subset of SNPs in this page: http://pngu.mgh.harvard.edu/~purcell/plink/dataman.shtml#exclude

If you have a text file (say snplist.txt) with SNP rsIDs (no headers) containing the list of SNPs that need to be excluded from the SNP data set (example.bed, example.bim, example.fam) use the following command (in PLINK 1.07)

plink --noweb --bfile example --exclude snplist.txt --make-bed --out newdata

This will make the new file in binary format .

If you have a list of SNPs in a text file called snps.txt and a BED file containing elements of interest called elements.bed, you could use grep to filter those elements:

$ grep -vwf snps.txt elements.bed > answer.bed

The -v option does an inverse match (to return lines that do not match patterns), the -w option does a whole-word match, and the -f option gets patterns from an input file.

Thanks for your reply. I'm not sure what exactly is contained in the .bed file - I received it as is and am unable to view the contents as it is binary. I'm mainly concerned with desynchronizing the contents of the .bim file and the .bed file by removing SNPs from the .bim and not the .bed (if that makes sense?). I have the list of SNPs I want to remove in a text document. I'm assuming there are also other columns in the .bed file (not containing SNPs). Would your solution update the SNP list in both the .bed and .bim?

You'd first need to convert the binary into some textual form for grep to operate on. I'm not too familiar with tools that work with binary BED files and rebuild BIM files; perhaps someone can comment here.

Log in to answer this question.