Closed jmorim closed 3 years ago
I don't want to add a new dedicated slot explicitly, which would break backwards compatibility. Your solution, that adds it to experimentData
is a step in the right direction - the @other
slot is a list that accepts any additional/new data. You could then wrap everything in a function
addScanRate <- function(x) {
stopifnot(inherits(x, "MSnExp"))
rts <- rtime(x)
nScans<- length(rts)
x@experimentData@other$scanRate <- nScans / (max(rts) - min(rts))
x
}
And use it:
> odmse <- addScanRate(odmse)
> experimentData(odmse)@other$scanRate
[1] 10.02938
You might however want to improve the function by calculating a per-file scan rate, when multiple files are read at once.
I think I got it.
addScanRate <- function(x){
stopifnot(inherits(x, 'MSnExp'))
rts.by.file = split(rtime(x), fromFile(x))
nScans = lapply(rts.by.file, length)
x@experimentData@other$scanRate = lapply(seq_along(nScans), function(x){
nScans[[x]] / (max(rts.by.file[[x]]) - min(rts.by.file[[x]]))
})
x
}
Would it be a good idea to make a slot for scan rate for an MS experiment? Like object@experimentData$scanRate
In the simplest case it can be calculated as