@@ -124,7 +124,7 @@ def get_sequence_by_chain(chain_id, sequence_id_map):
124
124
return sequence
125
125
return ''
126
126
127
- def merge_chain_pdbs (chain_mapping , outfile ):
127
+ def merge_chain_pdbs (chain_mapping , outfile , check_format = False ):
128
128
# reorder chains based on the stoichiometry
129
129
# e.g., A2B2: AB CD
130
130
chain_idx = 0
@@ -143,25 +143,36 @@ def merge_chain_pdbs(chain_mapping, outfile):
143
143
#print(contents)
144
144
fw .write ('\n ' .join (contents ))
145
145
146
+ if check_format :
147
+ parser = PDBParser (QUIET = True )
148
+ try :
149
+ structure2 = parser .get_structure ('' , outfile )
150
+ except Exception as e :
151
+ os .system ("rm " + outfile )
152
+
146
153
147
154
def filter_single_model (inparams ):
148
155
149
- clustalw_program , sequence_id_map , inpdb , pdbdir , outpdb = inparams
156
+ clustalw_program , sequence_id_map , inpdb , pdbdir , outpdb , check_format = inparams
150
157
151
158
# print(f"Filtering {inpdb}")
152
159
153
160
# get chain mapping from pdb to fasta file
154
- chain_mapping = get_chain_mapping (clustalw_program = clustalw_program ,
155
- sequence_id_map = sequence_id_map ,
156
- inpdb = inpdb ,
157
- pdbdir = pdbdir )
158
- # print(chain_mapping)
159
- merge_chain_pdbs (chain_mapping , outpdb )
161
+ try :
162
+ chain_mapping = get_chain_mapping (clustalw_program = clustalw_program ,
163
+ sequence_id_map = sequence_id_map ,
164
+ inpdb = inpdb ,
165
+ pdbdir = pdbdir )
166
+ # print(chain_mapping)
167
+ merge_chain_pdbs (chain_mapping , outpdb , check_format )
168
+ except Exception as e :
169
+ print (f"Filtering { inpdb } failed!" )
170
+ print (e )
160
171
161
172
os .system (f"rm -rf { pdbdir } " )
162
173
163
174
164
- def align_models (clustalw_program , fasta_path , outdir , input_model_dir ):
175
+ def align_models (clustalw_program , fasta_path , outdir , input_model_dir , check_format ):
165
176
166
177
# read sequences from fasta file
167
178
sequences , descriptions = parse_fasta (open (fasta_path ).read ())
@@ -193,7 +204,7 @@ def align_models(clustalw_program, fasta_path, outdir, input_model_dir):
193
204
194
205
makedir_if_not_exists (workdir )
195
206
196
- process_list .append ([clustalw_program , sequence_id_map , input_model_dir + '/' + model , workdir , outdir + '/' + model .replace ('.pdb' , '' )])
207
+ process_list .append ([clustalw_program , sequence_id_map , input_model_dir + '/' + model , workdir , outdir + '/' + model .replace ('.pdb' , '' ), check_format ])
197
208
198
209
pool = Pool (processes = 40 )
199
210
results = pool .map (filter_single_model , process_list )
@@ -208,8 +219,9 @@ def align_models(clustalw_program, fasta_path, outdir, input_model_dir):
208
219
parser .add_argument ('--outdir' , type = str , required = True )
209
220
parser .add_argument ('--modeldir' , type = str , required = True )
210
221
parser .add_argument ('--clustalw_program' , type = str , required = True )
211
-
222
+ parser .add_argument ('--check_format' , default = False , type = lambda x : (str (x ).lower () == 'true' ))
223
+
212
224
args = parser .parse_args ()
213
225
214
- align_models (args .clustalw_program , args .fasta_path , args .outdir , args .modeldir )
226
+ align_models (args .clustalw_program , args .fasta_path , args .outdir , args .modeldir , args . check_format )
215
227
0 commit comments