[Experimental]

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)))

Arguments

genes

(named character or NULL)
the gene IDs, where the names are used as labels if available.

fun

(function or NULL)
summary function. If NULL is used then multiple genes are not summarized but returned as a matrix from the extract method.

fun_name

(string)
name of the summary function.

Returns

A new GeneSpec object.


Method get_genes()

Returns the genes.

Usage

GeneSpec$get_genes()


Method get_gene_labels()

Returns the gene labels (substituted by gene IDs if not available).

Usage

GeneSpec$get_gene_labels(genes = self$get_genes())

Arguments

genes

(character)
for which subset of genes the labels should be returned.


Method returns_vector()

Predicate whether the extract returns a vector or not.

Usage

GeneSpec$returns_vector()


Method get_label()

Returns a string which can be used e.g. for plot labels.

Usage

GeneSpec$get_label(genes = self$get_genes())

Arguments

genes

(character)
for which subset of genes the labels should be returned.


Method extract()

Extract the gene values from an assay as specified.

Usage

GeneSpec$extract(assay)

Arguments

assay

(matrix)
original matrix with rownames containing the specified genes.

Returns

Either a vector with one value per column, or a matrix with multiple genes in the rows.


Method extract_data_frame()

Extract the gene values as a data.frame.

Usage

GeneSpec$extract_data_frame(assay)

Arguments

assay

(matrix)
original matrix with rownames containing the specified genes.

Returns

A data.frame with the genes in the columns and the samples in the rows.


Method clone()

The objects of this class are cloneable with this method.

Usage

GeneSpec$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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           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