[hg] galaxy 2870: symlinks are not very useful

details: http://www.bx.psu.edu/hg/galaxy/rev/1a0bb7d6897c changeset: 2870:1a0bb7d6897c user: Ross Lazarus <ross.lazarus@gmail.com> date: Sun Oct 11 15:07:11 2009 -0400 description: symlinks are not very useful 6 file(s) affected in this change: lib/galaxy/datatypes/converters/lped_to_fped_converter.py lib/galaxy/datatypes/converters/lped_to_fped_converter.xml lib/galaxy/datatypes/converters/lped_to_pbed_converter.py lib/galaxy/datatypes/converters/lped_to_pbed_converter.xml lib/galaxy/datatypes/converters/pbed_to_lped_converter.py lib/galaxy/datatypes/converters/pbed_to_lped_converter.xml diffs (383 lines): diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/lped_to_fped_converter.py --- a/lib/galaxy/datatypes/converters/lped_to_fped_converter.py Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/lped_to_fped_converter.py Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,110 @@ -/opt/galaxy/tools/rgenetics/converters/lped_to_fped_converter.py \ No newline at end of file +# for rgenetics - lped to fbat +# recode to numeric fbat version +# much slower so best to always +# use numeric alleles internally + +import sys,os,time + + +prog = os.path.split(sys.argv[0])[-1] +myversion = 'Oct 10 2009' + +galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> +<title></title> +<link rel="stylesheet" href="/static/style/base.css" type="text/css" /> +</head> +<body> +<div class="document"> +""" + +def timenow(): + """return current time as a string + """ + return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) + + +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() + + +def main(): + """call fbater + need to work with rgenetics composite datatypes + so in and out are html files with data in extrafiles path + <command interpreter="python">rg_convert_lped_fped.py '$input1/$input1.metadata.base_name' + '$output1' '$output1.extra_files_path' + </command> + """ + nparm = 3 + if len(sys.argv) < nparm: + sys.stderr.write('## %s called with %s - needs %d parameters \n' % (prog,sys.argv,nparm)) + sys.exit(1) + inpedfilepath = sys.argv[1] + outhtmlname = sys.argv[2] + outfilepath = sys.argv[3] + try: + os.makedirs(outfilepath) + except: + pass + rgConv(inpedfilepath,outhtmlname,outfilepath) + f = file(outhtmlname,'w') + f.write(galhtmlprefix % prog) + flist = os.listdir(outfilepath) + print '## Rgenetics: http://rgenetics.org Galaxy Tools %s %s' % (prog,timenow()) # becomes info + f.write('<div>## Rgenetics: http://rgenetics.org Galaxy Tools %s %s\n<ol>' % (prog,timenow())) + for i, data in enumerate( flist ): + f.write('<li><a href="%s">%s</a></li>\n' % (os.path.split(data)[-1],os.path.split(data)[-1])) + f.write("</div></body></html>") + f.close() + + + +if __name__ == "__main__": + main() diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/lped_to_fped_converter.xml --- a/lib/galaxy/datatypes/converters/lped_to_fped_converter.xml Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/lped_to_fped_converter.xml Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,15 @@ -/opt/galaxy/tools/rgenetics/converters/lped_to_fped_converter.xml \ No newline at end of file +<tool id="lped2fpedconvert" name="Convert lped to fped" version="0.01"> + <!-- <description>__NOT_USED_CURRENTLY_FOR_CONVERTERS__</description> --> + <!-- Used on the metadata edit page. --> + <command interpreter="python"> + lped_to_fped_converter.py '$input1.extra_files_path/$input1.metadata.base_name' '$output1' '$output1.extra_files_path' + </command> + <inputs> + <param format="lped" name="input1" type="data" label="Choose linkage pedigree file"/> + </inputs> + <outputs> + <data format="fped" name="output1" metadata_source="input1"/> + </outputs> + <help> + </help> +</tool> diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/lped_to_pbed_converter.py --- a/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/lped_to_pbed_converter.py Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,110 @@ -/opt/galaxy/tools/rgenetics/converters/lped_to_pbed_converter.py \ No newline at end of file +# for rgenetics - lped to pbed +# where to stop with converters +# pbed might be central +# eg lped/eigen/fbat/snpmatrix all to pbed +# and pbed to lped/eigen/fbat/snpmatrix ? +# that's a lot of converters +import sys,os,time,subprocess + + +prog = os.path.split(sys.argv[0])[-1] +myversion = 'Oct 10 2009' + +galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> +<title></title> +<link rel="stylesheet" href="/static/style/base.css" type="text/css" /> +</head> +<body> +<div class="document"> +""" + +def timenow(): + """return current time as a string + """ + return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) + +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 + try: + l = f.readline() + except: + 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 + close(f) + return missval + +def rgConv(inpedfilepath,outhtmlname,outfilepath,plink): + """ + """ + pedf = '%s.ped' % inpedfilepath + basename = os.path.split(inpedfilepath)[-1] # get basename + outroot = os.path.join(outfilepath,basename) + missval = getMissval(inped = pedf) + if not missval: + print '### lped_to_pbed_converter.py cannot identify missing value in %s' % pedf + 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 + + + + +def main(): + """ + need to work with rgenetics composite datatypes + so in and out are html files with data in extrafiles path + <command interpreter="python">lped_to_pbed_converter.py '$input1/$input1.metadata.base_name' + '$output1' '$output1.extra_files_path' '${GALAXY_DATA_INDEX_DIR}/rg/bin/plink' + </command> + """ + nparm = 4 + if len(sys.argv) < nparm: + sys.stderr.write('## %s called with %s - needs %d parameters \n' % (prog,sys.argv,nparm)) + sys.exit(1) + inpedfilepath = sys.argv[1] + outhtmlname = sys.argv[2] + outfilepath = sys.argv[3] + try: + os.makedirs(outfilepath) + except: + pass + plink = sys.argv[4] + rgConv(inpedfilepath,outhtmlname,outfilepath,plink) + f = file(outhtmlname,'w') + f.write(galhtmlprefix % prog) + flist = os.listdir(outfilepath) + s = '## Rgenetics: http://rgenetics.org Galaxy Tools %s %s' % (prog,timenow()) # becomes info + print s + f.write('<div>%s\n<ol>' % (s)) + for i, data in enumerate( flist ): + f.write('<li><a href="%s">%s</a></li>\n' % (os.path.split(data)[-1],os.path.split(data)[-1])) + f.write("</div></body></html>") + f.close() + + + +if __name__ == "__main__": + main() diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/lped_to_pbed_converter.xml --- a/lib/galaxy/datatypes/converters/lped_to_pbed_converter.xml Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/lped_to_pbed_converter.xml Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,16 @@ -/opt/galaxy/tools/rgenetics/converters/lped_to_pbed_converter.xml \ No newline at end of file +<tool id="lped2pbedconvert" name="Convert lped to plink pbed" version="0.01"> + <!-- <description>__NOT_USED_CURRENTLY_FOR_CONVERTERS__</description> --> + <!-- Used on the metadata edit page. --> + <command interpreter="python"> + lped_to_pbed_converter.py '$input1.extra_files_path/$input1.metadata.base_name' + '$output1' '$output1.extra_files_path' '${GALAXY_DATA_INDEX_DIR}/rg/bin/plink' + </command> + <inputs> + <param format="lped" name="input1" type="data" label="Choose linkage pedigree file"/> + </inputs> + <outputs> + <data format="pbed" name="output1" metadata_source="input1"/> + </outputs> + <help> + </help> +</tool> diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/pbed_to_lped_converter.py --- a/lib/galaxy/datatypes/converters/pbed_to_lped_converter.py Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/pbed_to_lped_converter.py Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,80 @@ -/opt/galaxy/tools/rgenetics/converters/pbed_to_lped_converter.py \ No newline at end of file +# for rgenetics - lped to pbed +# where to stop with converters +# pbed might be central +# eg lped/eigen/fbat/snpmatrix all to pbed +# and pbed to lped/eigen/fbat/snpmatrix ? +# that's a lot of converters +import sys,os,time,subprocess + + +prog = os.path.split(sys.argv[0])[-1] +myversion = 'Oct 10 2009' + +galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> +<title></title> +<link rel="stylesheet" href="/static/style/base.css" type="text/css" /> +</head> +<body> +<div class="document"> +""" + +def timenow(): + """return current time as a string + """ + return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) + + +def rgConv(inpedfilepath,outhtmlname,outfilepath,plink): + """ + """ + + basename = os.path.split(inpedfilepath)[-1] # get basename + outroot = os.path.join(outfilepath,basename) + cl = '%s --noweb --bfile %s --recode --out %s ' % (plink,inpedfilepath,outroot) + p = subprocess.Popen(cl,shell=True,cwd=outfilepath) + retval = p.wait() # run plink + + + + +def main(): + """ + need to work with rgenetics composite datatypes + so in and out are html files with data in extrafiles path + <command interpreter="python">pbed_to_lped_converter.py '$input1/$input1.metadata.base_name' + '$output1' '$output1.extra_files_path' '${GALAXY_DATA_INDEX_DIR}/rg/bin/plink' + </command> + """ + nparm = 4 + if len(sys.argv) < nparm: + sys.stderr.write('## %s called with %s - needs %d parameters \n' % (myname,sys.argv,nparm)) + sys.exit(1) + inpedfilepath = sys.argv[1] + outhtmlname = sys.argv[2] + outfilepath = sys.argv[3] + try: + os.makedirs(outfilepath) + except: + pass + plink = sys.argv[4] + rgConv(inpedfilepath,outhtmlname,outfilepath,plink) + f = file(outhtmlname,'w') + f.write(galhtmlprefix % prog) + flist = os.listdir(outfilepath) + s = '## Rgenetics: http://rgenetics.org Galaxy Tools %s %s' % (prog,timenow()) # becomes info + print s + f.write('<div>%s\n<ol>' % (s)) + for i, data in enumerate( flist ): + f.write('<li><a href="%s">%s</a></li>\n' % (os.path.split(data)[-1],os.path.split(data)[-1])) + f.write("</div></body></html>") + f.close() + + + +if __name__ == "__main__": + main() diff -r 639c6b5e0073 -r 1a0bb7d6897c lib/galaxy/datatypes/converters/pbed_to_lped_converter.xml --- a/lib/galaxy/datatypes/converters/pbed_to_lped_converter.xml Sun Oct 11 15:00:40 2009 -0400 +++ b/lib/galaxy/datatypes/converters/pbed_to_lped_converter.xml Sun Oct 11 15:07:11 2009 -0400 @@ -1,1 +1,16 @@ -/opt/galaxy/tools/rgenetics/converters/pbed_to_lped_converter.xml \ No newline at end of file +<tool id="pbed2lpedconvert" name="Convert plink pbed to linkage lped" version="0.01"> + <!-- <description>__NOT_USED_CURRENTLY_FOR_CONVERTERS__</description> --> + <!-- Used on the metadata edit page. --> + <command interpreter="python"> + pbed_to_lped_converter.py '$input1.extra_files_path/$input1.metadata.base_name' + '$output1' '$output1.extra_files_path' '${GALAXY_DATA_INDEX_DIR}/rg/bin/plink' + </command> + <inputs> + <param format="pbed" name="input1" type="data" label="Choose compressed Plink binary format genotype file"/> + </inputs> + <outputs> + <data format="lped" name="output1" metadata_source="input1"/> + </outputs> + <help> + </help> +</tool>
participants (1)
-
Greg Von Kuster