Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,40 +28,26 @@ download_db(HF_DB_URL, LOCAL_DB_PATH)
|
|
| 28 |
conn = get_connection(LOCAL_DB_PATH)
|
| 29 |
cursor = conn.cursor()
|
| 30 |
|
| 31 |
-
|
| 32 |
-
def
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
print_schema()
|
| 44 |
-
|
| 45 |
-
# Query function
|
| 46 |
-
def search_by_sequence(seq: str) -> str:
|
| 47 |
-
seq = seq.strip().upper()
|
| 48 |
-
cursor.execute("SELECT json FROM proteins")
|
| 49 |
-
for (json_blob,) in cursor.fetchall():
|
| 50 |
-
try:
|
| 51 |
-
data = json.loads(json_blob)
|
| 52 |
-
if data.get("sequence", "").upper() == seq:
|
| 53 |
-
return json.dumps(data, indent=2)
|
| 54 |
-
except json.JSONDecodeError:
|
| 55 |
-
continue
|
| 56 |
-
return "No match found."
|
| 57 |
|
| 58 |
# Gradio app
|
| 59 |
demo = gr.Interface(
|
| 60 |
-
fn=
|
| 61 |
-
inputs=gr.Textbox(label="Enter
|
| 62 |
-
outputs=gr.Textbox(label="Protein metadata"),
|
| 63 |
-
title="SwissProt Search",
|
| 64 |
-
description="Search Swiss-Prot by
|
| 65 |
)
|
| 66 |
|
| 67 |
demo.launch(show_api=True)
|
|
|
|
| 28 |
conn = get_connection(LOCAL_DB_PATH)
|
| 29 |
cursor = conn.cursor()
|
| 30 |
|
| 31 |
+
# Search by protein ID (exact match)
|
| 32 |
+
def search_by_id(protein_id: str) -> str:
|
| 33 |
+
protein_id = protein_id.strip().upper()
|
| 34 |
+
cursor.execute("SELECT json FROM proteins WHERE id = ?", (protein_id,))
|
| 35 |
+
row = cursor.fetchone()
|
| 36 |
+
if not row:
|
| 37 |
+
return "❌ No match found."
|
| 38 |
+
try:
|
| 39 |
+
data = json.loads(row[0])
|
| 40 |
+
return json.dumps(data, indent=2)
|
| 41 |
+
except json.JSONDecodeError:
|
| 42 |
+
return "❌ Found row but failed to parse JSON."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Gradio app
|
| 45 |
demo = gr.Interface(
|
| 46 |
+
fn=search_by_id,
|
| 47 |
+
inputs=gr.Textbox(label="Enter UniProt ID (e.g. P0DTC2)"),
|
| 48 |
+
outputs=gr.Textbox(label="Protein metadata (JSON)"),
|
| 49 |
+
title="SwissProt Search by ID",
|
| 50 |
+
description="Search Swiss-Prot database by UniProt protein ID"
|
| 51 |
)
|
| 52 |
|
| 53 |
demo.launch(show_api=True)
|