Skip to content

Commit

Permalink
initial testthat #2
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanse committed Jun 22, 2019
1 parent f989d5e commit a3bd1dd
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 13 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Authors@R: c(person(given = "Christian",
Depends: R (>= 3.6),
IRanges,
methods,
S4Vectors,
Spectra,
rDotNet (>= 0.9)
Suggests:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(MsBackendRawFileReader)
importClassesFrom(Spectra,MsBackendDataFrame)
importFrom(IRanges,NumericList)
importFrom(S4Vectors,DataFrame)
importFrom(methods,callNextMethod)
importFrom(methods,new)
importFrom(rDotNet,.cinit)
Expand Down
5 changes: 3 additions & 2 deletions R/MsBackendRawFileReader-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
)
Expand Down
5 changes: 2 additions & 3 deletions R/MsBackendRawFileReader.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
Binary file removed exec/MsBackendRawFileReader.dll
Binary file not shown.
25 changes: 25 additions & 0 deletions man/MsBackendRawFileReader-class.Rd

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

25 changes: 25 additions & 0 deletions man/hidden_aliases.Rd

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

16 changes: 8 additions & 8 deletions src/MsBackendRawFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
31 changes: 31 additions & 0 deletions tests/testthat/test_MsBackendMzR_MsBackendRawFileReader.R
Original file line number Diff line number Diff line change
@@ -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]])
})

})

0 comments on commit a3bd1dd

Please sign in to comment.