Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using sparse matrix #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion NAMESPACE
@@ -1,5 +1,12 @@
import("methods")

importFrom("Matrix",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Matrix to Depends in the DESCRIPTION file to make R CMD check working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll do! Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've committed the fixed DESCRIPTION file.

"t",
"Matrix",
"sparseMatrix",
"colSums",
"colMeans")

importFrom("parallel",
"mclapply",
"mcmapply")
Expand All @@ -9,7 +16,7 @@ importFrom("graphics",
"arrows",
"lines",
"par",
"plot.default",
"plot.default",
"points",
"rasterImage",
"rect",
Expand Down
15 changes: 7 additions & 8 deletions R/as.matrix-functions.R
Expand Up @@ -18,9 +18,9 @@

i <- findInterval(mass, uniqueMass)

m <- matrix(NA_real_, nrow=length(l), ncol=length(uniqueMass),
dimnames=list(NULL, uniqueMass))
m[cbind(r, i)] <- intensity
m <- sparseMatrix(i = r, j = i, x = intensity,
dims = c(length(l), length(uniqueMass)),
dimnames = list(NULL, uniqueMass))
attr(m, "mass") <- uniqueMass
m
}
Expand All @@ -34,10 +34,9 @@
## returns:
## a binary matrix
.as.binary.matrix <- function(m) {
stopifnot(is.matrix(m))
isNA <- which(is.na(m))
m[] <- 1L
m[isNA] <- 0L
mode(m) <- "integer"
stopifnot(is.matrix(m) | is(m, 'sparseMatrix'))
mass <- attr(m, 'mass')
m[m != 0] <- 1
attr(m, 'mass') <- mass
m
}
4 changes: 2 additions & 2 deletions R/filterPeaks-functions.R
Expand Up @@ -55,7 +55,7 @@ filterPeaks <- function(l, minFrequency, minNumber, labels,
m <- .as.binary.matrix(.as.matrix.MassObjectList(l))

## whitelist
w <- matrix(0L, nrow=nrow(m), ncol=ncol(m))
w <- Matrix(nrow = nrow(m), ncol = ncol(m), data = 0, sparse = TRUE)

## group indices by labels
idx <- lapply(ll, function(x)which(labels == x))
Expand Down Expand Up @@ -131,5 +131,5 @@ filterPeaks <- function(l, minFrequency, minNumber, labels,
## calculate minimal number of peaks
minPeakNumber <- max(minFrequency * length(rows), minNumber, na.rm=TRUE)

colSums(m[rows, , drop=FALSE]) >= minPeakNumber
colSums(m[rows, , drop = FALSE]) >= minPeakNumber
}