Skip to contents

Extracts columns relevant for a configuration from a data frame and create new columns e.g. sampleName column etc.

Usage

setup_analysis(data, configuration, debug = FALSE)

Arguments

data

a data.frame with the configured source hierarchy, factor, file-name and numeric response columns

configuration

AnalysisConfiguration

debug

if FALSE (default) and any hierarchy-key/sample combination has more than one observation, stop with an informative error. If TRUE, warn and return the diagnostic count table (inspect rows where n > 1) instead.

Value

A tibble with the columns relevant for configuration (sample, hierarchy, factor and response columns). Stops if any hierarchy-key/sample combination is observed more than once (unless debug = TRUE).

Details

setup_analysis() is optional: LFQData$new(setup = FALSE), the default, applies none of the steps below. Each step that changes the data says so with a message (class prolfqua_message) or warning:

  • several configured hierarchy or factor source columns are united into one key column (separator configuration$sep); avoid by configuring one column per key;

  • factor source columns of class factor stay factors, so their level order sets the reference level of the design; an ordered factor becomes unordered and unused levels are dropped (both announced); numeric or logical source columns are converted to character labels (announced), whose reference level is the first sorted label; avoid by supplying character or unordered factor columns; names of configuration$factors become the predictor column names;

  • a missing sample name is derived from the file name; avoid by supplying the sample name column;

  • missing identification q-values and child counts receive default values (child counts of one with a warning); avoid by supplying these columns;

  • unconfigured columns and their attributes are dropped; the returned table keeps only configured analysis columns;

  • feature and sample combinations absent from the input are added as rows with NA response, so every feature has a row in every sample.

Examples


# Example with a normValue column (e.g., creatinine)
set.seed(1234)
data <- sim_lfq_data(n_proteins = 10, peptide = TRUE, n_per_group = 4)
data$nr_children <- 1
data$qValue <- 0

# Add creatinine values per sample (not per protein/peptide)
sample_creatinine <- data |> dplyr::select(sample) |> dplyr::distinct() |>
  dplyr::mutate(creatinine = rnorm(dplyr::n(), mean = 100, sd = 10))
data <- dplyr::inner_join(data, sample_creatinine, by = "sample")

config <- AnalysisConfiguration$new()
config$file_name = "sample"
config$factors["group_"] = "group"
config$hierarchy[["protein_Id"]] = c("proteinID", "idtype2")
config$hierarchy[["peptide_Id"]] = "peptideID"
config$set_response("abundance")
config$norm_value = "creatinine"

adata <- setup_analysis(data, config)
#> `protein_Id`: columns `proteinID`, `idtype2` united with separator '~'.
#> creating sampleName from file_name column
#> setup_analysis: dropped 6 unconfigured columns: average_prot_abundance, sd, mean, N, avg_peptide_abd, Replicate.