Author: Michael R. Crusoe <michael.crusoe@gmail.com>
Description: r-cran-locfit is non-free and not yet packaged for Debian
--- a/R/core.R
+++ b/R/core.R
@@ -153,7 +153,7 @@ NULL
 #' Wald significance tests (defined by \code{\link{nbinomWaldTest}}),
 #' or the likelihood ratio test on the difference in deviance between a
 #' full and reduced model formula (defined by \code{\link{nbinomLRT}})
-#' @param fitType either "parametric", "local", or "mean"
+#' @param fitType either "parametric", or "mean"
 #' for the type of fitting of dispersions to the mean intensity.
 #' See \code{\link{estimateDispersions}} for description.
 #' @param betaPrior whether or not to put a zero-mean normal prior on
@@ -202,7 +202,6 @@ NULL
 #' Michael I Love, Wolfgang Huber, Simon Anders: Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2. Genome Biology 2014, 15:550. \url{http://dx.doi.org/10.1186/s13059-014-0550-8}
 #' @import BiocGenerics BiocParallel S4Vectors IRanges GenomicRanges SummarizedExperiment Biobase Rcpp methods
 #'
-#' @importFrom locfit locfit
 #' @importFrom genefilter rowVars filtered_p
 #' @importFrom Hmisc wtd.quantile
 #' 
