Skip to content

Commit

Permalink
Use S3 and S4 methods (#28)
Browse files Browse the repository at this point in the history
* use S3 and S4 methods for shared functionality across packages (e.g. FRASER)
* version bump: 1.7.0 -> 1.7.1

* CI fixes
  ** adapt to the new knitr update braking BiocStyle in R3.6
  ** no cache on appveyor
  ** just test r-release on windows (appveyor)
  • Loading branch information
c-mertes authored Oct 9, 2020
1 parent 515e247 commit 0bff757
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 239 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ before_install:
- tlmgr install index marginfix bera nowidow parnotes

install:
- R --version
- Rscript setupEnv.R

- R --version
- R -e "BiocManager::version()"

script:
- R CMD build .
- R -e 'BiocCheck::BiocCheck(".", `no-check-vignettes`=TRUE)'
- R CMD check --no-vignettes --timings *tar.gz
- R -e 'devtools::run_examples()'
- R -e 'devtools::run_examples(run=TRUE, document=TRUE)'
- cd vignettes && R CMD Sweave --engine=knitr::knitr --pdf OUTRIDER.Rnw


after_success:
- test $TRAVIS_BUILD_STAGE_NAME = "Test" && Rscript -e 'covr::codecov()'
9 changes: 4 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: OUTRIDER
Title: OUTRIDER - OUTlier in RNA-Seq fInDER
Type: Package
Version: 1.7.0
Version: 1.7.1
Date: 2020-04-13
URL: https://github.com/gagneurlab/OUTRIDER
BugRepots: https://github.com/gagneurlab/OUTRIDER/issues
Expand All @@ -27,7 +27,7 @@ biocViews: ImmunoOncology, RNASeq, Transcriptomics, Alignment, Sequencing,
License: MIT + file LICENSE
NeedsCompilation: yes
Encoding: UTF-8
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Depends:
R (>= 3.6),
BiocParallel,
Expand All @@ -37,16 +37,14 @@ Depends:
methods
Imports:
BBmisc,
Biobase,
BiocGenerics,
compiler,
DESeq2 (>= 1.16.1),
generics,
GenomicRanges,
ggplot2,
grDevices,
heatmaply,
pheatmap,
gplots,
graphics,
IRanges,
matrixStats,
Expand Down Expand Up @@ -79,6 +77,7 @@ LinkingTo:
Collate:
package-OUTRIDER.R
class-OutriderDataSet.R
AllGenerics.R
inputCheckerFunctions.R
helperFunctions.R
getNSetterFuns.R
Expand Down
24 changes: 13 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(fit,OutriderDataSet)
export("counts<-")
export("normalizationFactors<-")
export("sampleExclusionMask<-")
Expand All @@ -17,6 +18,7 @@ export(estimateSizeFactors)
export(filterExpression)
export(findEncodingDim)
export(findInjectZscore)
export(fit)
export(fpkm)
export(fpm)
export(getBestQ)
Expand All @@ -27,6 +29,7 @@ export(padj)
export(plotAberrantPerSample)
export(plotCountCorHeatmap)
export(plotCountGeneSampleHeatmap)
export(plotDispEsts)
export(plotEncDimSearch)
export(plotExpectedVsObservedCounts)
export(plotExpressedGenes)
Expand All @@ -41,14 +44,21 @@ export(sampleExclusionMask)
export(sizeFactors)
export(theta)
export(zScore)
exportMethods(aberrant)
exportMethods(computePvalues)
exportMethods(computeZscores)
exportMethods(dispersions)
exportMethods(filterExpression)
exportMethods(fit)
exportMethods(plotAberrantPerSample)
exportMethods(plotCountCorHeatmap)
exportMethods(plotDispEsts)
exportMethods(plotEncDimSearch)
exportMethods(plotQQ)
exportMethods(plotVolcano)
exportMethods(results)
import(data.table, except=melt)

import(methods)
importFrom(BBmisc,chunk)
importFrom(BBmisc,isFALSE)
importFrom(BBmisc,isScalarCharacter)
Expand All @@ -58,7 +68,6 @@ importFrom(BBmisc,isScalarNumeric)
importFrom(BBmisc,isScalarValue)
importFrom(BBmisc,seq_col)
importFrom(BBmisc,seq_row)
importFrom(Biobase,rowMax)
importFrom(BiocGenerics,estimateSizeFactors)
importFrom(BiocGenerics,plotDispEsts)
importFrom(BiocParallel,SerialParam)
Expand All @@ -79,6 +88,7 @@ importFrom(DESeq2,fpkm)
importFrom(DESeq2,fpm)
importFrom(DESeq2,makeExampleDESeqDataSet)
importFrom(DESeq2,normalizationFactors)
importFrom(DESeq2,plotDispEsts)
importFrom(DESeq2,replaceOutliers)
importFrom(DESeq2,show)
importFrom(DESeq2,sizeFactors)
Expand All @@ -90,7 +100,6 @@ importFrom(GenomicRanges,width)
importFrom(IRanges,IRanges)
importFrom(PRROC,pr.curve)
importFrom(RColorBrewer,brewer.pal)
importFrom(Rcpp,sourceCpp)
importFrom(S4Vectors,"metadata<-")
importFrom(S4Vectors,DataFrame)
importFrom(S4Vectors,metadata)
Expand All @@ -105,7 +114,7 @@ importFrom(SummarizedExperiment,assays)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,mcols)
importFrom(SummarizedExperiment,rowData)
importFrom(compiler,cmpfun)
importFrom(generics,fit)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotate)
importFrom(ggplot2,element_blank)
Expand Down Expand Up @@ -134,9 +143,6 @@ importFrom(ggplot2,theme_bw)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(ggplot2,ylim)
importFrom(gplots,barplot2)
importFrom(gplots,bluered)
importFrom(gplots,heatmap.2)
importFrom(grDevices,colorRampPalette)
importFrom(graphics,abline)
importFrom(graphics,axis)
Expand All @@ -157,10 +163,6 @@ importFrom(matrixStats,rowMeans2)
importFrom(matrixStats,rowMedians)
importFrom(matrixStats,rowQuantiles)
importFrom(matrixStats,rowSds)
importFrom(methods,as)
importFrom(methods,is)
importFrom(methods,new)
importFrom(methods,validObject)
importFrom(pcaMethods,loadings)
importFrom(pcaMethods,pca)
importFrom(pheatmap,pheatmap)
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
CHANGES IN VERSION 1.7.1
-----------------------------
o Move to S3/S4 methods to be compatible with FRASER
o Due to the S3/S4 changes minor changes in the argument names happend
mainly ods -> object or x

