Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 3d4f73f

Browse files
authored
Merge pull request #72 from sgibb/occurrence-list
Reduced memory requirement for filterPeaks; closes #71
2 parents b1ca2ff + f817438 commit 3d4f73f

9 files changed

Lines changed: 191 additions & 160 deletions

File tree

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
^CRAN-RELEASE$
1010
^cran-comments.md$
1111
^\.github$
12+
^.*\.Rproj$
13+
^\.Rproj\.user$

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.o
44
*.rds
55
CRAN-RELEASE
6+
.Rproj.user
7+
.Rproj

DESCRIPTION

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
Package: MALDIquant
2-
Version: 1.20
2+
Version: 1.20.0.9999
33
Date: 2021-07-29
44
Title: Quantitative Analysis of Mass Spectrometry Data
5-
Authors@R: c(person("Sebastian", "Gibb", role=c("aut", "cre"),
5+
Authors@R: c(
6+
person(
7+
given = "Sebastian", family = "Gibb",
68
email="mail@sebastiangibb.de",
7-
comment=c(ORCID="0000-0001-7406-4443")), person("Korbinian",
8-
"Strimmer", role="ths",
9-
comment=c(ORCID="0000-0001-7917-2056")))
9+
comment=c(ORCID="0000-0001-7406-4443"),
10+
role = c("aut", "cre")
11+
),
12+
person(
13+
given = "Korbinian", family = "Strimmer",
14+
comment=c(ORCID="0000-0001-7917-2056"),
15+
role="ths"
16+
),
17+
person(given = "Sigurdur", family = "Smarason", role = "ctb"),
18+
person(
19+
given = "Laurent", family = "Gatto",
20+
email = "laurent.gatto@uclouvain.be",
21+
comment = c(ORCID = "0000-0002-1520-2268"),
22+
role = "ctb"
23+
),
24+
person(given = "Paolo", "family = Inglese", role = "ctb"))
1025
Depends: R (>= 4.0.0), methods
1126
Imports: parallel
1227
Suggests: knitr, testthat (>= 0.8)
@@ -26,4 +41,4 @@ URL: https://www.strimmerlab.org/software/maldiquant/
2641
BugReports: https://github.com/sgibb/MALDIquant/issues/
2742
LazyLoad: yes
2843
VignetteBuilder: knitr
29-
RoxygenNote: 7.1.1
44+
RoxygenNote: 7.1.2

NEWS

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
RELEASE HISTORY OF THE "MALDIquant" PACKAGE
22
===========================================
33

4+
CHANGES IN MALDIquant VERSION 1.20.0.9999 [unreleased]:
5+
-------------------------------------------------------
6+
7+
MODIFICATIONS
8+
9+
* Reduce memory requirement for `filterPeaks`, especially for very sparse peak
10+
lists by rewriting `filterPeaks` and `.as.matrix.MassObjectList` to use a
11+
`list` internally instead of a `matrix`; see #71.
12+
Contributed by Paolo Inglese <p.inglese@outlook.com> (@paoloinglese).
13+
14+
INTERNAL CHANGES
15+
16+
* Remove `is.null(getGeneric(...))` tests before setting generics for
17+
S4 methods to avoid errors in package loading (especially with
18+
`pkgload::load_all()`).
19+
20+
421
CHANGES IN MALDIquant VERSION 1.20 [2021-07-29]:
522
------------------------------------------------
623

R/AllGenerics.R

Lines changed: 67 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,79 @@
11
## AbstractMassObject
2-
if (is.null(getGeneric("plotMsiSlice"))) {
3-
setGeneric("plotMsiSlice", function(x, ...) standardGeneric("plotMsiSlice"))
4-
}
5-
if (is.null(getGeneric(".prepareShow"))) {
6-
setGeneric(".prepareShow", function(object) standardGeneric(".prepareShow"))
7-
}
8-
if (is.null(getGeneric("transformIntensity"))) {
9-
setGeneric("transformIntensity",
10-
function(object, ...) standardGeneric("transformIntensity"))
11-
}
12-
if (is.null(getGeneric(".transformIntensity"))) {
13-
setGeneric(".transformIntensity",
14-
function(object, ...) standardGeneric(".transformIntensity"))
15-
}
16-
if (is.null(getGeneric("trim"))) {
17-
setGeneric("trim", function(object, range, ...) standardGeneric("trim"))
18-
}
2+
setGeneric("plotMsiSlice", function(x, ...) standardGeneric("plotMsiSlice"))
3+
setGeneric(".prepareShow", function(object) standardGeneric(".prepareShow"))
4+
setGeneric(
5+
"transformIntensity",
6+
function(object, ...) standardGeneric("transformIntensity")
7+
)
8+
setGeneric(
9+
".transformIntensity",
10+
function(object, ...) standardGeneric(".transformIntensity")
11+
)
12+
setGeneric("trim", function(object, range, ...) standardGeneric("trim"))
1913

