Skip to content

Commit

Permalink
Fix issue #359
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Mar 15, 2019
1 parent 09efc7a commit 5a346a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
40 changes: 20 additions & 20 deletions R/do_groupChromPeaks-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
##' @note The default settings might not be appropriate for all LC/GC-MS setups,
##' especially the \code{bw} and \code{binSize} parameter should be adjusted
##' accordingly.
##'
##'
##' @param peaks A \code{matrix} or \code{data.frame} with the mz values and
##' retention times of the identified chromatographic peaks in all samples of an
##' experiment. Required columns are \code{"mz"}, \code{"rt"} and
Expand Down Expand Up @@ -82,7 +82,7 @@ do_groupChromPeaks_density <- function(peaks, sampleGroups,
"assignment of the samples.")
if (missing(peaks))
stop("Parameter 'peaks' is missing!")
if (!is.matrix(peaks) | is.data.frame(peaks))
if (!(is.matrix(peaks) | is.data.frame(peaks)))
stop("'peaks' has to be a 'matrix' or a 'data.frame'!")
## Check that we've got all required columns
.reqCols <- c("mz", "rt", "sample")
Expand All @@ -102,7 +102,7 @@ do_groupChromPeaks_density <- function(peaks, sampleGroups,
if (max(peaks[, "sample"]) > length(sampleGroups))
stop("Sample indices in 'peaks' are larger than there are sample",
" groups specified with 'sampleGroups'!")

## Order peaks matrix by mz
peakOrder <- order(peaks[, "mz"])
peaks <- peaks[peakOrder, .reqCols, drop = FALSE]
Expand Down Expand Up @@ -190,7 +190,7 @@ do_groupChromPeaks_density <- function(peaks, sampleGroups,
}
}
message("OK")

colnames(groupmat) <- c("mzmed", "mzmin", "mzmax", "rtmed", "rtmin", "rtmax",
"npeaks", sampleGroupNames)

