Commit 09b25bbb authored by Jordan Eckhoff's avatar Jordan Eckhoff

Added an error box for IS_Fasta_Main.py crashing when the Cancel button is...

Added an error box for IS_Fasta_Main.py crashing when the Cancel button is pressed during file selection.

Instead of crashing outright, a custom error message is now displayed as per a try-except statement
parent 9e98c60e
......@@ -15,54 +15,57 @@
import IS_Fasta_Sequence # Custom module for working with FASTA files
from tkinter import messagebox
from tkinter import Tk #
from tkinter.filedialog import askopenfilename # Asks user to select a .fa FASTA file
Tk().withdraw() #
with open(askopenfilename(),'r') as FastaFile: # Opens the selected .fa file via its PATH
Sequences = IS_Fasta_Sequence.Sequence_Read(FastaFile.readlines()) # Creates a list of custom FASTA_Seq objects, each of which contains a single sequence from the FASTA file
# and its associated metadata as seperate properties, Seq and Meta respectively, as well as Code, a string
# indicating the type of sequence encoded (DNA, mRNA, Protein, or Indeterminable)
try:
with open(askopenfilename(),'r') as FastaFile: # Opens the selected .fa file via its PATH
Sequences = IS_Fasta_Sequence.Sequence_Read(FastaFile.readlines()) # Creates a list of custom FASTA_Seq objects, each of which contains a single sequence from the FASTA file
# and its associated metadata as seperate properties, Seq and Meta respectively, as well as Code, a string
# indicating the type of sequence encoded (DNA, mRNA, Protein, or Indeterminable)
print('There are ' + str(len(Sequences)) + ' sequences in this FASTA file.\n' + 'Please input which number sequence you would like to use:')
SeqNo = int(input())
print('\n')
print('Selected sequence data:\n')
print(' Metadata: ' + Sequences[SeqNo - 1].Meta + '\n')
print(' Original Sequence: ' + Sequences[SeqNo - 1].Seq + '\n')
print('Please enter reading frame number (0, 1, or 2):')
FrameNo = int(input())
X = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[SeqNo-1],FrameNo)
print('Translated Sequence: ' + X.Seq)
print('There are ' + str(len(Sequences)) + ' sequences in this FASTA file.\n' + 'Please input which number sequence you would like to use:')
SeqNo = int(input())
print('\n')
print('Selected sequence data:\n')
print(' Metadata: ' + Sequences[SeqNo - 1].Meta + '\n')
print(' Original Sequence: ' + Sequences[SeqNo - 1].Seq + '\n')
print('Please enter reading frame number (0, 1, or 2):')
FrameNo = int(input())
X = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[SeqNo-1],FrameNo)
print('Translated Sequence: ' + X.Seq)
#for a in range(0,len(Sequences)):
# print(Sequences[a].Meta + '\n',
# Sequences[a].Seq + '\n',
# Sequences[a].CodeType + '\n')
#for a in range(0,len(Sequences)):
# print(Sequences[a].Meta + '\n',
# Sequences[a].Seq + '\n',
# Sequences[a].CodeType + '\n')
#W = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[0],2,'Protein')
#W = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[0],2,'Protein')
#print(W.Meta + '\n',
# W.Seq + '\n',
# W.CodeType + '\n')
#print(W.Meta + '\n',
# W.Seq + '\n',
# W.CodeType + '\n')
#X = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[1],2,'Protein')
#X = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[1],2,'Protein')
#print(X.Meta + '\n',
# X.Seq + '\n',
# X.CodeType + '\n')
#print(X.Meta + '\n',
# X.Seq + '\n',
# X.CodeType + '\n')
#Y = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[2],2,'Protein')
#Y = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[2],2,'Protein')
#print(Y.Meta + '\n',
# Y.Seq + '\n',
# Y.CodeType + '\n')
#print(Y.Meta + '\n',
# Y.Seq + '\n',
# Y.CodeType + '\n')
#Z = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[3],2,'Protein')
#Z = IS_Fasta_Sequence.Sequence_Forward_Translate(Sequences[3],2,'Protein')
#print(Z.Meta + '\n',
# Z.Seq + '\n',
# Z.CodeType + '\n')
#print(Z.Meta + '\n',
# Z.Seq + '\n',
# Z.CodeType + '\n')
except FileNotFoundError:
messagebox.showerror('File Selection Error','No file selected, please try again')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment