diff --git a/DESCRIPTION b/DESCRIPTION index 0b86cd5..c8ecbf6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,6 +11,7 @@ Authors@R: c(person(given = "Christian", Depends: R (>= 3.6), IRanges, methods, + S4Vectors, Spectra, rDotNet (>= 0.9) Suggests: diff --git a/NAMESPACE b/NAMESPACE index eea11ca..e5ae2d9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(MsBackendRawFileReader) importClassesFrom(Spectra,MsBackendDataFrame) importFrom(IRanges,NumericList) +importFrom(S4Vectors,DataFrame) importFrom(methods,callNextMethod) importFrom(methods,new) importFrom(rDotNet,.cinit) diff --git a/R/MsBackendRawFileReader-functions.R b/R/MsBackendRawFileReader-functions.R index 707588a..9051aba 100644 --- a/R/MsBackendRawFileReader-functions.R +++ b/R/MsBackendRawFileReader-functions.R @@ -18,6 +18,7 @@ MsBackendRawFileReader <- function() { #' adapted from the MsBackendMzR-function.R file by Johannes Rainer #' #' @return `DataFrame` with the header. +#' @importFrom S4Vectors DataFrame #' @noRd .MsBackendRawFileReader_header <- function(x) { stopifnot(class(x) == "rDotNet") @@ -27,10 +28,10 @@ MsBackendRawFileReader <- function() { first <- x$getFirstScanNumber() last <- x$getLastScanNumber() - S4Vectors::DataFrame( + DataFrame( scanIndex = first:last, msLevel = vapply(first:last, FUN=function(z){x$GetMsLevel(z)}, FUN.VALUE = as.integer(1)), - precursorMz = vapply(first:last, FUN=function(z){x$GetPepmass(z)}, FUN.VALUE = as.double(1.0)), + precursorMz = vapply(first:last, FUN=function(z){x$GetPrecursorMz(z)}, FUN.VALUE = as.double(1.0)), precursorCharge = as.integer(vapply(first:last, FUN=function(z){x$GetCharge(z)}, FUN.VALUE = as.character(1.0))), rtime = vapply(first:last, FUN=function(z){x$GetRTinSeconds(z)}, FUN.VALUE = as.double(1.0)) ) diff --git a/R/MsBackendRawFileReader.R b/R/MsBackendRawFileReader.R index d47cf4e..8de4460 100644 --- a/R/MsBackendRawFileReader.R +++ b/R/MsBackendRawFileReader.R @@ -3,9 +3,9 @@ NULL #' @title RawFileReader-based backend -#' +#' @aliases MsBackendRawFileReader #' @description -#' + #' The `MsBackendRawFileReader` inherits all slots and methods from the base #' `MsBackendDataFrame` (in-memory) backend. It overrides the base `mz` and #' `intensity` methods as well as `peaks` to read the respective data from @@ -23,7 +23,6 @@ NULL #' adapted from the MsBackendMzR.R file by Johannes Rainer #' #' @importClassesFrom Spectra MsBackendDataFrame -#' @rdname hidden_aliases setClass("MsBackendRawFileReader", contains = "MsBackendDataFrame", prototype = prototype(version = "0.1", diff --git a/exec/MsBackendRawFileReader.dll b/exec/MsBackendRawFileReader.dll deleted file mode 100755 index 9beaf72..0000000 Binary files a/exec/MsBackendRawFileReader.dll and /dev/null differ diff --git a/man/MsBackendRawFileReader-class.Rd b/man/MsBackendRawFileReader-class.Rd new file mode 100644 index 0000000..3b53fbf --- /dev/null +++ b/man/MsBackendRawFileReader-class.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/MsBackendRawFileReader.R +\docType{class} +\name{MsBackendRawFileReader-class} +\alias{MsBackendRawFileReader-class} +\alias{MsBackendRawFileReader} +\title{RawFileReader-based backend} +\description{ +The `MsBackendRawFileReader` inherits all slots and methods from the base +`MsBackendDataFrame` (in-memory) backend. It overrides the base `mz` and +`intensity` methods as well as `peaks` to read the respective data from +the original raw data files. + +The validator function has to ensure that the files provided in the +`files` slot exist. + +The `backendInitialize` method reads the header data from the raw files and +hence fills the `spectraData` slot. Note that this method could be called +several times, e.g. also to *re-fill* `spectraData` after dropping some of +its columns. +} +\author{ +Christian Panse 2019-06-15 +adapted from the MsBackendMzR.R file by Johannes Rainer +} diff --git a/man/hidden_aliases.Rd b/man/hidden_aliases.Rd new file mode 100644 index 0000000..f81be26 --- /dev/null +++ b/man/hidden_aliases.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hidden_aliases.R, R/MsBackendRawFileReader.R +\docType{methods} +\name{hidden_aliases} +\alias{hidden_aliases} +\alias{[,MsBackendDataFrame-method} +\alias{backendInitialize,MsBackendRawFileReader-method} +\alias{show,MsBackendRawFileReader-method} +\alias{intensity,MsBackendRawFileReader-method} +\alias{mz,MsBackendRawFileReader-method} +\title{Internal page for hidden aliases} +\usage{ +\S4method{backendInitialize}{MsBackendRawFileReader}(object, files, + spectraData, ..., BPPARAM = bpparam()) + +\S4method{show}{MsBackendRawFileReader}(object) + +\S4method{intensity}{MsBackendRawFileReader}(object) + +\S4method{mz}{MsBackendRawFileReader}(object) +} +\description{ +For S4 methods that require a documentation entry but only clutter the index. +} +\keyword{internal} diff --git a/src/MsBackendRawFileReader.cs b/src/MsBackendRawFileReader.cs index 714873c..8d91310 100644 --- a/src/MsBackendRawFileReader.cs +++ b/src/MsBackendRawFileReader.cs @@ -96,9 +96,16 @@ public string GetTitle(int scanNumber) return s; } - public double GetPepmass(int scanNumber) + public double GetPrecursorMz(int scanNumber) { + + + var scanFilter = rawFile.GetFilterForScanNumber(scanNumber); + + if (scanFilter.MSOrder.ToString() == "Ms") return 0.0; + var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); + try { var reaction0 = scanEvent.GetReaction(0); @@ -110,13 +117,6 @@ public double GetPepmass(int scanNumber) } } - public double[] GetPepmasss() - { - var pepmass = new double[this.getLastScanNumber()]; - foreach (int scan in this.scans) pepmass[scan] = GetPepmass(scan); - return pepmass; - } - public string GetScanType(int scanNumber) { diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..7feb6c4 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,17 @@ +library("testthat") +library("MsBackendRawFileReader") +library("Spectra") + +sample_raw_file <- file.path(path.package(package = 'MsBackendRawFileReader'), + 'extdata', 'sample.raw') + +sample_mzXML_file <- file.path(path.package(package = 'MsBackendRawFileReader'), + 'extdata', 'sample.mzXML') + + +sample_raw <- backendInitialize(MsBackendRawFileReader(), files = sample_raw_file) +sample_mzr <- backendInitialize(MsBackendMzR(), files = sample_mzXML_file) + + + +test_check("MsBackendRawFileReader") diff --git a/tests/testthat/test_MsBackendMzR_MsBackendRawFileReader.R b/tests/testthat/test_MsBackendMzR_MsBackendRawFileReader.R new file mode 100644 index 0000000..b9f7b96 --- /dev/null +++ b/tests/testthat/test_MsBackendMzR_MsBackendRawFileReader.R @@ -0,0 +1,31 @@ +test_that("msLevel", { + expect_identical(msLevel(sample_raw), msLevel(sample_mzr)) +}) + + +test_that("rtime", { + expect_equal(rtime(sample_raw), rtime(sample_mzr), tolerance = 1E-4) +}) + +test_that("precursorMz", { + expect_equal(precursorMz(sample_raw), precursorMz(sample_mzr), tolerance = 1E-5) +}) + +test_that("precursorCharge", { + expect_identical(precursorCharge(sample_raw), precursorCharge(sample_mzr)) +}) + + +test_that("peaks", { + + sample_peaks_raw <- peaks(sample_raw) + sample_peaks_mzr <- peaks(sample_mzr) + + n <- length(sample_peaks_raw ) + expect_true(n == 574) + + rv <- lapply(1:n, function(i){ + expect_identical(sample_peaks_raw[[i]] , sample_peaks_mzr[[i]]) + }) + +})