Thanks for looking into and fixing the error - very much appreciated.
I was quite intrigued that you said fillChromPeaks always uses the adjusted retention time, so I looked a bit deeper into the code.
It seems fairly simple to allow the ability to integrate using the original rt range.
If you included another parameter on getChromPeakData to select whether switch back to the unadjusted rtrange, stored the unadjusted rtime, figured out which index of rtim is the rtmin and rtmax, then use those indexes to get the original rt for use in the calculation of res[,"into"]
.getChromPeakData <- function(object, peakArea, sample_idx,
mzCenterFun = "weighted.mean",
cn = c("mz", "rt", "into", "maxo", "sample"),
unadjusted=FALSE) {
...
rtim <- rtime(object)
if(unadjusted) rtim_adjusted <- rtime(object,adjusted=!unadjusted)
...
rtScans<-range(which(rtim >= rtr[1] & rtim <= rtr[2]))
...
if(unadjusted) rtrange<-rtim_unadjusted[rtScans] else rtrange<-rtim[rtScans]
...
res[i, "into"] <- sum(mtx[, 3], na.rm = TRUE) *
((rtrange[2] - rtrange[1]) /
max(1, (sum(rtim >= rtr[1] & rtim <= rtr[2]) - 1)))
However, this highlighted something else in the code that felt odd to me (again, I'm making a lot of assumptions).
By using 'rtr[2] - rtr[1]' in the calculation of "into", don't we always end up overestimating the area of the peak?
rtr comes from the medians of other samples, but getChromPeakData integrates using scans found between these limits. So the rt range of where it integrates is notionally smaller than 'rtr[2] - rtr[1]'. In the example above, rtrange is indeed smaller (with unadjusted=FALSE).
Could we iterate over peakArea and calculate new rtmin and rtmax based on the actual rtime?
peakArea<-apply(peakArea,1,function(pk) {
# Get start and end index of rtim between rt range
rtScans<-range(which(rtim >= pk["rtmin"] & rtim <= pk["rtmax"]))
# Convert median rt range to actual rt range
pk[c("rtmin","rtmax")]<-rtim[rtScans]
# If the user wants unadjusted rt range give it to them, otherwise just rt range
if(unadjusted) rtrange<-rtim_unadjusted[rtScans] else rtrange<-rtim[rtScans]
# Save rt range in peakArea, so it can be used instead of rtr[2]-rtr[1] for res[i,'into']
pk[c("rtDiff")]<-diff(rtrange)
return(pk)
})
peakArea<-t(peakArea)
I'm not sure how centWave integrates peaks and how the rtmin and rtmax are chosen. So maybe this doesn't make sense...
Cheers,
Corey