sneumann / xcms

This is the git repository matching the Bioconductor package xcms: LC/MS and GC/MS Data Analysis
Other
184 stars 80 forks source link

'Error in names(res) <- nms' during obiwarp #312

Closed cdinter closed 5 years ago

cdinter commented 6 years ago

Hallo again, I have encountered an error during obiwarp that has me stumped.

First the code I am using:

require(xcms)

workdir  <-  "experiments/08302018_ZIC-cHILIC_Spike2/AS"
cent1dir  <-  "data/08292018_ZIC-cHILIC_Spike2/AS/cent/10"
cent2dir  <-  "data/08292018_ZIC-cHILIC_Spike2/AS/cent/100"

cent1files  <-  dir(
  path = cent1dir,
  pattern = ".mzML",
  recursive = FALSE,
  include.dirs = TRUE)

cent1files  <-  paste(
  cent1dir,
  cent1files,
  sep = "/")

cent2files  <-  dir(
  path = cent2dir,
  pattern = ".mzML",
  recursive = FALSE,
  include.dirs = TRUE)

cent2files  <-  paste(
  cent2dir,
  cent2files,
  sep = "/")

pd  <-  data.frame(sample_names = sub(basename(c(cent1files, cent2files)),
                                      pattern = ".mzML", replacement = "",
                                      fixed = TRUE),
                   sample_group = c(rep(basename(cent1dir), 4),
                                    rep(basename(cent2dir), 4)),
                   stringsAsFactors = FALSE)

rawData  <-  readMSData(files = c(cent1files, cent2files),
                        pdata = new("NAnnotatedDataFrame", pd),
                        mode = "onDisk", centroided. = TRUE, msLevel. = 1)

cwp  <-  CentWaveParam(peakwidth = c(10, 210),
                       snthresh = 5,
                       prefilter = c(3, 10),
                       mzdiff = 0.01)
chromData  <-  findChromPeaks(rawData, param = cwp)

owp  <-  ObiwarpParam(center = 4)
adjData  <-  adjustRtime(chromData, param = owp)

During the first alignment I get the following error:

Error in names(res) <- nms 'names' attribute [7] must be the same length as the vector [3]

In xcms itself I could not even find a line which reads names(res) <- nms. So I checked out msnbase and there is indeed a function called 'commonFeatureNames' which has the specified line. But this function is nowhere called in msnbase or xcms. I hope you can help.

Thank you very much again.

sessionInfo() R version 3.5.1 (2018-07-02) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.5 LTS

Matrix products: default BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0 LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] parallel stats graphics grDevices utils datasets methods
[8] base

other attached packages: [1] xcms_3.3.3 MSnbase_2.6.2 ProtGenerics_1.12.0 [4] mzR_2.14.0 Rcpp_0.12.18 BiocParallel_1.14.2 [7] Biobase_2.40.0 BiocGenerics_0.26.0

loaded via a namespace (and not attached): [1] RColorBrewer_1.1-2 DEoptimR_1.0-8 pillar_1.3.0
[4] compiler_3.5.1 BiocInstaller_1.30.0 plyr_1.8.4
[7] iterators_1.0.10 zlibbioc_1.26.0 MALDIquant_1.18
[10] digest_0.6.15 preprocessCore_1.42.0 tibble_1.4.2
[13] gtable_0.2.0 lattice_0.20-35 rlang_0.2.1
[16] Matrix_1.2-14 foreach_1.4.4 S4Vectors_0.18.3
[19] IRanges_2.14.10 multtest_2.36.0 stats4_3.5.1
[22] grid_3.5.1 robustbase_0.93-2 impute_1.54.0
[25] survival_2.42-6 XML_3.98-1.15 RANN_2.6
[28] limma_3.36.2 ggplot2_3.0.0 splines_3.5.1
[31] scales_1.0.0 pcaMethods_1.72.0 codetools_0.2-15
[34] MASS_7.3-50 MassSpecWavelet_1.46.0 mzID_1.18.0
[37] colorspace_1.3-2 affy_1.58.0 lazyeval_0.2.1
[40] munsell_0.5.0 doParallel_1.0.11 vsn_3.48.1
[43] crayon_1.3.4 affyio_1.50.0

jorainer commented 6 years ago

This is indeed an interesting error. Can you please call traceback() after you get the error?

