thin_all: Binomial thinning for altering read-depth.

View source: R/genthin.R

thin_allR Documentation

Binomial thinning for altering read-depth.


Given a matrix of real RNA-seq counts, this function will apply a thinning factor uniformly to every count in this matrix. This uniformly lowers the read-depth for the entire dataset. The thinning factor should be provided on the log2-scale. This is a specific application of the binomial thinning approach in thin_diff. Though this particular form of thinning was used by Robinson and Storey (2014) in the context of deriving read-depth suggestions. It is also described in detail in Gerard (2020).


thin_all(mat, thinlog2, type = c("thin", "mult"))



A numeric matrix of RNA-seq counts. The rows index the genes and the columns index the samples.


A numeric scalar. This is the amount to shrink each count in mat (on the log2-scale). For example, a value of 0 means that we do not thin, a value of 1 means that we thin by a factor of 2, a value of 2 means we thin by a factor of 4, etc.


Should we apply binomial thinning (type = "thin") or just naive multiplication of the counts (type = "mult"). You should always have this set to "thin".


A list-like S3 object of class ThinData. Components include some or all of the following:


The modified matrix of counts.


The design matrix of variables used to simulate signal. This is made by column-binding design_fixed and the permuted version of design_perm.


A matrix of coefficients corresponding to designmat.


Additional variables that should be included in your design matrix in downstream fittings. This is made by column-binding the vector of 1's with design_obs.


A matrix of estimated surrogate variables. In simulation studies you would probably leave this out and estimate your own surrogate variables.


A matrix of target correlations between the surrogate variables and the permuted variables in the design matrix. This might be different from the target_cor you input because we pass it through fix_cor to ensure positive semi-definiteness of the resulting covariance matrix.


A matrix of simulated variables used to permute design_perm if the target_cor is not NULL.


David Gerard


  • Gerard, D (2020). "Data-based RNA-seq simulations by binomial thinning." BMC Bioinformatics. 21(1), 206. doi: 10.1186/s12859-020-3450-9.

  • Robinson, David G., and John D. Storey. "subSeq: determining appropriate sequencing depth through efficient read subsampling." Bioinformatics 30, no. 23 (2014): 3424-3426. doi: 10.1093/bioinformatics/btu552.

See Also


For subsampling the rows and columns of your real RNA-seq count matrix prior to applying binomial thinning.


For the more general thinning approach.


For thinning sample-wise.


For thinning gene-wise.


For converting a ThinData object to a SummarizedExperiment object.


For converting a ThinData object to a DESeqDataSet object.


## Generate count data and set thinning factor
## In practice, you would obtain mat from a real dataset, not simulate it.
n <- 10
p <- 1000
lambda <- 1000
mat <- matrix(lambda, ncol = n, nrow = p)
thinlog2 <- 1

## Thin read-depths
thout <- thin_all(mat = mat, thinlog2 = thinlog2)

## Compare empirical and theoretical proportions
mean(thout$mat) / lambda
2 ^ -thinlog2

seqgendiff documentation built on March 18, 2022, 5:21 p.m.