-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
53 lines (43 loc) · 1.88 KB
/
gui.py
File metadata and controls
53 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import tkinter as tk
from tkinter import filedialog, scrolledtext
import subprocess
def run_gui():
root = tk.Tk()
root.title("SNP Ranger - Locating SNPs in annotated regions")
''' widget for Mauve SNP output '''
tk.Label(root, text="Mauve SNP Output:").grid(row=0, column=0, sticky="e")
mauve_entry = tk.Entry(root, width=50)
mauve_entry.grid(row=0, column=1)
tk.Button(root, text="Browse", command=lambda: mauve_entry.insert(0, filedialog.askopenfilename())).grid(row=0, column=2)
''' widget for first gbk file input'''
tk.Label(root, text="First GBK File:").grid(row=1, column=0, sticky="e")
gbk_entry = tk.Entry(root, width=50)
gbk_entry.grid(row=1, column=1)
tk.Button(root, text="Browse", command=lambda: gbk_entry.insert(0, filedialog.askopenfilename())).grid(row=1, column=2)
''' scrollable text box output'''
result_text = scrolledtext.ScrolledText(root, width=80, height=30)
result_text.grid(row=3, column=0, columnspan=3, padx=10, pady=10)
''' run button '''
def run_analysis():
mauve_file = mauve_entry.get()
gbk_file = gbk_entry.get()
result_text.delete(1.0, tk.END)
try:
''' run snp ranger as a subprocess'''
result = subprocess.run(
["python3", "snp_ranger.py", mauve_file, gbk_file],
capture_output=True,
text=True
)
''' print stdout and stderr '''
result_text.insert(tk.END, result.stdout)
if result.stderr:
result_text.insert(tk.END, "\nErrors:\n" + result.stderr)
except Exception as e:
result_text.insert(tk.END, f"Error running script: {e}")
tk.Button(root, text="Find my SNPs!", command=run_analysis).grid(row=2, column=1)
root.mainloop()
if __name__ == "__main__":
run_gui()