Skip to content

Unexpected results in subset-based alignment and alignment against reference #795

@jorainer

Description

@jorainer

For some data sets we see a strange artifact when using subset-based alignment:

Image

i.e., instead of the expected continuous, smooth line for each sample we see such random scattering for the retention time differences (rtadj - rtraw) for the samples that get aligned against the subset (smooth solid lines in the plot).

This seems to be specific to certain data sets as we don't see this e.g. on the data set used in the package vignette.

In subset-based alignment we use the internal .applyRtAdjustment() function that aligns a vector of values against reference values:

.applyRtAdjustment <- function(x, rtraw, rtadj) {
    ## re-order everything if rtraw is not sorted; issue #146
    if (is.unsorted(rtraw)) {
        idx <- order(rtraw)
        rtraw <- rtraw[idx]
        rtadj <- rtadj[idx]
    }
    adjFun <- stepfun(rtraw[-1] - diff(rtraw) / 2, rtadj)
    res <- adjFun(x)
    ## Fix margins.
    idx_low <- which(x < rtraw[1])
    if (length(idx_low)) {
        first_adj <- idx_low[length(idx_low)] + 1
        res[idx_low] <- x[idx_low] + res[first_adj] - x[first_adj]
    }
    idx_high <- which(x > rtraw[length(rtraw)])
    if (length(idx_high)) {
        last_adj <- idx_high[1] - 1
        res[idx_high] <- x[idx_high] + res[last_adj] - x[last_adj]
    }
    if (is.null(dim(res)))
        names(res) <- names(x)
    res
}

My suspicion is the use of stepfun() here. I will check if we could not maybe use approxfun() with linear interpolation instead.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions