Add sample annotations from an external annotation table to an existing SummarizedExperiment object.

addSampleAnnots(sce, sampleAnnot)

Arguments

sce

A SummarizedExperiment object (or a derivative).

sampleAnnot

A data.frame with sample annotations. Must have at least columns named sample (which must contain all the column names of sce) and group (which contains the group assignment for each sample).

Value

An object of the same type as sce with additional sample annotations.

Author

Charlotte Soneson

Examples

## Import example data
mqFile <- system.file("extdata", "mq_example", "1356_proteinGroups.txt",
                      package = "einprot")
samples <- c("Adnp_IP04", "Adnp_IP05", "Adnp_IP06",
             "Chd4BF_IP07", "Chd4BF_IP08", "Chd4BF_IP09",
             "RBC_ctrl_IP01", "RBC_ctrl_IP02", "RBC_ctrl_IP03")
out <- importExperiment(inFile = mqFile, iColPattern = "^iBAQ\\.",
                        includeOnlySamples = samples)

## Define sample annotations
sampleAnnot <- data.frame(sample = samples,
                          group = gsub("_IP.*", "", samples),
                          random = sample(seq_len(9), 9))

## Add sample annotations to SCE
sce <- addSampleAnnots(out$sce, sampleAnnot = sampleAnnot)
SummarizedExperiment::colData(sce)  ## group information added to sce
#> DataFrame with 9 rows and 3 columns
#>                      sample       group    random
#>                 <character> <character> <integer>
#> Adnp_IP04         Adnp_IP04        Adnp         7
#> Adnp_IP05         Adnp_IP05        Adnp         4
#> Adnp_IP06         Adnp_IP06        Adnp         9
#> Chd4BF_IP07   Chd4BF_IP0...      Chd4BF         5
#> Chd4BF_IP08   Chd4BF_IP0...      Chd4BF         8
#> Chd4BF_IP09   Chd4BF_IP0...      Chd4BF         2
#> RBC_ctrl_IP01 RBC_ctrl_I...    RBC_ctrl         1
#> RBC_ctrl_IP02 RBC_ctrl_I...    RBC_ctrl         3
#> RBC_ctrl_IP03 RBC_ctrl_I...    RBC_ctrl         6