EuracBiomedicalResearch / VAMS_vs_intraveinous

Comparison of Volumetric Absorbtive Microsampling to venous blood sampling
0 stars 0 forks source link

Evaluate full MS1 spectrum for selected features #85

Open jorainer opened 3 years ago

jorainer commented 3 years ago

The goal is to extract for a feature the (full) MS1 spectrum at the features' (peaks') apex position:

## Define the ID of the feature.
ft <- rownames(std_res)[rowData(std_res)$name == "Cystine"]

## Restrict to files for the present analysis
data <- filterFile(data_pos, match(res_pos$mzML_file, data_pos$mzML_file),
                   keepFeatures = TRUE)

library(Spectra)
library(MsCoreUtils)
## Extract for each sample the MS1 spectrum with the retention time closest
## to the apex position of the chromatographic peak
ft_sps <- featureSpectra(data, msLevel = 1L, return.type = "Spectra",
                         features = ft, method = "closest_rt",
                         skipFilled = FALSE)

## Get a spectrum for a plasma sample
sp_plas <- ft_sps[pData(data)$source[ft_sps$fromFile] == "plasma"][1L]

## Get a spectrum for a capillary sample
sp_cap <- ft_sps[pData(data)$source[ft_sps$fromFile] == "capillary"][1L]

## Plot labeling peaks with intensity > 2000 with their m/z
label_fun <- function(x) {
    ints <- unlist(intensity(x))
    mzs <- format(unlist(mz(x)), digits = 4)
    mzs[ints < 2000] <- ""
    mzs
}
par(mfrow = c(1, 2))
plotSpectra(sp_plas, labels = label_fun, labelPos = 4, labelOffset = 0.2,
            labelSrt = 30)
grid()
abline(v = rowData(std_res)[ft, "mzmed"], lty = 3, col = "#ff000060", lwd = 2)
plotSpectra(sp_cap, labels = label_fun, labelPos = 4, labelOffset = 0.2,
            labelSrt = 30)
grid()
abline(v = rowData(std_res)[ft, "mzmed"], lty = 3, col = "#ff000060", lwd = 2)
Cystine-mz

Left is for a plasma sample, right for a capillary sample. In addition, I just created the same plot labeling peaks which m/z would match an adduct of Cystine (just to cross-check that not a differet ion would be created in capillary samples.

## Highlighting all adducts of Cystine.
monomass <- std_info[std_info$name == "Cystine", "mzneut"]
adduct_mz <- sort(mass2mz(monomass, adduct = adductNames("pos"))[1, ])

adduct_fun <- function(x) {
    is_adduct <- closest(unlist(mz(x)), adduct_mz, ppm = 20, tolerance = 0)
    lbls <- names(adduct_mz)[is_adduct]
    lbls[is.na(lbls)] <- ""
    lbls
}
par(mfrow = c(1, 2))
plotSpectra(sp_plas, labels = adduct_fun, labelPos = 4, labelOffset = 0.2,
            labelSrt = 30)
grid()
abline(v = rowData(std_res)[ft, "mzmed"], lty = 3, col = "#ff000060", lwd = 2)
plotSpectra(sp_cap, labels = adduct_fun, labelPos = 4, labelOffset = 0.2,
            labelSrt = 30)
grid()
abline(v = rowData(std_res)[ft, "mzmed"], lty = 3, col = "#ff000060", lwd = 2)
Cystine-adduct
jorainer commented 3 years ago

Instead of looking at individual samples we could also aggregate MS1 spectra per sample source:

ft_sps$source <- pData(data)$source[ft_sps$fromFile]

## Combine spectra per source, keeping only peaks present in 50%
ft_sps_agg <- combineSpectra(ft_sps, f = ft_sps$source, p = ft_sps$source,
                             peaks = "intersect", minProp = 0.2, ppm = 10,
                             intensityFun = median, mzFun = median)

par(mfrow = c(2, 3))
mze <- rowData(std_res)[ft, "mzmed"]
plotSpectra(ft_sps_agg[1])
legend("topright", legend = ft_sps_agg$source[1])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)

plotSpectra(ft_sps_agg[2])
legend("topright", legend = ft_sps_agg$source[2])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)

plotSpectra(ft_sps_agg[3])
legend("topright", legend = ft_sps_agg$source[3])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)

tmp <- filterMzRange(ft_sps_agg, mz = mze + c(-50, 50))
plotSpectra(tmp[1])
legend("topright", legend = tmp$source[1])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)
plotSpectra(tmp[2])
legend("topright", legend = tmp$source[2])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)
plotSpectra(tmp[3])
legend("topright", legend = tmp$source[3])
grid()
abline(v = mze, lty = 3, col = "#ff000060", lwd = 2)