mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Fix lped converters and remove from flake8 blacklist
This commit is contained in:
@@ -32,49 +32,49 @@ def timenow():
|
||||
|
||||
|
||||
def rgConv(inpedfilepath, outhtmlname, outfilepath):
|
||||
"""convert linkage ped/map to fbat"""
|
||||
recode = {'A': '1', 'C': '2', 'G': '3', 'T': '4', 'N': '0', '0': '0', '1': '1', '2': '2', '3': '3', '4': '4'}
|
||||
basename = os.path.split(inpedfilepath)[-1] # get basename
|
||||
inmap = '%s.map' % inpedfilepath
|
||||
inped = '%s.ped' % inpedfilepath
|
||||
outf = '%s.ped' % basename # note the fbat exe insists that this is the extension for the ped data
|
||||
outfpath = os.path.join(outfilepath, outf) # where to write the fbat format file to
|
||||
try:
|
||||
mf = file(inmap, 'r')
|
||||
except:
|
||||
sys.stderr.write('%s cannot open inmap file %s - do you have permission?\n' % (prog, inmap))
|
||||
sys.exit(1)
|
||||
try:
|
||||
rsl = [x.split()[1] for x in mf]
|
||||
except:
|
||||
sys.stderr.write('## cannot parse %s' % inmap)
|
||||
sys.exit(1)
|
||||
try:
|
||||
os.makedirs(outfilepath)
|
||||
except:
|
||||
pass # already exists
|
||||
head = ' '.join(rsl) # list of rs numbers
|
||||
# TODO add anno to rs but fbat will prolly barf?
|
||||
pedf = file(inped, 'r')
|
||||
o = file(outfpath, 'w', 2 ** 20)
|
||||
o.write(head)
|
||||
o.write('\n')
|
||||
for i, row in enumerate(pedf):
|
||||
if i == 0:
|
||||
lrow = row.split()
|
||||
try:
|
||||
x = [int(x) for x in lrow[10:50]] # look for non numeric codes
|
||||
except:
|
||||
dorecode = 1
|
||||
if dorecode:
|
||||
lrow = row.strip().split()
|
||||
p = lrow[:6]
|
||||
g = lrow[6:]
|
||||
gc = [recode.get(x, '0') for x in g]
|
||||
lrow = p + gc
|
||||
row = '%s\n' % ' '.join(lrow)
|
||||
o.write(row)
|
||||
o.close()
|
||||
"""convert linkage ped/map to fbat"""
|
||||
recode = {'A': '1', 'C': '2', 'G': '3', 'T': '4', 'N': '0', '0': '0', '1': '1', '2': '2', '3': '3', '4': '4'}
|
||||
basename = os.path.split(inpedfilepath)[-1] # get basename
|
||||
inmap = '%s.map' % inpedfilepath
|
||||
inped = '%s.ped' % inpedfilepath
|
||||
outf = '%s.ped' % basename # note the fbat exe insists that this is the extension for the ped data
|
||||
outfpath = os.path.join(outfilepath, outf) # where to write the fbat format file to
|
||||
try:
|
||||
mf = file(inmap, 'r')
|
||||
except:
|
||||
sys.stderr.write('%s cannot open inmap file %s - do you have permission?\n' % (prog, inmap))
|
||||
sys.exit(1)
|
||||
try:
|
||||
rsl = [x.split()[1] for x in mf]
|
||||
except:
|
||||
sys.stderr.write('## cannot parse %s' % inmap)
|
||||
sys.exit(1)
|
||||
try:
|
||||
os.makedirs(outfilepath)
|
||||
except:
|
||||
pass # already exists
|
||||
head = ' '.join(rsl) # list of rs numbers
|
||||
# TODO add anno to rs but fbat will prolly barf?
|
||||
pedf = file(inped, 'r')
|
||||
o = file(outfpath, 'w', 2 ** 20)
|
||||
o.write(head)
|
||||
o.write('\n')
|
||||
for i, row in enumerate(pedf):
|
||||
if i == 0:
|
||||
lrow = row.split()
|
||||
try:
|
||||
x = [int(x) for x in lrow[10:50]] # look for non numeric codes
|
||||
except:
|
||||
dorecode = 1
|
||||
if dorecode:
|
||||
lrow = row.strip().split()
|
||||
p = lrow[:6]
|
||||
g = lrow[6:]
|
||||
gc = [recode.get(z, '0') for z in g]
|
||||
lrow = p + gc
|
||||
row = '%s\n' % ' '.join(lrow)
|
||||
o.write(row)
|
||||
o.close()
|
||||
|
||||
|
||||
def main():
|
||||
@@ -108,6 +108,5 @@ def main():
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -33,31 +33,31 @@ def timenow():
|
||||
|
||||
|
||||
def getMissval(inped=''):
|
||||
"""
|
||||
read some lines...ugly hack - try to guess missing value
|
||||
should be N or 0 but might be . or -
|
||||
"""
|
||||
commonmissvals = {'N': 'N', '0': '0', 'n': 'n', '9': '9', '-': '-', '.': '.'}
|
||||
try:
|
||||
f = file(inped, 'r')
|
||||
except:
|
||||
return None # signal no in file
|
||||
missval = None
|
||||
while missval == None: # doggedly continue until we solve the mystery
|
||||
"""
|
||||
read some lines...ugly hack - try to guess missing value
|
||||
should be N or 0 but might be . or -
|
||||
"""
|
||||
commonmissvals = {'N': 'N', '0': '0', 'n': 'n', '9': '9', '-': '-', '.': '.'}
|
||||
try:
|
||||
f = file(inped, 'r')
|
||||
except:
|
||||
return None # signal no in file
|
||||
missval = None
|
||||
while missval is None: # doggedly continue until we solve the mystery
|
||||
try:
|
||||
l = f.readline()
|
||||
l = f.readline()
|
||||
except:
|
||||
break
|
||||
break
|
||||
ll = l.split()[6:] # ignore pedigree stuff
|
||||
for c in ll:
|
||||
if commonmissvals.get(c, None):
|
||||
missval = c
|
||||
f.close()
|
||||
return missval
|
||||
if not missval:
|
||||
missval = 'N' # punt
|
||||
f.close()
|
||||
return missval
|
||||
missval = c
|
||||
f.close()
|
||||
return missval
|
||||
if not missval:
|
||||
missval = 'N' # punt
|
||||
f.close()
|
||||
return missval
|
||||
|
||||
|
||||
def rgConv(inpedfilepath, outhtmlname, outfilepath, plink):
|
||||
@@ -72,9 +72,7 @@ def rgConv(inpedfilepath, outhtmlname, outfilepath, plink):
|
||||
missval = '0'
|
||||
cl = '%s --noweb --file %s --make-bed --out %s --missing-genotype %s' % (plink, inpedfilepath, outroot, missval)
|
||||
p = subprocess.Popen(cl, shell=True, cwd=outfilepath)
|
||||
retval = p.wait() # run plink
|
||||
|
||||
|
||||
p.wait() # run plink
|
||||
|
||||
|
||||
def main():
|
||||
@@ -110,6 +108,5 @@ def main():
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user