ThorbenFroehlking commited on
Commit
d2ee732
·
1 Parent(s): 0c6c0c1
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +61 -32
  2. app.py +61 -32
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -208,18 +208,39 @@ def process_pdb(pdb_id_or_file, segment):
208
  residue_scores = [(resi, score) for resi, score in zip(sequence_id, normalized_scores)]
209
 
210
 
211
- # Identify high scoring residues (> 0.5)
212
- high_score_residues = [resi for resi, score in residue_scores if score > 0.5]
 
 
 
 
 
 
213
 
214
- # Preparing the result: only print high scoring residues
 
 
 
 
 
 
 
 
 
 
215
  current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
216
  result_str = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
217
- result_str += "High-scoring Residues (Score > 0.5):\n"
218
- result_str += "Columns: Residue Name, Residue Number, One-letter Code, Normalized Score\n\n"
219
- result_str += "\n".join([
220
- f"{res.resname} {res.id[1]} {sequence[i]} {normalized_scores[i]:.2f}"
221
- for i, res in enumerate(protein_residues) if res.id[1] in high_score_residues
222
- ])
 
 
 
 
 
223
 
224
  # Create chain-specific PDB with scores in B-factor
225
  scored_pdb = create_chain_specific_pdb(pdb_path, segment, residue_scores, protein_residues)
@@ -232,24 +253,32 @@ def process_pdb(pdb_id_or_file, segment):
232
  pymol_commands = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
233
 
234
  pymol_commands += f"""
235
- # PyMOL Visualization Commands
236
- load {os.path.abspath(pdb_path)}, protein
237
- hide everything, all
238
- show cartoon, chain {segment}
239
- color white, chain {segment}
240
- """
 
 
 
 
 
 
 
 
 
241
 
242
- # Color specific residues
243
- for score_range, color in [
244
- (high_score_residues, "red")
245
- ]:
246
- if score_range:
247
- resi_list = '+'.join(map(str, score_range))
248
  pymol_commands += f"""
249
- select high_score_residues, resi {resi_list} and chain {segment}
250
- show sticks, high_score_residues
251
- color {color}, high_score_residues
252
- """
253
  # Create prediction and scored PDB files
254
  prediction_file = f"{pdb_id}_binding_site_residues.txt"
255
  with open(prediction_file, "w") as f:
@@ -294,7 +323,7 @@ def molecule(input_pdb, residue_scores=None, segment='A'):
294
  class2Model.setStyle({}, {});
295
  class2Model.setStyle(
296
  {"chain": "%s", "resi": [%s]},
297
- {"stick": {"color": "0xFFD580", "opacity": 0.5}}
298
  );
299
 
300
  // Create a new model for high-scoring residues and apply red sticks style
@@ -434,12 +463,12 @@ with gr.Blocks() as demo:
434
 
435
  molecule_output = gr.HTML(label="Protein Structure")
436
  explanation_vis = gr.Markdown("""
437
- Residues with a score > 0.5 are represented as sticks with a score dependent colorcoding:
438
- - 0.5-0.6: blue
439
- - 0.6–0.7: light blue
440
- - 0.7–0.8: white
441
- - 0.8–0.9: orange
442
- - 0.9–1.0: red
443
  """)
444
  predictions_output = gr.Textbox(label="Visualize Prediction with PyMol")
445
  gr.Markdown("### Download:\n- List of predicted binding site residues\n- PDB with score in beta factor column")
 
208
  residue_scores = [(resi, score) for resi, score in zip(sequence_id, normalized_scores)]
209
 
210
 
211
+ # Define the score brackets
212
+ score_brackets = {
213
+ "0.0-0.2": (0.0, 0.2),
214
+ "0.2-0.4": (0.2, 0.4),
215
+ "0.4-0.6": (0.4, 0.6),
216
+ "0.6-0.8": (0.6, 0.8),
217
+ "0.8-1.0": (0.8, 1.0)
218
+ }
219
 
220
+ # Initialize a dictionary to store residues by bracket
221
+ residues_by_bracket = {bracket: [] for bracket in score_brackets}
222
+
223
+ # Categorize residues into brackets
224
+ for resi, score in residue_scores:
225
+ for bracket, (lower, upper) in score_brackets.items():
226
+ if lower <= score < upper:
227
+ residues_by_bracket[bracket].append(resi)
228
+ break
229
+
230
+ # Preparing the result string
231
  current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
232
  result_str = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
233
+ result_str += "Residues by Score Brackets:\n\n"
234
+
235
+ # Add residues for each bracket
236
+ for bracket, residues in residues_by_bracket.items():
237
+ result_str += f"Bracket {bracket}:\n"
238
+ result_str += "Columns: Residue Name, Residue Number, One-letter Code, Normalized Score\n"
239
+ result_str += "\n".join([
240
+ f"{res.resname} {res.id[1]} {sequence[i]} {normalized_scores[i]:.2f}"
241
+ for i, res in enumerate(protein_residues) if res.id[1] in residues
242
+ ])
243
+ result_str += "\n\n"
244
 
