Skip to contents

Comparison Class

Comparison Class

Details

An R6 class that represents a comparison between two groups of samples. This class contains the comparison name, the group order, and the comparison table. It includes methods to initialise, print, and validate the data.

Public fields

comparison_name

Character. The name of the comparison.

group_order

Character vector. The order of groups for the comparison, with length 2. The first element is treated as the "control" group, and the second as the "test" group.

comparison_table

A data.table that contains the group, sample, and condition information for the comparison.

Methods


Method new()

Create a new Comparison object.

Usage

Comparison$new(comparison_name, group_order, comparison_table)

Arguments

comparison_name

A character string representing the name of the comparison. Must be of length 1 and not exceed 100 characters.

group_order

A character vector specifying the order of groups for the comparison. Must be of length 2.

comparison_table

A data.table that contains group and sample information for the comparison. It should have two columns, named "group" and "sample". The "group" column identifies the clinical group to which each sample belongs, and the "sample" column lists the names/IDs of the samples. The groups in this table should match the names specified in `group_order`. Print a summary of the Comparison object.


Method print()

Usage

Comparison$print()

Returns

None. This method is called for its side effect of printing to the console. Validate the Comparison object.


Method clone()

The objects of this class are cloneable with this method.

Usage

Comparison$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

comparison <- Comparison$new(
  comparison_name = "Treatment vs Control",
  group_order = c("Control", "Treatment"),
  comparison_table = data.table::data.table(
    group = c("Control", "Control", "Treatment", "Treatment"),
    sample = c("Sample1", "Sample2", "Sample3", "Sample4")
  )
)
#> Treatment vs Control: deriving condition "control", "test" from group_order argument: control - Control, test - Treatment
print(comparison)
#> Comparison R6 object
#> -----------------
#> Comparison Name:  Treatment vs Control 
#> Group Order:  Control, Treatment 
#> Comparison Table:
#>       group  sample condition
#> 1   Control Sample1   control
#> 2   Control Sample2   control
#> 3 Treatment Sample3      test
#> 4 Treatment Sample4      test