Package Biskit :: Package Mod :: Module AlignerSlave
[hide private]
[frames] | no frames]

Source Code for Module Biskit.Mod.AlignerSlave

  1  ## 
  2  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  3  ## Copyright (C) 2004-2006 Raik Gruenberg & Johan Leckner 
  4  ## 
  5  ## This program is free software; you can redistribute it and/or 
  6  ## modify it under the terms of the GNU General Public License as 
  7  ## published by the Free Software Foundation; either version 2 of the 
  8  ## License, or any later version. 
  9  ## 
 10  ## This program is distributed in the hope that it will be useful, 
 11  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 13  ## General Public License for more details. 
 14  ## 
 15  ## You find a copy of the GNU General Public License in the file 
 16  ## license.txt along with this program; if not, write to the Free 
 17  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 18   
 19  ## Contributions: Olivier PERIN, Raik Gruenberg 
 20  ## last $Author: graik $ 
 21  ## last $Date: 2007/03/05 10:28:22 $ 
 22  ## $Revision: 2.7 $ 
 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   
37 -class AlignerSlave(JobSlave):
38 """ 39 See also: Aligner.py, AlignerMaster.py 40 """ 41
42 - def initialize(self, params):
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 ## Only the PATH must be updated from the master to run properly 53 os.environ["PATH"]=self.params['os.environ']["PATH"] 54 55 self.errorLog = LogFile( self.ferror, mode='a' )
56 57 58
59 - def reportError(self, msg, d ):
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
88 - def prepareT_coffee(self, input_file):
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 ## For the cross validation 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 ## For a classic project folder 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 ## empty test 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