R/process-peakFilter.R

Defines functions peakFilter.freq peakFilter.method

Documented in peakFilter.freq

#### Peak filtering methods ####
## ---------------------------

setMethod("peakFilter", "MSImageSet",
	function(object, method = "freq", ...)
	{
		.Deprecated_Cardinal1()
		if ( !centroided(object) )
			.stop("peakFilter: 'object' is not centroided. Run 'peakAlign' on it first.")
		fun <- peakFilter.method(method)
		.message("peakFilter: Using method = ", match.method(method))
		.time.start()
		feature <- featureApply(object, .fun=fun, ...,
			.use.names=FALSE, .simplify=TRUE)
		object <- object[feature,]
		.message("peakFilter: Done.")
		.time.stop()
		object
	})

peakFilter.method <- function(method, name.only=FALSE) {
	if ( is.character(method) || is.null(method) ) {
		options <- "freq"
		method <- match.method(method, options)
		if ( name.only )
			return(method)
		method <- switch(method,
			freq = peakFilter.freq,
			match.fun(method))
	}
	match.fun(method)
}

peakFilter.freq <- function(x, freq.min=0.01, ...) {
	if ( freq.min >= 1 ) {
		warning("freq.min >= 1 detected; assuming count")
		freq.min <- freq.min / length(x)
	}
	(sum(x > 0) / length(x)) > freq.min
}

Try the Cardinal package in your browser

Any scripts or data that you put into this service are public.

Cardinal documentation built on Nov. 8, 2020, 11:10 p.m.