diff --git a/.ci/pep8_sources.txt b/.ci/pep8_sources.txt index e9f4925542e..3f89b65a918 100644 --- a/.ci/pep8_sources.txt +++ b/.ci/pep8_sources.txt @@ -1,9 +1,6 @@ contrib/ doc/patch.py doc/source/conf.py -lib/galaxy/datatypes/converters/lped_to_fped_converter.py -lib/galaxy/datatypes/converters/lped_to_pbed_converter.py -lib/galaxy/datatypes/converters/pbed_ldreduced_converter.py lib/galaxy/model/mapping.py lib/galaxy/model/migrate/versions/ lib/galaxy/model/tool_shed_install/migrate/versions/ diff --git a/lib/galaxy/datatypes/converters/lped_to_fped_converter.py b/lib/galaxy/datatypes/converters/lped_to_fped_converter.py index ad0b9590208..c68b03201cc 100644 --- a/lib/galaxy/datatypes/converters/lped_to_fped_converter.py +++ b/lib/galaxy/datatypes/converters/lped_to_fped_converter.py @@ -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() diff --git a/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py b/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py index 02de89d1070..381630e9d8a 100644 --- a/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py +++ b/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py @@ -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()