Skip to contents

Validate SEDesign object contents

Usage

validate_sedesign(
  object,
  min_reps = 1,
  samples = NULL,
  groups = NULL,
  contrasts = NULL,
  verbose = FALSE,
  ...
)

Arguments

object

SEDesign object

min_reps

integer indicating the minimum required replicate samples per design group to be used during analysis. Any design groups with fewer replicates will be removed from the design matrix, and subsequently will be removed from the contrasts matrix.

samples, groups, contrasts

character vectors used to subset the samples, groups, or contrasts.

verbose

logical indicating whether to print verbose output, where verbose=TRUE will print messages at the end of operations, and verbose=2 will also print messages during operations.

...

additional arguments are ignored.

Value

SEDesign object after validation updates have been applied.

Details

This function validates and enforces constraints on SEDesign objects:

  • samples must match rownames(design)

  • colnames(design) must match rownames(contrasts)

If samples does not exist, and rownames(design) does exist, then samples will be defined as rownames(design).

If design and samples are provided, but rownames(design) is empty, it must be the same length as samples. then rownames(design) will be defined as samples.

Examples

factors2 <- rep(c("one", "two", "three", "four"), each=3)
factors2 <- factor(factors2,
   levels=unique(factors2))
names(factors2) <- paste0("sample", seq_along(factors2))
factors2
#>  sample1  sample2  sample3  sample4  sample5  sample6  sample7  sample8 
#>      one      one      one      two      two      two    three    three 
#>  sample9 sample10 sample11 sample12 
#>    three     four     four     four 
#> Levels: one two three four

mm2 <- model.matrix(~0 + factors2)
rownames(mm2) <- names(factors2)
colnames(mm2) <- levels(factors2);
mm2
#>          one two three four
#> sample1    1   0     0    0
#> sample2    1   0     0    0
#> sample3    1   0     0    0
#> sample4    0   1     0    0
#> sample5    0   1     0    0
#> sample6    0   1     0    0
#> sample7    0   0     1    0
#> sample8    0   0     1    0
#> sample9    0   0     1    0
#> sample10   0   0     0    1
#> sample11   0   0     0    1
#> sample12   0   0     0    1
#> attr(,"assign")
#> [1] 1 1 1 1
#> attr(,"contrasts")
#> attr(,"contrasts")$factors2
#> [1] "contr.treatment"
#> 

icontrastnames <- c("two-one",
   "four-three",
   "(four-three)-(two-one)");
icon <- c(-1, 1, 0, 0,
   0, 0, -1, 1,
   1, -1, -1, 1)
icontrasts2 <- matrix(icon,
   ncol=3,
   dimnames=list(levels(factors2),
      icontrastnames))
icontrasts2
#>       two-one four-three (four-three)-(two-one)
#> one        -1          0                      1
#> two         1          0                     -1
#> three       0         -1                     -1
#> four        0          1                      1

condes2 <- new("SEDesign",
   design=mm2,
   contrasts=icontrasts2)
condes2
#> An object of class "SEDesign"
#> Slot "design":
#>          one two three four
#> sample1    1   0     0    0
#> sample2    1   0     0    0
#> sample3    1   0     0    0
#> sample4    0   1     0    0
#> sample5    0   1     0    0
#> sample6    0   1     0    0
#> sample7    0   0     1    0
#> sample8    0   0     1    0
#> sample9    0   0     1    0
#> sample10   0   0     0    1
#> sample11   0   0     0    1
#> sample12   0   0     0    1
#> attr(,"assign")
#> [1] 1 1 1 1
#> attr(,"contrasts")
#> attr(,"contrasts")$factors2
#> [1] "contr.treatment"
#> 
#> 
#> Slot "contrasts":
#>       two-one four-three (four-three)-(two-one)
#> one        -1          0                      1
#> two         1          0                     -1
#> three       0         -1                     -1
#> four        0          1                      1
#> 
#> Slot "samples":
#> character(0)
#> 

# now subset samples
validate_sedesign(condes2,
   samples=paste0("sample", 2:12))
#> An object of class "SEDesign"
#> Slot "design":
#>          one two three four
#> sample2    1   0     0    0
#> sample3    1   0     0    0
#> sample4    0   1     0    0
#> sample5    0   1     0    0
#> sample6    0   1     0    0
#> sample7    0   0     1    0
#> sample8    0   0     1    0
#> sample9    0   0     1    0
#> sample10   0   0     0    1
#> sample11   0   0     0    1
#> sample12   0   0     0    1
#> 
#> Slot "contrasts":
#>       two-one four-three (four-three)-(two-one)
#> one        -1          0                      1
#> two         1          0                     -1
#> three       0         -1                     -1
#> four        0          1                      1
#> 
#> Slot "samples":
#>  [1] "sample2"  "sample3"  "sample4"  "sample5"  "sample6"  "sample7" 
#>  [7] "sample8"  "sample9"  "sample10" "sample11" "sample12"
#> 

# now subset enough samples to remove one group
validate_sedesign(condes2,
   samples=paste0("sample", 4:12))
#> Warning: longer object length is not a multiple of shorter object length
#> An object of class "SEDesign"
#> Slot "design":
#>          two three four
#> sample4    1     0    0
#> sample5    1     0    0
#> sample6    1     0    0
#> sample7    0     1    0
#> sample8    0     1    0
#> sample9    0     1    0
#> sample10   0     0    1
#> sample11   0     0    1
#> sample12   0     0    1
#> 
#> Slot "contrasts":
#>       four-three
#> two            0
#> three         -1
#> four           1
#> 
#> Slot "samples":
#> [1] "sample4"  "sample5"  "sample6"  "sample7"  "sample8"  "sample9"  "sample10"
#> [8] "sample11" "sample12"
#> 

validate_sedesign(condes2, groups=c("one", "two"))
#> An object of class "SEDesign"
#> Slot "design":
#>          one two
#> sample1    1   0
#> sample2    1   0
#> sample3    1   0
#> sample4    0   1
#> sample5    0   1
#> sample6    0   1
#> sample7    0   0
#> sample8    0   0
#> sample9    0   0
#> sample10   0   0
#> sample11   0   0
#> sample12   0   0
#> 
#> Slot "contrasts":
#>     two-one
#> one      -1
#> two       1
#> 
#> Slot "samples":
#>  [1] "sample1"  "sample2"  "sample3"  "sample4"  "sample5"  "sample6" 
#>  [7] "sample7"  "sample8"  "sample9"  "sample10" "sample11" "sample12"
#> 

condes2[, c("one", "two")]
#> An object of class "SEDesign"
#> Slot "design":
#>          one two
#> sample1    1   0
#> sample2    1   0
#> sample3    1   0
#> sample4    0   1
#> sample5    0   1
#> sample6    0   1
#> sample7    0   0
#> sample8    0   0
#> sample9    0   0
#> sample10   0   0
#> sample11   0   0
#> sample12   0   0
#> 
#> Slot "contrasts":
#>     two-one
#> one      -1
#> two       1
#> 
#> Slot "samples":
#>  [1] "sample1"  "sample2"  "sample3"  "sample4"  "sample5"  "sample6" 
#>  [7] "sample7"  "sample8"  "sample9"  "sample10" "sample11" "sample12"
#>