CHANGES IN VERSION 1.3.5
-----------------------------
o Change plotAberrantPerSample from base-R to ggplot2
Expand Down
50 changes: 50 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' @rdname aberrant
#' @export
setGeneric("aberrant", function(object, ...) standardGeneric("aberrant"))

#' @importFrom DESeq2 dispersions
#' @noRd
#' @export
DESeq2::dispersions

#' @rdname filterExpression
#' @export
setGeneric("filterExpression", function(object, ...)
standardGeneric("filterExpression"))

#' @importFrom generics fit
#' @noRd
#' @export
generics::fit

#' @rdname plotFunctions
#' @export
setGeneric("plotAberrantPerSample", function(object, ...)
standardGeneric("plotAberrantPerSample"))

#' @rdname plotFunctions
#' @export
setGeneric("plotCountCorHeatmap", function(object, ...)
standardGeneric("plotCountCorHeatmap"))

#' @importFrom DESeq2 plotDispEsts
#' @noRd
#' @export
DESeq2::plotDispEsts

#' @rdname plotFunctions
#' @export
setGeneric("plotEncDimSearch", function(object, ...)
standardGeneric("plotEncDimSearch"))

#' @rdname plotFunctions
#' @export
setGeneric("plotQQ", function(object, ...) standardGeneric("plotQQ"))

#' @rdname plotFunctions
#' @export
setGeneric("plotVolcano", function(object, ...) standardGeneric("plotVolcano"))

#' @rdname results
#' @export
setGeneric("results", function(object, ...) standardGeneric("results"))
38 changes: 17 additions & 21 deletions R/filterExpression.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
filterExpression.OUTRIDER <- function(object, gtfFile, fpkmCutoff=1,
percentile=0.95, filterGenes=TRUE, savefpkm=FALSE,
minCounts=FALSE, addExpressedGenes=TRUE, ...){
object <- filterMinCounts(object, filterGenes=filterGenes,
verbose=minCounts)
if(isTRUE(minCounts)){
return(object)
}
if(!missing(gtfFile)){
object <- computeGeneLength(object, gtfFile=gtfFile, ...)
}
filterExp(object, fpkmCutoff=fpkmCutoff, percentile=percentile,
filterGenes=filterGenes, savefpkm=savefpkm,
addExpressedGenes=addExpressedGenes)
}

#'
#' Filter expression
#'
Expand All @@ -8,7 +24,7 @@
#' the basepair parameter as described in \code{\link[DESeq2]{fpkm}}.
#'
#' @rdname filterExpression
#' @param x An OutriderDataSet object
#' @param object An OutriderDataSet object
#' @param filterGenes If TRUE, the default, the object is subseted.
#' @param minCounts If TRUE, only genes with 0 counts in all samples are
#' filtered
Expand Down Expand Up @@ -39,26 +55,6 @@
#' dim(ods)
#'
#' @export
setGeneric("filterExpression",
function(x, ...) standardGeneric("filterExpression"))