Expand Down Expand Up @@ -223,7 +223,7 @@ do_groupChromPeaks_density_par <- function(peaks, sampleGroups,
"assignment of the samples.")
if (missing(peaks))
stop("Parameter 'peaks' is missing!")
if (!is.matrix(peaks) | is.data.frame(peaks))
if (!(is.matrix(peaks) | is.data.frame(peaks)))
stop("Peaks has to be a 'matrix' or a 'data.frame'!")
## Check that we've got all required columns
.reqCols <- c("mz", "rt", "sample")
Expand Down Expand Up @@ -310,7 +310,7 @@ do_groupChromPeaks_density_par <- function(peaks, sampleGroups,
## Now we have to process that list of results.
groupmat <- do.call(rbind, lapply(res, function(z) z[["grps"]]))
groupidx <- unlist(lapply(res, function(z) z[["idx"]]), recursive = FALSE)

colnames(groupmat) <- c("mzmed", "mzmin", "mzmax", "rtmed", "rtmin", "rtmax",
"npeaks", sampleGroupNames)

Expand All @@ -335,11 +335,11 @@ do_groupChromPeaks_density_par <- function(peaks, sampleGroups,
##'
##' @description The \code{do_groupPeaks_mzClust} function performs high
##' resolution correspondence on single spectra samples.
##'
##'
##' @inheritParams groupChromPeaks-density
##' @inheritParams do_groupChromPeaks_density
##' @inheritParams groupChromPeaks-mzClust
##'
##'
##' @return A \code{list} with elements \code{"featureDefinitions"} and
##' \code{"peakIndex"}. \code{"featureDefinitions"} is a \code{matrix}, each row
##' representing an (mz-rt) feature (i.e. peak group) with columns:
Expand Down Expand Up @@ -372,7 +372,7 @@ do_groupPeaks_mzClust <- function(peaks, sampleGroups, ppm = 20,
"assignment of the samples.")
if (missing(peaks))
stop("Parameter 'peaks' is missing!")
if (!is.matrix(peaks) | is.data.frame(peaks))
if (!(is.matrix(peaks) | is.data.frame(peaks)))
stop("Peaks has to be a 'matrix' or a 'data.frame'!")
## Check that we've got all required columns
.reqCols <- c("mz", "sample")
Expand All @@ -386,7 +386,7 @@ do_groupPeaks_mzClust <- function(peaks, sampleGroups, ppm = 20,
sampleGroupTable <- table(sampleGroups)
nSampleGroups <- length(sampleGroupTable)
##sampleGroups <- as.numeric(sampleGroups)

## Check that sample groups matches with sample column.
if (max(peaks[, "sample"]) > length(sampleGroups))
stop("Sample indices in 'peaks' are larger than there are sample",
Expand All @@ -411,7 +411,7 @@ do_groupPeaks_mzClust <- function(peaks, sampleGroups, ppm = 20,
grpmat[, 4:ncol(grpmat), drop = FALSE])
colnames(grpmat) <- c(cns[1:3], c("rtmed", "rtmin", "rtmax"),
cns[4:length(cns)])
return(list(featureDefinitions = grpmat, peakIndex = grps$idx))
return(list(featureDefinitions = grpmat, peakIndex = grps$idx))
}

##' @title Core API function for chromatic peak grouping using a nearest
Expand All @@ -421,10 +421,10 @@ do_groupPeaks_mzClust <- function(peaks, sampleGroups, ppm = 20,
##' across samples by creating a master peak list and assigning corresponding
##' peaks from all samples to each peak group (i.e. feature). The method is
##' inspired by the correspondence algorithm of mzMine [Katajamaa 2006].
##'
##'
##' @inheritParams do_groupChromPeaks_density
##' @inheritParams groupChromPeaks-nearest
##'
##'
##' @return A \code{list} with elements \code{"featureDefinitions"} and
##' \code{"peakIndex"}. \code{"featureDefinitions"} is a \code{matrix}, each row
##' representing an (mz-rt) feature (i.e. peak group) with columns:
Expand All @@ -444,7 +444,7 @@ do_groupPeaks_mzClust <- function(peaks, sampleGroups, ppm = 20,
##'
##' @references Katajamaa M, Miettinen J, Oresic M: MZmine: Toolbox for
##' processing and visualization of mass spectrometry based molecular profile
##' data. \emph{Bioinformatics} 2006, 22:634-636.
##' data. \emph{Bioinformatics} 2006, 22:634-636.
do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
absMz = 0.2, absRt = 15, kNN = 10) {
if (missing(sampleGroups))
Expand All @@ -453,7 +453,7 @@ do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
"assignment of the samples.")
if (missing(peaks))
stop("Parameter 'peaks' is missing!")
if (!is.matrix(peaks) | is.data.frame(peaks))
if (!(is.matrix(peaks) | is.data.frame(peaks)))
stop("Peaks has to be a 'matrix' or a 'data.frame'!")
## Check that we've got all required columns
.reqCols <- c("mz", "rt", "sample")
Expand All @@ -472,7 +472,7 @@ do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
## peaks == peakmat

peaks <- peaks[, .reqCols, drop = FALSE]

parameters <- list(mzVsRTBalance = mzVsRtBalance, mzcheck = absMz,
rtcheck = absRt, knn = kNN)

Expand Down Expand Up @@ -514,7 +514,7 @@ do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
)
if (length(mplenv$peakIdxList$peakidx) == 0)
message("Warning: No peaks in sample number ", sample)

## this really doesn't take a long time not worth parallel version here.
## but make an apply loop now faster even with rearranging the data :D : PB
scoreList <- sapply(mplenv$peakIdxList$peakidx,
Expand Down Expand Up @@ -553,7 +553,7 @@ do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
}
}
notJoinedPeaks <- mplenv$peakIdxList[which(mplenv$peakIdxList$isJoinedPeak == FALSE), "peakidx"]

for (notJoinedPeak in notJoinedPeaks) {
mplenv$mplist <- rbind(mplenv$mplist,
matrix(0, 1, dim(mplenv$mplist)[2]))
Expand Down Expand Up @@ -593,6 +593,6 @@ do_groupChromPeaks_nearest <- function(peaks, sampleGroups, mzVsRtBalance = 10,
## groupmat[i, 7 + seq(along = gcount)] <- gcount
groupindex[[i]] <- mplenv$mplist[i, (which(mplenv$mplist[i,]>0))]
}
return(list(featureDefinitions = groupmat, peakIndex = groupindex))

return(list(featureDefinitions = groupmat, peakIndex = groupindex))
}
1 change: 1 addition & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Changes in version 3.4.4

- Fix issue #349: dropChromPeaks fails if no retention time adjustment process
history is present.
- Fix issue #359.


Changes in version 3.4.2
Expand Down

0 comments on commit 5a346a3

Please sign in to comment.