I have downloaded a GWAS sumstats file and have a list of SNP locations. 

The information for each SNP location is condensed in column 1 of the sumstats file in the following format:

        1:100000012_G_T

- 1 = Chromosome
- 100000012 = SNP location
- T = Allele 1
- G = Allele 2

I'm trying to run an LD Score analysis on this sumstats file, but I first need merge these SNPs with SNPs in the hapmap3 SNP list that has SNP IDs in the rs number format (obvs incompatible with the info in the sumstats file). 

I'm looking for the most efficient way to obtain rsIDs for all the SNPs I have in the sumstats file (munging the file itself is not an issue).

Is there an R/bash method/package/command that can do this (I've checked out bed2vcf in R but don't think I have enough information for this to work)? 

Or, alternatively, is there a way to generate a VCF file from the information I have here? I've looked into `bcftools annotate` to generate my rs IDs. I have already downloaded hg19 dbSNP VCF file that contains all the rsIDs and associated info, but not sure how to generate the second VCF file (from my sumstats SNP ID info) to run this command. 
Hello,
 
here is a way which can work. First create a python3 script called `sumstat2vcf.py` with this code:

    import re
    import sys
    
    for line in sys.stdin.readlines():
        data = re.split(':|_', line.strip())
        print(data[0], data[1], ".", data[2], data[3], ".", ".", ".", sep="\t")


It expect a list of the location in the format you give above. So we can use `cut` on your sumstat file to get the first column. If the first line of the file decscribes the columns we have to use also `tail` to get rid of it. The result can be streamed directly to the python script to create a vcf file:


    cut -f1 sumstat.txt|tail -n+2|python sumstat2vcf.py|sort -k1,1V -k2,2g > sumstat.vcf


For annotating I prefer [snpSift][1]. To snpSift we can also pipe directly:

    cut -f1 sumstat.txt|tail -n+2|python sumstat2vcf.py|sort -k1,1V -k2,2g|java -jar SnpSift.jar annotate -id dbSNP.vcf.gz > sumstat_annotated.vcf


If you now just wants a list of rs IDs we can go on using `cut` and `grep`:


    cut -f1 sumstat.txt|tail -n+2|python sumstat2vcf.py|sort -k1,1V -k2,2g|java -jar SnpSift.jar annotate -id dbSNP.vcf.gz|cut -f3|grep -e "^rs" > rsId_list.txt

Good luck :)

fin swimmer

**EDIT:**

Based on Alex' answer you can use `awk` instead of the python script. Just replace `python sumstat2vcf.py` with 

    awk '{n=split($0,a,/[:_]/); print a[1]"\t"a[2]"\t.\t"a[3]"\t"a[4]"\t.\t.\t."}'

**EDIT2:**

Tidied up the python code a little bit.
  [1]: http://snpeff.sourceforge.net/SnpSift.html#annotate