I’m attempting to write a GUI searchable bacteria database with the database array embedded in the code using tkinter python 2.7. Choosing certain criteria via radiobuttons selectively searches the array, then hitting the ‘Identify’ button should print out the id of all bacteria which match those selections as a label.
I’ve posted the nonfunctional snippet [idbuttonclick(self)] below.
What the snippet def idbuttonclick(self) is supposed to do:
1) Search the matrix/array named ‘data’ for which columns 1-4 represent a radiobutton string variable option and each row a bacteria id
2) Select the rows in ‘data’ whose variable options match the radiobutton selections
3) Prints the bacteria ids in data column 0 from the selected rows as a label in the self.id_frame if the number of ids is 1-20. Otherwise, print the message label “Error: Not enough data.”
def idbuttonclick(self):
def column(matrix, i):
if column(data, 1)!=self.gram_option.get(): line.destroy()
if column(data, 2)!=self.meta_option.get(): line.destroy()
if column(data, 3)!=self.cat_option.get(): line.destroy()
if column(data, 4)!=self.oxi_option.get(): line.destroy()
column(data, 0)==id
if id.count >= 20 or id.count == 0:
Label(self.id_frame, text = "Error: Not enough data", background = "white").pack(side=TOP, anchor = N)
else: Label(self.id_frame, text = id, background = "white").pack(side=TOP, anchor = N)
I’ve gotten the code to give me id.frame labels based on radiobutton selections, but still can’t link the radiobutton selections to coordinates in the array to then provide id.frame labels based on the radiobutton/array coordinate matches.
It is now specifically an array, not a matrix, as matrices and lists of lists and tuples apparently cannot store elements using a coordinate index (i,j).
Here’s my new draft below, which includes array and idbutton click command.
How this should work:
Any bacteria name in array column 1 with a ‘+’ value in array column 2 within the same row should appear in the id.frame label if the radiobutton self.gram_option=(‘+’) is selected.
So, the label should read: ‘Acetobacter aceti, Pseudomonas sp.’
Additionally clicking self.meta_option.get() should then correspond to column 2, narrowing the selection: a ‘fac anaerobe’ value would label ‘Acetobacter aceti’ and an ‘aerobe’ value would label ‘Pseudomonas sp.’
data = array([
['Acetobacter aceti','+', 'fac anaerobe', '+', '--'],
['Citrobacter freundii','--', 'fac anaerobe', '+', '--'],
['Pseudomonas sp','+', 'aerobe', '--', '--']])
data.readlines()
def idbuttonclick(self, event):
self.id_frame.destroy()
self.id_frame = Frame(self.main_right_frame, borderwidth=5, height=50, background="white")
self.id_frame.pack(side=TOP, fill=BOTH)
if data[i,1]==self.gram_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,2]==self.shape_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,3]==self.meta_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,4]==self.cat_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
else: Label(self.id_frame, text = 'Error: Not enough data', background = "white").pack(side=LEFT, anchor = N)
If I’m not stating my array coordinates correctly or someone knows a workable way to arrange the above scenario in python code…
I’ve gotten 56 views on this question over a period of about two weeks, but no code-writing feedback from the community. Hopefully, this new version better addresses what I originally had in mind and what needs tweaking.
Sincerely,
Jeff
This solution uses a probability comparison instead of + and – (i.e., each bacteria has X probability of getting a + score and 1-X probability of getting a – score.) But this code will tie in the radiobuttons to the data matrix and then rank the top ten scoring bacteria accordingly. All the pieces are cooperating.