File size: 4,947 Bytes
4b71c5b eaa0e59 4b71c5b 2941a1c 4b71c5b f29fbd1 b73ccc2 2941a1c 4b71c5b eaa0e59 4b71c5b eaa0e59 4b71c5b b73ccc2 4b71c5b f29fbd1 4b71c5b b73ccc2 f29fbd1 eaa0e59 b73ccc2 f29fbd1 2941a1c 4b71c5b 2941a1c 4b71c5b 2941a1c 4b71c5b 2941a1c 2491d7e 2941a1c 4b71c5b 2941a1c eaa0e59 2941a1c 2491d7e eaa0e59 fbdd746 eaa0e59 b73ccc2 eaa0e59 b73ccc2 2941a1c b73ccc2 eaa0e59 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
"""
Protein Location Predictor GUI
This module provides a Tkinter-based GUI for loading FASTA files
and running protein location prediction tools.
"""
import tkinter as tk
from tkinter import Menu, filedialog, messagebox
import torch
from src.my_utils import predict_with_prost, predict_with_esm
FASTA_FILE_PATH = None # Global or instance variable
def load_fasta_file():
"""
Opens a file dialog for the user to select a FASTA file and
stores the selected file path in a global variable.
If a file is selected, displays an information message with the file path.
If no file is selected, displays a warning message.
Uses:
- filedialog.askopenfilename for file selection.
- messagebox.showinfo and messagebox.showwarning for user feedback.
Global Variables:
FASTA_FILE_PATH (str): Path to the selected FASTA file.
"""
global FASTA_FILE_PATH # pylint: disable=global-statement
FASTA_FILE_PATH = filedialog.askopenfilename(
filetypes=[("FASTA files", "*.fasta *.fa")],
title="Select a FASTA file"
)
if FASTA_FILE_PATH:
messagebox.showinfo("File Loaded", f"Loaded file:\n{FASTA_FILE_PATH}")
else:
messagebox.showwarning("No file", "No file was selected.")
def run_prost():
"""
Runs the protein location prediction process.
Checks if a FASTA file path is provided. If not, displays an error message to the user.
If a FASTA file is loaded, proceeds to run the prediction using the PROST model.
Raises:
Shows a message box error if no FASTA file is loaded.
"""
if not FASTA_FILE_PATH:
messagebox.showerror("Error", "Please load a FASTA file first.")
return
predict_with_prost(FASTA_FILE_PATH)
torch.cuda.empty_cache()
def run_esm300():
"""
Runs the protein location prediction process.
Checks if a FASTA file path is provided. If not, displays an error message to the user.
If a FASTA file is loaded, proceeds to run the prediction using the PROST model.
Raises:
Shows a message box error if no FASTA file is loaded.
"""
if not FASTA_FILE_PATH:
messagebox.showerror("Error", "Please load a FASTA file first.")
return
predict_with_esm(fasta_path = FASTA_FILE_PATH,
model = 'esmc_300m')
torch.cuda.empty_cache()
def run_esm600():
"""
Runs the protein location prediction process.
Checks if a FASTA file path is provided. If not, displays an error message to the user.
If a FASTA file is loaded, proceeds to run the prediction using the PROST model.
Raises:
Shows a message box error if no FASTA file is loaded.
"""
if not FASTA_FILE_PATH:
messagebox.showerror("Error", "Please load a FASTA file first.")
return
predict_with_esm(fasta_path = FASTA_FILE_PATH,
model = 'esmc_600m')
torch.cuda.empty_cache()
def menu():
"""
Displays the main GUI menu for the Protein Tools application.
This function creates a Tkinter window with a menu bar containing 'File' and 'Help' menus,
and buttons for running protein prediction tools and exiting the application.
Menus:
- File: Options to load a FASTA file or close the application.
- Help: Options for welcome information and about dialog.
Buttons:
- Predict with Prost: Runs the Prost prediction tool.
- Predict with ESM C: Placeholder for ESM prediction functionality (not yet implemented).
- Exit: Closes the application.
"""
# root window
root = tk.Tk()
root.geometry('320x200')
root.title('Protein Location Predictor')
# create a menubar
menubar = Menu(root)
root.config(menu=menubar)
# create the file_menu
file_menu = Menu(menubar, tearoff=0)
file_menu.add_command(label='Load FASTA', command=load_fasta_file)
file_menu.add_command(label='Close', command=root.quit)
file_menu.add_separator()
menubar.add_cascade(label="File", menu=file_menu, underline=0)
# help menu
help_menu = Menu(menubar, tearoff=0)
help_menu.add_command(label='Welcome')
help_menu.add_command(label='About...')
menubar.add_cascade(label="Help", menu=help_menu, underline=0)
btn_prost = tk.Button(root, text="Predict with Prost T5",
command=run_prost) #Predict with Prost
btn_prost.pack(pady=5)
btn_esm300 = tk.Button(root, text="Predict with ESM C 300m",
command = run_esm300) #Predict with ESM C 300m
btn_esm300.pack(pady=5)
btn_esm300 = tk.Button(root, text="Predict with ESM C 600m",
command = run_esm600) #Predict with ESM C 600m
btn_esm300.pack(pady=5)
btn_exit = tk.Button(root, text="Exit", command=root.quit)
btn_exit.pack(pady=5)
root.mainloop()
if __name__ == "__main__":
menu()
# End-of-file (EOF)
|