rietho / IPO

A Tool for automated Optimization of XCMS Parameters
http://bioconductor.org/packages/IPO/
Other
34 stars 20 forks source link

Error when plotting #53

Closed sneumann closed 6 years ago

sneumann commented 6 years ago

Hi,

when running the code from the vignette on own files, and changing to centWave/loess:

peakpickingParameters <- getDefaultXcmsSetStartingParams('centWave')

time.xcmsSet <- system.time({ # measuring time
  resultPeakpicking <- optimizeXcmsSet(files = files, 
                    params = peakpickingParameters, 
                    nSlaves = nSlaves, 
                    subdir = NULL,
                    plot = TRUE)
})

optimizedXcmsSetObject <- resultPeakpicking$best_settings$xset

retcorGroupParameters <- getDefaultRetGroupStartingParams(retcorMethod="loess")
time.RetGroup <- system.time({ # measuring time
  resultRetcorGroup <- optimizeRetGroup(xset = optimizedXcmsSetObject, 
                     params = retcorGroupParameters, 
                     nSlaves = 1, 
                     subdir = NULL,
                     plot = TRUE)
})

I get an error in the DoE plotting:

Error in plot.new() : figure margins too large

12.     plot.new()
11.     plot.default(xlim, ylim, xlim = xlim, ylim = ylim, type = "n", 
        xaxs = xaxs, yaxs = yaxs, xlab = xlab, ylab = ylab, ...)
10.     plot(xlim, ylim, xlim = xlim, ylim = ylim, type = "n", xaxs = xaxs, 
        yaxs = yaxs, xlab = xlab, ylab = ylab, ...) 
9.      image.default(x = c(1, 1.08, 1.16, 1.24, 1.32, 1.4, 1.48, 1.56, 
        1.64, 1.72, 1.8, 1.88, 1.96, 2.04, 2.12, 2.2, 2.28, 2.36, 2.44, 
        2.52, 2.6, 2.68, 2.76, 2.84, 2.92, 3), y = c(1, 1.08, 1.16, 1.24, 
        1.32, 1.4, 1.48, 1.56, 1.64, 1.72, 1.8, 1.88, 1.96, 2.04, 2.12,  ... 
8.      image(x = c(1, 1.08, 1.16, 1.24, 1.32, 1.4, 1.48, 1.56, 1.64, 
        1.72, 1.8, 1.88, 1.96, 2.04, 2.12, 2.2, 2.28, 2.36, 2.44, 2.52, 
        2.6, 2.68, 2.76, 2.84, 2.92, 3), y = c(1, 1.08, 1.16, 1.24, 1.32, 
        1.4, 1.48, 1.56, 1.64, 1.72, 1.8, 1.88, 1.96, 2.04, 2.12, 2.2,  ...
7.      do.call("image", args)
6.      contour.lm(model, plots, image = TRUE, at = maximum_slice)
5.      contour(model, plots, image = TRUE, at = maximum_slice)
4.      plotContours(model = retcor_result$model, maximum_slice = tmp, 
        plot_name = NULL)
3.      retGroupExperimentStatistic(retcor_result = retcor_result, subdir = subdir, 
        plot = plot, iterator = iterator, xset = xset)
2.      optimizeRetGroup(xset = optimizedXcmsSetObject, params = retcorGroupParameters, 
        nSlaves = 1, subdir = NULL, plot = TRUE) 
1.      system.time({
        resultRetcorGroup <- optimizeRetGroup(xset = optimizedXcmsSetObject, 
                params = retcorGroupParameters, nSlaves = 1, subdir = NULL, 
                plot = TRUE) ...

Yours, Steffen

sneumann commented 6 years ago

Running with plot = FALSE worked fine. Can I help debugging the above figure margins too large ? Ideas what I should check ? Yours, Steffen.

rietho commented 6 years ago

Hi,

Thanks for reporting. I can't say much about this error yet. I'd guess that the jpeg size is too small, but I can't say why, as IPO tries to make the device as large as needed.

Thanks for your offer to help. You could look at the plotContours-function and with the respective values of model and maximum_slice to see what makes it fail. It would also be interesting to see what happens if plot_name is NULL. I'll have a look as well.

rietho commented 6 years ago

Ok, I just saw that you're using subdir = NULL, which results in plot_name = NULL. So maybe it's because your graphic device (e.g. Rstudio plot window) is too small. Does the error also occur when you set subdir to a subdirectory?

sneumann commented 6 years ago

worked nicely with plotting and a subdirectory. So maybe double checking plot==TRUE & !is.null(subdir) would help. Yours, Steffen

rietho commented 6 years ago

Thanks for the reply. I could reproduce the error now. The error happens in your example, as you are optimizing 6 parameters, which results in a plot of 6 choose 2 = 15 plots in a single graphic device. If subdir is NULL, IPO tries to plot to the standard graphics device. So it might happen, that your graphics device is too small to hold all these plots, which is not controllable by IPO.

I'll fix this by catching potential errors, because of course IPO should not crash in this case.

A potential new feature to further address this error is a plot function to make it possible for the user to (re)generate the plots after the calculations are done. This should be possible, as the results hold all necessary information. I'll add it to my list of potential new features.

For now for all interested people, here's a sample code to generate the plots manually based on your example:

# needed functions from utils.R
# - getMaximumLevels
# - expand.grid.subset
# - getMaxSettings
# - plotContours
step <- 1 # DoE step to plot
model <- resultRetcorGroup[[step]]$model
max_settings <- getMaximumLevels(model)
maximum_slice <- max_settings[1,-1]
plotContours(model = model, maximum_slice = maximum_slice, plot_name = NULL)