scran
C++ library for basic single-cell RNA-seq analyses
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
scran::FitVarianceTrend Class Reference

Fit a mean-variance trend to log-count data. More...

#include <FitVarianceTrend.hpp>

Classes

struct  Defaults
 Parameter defaults for trend fitting. More...
 
struct  Results
 Results of the trend fit. More...
 

Public Member Functions

FitVarianceTrendset_span (double s=Defaults::span)
 
FitVarianceTrendset_minimum_mean (double m=Defaults::minimum_mean)
 
FitVarianceTrendset_filter (bool f=Defaults::filter)
 
FitVarianceTrendset_transform (bool t=Defaults::transform)
 
FitVarianceTrendset_use_fixed_width (bool u=Defaults::use_fixed_width)
 
FitVarianceTrendset_fixed_width (double f=Defaults::fixed_width)
 
FitVarianceTrendset_minimum_window_count (int c=Defaults::minimum_window_count)
 
void run (size_t n, const double *mean, const double *variance, double *fitted, double *residuals) const
 
Results run (size_t n, const double *mean, const double *variance) const
 

Detailed Description

Fit a mean-variance trend to log-count data.

Fit a trend to the per-feature variances against the means, both of which are computed from log-normalized expression data. We use a LOWESS smoother in several steps:

  1. Filter out low-abundance genes, to ensure the span of the smoother is not skewed by many low-abundance genes.
  2. Take the quarter-root of the variances, to squeeze the trend towards 1. This makes the trend more "linear" to improve the performance of the LOWESS smoother; it also reduces the chance of obtaining negative fitted values.
  3. Apply the LOWESS smoother to the quarter-root variances. This is done using the implementation in the WeightedLowess library.
  4. Reverse the quarter-root transformation to obtain the fitted values for all non-low-abundance genes.
  5. Extrapolate linearly from the left-most fitted value to the origin to obtain fitted values for the previously filtered genes. This is empirically justified by the observation that mean-variance trends of log-expression data are linear at very low abundances.

Member Function Documentation

◆ set_span()

FitVarianceTrend & scran::FitVarianceTrend::set_span ( double  s = Defaults::span)
inline

Set the span for the LOWESS smoother as a proportion of the total number of points. This is only used if set_use_fixed_width() is set to false.

Parameters
sSpan for the smoother.
Returns
A reference to this FitVarianceTrend object.

◆ set_minimum_mean()

FitVarianceTrend & scran::FitVarianceTrend::set_minimum_mean ( double  m = Defaults::minimum_mean)
inline

Set the minimum mean log-expression, to use for filtering out low-abundance genes.

Parameters
mMinimum value for the mean log-expression.
Returns
A reference to this FitVarianceTrend object.

◆ set_filter()

FitVarianceTrend & scran::FitVarianceTrend::set_filter ( bool  f = Defaults::filter)
inline

Should any filtering be performed by log-expression? This may need to be disabled if FitVarianceTrend is not being used on statistics computed from log-expression values.

Parameters
fWhether filtering should be performed.
Returns
A reference to this FitVarianceTrend object.

◆ set_transform()

FitVarianceTrend & scran::FitVarianceTrend::set_transform ( bool  t = Defaults::transform)
inline

Should any transformation of the variances be performed prior to LOWESS smoothing. This may need to be disabled if FitVarianceTrend is not being used on statistics computed from log-expression values.

Parameters
tWhether transformation should be performed.
Returns
A reference to this FitVarianceTrend object.

◆ set_use_fixed_width()

FitVarianceTrend & scran::FitVarianceTrend::set_use_fixed_width ( bool  u = Defaults::use_fixed_width)
inline

Should a fixed-width constraint be applied to the LOWESS smoother? This forces each window to be a minimum width (see fixed_width()) and avoids problems with large differences in density. For example, the default smoother performs poorly at high abundances where there are few genes.

Parameters
uWhether to apply fixed-width constraints.
Returns
A reference to this FitVarianceTrend object.

◆ set_fixed_width()

FitVarianceTrend & scran::FitVarianceTrend::set_fixed_width ( double  f = Defaults::fixed_width)
inline

Define the width of the window to use when set_use_fixed_width() is set to true. This should be relative to the range of mean values in run(); the default value is chosen based on the typical range in single-cell RNA-seq data.

Parameters
fFixed width of the window.
Returns
A reference to this FitVarianceTrend object.

◆ set_minimum_window_count()

FitVarianceTrend & scran::FitVarianceTrend::set_minimum_window_count ( int  c = Defaults::minimum_window_count)
inline

Define the minimum number of observations in each window when set_use_fixed_width() is set to true. This ensures that each window contains at least a given number of observations; if it does not, it is extended using the standard LOWESS logic until the minimum number is achieved.

Parameters
cMinimum number of observations in the window.
Returns
A reference to this FitVarianceTrend object.

◆ run() [1/2]

void scran::FitVarianceTrend::run ( size_t  n,
const double *  mean,
const double *  variance,
double *  fitted,
double *  residuals 
) const
inline

Run the trend fitting on the means and variances across all features. This returns the fitted value and residual from the trend for each feature.

Parameters
nNumber of features.
[in]meanPointer to an array of length n, containing the means for all features.
[in]variancePointer to an array of length n, containing the variances for all features.
[out]fittedPointer to an array of length n, to store the fitted values.
[out]residualsPointer to an array of length n, to store the residuals.

◆ run() [2/2]

Results scran::FitVarianceTrend::run ( size_t  n,
const double *  mean,
const double *  variance 
) const
inline

Run the trend fitting on the means and variances across all features.

Parameters
nNumber of features.
[in]meanPointer to an array of length n, containing the means for all features.
[in]variancePointer to an array of length n, containing the variances for all features.
Returns
A Results object containing the fitted values and residuals of the trend.

The documentation for this class was generated from the following file: