A GeneSpec
consists of the gene IDs (possibly named with labels),
the summary function and the name of the summary function.
new()
Creates a new GeneSpec
object.
GeneSpec$new(genes = NULL, fun = NULL, fun_name = deparse(substitute(fun)))
# Minimal specification if only one gene is used.
x_spec <- gene_spec("GeneID:1820")
# Using multiple genes with a signature.
x_spec <- gene_spec(c("GeneID:1820", "GeneID:52"), fun = colMeans)
x_spec <- gene_spec(c("GeneID:1820", "GeneID:52"), fun = colPrinComp1)
x_spec$returns_vector()
#> [1] TRUE
x_spec$get_genes()
#> [1] "GeneID:1820" "GeneID:52"
x_spec$get_gene_labels()
#> [1] "GeneID:1820" "GeneID:52"
x_spec$get_label()
#> [1] "colPrinComp1(GeneID:1820, GeneID:52)"
# Using multiple genes with partial labels, without a signature.
x_spec <- gene_spec(c(A = "GeneID:1820", "GeneID:52"))
x_spec$returns_vector()
#> [1] FALSE
x_spec$get_gene_labels()
#> [1] "A" "GeneID:52"
# Use the gene specification to extract genes from a matrix.
mat <- matrix(
data = rpois(15, 10),
nrow = 3, ncol = 5,
dimnames = list(c("GeneID:1820", "GeneID:52", "GeneID:523"), NULL)
)
x_spec$extract(mat)
#> [,1] [,2] [,3] [,4] [,5]
#> A 15 8 9 4 10
#> GeneID:52 6 10 9 9 14
# We can also extract these as a `data.frame`.
x_spec$extract_data_frame(mat)
#> A GeneID.52
#> 1 15 6
#> 2 8 10
#> 3 9 9
#> 4 4 9
#> 5 10 14