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