annotate tools/rgenetics/rgGTOOL.py @ 0:9071e359b9a3

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