cdinter commented 6 years ago

Sry for the late answer.

After the described error message there is also a warning.

In addition: Warning message: stop worker failed: 'clear_cluster' receive data failed: reached elapsed time limit

I don't know if this might effect the traceback, but here is the traceback after the error and warning.

11: bplapply(X, FUN, ..., BPREDO = BPREDO, BPPARAM = BPPARAM) 10: bplapply(X, FUN, ..., BPREDO = BPREDO, BPPARAM = BPPARAM) 9: bplapply(objL, function(z, cntr, cntrPr, parms) { message("Aligning ", basename(fileNames(z)), " against ", basename(fileNames(cntr)), " ... ", appendLF = FALSE) suppressMessages(curP <- profMat(z, method = "bin", step = binSize(parms), returnBreaks = TRUE)[[1]]) scantime1 <- unname(rtime(cntr)) scantime2 <- unname(rtime(z)) mstdiff <- median(c(diff(scantime1), diff(scantime2))) mst1 <- which(diff(scantime1) > 5 mstdiff)[1] if (!is.na(mst1)) { scantime1 <- scantime1[seq_len((mst1 - 1))] message("Found gaps in scan times of the center sample: cut ", "scantime-vector at ", scantime1[mst1], " seconds.") } mst2 <- which(diff(scantime2) > 5 mstdiff)[1] if (!is.na(mst2)) { scantime2 <- scantime2[seq_len((mst2 - 1))] message("Found gaps in scan time of file ", basename(fileNames(z)), ": cut scantime-vector at ", scantime2[mst2], " seconds.") } rtmaxdiff <- abs(diff(c(scantime1[length(scantime1)], scantime2[length(scantime2)]))) if (rtmaxdiff > (5 mstdiff)) { rtmax <- min(scantime1[length(scantime1)], scantime2[length(scantime2)]) scantime1 <- scantime1[scantime1 <= rtmax] scantime2 <- scantime2[scantime2 <= rtmax] } valscantime1 <- length(scantime1) valscantime2 <- length(scantime2) if (ncol(cntrPr$profMat) > valscantime1) { cntrPr$profMat <- cntrPr$profMat[, -c((valscantime1 + 1):ncol(cntrPr$profMat))] } if (ncol(curP$profMat) > valscantime2) { curP$profMat <- curP$profMat[, -c((valscantime2 + 1):ncol(curP$profMat))] } mzr1 <- c(cntrPr$breaks[1], cntrPr$breaks[length(cntrPr$breaks) - 1]) mzr2 <- c(curP$breaks[1], curP$breaks[length(curP$breaks) - 1]) mzmin <- min(c(mzr1[1], mzr2[1])) mzmax <- max(c(mzr1[2], mzr2[2])) mzs <- seq(mzmin, mzmax, by = binSize(parms)) if (mzmin < mzr1[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr1[1], binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(tmp, cntrPr$profMat) } if (mzmax > mzr1[2]) { tmp <- matrix(0, (length(seq(mzr1[2], mzmax, binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(cntrPr$profMat, tmp) } if (mzmin < mzr2[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr2[1], binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(tmp, curP$profMat) } if (mzmax > mzr2[2]) { tmp <- matrix(0, (length(seq(mzr2[2], mzmax, binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(curP$profMat, tmp) } mzvals <- length(mzs) cntrVals <- length(cntrPr$profMat) curVals <- length(curP$profMat) if ((mzvals valscantime1) != cntrVals | (mzvals valscantime2) != curVals) stop("Dimensions of profile matrices of files ", basename(fileNames(cntr)), " and ", basename(fileNames(z)), " do not match!") rtadj <- .Call("R_set_from_xcms", valscantime1, scantime1, mzvals, mzs, cntrPr$profMat, valscantime2, scantime2, mzvals, mzs, curP$profMat, response(parms), distFun(parms), gapInit(parms), gapExtend(parms), factorDiag(parms), factorGap(parms), as.numeric(localAlignment(parms)), initPenalty(parms)) if (length(rtime(z)) > valscantime2) { rtadj <- c(rtadj, rtime(z)[(valscantime2 + 1):length(rtime(z))]) warning(basename(fileNames(z)), " :could only align up to a ", "retention time of ", rtime(z)[valscantime2], " seconds. ", "After that raw retention times are reported.") } message("OK") return(rtadj) }, cntr = centerObject, cntrPr = profCtr, parms = param) 8: bplapply(objL, function(z, cntr, cntrPr, parms) { message("Aligning ", basename(fileNames(z)), " against ", basename(fileNames(cntr)), " ... ", appendLF = FALSE) suppressMessages(curP <- profMat(z, method = "bin", step = binSize(parms), returnBreaks = TRUE)[[1]]) scantime1 <- unname(rtime(cntr)) scantime2 <- unname(rtime(z)) mstdiff <- median(c(diff(scantime1), diff(scantime2))) mst1 <- which(diff(scantime1) > 5 mstdiff)[1] if (!is.na(mst1)) { scantime1 <- scantime1[seq_len((mst1 - 1))] message("Found gaps in scan times of the center sample: cut ", "scantime-vector at ", scantime1[mst1], " seconds.") } mst2 <- which(diff(scantime2) > 5 mstdiff)[1] if (!is.na(mst2)) { scantime2 <- scantime2[seq_len((mst2 - 1))] message("Found gaps in scan time of file ", basename(fileNames(z)), ": cut scantime-vector at ", scantime2[mst2], " seconds.") } rtmaxdiff <- abs(diff(c(scantime1[length(scantime1)], scantime2[length(scantime2)]))) if (rtmaxdiff > (5 mstdiff)) { rtmax <- min(scantime1[length(scantime1)], scantime2[length(scantime2)]) scantime1 <- scantime1[scantime1 <= rtmax] scantime2 <- scantime2[scantime2 <= rtmax] } valscantime1 <- length(scantime1) valscantime2 <- length(scantime2) if (ncol(cntrPr$profMat) > valscantime1) { cntrPr$profMat <- cntrPr$profMat[, -c((valscantime1 + 1):ncol(cntrPr$profMat))] } if (ncol(curP$profMat) > valscantime2) { curP$profMat <- curP$profMat[, -c((valscantime2 + 1):ncol(curP$profMat))] } mzr1 <- c(cntrPr$breaks[1], cntrPr$breaks[length(cntrPr$breaks) - 1]) mzr2 <- c(curP$breaks[1], curP$breaks[length(curP$breaks) - 1]) mzmin <- min(c(mzr1[1], mzr2[1])) mzmax <- max(c(mzr1[2], mzr2[2])) mzs <- seq(mzmin, mzmax, by = binSize(parms)) if (mzmin < mzr1[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr1[1], binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(tmp, cntrPr$profMat) } if (mzmax > mzr1[2]) { tmp <- matrix(0, (length(seq(mzr1[2], mzmax, binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(cntrPr$profMat, tmp) } if (mzmin < mzr2[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr2[1], binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(tmp, curP$profMat) } if (mzmax > mzr2[2]) { tmp <- matrix(0, (length(seq(mzr2[2], mzmax, binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(curP$profMat, tmp) } mzvals <- length(mzs) cntrVals <- length(cntrPr$profMat) curVals <- length(curP$profMat) if ((mzvals valscantime1) != cntrVals | (mzvals valscantime2) != curVals) stop("Dimensions of profile matrices of files ", basename(fileNames(cntr)), " and ", basename(fileNames(z)), " do not match!") rtadj <- .Call("R_set_from_xcms", valscantime1, scantime1, mzvals, mzs, cntrPr$profMat, valscantime2, scantime2, mzvals, mzs, curP$profMat, response(parms), distFun(parms), gapInit(parms), gapExtend(parms), factorDiag(parms), factorGap(parms), as.numeric(localAlignment(parms)), initPenalty(parms)) if (length(rtime(z)) > valscantime2) { rtadj <- c(rtadj, rtime(z)[(valscantime2 + 1):length(rtime(z))]) warning(basename(fileNames(z)), " :could only align up to a ", "retention time of ", rtime(z)[valscantime2], " seconds. ", "After that raw retention times are reported.") } message("OK") return(rtadj) }, cntr = centerObject, cntrPr = profCtr, parms = param) 7: xcms:::.obiwarp(object_sub, param = param) 6: .local(object, param, ...) 5: adjustRtime(as(object, "OnDiskMSnExp"), param = param, msLevel = msLevel) 4: adjustRtime(as(object, "OnDiskMSnExp"), param = param, msLevel = msLevel) 3: .local(object, param, ...) 2: adjustRtime(chromData, param = owp) 1: adjustRtime(chromData, param = owp)

cdinter commented 6 years ago

Hey I just changed changed the end of my code to:

register(SerialParam())
adjData  <-  adjustRtime(chromData, param = owp)

The output I receive is:

Sample number 4 used as center sample. Aligning 50 mul 10 muM AS Std Mix + 50 mul C. glut U-13C ISTD_0.mzML against 50 mul 10 muM AS Std Mix + 50 mul C. glut U-13C ISTD_3.mzML ... OK Aligning 50 mul 10 muM AS Std Mix + 50 mul C. glut U-13C ISTD_1.mzML against 50 mul 10 muM AS Std Mix + 50 mul C. glut U-13C ISTD_3.mzML ... Error in binYonX(mz, int, breaks = brks, fromIdx = fromIdx, toIdx = toIdx, : 'fromIdx' and 'toIdx' have to be >= 0!

Now the first alignment works, but in the second alignment I receive a different error message. Here is the traceback to this error:

19: stop(e) 18: value[3L] 17: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 16: tryCatchList(expr, classes, parentenv, handlers) 15: tryCatch({ FUN(...) }, error = handle_error) 14: withCallingHandlers({ tryCatch({ FUN(...) }, error = handle_error) }, warning = handle_warning) 13: FUN(X[[i]], ...) 12: lapply(X, FUN, ...) 11: bplapply(X, FUN, ..., BPREDO = BPREDO, BPPARAM = BPPARAM) 10: bplapply(X, FUN, ..., BPREDO = BPREDO, BPPARAM = BPPARAM) 9: bplapply(objL, function(z, cntr, cntrPr, parms) { message("Aligning ", basename(fileNames(z)), " against ", basename(fileNames(cntr)), " ... ", appendLF = FALSE) suppressMessages(curP <- profMat(z, method = "bin", step = binSize(parms), returnBreaks = TRUE)[[1]]) scantime1 <- unname(rtime(cntr)) scantime2 <- unname(rtime(z)) mstdiff <- median(c(diff(scantime1), diff(scantime2))) mst1 <- which(diff(scantime1) > 5 mstdiff)[1] if (!is.na(mst1)) { scantime1 <- scantime1[seq_len((mst1 - 1))] message("Found gaps in scan times of the center sample: cut ", "scantime-vector at ", scantime1[mst1], " seconds.") } mst2 <- which(diff(scantime2) > 5 mstdiff)[1] if (!is.na(mst2)) { scantime2 <- scantime2[seq_len((mst2 - 1))] message("Found gaps in scan time of file ", basename(fileNames(z)), ": cut scantime-vector at ", scantime2[mst2], " seconds.") } rtmaxdiff <- abs(diff(c(scantime1[length(scantime1)], scantime2[length(scantime2)]))) if (rtmaxdiff > (5 mstdiff)) { rtmax <- min(scantime1[length(scantime1)], scantime2[length(scantime2)]) scantime1 <- scantime1[scantime1 <= rtmax] scantime2 <- scantime2[scantime2 <= rtmax] } valscantime1 <- length(scantime1) valscantime2 <- length(scantime2) if (ncol(cntrPr$profMat) > valscantime1) { cntrPr$profMat <- cntrPr$profMat[, -c((valscantime1 + 1):ncol(cntrPr$profMat))] } if (ncol(curP$profMat) > valscantime2) { curP$profMat <- curP$profMat[, -c((valscantime2 + 1):ncol(curP$profMat))] } mzr1 <- c(cntrPr$breaks[1], cntrPr$breaks[length(cntrPr$breaks) - 1]) mzr2 <- c(curP$breaks[1], curP$breaks[length(curP$breaks) - 1]) mzmin <- min(c(mzr1[1], mzr2[1])) mzmax <- max(c(mzr1[2], mzr2[2])) mzs <- seq(mzmin, mzmax, by = binSize(parms)) if (mzmin < mzr1[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr1[1], binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(tmp, cntrPr$profMat) } if (mzmax > mzr1[2]) { tmp <- matrix(0, (length(seq(mzr1[2], mzmax, binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(cntrPr$profMat, tmp) } if (mzmin < mzr2[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr2[1], binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(tmp, curP$profMat) } if (mzmax > mzr2[2]) { tmp <- matrix(0, (length(seq(mzr2[2], mzmax, binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(curP$profMat, tmp) } mzvals <- length(mzs) cntrVals <- length(cntrPr$profMat) curVals <- length(curP$profMat) if ((mzvals valscantime1) != cntrVals | (mzvals valscantime2) != curVals) stop("Dimensions of profile matrices of files ", basename(fileNames(cntr)), " and ", basename(fileNames(z)), " do not match!") rtadj <- .Call("R_set_from_xcms", valscantime1, scantime1, mzvals, mzs, cntrPr$profMat, valscantime2, scantime2, mzvals, mzs, curP$profMat, response(parms), distFun(parms), gapInit(parms), gapExtend(parms), factorDiag(parms), factorGap(parms), as.numeric(localAlignment(parms)), initPenalty(parms)) if (length(rtime(z)) > valscantime2) { rtadj <- c(rtadj, rtime(z)[(valscantime2 + 1):length(rtime(z))]) warning(basename(fileNames(z)), " :could only align up to a ", "retention time of ", rtime(z)[valscantime2], " seconds. ", "After that raw retention times are reported.") } message("OK") return(rtadj) }, cntr = centerObject, cntrPr = profCtr, parms = param) 8: bplapply(objL, function(z, cntr, cntrPr, parms) { message("Aligning ", basename(fileNames(z)), " against ", basename(fileNames(cntr)), " ... ", appendLF = FALSE) suppressMessages(curP <- profMat(z, method = "bin", step = binSize(parms), returnBreaks = TRUE)[[1]]) scantime1 <- unname(rtime(cntr)) scantime2 <- unname(rtime(z)) mstdiff <- median(c(diff(scantime1), diff(scantime2))) mst1 <- which(diff(scantime1) > 5 mstdiff)[1] if (!is.na(mst1)) { scantime1 <- scantime1[seq_len((mst1 - 1))] message("Found gaps in scan times of the center sample: cut ", "scantime-vector at ", scantime1[mst1], " seconds.") } mst2 <- which(diff(scantime2) > 5 mstdiff)[1] if (!is.na(mst2)) { scantime2 <- scantime2[seq_len((mst2 - 1))] message("Found gaps in scan time of file ", basename(fileNames(z)), ": cut scantime-vector at ", scantime2[mst2], " seconds.") } rtmaxdiff <- abs(diff(c(scantime1[length(scantime1)], scantime2[length(scantime2)]))) if (rtmaxdiff > (5 mstdiff)) { rtmax <- min(scantime1[length(scantime1)], scantime2[length(scantime2)]) scantime1 <- scantime1[scantime1 <= rtmax] scantime2 <- scantime2[scantime2 <= rtmax] } valscantime1 <- length(scantime1) valscantime2 <- length(scantime2) if (ncol(cntrPr$profMat) > valscantime1) { cntrPr$profMat <- cntrPr$profMat[, -c((valscantime1 + 1):ncol(cntrPr$profMat))] } if (ncol(curP$profMat) > valscantime2) { curP$profMat <- curP$profMat[, -c((valscantime2 + 1):ncol(curP$profMat))] } mzr1 <- c(cntrPr$breaks[1], cntrPr$breaks[length(cntrPr$breaks) - 1]) mzr2 <- c(curP$breaks[1], curP$breaks[length(curP$breaks) - 1]) mzmin <- min(c(mzr1[1], mzr2[1])) mzmax <- max(c(mzr1[2], mzr2[2])) mzs <- seq(mzmin, mzmax, by = binSize(parms)) if (mzmin < mzr1[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr1[1], binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(tmp, cntrPr$profMat) } if (mzmax > mzr1[2]) { tmp <- matrix(0, (length(seq(mzr1[2], mzmax, binSize(parms))) - 1), ncol = ncol(cntrPr$profMat)) cntrPr$profMat <- rbind(cntrPr$profMat, tmp) } if (mzmin < mzr2[1]) { tmp <- matrix(0, (length(seq(mzmin, mzr2[1], binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(tmp, curP$profMat) } if (mzmax > mzr2[2]) { tmp <- matrix(0, (length(seq(mzr2[2], mzmax, binSize(parms))) - 1), ncol = ncol(curP$profMat)) curP$profMat <- rbind(curP$profMat, tmp) } mzvals <- length(mzs) cntrVals <- length(cntrPr$profMat) curVals <- length(curP$profMat) if ((mzvals valscantime1) != cntrVals | (mzvals valscantime2) != curVals) stop("Dimensions of profile matrices of files ", basename(fileNames(cntr)), " and ", basename(fileNames(z)), " do not match!") rtadj <- .Call("R_set_from_xcms", valscantime1, scantime1, mzvals, mzs, cntrPr$profMat, valscantime2, scantime2, mzvals, mzs, curP$profMat, response(parms), distFun(parms), gapInit(parms), gapExtend(parms), factorDiag(parms), factorGap(parms), as.numeric(localAlignment(parms)), initPenalty(parms)) if (length(rtime(z)) > valscantime2) { rtadj <- c(rtadj, rtime(z)[(valscantime2 + 1):length(rtime(z))]) warning(basename(fileNames(z)), " :could only align up to a ", "retention time of ", rtime(z)[valscantime2], " seconds. ", "After that raw retention times are reported.") } message("OK") return(rtadj) }, cntr = centerObject, cntrPr = profCtr, parms = param) 7: xcms:::.obiwarp(object_sub, param = param) 6: .local(object, param, ...) 5: adjustRtime(as(object, "OnDiskMSnExp"), param = param, msLevel = msLevel) 4: adjustRtime(as(object, "OnDiskMSnExp"), param = param, msLevel = msLevel) 3: .local(object, param, ...) 2: adjustRtime(chromData, param = owp) 1: adjustRtime(chromData, param = owp)

jorainer commented 6 years ago

What happens when you call

pm <- profMat(filterFile(chromData, 2), binSize = 1, returnBreaks = TRUE)

does this throw an error?

cdinter commented 6 years ago

Ah I was on the right track, was just reading 'profMat' and '.createProfileMatrix'.

Yes this does indeed return the same error as above, but I dont understand why. To calculate 'toIdx' and 'fromIdx' this is what happens in 'profMat'

sps <- spectra(filterFile(chromData, 2))
mzs <- lapply(sps, mz)
vps <- lengths(mzs, use.names = FALSE)

vps is then supplied to '.createProfileMatrix' as valsPerSpect, where this happens

valsPerSpect <- vps
toIdx <- cumsum(valsPerSpect)
fromIdx <- c(1L, toIdx[-length(toIdx)] + 1L)

# test if indices are empty
length(toIdx) #13041
length(fromIdx) #13041

Wild guess: My first spectrum is apparently empty and therefor toIdx[1] is 0. Is this my problem?

sps[1] $F2.S00001 Object of class "Spectrum1" Retention time: 0:0 MSn level: 1 Total ion count: 0 Polarity: 1

toIdx[1] [1] 0

jorainer commented 6 years ago

That could indeed be a problem. You could try to filter the object by retention time, using the retention time of the first non-empty spectrum as the lower boundary and try again.

cdinter commented 6 years ago

Ah thanks for the tip. Following code runs without error.

spl <- filterFile(chromData, 2)
spl <- filterRt(spl, rt = c(rtime(spl[[2]]), rtime(spl)[length(spl)]))
pm <- profMat(spl, binSize = 1, returnBreaks = TRUE)

I guess for now I will snip off empty spectra by filterRt on all my files if needed.

Idea for fix in xcms: In method 'profMat' this happens:

    sps <- spectra(z, BPPARAM = SerialParam())
    mzs <- lapply(sps, mz)
    vps <- lengths(mzs, use.names = FALSE)
    return(.createProfileMatrix(mz = unlist(mzs, use.names = FALSE),
                                int = unlist(lapply(sps, intensity),
                                             use.names = FALSE),
                                valsPerSpect = vps,
                                method = bmethod,
                                step = bstep,
                                baselevel = bbaselevel,
                                basespace = bbasespace,
                                mzrange. = bmzrange.,
                                returnBreaks = breturnBreaks)

Simply adding vps <- vps[-which(vps == 0)] should remove the empty spectras for creation of the profile matrix and fix the problem? Hestiant to just try this, because I am not sure about any conflicts with the acutal alignment step. Edit: This would obviously also remove emtpy spectras which are not at the beginning of the rtime. Not sure if this is even desirable behaviour. It should probably atleast throw a warning?

jorainer commented 6 years ago

thanks for digging into this! nice work @cdinter! I'll check whether we could use your proposed solution.

jorainer commented 6 years ago

The problem is fixed now in the master branch. I'm closing the issue now. Feel free to reopen if needed. Thanks!

cdinter commented 6 years ago

Hey I downloaded the new github version of xcms, but my problem persists. Simply applying obiwarp to my data still leads to the following error.

Error in names(res) <- nms : 'names' attribute [7] must be the same length as the vector [3]

When I use the following function on my data, then 'filterRT' with the new retention time range obiwarp runs without error.

rtNoEmpSpec  <-  function(object) {  
  newRtRange  <-  range(rtime(object))

  for (fileIdx in seq_along(fileNames(object))) {
    file  <-  filterFile(object, fileIdx)

    flag  <-  TRUE
    specIdx  <-  1
    while (flag) {
      if (length(mz(file[[specIdx]])) == 0) {
        specIdx  <-  specIdx + 1
        newRtRange[1]  <-  rtime(file[[specIdx]])
      } else {
        flag  <-  FALSE
      }
    }
  }
  return(newRtRange)
}
jorainer commented 6 years ago

Strange that the error still persists. Would it be possible for you to share one or two of the files on which obiwarp (or profMat) fails so I can check? I did manually remove signal from some spectra in order to build a unit test for this bug, but apparently there's something more...

cdinter commented 6 years ago

Hey, sry for the late answer, I had to check with my supervisor. Link: https://fz-juelich.sciebo.de/s/SCG5g2DFJs00sUh The link is valid until the first of november.

Just running this with xcms leads to the descirbed error, removing the first spectra in each file and then running obiwarp works. I tried replicating the error with just two files. One file with an empty first spectrum and 2nd one with a non-empty one. This changed the error message to something along the lines of 'profMat dimension dont fit'. (I didnt save the error message for this one though. DUH!):

jorainer commented 6 years ago

Thanks for the data! this was such an elusive bug, but now I'm pretty sure we can fix!

hhabra commented 6 years ago

Hey Johannes!

I'm having the same "'fromIdx' and 'toIdx' have to be >= 0!" issue myself. Please let me know if you end up finding a good fix for it. Thanks!

jorainer commented 6 years ago

The fix is in: it finally settles any problems related to files with empty spectra and ensures that obiwarp doesn't crash if files with different numbers of spectra are aligned.

@cdinter xcms is now sucessfully aligning the 4 test files you provided. Could you eventually also check this for other files you have?

@hhabra it should fix also the problem you report. Can you also please check?

Reminder: you would have to install the latest xcms from github and that requires R-3.5.1 and Bioconductor 3.8 (the current devel). To install, in R install first install.packages("BiocManager"), then run BiocManager::install() followed by BiocManager::install("xcms", version = "devel"). With that you should have the current development versions of MSnbase and other required packages. The you can install xcms from github: devtools::install_github("sneumann/xcms").

cdinter commented 5 years ago

Hey, is this fix included in the new xms release in bioconductor 3.8?

jorainer commented 5 years ago

Yes it is. I've just verified by aligning the 4 test files you provided with Bioconductor 3.8.

Please close the issue after verifying with your data.

cdinter commented 5 years ago

No longer throws errors. Thanks again for your help!

Farideh85 commented 4 years ago

Hi, Can someone help me? I am an amateur in coding. I am facing error in xsg2 part (below) says: Dimensions of profile matrices do not match ! when I run my samples. Among samples, there is one with a higher number of features, when I remove that one, then the code works. How can I solve it while keeping that sample as well? since that one is a pooled sample. Here are my codes:

xset <- xcmsSet (profmethod= "binlin", method="centWave", ppm = 20, peakwidth = c(3, 15 ), snthresh = 20, prefilter = c(3,1000), polarity = "negative", mzCenterFun="wMean", integrate = 2, mzdiff = 0.05, noise = 1000) xsg <- group(xset, bw = 5 , minfrac= 0.5 ) xsg2 <- retcor(xsg, method="obiwarp", plottype="deviation")

Thank you in advance