@@ -234,14 +233,14 @@ NULL
 #'
 #' @export
 DESeq <- function(object, test=c("Wald","LRT"),
-                  fitType=c("parametric","local","mean"), betaPrior,
+                  fitType=c("parametric","mean"), betaPrior,
                   full=design(object), reduced, quiet=FALSE,
                   minReplicatesForReplace=7, modelMatrixType,
                   parallel=FALSE, BPPARAM=bpparam()) {
   # check arguments
   stopifnot(is(object, "DESeqDataSet"))
   test <- match.arg(test, choices=c("Wald","LRT"))
-  fitType <- match.arg(fitType, choices=c("parametric","local","mean"))
+  fitType <- match.arg(fitType, choices=c("parametric","mean"))
   stopifnot(is.logical(quiet))
   stopifnot(is.numeric(minReplicatesForReplace))
   stopifnot(is.logical(parallel))
@@ -495,7 +494,7 @@ estimateSizeFactorsForMatrix <- function
 #' examples below.
 #'
 #' @param object a DESeqDataSet
-#' @param fitType either "parametric", "local", or "mean"
+#' @param fitType either "parametric", or "mean"
 #' for the type of fitting of dispersions to the mean intensity.
 #' See \code{\link{estimateDispersions}} for description.
 #' @param outlierSD the number of standard deviations of log
@@ -694,7 +693,7 @@ estimateDispersionsGeneEst <- function(o
 
 #' @rdname estimateDispersionsGeneEst
 #' @export
-estimateDispersionsFit <- function(object,fitType=c("parametric","local","mean"),
+estimateDispersionsFit <- function(object,fitType=c("parametric","mean"),
                                    minDisp=1e-8, quiet=FALSE) {
 
   if (is.null(mcols(object)$allZero)) {
@@ -711,7 +710,7 @@ estimateDispersionsFit <- function(objec
   ...then continue with testing using nbinomWaldTest or nbinomLRT")
   }
   
-  fitType <- match.arg(fitType, choices=c("parametric","local","mean"))
+  fitType <- match.arg(fitType, choices=c("parametric","mean"))
   stopifnot(length(fitType)==1)
   stopifnot(length(minDisp)==1)
   if (fitType == "parametric") {
@@ -725,18 +724,18 @@ estimateDispersionsFit <- function(objec
       fitType <- "local"
     }
   }
-  if (fitType == "local") {
-    dispFunction <- localDispersionFit(means = mcols(objectNZ)$baseMean[useForFit],
-                                       disps = mcols(objectNZ)$dispGeneEst[useForFit],
-                                       minDisp = minDisp)
-  }
+  #if (fitType == "local") {
+  #  dispFunction <- localDispersionFit(means = mcols(objectNZ)$baseMean[useForFit],
+  #                                     disps = mcols(objectNZ)$dispGeneEst[useForFit],
+  #                                     minDisp = minDisp)
+  #}
   if (fitType == "mean") {
     useForMean <- mcols(objectNZ)$dispGeneEst > 10*minDisp
     meanDisp <- mean(mcols(objectNZ)$dispGeneEst[useForMean],na.rm=TRUE,trim=0.001)
     dispFunction <- function(means) meanDisp
     attr( dispFunction, "mean" ) <- meanDisp
   }
-  if (!(fitType %in% c("parametric","local","mean"))) {
+  if (!(fitType %in% c("parametric","mean"))) {
     stop("unknown fitType")
   }
  
@@ -1849,16 +1848,17 @@ parametricDispersionFit <- function( mea
 
 # Local fit of dispersion to the mean intensity
 # fitting is done on log dispersion, log mean scale
-localDispersionFit <- function( means, disps, minDisp ) {
-  if (all(disps < minDisp*10)) {
-    return(rep(minDisp,length(disps)))
-  }
-  d <- data.frame(logDisps = log(disps), logMeans = log(means))
-  fit <- locfit(logDisps ~ logMeans, data=d[disps >= minDisp*10,,drop=FALSE],
-                weights = means[disps >= minDisp*10])
-  dispFunction <- function(means) exp(predict(fit, data.frame(logMeans=log(means))))
-  return(dispFunction)
-}
+# locfit is non-free and not packaged at this time for Debian
+#localDispersionFit <- function( means, disps, minDisp ) {
+#  if (all(disps < minDisp*10)) {
+#    return(rep(minDisp,length(disps)))
+#  }
+#  d <- data.frame(logDisps = log(disps), logMeans = log(means))
+#  fit <- locfit(logDisps ~ logMeans, data=d[disps >= minDisp*10,,drop=FALSE],
+#                weights = means[disps >= minDisp*10])
+#  dispFunction <- function(means) exp(predict(fit, data.frame(logMeans=log(means))))
+#  return(dispFunction)
+#}
 
 
 # convenience function for testing the log likelihood
--- a/R/methods.R
+++ b/R/methods.R
@@ -493,7 +493,7 @@ estimateSizeFactors.DESeqDataSet <- func
 setMethod("estimateSizeFactors", signature(object="DESeqDataSet"),
           estimateSizeFactors.DESeqDataSet)
 
-estimateDispersions.DESeqDataSet <- function(object, fitType=c("parametric","local","mean"),
+estimateDispersions.DESeqDataSet <- function(object, fitType=c("parametric","mean"),
                                              maxit=100, quiet=FALSE, modelMatrix=NULL) {
   # Temporary hack for backward compatibility with "old" DESeqDataSet
   # objects. Remove once all serialized DESeqDataSet objects around have
@@ -522,7 +522,7 @@ this column could have come in during co
     mcols(object) <- mcols(object)[,!(mcols(mcols(object))$type %in% c("intermediate","results")),drop=FALSE]
   }
   stopifnot(length(maxit)==1)
-  fitType <- match.arg(fitType, choices=c("parametric","local","mean"))
+  fitType <- match.arg(fitType, choices=c("parametric","mean"))
   
   noReps <- checkForExperimentalReplicates(object, modelMatrix)
   if (noReps) {
@@ -615,7 +615,7 @@ checkForExperimentalReplicates <- functi
 #' @rdname estimateDispersions
 #' @aliases estimateDispersions estimateDispersions,DESeqDataSet-method
 #' @param object a DESeqDataSet
-#' @param fitType either "parametric", "local", or "mean"
+#' @param fitType either "parametric", or "mean"
 #' for the type of fitting of dispersions to the mean intensity.
 #' \itemize{
 #'   \item parametric - fit a dispersion-mean relation of the form:
@@ -623,10 +623,6 @@ checkForExperimentalReplicates <- functi
 #'     via a robust gamma-family GLM. The coefficients \code{asymptDisp} and \code{extraPois}
 #'     are given in the attribute \code{coefficients} of the \code{\link{dispersionFunction}}
 #'     of the object.
-#'   \item local - use the locfit package to fit a local regression
-#'     of log dispersions over log base mean (normal scale means and dispersions
-#'     are input and output for \code{\link{dispersionFunction}}). The points
-#'     are weighted by normalized mean count in the local regression.
 #'   \item mean - use the mean of gene-wise dispersion estimates.
 #' }
 #' @param maxit control parameter: maximum number of iterations to allow for convergence
--- a/R/vst.R
+++ b/R/vst.R
@@ -53,12 +53,6 @@
 #' count data. The expression can be found in the file \file{vst.pdf}
 #' which is distributed with the vignette.
 #'
-#' \code{fitType="local"},
-#' the reciprocal of the square root of the variance of the normalized counts, as derived
-#' from the dispersion fit, is then numerically
-#' integrated, and the integral (approximated by a spline function) is evaluated for each
-#' count value in the column, yielding a transformed value. 
-#'
 #' \code{fitType="mean"}, a VST is applied for Negative Binomial distributed counts, 'k',
 #' with a fixed dispersion, 'a': ( 2 asinh(sqrt(a k)) - log(a) - log(4) )/log(2).
 #' 
@@ -202,7 +196,7 @@ getVarianceStabilizedData <- function(ob
     vst <- function(q) ( 2 * asinh(sqrt(alpha * q)) - log(alpha) - log(4) ) / log(2)
     return(vst(ncounts))
   } else {
-    stop( "fitType is not parametric, local or mean" )
+    stop( "fitType is not parametric, or mean" )
   }
 }
 
--- a/inst/doc/DESeq2.Rnw
+++ b/inst/doc/DESeq2.Rnw
@@ -961,9 +961,7 @@ Above, we used a parametric fit for the
 closed-form expression for the variance stabilizing transformation is
 used by \Rfunction{varianceStabilizingTransformation}, which is
 derived in the file \texttt{vst.pdf}, that is distributed in the
-package alongside this vignette. If a local fit is used (option
-\Robject{fitType="locfit"} to \Rfunction{estimateDispersions}) a
-numerical integration is used instead.
+package alongside this vignette.
 
 <<vsd1, echo=FALSE, fig.width=4.5, fig.height=4.5, fig.show="asis", fig.small=TRUE, fig.pos="!bt", fig.cap="VST and log2. Graphs of the variance stabilizing transformation for sample 1, in blue, and of the transformation $f(n) = \\log_2(n/s_1)$, in black. $n$ are the counts and $s_1$ is the size factor for the first sample.\\label{figure/vsd1-1}">>=
 px     <- counts(dds)[,1] / sizeFactors(dds)[1]
--- a/tests/testthat/test_disp_fit.R
+++ b/tests/testthat/test_disp_fit.R
@@ -78,7 +78,7 @@ expect_equal(dispD2DESeq, dispD2Num, tol
 # test fit alternative
 dds <- makeExampleDESeqDataSet()
 dds <- estimateSizeFactors(dds)
-ddsLocal <- estimateDispersions(dds, fitType="local")
+#ddsLocal <- estimateDispersions(dds, fitType="local")
 ddsMean <- estimateDispersions(dds, fitType="mean")
 ddsMed <- estimateDispersionsGeneEst(dds)
 useForMedian <- mcols(ddsMed)$dispGeneEst > 1e-7
--- a/tests/testthat/test_vst.R
+++ b/tests/testthat/test_vst.R
@@ -4,7 +4,7 @@ dds <- estimateSizeFactors(dds)
 dds <- estimateDispersionsGeneEst(dds)
 dds <- estimateDispersionsFit(dds, fitType="parametric")
 vsd <- varianceStabilizingTransformation(dds, blind=FALSE)
-dds <- estimateDispersionsFit(dds, fitType="local")
+#dds <- estimateDispersionsFit(dds, fitType="local")
 vsd <- varianceStabilizingTransformation(dds, blind=FALSE)
 dds <- estimateDispersionsFit(dds, fitType="mean")
 vsd <- varianceStabilizingTransformation(dds, blind=FALSE)  
@@ -28,4 +28,4 @@ vsd <- vst(counts(dds))
 dds <- makeExampleDESeqDataSet(n=100, m=10, betaSD=1.5)
 nf <- matrix(exp(rnorm(1000,0,.2)),ncol=10)
 normalizationFactors(dds) <- nf
-vsd <- varianceStabilizingTransformation(dds, fitType="local")
+#vsd <- varianceStabilizingTransformation(dds, fitType="local")
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -12,7 +12,7 @@ Description: Estimate variance-mean depe
 License: LGPL (>= 3)
 VignetteBuilder: knitr
 Imports: BiocGenerics (>= 0.7.5), Biobase, BiocParallel, genefilter,
-        methods, locfit, geneplotter, ggplot2, Hmisc, Rcpp (>= 0.11.0)
+        methods, geneplotter, ggplot2, Hmisc, Rcpp (>= 0.11.0)
 Depends: S4Vectors (>= 0.9.25), IRanges, GenomicRanges,
         SummarizedExperiment (>= 1.1.6)
 Suggests: testthat, knitr, BiocStyle, vsn, pheatmap, RColorBrewer,
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -86,7 +86,6 @@ importFrom(graphics,axis)
 importFrom(graphics,hist)
 importFrom(graphics,plot)
 importFrom(graphics,points)
-importFrom(locfit,locfit)
 importFrom(stats,Gamma)
 importFrom(stats,as.formula)
 importFrom(stats,coef)
--- a/vignettes/DESeq2.Rnw
+++ b/vignettes/DESeq2.Rnw
@@ -961,9 +961,7 @@ Above, we used a parametric fit for the
 closed-form expression for the variance stabilizing transformation is
 used by \Rfunction{varianceStabilizingTransformation}, which is
 derived in the file \texttt{vst.pdf}, that is distributed in the
-package alongside this vignette. If a local fit is used (option
-\Robject{fitType="locfit"} to \Rfunction{estimateDispersions}) a
-numerical integration is used instead.
+package alongside this vignette.
 
 <<vsd1, echo=FALSE, fig.width=4.5, fig.height=4.5, fig.show="asis", fig.small=TRUE, fig.pos="!bt", fig.cap="VST and log2. Graphs of the variance stabilizing transformation for sample 1, in blue, and of the transformation $f(n) = \\log_2(n/s_1)$, in black. $n$ are the counts and $s_1$ is the size factor for the first sample.\\label{figure/vsd1-1}">>=
 px     <- counts(dds)[,1] / sizeFactors(dds)[1]
@@ -1450,15 +1448,6 @@ and the variability of the gene-wise est
 plotDispEsts(dds)
 @
 
-\subsubsection{Local or mean dispersion fit}
-
-A local smoothed dispersion fit is automatically substitited in the case that
-the parametric curve doesn't fit the observed dispersion mean relationship.
-This can be prespecified by providing the argument
-\Robject{fitType="local"} to either \Rfunction{DESeq} or \Rfunction{estimateDispersions}.
-Additionally, using the mean of gene-wise disperion estimates as the
-fitted value can be specified by providing the argument \Robject{fitType="mean"}. 
-
 \subsubsection{Supply a custom dispersion fit}
 
 Any fitted values can be provided during dispersion estimation, using
