icoshift: Align Spectra with Interval Correlation Optimized Shifting

View source: R/icoshift.R

icoshiftR Documentation

Align Spectra with Interval Correlation Optimized Shifting

Description

Splits spectra into intervals and rigidly shifts each interval to maximize its cross-correlation with a target. Samples must be rows and spectral points must be columns.

Usage

icoshift(xT, xP, inter = "whole", n = NULL, options = NULL, Scal = NULL)

Arguments

xT

A numeric target with one value per column of xP, or one of "average", "average2", "median", or "max". "average2" uses a fixed multiplier of 3.

xP

Numeric matrix with samples in rows and spectral points in columns.

inter

"whole"; an integer number of intervals; a character interval length or range; or a numeric vector of start/end pairs. Numeric values refer to points unless options[5] is 1.

n

Positive maximum shift, "f" for fast automatic search, or "b" for the more exhaustive search. Numeric values use points or scale units according to options[5].

options

Numeric vector or named list with show, fill, preCOShift, maxPreCOShift, useScal, and alignPreprocessed. Defaults are c(1, 1, 0, 0, 0, 0). Preprocessing values are 0 (raw), 1 (SNV), 3 (the original msc(0, A) behavior), -1, or -2 (derivatives).

Scal

Optional strictly monotonic axis with one value per column. Used for conversion when options[5] is 1; it is not modified.

Details

This implementation covers one-dimensional spectra, not MATLAB icoshiftMC. show=2 does not create the MATLAB diagnostic plot. The "b" search may be slow, overlapping intervals are not reconciled, and repeated boundary filling can create edge artifacts. Character ranges use - as separator and cannot express negative endpoints; use numeric pairs. See system.file("ICOSHIFT.md", package = "iSTATS") for the app workflow.

Value

A list containing aligned matrix xCS, interval table ints, shift indices ind (positive is left, negative is right), and actual target.

References

Savorani F, Tomasi G, Engelsen SB (2010). "icoshift: A versatile tool for the rapid alignment of 1D NMR spectra." Journal of Magnetic Resonance, 202(2), 190-202. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.jmr.2009.11.012")}.

Examples

axis <- seq(1, -1, length.out = 64)
target <- dnorm(seq(-3, 3, length.out = 64))
spectra <- rbind(target, c(target[-1], 0), c(0, target[-64]))

fit <- icoshift("average", spectra, c(1, 64), n = 3,
                options = c(0, 1, 0, 0, 0, 0))
dim(fit$xCS)
fit$ind

fit_ppm <- icoshift("average", spectra, c(-0.5, 0.5), n = "f",
                    options = c(0, 1, 0, 0, 1, 1), Scal = axis)

iSTATS documentation built on Nov. 6, 2026, 1:07 a.m.

Related to icoshift in iSTATS...