Browse code

fix: ensure header returns the same columns for all backends

- Fix for issue #238: ensure `header` returns the same columns for all backends.

jorainer authored on 02/02/2021 18:46:29
Showing 6 changed files

... ...
@@ -2,7 +2,7 @@ Package: mzR
2 2
 Type: Package
3 3
 Title: parser for netCDF, mzXML, mzData and mzML and mzIdentML files
4 4
        (mass spectrometry data)
5
-Version: 2.25.1
5
+Version: 2.25.2
6 6
 Author: Bernd Fischer, Steffen Neumann, Laurent Gatto, Qiang Kou, Johannes Rainer
7 7
 Maintainer: Steffen Neumann <sneumann@ipb-halle.de>,
8 8
 	    Laurent Gatto <laurent.gatto@uclouvain.be>,
... ...
@@ -1,3 +1,8 @@
1
+CHANGES IN VERSION 2.25.2
2
+-------------------------
3
+ o Fix issue #238: ensure `header` call returns the same columns for all
4
+   backends.
5
+
1 6
 CHANGES IN VERSION 2.25.1
2 7
 -------------------------
3 8
  o Bump version to trigger new build using latest Rcpp
... ...
@@ -51,41 +51,44 @@ setMethod("header",
51 51
           signature=c("mzRnetCDF","missing"),
52 52
           function(object) return(header(object, 1:length(object))))
53 53
 
54
-setMethod("header",
55
-          signature=c("mzRnetCDF","numeric"),
56
-          function(object, scans) {
57
-            empty_val <- rep(-1, length(scans))
58
-            result <- data.frame(seqNum=scans,
59
-                            acquisitionNum=scans,
60
-                            msLevel=rep(1, length(scans)),
61
-                            peaksCount=rep(1, length(scans)),
62
-                            totIonCurrent=netCDFVarDouble(object@backend, "total_intensity")[scans],
63
-                            retentionTime=netCDFVarDouble(object@backend, "scan_acquisition_time")[scans], 
64
-                            basePeakMZ = empty_val,
65
-                            basePeakIntensity = empty_val,
66
-                            collisionEnergy = empty_val,
67
-                            ionisationEnergy = empty_val,
68
-                            highMZ = empty_val,
69
-                            precursorScanNum = empty_val,
70
-                            precursorMZ = empty_val,
71
-                            precursorCharge = empty_val,
72
-                            precursorIntensity = empty_val,
73
-                            mergedScan = empty_val,
74
-                            mergedResultScanNum = empty_val,
75
-                            mergedResultStartScanNum = empty_val,
76
-                            mergedResultEndScanNum = empty_val,
77
-                            injectionTime = empty_val,
78
-                            spectrumId = paste0("scan=", scans),
79
-                            centroided = NA,
80
-                            ionMobilityDriftTime = empty_val,
81
-                            stringsAsFactors = FALSE)
82
-            result$isolationWindowTargetMZ <- NA_real_
83
-            result$isolationWindowLowerOffset <- NA_real_
84
-            result$isolationWindowUpperOffset <- NA_real_
85
-            result$scanWindowLowerLimit <- NA_real_
86
-            result$scanWindowUpperLimit <- NA_real_
87
-            return(result)
88
-          })
54
+setMethod("header", c("mzRnetCDF", "numeric"), function(object, scans) {
55
+    ls <- length(scans)
56
+    empty_val <- rep(-1, ls)
57
+    na_real <- rep(NA_real_, ls)
58
+    result <- data.frame(
59
+        seqNum=scans,
60
+        acquisitionNum=scans,
61
+        msLevel=rep(1, length(scans)),
62
+        polarity = empty_val,
63
+        peaksCount=rep(1, length(scans)),
64
+        totIonCurrent=netCDFVarDouble(object@backend, "total_intensity")[scans],
65
+        retentionTime=netCDFVarDouble(object@backend, "scan_acquisition_time")[scans],
66
+        basePeakMZ = empty_val,
67
+        basePeakIntensity = empty_val,
68
+        collisionEnergy = empty_val,
69
+        ionisationEnergy = empty_val,
70
+        lowMZ = empty_val,
71
+        highMZ = empty_val,
72
+        precursorScanNum = empty_val,
73
+        precursorMZ = empty_val,
74
+        precursorCharge = empty_val,
75
+        precursorIntensity = empty_val,
76
+        mergedScan = empty_val,
77
+        mergedResultScanNum = empty_val,
78
+        mergedResultStartScanNum = empty_val,
79
+        mergedResultEndScanNum = empty_val,
80
+        injectionTime = empty_val,
81
+        filterString = NA_character_,
82
+        spectrumId = paste0("scan=", scans),
83
+        centroided = NA,
84
+        ionMobilityDriftTime = empty_val,
85
+        isolationWindowTargetMZ = na_real,
86
+        isolationWindowLowerOffset = na_real,
87
+        isolationWindowUpperOffset = na_real,
88
+        scanWindowLowerLimit = na_real,
89
+        scanWindowUpperLimit = na_real)
90
+    return(result)
91
+})
89 92
 
90 93
 setMethod("close", 
91 94
           signature="mzRnetCDF",
... ...
@@ -1,4 +1,4 @@
1
-BUILT_RCPP_VERSION = package_version("0.12.19")
1
+BUILT_RCPP_VERSION = package_version("1.0.2")
2 2
 
3 3
 .onLoad <-
4 4
     function(libname, pkgname) {
... ...
@@ -64,7 +64,7 @@ test_header <- function() {
64 64
   cdf <- openMSfile(file, backend="netCDF")        
65 65
 
66 66
   h <- header(cdf)
67
-  checkEquals(ncol(h), 28)
67
+  checkEquals(ncol(h), 31)
68 68
   checkEquals(nrow(h), 1278)
69 69
   checkTrue(any(colnames(h) == "centroided"))
70 70
   checkTrue(all(is.na(h$centroided)))
... ...
@@ -80,11 +80,11 @@ test_header <- function() {
80 80
   checkTrue(all(is.na(h$scanWindowUpperLimit)))
81 81
 
82 82
   h <- header(cdf, 1)
83
-  checkEquals(ncol(h), 28)
83
+  checkEquals(ncol(h), 31)
84 84
   checkEquals(nrow(h), 1)
85 85
 
86 86
   h <- header(cdf, 2:3)
87
-  checkEquals(ncol(h), 28)
87
+  checkEquals(ncol(h), 31)
88 88
   checkEquals(nrow(h), 2)
89 89
 
90 90
   close(cdf)
91 91
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+test_header_all <- function() {
2
+    ## Check that the header call returns the same columns irrespectively of the
3
+    ## backend. Issue #238
4
+    file <- system.file('cdf/ko15.CDF', package = "msdata")
5
+    cdf <- openMSfile(file, backend="netCDF")
6
+    header_cdf <- header(cdf)
7
+    close(cdf)
8
+
9
+    file <- system.file("threonine", "threonine_i2_e35_pH_tree.mzXML", package = "msdata")
10
+    mzxml <- openMSfile(file, backend="pwiz")
11
+    header_pwiz <- header(mzxml)
12
+    close(mzxml)
13
+
14
+    mzxml <- openMSfile(file, backend="Ramp")
15
+    header_ramp <- header(mzxml)
16
+    close(mzxml)
17
+
18
+    checkEquals(colnames(header_cdf), colnames(header_pwiz))
19
+    checkEquals(colnames(header_ramp), colnames(header_pwiz))
20
+}