tap-developability 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. tap_developability/CDR_Profiler/CDR_Assigner.py +96 -0
  2. tap_developability/CDR_Profiler/__init__.py +0 -0
  3. tap_developability/Hydrophobicity_and_Charge_Profiler/Common/PDBUtils.py +187 -0
  4. tap_developability/Hydrophobicity_and_Charge_Profiler/Common/__init__.py +0 -0
  5. tap_developability/Hydrophobicity_and_Charge_Profiler/Hydrophobicity_and_Charge_Assigner.py +814 -0
  6. tap_developability/Hydrophobicity_and_Charge_Profiler/__init__.py +0 -0
  7. tap_developability/Hydrophobicity_and_Charge_Profiler/dat/Hydrophobics.txt +20 -0
  8. tap_developability/Hydrophobicity_and_Charge_Profiler/surface.py +126 -0
  9. tap_developability/Plotters/CDRLen_D3_Template.py +3 -0
  10. tap_developability/Plotters/PNC_D3_Template.py +3 -0
  11. tap_developability/Plotters/PPC_D3_Template.py +3 -0
  12. tap_developability/Plotters/PSH_D3_Template.py +3 -0
  13. tap_developability/Plotters/SFvCSP_D3_Template.py +3 -0
  14. tap_developability/Plotters/__init__.py +26 -0
  15. tap_developability/__init__.py +0 -0
  16. tap_developability/cli.py +470 -0
  17. tap_developability/structure/__init__.py +0 -0
  18. tap_developability/structure/pdb_remove_hydrogens.py +28 -0
  19. tap_developability/structure/process_pdb.py +311 -0
  20. tap_developability/structure/sequence_liabilities.py +74 -0
  21. tap_developability/thresholds.py +91 -0
  22. tap_developability-2.0.1.dist-info/METADATA +202 -0
  23. tap_developability-2.0.1.dist-info/RECORD +26 -0
  24. tap_developability-2.0.1.dist-info/WHEEL +4 -0
  25. tap_developability-2.0.1.dist-info/entry_points.txt +3 -0
  26. tap_developability-2.0.1.dist-info/licenses/LICENCE +11 -0
