-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_particles_after_EMAN2refine.py
executable file
·86 lines (63 loc) · 2.14 KB
/
extract_particles_after_EMAN2refine.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
#!/usr/bin/env python
import sys
import subprocess
from optparse import OptionParser
import optparse
def setupParserOptions():
parser = optparse.OptionParser()
parser.set_usage("%prog -f <stack> -p <parameter file> --num=<FLOAT>")
parser.add_option("-f",dest="stack",type="string",metavar="FILE",
help="HDF particle stack")
parser.add_option("-p",dest="param",type="string",metavar="FILE",
help="EMAN2 output parameter file")
parser.add_option("--num",dest="num",type="int", metavar="INT",
help="number of models used in refinement")
options,args = parser.parse_args()
if len(args) > 4:
parser.error("Unknown commandline options: " +str(args))
if len(sys.argv) < 4:
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 main(params):
stack=params['stack']
numMods=int(params['num'])
new=stack.strip('.hdf')
if numMods == 1:
param=open(params['param'],'r')
count=1
text='%s_%02d.txt' %(new,1)
text=open(text,'w')
for line in param:
l=line.split()
member=float(l[5])
if member == 999:
text.write("%s\n" %(count-1))
count=count+1
text.close()
param.close()
cmd="e2proc2d.py --list=%s_%02d.txt %s %s_%02d.hdf " %(new,1,stack,new,1)
subprocess.Popen(cmd,shell=True).wait()
else:
for n in range(0,numMods):
param=open(params['param'],'r')
count=1
text='%s_%02d.txt' %(new,n)
text=open(text,'w')
for line in param:
l=line.split()
member=float(l[5])
if member == n:
text.write("%s\n" %(count-1))
count=count+1
text.close()
param.close()
cmd="e2proc2d.py --list=%s_%02d.txt %s %s_%02d.hdf " %(new,n,stack,new,n)
subprocess.Popen(cmd,shell=True).wait()
if __name__ == "__main__":
params=setupParserOptions()
main(params)