-
Notifications
You must be signed in to change notification settings - Fork 0
/
isac_to_star.py
executable file
·47 lines (36 loc) · 1.53 KB
/
isac_to_star.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
#!/usr/bin/env python
# script to edit a star file to keep only the good particles from an ISAC run
# Usage
# genlist.py --starfile=<STARFILE> --list=<SPARXLIST> --output=<OUTPUTSTAR>
# default starfile is particles.star
# default list is isac_substack_particle_id_list.txt
# outputs
# default isac_particles.star -- starfile containing only the good particles as selected by ISAC
# wjr 12-02-2017
import os.path
from optparse import OptionParser
def GetData():
parser=OptionParser()
parser.add_option("--starfile", dest="starfile", help="default=particles.star", default='particles.star',metavar="INPUT_STARFILE")
parser.add_option("--list", dest="isac_list", help="default=isac_substack_particle_id_list.txt", default = 'isac_substack_particle_id_list.txt', metavar="ISAC_LIST")
parser.add_option("--output", dest="outstar", help="default=isac_particles.star", default = 'isac_particles.star', metavar="OUTPUT_STARFILE")
(options, args) = parser.parse_args()
return (options.starfile,options.isac_list,options.outstar)
(starfile,isac_list,outstar)=GetData()
with open (starfile,'r') as fin:
starlines=fin.readlines()
fin.close()
with open (isac_list,'r') as fin:
isac_sel=fin.readlines()
fin.close()
fout=open(outstar,"w")
stardata=[]
for line in starlines:
data=line.split()
if len(data) < 3: #assuming all stardata has at least 3 items, basically this just writes the header
fout.write("%s" %line)
else:
stardata.append(line)
for key in isac_sel:
key = int(key)
fout.write("%s" %stardata[key])