GCRMA not working inside tryCatch block in R
2
0
Entering edit mode
@perdedorium-15654
Last seen 6.1 years ago
Houston, TX

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(
    { 
      ReadAffy()
    }, 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.)

gcrma simpleaffy error handling trycatch • 1.3k views
ADD COMMENT
2
Entering edit mode
@martin-morgan-1513
Last seen 3 months ago
United States

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
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode
@james-w-macdonald-5106
Last seen 15 minutes ago
United States

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

ADD COMMENT

Login before adding your answer.

Traffic: 797 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6