GeneSpec: R6 Class Representing a Gene (Signature) Specification

GeneSpecR Documentation

R6 Class Representing a Gene (Signature) Specification

Description

[Experimental]

A GeneSpec consists of the gene IDs (possibly named with labels), the summary function and the name of the summary function.

Methods

Public 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()
x_spec$get_genes()
x_spec$get_gene_labels()
x_spec$get_label()

# Using multiple genes with partial labels, without a signature.
x_spec <- gene_spec(c(A = "GeneID:1820", "GeneID:52"))
x_spec$returns_vector()
x_spec$get_gene_labels()

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

# We can also extract these as a `data.frame`.
x_spec$extract_data_frame(mat)

insightsengineering/hermes documentation built on Dec. 15, 2024, 8:07 a.m.