Xianfish9 commited on
Commit
f135a23
·
verified ·
1 Parent(s): f41061a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
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 (Kac)", "Crotonyllysine (Kcr)", "Methyllysine (Kme)", "Succinyllysine (Ksucc)"]
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("请输入有效的FASTA格式序列。")
93
 
94
  sequence = parse_fasta(fasta_input)
95
 
96
  if len(sequence) < 49:
97
- raise gr.Error(f"序列过短!需要至少49个氨基酸,当前长度为 {len(sequence)}。")
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)], {}, "在序列中没有找到任何可以进行预测的有效K位点(即K前后没有足够的氨基酸)。"
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 = "处理完成!请点击下方序列中高亮的红色 'K' 位点查看其预测结果。"
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"以位置 {k_index + 1} 'K' 为中心的片段预测结果:"
157
  return result_dict, site_info
158
 
159
  # 如果没有选择或出现错误
160
- return None, "请点击上方序列中高亮的红色 'K' 位点查看结果。"
161
 
162
 
163
  # --- 7. 创建并启动 Gradio 界面 (使用 gr.Blocks) ---
164
- fasta_example = """>sp|P0C9F0|NUSA_BACAN Nickel-binding GTPase (Fragment)
165
- MNEKNKSQLRIIFVCGKSFIWSSTLFKHKRIHTGEKPYKCEECGKAFNHSQILLHIRHKR
166
- MHTGEKPYKCEECGKAFSRSSHLTTHIRHTGEKPYVCKECGKAFNRSSHLTTHIRHTGEK
167
- PYKCEECGKAFSRSSHLTTHIRHTGEKPYKCEECGKAFSRSSHLTTHIRHTGEKPYKCEE
168
- CGKAFSRSSHLTTHIRHTGEKPYKCEECGKAFNRSSHLTTHIRHTGEKPYKCEECGKAFN
169
- RSSTLTTHIRHTGEKPYKCEECGKAFSRSSH"""
170
 
171
  with gr.Blocks(css=".predictable-k {color: red; font-weight: bold;}") as demo:
172
  gr.Markdown(
173
  """
174
- # CAFN Model: Multi-label Classifier for Lysine Modifications
175
- **支持FASTA格式输入,交互式查看蛋白序列中各个赖氨酸位点的修饰可能性。**
176
  """
177
  )
178
  with gr.Row():
179
  with gr.Column(scale=2):
180
  fasta_input = gr.Textbox(
181
  lines=10,
182
- label="输入FASTA格式的蛋白质序列 (Input FASTA Sequence)",
183
- placeholder="请在此处粘贴您的FASTA格式序列..."
184
  )
185
- submit_btn = gr.Button("提交预测", variant="primary")
186
 
187
  with gr.Column(scale=3):
188
- gr.Markdown("### 预测结果 (Prediction Results)")
189
- info_text = gr.Textbox(label="状态", interactive=False, value="等待输入...")
190
  # 用于存储所有位点的预测结果,对用户不可见
191
  predictions_state = gr.State({})
192
- results_output = gr.Label(num_top_classes=4, label="点击红色'K'位点后,此处将显示结果")
193
 
194
  gr.Markdown("---")
195
- gr.Markdown("### 可视化序列 (Visualized Sequence)")
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
  # --- 设定事件逻辑 ---