0
|
1 """
|
|
2 @summary: Save partial z file
|
|
3 @version 7
|
|
4
|
|
5 """
|
|
6 # MAPPER --> save z file
|
|
7
|
|
8 # Input: qtlcart.inp
|
|
9 # qtlcart.map
|
|
10 # parameters.txt
|
|
11
|
|
12 # Output: z_partial.txt
|
|
13
|
|
14 import optparse, sys
|
|
15 import tempfile
|
|
16 import re
|
|
17
|
|
18 def stop_err( msg ):
|
|
19 sys.stderr.write( "%s\n" % msg )
|
|
20 sys.exit()
|
|
21
|
|
22 def __main__():
|
|
23 parser = optparse.OptionParser()
|
|
24 parser.add_option("-i", "--input1", default=None, dest="input1",
|
|
25 help="qtlcart.inp file")
|
|
26 parser.add_option("-j", "--input2", default=None, dest="input2",
|
|
27 help="qtlcart.map file")
|
|
28 parser.add_option("-k", "--input3", default=None, dest="input3",
|
|
29 help="parameters.txt file")
|
|
30
|
|
31 parser.add_option("-p", "--output1", default=None, dest="output1",
|
|
32 help="qtlcart_partial.z file")
|
|
33 (options, args) = parser.parse_args()
|
|
34
|
|
35 try:
|
|
36 open(options.input1, "r").close()
|
|
37 except TypeError, e:
|
|
38 stop_err("You need to supply the qtlcart.inp file:\n" + str(e))
|
|
39 except IOError, e:
|
|
40 stop_err("Can not open the qtlcart.inp file:\n" + str(e))
|
|
41
|
|
42 try:
|
|
43 open(options.input2, "r").close()
|
|
44 except TypeError, e:
|
|
45 stop_err("You need to supply the qtlcart.map file:\n" + str(e))
|
|
46 except IOError, e:
|
|
47 stop_err("Can not open the qtlcart.map file:\n" + str(e))
|
|
48
|
|
49 try:
|
|
50 open(options.input3, "r").close()
|
|
51 except TypeError, e:
|
|
52 stop_err("You need to supply the parameters.txt file:\n" + str(e))
|
|
53 except IOError, e:
|
|
54 stop_err("Can not open the parameters.txt file:\n" + str(e))
|
|
55
|
|
56 ######################################################################
|
|
57 # submit.py
|
|
58 ######################################################################
|
|
59
|
|
60 import subprocess
|
|
61 import os
|
|
62
|
|
63 # Create temp direcotry
|
|
64 tempdir = tempfile.mkdtemp()
|
|
65 #print tempdir
|
|
66
|
|
67 s = "cp %s %s/parameters.txt" %(options.input3, tempdir)
|
|
68 subprocess.call(s, shell=True)
|
|
69 paramters_file = open(tempdir+"/parameters.txt", "r")
|
|
70 parvalues = []
|
|
71 for line in paramters_file:
|
|
72 l = line.strip().split("\t")
|
|
73 if l[0] == "SRmodel":
|
|
74 SRmodel = l[1]
|
|
75 if l[0] == "Zmodel":
|
|
76 Zmodel = l[1]
|
|
77 if l[0] == "threshold":
|
|
78 threshold = l[1]
|
|
79 if l[0] == "walking_speed":
|
|
80 walking_speed = l[1]
|
|
81 if l[0] == "window_size":
|
|
82 window_size = l[1]
|
|
83 if l[0] == "minimum_cM_between_QTL":
|
|
84 minimum_cM_between_QTL = l[1]
|
|
85 paramters_file.close()
|
|
86
|
|
87 # copy INPUT file to the temp directory
|
|
88 s = "cp %s %s/qtlcart.inp" %(options.input1, tempdir)
|
|
89 subprocess.call(s, shell=True)
|
|
90 s = "cp %s %s/qtlcart.map" %(options.input2, tempdir)
|
|
91 subprocess.call(s, shell=True)
|
|
92
|
|
93 f=open(tempdir+"/qtlcart.inp", "r")
|
|
94 ln=f.readlines()
|
|
95 f.close()
|
|
96 count = 0
|
|
97
|
|
98 if ln[0] == "NA":
|
|
99 f1=open(tempdir+"/QTLs_total_parsed_LOD.txt", "w")
|
|
100 f1.write("")
|
|
101 f1.close()
|
|
102 os.system("mv %s/QTLs_total_parsed_LOD.txt %s" %(tempdir,options.output1))
|
|
103 #os.system("mv %s/qtlcart.rc %s" %(tempdir,options.output2))
|
|
104 else:
|
|
105 count += 1
|
|
106 if count == 1:
|
|
107 instruction = "/cluster1/bin/Rcross -i %s/qtlcart.inp -o %s/qtlcart.cro -A -V" %(tempdir, tempdir)
|
|
108 os.system(instruction)
|
|
109
|
|
110 instruction = "/cluster1/bin/SRmapqtl -i %s/qtlcart.cro -e %s/SRqtlcart.log -o %s/qtlcart.sr -m %s/qtlcart.map -M %s -t 9999999999 -A -V" %(tempdir, tempdir, tempdir, tempdir, str(SRmodel))
|
|
111 os.system(instruction)
|
|
112
|
|
113 instruction = "/cluster1/bin/Zmapqtl -i %s/qtlcart.cro -o %s/qtlcart.z -m %s/qtlcart.map -S %s/qtlcart.sr -M %s -d %s -w %s -t 9999999999 -A -V" %(tempdir, tempdir, tempdir, tempdir, str(Zmodel), str(walking_speed), str(window_size))
|
|
114 os.system(instruction)
|
|
115
|
|
116 #####################
|
|
117 # Save partial z file
|
|
118 #####################
|
|
119
|
|
120 zfile=open(tempdir+"/qtlcart_partial.z", "w")
|
|
121 f=open(tempdir+"/qtlcart.z", "r")
|
|
122 done = "no"
|
|
123 for l in f:
|
|
124 if (done != "yes") and (not l.startswith("-e")):
|
|
125 zfile.write(l.strip()+"\n")
|
|
126 else:
|
|
127 done = "yes"
|
|
128 f.close()
|
|
129 zfile.write("-e\n")
|
|
130 zfile.close()
|
|
131
|
|
132 os.system("mv %s/qtlcart_partial.z %s" %(tempdir,options.output1))
|
|
133
|
|
134 if __name__=="__main__":
|
|
135 __main__()
|
|
136
|
|
137
|