-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeHand_calc_plot.py
executable file
·293 lines (236 loc) · 9.61 KB
/
freeHand_calc_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env python
import glob
import optparse
from sys import *
import os,sys,re
from optparse import OptionParser
import glob
import subprocess
from os import system
import linecache
def setupParserOptions():
parser = optparse.OptionParser()
parser.set_usage("%prog -p <parameter file> -m <model> -o <output folder>")
parser.add_option("-p",dest="param",type="string", metavar="FILE",
help="Parameter file with refinement info (free_param.par)")
parser.add_option("-m",dest="model",type="string", metavar="FILE",
help="Model(s) file used for free-hand test")
parser.add_option("-o",dest="out",type="string", metavar="FILE",
help="Output folder name")
parser.add_option("-d", action="store_true",dest="debug",default=False,
help="debug")
options,args = parser.parse_args()
if len(args) > 0:
parser.error("Unknown commandline options: " +str(args))
if len(sys.argv) < 2:
parser.print_help()
sys.exit()
params={}
for i in parser.option_list:
if isinstance(i.dest,str):
params[i.dest] = getattr(options,i.dest)
return params
def peak(stack,tot,cent):
spifile = "currentSpiderScript.spi"
if os.path.isfile(spifile):
os.remove(spifile)
spi=open(spifile,'w')
spicmd="SD IC NEW\n"
spicmd+="incore\n"
spicmd+="2,%s\n" %(tot)
spicmd+="do lb1 [part] = 1, %s\n" %(tot)
spicmd+="\n"
spicmd+="PK [x] [y]\n"
spicmd+="%s@{******[part]}\n"%(stack[:-4])
spicmd+="(1,0)\n"
spicmd+="[newX] = %s +[x]\n" %(cent)
spicmd+="[newY] = %s +[y]\n" %(cent)
spicmd+="SD IC [part] [newX] [newY]\n"
spicmd+="incore\n"
spicmd+="lb1\n"
spicmd+="SD IC COPY\n"
spicmd+="incore\n"
spicmd+="%s_peak\n" %(stack[:-4])
spicmd+="SD ICE\n"
spicmd+="incore\n"
spicmd+="en d\n"
runSpider(spicmd)
def runSpider(lines):
spifile = "currentSpiderScript.spi"
if os.path.isfile(spifile):
os.remove(spifile)
spi=open(spifile,'w')
spi.write("MD\n")
spi.write("TR OFF\n")
spi.write("MD\n")
spi.write("VB OFF\n")
spi.write("MD\n")
spi.write("SET MP\n")
spi.write("(0)\n")
spi.write("\n")
spi.write(lines)
spi.write("\nEN D\n")
spi.close()
spicmd = "spider spi @currentSpiderScript"
spiout = subprocess.Popen(spicmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stderr.read()
output = spiout.strip().split()
if "ERROR" in output:
print "Spider Error, check 'currentSpiderScript.spi'\n"
sys.exit()
# clean up
os.remove(spifile)
if os.path.isfile("LOG.spi"):
os.remove("LOG.spi")
resultf = glob.glob("results.spi.*")
if resultf:
for f in resultf:
os.remove(f)
def getIMAGICPath():
### get the imagicroot directory
impath = subprocess.Popen("env | grep IMAGIC_ROOT", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
imagicpath = impath.replace("IMAGIC_ROOT=","")
if imagicpath != '/opt/qb3/imagic-110326':
print "imagic/110326 was not found, make sure it is in your path"
sys.exit()
def getCCP4Path():
### get the openmpi directory
ccp4path = subprocess.Popen("env | grep CCP4_PATH", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if ccp4path:
ccp4path = ccp4path.replace("CCP4_PATH=","")
if os.path.exists(ccp4path):
return ccp4path
print "ccp4 is not loaded, make sure it is in your path"
sys.exit()
def grep(string,list):
expr = re.compile(string)
for text in list:
match = expr.search(text)
if match != None:
return match.string
def getEMANPath():
### get the imagicroot directory
emanpath = subprocess.Popen("env | grep EMAN2DIR", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if emanpath:
emanpath = emanpath.replace("EMAN2DIR=","")
if os.path.exists(emanpath):
return emanpath
print "EMAN2 was not found, make sure eman2/2.05 is in your path"
sys.exit()
def main2(params):
param = params['param']
out = params['out']
debug = params['debug']
model = params['model']
#Free hand angular search
p8 = open(param,'r')
fs1 = 'freeHand_ang_search'
fs2 = grep(fs1,p8)
fs3 = fs2.split()
angSearch = fs3[2]
p18 = open(param,'r')
fs1 = 'calc'
fs2 = grep(fs1,p8)
fs3 = fs2.split()
calc = fs3[2]
#Free hand angular search
p9 = open(param,'r')
fs1 = 'num_mod'
fs2 = grep(fs1,p9)
fs3 = fs2.split()
mods = float(fs3[2])
#Merge stacks:
m = 0
script = sys.argv[0]
cwd = '%s/lib' %(script[:-22])
while m < mods:
num = len(glob.glob('model%02d_plots*.mrc'%(m)))
i = 1
while i <= int(num):
cmd = '%s/mrc_to_im.b model%02d_plots_CC_v101_%s.mrc' %(cwd,m,i)
if debug is True:
print cmd
subprocess.Popen(cmd,shell=True).wait()
cmd = 'proc2d model%02d_plots_CC_v101_%s.img model%02d_plots_CC_v101_merge.img' %(m,i,m)
if debug is True:
print cmd
subprocess.Popen(cmd,shell=True).wait()
i = i + 1
cmd = '%s/im_to_mrc.b model%02d_plots_CC_v101_merge.img' %(cwd,m)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s/totsumstack.exe .' %(cwd)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s/totsumstack_mult.csh .' %(cwd)
subprocess.Popen(cmd,shell=True).wait()
cmd = './totsumstack_mult.csh model%02d' %(m)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'rm totsumstack.exe totsumstack_mult.csh'
subprocess.Popen(cmd,shell=True).wait()
if calc is 'C':
line1 = (float(angSearch)*2)/5
line = line1/2
if debug is True:
print '%s = float(%s*2)/5' %(line1,angSearch)
print '%s = %s / 2' %(line,line1)
print '%s/npo_CC_wrap_mult.csh %s model%02d %s' %(cwd,str(float(angSearch)*2),m,line)
cmd = '%s/npo_CC_wrap_mult.csh %s model%02d %s' %(cwd,str(float(angSearch)*2),m,line)
subprocess.Popen(cmd,shell=True).wait()
cmd = '%s/mrc_to_spi.b model%02d_plots_CC_v101_merge.mrc' %(cwd,m)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mkdir %s' %(out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_plots_CC_v101* %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_frehand_CC.ps %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_averageplot_CC_v101.mrc %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s %s/' %(model,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s %s/' %(param,out)
subprocess.Popen(cmd,shell=True).wait()
tot = EMUtil.get_image_count('%s/model%02d_plots_CC_v101_merge.img' %(out,m))
n = int(angSearch)+1
stack = '%s/model%02d_plots_CC_v101_merge.spi' %(out,m)
peak(stack,tot,n)
m = m + 1
if calc is 'P':
line1 = (float(angSearch)*2)/5
line = line1/2
if debug is True:
print '%s = float(%s*2)/5' %(line1,angSearch)
print '%s = %s / 2' %(line,line1)
print '%s/npo_CC_wrap_mult_phase.csh %s model%02d %s' %(cwd,str(float(angSearch)*2),m,line)
cmd = '%s/npo_CC_wrap_mult_phase.csh %s model%02d %s' %(cwd,str(float(angSearch)*2),m,line)
subprocess.Popen(cmd,shell=True).wait()
cmd = '%s/mrc_to_spi.b model%02d_plots_CC_v101_merge.mrc' %(cwd,m)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mkdir %s' %(out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_plots_CC_v101* %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_frehand_CC.ps %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'mv model%02d_averageplot_CC_v101.mrc %s/' %(m,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s %s/' %(model,out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'cp %s %s/' %(param,out)
subprocess.Popen(cmd,shell=True).wait()
tot = EMUtil.get_image_count('%s/model%02d_plots_CC_v101_merge.img' %(out,m))
n = int(angSearch)+1
stack = '%s/model%02d_plots_CC_v101_merge.spi' %(out,m)
peak(stack,tot,n)
m = m + 1
cmd = 'mv *00.* %s' %(out)
subprocess.Popen(cmd,shell=True).wait()
cmd = 'rm -r logfile* test.img test.hed model??*.mrc refine_eman2 z.plot start.hdf *_prep.img *_prep.hed '
subprocess.Popen(cmd,shell=True).wait()
cmd = "cp %s/find_peaks_freeHand.spi %s" %(cwd,out)
subprocess.Popen(cmd,shell=True).wait()
if __name__ == "__main__":
imagicroot = getIMAGICPath()
getCCP4Path()
getEMANPath()
from EMAN2 import *
params=setupParserOptions()
main2(params)