1
HMDB / Re: Python script to process HMDB xml file
I'm sure that will be helpful for people. Plus, it was good to find your paper. I look forward to having a good read later today.
This section allows you to view all Messages made by this member. Note that you can only see Messages made in areas you currently have access to.
[url=https://github.com/sneumann/xcms/blob/557b936967271690140e19224be707d87ea63168/R/functions-XCMSnExp.R#L1804]ms2_spectra_for_all_peaks[/url]
pks <- chromPeaks(xdata)
xdata_filtered <- filterMsLevel(as(xdata, "OnDiskMSnExp"), 2L)
## Split data per file
file_factor <- factor(pks[, "sample"])
pks <- split.data.frame(pks, f = file_factor)
xdata_filtered <- lapply(as.integer(levels(file_factor)), filterFile, object = xdata_filtered)
## You then need to loop through xdata_filtered and pks for the samples you need. Each entry in xdata_filtered becomes 'x' and 'pks' is the corresponding entry in the pks list.
sps <- spectra(x)
pmz <- precursorMz(x)
rtm <- rtime(x)
[url=https://github.com/sneumann/xcms/blob/557b936967271690140e19224be707d87ea63168/R/functions-XCMSnExp.R#L1877]ms2_spectra_for_peaks_from_file[/url]
## Make sure you define all the required parameters i.e. method = 'closest_mz'
res <- vector(mode = "list", nrow(pks))
for (i in 1:nrow(pks)) {
if (is.na(pks[i, "mz"]))
next
idx <- which(pmz >= pks[i, "mzmin"] & pmz <= pks[i, "mzmax"] &
rtm >= pks[i, "rtmin"] & rtm <= pks[i, "rtmax"])
if (length(idx)) {
if (length(idx) > 1 & method != "all") {
if (method == "closest_rt")
idx <- idx[order(abs(rtm[idx] - pks[i, "rt"]))][1]
if (method == "closest_mz")
idx <- idx[order(abs(pmz[idx] - pks[i, "mz"]))][1]
if (method == "signal") {
sps_sub <- sps[idx]
ints <- vapply(sps_sub, function(z) sum(intensity(z)),
numeric(1))
idx <- idx[order(abs(ints - pks[i, "maxo"]))][1]
}
}
res[[i]] <- lapply(sps[idx], function(z) {
z@fromFile = fromFile
z
})
}
}
names(res) <- rownames(pks)