1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Parallelise Sequence Alignment
25 """
26
27 from Biskit.PVM import JobSlave
28 import Biskit.tools as T
29
30 from Biskit.Mod.Aligner import Aligner
31 from Biskit.Mod.TemplateCleaner import TemplateCleaner as TC
32 from Biskit.Mod.ValidationSetup import ValidationSetup as VS
33
34 from Biskit import LogFile
35 import os
36
38 """
39 See also: Aligner.py, AlignerMaster.py
40 """
41
43 """
44 Initialize AlignerSlave.
45
46 @param params: dictionary with init parameters
47 @type params: {param:value}
48 """
49 self.__dict__.update( params )
50 self.params = params
51
52
53 os.environ["PATH"]=self.params['os.environ']["PATH"]
54
55 self.errorLog = LogFile( self.ferror, mode='a' )
56
57
58
60 """
61 Report error.
62
63 @param msg: error message
64 @type msg: str
65 @param d: error data
66 @type d: any
67 """
68 try:
69 s = '%s on %s, job %r\n' % (msg, os.uname()[1], d)
70 s += '\nErrorTrace:\n' + T.lastErrorTrace() + '\n'
71
72 self.errorLog.add( s )
73
74 try:
75 print msg
76 except:
77 pass
78 except Exception, why:
79 f = open('ErrorReportError_XRefineSlave','a')
80 f.write( str(why) )
81 try:
82 f.write( T.lastErrorTrace() )
83 except:
84 pass
85 f.close()
86
87
89 """
90 Prepare list of coordinate files (.alpha)
91
92 @param input_file: file with list of .alpha files
93 @type input_file: str
94
95 @return: list of file names
96 @rtype: [str]
97 """
98 alpha_index = open(T.absfile('%s'%input_file,'a+'))
99
100 string_lines = alpha_index.readlines()
101
102 alpha_path = []
103
104 for line in string_lines:
105
106 alpha_path.append(line[:-1])
107
108 return alpha_path
109
110
111 - def go(self, dict):
112 """
113 Run alignment job.
114
115 @param dict: dictionary with run parameters
116 @type dict: {param:value}
117 """
118 d = {}
119 val = None
120
121 try:
122
123 T.flushPrint( self.progress_str )
124 for id, val in dict.items():
125
126 aligner_log = LogFile( '%s/Aligner.log' %val["outFolder"] )
127
128 d[id] = val
129
130 aligner_log.add('Slave aligns %s on %s' % (id,os.uname()[1]) )
131
132 a = Aligner( outFolder= val["outFolder"], log=aligner_log)
133
134
135 if not os.path.exists(val["outFolder"] + TC.F_COFFEE):
136
137 input_file = val["outFolder"] + VS.F_TCOFFEE
138
139 alpha_path = self.prepareT_coffee(input_file)
140
141 a.align_for_modeller_inp( pdbFiles=alpha_path,
142 fasta_templates=val["fastaTemplates"],
143 fasta_sequences=val["fastaSequences"],
144 fasta_target=val["fastaTarget"])
145
146
147 else:
148 a.align_for_modeller_inp(pdbFiles=val["pdbFiles"],
149 fasta_templates=val["fastaTemplates"],
150 fasta_sequences=val["fastaSequences"],
151 fasta_target=val["fastaTarget"])
152
153 a.go()
154
155
156 except Exception, why:
157 self.reportError( 'ERROR '+str(why), val )
158
159 print "Done."
160
161 return d
162
163
164
165
166 import Biskit.test as BT
167
168 -class Test(BT.BiskitTest):
169 """Mock test, the Slave is tested in L{Biskit.Mod.AlignerMaster}"""
170 pass
171
172 if __name__ == '__main__':
173
174 slave = AlignerSlave()
175 slave.start()
176