filterExpression.OUTRIDER <- function(x, gtfFile, fpkmCutoff=1,
percentile=0.95, filterGenes=TRUE, savefpkm=FALSE,
minCounts=FALSE, addExpressedGenes=TRUE, ...){
x <- filterMinCounts(x, filterGenes=filterGenes, verbose=minCounts)
if(isTRUE(minCounts)){
return(x)
}
if(!missing(gtfFile)){
x <- computeGeneLength(x, gtfFile=gtfFile, ...)
}
filterExp(x, fpkmCutoff=fpkmCutoff, percentile=percentile,
filterGenes=filterGenes, savefpkm=savefpkm,
addExpressedGenes=addExpressedGenes)
}

#' @rdname filterExpression
#' @export
setMethod("filterExpression", "OutriderDataSet", filterExpression.OUTRIDER)

filterExp <- function(ods, fpkmCutoff, percentile, filterGenes, savefpkm,
Expand Down
18 changes: 9 additions & 9 deletions R/fitNB.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
#'
#' @param object An OutriderDataSet
#' @param BPPARAM by default bpparam()
#' @param ... additional arguments, currently not used.
#' @param ... Currently not used.
#' @return An OutriderDataSet object with the fitted model. Accessible through:
#' \code{mcols(ods)[,c('mu', 'theta')]}.
#'
#' @docType methods
#' @name fit
#' @rdname fit
#' @aliases fit fit,OutriderDataSet-method
#'
#' @examples
#' ods <- makeExampleOutriderDataSet()
Expand All @@ -23,13 +21,15 @@
#'
#' mcols(ods)[1:10,c('mu', 'theta')]
#'
#' @exportMethod fit
setGeneric("fit", function(object, ...) standardGeneric("fit"))

#' @rdname fit
#' @export
setMethod("fit", "OutriderDataSet", function(object, BPPARAM=bpparam()){
fitTheta(object, BPPARAM=BPPARAM)})
fit.OutriderDataSet <- function(object, BPPARAM=bpparam(), ...){
if(length(list(...))){
stop("... is currently not used. Please remove the ",
"additional arguments: ",
paste(names(list(...)), collapse=", "))
}
fitTheta(object, BPPARAM=BPPARAM)
}

fitTheta <- function(ods, BPPARAM){
checkOutriderDataSet(ods)
Expand Down
8 changes: 6 additions & 2 deletions R/getNSetterFuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ padj <- function(ods){
return(ods)
}


#' @rdname getter_setter_functions
#' @export dispersions
setMethod("dispersions", signature(object="OutriderDataSet"),
#' @aliases dispersions dispersions,OutriderDataSet-method
#' @seealso \code{\link[DESeq2]{estimateDispersions}}
#' @export
setMethod("dispersions", signature(object="OutriderDataSet"),
function(object, ...){ 1/theta(object) })


#' @rdname getter_setter_functions
#' @export theta
theta <- function(ods){
Expand Down
36 changes: 19 additions & 17 deletions R/method-evaluation.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
aberrant.OUTRIDER <- function(object, padjCutoff=0.05, zScoreCutoff=0,
by=c("none", "sample", "gene")){
checkFullAnalysis(object)

aberrantEvents <- padj(object) <= padjCutoff
if(isScalarNumeric(zScoreCutoff, na.ok=FALSE)){
aberrantEvents <- aberrantEvents & abs(zScore(object)) >= zScoreCutoff
}

return(switch(match.arg(by),
none = aberrantEvents,
sample = colSums(aberrantEvents, na.rm=TRUE),
gene = rowSums(aberrantEvents, na.rm=TRUE)
))
}

#'
#' Number of aberrant events
#'
#' Identifies the aberrant events and returns the number of aberrant counts per
#' gene or sample or returns a matrix indicating aberrant events.
#'
#' @param ods An OutriderDataSet object
#' @param object An OutriderDataSet object
#' @param padjCutoff The padjust cutoff
#' @param zScoreCutoff The absolute Z-score cutoff,
#' if NA or NULL no Z-score cutoff is used
#' @param by if the results should be summarized by 'sample',
#' 'gene' or not at all (default).
#' @param ... Currently not in use.
#'
#' @return The number of aberrent events by gene or sample or a TRUE/FALSE
#' matrix of the size sample x gene of aberrent events.
Expand All @@ -24,19 +41,4 @@
#'
#' @rdname aberrant
#' @export
aberrant <- function(ods, padjCutoff=0.05, zScoreCutoff=0,
by=c("none", "sample", "gene")){
checkFullAnalysis(ods)

aberrantEvents <- padj(ods) <= padjCutoff
if(isScalarNumeric(zScoreCutoff, na.ok=FALSE)){
aberrantEvents <- aberrantEvents & abs(zScore(ods)) >= zScoreCutoff
}

return(switch(match.arg(by),
none = aberrantEvents,
sample = colSums(aberrantEvents, na.rm=TRUE),
gene = rowSums(aberrantEvents, na.rm=TRUE)
))
}

setMethod("aberrant", signature="OutriderDataSet", aberrant.OUTRIDER)
Loading

0 comments on commit 0bff757

Please sign in to comment.