pswap commited on
Commit
e77adef
·
verified ·
1 Parent(s): 325c721
Files changed (3) hide show
  1. app.py +22 -0
  2. requirements.txt +3 -0
  3. utils.py +50 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils import run_clinker
3
+
4
+
5
+ with gr.Blocks(title="Clinker Gene Cluster Comparison") as demo:
6
+ gr.Markdown("## Clinker Gene Cluster Comparison\nEnter one NCBI nucleotide accession per line.")
7
+ accessions_input = gr.Textbox(
8
+ lines=6,
9
+ placeholder="e.g.\nMH816969\nMH816970",
10
+ label="Accessions",
11
+ )
12
+ run_btn = gr.Button("Run", variant="primary")
13
+ status = gr.Textbox(label="Status", interactive=False)
14
+ html_output = gr.HTML(label="Clinker Output")
15
+
16
+ run_btn.click(
17
+ fn=run_clinker,
18
+ inputs=accessions_input,
19
+ outputs=[html_output, status],
20
+ )
21
+
22
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ biopython
3
+ clinker-bio
utils.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import tempfile
4
+ import subprocess
5
+ from Bio import Entrez, SeqIO
6
+
7
+ Entrez.email = "user@example.com"
8
+
9
+
10
+ def fetch_genbank(accession, out_dir):
11
+ handle = Entrez.efetch(db="nuccore", id=accession, rettype="gbwithparts", retmode="text")
12
+ record = SeqIO.read(handle, "genbank")
13
+ handle.close()
14
+ path = os.path.join(out_dir, f"{accession}.gbk")
15
+ SeqIO.write(record, path, "genbank")
16
+ return path
17
+
18
+
19
+ def run_clinker(accessions_text):
20
+ accessions = [a.strip() for a in accessions_text.strip().splitlines() if a.strip()]
21
+ if not accessions:
22
+ return None, "Please enter at least one accession."
23
+
24
+ work_dir = tempfile.mkdtemp()
25
+ gbk_files = []
26
+ errors = []
27
+
28
+ for acc in accessions:
29
+ try:
30
+ gbk_files.append(fetch_genbank(acc, work_dir))
31
+ except Exception as e:
32
+ errors.append(f"{acc}: {e}")
33
+
34
+ if not gbk_files:
35
+ shutil.rmtree(work_dir)
36
+ return None, "Failed to download any records:\n" + "\n".join(errors)
37
+
38
+ html_out = os.path.join(work_dir, "output.html")
39
+ result = subprocess.run(["clinker"] + gbk_files + ["-p", html_out], capture_output=True, text=True)
40
+
41
+ if not os.path.exists(html_out):
42
+ shutil.rmtree(work_dir)
43
+ return None, f"clinker failed:\n{result.stderr}"
44
+
45
+ with open(html_out) as f:
46
+ html_content = f.read()
47
+
48
+ shutil.rmtree(work_dir)
49
+ msg = "Done." if not errors else "Done.\nSkipped:\n" + "\n".join(errors)
50
+ return html_content, msg