Question: GCRMA not working inside tryCatch block in R
0
5 months ago by
Houston, TX
perdedorium0 wrote:

I've written a script with a for() loop to process the raw microarray CEL files of five different GEO data sets in R, but it screws up when it gets to the GCRMA processing part. I get a "Was unable to process microarray data" message in my log file, but no error message, despite having an error block. Also, it works just fine when I don't use a tryCatch block, which makes me think it's something with the way I have my error handling set up. But I have the exact same setup for reading the CEL files into an Affybatch, and that works just fine. What am I doing wrong here?

Here's the GCRMA processing step (which is not working):

eset <- tryCatch(
{
gcrma(affy.data)
}, warning = function(w) {
# For warnings, write them to the output file.
cat(paste("Warning in GEO data set", i, "when performing GCRMA processing:", conditionMessage(w)), file=logfile, append=TRUE, sep = "\n")
}, error = function(e) {
# For errors, write them to the output file and then skip to the next data set.
cat(paste("Error in GEO data set", i, "when performing GCRMA processing", conditionMessage(e)), file=logfile, append=TRUE, sep = "\n")
return(NULL)
}
)
if(is.null(eset)) {
cat(paste("Was unable to process microarray data for GEO data set", i, ". Skipping to next data set."), file=logfile, append=TRUE, sep = "\n")
next
} else {
# If everything went all right, make a note of that in the output file.
cat(paste("Successfully processed GEO data set", i), file=logfile, append=TRUE, sep = "\n")
}


... and here's the step for reading into an Affybatch, which is:

# Read the CEL files into an Affybatch object.
affy.data <- tryCatch(
{
}, warning = function(w) {
# For warnings, write them to the output file.
cat(paste("Warning in GEO data set", i, "when reading CEL files:", conditionMessage(w)), file=logfile, append=TRUE, sep = "\n")
}, error = function(e) {
# For errors, write them to the output file and then skip to the next data set.
cat(paste("Error in GEO data set", i, "when reading CEL files:", conditionMessage(e)), file=logfile, append=TRUE, sep = "\n")
return(NULL)
}
)
if(is.null(affy.data)) {
cat(paste("Was unable to read in CEL files for GEO data set", i, ". Skipping to next data set."), file=logfile, append=TRUE, sep = "\n")
next
} else {
cat(paste("Successfully read CEL files for GEO data set", i), file=logfile, append=TRUE, sep = "\n")
}

(Btw, i is the loop variable that holds the name of the data set.)

modified 5 months ago by James W. MacDonald49k • written 5 months ago by perdedorium0
Answer: GCRMA not working inside tryCatch block in R
2
5 months ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

I didn't take a close look but using tryCatch() to catch warnings is not usually the right thing to do -- when a warning is encountered control flow goes to the handler and then to the rest of the 'top level' code, so code after the warning is never executed. Compare

> tryCatch({ warning("oops"); 1 }, warning = function(...) {}); 2
NULL
[1] 2
> withCallingHandlers({ warning("oops"); 1 }, warning = function(...) invokeRestart("muffleWarning")); 2
[1] 1
[1] 2

That did the trick! And thanks, I did not know that about tryCatch().

Answer: GCRMA not working inside tryCatch block in R
2
5 months ago by
United States
James W. MacDonald49k wrote:

You might try Martin Maechler's error catching code, from not as long ago as I remember it...