xcms
xcms copied to clipboard
Using xcms and Spectra package
Dear all, From what I understand, the connection between xcms and Spectra is made with MsExperiment objects. I'm trying to reproduce the xcmsTutorials but with fictitious data in Spectra, but I'm having difficulties when linking the linkSampleData.
Please see this minimal example:
library(xcms)
library(MsExperiment)
library(Spectra)
#' fake MS data
mz <- c(56.0494, 69.0447, 83.0603, 109.0395, 110.0712,
111.0551, 123.0429, 138.0662, 195.0876)
int <- c(0.459, 2.585, 2.446, 0.508, 8.968, 0.524, 0.974, 100.0, 40.994)
sv <- data.frame(msLevel = 1L, polarity = 1L, rtime=1)
sv <- rbind(sv, data.frame(msLevel = 1L, polarity = 1L, rtime=2))
sv <- rbind(sv, data.frame(msLevel = 1L, polarity = 1L, rtime=3))
sv$mz <- list(mz)
sv$intensity <- list(int)
sv$dataOrigin = normalizePath("abstractFile.mzML")
sps_sv <- Spectra(sv)
sps_sv
msexp <- MsExperiment()
msexp
spectra(msexp) <- sps_sv
sampleData(msexp)$raw_file <- sps_sv$dataOrigin
the error:
> sampleData(msexp)$raw_file <- sps_sv$dataOrigin
Error in `[[<-`(`*tmp*`, name, value = c("C:\\Users\\User\\testing\\abstractFile.mzML", :
3 elements in value to replace 0 elements
Is there another way to use xcms functions with Spectra data? thanks