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

Compute the median and MAD from an array of values. More...

#include <ComputeMedianMad.hpp>

Classes

struct  Defaults
 Default parameters. More...
 
struct  Results
 Medians and MADs, possibly for multiple blocks. More...
 

Public Member Functions

ComputeMedianMadset_log (bool l=Defaults::log)
 
ComputeMedianMadset_median_only (bool m=Defaults::median_only)
 
template<typename Input , typename Buffer >
Results run (size_t n, const Input *metrics, Buffer *buffer) const
 
template<typename Input >
Results run (size_t n, const Input *metrics) const
 
template<typename Input , typename Block , typename Buffer >
Results run_blocked (size_t n, const Block *block, std::vector< int > starts, const Input *metrics, Buffer *buffer) const
 
template<typename Block , typename Input >
Results run_blocked (size_t n, const Block *block, const Input *metrics) const
 

Static Public Member Functions

template<typename Block >
static std::vector< int > compute_block_starts (size_t n, const Block *block)
 

Detailed Description

Compute the median and MAD from an array of values.

Pretty much as it says on the can; computes the median of an array of values first, and uses the median to then compute the median absolute deviation (MAD) from that array. We support calculation of medians and MADs for separate "blocks" of observations in the same array. These statistics can be used in FilterOutliers to obtain filter thresholds for removing outliers.

Member Function Documentation

◆ set_log()

ComputeMedianMad & scran::ComputeMedianMad::set_log ( bool  l = Defaults::log)
inline
Parameters
lWhether to compute the median and MAD after log-transformation of the values. This is useful for defining thresholds based on fold changes from the center. If true, all values are assumed to be non-negative.
Returns
A reference to this ComputeMedianMad object.

◆ set_median_only()

ComputeMedianMad & scran::ComputeMedianMad::set_median_only ( bool  m = Defaults::median_only)
inline
Parameters
mWhether to only compute the median. If true, Results::mads will be filled with NaNs.
Returns
A reference to this ComputeMedianMad object.

◆ compute_block_starts()

template<typename Block >
static std::vector< int > scran::ComputeMedianMad::compute_block_starts ( size_t  n,
const Block *  block 
)
inlinestatic
Template Parameters
BlockInteger type, containing the block IDs.
Parameters
nNumber of observations.
[in]blockPointer to an array of block identifiers. If provided, the array should be of length equal to n. Values should be integer IDs in $[0, N)$ where $N$ is the number of blocks. If a null pointer is supplied, all observations are assumed to belong to the same block.
Returns
Vector of indices specifying the start position for each block on the workspace buffer, if observations from successive blocks were arranged contiguously onto the buffer.

◆ run() [1/2]

template<typename Input , typename Buffer >
Results scran::ComputeMedianMad::run ( size_t  n,
const Input *  metrics,
Buffer *  buffer 
) const
inline
Template Parameters
InputNumeric type for the input.
BufferFloating-point type for the buffer.
Parameters
nNumber of observations.
[in]metricsPointer to an array of observations of length n. NaNs are ignored.
bufferPointer to an array of length n, to be used as a workspace.
Returns
Median and MAD for the metrics.

◆ run() [2/2]

template<typename Input >
Results scran::ComputeMedianMad::run ( size_t  n,
const Input *  metrics 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Template Parameters
InputNumeric type for the input.
Parameters
nNumber of observations.
[in]metricsPointer to an array of observations of length n. NaNs are ignored.
Returns
Median and the MAD for metrics.

◆ run_blocked() [1/2]

template<typename Input , typename Block , typename Buffer >
Results scran::ComputeMedianMad::run_blocked ( size_t  n,
const Block *  block,
std::vector< int >  starts,
const Input *  metrics,
Buffer *  buffer 
) const
inline
Template Parameters
BlockInteger type, containing the block IDs.
InputNumeric type for the input.
BufferFloating-point type for the buffer.
Parameters
nNumber of observations.
[in]blockOptional pointer to an array of block identifiers. If provided, the array should be of length equal to ncells. Values should be integer IDs in $[0, N)$ where $N$ is the number of blocks. If a null pointer is supplied, all observations are assumed to belong to the same block.
startsVector of start positions for the observations from each block, typically generated by calling compute_block_starts() on n and block.
[in]metricsPointer to an array of observations of length n.
bufferPointer to an array of length n, to be used as a workspace.
Returns
Medians and MADs for each block in metrics.

◆ run_blocked() [2/2]

template<typename Block , typename Input >
Results scran::ComputeMedianMad::run_blocked ( size_t  n,
const Block *  block,
const Input *  metrics 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Template Parameters
BlockInteger type, containing the block IDs.
InputType of observation, numeric.
Parameters
nNumber of observations.
[in]blockOptional pointer to an array of block identifiers. If provided, the array should be of length equal to ncells. Values should be integer IDs in $[0, N)$ where $N$ is the number of blocks. If a null pointer is supplied, all observations are assumed to belong to the same block.
[in]metricsPointer to an array of observations of length n.
Returns
Median and the MAD for each block in metrics.

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