Skip to content

Instantly share code, notes, and snippets.

@martijnvermaat
Last active May 30, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnvermaat/09cfa3ec1aeaca9d6dec to your computer and use it in GitHub Desktop.
Save martijnvermaat/09cfa3ec1aeaca9d6dec to your computer and use it in GitHub Desktop.
Rename Plink SNPs to their dbSNP rs#
@Heuertje
Copy link

Heuertje commented Mar 4, 2016

Have you got a script to do this? or is this just a note?
Thank you in advance!

@martijnvermaat
Copy link
Author

Hi @Heuertje, sorry for not seeing your comment, GitHub doesn't send notifications for Gist comments...

I used something very simple like this:

#!/usr/bin/env python

import sys

snps = {'snp_%s_%s' % (e[0][3:], e[1]): e[2] for e in
        (l.strip().split() for l in open(sys.argv[1]))}

bim = (l.strip().split() for l in open(sys.argv[2]))
new = open(sys.argv[3], 'w')

for e in bim:
    e[1] = snps.get(e[1], e[1])
    new.write('\t'.join(e) + '\n')

new.close()
bim.close()

Use like this if saved as add_snps.py:

python add_snps.py snp137Common.txt original.bim new.bim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment