Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,8 +69,8 @@ def predict_single_49mer(sequence_49mer):
|
|
| 69 |
outputs = model(tensor_x1, tensor_x2)
|
| 70 |
|
| 71 |
probabilities = torch.sigmoid(outputs).squeeze().cpu().numpy()
|
| 72 |
-
|
| 73 |
-
labels = ["Acetyllysine (
|
| 74 |
result = {label: float(prob) for label, prob in zip(labels, probabilities)}
|
| 75 |
|
| 76 |
return result
|
|
@@ -89,12 +89,12 @@ def process_fasta_and_predict(fasta_input):
|
|
| 89 |
并返回用于Gradio HighlightedText组件的数据和一个包含预测结果的状态字典。
|
| 90 |
"""
|
| 91 |
if not fasta_input or not isinstance(fasta_input, str):
|
| 92 |
-
raise gr.Error("
|
| 93 |
|
| 94 |
sequence = parse_fasta(fasta_input)
|
| 95 |
|
| 96 |
if len(sequence) < 49:
|
| 97 |
-
raise gr.Error(f"
|
| 98 |
|
| 99 |
# 存储每个可预测K位点(索引)及其预测结果
|
| 100 |
predictions_map = {}
|
|
@@ -116,7 +116,7 @@ def process_fasta_and_predict(fasta_input):
|
|
| 116 |
|
| 117 |
if not predictions_map:
|
| 118 |
# 如果没有一个K位点可以被成功预测
|
| 119 |
-
return [(sequence, None)], {}, "
|
| 120 |
|
| 121 |
# --- 构建Gradio HighlightedText的输入格式 ---
|
| 122 |
highlight_data = []
|
|
@@ -134,7 +134,7 @@ def process_fasta_and_predict(fasta_input):
|
|
| 134 |
# 添加最后一个K之后剩余的部分
|
| 135 |
highlight_data.append((sequence[last_pos:], None))
|
| 136 |
|
| 137 |
-
initial_info = "
|
| 138 |
|
| 139 |
return highlight_data, predictions_map, initial_info
|
| 140 |
|
|
@@ -153,49 +153,49 @@ def show_results_for_site(evt: gr.SelectData, state_data):
|
|
| 153 |
result_dict = state_data.get(k_index)
|
| 154 |
|
| 155 |
if result_dict:
|
| 156 |
-
site_info = f"
|
| 157 |
return result_dict, site_info
|
| 158 |
|
| 159 |
# 如果没有选择或出现错误
|
| 160 |
-
return None, "
|
| 161 |
|
| 162 |
|
| 163 |
# --- 7. 创建并启动 Gradio 界面 (使用 gr.Blocks) ---
|
| 164 |
-
fasta_example = """>sp|
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
|
| 171 |
with gr.Blocks(css=".predictable-k {color: red; font-weight: bold;}") as demo:
|
| 172 |
gr.Markdown(
|
| 173 |
"""
|
| 174 |
-
#
|
| 175 |
-
|
| 176 |
"""
|
| 177 |
)
|
| 178 |
with gr.Row():
|
| 179 |
with gr.Column(scale=2):
|
| 180 |
fasta_input = gr.Textbox(
|
| 181 |
lines=10,
|
| 182 |
-
label="
|
| 183 |
-
placeholder="
|
| 184 |
)
|
| 185 |
-
submit_btn = gr.Button("
|
| 186 |
|
| 187 |
with gr.Column(scale=3):
|
| 188 |
-
gr.Markdown("###
|
| 189 |
-
info_text = gr.Textbox(label="
|
| 190 |
# 用于存储所有位点的预测结果,对用户不可见
|
| 191 |
predictions_state = gr.State({})
|
| 192 |
-
results_output = gr.Label(num_top_classes=4, label="
|
| 193 |
|
| 194 |
gr.Markdown("---")
|
| 195 |
-
gr.Markdown("###
|
| 196 |
# 使用 a[class='predictable-k'] 来应用CSS
|
| 197 |
highlighted_output = gr.HighlightedText(
|
| 198 |
-
label="
|
| 199 |
color_map={"predictable-k": "red"}, # 旧版Gradio的用法
|
| 200 |
# 在新版Gradio中,CSS通过gr.Blocks的css参数全局定义更可靠
|
| 201 |
)
|
|
@@ -203,7 +203,7 @@ with gr.Blocks(css=".predictable-k {color: red; font-weight: bold;}") as demo:
|
|
| 203 |
gr.Examples(
|
| 204 |
examples=[[fasta_example]],
|
| 205 |
inputs=fasta_input,
|
| 206 |
-
label="
|
| 207 |
)
|
| 208 |
|
| 209 |
# --- 设定事件逻辑 ---
|
|
|
|
| 69 |
outputs = model(tensor_x1, tensor_x2)
|
| 70 |
|
| 71 |
probabilities = torch.sigmoid(outputs).squeeze().cpu().numpy()
|
| 72 |
+
#Lysine-Acetylation(K-Ac)
|
| 73 |
+
labels = ["Lysine-Acetyllysine (K-Ac)", "Lysine-Crotonyllysine (K-Cr)", "Lysine-Methyllysine (K-Me)", "Lysine-Succinyllysine (K-Succ)"]
|
| 74 |
result = {label: float(prob) for label, prob in zip(labels, probabilities)}
|
| 75 |
|
| 76 |
return result
|
|
|
|
| 89 |
并返回用于Gradio HighlightedText组件的数据和一个包含预测结果的状态字典。
|
| 90 |
"""
|
| 91 |
if not fasta_input or not isinstance(fasta_input, str):
|
| 92 |
+
raise gr.Error("Please enter a valid FASTA format sequence.")
|
| 93 |
|
| 94 |
sequence = parse_fasta(fasta_input)
|
| 95 |
|
| 96 |
if len(sequence) < 49:
|
| 97 |
+
raise gr.Error(f"The sequence is too short! It needs to be at least 49 amino acids. The current length is {len(sequence)}。")
|
| 98 |
|
| 99 |
# 存储每个可预测K位点(索引)及其预测结果
|
| 100 |
predictions_map = {}
|
|
|
|
| 116 |
|
| 117 |
if not predictions_map:
|
| 118 |
# 如果没有一个K位点可以被成功预测
|
| 119 |
+
return [(sequence, None)], {}, "No valid K sites were found in the sequence for prediction (i.e., there were not enough amino acids before and after K)."
|
| 120 |
|
| 121 |
# --- 构建Gradio HighlightedText的输入格式 ---
|
| 122 |
highlight_data = []
|
|
|
|
| 134 |
# 添加最后一个K之后剩余的部分
|
| 135 |
highlight_data.append((sequence[last_pos:], None))
|
| 136 |
|
| 137 |
+
initial_info = "Processing complete! Click on the highlighted 'K' site in the sequence below to see its prediction."
|
| 138 |
|
| 139 |
return highlight_data, predictions_map, initial_info
|
| 140 |
|
|
|
|
| 153 |
result_dict = state_data.get(k_index)
|
| 154 |
|
| 155 |
if result_dict:
|
| 156 |
+
site_info = f"Prediction results for the segment centered at 'K' at position {k_index + 1}:"
|
| 157 |
return result_dict, site_info
|
| 158 |
|
| 159 |
# 如果没有选择或出现错误
|
| 160 |
+
return None, "Please click on the highlighted 'K' site in the sequence above to view the results."
|
| 161 |
|
| 162 |
|
| 163 |
# --- 7. 创建并启动 Gradio 界面 (使用 gr.Blocks) ---
|
| 164 |
+
fasta_example = """>sp|P05141|ADT2_HUMAN ADP/ATP translocase 2 OS=Homo sapiens OX=9606 GN=SLC25A5 PE=1 SV=7
|
| 165 |
+
MTDAAVSFAKDFLAGGVAAAISKTAVAPIERVKLLLQVQHASKQITADKQYKGIIDCVVR
|
| 166 |
+
IPKEQGVLSFWRGNLANVIRYFPTQALNFAFKDKYKQIFLGGVDKRTQFWLYFAGNLASG
|
| 167 |
+
GAAGATSLCFVYPLDFARTRLAADVGKAGAEREFRGLGDCLVKIYKSDGIKGLYQGFNVS
|
| 168 |
+
VQGIIIYRAAYFGIYDTAKGMLPDPKNTHIVISWMIAQTVTAVAGLTSYPFDTVRRRMMM
|
| 169 |
+
QSGRKGTDIMYTGTLDCWRKIARDEGGKAFFKGAWSNVLRGMGGAFVLVLYDEIKKYT"""
|
| 170 |
|
| 171 |
with gr.Blocks(css=".predictable-k {color: red; font-weight: bold;}") as demo:
|
| 172 |
gr.Markdown(
|
| 173 |
"""
|
| 174 |
+
# DeepKMulti Model: Multi-label Classifier for Lysine Modifications
|
| 175 |
+
**Supports FASTA format input, allowing interactive viewing of the modification possibilities of each lysine site in the protein sequence.**
|
| 176 |
"""
|
| 177 |
)
|
| 178 |
with gr.Row():
|
| 179 |
with gr.Column(scale=2):
|
| 180 |
fasta_input = gr.Textbox(
|
| 181 |
lines=10,
|
| 182 |
+
label="Input FASTA format protein sequence",
|
| 183 |
+
placeholder="Please paste your FASTA formatted sequence here..."
|
| 184 |
)
|
| 185 |
+
submit_btn = gr.Button("Submit Prediction", variant="primary")
|
| 186 |
|
| 187 |
with gr.Column(scale=3):
|
| 188 |
+
gr.Markdown("### Prediction Results")
|
| 189 |
+
info_text = gr.Textbox(label="State", interactive=False, value="Waiting for input...")
|
| 190 |
# 用于存储所有位点的预测结果,对用户不可见
|
| 191 |
predictions_state = gr.State({})
|
| 192 |
+
results_output = gr.Label(num_top_classes=4, label="After clicking on the colored 'K' site, the results will be displayed here")
|
| 193 |
|
| 194 |
gr.Markdown("---")
|
| 195 |
+
gr.Markdown("### Visualized Sequence")
|
| 196 |
# 使用 a[class='predictable-k'] 来应用CSS
|
| 197 |
highlighted_output = gr.HighlightedText(
|
| 198 |
+
label="Sequence Analysis",
|
| 199 |
color_map={"predictable-k": "red"}, # 旧版Gradio的用法
|
| 200 |
# 在新版Gradio中,CSS通过gr.Blocks的css参数全局定义更可靠
|
| 201 |
)
|
|
|
|
| 203 |
gr.Examples(
|
| 204 |
examples=[[fasta_example]],
|
| 205 |
inputs=fasta_input,
|
| 206 |
+
label="Example sequence"
|
| 207 |
)
|
| 208 |
|
| 209 |
# --- 设定事件逻辑 ---
|