xcms
xcms copied to clipboard
ERROR: Dimensions of profile matrices do not match !
I met this ERROR when proccessing my data.
my code:
f.in <- list.files(getwd(), pattern = '\\.(mz[X]{0,1}ML|cdf)', recursive = TRUE)
xset <- xcms::xcmsSet(f.in, method = "centWave", ppm = 15,
snthr = 10, peakwidth = c(5, 40), mzdiff = 0.01,
BPPARAM = bpparam())
save(list = c('xset'), file = paste(getwd(), '/xset.RData', sep = ''))
##retention time correction
pdf('rector-obiwarp.pdf')
xsetc <- xcms::retcor(xset, method = "obiwarp", plottype = "deviation",
profStep = 0.1)
dev.off()
save(list = c('xsetc'), file = paste(getwd(), '/xsetc.RData', sep=""))
rm('xset')
invisible(gc())
my seesionInfo : R version 4.3.0 (2023-04-21 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8 LC_CTYPE=Chinese (Simplified)_China.utf8
[3] LC_MONETARY=Chinese (Simplified)_China.utf8 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8
time zone: Asia/Hong_Kong tzcode source: internal
attached base packages: [1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] xcms_3.22.0 MSnbase_2.26.0 ProtGenerics_1.32.0 S4Vectors_0.38.1 mzR_2.34.0 Rcpp_1.0.10
[7] Biobase_2.60.0 BiocGenerics_0.46.0 BiocParallel_1.34.2
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.30.1 gtable_0.3.3 impute_1.74.1 ggplot2_3.4.2
[5] lattice_0.21-8 vctrs_0.6.2 tools_4.3.0 bitops_1.0-7
[9] generics_0.1.3 MassSpecWavelet_1.66.0 parallel_4.3.0 tibble_3.2.1
[13] fansi_1.0.4 vsn_3.68.0 DEoptimR_1.0-13 cluster_2.1.4
[17] pkgconfig_2.0.3 Matrix_1.5-4.1 RColorBrewer_1.1-3 lifecycle_1.0.3
[21] GenomeInfoDbData_1.2.10 compiler_4.3.0 munsell_0.5.0 codetools_0.2-19
[25] ncdf4_1.21 clue_0.3-64 GenomeInfoDb_1.36.0 snow_0.4-4
[29] RCurl_1.98-1.12 preprocessCore_1.62.1 pillar_1.9.0 crayon_1.5.2
[33] MASS_7.3-60 limma_3.56.1 affy_1.78.0 DelayedArray_0.26.3
[37] iterators_1.0.14 foreach_1.5.2 MALDIquant_1.22.1 robustbase_0.95-1
[41] pcaMethods_1.92.0 digest_0.6.31 tidyselect_1.2.0 dplyr_1.1.2
[45] splines_4.3.0 grid_4.3.0 colorspace_2.1-0 cli_3.6.1
[49] magrittr_2.0.3 S4Arrays_1.0.4 XML_3.99-0.14 survival_3.5-5
[53] utf8_1.2.3 scales_1.2.1 XVector_0.40.0 affyio_1.70.0
[57] matrixStats_0.63.0 mzID_1.38.0 multtest_2.56.0 RANN_2.6.1
[61] MsFeatures_1.8.0 GenomicRanges_1.52.0 IRanges_2.34.0 doParallel_1.0.17
[65] rlang_1.1.1 glue_1.6.2 BiocManager_1.30.20 rstudioapi_0.14
[69] R6_2.5.1 plyr_1.8.8 MatrixGenerics_1.12.0 zlibbioc_1.46.0
[73] MsCoreUtils_1.12.0
I've read the source code of XCMS 3.22.0, and i think the problem starts from line 2334 in methods-xcmsRaw.R.
The function profMat
:
setMethod("profMat", signature(object = "xcmsRaw"), function(object, method,
step,
baselevel,
basespace,
mzrange.) {
## Call the .createProfileMatrix if the internal profile matrix is empty or
## if the settings differ from the internal settings.
pi <- profinfo(object)
if (missing(method))
method <- pi$method
if (missing(step))
step <- pi$step
if (missing(baselevel))
baselevel <- pi$baselevel
if (missing(basespace))
basespace <- pi$basespace
if (length(object@env$profile) > 0) {
## Check if the settings are the same...
have_method <- pi$method
have_step <- pi$step
have_basespace <- pi$basespace
have_baselevel <- pi$baselevel
if (!is.character(all.equal(list(method, step, basespace, baselevel),
list(have_method, have_step,
have_basespace, have_baselevel)))) {
return(object@env$profile)
}
}
if (missing(mzrange.)) {
mzrange. <- NULL
} else {
if (length(mzrange.) != 2 | !is.numeric(mzrange.))
stop("If provided, 'mzrange.' has to be a numeric of length 2!")
}
## Calculate the profile matrix
if (step <= 0)
stop("Can not calculate a profile matrix with step=",step, "! Either",
" provide a positive number with argument 'step' or use the",
" 'profStep' method to set the step parameter for the xcmsSet.")
message("Create profile matrix with method '", method,
"' and step ", step, " ... ", appendLF = FALSE)
res <- .createProfileMatrix(mz = object@env$mz, int = object@env$intensity,
valsPerSpect = diff(c(object@scanindex,
length(object@env$mz))),
method = method, step = step,
baselevel = baselevel, basespace = basespace,
mzrange. = mzrange.)
message("OK")
res
})
I think it is not correct to copy object@env$profile
when the settings are the same because in methods-xcmsSet.R, the function retcor.obiwarp
may change object@env$profile
when running. This will cause the ERROR I met because profStepPad(obj1) <- profStep
in line 912 in methods-xcmsSet.R will get the wrong answer if object@env$profile
changes in the last loop.
Now, I try to add obj1@env$profile = NULL
before starting the next loop (then the function profMat
will re-calculate the profile matrix) to aviod this ERROR.
Note that the code you are looking at and debugging is no longer maintained. This belongs to the deprecated (old) functions and object (xcmsSet
, xcmsRaw
etc). Please use the new functions and objects introduced with xcms version 3.