Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
import csv
import json
import sys
import os
import os.path
import urllib2
class SkipComments(object):
def __init__(self, f):
self._f = f
def next(self):
line =
while line.startswith('#'):
line =
return line
def __iter__(self):
return self
SNPS_INDEX_PATH = '.snps-index'
if os.path.isfile(SNPS_INDEX_PATH):
with open(SNPS_INDEX_PATH) as f:
snps_index = json.loads(
snps_data = urllib2.urlopen('')
reader = csv.DictReader(SkipComments(snps_data), dialect='excel-tab')
sys.stderr.write('building SNP index')
snps_index = {}
for i, row in enumerate(reader):
snps_index[row['snp']] = int(row['index']) * 2
if i % 10000 == 0:
with open(SNPS_INDEX_PATH, 'w') as f:
json.dump(snps_index, f)
data = json.loads(
for snp in sys.argv[1:]:
pos = snps_index.get(snp)
if pos is None:
bases = data['genome'][pos:pos+2]
print '\t'.join([snp, bases])