A GeneSpec
consists of the gene IDs (possibly named with labels),
the summary function and the name of the summary function.
Methods
Method new()
Creates a new GeneSpec
object.
Usage
GeneSpec$new(genes = NULL, fun = NULL, fun_name = deparse(substitute(fun)))
Examples
# 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 5 11 7 11 11
#> GeneID:52 6 13 9 16 7
# We can also extract these as a `data.frame`.
x_spec$extract_data_frame(mat)
#> A GeneID.52
#> 1 5 6
#> 2 11 13
#> 3 7 9
#> 4 11 16
#> 5 11 7