@@ -0,0 +1,470 @@
1
+ ####################################################################################################
2
+ #### The Therapeutic Antibody Profiler (TAP) ####
3
+ ####################################################################################################
4
+
5
+ #AUTHORS: Matthew IJ Raybould (1), Claire Marks (1), Konrad Krawczyk (1), Bruck Taddese (2), Alan P. Lewis (3), Alexander Bujotzek (4), Jiye Shi (5), Charlotte M Deane (1)
6
+ #
7
+ #(1) Department of Statistics (Oxford Protein Informatics Group), University of Oxford, UK
8
+ #(2) Antibody Discovery Protein Engineering, MedImmune, Cambridge, UK
9
+ #(3) Computation and Modelling Sciences, GlaxoSmithKline Research and Development, Stevenage, UK
10
+ #(4) Roche Pharma Research and Early Development, Large Molecule Research, Penzberg, Germany
11
+ #(5) Chemistry Department, UCB Pharma, Slough, UK
12
+
13
+ ####################################################################################################
14
+ # REQUIRED MODULES
15
+
16
+ from tap_developability.CDR_Profiler.CDR_Assigner import main as region_and_aa_dicts
17
+ from tap_developability.Hydrophobicity_and_Charge_Profiler.Hydrophobicity_and_Charge_Assigner import CreateAnnotation as hydrophob_and_charge_calc
18
+ from tap_developability.Plotters.PSH_D3_Template import psh_graph
19
+ from tap_developability.Plotters.CDRLen_D3_Template import cdr_graph
20
+ from tap_developability.Plotters.PPC_D3_Template import ppc_graph
21
+ from tap_developability.Plotters.PNC_D3_Template import pnc_graph
22
+ from tap_developability.Plotters.SFvCSP_D3_Template import sfvcsp_graph as SFvCSP_graph
23
+ from tap_developability.Plotters import set_threshold_lines
24
+ from tap_developability.thresholds import assign_flag # noqa: F401 (re-exported)
25
+ from tap_developability.structure.pdb_remove_hydrogens import pdb_remove_hydrogens
26
+ from tap_developability.structure.process_pdb import get_modelling_details
27
+ from antibody_utils.structure import Fv, read_structure
28
+ from Bio import SeqIO
29
+ import pickle as pickle
30
+ import subprocess,time,re,argparse,json,os,sys,shutil
31
+ import multiprocessing as mp
32
+ import os,glob
33
+
34
+ ####################################################################################################
35
+
36
+ columns = 100
37
+ linedivide = "\n\n" + ("-"*columns) + "\n\n"
38
+
39
+ header = linedivide + """
40
+ __/\\\\\\\\\\\\\\\\\\\\\\\\\\\\___/\\\\\\\\\\\\\\\\____/\\\\\\\\\\\\\\\\\\\\____\n _\\///////\\\\/////__/\\\\\\\\\\\\\\\\\\\\\\__\\//////////\\\\___\n _______\\/\\\\______/\\\\/////////\\\\_\\/\\\\_____\\/\\\\___\n _______\\/\\\\_____\\/\\\\_______\\/\\\\_\\/\\\\\\\\\\\\\\\\\\/____\n _______\\/\\\\_____\\/\\\\\\\\\\\\\\\\\\\\/\\\\_\\/////////______\n _______\\/\\\\_____\\/\\\\/////////\\\\_\\/\\\\____________\n _______\\/\\\\_____\\/\\\\_______\\/\\\\_\\/\\\\____________\n _______\\/\\\\_____\\/\\\\_______\\/\\\\_\\/\\\\____________\n _______\\///_____\\///_______\\///_\\///____________
41
+ \n\nTHE THERAPEUTIC ANTIBODY PROFILER\n
42
+ Software developed in the Oxford Protein Informatics Group, Department of Statistics, University of Oxford\n
43
+ Matthew I. J. Raybould (Oxford), Claire Marks (Oxford), Konrad Krawczyk (Oxford), Bruck Taddese (AstraZeneca), Jaroslaw Nowak (Oxford), Alan P. Lewis (GSK), Alexander Bujotzek (Roche), Jiye Shi (UCB), Charlotte M. Deane (Oxford)\n
44
+ If you are using this resource for a publication, please cite the following paper:\n
45
+ Raybould, M.I.J., Marks, C., Krawczyk, K., Taddese, B., Nowak, J., Lewis, A.P., Bujotzek, A., Shi, J. & Deane, C.M. (2019) Five Computational Developability Guidelines for Therapeutic Antibody Profiling Proceedings of the National Academy of Sciences USA, 116(10):4025-4030\n
46
+ Example usage: TAP -s QVKLQESGAELARPGASVKLSCKASGYTFTNYWMQWVKQRPGQGLDWIGAIYPGDGNTRYTHKFKGKATLTADKSSSTAYMQLSSLASEDSGVYYCARGEGNYAWFAYWGQGTTVTVSS/DIELTQSPASLSASVGETVTITCQASENIYSYLAWHQQKQGKSPQLLVYNAKTLAGGVSSRFSGSGSGTHFSLKIKSLQPEDFGIYYCQHHYGILPTFGGGTKLEIK --output TAP_example_output
47
+ """ + linedivide
48
+
49
+ ####################################################################################################
50
+
51
+ # Main function that runs TAP on a sequence
52
+ def profile_sequence(heavy_name, heavy_sequence, light_name, light_sequence, h_scale, output, web, verbose=False):
53
+
54
+ if True:
55
+ CDR_data_loc = os.path.join(output, "Outputs")
56
+ Model_data_loc = os.path.join(output, "Final_Models")
57
+ status = "Good"
58
+ abbrev_name = heavy_name[:-2]
59
+ print("TAP is running on sequence %s" %(abbrev_name))
60
+
61
+ logfile = os.path.join(output, abbrev_name+"_TAP.log")
62
+ with open(logfile,"w") as fo:
63
+
64
+ fo.write("The TAP job initialised successfully for "+abbrev_name+".\nIt will calculate CDR lengths, Hydrophobicity and Charge properties, Amino Acid Usage, and Canonical Form Usage.\n\n--------------------------------------------------------------\n\n")
65
+
66
+ if verbose: print("\nAnalysing CDRs and amino acid compositions...\n\n")
67
+
68
+ if verbose: print("The Heavy Chain is analysed as follows:\n\n")
69
+ try:
70
+ heavy_cdr_dict, heavy_aa_dict, heavy_len_dict = region_and_aa_dicts(heavy_name,heavy_sequence,"H",output,verbose=verbose)
71
+ fo.write("TAP managed to number the heavy chain sequence with ANARCI\n")
72
+ except:
73
+ print("TAP could not number the heavy chain sequence %s with ANARCI" %abbrev_name)
74
+ fo.write("TAP failed to number the heavy chain sequence with ANARCI\n")
75
+ return
76
+
77
+ if verbose: print("\n\nThe Light Chain is analysed as follows:\n\n")
78
+ try:
79
+ light_cdr_dict, light_aa_dict, light_len_dict = region_and_aa_dicts(light_name,light_sequence,"L",output,verbose=verbose)
80
+ fo.write("TAP managed to number the light chain sequence with ANARCI.\n")
81
+ except:
82
+ print("TAP could not number the light chain sequence %s with ANARCI" %abbrev_name)
83
+ fo.write("TAP failed to number the light chain sequence with ANARCI.\n")
84
+ return
85
+
86
+ total_imgt_cdr_length = 0
87
+ heavy_loops = ['cdrh1','cdrh2','cdrh3']
88
+ light_loops = ['cdrl1','cdrl2','cdrl3']
89
+
90
+ #Calculate total loop length
91
+ for loop in heavy_loops:
92
+ total_imgt_cdr_length += heavy_len_dict['imgt'][loop]
93
+ for loop in light_loops:
94
+ total_imgt_cdr_length += light_len_dict['imgt'][loop]
95
+
96
+ fo.write("CDR lengths/sequences and amino acid compositions are stored in "+str(output)+"/Outputs/\n")
97
+
98
+ if verbose:
99
+ print(linedivide + "Calling ABodyBuilder2 (ImmuneBuilder model for antibodies) to model your Fv\n\n")
100
+
101
+ try:
102
+ os.makedirs(abbrev_name, exist_ok=True)
103
+
104
+ cmd = ["ABodyBuilder2",
105
+ "--heavy_sequence", heavy_sequence,
106
+ "--light_sequence", light_sequence,
107
+ "--output", os.path.join(abbrev_name, abbrev_name + ".pdb"),
108
+ "--n_threads", "1"]
109
+ if verbose:
110
+ cmd.append("--verbose")
111
+
112
+ subprocess.run(cmd, check=True)
113
+
114
+ #if verbose:
115
+ # subprocess.call(["ABodyBuilder2","--verbose","--heavy_sequence",heavy_sequence,"--light_sequence",light_sequence,"--output",os.path.join(abbrev_name, abbrev_name)+".pdb"])
116
+ #else:
117
+ # subprocess.call(["ABodyBuilder2","--heavy_sequence",heavy_sequence,"--light_sequence",light_sequence,"--output",os.path.join(abbrev_name, abbrev_name)+".pdb"])
118
+
119
+ fo.write("ABodyBuilder2 (ImmuneBuilder) was able to generate a model for this heavy/light chain pairing\n")
120
+
121
+ try:
122
+ input_pdb = os.path.join(abbrev_name, abbrev_name)+".pdb"
123
+ pdb_remove_hydrogens(input_pdb)
124
+ print("Removed all Hydrogens from ABodyBuilder2 model")
125
+
126
+ except Exception as e:
127
+ print(e)
128
+
129
+ except Exception as e:
130
+ print("ERROR: ABodyBuilder2 (ImmuneBuilder) failed to generate a model for your antibody")
131
+ fo.write("ABodyBuilder2 (ImmuneBuilder) was unable to generate a model for this heavy/light chain pairing\n")
132
+ print(e)
133
+ return
134
+
135
+ try:
136
+ # Generate modelling_details.jsonp file (Now a separate step from ImmuneBuilder)
137
+ modelling_details = get_modelling_details(os.path.join(abbrev_name, abbrev_name)+".pdb",type='antibody',save=True)
138
+ fo.write("Saved modelling_details.jsonp for ABodyBuilder2 (ImmuneBuilder) model\n")
139
+
140
+ except Exception as e:
141
+ print("ERROR: Failed to process output PDB. " + str(e))
142
+
143
+ if os.path.exists(os.path.join("Raw_Model_Outputs", abbrev_name)):
144
+ shutil.rmtree(os.path.join("Raw_Model_Outputs", abbrev_name))
145
+ subprocess.call(["mv",abbrev_name,"Raw_Model_Outputs/"+str(heavy_name[:-2])])
146
+ subprocess.call(["cp","Raw_Model_Outputs/"+str(heavy_name[:-2])+"/"+abbrev_name+".pdb","Final_Models/"+str(heavy_name[:-2])+"_ABodyBuilder2_Model.pdb"])
147
+ subprocess.call(["cp","Raw_Model_Outputs/"+str(heavy_name[:-2])+"/modelling_details.jsonp","Final_Models/"+str(heavy_name[:-2])+"_ABodyBuilder2_Model_Details.json"])
148
+ subprocess.call(["cp","Raw_Model_Outputs/"+str(heavy_name[:-2])+"/sequence_liabilities.csv","Final_Models/"+str(heavy_name[:-2])+"_ABodyBuilder2_Sequence_Liabilities.json"])
149
+
150
+ if verbose:
151
+ print(linedivide + "ABodyBuilder2 (ImmuneBuilder) successfully modelled your Fv. Now assigning canonical forms to the loops...\n\n")
152
+
153
+ if verbose:
154
+ print(linedivide + "Finally, calculating surface hydrophobicity and charge properties for your Fv at pH 7.4 (with salt-bridge correction)...\n\n")
155
+
156
+ hydrophob_and_charge_dict = hydrophob_and_charge_calc(h_scale, 7.4, os.path.join(Model_data_loc, abbrev_name+"_ABodyBuilder2_Model.pdb"), os.path.join(output, "Outputs", abbrev_name+"_hydrophobicity_and_charge_dict.pkl"), "IG", "imgt", output, verbose=verbose)
157
+
158
+ fo.write("TAP was able to calculate PSH, PPC, PNC, and SFvCSP scores for your model structure.\n")
159
+
160
+ PSH = hydrophob_and_charge_dict[h_scale]['Patch_Hydrophob_CDR']
161
+ PPC = hydrophob_and_charge_dict[h_scale]['Patch_Pos_Charge_CDR']
162
+ PNC = hydrophob_and_charge_dict[h_scale]['Patch_Neg_Charge_CDR']
163
+ SFvCSP = hydrophob_and_charge_dict[h_scale]['Net Heavy Fv Charge']*hydrophob_and_charge_dict[h_scale]['Net Light Fv Charge']
164
+
165
+ ###############################################################################################################
166
+
167
+ fv_tap_dictionary = {}
168
+ fv_tap_dictionary['name'] = abbrev_name
169
+ fv_tap_dictionary['HCDRs'] = heavy_cdr_dict
170
+ fv_tap_dictionary['LCDRs'] = light_cdr_dict
171
+ fv_tap_dictionary['H3 Length'] = heavy_len_dict['imgt']['cdrh3']
172
+ fv_tap_dictionary['Total CDR Length'] = total_imgt_cdr_length
173
+ fv_tap_dictionary['Hydrophobicity and Charge'] = hydrophob_and_charge_dict
174
+
175
+ fv_tap_dictionary['Flags'] = { "L" : assign_flag("L", total_imgt_cdr_length),
176
+ "PSH" : assign_flag("PSH", PSH),
177
+ "PPC" : assign_flag("PPC", PPC),
178
+ "PNC" : assign_flag("PNC", PNC),
179
+ "SFvCSP": assign_flag("SFvCSP", SFvCSP) }
180
+
181
+ fo.write("\n\nSummary Statistics for %s:\n" %(abbrev_name))
182
+ fo.write(" IMGT H3 Length: %d\n" %(fv_tap_dictionary['H3 Length']))
183
+ fo.write(" Total IMGT CDR Length: %d (%s flag)\n" %(fv_tap_dictionary['Total CDR Length'], fv_tap_dictionary['Flags']['L'].upper()))
184
+ fo.write(" Patch CDR Surface Hydrophobicity score is: %f (%s flag)\n" %(fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Hydrophob_CDR'], fv_tap_dictionary['Flags']['PSH'].upper()))
185
+ fo.write(" Patch CDR Positive Charge score is: %f (%s flag)\n" %(fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Pos_Charge_CDR'], fv_tap_dictionary['Flags']['PPC'].upper()))
186
+ fo.write(" Patch CDR Negative Charge score is: %f (%s flag)\n" %(fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Neg_Charge_CDR'], fv_tap_dictionary['Flags']['PNC'].upper()))
187
+ fo.write(" SFvCSP score is: %f (%s flag)\n" %(fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Net Heavy Fv Charge']*fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Net Light Fv Charge'], fv_tap_dictionary['Flags']['SFvCSP'].upper()))
188
+
189
+ # Populate the output graphs!
190
+ # Only if being run for the web server
191
+ if web:
192
+ from tap_developability.Plotters.PSH_D3_Template import psh_graph
193
+ from tap_developability.Plotters.CDRLen_D3_Template import cdr_graph
194
+ from tap_developability.Plotters.PPC_D3_Template import ppc_graph
195
+ from tap_developability.Plotters.PNC_D3_Template import pnc_graph
196
+ from tap_developability.Plotters.SFvCSP_D3_Template import sfvcsp_graph as SFvCSP_graph
197
+
198
+ flag2hex = { "red": "#FF0000", "amber": "#FFA500", "green": "#5CBE67", "grey": "#808080" }
199
+
200
+ #PSH GRAPH
201
+ set_threshold_lines(psh_graph, "PSH")
202
+ psh_graph['data']['data01'][0][5] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Hydrophob_CDR']
203
+ psh_graph['data']['data01'][1][5] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Hydrophob_CDR']
204
+ psh_graph['axes'][0]['lines'][4]['color'] = flag2hex[fv_tap_dictionary['Flags']['PSH']]
205
+
206
+ with open(os.path.join(output, "PSH_D3_Template.json"),"w") as fo4:
207
+ json.dump(psh_graph,fo4)
208
+
209
+ #CDR GRAPH
210
+ set_threshold_lines(cdr_graph, "L")
211
+ cdr_graph['data']['data01'][0][5] = fv_tap_dictionary['Total CDR Length'] #was 3 before lower bound too
212
+ cdr_graph['data']['data01'][1][5] = fv_tap_dictionary['Total CDR Length']
213
+ cdr_graph['axes'][0]['lines'][4]['color'] = flag2hex[fv_tap_dictionary['Flags']['L']]
214
+
215
+ with open(os.path.join(output, "CDRLen_D3_Template.json"),"w") as fo4:
216
+ json.dump(cdr_graph,fo4)
217
+
218
+ #PPC GRAPH
219
+ set_threshold_lines(ppc_graph, "PPC")
220
+ ppc_graph['data']['data01'][0][3] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Pos_Charge_CDR']
221
+ ppc_graph['data']['data01'][1][3] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Pos_Charge_CDR']
222
+ ppc_graph['axes'][0]['lines'][2]['color'] = flag2hex[fv_tap_dictionary['Flags']['PPC']]
223
+
224
+ with open(os.path.join(output, "PPC_D3_Template.json"),"w") as fo4:
225
+ json.dump(ppc_graph,fo4)
226
+
227
+ #PNC GRAPH
228
+ set_threshold_lines(pnc_graph, "PNC")
229
+ pnc_graph['data']['data01'][0][3] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Neg_Charge_CDR']
230
+ pnc_graph['data']['data01'][1][3] = fv_tap_dictionary['Hydrophobicity and Charge'][h_scale]['Patch_Neg_Charge_CDR']
231
+ pnc_graph['axes'][0]['lines'][2]['color'] = flag2hex[fv_tap_dictionary['Flags']['PNC']]
232
+
233
+ with open(os.path.join(output, "PNC_D3_Template.json"),"w") as fo4:
234
+ json.dump(pnc_graph,fo4)
235
+
236
+ #SFvCSP GRAPH
237
+ set_threshold_lines(SFvCSP_graph, "SFvCSP")
238
+ SFvCSP_graph['data']['data01'][0][3] = SFvCSP
239
+ SFvCSP_graph['data']['data01'][1][3] = SFvCSP
240
+ SFvCSP_graph['axes'][0]['lines'][2]['color'] = flag2hex[fv_tap_dictionary['Flags']['SFvCSP']]
241
+
242
+ with open(os.path.join(output, "SFvCSP_D3_Template.json"),"w") as fo4:
243
+ json.dump(SFvCSP_graph,fo4)
244
+
245
+ return fv_tap_dictionary
246
+ else:
247
+ print("TAP failed for sequence %s" %(heavy_name[:-2]))
248
+ return {}
249
+
250
+
251
+ def tap_protocol_model_mode(model_path,h_scale,output,web,verbose): #user supplies the directory where all the models sit
252
+
253
+ # Models must be numbered in IMGT, with heavy chain H and light chain L, as
254
+ # ABodyBuilder2 writes them.
255
+ model_name = model_path.split('/')[-1][:-4]
256
+ full_model_root = "/".join(os.path.abspath(model_path).split('/')[0:-1])
257
+
258
+ try:
259
+ s = read_structure(model_path, "imgt", chains={"H": "H", "L": "L"})
260
+ fv = Fv(s["H"], s["L"])
261
+
262
+ tot = 0
263
+
264
+ for region, residues in fv.region_residues("imgt").items():
265
+ if region.is_cdr:
266
+ tot += len(residues)
267
+
268
+ shutil.copy(model_path, full_model_root+"/Final_Models/"+model_name+".pdb")
269
+
270
+ #Calculate charge/hydrophobicity properties
271
+ hydrophob_and_charge_dict = hydrophob_and_charge_calc(h_scale, 7.4, model_path, full_model_root+"/tmp/"+model_name+"_hydrophobicity_and_charge_dict.pkl", "IG", "imgt", output, verbose=verbose)
272
+
273
+ fv_tap_dictionary = {}
274
+ fv_tap_dictionary['name'] = model_name
275
+ fv_tap_dictionary['Tot_CDR_Len'] = tot
276
+ fv_tap_dictionary['PSH'] = hydrophob_and_charge_dict[h_scale]['Patch_Hydrophob_CDR']
277
+ fv_tap_dictionary['PPC'] = hydrophob_and_charge_dict[h_scale]['Patch_Pos_Charge_CDR']
278
+ fv_tap_dictionary['PNC'] = hydrophob_and_charge_dict[h_scale]['Patch_Neg_Charge_CDR']
279
+ fv_tap_dictionary['SFvCSP'] = hydrophob_and_charge_dict[h_scale]['SFvCSP']
280
+
281
+ return fv_tap_dictionary
282
+ except:
283
+ fv_tap_dictionary = {}
284
+ return fv_tap_dictionary
285
+
286
+ ####################################################################################################
287
+ ####################################################################################################
288
+ ####################################################################################################
289
+
290
+ def main():
291
+
292
+ print(header)
293
+
294
+ # Set up argument parser
295
+ parser = argparse.ArgumentParser(description="TAP Required Arguments")
296
+
297
+ parser.add_argument('--hscale',dest='h_scale',default=0,help='Hydrophobicity Scale: 0 for Kyte and Doolittle, 1 for Whimley and White, 2 for Hessa et al, 3 for Eisenberg and McLachlan, 4 for Black and Mould. Defaults to Kyte and Doolittle.')
298
+ parser.add_argument('--name',dest='name',default='Fv1',help='Sequence or dataset name. Defaulted to Fv1 for a single sequence.')
299
+ parser.add_argument('--output',dest='output',help='The folder to which TAP should send all outputs',default='TAP_output',type=os.path.abspath)
300
+ parser.add_argument('--web','-w',action='store_true',default=False, help="Flag that this is being running for the web front end. JSON files will be written.", dest="web")
301
+ parser.add_argument('--verbose','-v',action='store_true',default=False, help="Turns on verbose output. Only for runs using 1 core.", dest="verbose")
302
+ parser.add_argument('--ncores',dest='ncores',default=1,help='The number of cores TAP should use for this run.')
303
+
304
+ group = parser.add_mutually_exclusive_group(required=True)
305
+ group.add_argument('--seq','-s',dest='sequence',help='Paired antibody sequence for TAP analysis - in the form "[Heavy Seq]/[Light Seq]"')
306
+ group.add_argument('--file','-f',dest='file',help='A file containing multiple antibody sequences in FASTA format in the form "[Heavy Seq]/[Light Seq]".', type=os.path.abspath)
307
+ group.add_argument('--models','-m',dest='model_folder',help='A folder containing antibody models for processing through TAP', type=os.path.abspath)
308
+
309
+ args = parser.parse_args()
310
+
311
+ h_scale = int(args.h_scale)
312
+ output = str(args.output)
313
+ web = args.web
314
+ verbose = args.verbose
315
+ ncores = int(args.ncores)
316
+ start = time.time()
317
+
318
+ # Make output directory if it doesn't already exist
319
+ if os.path.exists(output) is False:
320
+ os.makedirs(output)
321
+ os.chdir(output)
322
+ if os.path.exists(os.path.join(output, "Outputs")) is False:
323
+ os.mkdir("Outputs")
324
+ if os.path.exists(os.path.join(output, "Raw_Model_Outputs")) is False:
325
+ os.mkdir("Raw_Model_Outputs")
326
+ if os.path.exists(os.path.join(output, "Final_Models")) is False:
327
+ os.mkdir("Final_Models")
328
+
329
+ #print "Outputs will be written to the following directory: " +output
330
+
331
+ if h_scale == 0:
332
+ print("The hydrophobicity scale is set to Kyte & Doolittle")
333
+ elif h_scale == 1:
334
+ print("The hydrophobicity scale is set to Whimley & White")
335
+ elif h_scale == 2:
336
+ print("The hydrophobicity scale is set to Hessa et al.")
337
+ elif h_scale == 3:
338
+ print("The hydrophobicity scale is set to Eisenberg & McLachlan")
339
+ elif h_scale == 4:
340
+ print("The hydrophobicity scale is set to Black & Mould")
341
+
342
+ if args.name:
343
+ name = str(args.name)
344
+
345
+ sequences = {}
346
+ # Single sequence input
347
+ if args.sequence:
348
+ twin_seq = str(args.sequence)
349
+ split_seq = re.split(r"/",twin_seq)
350
+ heavy_name,heavy_chain = (name+"_H",split_seq[0].upper())
351
+ light_name,light_chain = (name+"_L",split_seq[1].upper())
352
+ print("You have chosen the single sequence option.\nSequence name is: "+name+"\nHeavy chain is: "+str(heavy_chain)+"\nLight chain is: "+str(light_chain))
353
+ print(linedivide)
354
+
355
+ sequences[name] = {"heavy_name": heavy_name,
356
+ "heavy_chain": heavy_chain,
357
+ "light_name": light_name,
358
+ "light_chain": light_chain}
359
+
360
+ results_dict = {name: profile_sequence(heavy_name,heavy_chain,light_name,light_chain,h_scale,output,web,verbose)}
361
+
362
+ with open("TAP_Results_SingleSeqEntry_"+name+".json","w") as fo:
363
+ json.dump(results_dict,fo)
364
+
365
+ # Fasta file input
366
+ elif args.file:
367
+ results_dict = {}
368
+ print("You have chosen to supply your sequences in a FASTA file.")
369
+
370
+ file_dest = args.file
371
+ try:
372
+ for line in SeqIO.parse(file_dest,"fasta"):
373
+ twin_seq = str(line.seq)
374
+ try:
375
+ split_seq = re.split(r"/",twin_seq)
376
+ except:
377
+ sys.exit("Failed to split heavy and light chain sequences. Ensure they are separated by a '/' for each case.")
378
+
379
+ heavy_name,heavy_chain = (line.id+"_H",split_seq[0])
380
+ light_name,light_chain = (line.id+"_L",split_seq[1])
381
+
382
+ sequences[line.id] = {"heavy_name": heavy_name,
383
+ "heavy_chain": heavy_chain,
384
+ "light_name": light_name,
385
+ "light_chain": light_chain}
386
+
387
+ print("The fasta file provided contains %d sequences." %(len(sequences)))
388
+ print("TAP will use %d core(s)." %(ncores))
389
+ print(linedivide)
390
+ except:
391
+ sys.exit("Error: please ensure you have supplied your sequences in fasta format.")
392
+
393
+ if ncores <= 1:
394
+ for seqid in sequences:
395
+ heavy_name = sequences[seqid]["heavy_name"]
396
+ heavy_chain = sequences[seqid]["heavy_chain"]
397
+ light_name = sequences[seqid]["light_name"]
398
+ light_chain = sequences[seqid]["light_chain"]
399
+ results_dict[seqid] = profile_sequence(heavy_name,heavy_chain,light_name,light_chain,h_scale,output,web,verbose)
400
+ else:
401
+ job_params = {}
402
+ for seqid in sequences:
403
+ job_params[seqid] = [sequences[seqid]["heavy_name"], sequences[seqid]["heavy_chain"], sequences[seqid]["light_name"], sequences[seqid]["light_chain"], h_scale, output, web, verbose]
404
+ pool = mp.Pool(ncores)
405
+ j_list = [ pool.apply_async( profile_sequence, args = (blah) ) for blah in list(job_params.values()) ]
406
+ mp_results = [ j.get() for j in j_list ]
407
+
408
+ results_dict = {}
409
+ for r in mp_results:
410
+ if r:
411
+ results_dict[r['name']] = r
412
+
413
+ with open("TAP_Results_Multientry.json","w") as fo:
414
+ json.dump(results_dict,fo)
415
+
416
+ elif args.model_folder:
417
+ results_dict = {}
418
+ print("You are running TAP on a set of precomputed Models.")
419
+
420
+ job_params = {}
421
+
422
+ for pdb in glob.glob(args.model_folder+"/*pdb"):
423
+ job_params[pdb] = [pdb,h_scale,output,web,verbose]
424
+
425
+ subprocess.call(["mkdir",args.model_folder+"/Final_Models/"])
426
+ subprocess.call(["mkdir",args.model_folder+"/tmp/"])
427
+
428
+ pool = mp.Pool(ncores)
429
+ j_list = [ pool.apply_async(tap_protocol_model_mode, args = (blah) ) for blah in list(job_params.values())]
430
+ mp_results = [ j.get() for j in j_list ]
431
+
432
+ results_dict = {}
433
+ for r in mp_results:
434
+ if r:
435
+ results_dict[r['name']] = {}
436
+ results_dict[r['name']]['Tot_CDR_Len'] = r['Tot_CDR_Len']
437
+ results_dict[r['name']]['PSH'] = r['PSH']
438
+ results_dict[r['name']]['PPC'] = r['PPC']
439
+ results_dict[r['name']]['PNC'] = r['PNC']
440
+ results_dict[r['name']]['SFvCSP'] = r['SFvCSP']
441
+
442
+ print("Job Complete!")
443
+
444
+ with open("TAP_Results_Multientry.json","w") as fo:
445
+ json.dump(results_dict,fo)
446
+
447
+ elapsed = (time.time() - start)
448
+ print(linedivide)
449
+ print("TAP is Complete! It took %.2fs running on %d core(s).\n" %(elapsed, ncores))
450
+
451
+ # Print results summary
452
+ if args.sequence or args.file:
453
+ for seqid in sequences:
454
+ if results_dict.get(seqid):
455
+ print("Summary Statistics for %s:\n" %(seqid))
456
+ print(" IMGT H3 Length: %d" %(results_dict[seqid]['H3 Length']))
457
+ print(" Total IMGT CDR Length: %d (%s flag)" %(results_dict[seqid]['Total CDR Length'], results_dict[seqid]['Flags']['L'].upper()))
458
+ print(" Patch CDR Surface Hydrophobicity score is: %f (%s flag)" %(results_dict[seqid]['Hydrophobicity and Charge'][h_scale]['Patch_Hydrophob_CDR'], results_dict[seqid]['Flags']['PSH'].upper()))
459
+ print(" Patch CDR Positive Charge score is: %f (%s flag)" %(results_dict[seqid]['Hydrophobicity and Charge'][h_scale]['Patch_Pos_Charge_CDR'], results_dict[seqid]['Flags']['PPC'].upper()))
460
+ print(" Patch CDR Negative Charge score is: %f (%s flag)" %(results_dict[seqid]['Hydrophobicity and Charge'][h_scale]['Patch_Neg_Charge_CDR'], results_dict[seqid]['Flags']['PNC'].upper()))
461
+ print(" SFvCSP score is: %f (%s flag)" %(results_dict[seqid]['Hydrophobicity and Charge'][h_scale]['Net Heavy Fv Charge']*results_dict[seqid]['Hydrophobicity and Charge'][h_scale]['Net Light Fv Charge'], results_dict[seqid]['Flags']['SFvCSP'].upper()))
462
+ print()
463
+ else:
464
+ print("TAP crashed on sequence %s\n" %(seqid))
465
+
466
+ print(linedivide)
467
+
468
+
469
+ if __name__ == "__main__":
470
+ main()
File without changes
@@ -0,0 +1,28 @@
1
+ import re
2
+ from Bio.PDB import PDBParser, PDBIO, Select
3
+
4
+ _hydrogen = re.compile("[123 ]*H.*")
5
+
6
+ class RemoveHydrogen(Select):
7
+ def accept_atom(self, atom):
8
+ """Verify if atoms are not Hydrogen."""
9
+ # atoms - get rid of hydrogens
10
+ name = atom.get_id()
11
+ return 0 if _hydrogen.match(name) else 1
12
+
13
+ def pdb_remove_hydrogens(input_pdb):
14
+ try:
15
+ pdb = PDBParser().get_structure("antibody", input_pdb)
16
+ io = PDBIO()
17
+ io.set_structure(pdb)
18
+
19
+ output_model = f'{input_pdb[:-4]}.pdb'
20
+ io.save(output_model, RemoveHydrogen())
21
+
22
+ except Exception as e:
23
+ print(e)
24
+
25
+ if __name__ == "__main__":
26
+ import sys
27
+ input_pdb = sys.argv[1]
28
+ pdb_remove_hydrogens(input_pdb)