245
  # Create chain-specific PDB with scores in B-factor
246
  scored_pdb = create_chain_specific_pdb(pdb_path, segment, residue_scores, protein_residues)
 
253
  pymol_commands = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
254
 
255
  pymol_commands += f"""
256
+ # PyMOL Visualization Commands
257
+ load {os.path.abspath(pdb_path)}, protein
258
+ hide everything, all
259
+ show cartoon, chain {segment}
260
+ color white, chain {segment}
261
+ """
262
+
263
+ # Define colors for each score bracket
264
+ bracket_colors = {
265
+ "0.0-0.2": "white",
266
+ "0.2-0.4": "lightorange",
267
+ "0.4-0.6": "orange",
268
+ "0.6-0.8": "orangered",
269
+ "0.8-1.0": "red"
270
+ }
271
 
272
+ # Add PyMOL commands for each score bracket
273
+ for bracket, residues in residues_by_bracket.items():
274
+ if residues: # Only add commands if there are residues in this bracket
275
+ color = bracket_colors[bracket]
276
+ resi_list = '+'.join(map(str, residues))
 
277
  pymol_commands += f"""
278
+ select bracket_{bracket.replace('.', '').replace('-', '_')}, resi {resi_list} and chain {segment}
279
+ show sticks, bracket_{bracket.replace('.', '').replace('-', '_')}
280
+ color {color}, bracket_{bracket.replace('.', '').replace('-', '_')}
281
+ """
282
  # Create prediction and scored PDB files
283
  prediction_file = f"{pdb_id}_binding_site_residues.txt"
284
  with open(prediction_file, "w") as f:
 
323
  class2Model.setStyle({}, {});
324
  class2Model.setStyle(
325
  {"chain": "%s", "resi": [%s]},
326
+ {"stick": {"color": "0xFFD580", "opacity": 0.7}}
327
  );
328
 
329
  // Create a new model for high-scoring residues and apply red sticks style
 
463
 
464
  molecule_output = gr.HTML(label="Protein Structure")
465
  explanation_vis = gr.Markdown("""
466
+ Score dependent colorcoding:
467
+ - 0.0-0.2: white
468
+ - 0.2–0.4: light orange
469
+ - 0.4–0.6: orange
470
+ - 0.6–0.8: orangered
471
+ - 0.8–1.0: red
472
  """)
473
  predictions_output = gr.Textbox(label="Visualize Prediction with PyMol")
474
  gr.Markdown("### Download:\n- List of predicted binding site residues\n- PDB with score in beta factor column")
app.py CHANGED
@@ -208,18 +208,39 @@ def process_pdb(pdb_id_or_file, segment):
208
  residue_scores = [(resi, score) for resi, score in zip(sequence_id, normalized_scores)]
209
 
210
 
211
- # Identify high scoring residues (> 0.5)
212
- high_score_residues = [resi for resi, score in residue_scores if score > 0.5]
 
 
 
 
 
 
213
 
214
- # Preparing the result: only print high scoring residues
 
 
 
 
 
 
 
 
 
 
215
  current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
216
  result_str = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
217
- result_str += "High-scoring Residues (Score > 0.5):\n"
218
- result_str += "Columns: Residue Name, Residue Number, One-letter Code, Normalized Score\n\n"
219
- result_str += "\n".join([
220
- f"{res.resname} {res.id[1]} {sequence[i]} {normalized_scores[i]:.2f}"
221
- for i, res in enumerate(protein_residues) if res.id[1] in high_score_residues
222
- ])
 
 
 
 
 
223
 
224
  # Create chain-specific PDB with scores in B-factor
225
  scored_pdb = create_chain_specific_pdb(pdb_path, segment, residue_scores, protein_residues)
@@ -232,24 +253,32 @@ def process_pdb(pdb_id_or_file, segment):
232
  pymol_commands = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
233
 
234
  pymol_commands += f"""
235
- # PyMOL Visualization Commands
236
- load {os.path.abspath(pdb_path)}, protein
237
- hide everything, all
238
- show cartoon, chain {segment}
239
- color white, chain {segment}
240
- """
 
 
 
 
 
 
 
 
 
241
 
242
- # Color specific residues
243
- for score_range, color in [
244
- (high_score_residues, "red")
245
- ]:
246
- if score_range:
247
- resi_list = '+'.join(map(str, score_range))
248
  pymol_commands += f"""
249
- select high_score_residues, resi {resi_list} and chain {segment}
250
- show sticks, high_score_residues
251
- color {color}, high_score_residues
252
- """
253
  # Create prediction and scored PDB files
254
  prediction_file = f"{pdb_id}_binding_site_residues.txt"
255
  with open(prediction_file, "w") as f:
@@ -294,7 +323,7 @@ def molecule(input_pdb, residue_scores=None, segment='A'):
294
  class2Model.setStyle({}, {});
295
  class2Model.setStyle(
296
  {"chain": "%s", "resi": [%s]},
297
- {"stick": {"color": "0xFFD580", "opacity": 0.5}}
298
  );
