## load library
library("MALDIquant");
## create some artificial spectra
mass <- 1:10;
intensity <- c(1, 2, 10, 1, 0, 0, 10, 1, 0, 1);
original <- createMassSpectrum(mass=mass, intensity=intensity);
filtered <- createMassSpectrum(mass=mass[intensity!=0],
intensity=intensity[intensity!=0]);
## compare length == FALSE
length(original) == length(filtered);
## filtered is the shorter spectrum
length(original) > length(filtered);
## run peak detection
pO <- detectPeaks(original, halfWindowSize=2);
pF <- detectPeaks(filtered, halfWindowSize=2);
## a peak in pF is missing caused by an incorrect index distance
length(pO) > length(pF);
## fix it
imputed <- MALDIquant:::imputeMass(filtered, verbose=TRUE);
## now original and imputed have the same length
length(original) == length(imputed);
## and everything is equal
all.equal(intensity(original), intensity(original));
all.equal(mass(original), mass(original));
## test peak detection
pI <- detectPeaks(imputed, halfWindowSize=2);
## all peaks detected
length(pO) == length(pI);
## all peaks are the same
all.equal(intensity(pO), intensity(pI));
all.equal(mass(pO), mass(pO));
## if mass imputation is not needed the spectrum would not changed
a <- createMassSpectrum(mass=1:10, intensity=rep(1, 10));
b <- MALDIquant:::imputeMass(a, verbose=TRUE);
length(a) == length(b);
all.equal(intensity(a), intensity(b));
all.equal(mass(a), mass(b));Run the code above in your browser using DataLab