Skip to content

Instantly share code, notes, and snippets.

@endrebak
Last active December 16, 2019 08:35
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 endrebak/10deff3fba017cbdb61d5da795f7b331 to your computer and use it in GitHub Desktop.
Save endrebak/10deff3fba017cbdb61d5da795f7b331 to your computer and use it in GitHub Desktop.
index1 = 0
index2 = 0
while index1 < len(posin):
pos = posin[index1]
rs = rsin[index1]
if pos == mappos[index2]:
#the 1000 Genomes site was genotyped as part of the map
results.append((rs, pos, mapgpos[index2]))
index1 = index1 + 1
elif pos < mappos[index2]:
#current position in interpolation before marker
if index2 == 0:
#before the first site in the map (genetic position = 0)
results.append((rs, pos, mapgpos[index2]))
index1 = index1 + 1
else:
#interpolate
prevg = mapgpos[index2 - 1]
prevpos = mappos[index2]
frac = (float(pos) - float(mappos[index2 - 1]))/ (float(mappos[index2]) - float(mappos[index2 - 1]))
tmpg = prevg + frac * (mapgpos[index2] - prevg)
results.append((rs, pos, tmpg))
index1 = index1 + 1
elif pos > mappos[index2]:
#current position in interpolation after marker
if index2 == len(mappos) - 1:
#after the last site in the map (genetic position = maximum in map, note could try to extrapolate based
# on rate instead)
results.append((rs, pos, mapgpos[index2]))
index1 = index1 + 1
else:
#increment the marker
index2 = index2 + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment