Skip to content

Commit

Permalink
accessor function
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Mar 14, 2024
1 parent f9220d7 commit 0cddc6c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
11 changes: 5 additions & 6 deletions R/XcmsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -1378,17 +1378,16 @@ setMethod(

# Check if user as ran matching lama vs chrompeaks beforehand
if(length(param@rtMap) == 0)
rtMap <- matchLamasChromPeaks(object, param)
else
rtMap <- param@rtMap
param <- matchLamasChromPeaks(object, param)
rtMap <- param@rtMap
if(length(rtMap) != length(object))
stop("The mismatch betweent the number of files matched to lamas ",
"and files in the object.")
stop("Mismatch between the number of files matched to lamas: ",
length(rtMap), "and files in the object: ", length(object))

# Make model and adjust retention for each file
rt_adj <- bpmapply(rtMap, rt_raw, idx, FUN = function(x, y, i, param) {
if (nrow(x) >= 10) { # too strict ? Gam always throws error when less than that and loess does not work that well either.
.adjust_rt_model(y, method = param@method,
xcms:::.adjust_rt_model(y, method = param@method,
rt_map = x, span = param@span,
resid_ratio = param@outlierTolerance,
zero_weight = param@zeroWeight,
Expand Down
16 changes: 12 additions & 4 deletions R/do_adjustRtime-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,15 @@ summarizeLamaMatch <- function(param){
x
}

#' Function to access rtMap from `LamaParama` object
rtMap <- function(x){
if(!inherits(x, "LamaParama"))
stop("The inputs need to be of class LamaParama")
rtMap <- param@rtMap
rtMap
}


## phili: need to move that to a better file because its a method
#' @title Plot summary of information of matching lamas to chromPeaks
#'
Expand All @@ -886,14 +895,13 @@ setMethod("plot", "LamaParama", function(x, index = 1L, colPoints = "#00000060",
xlab = "Matched Chromatographic peaks",
ylab = "Lamas",
main = NULL,...){
model <- .rt_model(method = param@method,
model <- xcms:::.rt_model(method = param@method,
rt_map= x@rtMap[[index]], span = param@span,
resid_ratio = param@outlierTolerance,
zero_weight = param@zeroWeight,
bs = param@bs)
x <- x@rtMap[[index]]
callNextMethod(x = x, col = colPoints, xlab = xlab,
ylab = ylab, main = main, ...) #not working and not sure why
#plot(obs, ref, type = type, xlab = xlab, ylab = ylab, col = "blue", main = main)
plot(x, type = "p", xlab = xlab, ylab = ylab, col = "blue",
main = main)
points(model, type = "l", col = "black")
})
8 changes: 8 additions & 0 deletions tests/testthat/test_do_adjustRtime-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,11 @@ test_that("summarizeLamaMatch works", {
expect_equal(nrow(res), length(tst))
expect_equal(ncol(res), 7)
})

test_that("Accessing rtMap from LamaParama object works", {
param <- LamaParama(lamas = ref_mz_rt, toleranceRt = 10)
param <- matchLamasChromPeaks(tst, param)
expect_error(rtMap(ObiwarpParam()), "class")
rtMap <- rtMap(param)
expect_equal(length(rtMap), length(param@rtMap))
})
14 changes: 8 additions & 6 deletions vignettes/xcms.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ performance. See the package vignette from the `r Biocpkg("Spectra")` package or
the [SpectraTutorials](https://jorainer.github.io/SpectraTutorials) tutorial for
more details on `Spectra` backends and how to change between them.


## Initial data inspection

The `MsExperiment` object is a simple and flexible container for MS
Expand Down Expand Up @@ -1384,20 +1383,23 @@ It can be run before adjusting as well.

```{r}
param <- matchLamasChromPeaks(tst, param = param)
rtMap <- rtMap(param)
summary <- summaryLama(param)
plot(param)
#' BPC of the first sample with matches to lamas overlay
par(mfrow = c(1, 1))
plot(bpc[1, 1], col = "#00000080", main = "Distribution CP matched to Lamas")
points(rtime(bpc_tst_adj[1, 1]), intensity(bpc_tst_adj[1, 1]), type = "l",
col = "#0000ff80")
grid()
abline(v = rtMap[[1]]$obs)
```
### add diagnostic part: see that later
#access summary of matches and model information
summary <- summarizeLamaMatch(param)
summary[1]
# Plot obs vs. ref with fitting line
plot(param)
```

# Additional details and notes

Expand Down

0 comments on commit 0cddc6c

Please sign in to comment.