From a3bd1dda51b4f1258f12868f0b89df022b1bdcce Mon Sep 17 00:00:00 2001 From: Christian Panse Date: Sat, 22 Jun 2019 08:02:09 +0200 Subject: [PATCH] initial testthat #2 --- DESCRIPTION | 1 + NAMESPACE | 1 + R/MsBackendRawFileReader-functions.R | 5 +-- R/MsBackendRawFileReader.R | 5 ++- exec/MsBackendRawFileReader.dll | Bin 9728 -> 0 bytes man/MsBackendRawFileReader-class.Rd | 25 ++++++++++++++ man/hidden_aliases.Rd | 25 ++++++++++++++ src/MsBackendRawFileReader.cs | 16 ++++----- tests/testthat.R | 17 ++++++++++ ...test_MsBackendMzR_MsBackendRawFileReader.R | 31 ++++++++++++++++++ 10 files changed, 113 insertions(+), 13 deletions(-) delete mode 100755 exec/MsBackendRawFileReader.dll create mode 100644 man/MsBackendRawFileReader-class.Rd create mode 100644 man/hidden_aliases.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_MsBackendMzR_MsBackendRawFileReader.R 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 9beaf72eae503f3204b548c7e4570ac9a1e167b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9728 zcmeHMeQ*`mbw79ay?v{P-a~pq0s+EL=EFh)S%91(B8bqJd8q^{5)g=sSUoLb&3n6# z-F<*;pwQH`O~6SeN%PThYx76aOxn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uy*? zp>PC_5_%JXq`+x#eH+#n%JO(j8o)Btn9%XDK3q)5aXk`4tiYMnG0dcd9*e1|zSP!4 zJf^lKpaEi27mFYY90G9YEG1<%=Hsylnq&OOX6ZaZ4<_j7$_X$VLXyB!>r=(l`~prF z_9VhsM z(pSFlgGpp&a6OA(|4P@3+)tOV+P3sNCebvW@P~7`aU4e^Yl~@yr2)Tiucq`s?Zn?; zRUY7PWQ6Yzbhe6!E{Bh(=N5G4+kyLi1Na82Fcw_TD*Ow>UYew7z!7|-pF|DaMLU6K z07ud1>*>gA*K6NLC7JMZt-SaRv`Va`4Fd{D<%(IV+Zj~A!>Fo!t&;D&Qy2{@bxu}O z3!}Ci|2=wKeqtBUiR-%s`rIufMX<1d)jjx?>M&q0&9D#f{;hyM1bKN`m2F5t&6laU zs%oqt*Pn;ALG|Xv)4113o|5LnsOx;HupR|Ss_4nQJ$T0!W!?6ImtQ(7JU#eUQMn1H z!ea2VH~9Q;(Hc0{DjM*)GzeOjj$+)VSwzO56Xg|lgKB`vbNT9!x{d*#lako#0=^%y zwsSbOeDI`k2R2ps0`Ie&Jm$GrjXf0b9>RAFf%pe9*!!$w$sdgISx59vbnS-DIsEYz v#9#vQ9Z-v~)vxkEphI9+EzeuMo0igk%>fdce`dH=RcC+AE&h#pRUY^s!qGKS 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]]) + }) + +})