3 __doc__ =
"Write assembly transformation file in other formats."
7 from optparse
import OptionParser
9 class Formatter(object):
10 def __init__(self, fh):
13 def write_header(self, settings):
17 class ChimeraFormatter(Formatter):
19 """Each line in 'chimera' format lists the transformation index, the
20 cross correlation score, and then the transformation for each component,
21 as a rotation matrix (row-major order) and a translation in angstroms."""
23 def write_line(self, ind, score, transforms):
24 self.fh.write(str(ind)+
"\t"+ score+
"\t")
27 v=t.get_rotation().get_rotation_matrix_row(k)
28 self.fh.write(str(v[0])+
" "+str(v[1])+
" "+str(v[2])+
" ")
30 self.fh.write(str(v[0])+
" "+str(v[1])+
" "+str(v[2])+
" | ")
34 class DockRefFormatter(Formatter):
36 """Each line in 'dockref' format lists the transformation for each component,
37 as a set of three Euler angles (in radians about the fixed x, y and z axes)
38 and a translation in angstroms."""
40 def write_header(self, sd):
42 for i
in range(sd.get_number_of_component_headers()):
43 self.fh.write(sd.get_component_header(i).get_name()+
"|")
46 def write_line(self, ind, score, transforms):
49 tr = t.get_translation()
51 self.fh.write(
"%.6g %.6g %.6g %.6g %.6g %.6g|" \
52 % (eulers.get_x(), eulers.get_y(), eulers.get_z(),
57 formatters = {
'chimera':ChimeraFormatter,
58 'dockref':DockRefFormatter}
61 usage =
"""%prog [options] <asmb.input> <scores> <output file>
63 Write assembly transformation file in other formats.
65 """ +
"\n\n".join([x.__doc__
for x
in formatters.values()])
68 parser.add_option(
"-f",
"--format", default=
'chimera', type=
"choice",
69 choices=formatters.keys(),
70 help=
"type of output to generate (" \
71 +
", ".join(formatters.keys()) \
72 +
"; default: chimera)")
73 options, args = parser.parse_args()
75 parser.error(
"incorrect number of arguments")
78 def run(asmb_fn, combs_fn, fmt):
84 for i
in range(sd.get_number_of_component_headers()):
85 fn = sd.get_component_header(i).get_transformations_fn()
87 for ind, line
in enumerate(open(combs_fn)):
91 fmt.write_line(ind, score,
92 [fits[i][int(c)].get_fit_transformation() \
93 for i,c
in enumerate(comb.split())])
96 options, args = parse_args()
97 fmt = formatters[options.format](open(args[2],
'w'))
98 run(args[0], args[1], fmt)
100 if __name__ ==
"__main__":