Skip to content

Commit 75fea53

Browse files
authored
Update digestR.R
1 parent 6948fb6 commit 75fea53

File tree

1 file changed

+67
-54
lines changed

1 file changed

+67
-54
lines changed

R/digestR.R

+67-54
Original file line numberDiff line numberDiff line change
@@ -18980,87 +18980,100 @@ ps <- function(dispPane='co'){
1898018980
# }
1898118981
# displayGeneButton <- ttkbutton(genePlotTypeFrame, text='Display Single Gene', width=21, command=onDisplayGene)
1898218982

18983-
onDisplayGene <- function()
18984-
{
18985-
# Existing modal dialog for gene name entry
18986-
geneName <- modalDialog(dlg, 'Gene Name Entry', 'Enter the name of the gene you wish to view in detail:', '')
18983+
onDisplayGene <- function() {
18984+
# Generate a temporary dialog window
18985+
geneDialog <- tktoplevel()
18986+
tkwm.title(geneDialog, "Gene Name Entry")
1898718987

18988-
if(geneName == 'ID_CANCEL') {
18989-
return()
18990-
} else {
18991-
if(nchar(geneName) == 0) {
18992-
analyze_genes('')
18993-
}
18994-
else if(geneName %in% species$genes$name) {
18995-
analyze_genes(geneName)
18996-
} else {
18997-
log_message(paste0(geneName, ' is not a valid gene of ', species$name))
18998-
}
18999-
}
18988+
# Instruction label
18989+
geneLabel <- ttklabel(geneDialog, text = 'Enter the name of the gene you wish to view in detail:')
18990+
tkgrid(geneLabel, padx = 10, pady = 5)
1900018991

19001-
# Add the Listbox for Genes Above Threshold
19002-
addGeneListboxAboveThreshold()
19003-
}
19004-
19005-
# Function to add listbox for genes above threshold
19006-
addGeneListboxAboveThreshold <- function() {
19007-
# Create a new window for displaying the filtered gene list
19008-
geneDialog <- tktoplevel()
19009-
tkwm.title(geneDialog, "Filtered Genes Above Threshold")
18992+
# Entry box for manual gene name input
18993+
geneEntry <- tkentry(geneDialog, width = 30)
18994+
tkgrid(geneEntry, padx = 10, pady = 5)
1901018995

19011-
# Fetch the threshold value from the current spectrum
18996+
# Dropdown (combobox) populated with available gene names from species$genes$name
18997+
geneNamesList <- species$genes$name # Assuming this is a list of available gene names
18998+
18999+
### Get Threshold from gene_labeling ###
1901219000
if (fileFolder[[currentSpectrum]]$file.par$noise_override != -1) {
1901319001
threshold <- fileFolder[[currentSpectrum]]$file.par$noise_override
1901419002
} else {
1901519003
threshold <- fileFolder[[currentSpectrum]]$file.par$noise_multiplier
1901619004
}
1901719005

19018-
# Assuming there is a corresponding scores vector in species$genes$scores
19019-
geneScores <- species$genes$scores
19020-
geneNamesList <- species$genes$name
19021-
19022-
# Filter genes based on the threshold
19023-
filteredGenes <- geneNamesList[geneScores > threshold]
19006+
### Filter genes based on the threshold ###
19007+
# Assuming there's a corresponding `species$genes$scores` vector with gene scores
19008+
geneScores <- species$genes$scores # Make sure this vector exists
19009+
filteredGenes <- geneNamesList[geneScores > threshold] # Filter genes above the threshold
1902419010

19025-
# Listbox to display the filtered genes
19011+
### Add a Listbox to Display Filtered Gene Names ###
1902619012
geneListVar <- tclVar()
19027-
tclObj(geneListVar) <- filteredGenes
19013+
tclObj(geneListVar) <- filteredGenes # Populate the listbox with filtered gene names
1902819014

1902919015
geneListbox <- tklistbox(geneDialog, listvariable = geneListVar, selectmode = "single", width = 30, height = 10)
1903019016
tkgrid(geneListbox, padx = 10, pady = 5)
1903119017

19032-
# Add scrollbar for listbox
19018+
# Scrollbar for the listbox
1903319019
listScrollbar <- ttkscrollbar(geneDialog, orient = "vertical", command = function(...) tkyview(geneListbox, ...))
1903419020
tkconfigure(geneListbox, yscrollcommand = function(...) tkset(listScrollbar, ...))
19035-
tkgrid(listScrollbar, column = 2, row = 1, sticky = "ns")
19036-
19037-
# OK button to confirm gene selection from listbox
19038-
onGeneSelectOK <- function() {
19039-
selectedIdx <- as.integer(tkcurselection(geneListbox))
19040-
if (length(selectedIdx) > 0) {
19041-
selectedGene <- filteredGenes[selectedIdx + 1] # Get selected gene name
19042-
analyze_genes(selectedGene)
19021+
tkgrid(listScrollbar, column = 2, row = 4, sticky = "ns")
19022+
19023+
# Function to handle the 'OK' button click
19024+
onOK <- function() {
19025+
# Get the gene name from either the entry box, dropdown, or listbox
19026+
geneName <- tclvalue(geneEntry)
19027+
19028+
if (nchar(geneName) == 0) {
19029+
geneName <- tclvalue(geneDropdown) # Fall back to dropdown selection
19030+
}
19031+
19032+
# Get the selected item from the listbox if nothing else is selected
19033+
if (nchar(geneName) == 0) {
19034+
selectedIdx <- as.integer(tkcurselection(geneListbox))
19035+
if (length(selectedIdx) > 0) {
19036+
geneName <- filteredGenes[selectedIdx + 1] # Listbox is 0-indexed
19037+
}
19038+
}
19039+
19040+
# Proceed with analysis
19041+
if (nchar(geneName) == 0) {
19042+
# No gene entered or selected, analyze full proteome
19043+
analyze_genes('')
19044+
} else if (geneName %in% species$genes$name) {
19045+
# Valid gene name, analyze the selected gene
19046+
analyze_genes(geneName)
19047+
} else {
19048+
# Invalid gene name, display error message
19049+
log_message(paste0(geneName, ' is not a valid gene of ', species$name))
1904319050
}
19044-
tkdestroy(geneDialog) # Close the listbox window
19051+
19052+
tkdestroy(geneDialog) # Close the dialog box
1904519053
}
1904619054

19047-
# OK and Cancel buttons
19048-
okButton <- ttkbutton(geneDialog, text = 'OK', command = onGeneSelectOK)
19055+
# OK button
19056+
okButton <- ttkbutton(geneDialog, text = 'OK', command = onOK)
1904919057
tkgrid(okButton, padx = 10, pady = 10)
1905019058

19051-
cancelButton <- ttkbutton(geneDialog, text = 'Cancel', command = function() tkdestroy(geneDialog))
19059+
# Cancel button
19060+
onCancel <- function() {
19061+
tkdestroy(geneDialog) # Close the dialog box without action
19062+
}
19063+
cancelButton <- ttkbutton(geneDialog, text = 'Cancel', command = onCancel)
1905219064
tkgrid(cancelButton, padx = 10, pady = 10)
1905319065

19054-
# Set focus on the listbox window
19066+
# Keep focus on the dialog
1905519067
tkfocus(geneDialog)
1905619068
}
19069+
1905719070
displayGeneButton <- ttkbutton(genePlotTypeFrame, text='Display Single Gene', width=21, command=onDisplayGene)
19058-
19059-
onDisplayProteome <- function()
19060-
{
19061-
analyze_genes('')
19062-
}
19063-
displayGenomeButton <- ttkbutton(genePlotTypeFrame, text='Display Full Proteome', width=21, command=onDisplayProteome)
19071+
19072+
onDisplayProteome <- function()
19073+
{
19074+
analyze_genes('')
19075+
}
19076+
displayGenomeButton <- ttkbutton(genePlotTypeFrame, text='Display Full Proteome', width=21, command=onDisplayProteome)
1906419077

1906519078

1906619079
# onDisplayGene <- function() {

0 commit comments

Comments
 (0)