Skip to contents

Limma-based contrasts (direct limma pipeline)

Limma-based contrasts (direct limma pipeline)

Details

Uses limma's contrasts.fit + eBayes pipeline directly, rather than fitting per-protein lm models and then moderating. Inherits from ContrastsInterface with the same API as Contrasts.

Super class

prolfqua::ContrastsInterface -> ContrastsLimma

Public fields

model

ModelLimma object

contrasts

named character vector of contrasts

modelName

model name

subject_Id

columns with subject_Id (proteinID)

p.adjust

function to adjust p-values

contrast_result

cached contrast results

Methods

Inherited methods


Method new()

initialize ContrastsLimma

Usage

ContrastsLimma$new(
  model,
  contrasts,
  p.adjust = prolfqua::adjust_p_values,
  modelName = "limma"
)

Arguments

model

a ModelLimma object

contrasts

named character vector of contrasts

p.adjust

function to adjust p-values

modelName

name of the contrast method


Method get_contrast_sides()

get both sides of contrasts

Usage

ContrastsLimma$get_contrast_sides()


Method get_linfct()

get linear functions from contrasts

Usage

ContrastsLimma$get_linfct(global = TRUE, avg = TRUE)

Arguments

global

ignored (for API compatibility)

avg

logical, also compute avgAbd linfct


Method get_contrasts()

get table with contrast estimates via limma pipeline

Usage

ContrastsLimma$get_contrasts(all = FALSE)

Arguments

all

should all columns be returned (default FALSE)

Returns

data.frame with contrasts


Method get_Plotter()

return ContrastsPlotter

Usage

ContrastsLimma$get_Plotter(FCthreshold = 1, FDRthreshold = 0.1)

Arguments

FCthreshold

fold change threshold to show in plots

FDRthreshold

FDR threshold to show in plots


Method to_wide()

convert to wide format

Usage

ContrastsLimma$to_wide(columns = c("p.value", "FDR", "statistic"))

Arguments

columns

value column default p.value

Returns

data.frame


Method clone()

The objects of this class are cloneable with this method.

Usage

ContrastsLimma$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


istar <- sim_lfq_data_protein_config(Nprot = 50)
#> creating sampleName from fileName column
#> completing cases
#> completing cases done
#> setup done
lProt <- LFQData$new(istar$data, istar$config)
lProt$rename_response("transformedIntensity")

strat <- strategy_limma("transformedIntensity ~ group_")
mod_limma <- build_model_limma(lProt, strat)
#> Warning: Partial NA coefficients for 1 probe(s)

Contr <- c("dil.b_vs_a" = "group_A - group_Ctrl")
contr_limma <- ContrastsLimma$new(mod_limma, Contr)
res <- contr_limma$get_contrasts()
head(res)
#> # A tibble: 6 × 13
#>   modelName protein_Id contrast   diff     FDR std.error statistic p.value sigma
#>   <chr>     <chr>      <chr>     <dbl>   <dbl>     <dbl>     <dbl>   <dbl> <dbl>
#> 1 limma     0EfVhX~71… dil.b_v…  3.00  6.99e-4     0.681     4.40  1.43e-5 0.963
#> 2 limma     0m5WN4~35… dil.b_v…  0.222 8.35e-1     0.736     0.301 7.63e-1 0.963
#> 3 limma     76k03k~97… dil.b_v…  0.509 8.35e-1     0.681     0.747 4.55e-1 0.963
#> 4 limma     7QuTub~55… dil.b_v… -1.22  4.39e-1     0.736    -1.66  9.69e-2 0.963
#> 5 limma     7cbcrd~04… dil.b_v…  1.38  5.47e-1     0.963     1.44  1.51e-1 0.963
#> 6 limma     7soopj~34… dil.b_v…  0.822 5.88e-1     0.681     1.21  2.28e-1 0.963
#> # ℹ 4 more variables: df <dbl>, conf.low <dbl>, conf.high <dbl>, avgAbd <dbl>
stopifnot(all(c("diff", "FDR", "p.value", "statistic") %in% colnames(res)))

# Compare with prolfqua's own pipeline
modelFunction <- strategy_lm("transformedIntensity ~ group_")
mod <- build_model(lProt, modelFunction)
#> Joining with `by = join_by(protein_Id)`
contr_prolfqua <- Contrasts$new(mod, Contr)
res_prolfqua <- contr_prolfqua$get_contrasts()
#> determine linear functions:
#> Warning: Warn 'linfct_matrix_contrasts':In argument: `dil.b_vs_a = group_A - group_Ctrl`.
#> Warning: Warn 'linfct_matrix_contrasts':In argument: `avg_dil.b_vs_a = (group_A + group_Ctrl)/2`.
#> get_contrasts -> contrasts_linfct
#> contrasts_linfct
#> Joining with `by = join_by(protein_Id, contrast)`

# fold changes should be very similar
merged <- dplyr::inner_join(
  dplyr::select(res, protein_Id, diff_limma = diff),
  dplyr::select(res_prolfqua, protein_Id, diff_prolfqua = diff),
  by = "protein_Id")
#> Adding missing grouping variables: `contrast`
stopifnot(cor(merged$diff_limma, merged$diff_prolfqua, use = "complete.obs") > 0.99)

# Plotter works
pl <- contr_limma$get_Plotter()

# to_wide works
wide <- contr_limma$to_wide()
head(wide)
#> # A tibble: 6 × 5
#>   protein_Id  diff.dil.b_vs_a p.value.dil.b_vs_a FDR.dil.b_vs_a
#>   <chr>                 <dbl>              <dbl>          <dbl>
#> 1 0EfVhX~7161           3.00           0.0000143       0.000699
#> 2 0m5WN4~3543           0.222          0.763           0.835   
#> 3 76k03k~9735           0.509          0.455           0.835   
#> 4 7QuTub~5556          -1.22           0.0969          0.439   
#> 5 7cbcrd~0495           1.38           0.151           0.547   
#> 6 7soopj~3451           0.822          0.228           0.588   
#> # ℹ 1 more variable: statistic.dil.b_vs_a <dbl>

# merge_contrasts_results works
Contr2 <- c("dil.b_vs_a" = "group_A - group_Ctrl")
csi <- ContrastsMissing$new(lProt, contrasts = Contr2)
merged_res <- merge_contrasts_results(contr_limma, csi)
#> completing cases
#> dil.b_vs_a=group_A - group_Ctrl
#> dil.b_vs_a=group_A - group_Ctrl
#> dil.b_vs_a=group_A - group_Ctrl
#> Joining with `by = join_by(protein_Id, contrast)`
#> Joining with `by = join_by(protein_Id, contrast)`