2014
## get/set slots
21-
if (is.null(getGeneric("mass"))) {
22-
setGeneric("mass", function(object, ...) standardGeneric("mass"))
23-
}
24-
if (is.null(getGeneric("mass<-"))) {
25-
setGeneric("mass<-", function(object, value) standardGeneric("mass<-"))
26-
}
15+
setGeneric("mass", function(object, ...) standardGeneric("mass"))
16+
setGeneric("mass<-", function(object, value) standardGeneric("mass<-"))
17+
2718
# from ProtGenerics (same as mass)
28-
if (is.null(getGeneric("mz"))) {
29-
setGeneric("mz", function(object, ...) standardGeneric("mz"))
30-
}
31-
if (is.null(getGeneric("mz<-"))) {
32-
setGeneric("mz<-", function(object, value) standardGeneric("mz<-"))
33-
}
34-
if (is.null(getGeneric("intensity"))) {
35-
setGeneric("intensity", function(object, ...) standardGeneric("intensity"))
36-
}
37-
if (is.null(getGeneric("intensity<-"))) {
38-
setGeneric("intensity<-",
39-
function(object, value) standardGeneric("intensity<-"))
40-
}
41-
if (is.null(getGeneric("isEmpty"))) {
42-
setGeneric("isEmpty", function(x) standardGeneric("isEmpty"))
43-
}
44-
if (is.null(getGeneric(".isEmptyWarning"))) {
45-
setGeneric(".isEmptyWarning", function(x) standardGeneric(".isEmptyWarning"))
46-
}
47-
if (is.null(getGeneric("metaData"))) {
48-
setGeneric("metaData", function(object) standardGeneric("metaData"))
49-
}
50-
if (is.null(getGeneric("metaData<-"))) {
51-
setGeneric("metaData<-",
52-
function(object, value) standardGeneric("metaData<-"))
53-
}
54-
if (is.null(getGeneric("coordinates"))) {
55-
setGeneric("coordinates",
56-
function(object, ...) standardGeneric("coordinates"))
57-
}
58-
if (is.null(getGeneric("coordinates<-"))) {
59-
setGeneric("coordinates<-",
60-
function(object, value) standardGeneric("coordinates<-"))
61-
}
19+
setGeneric("mz", function(object, ...) standardGeneric("mz"))
20+
setGeneric("mz<-", function(object, value) standardGeneric("mz<-"))
6221

22+
setGeneric("intensity", function(object, ...) standardGeneric("intensity"))
23+
setGeneric(
24+
"intensity<-",
25+
function(object, value) standardGeneric("intensity<-")
26+
)
27+
setGeneric("isEmpty", function(x) standardGeneric("isEmpty"))
28+
setGeneric(".isEmptyWarning", function(x) standardGeneric(".isEmptyWarning"))
29+
setGeneric("metaData", function(object) standardGeneric("metaData"))
30+
setGeneric("metaData<-", function(object, value) standardGeneric("metaData<-"))
31+
setGeneric("coordinates", function(object, ...) standardGeneric("coordinates"))
32+
setGeneric(
33+
"coordinates<-",
34+
function(object, value) standardGeneric("coordinates<-")
35+
)
6336
## end of AbstractMassObject
6437

6538
## MassSpectrum
66-
if (is.null(getGeneric("calibrateIntensity"))) {
67-
setGeneric("calibrateIntensity",
68-
function(object, ...) standardGeneric("calibrateIntensity"))
69-
}
70-
if (is.null(getGeneric("detectPeaks"))) {
71-
setGeneric("detectPeaks",
72-
function(object, ...) standardGeneric("detectPeaks"))
73-
}
74-
if (is.null(getGeneric("estimateBaseline"))) {
75-
setGeneric("estimateBaseline",
76-
function(object, method=c("SNIP", "ConvexHull", "Median"), ...)
77-
standardGeneric("estimateBaseline"))
78-
}
79-
if (is.null(getGeneric("estimateNoise"))) {
80-
setGeneric("estimateNoise",
81-
function(object, ...) standardGeneric("estimateNoise"))
82-
}
83-
if (is.null(getGeneric(".findLocalMaxima"))) {
84-
setGeneric(".findLocalMaxima",
85-
function(object, halfWindowSize=20L)
86-
standardGeneric(".findLocalMaxima"))
87-
}
88-
if (is.null(getGeneric(".findLocalMaximaLogical"))) {
89-
setGeneric(".findLocalMaximaLogical",
90-
function(object, halfWindowSize=20L)
91-
standardGeneric(".findLocalMaximaLogical"))
92-
}
93-
if (is.null(getGeneric("isRegular"))) {
94-
setGeneric("isRegular",
95-
function(object, ...) standardGeneric("isRegular"))
96-
}
97-
if (is.null(getGeneric("removeBaseline"))) {
98-
setGeneric("removeBaseline",
99-
function(object, ...) standardGeneric("removeBaseline"))
100-
}
101-
if (is.null(getGeneric("smoothIntensity"))) {
102-
setGeneric("smoothIntensity",
103-
function(object, ...)
104-
standardGeneric("smoothIntensity"))
105-
}
106-
if (is.null(getGeneric("totalIonCurrent"))) {
107-
setGeneric("totalIonCurrent",
108-
function(object) standardGeneric("totalIonCurrent"))
109-
}
39+
setGeneric(
40+
"calibrateIntensity",
41+
function(object, ...) standardGeneric("calibrateIntensity")
42+
)
43+
setGeneric("detectPeaks", function(object, ...) standardGeneric("detectPeaks"))
44+
setGeneric(
45+
"estimateBaseline",
46+
function(object, method=c("SNIP", "ConvexHull", "Median"), ...)
47+
standardGeneric("estimateBaseline"))
48+
setGeneric(
49+
"estimateNoise", function(object, ...) standardGeneric("estimateNoise")
50+
)
51+
setGeneric(
52+
".findLocalMaxima",
53+
function(object, halfWindowSize=20L) standardGeneric(".findLocalMaxima")
54+
)
55+
setGeneric(
56+
".findLocalMaximaLogical",
57+
function(object, halfWindowSize=20L)
58+
standardGeneric(".findLocalMaximaLogical")
59+
)
60+
setGeneric("isRegular", function(object, ...) standardGeneric("isRegular"))
61+
setGeneric(
62+
"removeBaseline", function(object, ...) standardGeneric("removeBaseline")
63+
)
64+
setGeneric(
65+
"smoothIntensity", function(object, ...) standardGeneric("smoothIntensity")
66+
)
67+
setGeneric(
68+
"totalIonCurrent", function(object) standardGeneric("totalIonCurrent")
69+
)
11070
## end of MassSpectrum
11171

