Working out a few kinks in this code and for some reason my method validation check is not quite working. All I want it to do is to validate that the input from the user ONLY contains letters G, C, A, T before moving onto the method at_calculate which performs the maths on the input sequence. Any help/tips would be appreciated.
import re
from tkinter import *
class AT_content_calculator:
def __init__(self, master):
#initialising various widgets
frame_1 = Frame(master)
frame_1.pack()
self.varoutput_1 = StringVar()
self.label_1 = Label(frame_1, text="Please enter a DNA sequence:")
self.label_1.pack()
self.entry_1 = Entry(frame_1, textvariable=self.dna_sequence)
self.entry_1.pack()
self.output_1 = Label(frame_1, textvariable=self.varoutput_1)
self.output_1.pack()
self.button_1 = Button(frame_1, text="Calculate", command=self.validation_check)
self.button_1.pack()
def dna_sequence(self):
self.dna_sequence = ()
def validation_check(self):
#used to validate that self.dna_sequence only contains letters G, C, A, T
if re.match(r"GCAT", self.dna_sequence):
self.at_calculate()
else:
self.varoutput_1.append = "Invalid DNA sequence. Please enter again."
self.validation_check()
def at_calculate(self):
#used to calculate AT content of string stored in self.dna_sequence
self.dna_sequence = self.entry_1.get()
self.total_bases = len(self.dna_sequence)
self.a_bases = self.dna_sequence.count("A")
self.b_bases = self.dna_sequence.count("T")
self.at_content = "%.2f" % ((self.a_bases + self.b_bases) / self.total_bases)
self.varoutput_1.set("AT content percentage: " + self.at_content)
root = Tk()
root.title("AT content calculator")
root.geometry("320x320")
b = AT_content_calculator(root)
root.mainloop()