Update app.py
Browse files
app.py
CHANGED
|
@@ -105,7 +105,7 @@ def create_heatmap(contact_matrix, rna_labels, protein_labels, rna_name, protein
|
|
| 105 |
# Apply Threshold threshold
|
| 106 |
filtered_matrix = contact_matrix.copy()
|
| 107 |
filtered_matrix[filtered_matrix < Threshold] = 0
|
| 108 |
-
|
| 109 |
fig = go.Figure(data=go.Heatmap(
|
| 110 |
z=filtered_matrix,
|
| 111 |
x=protein_labels,
|
|
@@ -123,13 +123,12 @@ def create_heatmap(contact_matrix, rna_labels, protein_labels, rna_name, protein
|
|
| 123 |
'xanchor': 'center',
|
| 124 |
'yanchor': 'top'
|
| 125 |
},
|
| 126 |
-
xaxis_title=f"
|
| 127 |
-
yaxis_title=f"
|
| 128 |
-
width=
|
| 129 |
-
height=
|
| 130 |
font=dict(size=12)
|
| 131 |
)
|
| 132 |
-
|
| 133 |
return fig
|
| 134 |
|
| 135 |
|
|
@@ -322,10 +321,21 @@ def create_interface():
|
|
| 322 |
margin-bottom: 8px;
|
| 323 |
color: #4a5568;
|
| 324 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
"""
|
| 326 |
|
| 327 |
with gr.Blocks(title="RNA-Protein Contact Prediction Tool",
|
| 328 |
-
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="teal")) as app:
|
| 329 |
gr.Markdown("""
|
| 330 |
<center>
|
| 331 |
|
|
@@ -346,28 +356,29 @@ def create_interface():
|
|
| 346 |
with gr.Group(elem_classes="input-group"):
|
| 347 |
input_method = gr.Radio(
|
| 348 |
choices=["Upload FASTA File", "Enter Sequences Directly"],
|
| 349 |
-
value="
|
| 350 |
label="Input Method"
|
| 351 |
)
|
| 352 |
|
| 353 |
fasta_input = gr.File(
|
| 354 |
label="FASTA File",
|
| 355 |
file_types=['.fasta', '.fa', '.txt'],
|
| 356 |
-
type='binary'
|
|
|
|
| 357 |
)
|
| 358 |
|
| 359 |
rna_input = gr.Textbox(
|
| 360 |
label="RNA Sequence",
|
| 361 |
placeholder="Enter RNA sequence (use A,C,G,U)",
|
| 362 |
lines=3,
|
| 363 |
-
visible=
|
| 364 |
)
|
| 365 |
|
| 366 |
protein_input = gr.Textbox(
|
| 367 |
label="Protein Sequence",
|
| 368 |
placeholder="Enter protein sequence (standard amino acid codes)",
|
| 369 |
lines=3,
|
| 370 |
-
visible=
|
| 371 |
)
|
| 372 |
|
| 373 |
# Example data
|
|
@@ -415,7 +426,6 @@ def create_interface():
|
|
| 415 |
""")
|
| 416 |
# Heatmap display
|
| 417 |
heatmap_plot = gr.Plot(label='Contact Map')
|
| 418 |
-
|
| 419 |
# Contact pairs table with info header
|
| 420 |
gr.Markdown("### 🎯Contact Pairs")
|
| 421 |
contact_info = gr.Markdown("", elem_classes="contact-info")
|
|
|
|
| 105 |
# Apply Threshold threshold
|
| 106 |
filtered_matrix = contact_matrix.copy()
|
| 107 |
filtered_matrix[filtered_matrix < Threshold] = 0
|
| 108 |
+
ratio = filtered_matrix.shape[1] / filtered_matrix.shape[0]
|
| 109 |
fig = go.Figure(data=go.Heatmap(
|
| 110 |
z=filtered_matrix,
|
| 111 |
x=protein_labels,
|
|
|
|
| 123 |
'xanchor': 'center',
|
| 124 |
'yanchor': 'top'
|
| 125 |
},
|
| 126 |
+
xaxis_title=f"Residues ({protein_name}, {len(protein_labels)} AA)",
|
| 127 |
+
yaxis_title=f"Nucleotides ({rna_name}, {len(rna_labels)} nt)",
|
| 128 |
+
width=max(ratio*300,600),
|
| 129 |
+
height=300,
|
| 130 |
font=dict(size=12)
|
| 131 |
)
|
|
|
|
| 132 |
return fig
|
| 133 |
|
| 134 |
|
|
|
|
| 321 |
margin-bottom: 8px;
|
| 322 |
color: #4a5568;
|
| 323 |
}
|
| 324 |
+
.scrollable-plot {
|
| 325 |
+
max-width: 100%;
|
| 326 |
+
overflow-x: auto; /* 水平滚动条 */
|
| 327 |
+
overflow-y: auto; /* 垂直滚动条 */
|
| 328 |
+
border: 1px solid #ddd;
|
| 329 |
+
border-radius: 4px;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
.scrollable-plot > div {
|
| 333 |
+
min-width: max-content; /* 保持原始宽度 */
|
| 334 |
+
}
|
| 335 |
"""
|
| 336 |
|
| 337 |
with gr.Blocks(title="RNA-Protein Contact Prediction Tool",
|
| 338 |
+
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="teal"),css=None) as app:
|
| 339 |
gr.Markdown("""
|
| 340 |
<center>
|
| 341 |
|
|
|
|
| 356 |
with gr.Group(elem_classes="input-group"):
|
| 357 |
input_method = gr.Radio(
|
| 358 |
choices=["Upload FASTA File", "Enter Sequences Directly"],
|
| 359 |
+
value="Enter Sequences Directly",
|
| 360 |
label="Input Method"
|
| 361 |
)
|
| 362 |
|
| 363 |
fasta_input = gr.File(
|
| 364 |
label="FASTA File",
|
| 365 |
file_types=['.fasta', '.fa', '.txt'],
|
| 366 |
+
type='binary',
|
| 367 |
+
visible = False
|
| 368 |
)
|
| 369 |
|
| 370 |
rna_input = gr.Textbox(
|
| 371 |
label="RNA Sequence",
|
| 372 |
placeholder="Enter RNA sequence (use A,C,G,U)",
|
| 373 |
lines=3,
|
| 374 |
+
visible=True
|
| 375 |
)
|
| 376 |
|
| 377 |
protein_input = gr.Textbox(
|
| 378 |
label="Protein Sequence",
|
| 379 |
placeholder="Enter protein sequence (standard amino acid codes)",
|
| 380 |
lines=3,
|
| 381 |
+
visible=True
|
| 382 |
)
|
| 383 |
|
| 384 |
# Example data
|
|
|
|
| 426 |
""")
|
| 427 |
# Heatmap display
|
| 428 |
heatmap_plot = gr.Plot(label='Contact Map')
|
|
|
|
| 429 |
# Contact pairs table with info header
|
| 430 |
gr.Markdown("### 🎯Contact Pairs")
|
| 431 |
contact_info = gr.Markdown("", elem_classes="contact-info")
|