Skip to content

Commit 65eb112

Browse files
authored
Update digestR.R
1 parent 42e5a7a commit 65eb112

File tree

1 file changed

+13
-347
lines changed

1 file changed

+13
-347
lines changed

R/digestR.R

+13-347
Original file line numberDiff line numberDiff line change
@@ -1331,33 +1331,33 @@ splashScreen <- function(){
13311331

13321332
par(mar=defaultSettings$mar, cex.axis=defaultSettings$cex.axis,
13331333
cex.main=defaultSettings$cex.main, bg='black')
1334-
colMain <- '#b4d0f3'
1334+
colMain <- '#4da6ff'
13351335
colBack <- '#0065ca'
13361336
plot(0, 0, type='n', xlab='', ylab='', col.axis='black')
13371337
# Define your color palette
13381338
#colMain <- '#FF5733' # A warm main color
13391339
#colBack <- '#2E86C1' # A contrasting background color
13401340

13411341
# Letter positions and colors
1342-
letters <- c('D', 'I', 'G', 'E', 'S', 'T', 'R')
1343-
colors <- c(colMain, colMain, colMain, colMain, colMain, colMain, colBack)
1344-
cex_values <- c(7, 7, 7, 7, 7, 7, 6.5)
1345-
offset_values <- c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.4)
1342+
letters <- c('P', 'A', 'N', 'D', 'A', 'S')
1343+
colors <- c(colMain, colMain, colMain, colMain, colMain, colMain)
1344+
cex_values <- c(7, 7, 7, 7, 7, 7)
1345+
offset_values <- c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5)
13461346

13471347
# Loop to create and position letters
13481348
for (i in 1:length(letters)) {
13491349
text(-0.75 + (i-1)*0.25, 0.2, letters[i], col=colors[i], cex=cex_values[i], pos=3, offset=offset_values[i])
13501350
}
13511351

1352-
# Add a decorative 'R' in a different color
1353-
text(0.70, 0.2, 'R', col='#E74C3C', cex=5.5, pos=3, offset=0.4)
1352+
# # Add a decorative 'R' in a different color
1353+
# text(0.70, 0.2, 'R', col='#E74C3C', cex=5.5, pos=3, offset=0.4)
13541354

1355-
# Other text elements (modify as needed)
1356-
text(0, 0.08, 'Digestomics Analyzer', col=colMain, cex=2.5, font=1)
1357-
text(0, -0.15, paste('version 1.0.0', pkgVar$version), col=colMain, font=3)
1358-
text(0, -0.25, 'gp() - Generate New Proteome', col=colMain)
1359-
text(0, -0.35, 'pm() - Process Mascot files', col=colMain)
1360-
text(0, -0.45, 'fo() - Open *.dcf files', col=colMain)
1355+
# # Other text elements (modify as needed)
1356+
# text(0, 0.08, 'Digestomics Analyzer', col=colMain, cex=2.5, font=1)
1357+
# text(0, -0.15, paste('version 1.0.0', pkgVar$version), col=colMain, font=3)
1358+
# text(0, -0.25, 'gp() - Generate New Proteome', col=colMain)
1359+
# text(0, -0.35, 'pm() - Process Mascot files', col=colMain)
1360+
# text(0, -0.45, 'fo() - Open *.dcf files', col=colMain)
13611361

13621362
# Force the graphics device to refresh
13631363
dev.flush()
@@ -6164,340 +6164,6 @@ pseudo1D <- function(x){range(x)[which.max(abs(range(x)))]}
61646164
# Updated fo function: DDLM
61656165
#################################################################################
61666166

