Name annotation downloads by assembly, record, and segment coordinates
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""A small Hugging Face Space for exploring genome annotations by accession."""
|
| 2 |
from pathlib import Path
|
| 3 |
import os
|
|
|
|
| 4 |
import tempfile
|
| 5 |
|
| 6 |
# Shared compute hosts can have /tmp/gradio owned by a different user.
|
|
@@ -55,8 +56,14 @@ def build_app(catalog=None):
|
|
| 55 |
def export(index):
|
| 56 |
if index is None:
|
| 57 |
raise gr.Error("Choose a segment first.")
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return str(target)
|
| 61 |
|
| 62 |
with gr.Blocks(title="GenBank Annotation Explorer", delete_cache=(3600, 3600)) as demo:
|
|
|
|
| 1 |
"""A small Hugging Face Space for exploring genome annotations by accession."""
|
| 2 |
from pathlib import Path
|
| 3 |
import os
|
| 4 |
+
import re
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
# Shared compute hosts can have /tmp/gradio owned by a different user.
|
|
|
|
| 56 |
def export(index):
|
| 57 |
if index is None:
|
| 58 |
raise gr.Error("Choose a segment first.")
|
| 59 |
+
table = catalog.segment_table(index)
|
| 60 |
+
assembly = re.sub(r"[^A-Za-z0-9._-]", "_", table["assembly_accession"][0].as_py())
|
| 61 |
+
record = re.sub(r"[^A-Za-z0-9._-]", "_", table["record_name"][0].as_py())
|
| 62 |
+
start = table["segment_start_bp"][0].as_py()
|
| 63 |
+
end = table["segment_end_bp"][0].as_py()
|
| 64 |
+
filename = f"{assembly}__{record}__{start}-{end}.parquet"
|
| 65 |
+
target = Path(tempfile.mkdtemp(prefix="genbank-export-")) / filename
|
| 66 |
+
pq.write_table(table, target, compression="zstd")
|
| 67 |
return str(target)
|
| 68 |
|
| 69 |
with gr.Blocks(title="GenBank Annotation Explorer", delete_cache=(3600, 3600)) as demo:
|