ProtGenerics/DESCRIPTION0000644000175100017510000000150014614351015015700 0ustar00biocbuildbiocbuildPackage: ProtGenerics Title: Generic infrastructure for Bioconductor mass spectrometry packages Description: S4 generic functions and classes needed by Bioconductor proteomics packages. Version: 1.36.0 Author: Laurent Gatto , Johannes Rainer Maintainer: Laurent Gatto biocViews: Infrastructure, Proteomics, MassSpectrometry URL: https://github.com/RforMassSpectrometry/ProtGenerics Depends: methods Suggests: testthat License: Artistic-2.0 NeedsCompilation: no RoxygenNote: 7.3.1 git_url: https://git.bioconductor.org/packages/ProtGenerics git_branch: RELEASE_3_19 git_last_commit: f1a8d20 git_last_commit_date: 2024-04-30 Repository: Bioconductor 3.19 Date/Publication: 2024-04-30 Packaged: 2024-05-01 05:24:29 UTC; biocbuild ProtGenerics/man/0000755000175100017510000000000014614306144014754 5ustar00biocbuildbiocbuildProtGenerics/man/backendInitialize.Rd0000644000175100017510000000202114614306144020647 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/protgenerics.R \name{backendInitialize} \alias{backendInitialize} \alias{isReadOnly} \alias{setBackend} \alias{backendMerge} \alias{backendBpparam} \alias{backendParallelFactor} \alias{supportsSetBackend} \title{General backend methods} \usage{ backendInitialize(object, ...) isReadOnly(object) setBackend(object, backend, ...) backendMerge(object, ...) backendBpparam(object, ...) backendParallelFactor(object, ...) supportsSetBackend(object, ...) } \arguments{ \item{object}{The \emph{backend} object.} \item{...}{Optional parameters.} \item{backend}{A \emph{backend} object.} } \description{ These methods are used for implementations of \emph{backends} e.g. for \code{Spectra} or \code{Chromatograms} object to initialize the backend, merge backends or extract specific information from them. See the respective help pages (e.g. in the \code{Spectra} or \code{Chromatograms} packages) for information on the actual implementations of these methods. } ProtGenerics/man/filterFeatures.Rd0000644000175100017510000000105614614306144020231 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/protgenerics.R \name{filterFeatures} \alias{filterFeatures} \title{Filter features} \usage{ filterFeatures(object, filter, ...) } \arguments{ \item{object}{The object to filter.} \item{filter}{The filtering criteria on which \code{object} should be filtered.} \item{...}{Optional parameters.} } \description{ Implementations of this generic filter function are supposed to filter \emph{features} in \code{object} based on a filter criteria defined by parameter \code{filter}. } ProtGenerics/man/filterSpectra.Rd0000644000175100017510000000110414614306144020046 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/protgenerics.R \name{filterSpectra} \alias{filterSpectra} \title{Filter Spectra} \usage{ filterSpectra(object, filter, ...) } \arguments{ \item{object}{The object to filter.} \item{filter}{The filtering criteria based on which \code{object} should be filtered.} \item{...}{Optional parameters.} } \description{ Implementations of this generic filter function are supposed to filter \emph{spectra} (e.g. within a \code{Spectra} object) based on filter criteria defined with parameter \code{filter}. } ProtGenerics/man/Param.Rd0000644000175100017510000000177514614306144016315 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/DataClasses.R \docType{class} \name{Param} \alias{Param} \alias{Param-class} \alias{as.list,Param-method} \alias{show,Param-method} \title{Generic parameter class} \usage{ \S4method{as.list}{Param}(x, ...) \S4method{show}{Param}(object) } \arguments{ \item{x}{`Param` object.} \item{...}{ignored.} \item{object}{`Param` object.} } \description{ The `Param` class is a virtual class which can be used as *base* class from which *parameter* classes can inherit. The methods implemented for the `Param` class are: - `as.list`: coerces the `Param` class to a `list` with list elements representing the object's slot values, names the slot names. *Hidden* slots (i.e. those with a name starting with `.`) are not returned. In addition, a `Param` class can be coerced to a `list` using `as(object, "list")`. - `show`: prints the content of the `Param` object (i.e. the individual slots and their value). } \author{ Johannes Rainer } ProtGenerics/man/peaksData.Rd0000644000175100017510000000127414614306144017144 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/protgenerics.R \name{peaksData} \alias{peaksData} \alias{peaksData<-} \alias{peaksVariables} \title{Get or set MS peak data} \usage{ peaksData(object, ...) peaksData(object) <- value peaksVariables(object, ...) } \arguments{ \item{object}{A data object.} \item{...}{Optional parameters.} \item{value}{Replacement for peaks data.} } \description{ These methods get or set mass spectrometry (MS) peaks data, which can be m/z, intensity or retention time values. See the respective help pages (e.g. in the \code{Spectra} or \code{Chromatograms} packages) for information on the actual implementations of these methods. } ProtGenerics/man/ProcessingStep.Rd0000644000175100017510000000302014614306144020206 0ustar00biocbuildbiocbuild% Generated by roxygen2: do not edit by hand % Please edit documentation in R/ProcessingStep.R \name{ProcessingStep} \alias{ProcessingStep} \alias{ProcessingStep-class} \alias{characterOrFunction-class} \alias{show,ProcessingStep-method} \alias{executeProcessingStep} \title{Processing step} \usage{ ProcessingStep(FUN = character(), ARGS = list()) \S4method{show}{ProcessingStep}(object) executeProcessingStep(object, ...) } \arguments{ \item{FUN}{\code{function} or \code{character} representing a function name.} \item{ARGS}{\code{list} of arguments to be passed along to \code{FUN}.} \item{object}{\code{ProcessingStep} object.} \item{...}{optional additional arguments to be passed along.} } \value{ The \code{ProcessingStep} function returns and object of type \code{ProcessingStep}. } \description{ Class containing the function and arguments to be applied in a lazy-execution framework. Objects of this class are created using the \code{ProcessingStep()} function. The processing step is executed with the \code{executeProcessingStep()} function. } \details{ This object contains all relevant information of a data analysis processing step, i.e. the function and all of its arguments to be applied to the data. This object is mainly used to record possible processing steps of a \code{Spectra} or \code{OnDiskMSnExp} object (from the \code{Spectra} and \code{MSnbase} packages, respectively). } \examples{ ## Create a simple processing step object ps <- ProcessingStep(sum) executeProcessingStep(ps, 1:10) } \author{ Johannes Rainer } ProtGenerics/man/protgenerics.Rd0000644000175100017510000001473414614306144017760 0ustar00biocbuildbiocbuild\name{ProtGenerics} \alias{ProtGenerics-package} \alias{ProtGenerics} \alias{psms} \alias{peaks} \alias{peaks<-} \alias{modifications} \alias{database} \alias{rtime} \alias{tic} \alias{spectra} \alias{spectra<-} \alias{ionCount} \alias{scanIndex} \alias{precursorMz} \alias{precursorIntensity} \alias{precursorCharge} \alias{precursorCharge<-} \alias{acquisitionNum} \alias{precAcquisitionNum} \alias{precScanNum} \alias{msLevel} \alias{uniqueMsLevels} \alias{collisionEnergy} \alias{polarity} \alias{intensity} \alias{mz} \alias{mz<-} \alias{combineFeatures} \alias{aggregateFeatures} \alias{impute} \alias{processingData} \alias{processingData<-} \alias{msInfo} \alias{expemail} \alias{exptitle} \alias{ionSource} \alias{ionSourceDetails} \alias{analyser} \alias{analyzer} \alias{analyzerDetails} \alias{analyserDetails} \alias{detectorType} \alias{instrumentManufacturer} \alias{instrumentCustomisations} \alias{smooth} \alias{centroided} \alias{centroided<-} \alias{smoothed} \alias{smoothed<-} \alias{instrumentModel} \alias{peptides} \alias{proteins} \alias{accessions} \alias{scans} \alias{mass} \alias{ions} \alias{chromatograms} \alias{chromatogram} \alias{isCentroided} \alias{writeMSData} \alias{isolationWindowTargetMz} \alias{isolationWindowTargetMz<-} \alias{isolationWindowLowerMz} \alias{isolationWindowLowerMz<-} \alias{isolationWindowUpperMz} \alias{isolationWindowUpperMz<-} \alias{intensity<-} \alias{precursorMz<-} \alias{precursorIntensity<-} \alias{msLevel<-} \alias{collisionEnergy<-} \alias{polarity<-} \alias{rtime<-} \alias{spectraNames} \alias{spectraNames<-} \alias{spectraData} \alias{spectraData<-} \alias{spectraVariables} \alias{dataOrigin} \alias{dataOrigin<-} \alias{dataStorage} \alias{dataStorage<-} \alias{productMz} \alias{productMz<-} \alias{filterAcquisitionNum} \alias{filterDataOrigin} \alias{filterDataStorage} \alias{filterEmptySpectra} \alias{filterIsolationWindow} \alias{filterMsLevel} \alias{filterPolarity} \alias{filterPrecursorMz} \alias{filterPrecursorMzRange} \alias{filterPrecursorMzValues} \alias{filterPrecursorCharge} \alias{filterProductMz} \alias{filterProductMzRange} \alias{filterProductMzValues} \alias{filterPrecursorScan} \alias{filterRt} \alias{filterMz} \alias{filterMzValues} \alias{filterMzRange} \alias{filterNA} \alias{tolerance} \alias{calculateFragments} \alias{compounds} \alias{filterIntensity} \alias{alignRt} \alias{quantify} \alias{bin} \alias{compareSpectra} \alias{compareChromatograms} \alias{adjacencyMatrix} \alias{addProcessing} \alias{spectrapply} \alias{filterRanges} \alias{filterValues} \title{ S4 generic functions for Bioconductor proteomics infrastructure } \description{ These generic functions provide basic interfaces to operations on and data access to proteomics and mass spectrometry infrastructure in the Bioconductor project. For the details, please consult the respective methods' manual pages. } \details{ \subsection{When should one define a generics?}{ Generics are appropriate for functions that have \emph{generic} names, i.e. names that occur in multiple circumstances, (with different input classes, most often defined in different packages) or, when (multiple) dispatching is better handled by the generics mechanism rather than the developer. The dispatching mechanism will then automatically call the appropriate method and save the user from explicitly calling \code{package::method} or the developer to handle the multiple input types cases. When no such conflict exists or is unlikely to happen (for example when the name of the function is specific to a package or domain, or for class slots accessors and replacement methods), the usage of a generic is arguably questionable, and in most of these cases, simple, straightforward functions would be perfectly valid. } \subsection{When to define a generic in \code{ProtGenerics}?}{ \code{ProtGenerics} is not meant to be the central package for generics, nor should it stop developers from defining the generics they need. It is a means to centralise generics that are defined in different packages (for example \code{mzR::psms} and \code{mzID::psms}, or \code{IRanges::score} and \code{mzR::score}, now \code{BioGenerics::score}) or generics that live in a rather big package (say \code{mzR}) on which one wouldn't want to depend just for the sake of that generics' definition. The goal of \code{ProtGenerics} is to step in when namespace conflicts arise so as to to facilitate inter-operability of packages. In case such conflict appears due to multiple generics, we would (1) add these same definitions in \code{ProtGenerics}, (2) remove the definitions from the packages they stem from, which then (3) only need to import \code{ProtGenerics}. This would be very minor/straightforward changes for the developers and would resolve issues when they arise. More generics can be added on request by opening an issue or sending a pull request on: \url{https://github.com/lgatto/ProtGenerics} } } \usage{ psms(object, ...) peaks(object, ...) modifications(object, ...) database(object, ...) rtime(object, ...) tic(object, ...) spectra(object, ...) intensity(object, ...) mz(object, ...) peptides(object, ...) proteins(object, ...) accessions(object, ...) scans(object, ...) mass(object, ...) ions(object, ...) chromatograms(object, ...) chromatogram(object, ...) isCentroided(object, ...) writeMSData(object, file, ...) ## and many more } \arguments{ \item{object}{Object of class for which methods are defined. } \item{file}{for \code{writeMSData}}: the name of the file to which the data should be exported. \item{\dots}{Further arguments, possibly used by downstream methods. } } \seealso{ \itemize{ \item The \pkg{BiocGenerics} package for S4 generic functions needed by many Bioconductor packages. \item \code{\link[methods]{showMethods}} for displaying a summary of the methods defined for a given generic function. \item \code{\link[methods]{selectMethod}} for getting the definition of a specific method. \item \code{\link[methods]{setGeneric}} and \code{\link[methods]{setMethod}} for defining generics and methods. } } \author{ Laurent Gatto } \examples{ ## List all the symbols defined in this package: ls('package:ProtGenerics') \dontrun{ ## What methods exists for 'peaks' showMethods("peaks") ## To look at one method in particular getMethod("peaks", "mzRpwiz") } } \keyword{methods} ProtGenerics/NAMESPACE0000644000175100017510000000006014614306144015414 0ustar00biocbuildbiocbuildimport(methods) exportPattern("^[[:alpha:]]+") ProtGenerics/NEWS0000644000175100017510000001037414614306144014705 0ustar00biocbuildbiocbuildCHANGES IN VERSION 1.35.4 ------------------------- o Move `backendParallelFactor` and `backendBpparam` and `supportsSetBackend` generics from `Spectra`. CHANGES IN VERSION 1.35.3 ------------------------- o Move `backendInitialize`, `backendMerge`, `setBackend`, `isReadOnly`, `peaksData`, `peaksData<-` and `peaksVariables`, `filterRanges`, `filterValues`, `filterPrecursorMzRange`, `filterPrecursorMzValues`, `filterProductMzRange`, `filterProductMzValues` generics from the Spectra package. CHANGES IN VERSION 1.35.2 ------------------------- o Add `filterSpectra` generic. CHANGES IN VERSION 1.35.1 ------------------------- o Add `filterFeatures` generic. CHANGES IN VERSION 1.33.1 ------------------------- o Rename uniqueMsLevel() to uniqueMsLevels() CHANGES IN VERSION 1.29.1 ------------------------- o Add spectrapply generic CHANGES IN VERSION 1.27.2 ------------------------- o Add addProcessing generic <2022-01-04 Tue> CHANGES IN VERSION 1.27.1 ------------------------- o Add new adjacencyMatrix generic <2021-12-11 Sat> CHANGES IN VERSION 1.27.0 ------------------------- o New Bioc devel version CHANGES IN VERSION 1.25.1 ------------------------- o add bin, compareChromatograms and compareSpectra CHANGES IN VERSION 1.25.0 ------------------------- o Bioc devel (3.14) version bump CHANGES IN VERSION 1.23.9 ------------------------- o Added new uniqueMsLevel generic <2021-04-08 Thu> CHANGES IN VERSION 1.23.8 ------------------------- o Added new filterPrecursorCharge generic <2021-04-06 Tue> CHANGES IN VERSION 1.23.7 ------------------------- o Add ProcessingStep object and related methods (moved from Spectra) CHANGES IN VERSION 1.23.6 ------------------------- o Added quantify generics (moved from MSnbase) <2021-01-02 Sat> CHANGES IN VERSION 1.23.5 ------------------------- o new alignRt generic. CHANGES IN VERSION 1.23.4 ------------------------- o new virtual Param class. CHANGES IN VERSION 1.23.3 ------------------------- o new filterIntensity generic. CHANGES IN VERSION 1.23.2 ------------------------- o new compounds generic. CHANGES IN VERSION 1.23.1 ------------------------- o new calculateFragments generic (moved from MSnbase) CHANGES IN VERSION 1.19.3 ------------------------- o new impute generic CHANGES IN VERSION 1.19.2 ------------------------- o new filterNA generic CHANGES IN VERSION 1.19.1 ------------------------- o new aggregateFeatures generic CHANGES IN VERSION 1.17.4 ------------------------- o New generics needed in Spectra and Chromatograms packages <2019-08-20 Tue> CHANGES IN VERSION 1.17.3 ------------------------- o New tolerance generic <2019-08-16 Fri> CHANGES IN VERSION 1.17.2 ------------------------- o New generics (see issue #8) <2019-05-12 Sun> CHANGES IN VERSION 1.17.1 ------------------------- o Move many generics from MSnbase <2019-05-11 Sat> CHANGES IN VERSION 1.9.1 ------------------------ o add writeMSData <2017-09-20 Wed> CHANGES IN VERSION 1.5.1 ------------------------ o added isCentroided generic <2016-07-23 Sat> CHANGES IN VERSION 1.5.0 ------------------------ o Version bump Bioc devel CHANGES IN VERSION 1.4.0 ------------------------ o Version bump Bioc 3.3 CHANGES IN VERSION 1.3.3 ------------------------ o exporting mz<- generic <2015-10-19 Mon> CHANGES IN VERSION 1.3.2 ------------------------ o Not depending on BiocGenerics <2015-10-16 Fri> CHANGES IN VERSION 1.3.1 ------------------------ o added chomatogram generic (previously defined in MSnbase) <2015-10-15 Thu> CHANGES IN VERSION 1.3.0 ------------------------ o Bioc release 3.3 CHANGES IN VERSION 1.2.0 ------------------------ o Bioc release 3.2 CHANGES IN VERSION 1.1.1 ------------------------ o new mz<- generic function <2015-10-01 Thu> CHANGES IN VERSION 1.1.0 ------------------------ o Bioc devel version 3.2 CHANGES IN VERSION 1.0.0 ------------------------ o Bioc release version 3.1 CHANGES IN VERSION 0.99.3 ------------------------- o update man with when and why ProtGenerics [2015-03-16 Mon] CHANGES IN VERSION 0.99.2 ------------------------- o updating DESCRIPTION as with BiocContributions::clean [2015-03-03 Tue] CHANGES IN VERSION 0.99.1 ------------------------- o Adding NEWS file [2015-02-27 Fri] CHANGES IN VERSION 0.99.0 ------------------------- o adding ProtGenerics to Manifest ProtGenerics/R/0000755000175100017510000000000014614306144014402 5ustar00biocbuildbiocbuildProtGenerics/R/DataClasses.R0000644000175100017510000000306714614306144016722 0ustar00biocbuildbiocbuild#' @title Generic parameter class #' #' @name Param #' #' @rdname Param #' #' @author Johannes Rainer #' #' @description #' #' The `Param` class is a virtual class which can be used as *base* class #' from which *parameter* classes can inherit. #' #' The methods implemented for the `Param` class are: #' #' - `as.list`: coerces the `Param` class to a `list` with list elements #' representing the object's slot values, names the slot names. *Hidden* #' slots (i.e. those with a name starting with `.`) are not returned. In #' addition, a `Param` class can be coerced to a `list` using #' `as(object, "list")`. #' #' - `show`: prints the content of the `Param` object (i.e. the individual #' slots and their value). #' #' @param object `Param` object. #' #' @param x `Param` object. #' #' @param ... ignored. NULL #' @rdname Param setClass("Param", contains = "VIRTUAL") #' @rdname Param setMethod("as.list", signature(x = "Param"), function(x, ...) { snames <- slotNames(x) skip <- grep(snames, pattern = "^\\.") if (length(skip)) snames <- snames[-skip] res <- vector("list", length(snames)) names(res) <- snames for (i in seq_along(res)) res[[i]] <- slot(x, name = snames[i]) res }) #' @rdname Param setMethod("show", "Param", function(object) { cat("Object of class: ", class(object), "\n") lst <- as.list(object) cat(" Parameters:\n") for (i in seq_along(lst)) { cat(" - ", names(lst)[i], ": ", sep = "") print(lst[[i]]) } }) setAs("Param", "list", function(from, to) { as.list(from) }) ProtGenerics/R/ProcessingStep.R0000644000175100017510000000626014614306144017501 0ustar00biocbuildbiocbuildsetClassUnion("characterOrFunction", c("character", "function")) #' @title Processing step #' #' @aliases ProcessingStep-class characterOrFunction-class #' #' @description #' #' Class containing the function and arguments to be applied in a lazy-execution #' framework. #' #' Objects of this class are created using the `ProcessingStep()` function. The #' processing step is executed with the `executeProcessingStep()` function. #' #' @details #' #' This object contains all relevant information of a data analysis processing #' step, i.e. the function and all of its arguments to be applied to the data. #' This object is mainly used to record possible processing steps of a #' `Spectra` or `OnDiskMSnExp` object (from the `Spectra` and `MSnbase` #' packages, respectively). #' #' @return The `ProcessingStep` function returns and object of type #' `ProcessingStep`. #' #' @author Johannes Rainer #' #' @exportClass ProcessingStep #' #' @md #' #' @examples #' #' ## Create a simple processing step object #' ps <- ProcessingStep(sum) #' #' executeProcessingStep(ps, 1:10) #' #' @name ProcessingStep NULL setClass("ProcessingStep", representation = representation( FUN = "characterOrFunction", ARGS = "list" ), prototype = prototype( ARGS = list(), FUN = character() ), validity = function(object) { msg <- character() ## Fails with un-exported functions. if (length(object@FUN)) { if (!is.function(object@FUN)) { res <- try(match.fun(object@FUN), silent = TRUE) if (is(res, "try-error")) msg <- c(msg, paste0("Function '", object@FUN, "' not found.")) } } if (length(msg)) msg else TRUE }) #' @param FUN `function` or `character` representing a function name. #' #' @param ARGS `list` of arguments to be passed along to `FUN`. #' #' @rdname ProcessingStep #' #' @md #' #' @export ProcessingStep <- function(FUN = character(), ARGS = list()) { if (missing(FUN)) FUN <- character() new("ProcessingStep", FUN = FUN, ARGS = ARGS) } .cat_fun <- function(x) { if (is.function(x)) "user-provided function" else x } #' @rdname ProcessingStep #' #' @exportMethod show setMethod("show", "ProcessingStep", function(object) { cat("Object of class \"", class(object), "\"\n", sep = "") cat(" Function: ", .cat_fun(object@FUN), "\n", sep = "") args <- object@ARGS if (length(args) > 0) { cat(" Arguments:\n") for (i in seq_along(args)) { cat(" o ", names(args)[i], " = ", .cat_fun(args[[i]]), "\n", sep = "") } } }) #' @param object `ProcessingStep` object. #' #' @param ... optional additional arguments to be passed along. #' #' @rdname ProcessingStep #' #' @md #' #' @export executeProcessingStep <- function(object, ...) { if (!is(object, "ProcessingStep")) stop("'object' is supposed to be a 'ProcessingStep' object!") do.call(object@FUN, args = c(list(...), object@ARGS)) } ProtGenerics/R/protgenerics.R0000644000175100017510000003345114614306144017237 0ustar00biocbuildbiocbuild## ------------------------------------------------------------- ## Data slots ## ------------------------------------------------------------- setGeneric("processingData", function(object, ...) standardGeneric("processingData")) setGeneric("processingData<-", function(object, ..., value) standardGeneric("processingData<-")) setGeneric("spectraVariables", function(object, ...) standardGeneric("spectraVariables")) setGeneric("spectraNames", function(object, ...) standardGeneric("spectraNames")) setGeneric("spectraNames<-", function(object, ..., value) standardGeneric("spectraNames<-")) setGeneric("spectraData", function(object, ...) standardGeneric("spectraData")) setGeneric("spectraData<-", function(object, ..., value) standardGeneric("spectraData<-")) setGeneric("dataOrigin", function(object, ...) standardGeneric("dataOrigin")) setGeneric("dataOrigin<-", function(object, value) standardGeneric("dataOrigin<-")) setGeneric("dataStorage", function(object, ...) standardGeneric("dataStorage")) setGeneric("dataStorage<-", function(object, value) standardGeneric("dataStorage<-")) ## ------------------------------------------------------------- ## Metadata ## ------------------------------------------------------------- setGeneric("ionCount", function(object, ...) standardGeneric("ionCount")) setGeneric("scanIndex", function(object, ...) standardGeneric("scanIndex")) setGeneric("precursorMz", function(object, ...) standardGeneric("precursorMz")) setGeneric("precursorMz<-", function(object, ..., value) standardGeneric("precursorMz<-")) setGeneric("precursorIntensity", function(object, ...) standardGeneric("precursorIntensity")) setGeneric("precursorIntensity<-", function(object, ..., value) standardGeneric("precursorIntensity<-")) setGeneric("precursorCharge", function(object, ...) standardGeneric("precursorCharge")) setGeneric("precursorCharge<-", function(object, ..., value) standardGeneric("precursorCharge<-")) setGeneric("acquisitionNum", function(object, ...) standardGeneric("acquisitionNum")) setGeneric("precAcquisitionNum", function(object, ...) standardGeneric("precAcquisitionNum")) setGeneric("precScanNum", function(object, ...) standardGeneric("precScanNum")) setGeneric("msLevel", function(object, ...) standardGeneric("msLevel")) setGeneric("msLevel<-", function(object, ..., value) standardGeneric("msLevel<-")) setGeneric("uniqueMsLevels", function(object, ...) standardGeneric("uniqueMsLevels")) setGeneric("collisionEnergy", function(object, ...) standardGeneric("collisionEnergy")) setGeneric("collisionEnergy<-", function(object, ..., value) standardGeneric("collisionEnergy<-")) setGeneric("polarity", function(object, ...) standardGeneric("polarity")) setGeneric("polarity<-", function(object, ..., value) standardGeneric("polarity<-")) setGeneric("tic", function(object, ...) standardGeneric("tic")) setGeneric("rtime", function(object, ...) standardGeneric("rtime")) setGeneric("rtime<-", function(object, ..., value) standardGeneric("rtime<-")) setGeneric("centroided", function(object, ...) standardGeneric("centroided")) setGeneric("centroided<-", function(object, ..., value) standardGeneric("centroided<-")) setGeneric("smoothed", function(object) standardGeneric("smoothed")) setGeneric("smoothed<-", function(object, ..., value) standardGeneric("smoothed<-")) setGeneric("isCentroided", function(object, ...) standardGeneric("isCentroided")) setGeneric("isolationWindowTargetMz", function(object, ...) standardGeneric("isolationWindowTargetMz")) setGeneric("isolationWindowTargetMz<-", function(object, ..., value) standardGeneric("isolationWindowTargetMz<-")) setGeneric("isolationWindowLowerMz", function(object, ...) standardGeneric("isolationWindowLowerMz")) setGeneric("isolationWindowLowerMz<-", function(object, ..., value) standardGeneric("isolationWindowLowerMz<-")) setGeneric("isolationWindowUpperMz", function(object, ...) standardGeneric("isolationWindowUpperMz")) setGeneric("isolationWindowUpperMz<-", function(object, ..., value) standardGeneric("isolationWindowUpperMz<-")) setGeneric("productMz", function(object, ...) standardGeneric("productMz")) setGeneric("productMz<-", function(object, ..., value) standardGeneric("productMz<-")) setGeneric("compounds", function(object, ...) standardGeneric("compounds")) ## ------------------------------------------------------------- ## Raw data ## ------------------------------------------------------------- setGeneric("peaks", function(object, ...) standardGeneric("peaks")) setGeneric("peaks<-", function(object, ..., value) standardGeneric("peaks<-")) setGeneric("intensity", function(object, ...) standardGeneric("intensity")) setGeneric("intensity<-", function(object, ..., value) standardGeneric("intensity<-")) setGeneric("mz", function(object, ...) standardGeneric("mz")) setGeneric("mz<-", function(object, ..., value) standardGeneric("mz<-")) setGeneric("spectra", function(object, ...) standardGeneric("spectra")) setGeneric("spectra<-", function(object, ..., value) standardGeneric("spectra<-")) setGeneric("scans", function(object, ...) standardGeneric("scans")) setGeneric("chromatograms", function(object, ...) standardGeneric("chromatograms")) setGeneric("chromatogram", function(object, ...) standardGeneric("chromatogram")) setGeneric("mass", function(object, ...) standardGeneric("mass")) setGeneric("ions", function(object, ...) standardGeneric("ions")) ## ------------------------------------------------------------- ## Identification ## ------------------------------------------------------------- setGeneric("modifications", function(object, ...) standardGeneric("modifications")) setGeneric("database", function(object, ...) standardGeneric("database")) setGeneric("psms", function(object, ...) standardGeneric("psms")) setGeneric("peptides", function(object, ...) standardGeneric("peptides")) setGeneric("proteins", function(object, ...) standardGeneric("proteins")) setGeneric("accessions", function(object, ...) standardGeneric("accessions")) setGeneric("tolerance", function(object, ...) standardGeneric("tolerance")) setGeneric("calculateFragments", function(sequence, object, ...) standardGeneric("calculateFragments")) setGeneric("adjacencyMatrix", function(object, ...) standardGeneric("adjacencyMatrix")) ## ------------------------------------------------------------- ## Instrument ## ------------------------------------------------------------- setGeneric("msInfo", function(object) standardGeneric("msInfo")) setGeneric("expemail", function(object) standardGeneric("expemail")) setGeneric("exptitle", function(object) standardGeneric("exptitle")) setGeneric("ionSource", function(object) standardGeneric("ionSource")) setGeneric("ionSourceDetails", function(object) standardGeneric("ionSourceDetails")) setGeneric("analyser", function(object) standardGeneric("analyser")) setGeneric("analyzer", function(object) standardGeneric("analyzer")) setGeneric("analyzerDetails", function(object) standardGeneric("analyzerDetails")) setGeneric("analyserDetails", function(object) standardGeneric("analyserDetails")) setGeneric("detectorType", function(object) standardGeneric("detectorType")) setGeneric("instrumentManufacturer", function(object) standardGeneric("instrumentManufacturer")) setGeneric("instrumentCustomisations", function(object) standardGeneric("instrumentCustomisations")) setGeneric("instrumentModel", function(object) standardGeneric("instrumentModel")) ## ------------------------------------------------------------- ## Data-processing ## ------------------------------------------------------------- setGeneric("smooth", function(x, ...) standardGeneric("smooth")) ## stats::smooth already exists setGeneric("combineFeatures", function(object, ...) standardGeneric("combineFeatures")) setGeneric("aggregateFeatures", function(object, ...) standardGeneric("aggregateFeatures")) setGeneric("impute", function(object, ...) standardGeneric("impute")) setGeneric("alignRt", function(x, y, ...) standardGeneric("alignRt")) setGeneric("quantify", function(object, ...) standardGeneric("quantify")) setGeneric("bin", function(x, ...) standardGeneric("bin")) setGeneric("compareSpectra", function(x, y, ...) standardGeneric("compareSpectra")) setGeneric("compareChromatograms", function(x, y, ...) standardGeneric("compareChromatograms")) setGeneric("addProcessing", function(object, ...) standardGeneric("addProcessing")) setGeneric("spectrapply", function(object, ...) standardGeneric("spectrapply")) ## ------------------------------------------------------------- ## IO ## ------------------------------------------------------------- setGeneric("writeMSData", function(object, file, ...) standardGeneric("writeMSData")) ## ------------------------------------------------------------- ## Filtering ## ------------------------------------------------------------- setGeneric("filterAcquisitionNum", function(object, ...) standardGeneric("filterAcquisitionNum")) setGeneric("filterDataOrigin", function(object, ...) standardGeneric("filterDataOrigin")) setGeneric("filterDataStorage", function(object, ...) standardGeneric("filterDataStorage")) setGeneric("filterEmptySpectra", function(object, ...) standardGeneric("filterEmptySpectra")) setGeneric("filterIsolationWindow", function(object, ...) standardGeneric("filterIsolationWindow")) setGeneric("filterMsLevel", function(object, ...) standardGeneric("filterMsLevel")) setGeneric("filterPolarity", function(object, ...) standardGeneric("filterPolarity")) setGeneric("filterPrecursorMz", function(object, ...) standardGeneric("filterPrecursorMz")) setGeneric("filterPrecursorMzRange", function(object, ...) standardGeneric("filterPrecursorMzRange")) setGeneric("filterPrecursorMzValues", function(object, ...) standardGeneric("filterPrecursorMzValues")) setGeneric("filterPrecursorCharge", function(object, ...) standardGeneric("filterPrecursorCharge")) setGeneric("filterProductMz", function(object, ...) standardGeneric("filterProductMz")) setGeneric("filterProductMzRange", function(object, ...) standardGeneric("filterProductMzRange")) setGeneric("filterProductMzValues", function(object, ...) standardGeneric("filterProductMzValues")) setGeneric("filterPrecursorScan", function(object, ...) standardGeneric("filterPrecursorScan")) setGeneric("filterRt", function(object, ...) standardGeneric("filterRt")) setGeneric("filterMz", function(object, ...) standardGeneric("filterMz")) setGeneric("filterMzRange", function(object, ...) standardGeneric("filterMzRange")) setGeneric("filterMzValues", function(object, ...) standardGeneric("filterMzValues")) setGeneric("filterNA", function(object, ...) standardGeneric("filterNA")) setGeneric("filterIntensity", function(object, ...) standardGeneric("filterIntensity")) setGeneric("filterRanges", function(object, ...) standardGeneric("filterRanges")) setGeneric("filterValues", function(object, ...) standardGeneric("filterValues")) #' @title Filter features #' #' @description #' #' Implementations of this generic filter function are supposed to filter #' *features* in `object` based on a filter criteria defined by #' parameter `filter`. #' #' @param object The object to filter. #' #' @param filter The filtering criteria on which `object` should be filtered. #' #' @param ... Optional parameters. #' #' @md setGeneric("filterFeatures", function(object, filter, ...) standardGeneric("filterFeatures")) #' @title Filter Spectra #' #' @description #' #' Implementations of this generic filter function are supposed to filter #' *spectra* (e.g. within a `Spectra` object) based on filter criteria #' defined with parameter `filter`. #' #' @param object The object to filter. #' #' @param filter The filtering criteria based on which `object` should be #' filtered. #' #' @param ... Optional parameters. #' #' @md setGeneric("filterSpectra", def = function(object, filter, ...) standardGeneric("filterSpectra")) #' @title General backend methods #' #' @description #' #' These methods are used for implementations of *backends* e.g. for `Spectra` #' or `Chromatograms` object to initialize the backend, merge backends or #' extract specific information from them. #' See the respective help pages (e.g. in the `Spectra` or `Chromatograms` #' packages) for information on the actual implementations of these methods. #' #' @param backend A *backend* object. #' #' @param object The *backend* object. #' #' @param ... Optional parameters. #' #' @md #' #' @name backendInitialize setGeneric("backendInitialize", function(object, ...) standardGeneric("backendInitialize")) #' @rdname backendInitialize setGeneric("isReadOnly", function(object) standardGeneric("isReadOnly")) #' @rdname backendInitialize setGeneric("setBackend", function(object, backend, ...) standardGeneric("setBackend")) #' @rdname backendInitialize setGeneric("backendMerge", function(object, ...) standardGeneric("backendMerge")) #' @rdname backendInitialize setGeneric("backendBpparam", def = function(object, ...) standardGeneric("backendBpparam")) #' @rdname backendInitialize setGeneric("backendParallelFactor", def = function(object, ...) standardGeneric("backendParallelFactor")) #' @rdname backendInitialize setGeneric("supportsSetBackend", function(object, ...) standardGeneric("supportsSetBackend")) #' @title Get or set MS peak data #' #' @description #' #' These methods get or set mass spectrometry (MS) peaks data, which can be #' m/z, intensity or retention time values. #' See the respective help pages (e.g. in the `Spectra` or `Chromatograms` #' packages) for information on the actual implementations of these methods. #' #' @param object A data object. #' #' @param value Replacement for peaks data. #' #' @param ... Optional parameters. #' #' @md #' #' @name peaksData setGeneric("peaksData", function(object, ...) standardGeneric("peaksData")) #' @rdname peaksData setGeneric("peaksData<-", function(object, value) standardGeneric("peaksData<-")) #' @rdname peaksData setGeneric("peaksVariables", function(object, ...) standardGeneric("peaksVariables")) ProtGenerics/README.md0000644000175100017510000001645014614306144015466 0ustar00biocbuildbiocbuild # Generic infrastructure for Bioconductor mass spectrometry packages ## Description: These generic functions and classes provide basic interfaces to operations on and data access to mass spectrometry infrastructure in the Bioconductor project. For the details, please consult the respective methods' manual pages. ## Usage: ```r psms(object, ...) peaks(object, ...) modifications(object, ...) database(object, ...) rtime(object, ...) tic(object, ...) spectra(object, ...) intensity(object, ...) mz(object, ...) peptides(object, ...) proteins(object, ...) accessions(object, ...) scans(object, ...) mass(object, ...) ions(object, ...) chromatograms(object, ...) chromatogram(object, ...) isCentroided(object, ...) ## and many more - see below ``` ## Arguments: - `object`: Object of class for which methods are defined. - `...`: Further arguments, possibly used by downstream methods. ## Details: ### When should one define a generics?: Generics are appropriate for functions that have _generic_ names, i.e. names that occur in multiple circumstances, (with different input classes, most often defined in different packages) or, when (multiple) dispatching is better handled by the generics mechanism rather than the developer. The dispatching mechanism will then automatically call the appropriate method and save the user from explicitly calling `package::method` or the developer to handle the multiple input types cases. When no such conflict exists or is unlikely to happen (for example when the name of the function is specific to a package or domain, or for class slots accessors and replacement methods), the usage of a generic is arguably questionable, and in most of these cases, simple, straightforward functions would be perfectly valid. ### When to define a generic in `ProtGenerics`?: `ProtGenerics` is not meant to be the central package for generics, nor should it stop developers from defining the generics they need. It is a means to centralise generics that are defined in different packages (for example `mzR::psms` and `mzID::psms`, or `IRanges::score` and `mzR::score`, now `BioGenerics::score`) or generics that live in a rather big package (say `mzR`) on which one wouldn't want to depend just for the sake of that generics' definition. The goal of `ProtGenerics` is to step in when namespace conflicts arise so as to to facilitate inter-operability of packages. In case such conflict appears due to multiple generics, we would (1) add these same definitions in `ProtGenerics`, (2) remove the definitions from the packages they stem from, which then (3) only need to import `ProtGenerics`. This would be very minor/straightforward changes for the developers and would resolve issues when they arise. More generics can be added on request by opening an issue or sending a pull request on: [https://github.com/RforMassSpectrometry/ProtGenerics](https://github.com/RforMassSpectrometry/ProtGenerics) ## See Also: - The `BiocGenerics` package for S4 generic functions needed by many Bioconductor packages. - `showMethods` for displaying a summary of the methods defined for a given generic function. - `selectMethod` for getting the definition of a specific method. - `setGeneric` and `setMethod` for defining generics and methods. ## Examples: ```r library("ProtGenerics") ## ## Attaching package: 'ProtGenerics' ## The following object is masked from 'package:stats': ## ## smooth ## List all the symbols defined in this package: ls('package:ProtGenerics') ## [1] "accessions" "acquisitionNum" ## [3] "addProcessing" "adjacencyMatrix" ## [5] "aggregateFeatures" "alignRt" ## [7] "analyser" "analyserDetails" ## [9] "analyzer" "analyzerDetails" ## [11] "as.list" "bin" ## [13] "calculateFragments" "centroided" ## [15] "centroided<-" "chromatogram" ## [17] "chromatograms" "collisionEnergy" ## [19] "collisionEnergy<-" "combineFeatures" ## [21] "compareChromatograms" "compareSpectra" ## [23] "compounds" "database" ## [25] "dataOrigin" "dataOrigin<-" ## [27] "dataStorage" "dataStorage<-" ## [29] "detectorType" "executeProcessingStep" ## [31] "expemail" "exptitle" ## [33] "filterAcquisitionNum" "filterDataOrigin" ## [35] "filterDataStorage" "filterEmptySpectra" ## [37] "filterIntensity" "filterIsolationWindow" ## [39] "filterMsLevel" "filterMz" ## [41] "filterNA" "filterPolarity" ## [43] "filterPrecursorCharge" "filterPrecursorMz" ## [45] "filterPrecursorScan" "filterProductMz" ## [47] "filterRt" "impute" ## [49] "instrumentCustomisations" "instrumentManufacturer" ## [51] "instrumentModel" "intensity" ## [53] "intensity<-" "ionCount" ## [55] "ions" "ionSource" ## [57] "ionSourceDetails" "isCentroided" ## [59] "isolationWindowLowerMz" "isolationWindowLowerMz<-" ## [61] "isolationWindowTargetMz" "isolationWindowTargetMz<-" ## [63] "isolationWindowUpperMz" "isolationWindowUpperMz<-" ## [65] "mass" "modifications" ## [67] "msInfo" "msLevel" ## [69] "msLevel<-" "mz" ## [71] "mz<-" "peaks" ## [73] "peaks<-" "peptides" ## [75] "polarity" "polarity<-" ## [77] "precAcquisitionNum" "precScanNum" ## [79] "precursorCharge" "precursorCharge<-" ## [81] "precursorIntensity" "precursorIntensity<-" ## [83] "precursorMz" "precursorMz<-" ## [85] "processingData" "processingData<-" ## [87] "ProcessingStep" "productMz" ## [89] "productMz<-" "proteins" ## [91] "psms" "quantify" ## [93] "rtime" "rtime<-" ## [95] "scanIndex" "scans" ## [97] "smooth" "smoothed" ## [99] "smoothed<-" "spectra" ## [ reached getOption("max.print") -- omitted 11 entries ] library("mzR") ## Loading required package: Rcpp ## What methods exists for 'peaks' showMethods("peaks") ## Function: peaks (package ProtGenerics) ## object="mzRnetCDF" ## object="mzRpwiz" ## To look at one method in particular getMethod("peaks", "mzRpwiz") ## Method Definition: ## ## function (object, ...) ## { ## .local <- function (object, scans) ## .peaks(object, scans) ## .local(object, ...) ## } ## ## ## ## Signatures: ## object ## target "mzRpwiz" ## defined "mzRpwiz" ``` ProtGenerics/tests/0000755000175100017510000000000014614306144015343 5ustar00biocbuildbiocbuildProtGenerics/tests/testthat/0000755000175100017510000000000014614306144017203 5ustar00biocbuildbiocbuildProtGenerics/tests/testthat.R0000644000175100017510000000011014614306144017316 0ustar00biocbuildbiocbuildlibrary("testthat") library("ProtGenerics") test_check("ProtGenerics") ProtGenerics/tests/testthat/test_ProcessingStep.R0000644000175100017510000000231314614306144023334 0ustar00biocbuildbiocbuildtest_that("ProcessingStep constructor", { ps <- new("ProcessingStep", FUN = "mean", ARGS = list(na.rm = TRUE)) expect_match(capture.output(show(ps))[1], "Object of class \"ProcessingStep\"") expect_error(new("ProcessingStep", FUN = "aaaa")) ps <- ProcessingStep(mean, list(na.rm = TRUE)) expect_true(validObject(ps)) }) test_that("ProcessingStep executeProcessingStep", { ps <- ProcessingStep("sum", list(c(1, 4, 5))) expect_identical(executeProcessingStep(ps), 10) ps <- ProcessingStep("sum", list(c(1, 4, 5, NA))) ## Pass optional arguments to ... expect_identical(executeProcessingStep(ps, na.rm = TRUE), 10) }) test_that(".cat_fun works", { res <- .cat_fun("sum") expect_equal(res, "sum") res <- .cat_fun(sum) expect_equal(res, "user-provided function") }) test_that("show,ProcessingStep works", { ps <- ProcessingStep(sum, list(1:4)) expect_output(show(ps), "user-provided function") ps <- ProcessingStep(function(z) z + 4) expect_output(show(ps), "user-provided function") ps <- ProcessingStep("sum", list(a = sqrt)) expect_output(show(ps), "Function: sum") expect_output(show(ps), "a = user-provided function") })