This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Identify the nearest common SNP to a given rare variant

I have a list of rare single nucleotide variations (SNVs), and I would like to identify the nearest common SNP to each from both ends.


The input information would be the coordinates of the SNVs (something like this: chr7:127991052, chr18:321720, chr5:76174154, etc.). The output I need is the nearest SNP to each SNV (both upstream and downstream).


What tools could perform this task? Your help is much appreciated!

variant-analysis snv snp

2 answers

assuming the file is sorted

grep -A 1 -B 1 -F 'chr7:127991052' input.txt

Via BEDOPS:

$ vcf2bed < list.vcf > list.bed
$ vcf2bed < snps.vcf > snps.bed
$ closest-features list.bed snps.bed > answer.bed

This seems like a good tool. But it's taking forever to convert the dbSNP file (downloaded from NCBI) from csv to bed....any suggestions? Note that I'm using Cygwin on Windows to run the commands.

To get around limitations in /tmp you could specify an alternative temporary directory for sorting. Add --sort-tmpdir=<dir> and (for example) --max-mem=2g to do sorting in a non-temporary (non /tmp) directory and to sort with 2GB of system memory. See --help or the online documentation for more detail.

Log in to answer this question.