Mercurial > repos > lecorguille > xcms_fillpeaks
annotate lib-xcms3.x.x.r @ 38:a3e80894efd3 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
| author | lecorguille | 
|---|---|
| date | Mon, 17 Sep 2018 08:46:47 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 38 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 1 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 2 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 3 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 4 # https://github.com/sneumann/xcms/issues/250 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 5 groupnamesW4M <- function(xdata, mzdec = 0, rtdec = 0) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 6 mzfmt <- paste("%.", mzdec, "f", sep = "") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 7 rtfmt <- paste("%.", rtdec, "f", sep = "") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 8 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 9 gnames <- paste("M", sprintf(mzfmt, featureDefinitions(xdata)[,"mzmed"]), "T", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 10 sprintf(rtfmt, featureDefinitions(xdata)[,"rtmed"]), sep = "") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 11 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 12 if (any(dup <- duplicated(gnames))) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 13 for (dupname in unique(gnames[dup])) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 14 dupidx <- which(gnames == dupname) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 15 gnames[dupidx] <- paste(gnames[dupidx], seq(along = dupidx), sep = "_") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 16 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 17 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 18 return (gnames) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 19 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 20 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 21 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 22 # https://github.com/sneumann/xcms/issues/247 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 23 .concatenate_XCMSnExp <- function(...) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 24 x <- list(...) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 25 if (length(x) == 0) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 26 return(NULL) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 27 if (length(x) == 1) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 28 return(x[[1]]) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 29 ## Check that all are XCMSnExp objects. | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 30 if (!all(unlist(lapply(x, function(z) is(z, "XCMSnExp"))))) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 31 stop("All passed objects should be 'XCMSnExp' objects") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 32 new_x <- as(.concatenate_OnDiskMSnExp(...), "XCMSnExp") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 33 ## If any of the XCMSnExp has alignment results or detected features drop | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 34 ## them! | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 35 x <- lapply(x, function(z) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 36 if (hasAdjustedRtime(z)) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 37 z <- dropAdjustedRtime(z) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 38 warning("Adjusted retention times found, had to drop them.") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 39 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 40 if (hasFeatures(z)) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 41 z <- dropFeatureDefinitions(z) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 42 warning("Feature definitions found, had to drop them.") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 43 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 44 z | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 45 }) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 46 ## Combine peaks | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 47 fls <- lapply(x, fileNames) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 48 startidx <- cumsum(lengths(fls)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 49 pks <- lapply(x, chromPeaks) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 50 procH <- lapply(x, processHistory) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 51 for (i in 2:length(fls)) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 52 pks[[i]][, "sample"] <- pks[[i]][, "sample"] + startidx[i - 1] | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 53 procH[[i]] <- lapply(procH[[i]], function(z) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 54 z@fileIndex <- as.integer(z@fileIndex + startidx[i - 1]) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 55 z | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 56 }) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 57 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 58 pks <- do.call(rbind, pks) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 59 new_x@.processHistory <- unlist(procH) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 60 chromPeaks(new_x) <- pks | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 61 if (validObject(new_x)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 62 new_x | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 63 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 64 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 65 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 66 # https://github.com/sneumann/xcms/issues/247 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 67 .concatenate_OnDiskMSnExp <- function(...) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 68 x <- list(...) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 69 if (length(x) == 0) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 70 return(NULL) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 71 if (length(x) == 1) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 72 return(x[[1]]) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 73 ## Check that all are XCMSnExp objects. | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 74 if (!all(unlist(lapply(x, function(z) is(z, "OnDiskMSnExp"))))) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 75 stop("All passed objects should be 'OnDiskMSnExp' objects") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 76 ## Check processingQueue | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 77 procQ <- lapply(x, function(z) z@spectraProcessingQueue) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 78 new_procQ <- procQ[[1]] | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 79 is_ok <- unlist(lapply(procQ, function(z) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 80 !is.character(all.equal(new_procQ, z)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 81 )) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 82 if (any(!is_ok)) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 83 warning("Processing queues from the submitted objects differ! ", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 84 "Dropping the processing queue.") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 85 new_procQ <- list() | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 86 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 87 ## processingData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 88 fls <- lapply(x, function(z) z@processingData@files) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 89 startidx <- cumsum(lengths(fls)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 90 ## featureData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 91 featd <- lapply(x, fData) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 92 ## Have to update the file index and the spectrum names. | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 93 for (i in 2:length(featd)) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 94 featd[[i]]$fileIdx <- featd[[i]]$fileIdx + startidx[i - 1] | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 95 rownames(featd[[i]]) <- MSnbase:::formatFileSpectrumNames( | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 96 fileIds = featd[[i]]$fileIdx, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 97 spectrumIds = featd[[i]]$spIdx, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 98 nSpectra = nrow(featd[[i]]), | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 99 nFiles = length(unlist(fls)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 100 ) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 101 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 102 featd <- do.call(rbind, featd) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 103 featd$spectrum <- 1:nrow(featd) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 104 ## experimentData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 105 expdata <- lapply(x, function(z) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 106 ed <- z@experimentData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 107 data.frame(instrumentManufacturer = ed@instrumentManufacturer, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 108 instrumentModel = ed@instrumentModel, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 109 ionSource = ed@ionSource, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 110 analyser = ed@analyser, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 111 detectorType = ed@detectorType, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 112 stringsAsFactors = FALSE) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 113 }) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 114 expdata <- do.call(rbind, expdata) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 115 expdata <- new("MIAPE", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 116 instrumentManufacturer = expdata$instrumentManufacturer, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 117 instrumentModel = expdata$instrumentModel, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 118 ionSource = expdata$ionSource, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 119 analyser = expdata$analyser, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 120 detectorType = expdata$detectorType) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 121 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 122 ## protocolData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 123 protodata <- lapply(x, function(z) z@protocolData) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 124 if (any(unlist(lapply(protodata, nrow)) > 0)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 125 warning("Found non-empty protocol data, but merging protocol data is", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 126 " currently not supported. Skipped.") | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 127 ## phenoData | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 128 pdata <- do.call(rbind, lapply(x, pData)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 129 res <- new( | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 130 "OnDiskMSnExp", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 131 phenoData = new("NAnnotatedDataFrame", data = pdata), | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 132 featureData = new("AnnotatedDataFrame", featd), | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 133 processingData = new("MSnProcess", | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 134 processing = paste0("Concatenated [", date(), "]"), | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 135 files = unlist(fls), smoothed = NA), | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 136 experimentData = expdata, | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 137 spectraProcessingQueue = new_procQ) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 138 if (validObject(res)) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 139 res | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 140 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 141 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 142 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 143 # https://github.com/sneumann/xcms/issues/247 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 144 c.XCMSnExp <- function(...) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 145 .concatenate_XCMSnExp(...) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 146 } | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 147 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 148 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 149 # https://github.com/sneumann/xcms/issues/247 | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 150 c.MSnbase <- function(...) { | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 151 .concatenate_OnDiskMSnExp(...) | 
| 
a3e80894efd3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e131bacd37bfaf2c4132fd214c81db9b8a9df513
 lecorguille parents: diff
changeset | 152 } | 
