deconvolveSources: Deconvolves the mixed scans in ms2_mat returned by getMS2Mat

Description Usage Arguments Details Value Author(s) Examples

View source: R/functions.r

Description

Uses non-negative least squares to find the most likely portion of each observed mass that was contributed by each precursor in each scan

Usage

1
deconvolveSources(ms2_mat, precursors, windowOffSet = c(-1, 9), deisotope = T, intensityFilter = 0.05, cole = 20)

Arguments

ms2_mat

data.frame returned by getMS2Mat

precursors

the precursors that were targeted

windowOffSet

window offset for the instrument that gives the bounds of the isolation window. Used to define which columns could potentially be precursors.

deisotope

remove potential isotope precursors

intensityFilter

minimal relative intensity for a precursor

cole

collsiion energy that contains non0V scans

Details

Most useful parameter to tinker with is the intensityFilter

Value

sources

a matrix with a row for each source and column for each mass. Plot each row with plot_source.

Author(s)

Igor Nikolskiy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (ms2_mat, precursors, windowOffSet = c(-1, 9), deisotope = T,
    intensityFilter = 0.05, cole = 20)
{
    precMat = subset_ms2_mat(ms2_mat, prec = precursors, cole = 0)
    cols = grep("[0-9]+.[0-9]+", colnames(precMat))
    masses = as.numeric(colnames(precMat)[cols])
    possiblePrecs = min(precursors) + windowOffSet[1] < masses &
        max(precursors) + windowOffSet[2] > masses
    cols = cols[possiblePrecs]
    masses = as.numeric(colnames(precMat)[cols])
    if (deisotope) {
        isos = findIsotopeMasses(masses)
        if (any(isos))
            cols = cols[-isos]
    }
    interpolated = c()
    observations = c()
    for (xr in unique(ms2_mat$xcmsRaw)) {
        for (p in unique(ms2_mat$prec)) {
            om = subset_ms2_mat(ms2_mat, prec = p, cole = cole,
                xr = xr)
            pm = subset_ms2_mat(ms2_mat, prec = p, cole = 0,
                xr = xr)
            loc = apply(pm[, cols, drop = F], 2, function(x) {
                interpolatePrecursor(x, rownames(pm), rownames(om))
            })
            interpolated = rbind(interpolated, loc)
            observations = rbind(observations, om)
        }
    }
    cols = max(interpolated) * intensityFilter < apply(interpolated,
        2, max)
    interpolated = interpolated[, cols, drop = F]
    sources = sapply(apply(observations, 2, nnls, A = interpolated),
        function(x) x$x)
    if (!is.null(dim(sources))) {
        rownames(sources) = colnames(interpolated)
    }
    sources
  }

yufree/decoMS2 documentation built on May 27, 2019, 9:56 a.m.