11272
## MassPeaks
113-
if (is.null(getGeneric("labelPeaks"))) {
114-
setGeneric("labelPeaks", function(object, ...) standardGeneric("labelPeaks"))
115-
}
116-
if (is.null(getGeneric("monoisotopicPeaks"))) {
117-
setGeneric("monoisotopicPeaks",
118-
function(object, ...) standardGeneric("monoisotopicPeaks"))
119-
}
120-
if (is.null(getGeneric("snr"))) {
121-
setGeneric("snr", function(object) standardGeneric("snr"))
122-
}
73+
setGeneric("labelPeaks", function(object, ...) standardGeneric("labelPeaks"))
74+
setGeneric(
75+
"monoisotopicPeaks",
76+
function(object, ...) standardGeneric("monoisotopicPeaks")
77+
)
78+
setGeneric("snr", function(object) standardGeneric("snr"))
12379
## end of MassPeaks

R/as.list-functions.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## .as.occurrence.list
2+
## internal function to create a list of peaks occurrence
3+
##
4+
## params:
5+
## l: list of AbstractMassObject objects
6+
##
7+
## returns:
8+
## a list, where sample is the sample id, i is the index of the uniqueMass,
9+
## and mass is the unique mass vector
10+
.as.occurrence.list.MassObjectList <- function(l) {
11+
.stopIfNotIsMassObjectList(l)
12+
13+
mass <- .unlist(lapply(l, function(x)x@mass))
14+
uniqueMass <- sort.int(unique(mass))
15+
n <- lengths(l)
16+
17+
list(
18+
sample = rep.int(seq_along(l), lengths(l)),
19+
i = findInterval(mass, uniqueMass),
20+
mass = uniqueMass
21+
)
22+
}

R/as.matrix-functions.R

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@
88
## returns:
99
## a matrix
1010
.as.matrix.MassObjectList <- function(l) {
11-
.stopIfNotIsMassObjectList(l)
11+
.stopIfNotIsMassObjectList(l)
1212

13-
mass <- .unlist(lapply(l, function(x)x@mass))
14-
intensity <- .unlist(lapply(l, function(x)x@intensity))
15-
uniqueMass <- sort.int(unique(mass))
16-
n <- lengths(l)
17-
r <- rep.int(seq_along(l), n)
13+
intensity <- .unlist(lapply(l, function(x)x@intensity))
14+
o <- .as.occurrence.list.MassObjectList(l)
1815

19-
i <- findInterval(mass, uniqueMass)
20-
21-
m <- matrix(NA_real_, nrow=length(l), ncol=length(uniqueMass),
22-
dimnames=list(NULL, uniqueMass))
23-
m[cbind(r, i)] <- intensity
24-
attr(m, "mass") <- uniqueMass
25-
m
16+
m <- matrix(
17+
NA_real_, nrow=length(l), ncol=length(o$mass),
18+
dimnames=list(NULL, o$mass)
19+
)
20+
m[cbind(o$sample, o$i)] <- intensity
21+
attr(m, "mass") <- o$mass
22+
m
2623
}
2724

2825
## .as.binary.matrix
@@ -34,10 +31,9 @@
3431
## returns:
3532
## a binary matrix
3633
.as.binary.matrix <- function(m) {
37-
stopifnot(is.matrix(m))
38-
isNA <- which(is.na(m))
39-
m[] <- 1L
40-
m[isNA] <- 0L
41-
mode(m) <- "integer"
42-
m
34+
if (!is.matrix(m))
35+
stop("'x' has to be a matrix!")
36+
m[] <- !is.na(m)
37+
mode(m) <- "integer"
38+
m
4339
}

0 commit comments

Comments
 (0)