... | ... |
@@ -7,17 +7,6 @@ |
7 | 7 |
else res |
8 | 8 |
} |
9 | 9 |
|
10 |
-.peaks_ramp <- function(object, scans) { |
|
11 |
- if (missing(scans)) |
|
12 |
- scans <- 1:length(object) |
|
13 |
- if (length(scans) == 1) { |
|
14 |
- object@backend$getPeakList(scans)$peaks |
|
15 |
- } else { |
|
16 |
- sapply(scans, function(x) object@backend$getPeakList(x)$peaks, |
|
17 |
- simplify = FALSE) |
|
18 |
- } |
|
19 |
-} |
|
20 |
- |
|
21 | 10 |
setMethod("isolationWindow", "character", |
22 | 11 |
function(object, ...) .isolationWindow(object, ...)) |
23 | 12 |
|
- Rewrite the C++ code for peak data extraction with the pwiz backend.
- Fix unit tests.
... | ... |
@@ -1,20 +1,26 @@ |
1 | 1 |
.peaks <- function(object, scans) { |
2 |
+ if (missing(scans)) |
|
3 |
+ scans <- 1:length(object) |
|
4 |
+ res <- object@backend$getPeakList(scans) |
|
5 |
+ if (length(res) == 1) |
|
6 |
+ res[[1]] |
|
7 |
+ else res |
|
8 |
+} |
|
9 |
+ |
|
10 |
+.peaks_ramp <- function(object, scans) { |
|
2 | 11 |
if (missing(scans)) |
3 | 12 |
scans <- 1:length(object) |
4 | 13 |
if (length(scans) == 1) { |
5 |
- return(object@backend$getPeakList(scans)$peaks) |
|
14 |
+ object@backend$getPeakList(scans)$peaks |
|
6 | 15 |
} else { |
7 |
- return(sapply(scans, |
|
8 |
- function(x) object@backend$getPeakList(x)$peaks, |
|
9 |
- simplify = FALSE)) |
|
16 |
+ sapply(scans, function(x) object@backend$getPeakList(x)$peaks, |
|
17 |
+ simplify = FALSE) |
|
10 | 18 |
} |
11 | 19 |
} |
12 | 20 |
|
13 |
- |
|
14 | 21 |
setMethod("isolationWindow", "character", |
15 | 22 |
function(object, ...) .isolationWindow(object, ...)) |
16 | 23 |
|
17 |
- |
|
18 | 24 |
.isolationWindow <- function(x, unique. = TRUE, simplify = TRUE) { |
19 | 25 |
stopifnot(all(file.exists(x))) |
20 | 26 |
if (!requireNamespace("XML")) |
- Add scanWindowLowerLimit and scanWindowUpperLimit variables.
- Export scanWindowLowerLimit and scanWindowUpperLimit to mzML (issue #202).
- Update and amend documentation and unit tests accordingly.
... | ... |
@@ -77,7 +77,8 @@ setMethod("isolationWindow", "character", |
77 | 77 |
"precursorIsolationWindowTargetMZ", |
78 | 78 |
"precursorIsolationWindowLowerOffset", |
79 | 79 |
"precursorIsolationWindowUpperOffset", |
80 |
- "precursorCollisionEnergy", "productIsolationWindowTargetMZ", |
|
80 |
+ "precursorCollisionEnergy", |
|
81 |
+ "productIsolationWindowTargetMZ", |
|
81 | 82 |
"productIsolationWindowLowerOffset", |
82 | 83 |
"productIsolationWindowUpperOffset") |
83 | 84 |
data.frame(matrix(nrow = 0, ncol = length(cn), |
- Add the .hasChromatograms function.
- Add chromatogram, chromatograms and chromatogramHeader methods for the ramp
and netCDF backends.
- Add related unit tests.
... | ... |
@@ -43,8 +43,56 @@ setMethod("isolationWindow", "character", |
43 | 43 |
|
44 | 44 |
|
45 | 45 |
.hasSpectra <- function(x) { |
46 |
- if (is.character(x) & file.exists(x)) |
|
46 |
+ close_after <- FALSE |
|
47 |
+ if (is.character(x) && file.exists(x)) { |
|
47 | 48 |
x <- mzR::openMSfile(x) |
49 |
+ ## Ensure we are closing the file later |
|
50 |
+ close_after <- TRUE |
|
51 |
+ } |
|
52 |
+ stopifnot(inherits(x, "mzR")) |
|
53 |
+ len <- length(x) |
|
54 |
+ if (close_after) |
|
55 |
+ close(x) |
|
56 |
+ return(as.logical(len)) |
|
57 |
+} |
|
58 |
+ |
|
59 |
+#' Create return data for MS backends not supporting chromatographic data. This |
|
60 |
+#' function is supposed to be called by the chromatogram(s) methods for these |
|
61 |
+#' backends |
|
62 |
+#' |
|
63 |
+#' @author Johannes Rainer |
|
64 |
+#' |
|
65 |
+#' @noRd |
|
66 |
+.empty_chromatogram <- function() { |
|
67 |
+ list() |
|
68 |
+} |
|
69 |
+ |
|
70 |
+#' Create return data for MS backends not supporting chromatographic data. |
|
71 |
+#' |
|
72 |
+#' @author Johannes Rainer |
|
73 |
+#' |
|
74 |
+#' @noRd |
|
75 |
+.empty_chromatogram_header <- function() { |
|
76 |
+ cn <- c("chromatogramId", "chromatogramIndex", "polarity", |
|
77 |
+ "precursorIsolationWindowTargetMZ", |
|
78 |
+ "precursorIsolationWindowLowerOffset", |
|
79 |
+ "precursorIsolationWindowUpperOffset", |
|
80 |
+ "precursorCollisionEnergy", "productIsolationWindowTargetMZ", |
|
81 |
+ "productIsolationWindowLowerOffset", |
|
82 |
+ "productIsolationWindowUpperOffset") |
|
83 |
+ data.frame(matrix(nrow = 0, ncol = length(cn), |
|
84 |
+ dimnames = list(character(), cn))) |
|
85 |
+} |
|
86 |
+ |
|
87 |
+.hasChromatograms <- function(x) { |
|
88 |
+ close_after <- FALSE |
|
89 |
+ if (is.character(x) && file.exists(x)) { |
|
90 |
+ x <- mzR::openMSfile(x) |
|
91 |
+ close_after <- TRUE |
|
92 |
+ } |
|
48 | 93 |
stopifnot(inherits(x, "mzR")) |
49 |
- return(as.logical(length(x))) |
|
94 |
+ hdr <- chromatogramHeader(x) |
|
95 |
+ if (close_after) |
|
96 |
+ close(x) |
|
97 |
+ as.logical(nrow(hdr)) |
|
50 | 98 |
} |
... | ... |
@@ -40,3 +40,11 @@ setMethod("isolationWindow", "character", |
40 | 40 |
x <- lapply(x, base::unique) |
41 | 41 |
any(sapply(x, function(xx) nrow(xx) > 1)) |
42 | 42 |
} |
43 |
+ |
|
44 |
+ |
|
45 |
+.hasSpectra <- function(x) { |
|
46 |
+ if (is.character(x) & file.exists(x)) |
|
47 |
+ x <- mzR::openMSfile(x) |
|
48 |
+ stopifnot(inherits(x, "mzR")) |
|
49 |
+ return(as.logical(length(x))) |
|
50 |
+} |
From: Laurent <lg390@cam.ac.uk>
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@125207 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -1,3 +1,16 @@ |
1 |
+.peaks <- function(object, scans) { |
|
2 |
+ if (missing(scans)) |
|
3 |
+ scans <- 1:length(object) |
|
4 |
+ if (length(scans) == 1) { |
|
5 |
+ return(object@backend$getPeakList(scans)$peaks) |
|
6 |
+ } else { |
|
7 |
+ return(sapply(scans, |
|
8 |
+ function(x) object@backend$getPeakList(x)$peaks, |
|
9 |
+ simplify = FALSE)) |
|
10 |
+ } |
|
11 |
+} |
|
12 |
+ |
|
13 |
+ |
|
1 | 14 |
setMethod("isolationWindow", "character", |
2 | 15 |
function(object, ...) .isolationWindow(object, ...)) |
3 | 16 |
|
From: Laurent <lg390@cam.ac.uk>
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@121322 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,29 @@ |
1 |
+setMethod("isolationWindow", "character", |
|
2 |
+ function(object, ...) .isolationWindow(object, ...)) |
|
3 |
+ |
|
4 |
+ |
|
5 |
+.isolationWindow <- function(x, unique. = TRUE, simplify = TRUE) { |
|
6 |
+ stopifnot(all(file.exists(x))) |
|
7 |
+ if (!requireNamespace("XML")) |
|
8 |
+ stop("Please install the XML package to use this functionality.") |
|
9 |
+ res <- lapply(x, function(xx) { |
|
10 |
+ xml <- XML::xmlParse(xx) |
|
11 |
+ ns <- c(x = "http://psi.hupo.org/ms/mzml") |
|
12 |
+ path <- c(low = "//x:isolationWindow/x:cvParam[@accession='MS:1000828']/@value", |
|
13 |
+ high = "//x:isolationWindow/x:cvParam[@accession='MS:1000829']/@value") |
|
14 |
+ low <- as.numeric(XML::xpathSApply(xml, path["low"], namespaces = ns)) |
|
15 |
+ high <- as.numeric(XML::xpathSApply(xml, path["high"], namespaces = ns)) |
|
16 |
+ cbind(low, high) |
|
17 |
+ }) |
|
18 |
+ if (.multipleIsolationWindows(res)) |
|
19 |
+ message("Found multiple isolation windows in an acquisition.") |
|
20 |
+ if (unique.) |
|
21 |
+ res <- lapply(res, base::unique) |
|
22 |
+ if (simplify & length(x) == 1) res <- res[[1]] |
|
23 |
+ return(res) |
|
24 |
+} |
|
25 |
+ |
|
26 |
+.multipleIsolationWindows <- function(x) { |
|
27 |
+ x <- lapply(x, base::unique) |
|
28 |
+ any(sapply(x, function(xx) nrow(xx) > 1)) |
|
29 |
+} |