PageRenderTime 5ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/galaxy/datatypes/converters/pbed_to_lped_converter.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 80 lines | 71 code | 3 blank | 6 comment | 0 complexity | f5b6abbaa0157355ac03469937e13b4e MD5 | raw file
  1. # for rgenetics - lped to pbed
  2. # where to stop with converters
  3. # pbed might be central
  4. # eg lped/eigen/fbat/snpmatrix all to pbed
  5. # and pbed to lped/eigen/fbat/snpmatrix ?
  6. # that's a lot of converters
  7. import sys,os,time,subprocess
  8. prog = os.path.split(sys.argv[0])[-1]
  9. myversion = 'Oct 10 2009'
  10. galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  12. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  15. <meta name="generator" content="Galaxy %s tool output - see http://getgalaxy.org" />
  16. <title></title>
  17. <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
  18. </head>
  19. <body>
  20. <div class="document">
  21. """
  22. def timenow():
  23. """return current time as a string
  24. """
  25. return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
  26. def rgConv(inpedfilepath,outhtmlname,outfilepath,plink):
  27. """
  28. """
  29. basename = os.path.split(inpedfilepath)[-1] # get basename
  30. outroot = os.path.join(outfilepath,basename)
  31. cl = '%s --noweb --bfile %s --recode --out %s ' % (plink,inpedfilepath,outroot)
  32. p = subprocess.Popen(cl,shell=True,cwd=outfilepath)
  33. retval = p.wait() # run plink
  34. def main():
  35. """
  36. need to work with rgenetics composite datatypes
  37. so in and out are html files with data in extrafiles path
  38. <command interpreter="python">pbed_to_lped_converter.py '$input1/$input1.metadata.base_name'
  39. '$output1' '$output1.extra_files_path' '${GALAXY_DATA_INDEX_DIR}/rg/bin/plink'
  40. </command>
  41. """
  42. nparm = 4
  43. if len(sys.argv) < nparm:
  44. sys.stderr.write('## %s called with %s - needs %d parameters \n' % (myname,sys.argv,nparm))
  45. sys.exit(1)
  46. inpedfilepath = sys.argv[1]
  47. outhtmlname = sys.argv[2]
  48. outfilepath = sys.argv[3]
  49. try:
  50. os.makedirs(outfilepath)
  51. except:
  52. pass
  53. plink = sys.argv[4]
  54. rgConv(inpedfilepath,outhtmlname,outfilepath,plink)
  55. f = file(outhtmlname,'w')
  56. f.write(galhtmlprefix % prog)
  57. flist = os.listdir(outfilepath)
  58. s = '## Rgenetics: http://bitbucket.org/rgalaxy Galaxy Tools %s %s' % (prog,timenow()) # becomes info
  59. print s
  60. f.write('<div>%s\n<ol>' % (s))
  61. for i, data in enumerate( flist ):
  62. f.write('<li><a href="%s">%s</a></li>\n' % (os.path.split(data)[-1],os.path.split(data)[-1]))
  63. f.write("</div></body></html>")
  64. f.close()
  65. if __name__ == "__main__":
  66. main()