6167-
# handleFoErrors <- function(cond) {
6168-
# # Log and handle the error message
6169-
# log_message(paste("An error occurred:", cond$message))
6170-
6171-
# # Return NULL to indicate that the file couldn't be processed
6172-
# return(NULL)
6173-
# }
6174-
6175-
# file_open <- function(fileName, ...) {
6176-
6177-
# # Initialize necessary objects at the beginning
6178-
# if (!exists("fileFolder") || is.null(fileFolder)) {
6179-
# fileFolder <- list() # Initialize fileFolder if it doesn't exist or is NULL
6180-
# }
6181-
6182-
# if (!exists("currentSpectrum") || is.null(currentSpectrum)) {
6183-
# currentSpectrum <- NULL # Initialize currentSpectrum to a default state
6184-
# }
6185-
6186-
# # Create any/all of the digestR objects that are missing
6187-
# createObj()
6188-
6189-
# # Suppress warnings temporarily
6190-
# old_warn <- options(warn = -1) # Save the current warning settings and suppress warnings
6191-
6192-
# # Have user select all files they wish to open
6193-
# if (missing(fileName)) {
6194-
# usrList <- sort(myOpen())
6195-
# if (!length(usrList) || !nzchar(usrList)) {
6196-
# log_message("No files selected.")
6197-
# options(old_warn) # Restore warning settings
6198-
# return(invisible())
6199-
# }
6200-
# } else {
6201-
# usrList <- fileName
6202-
# }
6203-
6204-
# log_message(paste("Files to be processed:", paste(usrList, collapse = ", ")))
6205-
6206-
# # Read selected files
6207-
# for (i in 1:length(usrList)) {
6208-
6209-
# # Try to read the file while suppressing warnings specific to readChar
6210-
# new.file <- suppressWarnings(
6211-
# tryCatch(
6212-
# dianaHead(file.name = usrList[i], print.info = TRUE),
6213-
# error = function(cond) handleFoErrors(cond) # Only pass 'cond'
6214-
# )
6215-
# )
6216-
6217-
# if (is.null(new.file)) {
6218-
# log_message(paste("Error opening file", basename(usrList[i])))
6219-
# next
6220-
# }
6221-
6222-
# log_message(paste("File", basename(usrList[i]), "loaded successfully"))
6223-
6224-
# # Make sure input files are of the correct format
6225-
# if (length(new.file$file.par) == 0) {
6226-
# log_message(paste('ERROR:', basename(usrList)[i], "is unreadable"), quote = FALSE)
6227-
# flush.console()
6228-
# next
6229-
# }
6230-
6231-
# new.file$graphics.par <- defaultSettings
6232-
6233-
# if (new.file$file.par$number_dimensions == 1) {
6234-
# new.file$graphics.par$usr <- c(
6235-
# new.file$file.par$downfield_ppm[1],
6236-
# new.file$file.par$upfield_ppm[1],
6237-
# new.file$file.par$min_intensity,
6238-
# new.file$file.par$max_intensity
6239-
# )
6240-
# } else {
6241-
# new.file$graphics.par$usr <- c(
6242-
# new.file$file.par$downfield_ppm[2],
6243-
# new.file$file.par$upfield_ppm[2],
6244-
# new.file$file.par$downfield_ppm[1],
6245-
# new.file$file.par$upfield_ppm[1]
6246-
# )
6247-
# }
6248-
6249-
# filePar <- new.file$file.par
6250-
# fileNames <- names(fileFolder)
6251-
# userTitles <- NULL
6252-
# if (!is.null(fileFolder)) {
6253-
# userTitles <- sapply(fileFolder, function(x) x$file.par$user_title)
6254-
# }
6255-
6256-
# if (!new.file$file.par$file.name %in% fileNames) {
6257-
# if (new.file$file.par$number_dimensions < 3) {
6258-
# if (new.file$file.par$user_title %in% userTitles)
6259-
# new.file$file.par$user_title <- new.file$file.par$file.name
6260-
# fileFolder[[(length(fileFolder) + 1)]] <- new.file
6261-
# names(fileFolder)[length(fileFolder)] <- new.file$file.par$file.name
6262-
# } else {
6263-
# w3 <- seq(filePar$upfield_ppm[3], filePar$downfield_ppm[3],
6264-
# length.out = filePar$matrix_size[3])
6265-
# for (j in seq_along(w3)) {
6266-
# userTitle <- paste(basename(filePar$file.name), ' (z=', w3[j], ')', sep = '')
6267-
# new.file$file.par$user_title <- userTitle
6268-
# new.file$file.par$z_value <- w3[j]
6269-
# fileFolder[[length(fileFolder) + 1]] <- new.file
6270-
# names(fileFolder)[length(fileFolder)] <- userTitle
6271-
# }
6272-
# }
6273-
# } else {
6274-
# fLoc <- match(new.file$file.par$file.name, fileNames)
6275-
# if (new.file$file.par$number_dimensions < 3) {
6276-
# fileFolder[[fLoc]] <- new.file
6277-
# if (new.file$file.par$user_title %in% userTitles)
6278-
# new.file$file.par$user_title <- new.file$file.par$file.name
6279-
# } else {
6280-
# for (j in fLoc) {
6281-
# zVal <- fileFolder[[j]]$file.par$z_value
6282-
# new.file$file.par$user_title <- paste(basename(filePar$file.name), ' (z=', zVal, ')', sep = '')
6283-
# new.file$file.par$z_value <- zVal
6284-
# fileFolder[[j]] <- new.file
6285-
# }
6286-
# }
6287-
# }
6288-
6289-
# if (new.file$file.par$number_dimensions < 3) {
6290-
# currentSpectrum <- new.file$file.par$file.name
6291-
# } else {
6292-
# currentSpectrum <- userTitle
6293-
# }
6294-
6295-
# log_message(basename(usrList[i]), quote = FALSE)
6296-
# flush.console()
6297-
# }
6298-
6299-
# options(old_warn) # Restore warning settings to their previous state
6300-
6301-
# myAssign("fileFolder", fileFolder, save.backup = FALSE)
6302-
# myAssign("currentSpectrum", currentSpectrum, save.backup = FALSE)
6303-
6304-
# if (is.null(fileFolder) || length(fileFolder) == 0) {
6305-
# log_message("fileFolder is empty after loading.")
6306-
# } else {
6307-
# log_message(paste("fileFolder is populated. CurrentSpectrum is:", currentSpectrum))
6308-
6309-
# if (dev.cur() == 1) {
6310-
# dev.new()
6311-
# }
6312-
6313-
# splashScreen()
6314-
6315-
# log_message("splashScreen called to update the UI.")
6316-
6317-
# plotData(currentSpectrum, fileFolder)
6318-
6319-
# Sys.sleep(0.5)
6320-
6321-
# dev.flush()
6322-
# refresh(...)
6323-
# }
6324-
6325-
# return(invisible(usrList))
6326-
# }
6327-
6328-
# ## Plotting function with bg parameter fix
6329-
# plotData <- function(spectrum, fileFolder) {
6330-
# if (!is.null(spectrum)) {
6331-
# log_message(paste("Plotting data for spectrum:", spectrum))
6332-
6333-
# ## Retrieve the relevant file's graphical parameters
6334-
# file <- fileFolder[[which(names(fileFolder) == spectrum)]]
6335-
# graphicsParams <- file$graphics.par
6336-
6337-
# ## Log the parameters to debug
6338-
# log_message(paste("Using graphics parameters:", graphicsParams))
6339-
6340-
# ## Set correct graphical parameters
6341-
# par(bg = "white") # Set the background to a valid single value
6342-
6343-
# ## Apply other graphical parameters if needed
6344-
# usr <- graphicsParams$usr
6345-
# if (!is.null(usr)) {
6346-
# par(usr = usr)
6347-
# }
6348-
6349-
# ## Add your actual plotting code here
6350-
# # Example plot:
6351-
# # plot(x, y, ...)
6352-
6353-
# } else {
6354-
# log_message("No spectrum available for plotting.")
6355-
# }
6356-
# }
6357-
#######################################################################################
6358-
# file_open <- function(fileName, ...){
6359-
6360-
# ## Create any/all of the digestR objects that are missing
6361-
# createObj()
6362-
6363-
# ## Have user select all files they wish to open
6364-
# if (missing(fileName)){
6365-
# usrList <- sort(myOpen())
6366-
# if (!length(usrList) || !nzchar(usrList))
6367-
# return(invisible())
6368-
# } else {
6369-
# usrList <- fileName
6370-
# }
6371-
6372-
# ## Read selected files
6373-
# errors <- FALSE
6374-
# fileNames <- names(fileFolder)
6375-
# userTitles <- NULL
6376-
# if (!is.null(fileFolder))
6377-
# userTitles <- sapply(fileFolder, function(x) x$file.par$user_title)
6378-
6379-
# for (i in 1:length(usrList)) {
6380-
6381-
# ## Read Sparky Header and file info from binary
6382-
# new.file <- tryCatch(dianaHead(file.name = usrList[i], print.info = TRUE),
6383-
# error = function(er){
6384-
# errors <<- TRUE
6385-
# return(er$message)
6386-
# })
6387-
6388-
# if (errors) {
6389-
# err(new.file)
6390-
# next
6391-
# }
6392-
6393-
# ## Make sure input files are of the correct format
6394-
# if (length(new.file$file.par) == 0) {
6395-
# log_message(paste('ERROR:', basename(usrList)[i], "is unreadable"), quote = FALSE)
6396-
# flush.console()
6397-
# next
6398-
# }
6399-
6400-
# ## Fetch the default graphics settings
6401-
# new.file$graphics.par <- defaultSettings
6402-
6403-
# ## Set initial plotting range
6404-
# if (new.file$file.par$number_dimensions == 1) {
6405-
# new.file$graphics.par$usr <- c(new.file$file.par$downfield_ppm[1],
6406-
# new.file$file.par$upfield_ppm[1],
6407-
# new.file$file.par$min_intensity,
6408-
# new.file$file.par$max_intensity)
6409-
# } else {
6410-
# new.file$graphics.par$usr <- c(new.file$file.par$downfield_ppm[2],
6411-
# new.file$file.par$upfield_ppm[2],
6412-
# new.file$file.par$downfield_ppm[1],
6413-
# new.file$file.par$upfield_ppm[1])
6414-
# }
6415-
6416-
# ## Make a new entry in the file folder if file is not already present
6417-
# filePar <- new.file$file.par
6418-
# if (!new.file$file.par$file.name %in% fileNames) {
6419-
6420-
# ## Add 1D/2D spectra to the file folder
6421-
# if (new.file$file.par$number_dimensions < 3) {
6422-
# if (new.file$file.par$user_title %in% userTitles)
6423-
# new.file$file.par$user_title <- new.file$file.par$file.name
6424-
# fileFolder[[length(fileFolder) + 1]] <- new.file
6425-
# names(fileFolder)[length(fileFolder)] <- new.file$file.par$file.name
6426-
# } else {
6427-
6428-
# ## Make duplicate entries in fileFolder for each z-slice in 3D spectra
6429-
# w3 <- seq(filePar$upfield_ppm[3], filePar$downfield_ppm[3],
6430-
# length.out = filePar$matrix_size[3])
6431-
# for (j in seq_along(w3)) {
6432-
# userTitle <- paste(basename(filePar$file.name), ' (z=', w3[j], ')', sep = '')
6433-
# new.file$file.par$user_title <- userTitle
6434-
# new.file$file.par$z_value <- w3[j]
6435-
# fileFolder[[length(fileFolder) + 1]] <- new.file
6436-
# names(fileFolder)[length(fileFolder)] <- userTitle
6437-
# }
6438-
# }
6439-
# } else {
6440-
6441-
# ## Update fileFolder entry if file is already present in fileFolder
6442-
# fLoc <- match(new.file$file.par$file.name, fileNames)
6443-
# if (new.file$file.par$number_dimensions < 3) {
6444-
# fileFolder[[fLoc]] <- new.file
6445-
# if (new.file$file.par$user_title %in% userTitles)
6446-
# new.file$file.par$user_title <- new.file$file.par$file.name
6447-
# } else {
6448-
# for (j in fLoc) {
6449-
# zVal <- fileFolder[[j]]$file.par$z_value
6450-
# new.file$file.par$user_title <- paste(basename(filePar$file.name),
6451-
# ' (z=', zVal, ')', sep = '')
6452-
# new.file$file.par$z_value <- zVal
6453-
# fileFolder[[j]] <- new.file
6454-
# }
6455-
# }
6456-
# }
6457-
6458-
# ## Reassign currentSpectrum
6459-
# if (new.file$file.par$number_dimensions < 3) {
6460-
# currentSpectrum <- new.file$file.par$file.name
6461-
# } else {
6462-
# currentSpectrum <- userTitle
6463-
# }
6464-
6465-
# ## Tell user which files have been loaded
6466-
# log_message(basename(usrList)[i], quote = FALSE)
6467-
# flush.console()
6468-
# }
6469-
6470-
# ## Assign the new objects to the global environment
6471-
# myAssign("fileFolder", fileFolder, save.backup = FALSE)
6472-
# myAssign("currentSpectrum", currentSpectrum, save.backup = FALSE)
6473-
6474-
# ## Refresh the splash screen after the files are loaded and currentSpectrum is set
6475-
# if (!is.null(fileFolder) && length(fileFolder) > 0) {
6476-
# log_message("Refreshing splash screen with current spectrum.")
6477-
6478-
# ## Ensure the graphical device is ready and refresh splash screen
6479-
# if (dev.cur() == 1) {
6480-
# dev.new() # Open a new graphics device if none is active
6481-
# }
6482-
6483-
# splashScreen() # Call the splash screen
6484-
6485-
# ## Short delay to ensure screen is ready
6486-
# Sys.sleep(0.5)
6487-
6488-
# ## Force a redraw of the graphics device
6489-
# dev.flush()
6490-
# refresh(...)
6491-
# }
6492-
6493-
# ## Display error dialog if errors occurred
6494-
# if (errors) {
6495-
# myMsg(paste('Errors occurred while opening files. Check the R console for details.', sep = '\n'), icon = 'error')
6496-
# }
6497-
6498-
# return(invisible(usrList))
6499-
# }
6500-
#######################################################################################
65016167
handleFoErrors <- function(cond, fileName = NULL, logFile = "fo_error_log.txt") {
65026168
# Set errors flag to TRUE to indicate that an error occurred
65036169
errors <<- TRUE

0 commit comments

Comments
 (0)