Calculate Tsallis diversity per gene across samples
Source:R/calculate_diversity.R
calculate_diversity.RdCalculate Tsallis diversity per gene across samples
Usage
calculate_diversity(
x,
genes = NULL,
norm = TRUE,
tpm = FALSE,
assayno = 1,
verbose = FALSE,
q = 2,
what = c("S", "D"),
nthreads = 1
)Arguments
- x
A numeric matrix or data.frame of transcript-level expression values (rows = transcripts, columns = samples), or a SummarizedExperiment- like object.
- genes
Character vector assigning each transcript (row) to a gene. Must have length equal to nrow(x) or the number of transcripts in `x`.
- norm
Logical; if TRUE, normalize Tsallis entropy to [0,1] per gene.
- tpm
Logical. If TRUE and `x` is a tximport-style list, use the `$abundance` matrix instead of `$counts`.
- assayno
Integer assay index to use when `x` is a SummarizedExperiment.
- verbose
Logical; print diagnostic messages when TRUE.
- q
Numeric scalar or vector of Tsallis q values to evaluate (q > 0). If length(q) > 1, the result will contain separate columns per sample and q.
- what
Which quantity to return: 'S' for Tsallis entropy or 'D' for Hill numbers.
- nthreads
Number of threads for parallel processing (default: 1). Set to > 1 to parallelize per-gene entropy calculations.
Value
A SummarizedExperiment with assay `diversity` containing per-gene diversity values.
Examples
data('tcga_brca_luma', package = 'TSENAT')
rc <- as.matrix(tcga_brca_luma[1:20, -1, drop = FALSE])
gs <- tcga_brca_luma[1:20, 1]
se <- calculate_diversity(rc, gs, q = 0.1, norm = TRUE)
SummarizedExperiment::assay(se)[1:3, 1:3]
#> TCGA-A7-A0CH_N TCGA-A7-A0CH_T TCGA-A7-A0D9_N
#> NA NA NA NA
#> NA.1 NA NA NA
#> NA.2 NA NA NA