20 Wrappers for the tmalign and tmscore utilities.
24 tmscore: Yang Zhang and Jeffrey Skolnick, Proteins 2004 57: 702-710
25 tmalign: Y. Zhang and J. Skolnick, Nucl. Acids Res. 2005 33, 2302-9
28 Authors: Pascal Benkert, Marco Biasini
31 import subprocess, os, tempfile, platform
32 from ost
import settings, io, geom, seq
34 def _SetupFiles(models):
36 tmp_dir_name=tempfile.mkdtemp()
37 for index, model
in enumerate(models):
38 io.SavePDB(model, os.path.join(tmp_dir_name,
'model%02d.pdb' % (index+1)))
41 def _CleanupFiles(dir_name):
43 shutil.rmtree(dir_name)
46 def __init__(self, rmsd, tm_score, aligned_length, transform, ref_sequence, alignment):
54 def _ParseTmAlign(lines):
55 info_line=lines[11].split(
',')
56 aln_length=float(info_line[0].split(
'=')[1].strip())
57 rmsd=float(info_line[1].split(
'=')[1].strip())
58 tm_score=float(info_line[2].split(
'=')[1].strip())
59 tf1=[float(i.strip())
for i
in lines[15].split()]
60 tf2=[float(i.strip())
for i
in lines[16].split()]
61 tf3=[float(i.strip())
for i
in lines[17].split()]
62 rot=
geom.Mat3(tf1[2], tf1[3], tf1[4], tf2[2], tf2[3],
63 tf2[4], tf3[2], tf3[3], tf3[4])
65 tf.PasteTranslation(
geom.Vec3(tf1[1], tf2[1], tf3[1]))
66 seq1 = seq.CreateSequence(
"1",lines[26].strip())
67 seq2 = seq.CreateSequence(
"2",lines[28].strip())
68 alignment = seq.CreateAlignment()
69 alignment.AddSequence(seq2)
70 alignment.AddSequence(seq1)
71 return TMAlignResult(rmsd, tm_score, aln_length, tf, seq2, alignment)
73 def _RunTmAlign(tmalign, tmp_dir):
74 model1_filename=os.path.join(tmp_dir,
'model01.pdb')
75 model2_filename=os.path.join(tmp_dir,
'model02.pdb')
76 if platform.system() ==
"Windows":
77 tmalign_path=settings.Locate(
'tmalign.exe', explicit_file_name=tmalign)
78 command=
"\"%s\" %s %s" %(os.path.normpath(tmalign_path), model1_filename, model2_filename)
80 tmalign_path=settings.Locate(
'tmalign', explicit_file_name=tmalign)
81 command=
"\"%s\" \"%s\" \"%s\"" %(tmalign_path, model1_filename, model2_filename)
82 ps=subprocess.Popen(command, shell=
True, stdout=subprocess.PIPE)
84 lines=ps.stdout.readlines()
86 raise RuntimeError(
"tmalign superposition failed")
87 return _ParseTmAlign(lines)
90 def __init__(self, rmsd_common, tm_score, max_sub,
91 gdt_ts, gdt_ha, rmsd_below_five, transform):
100 def _ParseTmScore(lines):
101 tf1=[float(i.strip())
for i
in lines[23].split()]
102 tf2=[float(i.strip())
for i
in lines[24].split()]
103 tf3=[float(i.strip())
for i
in lines[25].split()]
104 rot=
geom.Mat3(tf1[2], tf1[3], tf1[4], tf2[2], tf2[3],
105 tf2[4], tf3[2], tf3[3], tf3[4])
107 tf.PasteTranslation(
geom.Vec3(tf1[1], tf2[1], tf3[1]))
109 float(lines[16].split()[2].strip()),
110 float(lines[17].split()[1].strip()),
111 float(lines[18].split()[1].strip()),
112 float(lines[19].split()[1].strip()),
113 float(lines[27].split()[-1].strip()),
118 def _RunTmScore(tmscore, tmp_dir):
119 model1_filename=os.path.join(tmp_dir,
'model01.pdb')
120 model2_filename=os.path.join(tmp_dir,
'model02.pdb')
121 if platform.system() ==
"Windows":
122 tmscore_path=settings.Locate(
'tmscore.exe', explicit_file_name=tmscore)
123 command=
"\"%s\" %s %s" %(os.path.normpath(tmscore_path), model1_filename,
126 tmscore_path=settings.Locate(
'tmscore', explicit_file_name=tmscore)
127 command=
"\"%s\" \"%s\" \"%s\"" % (tmscore_path, model1_filename,
129 ps=subprocess.Popen(command, shell=
True, stdout=subprocess.PIPE)
131 lines=ps.stdout.readlines()
133 raise RuntimeError(
"tmscore superposition failed")
134 return _ParseTmScore(lines)
138 Run tmalign on two protein structures
140 tmp_dir_name=_SetupFiles((model1, model2))
141 result=_RunTmAlign(tmalign, tmp_dir_name)
142 model1.handle.EditXCS().ApplyTransform(result.transform)
143 _CleanupFiles(tmp_dir_name)
147 Run tmscore on two protein structures
149 tmp_dir_name=_SetupFiles((model1, model2))
150 result=_RunTmScore(tmscore, tmp_dir_name)
151 model1.handle.EditXCS().ApplyTransform(result.transform)
152 _CleanupFiles(tmp_dir_name)