Skip to content

Instantly share code, notes, and snippets.

@adiamb
Created November 7, 2017 06:16
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 adiamb/0178c95717cffe3fb8554a96377c4d8b to your computer and use it in GitHub Desktop.
Save adiamb/0178c95717cffe3fb8554a96377c4d8b to your computer and use it in GitHub Desktop.
import re
import subprocess
from subprocess import PIPE
import sys
import time
import numpy as np
import numpy
impute_file = sys.argv[1]
sample_file= sys.argv[2]
info_file = sys.argv[3]
def dosage_convert(genos):
out=(genos[0]*0)+(genos[1]*1)+(genos[2]*2)
return(str(out))
#[0*p(AA)]+[1*p(AB)]+[2*p(BB)]
## debugging scripts
snps = {}
with open('test_impute.txt') as f_in:
for line in f_in:
if line:
line_parse = line.strip('\r\n').split(' ')
make_keys = ','.join(line_parse[:5])
for i in range(5, len(line_parse), 3):
print line_parse[i:i+3]
genos = np.array(line_parse[i:i+3], dtype=float)
genos1=dosage_convert(genos=genos)
### function to convert genos into dosages goes here
if make_keys in snps:
get_geno = snps.get(make_keys)
snps[make_keys] = str(get_geno)+','+str(genos1)
else:
snps[make_keys]= str(genos1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment