Skip to content

Commit

Permalink
Merge pull request #51 from rformassspectrometry/jomain
Browse files Browse the repository at this point in the history
feat: add extractByIndex method
  • Loading branch information
jorainer authored Sep 27, 2024
2 parents a55a389 + edc6a76 commit d373a25
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MsBackendMassbank
Title: Mass Spectrometry Data Backend for MassBank record Files
Version: 1.13.0
Version: 1.13.1
Authors@R:
c(person(given = "RforMassSpectrometry Package Maintainer",
email = "maintainer@rformassspectrometry.org",
Expand All @@ -25,7 +25,7 @@ Description: Mass spectrometry (MS) data backend supporting import and
adds MassBank support to the Spectra package.
Depends:
R (>= 4.0),
Spectra (>= 1.9.12)
Spectra (>= 1.15.10)
Imports:
BiocParallel,
S4Vectors,
Expand All @@ -50,7 +50,7 @@ BugReports: /~https://github.com/RforMassSpectrometry/MsBackendMassbank/issues
URL: /~https://github.com/RforMassSpectrometry/MsBackendMassbank
biocViews: Infrastructure, MassSpectrometry, Metabolomics, DataImport
Roxygen: list(markdown=TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'hidden_aliases.R'
'MsBackendMassbank.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exportMethods(backendInitialize)
exportMethods(compounds)
exportMethods(dataStorage)
exportMethods(export)
exportMethods(extractByIndex)
exportMethods(peaksData)
exportMethods(precScanNum)
exportMethods(reset)
Expand Down Expand Up @@ -71,6 +72,7 @@ importMethodsFrom(Spectra,"$<-")
importMethodsFrom(Spectra,"spectraData<-")
importMethodsFrom(Spectra,backendBpparam)
importMethodsFrom(Spectra,export)
importMethodsFrom(Spectra,extractByIndex)
importMethodsFrom(Spectra,precScanNum)
importMethodsFrom(Spectra,reset)
importMethodsFrom(Spectra,spectraData)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# MsBackendMassbank 1.13

## Changes in 1.13.1

- Add `extractByIndex()` method.

# MsBackendMassbank 1.11

## Changes in 1.11.2
Expand Down
16 changes: 13 additions & 3 deletions R/MsBackendMassbankSql.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,21 @@ setMethod("[", "MsBackendMassbankSql", function(x, i, j, ..., drop = FALSE) {
if (missing(i))
return(x)
i <- i2index(i, length(x), x@spectraIds)
slot(x, "spectraIds", check = FALSE) <- x@spectraIds[i]
x <- callNextMethod(x, i = i)
x
extractByIndex(x, i)
})


#' @rdname MsBackendMassbankSql
#'
#' @importMethodsFrom Spectra extractByIndex
#'
#' @export
setMethod("extractByIndex", c("MsBackendMassbankSql", "ANY"),
function(object, i) {
slot(object, "spectraIds", check = FALSE) <- object@spectraIds[i]
callNextMethod(object, i = i)
})

#' @rdname MsBackendMassbankSql
#'
#' @importFrom ProtGenerics compounds
Expand Down
3 changes: 3 additions & 0 deletions man/MsBackendMassbankSql.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/test_MsBackendMassbankSql.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,23 @@ test_that("selectSpectraVariables,MsBackendMassbankSql works", {
unique(c(names(Spectra:::.SPECTRA_DATA_COLUMNS)), "rtime"))
})

test_that("extractByIndex,MsBackendMassbankSql works", {
be <- backendInitialize(MsBackendMassbankSql(), dbc)

res <- extractByIndex(be, 2:3)
expect_true(length(res) == 2)
expect_equal(res@spectraIds, be@spectraIds[2:3])
expect_equal(res@spectraIds, res$spectrum_id)
expect_equal(be$mz[2:3], res$mz)

})

test_that("[,MsBackendMassbankSql works", {
be <- backendInitialize(MsBackendMassbankSql(), dbc)

res <- be[]
expect_equal(res, be)

res <- be[2:3]
expect_true(length(res) == 2)
expect_equal(res@spectraIds, be@spectraIds[2:3])
Expand Down

0 comments on commit d373a25

Please sign in to comment.