root/galaxy-central/tools/rgenetics/rgGTOOL.py

リビジョン 2, 2.3 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/local/bin/python
2# hack to run and process a linkage format file into
3# the format used by Marchini's SNPTEST imputed case control association
4# expects args as 
5#         rgGTOOL.py $i $o $discrete $logf $outdir
6# ross lazarus
7
8import sys,math,shutil,subprocess,os,time
9from os.path import abspath
10imagedir = '/static/rg' # if needed for images
11myversion = 'V000.1 August 2007'
12
13def timenow():
14    """return current time as a string
15    """
16    return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
17
18
19               
20if __name__ == "__main__":
21    if len(sys.argv) < 6:
22       s = 'rgGTOOL.py needs 5 params - got %s \n' % (sys.argv)
23       sys.stderr.write(s) # print >>,s would probably also work?
24       sys.exit(0)
25    print 'Rgenetics %s http://rgenetics.org SNPTEST Tools, rgGTOOL.py starting at %s' % (myversion,timenow())
26    pname = sys.argv[1]
27    lpedname = pname.split('.ped')[0] # get file name part
28    outname = sys.argv[2]
29    discrete = sys.argv[3]
30    logf = sys.argv[4]
31    outdir = sys.argv[5]
32    cdir = os.getcwd()
33    me = sys.argv[0]
34    mypath = abspath(os.path.join(cdir,me)) # get abs path to this python script
35    shpath = abspath(os.path.sep.join(mypath.split(os.path.sep)[:-1]))
36    alogf = abspath(os.path.join(cdir,logf)) # absolute paths
37    apedf = abspath(os.path.join(cdir,'%s.ped' % lpedname)) # absolute paths
38    amapf = abspath(os.path.join(cdir,'%s.map' % lpedname)) # absolute paths
39    outg = abspath(os.path.join(outdir,'%s.gen' % outname)) # absolute paths
40    outs = abspath(os.path.join(outdir,'%s.sample' % outname)) # absolute paths
41    workdir = abspath(os.path.sep.join(mypath.split(os.path.sep)[:-1])) # trim end off './database/files/foo.dat'
42    os.chdir(workdir)
43    tlogname = '%s.logtemp' % outname
44    sto = file(tlogname,'w')
45    sto.write('rgGTOOL.py: called with %s\n' % (sys.argv))
46    exme = 'gtool'
47    vcl = [exme,'-P','--ped',apedf,'--map',amapf,'--discrete_phenotype',discrete,'--og',outg,'--os',outs]
48    #'/usr/local/bin/plink','/usr/local/bin/plink',pc1,pc2,pc3)
49    #os.spawnv(os.P_WAIT,plink,vcl)
50    p=subprocess.Popen(' '.join(vcl),shell=True,stdout=sto)
51    retval = p.wait()
52    sto.write('rgGTOOL.py after calling %s: vcl=%s\n' % (exme,vcl))
53    sto.close()
54    shutil.move(tlogname,alogf)
55    os.chdir(cdir)
56
57
58
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。