Spaces:
Running
Running
ThorbenFroehlking
commited on
Commit
·
d2ee732
1
Parent(s):
0c6c0c1
Update
Browse files- .ipynb_checkpoints/app-checkpoint.py +61 -32
- 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 |
-
#
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 += "
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
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 |
-
#
|
243 |
-
for
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
resi_list = '+'.join(map(str, score_range))
|
248 |
pymol_commands += f"""
|
249 |
-
select
|
250 |
-
show sticks,
|
251 |
-
color {color},
|
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.
|
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 |
-
|
438 |
-
- 0.
|
439 |
-
- 0.
|
440 |
-
- 0.
|
441 |
-
- 0.
|
442 |
-
- 0.
|
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 |
-
#
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 += "
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
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 |
-
#
|
243 |
-
for
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
resi_list = '+'.join(map(str, score_range))
|
248 |
pymol_commands += f"""
|
249 |
-
select
|
250 |
-
show sticks,
|
251 |
-
color {color},
|
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.
|
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 |
-
|
438 |
-
- 0.
|
439 |
-
- 0.
|
440 |
-
- 0.
|
441 |
-
- 0.
|
442 |
-
- 0.
|
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")
|