Skip to main content

Compute dynamic SWATH (DIA) windows

Description

An R6 class that splits the MS1 mass range into n_bins windows with about equal numbers of precursors. The window boundaries (breaks) are computed once, when the object is created, with one of three methods:

  • “mixture” (default): the quantile breaks of the masses mixed with uniformly spread data, with the smallest share of uniform data that keeps all window widths within [min_window, max_window]; the quantile breaks themselves if they fit. The limits hold for the rounded and padded breaks. Stops if even windows of equal width violate the limits.

  • “quantile”: windows with equal numbers of masses, of any width.

  • “constant”: windows of equal width.

The breaks are rounded to digits decimals, and the outer breaks are rounded outward and padded by 1 / 10^digits, so that the windows enclose all masses.

The object cannot be changed: its fields are read-only and its methods only read them, so their results do not depend on the order in which they are called. To compare methods or settings, create one object for each. clone() copies an object.

Value

Cdsw$new() returns a Cdsw R6 object; see Methods.

Active bindings

masses
MS1 masses (read-only).
n_bins
Number of windows (read-only).
method
Method that placed the breaks (read-only).
breaks
Window boundaries, n_bins + 1 values (read-only).

Methods

Public methods


Cdsw$new()

Compute the breaks of n_bins windows over the masses with method.

Usage
Cdsw\$new(
  masses,
  n_bins = 25,
  method = c("mixture", "quantile", "constant"),
  max_window = 150,
  min_window = 5,
  digits = 2
)
Arguments
masses
MS1 masses (m/z): a numeric vector of finite values.
n_bins
Number of windows.
method
How to place the breaks: “mixture” (default), “quantile” or “constant”; see Description.
max_window, min_window
Largest and smallest window width in m/z; used by method = “mixture” only.
digits
Number of decimal places of the breaks.
Returns

A new Cdsw object.


Cdsw$print()

Print the number of masses and windows, the method and the range of window widths.

Usage
Cdsw\$print(...)
Arguments
…
Not used.
Returns

The object, invisibly.


Cdsw$as_table()

The windows as a data frame.

Usage
Cdsw\$as_table(overlap = 1)
Arguments
overlap
Overlap of neighboring windows in m/z, at least 0: each window is widened by overlap / 2 on both sides.
Returns

A data frame with one row per window: start from, end to, center mid, width and the number of precursors with from < m/z <= to (n_precursors).


Cdsw$error()

Deviation of the windows from equal numbers of precursors.

Usage
Cdsw\$error()
Returns

A list with manhattan (Manhattan distance), euclidean (Euclidean distance), normalized_counts (precursors per window) and equal_counts (the counts of windows with equal numbers of precursors), both counts normalized to length 1.


Cdsw$optimize_windows()

Move window starts and ends to regions with few precursors, with readjust_windows().

Usage
Cdsw\$optimize_windows(bin_width = 0.1, min_count = 15, overlap = 1)
Arguments
bin_width
Width of the bins (m/z) into which the masses are binned.
min_count
Bins with fewer than min_count precursors count as empty.
overlap
Overlap of neighboring windows in m/z, as in as_table().
Returns

A data frame with the columns of as_table().


Cdsw$plot()

Plot the precursors per window (from < m/z <= to); the dashed line marks equal counts.

Usage
Cdsw\$plot()
Returns

A ggplot object.


Cdsw$plot_breaks()

Plot the breaks of this object against the constant and quantile breaks of the same masses.

Usage
Cdsw\$plot_breaks()
Returns

A ggplot object.


Cdsw$plot_cycle()

Plot the DIA cycle, one window per step.

Usage
Cdsw\$plot_cycle(overlap = 1)
Arguments
overlap
Overlap of neighboring windows in m/z, as in as_table().
Returns

A ggplot object.


Cdsw$clone()

The objects of this class are cloneable with this method.

Usage
Cdsw\$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.

See Also

Other DIA windows: masses, plot_windows(), readjust_windows()

Examples

library("prozor")

data(masses)
cdsw <- Cdsw$new(masses, max_window = 100)
cdsw
<Cdsw> 146,009 masses in 25 windows, method "mixture"
window widths 20.69 to 100.00 m/z
cdsw$plot_breaks()

cdsw$plot()

head(cdsw$as_table())
    from     to     mid width n_precursors
1 349.63 381.69 365.660 32.06         6098
2 380.69 408.26 394.475 27.57         6377
3 407.26 432.22 419.740 24.96         6531
4 431.22 454.62 442.920 23.40         6588
5 453.62 476.03 464.825 22.41         6627
6 475.03 496.74 485.885 21.71         6715
head(cdsw$optimize_windows())
    from     to    mid width n_precursors
1 349.63 381.95 365.79 32.32         6177
2 380.65 408.35 394.50 27.70         6395
3 407.15 432.35 419.75 25.20         6695
4 431.15 454.65 442.90 23.50         6613
5 453.45 476.05 464.75 22.60         6658
6 474.85 496.85 485.85 22.00         6842
cdsw$plot_cycle()

# one object per method
quantile_windows <- Cdsw$new(masses, method = "quantile")
c(mixture = cdsw$error()$manhattan, quantile = quantile_windows$error()$manhattan)
    mixture    quantile 
0.086158661 0.002159576