299
 
300
  // Create a new model for high-scoring residues and apply red sticks style
@@ -434,12 +463,12 @@ with gr.Blocks() as demo:
434
 
435
  molecule_output = gr.HTML(label="Protein Structure")
436
  explanation_vis = gr.Markdown("""
437
- Residues with a score > 0.5 are represented as sticks with a score dependent colorcoding:
438
- - 0.5-0.6: blue
439
- - 0.6–0.7: light blue
440
- - 0.7–0.8: white
441
- - 0.8–0.9: orange
442
- - 0.9–1.0: red
443
  """)
444
  predictions_output = gr.Textbox(label="Visualize Prediction with PyMol")
445
  gr.Markdown("### Download:\n- List of predicted binding site residues\n- PDB with score in beta factor column")
 
208
  residue_scores = [(resi, score) for resi, score in zip(sequence_id, normalized_scores)]
209
 
210
 
211
+ # Define the score brackets
212
+ score_brackets = {
213
+ "0.0-0.2": (0.0, 0.2),
214
+ "0.2-0.4": (0.2, 0.4),
215
+ "0.4-0.6": (0.4, 0.6),
216
+ "0.6-0.8": (0.6, 0.8),
217
+ "0.8-1.0": (0.8, 1.0)
218
+ }
219
 
220
+ # Initialize a dictionary to store residues by bracket
221
+ residues_by_bracket = {bracket: [] for bracket in score_brackets}
222
+
223
+ # Categorize residues into brackets
224
+ for resi, score in residue_scores:
225
+ for bracket, (lower, upper) in score_brackets.items():
226
+ if lower <= score < upper:
227
+ residues_by_bracket[bracket].append(resi)
228
+ break
229
+
230
+ # Preparing the result string
231
  current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
232
  result_str = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
233
+ result_str += "Residues by Score Brackets:\n\n"
234
+
235
+ # Add residues for each bracket
236
+ for bracket, residues in residues_by_bracket.items():
237
+ result_str += f"Bracket {bracket}:\n"
238
+ result_str += "Columns: Residue Name, Residue Number, One-letter Code, Normalized Score\n"
239
+ result_str += "\n".join([
240
+ f"{res.resname} {res.id[1]} {sequence[i]} {normalized_scores[i]:.2f}"
241
+ for i, res in enumerate(protein_residues) if res.id[1] in residues
242
+ ])
243
+ result_str += "\n\n"
244
 
245
  # Create chain-specific PDB with scores in B-factor
246
  scored_pdb = create_chain_specific_pdb(pdb_path, segment, residue_scores, protein_residues)
 
253
  pymol_commands = f"Prediction for PDB: {pdb_id}, Chain: {segment}\nDate: {current_time}\n\n"
254
 
255
  pymol_commands += f"""
256
+ # PyMOL Visualization Commands
257
+ load {os.path.abspath(pdb_path)}, protein
258
+ hide everything, all
259
+ show cartoon, chain {segment}
260
+ color white, chain {segment}
261
+ """
262
+
263
+ # Define colors for each score bracket
264
+ bracket_colors = {
265
+ "0.0-0.2": "white",
266
+ "0.2-0.4": "lightorange",
267
+ "0.4-0.6": "orange",
268
+ "0.6-0.8": "orangered",
269
+ "0.8-1.0": "red"
270
+ }
271
 
272
+ # Add PyMOL commands for each score bracket
273
+ for bracket, residues in residues_by_bracket.items():
274
+ if residues: # Only add commands if there are residues in this bracket
275
+ color = bracket_colors[bracket]
276
+ resi_list = '+'.join(map(str, residues))
 
277
  pymol_commands += f"""
278
+ select bracket_{bracket.replace('.', '').replace('-', '_')}, resi {resi_list} and chain {segment}
279
+ show sticks, bracket_{bracket.replace('.', '').replace('-', '_')}
280
+ color {color}, bracket_{bracket.replace('.', '').replace('-', '_')}
281
+ """
282
  # Create prediction and scored PDB files
283
  prediction_file = f"{pdb_id}_binding_site_residues.txt"
284
  with open(prediction_file, "w") as f:
 
323
  class2Model.setStyle({}, {});
324
  class2Model.setStyle(
325
  {"chain": "%s", "resi": [%s]},
326
+ {"stick": {"color": "0xFFD580", "opacity": 0.7}}
327
  );
328
 
329
  // Create a new model for high-scoring residues and apply red sticks style
 
463
 
464
  molecule_output = gr.HTML(label="Protein Structure")
465
  explanation_vis = gr.Markdown("""
466
+ Score dependent colorcoding:
467
+ - 0.0-0.2: white
468
+ - 0.2–0.4: light orange
469
+ - 0.4–0.6: orange
470
+ - 0.6–0.8: orangered
471
+ - 0.8–1.0: red
472
  """)
473
  predictions_output = gr.Textbox(label="Visualize Prediction with PyMol")
474
  gr.Markdown("### Download:\n- List of predicted binding site residues\n- PDB with score in beta factor column")